| 1 | // RUN: %clang_builtins %s %librt -o %t && %run %t |
| 2 | // REQUIRES: librt_has_truncxfhf2 |
| 3 | |
| 4 | #include <stdio.h> |
| 5 | |
| 6 | #include "fp_test.h" |
| 7 | |
| 8 | #if HAS_80_BIT_LONG_DOUBLE |
| 9 | |
| 10 | TYPE_FP16 __truncxfhf2(xf_float f); |
| 11 | |
| 12 | int test_truncxfhf2(uint16_t inputHi, uint64_t inputLo, uint16_t e) { |
| 13 | xf_float a = F80FromRep80(hi: inputHi, lo: inputLo); |
| 14 | TYPE_FP16 x = __truncxfhf2(f: a); |
| 15 | int ret = compareResultH(result: x, expected: e); |
| 16 | if (ret) { |
| 17 | printf(format: "error in test__truncxfhf2(%Lf) = %#.4x, " |
| 18 | "expected %#.4x\n" , |
| 19 | a, toRep16(x), e); |
| 20 | } |
| 21 | return ret; |
| 22 | } |
| 23 | |
| 24 | int main() { |
| 25 | // Small positive value |
| 26 | if (test_truncxfhf2(UINT16_C(0x3ffb), UINT64_C(0xccc0000000000000), |
| 27 | UINT16_C(0x2e66))) |
| 28 | return 1; |
| 29 | |
| 30 | // Small negative value |
| 31 | if (test_truncxfhf2(UINT16_C(0xbffb), UINT64_C(0xccc0000000000000), |
| 32 | UINT16_C(0xae66))) |
| 33 | return 1; |
| 34 | |
| 35 | // Zero |
| 36 | if (test_truncxfhf2(UINT16_C(0x0), UINT64_C(0x0), UINT16_C(0))) |
| 37 | return 1; |
| 38 | |
| 39 | // Smallest positive non-zero value |
| 40 | if (test_truncxfhf2(UINT16_C(0x3fef), UINT64_C(0x8000000000000000), |
| 41 | UINT16_C(0x0100))) |
| 42 | return 1; |
| 43 | |
| 44 | // Smallest negative non-zero value |
| 45 | if (test_truncxfhf2(UINT16_C(0xbfef), UINT64_C(0x8000000000000000), |
| 46 | UINT16_C(0x8100))) |
| 47 | return 1; |
| 48 | |
| 49 | // Positive infinity |
| 50 | if (test_truncxfhf2(UINT16_C(0x7fff), UINT64_C(0x8000000000000000), |
| 51 | UINT16_C(0x7c00))) |
| 52 | return 1; |
| 53 | |
| 54 | // Negative infinity |
| 55 | if (test_truncxfhf2(UINT16_C(0xffff), UINT64_C(0x8000000000000000), |
| 56 | UINT16_C(0xfc00))) |
| 57 | return 1; |
| 58 | |
| 59 | // NaN |
| 60 | if (test_truncxfhf2(UINT16_C(0x7fff), UINT64_C(0xc000000000000000), |
| 61 | UINT16_C(0x7e00))) |
| 62 | return 1; |
| 63 | |
| 64 | return 0; |
| 65 | } |
| 66 | |
| 67 | #else |
| 68 | |
| 69 | int main() { |
| 70 | printf("skipped\n" ); |
| 71 | return 0; |
| 72 | } |
| 73 | |
| 74 | #endif |
| 75 | |