Skip to content

[libc] Make ldexpf128/scalbnf128/scalblnf128 use emulated Float128 - #220295

Open
rigalis wants to merge 4 commits into
llvm:mainfrom
rigalis:ldexp_scalbn
Open

[libc] Make ldexpf128/scalbnf128/scalblnf128 use emulated Float128#220295
rigalis wants to merge 4 commits into
llvm:mainfrom
rigalis:ldexp_scalbn

Conversation

@rigalis

@rigalis rigalis commented Sep 1, 2026

Copy link
Copy Markdown

This makes the three exponent scaling functions ldexpf128, scalbnf128 and scalblnf128 work with the emulated Float128 type, so they can be used on platforms without native __float128.

Fixes #219759 (part of #216576).

@rigalis
rigalis requested a review from a team as a code owner September 1, 2026 16:54
@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown

Hello @rigalis 👋

Thank you for submitting a Pull Request (PR) to the LLVM Project. Since this is your first PR, here are a few useful links covering our main contribution policies and review practices.

  • All contributions to LLVM must follow our LLVM AI Tool Use Policy. In particular, if you used AI while working on this PR, remember to add a note to the PR description.
  • The LLVM Code-Review Policy and Practices document contains practical information about the PR process, including how patches are reviewed and accepted, and who can review a PR.
  • Our LLVM Developer Policy describes our expectations for code quality, commit summaries and contains notes on our CI system.

Please reply to this message to confirm that you have read these policies, especially the LLVM AI Tool Use Policy, and that any AI tool usage has been noted in the PR description.


Frequently asked questions

How do I add reviewers?

This PR will be automatically labeled, and the relevant teams will be notified. For some parts of the project, reviewers may also be added automatically.

You can also add reviewers manually using the Reviewers section on this page. If you cannot use that section, it is probably because you do not have write permissions for the repository. In that case, you can request a review by tagging reviewers in a comment using @ followed by their GitHub username.

What if there are no comments?

If you have not received any comments on your PR after a week, you can request a review by pinging the PR with a comment such as “Ping”. The common courtesy ping rate is once a week. Please remember that you are asking for volunteer time from other developers.

Are any special GitHub settings required to contribute to LLVM?

We only require contributors to have a public email address associated with their GitHub commits, see this section of LLVM Developer Policy for details.


If you have questions, feel free to leave a comment on this PR, or ask on LLVM Discord or LLVM Discourse.

Thank you,
The LLVM Community

@llvmorg-github-actions

llvmorg-github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown

@llvm/pr-subscribers-backend-amdgpu

@llvm/pr-subscribers-libc

Author: Parth Patel (rigalis)

Changes

This makes the three exponent scaling functions ldexpf128, scalbnf128 and scalblnf128 work with the emulated Float128 type, so they can be used on platforms without native __float128.

Fixes #219759 (part of #216576).


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

24 Files Affected:

  • (modified) libc/config/baremetal/aarch64/entrypoints.txt (+3-3)
  • (modified) libc/config/baremetal/arm/entrypoints.txt (+3-3)
  • (modified) libc/config/baremetal/riscv/entrypoints.txt (+3-3)
  • (modified) libc/config/darwin/aarch64/entrypoints.txt (+3-3)
  • (modified) libc/config/freebsd/x86_64/entrypoints.txt (+3-3)
  • (modified) libc/config/linux/aarch64/entrypoints.txt (+3-3)
  • (modified) libc/config/linux/riscv/entrypoints.txt (+3-3)
  • (modified) libc/config/linux/x86_64/entrypoints.txt (+3-3)
  • (modified) libc/shared/math/ldexpf128.h (-6)
  • (modified) libc/shared/math/scalblnf128.h (+1-7)
  • (modified) libc/shared/math/scalbnf128.h (+1-7)
  • (modified) libc/src/__support/math/CMakeLists.txt (+4-4)
  • (modified) libc/src/__support/math/ldexpf128.h (+5-11)
  • (modified) libc/src/__support/math/scalblnf128.h (+4-7)
  • (modified) libc/src/__support/math/scalbnf128.h (+4-7)
  • (modified) libc/src/math/generic/CMakeLists.txt (+3)
  • (modified) libc/src/math/generic/ldexpf128.cpp (+4-2)
  • (modified) libc/src/math/generic/scalblnf128.cpp (+4-1)
  • (modified) libc/src/math/generic/scalbnf128.cpp (+4-1)
  • (modified) libc/src/math/ldexpf128.h (+5)
  • (modified) libc/src/math/scalblnf128.h (+6-1)
  • (modified) libc/src/math/scalbnf128.h (+6-1)
  • (modified) libc/test/shared/shared_math_constexpr_test.cpp (+6-4)
  • (modified) libc/test/shared/shared_math_test.cpp (+8-8)
