[compiler-rt] d4b8572 - [compiler-rt] Fix src_rep_t_clz and clz_in_sig_frac

Alexander Shaposhnikov via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 28 03:21:10 PDT 2023


Author: Alexander Shaposhnikov
Date: 2023-10-28T10:20:57Z
New Revision: d4b8572f11869fd47a4606ea91ee59d2833ce23c

URL: https://github.com/llvm/llvm-project/commit/d4b8572f11869fd47a4606ea91ee59d2833ce23c
DIFF: https://github.com/llvm/llvm-project/commit/d4b8572f11869fd47a4606ea91ee59d2833ce23c.diff

LOG: [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)

Added: 
    

Modified: 
    compiler-rt/lib/builtins/fp_extend.h
    compiler-rt/test/builtins/Unit/extenddftf2_test.c

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/builtins/fp_extend.h b/compiler-rt/lib/builtins/fp_extend.h
index 961e521846a21ae..95ea2a7ac4b2c0b 100644
--- a/compiler-rt/lib/builtins/fp_extend.h
+++ b/compiler-rt/lib/builtins/fp_extend.h
@@ -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

diff  --git a/compiler-rt/test/builtins/Unit/extenddftf2_test.c b/compiler-rt/test/builtins/Unit/extenddftf2_test.c
index fcc030ca92202e9..b2fbdcf1b07944a 100644
--- a/compiler-rt/test/builtins/Unit/extenddftf2_test.c
+++ b/compiler-rt/test/builtins/Unit/extenddftf2_test.c
@@ -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");
 


        


More information about the llvm-commits mailing list