Mesa (main): pan/bi: Unit test new constant folding patterns

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Aug 11 19:19:58 UTC 2021


Module: Mesa
Branch: main
Commit: cfd73b4542dc60230ca85b217b35013e15fc092b
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=cfd73b4542dc60230ca85b217b35013e15fc092b

Author: Alyssa Rosenzweig <alyssa at collabora.com>
Date:   Tue Aug 10 15:49:47 2021 -0400

pan/bi: Unit test new constant folding patterns

Signed-off-by: Alyssa Rosenzweig <alyssa at collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12205>

---

 src/panfrost/bifrost/test/test-constant-fold.c | 31 +++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/src/panfrost/bifrost/test/test-constant-fold.c b/src/panfrost/bifrost/test/test-constant-fold.c
index fad4e024142..73d4da82646 100644
--- a/src/panfrost/bifrost/test/test-constant-fold.c
+++ b/src/panfrost/bifrost/test/test-constant-fold.c
@@ -32,7 +32,7 @@
       fprintf(stderr, "Constant folding failed:\n"); \
       bi_print_instr(instr, stderr); \
       fprintf(stderr, "\n"); \
-   } else if (_value == expected) { \
+   } else if (_value == (expected)) { \
       nr_pass++; \
    } else { \
       fprintf(stderr, "Got %" PRIx32 ", expected %" PRIx32 "\n", _value, expected); \
@@ -80,6 +80,35 @@ main(int argc, const char **argv)
    CASE(bi_mkvec_v2i16_to(b, reg, bi_swz_16(bi_imm_u32(0xCAFEBABE), true, true),
          bi_swz_16(bi_imm_u32(0xCAFEBABE), false, false)), 0xBABECAFE);
 
+   {
+      bi_index u32 = bi_imm_u32(0xCAFEBABE);
+
+      bi_index a = bi_byte(u32, 0); /* 0xBE */
+      bi_index c = bi_byte(u32, 2); /* 0xFE */
+
+      CASE(bi_mkvec_v4i8_to(b, reg, a, a, a, a), 0xBEBEBEBE);
+      CASE(bi_mkvec_v4i8_to(b, reg, a, c, a, c), 0xFEBEFEBE);
+      CASE(bi_mkvec_v4i8_to(b, reg, c, a, c, a), 0xBEFEBEFE);
+      CASE(bi_mkvec_v4i8_to(b, reg, c, c, c, c), 0xFEFEFEFE);
+   }
+
+   /* Limited shifts required for texturing */
+   CASE(bi_lshift_or_i32_to(b, reg, bi_imm_u32(0xCAFE), bi_imm_u32(0xA0000), bi_imm_u8(4)), (0xCAFE << 4) | 0xA0000);
+   NEGCASE(bi_lshift_or_i32_to(b, reg, bi_imm_u32(0xCAFE), bi_not(bi_imm_u32(0xA0000)), bi_imm_u8(4)));
+   NEGCASE(bi_lshift_or_i32_to(b, reg, bi_not(bi_imm_u32(0xCAFE)), bi_imm_u32(0xA0000), bi_imm_u8(4)));
+   {
+      bi_instr *I = bi_lshift_or_i32_to(b, reg, bi_imm_u32(0xCAFE), bi_imm_u32(0xA0000), bi_imm_u8(4));
+      I->not_result = true;
+      NEGCASE(I);
+   }
+
+   /* Limited rounding needed for texturing */
+   CASE(bi_f32_to_u32_to(b, reg, bi_imm_f32(15.0), BI_ROUND_NONE), 15);
+   CASE(bi_f32_to_u32_to(b, reg, bi_imm_f32(15.9), BI_ROUND_NONE), 15);
+   CASE(bi_f32_to_u32_to(b, reg, bi_imm_f32(-20.4), BI_ROUND_NONE), 0);
+   NEGCASE(bi_f32_to_u32_to(b, reg, bi_imm_f32(-20.4), BI_ROUND_RTP));
+   NEGCASE(bi_f32_to_u32_to(b, reg, bi_imm_f32(-20.4), BI_ROUND_RTZ));
+
    /* Instructions with non-constant sources cannot be constant folded */
    NEGCASE(bi_swz_v2i16_to(b, reg, bi_temp(b->shader)));
    NEGCASE(bi_mkvec_v2i16_to(b, reg, bi_temp(b->shader), bi_temp(b->shader)));



More information about the mesa-commit mailing list