}
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);
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;
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};
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
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)
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)
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);