nir: nir_const_value_negative_equal compares one value at a time

Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Suggested-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Matt Turner <mattst88@gmail.com>
This commit is contained in:
Ian Romanick
2019-06-13 14:06:55 -07:00
parent bcd22b740c
commit ad50e812a3
3 changed files with 24 additions and 92 deletions

View File

@@ -1029,9 +1029,7 @@ nir_ssa_alu_instr_src_components(const nir_alu_instr *instr, unsigned src)
return instr->dest.dest.ssa.num_components; return instr->dest.dest.ssa.num_components;
} }
bool nir_const_value_negative_equal(const nir_const_value *c1, bool nir_const_value_negative_equal(nir_const_value c1, nir_const_value c2,
const nir_const_value *c2,
unsigned components,
nir_alu_type full_type); nir_alu_type full_type);
bool nir_alu_srcs_equal(const nir_alu_instr *alu1, const nir_alu_instr *alu2, bool nir_alu_srcs_equal(const nir_alu_instr *alu1, const nir_alu_instr *alu2,

View File

@@ -302,9 +302,8 @@ get_neg_instr(nir_src s)
} }
bool bool
nir_const_value_negative_equal(const nir_const_value *c1, nir_const_value_negative_equal(nir_const_value c1,
const nir_const_value *c2, nir_const_value c2,
unsigned components,
nir_alu_type full_type) nir_alu_type full_type)
{ {
assert(nir_alu_type_get_base_type(full_type) != nir_type_invalid); assert(nir_alu_type_get_base_type(full_type) != nir_type_invalid);
@@ -312,66 +311,29 @@ nir_const_value_negative_equal(const nir_const_value *c1,
switch (full_type) { switch (full_type) {
case nir_type_float16: case nir_type_float16:
for (unsigned i = 0; i < components; i++) { return _mesa_half_to_float(c1.u16) == -_mesa_half_to_float(c2.u16);
if (_mesa_half_to_float(c1[i].u16) !=
-_mesa_half_to_float(c2[i].u16)) {
return false;
}
}
return true;
case nir_type_float32: case nir_type_float32:
for (unsigned i = 0; i < components; i++) { return c1.f32 == -c2.f32;
if (c1[i].f32 != -c2[i].f32)
return false;
}
return true;
case nir_type_float64: case nir_type_float64:
for (unsigned i = 0; i < components; i++) { return c1.f64 == -c2.f64;
if (c1[i].f64 != -c2[i].f64)
return false;
}
return true;
case nir_type_int8: case nir_type_int8:
case nir_type_uint8: case nir_type_uint8:
for (unsigned i = 0; i < components; i++) { return c1.i8 == -c2.i8;
if (c1[i].i8 != -c2[i].i8)
return false;
}
return true;
case nir_type_int16: case nir_type_int16:
case nir_type_uint16: case nir_type_uint16:
for (unsigned i = 0; i < components; i++) { return c1.i16 == -c2.i16;
if (c1[i].i16 != -c2[i].i16)
return false;
}
return true;
case nir_type_int32: case nir_type_int32:
case nir_type_uint32: case nir_type_uint32:
for (unsigned i = 0; i < components; i++) { return c1.i32 == -c2.i32;
if (c1[i].i32 != -c2[i].i32)
return false;
}
return true;
case nir_type_int64: case nir_type_int64:
case nir_type_uint64: case nir_type_uint64:
for (unsigned i = 0; i < components; i++) { return c1.i64 == -c2.i64;
if (c1[i].i64 != -c2[i].i64)
return false;
}
return true;
default: default:
break; break;
@@ -424,11 +386,15 @@ nir_alu_srcs_negative_equal(const nir_alu_instr *alu1,
return false; return false;
/* FINISHME: Apply the swizzle? */ /* FINISHME: Apply the swizzle? */
return nir_const_value_negative_equal(const1, const unsigned components = nir_ssa_alu_instr_src_components(alu1, src1);
const2, const nir_alu_type full_type = nir_op_infos[alu1->op].input_types[src1] |
nir_ssa_alu_instr_src_components(alu1, src1), nir_src_bit_size(alu1->src[src1].src);
nir_op_infos[alu1->op].input_types[src1] | for (unsigned i = 0; i < components; i++) {
nir_src_bit_size(alu1->src[src1].src)); if (!nir_const_value_negative_equal(const1[i], const2[i], full_type))
return false;
}
return true;
} }
uint8_t alu1_swizzle[4] = {0}; uint8_t alu1_swizzle[4] = {0};

View File

@@ -71,15 +71,13 @@ protected:
TEST_F(const_value_negative_equal_test, float32_zero) TEST_F(const_value_negative_equal_test, float32_zero)
{ {
/* Verify that 0.0 negative-equals 0.0. */ /* Verify that 0.0 negative-equals 0.0. */
EXPECT_TRUE(nir_const_value_negative_equal(c1, c1, NIR_MAX_VEC_COMPONENTS, EXPECT_TRUE(nir_const_value_negative_equal(c1[0], c1[0], nir_type_float32));
nir_type_float32));
} }
TEST_F(const_value_negative_equal_test, float64_zero) TEST_F(const_value_negative_equal_test, float64_zero)
{ {
/* Verify that 0.0 negative-equals 0.0. */ /* Verify that 0.0 negative-equals 0.0. */
EXPECT_TRUE(nir_const_value_negative_equal(c1, c1, NIR_MAX_VEC_COMPONENTS, EXPECT_TRUE(nir_const_value_negative_equal(c1[0], c1[0], nir_type_float64));
nir_type_float64));
} }
/* Compare an object with non-zero values to itself. This should always be /* Compare an object with non-zero values to itself. This should always be
@@ -89,9 +87,7 @@ TEST_F(const_value_negative_equal_test, float64_zero)
TEST_F(const_value_negative_equal_test, full_type ## _self) \ TEST_F(const_value_negative_equal_test, full_type ## _self) \
{ \ { \
count_sequence(c1, full_type, 1); \ count_sequence(c1, full_type, 1); \
EXPECT_FALSE(nir_const_value_negative_equal(c1, c1, \ EXPECT_FALSE(nir_const_value_negative_equal(c1[0], c1[0], full_type)); \
NIR_MAX_VEC_COMPONENTS, \
full_type)); \
} }
compare_with_self(nir_type_float16) compare_with_self(nir_type_float16)
@@ -113,10 +109,8 @@ compare_with_self(nir_type_uint64)
TEST_F(const_value_negative_equal_test, full_type ## _trivially_true) \ TEST_F(const_value_negative_equal_test, full_type ## _trivially_true) \
{ \ { \
count_sequence(c1, full_type, 1); \ count_sequence(c1, full_type, 1); \
negate(c2, c1, full_type, NIR_MAX_VEC_COMPONENTS); \ negate(c2, c1, full_type, 1); \
EXPECT_TRUE(nir_const_value_negative_equal(c1, c2, \ EXPECT_TRUE(nir_const_value_negative_equal(c1[0], c2[0], full_type)); \
NIR_MAX_VEC_COMPONENTS, \
full_type)); \
} }
compare_with_negation(nir_type_float16) compare_with_negation(nir_type_float16)
@@ -132,32 +126,6 @@ compare_with_negation(nir_type_int64)
compare_with_negation(nir_type_uint64) compare_with_negation(nir_type_uint64)
#undef compare_with_negation #undef compare_with_negation
/* Compare fewer than the maximum possible components. All of the components
* that are compared a negative-equal, but the extra components are not.
*/
#define compare_fewer_components(full_type) \
TEST_F(const_value_negative_equal_test, full_type ## _fewer_components) \
{ \
count_sequence(c1, full_type, 1); \
negate(c2, c1, full_type, 3); \
EXPECT_TRUE(nir_const_value_negative_equal(c1, c2, 3, full_type)); \
EXPECT_FALSE(nir_const_value_negative_equal(c1, c2, \
NIR_MAX_VEC_COMPONENTS, \
full_type)); \
}
compare_fewer_components(nir_type_float16)
compare_fewer_components(nir_type_float32)
compare_fewer_components(nir_type_float64)
compare_fewer_components(nir_type_int8)
compare_fewer_components(nir_type_uint8)
compare_fewer_components(nir_type_int16)
compare_fewer_components(nir_type_uint16)
compare_fewer_components(nir_type_int32)
compare_fewer_components(nir_type_uint32)
compare_fewer_components(nir_type_int64)
compare_fewer_components(nir_type_uint64)
TEST_F(alu_srcs_negative_equal_test, trivial_float) TEST_F(alu_srcs_negative_equal_test, trivial_float)
{ {
nir_ssa_def *two = nir_imm_float(&bld, 2.0f); nir_ssa_def *two = nir_imm_float(&bld, 2.0f);