xref: /minix3/sys/external/bsd/compiler_rt/dist/test/Unit/floatuntisf_test.c (revision 4684ddb6aab0b36791c8099bc705d6140b3d05d0)
1*4684ddb6SLionel Sambuc //===-- floatuntisf.c - Test __floatuntisf --------------------------------===//
2*4684ddb6SLionel Sambuc //
3*4684ddb6SLionel Sambuc //                     The LLVM Compiler Infrastructure
4*4684ddb6SLionel Sambuc //
5*4684ddb6SLionel Sambuc // This file is dual licensed under the MIT and the University of Illinois Open
6*4684ddb6SLionel Sambuc // Source Licenses. See LICENSE.TXT for details.
7*4684ddb6SLionel Sambuc //
8*4684ddb6SLionel Sambuc //===----------------------------------------------------------------------===//
9*4684ddb6SLionel Sambuc //
10*4684ddb6SLionel Sambuc // This file tests __floatuntisf for the compiler_rt library.
11*4684ddb6SLionel Sambuc //
12*4684ddb6SLionel Sambuc //===----------------------------------------------------------------------===//
13*4684ddb6SLionel Sambuc 
14*4684ddb6SLionel Sambuc #if __x86_64
15*4684ddb6SLionel Sambuc 
16*4684ddb6SLionel Sambuc #include "int_lib.h"
17*4684ddb6SLionel Sambuc #include <float.h>
18*4684ddb6SLionel Sambuc #include <stdio.h>
19*4684ddb6SLionel Sambuc 
20*4684ddb6SLionel Sambuc // Returns: convert a to a float, rounding toward even.
21*4684ddb6SLionel Sambuc 
22*4684ddb6SLionel Sambuc // Assumption: float is a IEEE 32 bit floating point type
23*4684ddb6SLionel Sambuc //             tu_int is a 128 bit integral type
24*4684ddb6SLionel Sambuc 
25*4684ddb6SLionel Sambuc // seee eeee emmm mmmm mmmm mmmm mmmm mmmm
26*4684ddb6SLionel Sambuc 
27*4684ddb6SLionel Sambuc float __floatuntisf(tu_int a);
28*4684ddb6SLionel Sambuc 
test__floatuntisf(tu_int a,float expected)29*4684ddb6SLionel Sambuc int test__floatuntisf(tu_int a, float expected)
30*4684ddb6SLionel Sambuc {
31*4684ddb6SLionel Sambuc     float x = __floatuntisf(a);
32*4684ddb6SLionel Sambuc     if (x != expected)
33*4684ddb6SLionel Sambuc     {
34*4684ddb6SLionel Sambuc         utwords at;
35*4684ddb6SLionel Sambuc         at.all = a;
36*4684ddb6SLionel Sambuc         printf("error in __floatuntisf(0x%.16llX%.16llX) = %a, expected %a\n",
37*4684ddb6SLionel Sambuc                at.s.high, at.s.low, x, expected);
38*4684ddb6SLionel Sambuc     }
39*4684ddb6SLionel Sambuc     return x != expected;
40*4684ddb6SLionel Sambuc }
41*4684ddb6SLionel Sambuc 
42*4684ddb6SLionel Sambuc char assumption_1[sizeof(tu_int) == 2*sizeof(du_int)] = {0};
43*4684ddb6SLionel Sambuc char assumption_2[sizeof(tu_int)*CHAR_BIT == 128] = {0};
44*4684ddb6SLionel Sambuc char assumption_3[sizeof(float)*CHAR_BIT == 32] = {0};
45*4684ddb6SLionel Sambuc 
46*4684ddb6SLionel Sambuc #endif
47*4684ddb6SLionel Sambuc 
main()48*4684ddb6SLionel Sambuc int main()
49*4684ddb6SLionel Sambuc {
50*4684ddb6SLionel Sambuc #if __x86_64
51*4684ddb6SLionel Sambuc     if (test__floatuntisf(0, 0.0F))
52*4684ddb6SLionel Sambuc         return 1;
53*4684ddb6SLionel Sambuc 
54*4684ddb6SLionel Sambuc     if (test__floatuntisf(1, 1.0F))
55*4684ddb6SLionel Sambuc         return 1;
56*4684ddb6SLionel Sambuc     if (test__floatuntisf(2, 2.0F))
57*4684ddb6SLionel Sambuc         return 1;
58*4684ddb6SLionel Sambuc     if (test__floatuntisf(20, 20.0F))
59*4684ddb6SLionel Sambuc         return 1;
60*4684ddb6SLionel Sambuc 
61*4684ddb6SLionel Sambuc     if (test__floatuntisf(0x7FFFFF8000000000LL, 0x1.FFFFFEp+62F))
62*4684ddb6SLionel Sambuc         return 1;
63*4684ddb6SLionel Sambuc     if (test__floatuntisf(0x7FFFFF0000000000LL, 0x1.FFFFFCp+62F))
64*4684ddb6SLionel Sambuc         return 1;
65*4684ddb6SLionel Sambuc 
66*4684ddb6SLionel Sambuc     if (test__floatuntisf(make_ti(0x8000008000000000LL, 0), 0x1.000001p+127F))
67*4684ddb6SLionel Sambuc         return 1;
68*4684ddb6SLionel Sambuc     if (test__floatuntisf(make_ti(0x8000000000000800LL, 0), 0x1.0p+127F))
69*4684ddb6SLionel Sambuc         return 1;
70*4684ddb6SLionel Sambuc     if (test__floatuntisf(make_ti(0x8000010000000000LL, 0), 0x1.000002p+127F))
71*4684ddb6SLionel Sambuc         return 1;
72*4684ddb6SLionel Sambuc 
73*4684ddb6SLionel Sambuc     if (test__floatuntisf(make_ti(0x8000000000000000LL, 0), 0x1.000000p+127F))
74*4684ddb6SLionel Sambuc         return 1;
75*4684ddb6SLionel Sambuc 
76*4684ddb6SLionel Sambuc     if (test__floatuntisf(0x0007FB72E8000000LL, 0x1.FEDCBAp+50F))
77*4684ddb6SLionel Sambuc         return 1;
78*4684ddb6SLionel Sambuc 
79*4684ddb6SLionel Sambuc     if (test__floatuntisf(0x0007FB72EA000000LL, 0x1.FEDCBA8p+50F))
80*4684ddb6SLionel Sambuc         return 1;
81*4684ddb6SLionel Sambuc     if (test__floatuntisf(0x0007FB72EB000000LL, 0x1.FEDCBACp+50F))
82*4684ddb6SLionel Sambuc         return 1;
83*4684ddb6SLionel Sambuc 
84*4684ddb6SLionel Sambuc     if (test__floatuntisf(0x0007FB72EC000000LL, 0x1.FEDCBBp+50F))
85*4684ddb6SLionel Sambuc         return 1;
86*4684ddb6SLionel Sambuc 
87*4684ddb6SLionel Sambuc     if (test__floatuntisf(0x0007FB72E6000000LL, 0x1.FEDCB98p+50F))
88*4684ddb6SLionel Sambuc         return 1;
89*4684ddb6SLionel Sambuc     if (test__floatuntisf(0x0007FB72E7000000LL, 0x1.FEDCB9Cp+50F))
90*4684ddb6SLionel Sambuc         return 1;
91*4684ddb6SLionel Sambuc     if (test__floatuntisf(0x0007FB72E4000000LL, 0x1.FEDCB9p+50F))
92*4684ddb6SLionel Sambuc         return 1;
93*4684ddb6SLionel Sambuc 
94*4684ddb6SLionel Sambuc     if (test__floatuntisf(0xFFFFFFFFFFFFFFFELL, 0x1p+64F))
95*4684ddb6SLionel Sambuc         return 1;
96*4684ddb6SLionel Sambuc     if (test__floatuntisf(0xFFFFFFFFFFFFFFFFLL, 0x1p+64F))
97*4684ddb6SLionel Sambuc         return 1;
98*4684ddb6SLionel Sambuc 
99*4684ddb6SLionel Sambuc     if (test__floatuntisf(0x0007FB72E8000000LL, 0x1.FEDCBAp+50F))
100*4684ddb6SLionel Sambuc         return 1;
101*4684ddb6SLionel Sambuc 
102*4684ddb6SLionel Sambuc     if (test__floatuntisf(0x0007FB72EA000000LL, 0x1.FEDCBAp+50F))
103*4684ddb6SLionel Sambuc         return 1;
104*4684ddb6SLionel Sambuc     if (test__floatuntisf(0x0007FB72EB000000LL, 0x1.FEDCBAp+50F))
105*4684ddb6SLionel Sambuc         return 1;
106*4684ddb6SLionel Sambuc     if (test__floatuntisf(0x0007FB72EBFFFFFFLL, 0x1.FEDCBAp+50F))
107*4684ddb6SLionel Sambuc         return 1;
108*4684ddb6SLionel Sambuc     if (test__floatuntisf(0x0007FB72EC000000LL, 0x1.FEDCBCp+50F))
109*4684ddb6SLionel Sambuc         return 1;
110*4684ddb6SLionel Sambuc     if (test__floatuntisf(0x0007FB72E8000001LL, 0x1.FEDCBAp+50F))
111*4684ddb6SLionel Sambuc         return 1;
112*4684ddb6SLionel Sambuc 
113*4684ddb6SLionel Sambuc     if (test__floatuntisf(0x0007FB72E6000000LL, 0x1.FEDCBAp+50F))
114*4684ddb6SLionel Sambuc         return 1;
115*4684ddb6SLionel Sambuc     if (test__floatuntisf(0x0007FB72E7000000LL, 0x1.FEDCBAp+50F))
116*4684ddb6SLionel Sambuc         return 1;
117*4684ddb6SLionel Sambuc     if (test__floatuntisf(0x0007FB72E7FFFFFFLL, 0x1.FEDCBAp+50F))
118*4684ddb6SLionel Sambuc         return 1;
119*4684ddb6SLionel Sambuc     if (test__floatuntisf(0x0007FB72E4000001LL, 0x1.FEDCBAp+50F))
120*4684ddb6SLionel Sambuc         return 1;
121*4684ddb6SLionel Sambuc     if (test__floatuntisf(0x0007FB72E4000000LL, 0x1.FEDCB8p+50F))
122*4684ddb6SLionel Sambuc         return 1;
123*4684ddb6SLionel Sambuc 
124*4684ddb6SLionel Sambuc     if (test__floatuntisf(make_ti(0x0000000000001FEDLL, 0xCB90000000000001LL),
125*4684ddb6SLionel Sambuc                           0x1.FEDCBAp+76F))
126*4684ddb6SLionel Sambuc         return 1;
127*4684ddb6SLionel Sambuc     if (test__floatuntisf(make_ti(0x0000000000001FEDLL, 0xCBA0000000000000LL),
128*4684ddb6SLionel Sambuc                           0x1.FEDCBAp+76F))
129*4684ddb6SLionel Sambuc         return 1;
130*4684ddb6SLionel Sambuc     if (test__floatuntisf(make_ti(0x0000000000001FEDLL, 0xCBAFFFFFFFFFFFFFLL),
131*4684ddb6SLionel Sambuc                           0x1.FEDCBAp+76F))
132*4684ddb6SLionel Sambuc         return 1;
133*4684ddb6SLionel Sambuc     if (test__floatuntisf(make_ti(0x0000000000001FEDLL, 0xCBB0000000000000LL),
134*4684ddb6SLionel Sambuc                           0x1.FEDCBCp+76F))
135*4684ddb6SLionel Sambuc         return 1;
136*4684ddb6SLionel Sambuc     if (test__floatuntisf(make_ti(0x0000000000001FEDLL, 0xCBB0000000000001LL),
137*4684ddb6SLionel Sambuc                           0x1.FEDCBCp+76F))
138*4684ddb6SLionel Sambuc         return 1;
139*4684ddb6SLionel Sambuc     if (test__floatuntisf(make_ti(0x0000000000001FEDLL, 0xCBBFFFFFFFFFFFFFLL),
140*4684ddb6SLionel Sambuc                           0x1.FEDCBCp+76F))
141*4684ddb6SLionel Sambuc         return 1;
142*4684ddb6SLionel Sambuc     if (test__floatuntisf(make_ti(0x0000000000001FEDLL, 0xCBC0000000000000LL),
143*4684ddb6SLionel Sambuc                           0x1.FEDCBCp+76F))
144*4684ddb6SLionel Sambuc         return 1;
145*4684ddb6SLionel Sambuc     if (test__floatuntisf(make_ti(0x0000000000001FEDLL, 0xCBC0000000000001LL),
146*4684ddb6SLionel Sambuc                           0x1.FEDCBCp+76F))
147*4684ddb6SLionel Sambuc         return 1;
148*4684ddb6SLionel Sambuc     if (test__floatuntisf(make_ti(0x0000000000001FEDLL, 0xCBD0000000000000LL),
149*4684ddb6SLionel Sambuc                           0x1.FEDCBCp+76F))
150*4684ddb6SLionel Sambuc         return 1;
151*4684ddb6SLionel Sambuc     if (test__floatuntisf(make_ti(0x0000000000001FEDLL, 0xCBD0000000000001LL),
152*4684ddb6SLionel Sambuc                           0x1.FEDCBEp+76F))
153*4684ddb6SLionel Sambuc         return 1;
154*4684ddb6SLionel Sambuc     if (test__floatuntisf(make_ti(0x0000000000001FEDLL, 0xCBDFFFFFFFFFFFFFLL),
155*4684ddb6SLionel Sambuc                           0x1.FEDCBEp+76F))
156*4684ddb6SLionel Sambuc         return 1;
157*4684ddb6SLionel Sambuc     if (test__floatuntisf(make_ti(0x0000000000001FEDLL, 0xCBE0000000000000LL),
158*4684ddb6SLionel Sambuc                           0x1.FEDCBEp+76F))
159*4684ddb6SLionel Sambuc         return 1;
160*4684ddb6SLionel Sambuc 
161*4684ddb6SLionel Sambuc #else
162*4684ddb6SLionel Sambuc     printf("skipped\n");
163*4684ddb6SLionel Sambuc #endif
164*4684ddb6SLionel Sambuc    return 0;
165*4684ddb6SLionel Sambuc }
166