diff --git a/libc/config/baremetal/aarch64/entrypoints.txt b/libc/config/baremetal/aarch64/entrypoints.txt
index 9a296693e22eb..fad95af15ae81 100644
--- a/libc/config/baremetal/aarch64/entrypoints.txt
+++ b/libc/config/baremetal/aarch64/entrypoints.txt
@@ -412,6 +412,9 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.ffma
     libc.src.math.ffmal
     libc.src.math.floor
+    libc.src.math.ldexpf128
+    libc.src.math.scalblnf128
+    libc.src.math.scalbnf128
     libc.src.math.floorf
     libc.src.math.floorf128
     libc.src.math.floorl
@@ -779,7 +782,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.fsubf128
     libc.src.math.getpayloadf128
     libc.src.math.ilogbf128
-    libc.src.math.ldexpf128
     libc.src.math.llogbf128
     libc.src.math.logbf128
     libc.src.math.modff128
@@ -789,8 +791,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.nextupf128
     libc.src.math.remainderf128
     libc.src.math.remquof128
-    libc.src.math.scalblnf128
-    libc.src.math.scalbnf128
     libc.src.math.setpayloadf128
     libc.src.math.setpayloadsigf128
     libc.src.math.totalorderf128
diff --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt
index 7ac1a9ce0d35f..24a39419fedbb 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -424,6 +424,9 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.ffma
     libc.src.math.ffmal
     libc.src.math.floor
+    libc.src.math.ldexpf128
+    libc.src.math.scalblnf128
+    libc.src.math.scalbnf128
     libc.src.math.floorf
     libc.src.math.floorf128
     libc.src.math.floorl
@@ -790,7 +793,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.fsubf128
     libc.src.math.getpayloadf128
     libc.src.math.ilogbf128
-    libc.src.math.ldexpf128
     libc.src.math.llogbf128
     libc.src.math.logbf128
     libc.src.math.modff128
@@ -800,8 +802,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.nextupf128
     libc.src.math.remainderf128
     libc.src.math.remquof128
-    libc.src.math.scalblnf128
-    libc.src.math.scalbnf128
     libc.src.math.setpayloadf128
     libc.src.math.setpayloadsigf128
     libc.src.math.totalorderf128
diff --git a/libc/config/baremetal/riscv/entrypoints.txt b/libc/config/baremetal/riscv/entrypoints.txt
index 9dbaf71d285ee..4b4690f433ebc 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -420,6 +420,9 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.ffma
     libc.src.math.ffmal
     libc.src.math.floor
+    libc.src.math.ldexpf128
+    libc.src.math.scalblnf128
+    libc.src.math.scalbnf128
     libc.src.math.floorf
     libc.src.math.floorf128
     libc.src.math.floorl
@@ -787,7 +790,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.fsubf128
     libc.src.math.getpayloadf128
     libc.src.math.ilogbf128
-    libc.src.math.ldexpf128
     libc.src.math.llogbf128
     libc.src.math.logbf128
     libc.src.math.modff128
@@ -797,8 +799,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.nextupf128
     libc.src.math.remainderf128
     libc.src.math.remquof128
-    libc.src.math.scalblnf128
-    libc.src.math.scalbnf128
     libc.src.math.setpayloadf128
     libc.src.math.setpayloadsigf128
     libc.src.math.totalorderf128
