Weiming Zhao | 9b7bbec | 2017-03-21 05:32:51 +0000 | [diff] [blame] | 1 | // RUN: %clang_builtins %s %librt -o %t && %run %t |
Joerg Sonnenberger | 91bd698 | 2015-03-11 21:13:56 +0000 | [diff] [blame] | 2 | //===--------------- fixunstfsi_test.c - Test __fixunstfsi ----------------===// |
| 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 __fixunstfsi for the compiler_rt library. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include <stdio.h> |
| 16 | |
| 17 | #if __LDBL_MANT_DIG__ == 113 |
| 18 | |
| 19 | #include "fp_test.h" |
| 20 | |
| 21 | unsigned int __fixunstfsi(long double a); |
| 22 | |
| 23 | int test__fixunstfsi(long double a, unsigned int expected) |
| 24 | { |
| 25 | unsigned int x = __fixunstfsi(a); |
| 26 | int ret = (x != expected); |
| 27 | |
| 28 | if (ret) |
| 29 | { |
| 30 | printf("error in test__fixunstfsi(%.20Lf) = %u, " |
| 31 | "expected %u\n", a, x, expected); |
| 32 | } |
| 33 | return ret; |
| 34 | } |
| 35 | |
| 36 | char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0}; |
| 37 | |
| 38 | #endif |
| 39 | |
| 40 | int main() |
| 41 | { |
| 42 | #if __LDBL_MANT_DIG__ == 113 |
| 43 | if (test__fixunstfsi(makeInf128(), UINT32_C(0xffffffff))) |
| 44 | return 1; |
| 45 | if (test__fixunstfsi(0, UINT32_C(0x0))) |
| 46 | return 1; |
| 47 | if (test__fixunstfsi(0x1.23456789abcdefp+5, UINT32_C(0x24))) |
| 48 | return 1; |
| 49 | if (test__fixunstfsi(0x1.23456789abcdefp-3, UINT32_C(0x0))) |
| 50 | return 1; |
| 51 | if (test__fixunstfsi(0x1.23456789abcdefp+20, UINT32_C(0x123456))) |
| 52 | return 1; |
| 53 | if (test__fixunstfsi(0x1.23456789abcdefp+40, UINT32_C(0xffffffff))) |
| 54 | return 1; |
| 55 | if (test__fixunstfsi(0x1.23456789abcdefp+256, UINT32_C(0xffffffff))) |
| 56 | return 1; |
| 57 | if (test__fixunstfsi(-0x1.23456789abcdefp+3, UINT32_C(0x0))) |
| 58 | return 1; |
| 59 | |
Sergey Dmitrouk | 195f3a1 | 2015-11-05 18:36:42 +0000 | [diff] [blame] | 60 | if (test__fixunstfsi(0x1.p+32, 0xFFFFFFFFLL)) |
| 61 | return 1; |
| 62 | |
Joerg Sonnenberger | 91bd698 | 2015-03-11 21:13:56 +0000 | [diff] [blame] | 63 | #else |
| 64 | printf("skipped\n"); |
| 65 | |
| 66 | #endif |
| 67 | return 0; |
| 68 | } |