Debian Codegraph @

src/panfrost/compiler/bifrost/valhall/test/test-lower-isel.cpp

raw
1 /*
2 * Copyright (C) 2021 Collabora, Ltd.
3 * SPDX-License-Identifier: MIT
4 */
5
6 #include "bi_builder.h"
7 #include "bi_test.h"
8 #include "va_compiler.h"
9
10 #include <gtest/gtest.h>
11
12 #define CASE(instr, expected) INSTRUCTION_CASE(instr, expected, va_lower_isel)
13 #define NEGCASE(instr) CASE(instr, instr)
14
15 class LowerIsel : public testing::Test {
16 protected:
17 LowerIsel()
18 {
19 mem_ctx = ralloc_context(NULL);
20 reg = bi_register(1);
21 x = bi_register(2);
22 y = bi_register(3);
23 z = bi_register(4);
24 }
25
26 ~LowerIsel()
27 {
28 ralloc_free(mem_ctx);
29 }
30
31 void *mem_ctx;
32 bi_index reg, x, y, z;
33 };
34
35 TEST_F(LowerIsel, JumpsLoweredToBranches)
36 {
37 bi_block block = {};
38
39 CASE(
40 {
41 bi_instr *I = bi_jump(b, bi_imm_u32(0xDEADBEEF));
42 I->branch_target = &block;
43 },
44 {
45 bi_instr *I =
46 bi_branchz_i16(b, bi_zero(), bi_imm_u32(0xDEADBEEF), BI_CMPF_EQ);
47 I->branch_target = &block;
48 });
49 }
50
51 TEST_F(LowerIsel, IndirectJumpsLoweredToBranches)
52 {
53 CASE(bi_jump(b, bi_register(17)),
54 bi_branchzi(b, bi_zero(), bi_register(17), BI_CMPF_EQ));
55 }
56
57 TEST_F(LowerIsel, IntegerCSEL)
58 {
59 CASE(bi_csel_i32(b, reg, reg, reg, reg, BI_CMPF_EQ),
60 bi_csel_u32(b, reg, reg, reg, reg, BI_CMPF_EQ));
61
62 CASE(bi_csel_v2i16(b, reg, reg, reg, reg, BI_CMPF_EQ),
63 bi_csel_v2u16(b, reg, reg, reg, reg, BI_CMPF_EQ));
64 }
65
66 TEST_F(LowerIsel, AvoidSimpleMux)
67 {
68 CASE(bi_mux_i32(b, x, y, z, BI_MUX_INT_ZERO),
69 bi_csel_u32(b, z, bi_zero(), x, y, BI_CMPF_EQ));
70 CASE(bi_mux_i32(b, x, y, z, BI_MUX_NEG),
71 bi_csel_s32(b, z, bi_zero(), x, y, BI_CMPF_LT));
72 CASE(bi_mux_i32(b, x, y, z, BI_MUX_FP_ZERO),
73 bi_csel_f32(b, z, bi_zero(), x, y, BI_CMPF_EQ));
74
75 CASE(bi_mux_v2i16(b, x, y, z, BI_MUX_INT_ZERO),
76 bi_csel_v2u16(b, z, bi_zero(), x, y, BI_CMPF_EQ));
77 CASE(bi_mux_v2i16(b, x, y, z, BI_MUX_NEG),
78 bi_csel_v2s16(b, z, bi_zero(), x, y, BI_CMPF_LT));
79 CASE(bi_mux_v2i16(b, x, y, z, BI_MUX_FP_ZERO),
80 bi_csel_v2f16(b, z, bi_zero(), x, y, BI_CMPF_EQ));
81 }
82
83 TEST_F(LowerIsel, BitwiseMux)
84 {
85 NEGCASE(bi_mux_i32(b, x, y, z, BI_MUX_BIT));
86 NEGCASE(bi_mux_v2i16(b, x, y, z, BI_MUX_BIT));
87 NEGCASE(bi_mux_v4i8(b, x, y, z, BI_MUX_BIT));
88 }
89
90 TEST_F(LowerIsel, MuxInt8)
91 {
92 NEGCASE(bi_mux_v4i8(b, x, y, z, BI_MUX_INT_ZERO));
93 NEGCASE(bi_mux_v4i8(b, x, y, z, BI_MUX_NEG));
94 NEGCASE(bi_mux_v4i8(b, x, y, z, BI_MUX_FP_ZERO));
95 }
96
97 TEST_F(LowerIsel, FaddRscale)
98 {
99 CASE(
100 bi_fadd_rscale_f32_to(b, reg, x, y, z, BI_SPECIAL_NONE),
101 bi_fma_rscale_f32_to(b, reg, x, bi_imm_f32(1.0), y, z, BI_SPECIAL_NONE));
102
103 CASE(bi_fadd_rscale_f32_to(b, reg, x, y, z, BI_SPECIAL_N),
104 bi_fma_rscale_f32_to(b, reg, x, bi_imm_f32(1.0), y, z, BI_SPECIAL_N));
105 }
106
107 TEST_F(LowerIsel, Smoke)
108 {
109 NEGCASE(bi_fadd_f32_to(b, reg, reg, reg));
110 NEGCASE(bi_csel_s32_to(b, reg, reg, reg, reg, reg, BI_CMPF_LT));
111 NEGCASE(bi_csel_u32_to(b, reg, reg, reg, reg, reg, BI_CMPF_LT));
112 }