[libc-commits] [libc] [llvm] [libc][math] Refactor sinf16 implementation to header-only in src/__support/math folder. (PR #178062)

Nico Weber via libc-commits libc-commits at lists.llvm.org
Mon Jan 26 19:21:10 PST 2026


https://github.com/nico updated https://github.com/llvm/llvm-project/pull/178062

>From d7f8f1e9099be304cf7dee3a466d12c21a573c6a Mon Sep 17 00:00:00 2001
From: Nico Weber <thakis at chromium.org>
Date: Mon, 26 Jan 2026 16:53:09 -0500
Subject: [PATCH 1/5] [libc][math] Refactor sinf16 implementation to
 header-only in src/__support/math folder.

Part of #147386

in preparation for:
https://discourse.llvm.org/t/rfc-make-clang-builtin-math-functions-constexpr-with-llvm-libc-to-support-c-23-constexpr-math-functions/86450
---
 libc/shared/math.h                            |   1 +
 libc/shared/math/sinf16.h                     |  23 +++
 libc/src/__support/math/CMakeLists.txt        |  17 +++
 libc/src/__support/math/sinf16.h              | 131 ++++++++++++++++++
 libc/src/math/generic/CMakeLists.txt          |  13 +-
 libc/src/math/generic/sinf16.cpp              | 104 +-------------
 libc/test/shared/CMakeLists.txt               |   1 +
 libc/test/shared/shared_math_test.cpp         |   1 +
 .../llvm-project-overlay/libc/BUILD.bazel     |  14 +-
 9 files changed, 188 insertions(+), 117 deletions(-)
 create mode 100644 libc/shared/math/sinf16.h
 create mode 100644 libc/src/__support/math/sinf16.h

diff --git a/libc/shared/math.h b/libc/shared/math.h
index 170a2d6b1d4be..c3ac293390e94 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -88,6 +88,7 @@
 #include "math/rsqrtf16.h"
 #include "math/sin.h"
 #include "math/sinf.h"
+#include "math/sinf16.h"
 #include "math/sinhf.h"
 #include "math/sinhf16.h"
 #include "math/tan.h"
diff --git a/libc/shared/math/sinf16.h b/libc/shared/math/sinf16.h
new file mode 100644
index 0000000000000..4c39d8225f672
--- /dev/null
+++ b/libc/shared/math/sinf16.h
@@ -0,0 +1,23 @@
+//===-- Shared sinf16 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.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_SINF16_H
+#define LLVM_LIBC_SHARED_MATH_SINF16_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/sinf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::sinf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_SINF16_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index f95155a70a08d..57c64370deb9d 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -1125,6 +1125,23 @@ add_header_library(
     libc.src.__support.common
 )
 
