From 377bf3a5a4c35246385c762b0a8c88966ca3ac61 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Fri, 24 Jun 2022 09:07:42 -0400 Subject: [PATCH] pan/bi: Lower swizzles for 8-bit shifts Fixes integers_ops.integer_ctz Signed-off-by: Alyssa Rosenzweig Part-of: --- src/panfrost/bifrost/bi_lower_swizzle.c | 41 ++++++++++++------- .../bifrost/test/test-lower-swizzle.cpp | 23 +++++++++++ 2 files changed, 50 insertions(+), 14 deletions(-) diff --git a/src/panfrost/bifrost/bi_lower_swizzle.c b/src/panfrost/bifrost/bi_lower_swizzle.c index d5b096a58ed..53ea4ff357a 100644 --- a/src/panfrost/bifrost/bi_lower_swizzle.c +++ b/src/panfrost/bifrost/bi_lower_swizzle.c @@ -30,6 +30,20 @@ * recombine swizzles where we can as an optimization. */ +static bool +bi_swizzle_replicates_8(enum bi_swizzle swz) +{ + switch (swz) { + case BI_SWIZZLE_B0000: + case BI_SWIZZLE_B1111: + case BI_SWIZZLE_B2222: + case BI_SWIZZLE_B3333: + return true; + default: + return false; + } +} + static void lower_swizzle(bi_context *ctx, bi_instr *ins, unsigned src) { @@ -99,6 +113,19 @@ lower_swizzle(bi_context *ctx, bi_instr *ins, unsigned src) case BI_OPCODE_IADD_IMM_V4I8: break; + case BI_OPCODE_LSHIFT_AND_V4I8: + case BI_OPCODE_LSHIFT_OR_V4I8: + case BI_OPCODE_LSHIFT_XOR_V4I8: + case BI_OPCODE_RSHIFT_AND_V4I8: + case BI_OPCODE_RSHIFT_OR_V4I8: + case BI_OPCODE_RSHIFT_XOR_V4I8: + /* Last source allows identity or replication */ + if (src == 2 && bi_swizzle_replicates_8(ins->src[src].swizzle)) + return; + + /* Others do not allow swizzles */ + break; + /* We don't want to deal with reswizzling logic in modifier prop. Move * the swizzle outside, it's easier for clamp propagation. */ case BI_OPCODE_FCLAMP_V2F16: @@ -149,20 +176,6 @@ lower_swizzle(bi_context *ctx, bi_instr *ins, unsigned src) ins->src[src].swizzle = BI_SWIZZLE_H01; } -static bool -bi_swizzle_replicates_8(enum bi_swizzle swz) -{ - switch (swz) { - case BI_SWIZZLE_B0000: - case BI_SWIZZLE_B1111: - case BI_SWIZZLE_B2222: - case BI_SWIZZLE_B3333: - return true; - default: - return false; - } -} - static bool bi_swizzle_replicates_16(enum bi_swizzle swz) { diff --git a/src/panfrost/bifrost/test/test-lower-swizzle.cpp b/src/panfrost/bifrost/test/test-lower-swizzle.cpp index d8abd77358e..18473fc7bb0 100644 --- a/src/panfrost/bifrost/test/test-lower-swizzle.cpp +++ b/src/panfrost/bifrost/test/test-lower-swizzle.cpp @@ -75,3 +75,26 @@ TEST_F(LowerSwizzle, ClzHadd8) CASE(bi_hadd_v4u8_to(b, reg, y, x3210, BI_ROUND_RTP), bi_hadd_v4u8_to(b, reg, y, bi_swz_v4i8(b, x3210), BI_ROUND_RTP)); } + +TEST_F(LowerSwizzle, FirstShift8) +{ + enum bi_opcode ops[] = { + BI_OPCODE_LSHIFT_AND_V4I8, + BI_OPCODE_LSHIFT_OR_V4I8, + BI_OPCODE_LSHIFT_XOR_V4I8, + BI_OPCODE_RSHIFT_AND_V4I8, + BI_OPCODE_RSHIFT_OR_V4I8, + BI_OPCODE_RSHIFT_XOR_V4I8, + }; + + for (unsigned i = 0; i < ARRAY_SIZE(ops); ++i) { + CASE({ + bi_instr *I = bi_lshift_and_v4i8_to(b, reg, x3210, y, z); + I->op = ops[i]; + }, + { + bi_instr *I = bi_lshift_and_v4i8_to(b, reg, bi_swz_v4i8(b, x3210), y, z); + I->op = ops[i]; + }); + } +}