• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- fixunstfti_test.c - Test __fixunstfti -----------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file tests __fixunstfti for the compiler_rt library.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include <stdio.h>
15 
16 #if __LDBL_MANT_DIG__ == 113
17 
18 #include "fp_test.h"
19 #include "int_lib.h"
20 
21 // Returns: convert a to a unsigned long long, rounding toward zero.
22 //          Negative values all become zero.
23 
24 // Assumption: long double is a 128 bit floating point type
25 //             tu_int is a 128 bit integral type
26 //             value in long double is representable in tu_int or is negative
27 //                 (no range checking performed)
28 
29 COMPILER_RT_ABI tu_int __fixunstfti(long double a);
30 
test__fixunstfti(long double a,tu_int expected)31 int test__fixunstfti(long double a, tu_int expected)
32 {
33     tu_int x = __fixunstfti(a);
34     if (x != expected)
35     {
36         twords xt;
37         xt.all = x;
38 
39         twords expectedt;
40         expectedt.all = expected;
41 
42         printf("error in __fixunstfti(%.20Lf) = 0x%.16llX%.16llX, "
43                "expected 0x%.16llX%.16llX\n",
44                a, xt.s.high, xt.s.low, expectedt.s.high, expectedt.s.low);
45     }
46     return x != expected;
47 }
48 
49 char assumption_1[sizeof(tu_int) == 4*sizeof(su_int)] = {0};
50 char assumption_2[sizeof(tu_int)*CHAR_BIT == 128] = {0};
51 char assumption_3[sizeof(long double)*CHAR_BIT == 128] = {0};
52 
53 #endif
54 
main()55 int main()
56 {
57 #if __LDBL_MANT_DIG__ == 113
58     if (test__fixunstfti(makeInf128(), make_ti(0xffffffffffffffffLL,
59                                                0xffffffffffffffffLL)))
60         return 1;
61 
62     if (test__fixunstfti(0.0, 0))
63         return 1;
64 
65     if (test__fixunstfti(0.5, 0))
66         return 1;
67     if (test__fixunstfti(0.99, 0))
68         return 1;
69     if (test__fixunstfti(1.0, 1))
70         return 1;
71     if (test__fixunstfti(1.5, 1))
72         return 1;
73     if (test__fixunstfti(1.99, 1))
74         return 1;
75     if (test__fixunstfti(2.0, 2))
76         return 1;
77     if (test__fixunstfti(2.01, 2))
78         return 1;
79     if (test__fixunstfti(-0.01, 0))
80         return 1;
81     if (test__fixunstfti(-0.99, 0))
82         return 1;
83 
84     if (test__fixunstfti(0x1.p+128, make_ti(0xffffffffffffffffLL,
85                                             0xffffffffffffffffLL)))
86         return 1;
87 
88     if (test__fixunstfti(0x1.FFFFFEp+126, make_ti(0x7fffff8000000000LL, 0x0)))
89         return 1;
90     if (test__fixunstfti(0x1.FFFFFEp+127, make_ti(0xffffff0000000000LL, 0x0)))
91         return 1;
92     if (test__fixunstfti(0x1.FFFFFEp+128, make_ti(0xffffffffffffffffLL,
93                                                   0xffffffffffffffffLL)))
94         return 1;
95     if (test__fixunstfti(0x1.FFFFFEp+129, make_ti(0xffffffffffffffffLL,
96                                                   0xffffffffffffffffLL)))
97         return 1;
98 
99 #else
100     printf("skipped\n");
101 #endif
102    return 0;
103 }
104