[libc-commits] [libc] [libc][math][c23] Improve performance of fadd using double arithmetic (PR #112055)

Job Henandez Lara via libc-commits libc-commits at lists.llvm.org
Fri Oct 11 21:58:45 PDT 2024


https://github.com/Jobhdez updated https://github.com/llvm/llvm-project/pull/112055

>From eb246298eccd0653d659be629e619bc8eff3251b Mon Sep 17 00:00:00 2001
From: Job Hernandez <jobhdezlara93 at gmail.com>
Date: Fri, 11 Oct 2024 15:15:47 -0700
Subject: [PATCH 1/3] add performance tests for fadd

---
 .../math/performance_testing/CMakeLists.txt   | 12 ++++++++++
 .../math/performance_testing/fadd_perf.cpp    | 22 +++++++++++++++++++
 2 files changed, 34 insertions(+)
 create mode 100644 libc/test/src/math/performance_testing/fadd_perf.cpp

diff --git a/libc/test/src/math/performance_testing/CMakeLists.txt b/libc/test/src/math/performance_testing/CMakeLists.txt
index 60c074a248f72a..f1399663a6cf34 100644
--- a/libc/test/src/math/performance_testing/CMakeLists.txt
+++ b/libc/test/src/math/performance_testing/CMakeLists.txt
@@ -475,6 +475,18 @@ add_perf_binary(
     libc.src.math.fminimum_numf16
   COMPILE_OPTIONS
     -fno-builtin
+    )
+
+add_perf_binary(
+  fadd_perf
+  SRCS
+    fadd_perf.cpp
+  DEPENDS
+    .binary_op_single_output_diff
+    libc.src.math.fadd
+    libc.src.__support.FPUtil.fp_bits
+  COMPILE_OPTIONS
+    -fno-builtin
 )
 
 add_perf_binary(
diff --git a/libc/test/src/math/performance_testing/fadd_perf.cpp b/libc/test/src/math/performance_testing/fadd_perf.cpp
new file mode 100644
index 00000000000000..b903595d26c829
--- /dev/null
+++ b/libc/test/src/math/performance_testing/fadd_perf.cpp
@@ -0,0 +1,22 @@
+//===-- Performance test for the fadd function ----------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "BinaryOpSingleOutputPerf.h"
+#include "src/math/fadd.h"
+
+static constexpr size_t DOUBLE_ROUNDS = 40;
+
+float fadd_placeholder_binary(double x, double y) {
+  return static_cast<float>(x + y);
+}
+
+int main() {
+  BINARY_OP_SINGLE_OUTPUT_PERF_EX(float, double, myFunc, fadd_placeholder_binary, DOUBLE_ROUNDS, "fadd_perf.log")
+    return 0;
+}
+    

>From fb966e6df2a8dc646d27b8fbb11f0de265bb94ab Mon Sep 17 00:00:00 2001
From: Job Hernandez <jobhdezlara93 at gmail.com>
Date: Fri, 11 Oct 2024 21:57:09 -0700
Subject: [PATCH 2/3] fix bug

---
 libc/test/src/math/performance_testing/fadd_perf.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libc/test/src/math/performance_testing/fadd_perf.cpp b/libc/test/src/math/performance_testing/fadd_perf.cpp
index b903595d26c829..255cc7a5cd3973 100644
--- a/libc/test/src/math/performance_testing/fadd_perf.cpp
+++ b/libc/test/src/math/performance_testing/fadd_perf.cpp
@@ -16,7 +16,7 @@ float fadd_placeholder_binary(double x, double y) {
 }
 
 int main() {
-  BINARY_OP_SINGLE_OUTPUT_PERF_EX(float, double, myFunc, fadd_placeholder_binary, DOUBLE_ROUNDS, "fadd_perf.log")
+  BINARY_OP_SINGLE_OUTPUT_PERF_EX(float, double, LIBC_NAMESPACE::fadd, fadd_placeholder_binary, DOUBLE_ROUNDS, "fadd_perf.log")
     return 0;
 }
     

>From 334c4e7bb406670c111b62f05cf05f51e328a1cc Mon Sep 17 00:00:00 2001
From: Job Hernandez <jobhdezlara93 at gmail.com>
Date: Fri, 11 Oct 2024 21:58:34 -0700
Subject: [PATCH 3/3] format code

---
 libc/test/src/math/performance_testing/fadd_perf.cpp | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libc/test/src/math/performance_testing/fadd_perf.cpp b/libc/test/src/math/performance_testing/fadd_perf.cpp
index 255cc7a5cd3973..a80c27b6068a1e 100644
--- a/libc/test/src/math/performance_testing/fadd_perf.cpp
+++ b/libc/test/src/math/performance_testing/fadd_perf.cpp
@@ -16,7 +16,8 @@ float fadd_placeholder_binary(double x, double y) {
 }
 
 int main() {
-  BINARY_OP_SINGLE_OUTPUT_PERF_EX(float, double, LIBC_NAMESPACE::fadd, fadd_placeholder_binary, DOUBLE_ROUNDS, "fadd_perf.log")
-    return 0;
+  BINARY_OP_SINGLE_OUTPUT_PERF_EX(float, double, LIBC_NAMESPACE::fadd,
+                                  fadd_placeholder_binary, DOUBLE_ROUNDS,
+                                  "fadd_perf.log")
+  return 0;
 }
-    



More information about the libc-commits mailing list