Skip to content

Commit

Permalink
[libc] Generate math.h instead of the static file it is currently.
Browse files Browse the repository at this point in the history
Just enough to help a follow up patch adding cosf and sinf has been
added.

Reviewers: abrachet

Differential Revision: https://reviews.llvm.org/D76723
  • Loading branch information
Siva Chandra Reddy committed Mar 25, 2020
1 parent 8786cdb commit 2c080a3
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 368 deletions.
47 changes: 45 additions & 2 deletions libc/config/linux/api.td
Expand Up @@ -71,10 +71,53 @@ def AssertAPI : PublicAPI<"assert.h"> {
];
}

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<"INFINITY", "__builtin_inff()">,
SimpleMacroDef<"NAN", "__builtin_nanf(\"\")">,

IsFiniteMacro,
IsInfMacro,
IsNanMacro,
];
let Functions = [
"acos",
"acosl",
"round",
];
}

Expand Down
6 changes: 3 additions & 3 deletions libc/include/CMakeLists.txt
Expand Up @@ -19,10 +19,10 @@ add_header(
llvm_libc_common_h
)

add_header(
add_gen_header(
math_h
HDR
math.h
DEF_FILE math.h.def
GEN_HDR math.h
DEPENDS
llvm_libc_common_h
)
Expand Down

0 comments on commit 2c080a3

Please sign in to comment.