pan/bi: Constant fold MKVEC.v2i8
authorAlyssa Rosenzweig <alyssa@collabora.com>
Fri, 17 Jun 2022 15:55:23 +0000 (11:55 -0400)
committerMarge Bot <emma+marge@anholt.net>
Tue, 21 Jun 2022 22:42:34 +0000 (22:42 +0000)
Constant MKVEC.v2i8 will be generated during texturing on Valhall, just like
constant MKVEC.v4i8 is currently generated.

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

src/panfrost/bifrost/bi_opt_constant_fold.c
src/panfrost/bifrost/test/test-constant-fold.cpp

index 2679b9d..0099385 100644 (file)
@@ -58,6 +58,9 @@ bi_fold_constant(bi_instr *I, bool *unsupported)
         case BI_OPCODE_MKVEC_V4I8:
                 return (d << 24) | ((c & 0xFF) << 16) | ((b & 0xFF) << 8) | (a & 0xFF);
 
+        case BI_OPCODE_MKVEC_V2I8:
+                return (c << 16) | ((b & 0xFF) << 8) | (a & 0xFF);
+
         case BI_OPCODE_LSHIFT_OR_I32:
                 if (I->not_result || I->src[0].neg || I->src[1].neg)
                         break;
index d28fc95..90a6386 100644 (file)
@@ -152,6 +152,23 @@ TEST_F(ConstantFold, VectorConstructions4i8)
    EXPECT_FOLD(bi_mkvec_v4i8_to(b, reg, c, c, c, c), 0xFEFEFEFE);
 }
 
+TEST_F(ConstantFold, VectorConstructions2i8)
+{
+   bi_index reg = bi_register(0);
+   bi_index u32 = bi_imm_u32(0xCAFEBABE);
+   bi_index rem = bi_imm_u32(0xABCD1234);
+
+   bi_index a = bi_byte(u32, 0); /* 0xBE */
+   bi_index B = bi_byte(u32, 1); /* 0xBA */
+   bi_index c = bi_byte(u32, 2); /* 0xFE */
+   bi_index d = bi_byte(u32, 3); /* 0xCA */
+
+   EXPECT_FOLD(bi_mkvec_v2i8_to(b, reg, a, B, rem), 0x1234BABE);
+   EXPECT_FOLD(bi_mkvec_v2i8_to(b, reg, a, d, rem), 0x1234CABE);
+   EXPECT_FOLD(bi_mkvec_v2i8_to(b, reg, c, d, rem), 0x1234CAFE);
+   EXPECT_FOLD(bi_mkvec_v2i8_to(b, reg, d, d, rem), 0x1234CACA);
+}
+
 TEST_F(ConstantFold, LimitedShiftsForTexturing)
 {
    bi_index reg = bi_register(0);