VirtualBox

source: vbox/trunk/src/libs/softfloat-3e/testfloat/source/genCases_i32.c@ 106842

Last change on this file since 106842 was 94551, checked in by vboxsync, 3 years ago

libs/softfloat: Copied TestFloat-3e from vendor branch and to testfloat subdir. bugref:9898

  • Property svn:eol-style set to native
File size: 7.7 KB
Line 
1
2/*============================================================================
3
4This C source file is part of TestFloat, Release 3e, a package of programs for
5testing the correctness of floating-point arithmetic complying with the IEEE
6Standard for Floating-Point, by John R. Hauser.
7
8Copyright 2011, 2012, 2013, 2014 The Regents of the University of California.
9All rights reserved.
10
11Redistribution and use in source and binary forms, with or without
12modification, are permitted provided that the following conditions are met:
13
14 1. Redistributions of source code must retain the above copyright notice,
15 this list of conditions, and the following disclaimer.
16
17 2. Redistributions in binary form must reproduce the above copyright notice,
18 this list of conditions, and the following disclaimer in the documentation
19 and/or other materials provided with the distribution.
20
21 3. Neither the name of the University nor the names of its contributors may
22 be used to endorse or promote products derived from this software without
23 specific prior written permission.
24
25THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
26EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
27WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
28DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
29DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
32ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35
36=============================================================================*/
37
38#include <stdbool.h>
39#include <stdint.h>
40#include "platform.h"
41#include "random.h"
42#include "genCases.h"
43
44struct sequence {
45 int term1Num, term2Num;
46 bool done;
47};
48
49union ui32_i32 { uint32_t ui; int32_t i; };
50
51enum { i32NumP1 = 124 };
52static const uint32_t i32P1[i32NumP1] = {
53 0x00000000,
54 0x00000001,
55 0x00000002,
56 0x00000004,
57 0x00000008,
58 0x00000010,
59 0x00000020,
60 0x00000040,
61 0x00000080,
62 0x00000100,
63 0x00000200,
64 0x00000400,
65 0x00000800,
66 0x00001000,
67 0x00002000,
68 0x00004000,
69 0x00008000,
70 0x00010000,
71 0x00020000,
72 0x00040000,
73 0x00080000,
74 0x00100000,
75 0x00200000,
76 0x00400000,
77 0x00800000,
78 0x01000000,
79 0x02000000,
80 0x04000000,
81 0x08000000,
82 0x10000000,
83 0x20000000,
84 0x40000000,
85 0x80000000,
86 0xC0000000,
87 0xE0000000,
88 0xF0000000,
89 0xF8000000,
90 0xFC000000,
91 0xFE000000,
92 0xFF000000,
93 0xFF800000,
94 0xFFC00000,
95 0xFFE00000,
96 0xFFF00000,
97 0xFFF80000,
98 0xFFFC0000,
99 0xFFFE0000,
100 0xFFFF0000,
101 0xFFFF8000,
102 0xFFFFC000,
103 0xFFFFE000,
104 0xFFFFF000,
105 0xFFFFF800,
106 0xFFFFFC00,
107 0xFFFFFE00,
108 0xFFFFFF00,
109 0xFFFFFF80,
110 0xFFFFFFC0,
111 0xFFFFFFE0,
112 0xFFFFFFF0,
113 0xFFFFFFF8,
114 0xFFFFFFFC,
115 0xFFFFFFFE,
116 0xFFFFFFFF,
117 0xFFFFFFFD,
118 0xFFFFFFFB,
119 0xFFFFFFF7,
120 0xFFFFFFEF,
121 0xFFFFFFDF,
122 0xFFFFFFBF,
123 0xFFFFFF7F,
124 0xFFFFFEFF,
125 0xFFFFFDFF,
126 0xFFFFFBFF,
127 0xFFFFF7FF,
128 0xFFFFEFFF,
129 0xFFFFDFFF,
130 0xFFFFBFFF,
131 0xFFFF7FFF,
132 0xFFFEFFFF,
133 0xFFFDFFFF,
134 0xFFFBFFFF,
135 0xFFF7FFFF,
136 0xFFEFFFFF,
137 0xFFDFFFFF,
138 0xFFBFFFFF,
139 0xFF7FFFFF,
140 0xFEFFFFFF,
141 0xFDFFFFFF,
142 0xFBFFFFFF,
143 0xF7FFFFFF,
144 0xEFFFFFFF,
145 0xDFFFFFFF,
146 0xBFFFFFFF,
147 0x7FFFFFFF,
148 0x3FFFFFFF,
149 0x1FFFFFFF,
150 0x0FFFFFFF,
151 0x07FFFFFF,
152 0x03FFFFFF,
153 0x01FFFFFF,
154 0x00FFFFFF,
155 0x007FFFFF,
156 0x003FFFFF,
157 0x001FFFFF,
158 0x000FFFFF,
159 0x0007FFFF,
160 0x0003FFFF,
161 0x0001FFFF,
162 0x0000FFFF,
163 0x00007FFF,
164 0x00003FFF,
165 0x00001FFF,
166 0x00000FFF,
167 0x000007FF,
168 0x000003FF,
169 0x000001FF,
170 0x000000FF,
171 0x0000007F,
172 0x0000003F,
173 0x0000001F,
174 0x0000000F,
175 0x00000007,
176 0x00000003
177};
178
179static int32_t i32NextP1( struct sequence *sequencePtr )
180{
181 int termNum;
182 union ui32_i32 uZ;
183
184 termNum = sequencePtr->term1Num;
185 uZ.ui = i32P1[termNum];
186 ++termNum;
187 if ( i32NumP1 <= termNum ) {
188 termNum = 0;
189 sequencePtr->done = true;
190 }
191 sequencePtr->term1Num = termNum;
192 return uZ.i;
193
194}
195
196static const int_fast32_t i32NumP2 = (i32NumP1 * i32NumP1 + i32NumP1) / 2;
197
198static int32_t i32NextP2( struct sequence *sequencePtr )
199{
200 int term1Num, term2Num;
201 union ui32_i32 uZ;
202
203 term2Num = sequencePtr->term2Num;
204 term1Num = sequencePtr->term1Num;
205 uZ.ui = i32P1[term1Num] + i32P1[term2Num];
206 ++term2Num;
207 if ( i32NumP1 <= term2Num ) {
208 ++term1Num;
209 if ( i32NumP1 <= term1Num ) {
210 term1Num = 0;
211 sequencePtr->done = true;
212 }
213 term2Num = term1Num;
214 sequencePtr->term1Num = term1Num;
215 }
216 sequencePtr->term2Num = term2Num;
217 return uZ.i;
218
219}
220
221static int32_t i32RandomP3( void )
222{
223 union ui32_i32 uZ;
224
225 uZ.ui =
226 i32P1[randomN_ui8( i32NumP1 )] + i32P1[randomN_ui8( i32NumP1 )]
227 + i32P1[randomN_ui8( i32NumP1 )];
228 return uZ.i;
229
230}
231
232enum { i32NumPInfWeightMasks = 29 };
233static const uint32_t i32PInfWeightMasks[i32NumPInfWeightMasks] = {
234 0xFFFFFFFF,
235 0x7FFFFFFF,
236 0x3FFFFFFF,
237 0x1FFFFFFF,
238 0x0FFFFFFF,
239 0x07FFFFFF,
240 0x03FFFFFF,
241 0x01FFFFFF,
242 0x00FFFFFF,
243 0x007FFFFF,
244 0x003FFFFF,
245 0x001FFFFF,
246 0x000FFFFF,
247 0x0007FFFF,
248 0x0003FFFF,
249 0x0001FFFF,
250 0x0000FFFF,
251 0x00007FFF,
252 0x00003FFF,
253 0x00001FFF,
254 0x00000FFF,
255 0x000007FF,
256 0x000003FF,
257 0x000001FF,
258 0x000000FF,
259 0x0000007F,
260 0x0000003F,
261 0x0000001F,
262 0x0000000F
263};
264static const uint32_t i32PInfWeightOffsets[i32NumPInfWeightMasks] = {
265 0x00000000,
266 0xC0000000,
267 0xE0000000,
268 0xF0000000,
269 0xF8000000,
270 0xFC000000,
271 0xFE000000,
272 0xFF000000,
273 0xFF800000,
274 0xFFC00000,
275 0xFFE00000,
276 0xFFF00000,
277 0xFFF80000,
278 0xFFFC0000,
279 0xFFFE0000,
280 0xFFFF0000,
281 0xFFFF8000,
282 0xFFFFC000,
283 0xFFFFE000,
284 0xFFFFF000,
285 0xFFFFF800,
286 0xFFFFFC00,
287 0xFFFFFE00,
288 0xFFFFFF00,
289 0xFFFFFF80,
290 0xFFFFFFC0,
291 0xFFFFFFE0,
292 0xFFFFFFF0,
293 0xFFFFFFF8
294};
295
296static int32_t i32RandomPInf( void )
297{
298 int weightMaskNum;
299 union ui32_i32 uZ;
300
301 weightMaskNum = randomN_ui8( i32NumPInfWeightMasks );
302 uZ.ui =
303 (random_ui32() & i32PInfWeightMasks[weightMaskNum])
304 + i32PInfWeightOffsets[weightMaskNum];
305 return uZ.i;
306
307}
308
309static struct sequence sequenceA;
310static int subcase;
311
312int32_t genCases_i32_a;
313
314void genCases_i32_a_init( void )
315{
316
317 sequenceA.term1Num = 0;
318 sequenceA.term2Num = 0;
319 sequenceA.done = false;
320 subcase = 0;
321 genCases_total = (genCases_level == 1) ? 3 * i32NumP1 : 2 * i32NumP2;
322 genCases_done = false;
323
324}
325
326void genCases_i32_a_next( void )
327{
328
329 if ( genCases_level == 1 ) {
330 switch ( subcase ) {
331 case 0:
332 genCases_i32_a = i32RandomP3();
333 break;
334 case 1:
335 genCases_i32_a = i32RandomPInf();
336 break;
337 case 2:
338 genCases_i32_a = i32NextP1( &sequenceA );
339 genCases_done = sequenceA.done;
340 subcase = -1;
341 break;
342 }
343 } else {
344 switch ( subcase ) {
345 case 0:
346 genCases_i32_a = i32RandomP3();
347 break;
348 case 2:
349 genCases_i32_a = i32RandomPInf();
350 break;
351 case 3:
352 subcase = -1;
353 case 1:
354 genCases_i32_a = i32NextP2( &sequenceA );
355 genCases_done = sequenceA.done;
356 break;
357 }
358 }
359 ++subcase;
360
361}
362
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette