From 1a5f963ef0b49cfb44a9bcfa9dc355bdfee532fd Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sun, 9 Feb 2020 16:55:12 +1100 Subject: [PATCH] Make Math_AbsF/Math_SqrtF defines when compiling with gcc/clang. This way they get compiled to an inline intrinsic instruction, instead of a slow function call --- src/ExtMath.c | 3 +++ src/ExtMath.h | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/src/ExtMath.c b/src/ExtMath.c index d31950933..a4d3a60ec 100644 --- a/src/ExtMath.c +++ b/src/ExtMath.c @@ -7,8 +7,11 @@ /* TODO: Replace with own functions that don't rely on */ +#ifndef __GNUC__ float Math_AbsF(float x) { return fabsf(x); /* MSVC intrinsic */ } float Math_SqrtF(float x) { return sqrtf(x); /* MSVC intrinsic */ } +#endif + float Math_Mod1(float x) { return x - (int)x; /* fmodf(x, 1); */ } int Math_AbsI(int x) { return abs(x); /* MSVC intrinsic */ } diff --git a/src/ExtMath.h b/src/ExtMath.h index 29fb62b50..0dc7e8705 100644 --- a/src/ExtMath.h +++ b/src/ExtMath.h @@ -15,8 +15,16 @@ #define Math_Deg2Packed(x) ((cc_uint8)((x) * 256.0f / 360.0f)) #define Math_Packed2Deg(x) ((x) * 360.0f / 256.0f) +#ifdef __GNUC__ +/* fabsf/sqrtf are single intrinsic instructions in gcc/clang */ +/* (sqrtf is only when -fno-math-errno though) */ +#define Math_AbsF(x) __builtin_fabsf(x) +#define Math_SqrtF(x) __builtin_sqrtf(x) +#else float Math_AbsF(float x); float Math_SqrtF(float x); +#endif + float Math_Mod1(float x); int Math_AbsI(int x);