[PowerPC] Collect some CallLowering arguments into a struct. [NFC]
[llvm-project.git] / compiler-rt / test / builtins / Unit / fixunstfti_test.c
blob77c6a45d36fa5901d7d15f11af0e819d222ebe59
1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_fixunstfti
3 //===-- fixunstfti_test.c - Test __fixunstfti -----------------------------===//
4 //
5 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
6 // See https://llvm.org/LICENSE.txt for license information.
7 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //
9 //===----------------------------------------------------------------------===//
11 // This file tests __fixunstfti for the compiler_rt library.
13 //===----------------------------------------------------------------------===//
15 #include <stdio.h>
17 // UNSUPPORTED: mips
19 #if __LDBL_MANT_DIG__ == 113
21 #include "fp_test.h"
22 #include "int_lib.h"
24 // Returns: convert a to a unsigned long long, rounding toward zero.
25 // Negative values all become zero.
27 // Assumption: long double is a 128 bit floating point type
28 // tu_int is a 128 bit integral type
29 // value in long double is representable in tu_int or is negative
30 // (no range checking performed)
32 COMPILER_RT_ABI tu_int __fixunstfti(long double a);
34 int test__fixunstfti(long double a, tu_int expected)
36 tu_int x = __fixunstfti(a);
37 if (x != expected)
39 twords xt;
40 xt.all = x;
42 twords expectedt;
43 expectedt.all = expected;
45 printf("error in __fixunstfti(%.20Lf) = 0x%.16llX%.16llX, "
46 "expected 0x%.16llX%.16llX\n",
47 a, xt.s.high, xt.s.low, expectedt.s.high, expectedt.s.low);
49 return x != expected;
52 char assumption_1[sizeof(tu_int) == 4*sizeof(su_int)] = {0};
53 char assumption_2[sizeof(tu_int)*CHAR_BIT == 128] = {0};
54 char assumption_3[sizeof(long double)*CHAR_BIT == 128] = {0};
56 #endif
58 int main()
60 #if __LDBL_MANT_DIG__ == 113
61 if (test__fixunstfti(makeInf128(), make_ti(0xffffffffffffffffLL,
62 0xffffffffffffffffLL)))
63 return 1;
65 if (test__fixunstfti(0.0, 0))
66 return 1;
68 if (test__fixunstfti(0.5, 0))
69 return 1;
70 if (test__fixunstfti(0.99, 0))
71 return 1;
72 if (test__fixunstfti(1.0, 1))
73 return 1;
74 if (test__fixunstfti(1.5, 1))
75 return 1;
76 if (test__fixunstfti(1.99, 1))
77 return 1;
78 if (test__fixunstfti(2.0, 2))
79 return 1;
80 if (test__fixunstfti(2.01, 2))
81 return 1;
82 if (test__fixunstfti(-0.01, 0))
83 return 1;
84 if (test__fixunstfti(-0.99, 0))
85 return 1;
87 if (test__fixunstfti(0x1.p+128, make_ti(0xffffffffffffffffLL,
88 0xffffffffffffffffLL)))
89 return 1;
91 if (test__fixunstfti(0x1.FFFFFEp+126, make_ti(0x7fffff8000000000LL, 0x0)))
92 return 1;
93 if (test__fixunstfti(0x1.FFFFFEp+127, make_ti(0xffffff0000000000LL, 0x0)))
94 return 1;
95 if (test__fixunstfti(0x1.FFFFFEp+128, make_ti(0xffffffffffffffffLL,
96 0xffffffffffffffffLL)))
97 return 1;
98 if (test__fixunstfti(0x1.FFFFFEp+129, make_ti(0xffffffffffffffffLL,
99 0xffffffffffffffffLL)))
100 return 1;
102 #else
103 printf("skipped\n");
104 #endif
105 return 0;