diff --git a/libc/config/linux/api.td b/libc/config/linux/api.td --- a/libc/config/linux/api.td +++ b/libc/config/linux/api.td @@ -54,74 +54,11 @@ 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 --- a/libc/include/CMakeLists.txt +++ b/libc/include/CMakeLists.txt @@ -45,6 +45,7 @@ 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 @@ 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 --- 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 %%public_api() diff --git a/libc/include/llvm-libc-macros/CMakeLists.txt b/libc/include/llvm-libc-macros/CMakeLists.txt --- a/libc/include/llvm-libc-macros/CMakeLists.txt +++ b/libc/include/llvm-libc-macros/CMakeLists.txt @@ -20,12 +20,24 @@ .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 --- /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 --- /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 --- 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 %%public_api()