75 lines · c
1// RUN: %clang_builtins %s %librt -o %t && %run %t2// REQUIRES: librt_has_truncxfhf23 4#include <stdio.h>5 6#include "fp_test.h"7 8#if HAS_80_BIT_LONG_DOUBLE9 10TYPE_FP16 __truncxfhf2(xf_float f);11 12int test_truncxfhf2(uint16_t inputHi, uint64_t inputLo, uint16_t e) {13 xf_float a = F80FromRep80(inputHi, inputLo);14 TYPE_FP16 x = __truncxfhf2(a);15 int ret = compareResultH(x, e);16 if (ret) {17 printf("error in test__truncxfhf2(%Lf) = %#.4x, "18 "expected %#.4x\n",19 a, toRep16(x), e);20 }21 return ret;22}23 24int main() {25 // Small positive value26 if (test_truncxfhf2(UINT16_C(0x3ffb), UINT64_C(0xccc0000000000000),27 UINT16_C(0x2e66)))28 return 1;29 30 // Small negative value31 if (test_truncxfhf2(UINT16_C(0xbffb), UINT64_C(0xccc0000000000000),32 UINT16_C(0xae66)))33 return 1;34 35 // Zero36 if (test_truncxfhf2(UINT16_C(0x0), UINT64_C(0x0), UINT16_C(0)))37 return 1;38 39 // Smallest positive non-zero value40 if (test_truncxfhf2(UINT16_C(0x3fef), UINT64_C(0x8000000000000000),41 UINT16_C(0x0100)))42 return 1;43 44 // Smallest negative non-zero value45 if (test_truncxfhf2(UINT16_C(0xbfef), UINT64_C(0x8000000000000000),46 UINT16_C(0x8100)))47 return 1;48 49 // Positive infinity50 if (test_truncxfhf2(UINT16_C(0x7fff), UINT64_C(0x8000000000000000),51 UINT16_C(0x7c00)))52 return 1;53 54 // Negative infinity55 if (test_truncxfhf2(UINT16_C(0xffff), UINT64_C(0x8000000000000000),56 UINT16_C(0xfc00)))57 return 1;58 59 // NaN60 if (test_truncxfhf2(UINT16_C(0x7fff), UINT64_C(0xc000000000000000),61 UINT16_C(0x7e00)))62 return 1;63 64 return 0;65}66 67#else68 69int main() {70 printf("skipped\n");71 return 0;72}73 74#endif75