diff options
author | Jason Ekstrand <[email protected]> | 2019-04-01 21:31:26 -0500 |
---|---|---|
committer | Karol Herbst <[email protected]> | 2019-04-14 22:25:56 +0200 |
commit | 9b1e4bab6bb3be7a5dad910b10a28db0a4bb8b5f (patch) | |
tree | c0a17e60f0f182dfcace2f4ac315a4074447049a /src/compiler/nir | |
parent | daaf777376303077f9fd4c72e602b8892fe1caaf (diff) |
nir/builder: Add a nir_imm_zero helper
v2: replace nir_zero_vec with nir_imm_zero (Karol Herbst)
Reviewed-by: Karol Herbst <[email protected]>
Diffstat (limited to 'src/compiler/nir')
-rw-r--r-- | src/compiler/nir/nir_builder.h | 13 | ||||
-rw-r--r-- | src/compiler/nir/nir_lower_int64.c | 5 | ||||
-rw-r--r-- | src/compiler/nir/nir_lower_io.c | 6 |
3 files changed, 17 insertions, 7 deletions
diff --git a/src/compiler/nir/nir_builder.h b/src/compiler/nir/nir_builder.h index 66a028bac97..9ee58dafd21 100644 --- a/src/compiler/nir/nir_builder.h +++ b/src/compiler/nir/nir_builder.h @@ -209,6 +209,19 @@ nir_build_imm(nir_builder *build, unsigned num_components, } static inline nir_ssa_def * +nir_imm_zero(nir_builder *build, unsigned num_components, unsigned bit_size) +{ + nir_load_const_instr *load_const = + nir_load_const_instr_create(build->shader, num_components, bit_size); + + /* nir_load_const_instr_create uses rzalloc so it's already zero */ + + nir_builder_instr_insert(build, &load_const->instr); + + return &load_const->def; +} + +static inline nir_ssa_def * nir_imm_bool(nir_builder *build, bool x) { nir_const_value v; diff --git a/src/compiler/nir/nir_lower_int64.c b/src/compiler/nir/nir_lower_int64.c index e7d361da6da..b3b78c6649a 100644 --- a/src/compiler/nir/nir_lower_int64.c +++ b/src/compiler/nir/nir_lower_int64.c @@ -493,9 +493,8 @@ lower_udiv64_mod64(nir_builder *b, nir_ssa_def *n, nir_ssa_def *d, nir_ssa_def *d_lo = nir_unpack_64_2x32_split_x(b, d); nir_ssa_def *d_hi = nir_unpack_64_2x32_split_y(b, d); - nir_const_value v = { .u32 = { 0, 0, 0, 0 } }; - nir_ssa_def *q_lo = nir_build_imm(b, n->num_components, 32, v); - nir_ssa_def *q_hi = nir_build_imm(b, n->num_components, 32, v); + nir_ssa_def *q_lo = nir_imm_zero(b, n->num_components, 32); + nir_ssa_def *q_hi = nir_imm_zero(b, n->num_components, 32); nir_ssa_def *n_hi_before_if = n_hi; nir_ssa_def *q_hi_before_if = q_hi; diff --git a/src/compiler/nir/nir_lower_io.c b/src/compiler/nir/nir_lower_io.c index 331ecc08324..c666fe16f7b 100644 --- a/src/compiler/nir/nir_lower_io.c +++ b/src/compiler/nir/nir_lower_io.c @@ -754,10 +754,8 @@ build_explicit_io_load(nir_builder *b, nir_intrinsic_instr *intrin, * as to what we can do with an OOB read. Unfortunately, returning * undefined values isn't one of them so we return an actual zero. */ - nir_const_value zero_val; - memset(&zero_val, 0, sizeof(zero_val)); - nir_ssa_def *zero = nir_build_imm(b, load->num_components, - load->dest.ssa.bit_size, zero_val); + nir_ssa_def *zero = nir_imm_zero(b, load->num_components, + load->dest.ssa.bit_size); const unsigned load_size = (load->dest.ssa.bit_size / 8) * load->num_components; |