Debian Codegraph @

src/panfrost/compiler/bifrost/test/test-lower-swizzle.cpp

raw
1 /*
2 * Copyright (C) 2022 Collabora, Ltd.
3 * SPDX-License-Identifier: MIT
4 */
5
6 #include "bi_builder.h"
7 #include "bi_test.h"
8 #include "compiler.h"
9
10 #include <gtest/gtest.h>
11
12 #define CASE(instr, expected) \
13 INSTRUCTION_CASE(instr, expected, bi_lower_swizzle)
14 #define NEGCASE(instr) CASE(instr, instr)
15
16 class LowerSwizzle : public testing::Test {
17 protected:
18 LowerSwizzle()
19 {
20 mem_ctx = ralloc_context(NULL);
21
22 reg = bi_register(0);
23 x = bi_register(1);
24 y = bi_register(2);
25 z = bi_register(3);
26 w = bi_register(4);
27
28 x3210 = x;
29 x3210.swizzle = BI_SWIZZLE_B3210;
30 }
31
32 ~LowerSwizzle()
33 {
34 ralloc_free(mem_ctx);
35 }
36
37 void *mem_ctx;
38
39 bi_index reg, x, y, z, w;
40 bi_index x3210;
41 };
42
43 TEST_F(LowerSwizzle, Csel16)
44 {
45 CASE(bi_csel_v2f16_to(b, reg, bi_half(x, 0), y, z, w, BI_CMPF_NE),
46 bi_csel_v2f16_to(b, reg, bi_swz_v4i8(b, bi_half(x, 0)), y, z, w,
47 BI_CMPF_NE));
48 }
49
50 TEST_F(LowerSwizzle, Fma16)
51 {
52 NEGCASE(bi_fadd_v2f16_to(b, reg, bi_half(x, 0), y));
53 NEGCASE(bi_fma_v2f16_to(b, reg, bi_half(x, 0), y, z));
54 }
55
56 TEST_F(LowerSwizzle, ClzHadd8)
57 {
58 CASE(bi_clz_v4u8_to(b, reg, x3210, true),
59 bi_clz_v4u8_to(b, reg, bi_swz_v4i8(b, x3210), true));
60
61 CASE(bi_hadd_v4u8_to(b, reg, y, x3210, BI_ROUND_RTP),
62 bi_hadd_v4u8_to(b, reg, y, bi_swz_v4i8(b, x3210), BI_ROUND_RTP));
63 }
64
65 TEST_F(LowerSwizzle, FirstShift8)
66 {
67 enum bi_opcode ops[] = {
68 BI_OPCODE_LSHIFT_AND_V4I8, BI_OPCODE_LSHIFT_OR_V4I8,
69 BI_OPCODE_LSHIFT_XOR_V4I8, BI_OPCODE_RSHIFT_AND_V4I8,
70 BI_OPCODE_RSHIFT_OR_V4I8, BI_OPCODE_RSHIFT_XOR_V4I8,
71 };
72
73 for (unsigned i = 0; i < ARRAY_SIZE(ops); ++i) {
74 CASE(
75 {
76 bi_instr *I = bi_lshift_and_v4i8_to(b, reg, x3210, y, z);
77 I->op = ops[i];
78 },
79 {
80 bi_instr *I =
81 bi_lshift_and_v4i8_to(b, reg, bi_swz_v4i8(b, x3210), y, z);
82 I->op = ops[i];
83 });
84 }
85 }
86
87 TEST_F(LowerSwizzle, ShiftWithNot)
88 {
89 CASE(bi_lshift_and_v4i8_to(b, reg, y, bi_neg(x3210), z),
90 bi_lshift_and_v4i8_to(b, reg, y, bi_neg(bi_swz_v4i8(b, x3210)), z));
91 }
92
93 TEST_F(LowerSwizzle, FClampSwap)
94 {
95 CASE(bi_fclamp_v2f16_to(b, reg, bi_swz_16(x, 1, 0)),
96 bi_swz_v2i16_to(b, reg, bi_swz_16(bi_fclamp_v2f16(b, x), 1, 0)));
97 }