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

This commit is contained in:
UnknownShadow200 2020-02-09 16:55:12 +11:00
parent 1e7ee30156
commit 1a5f963ef0
2 changed files with 11 additions and 0 deletions

View File

@ -7,8 +7,11 @@
/* TODO: Replace with own functions that don't rely on <math> */
#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 */ }

View File

@ -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);