1*b9829059Sjoerg //===-- fixunssfti_test.c - Test __fixunssfti -----------------------------===//
2*b9829059Sjoerg //
3*b9829059Sjoerg // The LLVM Compiler Infrastructure
4*b9829059Sjoerg //
5*b9829059Sjoerg // This file is dual licensed under the MIT and the University of Illinois Open
6*b9829059Sjoerg // Source Licenses. See LICENSE.TXT for details.
7*b9829059Sjoerg //
8*b9829059Sjoerg //===----------------------------------------------------------------------===//
9*b9829059Sjoerg //
10*b9829059Sjoerg // This file tests __fixunssfti for the compiler_rt library.
11*b9829059Sjoerg //
12*b9829059Sjoerg //===----------------------------------------------------------------------===//
13*b9829059Sjoerg
14*b9829059Sjoerg #if __x86_64
15*b9829059Sjoerg
16*b9829059Sjoerg #include "int_lib.h"
17*b9829059Sjoerg #include <stdio.h>
18*b9829059Sjoerg
19*b9829059Sjoerg // Returns: convert a to a unsigned long long, rounding toward zero.
20*b9829059Sjoerg // Negative values all become zero.
21*b9829059Sjoerg
22*b9829059Sjoerg // Assumption: float is a IEEE 32 bit floating point type
23*b9829059Sjoerg // tu_int is a 64 bit integral type
24*b9829059Sjoerg // value in float is representable in tu_int or is negative
25*b9829059Sjoerg // (no range checking performed)
26*b9829059Sjoerg
27*b9829059Sjoerg // seee eeee emmm mmmm mmmm mmmm mmmm mmmm
28*b9829059Sjoerg
29*b9829059Sjoerg tu_int __fixunssfti(float a);
30*b9829059Sjoerg
test__fixunssfti(float a,tu_int expected)31*b9829059Sjoerg int test__fixunssfti(float a, tu_int expected)
32*b9829059Sjoerg {
33*b9829059Sjoerg tu_int x = __fixunssfti(a);
34*b9829059Sjoerg if (x != expected)
35*b9829059Sjoerg {
36*b9829059Sjoerg utwords xt;
37*b9829059Sjoerg xt.all = x;
38*b9829059Sjoerg utwords expectedt;
39*b9829059Sjoerg expectedt.all = expected;
40*b9829059Sjoerg printf("error in __fixunssfti(%A) = 0x%.16llX%.16llX, expected 0x%.16llX%.16llX\n",
41*b9829059Sjoerg a, xt.s.high, xt.s.low, expectedt.s.high, expectedt.s.low);
42*b9829059Sjoerg }
43*b9829059Sjoerg return x != expected;
44*b9829059Sjoerg }
45*b9829059Sjoerg
46*b9829059Sjoerg char assumption_1[sizeof(tu_int) == 2*sizeof(di_int)] = {0};
47*b9829059Sjoerg char assumption_2[sizeof(su_int)*CHAR_BIT == 32] = {0};
48*b9829059Sjoerg char assumption_3[sizeof(float)*CHAR_BIT == 32] = {0};
49*b9829059Sjoerg
50*b9829059Sjoerg #endif
51*b9829059Sjoerg
main()52*b9829059Sjoerg int main()
53*b9829059Sjoerg {
54*b9829059Sjoerg #if __x86_64
55*b9829059Sjoerg if (test__fixunssfti(0.0F, 0))
56*b9829059Sjoerg return 1;
57*b9829059Sjoerg
58*b9829059Sjoerg if (test__fixunssfti(0.5F, 0))
59*b9829059Sjoerg return 1;
60*b9829059Sjoerg if (test__fixunssfti(0.99F, 0))
61*b9829059Sjoerg return 1;
62*b9829059Sjoerg if (test__fixunssfti(1.0F, 1))
63*b9829059Sjoerg return 1;
64*b9829059Sjoerg if (test__fixunssfti(1.5F, 1))
65*b9829059Sjoerg return 1;
66*b9829059Sjoerg if (test__fixunssfti(1.99F, 1))
67*b9829059Sjoerg return 1;
68*b9829059Sjoerg if (test__fixunssfti(2.0F, 2))
69*b9829059Sjoerg return 1;
70*b9829059Sjoerg if (test__fixunssfti(2.01F, 2))
71*b9829059Sjoerg return 1;
72*b9829059Sjoerg if (test__fixunssfti(-0.5F, 0))
73*b9829059Sjoerg return 1;
74*b9829059Sjoerg if (test__fixunssfti(-0.99F, 0))
75*b9829059Sjoerg return 1;
76*b9829059Sjoerg #if !TARGET_LIBGCC
77*b9829059Sjoerg if (test__fixunssfti(-1.0F, 0)) // libgcc ignores "returns 0 for negative input" spec
78*b9829059Sjoerg return 1;
79*b9829059Sjoerg if (test__fixunssfti(-1.5F, 0))
80*b9829059Sjoerg return 1;
81*b9829059Sjoerg if (test__fixunssfti(-1.99F, 0))
82*b9829059Sjoerg return 1;
83*b9829059Sjoerg if (test__fixunssfti(-2.0F, 0))
84*b9829059Sjoerg return 1;
85*b9829059Sjoerg if (test__fixunssfti(-2.01F, 0))
86*b9829059Sjoerg return 1;
87*b9829059Sjoerg #endif
88*b9829059Sjoerg
89*b9829059Sjoerg if (test__fixunssfti(0x1.FFFFFEp+63F, 0xFFFFFF0000000000LL))
90*b9829059Sjoerg return 1;
91*b9829059Sjoerg if (test__fixunssfti(0x1.000000p+63F, 0x8000000000000000LL))
92*b9829059Sjoerg return 1;
93*b9829059Sjoerg if (test__fixunssfti(0x1.FFFFFEp+62F, 0x7FFFFF8000000000LL))
94*b9829059Sjoerg return 1;
95*b9829059Sjoerg if (test__fixunssfti(0x1.FFFFFCp+62F, 0x7FFFFF0000000000LL))
96*b9829059Sjoerg return 1;
97*b9829059Sjoerg
98*b9829059Sjoerg if (test__fixunssfti(0x1.FFFFFEp+127F, make_ti(0xFFFFFF0000000000LL, 0)))
99*b9829059Sjoerg return 1;
100*b9829059Sjoerg if (test__fixunssfti(0x1.000000p+127F, make_ti(0x8000000000000000LL, 0)))
101*b9829059Sjoerg return 1;
102*b9829059Sjoerg if (test__fixunssfti(0x1.FFFFFEp+126F, make_ti(0x7FFFFF8000000000LL, 0)))
103*b9829059Sjoerg return 1;
104*b9829059Sjoerg if (test__fixunssfti(0x1.FFFFFCp+126F, make_ti(0x7FFFFF0000000000LL, 0)))
105*b9829059Sjoerg return 1;
106*b9829059Sjoerg
107*b9829059Sjoerg #if !TARGET_LIBGCC
108*b9829059Sjoerg if (test__fixunssfti(-0x1.FFFFFEp+62F, 0x0000000000000000LL))
109*b9829059Sjoerg return 1;
110*b9829059Sjoerg if (test__fixunssfti(-0x1.FFFFFCp+62F, 0x0000000000000000LL))
111*b9829059Sjoerg return 1;
112*b9829059Sjoerg if (test__fixunssfti(-0x1.FFFFFEp+126F, 0x0000000000000000LL))
113*b9829059Sjoerg return 1;
114*b9829059Sjoerg if (test__fixunssfti(-0x1.FFFFFCp+126F, 0x0000000000000000LL))
115*b9829059Sjoerg return 1;
116*b9829059Sjoerg #endif
117*b9829059Sjoerg
118*b9829059Sjoerg #endif
119*b9829059Sjoerg return 0;
120*b9829059Sjoerg }
121