VirtualBox

source: vbox/trunk/src/libs/softfloat-3e/testfloat/source/genCases_ui32.c@ 107044

Last change on this file since 107044 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.0 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
49enum { ui32NumP1 = 124 };
50static const uint32_t ui32P1[ui32NumP1] = {
51 0x00000000,
52 0x00000001,
53 0x00000002,
54 0x00000004,
55 0x00000008,
56 0x00000010,
57 0x00000020,
58 0x00000040,
59 0x00000080,
60 0x00000100,
61 0x00000200,
62 0x00000400,
63 0x00000800,
64 0x00001000,
65 0x00002000,
66 0x00004000,
67 0x00008000,
68 0x00010000,
69 0x00020000,
70 0x00040000,
71 0x00080000,
72 0x00100000,
73 0x00200000,
74 0x00400000,
75 0x00800000,
76 0x01000000,
77 0x02000000,
78 0x04000000,
79 0x08000000,
80 0x10000000,
81 0x20000000,
82 0x40000000,
83 0x80000000,
84 0xC0000000,
85 0xE0000000,
86 0xF0000000,
87 0xF8000000,
88 0xFC000000,
89 0xFE000000,
90 0xFF000000,
91 0xFF800000,
92 0xFFC00000,
93 0xFFE00000,
94 0xFFF00000,
95 0xFFF80000,
96 0xFFFC0000,
97 0xFFFE0000,
98 0xFFFF0000,
99 0xFFFF8000,
100 0xFFFFC000,
101 0xFFFFE000,
102 0xFFFFF000,
103 0xFFFFF800,
104 0xFFFFFC00,
105 0xFFFFFE00,
106 0xFFFFFF00,
107 0xFFFFFF80,
108 0xFFFFFFC0,
109 0xFFFFFFE0,
110 0xFFFFFFF0,
111 0xFFFFFFF8,
112 0xFFFFFFFC,
113 0xFFFFFFFE,
114 0xFFFFFFFF,
115 0xFFFFFFFD,
116 0xFFFFFFFB,
117 0xFFFFFFF7,
118 0xFFFFFFEF,
119 0xFFFFFFDF,
120 0xFFFFFFBF,
121 0xFFFFFF7F,
122 0xFFFFFEFF,
123 0xFFFFFDFF,
124 0xFFFFFBFF,
125 0xFFFFF7FF,
126 0xFFFFEFFF,
127 0xFFFFDFFF,
128 0xFFFFBFFF,
129 0xFFFF7FFF,
130 0xFFFEFFFF,
131 0xFFFDFFFF,
132 0xFFFBFFFF,
133 0xFFF7FFFF,
134 0xFFEFFFFF,
135 0xFFDFFFFF,
136 0xFFBFFFFF,
137 0xFF7FFFFF,
138 0xFEFFFFFF,
139 0xFDFFFFFF,
140 0xFBFFFFFF,
141 0xF7FFFFFF,
142 0xEFFFFFFF,
143 0xDFFFFFFF,
144 0xBFFFFFFF,
145 0x7FFFFFFF,
146 0x3FFFFFFF,
147 0x1FFFFFFF,
148 0x0FFFFFFF,
149 0x07FFFFFF,
150 0x03FFFFFF,
151 0x01FFFFFF,
152 0x00FFFFFF,
153 0x007FFFFF,
154 0x003FFFFF,
155 0x001FFFFF,
156 0x000FFFFF,
157 0x0007FFFF,
158 0x0003FFFF,
159 0x0001FFFF,
160 0x0000FFFF,
161 0x00007FFF,
162 0x00003FFF,
163 0x00001FFF,
164 0x00000FFF,
165 0x000007FF,
166 0x000003FF,
167 0x000001FF,
168 0x000000FF,
169 0x0000007F,
170 0x0000003F,
171 0x0000001F,
172 0x0000000F,
173 0x00000007,
174 0x00000003
175};
176
177static uint32_t ui32NextP1( struct sequence *sequencePtr )
178{
179 int termNum;
180 uint32_t z;
181
182 termNum = sequencePtr->term1Num;
183 z = ui32P1[termNum];
184 ++termNum;
185 if ( ui32NumP1 <= termNum ) {
186 termNum = 0;
187 sequencePtr->done = true;
188 }
189 sequencePtr->term1Num = termNum;
190 return z;
191
192}
193
194static const uint_fast32_t ui32NumP2 = (ui32NumP1 * ui32NumP1 + ui32NumP1) / 2;
195
196static uint32_t ui32NextP2( struct sequence *sequencePtr )
197{
198 int term1Num, term2Num;
199 uint32_t z;
200
201 term2Num = sequencePtr->term2Num;
202 term1Num = sequencePtr->term1Num;
203 z = ui32P1[term1Num] + ui32P1[term2Num];
204 ++term2Num;
205 if ( ui32NumP1 <= term2Num ) {
206 ++term1Num;
207 if ( ui32NumP1 <= term1Num ) {
208 term1Num = 0;
209 sequencePtr->done = true;
210 }
211 term2Num = term1Num;
212 sequencePtr->term1Num = term1Num;
213 }
214 sequencePtr->term2Num = term2Num;
215 return z;
216
217}
218
219static uint32_t ui32RandomP3( void )
220{
221
222 return
223 ui32P1[randomN_ui8( ui32NumP1 )] + ui32P1[randomN_ui8( ui32NumP1 )]
224 + ui32P1[randomN_ui8( ui32NumP1 )];
225
226}
227
228enum { ui32NumPInfWeightMasks = 29 };
229static const uint32_t ui32PInfWeightMasks[ui32NumPInfWeightMasks] = {
230 0xFFFFFFFF,
231 0x7FFFFFFF,
232 0x3FFFFFFF,
233 0x1FFFFFFF,
234 0x0FFFFFFF,
235 0x07FFFFFF,
236 0x03FFFFFF,
237 0x01FFFFFF,
238 0x00FFFFFF,
239 0x007FFFFF,
240 0x003FFFFF,
241 0x001FFFFF,
242 0x000FFFFF,
243 0x0007FFFF,
244 0x0003FFFF,
245 0x0001FFFF,
246 0x0000FFFF,
247 0x00007FFF,
248 0x00003FFF,
249 0x00001FFF,
250 0x00000FFF,
251 0x000007FF,
252 0x000003FF,
253 0x000001FF,
254 0x000000FF,
255 0x0000007F,
256 0x0000003F,
257 0x0000001F,
258 0x0000000F
259};
260
261static uint32_t ui32RandomPInf( void )
262{
263 int weightMaskNum;
264
265 weightMaskNum = randomN_ui8( ui32NumPInfWeightMasks );
266 return random_ui32() & ui32PInfWeightMasks[weightMaskNum];
267
268}
269
270static struct sequence sequenceA;
271static int subcase;
272
273uint32_t genCases_ui32_a;
274
275void genCases_ui32_a_init( void )
276{
277
278 sequenceA.term1Num = 0;
279 sequenceA.term2Num = 0;
280 sequenceA.done = false;
281 subcase = 0;
282 genCases_total = (genCases_level == 1) ? 3 * ui32NumP1 : 2 * ui32NumP2;
283 genCases_done = false;
284
285}
286
287void genCases_ui32_a_next( void )
288{
289
290 if ( genCases_level == 1 ) {
291 switch ( subcase ) {
292 case 0:
293 genCases_ui32_a = ui32RandomP3();
294 break;
295 case 1:
296 genCases_ui32_a = ui32RandomPInf();
297 break;
298 case 2:
299 genCases_ui32_a = ui32NextP1( &sequenceA );
300 genCases_done = sequenceA.done;
301 subcase = -1;
302 break;
303 }
304 } else {
305 switch ( subcase ) {
306 case 0:
307 genCases_ui32_a = ui32RandomP3();
308 break;
309 case 2:
310 genCases_ui32_a = ui32RandomPInf();
311 break;
312 case 3:
313 subcase = -1;
314 case 1:
315 genCases_ui32_a = ui32NextP2( &sequenceA );
316 genCases_done = sequenceA.done;
317 break;
318 }
319 }
320 ++subcase;
321
322}
323
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