[libc-commits] [libc] 9edef3e - [libc] Move math.h and fenv.h macro definitions to llvm-libc-macros.

Siva Chandra Reddy via libc-commits libc-commits at lists.llvm.org
Tue Mar 7 10:09:00 PST 2023


Author: Siva Chandra Reddy
Date: 2023-03-07T18:08:52Z
New Revision: 9edef3e93de3f95ba2c6b4dcbb63ee02c6fa976e

URL: https://github.com/llvm/llvm-project/commit/9edef3e93de3f95ba2c6b4dcbb63ee02c6fa976e
DIFF: https://github.com/llvm/llvm-project/commit/9edef3e93de3f95ba2c6b4dcbb63ee02c6fa976e.diff

LOG: [libc] Move math.h and fenv.h macro definitions to llvm-libc-macros.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D145475

Added: 
    libc/include/llvm-libc-macros/fenv-macros.h
    libc/include/llvm-libc-macros/math-macros.h

Modified: 
    libc/config/linux/api.td
    libc/include/CMakeLists.txt
    libc/include/fenv.h.def
    libc/include/llvm-libc-macros/CMakeLists.txt
    libc/include/math.h.def

Removed: 
    


################################################################################
diff  --git a/libc/config/linux/api.td b/libc/config/linux/api.td
index 4f51ac7d1912..abe70a6681a4 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 fc8e2bc7b493..e496374de2b7 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 489756cf6325..f131a44914ab 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 a723cc86d283..74a5977641f4 100644
--- a/libc/include/llvm-libc-macros/CMakeLists.txt
+++ b/libc/include/llvm-libc-macros/CMakeLists.txt
@@ -20,12 +20,24 @@ add_header(
     .linux.fcntl_macros
 )
 
+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

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 000000000000..a73ebf41cbb3
--- /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 000000000000..136670e665e6
--- /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 5b27c33cdf27..813bb72c9b45 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()
 


        


More information about the libc-commits mailing list