diff --git a/compiler-rt/lib/builtins/extendhfxf2.c b/compiler-rt/lib/builtins/extendhfxf2.c index ce70c0eaf87118..2bd7c3b7c7487a 100644 --- a/compiler-rt/lib/builtins/extendhfxf2.c +++ b/compiler-rt/lib/builtins/extendhfxf2.c @@ -1,4 +1,5 @@ -//===-- lib/extendhfxf2.c - half -> long double conversion -------------*- C -*-===// +//===-- lib/extendhfxf2.c - half -> long double conversion -------------*- C +//-*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/compiler-rt/test/builtins/Unit/extendhfxf2_test.c b/compiler-rt/test/builtins/Unit/extendhfxf2_test.c new file mode 100644 index 00000000000000..567b70a671c175 --- /dev/null +++ b/compiler-rt/test/builtins/Unit/extendhfxf2_test.c @@ -0,0 +1,60 @@ +// RUN: %clang_builtins %s %librt -o %t && %run %t +// REQUIRES: librt_has_extendhfxf2 + +#include +#include // for isnan, isinf +#include + +long double __extendhfxf2(_Float16 f); + +int test_extendhfxf2(_Float16 a, long double expected) { + long double x = __extendhfxf2(a); + int ret = !(x == expected || (isnan(x) && isnan(expected)) || + (isinf(x) && isinf(expected) && x == expected)); + if (ret) { + printf("error in test__extendhfsf2(%f) = %.20Lf, " + "expected %.20Lf\n", + a, x, expected); + } + return ret; +} + +char assumption_1[sizeof(_Float16) * CHAR_BIT == 16] = {0}; + +int main() { + // Small positive value + if (test_extendhfxf2(0.09997558593750000000f, 0.09997558593750000000f)) + return 1; + + // Small negative value + if (test_extendhfxf2(-0.09997558593750000000f, -0.09997558593750000000f)) + return 1; + + // Zero + if (test_extendhfxf2(0.0f, 0.0L)) + return 1; + + // Smallest positive non-zero value + if (test_extendhfxf2(0x1p-16f, 0x1p-16f)) + return 1; + + // Smallest negative non-zero value + if (test_extendhfxf2(-0x1p-16f, -0x1p-16f)) + return 1; + + // Positive infinity + if (test_extendhfxf2(__builtin_huge_valf16(), __builtin_huge_valf64x())) + return 1; + + // Negative infinity + if (test_extendhfxf2(-__builtin_huge_valf16(), + (long double)-__builtin_huge_valf64x())) + return 1; + + // NaN + if (test_extendhfxf2(__builtin_nanf16(""), + (long double)__builtin_nanf64x(""))) + return 1; + + return 0; +}