r600/sb: replace memset by using member initialization/assignment
authorGert Wollny <gert.wollny@collabora.com>
Wed, 6 May 2020 16:29:44 +0000 (18:29 +0200)
committerGert Wollny <gert.wollny@collabora.com>
Thu, 7 May 2020 09:00:51 +0000 (11:00 +0200)
Closes #2860

Signed-off-by: Gert Wollny <gert.wollny@collabora.com>
Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4939>

src/gallium/drivers/r600/r600_isa.h
src/gallium/drivers/r600/sb/sb_bc.h
src/gallium/drivers/r600/sb/sb_expr.cpp
src/gallium/drivers/r600/sb/sb_if_conversion.cpp
src/gallium/drivers/r600/sb/sb_ir.h
src/gallium/drivers/r600/sb/sb_peephole.cpp

index fcaf1f766b36b143308ac417f57ceb61e2abd0bd..73694f7b43401fc378d8e1d3b2c8386e0668218d 100644 (file)
@@ -36,6 +36,7 @@ extern "C" {
 /* ALU flags */
 enum alu_op_flags
 {
+       AF_NONE = 0,
        AF_V            = (1<<0),    /* allowed in vector slots */
 
        /* allowed in scalar(trans) slot (slots xyz on cayman, may be replicated
index e7231702d802e755d0c55e21a842e4009d7cc361..942e228d95cdb80ac505ee8f53d744a02368e735 100644 (file)
@@ -495,6 +495,15 @@ struct bc_alu_src {
        unsigned abs:1;
        unsigned rel:1;
        literal value;
+
+       void clear() {
+               sel = 0;
+               chan = 0;
+               neg = 0;
+               abs = 0;
+               rel = 0;
+               value = 0;
+       }
 };
 
 struct bc_alu {
@@ -529,6 +538,31 @@ struct bc_alu {
                this->op = op;
                op_ptr = r600_isa_alu(op);
        }
+       void clear() {
+               op_ptr = nullptr;
+               op = 0;
+               for (int i = 0; i < 3; ++i)
+                       src[i].clear();
+               dst_gpr = 0;
+               dst_chan = 0;
+               dst_rel = 0;
+               clamp = 0;
+               omod = 0;
+               bank_swizzle = 0;
+               index_mode = 0;
+               last = 0;
+               pred_sel = 0;
+               fog_merge = 0;
+               write_mask = 0;
+               update_exec_mask = 0;
+               update_pred = 0;
+               slot = 0;
+               lds_idx_offset = 0;
+               slot_flags = AF_NONE;
+       }
+       bc_alu() {
+               clear();
+       }
 };
 
 struct bc_fetch {
index 73287f126b06c5ac842cf7f7f3568a1de73499f4..36361a251163f935f66bf09645bf52f99cd9be71 100644 (file)
@@ -719,7 +719,7 @@ bool expr_handler::fold_assoc(alu_node *n) {
                        n->src[0] = n->src[2];
                        n->bc.src[0] = n->bc.src[2];
                        n->src[1] = sh.get_const_value(cr);
-                       memset(&n->bc.src[1], 0, sizeof(bc_alu_src));
+                       n->bc.src[1].clear();
 
                        n->src.resize(2);
                        n->bc.set_op(ALU_OP2_ADD);
@@ -729,7 +729,7 @@ bool expr_handler::fold_assoc(alu_node *n) {
                n->bc.src[0] = a->bc.src[last_arg];
                n->bc.src[0].neg ^= cur_neg;
                n->src[1] = sh.get_const_value(cr);
-               memset(&n->bc.src[1], 0, sizeof(bc_alu_src));
+               n->bc.src[1].clear();
        }
 
        return false;
@@ -770,7 +770,7 @@ bool expr_handler::fold_alu_op2(alu_node& n) {
                        case ALU_OP2_ADD:  // (ADD x, x) => (MUL x, 2)
                                if (!sh.safe_math) {
                                        n.src[1] = sh.get_const_value(2.0f);
-                                       memset(&n.bc.src[1], 0, sizeof(bc_alu_src));
+                                       n.bc.src[1].clear();
                                        n.bc.set_op(ALU_OP2_MUL);
                                        return fold_alu_op2(n);
                                }
@@ -1070,7 +1070,7 @@ bool expr_handler::fold_alu_op3(alu_node& n) {
                                }
 
                                n.src[1] = t;
-                               memset(&n.bc.src[1], 0, sizeof(bc_alu_src));
+                               n.bc.src[1].clear();
 
                                n.src.resize(2);
 
@@ -1101,7 +1101,7 @@ bool expr_handler::fold_alu_op3(alu_node& n) {
                                dv = cv0.f * cv1.f;
                                n.bc.set_op(ALU_OP2_ADD);
                                n.src[0] = sh.get_const_value(dv);
-                               memset(&n.bc.src[0], 0, sizeof(bc_alu_src));
+                               n.bc.src[0].clear();
                                n.src[1] = n.src[2];
                                n.bc.src[1] = n.bc.src[2];
                                n.src.resize(2);
index 017153434fcaaf6e500f29f9f4f81eaaa3e64aac..48355e8d6e23a0bd82ff1d64687f77c969249241 100644 (file)
@@ -99,8 +99,8 @@ void if_conversion::convert_kill_instructions(region_node *r,
                        a->src[0] = cnd;
                        a->src[1] = sh.get_const_value(0);
                        // clear modifiers
-                       memset(&a->bc.src[0], 0, sizeof(bc_alu_src));
-                       memset(&a->bc.src[1], 0, sizeof(bc_alu_src));
+                       a->bc.src[0].clear();
+                       a->bc.src[1].clear();
                } else {
                        // kill with constant 'false' condition, this shouldn't happen
                        // but remove it anyway
index ef0fbd4e68f4545867ddc5173e5bf10c1d253d4b..2d629443641a1de76224689adc3c1ef0bac6e3f5 100644 (file)
@@ -1012,7 +1012,7 @@ public:
 
 class alu_node : public node {
 protected:
-       alu_node() : node(NT_OP, NST_ALU_INST) { memset(&bc, 0, sizeof(bc_alu)); }
+       alu_node() : node(NT_OP, NST_ALU_INST) {  }
 public:
        bc_alu bc;
 
index 4390a8f525c87749e2d4aae10ca91b2890a47181..979f4bc130ba97f5e79f70b770115a34e1e14fd5 100644 (file)
@@ -131,8 +131,8 @@ void peephole::optimize_cc_op2(alu_node* a) {
                std::swap(a->src[0],a->src[1]);
                swapped = true;
                // clear modifiers
-               memset(&a->bc.src[0], 0, sizeof(bc_alu_src));
-               memset(&a->bc.src[1], 0, sizeof(bc_alu_src));
+               a->bc.src[0].clear();
+               a->bc.src[1].clear();
        }
 
        if (swapped || (a->src[1]->is_const() &&