1 
2 /*============================================================================
3 
4 This C source file is part of TestFloat, Release 3e, a package of programs for
5 testing the correctness of floating-point arithmetic complying with the IEEE
6 Standard for Floating-Point, by John R. Hauser.
7 
8 Copyright 2011, 2012, 2013, 2014, 2015, 2017 The Regents of the University of
9 California.  All rights reserved.
10 
11 Redistribution and use in source and binary forms, with or without
12 modification, 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 
25 THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
26 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
27 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
28 DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
29 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
32 ON 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
34 SOFTWARE, 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 "softfloat.h"
43 #include "genCases.h"
44 
45 #ifdef FLOAT64
46 
47 struct sequence {
48     int expNum, term1Num, term2Num;
49     bool done;
50 };
51 
52 union ui64_f64 { uint64_t ui; float64_t f; };
53 
54 enum {
55     f64NumQIn  =  22,
56     f64NumQOut =  64,
57     f64NumP1   =   4,
58     f64NumP2   = 204
59 };
60 static const uint64_t f64QIn[f64NumQIn] = {
61     UINT64_C( 0x0000000000000000 ),    /* positive, subnormal       */
62     UINT64_C( 0x0010000000000000 ),    /* positive, -1022           */
63     UINT64_C( 0x3CA0000000000000 ),    /* positive,   -53           */
64     UINT64_C( 0x3FD0000000000000 ),    /* positive,    -2           */
65     UINT64_C( 0x3FE0000000000000 ),    /* positive,    -1           */
66     UINT64_C( 0x3FF0000000000000 ),    /* positive,     0           */
67     UINT64_C( 0x4000000000000000 ),    /* positive,     1           */
68     UINT64_C( 0x4010000000000000 ),    /* positive,     2           */
69     UINT64_C( 0x4340000000000000 ),    /* positive,    53           */
70     UINT64_C( 0x7FE0000000000000 ),    /* positive,  1023           */
71     UINT64_C( 0x7FF0000000000000 ),    /* positive, infinity or NaN */
72     UINT64_C( 0x8000000000000000 ),    /* negative, subnormal       */
73     UINT64_C( 0x8010000000000000 ),    /* negative, -1022           */
74     UINT64_C( 0xBCA0000000000000 ),    /* negative,   -53           */
75     UINT64_C( 0xBFD0000000000000 ),    /* negative,    -2           */
76     UINT64_C( 0xBFE0000000000000 ),    /* negative,    -1           */
77     UINT64_C( 0xBFF0000000000000 ),    /* negative,     0           */
78     UINT64_C( 0xC000000000000000 ),    /* negative,     1           */
79     UINT64_C( 0xC010000000000000 ),    /* negative,     2           */
80     UINT64_C( 0xC340000000000000 ),    /* negative,    53           */
81     UINT64_C( 0xFFE0000000000000 ),    /* negative,  1023           */
82     UINT64_C( 0xFFF0000000000000 )     /* negative, infinity or NaN */
83 };
84 static const uint64_t f64QOut[f64NumQOut] = {
85     UINT64_C( 0x0000000000000000 ),    /* positive, subnormal       */
86     UINT64_C( 0x0010000000000000 ),    /* positive, -1022           */
87     UINT64_C( 0x0020000000000000 ),    /* positive, -1021           */
88     UINT64_C( 0x37E0000000000000 ),    /* positive,  -129           */
89     UINT64_C( 0x37F0000000000000 ),    /* positive,  -128           */
90     UINT64_C( 0x3800000000000000 ),    /* positive,  -127           */
91     UINT64_C( 0x3810000000000000 ),    /* positive,  -126           */
92     UINT64_C( 0x3CA0000000000000 ),    /* positive,   -53           */
93     UINT64_C( 0x3FB0000000000000 ),    /* positive,    -4           */
94     UINT64_C( 0x3FC0000000000000 ),    /* positive,    -3           */
95     UINT64_C( 0x3FD0000000000000 ),    /* positive,    -2           */
96     UINT64_C( 0x3FE0000000000000 ),    /* positive,    -1           */
97     UINT64_C( 0x3FF0000000000000 ),    /* positive,     0           */
98     UINT64_C( 0x4000000000000000 ),    /* positive,     1           */
99     UINT64_C( 0x4010000000000000 ),    /* positive,     2           */
100     UINT64_C( 0x4020000000000000 ),    /* positive,     3           */
101     UINT64_C( 0x4030000000000000 ),    /* positive,     4           */
102     UINT64_C( 0x41C0000000000000 ),    /* positive,    29           */
103     UINT64_C( 0x41D0000000000000 ),    /* positive,    30           */
104     UINT64_C( 0x41E0000000000000 ),    /* positive,    31           */
105     UINT64_C( 0x41F0000000000000 ),    /* positive,    32           */
106     UINT64_C( 0x4340000000000000 ),    /* positive,    53           */
107     UINT64_C( 0x43C0000000000000 ),    /* positive,    61           */
108     UINT64_C( 0x43D0000000000000 ),    /* positive,    62           */
109     UINT64_C( 0x43E0000000000000 ),    /* positive,    63           */
110     UINT64_C( 0x43F0000000000000 ),    /* positive,    64           */
111     UINT64_C( 0x47E0000000000000 ),    /* positive,   127           */
112     UINT64_C( 0x47F0000000000000 ),    /* positive,   128           */
113     UINT64_C( 0x4800000000000000 ),    /* positive,   129           */
114     UINT64_C( 0x7FD0000000000000 ),    /* positive,  1022           */
115     UINT64_C( 0x7FE0000000000000 ),    /* positive,  1023           */
116     UINT64_C( 0x7FF0000000000000 ),    /* positive, infinity or NaN */
117     UINT64_C( 0x8000000000000000 ),    /* negative, subnormal       */
118     UINT64_C( 0x8010000000000000 ),    /* negative, -1022           */
119     UINT64_C( 0x8020000000000000 ),    /* negative, -1021           */
120     UINT64_C( 0xB7E0000000000000 ),    /* negative,  -129           */
121     UINT64_C( 0xB7F0000000000000 ),    /* negative,  -128           */
122     UINT64_C( 0xB800000000000000 ),    /* negative,  -127           */
123     UINT64_C( 0xB810000000000000 ),    /* negative,  -126           */
124     UINT64_C( 0xBCA0000000000000 ),    /* negative,   -53           */
125     UINT64_C( 0xBFB0000000000000 ),    /* negative,    -4           */
126     UINT64_C( 0xBFC0000000000000 ),    /* negative,    -3           */
127     UINT64_C( 0xBFD0000000000000 ),    /* negative,    -2           */
128     UINT64_C( 0xBFE0000000000000 ),    /* negative,    -1           */
129     UINT64_C( 0xBFF0000000000000 ),    /* negative,     0           */
130     UINT64_C( 0xC000000000000000 ),    /* negative,     1           */
131     UINT64_C( 0xC010000000000000 ),    /* negative,     2           */
132     UINT64_C( 0xC020000000000000 ),    /* negative,     3           */
133     UINT64_C( 0xC030000000000000 ),    /* negative,     4           */
134     UINT64_C( 0xC1C0000000000000 ),    /* negative,    29           */
135     UINT64_C( 0xC1D0000000000000 ),    /* negative,    30           */
136     UINT64_C( 0xC1E0000000000000 ),    /* negative,    31           */
137     UINT64_C( 0xC1F0000000000000 ),    /* negative,    32           */
138     UINT64_C( 0xC340000000000000 ),    /* negative,    53           */
139     UINT64_C( 0xC3C0000000000000 ),    /* negative,    61           */
140     UINT64_C( 0xC3D0000000000000 ),    /* negative,    62           */
141     UINT64_C( 0xC3E0000000000000 ),    /* negative,    63           */
142     UINT64_C( 0xC3F0000000000000 ),    /* negative,    64           */
143     UINT64_C( 0xC7E0000000000000 ),    /* negative,   127           */
144     UINT64_C( 0xC7F0000000000000 ),    /* negative,   128           */
145     UINT64_C( 0xC800000000000000 ),    /* negative,   129           */
146     UINT64_C( 0xFFD0000000000000 ),    /* negative,  1022           */
147     UINT64_C( 0xFFE0000000000000 ),    /* negative,  1023           */
148     UINT64_C( 0xFFF0000000000000 )     /* negative, infinity or NaN */
149 };
150 static const uint64_t f64P1[f64NumP1] = {
151     UINT64_C( 0x0000000000000000 ),
152     UINT64_C( 0x0000000000000001 ),
153     UINT64_C( 0x000FFFFFFFFFFFFF ),
154     UINT64_C( 0x000FFFFFFFFFFFFE )
155 };
156 static const uint64_t f64P2[f64NumP2] = {
157     UINT64_C( 0x0000000000000000 ),
158     UINT64_C( 0x0000000000000001 ),
159     UINT64_C( 0x0000000000000002 ),
160     UINT64_C( 0x0000000000000004 ),
161     UINT64_C( 0x0000000000000008 ),
162     UINT64_C( 0x0000000000000010 ),
163     UINT64_C( 0x0000000000000020 ),
164     UINT64_C( 0x0000000000000040 ),
165     UINT64_C( 0x0000000000000080 ),
166     UINT64_C( 0x0000000000000100 ),
167     UINT64_C( 0x0000000000000200 ),
168     UINT64_C( 0x0000000000000400 ),
169     UINT64_C( 0x0000000000000800 ),
170     UINT64_C( 0x0000000000001000 ),
171     UINT64_C( 0x0000000000002000 ),
172     UINT64_C( 0x0000000000004000 ),
173     UINT64_C( 0x0000000000008000 ),
174     UINT64_C( 0x0000000000010000 ),
175     UINT64_C( 0x0000000000020000 ),
176     UINT64_C( 0x0000000000040000 ),
177     UINT64_C( 0x0000000000080000 ),
178     UINT64_C( 0x0000000000100000 ),
179     UINT64_C( 0x0000000000200000 ),
180     UINT64_C( 0x0000000000400000 ),
181     UINT64_C( 0x0000000000800000 ),
182     UINT64_C( 0x0000000001000000 ),
183     UINT64_C( 0x0000000002000000 ),
184     UINT64_C( 0x0000000004000000 ),
185     UINT64_C( 0x0000000008000000 ),
186     UINT64_C( 0x0000000010000000 ),
187     UINT64_C( 0x0000000020000000 ),
188     UINT64_C( 0x0000000040000000 ),
189     UINT64_C( 0x0000000080000000 ),
190     UINT64_C( 0x0000000100000000 ),
191     UINT64_C( 0x0000000200000000 ),
192     UINT64_C( 0x0000000400000000 ),
193     UINT64_C( 0x0000000800000000 ),
194     UINT64_C( 0x0000001000000000 ),
195     UINT64_C( 0x0000002000000000 ),
196     UINT64_C( 0x0000004000000000 ),
197     UINT64_C( 0x0000008000000000 ),
198     UINT64_C( 0x0000010000000000 ),
199     UINT64_C( 0x0000020000000000 ),
200     UINT64_C( 0x0000040000000000 ),
201     UINT64_C( 0x0000080000000000 ),
202     UINT64_C( 0x0000100000000000 ),
203     UINT64_C( 0x0000200000000000 ),
204     UINT64_C( 0x0000400000000000 ),
205     UINT64_C( 0x0000800000000000 ),
206     UINT64_C( 0x0001000000000000 ),
207     UINT64_C( 0x0002000000000000 ),
208     UINT64_C( 0x0004000000000000 ),
209     UINT64_C( 0x0008000000000000 ),
210     UINT64_C( 0x000C000000000000 ),
211     UINT64_C( 0x000E000000000000 ),
212     UINT64_C( 0x000F000000000000 ),
213     UINT64_C( 0x000F800000000000 ),
214     UINT64_C( 0x000FC00000000000 ),
215     UINT64_C( 0x000FE00000000000 ),
216     UINT64_C( 0x000FF00000000000 ),
217     UINT64_C( 0x000FF80000000000 ),
218     UINT64_C( 0x000FFC0000000000 ),
219     UINT64_C( 0x000FFE0000000000 ),
220     UINT64_C( 0x000FFF0000000000 ),
221     UINT64_C( 0x000FFF8000000000 ),
222     UINT64_C( 0x000FFFC000000000 ),
223     UINT64_C( 0x000FFFE000000000 ),
224     UINT64_C( 0x000FFFF000000000 ),
225     UINT64_C( 0x000FFFF800000000 ),
226     UINT64_C( 0x000FFFFC00000000 ),
227     UINT64_C( 0x000FFFFE00000000 ),
228     UINT64_C( 0x000FFFFF00000000 ),
229     UINT64_C( 0x000FFFFF80000000 ),
230     UINT64_C( 0x000FFFFFC0000000 ),
231     UINT64_C( 0x000FFFFFE0000000 ),
232     UINT64_C( 0x000FFFFFF0000000 ),
233     UINT64_C( 0x000FFFFFF8000000 ),
234     UINT64_C( 0x000FFFFFFC000000 ),
235     UINT64_C( 0x000FFFFFFE000000 ),
236     UINT64_C( 0x000FFFFFFF000000 ),
237     UINT64_C( 0x000FFFFFFF800000 ),
238     UINT64_C( 0x000FFFFFFFC00000 ),
239     UINT64_C( 0x000FFFFFFFE00000 ),
240     UINT64_C( 0x000FFFFFFFF00000 ),
241     UINT64_C( 0x000FFFFFFFF80000 ),
242     UINT64_C( 0x000FFFFFFFFC0000 ),
243     UINT64_C( 0x000FFFFFFFFE0000 ),
244     UINT64_C( 0x000FFFFFFFFF0000 ),
245     UINT64_C( 0x000FFFFFFFFF8000 ),
246     UINT64_C( 0x000FFFFFFFFFC000 ),
247     UINT64_C( 0x000FFFFFFFFFE000 ),
248     UINT64_C( 0x000FFFFFFFFFF000 ),
249     UINT64_C( 0x000FFFFFFFFFF800 ),
250     UINT64_C( 0x000FFFFFFFFFFC00 ),
251     UINT64_C( 0x000FFFFFFFFFFE00 ),
252     UINT64_C( 0x000FFFFFFFFFFF00 ),
253     UINT64_C( 0x000FFFFFFFFFFF80 ),
254     UINT64_C( 0x000FFFFFFFFFFFC0 ),
255     UINT64_C( 0x000FFFFFFFFFFFE0 ),
256     UINT64_C( 0x000FFFFFFFFFFFF0 ),
257     UINT64_C( 0x000FFFFFFFFFFFF8 ),
258     UINT64_C( 0x000FFFFFFFFFFFFC ),
259     UINT64_C( 0x000FFFFFFFFFFFFE ),
260     UINT64_C( 0x000FFFFFFFFFFFFF ),
261     UINT64_C( 0x000FFFFFFFFFFFFD ),
262     UINT64_C( 0x000FFFFFFFFFFFFB ),
263     UINT64_C( 0x000FFFFFFFFFFFF7 ),
264     UINT64_C( 0x000FFFFFFFFFFFEF ),
265     UINT64_C( 0x000FFFFFFFFFFFDF ),
266     UINT64_C( 0x000FFFFFFFFFFFBF ),
267     UINT64_C( 0x000FFFFFFFFFFF7F ),
268     UINT64_C( 0x000FFFFFFFFFFEFF ),
269     UINT64_C( 0x000FFFFFFFFFFDFF ),
270     UINT64_C( 0x000FFFFFFFFFFBFF ),
271     UINT64_C( 0x000FFFFFFFFFF7FF ),
272     UINT64_C( 0x000FFFFFFFFFEFFF ),
273     UINT64_C( 0x000FFFFFFFFFDFFF ),
274     UINT64_C( 0x000FFFFFFFFFBFFF ),
275     UINT64_C( 0x000FFFFFFFFF7FFF ),
276     UINT64_C( 0x000FFFFFFFFEFFFF ),
277     UINT64_C( 0x000FFFFFFFFDFFFF ),
278     UINT64_C( 0x000FFFFFFFFBFFFF ),
279     UINT64_C( 0x000FFFFFFFF7FFFF ),
280     UINT64_C( 0x000FFFFFFFEFFFFF ),
281     UINT64_C( 0x000FFFFFFFDFFFFF ),
282     UINT64_C( 0x000FFFFFFFBFFFFF ),
283     UINT64_C( 0x000FFFFFFF7FFFFF ),
284     UINT64_C( 0x000FFFFFFEFFFFFF ),
285     UINT64_C( 0x000FFFFFFDFFFFFF ),
286     UINT64_C( 0x000FFFFFFBFFFFFF ),
287     UINT64_C( 0x000FFFFFF7FFFFFF ),
288     UINT64_C( 0x000FFFFFEFFFFFFF ),
289     UINT64_C( 0x000FFFFFDFFFFFFF ),
290     UINT64_C( 0x000FFFFFBFFFFFFF ),
291     UINT64_C( 0x000FFFFF7FFFFFFF ),
292     UINT64_C( 0x000FFFFEFFFFFFFF ),
293     UINT64_C( 0x000FFFFDFFFFFFFF ),
294     UINT64_C( 0x000FFFFBFFFFFFFF ),
295     UINT64_C( 0x000FFFF7FFFFFFFF ),
296     UINT64_C( 0x000FFFEFFFFFFFFF ),
297     UINT64_C( 0x000FFFDFFFFFFFFF ),
298     UINT64_C( 0x000FFFBFFFFFFFFF ),
299     UINT64_C( 0x000FFF7FFFFFFFFF ),
300     UINT64_C( 0x000FFEFFFFFFFFFF ),
301     UINT64_C( 0x000FFDFFFFFFFFFF ),
302     UINT64_C( 0x000FFBFFFFFFFFFF ),
303     UINT64_C( 0x000FF7FFFFFFFFFF ),
304     UINT64_C( 0x000FEFFFFFFFFFFF ),
305     UINT64_C( 0x000FDFFFFFFFFFFF ),
306     UINT64_C( 0x000FBFFFFFFFFFFF ),
307     UINT64_C( 0x000F7FFFFFFFFFFF ),
308     UINT64_C( 0x000EFFFFFFFFFFFF ),
309     UINT64_C( 0x000DFFFFFFFFFFFF ),
310     UINT64_C( 0x000BFFFFFFFFFFFF ),
311     UINT64_C( 0x0007FFFFFFFFFFFF ),
312     UINT64_C( 0x0003FFFFFFFFFFFF ),
313     UINT64_C( 0x0001FFFFFFFFFFFF ),
314     UINT64_C( 0x0000FFFFFFFFFFFF ),
315     UINT64_C( 0x00007FFFFFFFFFFF ),
316     UINT64_C( 0x00003FFFFFFFFFFF ),
317     UINT64_C( 0x00001FFFFFFFFFFF ),
318     UINT64_C( 0x00000FFFFFFFFFFF ),
319     UINT64_C( 0x000007FFFFFFFFFF ),
320     UINT64_C( 0x000003FFFFFFFFFF ),
321     UINT64_C( 0x000001FFFFFFFFFF ),
322     UINT64_C( 0x000000FFFFFFFFFF ),
323     UINT64_C( 0x0000007FFFFFFFFF ),
324     UINT64_C( 0x0000003FFFFFFFFF ),
325     UINT64_C( 0x0000001FFFFFFFFF ),
326     UINT64_C( 0x0000000FFFFFFFFF ),
327     UINT64_C( 0x00000007FFFFFFFF ),
328     UINT64_C( 0x00000003FFFFFFFF ),
329     UINT64_C( 0x00000001FFFFFFFF ),
330     UINT64_C( 0x00000000FFFFFFFF ),
331     UINT64_C( 0x000000007FFFFFFF ),
332     UINT64_C( 0x000000003FFFFFFF ),
333     UINT64_C( 0x000000001FFFFFFF ),
334     UINT64_C( 0x000000000FFFFFFF ),
335     UINT64_C( 0x0000000007FFFFFF ),
336     UINT64_C( 0x0000000003FFFFFF ),
337     UINT64_C( 0x0000000001FFFFFF ),
338     UINT64_C( 0x0000000000FFFFFF ),
339     UINT64_C( 0x00000000007FFFFF ),
340     UINT64_C( 0x00000000003FFFFF ),
341     UINT64_C( 0x00000000001FFFFF ),
342     UINT64_C( 0x00000000000FFFFF ),
343     UINT64_C( 0x000000000007FFFF ),
344     UINT64_C( 0x000000000003FFFF ),
345     UINT64_C( 0x000000000001FFFF ),
346     UINT64_C( 0x000000000000FFFF ),
347     UINT64_C( 0x0000000000007FFF ),
348     UINT64_C( 0x0000000000003FFF ),
349     UINT64_C( 0x0000000000001FFF ),
350     UINT64_C( 0x0000000000000FFF ),
351     UINT64_C( 0x00000000000007FF ),
352     UINT64_C( 0x00000000000003FF ),
353     UINT64_C( 0x00000000000001FF ),
354     UINT64_C( 0x00000000000000FF ),
355     UINT64_C( 0x000000000000007F ),
356     UINT64_C( 0x000000000000003F ),
357     UINT64_C( 0x000000000000001F ),
358     UINT64_C( 0x000000000000000F ),
359     UINT64_C( 0x0000000000000007 ),
360     UINT64_C( 0x0000000000000003 )
361 };
362 
363 static const uint_fast64_t f64NumQInP1 = f64NumQIn * f64NumP1;
364 static const uint_fast64_t f64NumQOutP1 = f64NumQOut * f64NumP1;
365 
f64NextQInP1(struct sequence * sequencePtr)366 static float64_t f64NextQInP1( struct sequence *sequencePtr )
367 {
368     int expNum, sigNum;
369     union ui64_f64 uZ;
370 
371     expNum = sequencePtr->expNum;
372     sigNum = sequencePtr->term1Num;
373     uZ.ui = f64QIn[expNum] | f64P1[sigNum];
374     ++sigNum;
375     if ( f64NumP1 <= sigNum ) {
376         sigNum = 0;
377         ++expNum;
378         if ( f64NumQIn <= expNum ) {
379             expNum = 0;
380             sequencePtr->done = true;
381         }
382         sequencePtr->expNum = expNum;
383     }
384     sequencePtr->term1Num = sigNum;
385     return uZ.f;
386 
387 }
388 
f64NextQOutP1(struct sequence * sequencePtr)389 static float64_t f64NextQOutP1( struct sequence *sequencePtr )
390 {
391     int expNum, sigNum;
392     union ui64_f64 uZ;
393 
394     expNum = sequencePtr->expNum;
395     sigNum = sequencePtr->term1Num;
396     uZ.ui = f64QOut[expNum] | f64P1[sigNum];
397     ++sigNum;
398     if ( f64NumP1 <= sigNum ) {
399         sigNum = 0;
400         ++expNum;
401         if ( f64NumQOut <= expNum ) {
402             expNum = 0;
403             sequencePtr->done = true;
404         }
405         sequencePtr->expNum = expNum;
406     }
407     sequencePtr->term1Num = sigNum;
408     return uZ.f;
409 
410 }
411 
412 static const uint_fast64_t f64NumQInP2 = f64NumQIn * f64NumP2;
413 static const uint_fast64_t f64NumQOutP2 = f64NumQOut * f64NumP2;
414 
f64NextQInP2(struct sequence * sequencePtr)415 static float64_t f64NextQInP2( struct sequence *sequencePtr )
416 {
417     int expNum, sigNum;
418     union ui64_f64 uZ;
419 
420     expNum = sequencePtr->expNum;
421     sigNum = sequencePtr->term1Num;
422     uZ.ui = f64QIn[expNum] | f64P2[sigNum];
423     ++sigNum;
424     if ( f64NumP2 <= sigNum ) {
425         sigNum = 0;
426         ++expNum;
427         if ( f64NumQIn <= expNum ) {
428             expNum = 0;
429             sequencePtr->done = true;
430         }
431         sequencePtr->expNum = expNum;
432     }
433     sequencePtr->term1Num = sigNum;
434     return uZ.f;
435 
436 }
437 
f64NextQOutP2(struct sequence * sequencePtr)438 static float64_t f64NextQOutP2( struct sequence *sequencePtr )
439 {
440     int expNum, sigNum;
441     union ui64_f64 uZ;
442 
443     expNum = sequencePtr->expNum;
444     sigNum = sequencePtr->term1Num;
445     uZ.ui = f64QOut[expNum] | f64P2[sigNum];
446     ++sigNum;
447     if ( f64NumP2 <= sigNum ) {
448         sigNum = 0;
449         ++expNum;
450         if ( f64NumQOut <= expNum ) {
451             expNum = 0;
452             sequencePtr->done = true;
453         }
454         sequencePtr->expNum = expNum;
455     }
456     sequencePtr->term1Num = sigNum;
457     return uZ.f;
458 
459 }
460 
f64RandomQOutP3(void)461 static float64_t f64RandomQOutP3( void )
462 {
463     union ui64_f64 uZ;
464 
465     uZ.ui =
466           f64QOut[randomN_ui8( f64NumQOut )]
467         | ((f64P2[randomN_ui8( f64NumP2 )] + f64P2[randomN_ui8( f64NumP2 )])
468                & UINT64_C( 0x000FFFFFFFFFFFFF ));
469     return uZ.f;
470 
471 }
472 
f64RandomQOutPInf(void)473 static float64_t f64RandomQOutPInf( void )
474 {
475     union ui64_f64 uZ;
476 
477     uZ.ui =
478         f64QOut[randomN_ui8( f64NumQOut )]
479             | (random_ui64() & UINT64_C( 0x000FFFFFFFFFFFFF ));
480     return uZ.f;
481 
482 }
483 
484 enum { f64NumQInfWeightMasks = 10 };
485 static const uint64_t f64QInfWeightMasks[f64NumQInfWeightMasks] = {
486     UINT64_C( 0xFFF0000000000000 ),
487     UINT64_C( 0xFFF0000000000000 ),
488     UINT64_C( 0xBFF0000000000000 ),
489     UINT64_C( 0x9FF0000000000000 ),
490     UINT64_C( 0x8FF0000000000000 ),
491     UINT64_C( 0x87F0000000000000 ),
492     UINT64_C( 0x83F0000000000000 ),
493     UINT64_C( 0x81F0000000000000 ),
494     UINT64_C( 0x80F0000000000000 ),
495     UINT64_C( 0x8070000000000000 )
496 };
497 static const uint64_t f64QInfWeightOffsets[f64NumQInfWeightMasks] = {
498     UINT64_C( 0x0000000000000000 ),
499     UINT64_C( 0x0000000000000000 ),
500     UINT64_C( 0x2000000000000000 ),
501     UINT64_C( 0x3000000000000000 ),
502     UINT64_C( 0x3800000000000000 ),
503     UINT64_C( 0x3C00000000000000 ),
504     UINT64_C( 0x3E00000000000000 ),
505     UINT64_C( 0x3F00000000000000 ),
506     UINT64_C( 0x3F80000000000000 ),
507     UINT64_C( 0x3FC0000000000000 )
508 };
509 
f64RandomQInfP3(void)510 static float64_t f64RandomQInfP3( void )
511 {
512     int weightMaskNum;
513     union ui64_f64 uZ;
514 
515     weightMaskNum = randomN_ui8( f64NumQInfWeightMasks );
516     uZ.ui =
517           (((uint_fast64_t) random_ui16()<<48
518                 & f64QInfWeightMasks[weightMaskNum])
519                + f64QInfWeightOffsets[weightMaskNum])
520         | ((f64P2[randomN_ui8( f64NumP2 )] + f64P2[randomN_ui8( f64NumP2 )])
521                & UINT64_C( 0x000FFFFFFFFFFFFF ));
522     return uZ.f;
523 
524 }
525 
f64RandomQInfPInf(void)526 static float64_t f64RandomQInfPInf( void )
527 {
528     int weightMaskNum;
529     union ui64_f64 uZ;
530 
531     weightMaskNum = randomN_ui8( f64NumQInfWeightMasks );
532     uZ.ui =
533         (random_ui64()
534              & (f64QInfWeightMasks[weightMaskNum]
535                     | UINT64_C( 0x000FFFFFFFFFFFFF )))
536             + f64QInfWeightOffsets[weightMaskNum];
537     return uZ.f;
538 
539 }
540 
f64Random(void)541 static float64_t f64Random( void )
542 {
543 
544     switch ( random_ui8() & 7 ) {
545      case 0:
546      case 1:
547      case 2:
548         return f64RandomQOutP3();
549      case 3:
550         return f64RandomQOutPInf();
551      case 4:
552      case 5:
553      case 6:
554         return f64RandomQInfP3();
555      case 7:
556         return f64RandomQInfPInf();
557     }
558 
559 }
560 
561 static struct sequence sequenceA, sequenceB, sequenceC;
562 static float64_t currentA, currentB, currentC;
563 static int subcase;
564 
565 float64_t genCases_f64_a, genCases_f64_b, genCases_f64_c;
566 
genCases_f64_a_init(void)567 void genCases_f64_a_init( void )
568 {
569 
570     sequenceA.expNum = 0;
571     sequenceA.term1Num = 0;
572     sequenceA.term2Num = 0;
573     sequenceA.done = false;
574     subcase = 0;
575     genCases_total =
576         (genCases_level == 1) ? 3 * f64NumQOutP1 : 2 * f64NumQOutP2;
577     genCases_done = false;
578 
579 }
580 
genCases_f64_a_next(void)581 void genCases_f64_a_next( void )
582 {
583 
584     if ( genCases_level == 1 ) {
585         switch ( subcase ) {
586          case 0:
587          case 1:
588             genCases_f64_a = f64Random();
589             break;
590          case 2:
591             genCases_f64_a = f64NextQOutP1( &sequenceA );
592             genCases_done = sequenceA.done;
593             subcase = -1;
594             break;
595         }
596      } else {
597         switch ( subcase ) {
598          case 0:
599             genCases_f64_a = f64Random();
600             break;
601          case 1:
602             genCases_f64_a = f64NextQOutP2( &sequenceA );
603             genCases_done = sequenceA.done;
604             subcase = -1;
605             break;
606         }
607     }
608     ++subcase;
609 
610 }
611 
genCases_f64_ab_init(void)612 void genCases_f64_ab_init( void )
613 {
614 
615     sequenceA.expNum = 0;
616     sequenceA.term1Num = 0;
617     sequenceA.term2Num = 0;
618     sequenceA.done = false;
619     sequenceB.expNum = 0;
620     sequenceB.term1Num = 0;
621     sequenceB.term2Num = 0;
622     sequenceB.done = false;
623     subcase = 0;
624     if ( genCases_level == 1 ) {
625         genCases_total = 6 * f64NumQInP1 * f64NumQInP1;
626         currentA = f64NextQInP1( &sequenceA );
627     } else {
628         genCases_total = 2 * f64NumQInP2 * f64NumQInP2;
629         currentA = f64NextQInP2( &sequenceA );
630     }
631     genCases_done = false;
632 
633 }
634 
genCases_f64_ab_next(void)635 void genCases_f64_ab_next( void )
636 {
637 
638     if ( genCases_level == 1 ) {
639         switch ( subcase ) {
640          case 0:
641             if ( sequenceB.done ) {
642                 sequenceB.done = false;
643                 currentA = f64NextQInP1( &sequenceA );
644             }
645             currentB = f64NextQInP1( &sequenceB );
646          case 2:
647          case 4:
648             genCases_f64_a = f64Random();
649             genCases_f64_b = f64Random();
650             break;
651          case 1:
652             genCases_f64_a = currentA;
653             genCases_f64_b = f64Random();
654             break;
655          case 3:
656             genCases_f64_a = f64Random();
657             genCases_f64_b = currentB;
658             break;
659          case 5:
660             genCases_f64_a = currentA;
661             genCases_f64_b = currentB;
662             genCases_done = sequenceA.done & sequenceB.done;
663             subcase = -1;
664             break;
665         }
666     } else {
667         switch ( subcase ) {
668          case 0:
669             genCases_f64_a = f64Random();
670             genCases_f64_b = f64Random();
671             break;
672          case 1:
673             if ( sequenceB.done ) {
674                 sequenceB.done = false;
675                 currentA = f64NextQInP2( &sequenceA );
676             }
677             genCases_f64_a = currentA;
678             genCases_f64_b = f64NextQInP2( &sequenceB );
679             genCases_done = sequenceA.done & sequenceB.done;
680             subcase = -1;
681             break;
682         }
683     }
684     ++subcase;
685 
686 }
687 
genCases_f64_abc_init(void)688 void genCases_f64_abc_init( void )
689 {
690 
691     sequenceA.expNum = 0;
692     sequenceA.term1Num = 0;
693     sequenceA.term2Num = 0;
694     sequenceA.done = false;
695     sequenceB.expNum = 0;
696     sequenceB.term1Num = 0;
697     sequenceB.term2Num = 0;
698     sequenceB.done = false;
699     sequenceC.expNum = 0;
700     sequenceC.term1Num = 0;
701     sequenceC.term2Num = 0;
702     sequenceC.done = false;
703     subcase = 0;
704     if ( genCases_level == 1 ) {
705         genCases_total = 9 * f64NumQInP1 * f64NumQInP1 * f64NumQInP1;
706         currentA = f64NextQInP1( &sequenceA );
707         currentB = f64NextQInP1( &sequenceB );
708     } else {
709         genCases_total = 2 * f64NumQInP2 * f64NumQInP2 * f64NumQInP2;
710         currentA = f64NextQInP2( &sequenceA );
711         currentB = f64NextQInP2( &sequenceB );
712     }
713     genCases_done = false;
714 
715 }
716 
genCases_f64_abc_next(void)717 void genCases_f64_abc_next( void )
718 {
719 
720     if ( genCases_level == 1 ) {
721         switch ( subcase ) {
722          case 0:
723             if ( sequenceC.done ) {
724                 sequenceC.done = false;
725                 if ( sequenceB.done ) {
726                     sequenceB.done = false;
727                     currentA = f64NextQInP1( &sequenceA );
728                 }
729                 currentB = f64NextQInP1( &sequenceB );
730             }
731             currentC = f64NextQInP1( &sequenceC );
732             genCases_f64_a = f64Random();
733             genCases_f64_b = f64Random();
734             genCases_f64_c = currentC;
735             break;
736          case 1:
737             genCases_f64_a = currentA;
738             genCases_f64_b = currentB;
739             genCases_f64_c = f64Random();
740             break;
741          case 2:
742             genCases_f64_a = f64Random();
743             genCases_f64_b = f64Random();
744             genCases_f64_c = f64Random();
745             break;
746          case 3:
747             genCases_f64_a = f64Random();
748             genCases_f64_b = currentB;
749             genCases_f64_c = currentC;
750             break;
751          case 4:
752             genCases_f64_a = currentA;
753             genCases_f64_b = f64Random();
754             genCases_f64_c = f64Random();
755             break;
756          case 5:
757             genCases_f64_a = f64Random();
758             genCases_f64_b = currentB;
759             genCases_f64_c = f64Random();
760             break;
761          case 6:
762             genCases_f64_a = currentA;
763             genCases_f64_b = f64Random();
764             genCases_f64_c = currentC;
765             break;
766          case 7:
767             genCases_f64_a = f64Random();
768             genCases_f64_b = f64Random();
769             genCases_f64_c = f64Random();
770             break;
771          case 8:
772             genCases_f64_a = currentA;
773             genCases_f64_b = currentB;
774             genCases_f64_c = currentC;
775             genCases_done = sequenceA.done & sequenceB.done & sequenceC.done;
776             subcase = -1;
777             break;
778         }
779     } else {
780         switch ( subcase ) {
781          case 0:
782             genCases_f64_a = f64Random();
783             genCases_f64_b = f64Random();
784             genCases_f64_c = f64Random();
785             break;
786          case 1:
787             if ( sequenceC.done ) {
788                 sequenceC.done = false;
789                 if ( sequenceB.done ) {
790                     sequenceB.done = false;
791                     currentA = f64NextQInP2( &sequenceA );
792                 }
793                 currentB = f64NextQInP2( &sequenceB );
794             }
795             genCases_f64_a = currentA;
796             genCases_f64_b = currentB;
797             genCases_f64_c = f64NextQInP2( &sequenceC );
798             genCases_done = sequenceA.done & sequenceB.done & sequenceC.done;
799             subcase = -1;
800             break;
801         }
802     }
803     ++subcase;
804 
805 }
806 
807 #endif
808 
809