+add_header_library(
+  sinf16
+  HDRS
+    sinf16.h
+  DEPENDS
+    .sincosf16_utils
+    libc.hdr.errno_macros
+    libc.hdr.fenv_macros
+    libc.src.__support.FPUtil.cast
+    libc.src.__support.FPUtil.except_value_utils
+    libc.src.__support.FPUtil.fenv_impl
+    libc.src.__support.FPUtil.fp_bits
+    libc.src.__support.FPUtil.multiply_add
+    libc.src.__support.macros.optimization
+    libc.src.__support.macros.properties.types
+)
+
 add_header_library(
   sinhfcoshf_utils
   HDRS
diff --git a/libc/src/__support/math/sinf16.h b/libc/src/__support/math/sinf16.h
new file mode 100644
index 0000000000000..68659852b0f9c
--- /dev/null
+++ b/libc/src/__support/math/sinf16.h
@@ -0,0 +1,131 @@
+//===-- Half-precision sin(x) 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_SINF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_SINF16_H
+
+
+#include "hdr/errno_macros.h"
+#include "hdr/fenv_macros.h"
+#include "src/__support/FPUtil/FEnvImpl.h"
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/FPUtil/cast.h"
+#include "src/__support/FPUtil/except_value_utils.h"
+#include "src/__support/FPUtil/multiply_add.h"
+#include "src/__support/macros/optimization.h"
+#include "sincosf16_utils.h"
+
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+namespace sinf16_internal {
+
+#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+LIBC_INLINE_VAR constexpr size_t N_EXCEPTS = 4;
+
+LIBC_INLINE_VAR constexpr fputil::ExceptValues<float16, N_EXCEPTS> SINF16_EXCEPTS{{
+    // (input, RZ output, RU offset, RD offset, RN offset)
+    {0x2b45, 0x2b43, 1, 0, 1},
+    {0x585c, 0x3ba3, 1, 0, 1},
+    {0x5cb0, 0xbbff, 0, 1, 0},
+    {0x51f5, 0xb80f, 0, 1, 0},
+}};
+#endif // !LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+
+} // namespace sinf16_internal
+
+LIBC_INLINE static float16 sinf16(float16 x) {
+  using namespace sinf16_internal;
+  using namespace sincosf16_internal;
+  using FPBits = fputil::FPBits<float16>;
+  FPBits xbits(x);
+
+  uint16_t x_u = xbits.uintval();
+  uint16_t x_abs = x_u & 0x7fff;
+  float xf = x;
+
+  // Range reduction:
+  // For |x| > pi/32, we perform range reduction as follows:
+  // Find k and y such that:
+  //   x = (k + y) * pi/32
+  //   k is an integer, |y| < 0.5
+  //
+  // This is done by performing:
+  //   k = round(x * 32/pi)
+  //   y = x * 32/pi - k
+  //
+  // Once k and y are computed, we then deduce the answer by the sine of sum
+  // formula:
+  //   sin(x) = sin((k + y) * pi/32)
+  //   	      = sin(k * pi/32) * cos(y * pi/32) +
+  //   	        sin(y * pi/32) * cos(k * pi/32)
+
+#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+  // Handle exceptional values
+  bool x_sign = x_u >> 15;
+
+  if (auto r = SINF16_EXCEPTS.lookup_odd(x_abs, x_sign);
+      LIBC_UNLIKELY(r.has_value()))
+    return r.value();
+#endif // !LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+
+  int rounding = fputil::quick_get_round();
+
+  // Exhaustive tests show that for |x| <= 0x1.f4p-11, 1ULP rounding errors
+  // occur. To fix this, the following apply:
+  if (LIBC_UNLIKELY(x_abs <= 0x13d0)) {
+    // sin(+/-0) = +/-0
+    if (LIBC_UNLIKELY(x_abs == 0U))
+      return x;
+
+    // When x > 0, and rounding upward, sin(x) == x.
+    // When x < 0, and rounding downward, sin(x) == x.
+    if ((rounding == FE_UPWARD && xbits.is_pos()) ||
+        (rounding == FE_DOWNWARD && xbits.is_neg()))
+      return x;
+
+    // When x < 0, and rounding upward, sin(x) == (x - 1ULP)
+    if (rounding == FE_UPWARD && xbits.is_neg()) {
+      x_u--;
+      return FPBits(x_u).get_val();
+    }
+  }
+
+  if (xbits.is_inf_or_nan()) {
+    if (xbits.is_signaling_nan()) {
+      fputil::raise_except_if_required(FE_INVALID);
+      return FPBits::quiet_nan().get_val();
+    }
+
+    if (xbits.is_inf()) {
+      fputil::set_errno_if_required(EDOM);
+      fputil::raise_except_if_required(FE_INVALID);
+    }
+
+    return x + FPBits::quiet_nan().get_val();
+  }
+
+  float sin_k, cos_k, sin_y, cosm1_y;
+  sincosf16_eval(xf, sin_k, cos_k, sin_y, cosm1_y);
+
+  if (LIBC_UNLIKELY(sin_y == 0 && sin_k == 0))
+    return FPBits::zero(xbits.sign()).get_val();
+
+  // Since, cosm1_y = cos_y - 1, therefore:
+  //   sin(x) = cos_k * sin_y + sin_k + (cosm1_y * sin_k)
+  return fputil::cast<float16>(fputil::multiply_add(
+      sin_y, cos_k, fputil::multiply_add(cosm1_y, sin_k, sin_k)));
+}
+
+} // namespace math
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_SINF16_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index bea38050edcf2..74ae335f13106 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -383,18 +383,7 @@ add_entrypoint_object(
   HDRS
     ../sinf16.h
   DEPENDS
-    libc.hdr.errno_macros
-    libc.hdr.fenv_macros
-    libc.src.__support.FPUtil.cast
-    libc.src.__support.FPUtil.fenv_impl
-    libc.src.__support.FPUtil.fp_bits
-    libc.src.__support.FPUtil.except_value_utils
-    libc.src.__support.FPUtil.multiply_add
-    libc.src.__support.macros.optimization
-    libc.src.__support.macros.properties.types
-    libc.src.__support.math.sincosf16_utils
-  COMPILE_OPTIONS
-    ${libc_opt_high_flag}
+    libc.src.__support.math.sinf16
 )
 
 add_entrypoint_object(
diff --git a/libc/src/math/generic/sinf16.cpp b/libc/src/math/generic/sinf16.cpp
index 2b579202ea111..611897026cd8f 100644
--- a/libc/src/math/generic/sinf16.cpp
+++ b/libc/src/math/generic/sinf16.cpp
@@ -7,110 +7,10 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/sinf16.h"
-#include "hdr/errno_macros.h"
-#include "hdr/fenv_macros.h"
-#include "src/__support/FPUtil/FEnvImpl.h"
-#include "src/__support/FPUtil/FPBits.h"
-#include "src/__support/FPUtil/cast.h"
-#include "src/__support/FPUtil/except_value_utils.h"
-#include "src/__support/FPUtil/multiply_add.h"
-#include "src/__support/macros/optimization.h"
-#include "src/__support/math/sincosf16_utils.h"
+#include "src/__support/math/sinf16.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
-#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
-constexpr size_t N_EXCEPTS = 4;
-
-constexpr fputil::ExceptValues<float16, N_EXCEPTS> SINF16_EXCEPTS{{
-    // (input, RZ output, RU offset, RD offset, RN offset)
-    {0x2b45, 0x2b43, 1, 0, 1},
-    {0x585c, 0x3ba3, 1, 0, 1},
-    {0x5cb0, 0xbbff, 0, 1, 0},
-    {0x51f5, 0xb80f, 0, 1, 0},
-}};
-#endif // !LIBC_MATH_HAS_SKIP_ACCURATE_PASS
-
-LLVM_LIBC_FUNCTION(float16, sinf16, (float16 x)) {
-  using namespace sincosf16_internal;
-  using FPBits = fputil::FPBits<float16>;
-  FPBits xbits(x);
-
-  uint16_t x_u = xbits.uintval();
-  uint16_t x_abs = x_u & 0x7fff;
-  float xf = x;
-
-  // Range reduction:
-  // For |x| > pi/32, we perform range reduction as follows:
-  // Find k and y such that:
-  //   x = (k + y) * pi/32
-  //   k is an integer, |y| < 0.5
-  //
-  // This is done by performing:
-  //   k = round(x * 32/pi)
-  //   y = x * 32/pi - k
-  //
-  // Once k and y are computed, we then deduce the answer by the sine of sum
-  // formula:
-  //   sin(x) = sin((k + y) * pi/32)
-  //   	      = sin(k * pi/32) * cos(y * pi/32) +
-  //   	        sin(y * pi/32) * cos(k * pi/32)
-
-#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
-  // Handle exceptional values
-  bool x_sign = x_u >> 15;
-
-  if (auto r = SINF16_EXCEPTS.lookup_odd(x_abs, x_sign);
-      LIBC_UNLIKELY(r.has_value()))
-    return r.value();
-#endif // !LIBC_MATH_HAS_SKIP_ACCURATE_PASS
-
-  int rounding = fputil::quick_get_round();
-
-  // Exhaustive tests show that for |x| <= 0x1.f4p-11, 1ULP rounding errors
-  // occur. To fix this, the following apply:
-  if (LIBC_UNLIKELY(x_abs <= 0x13d0)) {
-    // sin(+/-0) = +/-0
-    if (LIBC_UNLIKELY(x_abs == 0U))
-      return x;
-
-    // When x > 0, and rounding upward, sin(x) == x.
-    // When x < 0, and rounding downward, sin(x) == x.
-    if ((rounding == FE_UPWARD && xbits.is_pos()) ||
-        (rounding == FE_DOWNWARD && xbits.is_neg()))
-      return x;
-
-    // When x < 0, and rounding upward, sin(x) == (x - 1ULP)
-    if (rounding == FE_UPWARD && xbits.is_neg()) {
-      x_u--;
-      return FPBits(x_u).get_val();
-    }
-  }
-
-  if (xbits.is_inf_or_nan()) {
-    if (xbits.is_signaling_nan()) {
-      fputil::raise_except_if_required(FE_INVALID);
-      return FPBits::quiet_nan().get_val();
-    }
-
-    if (xbits.is_inf()) {
-      fputil::set_errno_if_required(EDOM);
-      fputil::raise_except_if_required(FE_INVALID);
-    }
-
-    return x + FPBits::quiet_nan().get_val();
-  }
-
-  float sin_k, cos_k, sin_y, cosm1_y;
-  sincosf16_eval(xf, sin_k, cos_k, sin_y, cosm1_y);
-
-  if (LIBC_UNLIKELY(sin_y == 0 && sin_k == 0))
-    return FPBits::zero(xbits.sign()).get_val();
-
-  // Since, cosm1_y = cos_y - 1, therefore:
-  //   sin(x) = cos_k * sin_y + sin_k + (cosm1_y * sin_k)
-  return fputil::cast<float16>(fputil::multiply_add(
-      sin_y, cos_k, fputil::multiply_add(cosm1_y, sin_k, sin_k)));
-}
+LLVM_LIBC_FUNCTION(float16, sinf16, (float16 x)) { return math::sinf16(x); }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 33084673b7150..e787658d16834 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -85,6 +85,7 @@ add_fp_unittest(
     libc.src.__support.math.rsqrtf16
     libc.src.__support.math.sin
     libc.src.__support.math.sinf
+    libc.src.__support.math.sinf16
     libc.src.__support.math.sinhf
     libc.src.__support.math.sinhf16
     libc.src.__support.math.tan
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 9bdbd483b0af0..f698768b00697 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -52,6 +52,7 @@ TEST(LlvmLibcSharedMathTest, AllFloat16) {
 
   EXPECT_FP_EQ(0x1.921fb6p+0f16, LIBC_NAMESPACE::shared::acosf16(0.0f16));
   EXPECT_FP_EQ(0x1p+0f16, LIBC_NAMESPACE::shared::f16sqrtl(1.0L));
+  EXPECT_FP_EQ(0.0f16, LIBC_NAMESPACE::shared::sinf16(0.0f16));
 }
 
 #endif // LIBC_TYPES_HAS_FLOAT16
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index c1120de29f3da..47acaac1db7bb 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -3507,6 +3507,16 @@ libc_support_library(
     ],
 )
 
+libc_support_library(
+    name = "__support_math_sinf16",
+    hdrs = ["src/__support/math/sinf16.h"],
+    deps = [
+        ":__support_fputil_nearest_integer",
+        ":__support_fputil_polyeval",
+        ":__support_math_sincosf16_utils",
+    ],
+)
+
 libc_support_library(
     name = "__support_math_sinhf16",
     hdrs = ["src/__support/math/sinhf16.h"],
@@ -5148,9 +5158,7 @@ libc_math_function(
 libc_math_function(
     name = "sinf16",
     additional_deps = [
-        ":__support_fputil_nearest_integer",
-        ":__support_fputil_polyeval",
-        ":__support_math_sincosf16_utils",
+        ":__support_math_sinf16",
     ],
 )
 

>From e51f0594efcdea6c8f6b6f42ca918317ac9969a9 Mon Sep 17 00:00:00 2001
From: Nico Weber <thakis at chromium.org>
Date: Mon, 26 Jan 2026 16:55:46 -0500
Subject: [PATCH 2/5] comments, clang-format

---
 libc/src/__support/math/CMakeLists.txt | 34 +++++++++++++-------------
 libc/src/__support/math/sinf16.h       | 19 +++++++-------
 2 files changed, 26 insertions(+), 27 deletions(-)

diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 57c64370deb9d..cbb66fbcc2fa4 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -1125,23 +1125,6 @@ add_header_library(
     libc.src.__support.common
 )
 
-add_header_library(
-  sinf16
-  HDRS
-    sinf16.h
-  DEPENDS
-    .sincosf16_utils
-    libc.hdr.errno_macros
-    libc.hdr.fenv_macros
-    libc.src.__support.FPUtil.cast
-    libc.src.__support.FPUtil.except_value_utils
-    libc.src.__support.FPUtil.fenv_impl
-    libc.src.__support.FPUtil.fp_bits
-    libc.src.__support.FPUtil.multiply_add
-    libc.src.__support.macros.optimization
-    libc.src.__support.macros.properties.types
-)
-
 add_header_library(
   sinhfcoshf_utils
   HDRS
@@ -1303,6 +1286,23 @@ add_header_library(
     libc.src.__support.macros.optimization
 )
 
+add_header_library(
+  sinf16
+  HDRS
+    sinf16.h
+  DEPENDS
+    .sincosf16_utils
+    libc.hdr.errno_macros
+    libc.hdr.fenv_macros
+    libc.src.__support.FPUtil.cast
+    libc.src.__support.FPUtil.except_value_utils
+    libc.src.__support.FPUtil.fenv_impl
+    libc.src.__support.FPUtil.fp_bits
+    libc.src.__support.FPUtil.multiply_add
+    libc.src.__support.macros.optimization
+    libc.src.__support.macros.properties.types
+)
+
 add_header_library(
   sinhf
   HDRS
diff --git a/libc/src/__support/math/sinf16.h b/libc/src/__support/math/sinf16.h
index 68659852b0f9c..2fcc4e28e1cc9 100644
--- a/libc/src/__support/math/sinf16.h
+++ b/libc/src/__support/math/sinf16.h
@@ -9,17 +9,15 @@
 #ifndef LLVM_LIBC_SRC___SUPPORT_MATH_SINF16_H
 #define LLVM_LIBC_SRC___SUPPORT_MATH_SINF16_H
 
-
 #include "hdr/errno_macros.h"
 #include "hdr/fenv_macros.h"
+#include "sincosf16_utils.h"
 #include "src/__support/FPUtil/FEnvImpl.h"
 #include "src/__support/FPUtil/FPBits.h"
 #include "src/__support/FPUtil/cast.h"
 #include "src/__support/FPUtil/except_value_utils.h"
 #include "src/__support/FPUtil/multiply_add.h"
 #include "src/__support/macros/optimization.h"
-#include "sincosf16_utils.h"
-
 
 namespace LIBC_NAMESPACE_DECL {
 
@@ -30,13 +28,14 @@ namespace sinf16_internal {
 #ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
 LIBC_INLINE_VAR constexpr size_t N_EXCEPTS = 4;
 
-LIBC_INLINE_VAR constexpr fputil::ExceptValues<float16, N_EXCEPTS> SINF16_EXCEPTS{{
-    // (input, RZ output, RU offset, RD offset, RN offset)
-    {0x2b45, 0x2b43, 1, 0, 1},
-    {0x585c, 0x3ba3, 1, 0, 1},
-    {0x5cb0, 0xbbff, 0, 1, 0},
-    {0x51f5, 0xb80f, 0, 1, 0},
-}};
+LIBC_INLINE_VAR constexpr fputil::ExceptValues<float16, N_EXCEPTS>
+    SINF16_EXCEPTS{{
+        // (input, RZ output, RU offset, RD offset, RN offset)
+        {0x2b45, 0x2b43, 1, 0, 1},
+        {0x585c, 0x3ba3, 1, 0, 1},
+        {0x5cb0, 0xbbff, 0, 1, 0},
+        {0x51f5, 0xb80f, 0, 1, 0},
+    }};
 #endif // !LIBC_MATH_HAS_SKIP_ACCURATE_PASS
 
 } // namespace sinf16_internal

>From c901e68265529cf59a3451956767dfbc73bdca37 Mon Sep 17 00:00:00 2001
From: Nico Weber <thakis at chromium.org>
Date: Mon, 26 Jan 2026 22:02:41 -0500
Subject: [PATCH 3/5] windows, bazel

---
 libc/shared/math/sinf16.h                         | 6 ++++++
 libc/src/__support/math/sinf16.h                  | 6 ++++++
 utils/bazel/llvm-project-overlay/libc/BUILD.bazel | 1 +
 3 files changed, 13 insertions(+)

diff --git a/libc/shared/math/sinf16.h b/libc/shared/math/sinf16.h
index 4c39d8225f672..0b4478e305eb7 100644
--- a/libc/shared/math/sinf16.h
+++ b/libc/shared/math/sinf16.h
@@ -9,6 +9,10 @@
 #ifndef LLVM_LIBC_SHARED_MATH_SINF16_H
 #define LLVM_LIBC_SHARED_MATH_SINF16_H
 
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
 #include "shared/libc_common.h"
 #include "src/__support/math/sinf16.h"
 
@@ -20,4 +24,6 @@ using math::sinf16;
 } // namespace shared
 } // namespace LIBC_NAMESPACE_DECL
 
+#endif // LIBC_TYPES_HAS_FLOAT16
+
 #endif // LLVM_LIBC_SHARED_MATH_SINF16_H
diff --git a/libc/src/__support/math/sinf16.h b/libc/src/__support/math/sinf16.h
index 2fcc4e28e1cc9..e18d0cfbd262f 100644
--- a/libc/src/__support/math/sinf16.h
+++ b/libc/src/__support/math/sinf16.h
@@ -9,6 +9,10 @@
 #ifndef LLVM_LIBC_SRC___SUPPORT_MATH_SINF16_H
 #define LLVM_LIBC_SRC___SUPPORT_MATH_SINF16_H
 
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
 #include "hdr/errno_macros.h"
 #include "hdr/fenv_macros.h"
 #include "sincosf16_utils.h"
@@ -127,4 +131,6 @@ LIBC_INLINE static float16 sinf16(float16 x) {
 
 } // namespace LIBC_NAMESPACE_DECL
 
+#endif // LIBC_TYPES_HAS_FLOAT16
+
 #endif // LLVM_LIBC_SRC___SUPPORT_MATH_SINF16_H
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 47acaac1db7bb..39be0fb58df93 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -5159,6 +5159,7 @@ libc_math_function(
     name = "sinf16",
     additional_deps = [
         ":__support_math_sinf16",
+        ":errno",
     ],
 )
 

>From c8e8cebb7218375d74a82616d8130eddf3724f75 Mon Sep 17 00:00:00 2001
From: Nico Weber <thakis at chromium.org>
Date: Mon, 26 Jan 2026 22:06:20 -0500
Subject: [PATCH 4/5] deps for float16_macros

---
 libc/src/__support/math/CMakeLists.txt            | 1 +
 utils/bazel/llvm-project-overlay/libc/BUILD.bazel | 1 +
 2 files changed, 2 insertions(+)

diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index cbb66fbcc2fa4..2c7588a3ef242 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -1294,6 +1294,7 @@ add_header_library(
     .sincosf16_utils
     libc.hdr.errno_macros
     libc.hdr.fenv_macros
+    libc.include.llvm-libc-macros.float16_macros
     libc.src.__support.FPUtil.cast
     libc.src.__support.FPUtil.except_value_utils
     libc.src.__support.FPUtil.fenv_impl
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 39be0fb58df93..fbb6948684897 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -3514,6 +3514,7 @@ libc_support_library(
         ":__support_fputil_nearest_integer",
         ":__support_fputil_polyeval",
         ":__support_math_sincosf16_utils",
+        ":llvm_libc_macros_float16_macros",
     ],
 )
 

>From e337ffd6b91e8f467151b67bfa3a43938fa3a440 Mon Sep 17 00:00:00 2001
From: Nico Weber <thakis at chromium.org>
Date: Mon, 26 Jan 2026 22:18:28 -0500
Subject: [PATCH 5/5] restore flag

---
 libc/src/math/generic/CMakeLists.txt | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 74ae335f13106..6d701e2a1d08d 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -384,6 +384,8 @@ add_entrypoint_object(
     ../sinf16.h
   DEPENDS
     libc.src.__support.math.sinf16
+  COMPILE_OPTIONS
+    ${libc_opt_high_flag}
 )
 
 add_entrypoint_object(



More information about the libc-commits mailing list