Sync sys/platform.h, incl. Workaround for MCST-LCC compiler

Workaround for MCST-LCC compiler < 1.28 version

mcst-lcc < 1.28 does not support __builtin_alloca_with_align()
Ref: http://mcst.ru/lcc
This commit is contained in:
Daniel Gibson 2024-03-18 23:03:05 +01:00
parent bad9c08c3f
commit d27f2c2c40

View file

@ -32,6 +32,16 @@ If you have questions concerning this license or the applicable additional terms
#include "config.h" #include "config.h"
#include "framework/BuildDefines.h" #include "framework/BuildDefines.h"
#ifdef _WIN32
#include <malloc.h> // _alloca()
#endif
// NOTE: By default Win32 uses a 1MB stack. Doom3 1.3.1 uses 4MB (probably set after compiling with EDITBIN /STACK
// dhewm3 now uses a 8MB stack, set with a linker flag in CMakeLists.txt (/STACK:8388608 for MSVC, -Wl,--stack,8388608 for mingw)
// Linux has a 8MB stack by default, and so does macOS, at least for the main thread
// anyway, a 2MB limit alloca should be safe even when using it multiple times in the same function
#define ID_MAX_ALLOCA_SIZE 2097152 // 2MB
/* /*
=============================================================================== ===============================================================================
@ -40,7 +50,7 @@ If you have questions concerning this license or the applicable additional terms
=============================================================================== ===============================================================================
*/ */
// Win32 // AROS
#if defined(__AROS__) #if defined(__AROS__)
#define _alloca alloca #define _alloca alloca
@ -71,7 +81,14 @@ If you have questions concerning this license or the applicable additional terms
// Win32 // Win32
#if defined(WIN32) || defined(_WIN32) #if defined(WIN32) || defined(_WIN32)
#define _alloca16( x ) ((void *)((((uintptr_t)_alloca( (x)+15 )) + 15) & ~15)) #ifdef __MINGW32__
#undef _alloca // in mingw _alloca is a #define
#define _alloca16( x ) ( (assert((x)<ID_MAX_ALLOCA_SIZE)), __builtin_alloca_with_align( (x), 16*8 ) )
#define _alloca( x ) ( (assert((x)<ID_MAX_ALLOCA_SIZE)), __builtin_alloca( (x) ) )
#else
#define _alloca16( x ) ( (void *) ( (assert((x)<ID_MAX_ALLOCA_SIZE)), ((((uintptr_t)_alloca( (x)+15 )) + 15) & ~15) ) )
#define _alloca( x ) ( (void *) ( (assert((x)<ID_MAX_ALLOCA_SIZE)), _alloca( (x) ) ) )
#endif
#define PATHSEPERATOR_STR "\\" #define PATHSEPERATOR_STR "\\"
#define PATHSEPERATOR_CHAR '\\' #define PATHSEPERATOR_CHAR '\\'
@ -105,6 +122,35 @@ If you have questions concerning this license or the applicable additional terms
#endif #endif
// Setting D3_ARCH for VisualC++ from CMake doesn't work when using VS integrated CMake
// so set it in code instead
#ifdef _MSC_VER
#ifdef D3_ARCH
#undef D3_ARCH
#endif // D3_ARCH
#ifdef _M_X64
// this matches AMD64 and ARM64EC (but not regular ARM64), but they're supposed to be binary-compatible somehow, so whatever
#define D3_ARCH "x86_64"
#elif defined(_M_ARM64)
#define D3_ARCH "arm64"
#elif defined(_M_ARM)
#define D3_ARCH "arm"
#elif defined(_M_IX86)
#define D3_ARCH "x86"
#else
// if you're not targeting one of the aforementioned architectures,
// check https://learn.microsoft.com/en-us/cpp/preprocessor/predefined-macros
// to find out how to detect yours and add it here - and please send a patch :)
#error "Unknown CPU architecture!"
// (for a quick and dirty solution, comment out the previous line, but keep in mind
// that savegames may not be compatible with other builds of dhewm3)
#define D3_ARCH "UNKNOWN"
#endif // _M_X64 etc
#endif // _MSC_VER
// Mac OSX // Mac OSX
#if defined(MACOS_X) || defined(__APPLE__) #if defined(MACOS_X) || defined(__APPLE__)
@ -139,8 +185,15 @@ If you have questions concerning this license or the applicable additional terms
// Unix // Unix
#ifdef __unix__ #ifdef __unix__
#define _alloca alloca #if !defined(__GNUC__) || (defined(__MCST__) && __LCC__ < 128)
#define _alloca16( x ) ((void *)((((uintptr_t)alloca( (x)+15 )) + 15) & ~15)) // MCST-LCC < 1.28 does not support __builtin_alloca_with_align()
#define _alloca( x ) (({assert( (x)<ID_MAX_ALLOCA_SIZE );}), alloca( (x) ))
#define _alloca16( x ) (({assert( (x)<ID_MAX_ALLOCA_SIZE );}),((void *)((((uintptr_t)alloca( (x)+15 )) + 15) & ~15)))
#else
// GCC, CLANG, MCST-LCC >= 1.28
#define _alloca16( x ) ( ({assert((x)<ID_MAX_ALLOCA_SIZE);}), __builtin_alloca_with_align( (x), 16*8 ) )
#define _alloca( x ) ( ({assert((x)<ID_MAX_ALLOCA_SIZE);}), __builtin_alloca( (x) ) )
#endif
#ifdef GAME_DLL #ifdef GAME_DLL
#define ID_GAME_API __attribute__((visibility ("default"))) #define ID_GAME_API __attribute__((visibility ("default")))
@ -179,9 +232,6 @@ If you have questions concerning this license or the applicable additional terms
// MSVC does not provide this C99 header // MSVC does not provide this C99 header
#include <inttypes.h> #include <inttypes.h>
#endif #endif
#if defined(__MINGW32__)
#include <malloc.h>
#endif
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdarg.h> #include <stdarg.h>
@ -200,6 +250,18 @@ If you have questions concerning this license or the applicable additional terms
#undef FindText // stupid namespace poluting Microsoft monkeys #undef FindText // stupid namespace poluting Microsoft monkeys
#endif #endif
// Apple legacy
#ifdef __APPLE__
#include <Availability.h>
#ifdef __MAC_OS_X_VERSION_MIN_REQUIRED
#if __MAC_OS_X_VERSION_MIN_REQUIRED == 1040
#define OSX_TIGER
#elif __MAC_OS_X_VERSION_MIN_REQUIRED < 1060
#define OSX_LEOPARD
#endif
#endif
#endif
#define ID_TIME_T time_t #define ID_TIME_T time_t
typedef unsigned char byte; // 8 bits typedef unsigned char byte; // 8 bits