Zebediah Figura : vkd3d-shader: Lower SUB to NEG + ADD at parse time.

Alexandre Julliard julliard at winehq.org
Wed Aug 11 16:33:48 CDT 2021


Module: vkd3d
Branch: master
Commit: 6e3bdb17dcbc6e4973d698328170fe75ec6de922
URL:    https://source.winehq.org/git/vkd3d.git/?a=commit;h=6e3bdb17dcbc6e4973d698328170fe75ec6de922

Author: Zebediah Figura <zfigura at codeweavers.com>
Date:   Mon Aug  9 21:56:19 2021 -0500

vkd3d-shader: Lower SUB to NEG + ADD at parse time.

Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
Signed-off-by: Matteo Bruni <mbruni at codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 libs/vkd3d-shader/hlsl.c     |  1 -
 libs/vkd3d-shader/hlsl.h     |  1 -
 libs/vkd3d-shader/hlsl.y     | 20 ++++++++++++++++++--
 libs/vkd3d-shader/hlsl_sm1.c |  4 ----
 4 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c
index d0be075..e407057 100644
--- a/libs/vkd3d-shader/hlsl.c
+++ b/libs/vkd3d-shader/hlsl.c
@@ -1062,7 +1062,6 @@ static const char *debug_expr_op(const struct hlsl_ir_expr *expr)
         "sat",
 
         "+",
-        "-",
         "*",
         "/",
 
diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h
index e566ac7..3b0e520 100644
--- a/libs/vkd3d-shader/hlsl.h
+++ b/libs/vkd3d-shader/hlsl.h
@@ -302,7 +302,6 @@ enum hlsl_ir_expr_op
     HLSL_IR_UNOP_SAT,
 
     HLSL_IR_BINOP_ADD,
-    HLSL_IR_BINOP_SUB,
     HLSL_IR_BINOP_MUL,
     HLSL_IR_BINOP_DIV,
 
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y
index 34cdb54..2754514 100644
--- a/libs/vkd3d-shader/hlsl.y
+++ b/libs/vkd3d-shader/hlsl.y
@@ -1118,7 +1118,7 @@ static enum hlsl_ir_expr_op op_from_assignment(enum parse_assign_op op)
     {
         0,
         HLSL_IR_BINOP_ADD,
-        HLSL_IR_BINOP_SUB,
+        0,
         HLSL_IR_BINOP_MUL,
         HLSL_IR_BINOP_DIV,
         HLSL_IR_BINOP_MOD,
@@ -1176,12 +1176,23 @@ static struct hlsl_ir_node *add_assignment(struct hlsl_ctx *ctx, struct list *in
     struct hlsl_ir_expr *copy;
     DWORD writemask = 0;
 
+    if (assign_op == ASSIGN_OP_SUB)
+    {
+        struct hlsl_ir_node *args[3] = {rhs};
+        struct hlsl_ir_expr *expr;
+
+        if (!(expr = add_expr(ctx, instrs, HLSL_IR_UNOP_NEG, args, &rhs->loc)))
+            return NULL;
+        rhs = &expr->node;
+        assign_op = ASSIGN_OP_ADD;
+    }
     if (assign_op != ASSIGN_OP_ASSIGN)
     {
         enum hlsl_ir_expr_op op = op_from_assignment(assign_op);
         struct hlsl_ir_node *args[3] = {lhs, rhs};
         struct hlsl_ir_expr *expr;
 
+        assert(op);
         if (!(expr = add_expr(ctx, instrs, op, args, &rhs->loc)))
             return NULL;
         rhs = &expr->node;
@@ -2909,7 +2920,12 @@ add_expr:
         }
     | add_expr '-' mul_expr
         {
-            $$ = add_binary_expr(ctx, $1, $3, HLSL_IR_BINOP_SUB, @2);
+            struct hlsl_ir_node *neg;
+
+            if (!(neg = hlsl_new_unary_expr(ctx, HLSL_IR_UNOP_NEG, node_from_list($3), @2)))
+                YYABORT;
+            list_add_tail($3, &neg->entry);
+            $$ = add_binary_expr(ctx, $1, $3, HLSL_IR_BINOP_ADD, @2);
         }
 
 shift_expr:
diff --git a/libs/vkd3d-shader/hlsl_sm1.c b/libs/vkd3d-shader/hlsl_sm1.c
index ca02f01..8ea663d 100644
--- a/libs/vkd3d-shader/hlsl_sm1.c
+++ b/libs/vkd3d-shader/hlsl_sm1.c
@@ -620,10 +620,6 @@ static void write_sm1_expr(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffer *b
             write_sm1_binary_op(ctx, buffer, D3DSIO_MUL, &instr->reg, &arg1->reg, &arg2->reg);
             break;
 
-        case HLSL_IR_BINOP_SUB:
-            write_sm1_binary_op(ctx, buffer, D3DSIO_SUB, &instr->reg, &arg1->reg, &arg2->reg);
-            break;
-
         case HLSL_IR_UNOP_NEG:
             write_sm1_unary_op(ctx, buffer, D3DSIO_MOV, &instr->reg, &arg1->reg, D3DSPSM_NEG);
             break;




More information about the wine-cvs mailing list