xref: /openbmc/qemu/tests/tcg/tricore/asm/macros.h (revision c85cad81)
1 /* Helpers */
2 #define LI(reg, val)           \
3     mov.u reg, lo:val;         \
4     movh DREG_TEMP_LI, up:val; \
5     or reg, reg, DREG_TEMP_LI; \
6 
7 #define LIA(reg, val)        \
8     LI(DREG_TEMP, val)       \
9     mov.a reg, DREG_TEMP;
10 
11 /* Address definitions */
12 #define TESTDEV_ADDR 0xf0000000
13 /* Register definitions */
14 #define DREG_RS1 %d0
15 #define DREG_RS2 %d1
16 #define DREG_RS3 %d2
17 #define DREG_CALC_RESULT %d3
18 #define DREG_CALC_PSW %d4
19 #define DREG_CORRECT_PSW %d5
20 #define DREG_TEMP_LI %d10
21 #define DREG_TEMP %d11
22 #define DREG_TEST_NUM %d14
23 #define DREG_CORRECT_RESULT %d15
24 #define DREG_CORRECT_RESULT_2 %d13
25 
26 #define AREG_ADDR %a0
27 #define AREG_CORRECT_RESULT %a3
28 
29 #define DREG_DEV_ADDR %a15
30 
31 #define EREG_RS1 %e6
32 #define EREG_RS1_LO %d6
33 #define EREG_RS1_HI %d7
34 #define EREG_RS2 %e8
35 #define EREG_RS2_LO %d8
36 #define EREG_RS2_HI %d9
37 #define EREG_CALC_RESULT %e8
38 #define EREG_CALC_RESULT_HI %d9
39 #define EREG_CALC_RESULT_LO %d8
40 #define EREG_CORRECT_RESULT_LO %d0
41 #define EREG_CORRECT_RESULT_HI %d1
42 
43 /* Test case wrappers */
44 #define TEST_CASE(num, testreg, correct, code...) \
45 test_ ## num:                                     \
46     code;                                         \
47     LI(DREG_CORRECT_RESULT, correct)              \
48     mov DREG_TEST_NUM, num;                       \
49     jne testreg, DREG_CORRECT_RESULT, fail        \
50 
51 #define TEST_CASE_E(num, correct_lo, correct_hi, code...)  \
52 test_ ## num:                                              \
53     code;                                                  \
54     mov DREG_TEST_NUM, num;                                \
55     LI(EREG_CORRECT_RESULT_LO, correct_lo)                 \
56     jne EREG_CALC_RESULT_LO, EREG_CORRECT_RESULT_LO, fail; \
57     LI(EREG_CORRECT_RESULT_HI, correct_hi)                 \
58     jne EREG_CALC_RESULT_HI, EREG_CORRECT_RESULT_HI, fail;
59 
60 #define TEST_CASE_PSW(num, testreg, correct, correct_psw, code...) \
61 test_ ## num:                                                      \
62     code;                                                          \
63     LI(DREG_CORRECT_RESULT, correct)                               \
64     mov DREG_TEST_NUM, num;                                        \
65     jne testreg, DREG_CORRECT_RESULT, fail;                        \
66     mfcr DREG_CALC_PSW, $psw;                                      \
67     LI(DREG_CORRECT_PSW, correct_psw)                              \
68     mov DREG_TEST_NUM, num;                                        \
69     jne DREG_CALC_PSW, DREG_CORRECT_PSW, fail;
70 
71 #define TEST_LD(insn, num, result, addr_result, ld_pattern) \
72 test_ ## num:                                               \
73     LIA(AREG_ADDR, test_data)                               \
74     insn DREG_CALC_RESULT, ld_pattern;                      \
75     LI(DREG_CORRECT_RESULT, result)                         \
76     mov DREG_TEST_NUM, num;                                 \
77     jne DREG_CALC_RESULT, DREG_CORRECT_RESULT, fail;        \
78     mov.d DREG_CALC_RESULT, AREG_ADDR;                      \
79     LI(DREG_CORRECT_RESULT, addr_result)                    \
80     jne DREG_CALC_RESULT, DREG_CORRECT_RESULT, fail;
81 
82 #define TEST_LD_SRO(insn, num, result, addr_result, ld_pattern)  \
83 test_ ## num:                                                    \
84     LIA(AREG_ADDR, test_data)                                    \
85     insn %d15, ld_pattern;                                       \
86     LI(DREG_CORRECT_RESULT_2, result)                            \
87     mov DREG_TEST_NUM, num;                                      \
88     jne %d15, DREG_CORRECT_RESULT_2, fail;                       \
89     mov.d DREG_CALC_RESULT, AREG_ADDR;                           \
90     LI(DREG_CORRECT_RESULT, addr_result)                         \
91     jne DREG_CALC_RESULT, DREG_CORRECT_RESULT, fail;
92 
93 
94 /* Actual test case type
95  * e.g inst %dX, %dY      -> TEST_D_D
96  *     inst %dX, %dY, %dZ -> TEST_D_DD
97  *     inst %eX, %dY, %dZ -> TEST_E_DD
98  */
99 
100 
101 #define TEST_D_D(insn, num, result, rs1)      \
102     TEST_CASE(num, DREG_CALC_RESULT, result,  \
103     LI(DREG_RS1, rs1);                        \
104     insn DREG_CALC_RESULT, DREG_RS1;          \
105     )
106 
107 #define TEST_D_D_PSW(insn, num, result, psw, rs1)     \
108     TEST_CASE_PSW(num, DREG_CALC_RESULT, result, psw, \
109     LI(DREG_RS1, rs1);                                \
110     rstv;                                             \
111     insn DREG_CORRECT_RESULT, DREG_RS1;               \
112     )
113 
114 #define TEST_D_DDD(insn, num, result, rs1, rs2, rs3)        \
115     TEST_CASE(num, DREG_CALC_RESULT, result,                \
116     LI(DREG_RS1, rs1);                                      \
117     LI(DREG_RS2, rs2);                                      \
118     LI(DREG_RS3, rs3);                                      \
119     rstv;                                                   \
120     insn DREG_CALC_RESULT, DREG_RS1, DREG_RS2, DREG_RS3; \
121     )
122 
123 #define TEST_D_DD_PSW(insn, num, result, psw, rs1, rs2) \
124     TEST_CASE_PSW(num, DREG_CALC_RESULT, result, psw,   \
125     LI(DREG_RS1, rs1);                                  \
126     LI(DREG_RS2, rs2);                                  \
127     rstv;                                               \
128     insn DREG_CALC_RESULT, DREG_RS1, DREG_RS2;          \
129     )
130 
131 #define TEST_D_DDD_PSW(insn, num, result, psw, rs1, rs2, rs3) \
132     TEST_CASE_PSW(num, DREG_CALC_RESULT, result, psw,         \
133     LI(DREG_RS1, rs1);                                        \
134     LI(DREG_RS2, rs2);                                        \
135     LI(DREG_RS3, rs3);                                        \
136     rstv;                                                     \
137     insn DREG_CALC_RESULT, DREG_RS1, DREG_RS2, DREG_RS3;      \
138     )
139 
140 #define TEST_D_DDI(insn, num, result, rs1, rs2, imm) \
141     TEST_CASE(num, DREG_CALC_RESULT, result,         \
142     LI(DREG_RS1, rs1);                               \
143     LI(DREG_RS2, rs2);                               \
144     rstv;                                            \
145     insn DREG_CALC_RESULT, DREG_RS1, DREG_RS2, imm;  \
146     )
147 
148 #define TEST_D_DDI_PSW(insn, num, result, psw, rs1, rs2, imm) \
149     TEST_CASE_PSW(num, DREG_CALC_RESULT, result, psw,         \
150     LI(DREG_RS1, rs1);                                        \
151     LI(DREG_RS2, rs2);                                        \
152     rstv;                                                     \
153     insn DREG_CALC_RESULT, DREG_RS1, DREG_RS2, imm;           \
154     )
155 
156 #define TEST_D_DIDI(insn, num, result, rs1, imm1, rs2, imm2) \
157     TEST_CASE(num, DREG_CALC_RESULT, result,                 \
158     LI(DREG_RS1, rs1);                                       \
159     LI(DREG_RS2, rs1);                                       \
160     rstv;                                                    \
161     insn DREG_CALC_RESULT, DREG_RS1, imm1, DREG_RS2, imm2;   \
162     )
163 
164 #define TEST_E_ED(insn, num, res_hi, res_lo, rs1_hi, rs1_lo, rs2) \
165     TEST_CASE_E(num, res_lo, res_hi,                              \
166     LI(EREG_RS1_LO, rs1_lo);                                      \
167     LI(EREG_RS1_HI, rs1_hi);                                      \
168     LI(DREG_RS2, rs2);                                            \
169     insn EREG_CALC_RESULT, EREG_RS1, DREG_RS2;                    \
170     )
171 
172 #define TEST_E_IDI(insn, num, res_hi, res_lo, imm1, rs1, imm2) \
173     TEST_CASE_E(num, res_lo, res_hi,                           \
174     LI(DREG_RS1, rs1);                                         \
175     rstv;                                                      \
176     insn EREG_CALC_RESULT, imm1, DREG_RS1, imm2;               \
177     )
178 
179 
180 
181 /* Pass/Fail handling part */
182 #define TEST_PASSFAIL                       \
183         j pass;                             \
184 fail:                                       \
185         LI(DREG_TEMP, TESTDEV_ADDR)         \
186         mov.a DREG_DEV_ADDR, DREG_TEMP;     \
187         st.w [DREG_DEV_ADDR], DREG_TEST_NUM;\
188         debug;                              \
189         j fail;                             \
190 pass:                                       \
191         LI(DREG_TEMP, TESTDEV_ADDR)         \
192         mov.a DREG_DEV_ADDR, DREG_TEMP;     \
193         mov DREG_TEST_NUM, 0;               \
194         st.w [DREG_DEV_ADDR], DREG_TEST_NUM;\
195         debug;                              \
196         j pass;
197