2
* Copyright (C) 2021 Collabora, Ltd.
4
* Permission is hereby granted, free of charge, to any person obtaining a
5
* copy of this software and associated documentation files (the "Software"),
6
* to deal in the Software without restriction, including without limitation
7
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
* and/or sell copies of the Software, and to permit persons to whom the
9
* Software is furnished to do so, subject to the following conditions:
11
* The above copyright notice and this permission notice (including the next
12
* paragraph) shall be included in all copies or substantial portions of the
15
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
#include "va_compiler.h"
26
#include "bi_builder.h"
28
#include <gtest/gtest.h>
31
case_cb(bi_context *ctx)
33
bi_foreach_instr_global(ctx, I) {
38
#define CASE(instr, expected) INSTRUCTION_CASE(instr, expected, case_cb)
39
#define NEGCASE(instr) CASE(instr, instr)
41
class LowerIsel : public testing::Test {
44
mem_ctx = ralloc_context(NULL);
56
TEST_F(LowerIsel, 8BitSwizzles) {
57
for (unsigned i = 0; i < 4; ++i) {
58
CASE(bi_swz_v4i8_to(b, reg, bi_byte(reg, i)),
59
bi_iadd_v4u8_to(b, reg, bi_byte(reg, i), bi_zero(), false));
63
TEST_F(LowerIsel, 16BitSwizzles) {
64
for (unsigned i = 0; i < 2; ++i) {
65
for (unsigned j = 0; j < 2; ++j) {
66
CASE(bi_swz_v2i16_to(b, reg, bi_swz_16(reg, i, j)),
67
bi_iadd_v2u16_to(b, reg, bi_swz_16(reg, i, j), bi_zero(), false));
72
TEST_F(LowerIsel, DiscardImplicitR60) {
73
CASE(bi_discard_f32(b, reg, reg, BI_CMPF_EQ), {
74
bi_instr *I = bi_discard_f32(b, reg, reg, BI_CMPF_EQ);
75
I->dest[0] = bi_register(60);
79
TEST_F(LowerIsel, JumpsLoweredToBranches) {
83
bi_instr *I = bi_jump(b, bi_imm_u32(0xDEADBEEF));
84
I->branch_target = █
86
bi_instr *I = bi_branchz_i16(b, bi_zero(), bi_imm_u32(0xDEADBEEF), BI_CMPF_EQ);
87
I->branch_target = █
91
TEST_F(LowerIsel, IndirectJumpsLoweredToBranches) {
92
CASE(bi_jump(b, bi_register(17)),
93
bi_branchzi(b, bi_zero(), bi_register(17), BI_CMPF_EQ));
96
TEST_F(LowerIsel, IntegerCSEL) {
97
CASE(bi_csel_i32(b, reg, reg, reg, reg, BI_CMPF_EQ),
98
bi_csel_u32(b, reg, reg, reg, reg, BI_CMPF_EQ));
100
CASE(bi_csel_v2i16(b, reg, reg, reg, reg, BI_CMPF_EQ),
101
bi_csel_v2u16(b, reg, reg, reg, reg, BI_CMPF_EQ));
104
TEST_F(LowerIsel, Smoke) {
105
NEGCASE(bi_fadd_f32_to(b, reg, reg, reg));
106
NEGCASE(bi_csel_s32_to(b, reg, reg, reg, reg, reg, BI_CMPF_LT));
107
NEGCASE(bi_csel_u32_to(b, reg, reg, reg, reg, reg, BI_CMPF_LT));