[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 18:20:27 PST 2026


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

>From 76dfc009cdea8e8309c4cda65f5eebb5023f2d58 Mon Sep 17 00:00:00 2001
From: jinge90 <ge.jin at intel.com>
Date: Wed, 11 Nov 2026 16:47:59 +0800
Subject: [PATCH 1/2] add gpu layer to place all shared GPU math code

Signed-off-by: jinge90 <ge.jin at intel.com>
---
 libc/src/math/CMakeLists.txt                 |  51 ++--
 libc/src/math/amdgpu/CMakeLists.txt          | 303 -------------------
 libc/src/math/amdgpu/fmax.cpp                |  22 --
 libc/src/math/{nvptx => gpu}/CMakeLists.txt  |  52 +---
 libc/src/math/gpu/amdgpu/CMakeLists.txt      | 103 +++++++
 libc/src/math/{ => gpu}/amdgpu/fmod.cpp      |   0
 libc/src/math/{ => gpu}/amdgpu/fmodf.cpp     |   0
 libc/src/math/{ => gpu}/amdgpu/frexp.cpp     |   0
 libc/src/math/{ => gpu}/amdgpu/frexpf.cpp    |   0
 libc/src/math/{ => gpu}/amdgpu/ldexp.cpp     |   0
 libc/src/math/{ => gpu}/amdgpu/ldexpf.cpp    |   0
 libc/src/math/{ => gpu}/amdgpu/lgamma.cpp    |   0
 libc/src/math/{ => gpu}/amdgpu/lgamma_r.cpp  |   0
 libc/src/math/{ => gpu}/amdgpu/llrint.cpp    |   0
 libc/src/math/{ => gpu}/amdgpu/llrintf.cpp   |   0
 libc/src/math/{ => gpu}/amdgpu/lrint.cpp     |   0
 libc/src/math/{ => gpu}/amdgpu/lrintf.cpp    |   0
 libc/src/math/{ => gpu}/amdgpu/scalbn.cpp    |   0
 libc/src/math/{ => gpu}/amdgpu/scalbnf.cpp   |   0
 libc/src/math/{ => gpu}/amdgpu/tgamma.cpp    |   0
 libc/src/math/{ => gpu}/amdgpu/tgammaf.cpp   |   0
 libc/src/math/{amdgpu => gpu}/ceil.cpp       |   0
 libc/src/math/{amdgpu => gpu}/ceilf.cpp      |   0
 libc/src/math/{amdgpu => gpu}/copysign.cpp   |   0
 libc/src/math/{amdgpu => gpu}/copysignf.cpp  |   0
 libc/src/math/{amdgpu => gpu}/fabs.cpp       |   0
 libc/src/math/{amdgpu => gpu}/fabsf.cpp      |   0
 libc/src/math/{amdgpu => gpu}/floor.cpp      |   0
 libc/src/math/{amdgpu => gpu}/floorf.cpp     |   0
 libc/src/math/{amdgpu => gpu}/fma.cpp        |   0
 libc/src/math/{amdgpu => gpu}/fmaf.cpp       |   0
 libc/src/math/{nvptx => gpu}/fmax.cpp        |   0
 libc/src/math/{amdgpu => gpu}/fmaxf.cpp      |   0
 libc/src/math/{amdgpu => gpu}/fmin.cpp       |   0
 libc/src/math/{amdgpu => gpu}/fminf.cpp      |   0
 libc/src/math/{amdgpu => gpu}/nearbyint.cpp  |   0
 libc/src/math/{amdgpu => gpu}/nearbyintf.cpp |   0
 libc/src/math/gpu/nvptx/CMakeLists.txt       |  39 +++
 libc/src/math/{ => gpu}/nvptx/lgamma.cpp     |   0
 libc/src/math/{ => gpu}/nvptx/lgamma_r.cpp   |   0
 libc/src/math/{ => gpu}/nvptx/llrint.cpp     |   0
 libc/src/math/{ => gpu}/nvptx/llrintf.cpp    |   0
 libc/src/math/{ => gpu}/nvptx/lrint.cpp      |   0
 libc/src/math/{ => gpu}/nvptx/tgamma.cpp     |   0
 libc/src/math/{ => gpu}/nvptx/tgammaf.cpp    |   0
 libc/src/math/{amdgpu => gpu}/remainder.cpp  |   0
 libc/src/math/{amdgpu => gpu}/remainderf.cpp |   0
 libc/src/math/{amdgpu => gpu}/rint.cpp       |   0
 libc/src/math/{amdgpu => gpu}/rintf.cpp      |   0
 libc/src/math/{amdgpu => gpu}/round.cpp      |   0
 libc/src/math/{amdgpu => gpu}/roundf.cpp     |   0
 libc/src/math/{amdgpu => gpu}/sqrt.cpp       |   0
 libc/src/math/{amdgpu => gpu}/sqrtf.cpp      |   0
 libc/src/math/{amdgpu => gpu}/trunc.cpp      |   0
 libc/src/math/{amdgpu => gpu}/truncf.cpp     |   0
 libc/src/math/nvptx/ceil.cpp                 |  17 --
 libc/src/math/nvptx/ceilf.cpp                |  17 --
 libc/src/math/nvptx/copysign.cpp             |  19 --
 libc/src/math/nvptx/copysignf.cpp            |  19 --
 libc/src/math/nvptx/fabs.cpp                 |  17 --
 libc/src/math/nvptx/fabsf.cpp                |  17 --
 libc/src/math/nvptx/floor.cpp                |  17 --
 libc/src/math/nvptx/floorf.cpp               |  17 --
 libc/src/math/nvptx/fma.cpp                  |  19 --
 libc/src/math/nvptx/fmaf.cpp                 |  19 --
 libc/src/math/nvptx/fmaxf.cpp                |  22 --
 libc/src/math/nvptx/fmin.cpp                 |  20 --
 libc/src/math/nvptx/fminf.cpp                |  20 --
 libc/src/math/nvptx/nearbyint.cpp            |  19 --
 libc/src/math/nvptx/nearbyintf.cpp           |  19 --
 libc/src/math/nvptx/remainder.cpp            |  19 --
 libc/src/math/nvptx/remainderf.cpp           |  19 --
 libc/src/math/nvptx/rint.cpp                 |  17 --
 libc/src/math/nvptx/rintf.cpp                |  17 --
 libc/src/math/nvptx/round.cpp                |  17 --
 libc/src/math/nvptx/roundf.cpp               |  17 --
 libc/src/math/nvptx/sqrt.cpp                 |  17 --
 libc/src/math/nvptx/sqrtf.cpp                |  17 --
 libc/src/math/nvptx/trunc.cpp                |  17 --
 libc/src/math/nvptx/truncf.cpp               |  17 --
 80 files changed, 181 insertions(+), 841 deletions(-)
 delete mode 100644 libc/src/math/amdgpu/CMakeLists.txt
 delete mode 100644 libc/src/math/amdgpu/fmax.cpp
 rename libc/src/math/{nvptx => gpu}/CMakeLists.txt (79%)
 create mode 100644 libc/src/math/gpu/amdgpu/CMakeLists.txt
 rename libc/src/math/{ => gpu}/amdgpu/fmod.cpp (100%)
 rename libc/src/math/{ => gpu}/amdgpu/fmodf.cpp (100%)
 rename libc/src/math/{ => gpu}/amdgpu/frexp.cpp (100%)
 rename libc/src/math/{ => gpu}/amdgpu/frexpf.cpp (100%)
 rename libc/src/math/{ => gpu}/amdgpu/ldexp.cpp (100%)
 rename libc/src/math/{ => gpu}/amdgpu/ldexpf.cpp (100%)
 rename libc/src/math/{ => gpu}/amdgpu/lgamma.cpp (100%)
 rename libc/src/math/{ => gpu}/amdgpu/lgamma_r.cpp (100%)
 rename libc/src/math/{ => gpu}/amdgpu/llrint.cpp (100%)
 rename libc/src/math/{ => gpu}/amdgpu/llrintf.cpp (100%)
 rename libc/src/math/{ => gpu}/amdgpu/lrint.cpp (100%)
 rename libc/src/math/{ => gpu}/amdgpu/lrintf.cpp (100%)
 rename libc/src/math/{ => gpu}/amdgpu/scalbn.cpp (100%)
 rename libc/src/math/{ => gpu}/amdgpu/scalbnf.cpp (100%)
 rename libc/src/math/{ => gpu}/amdgpu/tgamma.cpp (100%)
 rename libc/src/math/{ => gpu}/amdgpu/tgammaf.cpp (100%)
 rename libc/src/math/{amdgpu => gpu}/ceil.cpp (100%)
 rename libc/src/math/{amdgpu => gpu}/ceilf.cpp (100%)
 rename libc/src/math/{amdgpu => gpu}/copysign.cpp (100%)
 rename libc/src/math/{amdgpu => gpu}/copysignf.cpp (100%)
 rename libc/src/math/{amdgpu => gpu}/fabs.cpp (100%)
 rename libc/src/math/{amdgpu => gpu}/fabsf.cpp (100%)
 rename libc/src/math/{amdgpu => gpu}/floor.cpp (100%)
 rename libc/src/math/{amdgpu => gpu}/floorf.cpp (100%)
 rename libc/src/math/{amdgpu => gpu}/fma.cpp (100%)
 rename libc/src/math/{amdgpu => gpu}/fmaf.cpp (100%)
 rename libc/src/math/{nvptx => gpu}/fmax.cpp (100%)
 rename libc/src/math/{amdgpu => gpu}/fmaxf.cpp (100%)
 rename libc/src/math/{amdgpu => gpu}/fmin.cpp (100%)
 rename libc/src/math/{amdgpu => gpu}/fminf.cpp (100%)
 rename libc/src/math/{amdgpu => gpu}/nearbyint.cpp (100%)
 rename libc/src/math/{amdgpu => gpu}/nearbyintf.cpp (100%)
 create mode 100644 libc/src/math/gpu/nvptx/CMakeLists.txt
 rename libc/src/math/{ => gpu}/nvptx/lgamma.cpp (100%)
 rename libc/src/math/{ => gpu}/nvptx/lgamma_r.cpp (100%)
 rename libc/src/math/{ => gpu}/nvptx/llrint.cpp (100%)
 rename libc/src/math/{ => gpu}/nvptx/llrintf.cpp (100%)
 rename libc/src/math/{ => gpu}/nvptx/lrint.cpp (100%)
 rename libc/src/math/{ => gpu}/nvptx/tgamma.cpp (100%)
 rename libc/src/math/{ => gpu}/nvptx/tgammaf.cpp (100%)
 rename libc/src/math/{amdgpu => gpu}/remainder.cpp (100%)
 rename libc/src/math/{amdgpu => gpu}/remainderf.cpp (100%)
 rename libc/src/math/{amdgpu => gpu}/rint.cpp (100%)
 rename libc/src/math/{amdgpu => gpu}/rintf.cpp (100%)
 rename libc/src/math/{amdgpu => gpu}/round.cpp (100%)
 rename libc/src/math/{amdgpu => gpu}/roundf.cpp (100%)
 rename libc/src/math/{amdgpu => gpu}/sqrt.cpp (100%)
 rename libc/src/math/{amdgpu => gpu}/sqrtf.cpp (100%)
 rename libc/src/math/{amdgpu => gpu}/trunc.cpp (100%)
 rename libc/src/math/{amdgpu => gpu}/truncf.cpp (100%)
 delete mode 100644 libc/src/math/nvptx/ceil.cpp
 delete mode 100644 libc/src/math/nvptx/ceilf.cpp
 delete mode 100644 libc/src/math/nvptx/copysign.cpp
 delete mode 100644 libc/src/math/nvptx/copysignf.cpp
 delete mode 100644 libc/src/math/nvptx/fabs.cpp
 delete mode 100644 libc/src/math/nvptx/fabsf.cpp
 delete mode 100644 libc/src/math/nvptx/floor.cpp
 delete mode 100644 libc/src/math/nvptx/floorf.cpp
 delete mode 100644 libc/src/math/nvptx/fma.cpp
 delete mode 100644 libc/src/math/nvptx/fmaf.cpp
 delete mode 100644 libc/src/math/nvptx/fmaxf.cpp
 delete mode 100644 libc/src/math/nvptx/fmin.cpp
 delete mode 100644 libc/src/math/nvptx/fminf.cpp
 delete mode 100644 libc/src/math/nvptx/nearbyint.cpp
 delete mode 100644 libc/src/math/nvptx/nearbyintf.cpp
 delete mode 100644 libc/src/math/nvptx/remainder.cpp
 delete mode 100644 libc/src/math/nvptx/remainderf.cpp
 delete mode 100644 libc/src/math/nvptx/rint.cpp
 delete mode 100644 libc/src/math/nvptx/rintf.cpp
 delete mode 100644 libc/src/math/nvptx/round.cpp
 delete mode 100644 libc/src/math/nvptx/roundf.cpp
 delete mode 100644 libc/src/math/nvptx/sqrt.cpp
 delete mode 100644 libc/src/math/nvptx/sqrtf.cpp
 delete mode 100644 libc/src/math/nvptx/trunc.cpp
 delete mode 100644 libc/src/math/nvptx/truncf.cpp

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(double, ceil, (double x)) { return __builtin_ceil(x); }
-
-} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/nvptx/ceilf.cpp b/libc/src/math/nvptx/ceilf.cpp
deleted file mode 100644
index 5d26a30c849cd2..00000000000000
--- a/libc/src/math/nvptx/ceilf.cpp
+++ /dev/null
@@ -1,17 +0,0 @@
-//===-- Implementation of the ceilf 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/ceilf.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
-
-namespace LIBC_NAMESPACE_DECL {
-
-LLVM_LIBC_FUNCTION(float, ceilf, (float x)) { return __builtin_ceilf(x); }
-
-} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/nvptx/copysign.cpp b/libc/src/math/nvptx/copysign.cpp
deleted file mode 100644
index 06ef36fb3595f2..00000000000000
--- a/libc/src/math/nvptx/copysign.cpp
+++ /dev/null
@@ -1,19 +0,0 @@
-//===-- Implementation of the copysign 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/copysign.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
-
-namespace LIBC_NAMESPACE_DECL {
-
-LLVM_LIBC_FUNCTION(double, copysign, (double x, double y)) {
-  return __builtin_copysign(x, y);
-}
-
-} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/nvptx/copysignf.cpp b/libc/src/math/nvptx/copysignf.cpp
deleted file mode 100644
index aea94f3577d8fb..00000000000000
--- a/libc/src/math/nvptx/copysignf.cpp
+++ /dev/null
@@ -1,19 +0,0 @@
-//===-- Implementation of the copysignf 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/copysignf.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
-
-namespace LIBC_NAMESPACE_DECL {
-
-LLVM_LIBC_FUNCTION(float, copysignf, (float x, float y)) {
-  return __builtin_copysignf(x, y);
-}
-
-} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/nvptx/fabs.cpp b/libc/src/math/nvptx/fabs.cpp
deleted file mode 100644
index bb37596b9d563d..00000000000000
--- a/libc/src/math/nvptx/fabs.cpp
+++ /dev/null
@@ -1,17 +0,0 @@
-//===-- Implementation of the fabs 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/fabs.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
-
-namespace LIBC_NAMESPACE_DECL {
-
-LLVM_LIBC_FUNCTION(double, fabs, (double x)) { return __builtin_fabs(x); }
-
-} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/nvptx/fabsf.cpp b/libc/src/math/nvptx/fabsf.cpp
deleted file mode 100644
index 2698618f3f1e1a..00000000000000
--- a/libc/src/math/nvptx/fabsf.cpp
+++ /dev/null
@@ -1,17 +0,0 @@
-//===-- Implementation of the fabsf 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/fabsf.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
-
-namespace LIBC_NAMESPACE_DECL {
-
-LLVM_LIBC_FUNCTION(float, fabsf, (float x)) { return __builtin_fabsf(x); }
-
-} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/nvptx/floor.cpp b/libc/src/math/nvptx/floor.cpp
deleted file mode 100644
index 564efa9a7da384..00000000000000
--- a/libc/src/math/nvptx/floor.cpp
+++ /dev/null
@@ -1,17 +0,0 @@
-//===-- Implementation of the floor 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/floor.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
-
-namespace LIBC_NAMESPACE_DECL {
-
-LLVM_LIBC_FUNCTION(double, floor, (double x)) { return __builtin_floor(x); }
-
-} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/nvptx/floorf.cpp b/libc/src/math/nvptx/floorf.cpp
deleted file mode 100644
index 6717c8f60c9921..00000000000000
--- a/libc/src/math/nvptx/floorf.cpp
+++ /dev/null
@@ -1,17 +0,0 @@
-//===-- Implementation of the floorf 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/floorf.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
-
-namespace LIBC_NAMESPACE_DECL {
-
-LLVM_LIBC_FUNCTION(float, floorf, (float x)) { return __builtin_floorf(x); }
-
-} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/nvptx/fma.cpp b/libc/src/math/nvptx/fma.cpp
deleted file mode 100644
index c4a117e42a3aa6..00000000000000
--- a/libc/src/math/nvptx/fma.cpp
+++ /dev/null
@@ -1,19 +0,0 @@
-//===-- Implementation of the fma 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/fma.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
-
-namespace LIBC_NAMESPACE_DECL {
-
-LLVM_LIBC_FUNCTION(double, fma, (double x, double y, double z)) {
-  return __builtin_fma(x, y, z);
-}
-
-} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/nvptx/fmaf.cpp b/libc/src/math/nvptx/fmaf.cpp
deleted file mode 100644
index c088bd5b30fea8..00000000000000
--- a/libc/src/math/nvptx/fmaf.cpp
+++ /dev/null
@@ -1,19 +0,0 @@
-//===-- Implementation of the fmaf 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/fmaf.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
-
-namespace LIBC_NAMESPACE_DECL {
-
-LLVM_LIBC_FUNCTION(float, fmaf, (float x, float y, float z)) {
-  return __builtin_fmaf(x, y, z);
-}
-
-} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/nvptx/fmaxf.cpp b/libc/src/math/nvptx/fmaxf.cpp
deleted file mode 100644
index 586fd32fee59ba..00000000000000
--- a/libc/src/math/nvptx/fmaxf.cpp
+++ /dev/null
@@ -1,22 +0,0 @@
-//===-- Implementation of the fmaxf 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/fmaxf.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(float, fmaxf, (float x, float y)) {
-  return __builtin_fmaxf(x, y);
-}
-
-} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/nvptx/fmin.cpp b/libc/src/math/nvptx/fmin.cpp
deleted file mode 100644
index 694eb664b599bd..00000000000000
--- a/libc/src/math/nvptx/fmin.cpp
+++ /dev/null
@@ -1,20 +0,0 @@
-//===-- Implementation of the fmin 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/fmin.h"
-
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
-
-namespace LIBC_NAMESPACE_DECL {
-
-LLVM_LIBC_FUNCTION(double, fmin, (double x, double y)) {
-  return __builtin_fmin(x, y);
-}
-
-} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/nvptx/fminf.cpp b/libc/src/math/nvptx/fminf.cpp
deleted file mode 100644
index 2060b71b0841f9..00000000000000
--- a/libc/src/math/nvptx/fminf.cpp
+++ /dev/null
@@ -1,20 +0,0 @@
-//===-- Implementation of the fminf 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/fminf.h"
-
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
-
-namespace LIBC_NAMESPACE_DECL {
-
-LLVM_LIBC_FUNCTION(float, fminf, (float x, float y)) {
-  return __builtin_fminf(x, y);
-}
-
-} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/nvptx/nearbyint.cpp b/libc/src/math/nvptx/nearbyint.cpp
deleted file mode 100644
index 7d78c7241d0231..00000000000000
--- a/libc/src/math/nvptx/nearbyint.cpp
+++ /dev/null
@@ -1,19 +0,0 @@
-//===-- Implementation of the GPU nearbyint 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 "src/math/nearbyint.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
-
-namespace LIBC_NAMESPACE_DECL {
-
-LLVM_LIBC_FUNCTION(double, nearbyint, (double x)) {
-  return __builtin_nearbyint(x);
-}
-
-} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/nvptx/nearbyintf.cpp b/libc/src/math/nvptx/nearbyintf.cpp
deleted file mode 100644
index 4bd20dc58fb892..00000000000000
--- a/libc/src/math/nvptx/nearbyintf.cpp
+++ /dev/null
@@ -1,19 +0,0 @@
-//===-- Implementation of the GPU nearbyintf 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 "src/math/nearbyintf.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
-
-namespace LIBC_NAMESPACE_DECL {
-
-LLVM_LIBC_FUNCTION(float, nearbyintf, (float x)) {
-  return __builtin_nearbyintf(x);
-}
-
-} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/nvptx/remainder.cpp b/libc/src/math/nvptx/remainder.cpp
deleted file mode 100644
index 9027204312e009..00000000000000
--- a/libc/src/math/nvptx/remainder.cpp
+++ /dev/null
@@ -1,19 +0,0 @@
-//===-- Implementation of the GPU remainder 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 "src/math/remainder.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
-
-namespace LIBC_NAMESPACE_DECL {
-
-LLVM_LIBC_FUNCTION(double, remainder, (double x, double y)) {
-  return __builtin_remainder(x, y);
-}
-
-} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/nvptx/remainderf.cpp b/libc/src/math/nvptx/remainderf.cpp
deleted file mode 100644
index 50df3b2ce25c19..00000000000000
--- a/libc/src/math/nvptx/remainderf.cpp
+++ /dev/null
@@ -1,19 +0,0 @@
-//===-- Implementation of the GPU remainderf 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 "src/math/remainderf.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
-
-namespace LIBC_NAMESPACE_DECL {
-
-LLVM_LIBC_FUNCTION(float, remainderf, (float x, float y)) {
-  return __builtin_remainderf(x, y);
-}
-
-} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/nvptx/rint.cpp b/libc/src/math/nvptx/rint.cpp
deleted file mode 100644
index ac6837a4abc378..00000000000000
--- a/libc/src/math/nvptx/rint.cpp
+++ /dev/null
@@ -1,17 +0,0 @@
-//===-- Implementation of the GPU rint 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 "src/math/rint.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
-
-namespace LIBC_NAMESPACE_DECL {
-
-LLVM_LIBC_FUNCTION(double, rint, (double x)) { return __builtin_rint(x); }
-
-} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/nvptx/rintf.cpp b/libc/src/math/nvptx/rintf.cpp
deleted file mode 100644
index 94093471a8d92a..00000000000000
--- a/libc/src/math/nvptx/rintf.cpp
+++ /dev/null
@@ -1,17 +0,0 @@
-//===-- Implementation of the GPU rintf 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 "src/math/rintf.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
-
-namespace LIBC_NAMESPACE_DECL {
-
-LLVM_LIBC_FUNCTION(float, rintf, (float x)) { return __builtin_rintf(x); }
-
-} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/nvptx/round.cpp b/libc/src/math/nvptx/round.cpp
deleted file mode 100644
index 0d2765f2e959fb..00000000000000
--- a/libc/src/math/nvptx/round.cpp
+++ /dev/null
@@ -1,17 +0,0 @@
-//===-- Implementation of the GPU round 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 "src/math/round.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
-
-namespace LIBC_NAMESPACE_DECL {
-
-LLVM_LIBC_FUNCTION(double, round, (double x)) { return __builtin_round(x); }
-
-} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/nvptx/roundf.cpp b/libc/src/math/nvptx/roundf.cpp
deleted file mode 100644
index 86e8ba3ac83d68..00000000000000
--- a/libc/src/math/nvptx/roundf.cpp
+++ /dev/null
@@ -1,17 +0,0 @@
-//===-- Implementation of the GPU roundf 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 "src/math/roundf.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
-
-namespace LIBC_NAMESPACE_DECL {
-
-LLVM_LIBC_FUNCTION(float, roundf, (float x)) { return __builtin_roundf(x); }
-
-} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/nvptx/sqrt.cpp b/libc/src/math/nvptx/sqrt.cpp
deleted file mode 100644
index ed83b6e5c6caec..00000000000000
--- a/libc/src/math/nvptx/sqrt.cpp
+++ /dev/null
@@ -1,17 +0,0 @@
-//===-- Implementation of the GPU sqrt 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 "src/math/sqrt.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
-
-namespace LIBC_NAMESPACE_DECL {
-
-LLVM_LIBC_FUNCTION(double, sqrt, (double x)) { return __builtin_sqrt(x); }
-
-} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/nvptx/sqrtf.cpp b/libc/src/math/nvptx/sqrtf.cpp
deleted file mode 100644
index 851922c316452a..00000000000000
--- a/libc/src/math/nvptx/sqrtf.cpp
+++ /dev/null
@@ -1,17 +0,0 @@
-//===-- Implementation of the GPU sqrtf 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 "src/math/sqrtf.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
-
-namespace LIBC_NAMESPACE_DECL {
-
-LLVM_LIBC_FUNCTION(float, sqrtf, (float x)) { return __builtin_sqrtf(x); }
-
-} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/nvptx/trunc.cpp b/libc/src/math/nvptx/trunc.cpp
deleted file mode 100644
index f60caa2a71d782..00000000000000
--- a/libc/src/math/nvptx/trunc.cpp
+++ /dev/null
@@ -1,17 +0,0 @@
-//===-- Implementation of the GPU trunc 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 "src/math/trunc.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
-
-namespace LIBC_NAMESPACE_DECL {
-
-LLVM_LIBC_FUNCTION(double, trunc, (double x)) { return __builtin_trunc(x); }
-
-} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/nvptx/truncf.cpp b/libc/src/math/nvptx/truncf.cpp
deleted file mode 100644
index a6c9b8f188f02d..00000000000000
--- a/libc/src/math/nvptx/truncf.cpp
+++ /dev/null
@@ -1,17 +0,0 @@
-//===-- Implementation of the GPU truncf 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 "src/math/truncf.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
-
-namespace LIBC_NAMESPACE_DECL {
-
-LLVM_LIBC_FUNCTION(float, truncf, (float x)) { return __builtin_truncf(x); }
-
-} // namespace LIBC_NAMESPACE_DECL

>From 306bee35b9c462031fabfed2f324b32e34cfb106 Mon Sep 17 00:00:00 2001
From: jinge90 <ge.jin at intel.com>
Date: Thu, 12 Nov 2026 10:19:53 +0800
Subject: [PATCH 2/2] Fix format issue

Signed-off-by: jinge90 <ge.jin at intel.com>
---
 libc/src/math/gpu/CMakeLists.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libc/src/math/gpu/CMakeLists.txt b/libc/src/math/gpu/CMakeLists.txt
index 29d9354c3ab01d..8691f08e17960b 100644
--- a/libc/src/math/gpu/CMakeLists.txt
+++ b/libc/src/math/gpu/CMakeLists.txt
@@ -6,7 +6,7 @@ endif()
 # 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)
+    NOT LIBC_TARGET_ARCHITECTURE_IS_NVPTX)
   return()
 endif()
 



More information about the libc-commits mailing list