blob: 0a48a73327036d420ad065dde1507717c71131a2 [file] [log] [blame]
Weiming Zhao9b7bbec2017-03-21 05:32:51 +00001// RUN: %clang_builtins %s %librt -o %t && %run %t
2// XFAIL: aarch64
3// test fails for aarch64 (see pr32260)
4
Simon Dardis19a4d972017-05-04 13:34:17 +00005// UNSUPPORTED: mips
6
Daniel Dunbarfd089992009-06-26 16:47:03 +00007//===-- fixunsxfti_test.c - Test __fixunsxfti -----------------------------===//
8//
9// The LLVM Compiler Infrastructure
10//
Howard Hinnant5b791f62010-11-16 22:13:33 +000011// This file is dual licensed under the MIT and the University of Illinois Open
12// Source Licenses. See LICENSE.TXT for details.
Daniel Dunbarfd089992009-06-26 16:47:03 +000013//
14//===----------------------------------------------------------------------===//
15//
16// This file tests __fixunsxfti for the compiler_rt library.
17//
18//===----------------------------------------------------------------------===//
19
Daniel Dunbarfd089992009-06-26 16:47:03 +000020#include "int_lib.h"
21#include <stdio.h>
22
Joerg Sonnenberger14743122014-03-18 21:35:30 +000023#ifdef CRT_HAS_128BIT
24
Daniel Dunbarfd089992009-06-26 16:47:03 +000025// Returns: convert a to a unsigned long long, rounding toward zero.
26// Negative values all become zero.
27
28// Assumption: long double is an intel 80 bit floating point type padded with 6 bytes
29// tu_int is a 64 bit integral type
30// value in long double is representable in tu_int or is negative
31// (no range checking performed)
32
33// gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee eeee |
34// 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm
35
Derek Schuffeb0ebc32015-04-24 15:45:57 +000036COMPILER_RT_ABI tu_int __fixunsxfti(long double a);
Daniel Dunbarfd089992009-06-26 16:47:03 +000037
38int test__fixunsxfti(long double a, tu_int expected)
39{
40 tu_int x = __fixunsxfti(a);
41 if (x != expected)
42 {
43 utwords xt;
44 xt.all = x;
45 utwords expectedt;
46 expectedt.all = expected;
47 printf("error in __fixunsxfti(%LA) = 0x%.16llX%.16llX, expected 0x%.16llX%.16llX\n",
Daniel Dunbar64857202009-10-27 17:49:07 +000048 a, xt.s.high, xt.s.low, expectedt.s.high, expectedt.s.low);
Daniel Dunbarfd089992009-06-26 16:47:03 +000049 }
50 return x != expected;
51}
52
53char assumption_1[sizeof(tu_int) == 2*sizeof(du_int)] = {0};
54char assumption_2[sizeof(tu_int)*CHAR_BIT == 128] = {0};
55char assumption_3[sizeof(long double)*CHAR_BIT == 128] = {0};
56
57#endif
58
59int main()
60{
Joerg Sonnenberger14743122014-03-18 21:35:30 +000061#ifdef CRT_HAS_128BIT
Daniel Dunbarfd089992009-06-26 16:47:03 +000062 if (test__fixunsxfti(0.0, 0))
63 return 1;
64
65 if (test__fixunsxfti(0.5, 0))
66 return 1;
67 if (test__fixunsxfti(0.99, 0))
68 return 1;
69 if (test__fixunsxfti(1.0, 1))
70 return 1;
71 if (test__fixunsxfti(1.5, 1))
72 return 1;
73 if (test__fixunsxfti(1.99, 1))
74 return 1;
75 if (test__fixunsxfti(2.0, 2))
76 return 1;
77 if (test__fixunsxfti(2.01, 2))
78 return 1;
79 if (test__fixunsxfti(-0.5, 0))
80 return 1;
81 if (test__fixunsxfti(-0.99, 0))
82 return 1;
83 if (test__fixunsxfti(-1.0, 0))
84 return 1;
85 if (test__fixunsxfti(-1.5, 0))
86 return 1;
87 if (test__fixunsxfti(-1.99, 0))
88 return 1;
89 if (test__fixunsxfti(-2.0, 0))
90 return 1;
91 if (test__fixunsxfti(-2.01, 0))
92 return 1;
93
94 if (test__fixunsxfti(0x1.FFFFFEp+62, 0x7FFFFF8000000000LL))
95 return 1;
96 if (test__fixunsxfti(0x1.FFFFFCp+62, 0x7FFFFF0000000000LL))
97 return 1;
98
99 if (test__fixunsxfti(-0x1.FFFFFEp+62, 0))
100 return 1;
101 if (test__fixunsxfti(-0x1.FFFFFCp+62, 0))
102 return 1;
103
104 if (test__fixunsxfti(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00LL))
105 return 1;
106 if (test__fixunsxfti(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800LL))
107 return 1;
108
109 if (test__fixunsxfti(-0x1.FFFFFFFFFFFFFp+62, 0))
110 return 1;
111 if (test__fixunsxfti(-0x1.FFFFFFFFFFFFEp+62, 0))
112 return 1;
113
114 if (test__fixunsxfti(0x1.FFFFFFFFFFFFFFFEp+63L, 0xFFFFFFFFFFFFFFFFLL))
115 return 1;
116 if (test__fixunsxfti(0x1.0000000000000002p+63L, 0x8000000000000001LL))
117 return 1;
118 if (test__fixunsxfti(0x1.0000000000000000p+63L, 0x8000000000000000LL))
119 return 1;
120 if (test__fixunsxfti(0x1.FFFFFFFFFFFFFFFCp+62L, 0x7FFFFFFFFFFFFFFFLL))
121 return 1;
122 if (test__fixunsxfti(0x1.FFFFFFFFFFFFFFF8p+62L, 0x7FFFFFFFFFFFFFFELL))
123 return 1;
124
125 if (test__fixunsxfti(-0x1.0000000000000000p+63L, 0))
126 return 1;
127 if (test__fixunsxfti(-0x1.FFFFFFFFFFFFFFFCp+62L, 0))
128 return 1;
129 if (test__fixunsxfti(-0x1.FFFFFFFFFFFFFFF8p+62L, 0))
130 return 1;
131
132 if (test__fixunsxfti(0x1.FFFFFFFFFFFFFFFEp+127L, make_ti(0xFFFFFFFFFFFFFFFFLL, 0)))
133 return 1;
134 if (test__fixunsxfti(0x1.0000000000000002p+127L, make_ti(0x8000000000000001LL, 0)))
135 return 1;
136 if (test__fixunsxfti(0x1.0000000000000000p+127L, make_ti(0x8000000000000000LL, 0)))
137 return 1;
138 if (test__fixunsxfti(0x1.FFFFFFFFFFFFFFFCp+126L, make_ti(0x7FFFFFFFFFFFFFFFLL, 0)))
139 return 1;
140 if (test__fixunsxfti(0x1.FFFFFFFFFFFFFFF8p+126L, make_ti(0x7FFFFFFFFFFFFFFELL, 0)))
141 return 1;
142
Joerg Sonnenbergerd9bcddd2011-05-29 21:43:29 +0000143#else
144 printf("skipped\n");
Daniel Dunbarfd089992009-06-26 16:47:03 +0000145#endif
146 return 0;
147}