xref: /openbmc/qemu/tests/tcg/tricore/asm/macros.h (revision 13b5ae94)
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 %d2
16 #define DREG_RS3 %d4
17 #define DREG_CALC_RESULT %d5
18 #define DREG_CALC_PSW %d6
19 #define DREG_CORRECT_PSW %d7
20 #define DREG_TEMP_LI %d13
21 #define DREG_TEMP %d14
22 #define DREG_TEST_NUM %d8
23 #define DREG_CORRECT_RESULT %d9
24 #define DREG_CORRECT_RESULT_2 %d10
25 
26 #define AREG_ADDR %a0
27 #define AREG_CORRECT_RESULT %a3
28 
29 #define DREG_DEV_ADDR %a15
30 
31 #define EREG_RS1 %e0
32 #define EREG_RS1_LO %d0
33 #define EREG_RS1_HI %d1
34 #define EREG_RS2 %e2
35 #define EREG_RS2_LO %d2
36 #define EREG_RS2_HI %d3
37 #define EREG_CALC_RESULT %e6
38 #define EREG_CALC_RESULT_LO %d6
39 #define EREG_CALC_RESULT_HI %d7
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     mov testreg, 0
51 
52 #define TEST_CASE_E(num, correct_lo, correct_hi, code...)  \
53 test_ ## num:                                              \
54     code;                                                  \
55     mov DREG_TEST_NUM, num;                                \
56     LI(EREG_CORRECT_RESULT_LO, correct_lo)                 \
57     jne EREG_CALC_RESULT_LO, EREG_CORRECT_RESULT_LO, fail; \
58     LI(EREG_CORRECT_RESULT_HI, correct_hi)                 \
59     jne EREG_CALC_RESULT_HI, EREG_CORRECT_RESULT_HI, fail;
60 
61 #define TEST_CASE_PSW(num, testreg, correct, correct_psw, code...) \
62 test_ ## num:                                                      \
63     code;                                                          \
64     LI(DREG_CORRECT_RESULT, correct)                               \
65     mov DREG_TEST_NUM, num;                                        \
66     jne testreg, DREG_CORRECT_RESULT, fail;                        \
67     mfcr DREG_CALC_PSW, $psw;                                      \
68     LI(DREG_CORRECT_PSW, correct_psw)                              \
69     mov DREG_TEST_NUM, num;                                        \
70     jne DREG_CALC_PSW, DREG_CORRECT_PSW, fail;
71 
72 #define TEST_LD(insn, num, result, addr_result, ld_pattern) \
73 test_ ## num:                                               \
74     LIA(AREG_ADDR, test_data)                               \
75     insn DREG_CALC_RESULT, ld_pattern;                      \
76     LI(DREG_CORRECT_RESULT, result)                         \
77     mov DREG_TEST_NUM, num;                                 \
78     jne DREG_CALC_RESULT, DREG_CORRECT_RESULT, fail;        \
79     mov.d DREG_CALC_RESULT, AREG_ADDR;                      \
80     LI(DREG_CORRECT_RESULT, addr_result)                    \
81     jne DREG_CALC_RESULT, DREG_CORRECT_RESULT, fail;
82 
83 #define TEST_LD_SRO(insn, num, result, addr_result, ld_pattern)  \
84 test_ ## num:                                                    \
85     LIA(AREG_ADDR, test_data)                                    \
86     insn %d15, ld_pattern;                                       \
87     LI(DREG_CORRECT_RESULT_2, result)                            \
88     mov DREG_TEST_NUM, num;                                      \
89     jne %d15, DREG_CORRECT_RESULT_2, fail;                       \
90     mov.d DREG_CALC_RESULT, AREG_ADDR;                           \
91     LI(DREG_CORRECT_RESULT, addr_result)                         \
92     jne DREG_CALC_RESULT, DREG_CORRECT_RESULT, fail;
93 
94 
95 /* Actual test case type
96  * e.g inst %dX, %dY      -> TEST_D_D
97  *     inst %dX, %dY, %dZ -> TEST_D_DD
98  *     inst %eX, %dY, %dZ -> TEST_E_DD
99  */
100 
101 
102 #define TEST_D_D(insn, num, result, rs1)      \
103     TEST_CASE(num, DREG_CALC_RESULT, result,  \
104     LI(DREG_RS1, rs1);                        \
105     insn DREG_CALC_RESULT, DREG_RS1;          \
106     )
107 
108 #define TEST_D_D_PSW(insn, num, result, psw, rs1)     \
109     TEST_CASE_PSW(num, DREG_CALC_RESULT, result, psw, \
110     LI(DREG_RS1, rs1);                                \
111     rstv;                                             \
112     insn DREG_CORRECT_RESULT, DREG_RS1;               \
113     )
114 
115 #define TEST_D_DDD(insn, num, result, rs1, rs2, rs3)        \
116     TEST_CASE(num, DREG_CALC_RESULT, result,                \
117     LI(DREG_RS1, rs1);                                      \
118     LI(DREG_RS2, rs2);                                      \
119     LI(DREG_RS3, rs3);                                      \
120     rstv;                                                   \
121     insn DREG_CALC_RESULT, DREG_RS1, DREG_RS2, DREG_RS3; \
122     )
123 
124 #define TEST_D_DD_PSW(insn, num, result, psw, rs1, rs2) \
125     TEST_CASE_PSW(num, DREG_CALC_RESULT, result, psw,   \
126     LI(DREG_RS1, rs1);                                  \
127     LI(DREG_RS2, rs2);                                  \
128     rstv;                                               \
129     insn DREG_CALC_RESULT, DREG_RS1, DREG_RS2;          \
130     )
131 
132 #define TEST_D_DDD_PSW(insn, num, result, psw, rs1, rs2, rs3) \
133     TEST_CASE_PSW(num, DREG_CALC_RESULT, result, psw,         \
134     LI(DREG_RS1, rs1);                                        \
135     LI(DREG_RS2, rs2);                                        \
136     LI(DREG_RS3, rs3);                                        \
137     rstv;                                                     \
138     insn DREG_CALC_RESULT, DREG_RS1, DREG_RS2, DREG_RS3;      \
139     )
140 
141 #define TEST_D_DDI(insn, num, result, rs1, rs2, imm) \
142     TEST_CASE(num, DREG_CALC_RESULT, result,         \
143     LI(DREG_RS1, rs1);                               \
144     LI(DREG_RS2, rs2);                               \
145     rstv;                                            \
146     insn DREG_CALC_RESULT, DREG_RS1, DREG_RS2, imm;  \
147     )
148 
149 #define TEST_D_DDI_PSW(insn, num, result, psw, rs1, rs2, imm) \
150     TEST_CASE_PSW(num, DREG_CALC_RESULT, result, psw,         \
151     LI(DREG_RS1, rs1);                                        \
152     LI(DREG_RS2, rs2);                                        \
153     rstv;                                                     \
154     insn DREG_CALC_RESULT, DREG_RS1, DREG_RS2, imm;           \
155     )
156 
157 #define TEST_D_DIDI(insn, num, result, rs1, imm1, rs2, imm2) \
158     TEST_CASE(num, DREG_CALC_RESULT, result,                 \
159     LI(DREG_RS1, rs1);                                       \
160     LI(DREG_RS2, rs1);                                       \
161     rstv;                                                    \
162     insn DREG_CALC_RESULT, DREG_RS1, imm1, DREG_RS2, imm2;   \
163     )
164 
165 #define TEST_D_DDII(insn, num, result, rs1, rs2, imm1, imm2) \
166     TEST_CASE(num, DREG_CALC_RESULT, result,                 \
167     LI(DREG_RS1, rs1);                                       \
168     LI(DREG_RS2, rs2);                                       \
169     rstv;                                                    \
170     insn DREG_CALC_RESULT, DREG_RS1, DREG_RS2, imm1, imm2;   \
171     )
172 
173 #define TEST_D_DIE(insn, num, result, rs1, imm1, rs2_lo, rs2_hi)\
174     TEST_CASE(num, DREG_CALC_RESULT, result,                    \
175     LI(DREG_RS1, rs1);                                          \
176     LI(EREG_RS2_LO, rs2_lo);                                    \
177     LI(EREG_RS2_HI, rs2_hi);                                    \
178     rstv;                                                       \
179     insn DREG_CALC_RESULT, DREG_RS1, imm1, EREG_RS2;            \
180     )
181 
182 #define TEST_D_DIII(insn, num, result, rs1, imm1, imm2, imm3)\
183     TEST_CASE(num, DREG_CALC_RESULT, result,                 \
184     LI(DREG_RS1, rs1);                                       \
185     rstv;                                                    \
186     insn DREG_CALC_RESULT, DREG_RS1, imm1, imm2, imm3;       \
187     )
188 
189 #define TEST_E_ED(insn, num, res_hi, res_lo, rs1_hi, rs1_lo, rs2) \
190     TEST_CASE_E(num, res_lo, res_hi,                              \
191     LI(EREG_RS1_LO, rs1_lo);                                      \
192     LI(EREG_RS1_HI, rs1_hi);                                      \
193     LI(DREG_RS2, rs2);                                            \
194     insn EREG_CALC_RESULT, EREG_RS1, DREG_RS2;                    \
195     )
196 
197 #define TEST_E_IDI(insn, num, res_hi, res_lo, imm1, rs1, imm2) \
198     TEST_CASE_E(num, res_lo, res_hi,                           \
199     LI(DREG_RS1, rs1);                                         \
200     rstv;                                                      \
201     insn EREG_CALC_RESULT, imm1, DREG_RS1, imm2;               \
202     )
203 
204 
205 
206 /* Pass/Fail handling part */
207 #define TEST_PASSFAIL                       \
208         j pass;                             \
209 fail:                                       \
210         LI(DREG_TEMP, TESTDEV_ADDR)         \
211         mov.a DREG_DEV_ADDR, DREG_TEMP;     \
212         st.w [DREG_DEV_ADDR], DREG_TEST_NUM;\
213         debug;                              \
214         j fail;                             \
215 pass:                                       \
216         LI(DREG_TEMP, TESTDEV_ADDR)         \
217         mov.a DREG_DEV_ADDR, DREG_TEMP;     \
218         mov DREG_TEST_NUM, 0;               \
219         st.w [DREG_DEV_ADDR], DREG_TEST_NUM;\
220         debug;                              \
221         j pass;
222