]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/builtins/Unit/fixunstfdi_test.c
Vendor import of compiler-rt trunk r351319 (just before the release_80
[FreeBSD/FreeBSD.git] / test / builtins / Unit / fixunstfdi_test.c
1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 //===-- fixunstfdi_test.c - Test __fixunstfdi -----------------------------===//
3 //
4 //                     The LLVM Compiler Infrastructure
5 //
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
8 //
9 //===----------------------------------------------------------------------===//
10 //
11 // This file tests __fixunstfdi for the compiler_rt library.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #include <stdio.h>
16
17 #if _ARCH_PPC || __aarch64__
18
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 //             du_int is a 64 bit integral type
26 //             value in long double is representable in du_int or is negative 
27 //                 (no range checking performed)
28
29 COMPILER_RT_ABI du_int __fixunstfdi(long double a);
30
31 int test__fixunstfdi(long double a, du_int expected)
32 {
33     du_int x = __fixunstfdi(a);
34     if (x != expected)
35         printf("error in __fixunstfdi(%LA) = %llX, expected %llX\n",
36                a, x, expected);
37     return x != expected;
38 }
39
40 char assumption_1[sizeof(du_int) == 2*sizeof(su_int)] = {0};
41 char assumption_2[sizeof(du_int)*CHAR_BIT == 64] = {0};
42 char assumption_3[sizeof(long double)*CHAR_BIT == 128] = {0};
43
44 #endif
45
46 int main()
47 {
48 #if _ARCH_PPC || __aarch64__
49     if (test__fixunstfdi(0.0, 0))
50         return 1;
51
52     if (test__fixunstfdi(0.5, 0))
53         return 1;
54     if (test__fixunstfdi(0.99, 0))
55         return 1;
56     if (test__fixunstfdi(1.0, 1))
57         return 1;
58     if (test__fixunstfdi(1.5, 1))
59         return 1;
60     if (test__fixunstfdi(1.99, 1))
61         return 1;
62     if (test__fixunstfdi(2.0, 2))
63         return 1;
64     if (test__fixunstfdi(2.01, 2))
65         return 1;
66     if (test__fixunstfdi(-0.5, 0))
67         return 1;
68     if (test__fixunstfdi(-0.99, 0))
69         return 1;
70     if (test__fixunstfdi(-1.0, 0))
71         return 1;
72     if (test__fixunstfdi(-1.5, 0))
73         return 1;
74     if (test__fixunstfdi(-1.99, 0))
75         return 1;
76     if (test__fixunstfdi(-2.0, 0))
77         return 1;
78     if (test__fixunstfdi(-2.01, 0))
79         return 1;
80
81     if (test__fixunstfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000LL))
82         return 1;
83     if (test__fixunstfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000LL))
84         return 1;
85
86     if (test__fixunstfdi(-0x1.FFFFFEp+62, 0))
87         return 1;
88     if (test__fixunstfdi(-0x1.FFFFFCp+62, 0))
89         return 1;
90
91     if (test__fixunstfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00LL))
92         return 1;
93     if (test__fixunstfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800LL))
94         return 1;
95
96     if (test__fixunstfdi(-0x1.FFFFFFFFFFFFFp+62, 0))
97         return 1;
98     if (test__fixunstfdi(-0x1.FFFFFFFFFFFFEp+62, 0))
99         return 1;
100
101     if (test__fixunstfdi(0x1.FFFFFFFFFFFFFFFEp+63L, 0xFFFFFFFFFFFFFFFFLL))
102         return 1;
103     if (test__fixunstfdi(0x1.0000000000000002p+63L, 0x8000000000000001LL))
104         return 1;
105     if (test__fixunstfdi(0x1.0000000000000000p+63L, 0x8000000000000000LL))
106         return 1;
107     if (test__fixunstfdi(0x1.FFFFFFFFFFFFFFFCp+62L, 0x7FFFFFFFFFFFFFFFLL))
108         return 1;
109     if (test__fixunstfdi(0x1.FFFFFFFFFFFFFFF8p+62L, 0x7FFFFFFFFFFFFFFELL))
110         return 1;
111     if (test__fixunstfdi(0x1.p+64L, 0xFFFFFFFFFFFFFFFFLL))
112         return 1;
113
114     if (test__fixunstfdi(-0x1.0000000000000000p+63L, 0))
115         return 1;
116     if (test__fixunstfdi(-0x1.FFFFFFFFFFFFFFFCp+62L, 0))
117         return 1;
118     if (test__fixunstfdi(-0x1.FFFFFFFFFFFFFFF8p+62L, 0))
119         return 1;
120
121 #else
122     printf("skipped\n");
123 #endif
124    return 0;
125 }