1 /*
2
3 Copyright (c) 2009, 2010, 2011 STMicroelectronics
4 Written by Christophe Lyon
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 THE SOFTWARE.
23
24 */
25
26 #if defined(__cplusplus)
27 #include <cstdio>
28 #include <cstdint>
29 #else
30 #include <stdio.h>
31 #if defined(_MSC_VER)
32 #include "msstdint.h"
33 #else
34 #include <stdint.h>
35 #endif
36 #endif
37
38 #if defined(__arm__) || defined(__aarch64__)
39 #include <armdsp.h>
40 #include <dspfns.h> /* For Overflow */
41 #else
42 #include "stm-armdsp.h"
43 #include "stm-dspfns.h" /* For Overflow */
44 #endif
45
46 extern FILE* ref_file;
47
exec_dsp(void)48 void exec_dsp (void)
49 {
50 int32_t svar1, svar2, sacc, sres;
51 int32_t lo, hi;
52
53
54 fprintf(ref_file, "\n\nDSP (non-NEON) intrinsics\n");
55
56 /* qadd */
57 /* int32_t qadd(int32_t val1, int32_t val2); */
58 svar1 = 1;
59 svar2 = 2;
60 Overflow = 0;
61 sres = qadd(svar1, svar2);
62 fprintf(ref_file, "qadd(%#x, %#x) = %#x sat %d\n", svar1, svar2, sres, Overflow);
63
64 svar1 = -1;
65 svar2 = -2;
66 Overflow = 0;
67 sres = qadd(svar1, svar2);
68 fprintf(ref_file, "qadd(%#x, %#x) = %#x sat %d\n", svar1, svar2, sres, Overflow);
69
70 svar1 = -1;
71 svar2 = 2;
72 Overflow = 0;
73 sres = qadd(svar1, svar2);
74 fprintf(ref_file, "qadd(%#x, %#x) = %#x sat %d\n", svar1, svar2, sres, Overflow);
75
76 svar1 = 0x7000;
77 svar2 = 0x7000;
78 Overflow = 0;
79 sres = qadd(svar1, svar2);
80 fprintf(ref_file, "qadd(%#x, %#x) = %#x sat %d\n", svar1, svar2, sres, Overflow);
81
82 svar1 = 0x8FFF;
83 svar2 = 0x8FFF;
84 Overflow = 0;
85 sres = qadd(svar1, svar2);
86 fprintf(ref_file, "qadd(%#x, %#x) = %#x sat %d\n", svar1, svar2, sres, Overflow);
87
88 svar1 = 0x70000000;
89 svar2 = 0x70000000;
90 Overflow = 0;
91 sres = qadd(svar1, svar2);
92 fprintf(ref_file, "qadd(%#x, %#x) = %#x sat %d\n", svar1, svar2, sres, Overflow);
93
94 svar1 = 0x8FFFFFFF;
95 svar2 = 0x8FFFFFFF;
96 Overflow = 0;
97 sres = qadd(svar1, svar2);
98 fprintf(ref_file, "qadd(%#x, %#x) = %#x sat %d\n", svar1, svar2, sres, Overflow);
99
100 /* qsub */
101 /* int32_t qsub(int32_t val1, int32_t val2); */
102 svar1 = 1;
103 svar2 = 2;
104 Overflow = 0;
105 sres = qsub(svar1, svar2);
106 fprintf(ref_file, "qsub(%#x, %#x) = %#x sat %d\n", svar1, svar2, sres, Overflow);
107
108 svar1 = -1;
109 svar2 = -2;
110 Overflow = 0;
111 sres = qsub(svar1, svar2);
112 fprintf(ref_file, "qsub(%#x, %#x) = %#x sat %d\n", svar1, svar2, sres, Overflow);
113
114 svar1 = -1;
115 svar2 = 2;
116 Overflow = 0;
117 sres = qsub(svar1, svar2);
118 fprintf(ref_file, "qsub(%#x, %#x) = %#x sat %d\n", svar1, svar2, sres, Overflow);
119
120 svar1 = 0x7000;
121 svar2 = 0xFFFF9000;
122 Overflow = 0;
123 sres = qsub(svar1, svar2);
124 fprintf(ref_file, "qsub(%#x, %#x) = %#x sat %d\n", svar1, svar2, sres, Overflow);
125
126 svar1 = 0x8FFF;
127 svar2 = 0xFFFF7001;
128 Overflow = 0;
129 sres = qsub(svar1, svar2);
130 fprintf(ref_file, "qsub(%#x, %#x) = %#x sat %d\n", svar1, svar2, sres, Overflow);
131
132 svar1 = 0x70000000;
133 svar2 = 0x90000000;
134 Overflow = 0;
135 sres = qsub(svar1, svar2);
136 fprintf(ref_file, "qsub(%#x, %#x) = %#x sat %d\n", svar1, svar2, sres, Overflow);
137
138 svar1 = 0x8FFFFFFF;
139 svar2 = 0x70000001;
140 Overflow = 0;
141 sres = qsub(svar1, svar2);
142 fprintf(ref_file, "qsub(%#x, %#x) = %#x sat %d\n", svar1, svar2, sres, Overflow);
143
144 svar1 = 0;
145 svar2 = 0x80000000;
146 Overflow = 0;
147 sres = qsub(svar1, svar2);
148 fprintf(ref_file, "qsub(%#x, %#x) = %#x sat %d\n", svar1, svar2, sres, Overflow);
149
150
151 /* qdadd */
152 /* int32_t qdadd(int32_t val1, int32_t val2); */
153 svar1 = 1;
154 svar2 = 2;
155 Overflow = 0;
156 sres = qdadd(svar1, svar2);
157 fprintf(ref_file, "qdadd(%#x, %#x) = %#x sat %d\n", svar1, svar2, sres, Overflow);
158
159 svar1 = -1;
160 svar2 = -2;
161 Overflow = 0;
162 sres = qdadd(svar1, svar2);
163 fprintf(ref_file, "qdadd(%#x, %#x) = %#x sat %d\n", svar1, svar2, sres, Overflow);
164
165 svar1 = -1;
166 svar2 = 2;
167 Overflow = 0;
168 sres = qdadd(svar1, svar2);
169 fprintf(ref_file, "qdadd(%#x, %#x) = %#x sat %d\n", svar1, svar2, sres, Overflow);
170
171 svar1 = 0x7000;
172 svar2 = 0x7000;
173 Overflow = 0;
174 sres = qdadd(svar1, svar2);
175 fprintf(ref_file, "qdadd(%#x, %#x) = %#x sat %d\n", svar1, svar2, sres, Overflow);
176
177 svar1 = 0x8FFF;
178 svar2 = 0x8FFF;
179 Overflow = 0;
180 sres = qdadd(svar1, svar2);
181 fprintf(ref_file, "qdadd(%#x, %#x) = %#x sat %d\n", svar1, svar2, sres, Overflow);
182
183 svar1 = 0x70000000;
184 svar2 = 0x70000000;
185 Overflow = 0;
186 sres = qdadd(svar1, svar2);
187 fprintf(ref_file, "qdadd(%#x, %#x) = %#x sat %d\n", svar1, svar2, sres, Overflow);
188
189 svar1 = 0;
190 svar2 = 0x70000000;
191 Overflow = 0;
192 sres = qdadd(svar1, svar2);
193 fprintf(ref_file, "qdadd(%#x, %#x) = %#x sat %d\n", svar1, svar2, sres, Overflow);
194
195 svar1 = 0x8FFFFFFF;
196 svar2 = 0x8FFFFFFF;
197 Overflow = 0;
198 sres = qdadd(svar1, svar2);
199 fprintf(ref_file, "qdadd(%#x, %#x) = %#x sat %d\n", svar1, svar2, sres, Overflow);
200
201 svar1 = 0;
202 svar2 = 0x8FFFFFFF;
203 Overflow = 0;
204 sres = qdadd(svar1, svar2);
205 fprintf(ref_file, "qdadd(%#x, %#x) = %#x sat %d\n", svar1, svar2, sres, Overflow);
206
207 /* qdsub */
208 /* int32_t qdsub(int32_t val1, int32_t val2); */
209 svar1 = 1;
210 svar2 = 2;
211 Overflow = 0;
212 sres = qdsub(svar1, svar2);
213 fprintf(ref_file, "qdsub(%#x, %#x) = %#x sat %d\n", svar1, svar2, sres, Overflow);
214
215 svar1 = -1;
216 svar2 = -2;
217 Overflow = 0;
218 sres = qdsub(svar1, svar2);
219 fprintf(ref_file, "qdsub(%#x, %#x) = %#x sat %d\n", svar1, svar2, sres, Overflow);
220
221 svar1 = -1;
222 svar2 = 2;
223 Overflow = 0;
224 sres = qdsub(svar1, svar2);
225 fprintf(ref_file, "qdsub(%#x, %#x) = %#x sat %d\n", svar1, svar2, sres, Overflow);
226
227 svar1 = 0x7000;
228 svar2 = 0xFFFF9000;
229 Overflow = 0;
230 sres = qdsub(svar1, svar2);
231 fprintf(ref_file, "qdsub(%#x, %#x) = %#x sat %d\n", svar1, svar2, sres, Overflow);
232
233 svar1 = 0x8FFF;
234 svar2 = 0xFFFF7001;
235 Overflow = 0;
236 sres = qdsub(svar1, svar2);
237 fprintf(ref_file, "qdsub(%#x, %#x) = %#x sat %d\n", svar1, svar2, sres, Overflow);
238
239 svar1 = 0x70000000;
240 svar2 = 0x90000000;
241 Overflow = 0;
242 sres = qdsub(svar1, svar2);
243 fprintf(ref_file, "qdsub(%#x, %#x) = %#x sat %d\n", svar1, svar2, sres, Overflow);
244
245 svar1 = 0;
246 svar2 = 0x90000000;
247 Overflow = 0;
248 sres = qdsub(svar1, svar2);
249 fprintf(ref_file, "qdsub(%#x, %#x) = %#x sat %d\n", svar1, svar2, sres, Overflow);
250
251 svar1 = 0x8FFFFFFF;
252 svar2 = 0x70000001;
253 Overflow = 0;
254 sres = qdsub(svar1, svar2);
255 fprintf(ref_file, "qdsub(%#x, %#x) = %#x sat %d\n", svar1, svar2, sres, Overflow);
256
257 svar1 = 0;
258 svar2 = 0x70000001;
259 Overflow = 0;
260 sres = qdsub(svar1, svar2);
261 fprintf(ref_file, "qdsub(%#x, %#x) = %#x sat %d\n", svar1, svar2, sres, Overflow);
262
263
264 /* smulbb, smulbt, smultb, smultt */
265 /* int32_t smulbb(int32_t val1, int32_t val2); */
266 svar1 = 0x12345678;
267 svar2 = 0x12345678;
268 sres = smulbb(svar1, svar2);
269 fprintf(ref_file, "smulbb(%#x, %#x) = %#x\n", svar1, svar2, sres);
270 sres = smulbt(svar1, svar2);
271 fprintf(ref_file, "smulbt(%#x, %#x) = %#x\n", svar1, svar2, sres);
272 sres = smultb(svar1, svar2);
273 fprintf(ref_file, "smultb(%#x, %#x) = %#x\n", svar1, svar2, sres);
274 sres = smultt(svar1, svar2);
275 fprintf(ref_file, "smultt(%#x, %#x) = %#x\n", svar1, svar2, sres);
276
277 svar1 = 0xF123F456;
278 svar2 = 0xF123F456;
279 sres = smulbb(svar1, svar2);
280 fprintf(ref_file, "smulbb(%#x, %#x) = %#x\n", svar1, svar2, sres);
281 sres = smulbt(svar1, svar2);
282 fprintf(ref_file, "smulbt(%#x, %#x) = %#x\n", svar1, svar2, sres);
283 sres = smultb(svar1, svar2);
284 fprintf(ref_file, "smultb(%#x, %#x) = %#x\n", svar1, svar2, sres);
285 sres = smultt(svar1, svar2);
286 fprintf(ref_file, "smultt(%#x, %#x) = %#x\n", svar1, svar2, sres);
287
288
289 /* smlabb, smlabt, smlatb, smlatt */
290 /* int32_t smlabb(int32_t val1, int32_t val2, int32_t acc); */
291 sacc = 0x01020304;
292 svar1 = 0x12345678;
293 svar2 = 0x12345678;
294 sres = smlabb(svar1, svar2, sacc);
295 fprintf(ref_file, "smlabb(%#x, %#x, %#x) = %#x\n", svar1, svar2, sacc, sres);
296 sres = smlabt(svar1, svar2, sacc);
297 fprintf(ref_file, "smlabt(%#x, %#x, %#x) = %#x\n", svar1, svar2, sacc, sres);
298 sres = smlatb(svar1, svar2, sacc);
299 fprintf(ref_file, "smlatb(%#x, %#x, %#x) = %#x\n", svar1, svar2, sacc, sres);
300 sres = smlatt(svar1, svar2, sacc);
301 fprintf(ref_file, "smlatt(%#x, %#x, %#x) = %#x\n", svar1, svar2, sacc, sres);
302
303 svar1 = 0xF123F456;
304 svar2 = 0xF123F456;
305 sres = smlabb(svar1, svar2, sacc);
306 fprintf(ref_file, "smlabb(%#x, %#x, %#x) = %#x\n", svar1, svar2, sacc, sres);
307 sres = smlabt(svar1, svar2, sacc);
308 fprintf(ref_file, "smlabt(%#x, %#x, %#x) = %#x\n", svar1, svar2, sacc, sres);
309 sres = smlatb(svar1, svar2, sacc);
310 fprintf(ref_file, "smlatb(%#x, %#x, %#x) = %#x\n", svar1, svar2, sacc, sres);
311 sres = smlatt(svar1, svar2, sacc);
312 fprintf(ref_file, "smlatt(%#x, %#x, %#x) = %#x\n", svar1, svar2, sacc, sres);
313
314
315 /* smlalbb, smlalbt, smlaltb, smlaltt */
316 /* int32_t smlalbb(int32_t *lo, int32_t *hi, int32_t val1, int32_t val2); */
317 svar1 = 0x12345678;
318 svar2 = 0x12345678;
319 hi = 0x12345678;
320 lo = 0x9ABCDEF0;
321 fprintf(ref_file, "smlalbb(&%#x, &%#x, %#x, %#x) = ", lo, hi, svar1, svar2);
322 smlalbb(&lo, &hi, svar1, svar2);
323 fprintf(ref_file, "%#x%#x\n", hi, lo);
324 hi = 0x12345678;
325 lo = 0x9ABCDEF0;
326 fprintf(ref_file, "smlalbt(&%#x, &%#x, %#x, %#x) = ", lo, hi, svar1, svar2);
327 smlalbt(&lo, &hi, svar1, svar2);
328 fprintf(ref_file, "%#x%#x\n", hi, lo);
329 hi = 0x12345678;
330 lo = 0x9ABCDEF0;
331 fprintf(ref_file, "smlaltb(&%#x, &%#x, %#x, %#x) = ", lo, hi, svar1, svar2);
332 smlaltb(&lo, &hi, svar1, svar2);
333 fprintf(ref_file, "%#x%#x\n", hi, lo);
334 hi = 0x12345678;
335 lo = 0x9ABCDEF0;
336 fprintf(ref_file, "smlaltt(&%#x, &%#x, %#x, %#x) = ", lo, hi, svar1, svar2);
337 smlaltt(&lo, &hi, svar1, svar2);
338 fprintf(ref_file, "%#x%#x\n", hi, lo);
339
340 svar1 = 0xF123F456;
341 svar2 = 0xF123F456;
342 hi = 0x12345678;
343 lo = 0x9ABCDEF0;
344 fprintf(ref_file, "smlalbb(&%#x, &%#x, %#x, %#x) = ", lo, hi, svar1, svar2);
345 smlalbb(&lo, &hi, svar1, svar2);
346 fprintf(ref_file, "%#x%#x\n", hi, lo);
347 hi = 0x12345678;
348 lo = 0x9ABCDEF0;
349 fprintf(ref_file, "smlalbt(&%#x, &%#x, %#x, %#x) = ", lo, hi, svar1, svar2);
350 smlalbt(&lo, &hi, svar1, svar2);
351 fprintf(ref_file, "%#x%#x\n", hi, lo);
352 hi = 0x12345678;
353 lo = 0x9ABCDEF0;
354 fprintf(ref_file, "smlaltb(&%#x, &%#x, %#x, %#x) = ", lo, hi, svar1, svar2);
355 smlaltb(&lo, &hi, svar1, svar2);
356 fprintf(ref_file, "%#x%#x\n", hi, lo);
357 hi = 0x12345678;
358 lo = 0x9ABCDEF0;
359 fprintf(ref_file, "smlaltt(&%#x, &%#x, %#x, %#x) = ", lo, hi, svar1, svar2);
360 smlaltt(&lo, &hi, svar1, svar2);
361 fprintf(ref_file, "%#x%#x\n", hi, lo);
362
363 svar1 = 0x7FFF7FFF;
364 svar2 = 0x7FFF7FFF;
365 hi = 0x12345678;
366 lo = 0xFFFFFFFF;
367 fprintf(ref_file, "smlalbb(&%#x, &%#x, %#x, %#x) = ", lo, hi, svar1, svar2);
368 smlalbb(&lo, &hi, svar1, svar2);
369 fprintf(ref_file, "%#x%#x\n", hi, lo);
370 hi = 0x12345678;
371 lo = 0xFFFFFFFF;
372 fprintf(ref_file, "smlalbt(&%#x, &%#x, %#x, %#x) = ", lo, hi, svar1, svar2);
373 smlalbt(&lo, &hi, svar1, svar2);
374 fprintf(ref_file, "%#x%#x\n", hi, lo);
375 hi = 0x12345678;
376 lo = 0xFFFFFFFF;
377 fprintf(ref_file, "smlaltb(&%#x, &%#x, %#x, %#x) = ", lo, hi, svar1, svar2);
378 smlaltb(&lo, &hi, svar1, svar2);
379 fprintf(ref_file, "%#x%#x\n", hi, lo);
380 hi = 0x12345678;
381 lo = 0xFFFFFFFF;
382 fprintf(ref_file, "smlaltt(&%#x, &%#x, %#x, %#x) = ", lo, hi, svar1, svar2);
383 smlaltt(&lo, &hi, svar1, svar2);
384 fprintf(ref_file, "%#x%#x\n", hi, lo);
385
386
387 /* smulwb, smulwt */
388 /* int32_t smulwb(int32_t val1, int32_t val2); */
389 svar1 = 0x12345678;
390 svar2 = 0x12345678;
391 sres = smulwb(svar1, svar2);
392 fprintf(ref_file, "smulwb(%#x, %#x) = %#x\n", svar1, svar2, sres);
393 sres = smulwt(svar1, svar2);
394 fprintf(ref_file, "smulwt(%#x, %#x) = %#x\n", svar1, svar2, sres);
395
396 svar1 = 0xF123F456;
397 svar2 = 0xF123F456;
398 sres = smulwb(svar1, svar2);
399 fprintf(ref_file, "smulwb(%#x, %#x) = %#x\n", svar1, svar2, sres);
400 sres = smulwt(svar1, svar2);
401 fprintf(ref_file, "smulwt(%#x, %#x) = %#x\n", svar1, svar2, sres);
402
403
404 /* smlawb, smlawt */
405 /* int32_t smlawb(int32_t val1, int32_t val2, int32_t acc); */
406 sacc = 0x01020304;
407 svar1 = 0x12345678;
408 svar2 = 0x12345678;
409 sres = smlawb(svar1, svar2, sacc);
410 fprintf(ref_file, "smlawb(%#x, %#x, %#x) = %#x\n", svar1, svar2, sacc, sres);
411 sres = smlawt(svar1, svar2, sacc);
412 fprintf(ref_file, "smlawt(%#x, %#x, %#x) = %#x\n", svar1, svar2, sacc, sres);
413
414 svar1 = 0xF123F456;
415 svar2 = 0xF123F456;
416 sres = smlawb(svar1, svar2, sacc);
417 fprintf(ref_file, "smlawb(%#x, %#x, %#x) = %#x\n", svar1, svar2, sacc, sres);
418 sres = smlawt(svar1, svar2, sacc);
419 fprintf(ref_file, "smlawt(%#x, %#x, %#X) = %#x\n", svar1, svar2, sacc, sres);
420
421 }
422