[libc-commits] [libc] [libc][GPU] Remove code duplicate in GPU math functions (PR #241177)

via libc-commits libc-commits at lists.llvm.org
Wed Nov 11 00:51:23 PST 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: jinge90

<details>
<summary>Changes</summary>



---

Patch is 40.17 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/241177.diff


80 Files Affected:

- (modified) libc/src/math/CMakeLists.txt (+27-24) 
- (removed) libc/src/math/amdgpu/CMakeLists.txt (-303) 
- (removed) libc/src/math/amdgpu/fmax.cpp (-22) 
- (renamed) libc/src/math/gpu/CMakeLists.txt (+12-40) 
- (added) libc/src/math/gpu/amdgpu/CMakeLists.txt (+103) 
- (renamed) libc/src/math/gpu/amdgpu/fmod.cpp () 
- (renamed) libc/src/math/gpu/amdgpu/fmodf.cpp () 
- (renamed) libc/src/math/gpu/amdgpu/frexp.cpp () 
- (renamed) libc/src/math/gpu/amdgpu/frexpf.cpp () 
- (renamed) libc/src/math/gpu/amdgpu/ldexp.cpp () 
- (renamed) libc/src/math/gpu/amdgpu/ldexpf.cpp () 
- (renamed) libc/src/math/gpu/amdgpu/lgamma.cpp () 
- (renamed) libc/src/math/gpu/amdgpu/lgamma_r.cpp () 
- (renamed) libc/src/math/gpu/amdgpu/llrint.cpp () 
- (renamed) libc/src/math/gpu/amdgpu/llrintf.cpp () 
- (renamed) libc/src/math/gpu/amdgpu/lrint.cpp () 
- (renamed) libc/src/math/gpu/amdgpu/lrintf.cpp () 
- (renamed) libc/src/math/gpu/amdgpu/scalbn.cpp () 
- (renamed) libc/src/math/gpu/amdgpu/scalbnf.cpp () 
- (renamed) libc/src/math/gpu/amdgpu/tgamma.cpp () 
- (renamed) libc/src/math/gpu/amdgpu/tgammaf.cpp () 
- (renamed) libc/src/math/gpu/ceil.cpp () 
- (renamed) libc/src/math/gpu/ceilf.cpp () 
- (renamed) libc/src/math/gpu/copysign.cpp () 
- (renamed) libc/src/math/gpu/copysignf.cpp () 
- (renamed) libc/src/math/gpu/fabs.cpp () 
- (renamed) libc/src/math/gpu/fabsf.cpp () 
- (renamed) libc/src/math/gpu/floor.cpp () 
- (renamed) libc/src/math/gpu/floorf.cpp () 
- (renamed) libc/src/math/gpu/fma.cpp () 
- (renamed) libc/src/math/gpu/fmaf.cpp () 
- (renamed) libc/src/math/gpu/fmax.cpp () 
- (renamed) libc/src/math/gpu/fmaxf.cpp () 
- (renamed) libc/src/math/gpu/fmin.cpp () 
- (renamed) libc/src/math/gpu/fminf.cpp () 
- (renamed) libc/src/math/gpu/nearbyint.cpp () 
- (renamed) libc/src/math/gpu/nearbyintf.cpp () 
- (added) libc/src/math/gpu/nvptx/CMakeLists.txt (+39) 
- (renamed) libc/src/math/gpu/nvptx/lgamma.cpp () 
- (renamed) libc/src/math/gpu/nvptx/lgamma_r.cpp () 
- (renamed) libc/src/math/gpu/nvptx/llrint.cpp () 
- (renamed) libc/src/math/gpu/nvptx/llrintf.cpp () 
- (renamed) libc/src/math/gpu/nvptx/lrint.cpp () 
- (renamed) libc/src/math/gpu/nvptx/tgamma.cpp () 
- (renamed) libc/src/math/gpu/nvptx/tgammaf.cpp () 
- (renamed) libc/src/math/gpu/remainder.cpp () 
- (renamed) libc/src/math/gpu/remainderf.cpp () 
- (renamed) libc/src/math/gpu/rint.cpp () 
- (renamed) libc/src/math/gpu/rintf.cpp () 
- (renamed) libc/src/math/gpu/round.cpp () 
- (renamed) libc/src/math/gpu/roundf.cpp () 
- (renamed) libc/src/math/gpu/sqrt.cpp () 
- (renamed) libc/src/math/gpu/sqrtf.cpp () 
- (renamed) libc/src/math/gpu/trunc.cpp () 
- (renamed) libc/src/math/gpu/truncf.cpp () 
- (removed) libc/src/math/nvptx/ceil.cpp (-17) 
- (removed) libc/src/math/nvptx/ceilf.cpp (-17) 
- (removed) libc/src/math/nvptx/copysign.cpp (-19) 
- (removed) libc/src/math/nvptx/copysignf.cpp (-19) 
- (removed) libc/src/math/nvptx/fabs.cpp (-17) 
- (removed) libc/src/math/nvptx/fabsf.cpp (-17) 
- (removed) libc/src/math/nvptx/floor.cpp (-17) 
- (removed) libc/src/math/nvptx/floorf.cpp (-17) 
- (removed) libc/src/math/nvptx/fma.cpp (-19) 
- (removed) libc/src/math/nvptx/fmaf.cpp (-19) 
- (removed) libc/src/math/nvptx/fmaxf.cpp (-22) 
- (removed) libc/src/math/nvptx/fmin.cpp (-20) 
- (removed) libc/src/math/nvptx/fminf.cpp (-20) 
- (removed) libc/src/math/nvptx/nearbyint.cpp (-19) 
- (removed) libc/src/math/nvptx/nearbyintf.cpp (-19) 
- (removed) libc/src/math/nvptx/remainder.cpp (-19) 
- (removed) libc/src/math/nvptx/remainderf.cpp (-19) 
- (removed) libc/src/math/nvptx/rint.cpp (-17) 
- (removed) libc/src/math/nvptx/rintf.cpp (-17) 
- (removed) libc/src/math/nvptx/round.cpp (-17) 
- (removed) libc/src/math/nvptx/roundf.cpp (-17) 
- (removed) libc/src/math/nvptx/sqrt.cpp (-17) 
- (removed) libc/src/math/nvptx/sqrtf.cpp (-17) 
- (removed) libc/src/math/nvptx/trunc.cpp (-17) 
- (removed) libc/src/math/nvptx/truncf.cpp (-17) 


``````````diff
diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index 88fca3c6b572f7..1c7e786aaad359 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -1,33 +1,36 @@
 add_subdirectory(generic)
-if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_ARCHITECTURE})
+if(LIBC_TARGET_OS_IS_GPU)
+  # GPU implementations are organized as 'gpu/' for code shared by all GPU
+  # targets and 'gpu/<arch>/' for architecture specific code.
+  add_subdirectory(gpu)
+elseif(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_ARCHITECTURE})
   add_subdirectory(${LIBC_TARGET_ARCHITECTURE})
 endif()
 
 function(add_math_entrypoint_object name)
