[PATCH] D123766: [CompilerRT] Fix 128-bit floating point division

Pavel Kosov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 14 01:41:46 PDT 2022


kpdev42 created this revision.
kpdev42 added reviewers: sepavloff, atrosinenko, joerg, efriedma.
kpdev42 added a project: LLVM.
Herald added a project: All.
kpdev42 requested review of this revision.
Herald added a project: Sanitizers.
Herald added a subscriber: Sanitizers.

Patch fixes number of iterations which should be 5 for given reciprocal precision, not 4.

OS Laboratory. Huawei Russian Research Institute. Saint-Petersburg


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123766

Files:
  compiler-rt/lib/builtins/divtf3.c
  compiler-rt/lib/builtins/fp_div_impl.inc
  compiler-rt/lib/builtins/int_util.h
  compiler-rt/test/builtins/Unit/divtf3_test.c


Index: compiler-rt/test/builtins/Unit/divtf3_test.c
===================================================================
--- compiler-rt/test/builtins/Unit/divtf3_test.c
+++ compiler-rt/test/builtins/Unit/divtf3_test.c
@@ -185,6 +185,11 @@
                      UINT64_C(0)))
         return 1;
 
+    if (test__divtf3(-1L,
+                     -0.999999999999999999999999999999999904L,
+                     UINT64_C(0x1),
+                     UINT64_C(0x3fff000000000000)))
+        return 1;
 #else
     printf("skipped\n");
 
Index: compiler-rt/lib/builtins/int_util.h
===================================================================
--- compiler-rt/lib/builtins/int_util.h
+++ compiler-rt/lib/builtins/int_util.h
@@ -40,6 +40,10 @@
 #define REPEAT_4_TIMES(code_to_repeat)                                         \
   REPEAT_3_TIMES(code_to_repeat)                                               \
   code_to_repeat
+#define REPEAT_5_TIMES(code_to_repeat)                                         \
+  REPEAT_4_TIMES(code_to_repeat)                                               \
+  code_to_repeat
+
 
 #define REPEAT_N_TIMES_(N, code_to_repeat) REPEAT_##N##_TIMES(code_to_repeat)
 #define REPEAT_N_TIMES(N, code_to_repeat) REPEAT_N_TIMES_(N, code_to_repeat)
Index: compiler-rt/lib/builtins/fp_div_impl.inc
===================================================================
--- compiler-rt/lib/builtins/fp_div_impl.inc
+++ compiler-rt/lib/builtins/fp_div_impl.inc
@@ -325,7 +325,7 @@
 #define RECIPROCAL_PRECISION REP_C(10)
 #elif defined(DOUBLE_PRECISION) && NUMBER_OF_HALF_ITERATIONS == 3 && NUMBER_OF_FULL_ITERATIONS == 1
 #define RECIPROCAL_PRECISION REP_C(220)
-#elif defined(QUAD_PRECISION) && NUMBER_OF_HALF_ITERATIONS == 4 && NUMBER_OF_FULL_ITERATIONS == 1
+#elif defined(QUAD_PRECISION) && NUMBER_OF_HALF_ITERATIONS == 5 && NUMBER_OF_FULL_ITERATIONS == 1
 #define RECIPROCAL_PRECISION REP_C(13922)
 #else
 #error Invalid number of iterations
Index: compiler-rt/lib/builtins/divtf3.c
===================================================================
--- compiler-rt/lib/builtins/divtf3.c
+++ compiler-rt/lib/builtins/divtf3.c
@@ -16,7 +16,7 @@
 
 #if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
 
-#define NUMBER_OF_HALF_ITERATIONS 4
+#define NUMBER_OF_HALF_ITERATIONS 5
 #define NUMBER_OF_FULL_ITERATIONS 1
 
 #include "fp_div_impl.inc"


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123766.422768.patch
Type: text/x-patch
Size: 2364 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220414/30f551ed/attachment.bin>


More information about the llvm-commits mailing list