aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSiva Chandra Reddy <sivachandra@google.com>2023-03-07 07:44:26 +0000
committerSiva Chandra Reddy <sivachandra@google.com>2023-03-07 18:08:52 +0000
commit9edef3e93de3f95ba2c6b4dcbb63ee02c6fa976e (patch)
treede1f54f6d2c058e25a24566cc2ebb0769f833826
parent9b2895469badad470dca186801fe025c52f5364c (diff)
downloadllvm-9edef3e93de3f95ba2c6b4dcbb63ee02c6fa976e.zip
llvm-9edef3e93de3f95ba2c6b4dcbb63ee02c6fa976e.tar.gz
llvm-9edef3e93de3f95ba2c6b4dcbb63ee02c6fa976e.tar.bz2
[libc] Move math.h and fenv.h macro definitions to llvm-libc-macros.
Reviewed By: lntue Differential Revision: https://reviews.llvm.org/D145475
-rw-r--r--libc/config/linux/api.td63
-rw-r--r--libc/include/CMakeLists.txt2
-rw-r--r--libc/include/fenv.h.def1
-rw-r--r--libc/include/llvm-libc-macros/CMakeLists.txt12
-rw-r--r--libc/include/llvm-libc-macros/fenv-macros.h27
-rw-r--r--libc/include/llvm-libc-macros/math-macros.h34
-rw-r--r--libc/include/math.h.def1
7 files changed, 77 insertions, 63 deletions
diff --git a/libc/config/linux/api.td b/libc/config/linux/api.td
index 4f51ac7..abe70a6 100644
--- a/libc/config/linux/api.td
+++ b/libc/config/linux/api.td
@@ -54,74 +54,11 @@ def IntTypesAPI : PublicAPI<"inttypes.h"> {
let Types = ["imaxdiv_t"];
}
-def MathErrHandlingMacro : MacroDef<"math_errhandling"> {
- let Defn = [{
- #ifndef math_errhandling
- #ifdef __FAST_MATH__
- #define math_errhandling 0
- #elif defined __NO_MATH_ERRNO__
- #define math_errhandling (MATH_ERREXCEPT)
- #else
- #define math_errhandling (MATH_ERRNO | MATH_ERREXCEPT)
- #endif
- #endif // math_errhandling not defined
- }];
-}
-
-def IsFiniteMacro : MacroDef<"isfinite"> {
- let Defn = [{
- #define isfinite(x) __builtin_isfinite(x)
- }];
-}
-
-def IsInfMacro : MacroDef<"isinf"> {
- let Defn = [{
- #define isinf(x) __builtin_isinf(x)
- }];
-}
-
-def IsNanMacro : MacroDef<"isnan"> {
- let Defn = [{
- #define isnan(x) __builtin_isnan(x)
- }];
-}
-
def MathAPI : PublicAPI<"math.h"> {
- let Macros = [
- SimpleMacroDef<"MATH_ERRNO", "1">,
- SimpleMacroDef<"MATH_ERREXCEPT", "2">,
- MathErrHandlingMacro,
-
- SimpleMacroDef<"HUGE_VAL", "__builtin_huge_val()">,
- SimpleMacroDef<"INFINITY", "__builtin_inff()">,
- SimpleMacroDef<"NAN", "__builtin_nanf(\"\")">,
-
- SimpleMacroDef<"FP_ILOGB0", "(-__INT_MAX__ - 1)">, // INT_MIN
- SimpleMacroDef<"FP_ILOGBNAN", "__INT_MAX__">,
-
- IsFiniteMacro,
- IsInfMacro,
- IsNanMacro,
- ];
let Types = ["double_t", "float_t"];
}
def FenvAPI: PublicAPI<"fenv.h"> {
- let Macros = [
- SimpleMacroDef<"FE_DIVBYZERO", "1">,
- SimpleMacroDef<"FE_INEXACT", "2">,
- SimpleMacroDef<"FE_INVALID", "4">,
- SimpleMacroDef<"FE_OVERFLOW", "8">,
- SimpleMacroDef<"FE_UNDERFLOW", "16">,
- SimpleMacroDef<"FE_ALL_EXCEPT", "(FE_DIVBYZERO|FE_INEXACT|FE_INVALID|FE_OVERFLOW|FE_UNDERFLOW)">,
-
- SimpleMacroDef<"FE_DOWNWARD", "1">,
- SimpleMacroDef<"FE_TONEAREST", "2">,
- SimpleMacroDef<"FE_TOWARDZERO", "4">,
- SimpleMacroDef<"FE_UPWARD", "8">,
-
- SimpleMacroDef<"FE_DFL_ENV", "((fenv_t *)-1)">,
- ];
let Types = ["fenv_t", "fexcept_t"];
}
diff --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt
index fc8e2bc..e496374 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -45,6 +45,7 @@ add_gen_header(
GEN_HDR fenv.h
DEPENDS
.llvm_libc_common_h
+ .llvm-libc-macros.fenv_macros
.llvm-libc-types.fenv_t
.llvm-libc-types.fexcept_t
)
@@ -64,6 +65,7 @@ add_gen_header(
GEN_HDR math.h
DEPENDS
.llvm_libc_common_h
+ .llvm-libc-macros.math_macros
.llvm-libc-types.double_t
.llvm-libc-types.float_t
)
diff --git a/libc/include/fenv.h.def b/libc/include/fenv.h.def
index 489756c..f131a44 100644
--- a/libc/include/fenv.h.def
+++ b/libc/include/fenv.h.def
@@ -10,6 +10,7 @@
#define LLVM_LIBC_FENV_H
#include <__llvm-libc-common.h>
+#include <llvm-libc-macros/fenv-macros.h>
%%public_api()
diff --git a/libc/include/llvm-libc-macros/CMakeLists.txt b/libc/include/llvm-libc-macros/CMakeLists.txt
index a723cc8..74a5977 100644
--- a/libc/include/llvm-libc-macros/CMakeLists.txt
+++ b/libc/include/llvm-libc-macros/CMakeLists.txt
@@ -21,12 +21,24 @@ add_header(
)
add_header(
+ fenv_macros
+ HDR
+ fenv-macros.h
+)
+
+add_header(
file_seek_macros
HDR
file-seek-macros.h
)
add_header(
+ math_macros
+ HDR
+ math-macros.h
+)
+
+add_header(
sched_macros
HDR
sched-macros.h
diff --git a/libc/include/llvm-libc-macros/fenv-macros.h b/libc/include/llvm-libc-macros/fenv-macros.h
new file mode 100644
index 0000000..a73ebf4
--- /dev/null
+++ b/libc/include/llvm-libc-macros/fenv-macros.h
@@ -0,0 +1,27 @@
+//===-- Definition of macros from fenv.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_MACROS_FENV_MACROS_H
+#define __LLVM_LIBC_MACROS_FENV_MACROS_H
+
+#define FE_DIVBYZERO 1
+#define FE_INEXACT 2
+#define FE_INVALID 4
+#define FE_OVERFLOW 8
+#define FE_UNDERFLOW 16
+#define FE_ALL_EXCEPT \
+ (FE_DIVBYZERO | FE_INEXACT | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW)
+
+#define FE_DOWNWARD 1
+#define FE_TONEAREST 2
+#define FE_TOWARDZERO 4
+#define FE_UPWARD 8
+
+#define FE_DFL_ENV ((fenv_t *)-1)
+
+#endif // __LLVM_LIBC_MACROS_FENV_MACROS_H
diff --git a/libc/include/llvm-libc-macros/math-macros.h b/libc/include/llvm-libc-macros/math-macros.h
new file mode 100644
index 0000000..136670e
--- /dev/null
+++ b/libc/include/llvm-libc-macros/math-macros.h
@@ -0,0 +1,34 @@
+//===-- 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_MACROS_MATH_MACROS_H
+#define __LLVM_LIBC_MACROS_MATH_MACROS_H
+
+#define MATH_ERRNO 1
+#define MATH_ERREXCEPT 2
+
+#define HUGE_VAL __builtin_huge_val()
+#define INFINITY __builtin_inf()
+#define NAN __builtin_nanf("")
+
+#define FP_ILOGB0 (-__INT_MAX__ - 1)
+#define FP_ILOGBNAN __INT_MAX__
+
+#define isfinite(x) __builtin_isfinite(x)
+#define isinf(x) __builtin_isinf(x)
+#define isnan(x) __builtin_isnan(x)
+
+#ifdef __FAST_MATH__
+#define math_errhandling 0
+#elif defined __NO_MATH_ERRNO__
+#define math_errhandling (MATH_ERREXCEPT)
+#else
+#define math_errhandling (MATH_ERRNO | MATH_ERREXCEPT)
+#endif
+
+#endif // __LLVM_LIBC_MACROS_MATH_MACROS_H
diff --git a/libc/include/math.h.def b/libc/include/math.h.def
index 5b27c33..813bb72 100644
--- a/libc/include/math.h.def
+++ b/libc/include/math.h.def
@@ -10,6 +10,7 @@
#define LLVM_LIBC_MATH_H
#include <__llvm-libc-common.h>
+#include <llvm-libc-macros/math-macros.h>
%%public_api()