diff --git a/common/xash3d_types.h b/common/xash3d_types.h index 1575eafd..3ce4e612 100644 --- a/common/xash3d_types.h +++ b/common/xash3d_types.h @@ -128,6 +128,14 @@ typedef uint64_t longtime_t; #define STATIC_ASSERT( x, y ) STATIC_ASSERT_2( __LINE__, x, y ) #endif +#if !defined( __cplusplus ) && __STDC_VERSION__ >= 199101L // not C++ and C99 or newer + #define XASH_RESTRICT restrict +#elif _MSC_VER || __GNUC__ || __clang__ // compiler-specific extensions + #define XASH_RESTRICT __restrict +#else + #define XASH_RESTRICT // nothing +#endif + #ifdef XASH_BIG_ENDIAN #define LittleLong(x) (((int)(((x)&255)<<24)) + ((int)((((x)>>8)&255)<<16)) + ((int)(((x)>>16)&255)<<8) + (((x) >> 24)&255)) #define LittleLongSW(x) (x = LittleLong(x) ) diff --git a/public/crtlib.c b/public/crtlib.c index cb066df0..b8545aa1 100644 --- a/public/crtlib.c +++ b/public/crtlib.c @@ -274,6 +274,13 @@ const byte *Q_memmem( const byte *haystack, size_t haystacklen, const byte *need return NULL; } +void Q_memor( byte *XASH_RESTRICT dst, const byte *XASH_RESTRICT src, size_t len ) +{ + size_t i; + for( i = 0; i < len; i++ ) // msvc likes to optimize this loop form + dst[i] |= src[i]; +} + const char* Q_timestamp( int format ) { static string timestamp; diff --git a/public/crtlib.h b/public/crtlib.h index ad9d345c..d03f308a 100644 --- a/public/crtlib.h +++ b/public/crtlib.h @@ -45,6 +45,10 @@ enum #define PFILE_TOKEN_MAX_LENGTH 1024 #define PFILE_FS_TOKEN_MAX_LENGTH 512 +#ifdef __cplusplus +#define restrict +#endif // __cplusplus + // // build.c // @@ -72,6 +76,7 @@ void Q_atov( float *vec, const char *str, size_t siz ); qboolean Q_stricmpext( const char *pattern, const char *text ); qboolean Q_strnicmpext( const char *pattern, const char *text, size_t minimumlen ); const byte *Q_memmem( const byte *haystack, size_t haystacklen, const byte *needle, size_t needlelen ); +void Q_memor( byte *XASH_RESTRICT dst, const byte *XASH_RESTRICT src, size_t len ); const char *Q_timestamp( int format ); int Q_vsnprintf( char *buffer, size_t buffersize, const char *format, va_list args ); int Q_snprintf( char *buffer, size_t buffersize, const char *format, ... ) _format( 3 );