| 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, 8BitSwizzles) |
| 36 |
{ |
| 37 |
for (unsigned i = 0; i < 4; ++i) { |
| 38 |
CASE(bi_swz_v4i8_to(b, reg, bi_byte(reg, i)), |
| 39 |
bi_iadd_v4u8_to(b, reg, bi_byte(reg, i), bi_zero(), false)); |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
TEST_F(LowerIsel, 16BitSwizzles) |
| 44 |
{ |
| 45 |
for (unsigned i = 0; i < 2; ++i) { |
| 46 |
for (unsigned j = 0; j < 2; ++j) { |
| 47 |
CASE(bi_swz_v2i16_to(b, reg, bi_swz_16(reg, i, j)), |
| 48 |
bi_iadd_v2u16_to(b, reg, bi_swz_16(reg, i, j), bi_zero(), false)); |
| 49 |
} |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
TEST_F(LowerIsel, JumpsLoweredToBranches) |
| 54 |
{ |
| 55 |
bi_block block = {}; |
| 56 |
|
| 57 |
CASE( |
| 58 |
{ |
| 59 |
bi_instr *I = bi_jump(b, bi_imm_u32(0xDEADBEEF)); |
| 60 |
I->branch_target = █ |
| 61 |
}, |
| 62 |
{ |
| 63 |
bi_instr *I = |
| 64 |
bi_branchz_i16(b, bi_zero(), bi_imm_u32(0xDEADBEEF), BI_CMPF_EQ); |
| 65 |
I->branch_target = █ |
| 66 |
}); |
| 67 |
} |
| 68 |
|
| 69 |
TEST_F(LowerIsel, IndirectJumpsLoweredToBranches) |
| 70 |
{ |
| 71 |
CASE(bi_jump(b, bi_register(17)), |
| 72 |
bi_branchzi(b, bi_zero(), bi_register(17), BI_CMPF_EQ)); |
| 73 |
} |
| 74 |
|
| 75 |
TEST_F(LowerIsel, IntegerCSEL) |
| 76 |
{ |
| 77 |
CASE(bi_csel_i32(b, reg, reg, reg, reg, BI_CMPF_EQ), |
| 78 |
bi_csel_u32(b, reg, reg, reg, reg, BI_CMPF_EQ)); |
| 79 |
|
| 80 |
CASE(bi_csel_v2i16(b, reg, reg, reg, reg, BI_CMPF_EQ), |
| 81 |
bi_csel_v2u16(b, reg, reg, reg, reg, BI_CMPF_EQ)); |
| 82 |
} |
| 83 |
|
| 84 |
TEST_F(LowerIsel, AvoidSimpleMux) |
| 85 |
{ |
| 86 |
CASE(bi_mux_i32(b, x, y, z, BI_MUX_INT_ZERO), |
| 87 |
bi_csel_u32(b, z, bi_zero(), x, y, BI_CMPF_EQ)); |
| 88 |
CASE(bi_mux_i32(b, x, y, z, BI_MUX_NEG), |
| 89 |
bi_csel_s32(b, z, bi_zero(), x, y, BI_CMPF_LT)); |
| 90 |
CASE(bi_mux_i32(b, x, y, z, BI_MUX_FP_ZERO), |
| 91 |
bi_csel_f32(b, z, bi_zero(), x, y, BI_CMPF_EQ)); |
| 92 |
|
| 93 |
CASE(bi_mux_v2i16(b, x, y, z, BI_MUX_INT_ZERO), |
| 94 |
bi_csel_v2u16(b, z, bi_zero(), x, y, BI_CMPF_EQ)); |
| 95 |
CASE(bi_mux_v2i16(b, x, y, z, BI_MUX_NEG), |
| 96 |
bi_csel_v2s16(b, z, bi_zero(), x, y, BI_CMPF_LT)); |
| 97 |
CASE(bi_mux_v2i16(b, x, y, z, BI_MUX_FP_ZERO), |
| 98 |
bi_csel_v2f16(b, z, bi_zero(), x, y, BI_CMPF_EQ)); |
| 99 |
} |
| 100 |
|
| 101 |
TEST_F(LowerIsel, BitwiseMux) |
| 102 |
{ |
| 103 |
NEGCASE(bi_mux_i32(b, x, y, z, BI_MUX_BIT)); |
| 104 |
NEGCASE(bi_mux_v2i16(b, x, y, z, BI_MUX_BIT)); |
| 105 |
NEGCASE(bi_mux_v4i8(b, x, y, z, BI_MUX_BIT)); |
| 106 |
} |
| 107 |
|
| 108 |
TEST_F(LowerIsel, MuxInt8) |
| 109 |
{ |
| 110 |
NEGCASE(bi_mux_v4i8(b, x, y, z, BI_MUX_INT_ZERO)); |
| 111 |
NEGCASE(bi_mux_v4i8(b, x, y, z, BI_MUX_NEG)); |
| 112 |
NEGCASE(bi_mux_v4i8(b, x, y, z, BI_MUX_FP_ZERO)); |
| 113 |
} |
| 114 |
|
| 115 |
TEST_F(LowerIsel, FaddRscale) |
| 116 |
{ |
| 117 |
CASE( |
| 118 |
bi_fadd_rscale_f32_to(b, reg, x, y, z, BI_SPECIAL_NONE), |
| 119 |
bi_fma_rscale_f32_to(b, reg, x, bi_imm_f32(1.0), y, z, BI_SPECIAL_NONE)); |
| 120 |
|
| 121 |
CASE(bi_fadd_rscale_f32_to(b, reg, x, y, z, BI_SPECIAL_N), |
| 122 |
bi_fma_rscale_f32_to(b, reg, x, bi_imm_f32(1.0), y, z, BI_SPECIAL_N)); |
| 123 |
} |
| 124 |
|
| 125 |
TEST_F(LowerIsel, Smoke) |
| 126 |
{ |
| 127 |
NEGCASE(bi_fadd_f32_to(b, reg, reg, reg)); |
| 128 |
NEGCASE(bi_csel_s32_to(b, reg, reg, reg, reg, reg, BI_CMPF_LT)); |
| 129 |
NEGCASE(bi_csel_u32_to(b, reg, reg, reg, reg, reg, BI_CMPF_LT)); |
| 130 |
} |