diff --git a/libc/config/darwin/aarch64/entrypoints.txt b/libc/config/darwin/aarch64/entrypoints.txt
index ba397e2958cae..801dda0f51b5f 100644
--- a/libc/config/darwin/aarch64/entrypoints.txt
+++ b/libc/config/darwin/aarch64/entrypoints.txt
@@ -231,6 +231,9 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.ffma
     libc.src.math.ffmal
     libc.src.math.floor
+    libc.src.math.ldexpf128
+    libc.src.math.scalblnf128
+    libc.src.math.scalbnf128
     libc.src.math.floorf
     libc.src.math.floorf128
     libc.src.math.floorl
@@ -599,7 +602,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.fsubf128
     libc.src.math.getpayloadf128
     libc.src.math.ilogbf128
-    libc.src.math.ldexpf128
     libc.src.math.llogbf128
     libc.src.math.logbf128
     libc.src.math.modff128
@@ -609,8 +611,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.nextupf128
     libc.src.math.remainderf128
     libc.src.math.remquof128
-    libc.src.math.scalblnf128
-    libc.src.math.scalbnf128
     libc.src.math.setpayloadf128
     libc.src.math.setpayloadsigf128
     libc.src.math.totalorderf128
diff --git a/libc/config/freebsd/x86_64/entrypoints.txt b/libc/config/freebsd/x86_64/entrypoints.txt
index 2bb022667dd09..f2320521e4ab4 100644
--- a/libc/config/freebsd/x86_64/entrypoints.txt
+++ b/libc/config/freebsd/x86_64/entrypoints.txt
@@ -166,6 +166,9 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.ffma
     libc.src.math.ffmal
     libc.src.math.floor
+    libc.src.math.ldexpf128
+    libc.src.math.scalblnf128
+    libc.src.math.scalbnf128
     libc.src.math.floorf
     libc.src.math.floorf128
     libc.src.math.floorl
@@ -539,7 +542,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.fsubf128
     libc.src.math.getpayloadf128
     libc.src.math.ilogbf128
-    libc.src.math.ldexpf128
     libc.src.math.llogbf128
     libc.src.math.logbf128
     libc.src.math.modff128
@@ -549,8 +551,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.nextupf128
     libc.src.math.remainderf128
     libc.src.math.remquof128
-    libc.src.math.scalblnf128
-    libc.src.math.scalbnf128
     libc.src.math.setpayloadf128
     libc.src.math.setpayloadsigf128
     libc.src.math.totalorderf128
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 869a8c35b91f7..a4673b2033136 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -579,6 +579,9 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.fdimf
     libc.src.math.fdiml
     libc.src.math.floor
+    libc.src.math.ldexpf128
+    libc.src.math.scalblnf128
+    libc.src.math.scalbnf128
     libc.src.math.floorf
     libc.src.math.floorf128
     libc.src.math.floorl
@@ -940,7 +943,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.fsubf128
     libc.src.math.getpayloadf128
     libc.src.math.ilogbf128
-    libc.src.math.ldexpf128
     libc.src.math.llogbf128
     libc.src.math.logbf128
     libc.src.math.modff128
@@ -950,8 +952,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.nextupf128
     libc.src.math.remainderf128
     libc.src.math.remquof128
-    libc.src.math.scalblnf128
-    libc.src.math.scalbnf128
     libc.src.math.setpayloadf128
     libc.src.math.setpayloadsigf128
     libc.src.math.totalorderf128
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index e7846fbf40d91..e1f84d0ec7482 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -648,6 +648,9 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.ffma
     libc.src.math.ffmal
     libc.src.math.floor
+    libc.src.math.ldexpf128
+    libc.src.math.scalblnf128
+    libc.src.math.scalbnf128
     libc.src.math.floorf
     libc.src.math.floorf128
     libc.src.math.floorl
@@ -1026,7 +1029,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.fsubf128
     libc.src.math.getpayloadf128
     libc.src.math.ilogbf128
-    libc.src.math.ldexpf128
     libc.src.math.llogbf128
     libc.src.math.logbf128
     libc.src.math.modff128
