1#include "macros.inc"
2
3test_suite mac16
4
5
6
7#define ext16(v) (((v) & 0xffff) | (((v) & 0x8000) * 0x1ffffffe))
8#define mul16(a, b) ((ext16(a) * ext16(b)))
9
10.macro assert_acc_value v
11 rsr a4, ACCLO
12 movi a5, (\v) & 0xffffffff
13 assert eq, a4, a5
14 rsr a4, ACCHI
15 movi a5, (\v) >> 32
16 sext a5, a5, 7
17 assert eq, a4, a5
18.endm
19
20.macro init_reg sr, reg, val
21 .if (\sr)
22 movi a4, \val
23 wsr a4, \reg
24 .else
25 movi \reg, \val
26 .endif
27.endm
28
29.macro test_mulxx mulop, comb, s, t, a, b
30 init_reg \comb & 2, \s, \a
31 init_reg \comb & 1, \t, \b
32
33 \mulop\().ll \s, \t
34 assert_acc_value mul16(\a, \b)
35
36 \mulop\().lh \s, \t
37 assert_acc_value mul16(\a, (\b >> 16))
38
39 \mulop\().hl \s, \t
40 assert_acc_value mul16((\a >> 16), \b)
41
42 \mulop\().hh \s, \t
43 assert_acc_value mul16((\a >> 16), (\b >> 16))
44.endm
45
46test mul_aa
47 test_mulxx mul.aa, 0, a2, a3, 0xf7315a5a, 0xa5a5137f
48test_end
49
50test mul_ad
51 test_mulxx mul.ad, 1, a2, m2, 0xf7315a5a, 0xa5a5137f
52test_end
53
54test mul_da
55 test_mulxx mul.da, 2, m1, a3, 0xf7315a5a, 0xa5a5137f
56test_end
57
58test mul_dd
59 test_mulxx mul.dd, 3, m0, m3, 0xf7315a5a, 0xa5a5137f
60test_end
61
62
63.macro init_acc iv
64 movi a4, (\iv) & 0xffffffff
65 wsr a4, ACCLO
66 movi a4, (\iv) >> 32
67 wsr a4, ACCHI
68.endm
69
70.macro test_mulxxx mulop, comb, s, t, a, b, iv, op
71 init_reg \comb & 2, \s, \a
72 init_reg \comb & 1, \t, \b
73
74 init_acc \iv
75 \mulop\().ll \s, \t
76 assert_acc_value (\iv \op mul16(\a, \b))
77
78 init_acc \iv
79 \mulop\().lh \s, \t
80 assert_acc_value (\iv \op mul16(\a, (\b >> 16)))
81
82 init_acc \iv
83 \mulop\().hl \s, \t
84 assert_acc_value (\iv \op mul16((\a >> 16), \b))
85
86 init_acc \iv
87 \mulop\().hh \s, \t
88 assert_acc_value (\iv \op mul16((\a >> 16), (\b >> 16)))
89.endm
90
91
92test mula_aa
93 test_mulxxx mula.aa, 0, a2, a3, 0xf7315a5a, 0xa5a5137f, 0xfff73155aa, +
94test_end
95
96test mula_ad
97 test_mulxxx mula.ad, 1, a2, m2, 0xf7315a5a, 0xa5a5137f, 0xfff73155aa, +
98test_end
99
100test mula_da
101 test_mulxxx mula.da, 2, m1, a3, 0xf7315a5a, 0xa5a5137f, 0x0ff73155aa, +
102test_end
103
104test mula_dd
105 test_mulxxx mula.dd, 3, m0, m3, 0xf7315a5a, 0xa5a5137f, 0x0ff73155aa, +
106test_end
107
108
109test muls_aa
110 test_mulxxx muls.aa, 0, a2, a3, 0xf7315a5a, 0xa5a5137f, 0x0ff73155aa, -
111test_end
112
113test muls_ad
114 test_mulxxx muls.ad, 1, a2, m2, 0xf7315a5a, 0xa5a5137f, 0x0ff73155aa, -
115test_end
116
117test muls_da
118 test_mulxxx muls.da, 2, m1, a3, 0xf7315a5a, 0xa5a5137f, 0xfff73155aa, -
119test_end
120
121test muls_dd
122 test_mulxxx muls.dd, 3, m0, m3, 0xf7315a5a, 0xa5a5137f, 0xfff73155aa, -
123test_end
124
125test ldinc
126 movi a2, 1f - 4
127 ldinc m0, a2
128 movi a3, 1f
129 assert eq, a2, a3
130 rsr a3, m0
131 movi a4, 0x55aa137f
132 assert eq, a3, a4
133 ldinc m1, a2
134 movi a3, 1f + 4
135 assert eq, a2, a3
136 rsr a3, m1
137 movi a4, 0x12345678
138 assert eq, a3, a4
139
140.data
1411: .word 0x55aa137f, 0x12345678, 0x137fa5a5
142.text
143test_end
144
145test lddec
146 movi a2, 1f
147 lddec m2, a2
148 movi a3, 1f - 4
149 assert eq, a2, a3
150 rsr a3, m2
151 movi a4, 0x12345678
152 assert eq, a3, a4
153 lddec m3, a2
154 movi a3, 1f - 8
155 assert eq, a2, a3
156 rsr a3, m3
157 movi a4, 0x55aa137f
158 assert eq, a3, a4
159.data
160 .word 0x55aa137f, 0x12345678
1611:
162.text
163test_end
164
165
166.macro test_mulxxx_ld mulop, ldop, comb, w, x, s, t, a, b, iv, op
167 init_reg \comb & 2, \s, \a
168 init_reg \comb & 1, \t, \b
169
170 init_acc \iv
171 \mulop\().ll.\ldop \w, \x, \s, \t
172 assert_acc_value (\iv \op mul16(\a, \b))
173
174 init_acc \iv
175 \mulop\().lh.\ldop \w, \x, \s, \t
176 assert_acc_value (\iv \op mul16(\a, (\b >> 16)))
177
178 init_acc \iv
179 \mulop\().hl.\ldop \w, \x, \s, \t
180 assert_acc_value (\iv \op mul16((\a >> 16), \b))
181
182 init_acc \iv
183 \mulop\().hh.\ldop \w, \x, \s, \t
184 assert_acc_value (\iv \op mul16((\a >> 16), (\b >> 16)))
185.endm
186
187test mula_da_ldinc
188 movi a2, 1f - 4
189 test_mulxxx_ld mula.da, ldinc, 2, m1, a2, m1, a3, \
190 0xf7315a5a, 0xa5a5137f, 0x0ff73155aa, +
191 movi a3, 1f + 12
192 assert eq, a2, a3
193 rsr a2, m1
194 movi a3, 0x12345678
195 assert eq, a2, a3
196.data
1971: .word 0xf7315a5a, 0xf7315a5a, 0xf7315a5a, 0x12345678
198.text
199test_end
200
201test mula_dd_ldinc
202 movi a2, 1f - 4
203 test_mulxxx_ld mula.dd, ldinc, 3, m2, a2, m1, m2, \
204 0xf7315a5a, 0xa5a5137f, 0x0ff73155aa, +
205 movi a3, 1f + 12
206 assert eq, a2, a3
207 rsr a2, m2
208 movi a3, 0x12345678
209 assert eq, a2, a3
210.data
2111: .word 0xa5a5137f, 0xa5a5137f, 0xa5a5137f, 0x12345678
212.text
213test_end
214
215test mula_da_lddec
216 movi a2, 1f
217 test_mulxxx_ld mula.da, lddec, 2, m1, a2, m1, a3, \
218 0xf7315a5a, 0xa5a5137f, 0x0ff73155aa, +
219 movi a3, 1f - 16
220 assert eq, a2, a3
221 rsr a2, m1
222 movi a3, 0x12345678
223 assert eq, a2, a3
224.data
225 .word 0x12345678, 0xf7315a5a, 0xf7315a5a, 0xf7315a5a
2261:
227.text
228test_end
229
230test mula_dd_lddec
231 movi a2, 1f
232 test_mulxxx_ld mula.dd, lddec, 3, m2, a2, m1, m2, \
233 0xf7315a5a, 0xa5a5137f, 0x0ff73155aa, +
234 movi a3, 1f - 16
235 assert eq, a2, a3
236 rsr a2, m2
237 movi a3, 0x12345678
238 assert eq, a2, a3
239.data
240 .word 0x12345678, 0xa5a5137f, 0xa5a5137f, 0xa5a5137f
2411:
242.text
243test_end
244
245#endif
246
247test_suite_end
248