mirror of
https://github.com/intel/llvm.git
synced 2026-01-20 19:07:53 +08:00
[compiler-rt] Fix src_rep_t_clz and clz_in_sig_frac
This is a follow-up to 910a4bf5b.
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)
This commit is contained in:
@@ -75,7 +75,11 @@ static const int srcSigFracBits = 10;
|
||||
// srcBits - srcSigFracBits - 1
|
||||
static const int srcExpBits = 5;
|
||||
|
||||
#define src_rep_t_clz __builtin_clz
|
||||
static inline int src_rep_t_clz_impl(src_rep_t a) {
|
||||
return __builtin_clz(a) - 16;
|
||||
}
|
||||
|
||||
#define src_rep_t_clz src_rep_t_clz_impl
|
||||
|
||||
#else
|
||||
#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) {
|
||||
|
||||
#ifdef src_rep_t_clz
|
||||
static inline int clz_in_sig_frac(src_rep_t sigFrac) {
|
||||
const int skip = (sizeof(dst_t) * CHAR_BIT - srcBits) + 1 + srcExpBits;
|
||||
const int skip = 1 + srcExpBits;
|
||||
return src_rep_t_clz(sigFrac) - skip;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -64,7 +64,11 @@ int main()
|
||||
UINT64_C(0x3fd2edcba9876543),
|
||||
UINT64_C(0x2000000000000000)))
|
||||
return 1;
|
||||
|
||||
// denormal
|
||||
if (test__extenddftf2(1.8194069811494184E-308,
|
||||
UINT64_C(0x3c00a2a7757954b9),
|
||||
UINT64_C(0x6000000000000000)))
|
||||
return 1;
|
||||
#else
|
||||
printf("skipped\n");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user