@@ -1036,8 +1038,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.nextupf128
     libc.src.math.remainderf128
     libc.src.math.remquof128
-    libc.src.math.scalblnf128
-    libc.src.math.scalbnf128
     libc.src.math.setpayloadf128
     libc.src.math.setpayloadsigf128
     libc.src.math.totalorderf128
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index d087d955bca16..c162a7abdc609 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -657,6 +657,9 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.ffma
     libc.src.math.ffmal
     libc.src.math.floor
+    libc.src.math.ldexpf128
+    libc.src.math.scalblnf128
+    libc.src.math.scalbnf128
     libc.src.math.floorf
     libc.src.math.floorf128
     libc.src.math.floorl
@@ -1035,7 +1038,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.fsubf128
     libc.src.math.getpayloadf128
     libc.src.math.ilogbf128
-    libc.src.math.ldexpf128
     libc.src.math.llogbf128
     libc.src.math.logbf128
     libc.src.math.modff128
@@ -1045,8 +1047,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.nextupf128
     libc.src.math.remainderf128
     libc.src.math.remquof128
-    libc.src.math.scalblnf128
-    libc.src.math.scalbnf128
     libc.src.math.setpayloadf128
     libc.src.math.setpayloadsigf128
     libc.src.math.totalorderf128
diff --git a/libc/shared/math/ldexpf128.h b/libc/shared/math/ldexpf128.h
index d221d71665516..91bd7bf3c321f 100644
--- a/libc/shared/math/ldexpf128.h
+++ b/libc/shared/math/ldexpf128.h
@@ -9,10 +9,6 @@
 #ifndef LLVM_LIBC_SHARED_MATH_LDEXPF128_H
 #define LLVM_LIBC_SHARED_MATH_LDEXPF128_H
 
-#include "include/llvm-libc-types/float128.h"
-
-#ifdef LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #include "shared/libc_common.h"
 #include "src/__support/math/ldexpf128.h"
 
@@ -24,6 +20,4 @@ using math::ldexpf128;
 } // namespace shared
 } // namespace LIBC_NAMESPACE_DECL
 
-#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #endif // LLVM_LIBC_SHARED_MATH_LDEXPF128_H
diff --git a/libc/shared/math/scalblnf128.h b/libc/shared/math/scalblnf128.h
index dfb15bed117cf..3953ea59401eb 100644
--- a/libc/shared/math/scalblnf128.h
+++ b/libc/shared/math/scalblnf128.h
@@ -1,4 +1,4 @@
-//===-- Shared scalblnf128 function -----------------------------*- C++ -*-===//
+//===-- Shared scalblnf128 function -------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -9,10 +9,6 @@
 #ifndef LLVM_LIBC_SHARED_MATH_SCALBLNF128_H
 #define LLVM_LIBC_SHARED_MATH_SCALBLNF128_H
 
-#include "include/llvm-libc-types/float128.h"
-
-#ifdef LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #include "shared/libc_common.h"
 #include "src/__support/math/scalblnf128.h"
 
@@ -24,6 +20,4 @@ using math::scalblnf128;
 } // namespace shared
 } // namespace LIBC_NAMESPACE_DECL
 
-#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #endif // LLVM_LIBC_SHARED_MATH_SCALBLNF128_H
diff --git a/libc/shared/math/scalbnf128.h b/libc/shared/math/scalbnf128.h
index 74c8defc0e6d3..a870b276a6dac 100644
--- a/libc/shared/math/scalbnf128.h
+++ b/libc/shared/math/scalbnf128.h
@@ -1,4 +1,4 @@
-//===-- Shared scalbnf128 function ------------------------------*- C++ -*-===//
+//===-- Shared scalbnf128 function -------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -9,10 +9,6 @@
 #ifndef LLVM_LIBC_SHARED_MATH_SCALBNF128_H
 #define LLVM_LIBC_SHARED_MATH_SCALBNF128_H
 
