[libc-commits] [libc] 4486fcb - [libc] Add proxy header for float.h. (#93504)
via libc-commits
libc-commits at lists.llvm.org
Tue May 28 16:14:29 PDT 2024
Author: lntue
Date: 2024-05-28T19:14:26-04:00
New Revision: 4486fcba756bfa4c8729673a9533578232f0bc04
URL: https://github.com/llvm/llvm-project/commit/4486fcba756bfa4c8729673a9533578232f0bc04
DIFF: https://github.com/llvm/llvm-project/commit/4486fcba756bfa4c8729673a9533578232f0bc04.diff
LOG: [libc] Add proxy header for float.h. (#93504)
This is the continuation of
https://github.com/llvm/llvm-project/pull/88674.
Fixes #88433, #90496.
---------
Co-authored-by: aniplcc <aniplccode at gmail.com>
Added:
libc/hdr/float_macros.h
Modified:
libc/hdr/CMakeLists.txt
libc/include/llvm-libc-macros/float-macros.h
libc/src/__support/macros/properties/CMakeLists.txt
libc/src/__support/macros/properties/types.h
libc/src/math/generic/CMakeLists.txt
libc/src/math/generic/scalbn.cpp
libc/src/math/generic/scalbnf.cpp
libc/src/math/generic/scalbnf128.cpp
libc/src/math/generic/scalbnl.cpp
utils/bazel/llvm-project-overlay/libc/BUILD.bazel
Removed:
################################################################################
diff --git a/libc/hdr/CMakeLists.txt b/libc/hdr/CMakeLists.txt
index 91b8cb71552a7..66b82c84dac49 100644
--- a/libc/hdr/CMakeLists.txt
+++ b/libc/hdr/CMakeLists.txt
@@ -87,4 +87,14 @@ add_proxy_header_library(
libc.include.llvm-libc-macros.time_macros
)
+add_proxy_header_library(
+ float_macros
+ HDRS
+ float_macros.h
+ DEPENDS
+ libc.include.llvm-libc-macros.float_macros
+ FULL_BUILD_DEPENDS
+ libc.include.float
+)
+
add_subdirectory(types)
diff --git a/libc/hdr/float_macros.h b/libc/hdr/float_macros.h
new file mode 100644
index 0000000000000..a0ef5e29b9868
--- /dev/null
+++ b/libc/hdr/float_macros.h
@@ -0,0 +1,22 @@
+//===-- Definition of macros from math.h ----------------------------------===//
+//
+// 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_HDR_FLOAT_MACROS_H
+#define LLVM_LIBC_HDR_FLOAT_MACROS_H
+
+#ifdef LIBC_FULL_BUILD
+
+#include "include/llvm-libc-macros/float-macros.h"
+
+#else // Overlay mode
+
+#include <float.h>
+
+#endif // LLVM_LIBC_FULL_BUILD
+
+#endif // LLVM_LIBC_HDR_FLOAT_MACROS_H
diff --git a/libc/include/llvm-libc-macros/float-macros.h b/libc/include/llvm-libc-macros/float-macros.h
index 4fe8590c5f70c..81c1df868bf6c 100644
--- a/libc/include/llvm-libc-macros/float-macros.h
+++ b/libc/include/llvm-libc-macros/float-macros.h
@@ -9,21 +9,6 @@
#ifndef LLVM_LIBC_MACROS_FLOAT_MACROS_H
#define LLVM_LIBC_MACROS_FLOAT_MACROS_H
-// Suppress `#include_next is a language extension` warnings.
-#ifdef __clang__
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wgnu-include-next"
-#pragma clang diagnostic ignored "-Winclude-next-absolute-path"
-#else // gcc
-#pragma GCC system_header
-#endif //__clang__
-
-#include_next <float.h>
-
-#ifdef __clang__
-#pragma clang diagnostic pop
-#endif //__clang__
-
#ifndef FLT_RADIX
#define FLT_RADIX __FLT_RADIX__
#endif // FLT_RADIX
@@ -32,9 +17,13 @@
#define FLT_EVAL_METHOD __FLT_EVAL_METHOD__
#endif // FLT_EVAL_METHOD
-#ifndef DECIMAL_DIG
-#define DECIMAL_DIG __DECIMAL_DIG__
-#endif // DECIMAL_DIG
+#ifndef FLT_ROUNDS
+#if __has_builtin(__builtin_flt_rounds)
+#define FLT_ROUNDS __builtin_flt_rounds()
+#else
+#define FLT_ROUNDS 1
+#endif
+#endif // FLT_ROUNDS
#ifndef FLT_DECIMAL_DIG
#define FLT_DECIMAL_DIG __FLT_DECIMAL_DIG__
@@ -48,6 +37,10 @@
#define LDBL_DECIMAL_DIG __LDBL_DECIMAL_DIG__
#endif // LDBL_DECIMAL_DIG
+#ifndef DECIMAL_DIG
+#define DECIMAL_DIG __DECIMAL_DIG__
+#endif // DECIMAL_DIG
+
#ifndef FLT_DIG
#define FLT_DIG __FLT_DIG__
#endif // FLT_DIG
@@ -97,15 +90,15 @@
#endif // LDBL_MAX
#ifndef FLT_TRUE_MIN
-#define FLT_TRUE_MIN __FLT_TRUE_MIN__
+#define FLT_TRUE_MIN __FLT_DENORM_MIN__
#endif // FLT_TRUE_MIN
#ifndef DBL_TRUE_MIN
-#define DBL_TRUE_MIN __DBL_TRUE_MIN__
+#define DBL_TRUE_MIN __DBL_DENORM_MIN__
#endif // DBL_TRUE_MIN
#ifndef LDBL_TRUE_MIN
-#define LDBL_TRUE_MIN __LDBL_TRUE_MIN__
+#define LDBL_TRUE_MIN __LDBL_DENORM_MIN__
#endif // LDBL_TRUE_MIN
#ifndef FLT_EPSILON
diff --git a/libc/src/__support/macros/properties/CMakeLists.txt b/libc/src/__support/macros/properties/CMakeLists.txt
index bbc45650f3fca..7718aeaa3de5a 100644
--- a/libc/src/__support/macros/properties/CMakeLists.txt
+++ b/libc/src/__support/macros/properties/CMakeLists.txt
@@ -33,6 +33,6 @@ add_header_library(
.compiler
.cpu_features
.os
- libc.include.llvm-libc-macros.float_macros
+ libc.hdr.float_macros
libc.include.llvm-libc-types.float128
)
diff --git a/libc/src/__support/macros/properties/types.h b/libc/src/__support/macros/properties/types.h
index d43cf99e6859b..781cf1b7a2b62 100644
--- a/libc/src/__support/macros/properties/types.h
+++ b/libc/src/__support/macros/properties/types.h
@@ -10,7 +10,7 @@
#ifndef LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_TYPES_H
#define LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_TYPES_H
-#include "include/llvm-libc-macros/float-macros.h" // LDBL_MANT_DIG
+#include "hdr/float_macros.h" // LDBL_MANT_DIG
#include "include/llvm-libc-types/float128.h" // float128
#include "src/__support/macros/properties/architectures.h"
#include "src/__support/macros/properties/compiler.h"
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index daaf505008ca1..269bc6be5d834 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -2933,6 +2933,7 @@ add_entrypoint_object(
HDRS
../scalbn.h
DEPENDS
+ libc.hdr.float_macros
libc.src.__support.FPUtil.manipulation_functions
COMPILE_OPTIONS
-O3
@@ -2945,6 +2946,7 @@ add_entrypoint_object(
HDRS
../scalbnf.h
DEPENDS
+ libc.hdr.float_macros
libc.src.__support.FPUtil.manipulation_functions
COMPILE_OPTIONS
-O3
@@ -2957,6 +2959,7 @@ add_entrypoint_object(
HDRS
../scalbnl.h
DEPENDS
+ libc.hdr.float_macros
libc.src.__support.FPUtil.manipulation_functions
COMPILE_OPTIONS
-O3
@@ -2969,6 +2972,7 @@ add_entrypoint_object(
HDRS
../scalbnf128.h
DEPENDS
+ libc.hdr.float_macros
libc.src.__support.macros.properties.types
libc.src.__support.FPUtil.manipulation_functions
COMPILE_OPTIONS
diff --git a/libc/src/math/generic/scalbn.cpp b/libc/src/math/generic/scalbn.cpp
index 3908f5892f144..207cce1550bc0 100644
--- a/libc/src/math/generic/scalbn.cpp
+++ b/libc/src/math/generic/scalbn.cpp
@@ -7,19 +7,18 @@
//===----------------------------------------------------------------------===//
#include "src/math/scalbn.h"
+#include "hdr/float_macros.h"
#include "src/__support/FPUtil/ManipulationFunctions.h"
#include "src/__support/common.h"
+#if FLT_RADIX != 2
+#error "FLT_RADIX != 2 is not supported."
+#endif
+
namespace LIBC_NAMESPACE {
LLVM_LIBC_FUNCTION(double, scalbn, (double x, int n)) {
-#if !defined(__FLT_RADIX__)
-#error __FLT_RADIX__ undefined.
-#elif __FLT_RADIX__ != 2
-#error __FLT_RADIX__!=2, unimplemented.
-#else
return fputil::ldexp(x, n);
-#endif
}
} // namespace LIBC_NAMESPACE
diff --git a/libc/src/math/generic/scalbnf.cpp b/libc/src/math/generic/scalbnf.cpp
index 4a4fa86dcfd89..e478088d3ce5a 100644
--- a/libc/src/math/generic/scalbnf.cpp
+++ b/libc/src/math/generic/scalbnf.cpp
@@ -7,19 +7,18 @@
//===----------------------------------------------------------------------===//
#include "src/math/scalbnf.h"
+#include "hdr/float_macros.h"
#include "src/__support/FPUtil/ManipulationFunctions.h"
#include "src/__support/common.h"
+#if FLT_RADIX != 2
+#error "FLT_RADIX != 2 is not supported."
+#endif
+
namespace LIBC_NAMESPACE {
LLVM_LIBC_FUNCTION(float, scalbnf, (float x, int n)) {
-#if !defined(__FLT_RADIX__)
-#error __FLT_RADIX__ undefined.
-#elif __FLT_RADIX__ != 2
-#error __FLT_RADIX__!=2, unimplemented.
-#else
return fputil::ldexp(x, n);
-#endif
}
} // namespace LIBC_NAMESPACE
diff --git a/libc/src/math/generic/scalbnf128.cpp b/libc/src/math/generic/scalbnf128.cpp
index be3d29ed27e98..5fd59611d53de 100644
--- a/libc/src/math/generic/scalbnf128.cpp
+++ b/libc/src/math/generic/scalbnf128.cpp
@@ -7,21 +7,18 @@
//===----------------------------------------------------------------------===//
#include "src/math/scalbnf128.h"
+#include "hdr/float_macros.h"
#include "src/__support/FPUtil/ManipulationFunctions.h"
#include "src/__support/common.h"
+#if FLT_RADIX != 2
+#error "FLT_RADIX != 2 is not supported."
+#endif
+
namespace LIBC_NAMESPACE {
LLVM_LIBC_FUNCTION(float128, scalbnf128, (float128 x, int n)) {
-// TODO: should be switched to use `FLT_RADIX` in hdr/float_macros.h" instead
-// see: https://github.com/llvm/llvm-project/issues/90496
-#if !defined(__FLT_RADIX__)
-#error __FLT_RADIX__ undefined.
-#elif __FLT_RADIX__ != 2
-#error __FLT_RADIX__!=2, unimplemented.
-#else
return fputil::ldexp(x, n);
-#endif
}
} // namespace LIBC_NAMESPACE
diff --git a/libc/src/math/generic/scalbnl.cpp b/libc/src/math/generic/scalbnl.cpp
index 681338ec01f07..1225a7ebaf572 100644
--- a/libc/src/math/generic/scalbnl.cpp
+++ b/libc/src/math/generic/scalbnl.cpp
@@ -7,19 +7,18 @@
//===----------------------------------------------------------------------===//
#include "src/math/scalbnl.h"
+#include "hdr/float_macros.h"
#include "src/__support/FPUtil/ManipulationFunctions.h"
#include "src/__support/common.h"
+#if FLT_RADIX != 2
+#error "FLT_RADIX != 2 is not supported."
+#endif
+
namespace LIBC_NAMESPACE {
LLVM_LIBC_FUNCTION(long double, scalbnl, (long double x, int n)) {
-#if !defined(__FLT_RADIX__)
-#error __FLT_RADIX__ undefined.
-#elif __FLT_RADIX__ != 2
-#error __FLT_RADIX__!=2, unimplemented.
-#else
return fputil::ldexp(x, n);
-#endif
}
} // namespace LIBC_NAMESPACE
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 446499cf15d7b..70ec3a48a5e2e 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -127,6 +127,11 @@ libc_support_library(
hdrs = ["hdr/time_macros.h"],
)
+libc_support_library(
+ name = "hdr_float_macros",
+ hdrs = ["hdr/float_macros.h"],
+)
+
############################ Type Proxy Header Files ###########################
libc_support_library(
@@ -189,7 +194,7 @@ libc_support_library(
":__support_macros_properties_compiler",
":__support_macros_properties_cpu_features",
":__support_macros_properties_os",
- ":llvm_libc_macros_float_macros",
+ ":hdr_float_macros",
":llvm_libc_types_float128",
],
)
More information about the libc-commits
mailing list