Skip to content

Commit

Permalink
more forgotten changes...
Browse files Browse the repository at this point in the history
ALIGNTYPE16
  • Loading branch information
revelator authored Nov 18, 2024
1 parent f50471b commit 8dcbdc2
Showing 1 changed file with 52 additions and 54 deletions.
106 changes: 52 additions & 54 deletions neo/sys/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,9 @@ If you have questions concerning this license or the applicable additional terms

// 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 1MB limit for _alloca() should be safe even when using it multiple times
// in the same function or callstack.
// If there's a risk of bigger stack allocations, Mem_MallocA() should be used instead.
#define ID_MAX_ALLOCA_SIZE 1048576 // 1MB
// 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

/*
===============================================================================
Expand All @@ -56,16 +54,16 @@ If you have questions concerning this license or the applicable additional terms
#if defined(__AROS__)

#define _alloca alloca
#define _alloca16( x ) ((void *)((((uintptr_t)alloca( (x)+15 )) + 15) & ~15))
#define _alloca16( x ) ( ( void * )( ( ( ( uintptr_t )alloca( ( x ) + 15 ) ) + 15 ) & ~15 ) )

#ifdef GAME_DLL
#define ID_GAME_API __attribute__((visibility ("default")))
#define ID_GAME_API __attribute__( ( visibility ( "default" ) ) )
#else
#define ID_GAME_API
#endif

#define ALIGN16( x ) x __attribute__ ((aligned (16)))
#define PACKED __attribute__((packed))
#define ALIGN16( x ) x __attribute__ ( ( aligned ( 16 ) ) )
#define PACKED __attribute__( ( packed ) )

#define PATHSEPERATOR_STR "/"
#define PATHSEPERATOR_CHAR '/'
Expand All @@ -84,25 +82,26 @@ If you have questions concerning this license or the applicable additional terms
#if defined(WIN32) || defined(_WIN32)

#ifdef __MINGW32__
#undef _alloca // in mingw _alloca is a #define
// NOTE: Do *not* use __builtin_alloca_with_align(), unlike regular alloca it frees at end of block instead of end of function !
#define _alloca16( x ) ( (void *) ( (assert((x)<ID_MAX_ALLOCA_SIZE)), ((((uintptr_t)__builtin_alloca( (x)+15 )) + 15) & ~15) ) )
#define _alloca( x ) ( (assert((x)<ID_MAX_ALLOCA_SIZE)), __builtin_alloca( (x) ) )
#undef _alloca // in mingw _alloca is a #define
// NOTE: Do *not* use __builtin_alloca_with_align(), unlike regular alloca it frees at end of block instead of end of function !
#define _alloca16( x ) ( (void *) ( (assert( ( x )<ID_MAX_ALLOCA_SIZE ) ), ( ( ( ( uintptr_t )__builtin_alloca( ( x ) + 15 ) ) + 15 ) & ~15 ) ) )
#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) ) ) )
#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_CHAR '\\'

#ifdef _MSC_VER
#ifdef GAME_DLL
#define ID_GAME_API __declspec(dllexport)
#define ID_GAME_API __declspec( dllexport )
#else
#define ID_GAME_API
#endif
#define ALIGN16( x ) __declspec(align(16)) x
#define ALIGN16( x ) __declspec( align( 16 ) ) x
#define ALIGNTYPE16 __declspec( align( 16 ) )
#define PACKED
#define ID_INLINE __forceinline
// DG: alternative to forced inlining of ID_INLINE for functions that do alloca()
Expand All @@ -112,64 +111,63 @@ If you have questions concerning this license or the applicable additional terms
#define assertmem( x, y ) assert( _CrtIsValidPointer( x, y, true ) )
#else
#ifdef GAME_DLL
#define ID_GAME_API __attribute__((visibility ("default")))
#define ID_GAME_API __attribute__( ( visibility ( "default" ) ) )
#else
#define ID_GAME_API
#endif
#define ALIGN16( x ) x __attribute__ ((aligned (16)))
#define PACKED __attribute__((packed))
#define ALIGN16( x ) x __attribute__ ( ( aligned ( 16 ) ) )
#define ALIGNTYPE16 __attribute__ ( ( aligned ( 16 ) ) )
#define PACKED __attribute__( ( packed ) )
#define ID_INLINE inline
#define ID_STATIC_TEMPLATE
#define assertmem( x, y )
#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
#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"
// 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"
#define D3_ARCH "arm64"
#elif defined(_M_ARM)
#define D3_ARCH "arm"
#define D3_ARCH "arm"
#elif defined(_M_IX86)
#define D3_ARCH "x86"
#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"
// 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
#if defined(MACOS_X) || defined(__APPLE__)

#ifdef GAME_DLL
#define ID_GAME_API __attribute__((visibility ("default")))
#define ID_GAME_API __attribute__( ( visibility ( "default" ) ) )
#else
#define ID_GAME_API
#endif

#define ALIGN16( x ) x __attribute__ ((aligned (16)))

#define PACKED __attribute__((packed))
#define ALIGN16( x ) x __attribute__ ( ( aligned ( 16 ) ) )
#define ALIGNTYPE16 __attribute__ ( ( aligned ( 16 ) ) )
#define PACKED __attribute__( ( packed ) )

#define _alloca alloca
#define _alloca16( x ) ((void *)((((uintptr_t)alloca( (x)+15 )) + 15) & ~15))
#define _alloca16( x ) ( ( void * )( ( ( ( uintptr_t )alloca( ( x ) + 15 ) ) + 15 ) & ~15 ) )

#define PATHSEPERATOR_STR "/"
#define PATHSEPERATOR_CHAR '/'
Expand All @@ -184,27 +182,27 @@ If you have questions concerning this license or the applicable additional terms

#endif


// Unix
#ifdef __unix__

#ifdef __GNUC__
// NOTE: Do *not* use __builtin_alloca_with_align(), unlike regular alloca it frees at end of block instead of end of function !
#define _alloca16( x ) (({assert( (x)<ID_MAX_ALLOCA_SIZE );}),((void *)((((uintptr_t)__builtin_alloca( (x)+15 )) + 15) & ~15)))
#define _alloca( x ) ( ({assert((x)<ID_MAX_ALLOCA_SIZE);}), __builtin_alloca( (x) ) )
// NOTE: Do *not* use __builtin_alloca_with_align(), unlike regular alloca it frees at end of block instead of end of function !
#define _alloca16( x ) ( ( {assert( ( x )<ID_MAX_ALLOCA_SIZE ); } ), ( ( void * )( ( ( ( uintptr_t )__builtin_alloca( ( x ) + 15 ) ) + 15 ) & ~15 ) ) )
#define _alloca( x ) ( ( {assert( ( x )<ID_MAX_ALLOCA_SIZE ); } ), __builtin_alloca( (x) ) )
#else
#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)))
#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 ) ) )
#endif

#ifdef GAME_DLL
#define ID_GAME_API __attribute__((visibility ("default")))
#define ID_GAME_API __attribute__( ( visibility ( "default" ) ) )
#else
#define ID_GAME_API
#endif

#define ALIGN16( x ) x
#define PACKED __attribute__((packed))
#define ALIGN16( x ) x __attribute__ ( ( aligned ( 16 ) ) )
#define ALIGNTYPE16 __attribute__ ( ( aligned ( 16 ) ) )
#define PACKED __attribute__( (packed) )

#define PATHSEPERATOR_STR "/"
#define PATHSEPERATOR_CHAR '/'
Expand All @@ -225,14 +223,14 @@ If you have questions concerning this license or the applicable additional terms
#endif // ID_MAYBE_INLINE

#ifdef __GNUC__
#define id_attribute(x) __attribute__(x)
#define id_attribute( x ) __attribute__( x )
#else
#define id_attribute(x)
#define id_attribute( x )
#endif

#if !defined(_MSC_VER)
// MSVC does not provide this C99 header
#include <inttypes.h>
// MSVC does not provide this C99 header
#include <inttypes.h>
#endif
#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -275,7 +273,7 @@ typedef unsigned long ulong;
typedef int qhandle_t;

#ifndef NULL
#define NULL ((void *)0)
#define NULL ( ( void * ) 0 )
#endif

#ifndef BIT
Expand Down

0 comments on commit 8dcbdc2

Please sign in to comment.