xref: /aosp_15_r20/external/mesa3d/src/asahi/compiler/test/test-compact-constants.cpp (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright 2021 Collabora, Ltd.
3  * SPDX-License-Identifier: MIT
4  */
5 
6 #include "agx_builder.h"
7 #include "agx_compiler.h"
8 #include "agx_test.h"
9 
10 #include <gtest/gtest.h>
11 
12 #define CASE(instr, expected, size)                                            \
13    INSTRUCTION_CASE(                                                           \
14       {                                                                        \
15          UNUSED agx_index out = agx_temp(b->shader, AGX_SIZE_##size);          \
16          instr;                                                                \
17          agx_unit_test(b, out);                                                \
18       },                                                                       \
19       {                                                                        \
20          UNUSED agx_index out = agx_temp(b->shader, AGX_SIZE_##size);          \
21          expected;                                                             \
22          agx_unit_test(b, out);                                                \
23       },                                                                       \
24       agx_opt_compact_constants)
25 
26 #define NEGCASE(instr, size)    CASE(instr, instr, size)
27 #define CASE32(instr, expected) CASE(instr, expected, 32)
28 #define NEGCASE32(instr)        NEGCASE(instr, 32)
29 
30 class CompactConstants : public testing::Test {
31  protected:
CompactConstants()32    CompactConstants()
33    {
34       mem_ctx = ralloc_context(NULL);
35 
36       wx = agx_register(0, AGX_SIZE_32);
37    }
38 
~CompactConstants()39    ~CompactConstants()
40    {
41       ralloc_free(mem_ctx);
42    }
43 
44    void *mem_ctx;
45    agx_index wx;
46 };
47 
TEST_F(CompactConstants,FP32)48 TEST_F(CompactConstants, FP32)
49 {
50    CASE32(agx_fadd_to(b, out, wx, agx_mov_imm(b, 32, fui(32768.0))),
51           agx_fadd_to(b, out, wx, agx_mov_imm(b, 16, 0x7800)));
52 }
53 
TEST_F(CompactConstants,InexactFP32)54 TEST_F(CompactConstants, InexactFP32)
55 {
56    NEGCASE32(agx_fadd_to(b, out, wx, agx_mov_imm(b, 32, fui(32769.0))));
57 }
58