1*b9829059Sjoerg //===-- fixunssfdi_test.c - Test __fixunssfdi -----------------------------===//
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 __fixunssfdi for the compiler_rt library.
11*b9829059Sjoerg //
12*b9829059Sjoerg //===----------------------------------------------------------------------===//
13*b9829059Sjoerg
14*b9829059Sjoerg #include "int_lib.h"
15*b9829059Sjoerg #include <stdio.h>
16*b9829059Sjoerg
17*b9829059Sjoerg // Returns: convert a to a unsigned long long, rounding toward zero.
18*b9829059Sjoerg // Negative values all become zero.
19*b9829059Sjoerg
20*b9829059Sjoerg // Assumption: float is a IEEE 32 bit floating point type
21*b9829059Sjoerg // du_int is a 64 bit integral type
22*b9829059Sjoerg // value in float is representable in du_int or is negative
23*b9829059Sjoerg // (no range checking performed)
24*b9829059Sjoerg
25*b9829059Sjoerg // seee eeee emmm mmmm mmmm mmmm mmmm mmmm
26*b9829059Sjoerg
27*b9829059Sjoerg du_int __fixunssfdi(float a);
28*b9829059Sjoerg
test__fixunssfdi(float a,du_int expected)29*b9829059Sjoerg int test__fixunssfdi(float a, du_int expected)
30*b9829059Sjoerg {
31*b9829059Sjoerg du_int x = __fixunssfdi(a);
32*b9829059Sjoerg if (x != expected)
33*b9829059Sjoerg printf("error in __fixunssfdi(%A) = %llX, expected %llX\n",
34*b9829059Sjoerg a, x, expected);
35*b9829059Sjoerg return x != expected;
36*b9829059Sjoerg }
37*b9829059Sjoerg
38*b9829059Sjoerg char assumption_1[sizeof(du_int) == 2*sizeof(si_int)] = {0};
39*b9829059Sjoerg char assumption_2[sizeof(su_int)*CHAR_BIT == 32] = {0};
40*b9829059Sjoerg char assumption_3[sizeof(float)*CHAR_BIT == 32] = {0};
41*b9829059Sjoerg
main()42*b9829059Sjoerg int main()
43*b9829059Sjoerg {
44*b9829059Sjoerg if (test__fixunssfdi(0.0F, 0))
45*b9829059Sjoerg return 1;
46*b9829059Sjoerg
47*b9829059Sjoerg if (test__fixunssfdi(0.5F, 0))
48*b9829059Sjoerg return 1;
49*b9829059Sjoerg if (test__fixunssfdi(0.99F, 0))
50*b9829059Sjoerg return 1;
51*b9829059Sjoerg if (test__fixunssfdi(1.0F, 1))
52*b9829059Sjoerg return 1;
53*b9829059Sjoerg if (test__fixunssfdi(1.5F, 1))
54*b9829059Sjoerg return 1;
55*b9829059Sjoerg if (test__fixunssfdi(1.99F, 1))
56*b9829059Sjoerg return 1;
57*b9829059Sjoerg if (test__fixunssfdi(2.0F, 2))
58*b9829059Sjoerg return 1;
59*b9829059Sjoerg if (test__fixunssfdi(2.01F, 2))
60*b9829059Sjoerg return 1;
61*b9829059Sjoerg if (test__fixunssfdi(-0.5F, 0))
62*b9829059Sjoerg return 1;
63*b9829059Sjoerg if (test__fixunssfdi(-0.99F, 0))
64*b9829059Sjoerg return 1;
65*b9829059Sjoerg #if !TARGET_LIBGCC
66*b9829059Sjoerg if (test__fixunssfdi(-1.0F, 0)) // libgcc ignores "returns 0 for negative input" spec
67*b9829059Sjoerg return 1;
68*b9829059Sjoerg if (test__fixunssfdi(-1.5F, 0))
69*b9829059Sjoerg return 1;
70*b9829059Sjoerg if (test__fixunssfdi(-1.99F, 0))
71*b9829059Sjoerg return 1;
72*b9829059Sjoerg if (test__fixunssfdi(-2.0F, 0))
73*b9829059Sjoerg return 1;
74*b9829059Sjoerg if (test__fixunssfdi(-2.01F, 0))
75*b9829059Sjoerg return 1;
76*b9829059Sjoerg #endif
77*b9829059Sjoerg
78*b9829059Sjoerg if (test__fixunssfdi(0x1.FFFFFEp+63F, 0xFFFFFF0000000000LL))
79*b9829059Sjoerg return 1;
80*b9829059Sjoerg if (test__fixunssfdi(0x1.000000p+63F, 0x8000000000000000LL))
81*b9829059Sjoerg return 1;
82*b9829059Sjoerg if (test__fixunssfdi(0x1.FFFFFEp+62F, 0x7FFFFF8000000000LL))
83*b9829059Sjoerg return 1;
84*b9829059Sjoerg if (test__fixunssfdi(0x1.FFFFFCp+62F, 0x7FFFFF0000000000LL))
85*b9829059Sjoerg return 1;
86*b9829059Sjoerg
87*b9829059Sjoerg #if !TARGET_LIBGCC
88*b9829059Sjoerg if (test__fixunssfdi(-0x1.FFFFFEp+62F, 0x0000000000000000LL))
89*b9829059Sjoerg return 1;
90*b9829059Sjoerg if (test__fixunssfdi(-0x1.FFFFFCp+62F, 0x0000000000000000LL))
91*b9829059Sjoerg return 1;
92*b9829059Sjoerg #endif
93*b9829059Sjoerg
94*b9829059Sjoerg return 0;
95*b9829059Sjoerg }
96