-  # We prefer machine specific implementation if available. Hence we check
-  # that first and return early if we are able to add an alias target for the
-  # machine specific implementation.
-  get_fq_target_name("${LIBC_TARGET_ARCHITECTURE}.${name}" fq_machine_specific_target_name)
-  if(TARGET ${fq_machine_specific_target_name})
-    add_entrypoint_object(
-      ${name}
-      ALIAS
-      DEPENDS
-        .${LIBC_TARGET_ARCHITECTURE}.${name}
-    )
-    return()
-  endif()
-
-  get_fq_target_name("generic.${name}" fq_generic_target_name)
-  if(TARGET ${fq_generic_target_name})
-    add_entrypoint_object(
-      ${name}
-      ALIAS
-      DEPENDS
-        .generic.${name}
-    )
-    return()
+  # We prefer machine specific implementation if available, followed by an
+  # implementation shared by all GPU targets, and finally the generic one. We
+  # return early once we are able to add an alias target for the first
+  # implementation found.
+  if(LIBC_TARGET_OS_IS_GPU)
+    set(impl_targets "gpu.${LIBC_TARGET_ARCHITECTURE}" "gpu")
+  else()
+    set(impl_targets "${LIBC_TARGET_ARCHITECTURE}")
   endif()
+  list(APPEND impl_targets "generic")
+
+  foreach(impl_tgt IN LISTS impl_targets)
+    get_fq_target_name("${impl_tgt}.${name}" fq_impl_target_name)
+    if(TARGET ${fq_impl_target_name})
+      add_entrypoint_object(
+        ${name}
+        ALIAS
+        DEPENDS
+          .${impl_tgt}.${name}
+      )
+      return()
+    endif()
+  endforeach()
 
   # Add a dummy entrypoint object for missing implementations. They will be skipped
   # anyway as there will be no entry for them in the target entrypoints list.
