diff --git a/src/Core.h b/src/Core.h index bbdc7ffd2..9c5fe5123 100644 --- a/src/Core.h +++ b/src/Core.h @@ -30,8 +30,8 @@ Copyright 2014-2025 ClassiCube | Licensed under BSD-3 #endif #ifndef CC_API - #define CC_API __declspec(dllexport, noinline) - #define CC_VAR __declspec(dllexport) + #define CC_API __declspec(dllexport, noinline) + #define CC_VAR __declspec(dllexport) #endif #define CC_HAS_TYPES @@ -62,9 +62,11 @@ Copyright 2014-2025 ClassiCube | Licensed under BSD-3 #define CC_HAS_TYPES #endif - #define CC_INLINE inline - #define CC_NOINLINE __attribute__((noinline)) - + #ifndef CC_INLINE + #define CC_INLINE inline + #define CC_NOINLINE __attribute__((noinline)) + #endif + #ifndef CC_API #ifdef _WIN32 #define CC_API __attribute__((dllexport, noinline)) diff --git a/src/ExtMath.c b/src/ExtMath.c index 58626063a..d8f6a1de3 100644 --- a/src/ExtMath.c +++ b/src/ExtMath.c @@ -74,13 +74,6 @@ float Math_Mod1(float x) { return x - (int)x; /* fmodf(x, 1); */ } /*########################################################################################################################* *-------------------------------------------------------Math intrinsics---------------------------------------------------* *#########################################################################################################################*/ -/* For abs(x) function */ -#if defined CC_BUILD_AMIGA || defined CC_BUILD_SATURN -static int abs(int x) { return x < 0 ? -x : x; } -#else -#include -#endif - /* 32x/Saturn/GBA is missing these intrinsics */ #if defined CC_BUILD_32X || defined CC_BUILD_SATURN || defined CC_BUILD_GBA #include "../third_party/fix16_sqrt.c" @@ -120,8 +113,6 @@ float sqrtf(float x) { float Math_SqrtF(float x) { return sqrtf(x); /* MSVC intrinsic */ } #endif -int Math_AbsI(int x) { return abs(x); /* MSVC intrinsic */ } - /*########################################################################################################################* *--------------------------------------------------Random number generator------------------------------------------------* diff --git a/src/ExtMath.h b/src/ExtMath.h index 236e0b41e..e292c2c18 100644 --- a/src/ExtMath.h +++ b/src/ExtMath.h @@ -32,7 +32,8 @@ CC_BEGIN_HEADER #endif float Math_Mod1(float x); -int Math_AbsI(int x); + +static CC_INLINE int Math_AbsI(int x) { return x < 0 ? -x : x; } static CC_INLINE float Math_SafeDiv(float a, float b) { if (Math_AbsF(b) < 0.000001f) return MATH_LARGENUM; diff --git a/src/_PlatformBase.h b/src/_PlatformBase.h index 444f15734..f8f525b2c 100644 --- a/src/_PlatformBase.h +++ b/src/_PlatformBase.h @@ -194,27 +194,29 @@ cc_bool DynamicLib_LoadAll(const cc_string* path, const struct DynamicLibSym* sy /* Encrypts data using XTEA block cipher, with OS specific method to get machine-specific key */ static void EncipherBlock(cc_uint32* v, const cc_uint32* key, cc_string* dst) { cc_uint32 v0 = v[0], v1 = v[1], sum = 0, delta = 0x9E3779B9; + int i; - for (int i = 0; i < 12; i++) + for (i = 0; i < 12; i++) { - v0 += (((v1 << 4) ^ (v1 >> 5)) + v1) ^ (sum + key[sum & 3]); - sum += delta; - v1 += (((v0 << 4) ^ (v0 >> 5)) + v0) ^ (sum + key[(sum>>11) & 3]); - } - v[0] = v0; v[1] = v1; + v0 += (((v1 << 4) ^ (v1 >> 5)) + v1) ^ (sum + key[sum & 3]); + sum += delta; + v1 += (((v0 << 4) ^ (v0 >> 5)) + v0) ^ (sum + key[(sum>>11) & 3]); + } + v[0] = v0; v[1] = v1; String_AppendAll(dst, v, 8); } static void DecipherBlock(cc_uint32* v, const cc_uint32* key) { cc_uint32 v0 = v[0], v1 = v[1], delta = 0x9E3779B9, sum = delta * 12; + int i; - for (int i = 0; i < 12; i++) + for (i = 0; i < 12; i++) { - v1 -= (((v0 << 4) ^ (v0 >> 5)) + v0) ^ (sum + key[(sum>>11) & 3]); - sum -= delta; - v0 -= (((v1 << 4) ^ (v1 >> 5)) + v1) ^ (sum + key[sum & 3]); - } - v[0] = v0; v[1] = v1; + v1 -= (((v0 << 4) ^ (v0 >> 5)) + v0) ^ (sum + key[(sum>>11) & 3]); + sum -= delta; + v0 -= (((v1 << 4) ^ (v1 >> 5)) + v1) ^ (sum + key[sum & 3]); + } + v[0] = v0; v[1] = v1; } #define ENC1 0xCC005EC0