Skip to content

Commit d4b8572

Browse files
[compiler-rt] Fix src_rep_t_clz and clz_in_sig_frac
This is a follow-up to 910a4bf. 1. __builtin_clz takes unsigned int, thus for uint16_t src_rep_t_clz can't use it directly but should subtract 16 (leading 16 bits of the promoted argument are zero). 2. Fix (and simplify) clz_in_sig_frac. Test plan: ninja check-compiler-rt (extendhfsf2_test.c and extenddftf2_test.c)
1 parent 2228b35 commit d4b8572

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

compiler-rt/lib/builtins/fp_extend.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ static const int srcSigFracBits = 10;
7575
// srcBits - srcSigFracBits - 1
7676
static const int srcExpBits = 5;
7777

78-
#define src_rep_t_clz __builtin_clz
78+
static inline int src_rep_t_clz_impl(src_rep_t a) {
79+
return __builtin_clz(a) - 16;
80+
}
81+
82+
#define src_rep_t_clz src_rep_t_clz_impl
7983

8084
#else
8185
#error Source should be half, single, or double precision!
@@ -138,7 +142,7 @@ static inline src_rep_t extract_sig_frac_from_src(src_rep_t x) {
138142

139143
#ifdef src_rep_t_clz
140144
static inline int clz_in_sig_frac(src_rep_t sigFrac) {
141-
const int skip = (sizeof(dst_t) * CHAR_BIT - srcBits) + 1 + srcExpBits;
145+
const int skip = 1 + srcExpBits;
142146
return src_rep_t_clz(sigFrac) - skip;
143147
}
144148
#endif

compiler-rt/test/builtins/Unit/extenddftf2_test.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ int main()
6464
UINT64_C(0x3fd2edcba9876543),
6565
UINT64_C(0x2000000000000000)))
6666
return 1;
67-
67+
// denormal
68+
if (test__extenddftf2(1.8194069811494184E-308,
69+
UINT64_C(0x3c00a2a7757954b9),
70+
UINT64_C(0x6000000000000000)))
71+
return 1;
6872
#else
6973
printf("skipped\n");
7074

0 commit comments

Comments
 (0)