Skip to content

Commit 6345941

Browse files
committed
Add extendhfxf2 into compiler rt
1 parent bba3849 commit 6345941

File tree

5 files changed

+102
-0
lines changed

5 files changed

+102
-0
lines changed

compiler-rt/lib/builtins/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ set(GENERIC_SOURCES
104104
divti3.c
105105
extendsfdf2.c
106106
extendhfsf2.c
107+
extendhfxf2.c
107108
ffsdi2.c
108109
ffssi2.c
109110
ffsti2.c
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//===-- lib/extendhfxf2.c - half -> long double conversion --------*- C -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#define SRC_HALF
10+
#define DST_DOUBLE
11+
#include "fp_extend_impl.inc"
12+
13+
// Use a forwarding definition and noinline to implement a poor man's alias,
14+
// as there isn't a good cross-platform way of defining one.
15+
// Long double are expected to be as precise as double.
16+
COMPILER_RT_ABI NOINLINE long double __extendhfxf2(src_t a) {
17+
return (long double)__extendXfYf2__(a);
18+
}

compiler-rt/lib/builtins/macho_embedded/common.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ divsf3
6060
divsi3
6161
extendsfdf2
6262
extendhfsf2
63+
extendhfxf2
6364
ffssi2
6465
fixdfsi
6566
fixsfsi
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// RUN: %clang_builtins %s %librt -o %t && %run %t
2+
// REQUIRES: librt_has_extendhfxf2
3+
4+
#include "int_lib.h"
5+
#include <stdio.h>
6+
7+
#if __LDBL_MANT_DIG__ == 113 && defined(COMPILER_RT_HAS_FLOAT16)
8+
9+
# include "fp_test.h"
10+
11+
COMPILER_RT_ABI long double __extendhfxf2(TYPE_FP16 a);
12+
13+
int test__extendhfxf2(TYPE_FP16 a, uint64_t expectedHi, uint64_t expectedLo) {
14+
long double x = __extendhfxf2(a);
15+
int ret = compareResultF128(x, expectedHi, expectedLo);
16+
17+
if (ret) {
18+
printf("error in test__extendhfxf2(%#.4x) = %.20Lf, "
19+
"expected %.20Lf\n",
20+
toRep16(a), x, fromRep128(expectedHi, expectedLo));
21+
}
22+
return ret;
23+
}
24+
25+
char assumption_1[sizeof(TYPE_FP16) * CHAR_BIT == 16] = {0};
26+
27+
#endif
28+
29+
int main() {
30+
#if __LDBL_MANT_DIG__ == 113 && defined(COMPILER_RT_HAS_FLOAT16)
31+
// qNaN
32+
if (test__extendhfxf2(makeQNaN16(), UINT64_C(0x7fff800000000000),
33+
UINT64_C(0x0)))
34+
return 1;
35+
// NaN
36+
if (test__extendhfxf2(makeNaN16(UINT16_C(0x0100)),
37+
UINT64_C(0x7fff400000000000), UINT64_C(0x0)))
38+
return 1;
39+
// inf
40+
if (test__extendhfxf2(makeInf16(), UINT64_C(0x7fff000000000000),
41+
UINT64_C(0x0)))
42+
return 1;
43+
if (test__extendhfxf2(-makeInf16(), UINT64_C(0xffff000000000000),
44+
UINT64_C(0x0)))
45+
return 1;
46+
// zero
47+
if (test__extendhfxf2(fromRep16(0x0U), UINT64_C(0x0), UINT64_C(0x0)))
48+
return 1;
49+
if (test__extendhfxf2(fromRep16(0x8000U), UINT64_C(0x8000000000000000),
50+
UINT64_C(0x0)))
51+
return 1;
52+
// denormal
53+
if (test__extendhfxf2(fromRep16(0x0010U), UINT64_C(0x3feb000000000000),
54+
UINT64_C(0x0000000000000000)))
55+
return 1;
56+
if (test__extendhfxf2(fromRep16(0x0001U), UINT64_C(0x3fe7000000000000),
57+
UINT64_C(0x0000000000000000)))
58+
return 1;
59+
if (test__extendhfxf2(fromRep16(0x8001U), UINT64_C(0xbfe7000000000000),
60+
UINT64_C(0x0000000000000000)))
61+
return 1;
62+
63+
// pi
64+
if (test__extendhfxf2(fromRep16(0x4248U), UINT64_C(0x4000920000000000),
65+
UINT64_C(0x0000000000000000)))
66+
return 1;
67+
if (test__extendhfxf2(fromRep16(0xc248U), UINT64_C(0xc000920000000000),
68+
UINT64_C(0x0000000000000000)))
69+
return 1;
70+
71+
if (test__extendhfxf2(fromRep16(0x508cU), UINT64_C(0x4004230000000000),
72+
UINT64_C(0x0)))
73+
return 1;
74+
if (test__extendhfxf2(fromRep16(0x1bb7U), UINT64_C(0x3ff6edc000000000),
75+
UINT64_C(0x0)))
76+
return 1;
77+
#else
78+
printf("skipped\n");
79+
#endif
80+
return 0;
81+
}

llvm/utils/gn/secondary/compiler-rt/lib/builtins/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ static_library("builtins") {
126126
"divsi3.c",
127127
"divti3.c",
128128
"extendhfsf2.c",
129+
"extendhfxf2.c"
129130
"extendsfdf2.c",
130131
"ffsdi2.c",
131132
"ffssi2.c",

0 commit comments

Comments
 (0)