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:
@@ -1029,9 +1029,7 @@ nir_ssa_alu_instr_src_components(const nir_alu_instr *instr, unsigned src)
|
||||
return instr->dest.dest.ssa.num_components;
|
||||
}
|
||||
|
||||
bool nir_const_value_negative_equal(const nir_const_value *c1,
|
||||
const nir_const_value *c2,
|
||||
unsigned components,
|
||||
bool nir_const_value_negative_equal(nir_const_value c1, nir_const_value c2,
|
||||
nir_alu_type full_type);
|
||||
|
||||
bool nir_alu_srcs_equal(const nir_alu_instr *alu1, const nir_alu_instr *alu2,
|
||||
|
@@ -302,9 +302,8 @@ get_neg_instr(nir_src s)
|
||||
}
|
||||
|
||||
bool
|
||||
nir_const_value_negative_equal(const nir_const_value *c1,
|
||||
const nir_const_value *c2,
|
||||
unsigned components,
|
||||
nir_const_value_negative_equal(nir_const_value c1,
|
||||
nir_const_value c2,
|
||||
nir_alu_type full_type)
|
||||
{
|
||||
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) {
|
||||
case nir_type_float16:
|
||||
for (unsigned i = 0; i < components; i++) {
|
||||
if (_mesa_half_to_float(c1[i].u16) !=
|
||||
-_mesa_half_to_float(c2[i].u16)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return _mesa_half_to_float(c1.u16) == -_mesa_half_to_float(c2.u16);
|
||||
|
||||
case nir_type_float32:
|
||||
for (unsigned i = 0; i < components; i++) {
|
||||
if (c1[i].f32 != -c2[i].f32)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return c1.f32 == -c2.f32;
|
||||
|
||||
case nir_type_float64:
|
||||
for (unsigned i = 0; i < components; i++) {
|
||||
if (c1[i].f64 != -c2[i].f64)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return c1.f64 == -c2.f64;
|
||||
|
||||
case nir_type_int8:
|
||||
case nir_type_uint8:
|
||||
for (unsigned i = 0; i < components; i++) {
|
||||
if (c1[i].i8 != -c2[i].i8)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return c1.i8 == -c2.i8;
|
||||
|
||||
case nir_type_int16:
|
||||
case nir_type_uint16:
|
||||
for (unsigned i = 0; i < components; i++) {
|
||||
if (c1[i].i16 != -c2[i].i16)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return c1.i16 == -c2.i16;
|
||||
|
||||
case nir_type_int32:
|
||||
case nir_type_uint32:
|
||||
for (unsigned i = 0; i < components; i++) {
|
||||
if (c1[i].i32 != -c2[i].i32)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return c1.i32 == -c2.i32;
|
||||
|
||||
case nir_type_int64:
|
||||
case nir_type_uint64:
|
||||
for (unsigned i = 0; i < components; i++) {
|
||||
if (c1[i].i64 != -c2[i].i64)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return c1.i64 == -c2.i64;
|
||||
|
||||
default:
|
||||
break;
|
||||
@@ -424,11 +386,15 @@ nir_alu_srcs_negative_equal(const nir_alu_instr *alu1,
|
||||
return false;
|
||||
|
||||
/* FINISHME: Apply the swizzle? */
|
||||
return nir_const_value_negative_equal(const1,
|
||||
const2,
|
||||
nir_ssa_alu_instr_src_components(alu1, src1),
|
||||
nir_op_infos[alu1->op].input_types[src1] |
|
||||
nir_src_bit_size(alu1->src[src1].src));
|
||||
const unsigned components = nir_ssa_alu_instr_src_components(alu1, src1);
|
||||
const nir_alu_type full_type = nir_op_infos[alu1->op].input_types[src1] |
|
||||
nir_src_bit_size(alu1->src[src1].src);
|
||||
for (unsigned i = 0; i < components; i++) {
|
||||
if (!nir_const_value_negative_equal(const1[i], const2[i], full_type))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t alu1_swizzle[4] = {0};
|
||||
|
@@ -71,15 +71,13 @@ protected:
|
||||
TEST_F(const_value_negative_equal_test, float32_zero)
|
||||
{
|
||||
/* Verify that 0.0 negative-equals 0.0. */
|
||||
EXPECT_TRUE(nir_const_value_negative_equal(c1, c1, NIR_MAX_VEC_COMPONENTS,
|
||||
nir_type_float32));
|
||||
EXPECT_TRUE(nir_const_value_negative_equal(c1[0], c1[0], nir_type_float32));
|
||||
}
|
||||
|
||||
TEST_F(const_value_negative_equal_test, float64_zero)
|
||||
{
|
||||
/* Verify that 0.0 negative-equals 0.0. */
|
||||
EXPECT_TRUE(nir_const_value_negative_equal(c1, c1, NIR_MAX_VEC_COMPONENTS,
|
||||
nir_type_float64));
|
||||
EXPECT_TRUE(nir_const_value_negative_equal(c1[0], c1[0], nir_type_float64));
|
||||
}
|
||||
|
||||
/* 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) \
|
||||
{ \
|
||||
count_sequence(c1, full_type, 1); \
|
||||
EXPECT_FALSE(nir_const_value_negative_equal(c1, c1, \
|
||||
NIR_MAX_VEC_COMPONENTS, \
|
||||
full_type)); \
|
||||
EXPECT_FALSE(nir_const_value_negative_equal(c1[0], c1[0], full_type)); \
|
||||
}
|
||||
|
||||
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) \
|
||||
{ \
|
||||
count_sequence(c1, full_type, 1); \
|
||||
negate(c2, c1, full_type, NIR_MAX_VEC_COMPONENTS); \
|
||||
EXPECT_TRUE(nir_const_value_negative_equal(c1, c2, \
|
||||
NIR_MAX_VEC_COMPONENTS, \
|
||||
full_type)); \
|
||||
negate(c2, c1, full_type, 1); \
|
||||
EXPECT_TRUE(nir_const_value_negative_equal(c1[0], c2[0], full_type)); \
|
||||
}
|
||||
|
||||
compare_with_negation(nir_type_float16)
|
||||
@@ -132,32 +126,6 @@ compare_with_negation(nir_type_int64)
|
||||
compare_with_negation(nir_type_uint64)
|
||||
#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)
|
||||
{
|
||||
nir_ssa_def *two = nir_imm_float(&bld, 2.0f);
|
||||
|
Reference in New Issue
Block a user