VirtualBox

source: vbox/trunk/src/libs/softfloat-3e/testfloat/source/verCases.h@ 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: 5.7 KB
Line 
1
2/*============================================================================
3
4This C header 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, 2015, 2016, 2017, 2018 The Regents of the
9University of California. All 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 <stdio.h>
41#include <signal.h>
42#include "uint128.h"
43#include "softfloat.h"
44
45/*----------------------------------------------------------------------------
46*----------------------------------------------------------------------------*/
47
48extern const char *verCases_functionNamePtr;
49extern uint_fast8_t verCases_roundingPrecision;
50extern int verCases_roundingCode;
51extern int verCases_tininessCode;
52extern bool verCases_usesExact, verCases_exact;
53extern bool verCases_checkNaNs, verCases_checkInvInts;
54extern uint_fast32_t verCases_maxErrorCount;
55extern bool verCases_errorStop;
56
57void verCases_writeFunctionName( FILE * );
58
59extern volatile sig_atomic_t verCases_stop;
60
61extern bool verCases_anyErrors;
62
63void verCases_exitWithStatus( void );
64
65/*----------------------------------------------------------------------------
66*----------------------------------------------------------------------------*/
67
68#ifdef INLINE
69
70#ifdef FLOAT16
71
72INLINE bool f16_same( float16_t a, float16_t b )
73{
74 union { uint16_t ui; float16_t f; } uA, uB;
75 uA.f = a;
76 uB.f = b;
77 return (uA.ui == uB.ui);
78}
79
80INLINE bool f16_isNaN( float16_t a )
81{
82 union { uint16_t ui; float16_t f; } uA;
83 uA.f = a;
84 return 0x7C00 < (uA.ui & 0x7FFF);
85}
86
87#endif
88
89INLINE bool f32_same( float32_t a, float32_t b )
90{
91 union { uint32_t ui; float32_t f; } uA, uB;
92 uA.f = a;
93 uB.f = b;
94 return (uA.ui == uB.ui);
95}
96
97INLINE bool f32_isNaN( float32_t a )
98{
99 union { uint32_t ui; float32_t f; } uA;
100 uA.f = a;
101 return 0x7F800000 < (uA.ui & 0x7FFFFFFF);
102}
103
104#ifdef FLOAT64
105
106INLINE bool f64_same( float64_t a, float64_t b )
107{
108 union { uint64_t ui; float64_t f; } uA, uB;
109 uA.f = a;
110 uB.f = b;
111 return (uA.ui == uB.ui);
112}
113
114INLINE bool f64_isNaN( float64_t a )
115{
116 union { uint64_t ui; float64_t f; } uA;
117 uA.f = a;
118 return
119 UINT64_C( 0x7FF0000000000000 )
120 < (uA.ui & UINT64_C( 0x7FFFFFFFFFFFFFFF ));
121}
122
123#endif
124
125#ifdef EXTFLOAT80
126
127INLINE bool extF80M_same( const extFloat80_t *aPtr, const extFloat80_t *bPtr )
128{
129 const struct extFloat80M *aSPtr = (const struct extFloat80M *) aPtr;
130 const struct extFloat80M *bSPtr = (const struct extFloat80M *) bPtr;
131 return
132 (aSPtr->signExp == bSPtr->signExp) && (aSPtr->signif == bSPtr->signif);
133}
134
135INLINE bool extF80M_isNaN( const extFloat80_t *aPtr )
136{
137 const struct extFloat80M *aSPtr = (const struct extFloat80M *) aPtr;
138 return
139 ((aSPtr->signExp & 0x7FFF) == 0x7FFF)
140 && (aSPtr->signif & UINT64_C( 0x7FFFFFFFFFFFFFFF ));
141}
142
143#endif
144
145#ifdef FLOAT128
146
147INLINE bool f128M_same( const float128_t *aPtr, const float128_t *bPtr )
148{
149 const struct uint128 *uiAPtr = (const struct uint128 *) aPtr;
150 const struct uint128 *uiBPtr = (const struct uint128 *) bPtr;
151 return (uiAPtr->v64 == uiBPtr->v64) && (uiAPtr->v0 == uiBPtr->v0);
152}
153
154INLINE bool f128M_isNaN( const float128_t *aPtr )
155{
156 const struct uint128 *uiAPtr = (const struct uint128 *) aPtr;
157 uint_fast64_t absA64 = uiAPtr->v64 & UINT64_C( 0x7FFFFFFFFFFFFFFF );
158 return
159 (UINT64_C( 0x7FFF000000000000 ) < absA64)
160 || ((absA64 == UINT64_C( 0x7FFF000000000000 )) && uiAPtr->v0);
161}
162
163#endif
164
165#else
166
167#ifdef FLOAT16
168bool f16_same( float16_t, float16_t );
169bool f16_isNaN( float16_t );
170#endif
171bool f32_same( float32_t, float32_t );
172bool f32_isNaN( float32_t );
173#ifdef FLOAT64
174bool f64_same( float64_t, float64_t );
175bool f64_isNaN( float64_t );
176#endif
177#ifdef EXTFLOAT80
178bool extF80M_same( const extFloat80_t *, const extFloat80_t * );
179bool extF80M_isNaN( const extFloat80_t * );
180#endif
181#ifdef FLOAT128
182bool f128M_same( const float128_t *, const float128_t * );
183bool f128M_isNaN( const float128_t * );
184#endif
185
186#endif
187
188extern uint_fast32_t verCases_tenThousandsCount, verCases_errorCount;
189
190void verCases_writeTestsPerformed( int );
191void verCases_perTenThousand( void );
192void verCases_writeErrorFound( int );
193
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