[Mesa-dev] [PATCH mesa 04/12] r600: fix memset(0) of non-trivial structs

Gert Wollny gw.fossdev at gmail.com
Wed Oct 31 07:31:21 UTC 2018


Am Montag, den 29.10.2018, 17:13 +0000 schrieb Eric Engestrom:
> Signed-off-by: Eric Engestrom <eric.engestrom at intel.com>
> ---
>  src/gallium/drivers/r600/sb/sb_expr.cpp          | 10 +++++-----
>  src/gallium/drivers/r600/sb/sb_if_conversion.cpp |  4 ++--
>  src/gallium/drivers/r600/sb/sb_ir.h              |  2 +-
>  src/gallium/drivers/r600/sb/sb_peephole.cpp      |  4 ++--
>  4 files changed, 10 insertions(+), 10 deletions(-)
> 
> diff --git a/src/gallium/drivers/r600/sb/sb_expr.cpp
> b/src/gallium/drivers/r600/sb/sb_expr.cpp
> index 05674ff24b88eaaae523..ee54f49531541d7860e9 100644
> --- a/src/gallium/drivers/r600/sb/sb_expr.cpp
> +++ b/src/gallium/drivers/r600/sb/sb_expr.cpp
> @@ -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] = {};

CMIIW, but this requires C++11, no? Is this already enabled for
compiling this part of mesa with the autotools? in .tavis-ci.yml I see
g++ 4.7 and 4.8 used, and these don't enable it by default. 

With this clarified this patch is 
Reviewed-By: Gert Wollny <gert.wollny at collabora.com> 

Best, 
Gert 

>  
>  			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] = {};
>  	}
>  
>  	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] = {};
>  					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] = {};
>  
>  				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] = {};
>  				n.src[1] = n.src[2];
>  				n.bc.src[1] = n.bc.src[2];
>  				n.src.resize(2);
> diff --git a/src/gallium/drivers/r600/sb/sb_if_conversion.cpp
> b/src/gallium/drivers/r600/sb/sb_if_conversion.cpp
> index 017153434fcaaf6e500f..42f934a1afa21638df60 100644
> --- a/src/gallium/drivers/r600/sb/sb_if_conversion.cpp
> +++ b/src/gallium/drivers/r600/sb/sb_if_conversion.cpp
> @@ -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] = {};
> +			a->bc.src[1] = {};
>  		} else {
>  			// kill with constant 'false' condition,
> this shouldn't happen
>  			// but remove it anyway
> diff --git a/src/gallium/drivers/r600/sb/sb_ir.h
> b/src/gallium/drivers/r600/sb/sb_ir.h
> index c7a94fcb930ecd9d9570..6410d7147d7e986ebcf0 100644
> --- a/src/gallium/drivers/r600/sb/sb_ir.h
> +++ b/src/gallium/drivers/r600/sb/sb_ir.h
> @@ -1012,7 +1012,7 @@ class cf_node : public container_node {
>  
>  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) { bc = {}; };
>  public:
>  	bc_alu bc;
>  
> diff --git a/src/gallium/drivers/r600/sb/sb_peephole.cpp
> b/src/gallium/drivers/r600/sb/sb_peephole.cpp
> index 4390a8f525c87749e2d4..b0b751d382c16193934f 100644
> --- a/src/gallium/drivers/r600/sb/sb_peephole.cpp
> +++ b/src/gallium/drivers/r600/sb/sb_peephole.cpp
> @@ -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] = {};
> +		a->bc.src[1] = {};
>  	}
>  
>  	if (swapped || (a->src[1]->is_const() &&


More information about the mesa-dev mailing list