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 #ifndef __arm__
39 #include "stm-arm.h"
40 #include "stm-dspfns.h" /* For Overflow */
41 #else
42 #include <dspfns.h> /* For Overflow */
43 #endif
44
45 extern FILE* ref_file;
46
exec_integer(void)47 void exec_integer (void)
48 {
49 int i;
50 uint32_t uvar, ures;
51 int32_t svar1, svar2, sres;
52
53 uint8_t clz;
54
55 fprintf(ref_file, "\n\nInteger (non-NEON) intrinsics\n");
56
57 /* __clz */
58 /* uint8_t __clz(uint32_t val); */
59 uvar = 0xFFFFFFFF;
60 for(i=0; i<=32; i++) {
61 clz = __clz(uvar);
62 fprintf(ref_file, "__clz(%#x) = %d\n", (unsigned int)uvar, clz);
63 uvar >>= 1;
64 }
65
66 /* __qadd */
67 /* int32_t __qadd(int32_t val1, int32_t val2); */
68 svar1 = 1;
69 svar2 = 2;
70 Overflow = 0;
71 sres = __qadd(svar1, svar2);
72 fprintf(ref_file, "__qadd(%#x, %#x) = %#x sat %d\n",
73 (unsigned int)svar1, (unsigned int)svar2, (unsigned int)sres, Overflow);
74
75 svar1 = -1;
76 svar2 = -2;
77 Overflow = 0;
78 sres = __qadd(svar1, svar2);
79 fprintf(ref_file, "__qadd(%#x, %#x) = %#x sat %d\n",
80 (unsigned int)svar1, (unsigned int)svar2, (unsigned int)sres, Overflow);
81
82 svar1 = -1;
83 svar2 = 2;
84 Overflow = 0;
85 sres = __qadd(svar1, svar2);
86 fprintf(ref_file, "__qadd(%#x, %#x) = %#x sat %d\n",
87 (unsigned int)svar1, (unsigned int)svar2, (unsigned int)sres, Overflow);
88
89 svar1 = 0x7000;
90 svar2 = 0x7000;
91 Overflow = 0;
92 sres = __qadd(svar1, svar2);
93 fprintf(ref_file, "__qadd(%#x, %#x) = %#x sat %d\n",
94 (unsigned int)svar1, (unsigned int)svar2, (unsigned int)sres, Overflow);
95
96 svar1 = 0x8FFF;
97 svar2 = 0x8FFF;
98 Overflow = 0;
99 sres = __qadd(svar1, svar2);
100 fprintf(ref_file, "__qadd(%#x, %#x) = %#x sat %d\n",
101 (unsigned int)svar1, (unsigned int)svar2, (unsigned int)sres, Overflow);
102
103 svar1 = 0x70000000;
104 svar2 = 0x70000000;
105 Overflow = 0;
106 sres = __qadd(svar1, svar2);
107 fprintf(ref_file, "__qadd(%#x, %#x) = %#x sat %d\n",
108 (unsigned int)svar1, (unsigned int)svar2, (unsigned int)sres, Overflow);
109
110 svar1 = 0x8FFFFFFF;
111 svar2 = 0x8FFFFFFF;
112 Overflow = 0;
113 sres = __qadd(svar1, svar2);
114 fprintf(ref_file, "__qadd(%#x, %#x) = %#x sat %d\n",
115 (unsigned int)svar1, (unsigned int)svar2, (unsigned int)sres, Overflow);
116
117 /* __qdbl */
118 /* int32_t __qdbl(int32_t val); */
119 svar1 = 1;
120 Overflow = 0;
121 sres = __qdbl(svar1);
122 fprintf(ref_file, "__qdbl(%#x) = %#x sat %d\n",
123 (unsigned int)svar1, (unsigned int)sres, Overflow);
124
125 svar1 = 0x70000000;
126 Overflow = 0;
127 sres = __qdbl(svar1);
128 fprintf(ref_file, "__qdbl(%#x) = %#x sat %d\n",
129 (unsigned int)svar1, (unsigned int)sres, Overflow);
130
131 svar1 = 0x8FFFFFFF;
132 Overflow = 0;
133 sres = __qdbl(svar1);
134 fprintf(ref_file, "__qdbl(%#x) = %#x sat %d\n",
135 (unsigned int)svar1, (unsigned int)sres, Overflow);
136
137 svar1 = 0xEFFFFFFF;
138 Overflow = 0;
139 sres = __qdbl(svar1);
140 fprintf(ref_file, "__qdbl(%#x) = %#x sat %d\n",
141 (unsigned int)svar1, (unsigned int)sres, Overflow);
142
143 /* __qsub */
144 /* int32_t __qsub(int32_t val1, int32_t val2); */
145 svar1 = 1;
146 svar2 = 2;
147 Overflow = 0;
148 sres = __qsub(svar1, svar2);
149 fprintf(ref_file, "__qsub(%#x, %#x) = %#x sat %d\n",
150 (unsigned int)svar1, (unsigned int)svar2, (unsigned int)sres, Overflow);
151
152 svar1 = -1;
153 svar2 = -2;
154 Overflow = 0;
155 sres = __qsub(svar1, svar2);
156 fprintf(ref_file, "__qsub(%#x, %#x) = %#x sat %d\n",
157 (unsigned int)svar1, (unsigned int)svar2, (unsigned int)sres, Overflow);
158
159 svar1 = -1;
160 svar2 = 2;
161 Overflow = 0;
162 sres = __qsub(svar1, svar2);
163 fprintf(ref_file, "__qsub(%#x, %#x) = %#x sat %d\n",
164 (unsigned int)svar1, (unsigned int)svar2, (unsigned int)sres, Overflow);
165
166 svar1 = 0x7000;
167 svar2 = 0xFFFF9000;
168 Overflow = 0;
169 sres = __qsub(svar1, svar2);
170 fprintf(ref_file, "__qsub(%#x, %#x) = %#x sat %d\n",
171 (unsigned int)svar1, (unsigned int)svar2, (unsigned int)sres, Overflow);
172
173 svar1 = 0x8FFF;
174 svar2 = 0xFFFF7001;
175 Overflow = 0;
176 sres = __qsub(svar1, svar2);
177 fprintf(ref_file, "__qsub(%#x, %#x) = %#x sat %d\n",
178 (unsigned int)svar1, (unsigned int)svar2, (unsigned int)sres, Overflow);
179
180 svar1 = 0x70000000;
181 svar2 = 0x90000000;
182 Overflow = 0;
183 sres = __qsub(svar1, svar2);
184 fprintf(ref_file, "__qsub(%#x, %#x) = %#x sat %d\n",
185 (unsigned int)svar1, (unsigned int)svar2, (unsigned int)sres, Overflow);
186
187 svar1 = 0x8FFFFFFF;
188 svar2 = 0x70000001;
189 Overflow = 0;
190 sres = __qsub(svar1, svar2);
191 fprintf(ref_file, "__qsub(%#x, %#x) = %#x sat %d\n",
192 (unsigned int)svar1, (unsigned int)svar2, (unsigned int)sres, Overflow);
193
194 svar1 = 0;
195 svar2 = 0x80000000;
196 Overflow = 0;
197 sres = __qsub(svar1, svar2);
198 fprintf(ref_file, "__qsub(%#x, %#x) = %#x sat %d\n",
199 (unsigned int)svar1, (unsigned int)svar2, (unsigned int)sres, Overflow);
200
201 /* __rbit */
202 /* uint32_t __rbit(uint32_t val); */
203 uvar = 0x12345678;
204 ures = __rbit(uvar);
205 fprintf(ref_file, "__rbit(%#x) = %#x\n",
206 (unsigned int)uvar, (unsigned int)ures);
207
208 /* __rev */
209 /* uint32_t __rev(uint32_t val); */
210 uvar = 0x12345678;
211 ures = __rev(uvar);
212 fprintf(ref_file, "__rev(%#x) = %#x\n",
213 (unsigned int)uvar, (unsigned int)ures);
214
215 /* __ssat */
216 /* int32_t __ssat(int32_t val, uint32_t sat); */
217 svar1 = 0x12345678;
218 Overflow = 0;
219 sres = __ssat(svar1, 30);
220 fprintf(ref_file, "__ssat(%#x, 30) = %#x sat %d\n",
221 (unsigned int)svar1, (unsigned int)sres, Overflow);
222
223 svar1 = 0x12345678;
224 Overflow = 0;
225 sres = __ssat(svar1, 19);
226 fprintf(ref_file, "__ssat(%#x, 19) = %#x sat %d\n",
227 (unsigned int)svar1, (unsigned int)sres, Overflow);
228
229 svar1 = 0x87654321;
230 Overflow = 0;
231 sres = __ssat(svar1, 29);
232 fprintf(ref_file, "__ssat(%#x, 29) = %#x sat %d\n",
233 (unsigned int)svar1, (unsigned int)sres, Overflow);
234
235 svar1 = 0x87654321;
236 Overflow = 0;
237 sres = __ssat(svar1, 12);
238 fprintf(ref_file, "__ssat(%#x, 12) = %#x sat %d\n",
239 (unsigned int)svar1, (unsigned int)sres, Overflow);
240
241 svar1 = 0x87654321;
242 Overflow = 0;
243 sres = __ssat(svar1, 32);
244 fprintf(ref_file, "__ssat(%#x, 32) = %#x sat %d\n",
245 (unsigned int)svar1, (unsigned int)sres, Overflow);
246
247 svar1 = 0x87654321;
248 Overflow = 0;
249 sres = __ssat(svar1, 1);
250 fprintf(ref_file, "__ssat(%#x, 1) = %#x sat %d\n",
251 (unsigned int)svar1, (unsigned int)sres, Overflow);
252
253 /* __usat */
254 /* int32_t __usat(uint32_t val, uint32_t sat); */
255 svar1 = 0x12345678;
256 Overflow = 0;
257 sres = __usat(svar1, 30);
258 fprintf(ref_file, "__usat(%#x, 30) = %#x sat %d\n",
259 (unsigned int)svar1, (unsigned int)sres, Overflow);
260
261 svar1 = 0x12345678;
262 Overflow = 0;
263 sres = __usat(svar1, 19);
264 fprintf(ref_file, "__usat(%#x, 19) = %#x sat %d\n",
265 (unsigned int)svar1, (unsigned int)sres, Overflow);
266
267 svar1 = 0x87654321;
268 Overflow = 0;
269 sres = __usat(svar1, 29);
270 fprintf(ref_file, "__usat(%#x, 29) = %#x sat %d\n",
271 (unsigned int)svar1, (unsigned int)sres, Overflow);
272
273 svar1 = 0x87654321;
274 Overflow = 0;
275 sres = __usat(svar1, 12);
276 fprintf(ref_file, "__usat(%#x, 12) = %#x sat %d\n",
277 (unsigned int)svar1, (unsigned int)sres, Overflow);
278
279 svar1 = 0x87654321;
280 Overflow = 0;
281 sres = __usat(svar1, 31);
282 fprintf(ref_file, "__usat(%#x, 31) = %#x sat %d\n",
283 (unsigned int)svar1, (unsigned int)sres, Overflow);
284
285 svar1 = 0x87654321;
286 Overflow = 0;
287 sres = __usat(svar1, 0);
288 fprintf(ref_file, "__usat(%#x, 0) = %#x sat %d\n",
289 (unsigned int)svar1, (unsigned int)sres, Overflow);
290 }
291