diff --git a/game/shared/shareddefs.h b/game/shared/shareddefs.h index d2da8f6b..b2108132 100644 --- a/game/shared/shareddefs.h +++ b/game/shared/shareddefs.h @@ -153,11 +153,7 @@ public: // The Source engine is really designed for 32 or less players. If you raise this number above 32, you better know what you are doing // and have a good answer for a bunch of perf question related to player simulation, thinking logic, tracelines, networking overhead, etc. // But if you are brave or are doing something interesting, go for it... ywb 9/22/03 -#if defined( CSTRIKE_DLL ) - #define MAX_PLAYERS 64 // Absolute max players supported -#else - #define MAX_PLAYERS 32 // Absolute max players supported -#endif +#define MAX_PLAYERS 128 // Absolute max players supported #define MAX_PLACE_NAME_LENGTH 18 @@ -695,6 +691,7 @@ struct EmitSound_t m_SoundLevel( SNDLVL_NONE ), m_nFlags( 0 ), m_nPitch( PITCH_NORM ), + m_nSpecialDSP( 0 ), m_pOrigin( 0 ), m_flSoundTime( 0.0f ), m_pflSoundDuration( 0 ), @@ -715,6 +712,7 @@ struct EmitSound_t soundlevel_t m_SoundLevel; int m_nFlags; int m_nPitch; + int m_nSpecialDSP; const Vector *m_pOrigin; float m_flSoundTime; ///< NOT DURATION, but rather, some absolute time in the future until which this sound should be delayed float *m_pflSoundDuration; diff --git a/lib/linux/libtier0.so b/lib/linux/libtier0_srv.so similarity index 100% rename from lib/linux/libtier0.so rename to lib/linux/libtier0_srv.so diff --git a/lib/linux/libvstdlib.so b/lib/linux/libvstdlib_srv.so similarity index 100% rename from lib/linux/libvstdlib.so rename to lib/linux/libvstdlib_srv.so diff --git a/lib/linux/mathlib_i486.a b/lib/linux/mathlib_i486.a index 963b347a..86830f2e 100644 Binary files a/lib/linux/mathlib_i486.a and b/lib/linux/mathlib_i486.a differ diff --git a/lib/linux/tier1_i486.a b/lib/linux/tier1_i486.a index 5a0555c1..f5b3cf6b 100644 Binary files a/lib/linux/tier1_i486.a and b/lib/linux/tier1_i486.a differ diff --git a/lib/public/mathlib.lib b/lib/public/mathlib.lib index 453b4aff..8df12e93 100644 Binary files a/lib/public/mathlib.lib and b/lib/public/mathlib.lib differ diff --git a/lib/public/tier1.lib b/lib/public/tier1.lib index f411d4b0..77716352 100644 Binary files a/lib/public/tier1.lib and b/lib/public/tier1.lib differ diff --git a/linux_sdk/Makefile b/linux_sdk/Makefile index 9963177a..b2863757 100644 --- a/linux_sdk/Makefile +++ b/linux_sdk/Makefile @@ -3,6 +3,8 @@ # # +OS := $(shell uname -s) + ############################################################################# # Developer configurable items ############################################################################# @@ -24,10 +26,17 @@ SRCDS_DIR = ~/srcds/orangebox GAME_DIR = $(SRCDS_DIR)/scratchmod # compiler options (gcc 3.4.1 or above is required - 4.1.2+ recommended) -CC = /usr/bin/gcc-4.2 -CPLUS = /usr/bin/g++-4.2 -CLINK = /usr/bin/gcc-4.2 -CPP_LIB = "libstdc++.a libgcc_eh.a" +#ifeq "$(OS)" "Darwin" +CC = /usr/bin/clang-3.8 +CPLUS = /usr/bin/clang++-3.8 +CLINK = /usr/bin/clang-3.8 +CPP_LIB = +#else +#CC = /usr/bin/gcc +#CPLUS = /usr/bin/g++ +#CLINK = /usr/bin/gcc +#CPP_LIB = $(SRCDS_DIR)/bin/libstdc++.so.6 $(SRCDS_DIR)/bin/libgcc_s.so.1 +#endif # put any compiler flags you want passed here USER_CFLAGS = @@ -58,21 +67,37 @@ BUILD_OBJ_DIR = $(BUILD_DIR)/obj # the location of the source code SRC_DIR = .. -# the location of the Linux static libraries + +# the location of the static libraries +ifeq "$(OS)" "Darwin" +LIB_DIR = $(SRC_DIR)/lib/mac +else LIB_DIR = $(SRC_DIR)/lib/linux +endif # the CPU target for the build, must be i486 for now ARCH = i486 ARCH_CFLAGS = -mtune=i686 -march=pentium3 -mmmx -m32 -DEFINES = -D_LINUX -DLINUX -DVPROF_LEVEL=1 -DSWDS -D_finite=finite -Dstricmp=strcasecmp -D_stricmp=strcasecmp \ - -D_strnicmp=strncasecmp -Dstrnicmp=strncasecmp -D_vsnprintf=vsnprintf -D_alloca=alloca -Dstrcmpi=strcasecmp +ifeq "$(OS)" "Darwin" +DEFINES = -D_OSX -DOSX +SHLIBEXT = dylib +SHLIBLDFLAGS = -dynamiclib -mmacosx-version-min=10.5 +SHLIBSUFFIX = +else +DEFINES = -D_LINUX -DLINUX +SHLIBEXT = so +SHLIBLDFLAGS = -shared -Wl,-Map,$@_map.txt -Wl +SHLIBSUFFIX = _srv +endif + +DEFINES +=-DGNUC -D_POSIX -DPOSIX -DVPROF_LEVEL=1 -DSWDS -DNO_MALLOC_OVERRIDE -D_finite=finite -Dstricmp=strcasecmp -D_stricmp=strcasecmp -D_strnicmp=strncasecmp \ + -Dstrnicmp=strncasecmp -D_vsnprintf=vsnprintf -D_alloca=alloca -Dstrcmpi=strcasecmp UNDEF = -Usprintf -Ustrncpy -UPROTECTED_THINGS_ENABLE -BASE_CFLAGS = -fno-strict-aliasing -Wall -Werror -Wconversion -Wno-non-virtual-dtor -Wno-invalid-offsetof -SHLIBEXT = so +BASE_CFLAGS = -fno-strict-aliasing -Wall -Wsign-compare -Werror -Wno-conversion -Wno-overloaded-virtual -Wno-non-virtual-dtor -Wno-invalid-offsetof \ + -Wno-delete-non-virtual-dtor -Wno-unused-const-variable SHLIBCFLAGS = -fPIC -SHLIBLDFLAGS = -shared -Wl,-Map,$@_map.txt -Wl # Flags passed to the c compiler CFLAGS = $(DEFINES) $(ARCH_CFLAGS) -O3 $(BASE_CFLAGS) @@ -88,7 +113,7 @@ DBG_CFLAGS = "$(DEFINES) $(ARCH_CFLAGS) -g -ggdb $(BASE_CFLAGS) $(UNDEF)" # define list passed to make for the sub makefile BASE_DEFINES = CC=$(CC) AR=$(AR) CPLUS=$(CPLUS) CPP_LIB=$(CPP_LIB) DEBUG=$(DEBUG) \ BUILD_DIR=$(BUILD_DIR) BUILD_OBJ_DIR=$(BUILD_OBJ_DIR) SRC_DIR=$(SRC_DIR) \ - LIB_DIR=$(LIB_DIR) SHLIBLDFLAGS=$(SHLIBLDFLAGS) SHLIBEXT=$(SHLIBEXT) \ + LIB_DIR=$(LIB_DIR) SHLIBLDFLAGS="$(SHLIBLDFLAGS)" SHLIBEXT=$(SHLIBEXT) SHLIBSUFFIX=$(SHLIBSUFFIX) \ CLINK=$(CLINK) CFLAGS="$(CFLAGS)" DBG_CFLAGS=$(DBG_CFLAGS) LDFLAGS=$(LDFLAGS) \ DEFINES="$(DEFINES)" DBG_DEFINES=$(DBG_DEFINES) \ ARCH=$(ARCH) SRCDS_DIR=$(SRCDS_DIR) MOD_CONFIG=$(MOD_CONFIG) NAME=$(NAME) \ @@ -111,9 +136,9 @@ check: if [ ! -e "$(LIB_DIR)/tier1_i486.a" ]; then $(MAKE) tier1;fi if [ ! -e "$(LIB_DIR)/mathlib_i486.a" ]; then $(MAKE) mathlib;fi if [ ! -e "$(LIB_DIR)/choreoobjects_i486.a" ]; then $(MAKE) choreo;fi - if [ ! -f "tier0_i486.so" ]; then ln -s $(SRCDS_DIR)/bin/tier0_i486.so .; fi - if [ ! -f "vstdlib_i486.so" ]; then ln -s $(SRCDS_DIR)/bin/vstdlib_i486.so .; fi - if [ ! -f "steam_api_i486.so" ]; then ln -s $(SRCDS_DIR)/bin/steam_api_i486.so .; fi + if [ ! -f "libtier0$(SHLIBSUFFIX).$(SHLIBEXT)" ]; then ln -fs $(LIB_DIR)/libtier0$(SHLIBSUFFIX).$(SHLIBEXT) .; fi + if [ ! -f "libvstdlib$(SHLIBSUFFIX).$(SHLIBEXT)" ]; then ln -fs $(LIB_DIR)/libvstdlib$(SHLIBSUFFIX).$(SHLIBEXT) .; fi + if [ ! -f "libsteam_api.$(SHLIBEXT)" ]; then ln -fs $(LIB_DIR)/libsteam_api.$(SHLIBEXT) .; fi vcpm: check if [ ! -e "vcpm" ]; then $(MAKE) -f $(MAKE_VCPM) $(BASE_DEFINES);fi diff --git a/linux_sdk/Makefile.mathlib b/linux_sdk/Makefile.mathlib index c2a55e6a..638c4df6 100644 --- a/linux_sdk/Makefile.mathlib +++ b/linux_sdk/Makefile.mathlib @@ -30,7 +30,6 @@ DO_CC += -o $@ -c $< ##################################################################### LIB_OBJS= \ - $(LIB_OBJ_DIR)/3dnow.o \ $(LIB_OBJ_DIR)/anorms.o \ $(LIB_OBJ_DIR)/bumpvects.o \ $(LIB_OBJ_DIR)/color_conversion.o \ diff --git a/linux_sdk/Makefile.tier1 b/linux_sdk/Makefile.tier1 index fac93119..20c0c818 100644 --- a/linux_sdk/Makefile.tier1 +++ b/linux_sdk/Makefile.tier1 @@ -42,7 +42,6 @@ LIB_OBJS= \ $(LIB_OBJ_DIR)/interface.o \ $(LIB_OBJ_DIR)/KeyValues.o \ $(LIB_OBJ_DIR)/mempool.o \ - $(LIB_OBJ_DIR)/memstack.o \ $(LIB_OBJ_DIR)/NetAdr.o \ $(LIB_OBJ_DIR)/newbitbuf.o \ $(LIB_OBJ_DIR)/processor_detect.o \ diff --git a/mathlib/3dnow.cpp b/mathlib/3dnow.cpp deleted file mode 100644 index 53a23736..00000000 --- a/mathlib/3dnow.cpp +++ /dev/null @@ -1,193 +0,0 @@ -//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============// -// -// Purpose: 3DNow Math primitives. -// -//=====================================================================================// - -#include -#include // Needed for FLT_EPSILON -#include "basetypes.h" -#include -#include "tier0/dbg.h" -#include "mathlib/mathlib.h" -#include "mathlib/amd3dx.h" -#include "mathlib/vector.h" - -// memdbgon must be the last include file in a .cpp file!!! -#include "tier0/memdbgon.h" - -#ifdef _MSC_VER -#pragma warning(disable:4244) // "conversion from 'const int' to 'float', possible loss of data" -#pragma warning(disable:4730) // "mixing _m64 and floating point expressions may result in incorrect code" -#endif - -//----------------------------------------------------------------------------- -// 3D Now Implementations of optimized routines: -//----------------------------------------------------------------------------- -float _3DNow_Sqrt(float x) -{ - Assert( s_bMathlibInitialized ); - float root = 0.f; -#ifdef _WIN32 - _asm - { - femms - movd mm0, x - PFRSQRT (mm1,mm0) - punpckldq mm0, mm0 - PFMUL (mm0, mm1) - movd root, mm0 - femms - } -#elif defined _LINUX || defined __APPLE__ - __asm __volatile__( "femms" ); - __asm __volatile__ - ( - "pfrsqrt %y0, %y1 \n\t" - "punpckldq %y1, %y1 \n\t" - "pfmul %y1, %y0 \n\t" - : "=y" (root), "=y" (x) - :"0" (x) - ); - __asm __volatile__( "femms" ); -#else -#error -#endif - - return root; -} - -// NJS FIXME: Need to test Recripricol squareroot performance and accuraccy -// on AMD's before using the specialized instruction. -float _3DNow_RSqrt(float x) -{ - Assert( s_bMathlibInitialized ); - - return 1.f / _3DNow_Sqrt(x); -} - - -float FASTCALL _3DNow_VectorNormalize (Vector& vec) -{ - Assert( s_bMathlibInitialized ); - float *v = &vec[0]; - float radius = 0.f; - - if ( v[0] || v[1] || v[2] ) - { -#ifdef _WIN32 - _asm - { - mov eax, v - femms - movq mm0, QWORD PTR [eax] - movd mm1, DWORD PTR [eax+8] - movq mm2, mm0 - movq mm3, mm1 - PFMUL (mm0, mm0) - PFMUL (mm1, mm1) - PFACC (mm0, mm0) - PFADD (mm1, mm0) - PFRSQRT (mm0, mm1) - punpckldq mm1, mm1 - PFMUL (mm1, mm0) - PFMUL (mm2, mm0) - PFMUL (mm3, mm0) - movq QWORD PTR [eax], mm2 - movd DWORD PTR [eax+8], mm3 - movd radius, mm1 - femms - } -#elif defined _LINUX || defined __APPLE__ - long long a,c; - int b,d; - memcpy(&a,&vec[0],sizeof(a)); - memcpy(&b,&vec[2],sizeof(b)); - memcpy(&c,&vec[0],sizeof(c)); - memcpy(&d,&vec[2],sizeof(d)); - - __asm __volatile__( "femms" ); - __asm __volatile__ - ( - "pfmul %y3, %y3\n\t" - "pfmul %y0, %y0 \n\t" - "pfacc %y3, %y3 \n\t" - "pfadd %y3, %y0 \n\t" - "pfrsqrt %y0, %y3 \n\t" - "punpckldq %y0, %y0 \n\t" - "pfmul %y3, %y0 \n\t" - "pfmul %y3, %y2 \n\t" - "pfmul %y3, %y1 \n\t" - : "=y" (radius), "=y" (c), "=y" (d) - : "y" (a), "0" (b), "1" (c), "2" (d) - ); - memcpy(&vec[0],&c,sizeof(c)); - memcpy(&vec[2],&d,sizeof(d)); - __asm __volatile__( "femms" ); - -#else -#error -#endif - } - return radius; -} - - -void FASTCALL _3DNow_VectorNormalizeFast (Vector& vec) -{ - _3DNow_VectorNormalize( vec ); -} - - -// JAY: This complains with the latest processor pack -#ifdef _MSC_VER -#pragma warning(disable: 4730) -#endif - -float _3DNow_InvRSquared(const float* v) -{ - Assert( s_bMathlibInitialized ); - float r2 = 1.f; -#ifdef _WIN32 - _asm { // AMD 3DNow only routine - mov eax, v - femms - movq mm0, QWORD PTR [eax] - movd mm1, DWORD PTR [eax+8] - movd mm2, [r2] - PFMUL (mm0, mm0) - PFMUL (mm1, mm1) - PFACC (mm0, mm0) - PFADD (mm1, mm0) - PFMAX (mm1, mm2) - PFRCP (mm0, mm1) - movd [r2], mm0 - femms - } -#elif defined _LINUX || defined __APPLE__ - long long a,c; - int b; - memcpy(&a,&v[0],sizeof(a)); - memcpy(&b,&v[2],sizeof(b)); - memcpy(&c,&v[0],sizeof(c)); - - __asm __volatile__( "femms" ); - __asm __volatile__ - ( - "PFMUL %y2, %y2 \n\t" - "PFMUL %y3, %y3 \n\t" - "PFACC %y2, %y2 \n\t" - "PFADD %y2, %y3 \n\t" - "PFMAX %y3, %y4 \n\t" - "PFRCP %y3, %y2 \n\t" - "movq %y2, %y0 \n\t" - : "=y" (r2) - : "0" (r2), "y" (a), "y" (b), "y" (c) - ); - __asm __volatile__( "femms" ); -#else -#error -#endif - - return r2; -} diff --git a/mathlib/3dnow.h b/mathlib/3dnow.h deleted file mode 100644 index 3e6e108b..00000000 --- a/mathlib/3dnow.h +++ /dev/null @@ -1,16 +0,0 @@ -//========= Copyright © 1996-2006, Valve Corporation, All rights reserved. ============// -// -// Purpose: -// -//=====================================================================================// - -#ifndef _3DNOW_H -#define _3DNOW_H - -float _3DNow_Sqrt(float x); -float _3DNow_RSqrt(float x); -float FASTCALL _3DNow_VectorNormalize (Vector& vec); -void FASTCALL _3DNow_VectorNormalizeFast (Vector& vec); -float _3DNow_InvRSquared(const float* v); - -#endif // _3DNOW_H diff --git a/mathlib/imagequant.cpp b/mathlib/imagequant.cpp index bdba52a6..b84d2c5c 100644 --- a/mathlib/imagequant.cpp +++ b/mathlib/imagequant.cpp @@ -6,6 +6,7 @@ // //=============================================================================// #include +#include #define N_EXTRAVALUES 1 #define N_DIMENSIONS (3+N_EXTRAVALUES) diff --git a/mathlib/mathlib-2005.sln b/mathlib/mathlib-2005.sln new file mode 100644 index 00000000..309bfa14 --- /dev/null +++ b/mathlib/mathlib-2005.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.25420.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mathlib", "mathlib-2005.vcxproj", "{884C66F2-7F84-4570-AE6C-B634C1113D69}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x86 = Debug|x86 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {884C66F2-7F84-4570-AE6C-B634C1113D69}.Debug|x86.ActiveCfg = Debug|Win32 + {884C66F2-7F84-4570-AE6C-B634C1113D69}.Debug|x86.Build.0 = Debug|Win32 + {884C66F2-7F84-4570-AE6C-B634C1113D69}.Release|x86.ActiveCfg = Release|Win32 + {884C66F2-7F84-4570-AE6C-B634C1113D69}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/mathlib/mathlib-2005.vcproj b/mathlib/mathlib-2005.vcproj deleted file mode 100644 index ff590e86..00000000 --- a/mathlib/mathlib-2005.vcproj +++ /dev/null @@ -1,407 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/mathlib/mathlib-2005.vcxproj b/mathlib/mathlib-2005.vcxproj new file mode 100644 index 00000000..d494a134 --- /dev/null +++ b/mathlib/mathlib-2005.vcxproj @@ -0,0 +1,207 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + mathlib + {884C66F2-7F84-4570-AE6C-B634C1113D69} + mathlib + 8.1 + + + + StaticLibrary + v120_xp + MultiByte + + + StaticLibrary + v140 + MultiByte + + + + + + + + + + + + + <_ProjectFileVersion>14.0.25420.1 + + + .\Debug\ + .\Debug\ + true + true + true + + + .\Release\ + .\Release\ + true + true + true + + + + + + + Disabled + ..\public;..\public\tier0;..\public\tier1;..\public\mathlib;%(AdditionalIncludeDirectories) + WIN32;_WIN32;_DEBUG;DEBUG;_LIB;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions) + true + true + + EnableFastChecks + MultiThreadedDebug + false + Fast + true + true + true + false + + false + + $(IntDir) + $(IntDir) + $(IntDir) + false + + $(IntDir) + Level4 + EditAndContinue + CompileAsCpp + Prompt + + + + + + false + ..\lib\public\mathlib.lib + true + + + true + + + true + $(OutDir)mathlib.bsc + + + + + + + + MaxSpeed + AnySuitable + true + Speed + ..\public;..\public\tier0;..\public\tier1;..\public\mathlib;%(AdditionalIncludeDirectories) + WIN32;_WIN32;NDEBUG;_LIB;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions) + true + + MultiThreaded + false + true + Fast + true + true + true + false + + false + + $(IntDir) + $(IntDir) + $(IntDir) + false + + $(IntDir) + Level4 + OldStyle + CompileAsCpp + Prompt + + + + + + false + ..\lib\public\mathlib.lib + true + + + true + + + true + $(OutDir)mathlib.bsc + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/mathlib/mathlib-2005.vcxproj.filters b/mathlib/mathlib-2005.vcxproj.filters new file mode 100644 index 00000000..53ed2377 --- /dev/null +++ b/mathlib/mathlib-2005.vcxproj.filters @@ -0,0 +1,150 @@ + + + + + {b3a9ae3e-2130-49ce-828c-923c9d4de5b1} + cpp;c;cxx;rc;def;r;odl;idl;hpj;bat + + + {1d151cce-a8fe-4bc0-97f5-605b9531b637} + h + + + {95debf5a-5683-4ab3-ad3a-638316176fd8} + h;hpp;hxx;hm;inl + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + + + Public Header Files + + + Public Header Files + + + Public Header Files + + + Public Header Files + + + Public Header Files + + + Public Header Files + + + Public Header Files + + + Public Header Files + + + Public Header Files + + + Public Header Files + + + Public Header Files + + + Public Header Files + + + Public Header Files + + + Public Header Files + + + Public Header Files + + + Public Header Files + + + Public Header Files + + + Public Header Files + + + Public Header Files + + + Public Header Files + + + Public Header Files + + + Public Header Files + + + Header Files + + + Header Files + + + \ No newline at end of file diff --git a/mathlib/mathlib_base.cpp b/mathlib/mathlib_base.cpp index 353dc2af..919bc4bf 100644 --- a/mathlib/mathlib_base.cpp +++ b/mathlib/mathlib_base.cpp @@ -24,8 +24,6 @@ #include "mathlib/mathlib.h" #include "mathlib/vector.h" #if !defined( _X360 ) -#include "mathlib/amd3dx.h" -#include "3dnow.h" #include "sse.h" #endif @@ -3235,24 +3233,7 @@ void MathLib_Init( float gamma, float texGamma, float brightness, int overbright s_bMMXEnabled = false; } - // SSE Generally performs better than 3DNow when present, so this is placed - // first to allow SSE to override these settings. - if ( bAllow3DNow && pi.m_b3DNow ) - { - s_b3DNowEnabled = true; - - // Select the 3DNow specific routines if available; - pfVectorNormalize = _3DNow_VectorNormalize; - pfVectorNormalizeFast = _3DNow_VectorNormalizeFast; - pfInvRSquared = _3DNow_InvRSquared; - pfSqrt = _3DNow_Sqrt; - pfRSqrt = _3DNow_RSqrt; - pfRSqrtFast = _3DNow_RSqrt; - } - else - { - s_b3DNowEnabled = false; - } + s_b3DNowEnabled = false; if ( bAllowSSE && pi.m_bSSE ) { diff --git a/mathlib/quantize.cpp b/mathlib/quantize.cpp index dbaf15f2..2c8c12e5 100644 --- a/mathlib/quantize.cpp +++ b/mathlib/quantize.cpp @@ -21,6 +21,8 @@ #include +#include + static int current_ndims; static struct QuantizedValue *current_root; static int current_ssize; diff --git a/mathlib/sse.cpp b/mathlib/sse.cpp index d524d2b7..f81eb5b7 100644 --- a/mathlib/sse.cpp +++ b/mathlib/sse.cpp @@ -35,18 +35,18 @@ static const uint32 _sincos_inv_masks[] = { (uint32)~0x0, (uint32)0x0 }; #define _PS_CONST(Name, Val) \ static const __declspec(align(16)) float _ps_##Name[4] = { Val, Val, Val, Val } -#elif defined _LINUX || defined __APPLE__ +#elif POSIX #define _PS_EXTERN_CONST(Name, Val) \ - const __attribute__((aligned(16))) float _ps_##Name[4] = { Val, Val, Val, Val } + const float _ps_##Name[4] __attribute__((aligned(16))) = { Val, Val, Val, Val } #define _PS_EXTERN_CONST_TYPE(Name, Type, Val) \ - const __attribute__((aligned(16))) Type _ps_##Name[4] = { Val, Val, Val, Val }; \ + const Type _ps_##Name[4] __attribute__((aligned(16))) = { Val, Val, Val, Val }; \ #define _EPI32_CONST(Name, Val) \ - static const __attribute__((aligned(16))) int32 _epi32_##Name[4] = { Val, Val, Val, Val } + static const int32 _epi32_##Name[4] __attribute__((aligned(16))) = { Val, Val, Val, Val } #define _PS_CONST(Name, Val) \ - static const __attribute__((aligned(16))) float _ps_##Name[4] = { Val, Val, Val, Val } + static const float _ps_##Name[4] __attribute__((aligned(16))) = { Val, Val, Val, Val } #endif _PS_EXTERN_CONST(am_0, 0.0f); @@ -90,14 +90,8 @@ float _SSE_Sqrt(float x) sqrtss xmm0, x movss root, xmm0 } -#elif defined _LINUX || defined __APPLE__ - __asm__ __volatile__( - "movss %1,%%xmm2\n" - "sqrtss %%xmm2,%%xmm1\n" - "movss %%xmm1,%0" - : "=m" (root) - : "m" (x) - ); +#elif POSIX + _mm_store_ss( &root, _mm_sqrt_ss( _mm_load_ss( &x ) ) ); #endif return root; } @@ -120,14 +114,21 @@ float _SSE_RSqrtAccurate(float x) return (0.5f * rroot) * (3.f - (x * rroot) * rroot); } #else + +#ifdef POSIX +const __m128 f3 = _mm_set_ss(3.0f); // 3 as SSE value +const __m128 f05 = _mm_set_ss(0.5f); // 0.5 as SSE value +#endif + // Intel / Kipps SSE RSqrt. Significantly faster than above. float _SSE_RSqrtAccurate(float a) { + +#ifdef _WIN32 float x; float half = 0.5f; float three = 3.f; -#ifdef _WIN32 __asm { movss xmm3, a; @@ -143,26 +144,25 @@ float _SSE_RSqrtAccurate(float a) movss x, xmm1; } -#elif defined _LINUX || defined __APPLE__ - __asm__ __volatile__( - "movss %1, %%xmm3 \n\t" - "movss %2, %%xmm1 \n\t" - "movss %3, %%xmm2 \n\t" - "rsqrtss %%xmm3, %%xmm0 \n\t" - "mulss %%xmm0, %%xmm3 \n\t" - "mulss %%xmm0, %%xmm1 \n\t" - "mulss %%xmm0, %%xmm3 \n\t" - "subss %%xmm3, %%xmm2 \n\t" - "mulss %%xmm2, %%xmm1 \n\t" - "movss %%xmm1, %0 \n\t" - : "=m" (x) - : "m" (a), "m" (half), "m" (three) -); + + return x; +#elif POSIX + __m128 xx = _mm_load_ss( &a ); + __m128 xr = _mm_rsqrt_ss( xx ); + __m128 xt; + + xt = _mm_mul_ss( xr, xr ); + xt = _mm_mul_ss( xt, xx ); + xt = _mm_sub_ss( f3, xt ); + xt = _mm_mul_ss( xt, f05 ); + xr = _mm_mul_ss( xr, xt ); + + _mm_store_ss( &a, xr ); + return a; #else #error "Not Implemented" #endif - return x; } #endif @@ -179,14 +179,8 @@ float _SSE_RSqrtFast(float x) rsqrtss xmm0, x movss rroot, xmm0 } -#elif defined _LINUX || defined __APPLE__ - __asm__ __volatile__( - "rsqrtss %1, %%xmm0 \n\t" - "movss %%xmm0, %0 \n\t" - : "=m" (x) - : "m" (rroot) - : "%xmm0" - ); +#elif POSIX + __asm__ __volatile__( "rsqrtss %0, %1" : "=x" (rroot) : "x" (x) ); #else #error #endif @@ -202,11 +196,14 @@ float FASTCALL _SSE_VectorNormalize (Vector& vec) // sice vec only has 3 floats, we can't "movaps" directly into it. #ifdef _WIN32 __declspec(align(16)) float result[4]; -#elif defined _LINUX || defined __APPLE__ - __attribute__((aligned(16))) float result[4]; +#elif POSIX + float result[4] __attribute__((aligned(16))); #endif float *v = &vec[0]; +#ifdef _WIN32 + float *r = &result[0]; +#endif float radius = 0.f; // Blah, get rid of these comparisons ... in reality, if you have all 3 as zero, it shouldn't @@ -214,7 +211,6 @@ float FASTCALL _SSE_VectorNormalize (Vector& vec) if ( v[0] || v[1] || v[2] ) { #ifdef _WIN32 - float *r = &result[0]; _asm { mov eax, v @@ -239,7 +235,7 @@ float FASTCALL _SSE_VectorNormalize (Vector& vec) mulps xmm4, xmm1 // r4 = vx * 1/radius, vy * 1/radius, vz * 1/radius, X movaps [edx], xmm4 // v = vx * 1/radius, vy * 1/radius, vz * 1/radius, X } -#elif defined _LINUX || defined __APPLE__ +#elif POSIX __asm__ __volatile__( #ifdef ALIGNED_VECTOR "movaps %2, %%xmm4 \n\t" @@ -262,6 +258,7 @@ float FASTCALL _SSE_VectorNormalize (Vector& vec) "movaps %%xmm4, %1 \n\t" : "=m" (radius), "=m" (result) : "m" (*v) + : "xmm1", "xmm2", "xmm3", "xmm4" ); #else #error "Not Implemented" @@ -303,12 +300,13 @@ float _SSE_InvRSquared(const float* v) shufps xmm2, xmm2, 1 // x2 = vy * vy, X, X, X addss xmm1, xmm2 // x1 = (vx * vx) + (vy * vy), X, X, X addss xmm1, xmm3 // x1 = (vx * vx) + (vy * vy) + (vz * vz), X, X, X - maxss xmm1, xmm5 // x1 = MAX( 1.0, x1 ) - rcpss xmm0, xmm1 // x0 = 1 / MAX( 1.0, x1 ) + maxss xmm1, xmm5 // x1 = max( 1.0, x1 ) + rcpss xmm0, xmm1 // x0 = 1 / max( 1.0, x1 ) movss inv_r2, xmm0 // inv_r2 = x0 } -#elif defined _LINUX || defined __APPLE__ +#elif POSIX __asm__ __volatile__( + "movss %0, %%xmm5 \n\t" #ifdef ALIGNED_VECTOR "movaps %1, %%xmm4 \n\t" #else @@ -324,8 +322,9 @@ float _SSE_InvRSquared(const float* v) "maxss %%xmm5, %%xmm1 \n\t" "rcpss %%xmm1, %%xmm0 \n\t" "movss %%xmm0, %0 \n\t" - : "=m" (inv_r2) - : "m" (*v), "m" (inv_r2) + : "+m" (inv_r2) + : "m" (*v) + : "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5" ); #else #error "Not Implemented" @@ -334,6 +333,48 @@ float _SSE_InvRSquared(const float* v) return inv_r2; } + +#ifdef POSIX +// #define _PS_CONST(Name, Val) static const ALIGN16 float _ps_##Name[4] ALIGN16_POST = { Val, Val, Val, Val } +#define _PS_CONST_TYPE(Name, Type, Val) static const ALIGN16 Type _ps_##Name[4] ALIGN16_POST = { Val, Val, Val, Val } + +_PS_CONST_TYPE(sign_mask, int, 0x80000000); +_PS_CONST_TYPE(inv_sign_mask, int, ~0x80000000); + + +#define _PI32_CONST(Name, Val) static const ALIGN16 int _pi32_##Name[4] ALIGN16_POST = { Val, Val, Val, Val } + +_PI32_CONST(1, 1); +_PI32_CONST(inv1, ~1); +_PI32_CONST(2, 2); +_PI32_CONST(4, 4); +_PI32_CONST(0x7f, 0x7f); +_PS_CONST(1 , 1.0f); +_PS_CONST(0p5, 0.5f); + +_PS_CONST(minus_cephes_DP1, -0.78515625); +_PS_CONST(minus_cephes_DP2, -2.4187564849853515625e-4); +_PS_CONST(minus_cephes_DP3, -3.77489497744594108e-8); +_PS_CONST(sincof_p0, -1.9515295891E-4); +_PS_CONST(sincof_p1, 8.3321608736E-3); +_PS_CONST(sincof_p2, -1.6666654611E-1); +_PS_CONST(coscof_p0, 2.443315711809948E-005); +_PS_CONST(coscof_p1, -1.388731625493765E-003); +_PS_CONST(coscof_p2, 4.166664568298827E-002); +_PS_CONST(cephes_FOPI, 1.27323954473516); // 4 / M_PI + +typedef union xmm_mm_union { + __m128 xmm; + __m64 mm[2]; +} xmm_mm_union; + +#define COPY_MM_TO_XMM(mm0_, mm1_, xmm_) { xmm_mm_union u; u.mm[0]=mm0_; u.mm[1]=mm1_; xmm_ = u.xmm; } + +typedef __m128 v4sf; // vector of 4 float (sse1) +typedef __m64 v2si; // vector of 2 int (mmx) + +#endif + void _SSE_SinCos(float x, float* s, float* c) { #ifdef _WIN32 @@ -421,8 +462,121 @@ void _SSE_SinCos(float x, float* s, float* c) movss [eax], xmm0 movss [edx], xmm4 } -#elif defined _LINUX || defined __APPLE__ -// #warning "_SSE_sincos NOT implemented!" +#elif POSIX + + Assert( "Needs testing, verify impl!\n" ); + + v4sf xx = _mm_load_ss( &x ); + + v4sf xmm1, xmm2, xmm3 = _mm_setzero_ps(), sign_bit_sin, y; + v2si mm0, mm1, mm2, mm3, mm4, mm5; + sign_bit_sin = xx; + /* take the absolute value */ + xx = _mm_and_ps(xx, *(v4sf*)_ps_inv_sign_mask); + /* extract the sign bit (upper one) */ + sign_bit_sin = _mm_and_ps(sign_bit_sin, *(v4sf*)_ps_sign_mask); + + /* scale by 4/Pi */ + y = _mm_mul_ps(xx, *(v4sf*)_ps_cephes_FOPI); + + /* store the integer part of y in mm2:mm3 */ + xmm3 = _mm_movehl_ps(xmm3, y); + mm2 = _mm_cvttps_pi32(y); + mm3 = _mm_cvttps_pi32(xmm3); + + /* j=(j+1) & (~1) (see the cephes sources) */ + mm2 = _mm_add_pi32(mm2, *(v2si*)_pi32_1); + mm3 = _mm_add_pi32(mm3, *(v2si*)_pi32_1); + mm2 = _mm_and_si64(mm2, *(v2si*)_pi32_inv1); + mm3 = _mm_and_si64(mm3, *(v2si*)_pi32_inv1); + + y = _mm_cvtpi32x2_ps(mm2, mm3); + + mm4 = mm2; + mm5 = mm3; + + /* get the swap sign flag for the sine */ + mm0 = _mm_and_si64(mm2, *(v2si*)_pi32_4); + mm1 = _mm_and_si64(mm3, *(v2si*)_pi32_4); + mm0 = _mm_slli_pi32(mm0, 29); + mm1 = _mm_slli_pi32(mm1, 29); + v4sf swap_sign_bit_sin; + COPY_MM_TO_XMM(mm0, mm1, swap_sign_bit_sin); + + /* get the polynom selection mask for the sine */ + + mm2 = _mm_and_si64(mm2, *(v2si*)_pi32_2); + mm3 = _mm_and_si64(mm3, *(v2si*)_pi32_2); + mm2 = _mm_cmpeq_pi32(mm2, _mm_setzero_si64()); + mm3 = _mm_cmpeq_pi32(mm3, _mm_setzero_si64()); + v4sf poly_mask; + COPY_MM_TO_XMM(mm2, mm3, poly_mask); + + /* The magic pass: "Extended precision modular arithmetic" + x = ((x - y * DP1) - y * DP2) - y * DP3; */ + xmm1 = *(v4sf*)_ps_minus_cephes_DP1; + xmm2 = *(v4sf*)_ps_minus_cephes_DP2; + xmm3 = *(v4sf*)_ps_minus_cephes_DP3; + xmm1 = _mm_mul_ps(y, xmm1); + xmm2 = _mm_mul_ps(y, xmm2); + xmm3 = _mm_mul_ps(y, xmm3); + xx = _mm_add_ps(xx, xmm1); + xx = _mm_add_ps(xx, xmm2); + xx = _mm_add_ps(xx, xmm3); + + /* get the sign flag for the cosine */ + mm4 = _mm_sub_pi32(mm4, *(v2si*)_pi32_2); + mm5 = _mm_sub_pi32(mm5, *(v2si*)_pi32_2); + mm4 = _mm_andnot_si64(mm4, *(v2si*)_pi32_4); + mm5 = _mm_andnot_si64(mm5, *(v2si*)_pi32_4); + mm4 = _mm_slli_pi32(mm4, 29); + mm5 = _mm_slli_pi32(mm5, 29); + v4sf sign_bit_cos; + COPY_MM_TO_XMM(mm4, mm5, sign_bit_cos); + _mm_empty(); /* good-bye mmx */ + + sign_bit_sin = _mm_xor_ps(sign_bit_sin, swap_sign_bit_sin); + + + /* Evaluate the first polynom (0 <= x <= Pi/4) */ + v4sf z = _mm_mul_ps(xx,xx); + y = *(v4sf*)_ps_coscof_p0; + + y = _mm_mul_ps(y, z); + y = _mm_add_ps(y, *(v4sf*)_ps_coscof_p1); + y = _mm_mul_ps(y, z); + y = _mm_add_ps(y, *(v4sf*)_ps_coscof_p2); + y = _mm_mul_ps(y, z); + y = _mm_mul_ps(y, z); + v4sf tmp = _mm_mul_ps(z, *(v4sf*)_ps_0p5); + y = _mm_sub_ps(y, tmp); + y = _mm_add_ps(y, *(v4sf*)_ps_1); + + /* Evaluate the second polynom (Pi/4 <= x <= 0) */ + + v4sf y2 = *(v4sf*)_ps_sincof_p0; + y2 = _mm_mul_ps(y2, z); + y2 = _mm_add_ps(y2, *(v4sf*)_ps_sincof_p1); + y2 = _mm_mul_ps(y2, z); + y2 = _mm_add_ps(y2, *(v4sf*)_ps_sincof_p2); + y2 = _mm_mul_ps(y2, z); + y2 = _mm_mul_ps(y2, xx); + y2 = _mm_add_ps(y2, xx); + + /* select the correct result from the two polynoms */ + xmm3 = poly_mask; + v4sf ysin2 = _mm_and_ps(xmm3, y2); + v4sf ysin1 = _mm_andnot_ps(xmm3, y); + y2 = _mm_sub_ps(y2,ysin2); + y = _mm_sub_ps(y, ysin1); + + xmm1 = _mm_add_ps(ysin1,ysin2); + xmm2 = _mm_add_ps(y,y2); + + /* update the sign */ + _mm_store_ss( s, _mm_xor_ps(xmm1, sign_bit_sin) ); + _mm_store_ss( c, _mm_xor_ps(xmm2, sign_bit_cos) ); + #else #error "Not Implemented" #endif @@ -479,8 +633,102 @@ float _SSE_cos( float x ) movss x, xmm0 } -#elif defined _LINUX || defined __APPLE__ -// #warning "_SSE_cos NOT implemented!" +#elif POSIX + + Assert( "Needs testing, verify impl!\n" ); + + v4sf xmm1, xmm2 = _mm_setzero_ps(), xmm3, y; + v2si mm0, mm1, mm2, mm3; + /* take the absolute value */ + v4sf xx = _mm_load_ss( &x ); + + xx = _mm_and_ps(xx, *(v4sf*)_ps_inv_sign_mask); + + /* scale by 4/Pi */ + y = _mm_mul_ps(xx, *(v4sf*)_ps_cephes_FOPI); + + /* store the integer part of y in mm0:mm1 */ + xmm2 = _mm_movehl_ps(xmm2, y); + mm2 = _mm_cvttps_pi32(y); + mm3 = _mm_cvttps_pi32(xmm2); + + /* j=(j+1) & (~1) (see the cephes sources) */ + mm2 = _mm_add_pi32(mm2, *(v2si*)_pi32_1); + mm3 = _mm_add_pi32(mm3, *(v2si*)_pi32_1); + mm2 = _mm_and_si64(mm2, *(v2si*)_pi32_inv1); + mm3 = _mm_and_si64(mm3, *(v2si*)_pi32_inv1); + + y = _mm_cvtpi32x2_ps(mm2, mm3); + + + mm2 = _mm_sub_pi32(mm2, *(v2si*)_pi32_2); + mm3 = _mm_sub_pi32(mm3, *(v2si*)_pi32_2); + + /* get the swap sign flag in mm0:mm1 and the + polynom selection mask in mm2:mm3 */ + + mm0 = _mm_andnot_si64(mm2, *(v2si*)_pi32_4); + mm1 = _mm_andnot_si64(mm3, *(v2si*)_pi32_4); + mm0 = _mm_slli_pi32(mm0, 29); + mm1 = _mm_slli_pi32(mm1, 29); + + mm2 = _mm_and_si64(mm2, *(v2si*)_pi32_2); + mm3 = _mm_and_si64(mm3, *(v2si*)_pi32_2); + + mm2 = _mm_cmpeq_pi32(mm2, _mm_setzero_si64()); + mm3 = _mm_cmpeq_pi32(mm3, _mm_setzero_si64()); + + v4sf sign_bit, poly_mask; + COPY_MM_TO_XMM(mm0, mm1, sign_bit); + COPY_MM_TO_XMM(mm2, mm3, poly_mask); + _mm_empty(); /* good-bye mmx */ + + /* The magic pass: "Extended precision modular arithmetic" + x = ((x - y * DP1) - y * DP2) - y * DP3; */ + xmm1 = *(v4sf*)_ps_minus_cephes_DP1; + xmm2 = *(v4sf*)_ps_minus_cephes_DP2; + xmm3 = *(v4sf*)_ps_minus_cephes_DP3; + xmm1 = _mm_mul_ps(y, xmm1); + xmm2 = _mm_mul_ps(y, xmm2); + xmm3 = _mm_mul_ps(y, xmm3); + xx = _mm_add_ps(xx, xmm1); + xx = _mm_add_ps(xx, xmm2); + xx = _mm_add_ps(xx, xmm3); + + /* Evaluate the first polynom (0 <= x <= Pi/4) */ + y = *(v4sf*)_ps_coscof_p0; + v4sf z = _mm_mul_ps(xx,xx); + + y = _mm_mul_ps(y, z); + y = _mm_add_ps(y, *(v4sf*)_ps_coscof_p1); + y = _mm_mul_ps(y, z); + y = _mm_add_ps(y, *(v4sf*)_ps_coscof_p2); + y = _mm_mul_ps(y, z); + y = _mm_mul_ps(y, z); + v4sf tmp = _mm_mul_ps(z, *(v4sf*)_ps_0p5); + y = _mm_sub_ps(y, tmp); + y = _mm_add_ps(y, *(v4sf*)_ps_1); + + /* Evaluate the second polynom (Pi/4 <= x <= 0) */ + + v4sf y2 = *(v4sf*)_ps_sincof_p0; + y2 = _mm_mul_ps(y2, z); + y2 = _mm_add_ps(y2, *(v4sf*)_ps_sincof_p1); + y2 = _mm_mul_ps(y2, z); + y2 = _mm_add_ps(y2, *(v4sf*)_ps_sincof_p2); + y2 = _mm_mul_ps(y2, z); + y2 = _mm_mul_ps(y2, xx); + y2 = _mm_add_ps(y2, xx); + + /* select the correct result from the two polynoms */ + xmm3 = poly_mask; + y2 = _mm_and_ps(xmm3, y2); //, xmm3); + y = _mm_andnot_ps(xmm3, y); + y = _mm_add_ps(y,y2); + /* update the sign */ + + _mm_store_ss( &x, _mm_xor_ps(y, sign_bit) ); + #else #error "Not Implemented" #endif @@ -491,6 +739,7 @@ float _SSE_cos( float x ) //----------------------------------------------------------------------------- // SSE2 implementations of optimized routines: //----------------------------------------------------------------------------- +#ifdef PLATFORM_WINDOWS_PC32 void _SSE2_SinCos(float x, float* s, float* c) // any x { #ifdef _WIN32 @@ -569,13 +818,16 @@ void _SSE2_SinCos(float x, float* s, float* c) // any x movss [eax], xmm0 movss [edx], xmm6 } -#elif defined _LINUX || defined __APPLE__ -// #warning "_SSE2_SinCos NOT implemented!" +#elif POSIX + #warning "_SSE2_SinCos NOT implemented!" + Assert( 0 ); #else #error "Not Implemented" #endif } +#endif // PLATFORM_WINDOWS_PC32 +#ifdef PLATFORM_WINDOWS_PC32 float _SSE2_cos(float x) { #ifdef _WIN32 @@ -624,15 +876,18 @@ float _SSE2_cos(float x) mulss xmm0, xmm1 movss x, xmm0 } -#elif defined _LINUX || defined __APPLE__ -// #warning "_SSE2_cos NOT implemented!" +#elif POSIX + #warning "_SSE2_cos NOT implemented!" + Assert( 0 ); #else #error "Not Implemented" #endif return x; } +#endif // PLATFORM_WINDOWS_PC32 +#if 0 // SSE Version of VectorTransform void VectorTransformSSE(const float *in1, const matrix3x4_t& in2, float *out1) { @@ -681,8 +936,8 @@ void VectorTransformSSE(const float *in1, const matrix3x4_t& in2, float *out1) addss xmm0, [ecx+12] movss [edx+8], xmm0; } -#elif defined _LINUX || defined __APPLE__ -// #warning "VectorTransformSSE C implementation only" +#elif POSIX + #warning "VectorTransformSSE C implementation only" out1[0] = DotProduct(in1, in2[0]) + in2[0][3]; out1[1] = DotProduct(in1, in2[1]) + in2[1][3]; out1[2] = DotProduct(in1, in2[2]) + in2[2][3]; @@ -690,7 +945,9 @@ void VectorTransformSSE(const float *in1, const matrix3x4_t& in2, float *out1) #error "Not Implemented" #endif } +#endif +#if 0 void VectorRotateSSE( const float *in1, const matrix3x4_t& in2, float *out1 ) { Assert( s_bMathlibInitialized ); @@ -735,8 +992,8 @@ void VectorRotateSSE( const float *in1, const matrix3x4_t& in2, float *out1 ) addss xmm0, xmm2; movss [edx+8], xmm0; } -#elif defined _LINUX || defined __APPLE__ -// #warning "VectorRotateSSE C implementation only" +#elif POSIX + #warning "VectorRotateSSE C implementation only" out1[0] = DotProduct( in1, in2[0] ); out1[1] = DotProduct( in1, in2[1] ); out1[2] = DotProduct( in1, in2[2] ); @@ -744,6 +1001,7 @@ void VectorRotateSSE( const float *in1, const matrix3x4_t& in2, float *out1 ) #error "Not Implemented" #endif } +#endif #ifdef _WIN32 void _declspec(naked) _SSE_VectorMA( const float *start, float scale, const float *direction, float *dest ) diff --git a/public/SoundEmitterSystem/isoundemittersystembase.h b/public/SoundEmitterSystem/isoundemittersystembase.h index 46bd4b2b..db9b4bf1 100644 --- a/public/SoundEmitterSystem/isoundemittersystembase.h +++ b/public/SoundEmitterSystem/isoundemittersystembase.h @@ -25,6 +25,7 @@ typedef short HSOUNDSCRIPTHANDLE; #define SOUNDEMITTER_INVALID_HANDLE (HSOUNDSCRIPTHANDLE)-1 +class IFileList; //----------------------------------------------------------------------------- // Purpose: @@ -253,13 +254,15 @@ public: // Called from both client and server (single player) or just one (server only in dedicated server and client only if connected to a remote server) // Called by LevelInitPreEntity to override sound scripts for the mod with level specific overrides based on custom mapnames, etc. - virtual void AddSoundOverrides( char const *scriptfile ) = 0; + virtual void AddSoundOverrides( char const *scriptfile, bool bUnknown ) = 0; // Called by either client or server in LevelShutdown to clear out custom overrides virtual void ClearSoundOverrides() = 0; virtual bool GetParametersForSoundEx( const char *soundname, HSOUNDSCRIPTHANDLE& handle, CSoundParameters& params, gender_t gender, bool isbeingemitted = false ) = 0; virtual soundlevel_t LookupSoundLevelByHandle( char const *soundname, HSOUNDSCRIPTHANDLE& handle ) = 0; + + virtual void ReloadSoundEntriesInList( IFileList *pFileList ) = 0; }; #endif // ISOUNDEMITTERSYSTEMBASE_H diff --git a/public/datamap.h b/public/datamap.h index de3b3e93..537936ab 100644 --- a/public/datamap.h +++ b/public/datamap.h @@ -120,10 +120,6 @@ DECLARE_FIELD_SIZE( FIELD_MODELINDEX, sizeof(int) ) DECLARE_FIELD_SIZE( FIELD_MATERIALINDEX, sizeof(int) ) -#ifndef offsetof -#define offsetof(s,m) (size_t)&(((s *)0)->m) -#endif - #define ARRAYSIZE2D(p) (sizeof(p)/sizeof(p[0][0])) #define SIZE_OF_ARRAY(p) _ARRAYSIZE(p) diff --git a/public/eiface.h b/public/eiface.h index 35ee4a2f..5167ad54 100644 --- a/public/eiface.h +++ b/public/eiface.h @@ -57,6 +57,8 @@ class CStandardSendProxies; class IAchievementMgr; class CGamestatsData; class CSteamID; +class IGet; +class IGMODDataTable; typedef struct player_info_s player_info_t; @@ -72,6 +74,12 @@ typedef struct player_info_s player_info_t; #define INTERFACEVERSION_VENGINESERVER "VEngineServer021" +struct bbox_t +{ + Vector mins; + Vector maxs; +}; + //----------------------------------------------------------------------------- // Purpose: Interface the engine exposes to the game DLL //----------------------------------------------------------------------------- @@ -387,12 +395,35 @@ public: // Send a client command keyvalues // keyvalues are deleted inside the function virtual void ClientCommandKeyValues( edict_t *pEdict, KeyValues *pCommand ) = 0; + + // Returns the SteamID of the specified player. It'll be NULL if the player hasn't authenticated yet. + virtual const CSteamID *GetClientSteamIDByPlayerIndex( int entnum ) = 0; + // Gets a list of all clusters' bounds. Returns total number of clusters. + virtual int GetClusterCount() = 0; + virtual int GetAllClusterBounds( bbox_t *pBBoxList, int maxBBox ) = 0; + + // Create a bot with the given name. Returns NULL if fake client can't be created + virtual edict_t *CreateFakeClientEx( const char *netname, bool bReportFakeClient = true ) = 0; + + // Server version from the steam.inf, this will be compared to the GC version + virtual int GetServerVersion() const = 0; + + virtual void GMOD_SetTimeManipulator( float flFramerateScale ) = 0; + virtual void GMOD_SendToClient( IRecipientFilter *filter, void *pData, int size ) = 0; + virtual void GMOD_SendToClient( int player_idx, void *pData, int size ) = 0; + virtual void GMOD_RawServerCommand( const char *str ) = 0; + virtual IGMODDataTable *GMOD_CreateDataTable( void ) = 0; + virtual void GMOD_DestroyDataTable( IGMODDataTable *pTable ) = 0; + virtual const char *GMOD_GetServerAddress( void ) = 0; + virtual void GMOD_LoadModel( const char *pszModel ) = 0; }; -#define INTERFACEVERSION_SERVERGAMEDLL_VERSION_4 "ServerGameDLL004" -#define INTERFACEVERSION_SERVERGAMEDLL_VERSION_5 "ServerGameDLL005" -#define INTERFACEVERSION_SERVERGAMEDLL_VERSION_6 "ServerGameDLL006" -#define INTERFACEVERSION_SERVERGAMEDLL "ServerGameDLL007" +#define INTERFACEVERSION_SERVERGAMEDLL_VERSION_8 "ServerGameDLL008" +#define INTERFACEVERSION_SERVERGAMEDLL_VERSION_9 "ServerGameDLL009" +#define INTERFACEVERSION_SERVERGAMEDLL "ServerGameDLL009" +#define INTERFACEVERSION_SERVERGAMEDLL_INT 9 + +class IServerGCLobby; //----------------------------------------------------------------------------- // Purpose: These are the interfaces that the game .dll exposes to the engine @@ -400,15 +431,18 @@ public: abstract_class IServerGameDLL { public: + virtual bool PreInit( CreateInterfaceFn engineFactory, IGet *get ) = 0; + // Initialize the game (one-time call when the DLL is first loaded ) // Return false if there is an error during startup. virtual bool DLLInit( CreateInterfaceFn engineFactory, CreateInterfaceFn physicsFactory, CreateInterfaceFn fileSystemFactory, CGlobalVars *pGlobals) = 0; - - virtual bool ReplayInit( CreateInterfaceFn replayFactory ) = 0; - + + // Setup replay interfaces on the server + virtual bool ReplayInit( CreateInterfaceFn fnReplayFactory ) = 0; + // This is called when a new game is started. (restart, map) virtual bool GameInit( void ) = 0; @@ -498,11 +532,29 @@ public: // iCookie is the value returned by IServerPluginHelpers::StartQueryCvarValue. // Added with version 2 of the interface. virtual void OnQueryCvarValueFinished( QueryCvarCookie_t iCookie, edict_t *pPlayerEntity, EQueryCvarValueStatus eStatus, const char *pCvarName, const char *pCvarValue ) = 0; - + // Called after the steam API has been activated post-level startup virtual void GameServerSteamAPIActivated( void ) = 0; - + + // Called after the steam API has been shutdown post-level startup virtual void GameServerSteamAPIShutdown( void ) = 0; + + virtual void SetServerHibernation( bool bHibernating ) = 0; + + // interface to the new GC based lobby system + virtual IServerGCLobby *GetServerGCLobby() = 0; + + // Return override string to show in the server browser + // "map" column, or NULL to just use the default value + // (the map name) + virtual const char *GetServerBrowserMapOverride() = 0; + + // Get gamedata string to send to the master serer updater. + virtual const char *GetServerBrowserGameData() = 0; + + virtual bool GMOD_CheckPassword( + unsigned long long, const char *, const char *, const char *, const char *, char *pszRejectMsg, unsigned int len + ) = 0; }; //----------------------------------------------------------------------------- @@ -606,6 +658,8 @@ public: virtual void ClientCommandKeyValues( edict_t *pEntity, KeyValues *pKeyValues ) = 0; virtual void ClientSpawned( edict_t *pEntity ) = 0; + + virtual void GMOD_ReceiveClientMessage( int, edict_t *pEntity, bf_read *bf, int len ) = 0; }; #define INTERFACEVERSION_UPLOADGAMESTATS "ServerUploadGameStats001" diff --git a/public/engine/ICollideable.h b/public/engine/ICollideable.h index c40c972b..3dce3b84 100644 --- a/public/engine/ICollideable.h +++ b/public/engine/ICollideable.h @@ -32,8 +32,10 @@ public: // These methods return the bounds of an OBB measured in "collision" space // which can be retreived through the CollisionToWorldTransform or // GetCollisionOrigin/GetCollisionAngles methods - virtual const Vector& OBBMins( ) const = 0; - virtual const Vector& OBBMaxs( ) const = 0; + virtual const Vector& OBBMinsPreScaled() const = 0; + virtual const Vector& OBBMaxsPreScaled() const = 0; + virtual const Vector& OBBMins() const = 0; + virtual const Vector& OBBMaxs() const = 0; // Returns the bounds of a world-space box used when the collideable is being traced // against as a trigger. It's only valid to call these methods if the solid flags diff --git a/public/engine/IEngineSound.h b/public/engine/IEngineSound.h index 25bcef2b..62b91dd5 100644 --- a/public/engine/IEngineSound.h +++ b/public/engine/IEngineSound.h @@ -72,15 +72,15 @@ public: // NOTE: setting iEntIndex to -1 will cause the sound to be emitted from the local // player (client-side only) virtual void EmitSound( IRecipientFilter& filter, int iEntIndex, int iChannel, const char *pSample, - float flVolume, float flAttenuation, int iFlags = 0, int iPitch = PITCH_NORM, + float flVolume, float flAttenuation, int iFlags = 0, int iPitch = PITCH_NORM, int iSpecialDSP = 0, const Vector *pOrigin = NULL, const Vector *pDirection = NULL, CUtlVector< Vector >* pUtlVecOrigins = NULL, bool bUpdatePositions = true, float soundtime = 0.0f, int speakerentity = -1 ) = 0; virtual void EmitSound( IRecipientFilter& filter, int iEntIndex, int iChannel, const char *pSample, - float flVolume, soundlevel_t iSoundlevel, int iFlags = 0, int iPitch = PITCH_NORM, + float flVolume, soundlevel_t iSoundlevel, int iFlags = 0, int iPitch = PITCH_NORM, int iSpecialDSP = 0, const Vector *pOrigin = NULL, const Vector *pDirection = NULL, CUtlVector< Vector >* pUtlVecOrigins = NULL, bool bUpdatePositions = true, float soundtime = 0.0f, int speakerentity = -1 ) = 0; virtual void EmitSentenceByIndex( IRecipientFilter& filter, int iEntIndex, int iChannel, int iSentenceIndex, - float flVolume, soundlevel_t iSoundlevel, int iFlags = 0, int iPitch = PITCH_NORM, + float flVolume, soundlevel_t iSoundlevel, int iFlags = 0, int iPitch = PITCH_NORM, int iSpecialDSP = 0, const Vector *pOrigin = NULL, const Vector *pDirection = NULL, CUtlVector< Vector >* pUtlVecOrigins = NULL, bool bUpdatePositions = true, float soundtime = 0.0f, int speakerentity = -1 ) = 0; virtual void StopSound( int iEntIndex, int iChannel, const char *pSample ) = 0; diff --git a/public/filesystem.h b/public/filesystem.h index b856a6c3..986a8be7 100644 --- a/public/filesystem.h +++ b/public/filesystem.h @@ -11,6 +11,7 @@ #include "tier0/memalloc.h" #include "tier1/interface.h" #include "tier1/utlsymbol.h" +#include "tier1/utlstring.h" #include "appframework/IAppSystem.h" #include "tier1/checksum_crc.h" @@ -300,7 +301,8 @@ enum FSAsyncFlags_t enum EFileCRCStatus { k_eFileCRCStatus_CantOpenFile, // We don't have this file. - k_eFileCRCStatus_GotCRC + k_eFileCRCStatus_GotCRC, + k_eFileCRCStatus_FileInVPK }; // Used in CacheFileCRCs. @@ -338,6 +340,29 @@ struct FileAsyncRequest_t FSAllocFunc_t pfnAlloc; // custom allocator. can be null. not compatible with FSASYNC_FLAGS_FREEDATAPTR }; +struct MD5Value_t +{ + unsigned char bits[16]; +}; + +struct FileHash_t +{ + int m_eFileHashType; + CRC32_t m_crcIOSequence; + MD5Value_t m_md5contents; + int m_cbFileLen; + int m_PackFileID; + int m_nPackFileNumber; +}; + +class CUnverifiedFileHash +{ +public: + char m_PathID[MAX_PATH]; + char m_Filename[MAX_PATH]; + int m_nFileFraction; + FileHash_t m_FileHash; +}; class CUnverifiedCRCFile { @@ -347,13 +372,22 @@ public: CRC32_t m_CRC; }; - // Spew flags for SetWhitelistSpewFlags (set with the fs_whitelist_spew_flags cvar). // Update the comment for the fs_whitelist_spew_flags cvar if you change these. #define WHITELIST_SPEW_WHILE_LOADING 0x0001 // list files as they are added to the CRC tracker #define WHITELIST_SPEW_RELOAD_FILES 0x0002 // show files the filesystem is telling the engine to reload #define WHITELIST_SPEW_DONT_RELOAD_FILES 0x0004 // show files the filesystem is NOT telling the engine to reload +abstract_class IPureServerWhitelist +{ +public: + virtual void AddRef() = 0; + virtual void Release() = 0; + virtual const char *GetFileClass( const char * ) = 0; + virtual int GetTrustedKeyCount() const = 0; + virtual void GetTrustedKey( int keyIndex, int *pBuffer ) = 0; +}; + //----------------------------------------------------------------------------- // Base file system interface @@ -401,7 +435,7 @@ public: // Main file system interface //----------------------------------------------------------------------------- -#define FILESYSTEM_INTERFACE_VERSION "VFileSystem019" +#define FILESYSTEM_INTERFACE_VERSION "VFileSystem022" abstract_class IFileSystem : public IAppSystem, public IBaseFileSystem { @@ -692,7 +726,7 @@ public: // This should be called ONCE at startup. Multiplayer games (gameinfo.txt does not contain singleplayer_only) // want to enable this so sv_pure works. - virtual void EnableWhitelistFileTracking( bool bEnable ) = 0; + virtual void EnableWhitelistFileTracking( bool bEnable, bool bCacheAllVPKHashes, bool bRecalculateAndCheckHashes ) = 0; // This is called when the client connects to a server using a pure_server_whitelist.txt file. // @@ -714,7 +748,7 @@ public: // and the engine should reload it so it can come from Steam. // // Be sure to call Release() on pFilesToReload. - virtual void RegisterFileWhitelist( IFileList *pWantCRCList, IFileList *pAllowFromDiskList, IFileList **pFilesToReload ) = 0; + virtual void RegisterFileWhitelist( IPureServerWhitelist *pPureList, IFileList **pFilesToReload ) = 0; // Called when the client logs onto a server. Any files that came off disk should be marked as // unverified because this server may have a different set of files it wants to guarantee. @@ -723,24 +757,16 @@ public: // As the server loads whitelists when it transitions maps, it calls this to calculate CRCs for any files marked // with check_crc. Then it calls CheckCachedFileCRC later when it gets client requests to verify CRCs. virtual void CacheFileCRCs( const char *pPathname, ECacheCRCType eType, IFileList *pFilter ) = 0; - virtual EFileCRCStatus CheckCachedFileCRC( const char *pPathID, const char *pRelativeFilename, CRC32_t *pCRC ) = 0; + virtual EFileCRCStatus CheckCachedFileHash( const char *pPathID, const char *pRelativeFilename, int nFileFraction, FileHash_t *pFileHash ) = 0; - virtual void CacheFileMD5s( const char *pPathname, ECacheCRCType eType, IFileList *pFilter ) = 0; - - // Last param is an MD5Value_t pointer. - virtual EFileCRCStatus CheckCachedFileMD5( const char *pPathID, const char *pRelativeFilename, void *pMD5 ) = 0; - // Fills in the list of files that have been loaded off disk and have not been verified. // Returns the number of files filled in (between 0 and nMaxFiles). // // This also removes any files it's returning from the unverified CRC list, so they won't be // returned from here again. // The client sends batches of these to the server to verify. - virtual int GetUnverifiedCRCFiles( CUnverifiedCRCFile *pFiles, int nMaxFiles ) = 0; + virtual int GetUnverifiedFileHashes( CUnverifiedFileHash *pFiles, int nMaxFiles ) = 0; - // First param is a CUnverifiedMD5File pointer. - virtual int GetUnverifiedMD5Files( void *pFiles, int nMaxFiles ) = 0; - // Control debug message output. // Pass a combination of WHITELIST_SPEW_ flags. virtual int GetWhitelistSpewFlags() = 0; @@ -757,6 +783,14 @@ public: virtual bool IsFileCacheFileLoaded( void *pFileCache, const char *szFile ) = 0; virtual bool IsFileCacheLoaded( void *pFileCache ) = 0; virtual void DestroyFileCache( void *pFileCache ) = 0; + + virtual bool RegisterMemoryFile( void *pFile, void **ppExistingFileWithRef ) = 0; + virtual void UnregisterMemoryFile( void *pFile ) = 0; + + virtual void CacheAllVPKFileHashes( bool bCacheAllVPKHashes, bool bRecalculateAndCheckHashes ) = 0; + virtual bool CheckVPKFileHash( int PackFileID, int nPackFileNumber, int nFileFraction, MD5Value_t &md5Value ) = 0; + + virtual void NotifyFileUnloaded( const char *pFileName, const char *pPathId ) = 0; }; //----------------------------------------------------------------------------- diff --git a/public/filesystem_passthru.h b/public/filesystem_passthru.h index b1b1041e..ba3a75de 100644 --- a/public/filesystem_passthru.h +++ b/public/filesystem_passthru.h @@ -215,24 +215,18 @@ public: virtual DVDMode_t GetDVDMode() { return m_pFileSystemPassThru->GetDVDMode(); } - virtual void EnableWhitelistFileTracking( bool bEnable ) - { m_pFileSystemPassThru->EnableWhitelistFileTracking( bEnable ); } - virtual void RegisterFileWhitelist( IFileList *pForceMatchList, IFileList *pAllowFromDiskList, IFileList **pFilesToReload ) - { m_pFileSystemPassThru->RegisterFileWhitelist( pForceMatchList, pAllowFromDiskList, pFilesToReload ); } + virtual void EnableWhitelistFileTracking( bool bEnable, bool bCacheAllVPKHashes, bool bRecalculateAndCheckHashes ) + { m_pFileSystemPassThru->EnableWhitelistFileTracking( bEnable, bCacheAllVPKHashes, bRecalculateAndCheckHashes ); } + virtual void RegisterFileWhitelist( IPureServerWhitelist *pPureList, IFileList **pFilesToReload ) + { m_pFileSystemPassThru->RegisterFileWhitelist( pPureList, pFilesToReload ); } virtual void MarkAllCRCsUnverified() { m_pFileSystemPassThru->MarkAllCRCsUnverified(); } virtual void CacheFileCRCs( const char *pPathname, ECacheCRCType eType, IFileList *pFilter ) { return m_pFileSystemPassThru->CacheFileCRCs( pPathname, eType, pFilter ); } - virtual void CacheFileMD5s( const char *pPathname, ECacheCRCType eType, IFileList *pFilter ) - { return m_pFileSystemPassThru->CacheFileMD5s( pPathname, eType, pFilter ); } - virtual EFileCRCStatus CheckCachedFileCRC( const char *pPathID, const char *pRelativeFilename, CRC32_t *pCRC ) - { return m_pFileSystemPassThru->CheckCachedFileCRC( pPathID, pRelativeFilename, pCRC ); } - virtual EFileCRCStatus CheckCachedFileMD5( const char *pPathID, const char *pRelativeFilename, void *pMD5 ) - { return m_pFileSystemPassThru->CheckCachedFileMD5( pPathID, pRelativeFilename, pMD5 ); } - virtual int GetUnverifiedCRCFiles( CUnverifiedCRCFile *pFiles, int nMaxFiles ) - { return m_pFileSystemPassThru->GetUnverifiedCRCFiles( pFiles, nMaxFiles ); } - virtual int GetUnverifiedMD5Files( void *pFiles, int nMaxFiles ) - { return m_pFileSystemPassThru->GetUnverifiedMD5Files( pFiles, nMaxFiles ); } + virtual EFileCRCStatus CheckCachedFileHash( const char *pPathID, const char *pRelativeFilename, int nFileFraction, FileHash_t *pFileHash ) + { return m_pFileSystemPassThru->CheckCachedFileHash( pPathID, pRelativeFilename, nFileFraction, pFileHash ); } + virtual int GetUnverifiedFileHashes( CUnverifiedFileHash *pFiles, int nMaxFiles ) + { return m_pFileSystemPassThru->GetUnverifiedFileHashes( pFiles, nMaxFiles ); } virtual int GetWhitelistSpewFlags() { return m_pFileSystemPassThru->GetWhitelistSpewFlags(); } virtual void SetWhitelistSpewFlags( int spewFlags ) @@ -253,6 +247,19 @@ public: virtual void DestroyFileCache( void *pFileCache ) { m_pFileSystemPassThru->DestroyFileCache( pFileCache ); } + virtual bool RegisterMemoryFile( void *pFile, void **ppExistingFileWithRef ) + { return m_pFileSystemPassThru->RegisterMemoryFile( pFile, ppExistingFileWithRef ); } + virtual void UnregisterMemoryFile( void *pFile ) + { m_pFileSystemPassThru->UnregisterMemoryFile( pFile ); } + + virtual void CacheAllVPKFileHashes( bool bCacheAllVPKHashes, bool bRecalculateAndCheckHashes ) + { m_pFileSystemPassThru->CacheAllVPKFileHashes( bCacheAllVPKHashes, bRecalculateAndCheckHashes ); } + virtual bool CheckVPKFileHash( int PackFileID, int nPackFileNumber, int nFileFraction, MD5Value_t &md5Value ) + { return m_pFileSystemPassThru->CheckVPKFileHash( PackFileID, nPackFileNumber, nFileFraction, md5Value ); } + + virtual void NotifyFileUnloaded( const char *pFileName, const char *pPathId ) + { m_pFileSystemPassThru->NotifyFileUnloaded( pFileName, pPathId ); } + protected: IFileSystem *m_pFileSystemPassThru; }; diff --git a/public/iclient.h b/public/iclient.h index e7457d30..412d5e1b 100644 --- a/public/iclient.h +++ b/public/iclient.h @@ -74,7 +74,6 @@ public: virtual bool IsFakeClient( void ) const = 0; // returns true, if client is a HLTV proxy virtual bool IsHLTV( void ) const = 0; - virtual bool IsReplay( void ) const = 0; // returns true, if client hears this player virtual bool IsHearingClient(int index) const = 0; diff --git a/public/inetchannel.h b/public/inetchannel.h index 2ac5e872..eb37a8ad 100644 --- a/public/inetchannel.h +++ b/public/inetchannel.h @@ -72,8 +72,6 @@ public: virtual void SetCompressionMode( bool bUseCompression ) = 0; virtual unsigned int RequestFile(const char *filename) = 0; - virtual float GetTimeSinceLastReceived( void ) const = 0; - virtual void SetMaxBufferSize(bool bReliable, int nBytes, bool bVoice = false ) = 0; virtual bool IsNull() const = 0; diff --git a/public/mathlib/amd3dx.h b/public/mathlib/amd3dx.h deleted file mode 100644 index 1cff7e8e..00000000 --- a/public/mathlib/amd3dx.h +++ /dev/null @@ -1,1187 +0,0 @@ -/****************************************************************************** - - Copyright (c) 1999 Advanced Micro Devices, Inc. - - LIMITATION OF LIABILITY: THE MATERIALS ARE PROVIDED *AS IS* WITHOUT ANY - EXPRESS OR IMPLIED WARRANTY OF ANY KIND INCLUDING WARRANTIES OF MERCHANTABILITY, - NONINFRINGEMENT OF THIRD-PARTY INTELLECTUAL PROPERTY, OR FITNESS FOR ANY - PARTICULAR PURPOSE. IN NO EVENT SHALL AMD OR ITS SUPPLIERS BE LIABLE FOR ANY - DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF PROFITS, - BUSINESS INTERRUPTION, LOSS OF INFORMATION) ARISING OUT OF THE USE OF OR - INABILITY TO USE THE MATERIALS, EVEN IF AMD HAS BEEN ADVISED OF THE POSSIBILITY - OF SUCH DAMAGES. BECAUSE SOME JURISDICTIONS PROHIBIT THE EXCLUSION OR LIMITATION - OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES, THE ABOVE LIMITATION MAY - NOT APPLY TO YOU. - - AMD does not assume any responsibility for any errors which may appear in the - Materials nor any responsibility to support or update the Materials. AMD retains - the right to make changes to its test specifications at any time, without notice. - - NO SUPPORT OBLIGATION: AMD is not obligated to furnish, support, or make any - further information, software, technical information, know-how, or show-how - available to you. - - So that all may benefit from your experience, please report any problems - or suggestions about this software to 3dsdk.support@amd.com - - AMD Developer Technologies, M/S 585 - Advanced Micro Devices, Inc. - 5900 E. Ben White Blvd. - Austin, TX 78741 - 3dsdk.support@amd.com - -******************************************************************************* - - AMD3DX.H - - MACRO FORMAT - ============ - This file contains inline assembly macros that - generate AMD-3D instructions in binary format. - Therefore, C or C++ programmer can use AMD-3D instructions - without any penalty in their C or C++ source code. - - The macro's name and format conventions are as follow: - - - 1. First argument of macro is a destination and - second argument is a source operand. - ex) _asm PFCMPEQ (mm3, mm4) - | | - dst src - - 2. The destination operand can be m0 to m7 only. - The source operand can be any one of the register - m0 to m7 or _eax, _ecx, _edx, _ebx, _esi, or _edi - that contains effective address. - ex) _asm PFRCP (MM7, MM6) - ex) _asm PFRCPIT2 (mm0, mm4) - ex) _asm PFMUL (mm3, _edi) - - 3. The prefetch(w) takes one src operand _eax, ecx, _edx, - _ebx, _esi, or _edi that contains effective address. - ex) _asm PREFETCH (_edi) - - For WATCOM C/C++ users, when using #pragma aux instead if - _asm, all macro names should be prefixed by a p_ or P_. - Macros should not be enclosed in quotes. - ex) p_pfrcp (MM7,MM6) - - NOTE: Not all instruction macros, nor all possible - combinations of operands have been explicitely - tested. If any errors are found, please report - them. - - EXAMPLE - ======= - Following program doesn't do anything but it shows you - how to use inline assembly AMD-3D instructions in C. - Note that this will only work in flat memory model which - segment registers cs, ds, ss and es point to the same - linear address space total less than 4GB. - - Used Microsoft VC++ 5.0 - - #include - #include "amd3d.h" - - void main () - { - float x = (float)1.25; - float y = (float)1.25; - float z, zz; - - _asm { - movd mm1, x - movd mm2, y - pfmul (mm1, mm2) - movd z, mm1 - femms - } - - printf ("value of z = %f\n", z); - - // - // Demonstration of using the memory instead of - // multimedia register - // - _asm { - movd mm3, x - lea esi, y // load effective address of y - pfmul (mm3, _esi) - movd zz, mm3 - femms - } - - printf ("value of zz = %f\n", zz); - } - - #pragma aux EXAMPLE with WATCOM C/C++ v11.x - =========================================== - - extern void Add(float *__Dest, float *__A, float *__B); - #pragma aux Add = \ - p_femms \ - "movd mm6,[esi]" \ - p_pfadd(mm6,_edi) \ - "movd [ebx],mm6" \ - p_femms \ - parm [ebx] [esi] [edi]; - -*******************************************************************************/ - -#ifndef _K3DMACROSINCLUDED_ -#define _K3DMACROSINCLUDED_ - -#if defined (__WATCOMC__) - -// The WATCOM C/C++ version of the 3DNow! macros. -// -// The older, compbined register style for WATCOM C/C++ macros is not -// supported. - -/* Operand defines for instructions two operands */ -#define _k3d_mm0_mm0 0xc0 -#define _k3d_mm0_mm1 0xc1 -#define _k3d_mm0_mm2 0xc2 -#define _k3d_mm0_mm3 0xc3 -#define _k3d_mm0_mm4 0xc4 -#define _k3d_mm0_mm5 0xc5 -#define _k3d_mm0_mm6 0xc6 -#define _k3d_mm0_mm7 0xc7 -#define _k3d_mm0_eax 0x00 -#define _k3d_mm0_ecx 0x01 -#define _k3d_mm0_edx 0x02 -#define _k3d_mm0_ebx 0x03 -#define _k3d_mm0_esi 0x06 -#define _k3d_mm0_edi 0x07 -#define _k3d_mm1_mm0 0xc8 -#define _k3d_mm1_mm1 0xc9 -#define _k3d_mm1_mm2 0xca -#define _k3d_mm1_mm3 0xcb -#define _k3d_mm1_mm4 0xcc -#define _k3d_mm1_mm5 0xcd -#define _k3d_mm1_mm6 0xce -#define _k3d_mm1_mm7 0xcf -#define _k3d_mm1_eax 0x08 -#define _k3d_mm1_ecx 0x09 -#define _k3d_mm1_edx 0x0a -#define _k3d_mm1_ebx 0x0b -#define _k3d_mm1_esi 0x0e -#define _k3d_mm1_edi 0x0f -#define _k3d_mm2_mm0 0xd0 -#define _k3d_mm2_mm1 0xd1 -#define _k3d_mm2_mm2 0xd2 -#define _k3d_mm2_mm3 0xd3 -#define _k3d_mm2_mm4 0xd4 -#define _k3d_mm2_mm5 0xd5 -#define _k3d_mm2_mm6 0xd6 -#define _k3d_mm2_mm7 0xd7 -#define _k3d_mm2_eax 0x10 -#define _k3d_mm2_ecx 0x11 -#define _k3d_mm2_edx 0x12 -#define _k3d_mm2_ebx 0x13 -#define _k3d_mm2_esi 0x16 -#define _k3d_mm2_edi 0x17 -#define _k3d_mm3_mm0 0xd8 -#define _k3d_mm3_mm1 0xd9 -#define _k3d_mm3_mm2 0xda -#define _k3d_mm3_mm3 0xdb -#define _k3d_mm3_mm4 0xdc -#define _k3d_mm3_mm5 0xdd -#define _k3d_mm3_mm6 0xde -#define _k3d_mm3_mm7 0xdf -#define _k3d_mm3_eax 0x18 -#define _k3d_mm3_ecx 0x19 -#define _k3d_mm3_edx 0x1a -#define _k3d_mm3_ebx 0x1b -#define _k3d_mm3_esi 0x1e -#define _k3d_mm3_edi 0x1f -#define _k3d_mm4_mm0 0xe0 -#define _k3d_mm4_mm1 0xe1 -#define _k3d_mm4_mm2 0xe2 -#define _k3d_mm4_mm3 0xe3 -#define _k3d_mm4_mm4 0xe4 -#define _k3d_mm4_mm5 0xe5 -#define _k3d_mm4_mm6 0xe6 -#define _k3d_mm4_mm7 0xe7 -#define _k3d_mm4_eax 0x20 -#define _k3d_mm4_ecx 0x21 -#define _k3d_mm4_edx 0x22 -#define _k3d_mm4_ebx 0x23 -#define _k3d_mm4_esi 0x26 -#define _k3d_mm4_edi 0x27 -#define _k3d_mm5_mm0 0xe8 -#define _k3d_mm5_mm1 0xe9 -#define _k3d_mm5_mm2 0xea -#define _k3d_mm5_mm3 0xeb -#define _k3d_mm5_mm4 0xec -#define _k3d_mm5_mm5 0xed -#define _k3d_mm5_mm6 0xee -#define _k3d_mm5_mm7 0xef -#define _k3d_mm5_eax 0x28 -#define _k3d_mm5_ecx 0x29 -#define _k3d_mm5_edx 0x2a -#define _k3d_mm5_ebx 0x2b -#define _k3d_mm5_esi 0x2e -#define _k3d_mm5_edi 0x2f -#define _k3d_mm6_mm0 0xf0 -#define _k3d_mm6_mm1 0xf1 -#define _k3d_mm6_mm2 0xf2 -#define _k3d_mm6_mm3 0xf3 -#define _k3d_mm6_mm4 0xf4 -#define _k3d_mm6_mm5 0xf5 -#define _k3d_mm6_mm6 0xf6 -#define _k3d_mm6_mm7 0xf7 -#define _k3d_mm6_eax 0x30 -#define _k3d_mm6_ecx 0x31 -#define _k3d_mm6_edx 0x32 -#define _k3d_mm6_ebx 0x33 -#define _k3d_mm6_esi 0x36 -#define _k3d_mm6_edi 0x37 -#define _k3d_mm7_mm0 0xf8 -#define _k3d_mm7_mm1 0xf9 -#define _k3d_mm7_mm2 0xfa -#define _k3d_mm7_mm3 0xfb -#define _k3d_mm7_mm4 0xfc -#define _k3d_mm7_mm5 0xfd -#define _k3d_mm7_mm6 0xfe -#define _k3d_mm7_mm7 0xff -#define _k3d_mm7_eax 0x38 -#define _k3d_mm7_ecx 0x39 -#define _k3d_mm7_edx 0x3a -#define _k3d_mm7_ebx 0x3b -#define _k3d_mm7_esi 0x3e -#define _k3d_mm7_edi 0x3f - -#define _k3d_name_xlat_m0 _mm0 -#define _k3d_name_xlat_m1 _mm1 -#define _k3d_name_xlat_m2 _mm2 -#define _k3d_name_xlat_m3 _mm3 -#define _k3d_name_xlat_m4 _mm4 -#define _k3d_name_xlat_m5 _mm5 -#define _k3d_name_xlat_m6 _mm6 -#define _k3d_name_xlat_m7 _mm7 -#define _k3d_name_xlat_M0 _mm0 -#define _k3d_name_xlat_M1 _mm1 -#define _k3d_name_xlat_M2 _mm2 -#define _k3d_name_xlat_M3 _mm3 -#define _k3d_name_xlat_M4 _mm4 -#define _k3d_name_xlat_M5 _mm5 -#define _k3d_name_xlat_M6 _mm6 -#define _k3d_name_xlat_M7 _mm7 -#define _k3d_name_xlat_mm0 _mm0 -#define _k3d_name_xlat_mm1 _mm1 -#define _k3d_name_xlat_mm2 _mm2 -#define _k3d_name_xlat_mm3 _mm3 -#define _k3d_name_xlat_mm4 _mm4 -#define _k3d_name_xlat_mm5 _mm5 -#define _k3d_name_xlat_mm6 _mm6 -#define _k3d_name_xlat_mm7 _mm7 -#define _k3d_name_xlat_MM0 _mm0 -#define _k3d_name_xlat_MM1 _mm1 -#define _k3d_name_xlat_MM2 _mm2 -#define _k3d_name_xlat_MM3 _mm3 -#define _k3d_name_xlat_MM4 _mm4 -#define _k3d_name_xlat_MM5 _mm5 -#define _k3d_name_xlat_MM6 _mm6 -#define _k3d_name_xlat_MM7 _mm7 -#define _k3d_name_xlat_eax _eax -#define _k3d_name_xlat_ebx _ebx -#define _k3d_name_xlat_ecx _ecx -#define _k3d_name_xlat_edx _edx -#define _k3d_name_xlat_esi _esi -#define _k3d_name_xlat_edi _edi -#define _k3d_name_xlat_ebp _ebp -#define _k3d_name_xlat_EAX _eax -#define _k3d_name_xlat_EBX _ebx -#define _k3d_name_xlat_ECX _ecx -#define _k3d_name_xlat_EDX _edx -#define _k3d_name_xlat_ESI _esi -#define _k3d_name_xlat_EDI _edi -#define _k3d_name_xlat_EBP _ebp -#define _k3d_name_xlat__eax _eax -#define _k3d_name_xlat__ebx _ebx -#define _k3d_name_xlat__ecx _ecx -#define _k3d_name_xlat__edx _edx -#define _k3d_name_xlat__esi _esi -#define _k3d_name_xlat__edi _edi -#define _k3d_name_xlat__ebp _ebp -#define _k3d_name_xlat__EAX _eax -#define _k3d_name_xlat__EBX _ebx -#define _k3d_name_xlat__ECX _ecx -#define _k3d_name_xlat__EDX _edx -#define _k3d_name_xlat__ESI _esi -#define _k3d_name_xlat__EDI _edi -#define _k3d_name_xlat__EBP _ebp - -#define _k3d_xglue3(a,b,c) a##b##c -#define _k3d_glue3(a,b,c) _k3d_xglue3(a,b,c) -#define _k3d_MODRM(dst, src) _k3d_glue3(_k3d,_k3d_name_xlat_##dst,_k3d_name_xlat_##src) - -/* Operand defines for prefetch and prefetchw */ - -#define _k3d_pref_eax 0x00 -#define _k3d_pref_ecx 0x01 -#define _k3d_pref_edx 0x02 -#define _k3d_pref_ebx 0x03 -#define _k3d_pref_esi 0x06 -#define _k3d_pref_edi 0x07 -#define _k3d_pref_EAX 0x00 -#define _k3d_pref_ECX 0x01 -#define _k3d_pref_EDX 0x02 -#define _k3d_pref_EBX 0x03 -#define _k3d_pref_ESI 0x06 -#define _k3d_pref_EDI 0x07 -#define _k3d_prefw_eax 0x08 -#define _k3d_prefw_ecx 0x09 -#define _k3d_prefw_edx 0x0A -#define _k3d_prefw_ebx 0x0B -#define _k3d_prefw_esi 0x0E -#define _k3d_prefw_edi 0x0F -#define _k3d_prefw_EAX 0x08 -#define _k3d_prefw_ECX 0x09 -#define _k3d_prefw_EDX 0x0A -#define _k3d_prefw_EBX 0x0B -#define _k3d_prefw_ESI 0x0E -#define _k3d_prefw_EDI 0x0F - -/* Defines for 3DNow! instructions */ -#define PF2ID(dst, src) db 0x0f, 0x0f, _k3d_MODRM(dst, src), 0x1d -#define PFACC(dst, src) db 0x0f, 0x0f, _k3d_MODRM(dst, src), 0xae -#define PFADD(dst, src) db 0x0f, 0x0f, _k3d_MODRM(dst, src), 0x9e -#define PFCMPEQ(dst, src) db 0x0f, 0x0f, _k3d_MODRM(dst, src), 0xb0 -#define PFCMPGE(dst, src) db 0x0f, 0x0f, _k3d_MODRM(dst, src), 0x90 -#define PFCMPGT(dst, src) db 0x0f, 0x0f, _k3d_MODRM(dst, src), 0xa0 -#define PFMAX(dst, src) db 0x0f, 0x0f, _k3d_MODRM(dst, src), 0xa4 -#define PFMIN(dst, src) db 0x0f, 0x0f, _k3d_MODRM(dst, src), 0x94 -#define PFMUL(dst, src) db 0x0f, 0x0f, _k3d_MODRM(dst, src), 0xb4 -#define PFRCP(dst, src) db 0x0f, 0x0f, _k3d_MODRM(dst, src), 0x96 -#define PFRCPIT1(dst, src) db 0x0f, 0x0f, _k3d_MODRM(dst, src), 0xa6 -#define PFRCPIT2(dst, src) db 0x0f, 0x0f, _k3d_MODRM(dst, src), 0xb6 -#define PFRSQRT(dst, src) db 0x0f, 0x0f, _k3d_MODRM(dst, src), 0x97 -#define PFRSQIT1(dst, src) db 0x0f, 0x0f, _k3d_MODRM(dst, src), 0xa7 -#define PFSUB(dst, src) db 0x0f, 0x0f, _k3d_MODRM(dst, src), 0x9a -#define PFSUBR(dst, src) db 0x0f, 0x0f, _k3d_MODRM(dst, src), 0xaa -#define PI2FD(dst, src) db 0x0f, 0x0f, _k3d_MODRM(dst, src), 0x0d -#define FEMMS db 0x0f, 0x0e -#define PAVGUSB(dst, src) db 0x0f, 0x0f, _k3d_MODRM(dst, src), 0xbf -#define PMULHRW(dst, src) db 0x0f, 0x0f, _k3d_MODRM(dst, src), 0xb7 -#define PREFETCH(src) db 0x0f, 0x0d, _k3d_pref_##src -#define PREFETCHW(src) db 0x0f, 0x0d, _k3d_prefw_##src -#define CPUID db 0x0f, 0xa2 - -/* Defines for new, K7 opcodes */ -#define PFNACC(dst,src) db 0x0f, 0x0f, _k3d_MODRM(dst,src), 0x8a -#define FPPNACC(dst,src) db 0x0f, 0x0f, _k3d_MODRM(dst,src), 0x8e -#define PSWAPD(dst,src) db 0x0f, 0x0f, _k3d_MODRM(dst,src), 0xbb -#define PMINUB(dst,src) db 0x0f, 0xda, _k3d_MODRM(dst,src) -#define PMAXUB(dst,src) db 0x0f, 0xde, _k3d_MODRM(dst,src) -#define PMINSW(dst,src) db 0x0f, 0xea, _k3d_MODRM(dst,src) -#define PMAXSW(dst,src) db 0x0f, 0xee, _k3d_MODRM(dst,src) -#define PMULHUW(dst,src) db 0x0f, 0xe4, _k3d_MODRM(dst,src) -#define PAVGB(dst,src) db 0x0f, 0xe0, _k3d_MODRM(dst,src) -#define PAVGW(dst,src) db 0x0f, 0xe3, _k3d_MODRM(dst,src) -#define PSADBW(dst,src) db 0x0f, 0xf6, _k3d_MODRM(dst,src) -#define PMOVMSKB(dst,src) db 0x0f, 0xd7, _k3d_MODRM(dst,src) -#define PMASKMOVQ(dst,src) db 0x0f, 0xf7, _k3d_MODRM(dst,src) -#define PINSRW(dst,src,msk) db 0x0f, 0xc4, _k3d_MODRM(dst,src), msk -#define PEXTRW(dst,src,msk) db 0x0f, 0xc5, _k3d_MODRM(dst,src), msk -#define PSHUFW(dst,src,msk) db 0x0f, 0x70, _k3d_MODRM(dst,src), msk -#define MOVNTQ(dst,src) db 0x0f, 0xe7, _k3d_MODRM(src,dst) -#define SFENCE db 0x0f, 0xae, 0xf8 - -/* Memory/offset versions of the opcodes */ -#define PF2IDM(dst,src,off) db 0x0f, 0x0f, _k3d_MODRM(dst,src) | 0x40, off, 0x1d -#define PFACCM(dst,src,off) db 0x0f, 0x0f, _k3d_MODRM(dst,src) | 0x40, off, 0xae -#define PFADDM(dst,src,off) db 0x0f, 0x0f, _k3d_MODRM(dst,src) | 0x40, off, 0x9e -#define PFCMPEQM(dst,src,off) db 0x0f, 0x0f, _k3d_MODRM(dst,src) | 0x40, off, 0xb0 -#define PFCMPGEM(dst,src,off) db 0x0f, 0x0f, _k3d_MODRM(dst,src) | 0x40, off, 0x90 -#define PFCMPGTM(dst,src,off) db 0x0f, 0x0f, _k3d_MODRM(dst,src) | 0x40, off, 0xa0 -#define PFMAXM(dst,src,off) db 0x0f, 0x0f, _k3d_MODRM(dst,src) | 0x40, off, 0xa4 -#define PFMINM(dst,src,off) db 0x0f, 0x0f, _k3d_MODRM(dst,src) | 0x40, off, 0x94 -#define PFMULM(dst,src,off) db 0x0f, 0x0f, _k3d_MODRM(dst,src) | 0x40, off, 0xb4 -#define PFRCPM(dst,src,off) db 0x0f, 0x0f, _k3d_MODRM(dst,src) | 0x40, off, 0x96 -#define PFRCPIT1M(dst,src,off) db 0x0f, 0x0f, _k3d_MODRM(dst,src) | 0x40, off, 0xa6 -#define PFRCPIT2M(dst,src,off) db 0x0f, 0x0f, _k3d_MODRM(dst,src) | 0x40, off, 0xb6 -#define PFRSQRTM(dst,src,off) db 0x0f, 0x0f, _k3d_MODRM(dst,src) | 0x40, off, 0x97 -#define PFRSQIT1M(dst,src,off) db 0x0f, 0x0f, _k3d_MODRM(dst,src) | 0x40, off, 0xa7 -#define PFSUBM(dst,src,off) db 0x0f, 0x0f, _k3d_MODRM(dst,src) | 0x40, off, 0x9a -#define PFSUBRM(dst,src,off) db 0x0f, 0x0f, _k3d_MODRM(dst,src) | 0x40, off, 0xaa -#define PI2FDM(dst,src,off) db 0x0f, 0x0f, _k3d_MODRM(dst,src) | 0x40, off, 0x0d -#define PAVGUSBM(dst,src,off) db 0x0f, 0x0f, _k3d_MODRM(dst,src) | 0x40, off, 0xbf -#define PMULHRWM(dst,src,off) db 0x0f, 0x0f, _k3d_MODRM(dst,src) | 0x40, off, 0xb7 - - -/* Memory/offset versions of the new, K7 opcodes */ -#define PFNACCM(dst,src,off) db 0x0f, 0x0f, _k3d_MODRM(dst,src) | 0x40, off, 0x8a -#define FPPNACCM(dst,src,off) db 0x0f, 0x0f, _k3d_MODRM(dst,src) | 0x40, off, 0x8e -#define PSWAPDM(dst,src,off) db 0x0f, 0x0f, _k3d_MODRM(dst,src) | 0x40, off, 0xbb -#define PMINUBM(dst,src,off) db 0x0f, 0xda, _k3d_MODRM(dst,src) | 0x40, off -#define PMAXUBM(dst,src,off) db 0x0f, 0xde, _k3d_MODRM(dst,src) | 0x40, off -#define PMINSWM(dst,src,off) db 0x0f, 0xea, _k3d_MODRM(dst,src) | 0x40, off -#define PMAXSWM(dst,src,off) db 0x0f, 0xee, _k3d_MODRM(dst,src) | 0x40, off -#define PMULHUWM(dst,src,off) db 0x0f, 0xe4, _k3d_MODRM(dst,src) | 0x40, off -#define PAVGBM(dst,src,off) db 0x0f, 0xe0, _k3d_MODRM(dst,src) | 0x40, off -#define PAVGWM(dst,src,off) db 0x0f, 0xe3, _k3d_MODRM(dst,src) | 0x40, off -#define PSADBWM(dst,src,off) db 0x0f, 0xf6, _k3d_MODRM(dst,src) | 0x40, off -#define PMOVMSKBM(dst,src,off) db 0x0f, 0xd7, _k3d_MODRM(dst,src) | 0x40, off -#define PMASKMOVQM(dst,src,off) db 0x0f, 0xf7, _k3d_MODRM(dst,src) | 0x40, off -#define MOVNTQM(dst,src,off) db 0x0f, 0xe7, _k3d_MODRM(src,dst) | 0x40, off -#define PINSRWM(dst,src,off,msk) db 0x0f, 0xc4, _k3d_MODRM(dst,src) | 0x40, off, msk -#define PSHUFWM(dst,src,off,msk) db 0x0f, 0x70, _k3d_MODRM(dst,src) | 0x40, off, msk - - -/* Defines for 3DNow! instructions for use in pragmas */ -#define p_pf2id(dst,src) 0x0f 0x0f _k3d_MODRM(dst,src) 0x1d -#define p_pfacc(dst,src) 0x0f 0x0f _k3d_MODRM(dst,src) 0xae -#define p_pfadd(dst,src) 0x0f 0x0f _k3d_MODRM(dst,src) 0x9e -#define p_pfcmpeq(dst,src) 0x0f 0x0f _k3d_MODRM(dst,src) 0xb0 -#define p_pfcmpge(dst,src) 0x0f 0x0f _k3d_MODRM(dst,src) 0x90 -#define p_pfcmpgt(dst,src) 0x0f 0x0f _k3d_MODRM(dst,src) 0xa0 -#define p_pfmax(dst,src) 0x0f 0x0f _k3d_MODRM(dst,src) 0xa4 -#define p_pfmin(dst,src) 0x0f 0x0f _k3d_MODRM(dst,src) 0x94 -#define p_pfmul(dst,src) 0x0f 0x0f _k3d_MODRM(dst,src) 0xb4 -#define p_pfrcp(dst,src) 0x0f 0x0f _k3d_MODRM(dst,src) 0x96 -#define p_pfrcpit1(dst,src) 0x0f 0x0f _k3d_MODRM(dst,src) 0xa6 -#define p_pfrcpit2(dst,src) 0x0f 0x0f _k3d_MODRM(dst,src) 0xb6 -#define p_pfrsqrt(dst,src) 0x0f 0x0f _k3d_MODRM(dst,src) 0x97 -#define p_pfrsqit1(dst,src) 0x0f 0x0f _k3d_MODRM(dst,src) 0xa7 -#define p_pfsub(dst,src) 0x0f 0x0f _k3d_MODRM(dst,src) 0x9a -#define p_pfsubr(dst,src) 0x0f 0x0f _k3d_MODRM(dst,src) 0xaa -#define p_pi2fd(dst,src) 0x0f 0x0f _k3d_MODRM(dst,src) 0x0d -#define p_femms 0x0f 0x0e -#define p_pavgusb(dst,src) 0x0f 0x0f _k3d_MODRM(dst,src) 0xbf -#define p_pmulhrw(dst,src) 0x0f 0x0f _k3d_MODRM(dst,src) 0xb7 -#define p_prefetch(src) 0x0f 0x0d _k3d_pref_##src -#define p_prefetchw(src) 0x0f 0x0d _k3d_prefw_##src -#define P_PFNACC(dst,src) 0x0f 0x0f (_k3d_MODRM(dst,src) | 0x40) off 0x8a -#define P_FPPNACC(dst,src) 0x0f 0x0f (_k3d_MODRM(dst,src) | 0x40) off 0x8e -#define P_PSWAPD(dst,src) 0x0f 0x0f (_k3d_MODRM(dst,src) | 0x40) off 0xbb -#define P_PMINUB(dst,src) 0x0f 0xda (_k3d_MODRM(dst,src) | 0x40) off -#define P_PMAXUB(dst,src) 0x0f 0xde (_k3d_MODRM(dst,src) | 0x40) off -#define P_PMINSW(dst,src) 0x0f 0xea (_k3d_MODRM(dst,src) | 0x40) off -#define P_PMAXSW(dst,src) 0x0f 0xee (_k3d_MODRM(dst,src) | 0x40) off -#define P_PMULHUW(dst,src) 0x0f 0xe4 (_k3d_MODRM(dst,src) | 0x40) off -#define P_PAVGB(dst,src) 0x0f 0xe0 (_k3d_MODRM(dst,src) | 0x40) off -#define P_PAVGW(dst,src) 0x0f 0xe3 (_k3d_MODRM(dst,src) | 0x40) off -#define P_PSADBW(dst,src) 0x0f 0xf6 (_k3d_MODRM(dst,src) | 0x40) off -#define P_PMOVMSKB(dst,src) 0x0f 0xd7 (_k3d_MODRM(dst,src) | 0x40) off -#define P_PMASKMOVQ(dst,src) 0x0f 0xf7 (_k3d_MODRM(dst,src) | 0x40) off -#define P_PINSRW(dst,src,msk) 0x0f 0xc4 (_k3d_MODRM(dst,src) | 0x40) off msk -#define P_PEXTRW(dst,src,msk) 0x0f 0xc5 (_k3d_MODRM(dst,src) | 0x40) off msk -#define P_PSHUFW(dst,src,msk) 0x0f 0x70 (_k3d_MODRM(dst,src) | 0x40) off msk -#define P_MOVNTQ(dst,src) 0x0f 0xe7 (_k3d_MODRM(src,dst) | 0x40) off - -#define P_PF2IDM(dst,src,off) 0x0f 0x0f (_k3d_MODRM(dst,src) | 0x40) off 0x1d -#define P_PFACCM(dst,src,off) 0x0f 0x0f (_k3d_MODRM(dst,src) | 0x40) off 0xae -#define P_PFADDM(dst,src,off) 0x0f 0x0f (_k3d_MODRM(dst,src) | 0x40) off 0x9e -#define P_PFCMPEQM(dst,src,off) 0x0f 0x0f (_k3d_MODRM(dst,src) | 0x40) off 0xb0 -#define P_PFCMPGEM(dst,src,off) 0x0f 0x0f (_k3d_MODRM(dst,src) | 0x40) off 0x90 -#define P_PFCMPGTM(dst,src,off) 0x0f 0x0f (_k3d_MODRM(dst,src) | 0x40) off 0xa0 -#define P_PFMAXM(dst,src,off) 0x0f 0x0f (_k3d_MODRM(dst,src) | 0x40) off 0xa4 -#define P_PFMINM(dst,src,off) 0x0f 0x0f (_k3d_MODRM(dst,src) | 0x40) off 0x94 -#define P_PFMULM(dst,src,off) 0x0f 0x0f (_k3d_MODRM(dst,src) | 0x40) off 0xb4 -#define P_PFRCPM(dst,src,off) 0x0f 0x0f (_k3d_MODRM(dst,src) | 0x40) off 0x96 -#define P_PFRCPIT1M(dst,src,off) 0x0f 0x0f (_k3d_MODRM(dst,src) | 0x40) off 0xa6 -#define P_PFRCPIT2M(dst,src,off) 0x0f 0x0f (_k3d_MODRM(dst,src) | 0x40) off 0xb6 -#define P_PFRSQRTM(dst,src,off) 0x0f 0x0f (_k3d_MODRM(dst,src) | 0x40) off 0x97 -#define P_PFRSQIT1M(dst,src,off) 0x0f 0x0f (_k3d_MODRM(dst,src) | 0x40) off 0xa7 -#define P_PFSUBM(dst,src,off) 0x0f 0x0f (_k3d_MODRM(dst,src) | 0x40) off 0x9a -#define P_PFSUBRM(dst,src,off) 0x0f 0x0f (_k3d_MODRM(dst,src) | 0x40) off 0xaa -#define P_PI2FDM(dst,src,off) 0x0f 0x0f (_k3d_MODRM(dst,src) | 0x40) off 0x0d -#define P_PAVGUSBM(dst,src,off) 0x0f 0x0f (_k3d_MODRM(dst,src) | 0x40) off 0xbf -#define P_PMULHRWM(dst,src,off) 0x0f 0x0f (_k3d_MODRM(dst,src) | 0x40) off 0xb7 -#define P_PFNACCM(dst,src,off) 0x0f 0x0f (_k3d_MODRM(dst,src) | 0x40) off 0x8a -#define P_FPPNACCM(dst,src,off) 0x0f 0x0f (_k3d_MODRM(dst,src) | 0x40) off 0x8e -#define P_PSWAPDM(dst,src,off) 0x0f 0x0f (_k3d_MODRM(dst,src) | 0x40) off 0xbb -#define P_PMINUBM(dst,src,off) 0x0f 0xda (_k3d_MODRM(dst,src) | 0x40) off -#define P_PMAXUBM(dst,src,off) 0x0f 0xde (_k3d_MODRM(dst,src) | 0x40) off -#define P_PMINSWM(dst,src,off) 0x0f 0xea (_k3d_MODRM(dst,src) | 0x40) off -#define P_PMAXSWM(dst,src,off) 0x0f 0xee (_k3d_MODRM(dst,src) | 0x40) off -#define P_PMULHUWM(dst,src,off) 0x0f 0xe4 (_k3d_MODRM(dst,src) | 0x40) off -#define P_PAVGBM(dst,src,off) 0x0f 0xe0 (_k3d_MODRM(dst,src) | 0x40) off -#define P_PAVGWM(dst,src,off) 0x0f 0xe3 (_k3d_MODRM(dst,src) | 0x40) off -#define P_PSADBWM(dst,src,off) 0x0f 0xf6 (_k3d_MODRM(dst,src) | 0x40) off -#define P_PMOVMSKBM(dst,src,off) 0x0f 0xd7 (_k3d_MODRM(dst,src) | 0x40) off -#define P_MOVNTQM(dst,src,off) 0x0f 0xe7 (_k3d_MODRM(src,dst) | 0x40) off -#define P_PMASKMOVQM(dst,src,off) 0x0f 0xf7 (_k3d_MODRM(dst,src) | 0x40) off -#define P_PINSRWM(dst,src,off,msk) 0x0f 0xc4 (_k3d_MODRM(dst,src) | 0x40) off msk -#define P_PSHUFWM(dst,src,off,msk) 0x0f 0x70 (_k3d_MODRM(dst,src) | 0x40) off msk - - -#define P_PF2ID(dst,src) p_pf2id(dst,src) -#define P_PFACC(dst,src) p_pfacc(dst,src) -#define P_PFADD(dst,src) p_pfadd(dst,src) -#define P_PFCMPEQ(dst,src) p_pfcmpeq(dst,src) -#define P_PFCMPGE(dst,src) p_pfcmpge(dst,src) -#define P_PFCMPGT(dst,src) p_pfcmpgt(dst,src) -#define P_PFMAX(dst,src) p_pfmax(dst,src) -#define P_PFMIN(dst,src) p_pfmin(dst,src) -#define P_PFMUL(dst,src) p_pfmul(dst,src) -#define P_PFRCP(dst,src) p_pfrcp(dst,src) -#define P_PFRCPIT1(dst,src) p_pfrcpit1(dst,src) -#define P_PFRCPIT2(dst,src) p_pfrcpit2(dst,src) -#define P_PFRSQRT(dst,src) p_pfrsqrt(dst,src) -#define P_PFRSQIT1(dst,src) p_pfrsqit1(dst,src) -#define P_PFSUB(dst,src) p_pfsub(dst,src) -#define P_PFSUBR(dst,src) p_pfsubr(dst,src) -#define P_PI2FD(dst,src) p_pi2fd(dst,src) -#define P_FEMMS p_femms -#define P_PAVGUSB(dst,src) p_pavgusb(dst,src) -#define P_PMULHRW(dst,src) p_pmulhrw(dst,src) -#define P_PREFETCH(src) p_prefetch(src) -#define P_PREFETCHW(src) p_prefetchw(src) -#define p_CPUID 0x0f 0xa2 -#define p_pf2idm(dst,src,off) P_PF2IDM(dst,src,off) -#define p_pfaccm(dst,src,off) P_PFACCM(dst,src,off) -#define p_pfaddm(dst,src,off) P_PFADDM(dst,src,off) -#define p_pfcmpeqm(dst,src,off) P_PFCMPEQM(dst,src,off) -#define p_pfcmpgem(dst,src,off) P_PFCMPGEM(dst,src,off) -#define p_pfcmpgtm(dst,src,off) P_PFCMPGTM(dst,src,off) -#define p_pfmaxm(dst,src,off) P_PFMAXM(dst,src,off) -#define p_pfminm(dst,src,off) P_PFMINM(dst,src,off) -#define p_pfmulm(dst,src,off) P_PFMULM(dst,src,off) -#define p_pfrcpm(dst,src,off) P_PFRCPM(dst,src,off) -#define p_pfrcpit1m(dst,src,off) P_PFRCPIT1M(dst,src,off) -#define p_pfrcpit2m(dst,src,off) P_PFRCPIT2M(dst,src,off) -#define p_pfrsqrtm(dst,src,off) P_PFRSQRTM(dst,src,off) -#define p_pfrsqit1m(dst,src,off) P_PFRSQIT1M(dst,src,off) -#define p_pfsubm(dst,src,off) P_PFSUBM(dst,src,off) -#define p_pfsubrm(dst,src,off) P_PFSUBRM(dst,src,off) -#define p_pi2fdm(dst,src,off) P_PI2FDM(dst,src,off) -#define p_pavgusbm(dst,src,off) P_PAVGUSBM(dst,src,off) -#define p_pmulhrwm(dst,src,off) P_PMULHRWM(dst,src,off) - -#define P_PFNACC(dst,src) p_pfnacc(dst,src) -#define P_FPPNACC(dst,src) p_pfpnacc(dst,src) -#define P_PSWAPD(dst,src) p_pswapd(dst,src) -#define P_PMINUB(dst,src) p_pminub(dst,src) -#define P_PMAXUB(dst,src) p_pmaxub(dst,src) -#define P_PMINSW(dst,src) p_pminsw(dst,src) -#define P_PMAXSW(dst,src) p_pmaxsw(dst,src) -#define P_PMULHUW(dst,src) p_pmulhuw(dst,src) -#define P_PAVGB(dst,src) p_pavgb(dst,src) -#define P_PAVGW(dst,src) p_avgw(dst,src) -#define P_PSADBW(dst,src) p_psadbw(dst,src) -#define P_PMOVMSKB(dst,src) p_pmovmskb(dst,src) -#define P_PMASKMOVQ(dst,src) p_pmaskmovq(dst,src) -#define P_PINSRW(dst,src,msk) p_pinsrw(dst,src) -#define P_PEXTRW(dst,src,msk) p_pextrw(dst,src) -#define P_PSHUFW(dst,src,msk) p_pshufw(dst,src) -#define P_MOVNTQ(dst,src) p_movntq(dst,src) - -#define P_PFNACCM(dst,src,off) p_pfnaccm(dst,src,off) -#define P_FPPNACCM(dst,src,off) p_pfpnaccm(dst,src,off) -#define P_PSWAPDM(dst,src,off) p_pswapdm(dst,src,off) -#define P_PMINUBM(dst,src,off) p_pminubm(dst,src,off) -#define P_PMAXUBM(dst,src,off) p_pmaxubm(dst,src,off) -#define P_PMINSWM(dst,src,off) p_pminswm(dst,src,off) -#define P_PMAXSWM(dst,src,off) p_pmaxswm(dst,src,off) -#define P_PMULHUWM(dst,src,off) p_pmulhuwm(dst,src,off) -#define P_PAVGBM(dst,src,off) p_pavgbm(dst,src,off) -#define P_PAVGWM(dst,src,off) p_avgwm(dst,src,off) -#define P_PSADBWM(dst,src,off) p_psadbwm(dst,src,off) -#define P_PMOVMSKBM(dst,src,off) p_pmovmskbm(dst,src,off) -#define P_PMASKMOVQM(dst,src,off) p_pmaskmovqm(dst,src,off) -#define P_PINSRWM(dst,src,off,msk) p_pinsrwm(dst,src,off,msk) -#define P_PSHUFWM(dst,src,off,msk) p_pshufwm(dst,src,off,msk) -#define P_MOVNTQM(dst,src,off) p_movntqm(dst,src,off) - -#elif defined (_MSC_VER) && !defined (__MWERKS__) -// The Microsoft Visual C++ version of the 3DNow! macros. - -// Stop the "no EMMS" warning, since it doesn't detect FEMMS properly -#pragma warning(disable:4799) - -// Defines for operands. -#define _K3D_MM0 0xc0 -#define _K3D_MM1 0xc1 -#define _K3D_MM2 0xc2 -#define _K3D_MM3 0xc3 -#define _K3D_MM4 0xc4 -#define _K3D_MM5 0xc5 -#define _K3D_MM6 0xc6 -#define _K3D_MM7 0xc7 -#define _K3D_mm0 0xc0 -#define _K3D_mm1 0xc1 -#define _K3D_mm2 0xc2 -#define _K3D_mm3 0xc3 -#define _K3D_mm4 0xc4 -#define _K3D_mm5 0xc5 -#define _K3D_mm6 0xc6 -#define _K3D_mm7 0xc7 -#define _K3D_EAX 0x00 -#define _K3D_ECX 0x01 -#define _K3D_EDX 0x02 -#define _K3D_EBX 0x03 -#define _K3D_ESI 0x06 -#define _K3D_EDI 0x07 -#define _K3D_eax 0x00 -#define _K3D_ecx 0x01 -#define _K3D_edx 0x02 -#define _K3D_ebx 0x03 -#define _K3D_esi 0x06 -#define _K3D_edi 0x07 - -// These defines are for compatibility with the previous version of the header file. -#define _K3D_M0 0xc0 -#define _K3D_M1 0xc1 -#define _K3D_M2 0xc2 -#define _K3D_M3 0xc3 -#define _K3D_M4 0xc4 -#define _K3D_M5 0xc5 -#define _K3D_M6 0xc6 -#define _K3D_M7 0xc7 -#define _K3D_m0 0xc0 -#define _K3D_m1 0xc1 -#define _K3D_m2 0xc2 -#define _K3D_m3 0xc3 -#define _K3D_m4 0xc4 -#define _K3D_m5 0xc5 -#define _K3D_m6 0xc6 -#define _K3D_m7 0xc7 -#define _K3D__EAX 0x00 -#define _K3D__ECX 0x01 -#define _K3D__EDX 0x02 -#define _K3D__EBX 0x03 -#define _K3D__ESI 0x06 -#define _K3D__EDI 0x07 -#define _K3D__eax 0x00 -#define _K3D__ecx 0x01 -#define _K3D__edx 0x02 -#define _K3D__ebx 0x03 -#define _K3D__esi 0x06 -#define _K3D__edi 0x07 - -// General 3DNow! instruction format that is supported by -// these macros. Note that only the most basic form of memory -// operands are supported by these macros. - -#define InjK3DOps(dst,src,inst) \ -{ \ - _asm _emit 0x0f \ - _asm _emit 0x0f \ - _asm _emit ((_K3D_##dst & 0x3f) << 3) | _K3D_##src \ - _asm _emit _3DNowOpcode##inst \ -} - -#define InjK3DMOps(dst,src,off,inst) \ -{ \ - _asm _emit 0x0f \ - _asm _emit 0x0f \ - _asm _emit (((_K3D_##dst & 0x3f) << 3) | _K3D_##src | 0x40) \ - _asm _emit off \ - _asm _emit _3DNowOpcode##inst \ -} - -#define InjMMXOps(dst,src,inst) \ -{ \ - _asm _emit 0x0f \ - _asm _emit _3DNowOpcode##inst \ - _asm _emit ((_K3D_##dst & 0x3f) << 3) | _K3D_##src \ -} - -#define InjMMXMOps(dst,src,off,inst) \ -{ \ - _asm _emit 0x0f \ - _asm _emit _3DNowOpcode##inst \ - _asm _emit (((_K3D_##dst & 0x3f) << 3) | _K3D_##src | 0x40) \ - _asm _emit off \ -} - -#define _3DNowOpcodePF2ID 0x1d -#define _3DNowOpcodePFACC 0xae -#define _3DNowOpcodePFADD 0x9e -#define _3DNowOpcodePFCMPEQ 0xb0 -#define _3DNowOpcodePFCMPGE 0x90 -#define _3DNowOpcodePFCMPGT 0xa0 -#define _3DNowOpcodePFMAX 0xa4 -#define _3DNowOpcodePFMIN 0x94 -#define _3DNowOpcodePFMUL 0xb4 -#define _3DNowOpcodePFRCP 0x96 -#define _3DNowOpcodePFRCPIT1 0xa6 -#define _3DNowOpcodePFRCPIT2 0xb6 -#define _3DNowOpcodePFRSQRT 0x97 -#define _3DNowOpcodePFRSQIT1 0xa7 -#define _3DNowOpcodePFSUB 0x9a -#define _3DNowOpcodePFSUBR 0xaa -#define _3DNowOpcodePI2FD 0x0d -#define _3DNowOpcodePAVGUSB 0xbf -#define _3DNowOpcodePMULHRW 0xb7 -#define _3DNowOpcodePFNACC 0x8a -#define _3DNowOpcodeFPPNACC 0x8e -#define _3DNowOpcodePSWAPD 0xbb -#define _3DNowOpcodePMINUB 0xda -#define _3DNowOpcodePMAXUB 0xde -#define _3DNowOpcodePMINSW 0xea -#define _3DNowOpcodePMAXSW 0xee -#define _3DNowOpcodePMULHUW 0xe4 -#define _3DNowOpcodePAVGB 0xe0 -#define _3DNowOpcodePAVGW 0xe3 -#define _3DNowOpcodePSADBW 0xf6 -#define _3DNowOpcodePMOVMSKB 0xd7 -#define _3DNowOpcodePMASKMOVQ 0xf7 -#define _3DNowOpcodePINSRW 0xc4 -#define _3DNowOpcodePEXTRW 0xc5 -#define _3DNowOpcodePSHUFW 0x70 -#define _3DNowOpcodeMOVNTQ 0xe7 -#define _3DNowOpcodePREFETCHT 0x18 - - -#define PF2ID(dst,src) InjK3DOps(dst, src, PF2ID) -#define PFACC(dst,src) InjK3DOps(dst, src, PFACC) -#define PFADD(dst,src) InjK3DOps(dst, src, PFADD) -#define PFCMPEQ(dst,src) InjK3DOps(dst, src, PFCMPEQ) -#define PFCMPGE(dst,src) InjK3DOps(dst, src, PFCMPGE) -#define PFCMPGT(dst,src) InjK3DOps(dst, src, PFCMPGT) -#define PFMAX(dst,src) InjK3DOps(dst, src, PFMAX) -#define PFMIN(dst,src) InjK3DOps(dst, src, PFMIN) -#define PFMUL(dst,src) InjK3DOps(dst, src, PFMUL) -#define PFRCP(dst,src) InjK3DOps(dst, src, PFRCP) -#define PFRCPIT1(dst,src) InjK3DOps(dst, src, PFRCPIT1) -#define PFRCPIT2(dst,src) InjK3DOps(dst, src, PFRCPIT2) -#define PFRSQRT(dst,src) InjK3DOps(dst, src, PFRSQRT) -#define PFRSQIT1(dst,src) InjK3DOps(dst, src, PFRSQIT1) -#define PFSUB(dst,src) InjK3DOps(dst, src, PFSUB) -#define PFSUBR(dst,src) InjK3DOps(dst, src, PFSUBR) -#define PI2FD(dst,src) InjK3DOps(dst, src, PI2FD) -#define PAVGUSB(dst,src) InjK3DOps(dst, src, PAVGUSB) -#define PMULHRW(dst,src) InjK3DOps(dst, src, PMULHRW) - -#define FEMMS \ -{ \ - _asm _emit 0x0f \ - _asm _emit 0x0e \ -} - -#define PREFETCH(src) \ -{ \ - _asm _emit 0x0f \ - _asm _emit 0x0d \ - _asm _emit (_K3D_##src & 0x07) \ -} - -/* Prefetch with a short offset, < 127 or > -127 - Carefull! Doesn't check for your offset being - in range. */ - -#define PREFETCHM(src,off) \ -{ \ - _asm _emit 0x0f \ - _asm _emit 0x0d \ - _asm _emit (0x40 | (_K3D_##src & 0x07)) \ - _asm _emit off \ -} - -/* Prefetch with a long offset */ - -#define PREFETCHMLONG(src,off) \ -{ \ - _asm _emit 0x0f \ - _asm _emit 0x0d \ - _asm _emit (0x80 | (_K3D_##src & 0x07)) \ - _asm _emit (off & 0x000000ff) \ - _asm _emit (off & 0x0000ff00) >> 8 \ - _asm _emit (off & 0x00ff0000) >> 16 \ - _asm _emit (off & 0xff000000) >> 24 \ -} - -#define PREFETCHW(src) \ -{ \ - _asm _emit 0x0f \ - _asm _emit 0x0d \ - _asm _emit (0x08 | (_K3D_##src & 0x07)) \ -} - -#define PREFETCHWM(src,off) \ -{ \ - _asm _emit 0x0f \ - _asm _emit 0x0d \ - _asm _emit 0x48 | (_K3D_##src & 0x07) \ - _asm _emit off \ -} - -#define PREFETCHWMLONG(src,off) \ -{ \ - _asm _emit 0x0f \ - _asm _emit 0x0d \ - _asm _emit 0x88 | (_K3D_##src & 0x07) \ - _asm _emit (off & 0x000000ff) \ - _asm _emit (off & 0x0000ff00) >> 8 \ - _asm _emit (off & 0x00ff0000) >> 16 \ - _asm _emit (off & 0xff000000) >> 24 \ -} - -#define CPUID \ -{ \ - _asm _emit 0x0f \ - _asm _emit 0xa2 \ -} - - -/* Defines for new, K7 opcodes */ -#define SFENCE \ -{ \ - _asm _emit 0x0f \ - _asm _emit 0xae \ - _asm _emit 0xf8 \ -} - -#define PFNACC(dst,src) InjK3DOps(dst,src,PFNACC) -#define PFPNACC(dst,src) InjK3DOps(dst,src,PFPNACC) -#define PSWAPD(dst,src) InjK3DOps(dst,src,PSWAPD) -#define PMINUB(dst,src) InjMMXOps(dst,src,PMINUB) -#define PMAXUB(dst,src) InjMMXOps(dst,src,PMAXUB) -#define PMINSW(dst,src) InjMMXOps(dst,src,PMINSW) -#define PMAXSW(dst,src) InjMMXOps(dst,src,PMAXSW) -#define PMULHUW(dst,src) InjMMXOps(dst,src,PMULHUW) -#define PAVGB(dst,src) InjMMXOps(dst,src,PAVGB) -#define PAVGW(dst,src) InjMMXOps(dst,src,PAVGW) -#define PSADBW(dst,src) InjMMXOps(dst,src,PSADBW) -#define PMOVMSKB(dst,src) InjMMXOps(dst,src,PMOVMSKB) -#define PMASKMOVQ(dst,src) InjMMXOps(dst,src,PMASKMOVQ) -#define PINSRW(dst,src,msk) InjMMXOps(dst,src,PINSRW) _asm _emit msk -#define PEXTRW(dst,src,msk) InjMMXOps(dst,src,PEXTRW) _asm _emit msk -#define PSHUFW(dst,src,msk) InjMMXOps(dst,src,PSHUFW) _asm _emit msk -#define MOVNTQ(dst,src) InjMMXOps(src,dst,MOVNTQ) -#define PREFETCHNTA(mem) InjMMXOps(mm0,mem,PREFETCHT) -#define PREFETCHT0(mem) InjMMXOps(mm1,mem,PREFETCHT) -#define PREFETCHT1(mem) InjMMXOps(mm2,mem,PREFETCHT) -#define PREFETCHT2(mem) InjMMXOps(mm3,mem,PREFETCHT) - - -/* Memory/offset versions of the opcodes */ -#define PAVGUSBM(dst,src,off) InjK3DMOps(dst,src,off,PAVGUSB) -#define PF2IDM(dst,src,off) InjK3DMOps(dst,src,off,PF2ID) -#define PFACCM(dst,src,off) InjK3DMOps(dst,src,off,PFACC) -#define PFADDM(dst,src,off) InjK3DMOps(dst,src,off,PFADD) -#define PFCMPEQM(dst,src,off) InjK3DMOps(dst,src,off,PFCMPEQ) -#define PFCMPGEM(dst,src,off) InjK3DMOps(dst,src,off,PFCMPGE) -#define PFCMPGTM(dst,src,off) InjK3DMOps(dst,src,off,PFCMPGT) -#define PFMAXM(dst,src,off) InjK3DMOps(dst,src,off,PFMAX) -#define PFMINM(dst,src,off) InjK3DMOps(dst,src,off,PFMIN) -#define PFMULM(dst,src,off) InjK3DMOps(dst,src,off,PFMUL) -#define PFRCPM(dst,src,off) InjK3DMOps(dst,src,off,PFRCP) -#define PFRCPIT1M(dst,src,off) InjK3DMOps(dst,src,off,PFRCPIT1) -#define PFRCPIT2M(dst,src,off) InjK3DMOps(dst,src,off,PFRCPIT2) -#define PFRSQRTM(dst,src,off) InjK3DMOps(dst,src,off,PFRSQRT) -#define PFRSQIT1M(dst,src,off) InjK3DMOps(dst,src,off,PFRSQIT1) -#define PFSUBM(dst,src,off) InjK3DMOps(dst,src,off,PFSUB) -#define PFSUBRM(dst,src,off) InjK3DMOps(dst,src,off,PFSUBR) -#define PI2FDM(dst,src,off) InjK3DMOps(dst,src,off,PI2FD) -#define PMULHRWM(dst,src,off) InjK3DMOps(dst,src,off,PMULHRW) - - -/* Memory/offset versions of the K7 opcodes */ -#define PFNACCM(dst,src,off) InjK3DMOps(dst,src,off,PFNACC) -#define PFPNACCM(dst,src,off) InjK3DMOps(dst,src,off,PFPNACC) -#define PSWAPDM(dst,src,off) InjK3DMOps(dst,src,off,PSWAPD) -#define PMINUBM(dst,src,off) InjMMXMOps(dst,src,off,PMINUB) -#define PMAXUBM(dst,src,off) InjMMXMOps(dst,src,off,PMAXUB) -#define PMINSWM(dst,src,off) InjMMXMOps(dst,src,off,PMINSW) -#define PMAXSWM(dst,src,off) InjMMXMOps(dst,src,off,PMAXSW) -#define PMULHUWM(dst,src,off) InjMMXMOps(dst,src,off,PMULHUW) -#define PAVGBM(dst,src,off) InjMMXMOps(dst,src,off,PAVGB) -#define PAVGWM(dst,src,off) InjMMXMOps(dst,src,off,PAVGW) -#define PSADBWM(dst,src,off) InjMMXMOps(dst,src,off,PSADBW) -#define PMOVMSKBM(dst,src,off) InjMMXMOps(dst,src,off,PMOVMSKB) -#define PMASKMOVQM(dst,src,off) InjMMXMOps(dst,src,off,PMASKMOVQ) -#define PINSRWM(dst,src,off,msk) InjMMXMOps(dst,src,off,PINSRW) _asm _emit msk -#define PSHUFWM(dst,src,off,msk) InjMMXMOps(dst,src,off,PSHUFW) _asm _emit msk -#define MOVNTQM(dst,src,off) InjMMXMOps(src,dst,off,MOVNTQ) -#define PREFETCHNTAM(mem,off) InjMMXMOps(mm0,mem,off,PREFETCHT) -#define PREFETCHT0M(mem,off) InjMMXMOps(mm1,mem,off,PREFETCHT) -#define PREFETCHT1M(mem,off) InjMMXMOps(mm2,mem,off,PREFETCHT) -#define PREFETCHT2M(mem,off) InjMMXMOps(mm3,mem,off,PREFETCHT) - - -#else - -/* Assume built-in support for 3DNow! opcodes, replace macros with opcodes */ -#define PAVGUSB(dst,src) pavgusb dst,src -#define PF2ID(dst,src) pf2id dst,src -#define PFACC(dst,src) pfacc dst,src -#define PFADD(dst,src) pfadd dst,src -#define PFCMPEQ(dst,src) pfcmpeq dst,src -#define PFCMPGE(dst,src) pfcmpge dst,src -#define PFCMPGT(dst,src) pfcmpgt dst,src -#define PFMAX(dst,src) pfmax dst,src -#define PFMIN(dst,src) pfmin dst,src -#define PFMUL(dst,src) pfmul dst,src -#define PFRCP(dst,src) pfrcp dst,src -#define PFRCPIT1(dst,src) pfrcpit1 dst,src -#define PFRCPIT2(dst,src) pfrcpit2 dst,src -#define PFRSQRT(dst,src) pfrsqrt dst,src -#define PFRSQIT1(dst,src) pfrsqit1 dst,src -#define PFSUB(dst,src) pfsub dst,src -#define PFSUBR(dst,src) pfsubr dst,src -#define PI2FD(dst,src) pi2fd dst,src -#define PMULHRW(dst,src) pmulhrw dst,src -#define PREFETCH(src) prefetch src -#define PREFETCHW(src) prefetchw src - -#define PAVGUSBM(dst,src,off) pavgusb dst,[src+off] -#define PF2IDM(dst,src,off) PF2ID dst,[src+off] -#define PFACCM(dst,src,off) PFACC dst,[src+off] -#define PFADDM(dst,src,off) PFADD dst,[src+off] -#define PFCMPEQM(dst,src,off) PFCMPEQ dst,[src+off] -#define PFCMPGEM(dst,src,off) PFCMPGE dst,[src+off] -#define PFCMPGTM(dst,src,off) PFCMPGT dst,[src+off] -#define PFMAXM(dst,src,off) PFMAX dst,[src+off] -#define PFMINM(dst,src,off) PFMIN dst,[src+off] -#define PFMULM(dst,src,off) PFMUL dst,[src+off] -#define PFRCPM(dst,src,off) PFRCP dst,[src+off] -#define PFRCPIT1M(dst,src,off) PFRCPIT1 dst,[src+off] -#define PFRCPIT2M(dst,src,off) PFRCPIT2 dst,[src+off] -#define PFRSQRTM(dst,src,off) PFRSQRT dst,[src+off] -#define PFRSQIT1M(dst,src,off) PFRSQIT1 dst,[src+off] -#define PFSUBM(dst,src,off) PFSUB dst,[src+off] -#define PFSUBRM(dst,src,off) PFSUBR dst,[src+off] -#define PI2FDM(dst,src,off) PI2FD dst,[src+off] -#define PMULHRWM(dst,src,off) PMULHRW dst,[src+off] - - -#if defined (__MWERKS__) -// At the moment, CodeWarrior does not support these opcodes, so hand-assemble them - -// Defines for operands. -#define _K3D_MM0 0xc0 -#define _K3D_MM1 0xc1 -#define _K3D_MM2 0xc2 -#define _K3D_MM3 0xc3 -#define _K3D_MM4 0xc4 -#define _K3D_MM5 0xc5 -#define _K3D_MM6 0xc6 -#define _K3D_MM7 0xc7 -#define _K3D_mm0 0xc0 -#define _K3D_mm1 0xc1 -#define _K3D_mm2 0xc2 -#define _K3D_mm3 0xc3 -#define _K3D_mm4 0xc4 -#define _K3D_mm5 0xc5 -#define _K3D_mm6 0xc6 -#define _K3D_mm7 0xc7 -#define _K3D_EAX 0x00 -#define _K3D_ECX 0x01 -#define _K3D_EDX 0x02 -#define _K3D_EBX 0x03 -#define _K3D_ESI 0x06 -#define _K3D_EDI 0x07 -#define _K3D_eax 0x00 -#define _K3D_ecx 0x01 -#define _K3D_edx 0x02 -#define _K3D_ebx 0x03 -#define _K3D_esi 0x06 -#define _K3D_edi 0x07 -#define _K3D_EAX 0x00 -#define _K3D_ECX 0x01 -#define _K3D_EDX 0x02 -#define _K3D_EBX 0x03 -#define _K3D_ESI 0x06 -#define _K3D_EDI 0x07 -#define _K3D_eax 0x00 -#define _K3D_ecx 0x01 -#define _K3D_edx 0x02 -#define _K3D_ebx 0x03 -#define _K3D_esi 0x06 -#define _K3D_edi 0x07 - -#define InjK3DOps(dst,src,inst) \ - db 0x0f, 0x0f, (((_K3D_##dst & 0x3f) << 3) | _K3D_##src), _3DNowOpcode##inst - -#define InjK3DMOps(dst,src,off,inst) \ - db 0x0f, 0x0f, (((_K3D_##dst & 0x3f) << 3) | _K3D_##src | 0x40), off, _3DNowOpcode##inst - -#define InjMMXOps(dst,src,inst) \ - db 0x0f, _3DNowOpcode##inst, (((_K3D_##dst & 0x3f) << 3) | _K3D_##src) - -#define InjMMXMOps(dst,src,off,inst) \ - db 0x0f, _3DNowOpcode##inst, (((_K3D_##dst & 0x3f) << 3) | _K3D_##src | 0x40), off - -#define PFNACC(dst,src) InjK3DOps(dst,src,PFNACC) -#define PFPNACC(dst,src) InjK3DOps(dst,src,PFPNACC) -#define PSWAPD(dst,src) InjK3DOps(dst,src,PSWAPD) -#define PMINUB(dst,src) InjMMXOps(dst,src,PMINUB) -#define PMAXUB(dst,src) InjMMXOps(dst,src,PMAXUB) -#define PMINSW(dst,src) InjMMXOps(dst,src,PMINSW) -#define PMAXSW(dst,src) InjMMXOps(dst,src,PMAXSW) -#define PMULHUW(dst,src) InjMMXOps(dst,src,PMULHUW) -#define PAVGB(dst,src) InjMMXOps(dst,src,PAVGB) -#define PAVGW(dst,src) InjMMXOps(dst,src,PAVGW) -#define PSADBW(dst,src) InjMMXOps(dst,src,PSADBW) -#define PMOVMSKB(dst,src) InjMMXOps(dst,src,PMOVMSKB) -#define PMASKMOVQ(dst,src) InjMMXOps(dst,src,PMASKMOVQ) -#define PINSRW(dst,src,msk) InjMMXOps(dst,src,PINSRW) db msk -#define PEXTRW(dst,src,msk) InjMMXOps(dst,src,PEXTRW) db msk -#define PSHUFW(dst,src,msk) InjMMXOps(dst,src,PSHUFW) db msk -#define MOVNTQ(dst,src) InjMMXOps(src,dst,MOVNTQ) -#define PREFETCHNTA(mem) InjMMXOps(mm0,mem,PREFETCHT) -#define PREFETCHT0(mem) InjMMXOps(mm1,mem,PREFETCHT) -#define PREFETCHT1(mem) InjMMXOps(mm2,mem,PREFETCHT) -#define PREFETCHT2(mem) InjMMXOps(mm3,mem,PREFETCHT) - - -/* Memory/offset versions of the K7 opcodes */ -#define PFNACCM(dst,src,off) InjK3DMOps(dst,src,off,PFNACC) -#define PFPNACCM(dst,src,off) InjK3DMOps(dst,src,off,PFPNACC) -#define PSWAPDM(dst,src,off) InjK3DMOps(dst,src,off,PSWAPD) -#define PMINUBM(dst,src,off) InjMMXMOps(dst,src,off,PMINUB) -#define PMAXUBM(dst,src,off) InjMMXMOps(dst,src,off,PMAXUB) -#define PMINSWM(dst,src,off) InjMMXMOps(dst,src,off,PMINSW) -#define PMAXSWM(dst,src,off) InjMMXMOps(dst,src,off,PMAXSW) -#define PMULHUWM(dst,src,off) InjMMXMOps(dst,src,off,PMULHUW) -#define PAVGBM(dst,src,off) InjMMXMOps(dst,src,off,PAVGB) -#define PAVGWM(dst,src,off) InjMMXMOps(dst,src,off,PAVGW) -#define PSADBWM(dst,src,off) InjMMXMOps(dst,src,off,PSADBW) -#define PMOVMSKBM(dst,src,off) InjMMXMOps(dst,src,off,PMOVMSKB) -#define PMASKMOVQM(dst,src,off) InjMMXMOps(dst,src,off,PMASKMOVQ) -#define PINSRWM(dst,src,off,msk) InjMMXMOps(dst,src,off,PINSRW), msk -#define PEXTRWM(dst,src,off,msk) InjMMXMOps(dst,src,off,PEXTRW), msk -#define PSHUFWM(dst,src,off,msk) InjMMXMOps(dst,src,off,PSHUFW), msk -#define MOVNTQM(dst,src,off) InjMMXMOps(src,dst,off,MOVNTQ) -#define PREFETCHNTAM(mem,off) InjMMXMOps(mm0,mem,off,PREFETCHT) -#define PREFETCHT0M(mem,off) InjMMXMOps(mm1,mem,off,PREFETCHT) -#define PREFETCHT1M(mem,off) InjMMXMOps(mm2,mem,off,PREFETCHT) -#define PREFETCHT2M(mem,off) InjMMXMOps(mm3,mem,off,PREFETCHT) - - -#else - -#define PFNACC(dst,src) PFNACC dst,src -#define PFPNACC(dst,src) PFPNACC dst,src -#define PSWAPD(dst,src) PSWAPD dst,src -#define PMINUB(dst,src) PMINUB dst,src -#define PMAXUB(dst,src) PMAXUB dst,src -#define PMINSW(dst,src) PMINSW dst,src -#define PMAXSW(dst,src) PMAXSW dst,src -#define PMULHUW(dst,src) PMULHUW dst,src -#define PAVGB(dst,src) PAVGB dst,src -#define PAVGW(dst,src) PAVGW dst,src -#define PSADBW(dst,src) PSADBW dst,src -#define PMOVMSKB(dst,src) PMOVMSKB dst,src -#define PMASKMOVQ(dst,src) PMASKMOVQ dst,src -#define PINSRW(dst,src,msk) PINSRW dst,src,msk -#define PEXTRW(dst,src,msk) PEXTRW dst,src,msk -#define PSHUFW(dst,src,msk) PSHUFW dst,src,msk -#define MOVNTQ(dst,src) MOVNTQ dst,src - -#define PFNACCM(dst,src,off) PFNACC dst,[src+off] -#define PFPNACCM(dst,src,off) PFPNACC dst,[src+off] -#define PSWAPDM(dst,src,off) PSWAPD dst,[src+off] -#define PMINUBM(dst,src,off) PMINUB dst,[src+off] -#define PMAXUBM(dst,src,off) PMAXUB dst,[src+off] -#define PMINSWM(dst,src,off) PMINSW dst,[src+off] -#define PMAXSWM(dst,src,off) PMAXSW dst,[src+off] -#define PMULHUWM(dst,src,off) PMULHUW dst,[src+off] -#define PAVGBM(dst,src,off) PAVGB dst,[src+off] -#define PAVGWM(dst,src,off) PAVGW dst,[src+off] -#define PSADBWM(dst,src,off) PSADBW dst,[src+off] -#define PMOVMSKBM(dst,src,off) PMOVMSKB dst,[src+off] -#define PMASKMOVQM(dst,src,off) PMASKMOVQ dst,[src+off] -#define PINSRWM(dst,src,off,msk) PINSRW dst,[src+off],msk -#define PEXTRWM(dst,src,off,msk) PEXTRW dst,[src+off],msk -#define PSHUFWM(dst,src,off,msk) PSHUFW dst,[src+off],msk -#define MOVNTQM(dst,src,off) MOVNTQ dst,[src+off] - -#endif - -#endif - -/* Just to deal with lower case. */ -#define pf2id(dst,src) PF2ID(dst,src) -#define pfacc(dst,src) PFACC(dst,src) -#define pfadd(dst,src) PFADD(dst,src) -#define pfcmpeq(dst,src) PFCMPEQ(dst,src) -#define pfcmpge(dst,src) PFCMPGE(dst,src) -#define pfcmpgt(dst,src) PFCMPGT(dst,src) -#define pfmax(dst,src) PFMAX(dst,src) -#define pfmin(dst,src) PFMIN(dst,src) -#define pfmul(dst,src) PFMUL(dst,src) -#define pfrcp(dst,src) PFRCP(dst,src) -#define pfrcpit1(dst,src) PFRCPIT1(dst,src) -#define pfrcpit2(dst,src) PFRCPIT2(dst,src) -#define pfrsqrt(dst,src) PFRSQRT(dst,src) -#define pfrsqit1(dst,src) PFRSQIT1(dst,src) -#define pfsub(dst,src) PFSUB(dst,src) -#define pfsubr(dst,src) PFSUBR(dst,src) -#define pi2fd(dst,src) PI2FD(dst,src) -#define femms FEMMS -#define pavgusb(dst,src) PAVGUSB(dst,src) -#define pmulhrw(dst,src) PMULHRW(dst,src) -#define prefetch(src) PREFETCH(src) -#define prefetchw(src) PREFETCHW(src) - -#define prefetchm(src,off) PREFETCHM(src,off) -#define prefetchmlong(src,off) PREFETCHMLONG(src,off) -#define prefetchwm(src,off) PREFETCHWM(src,off) -#define prefetchwmlong(src,off) PREFETCHWMLONG(src,off) - -#define pfnacc(dst,src) PFNACC(dst,src) -#define pfpnacc(dst,src) PFPNACC(dst,src) -#define pswapd(dst,src) PSWAPD(dst,src) -#define pminub(dst,src) PMINUB(dst,src) -#define pmaxub(dst,src) PMAXUB(dst,src) -#define pminsw(dst,src) PMINSW(dst,src) -#define pmaxsw(dst,src) PMAXSW(dst,src) -#define pmulhuw(dst,src) PMULHUW(dst,src) -#define pavgb(dst,src) PAVGB(dst,src) -#define pavgw(dst,src) PAVGW(dst,src) -#define psadbw(dst,src) PSADBW(dst,src) -#define pmovmskb(dst,src) PMOVMSKB(dst,src) -#define pmaskmovq(dst,src) PMASKMOVQ(dst,src) -#define pinsrw(dst,src,msk) PINSRW(dst,src,msk) -#define pextrw(dst,src,msk) PEXTRW(dst,src,msk) -#define pshufw(dst,src,msk) PSHUFW(dst,src,msk) -#define movntq(dst,src) MOVNTQ(dst,src) -#define prefetchnta(mem) PREFETCHNTA(mem) -#define prefetcht0(mem) PREFETCHT0(mem) -#define prefetcht1(mem) PREFETCHT1(mem) -#define prefetcht2(mem) PREFETCHT2(mem) - - -#define pavgusbm(dst,src,off) PAVGUSBM(dst,src,off) -#define pf2idm(dst,src,off) PF2IDM(dst,src,off) -#define pfaccm(dst,src,off) PFACCM(dst,src,off) -#define pfaddm(dst,src,off) PFADDM(dst,src,off) -#define pfcmpeqm(dst,src,off) PFCMPEQM(dst,src,off) -#define pfcmpgem(dst,src,off) PFCMPGEM(dst,src,off) -#define pfcmpgtm(dst,src,off) PFCMPGTM(dst,src,off) -#define pfmaxm(dst,src,off) PFMAXM(dst,src,off) -#define pfminm(dst,src,off) PFMINM(dst,src,off) -#define pfmulm(dst,src,off) PFMULM(dst,src,off) -#define pfrcpm(dst,src,off) PFRCPM(dst,src,off) -#define pfrcpit1m(dst,src,off) PFRCPIT1M(dst,src,off) -#define pfrcpit2m(dst,src,off) PFRCPIT2M(dst,src,off) -#define pfrsqrtm(dst,src,off) PFRSQRTM(dst,src,off) -#define pfrsqit1m(dst,src,off) PFRSQIT1M(dst,src,off) -#define pfsubm(dst,src,off) PFSUBM(dst,src,off) -#define pfsubrm(dst,src,off) PFSUBRM(dst,src,off) -#define pi2fdm(dst,src,off) PI2FDM(dst,src,off) -#define pmulhrwm(dst,src,off) PMULHRWM(dst,src,off) -#define cpuid CPUID -#define sfence SFENCE - -#define pfnaccm(dst,src,off) PFNACCM(dst,src,off) -#define pfpnaccm(dst,src,off) PFPNACCM(dst,src,off) -#define pswapdm(dst,src,off) PSWAPDM(dst,src,off) -#define pminubm(dst,src,off) PMINUBM(dst,src,off) -#define pmaxubm(dst,src,off) PMAXUBM(dst,src,off) -#define pminswm(dst,src,off) PMINSWM(dst,src,off) -#define pmaxswm(dst,src,off) PMAXSWM(dst,src,off) -#define pmulhuwm(dst,src,off) PMULHUWM(dst,src,off) -#define pavgbm(dst,src,off) PAVGBM(dst,src,off) -#define pavgwm(dst,src,off) PAVGWM(dst,src,off) -#define psadbwm(dst,src,off) PSADBWM(dst,src,off) -#define pmovmskbm(dst,src,off) PMOVMSKBM(dst,src,off) -#define pmaskmovqm(dst,src,off) PMASKMOVQM(dst,src,off) -#define pinsrwm(dst,src,off,msk) PINSRWM(dst,src,off,msk) -#define pextrwm(dst,src,off,msk) PEXTRWM(dst,src,off,msk) -#define pshufwm(dst,src,off,msk) PSHUFWM(dst,src,off,msk) -#define movntqm(dst,src,off) MOVNTQM(dst,src,off) -#define prefetchntam(mem,off) PREFETCHNTA(mem,off) -#define prefetcht0m(mem,off) PREFETCHT0(mem,off) -#define prefetcht1m(mem,off) PREFETCHT1(mem,off) -#define prefetcht2m(mem,off) PREFETCHT2(mem,off) - -#endif diff --git a/public/steam/steamclientpublic.h b/public/steam/steamclientpublic.h index dcf1f9ec..d9e4db0c 100644 --- a/public/steam/steamclientpublic.h +++ b/public/steam/steamclientpublic.h @@ -412,8 +412,8 @@ public: // this set of functions is hidden, will be moved out of class explicit CSteamID( const char *pchSteamID, EUniverse eDefaultUniverse = k_EUniverseInvalid ); - char * Render() const; // renders this steam ID to string - static char * Render( uint64 ulSteamID ); // static method to render a uint64 representation of a steam ID to a string + const char * Render() const; // renders this steam ID to string + static const char * Render( uint64 ulSteamID ); // static method to render a uint64 representation of a steam ID to a string void SetFromString( const char *pchSteamID, EUniverse eDefaultUniverse ); bool SetFromSteam2String( const char *pchSteam2ID, EUniverse eUniverse ); diff --git a/public/tier0/dbg.h b/public/tier0/dbg.h index 9c0a64fe..150ec659 100644 --- a/public/tier0/dbg.h +++ b/public/tier0/dbg.h @@ -178,6 +178,12 @@ enum SpewRetval_t /* type of externally defined function used to display debug spew */ typedef SpewRetval_t (*SpewOutputFunc_t)( SpewType_t spewType, const tchar *pMsg ); +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunknown-pragmas" +#pragma clang diagnostic ignored "-Wreturn-type-c-linkage" +#endif + /* Used to redirect spew output */ DBG_INTERFACE void SpewOutputFunc( SpewOutputFunc_t func ); @@ -206,6 +212,10 @@ DBG_INTERFACE bool SetupWin32ConsoleIO(); // Returns true if they want to break in the debugger. DBG_INTERFACE bool DoNewAssertDialog( const tchar *pFile, int line, const tchar *pExpression ); +#ifdef __clang__ +#pragma clang diagnostic pop +#endif + /* Used to define macros, never use these directly. */ #define _AssertMsg( _exp, _msg, _executeExp, _bFatal ) \ diff --git a/public/tier0/fasttimer.h b/public/tier0/fasttimer.h index 0678ebd6..d59a93a5 100644 --- a/public/tier0/fasttimer.h +++ b/public/tier0/fasttimer.h @@ -233,8 +233,8 @@ private: unsigned m_nIters; CCycleCount m_Total; CCycleCount m_Peak; - bool m_fReport; - const tchar *m_pszName; +// bool m_fReport; +// const tchar *m_pszName; }; // -------------------------------------------------------------------------- // diff --git a/public/tier0/memalloc.h b/public/tier0/memalloc.h index eb001b68..2840d095 100644 --- a/public/tier0/memalloc.h +++ b/public/tier0/memalloc.h @@ -1,4 +1,4 @@ -//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============// +//========= Copyright Valve Corporation, All rights reserved. ============// // // Purpose: This header should never be used directly from leaf code!!! // Instead, just add the file memoverride.cpp into your project and all this @@ -14,21 +14,31 @@ #pragma once #endif +// These memory debugging switches aren't relevant under Linux builds since memoverride.cpp +// isn't built into Linux projects +#ifndef POSIX // Define this in release to get memory tracking even in release builds //#define USE_MEM_DEBUG 1 +#endif #if defined( _MEMTEST ) +#ifdef _WIN32 #define USE_MEM_DEBUG 1 #endif +#endif // Undefine this if using a compiler lacking threadsafe RTTI (like vc6) #define MEM_DEBUG_CLASSNAME 1 -#if !defined(STEAM) && !defined(NO_MALLOC_OVERRIDE) - #include +#if defined( OSX ) +#include +#endif + #include "tier0/mem.h" +#if !defined(STEAM) && !defined(NO_MALLOC_OVERRIDE) + struct _CrtMemState; #define MEMALLOC_VERSION 1 @@ -103,7 +113,17 @@ public: #endif // Returns 0 if no failure, otherwise the size_t of the last requested chunk + // "I'm sure this is completely thread safe!" Brian Deen 7/19/2012. virtual size_t MemoryAllocFailed() = 0; + + // handles storing allocation info for coroutines + virtual uint32 GetDebugInfoSize() = 0; + virtual void SaveDebugInfo( void *pvDebugInfo ) = 0; + virtual void RestoreDebugInfo( const void *pvDebugInfo ) = 0; + virtual void InitDebugInfo( void *pvDebugInfo, const char *pchRootFileName, int nLine ) = 0; + + // Replacement for ::GlobalMemoryStatus which accounts for unused memory in our system + virtual void GlobalMemoryStatus( size_t *pUsedMemory, size_t *pFreeMemory ) = 0; }; //----------------------------------------------------------------------------- @@ -113,11 +133,52 @@ MEM_INTERFACE IMemAlloc *g_pMemAlloc; //----------------------------------------------------------------------------- +#ifdef MEMALLOC_REGIONS +#ifndef MEMALLOC_REGION +#define MEMALLOC_REGION 0 +#endif +inline void *MemAlloc_Alloc( size_t nSize ) +{ + return g_pMemAlloc->RegionAlloc( MEMALLOC_REGION, nSize ); +} + +inline void *MemAlloc_Alloc( size_t nSize, const char *pFileName, int nLine ) +{ + return g_pMemAlloc->RegionAlloc( MEMALLOC_REGION, nSize, pFileName, nLine ); +} +#else +#undef MEMALLOC_REGION +inline void *MemAlloc_Alloc( size_t nSize ) +{ + return g_pMemAlloc->Alloc( nSize ); +} + +inline void *MemAlloc_Alloc( size_t nSize, const char *pFileName, int nLine ) +{ + return g_pMemAlloc->Alloc( nSize, pFileName, nLine ); +} +#endif +inline void MemAlloc_Free( void *ptr ) +{ + g_pMemAlloc->Free( ptr ); +} +inline void MemAlloc_Free( void *ptr, const char *pFileName, int nLine ) +{ + g_pMemAlloc->Free( ptr, pFileName, nLine ); +} + +//----------------------------------------------------------------------------- + +inline bool ValueIsPowerOfTwo( size_t value ) // don't clash with mathlib definition +{ + return (value & ( value - 1 )) == 0; +} + inline void *MemAlloc_AllocAligned( size_t size, size_t align ) { unsigned char *pAlloc, *pResult; - if (!IsPowerOfTwo(uint(align))) + if (!IsPowerOfTwo(align)) return NULL; align = (align > sizeof(void *) ? align : sizeof(void *)) - 1; @@ -135,7 +196,7 @@ inline void *MemAlloc_AllocAligned( size_t size, size_t align, const char *pszFi { unsigned char *pAlloc, *pResult; - if (!IsPowerOfTwo(uint(align))) + if (!IsPowerOfTwo(align)) return NULL; align = (align > sizeof(void *) ? align : sizeof(void *)) - 1; @@ -149,9 +210,45 @@ inline void *MemAlloc_AllocAligned( size_t size, size_t align, const char *pszFi return (void *)pResult; } +inline void *MemAlloc_AllocAlignedUnattributed( size_t size, size_t align ) +{ + unsigned char *pAlloc, *pResult; + + if (!ValueIsPowerOfTwo(align)) + return NULL; + + align = (align > sizeof(void *) ? align : sizeof(void *)) - 1; + + if ( (pAlloc = (unsigned char*)MemAlloc_Alloc( sizeof(void *) + align + size ) ) == (unsigned char*)NULL) + return NULL; + + pResult = (unsigned char*)( (size_t)(pAlloc + sizeof(void *) + align ) & ~align ); + ((unsigned char**)(pResult))[-1] = pAlloc; + + return (void *)pResult; +} + +inline void *MemAlloc_AllocAlignedFileLine( size_t size, size_t align, const char *pszFile, int nLine ) +{ + unsigned char *pAlloc, *pResult; + + if (!ValueIsPowerOfTwo(align)) + return NULL; + + align = (align > sizeof(void *) ? align : sizeof(void *)) - 1; + + if ( (pAlloc = (unsigned char*)MemAlloc_Alloc( sizeof(void *) + align + size, pszFile, nLine ) ) == (unsigned char*)NULL) + return NULL; + + pResult = (unsigned char*)( (size_t)(pAlloc + sizeof(void *) + align ) & ~align ); + ((unsigned char**)(pResult))[-1] = pAlloc; + + return (void *)pResult; +} + inline void *MemAlloc_ReallocAligned( void *ptr, size_t size, size_t align ) { - if ( !IsPowerOfTwo( uint(align) ) ) + if ( !IsPowerOfTwo( align ) ) return NULL; // Don't change alignment between allocation + reallocation. @@ -197,6 +294,23 @@ inline void MemAlloc_FreeAligned( void *pMemBlock ) g_pMemAlloc->Free( pAlloc ); } +inline void MemAlloc_FreeAligned( void *pMemBlock, const char *pFileName, int nLine ) +{ + void *pAlloc; + + if ( pMemBlock == NULL ) + return; + + pAlloc = pMemBlock; + + // pAlloc points to the pointer to starting of the memory block + pAlloc = (void *)(((size_t)pAlloc & ~( sizeof(void *) - 1 ) ) - sizeof(void *)); + + // pAlloc is the pointer to the start of memory block + pAlloc = *( (void **)pAlloc ); + g_pMemAlloc->Free( pAlloc, pFileName, nLine ); +} + inline size_t MemAlloc_GetSizeAligned( void *pMemBlock ) { void *pAlloc; @@ -230,6 +344,20 @@ inline size_t MemAlloc_GetSizeAligned( void *pMemBlock ) #define MemAlloc_RegisterDeallocation( pFileName, nLine, nLogicalSize, nActualSize, nTime ) ((void)0) #endif +#define MemAlloc_DumpStats() g_pMemAlloc->DumpStats() +#define MemAlloc_CompactHeap() g_pMemAlloc->CompactHeap() +#define MemAlloc_OutOfMemory() g_pMemAlloc->OutOfMemory() +#define MemAlloc_CompactIncremental() g_pMemAlloc->CompactIncremental() +#define MemAlloc_DumpStatsFileBase( _filename ) g_pMemAlloc->DumpStatsFileBase( _filename ) +#define MemAlloc_CrtCheckMemory() g_pMemAlloc->CrtCheckMemory() +#define MemAlloc_GlobalMemoryStatus( _usedMemory, _freeMemory ) g_pMemAlloc->GlobalMemoryStatus( _usedMemory, _freeMemory ) +#define MemAlloc_MemoryAllocFailed() g_pMemAlloc->MemoryAllocFailed() + +#define MemAlloc_GetDebugInfoSize() g_pMemAlloc->GetDebugInfoSize() +#define MemAlloc_SaveDebugInfo( pvDebugInfo ) g_pMemAlloc->SaveDebugInfo( pvDebugInfo ) +#define MemAlloc_RestoreDebugInfo( pvDebugInfo ) g_pMemAlloc->RestoreDebugInfo( pvDebugInfo ) +#define MemAlloc_InitDebugInfo( pvDebugInfo, pchRootFileName, nLine ) g_pMemAlloc->InitDebugInfo( pvDebugInfo, pchRootFileName, nLine ) +#define MemAlloc_GetSize( x ) g_pMemAlloc->GetSize( x ); //----------------------------------------------------------------------------- class CMemAllocAttributeAlloction @@ -335,6 +463,51 @@ struct MemAllocFileLine_t //----------------------------------------------------------------------------- +#elif defined( POSIX ) + +#if defined( OSX ) +// Mac always aligns allocs, don't need to call posix_memalign which doesn't exist in 10.5.8 which TF2 still needs to run on +//inline void *memalign(size_t alignment, size_t size) {void *pTmp=NULL; posix_memalign(&pTmp, alignment, size); return pTmp;} +inline void *memalign(size_t alignment, size_t size) {void *pTmp=NULL; pTmp = malloc(size); return pTmp;} +#endif + +inline void *_aligned_malloc( size_t nSize, size_t align ) { return memalign( align, nSize ); } +inline void _aligned_free( void *ptr ) { free( ptr ); } + +inline void *MemAlloc_Alloc( size_t nSize, const char *pFileName = NULL, int nLine = 0 ) { return malloc( nSize ); } +inline void MemAlloc_Free( void *ptr, const char *pFileName = NULL, int nLine = 0 ) { free( ptr ); } + +inline void *MemAlloc_AllocAligned( size_t size, size_t align, const char *pszFile = NULL, int nLine = 0 ) { return memalign( align, size ); } +inline void *MemAlloc_AllocAlignedFileLine( size_t size, size_t align, const char *pszFile = NULL, int nLine = 0 ) { return memalign( align, size ); } +inline void MemAlloc_FreeAligned( void *pMemBlock, const char *pszFile = NULL, int nLine = 0 ) { free( pMemBlock ); } + +#if defined( OSX ) +inline size_t _msize( void *ptr ) { return malloc_size( ptr ); } +#else +inline size_t _msize( void *ptr ) { return malloc_usable_size( ptr ); } +#endif + +inline void *MemAlloc_ReallocAligned( void *ptr, size_t size, size_t align ) +{ + void *ptr_new_aligned = memalign( align, size ); + + if( ptr_new_aligned ) + { + size_t old_size = _msize( ptr ); + size_t copy_size = ( size < old_size ) ? size : old_size; + + memcpy( ptr_new_aligned, ptr, copy_size ); + free( ptr ); + } + + return ptr_new_aligned; +} +#else +#define MemAlloc_GetDebugInfoSize() g_pMemAlloc->GetDebugInfoSize() +#define MemAlloc_SaveDebugInfo( pvDebugInfo ) g_pMemAlloc->SaveDebugInfo( pvDebugInfo ) +#define MemAlloc_RestoreDebugInfo( pvDebugInfo ) g_pMemAlloc->RestoreDebugInfo( pvDebugInfo ) +#define MemAlloc_InitDebugInfo( pvDebugInfo, pchRootFileName, nLine ) g_pMemAlloc->InitDebugInfo( pvDebugInfo, pchRootFileName, nLine ) + #endif // !STEAM && !NO_MALLOC_OVERRIDE //----------------------------------------------------------------------------- @@ -343,11 +516,139 @@ struct MemAllocFileLine_t #define MEM_ALLOC_CREDIT_(tag) ((void)0) #define MEM_ALLOC_CREDIT() MEM_ALLOC_CREDIT_(__FILE__) +#define MEM_ALLOC_CREDIT_FUNCTION() #define MEM_ALLOC_CREDIT_CLASS() #define MEM_ALLOC_CLASSNAME(type) NULL +#define MemAlloc_PushAllocDbgInfo( pszFile, line ) +#define MemAlloc_PopAllocDbgInfo() +#define MemAlloc_RegisterAllocation( pFileName, nLine, nLogicalSize, nActualSize, nTime ) ((void)0) +#define MemAlloc_RegisterDeallocation( pFileName, nLine, nLogicalSize, nActualSize, nTime ) ((void)0) +#define MemAlloc_DumpStats() ((void)0) +#define MemAlloc_CompactHeap() ((void)0) +#define MemAlloc_OutOfMemory() ((void)0) +#define MemAlloc_CompactIncremental() ((void)0) +#define MemAlloc_DumpStatsFileBase( _filename ) ((void)0) +inline bool MemAlloc_CrtCheckMemory() { return true; } +inline void MemAlloc_GlobalMemoryStatus( size_t *pusedMemory, size_t *pfreeMemory ) +{ + *pusedMemory = 0; + *pfreeMemory = 0; +} +#define MemAlloc_MemoryAllocFailed() 0 + +#define MemAlloc_GetDebugInfoSize() 0 +#define MemAlloc_SaveDebugInfo( pvDebugInfo ) ((void)0) +#define MemAlloc_RestoreDebugInfo( pvDebugInfo ) ((void)0) +#define MemAlloc_InitDebugInfo( pvDebugInfo, pchRootFileName, nLine ) ((void)0) + + +#define MEMALLOC_DEFINE_EXTERNAL_TRACKING( tag ) +#define MemAlloc_RegisterExternalAllocation( tag, p, size ) ((void)0) +#define MemAlloc_RegisterExternalDeallocation( tag, p, size ) ((void)0) + #endif // !STEAM && NO_MALLOC_OVERRIDE //----------------------------------------------------------------------------- + + +// linux memory tracking via hooks. +#if defined( POSIX ) && !defined( NO_HOOK_MALLOC ) +PLATFORM_INTERFACE void MemoryLogMessage( char const *s ); // throw a message into the memory log +PLATFORM_INTERFACE void EnableMemoryLogging( bool bOnOff ); +PLATFORM_INTERFACE void DumpMemoryLog( int nThresh ); +PLATFORM_INTERFACE void DumpMemorySummary( void ); +PLATFORM_INTERFACE void SetMemoryMark( void ); +PLATFORM_INTERFACE void DumpChangedMemory( int nThresh ); + +#else +FORCEINLINE void MemoryLogMessage( char const *s ) +{ +} + +FORCEINLINE void EnableMemoryLogging( bool bOnOff ) +{ +} +FORCEINLINE void DumpMemoryLog( int nThresh ) +{ +} +FORCEINLINE void DumpMemorySummary( void ) +{ +} +FORCEINLINE void SetMemoryMark( void ) +{ +} +FORCEINLINE void DumpChangedMemory( int nThresh ) +{ +} + +#endif + +#ifdef POSIX +// ApproximateProcessMemoryUsage returns the approximate memory footprint of this process. +PLATFORM_INTERFACE size_t ApproximateProcessMemoryUsage( void ); +#else +FORCEINLINE size_t ApproximateProcessMemoryUsage( void ) +{ + return 0; +} + +#endif + +struct aligned_tmp_t +{ + // empty base class +}; + +/* +This class used to be required if you wanted an object to be allocated with a specific +alignment. ALIGN16 and ALIGN16_POST are not actually sufficient for this because they +guarantee that the globals, statics, locals, and function parameters are appropriately +aligned they do not affect memory allocation alignment. +However this class is usually not needed because as of 2012 our policy is that our +allocator should take care of this automatically. Any object whose size is a multiple +of 16 will be 16-byte aligned. Existing uses of this class were not changed because +the cost/benefit did not justify it. +*/ +// template here to allow adding alignment at levels of hierarchy that aren't the base +template< int bytesAlignment = 16, class T = aligned_tmp_t > +class CAlignedNewDelete : public T +{ + +public: + /* + Note that this class does not overload operator new[] and delete[] which means that + classes that depend on this for alignment may end up misaligned if an array is + allocated. This problem is now mostly theoretical because this class is mostly + obsolete. + */ + void *operator new( size_t nSize ) + { + return MemAlloc_AllocAligned( nSize, bytesAlignment ); + } + + void* operator new( size_t nSize, int nBlockUse, const char *pFileName, int nLine ) + { + return MemAlloc_AllocAlignedFileLine( nSize, bytesAlignment, pFileName, nLine ); + } + + void operator delete(void *pData) + { + if ( pData ) + { + MemAlloc_FreeAligned( pData ); + } + } + + void operator delete( void* pData, int nBlockUse, const char *pFileName, int nLine ) + { + if ( pData ) + { + MemAlloc_FreeAligned( pData, pFileName, nLine ); + } + } +}; + + #endif /* TIER0_MEMALLOC_H */ diff --git a/public/tier0/memdbgon.h b/public/tier0/memdbgon.h index 9282efb7..ef9a2cfb 100644 --- a/public/tier0/memdbgon.h +++ b/public/tier0/memdbgon.h @@ -11,6 +11,10 @@ // to include this potentially multiple times (since we can deactivate debugging // by including memdbgoff.h) +#if !defined(NO_MALLOC_OVERRIDE) && defined(POSIX) +#define NO_MALLOC_OVERRIDE +#endif + #if !defined(STEAM) && !defined(NO_MALLOC_OVERRIDE) // SPECIAL NOTE #2: This must be the final include in a .cpp or .h file!!! diff --git a/public/tier0/platform.h b/public/tier0/platform.h index 66add833..776f8320 100644 --- a/public/tier0/platform.h +++ b/public/tier0/platform.h @@ -75,27 +75,58 @@ #ifdef _WIN32 #define IsLinux() false + #define IsOSX() false + #define IsPosix() false + #ifndef PLATFORM_WINDOWS + #define PLATFORM_WINDOWS 1 // Windows PC or Xbox 360 + #endif #ifndef _X360 + #define IsWindows() true #define IsPC() true #define IsConsole() false #define IsX360() false #define IsPS3() false #define IS_WINDOWS_PC - #else - #ifndef _CONSOLE - #define _CONSOLE + #define PLATFORM_WINDOWS_PC 1 // Windows PC + #ifdef _WIN64 + #define IsPlatformWindowsPC64() true + #define IsPlatformWindowsPC32() false + #define PLATFORM_WINDOWS_PC64 1 + #else + #define IsPlatformWindowsPC64() false + #define IsPlatformWindowsPC32() true + #define PLATFORM_WINDOWS_PC32 1 #endif + #else + #define PLATFORM_X360 1 + #ifndef _CONSOLE + #define _CONSOLE + #endif + #define IsWindows() false #define IsPC() false #define IsConsole() true #define IsX360() true #define IsPS3() false #endif -#elif defined(_LINUX) || defined(__APPLE__) +#elif defined(POSIX) #define IsPC() true + #define IsWindows() false #define IsConsole() false #define IsX360() false #define IsPS3() false - #define IsLinux() true + #if defined( LINUX ) + #define IsLinux() true + #else + #define IsLinux() false + #endif + + #if defined( OSX ) + #define IsOSX() true + #else + #define IsOSX() false + #endif + + #define IsPosix() true #else #error #endif @@ -252,6 +283,17 @@ typedef void * HINSTANCE; #define MAX_PATH 260 #endif + +#ifdef GNUC +#undef offsetof +//#define offsetof( type, var ) __builtin_offsetof( type, var ) +#define offsetof(s,m) (size_t)&(((s *)0)->m) +#else +#undef offsetof +#define offsetof(s,m) (size_t)&(((s *)0)->m) +#endif + + #define ALIGN_VALUE( val, alignment ) ( ( val + alignment - 1 ) & ~( alignment - 1 ) ) // need macro for constant expression // Used to step into the debugger @@ -283,17 +325,41 @@ typedef void * HINSTANCE; #ifdef _WIN32 #define DECL_ALIGN(x) __declspec(align(x)) -#elif defined(_LINUX) || defined(__APPLE__) +#elif GNUC #define DECL_ALIGN(x) __attribute__((aligned(x))) #else #define DECL_ALIGN(x) /* */ #endif +#ifdef _MSC_VER +// MSVC has the align at the start of the struct +#define ALIGN4 DECL_ALIGN(4) #define ALIGN8 DECL_ALIGN(8) #define ALIGN16 DECL_ALIGN(16) #define ALIGN32 DECL_ALIGN(32) #define ALIGN128 DECL_ALIGN(128) +#define ALIGN4_POST +#define ALIGN8_POST +#define ALIGN16_POST +#define ALIGN32_POST +#define ALIGN128_POST +#elif defined( GNUC ) +// gnuc has the align decoration at the end +#define ALIGN4 +#define ALIGN8 +#define ALIGN16 +#define ALIGN32 +#define ALIGN128 + +#define ALIGN4_POST DECL_ALIGN(4) +#define ALIGN8_POST DECL_ALIGN(8) +#define ALIGN16_POST DECL_ALIGN(16) +#define ALIGN32_POST DECL_ALIGN(32) +#define ALIGN128_POST DECL_ALIGN(128) +#else +#error +#endif // Linux had a few areas where it didn't construct objects in the same order that Windows does. // So when CVProfile::CVProfile() would access g_pMemAlloc, it would crash because the allocator wasn't initalized yet. @@ -824,8 +890,18 @@ struct CPUInformation tchar* m_szProcessorID; // Processor vendor Identification. }; +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunknown-pragmas" +#pragma clang diagnostic ignored "-Wreturn-type-c-linkage" +#endif + PLATFORM_INTERFACE const CPUInformation& GetCPUInformation(); +#ifdef __clang__ +#pragma clang diagnostic pop +#endif + PLATFORM_INTERFACE void GetCurrentDate( int *pDay, int *pMonth, int *pYear ); // ---------------------------------------------------------------------------------- // diff --git a/public/tier1/CommandBuffer.h b/public/tier1/CommandBuffer.h index 0a3c4433..5ae2fa02 100644 --- a/public/tier1/CommandBuffer.h +++ b/public/tier1/CommandBuffer.h @@ -113,7 +113,7 @@ private: bool ParseArgV0( CUtlBuffer &buf, char *pArgv0, int nMaxLen, const char **pArgs ); char m_pArgSBuffer[ ARGS_BUFFER_LENGTH ]; - int m_nLastUsedArgSSize; + //int m_nLastUsedArgSSize; int m_nArgSBufferSize; CUtlFixedLinkedList< Command_t > m_Commands; int m_nCurrentTick; diff --git a/public/tier1/utlblockmemory.h b/public/tier1/utlblockmemory.h index 8d174466..7f08c40b 100644 --- a/public/tier1/utlblockmemory.h +++ b/public/tier1/utlblockmemory.h @@ -336,7 +336,6 @@ void CUtlBlockMemory::Purge( int numElements ) } int nBlockSize = NumElementsInBlock(); - int nBlocksOld = m_nBlocks; int nBlocks = ( numElements + nBlockSize - 1 ) / nBlockSize; // If the number of blocks is the same as the allocated number of blocks, we are done. diff --git a/public/toolframework/itoolentity.h b/public/toolframework/itoolentity.h index 63fce558..ed874882 100644 --- a/public/toolframework/itoolentity.h +++ b/public/toolframework/itoolentity.h @@ -27,6 +27,11 @@ class IToolSystem; class IClientRenderable; class Vector; class QAngle; +class CBaseEntity; +class CBaseAnimating; +class CTakeDamageInfo; +class ITempEntsSystem; +class IEntityFactoryDictionary; //----------------------------------------------------------------------------- @@ -173,19 +178,19 @@ public: virtual bool IsInNoClipMode( IClientEntity *pClientPlayer = NULL ) = 0; // entity searching - virtual void *FirstEntity( void ) = 0; - virtual void *NextEntity( void *pEntity ) = 0; - virtual void *FindEntityByHammerID( int iHammerID ) = 0; + virtual CBaseEntity *FirstEntity( void ) = 0; + virtual CBaseEntity *NextEntity( CBaseEntity *pEntity ) = 0; + virtual CBaseEntity *FindEntityByHammerID( int iHammerID ) = 0; // entity query - virtual bool GetKeyValue( void *pEntity, const char *szField, char *szValue, int iMaxLen ) = 0; - virtual bool SetKeyValue( void *pEntity, const char *szField, const char *szValue ) = 0; - virtual bool SetKeyValue( void *pEntity, const char *szField, float flValue ) = 0; - virtual bool SetKeyValue( void *pEntity, const char *szField, const Vector &vecValue ) = 0; + virtual bool GetKeyValue( CBaseEntity *pEntity, const char *szField, char *szValue, int iMaxLen ) = 0; + virtual bool SetKeyValue( CBaseEntity *pEntity, const char *szField, const char *szValue ) = 0; + virtual bool SetKeyValue( CBaseEntity *pEntity, const char *szField, float flValue ) = 0; + virtual bool SetKeyValue( CBaseEntity *pEntity, const char *szField, const Vector &vecValue ) = 0; // entity spawning - virtual void *CreateEntityByName( const char *szClassName ) = 0; - virtual void DispatchSpawn( void *pEntity ) = 0; + virtual CBaseEntity *CreateEntityByName( const char *szClassName ) = 0; + virtual void DispatchSpawn( CBaseEntity *pEntity ) = 0; // This reloads a portion or all of a particle definition file. // It's up to the server to decide if it cares about this file @@ -193,9 +198,32 @@ public: virtual void ReloadParticleDefintions( const char *pFileName, const void *pBufData, int nLen ) = 0; virtual void AddOriginToPVS( const Vector &org ) = 0; + virtual void MoveEngineViewTo( const Vector &vPos, const QAngle &vAngles ) = 0; + + virtual bool DestroyEntityByHammerId( int iHammerID ) = 0; + virtual CBaseEntity *GetBaseEntityByEntIndex( int iEntIndex ) = 0; + virtual void RemoveEntity( CBaseEntity *pEntity ) = 0; + virtual void RemoveEntityImmediate( CBaseEntity *pEntity ) = 0; + virtual IEntityFactoryDictionary *GetEntityFactoryDictionary( void ) = 0; + + virtual void SetMoveType( CBaseEntity *pEntity, int val ) = 0; + virtual void SetMoveType( CBaseEntity *pEntity, int val, int moveCollide ) = 0; + virtual void ResetSequence( CBaseAnimating *pEntity, int nSequence ) = 0; + virtual void ResetSequenceInfo( CBaseAnimating *pEntity ) = 0; + + virtual void ClearMultiDamage( void ) = 0; + virtual void ApplyMultiDamage( void ) = 0; + virtual void AddMultiDamage( const CTakeDamageInfo &pTakeDamageInfo, CBaseEntity *pEntity ) = 0; + virtual void RadiusDamage( const CTakeDamageInfo &info, const Vector &vecSrc, float flRadius, int iClassIgnore, CBaseEntity *pEntityIgnore ) = 0; + + virtual ITempEntsSystem *GetTempEntsSystem( void ) = 0; }; -#define VSERVERTOOLS_INTERFACE_VERSION "VSERVERTOOLS001" +typedef IServerTools IServerTools001; + +#define VSERVERTOOLS_INTERFACE_VERSION_1 "VSERVERTOOLS001" +#define VSERVERTOOLS_INTERFACE_VERSION "VSERVERTOOLS002" +#define VSERVERTOOLS_INTERFACE_VERSION_INT 2 //----------------------------------------------------------------------------- // Purpose: Client side tool interace (right now just handles IClientRenderables). diff --git a/tier1/KeyValues.cpp b/tier1/KeyValues.cpp index 18b1c220..7217799d 100644 --- a/tier1/KeyValues.cpp +++ b/tier1/KeyValues.cpp @@ -27,6 +27,17 @@ // memdbgon must be the last include file in a .cpp file!!! #include +template +T *KVStringAlloc(size_t nLength) +{ + return reinterpret_cast(MemAlloc_Alloc(sizeof(T) * nLength)); +} + +void KVStringDelete(void* pMem) +{ + MemAlloc_Free(pMem); +} + static const char * s_LastFileLoadingFrom = "unknown"; // just needed for error messages #define KEYVALUES_TOKEN_SIZE 1024 @@ -323,9 +334,9 @@ void KeyValues::RemoveEverything() delete dat; } - delete [] m_sValue; + KVStringDelete(m_sValue); m_sValue = NULL; - delete [] m_wsValue; + KVStringDelete(m_wsValue); m_wsValue = NULL; } @@ -1280,9 +1291,9 @@ void KeyValues::SetColor( const char *keyName, Color value) void KeyValues::SetStringValue( char const *strValue ) { // delete the old value - delete [] m_sValue; + KVStringDelete(m_sValue); // make sure we're not storing the WSTRING - as we're converting over to STRING - delete [] m_wsValue; + KVStringDelete(m_wsValue); m_wsValue = NULL; if (!strValue) @@ -1293,7 +1304,7 @@ void KeyValues::SetStringValue( char const *strValue ) // allocate memory for the new value and copy it in int len = Q_strlen( strValue ); - m_sValue = new char[len + 1]; + m_sValue = KVStringAlloc(len + 1); Q_memcpy( m_sValue, strValue, len+1 ); m_iDataType = TYPE_STRING; @@ -1309,9 +1320,9 @@ void KeyValues::SetString( const char *keyName, const char *value ) if ( dat ) { // delete the old value - delete [] dat->m_sValue; + KVStringDelete(dat->m_sValue); // make sure we're not storing the WSTRING - as we're converting over to STRING - delete [] dat->m_wsValue; + KVStringDelete(dat->m_wsValue); dat->m_wsValue = NULL; if (!value) @@ -1322,7 +1333,7 @@ void KeyValues::SetString( const char *keyName, const char *value ) // allocate memory for the new value and copy it in int len = Q_strlen( value ); - dat->m_sValue = new char[len + 1]; + dat->m_sValue = KVStringAlloc(len + 1); Q_memcpy( dat->m_sValue, value, len+1 ); dat->m_iDataType = TYPE_STRING; @@ -1338,9 +1349,9 @@ void KeyValues::SetWString( const char *keyName, const wchar_t *value ) if ( dat ) { // delete the old value - delete [] dat->m_wsValue; + KVStringDelete(dat->m_wsValue); // make sure we're not storing the STRING - as we're converting over to WSTRING - delete [] dat->m_sValue; + KVStringDelete(dat->m_sValue); dat->m_sValue = NULL; if (!value) @@ -1351,7 +1362,7 @@ void KeyValues::SetWString( const char *keyName, const wchar_t *value ) // allocate memory for the new value and copy it in int len = wcslen( value ); - dat->m_wsValue = new wchar_t[len + 1]; + dat->m_wsValue = KVStringAlloc(len + 1); Q_memcpy( dat->m_wsValue, value, (len+1) * sizeof(wchar_t) ); dat->m_iDataType = TYPE_WSTRING; @@ -1382,12 +1393,12 @@ void KeyValues::SetUint64( const char *keyName, uint64 value ) if ( dat ) { // delete the old value - delete [] dat->m_sValue; + KVStringDelete(dat->m_sValue); // make sure we're not storing the WSTRING - as we're converting over to STRING - delete [] dat->m_wsValue; + KVStringDelete(dat->m_wsValue); dat->m_wsValue = NULL; - dat->m_sValue = new char[sizeof(uint64)]; + dat->m_sValue = KVStringAlloc(sizeof(uint64)); *((uint64 *)dat->m_sValue) = value; dat->m_iDataType = TYPE_UINT64; } @@ -1444,7 +1455,7 @@ void KeyValues::RecursiveCopyKeyValues( KeyValues& src ) if( src.m_sValue ) { int len = Q_strlen(src.m_sValue) + 1; - m_sValue = new char[len]; + m_sValue = KVStringAlloc(len); Q_strncpy( m_sValue, src.m_sValue, len ); } break; @@ -1453,7 +1464,7 @@ void KeyValues::RecursiveCopyKeyValues( KeyValues& src ) m_iValue = src.m_iValue; Q_snprintf( buf,sizeof(buf), "%d", m_iValue ); int len = Q_strlen(buf) + 1; - m_sValue = new char[len]; + m_sValue = KVStringAlloc(len); Q_strncpy( m_sValue, buf, len ); } break; @@ -1462,7 +1473,7 @@ void KeyValues::RecursiveCopyKeyValues( KeyValues& src ) m_flValue = src.m_flValue; Q_snprintf( buf,sizeof(buf), "%f", m_flValue ); int len = Q_strlen(buf) + 1; - m_sValue = new char[len]; + m_sValue = KVStringAlloc(len); Q_strncpy( m_sValue, buf, len ); } break; @@ -1473,7 +1484,7 @@ void KeyValues::RecursiveCopyKeyValues( KeyValues& src ) break; case TYPE_UINT64: { - m_sValue = new char[sizeof(uint64)]; + m_sValue = KVStringAlloc(sizeof(uint64)); Q_memcpy( m_sValue, src.m_sValue, sizeof(uint64) ); } break; @@ -1584,7 +1595,7 @@ KeyValues *KeyValues::MakeCopy( void ) const { int len = Q_strlen( m_sValue ); Assert( !newKeyValue->m_sValue ); - newKeyValue->m_sValue = new char[len + 1]; + newKeyValue->m_sValue = KVStringAlloc(len + 1); Q_memcpy( newKeyValue->m_sValue, m_sValue, len+1 ); } } @@ -1594,7 +1605,7 @@ KeyValues *KeyValues::MakeCopy( void ) const if ( m_wsValue ) { int len = wcslen( m_wsValue ); - newKeyValue->m_wsValue = new wchar_t[len+1]; + newKeyValue->m_wsValue = KVStringAlloc(len + 1); Q_memcpy( newKeyValue->m_wsValue, m_wsValue, (len+1)*sizeof(wchar_t)); } } @@ -1620,7 +1631,7 @@ KeyValues *KeyValues::MakeCopy( void ) const break; case TYPE_UINT64: - newKeyValue->m_sValue = new char[sizeof(uint64)]; + newKeyValue->m_sValue = KVStringAlloc(sizeof(uint64)); Q_memcpy( newKeyValue->m_sValue, m_sValue, sizeof(uint64) ); break; }; @@ -2062,7 +2073,7 @@ void KeyValues::RecursiveLoadFromBuffer( char const *resourceName, CUtlBuffer &b if (dat->m_sValue) { - delete[] dat->m_sValue; + KVStringDelete(dat->m_sValue); dat->m_sValue = NULL; } @@ -2094,7 +2105,7 @@ void KeyValues::RecursiveLoadFromBuffer( char const *resourceName, CUtlBuffer &b digit -= 'A' - ( '9' + 1 ); retVal = ( retVal * 16 ) + ( digit - '0' ); } - dat->m_sValue = new char[sizeof(uint64)]; + dat->m_sValue = KVStringAlloc(sizeof(uint64)); *((uint64 *)dat->m_sValue) = retVal; dat->m_iDataType = TYPE_UINT64; } @@ -2116,7 +2127,7 @@ void KeyValues::RecursiveLoadFromBuffer( char const *resourceName, CUtlBuffer &b if (dat->m_iDataType == TYPE_STRING) { // copy in the string information - dat->m_sValue = new char[len+1]; + dat->m_sValue = KVStringAlloc(len + 1); Q_memcpy( dat->m_sValue, value, len+1 ); } @@ -2274,7 +2285,7 @@ bool KeyValues::ReadAsBinary( CUtlBuffer &buffer ) token[KEYVALUES_TOKEN_SIZE-1] = 0; int len = Q_strlen( token ); - dat->m_sValue = new char[len + 1]; + dat->m_sValue = KVStringAlloc(len + 1); Q_memcpy( dat->m_sValue, token, len+1 ); break; @@ -2293,7 +2304,7 @@ bool KeyValues::ReadAsBinary( CUtlBuffer &buffer ) case TYPE_UINT64: { - dat->m_sValue = new char[sizeof(uint64)]; + dat->m_sValue = KVStringAlloc(sizeof(uint64)); *((double *)dat->m_sValue) = buffer.GetDouble(); } diff --git a/tier1/bitbuf.cpp b/tier1/bitbuf.cpp index f49f5ea0..d7089fe0 100644 --- a/tier1/bitbuf.cpp +++ b/tier1/bitbuf.cpp @@ -867,7 +867,6 @@ int old_bf_read::ReadSBitLong( int numbits ) } const byte g_BitMask[8] = {0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80}; -const byte g_TrailingMask[8] = {0xff, 0xfe, 0xfc, 0xf8, 0xf0, 0xe0, 0xc0, 0x80}; inline int old_bf_read::CountRunOfZeros() { diff --git a/tier1/checksum_md5.cpp b/tier1/checksum_md5.cpp index d41f1de2..0c4aeefa 100644 --- a/tier1/checksum_md5.cpp +++ b/tier1/checksum_md5.cpp @@ -232,7 +232,7 @@ void MD5Final(unsigned char digest[MD5_DIGEST_LENGTH], MD5Context_t *ctx) MD5Transform(ctx->buf, (unsigned int *) ctx->in); //byteReverse((unsigned char *) ctx->buf, 4); memcpy(digest, ctx->buf, MD5_DIGEST_LENGTH); - memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */ + memset(ctx, 0, sizeof(MD5Context_t)); /* In case it's sensitive */ } //----------------------------------------------------------------------------- diff --git a/tier1/datamanager.cpp b/tier1/datamanager.cpp index 24935280..fd3ddf1a 100644 --- a/tier1/datamanager.cpp +++ b/tier1/datamanager.cpp @@ -122,8 +122,6 @@ unsigned int CDataManagerBase::FlushAll() unsigned int CDataManagerBase::Purge( unsigned int nBytesToPurge ) { unsigned int nTargetSize = MemUsed_Inline() - nBytesToPurge; - if ( nTargetSize < 0 ) - nTargetSize = 0; unsigned int nImpliedCapacity = MemTotal_Inline() - nTargetSize; return EnsureCapacity( nImpliedCapacity ); } diff --git a/tier1/generichash.cpp b/tier1/generichash.cpp index af784fc4..f251f1c4 100644 --- a/tier1/generichash.cpp +++ b/tier1/generichash.cpp @@ -142,7 +142,7 @@ unsigned FASTCALL HashInt( const int n ) odd = g_nRandomValues[((n >> 8) & 0xff)]; even = g_nRandomValues[odd ^ (n >> 24)]; - odd = g_nRandomValues[even ^ (n >> 16) & 0xff]; + odd = g_nRandomValues[even ^ ((n >> 16) & 0xff)]; even = g_nRandomValues[odd ^ ((n >> 8) & 0xff)]; odd = g_nRandomValues[even ^ (n & 0xff)]; @@ -163,7 +163,7 @@ unsigned FASTCALL Hash4( const void *pKey ) odd = g_nRandomValues[((n >> 8) & 0xff)]; even = g_nRandomValues[odd ^ (n >> 24)]; - odd = g_nRandomValues[even ^ (n >> 16) & 0xff]; + odd = g_nRandomValues[even ^ ((n >> 16) & 0xff)]; even = g_nRandomValues[odd ^ ((n >> 8) & 0xff)]; odd = g_nRandomValues[even ^ (n & 0xff)]; @@ -185,7 +185,7 @@ unsigned FASTCALL Hash8( const void *pKey ) odd = g_nRandomValues[((n >> 8) & 0xff)]; even = g_nRandomValues[odd ^ (n >> 24)]; - odd = g_nRandomValues[even ^ (n >> 16) & 0xff]; + odd = g_nRandomValues[even ^ ((n >> 16) & 0xff)]; even = g_nRandomValues[odd ^ ((n >> 8) & 0xff)]; odd = g_nRandomValues[even ^ (n & 0xff)]; @@ -213,7 +213,7 @@ unsigned FASTCALL Hash12( const void *pKey ) odd = g_nRandomValues[((n >> 8) & 0xff)]; even = g_nRandomValues[odd ^ (n >> 24)]; - odd = g_nRandomValues[even ^ (n >> 16) & 0xff]; + odd = g_nRandomValues[even ^ ((n >> 16) & 0xff)]; even = g_nRandomValues[odd ^ ((n >> 8) & 0xff)]; odd = g_nRandomValues[even ^ (n & 0xff)]; @@ -247,7 +247,7 @@ unsigned FASTCALL Hash16( const void *pKey ) odd = g_nRandomValues[((n >> 8) & 0xff)]; even = g_nRandomValues[odd ^ (n >> 24)]; - odd = g_nRandomValues[even ^ (n >> 16) & 0xff]; + odd = g_nRandomValues[even ^ ((n >> 16) & 0xff)]; even = g_nRandomValues[odd ^ ((n >> 8) & 0xff)]; odd = g_nRandomValues[even ^ (n & 0xff)]; diff --git a/tier1/strtools.cpp b/tier1/strtools.cpp index 3188f209..76b6da44 100644 --- a/tier1/strtools.cpp +++ b/tier1/strtools.cpp @@ -226,7 +226,7 @@ char *V_strnlwr(char *s, size_t count) if ( !s ) return s; - while ( --count >= 0 ) + while ( count-- ) { if ( !*s ) break; diff --git a/tier1/tier1-2005.sln b/tier1/tier1-2005.sln new file mode 100644 index 00000000..014b2bbc --- /dev/null +++ b/tier1/tier1-2005.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.25420.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tier1", "tier1-2005.vcxproj", "{E1DA8DB8-FB4C-4B14-91A6-98BCED6B9720}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x86 = Debug|x86 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E1DA8DB8-FB4C-4B14-91A6-98BCED6B9720}.Debug|x86.ActiveCfg = Debug|Win32 + {E1DA8DB8-FB4C-4B14-91A6-98BCED6B9720}.Debug|x86.Build.0 = Debug|Win32 + {E1DA8DB8-FB4C-4B14-91A6-98BCED6B9720}.Release|x86.ActiveCfg = Release|Win32 + {E1DA8DB8-FB4C-4B14-91A6-98BCED6B9720}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/tier1/tier1-2005.vcproj b/tier1/tier1-2005.vcproj deleted file mode 100644 index 34cff4df..00000000 --- a/tier1/tier1-2005.vcproj +++ /dev/null @@ -1,568 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/tier1/tier1-2005.vcxproj b/tier1/tier1-2005.vcxproj new file mode 100644 index 00000000..fac3f45d --- /dev/null +++ b/tier1/tier1-2005.vcxproj @@ -0,0 +1,251 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + tier1 + {E1DA8DB8-FB4C-4B14-91A6-98BCED6B9720} + tier1 + 8.1 + + + + StaticLibrary + v120_xp + MultiByte + + + StaticLibrary + v140 + MultiByte + + + + + + + + + + + + + <_ProjectFileVersion>14.0.25420.1 + + + .\Debug\ + .\Debug\ + true + true + true + + + .\Release\ + .\Release\ + true + true + true + + + + + + + Disabled + ..\public;..\public\tier0;..\public\tier1;%(AdditionalIncludeDirectories) + WIN32;_WIN32;_DEBUG;DEBUG;_LIB;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;TIER1_STATIC_LIB;%(PreprocessorDefinitions) + true + true + + EnableFastChecks + MultiThreadedDebug + false + Fast + true + true + true + false + + false + + $(IntDir) + $(IntDir) + $(IntDir) + false + + $(IntDir) + Level4 + EditAndContinue + CompileAsCpp + Prompt + + + + + + false + Rpcrt4.lib;%(AdditionalDependencies) + ..\lib\public\tier1.lib + true + + + true + + + true + $(OutDir)tier1.bsc + + + + + + + + MaxSpeed + AnySuitable + true + Speed + ..\public;..\public\tier0;..\public\tier1;%(AdditionalIncludeDirectories) + WIN32;_WIN32;NDEBUG;_LIB;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;TIER1_STATIC_LIB;%(PreprocessorDefinitions) + true + + MultiThreaded + false + true + Fast + true + true + true + false + + false + + $(IntDir) + $(IntDir) + $(IntDir) + false + + $(IntDir) + Level4 + OldStyle + CompileAsCpp + Prompt + + + + + + false + Rpcrt4.lib;%(AdditionalDependencies) + ..\lib\public\tier1.lib + true + + + true + + + true + $(OutDir)tier1.bsc + + + + + + + + + + + + + + + + + + + + + Sync + Sync + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tier1/tier1-2005.vcxproj.filters b/tier1/tier1-2005.vcxproj.filters new file mode 100644 index 00000000..912b59f8 --- /dev/null +++ b/tier1/tier1-2005.vcxproj.filters @@ -0,0 +1,263 @@ + + + + + {b2c0d006-1973-4c49-943e-d62b5b01e5c5} + cpp;c;cxx;rc;def;r;odl;idl;hpj;bat + + + {5fb26705-abb8-4153-bf1f-88ef637c9b51} + h;hpp;hxx;hm;inl + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + \ No newline at end of file