diff --git a/libc/src/math/amdgpu/CMakeLists.txt b/libc/src/math/amdgpu/CMakeLists.txt
deleted file mode 100644
index d05d519b74b4fe..00000000000000
--- a/libc/src/math/amdgpu/CMakeLists.txt
+++ /dev/null
@@ -1,303 +0,0 @@
-add_entrypoint_object(
-  ceil
-  SRCS
-    ceil.cpp
-  HDRS
-    ../ceil.h
-)
-
-add_entrypoint_object(
-  ceilf
-  SRCS
-    ceilf.cpp
-  HDRS
-    ../ceilf.h
-)
-
-add_entrypoint_object(
-  copysign
-  SRCS
-    copysign.cpp
-  HDRS
-    ../copysign.h
-)
-
-add_entrypoint_object(
-  copysignf
-  SRCS
-    copysignf.cpp
-  HDRS
-    ../copysignf.h
-)
-
-add_entrypoint_object(
-  fabs
-  SRCS
-    fabs.cpp
-  HDRS
-    ../fabs.h
-)
-
-add_entrypoint_object(
-  fabsf
-  SRCS
-    fabsf.cpp
-  HDRS
-    ../fabsf.h
-)
-
-add_entrypoint_object(
-  floor
-  SRCS
-    floor.cpp
-  HDRS
-    ../floor.h
-)
-
-add_entrypoint_object(
-  floorf
-  SRCS
-    floorf.cpp
-  HDRS
-    ../floorf.h
-)
-
-add_entrypoint_object(
-  fma
-  SRCS
-    fma.cpp
-  HDRS
-    ../fma.h
-)
-
-add_entrypoint_object(
-  fmaf
-  SRCS
-    fmaf.cpp
-  HDRS
-    ../fmaf.h
-)
-
-add_entrypoint_object(
-  fmax
-  SRCS
-    fmax.cpp
-  HDRS
-    ../fmax.h
-)
-
-add_entrypoint_object(
-  fmaxf
-  SRCS
-    fmaxf.cpp
-  HDRS
-    ../fmaxf.h
-)
-
-add_entrypoint_object(
-  fmin
-  SRCS
-    fmin.cpp
-  HDRS
-    ../fmin.h
-)
-
-add_entrypoint_object(
-  fminf
-  SRCS
-    fminf.cpp
-  HDRS
-    ../fminf.h
-)
-
-add_entrypoint_object(
-  fmod
-  SRCS
-    fmod.cpp
-  HDRS
-    ../fmod.h
-)
-
-add_entrypoint_object(
-  fmodf
-  SRCS
-    fmodf.cpp
-  HDRS
-    ../fmodf.h
-)
-
-add_entrypoint_object(
-  nearbyint
-  SRCS
-    nearbyint.cpp
-  HDRS
-    ../nearbyint.h
-)
-
-add_entrypoint_object(
-  nearbyintf
-  SRCS
-    nearbyintf.cpp
-  HDRS
-    ../nearbyintf.h
-)
-
-add_entrypoint_object(
-  remainder
-  SRCS
-    remainder.cpp
-  HDRS
-    ../remainder.h
-)
-
-add_entrypoint_object(
-  remainderf
-  SRCS
-    remainderf.cpp
-  HDRS
-    ../remainderf.h
-)
-
-add_entrypoint_object(
-  rint
-  SRCS
-    rint.cpp
-  HDRS
-    ../rint.h
-)
-
-add_entrypoint_object(
-  rintf
-  SRCS
-    rintf.cpp
-  HDRS
-    ../rintf.h
-)
-
-add_entrypoint_object(
-  round
-  SRCS
-    round.cpp
-  HDRS
-    ../round.h
-)
-
-add_entrypoint_object(
-  sqrt
-  SRCS
-    sqrt.cpp
-  HDRS
-    ../sqrt.h
-)
-
-add_entrypoint_object(
-  sqrtf
-  SRCS
-    sqrtf.cpp
-  HDRS
-    ../sqrtf.h
-)
-
-add_entrypoint_object(
-  trunc
-  SRCS
-    trunc.cpp
-  HDRS
-    ../trunc.h
-)
-
-add_entrypoint_object(
-  truncf
-  SRCS
-    truncf.cpp
-  HDRS
-    ../truncf.h
-)
-
-add_entrypoint_object(
-  frexp
-  SRCS
-    frexp.cpp
-  HDRS
-    ../frexp.h
-)
-
-add_entrypoint_object(
-  frexpf
-  SRCS
-    frexpf.cpp
-  HDRS
-    ../frexpf.h
-)
-
-add_entrypoint_object(
-  scalbn
-  SRCS
-    scalbn.cpp
-  HDRS
-    ../scalbn.h
-)
-
-add_entrypoint_object(
-  scalbnf
-  SRCS
-    scalbnf.cpp
-  HDRS
-    ../scalbnf.h
-)
-
-add_entrypoint_object(
-  ldexp
-  SRCS
-    ldexp.cpp
-  HDRS
-    ../ldexp.h
-)
-
-add_entrypoint_object(
-  ldexpf
-  SRCS
-    ldexpf.cpp
-  HDRS
-    ../ldexpf.h
-)
-
-add_entrypoint_object(
-  tgamma
-  SRCS
-    tgamma.cpp
-  HDRS
-    ../tgamma.h
-  COMPILE_OPTIONS
-    ${bitcode_link_flags}
-)
-
-add_entrypoint_object(
-  tgammaf
-  SRCS
-    tgammaf.cpp
-  HDRS
-    ../tgammaf.h
-  COMPILE_OPTIONS
-    ${bitcode_link_flags}
-)
-
-add_entrypoint_object(
-  lgamma
-  SRCS
-    lgamma.cpp
-  HDRS
-    ../lgamma.h
-  COMPILE_OPTIONS
-    ${bitcode_link_flags}
-)
-
-add_entrypoint_object(
-  lgamma_r
-  SRCS
-    lgamma_r.cpp
-  HDRS
-    ../lgamma_r.h
-  COMPILE_OPTIONS
-    ${bitcode_link_flags}
-)
diff --git a/libc/src/math/amdgpu/fmax.cpp b/libc/src/math/amdgpu/fmax.cpp
deleted file mode 100644
index 474019733598f8..00000000000000
--- a/libc/src/math/amdgpu/fmax.cpp
+++ /dev/null
@@ -1,22 +0,0 @@
-//===-- Implementation of the fmax function for GPU -----------------------===//
-//
-// 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 "src/math/fmax.h"
-
-#include "src/__support/CPP/bit.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
-#include "src/__support/macros/optimization.h"
-
-namespace LIBC_NAMESPACE_DECL {
-
-LLVM_LIBC_FUNCTION(double, fmax, (double x, double y)) {
-  return __builtin_fmax(x, y);
-}
-
-} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/nvptx/CMakeLists.txt b/libc/src/math/gpu/CMakeLists.txt
similarity index 79%
rename from libc/src/math/nvptx/CMakeLists.txt
rename to libc/src/math/gpu/CMakeLists.txt
index 78797092622a3d..29d9354c3ab01d 100644
--- a/libc/src/math/nvptx/CMakeLists.txt
+++ b/libc/src/math/gpu/CMakeLists.txt
@@ -1,3 +1,15 @@
+if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_ARCHITECTURE})
+  add_subdirectory(${LIBC_TARGET_ARCHITECTURE})
+endif()
+
+# Implementations shared by the AMDGPU and NVPTX targets. Architecture specific
+# implementations live in the corresponding subdirectory and take precedence
+# over the ones listed here.
+if(NOT LIBC_TARGET_ARCHITECTURE_IS_AMDGPU AND
+   NOT LIBC_TARGET_ARCHITECTURE_IS_NVPTX)
+  return()
+endif()
+
 add_entrypoint_object(
   ceil
   SRCS
@@ -197,43 +209,3 @@ add_entrypoint_object(
   HDRS
     ../truncf.h
 )
-
-add_entrypoint_object(
-  tgamma
-  SRCS
-    tgamma.cpp
-  HDRS
-    ../tgamma.h
-  COMPILE_OPTIONS
-    ${bitcode_link_flags}
-)
-
-add_entrypoint_object(
-  tgammaf
-  SRCS
-    tgammaf.cpp
-  HDRS
-    ../tgammaf.h
-  COMPILE_OPTIONS
-    ${bitcode_link_flags}
-)
-
-add_entrypoint_object(
-  lgamma
-  SRCS
-    lgamma.cpp
-  HDRS
-    ../lgamma.h
-  COMPILE_OPTIONS
-    ${bitcode_link_flags}
-)
-
-add_entrypoint_object(
-  lgamma_r
-  SRCS
-    lgamma_r.cpp
-  HDRS
-    ../lgamma_r.h
-  COMPILE_OPTIONS
-    ${bitcode_link_flags}
-)
diff --git a/libc/src/math/gpu/amdgpu/CMakeLists.txt b/libc/src/math/gpu/amdgpu/CMakeLists.txt
new file mode 100644
index 00000000000000..b8cda13741f8f6
--- /dev/null
+++ b/libc/src/math/gpu/amdgpu/CMakeLists.txt
@@ -0,0 +1,103 @@
+add_entrypoint_object(
+  fmod
+  SRCS
+    fmod.cpp
+  HDRS
+    ../../fmod.h
+)
+
+add_entrypoint_object(
+  fmodf
+  SRCS
+    fmodf.cpp
+  HDRS
+    ../../fmodf.h
+)
+
+add_entrypoint_object(
+  frexp
+  SRCS
+    frexp.cpp
+  HDRS
+    ../../frexp.h
+)
+
+add_entrypoint_object(
+  frexpf
+  SRCS
+    frexpf.cpp
+  HDRS
+    ../../frexpf.h
+)
+
+add_entrypoint_object(
+  scalbn
+  SRCS
+    scalbn.cpp
+  HDRS
+    ../../scalbn.h
+)
+
+add_entrypoint_object(
+  scalbnf
+  SRCS
+    scalbnf.cpp
+  HDRS
+    ../../scalbnf.h
+)
+
+add_entrypoint_object(
+  ldexp
+  SRCS
+    ldexp.cpp
+  HDRS
+    ../../ldexp.h
+)
+
+add_entrypoint_object(
+  ldexpf
+  SRCS
+    ldexpf.cpp
+  HDRS
+    ../../ldexpf.h
+)
+
+add_entrypoint_object(
+  tgamma
+  SRCS
+    tgamma.cpp
+  HDRS
+    ../../tgamma.h
+  COMPILE_OPTIONS
+    ${bitcode_link_flags}
+)
+
+add_entrypoint_object(
+  tgammaf
+  SRCS
+    tgammaf.cpp
+  HDRS
+    ../../tgammaf.h
+  COMPILE_OPTIONS
+    ${bitcode_link_flags}
+)
+
+add_entrypoint_object(
+  lgamma
+  SRCS
+    lgamma.cpp
+  HDRS
+    ../../lgamma.h
+  COMPILE_OPTIONS
+    ${bitcode_link_flags}
+)
+
+add_entrypoint_object(
+  lgamma_r
+  SRCS
+    lgamma_r.cpp
+  HDRS
+    ../../lgamma_r.h
+  COMPILE_OPTIONS
+    ${bitcode_link_flags}
+)
diff --git a/libc/src/math/amdgpu/fmod.cpp b/libc/src/math/gpu/amdgpu/fmod.cpp
similarity index 100%
rename from libc/src/math/amdgpu/fmod.cpp
rename to libc/src/math/gpu/amdgpu/fmod.cpp
diff --git a/libc/src/math/amdgpu/fmodf.cpp b/libc/src/math/gpu/amdgpu/fmodf.cpp
similarity index 100%
rename from libc/src/math/amdgpu/fmodf.cpp
rename to libc/src/math/gpu/amdgpu/fmodf.cpp
diff --git a/libc/src/math/amdgpu/frexp.cpp b/libc/src/math/gpu/amdgpu/frexp.cpp
similarity index 100%
rename from libc/src/math/amdgpu/frexp.cpp
rename to libc/src/math/gpu/amdgpu/frexp.cpp
diff --git a/libc/src/math/amdgpu/frexpf.cpp b/libc/src/math/gpu/amdgpu/frexpf.cpp
similarity index 100%
rename from libc/src/math/amdgpu/frexpf.cpp
rename to libc/src/math/gpu/amdgpu/frexpf.cpp
diff --git a/libc/src/math/amdgpu/ldexp.cpp b/libc/src/math/gpu/amdgpu/ldexp.cpp
similarity index 100%
rename from libc/src/math/amdgpu/ldexp.cpp
rename to libc/src/math/gpu/amdgpu/ldexp.cpp
diff --git a/libc/src/math/amdgpu/ldexpf.cpp b/libc/src/math/gpu/amdgpu/ldexpf.cpp
similarity index 100%
rename from libc/src/math/amdgpu/ldexpf.cpp
rename to libc/src/math/gpu/amdgpu/ldexpf.cpp
diff --git a/libc/src/math/amdgpu/lgamma.cpp b/libc/src/math/gpu/amdgpu/lgamma.cpp
similarity index 100%
rename from libc/src/math/amdgpu/lgamma.cpp
rename to libc/src/math/gpu/amdgpu/lgamma.cpp
diff --git a/libc/src/math/amdgpu/lgamma_r.cpp b/libc/src/math/gpu/amdgpu/lgamma_r.cpp
similarity index 100%
rename from libc/src/math/amdgpu/lgamma_r.cpp
rename to libc/src/math/gpu/amdgpu/lgamma_r.cpp
diff --git a/libc/src/math/amdgpu/llrint.cpp b/libc/src/math/gpu/amdgpu/llrint.cpp
similarity index 100%
rename from libc/src/math/amdgpu/llrint.cpp
rename to libc/src/math/gpu/amdgpu/llrint.cpp
diff --git a/libc/src/math/amdgpu/llrintf.cpp b/libc/src/math/gpu/amdgpu/llrintf.cpp
similarity index 100%
rename from libc/src/math/amdgpu/llrintf.cpp
rename to libc/src/math/gpu/amdgpu/llrintf.cpp
diff --git a/libc/src/math/amdgpu/lrint.cpp b/libc/src/math/gpu/amdgpu/lrint.cpp
similarity index 100%
rename from libc/src/math/amdgpu/lrint.cpp
rename to libc/src/math/gpu/amdgpu/lrint.cpp
diff --git a/libc/src/math/amdgpu/lrintf.cpp b/libc/src/math/gpu/amdgpu/lrintf.cpp
similarity index 100%
rename from libc/src/math/amdgpu/lrintf.cpp
rename to libc/src/math/gpu/amdgpu/lrintf.cpp
diff --git a/libc/src/math/amdgpu/scalbn.cpp b/libc/src/math/gpu/amdgpu/scalbn.cpp
similarity index 100%
rename from libc/src/math/amdgpu/scalbn.cpp
rename to libc/src/math/gpu/amdgpu/scalbn.cpp
diff --git a/libc/src/math/amdgpu/scalbnf.cpp b/libc/src/math/gpu/amdgpu/scalbnf.cpp
similarity index 100%
rename from libc/src/math/amdgpu/scalbnf.cpp
rename to libc/src/math/gpu/amdgpu/scalbnf.cpp
diff --git a/libc/src/math/amdgpu/tgamma.cpp b/libc/src/math/gpu/amdgpu/tgamma.cpp
similarity index 100%
rename from libc/src/math/amdgpu/tgamma.cpp
rename to libc/src/math/gpu/amdgpu/tgamma.cpp
diff --git a/libc/src/math/amdgpu/tgammaf.cpp b/libc/src/math/gpu/amdgpu/tgammaf.cpp
similarity index 100%
rename from libc/src/math/amdgpu/tgammaf.cpp
rename to libc/src/math/gpu/amdgpu/tgammaf.cpp
diff --git a/libc/src/math/amdgpu/ceil.cpp b/libc/src/math/gpu/ceil.cpp
similarity index 100%
rename from libc/src/math/amdgpu/ceil.cpp
rename to libc/src/math/gpu/ceil.cpp
diff --git a/libc/src/math/amdgpu/ceilf.cpp b/libc/src/math/gpu/ceilf.cpp
similarity index 100%
rename from libc/src/math/amdgpu/ceilf.cpp
rename to libc/src/math/gpu/ceilf.cpp
diff --git a/libc/src/math/amdgpu/copysign.cpp b/libc/src/math/gpu/copysign.cpp
similarity index 100%
rename from libc/src/math/amdgpu/copysign.cpp
rename to libc/src/math/gpu/copysign.cpp
diff --git a/libc/src/math/amdgpu/copysignf.cpp b/libc/src/math/gpu/copysignf.cpp
similarity index 100%
rename from libc/src/math/amdgpu/copysignf.cpp
rename to libc/src/math/gpu/copysignf.cpp
diff --git a/libc/src/math/amdgpu/fabs.cpp b/libc/src/math/gpu/fabs.cpp
similarity index 100%
rename from libc/src/math/amdgpu/fabs.cpp
rename to libc/src/math/gpu/fabs.cpp
diff --git a/libc/src/math/amdgpu/fabsf.cpp b/libc/src/math/gpu/fabsf.cpp
similarity index 100%
rename from libc/src/math/amdgpu/fabsf.cpp
rename to libc/src/math/gpu/fabsf.cpp
diff --git a/libc/src/math/amdgpu/floor.cpp b/libc/src/math/gpu/floor.cpp
similarity index 100%
rename from libc/src/math/amdgpu/floor.cpp
rename to libc/src/math/gpu/floor.cpp
diff --git a/libc/src/math/amdgpu/floorf.cpp b/libc/src/math/gpu/floorf.cpp
similarity index 100%
rename from libc/src/math/amdgpu/floorf.cpp
rename to libc/src/math/gpu/floorf.cpp
diff --git a/libc/src/math/amdgpu/fma.cpp b/libc/src/math/gpu/fma.cpp
similarity index 100%
rename from libc/src/math/amdgpu/fma.cpp
rename to libc/src/math/gpu/fma.cpp
diff --git a/libc/src/math/amdgpu/fmaf.cpp b/libc/src/math/gpu/fmaf.cpp
similarity index 100%
rename from libc/src/math/amdgpu/fmaf.cpp
rename to libc/src/math/gpu/fmaf.cpp
diff --git a/libc/src/math/nvptx/fmax.cpp b/libc/src/math/gpu/fmax.cpp
similarity index 100%
rename from libc/src/math/nvptx/fmax.cpp
rename to libc/src/math/gpu/fmax.cpp
diff --git a/libc/src/math/amdgpu/fmaxf.cpp b/libc/src/math/gpu/fmaxf.cpp
similarity index 100%
rename from libc/src/math/amdgpu/fmaxf.cpp
rename to libc/src/math/gpu/fmaxf.cpp
diff --git a/libc/src/math/amdgpu/fmin.cpp b/libc/src/math/gpu/fmin.cpp
similarity index 100%
rename from libc/src/math/amdgpu/fmin.cpp
rename to libc/src/math/gpu/fmin.cpp
diff --git a/libc/src/math/amdgpu/fminf.cpp b/libc/src/math/gpu/fminf.cpp
similarity index 100%
rename from libc/src/math/amdgpu/fminf.cpp
rename to libc/src/math/gpu/fminf.cpp
diff --git a/libc/src/math/amdgpu/nearbyint.cpp b/libc/src/math/gpu/nearbyint.cpp
similarity index 100%
rename from libc/src/math/amdgpu/nearbyint.cpp
rename to libc/src/math/gpu/nearbyint.cpp
diff --git a/libc/src/math/amdgpu/nearbyintf.cpp b/libc/src/math/gpu/nearbyintf.cpp
similarity index 100%
rename from libc/src/math/amdgpu/nearbyintf.cpp
rename to libc/src/math/gpu/nearbyintf.cpp
diff --git a/libc/src/math/gpu/nvptx/CMakeLists.txt b/libc/src/math/gpu/nvptx/CMakeLists.txt
new file mode 100644
index 00000000000000..6ddae372ef25d4
--- /dev/null
+++ b/libc/src/math/gpu/nvptx/CMakeLists.txt
@@ -0,0 +1,39 @@
+add_entrypoint_object(
+  tgamma
+  SRCS
+    tgamma.cpp
+  HDRS
+    ../../tgamma.h
+  COMPILE_OPTIONS
+    ${bitcode_link_flags}
+)
+
+add_entrypoint_object(
+  tgammaf
+  SRCS
+    tgammaf.cpp
+  HDRS
+    ../../tgammaf.h
+  COMPILE_OPTIONS
+    ${bitcode_link_flags}
+)
+
+add_entrypoint_object(
+  lgamma
+  SRCS
+    lgamma.cpp
+  HDRS
+    ../../lgamma.h
+  COMPILE_OPTIONS
+    ${bitcode_link_flags}
+)
+
+add_entrypoint_object(
+  lgamma_r
+  SRCS
+    lgamma_r.cpp
+  HDRS
+    ../../lgamma_r.h
+  COMPILE_OPTIONS
+    ${bitcode_link_flags}
+)
diff --git a/libc/src/math/nvptx/lgamma.cpp b/libc/src/math/gpu/nvptx/lgamma.cpp
similarity index 100%
rename from libc/src/math/nvptx/lgamma.cpp
rename to libc/src/math/gpu/nvptx/lgamma.cpp
diff --git a/libc/src/math/nvptx/lgamma_r.cpp b/libc/src/math/gpu/nvptx/lgamma_r.cpp
similarity index 100%
rename from libc/src/math/nvptx/lgamma_r.cpp
rename to libc/src/math/gpu/nvptx/lgamma_r.cpp
diff --git a/libc/src/math/nvptx/llrint.cpp b/libc/src/math/gpu/nvptx/llrint.cpp
similarity index 100%
rename from libc/src/math/nvptx/llrint.cpp
rename to libc/src/math/gpu/nvptx/llrint.cpp
diff --git a/libc/src/math/nvptx/llrintf.cpp b/libc/src/math/gpu/nvptx/llrintf.cpp
similarity index 100%
rename from libc/src/math/nvptx/llrintf.cpp
rename to libc/src/math/gpu/nvptx/llrintf.cpp
diff --git a/libc/src/math/nvptx/lrint.cpp b/libc/src/math/gpu/nvptx/lrint.cpp
similarity index 100%
rename from libc/src/math/nvptx/lrint.cpp
rename to libc/src/math/gpu/nvptx/lrint.cpp
diff --git a/libc/src/math/nvptx/tgamma.cpp b/libc/src/math/gpu/nvptx/tgamma.cpp
similarity index 100%
rename from libc/src/math/nvptx/tgamma.cpp
rename to libc/src/math/gpu/nvptx/tgamma.cpp
diff --git a/libc/src/math/nvptx/tgammaf.cpp b/libc/src/math/gpu/nvptx/tgammaf.cpp
similarity index 100%
rename from libc/src/math/nvptx/tgammaf.cpp
rename to libc/src/math/gpu/nvptx/tgammaf.cpp
diff --git a/libc/src/math/amdgpu/remainder.cpp b/libc/src/math/gpu/remainder.cpp
similarity index 100%
rename from libc/src/math/amdgpu/remainder.cpp
rename to libc/src/math/gpu/remainder.cpp
diff --git a/libc/src/math/amdgpu/remainderf.cpp b/libc/src/math/gpu/remainderf.cpp
similarity index 100%
rename from libc/src/math/amdgpu/remainderf.cpp
rename to libc/src/math/gpu/remainderf.cpp
diff --git a/libc/src/math/amdgpu/rint.cpp b/libc/src/math/gpu/rint.cpp
similarity index 100%
rename from libc/src/math/amdgpu/rint.cpp
rename to libc/src/math/gpu/rint.cpp
diff --git a/libc/src/math/amdgpu/rintf.cpp b/libc/src/math/gpu/rintf.cpp
similarity index 100%
rename from libc/src/math/amdgpu/rintf.cpp
rename to libc/src/math/gpu/rintf.cpp
diff --git a/libc/src/math/amdgpu/round.cpp b/libc/src/math/gpu/round.cpp
similarity index 100%
rename from libc/src/math/amdgpu/round.cpp
rename to libc/src/math/gpu/round.cpp
diff --git a/libc/src/math/amdgpu/roundf.cpp b/libc/src/math/gpu/roundf.cpp
similarity index 100%
rename from libc/src/math/amdgpu/roundf.cpp
rename to libc/src/math/gpu/roundf.cpp
diff --git a/libc/src/math/amdgpu/sqrt.cpp b/libc/src/math/gpu/sqrt.cpp
similarity index 100%
rename from libc/src/math/amdgpu/sqrt.cpp
rename to libc/src/math/gpu/sqrt.cpp
diff --git a/libc/src/math/amdgpu/sqrtf.cpp b/libc/src/math/gpu/sqrtf.cpp
similarity index 100%
rename from libc/src/math/amdgpu/sqrtf.cpp
rename to libc/src/math/gpu/sqrtf.cpp
diff --git a/libc/src/math/amdgpu/trunc.cpp b/libc/src/math/gpu/trunc.cpp
similarity index 100%
rename from libc/src/math/amdgpu/trunc.cpp
rename to libc/src/math/gpu/trunc.cpp
diff --git a/libc/src/math/amdgpu/truncf.cpp b/libc/src/math/gpu/truncf.cpp
similarity index 100%
rename from libc/src/math/amdgpu/truncf.cpp
rename to libc/src/math/gpu/truncf.cpp
diff --git a/libc/src/math/nvptx/ceil.cpp b/libc/src/math/nvptx/ceil.cpp
deleted file mode 100644
index 8834c7b560a1b9..00000000000000
--- a/libc/src/math/nvptx/ceil.cpp
+++ /dev/null
@@ -1,17 +0,0 @@
-//===-- Implementation of the ceil function for GPU -----------------------===//
-//
-// 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 "src/math/ceil.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
-
-namespace LIBC_NAMESPACE_DECL {
-
-LLVM_LIBC_FUNCTION...
[truncated]

``````````

</details>


https://github.com/llvm/llvm-project/pull/241177


More information about the libc-commits mailing list