[libc-commits] [libc] [llvm] [libc]Add proxy header hdr/float-macros.h (PR #88674)
via libc-commits
libc-commits at lists.llvm.org
Sun Apr 14 18:59:56 PDT 2024
https://github.com/aniplcc created https://github.com/llvm/llvm-project/pull/88674
Closes #88433
>From f76b5e8f0a691a65341c1923dd17efaee9dadd02 Mon Sep 17 00:00:00 2001
From: aniplcc <aniplccode at gmail.com>
Date: Mon, 15 Apr 2024 07:22:37 +0530
Subject: [PATCH] [libc]Add proxy header hdr/float-macros.h
---
libc/hdr/CMakeLists.txt | 11 +-
libc/hdr/float_macros.h | 168 ++++++++++++++++++
libc/include/llvm-libc-macros/float-macros.h | 163 ++++++++++-------
.../macros/properties/CMakeLists.txt | 2 +-
libc/src/__support/macros/properties/types.h | 2 +-
.../llvm-project-overlay/libc/BUILD.bazel | 9 +-
6 files changed, 289 insertions(+), 66 deletions(-)
create mode 100644 libc/hdr/float_macros.h
diff --git a/libc/hdr/CMakeLists.txt b/libc/hdr/CMakeLists.txt
index fb7c342f92b78f..1dd571a8147afb 100644
--- a/libc/hdr/CMakeLists.txt
+++ b/libc/hdr/CMakeLists.txt
@@ -41,6 +41,15 @@ add_proxy_header_library(
libc.include.fenv
)
+add_proxy_header_library(
+ float_macros
+ HDRS
+ float_macros.h
+ FULL_BUILD_DEPENDS
+ libc.include.llvm-libc-macros.float_macros
+ libc.incude.float
+)
+
add_proxy_header_library(
signal_macros
HDRS
@@ -58,5 +67,3 @@ add_proxy_header_library(
libc.include.sys_epoll
libc.include.llvm-libc-macros.sys_epoll_macros
)
-
-add_subdirectory(types)
diff --git a/libc/hdr/float_macros.h b/libc/hdr/float_macros.h
new file mode 100644
index 00000000000000..c1d10f02f6987f
--- /dev/null
+++ b/libc/hdr/float_macros.h
@@ -0,0 +1,168 @@
+//===-- Definition of macros from float.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>
+
+#ifndef FLT_RADIX
+#define FLT_RADIX __FLT_RADIX__
+#endif // FLT_RADIX
+
+#ifndef FLT_EVAL_METHOD
+#define FLT_EVAL_METHOD __FLT_EVAL_METHOD__
+#endif // FLT_EVAL_METHOD
+
+#ifndef DECIMAL_DIG
+#define DECIMAL_DIG __DECIMAL_DIG__
+#endif // DECIMAL_DIG
+
+#ifndef FLT_DECIMAL_DIG
+#define FLT_DECIMAL_DIG __FLT_DECIMAL_DIG__
+#endif // FLT_DECIMAL_DIG
+
+#ifndef DBL_DECIMAL_DIG
+#define DBL_DECIMAL_DIG __DBL_DECIMAL_DIG__
+#endif // DBL_DECIMAL_DIG
+
+#ifndef LDBL_DECIMAL_DIG
+#define LDBL_DECIMAL_DIG __LDBL_DECIMAL_DIG__
+#endif // LDBL_DECIMAL_DIG
+
+#ifndef FLT_DIG
+#define FLT_DIG __FLT_DIG__
+#endif // FLT_DIG
+
+#ifndef DBL_DIG
+#define DBL_DIG __DBL_DIG__
+#endif // DBL_DIG
+
+#ifndef LDBL_DIG
+#define LDBL_DIG __LDBL_DIG__
+#endif // LDBL_DIG
+
+#ifndef FLT_MANT_DIG
+#define FLT_MANT_DIG __FLT_MANT_DIG__
+#endif // FLT_MANT_DIG
+
+#ifndef DBL_MANT_DIG
+#define DBL_MANT_DIG __DBL_MANT_DIG__
+#endif // DBL_MANT_DIG
+
+#ifndef LDBL_MANT_DIG
+#define LDBL_MANT_DIG __LDBL_MANT_DIG__
+#endif // LDBL_MANT_DIG
+
+#ifndef FLT_MIN
+#define FLT_MIN __FLT_MIN__
+#endif // FLT_MIN
+
+#ifndef DBL_MIN
+#define DBL_MIN __DBL_MIN__
+#endif // DBL_MIN
+
+#ifndef LDBL_MIN
+#define LDBL_MIN __LDBL_MIN__
+#endif // LDBL_MIN
+
+#ifndef FLT_MAX
+#define FLT_MAX __FLT_MAX__
+#endif // FLT_MAX
+
+#ifndef DBL_MAX
+#define DBL_MAX __DBL_MAX__
+#endif // DBL_MAX
+
+#ifndef LDBL_MAX
+#define LDBL_MAX __LDBL_MAX__
+#endif // LDBL_MAX
+
+#ifndef FLT_TRUE_MIN
+#define FLT_TRUE_MIN __FLT_TRUE_MIN__
+#endif // FLT_TRUE_MIN
+
+#ifndef DBL_TRUE_MIN
+#define DBL_TRUE_MIN __DBL_TRUE_MIN__
+#endif // DBL_TRUE_MIN
+
+#ifndef LDBL_TRUE_MIN
+#define LDBL_TRUE_MIN __LDBL_TRUE_MIN__
+#endif // LDBL_TRUE_MIN
+
+#ifndef FLT_EPSILON
+#define FLT_EPSILON __FLT_EPSILON__
+#endif // FLT_EPSILON
+
+#ifndef DBL_EPSILON
+#define DBL_EPSILON __DBL_EPSILON__
+#endif // DBL_EPSILON
+
+#ifndef LDBL_EPSILON
+#define LDBL_EPSILON __LDBL_EPSILON__
+#endif // LDBL_EPSILON
+
+#ifndef FLT_MIN_EXP
+#define FLT_MIN_EXP __FLT_MIN_EXP__
+#endif // FLT_MIN_EXP
+
+#ifndef DBL_MIN_EXP
+#define DBL_MIN_EXP __DBL_MIN_EXP__
+#endif // DBL_MIN_EXP
+
+#ifndef LDBL_MIN_EXP
+#define LDBL_MIN_EXP __LDBL_MIN_EXP__
+#endif // LDBL_MIN_EXP
+
+#ifndef FLT_MIN_10_EXP
+#define FLT_MIN_10_EXP __FLT_MIN_10_EXP__
+#endif // FLT_MIN_10_EXP
+
+#ifndef DBL_MIN_10_EXP
+#define DBL_MIN_10_EXP __DBL_MIN_10_EXP__
+#endif // DBL_MIN_10_EXP
+
+#ifndef LDBL_MIN_10_EXP
+#define LDBL_MIN_10_EXP __LDBL_MIN_10_EXP__
+#endif // LDBL_MIN_10_EXP
+
+#ifndef FLT_MAX_EXP
+#define FLT_MAX_EXP __FLT_MAX_EXP__
+#endif // FLT_MAX_EXP
+
+#ifndef DBL_MAX_EXP
+#define DBL_MAX_EXP __DBL_MAX_EXP__
+#endif // DBL_MAX_EXP
+
+#ifndef LDBL_MAX_EXP
+#define LDBL_MAX_EXP __LDBL_MAX_EXP__
+#endif // LDBL_MAX_EXP
+
+#ifndef FLT_MAX_10_EXP
+#define FLT_MAX_10_EXP __FLT_MAX_10_EXP__
+#endif // FLT_MAX_10_EXP
+
+#ifndef DBL_MAX_10_EXP
+#define DBL_MAX_10_EXP __DBL_MAX_10_EXP__
+#endif // DBL_MAX_10_EXP
+
+#ifndef LDBL_MAX_10_EXP
+#define LDBL_MAX_10_EXP __LDBL_MAX_10_EXP__
+#endif // LDBL_MAX_10_EXP
+
+// TODO: Add FLT16 and FLT128 constants.
+
+#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 4fe8590c5f70c8..0f15b909eb19ac 100644
--- a/libc/include/llvm-libc-macros/float-macros.h
+++ b/libc/include/llvm-libc-macros/float-macros.h
@@ -9,163 +9,206 @@
#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
+#ifdef __FLT_RADIX__
#define FLT_RADIX __FLT_RADIX__
+#else
+#define FLT_RADIX 2
#endif // FLT_RADIX
-#ifndef FLT_EVAL_METHOD
+#ifdef FLT_EVAL_METHOD
#define FLT_EVAL_METHOD __FLT_EVAL_METHOD__
#endif // FLT_EVAL_METHOD
-#ifndef DECIMAL_DIG
+#ifdef DECIMAL_DIG
#define DECIMAL_DIG __DECIMAL_DIG__
+#else
+#define DECIMAL_DIG 10
#endif // DECIMAL_DIG
-#ifndef FLT_DECIMAL_DIG
+#ifdef FLT_DECIMAL_DIG
#define FLT_DECIMAL_DIG __FLT_DECIMAL_DIG__
+#else
+#define FLT_DECIMAL_DIG 6
#endif // FLT_DECIMAL_DIG
-#ifndef DBL_DECIMAL_DIG
+#ifdef DBL_DECIMAL_DIG
#define DBL_DECIMAL_DIG __DBL_DECIMAL_DIG__
+#else
+#define DBL_DECIMAL_DIG 10
#endif // DBL_DECIMAL_DIG
-#ifndef LDBL_DECIMAL_DIG
+#ifdef LDBL_DECIMAL_DIG
#define LDBL_DECIMAL_DIG __LDBL_DECIMAL_DIG__
+#else
+#define LDBL_DECIMAL_DIG 10
#endif // LDBL_DECIMAL_DIG
-#ifndef FLT_DIG
+#ifdef FLT_DIG
#define FLT_DIG __FLT_DIG__
+#else
+#define FLT_DIG 6
#endif // FLT_DIG
-#ifndef DBL_DIG
+#ifdef DBL_DIG
#define DBL_DIG __DBL_DIG__
+#else
+#define DBL_DIG 10
#endif // DBL_DIG
-#ifndef LDBL_DIG
+#ifdef LDBL_DIG
#define LDBL_DIG __LDBL_DIG__
+#else
+#define LDBL_DIG 10
#endif // LDBL_DIG
-#ifndef FLT_MANT_DIG
+#ifdef FLT_MANT_DIG
#define FLT_MANT_DIG __FLT_MANT_DIG__
+#else
+#define FLT_MANT_DIG 24
#endif // FLT_MANT_DIG
-#ifndef DBL_MANT_DIG
+#ifdef DBL_MANT_DIG
#define DBL_MANT_DIG __DBL_MANT_DIG__
+#else
+#define DBL_MANT_DIG 53
#endif // DBL_MANT_DIG
-#ifndef LDBL_MANT_DIG
+#ifdef LDBL_MANT_DIG
#define LDBL_MANT_DIG __LDBL_MANT_DIG__
+#else
+#define LDBL_MANT_DIG 113
#endif // LDBL_MANT_DIG
-#ifndef FLT_MIN
+#ifdef FLT_MIN
#define FLT_MIN __FLT_MIN__
+#else
+#define FLT_MIN 1E-37
#endif // FLT_MIN
-#ifndef DBL_MIN
+#ifdef DBL_MIN
#define DBL_MIN __DBL_MIN__
+#else
+#define DBL_MIN 1E-37
#endif // DBL_MIN
-#ifndef LDBL_MIN
+#ifdef LDBL_MIN
#define LDBL_MIN __LDBL_MIN__
+#else
+#define LDBL_MIN 1E-37
#endif // LDBL_MIN
-#ifndef FLT_MAX
+#ifdef FLT_MAX
#define FLT_MAX __FLT_MAX__
+#else
+#define FLT_MAX 1E+37
#endif // FLT_MAX
-#ifndef DBL_MAX
+#ifdef DBL_MAX
#define DBL_MAX __DBL_MAX__
+#else
+#define DBL_MAX 1E+37
#endif // DBL_MAX
-#ifndef LDBL_MAX
+#ifdef LDBL_MAX
#define LDBL_MAX __LDBL_MAX__
+#else
+#define LDBL_MAX 1E+37
#endif // LDBL_MAX
-#ifndef FLT_TRUE_MIN
-#define FLT_TRUE_MIN __FLT_TRUE_MIN__
-#endif // FLT_TRUE_MIN
-
-#ifndef DBL_TRUE_MIN
-#define DBL_TRUE_MIN __DBL_TRUE_MIN__
-#endif // DBL_TRUE_MIN
-
-#ifndef LDBL_TRUE_MIN
-#define LDBL_TRUE_MIN __LDBL_TRUE_MIN__
-#endif // LDBL_TRUE_MIN
-
-#ifndef FLT_EPSILON
+// #ifdef FLT_TRUE_MIN
+// #define FLT_TRUE_MIN __FLT_DNORM_MIN //acc to Clang's define [remove after review]
+// #else
+// #define FLT_TRUE_MIN 1E-37
+// #endif // FLT_TRUE_MIN
+//
+// #ifdef DBL_TRUE_MIN
+// #define DBL_TRUE_MIN __DBL_DENORM_MIN__ //acc to Clang's define [remove after review]
+// #else
+// #define DBL_TRUE_MIN 1E-37
+// #endif // DBL_TRUE_MIN
+//
+// #ifdef LDBL_TRUE_MIN
+// #define LDBL_TRUE_MIN __LDBL_DENORM_MIN__ //acc to Clang's define [remove after review]
+// #else
+// #define LDBL_TRUE_MIN 1E-37
+// #endif // LDBL_TRUE_MIN
+
+#ifdef FLT_EPSILON
#define FLT_EPSILON __FLT_EPSILON__
+#else
+#define FLT_EPSILON 1E-5
#endif // FLT_EPSILON
-#ifndef DBL_EPSILON
+#ifdef DBL_EPSILON
#define DBL_EPSILON __DBL_EPSILON__
+#else
+#define DBL_EPSILON 1E-9
#endif // DBL_EPSILON
-#ifndef LDBL_EPSILON
+#ifdef LDBL_EPSILON
#define LDBL_EPSILON __LDBL_EPSILON__
+#else
+#define LDBL_EPSILON 1E-9
#endif // LDBL_EPSILON
-#ifndef FLT_MIN_EXP
+#ifdef FLT_MIN_EXP
#define FLT_MIN_EXP __FLT_MIN_EXP__
#endif // FLT_MIN_EXP
-#ifndef DBL_MIN_EXP
+#ifdef DBL_MIN_EXP
#define DBL_MIN_EXP __DBL_MIN_EXP__
#endif // DBL_MIN_EXP
-#ifndef LDBL_MIN_EXP
+#ifdef LDBL_MIN_EXP
#define LDBL_MIN_EXP __LDBL_MIN_EXP__
#endif // LDBL_MIN_EXP
-#ifndef FLT_MIN_10_EXP
+#ifdef FLT_MIN_10_EXP
#define FLT_MIN_10_EXP __FLT_MIN_10_EXP__
+#else
+#define FLT_MIN_10_EXP -37
#endif // FLT_MIN_10_EXP
-#ifndef DBL_MIN_10_EXP
+#ifdef DBL_MIN_10_EXP
#define DBL_MIN_10_EXP __DBL_MIN_10_EXP__
+#else
+#define DBL_MIN_10_EXP -37
#endif // DBL_MIN_10_EXP
-#ifndef LDBL_MIN_10_EXP
+#ifdef LDBL_MIN_10_EXP
#define LDBL_MIN_10_EXP __LDBL_MIN_10_EXP__
+#else
+#define LDBL_MIN_10_EXP -37
#endif // LDBL_MIN_10_EXP
-#ifndef FLT_MAX_EXP
+#ifdef FLT_MAX_EXP
#define FLT_MAX_EXP __FLT_MAX_EXP__
#endif // FLT_MAX_EXP
-#ifndef DBL_MAX_EXP
+#ifdef DBL_MAX_EXP
#define DBL_MAX_EXP __DBL_MAX_EXP__
#endif // DBL_MAX_EXP
-#ifndef LDBL_MAX_EXP
+#ifdef LDBL_MAX_EXP
#define LDBL_MAX_EXP __LDBL_MAX_EXP__
#endif // LDBL_MAX_EXP
-#ifndef FLT_MAX_10_EXP
+#ifdef FLT_MAX_10_EXP
#define FLT_MAX_10_EXP __FLT_MAX_10_EXP__
+#else
+#define FLT_MAX_10_EXP +37
#endif // FLT_MAX_10_EXP
-#ifndef DBL_MAX_10_EXP
+#ifdef DBL_MAX_10_EXP
#define DBL_MAX_10_EXP __DBL_MAX_10_EXP__
+#else
+#define DBL_MAX_10_EXP +37
#endif // DBL_MAX_10_EXP
-#ifndef LDBL_MAX_10_EXP
+#ifdef LDBL_MAX_10_EXP
#define LDBL_MAX_10_EXP __LDBL_MAX_10_EXP__
+#else
+#define LDBL_MAX_10_EXP +37
#endif // LDBL_MAX_10_EXP
// TODO: Add FLT16 and FLT128 constants.
diff --git a/libc/src/__support/macros/properties/CMakeLists.txt b/libc/src/__support/macros/properties/CMakeLists.txt
index bbc45650f3fca3..7718aeaa3de5af 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 d43cf99e6859be..0e75af15849935 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/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 9270a9d75b01c4..a1179133e4960b 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -98,7 +98,7 @@ libc_support_library(
"@platforms//os:linux": [],
"//conditions:default": ["@platforms//:incompatible"],
}),
- deps = [":llvm_libc_macros_float_macros"],
+ deps = ["include/llvm-libc-macros/linux/float-macros.h"],
)
libc_support_library(
@@ -118,6 +118,11 @@ libc_support_library(
hdrs = ["hdr/fenv_macros.h"],
)
+libc_support_library(
+ name = "hdr_float_macros",
+ hdrs = ["hdr/float_macros.h"],
+)
+
libc_support_library(
name = "hdr_signal_macros",
hdrs = ["hdr/signal_macros.h"],
@@ -170,7 +175,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