1// RUN: %clang_builtins %s %librt -o %t && %run %t
2// REQUIRES: librt_has_fixunstfti
3// UNSUPPORTED: target=mips{{.*}}
4
5#include <stdio.h>
6
7
8#if __LDBL_MANT_DIG__ == 113
9
10#include "fp_test.h"
11#include "int_lib.h"
12
13// Returns: convert a to a unsigned long long, rounding toward zero.
14// Negative values all become zero.
15
16// Assumption: long double is a 128 bit floating point type
17// tu_int is a 128 bit integral type
18// value in long double is representable in tu_int or is negative
19// (no range checking performed)
20
21COMPILER_RT_ABI tu_int __fixunstfti(long double a);
22
23int test__fixunstfti(long double a, tu_int expected)
24{
25 tu_int x = __fixunstfti(a);
26 if (x != expected)
27 {
28 twords xt;
29 xt.all = x;
30
31 twords expectedt;
32 expectedt.all = expected;
33
34 printf("error in __fixunstfti(%.20Lf) = 0x%.16llX%.16llX, "
35 "expected 0x%.16llX%.16llX\n",
36 a, xt.s.high, xt.s.low, expectedt.s.high, expectedt.s.low);
37 }
38 return x != expected;
39}
40
41char assumption_1[sizeof(tu_int) == 4*sizeof(su_int)] = {0};
42char assumption_2[sizeof(tu_int)*CHAR_BIT == 128] = {0};
43char assumption_3[sizeof(long double)*CHAR_BIT == 128] = {0};
44
45#endif
46
47int main()
48{
49#if __LDBL_MANT_DIG__ == 113
50 if (test__fixunstfti(makeInf128(), make_ti(0xffffffffffffffffLL,
51 0xffffffffffffffffLL)))
52 return 1;
53
54 if (test__fixunstfti(0.0, 0))
55 return 1;
56
57 if (test__fixunstfti(0.5, 0))
58 return 1;
59 if (test__fixunstfti(0.99, 0))
60 return 1;
61 if (test__fixunstfti(1.0, 1))
62 return 1;
63 if (test__fixunstfti(1.5, 1))
64 return 1;
65 if (test__fixunstfti(1.99, 1))
66 return 1;
67 if (test__fixunstfti(2.0, 2))
68 return 1;
69 if (test__fixunstfti(2.01, 2))
70 return 1;
71 if (test__fixunstfti(-0.01, 0))
72 return 1;
73 if (test__fixunstfti(-0.99, 0))
74 return 1;
75
76 if (test__fixunstfti(0x1.p+128, make_ti(0xffffffffffffffffLL,
77 0xffffffffffffffffLL)))
78 return 1;
79
80 if (test__fixunstfti(0x1.FFFFFEp+126, make_ti(0x7fffff8000000000LL, 0x0)))
81 return 1;
82 if (test__fixunstfti(0x1.FFFFFEp+127, make_ti(0xffffff0000000000LL, 0x0)))
83 return 1;
84 if (test__fixunstfti(0x1.FFFFFEp+128, make_ti(0xffffffffffffffffLL,
85 0xffffffffffffffffLL)))
86 return 1;
87 if (test__fixunstfti(0x1.FFFFFEp+129, make_ti(0xffffffffffffffffLL,
88 0xffffffffffffffffLL)))
89 return 1;
90
91#else
92 printf(format: "skipped\n");
93#endif
94 return 0;
95}
96

source code of compiler-rt/test/builtins/Unit/fixunstfti_test.c