-#include "include/llvm-libc-types/float128.h"
-
-#ifdef LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #include "shared/libc_common.h"
 #include "src/__support/math/scalbnf128.h"
 
@@ -24,6 +20,4 @@ using math::scalbnf128;
 } // namespace shared
 } // namespace LIBC_NAMESPACE_DECL
 
-#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #endif // LLVM_LIBC_SHARED_MATH_SCALBNF128_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 272e9425a4e1e..809d90fe3df69 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -2621,7 +2621,7 @@ add_header_library(
     scalblnf128.h
   DEPENDS
     libc.hdr.float_macros
-    libc.include.llvm-libc-types.float128
+    libc.src.__support.FPUtil.float128
     libc.src.__support.FPUtil.manipulation_functions
     libc.src.__support.macros.config
 )
@@ -2684,7 +2684,7 @@ add_header_library(
     scalbnf128.h
   DEPENDS
     libc.hdr.float_macros
-    libc.include.llvm-libc-types.float128
+    libc.src.__support.FPUtil.float128
     libc.src.__support.FPUtil.manipulation_functions
     libc.src.__support.macros.config
 )
@@ -4039,9 +4039,9 @@ add_header_library(
   HDRS
     ldexpf128.h
   DEPENDS
-    libc.src.__support.macros.properties.types
+    libc.src.__support.FPUtil.float128
     libc.src.__support.FPUtil.manipulation_functions
-    libc.include.llvm-libc-types.float128
+    libc.src.__support.macros.config
 )
 
 add_header_library(
diff --git a/libc/src/__support/math/ldexpf128.h b/libc/src/__support/math/ldexpf128.h
index 74e4c354ff8fe..e543d2870f2f7 100644
--- a/libc/src/__support/math/ldexpf128.h
+++ b/libc/src/__support/math/ldexpf128.h
@@ -1,4 +1,4 @@
-//===-- Implementation header for ldexpf ------------------------*- C++ -*-===//
+//===-- Implementation header for ldexpf128 ---------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -9,26 +9,20 @@
 #ifndef LLVM_LIBC_SRC___SUPPORT_MATH_LDEXPF128_H
 #define LLVM_LIBC_SRC___SUPPORT_MATH_LDEXPF128_H
 
-#include "include/llvm-libc-types/float128.h"
-
-#ifdef LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #include "src/__support/FPUtil/ManipulationFunctions.h"
-#include "src/__support/common.h"
+#include "src/__support/FPUtil/float128.h"
 #include "src/__support/macros/config.h"
 
 namespace LIBC_NAMESPACE_DECL {
-
 namespace math {
 
-LIBC_INLINE constexpr float128 ldexpf128(float128 x, int exp) {
+using LIBC_NAMESPACE::fputil::Float128;
+
+LIBC_INLINE constexpr Float128 ldexpf128(Float128 x, int exp) {
   return fputil::ldexp(x, exp);
 }
 
 } // namespace math
-
 } // namespace LIBC_NAMESPACE_DECL
 
-#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #endif // LLVM_LIBC_SRC___SUPPORT_MATH_LDEXPF128_H
diff --git a/libc/src/__support/math/scalblnf128.h b/libc/src/__support/math/scalblnf128.h
index 6bd6dd92b7eb1..d0947e1e168b1 100644
--- a/libc/src/__support/math/scalblnf128.h
+++ b/libc/src/__support/math/scalblnf128.h
@@ -9,12 +9,9 @@
 #ifndef LLVM_LIBC_SRC___SUPPORT_MATH_SCALBLNF128_H
 #define LLVM_LIBC_SRC___SUPPORT_MATH_SCALBLNF128_H
 
-#include "include/llvm-libc-types/float128.h"
-
-#ifdef LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #include "hdr/float_macros.h"
 #include "src/__support/FPUtil/ManipulationFunctions.h"
+#include "src/__support/FPUtil/float128.h"
 #include "src/__support/macros/config.h"
 
 #if FLT_RADIX != 2
@@ -24,13 +21,13 @@
 namespace LIBC_NAMESPACE_DECL {
 namespace math {
 
-LIBC_INLINE constexpr float128 scalblnf128(float128 x, long n) {
+using LIBC_NAMESPACE::fputil::Float128;
+
+LIBC_INLINE constexpr Float128 scalblnf128(Float128 x, long n) {
   return fputil::ldexp(x, n);
 }
 
 } // namespace math
 } // namespace LIBC_NAMESPACE_DECL
 
-#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #endif // LLVM_LIBC_SRC___SUPPORT_MATH_SCALBLNF128_H
diff --git a/libc/src/__support/math/scalbnf128.h b/libc/src/__support/math/scalbnf128.h
index bb9b3ecfa4024..98aadb1f6165b 100644
--- a/libc/src/__support/math/scalbnf128.h
+++ b/libc/src/__support/math/scalbnf128.h
@@ -9,12 +9,9 @@
 #ifndef LLVM_LIBC_SRC___SUPPORT_MATH_SCALBNF128_H
 #define LLVM_LIBC_SRC___SUPPORT_MATH_SCALBNF128_H
 
-#include "include/llvm-libc-types/float128.h"
-
-#ifdef LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #include "hdr/float_macros.h"
 #include "src/__support/FPUtil/ManipulationFunctions.h"
+#include "src/__support/FPUtil/float128.h"
 #include "src/__support/macros/config.h"
 
 #if FLT_RADIX != 2
@@ -24,13 +21,13 @@
 namespace LIBC_NAMESPACE_DECL {
 namespace math {
 
-LIBC_INLINE constexpr float128 scalbnf128(float128 x, int n) {
+using LIBC_NAMESPACE::fputil::Float128;
+
+LIBC_INLINE constexpr Float128 scalbnf128(Float128 x, int n) {
   return fputil::ldexp(x, n);
 }
 
 } // namespace math
 } // namespace LIBC_NAMESPACE_DECL
 
-#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #endif // LLVM_LIBC_SRC___SUPPORT_MATH_SCALBNF128_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 71f610d9f8281..274d679bb8593 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -1733,6 +1733,7 @@ add_entrypoint_object(
   HDRS
     ../ldexpf128.h
   DEPENDS
+    libc.src.__support.CPP.bit
     libc.src.__support.math.ldexpf128
 )
 
@@ -4118,6 +4119,7 @@ add_entrypoint_object(
   HDRS
     ../scalblnf128.h
   DEPENDS
+    libc.src.__support.CPP.bit
     libc.src.__support.math.scalblnf128
 )
 
@@ -4178,6 +4180,7 @@ add_entrypoint_object(
   HDRS
     ../scalbnf128.h
   DEPENDS
+    libc.src.__support.CPP.bit
     libc.src.__support.math.scalbnf128
 )
 
diff --git a/libc/src/math/generic/ldexpf128.cpp b/libc/src/math/generic/ldexpf128.cpp
index 40afa5b285bcd..13c64041b7eda 100644
--- a/libc/src/math/generic/ldexpf128.cpp
+++ b/libc/src/math/generic/ldexpf128.cpp
@@ -7,13 +7,15 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/ldexpf128.h"
-
+#include "src/__support/CPP/bit.h"
 #include "src/__support/math/ldexpf128.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
+using LIBC_NAMESPACE::fputil::Float128;
+
 LLVM_LIBC_FUNCTION(float128, ldexpf128, (float128 x, int exp)) {
-  return math::ldexpf128(x, exp);
+  return cpp::bit_cast<float128>(math::ldexpf128(cpp::bit_cast<Float128>(x), exp));
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/scalblnf128.cpp b/libc/src/math/generic/scalblnf128.cpp
index 151b75a913dac..31428084a5951 100644
--- a/libc/src/math/generic/scalblnf128.cpp
+++ b/libc/src/math/generic/scalblnf128.cpp
@@ -7,12 +7,15 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/scalblnf128.h"
+#include "src/__support/CPP/bit.h"
 #include "src/__support/math/scalblnf128.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
+using LIBC_NAMESPACE::fputil::Float128;
+
 LLVM_LIBC_FUNCTION(float128, scalblnf128, (float128 x, long n)) {
-  return math::scalblnf128(x, n);
+  return cpp::bit_cast<float128>(math::scalblnf128(cpp::bit_cast<Float128>(x), n));
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/scalbnf128.cpp b/libc/src/math/generic/scalbnf128.cpp
index f2655a3782f33..0923372dc6c53 100644
--- a/libc/src/math/generic/scalbnf128.cpp
+++ b/libc/src/math/generic/scalbnf128.cpp
@@ -7,12 +7,15 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/scalbnf128.h"
+#include "src/__support/CPP/bit.h"
 #include "src/__support/math/scalbnf128.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
+using LIBC_NAMESPACE::fputil::Float128;
+
 LLVM_LIBC_FUNCTION(float128, scalbnf128, (float128 x, int n)) {
-  return math::scalbnf128(x, n);
+  return cpp::bit_cast<float128>(math::scalbnf128(cpp::bit_cast<Float128>(x), n));
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/ldexpf128.h b/libc/src/math/ldexpf128.h
index 74c3ef612166e..64e1e07ed80b3 100644
--- a/libc/src/math/ldexpf128.h
+++ b/libc/src/math/ldexpf128.h
@@ -9,11 +9,16 @@
 #ifndef LLVM_LIBC_SRC_MATH_LDEXPF128_H
 #define LLVM_LIBC_SRC_MATH_LDEXPF128_H
 
+#include "src/__support/FPUtil/float128.h"
 #include "src/__support/macros/config.h"
 #include "src/__support/macros/properties/types.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
+#ifndef LIBC_TYPES_HAS_NATIVE_FLOAT128
+using float128 = LIBC_NAMESPACE::fputil::Float128;
+#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
+
 float128 ldexpf128(float128 x, int exp);
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/scalblnf128.h b/libc/src/math/scalblnf128.h
index b9b7a862f66f6..35ba8ae5f0095 100644
--- a/libc/src/math/scalblnf128.h
+++ b/libc/src/math/scalblnf128.h
@@ -1,4 +1,4 @@
-//===-- Implementation header for scalblnf128 -------------------*- C++ -*-===//
+//===-- Implementation header for scalblnf128 ---------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -9,11 +9,16 @@
 #ifndef LLVM_LIBC_SRC_MATH_SCALBLNF128_H
 #define LLVM_LIBC_SRC_MATH_SCALBLNF128_H
 
+#include "src/__support/FPUtil/float128.h"
 #include "src/__support/macros/config.h"
 #include "src/__support/macros/properties/types.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
+#ifndef LIBC_TYPES...
[truncated]

@llvmorg-github-actions llvmorg-github-actions Bot added the bazel "Peripheral" support tier build system: utils/bazel label Sep 1, 2026
@Sukumarsawant
Sukumarsawant self-requested a review September 1, 2026 18:42

@Sukumarsawant Sukumarsawant left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're on the right track for this one !
Some changes and missed parts:

  • Missed adding smoke tests too.
  • Also add src/math (MPFR-based tests).

Additionally, also check the 80-character-wide header comment for every file and add entry points similar to bf16 for reference.

Comment thread libc/config/baremetal/aarch64/entrypoints.txt Outdated
Comment thread libc/config/baremetal/arm/entrypoints.txt Outdated
Comment thread libc/config/linux/x86_64/entrypoints.txt
Comment thread libc/shared/math/scalblnf128.h Outdated
Comment thread libc/shared/math/scalbnf128.h Outdated
Comment thread libc/src/math/scalblnf128.h Outdated
Comment thread libc/src/math/scalbnf128.h Outdated
Comment thread libc/test/shared/shared_math_constexpr_test.cpp Outdated
Comment thread libc/src/math/scalbnf128.h Outdated
Comment thread libc/test/shared/shared_math_test.cpp Outdated
Comment thread libc/test/src/math/CMakeLists.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend:AMDGPU bazel "Peripheral" support tier build system: utils/bazel libc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[libc] Modify Exponent scaling functions to work with emulated Float128

2 participants