[liba] Proper support for function-like macros for math functions

This commit is contained in:
Romain Goyet
2017-10-19 14:17:44 +02:00
committed by EmilieNumworks
parent f34146be5e
commit 5a2446eff7
4 changed files with 102 additions and 29 deletions

View File

@@ -99,7 +99,7 @@ objs += $(addprefix liba/src/external/openbsd/, \
w_lgamma.o \
)
liba/src/external/openbsd/%.o: CFLAGS += -Iliba/src/external/openbsd/include
liba/src/external/openbsd/%.o: SFLAGS := -Iliba/src/external/openbsd/include $(SFLAGS)
liba/src/external/openbsd/e_lgammaf_r.o: CFLAGS += -w
liba/src/external/openbsd/s_log1pf.o: CFLAGS += -w
liba/src/external/openbsd/s_scalbnf.o: CFLAGS += -w

View File

@@ -73,6 +73,39 @@ float sqrtf(float x);
float tanf(float x);
float tanhf(float x);
double acos(double x);
double acosh(double x);
double asin(double x);
double asinh(double x);
double atan(double x);
double atanh(double x);
double ceil(double x);
double copysign(double x, double y);
double cos(double x);
double cosh(double x);
double exp(double x);
double expm1(double x);
double fabs(double x);
double floor(double x);
double lgamma(double x);
double lgamma_r(double x, int *signgamp);
double log1p(double x);
double log10(double x);
double log(double x);
double pow(double x, double y);
double round(double x);
double scalbn(double x, int n);
double sin(double x);
double sinh(double x);
double sqrt(double x);
double tan(double x);
double tanh(double x);
/* The C99 standard says that any libc function can be re-declared as a macro.
* (See N1124 paragraph 7.1.4). This means that C files willing to actually
* implement said functions should either re-define the prototype or #undef the
* macro. */
#define acosf(x) __builtin_acosf(x)
#define acoshf(x) __builtin_acoshf(x)
#define asinf(x) __builtin_asinf(x)
@@ -105,34 +138,6 @@ float tanhf(float x);
#define tanf(x) __builtin_tanf(x)
#define tanhf(x) __builtin_tanhf(x)
double acos(double x);
double acosh(double x);
double asin(double x);
double asinh(double x);
double atan(double x);
double atanh(double x);
double ceil(double x);
double copysign(double x, double y);
double cos(double x);
double cosh(double x);
double exp(double x);
double expm1(double x);
double fabs(double x);
double floor(double x);
double lgamma(double x);
double lgamma_r(double x, int *signgamp);
double log1p(double x);
double log10(double x);
double log(double x);
double pow(double x, double y);
double round(double x);
double scalbn(double x, int n);
double sin(double x);
double sinh(double x);
double sqrt(double x);
double tan(double x);
double tanh(double x);
#define acos(x) __builtin_acos(x)
#define acosh(x) __builtin_acosh(x)
#define asin(x) __builtin_asin(x)

View File

@@ -0,0 +1,66 @@
#include_next <math.h>
/* In accordance with the C99 standard, we've defined libm function as macros to
* leverage compiler optimizations. When comes the time to actually implement
* those functions, we don't want the macro to be active. OpenBSD doesn't use
* macros so it doesn't bother #undef-ing libm functions. Let's do it here. */
#undef acosf
#undef acoshf
#undef asinf
#undef asinhf
#undef atanf
#undef atan2f
#undef atanhf
#undef ceilf
#undef copysignf
#undef cosf
#undef coshf
#undef expf
#undef expm1f
#undef fabsf
#undef floorf
#undef fmodf
#undef lgammaf
#undef lgammaf_r
#undef log1pf
#undef log10f
#undef logf
#undef nanf
#undef nearbyintf
#undef powf
#undef roundf
#undef scalbnf
#undef sinf
#undef sinhf
#undef sqrtf
#undef tanf
#undef tanhf
#undef acos
#undef acosh
#undef asin
#undef asinh
#undef atan
#undef atanh
#undef ceil
#undef copysign
#undef cos
#undef cosh
#undef exp
#undef expm1
#undef fabs
#undef floor
#undef lgamma
#undef lgamma_r
#undef log1p
#undef log10
#undef log
#undef pow
#undef round
#undef scalbn
#undef sin
#undef sinh
#undef sqrt
#undef tan
#undef tanh

View File

@@ -1,5 +1,7 @@
#include <math.h>
#undef nearbyintf
/* nearbyintf is not supposed to be the same as roundf according to openBSD
* documentation. Indeed:
* - they round halfway cases to the nearest integer instead of away from zero