Port x64 fixes from Insurgency branch

This commit is contained in:
Nicholas Hastings 2025-11-09 12:13:45 -05:00
parent 4ca98539d2
commit ed67695b02
26 changed files with 61 additions and 49 deletions

View File

@ -329,7 +329,7 @@ enum XUSER_SIGNIN_STATE
#if (defined(POSIX)) #if (defined(POSIX))
typedef size_t ULONG_PTR; typedef size_t ULONG_PTR;
#else #elif !(defined(WIN64))
typedef _W64 unsigned long ULONG_PTR; typedef _W64 unsigned long ULONG_PTR;
#endif #endif
typedef ULONG_PTR DWORD_PTR, *PDWORD_PTR; typedef ULONG_PTR DWORD_PTR, *PDWORD_PTR;

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
lib/public/win64/tier0.lib Normal file

Binary file not shown.

BIN
lib/public/win64/tier1.lib Normal file

Binary file not shown.

Binary file not shown.

View File

@ -57,7 +57,7 @@ void ColorQuantize(uint8 const *Image,
{ {
struct QuantizedValue *v=FindQNode(q,p); struct QuantizedValue *v=FindQNode(q,p);
if (v) if (v)
for(int c=0;c<3;c++) for(c=0;c<3;c++)
out_palette[p*3+c]=v->Mean[c]; out_palette[p*3+c]=v->Mean[c];
} }
memset(Error,0,sizeof(Error)); memset(Error,0,sizeof(Error));

View File

@ -3236,6 +3236,7 @@ void MathLib_Init( float gamma, float texGamma, float brightness, int overbright
{ {
s_bSSEEnabled = true; s_bSSEEnabled = true;
#ifndef _WIN64
// Select the SSE specific routines if available // Select the SSE specific routines if available
pfVectorNormalizeFast = _SSE_VectorNormalizeFast; pfVectorNormalizeFast = _SSE_VectorNormalizeFast;
pfInvRSquared = _SSE_InvRSquared; pfInvRSquared = _SSE_InvRSquared;
@ -3245,6 +3246,7 @@ void MathLib_Init( float gamma, float texGamma, float brightness, int overbright
#ifdef _WIN32 #ifdef _WIN32
pfFastSinCos = _SSE_SinCos; pfFastSinCos = _SSE_SinCos;
pfFastCos = _SSE_cos; pfFastCos = _SSE_cos;
#endif
#endif #endif
} }
else else
@ -3255,7 +3257,7 @@ void MathLib_Init( float gamma, float texGamma, float brightness, int overbright
if ( bAllowSSE2 && pi.m_bSSE2 ) if ( bAllowSSE2 && pi.m_bSSE2 )
{ {
s_bSSE2Enabled = true; s_bSSE2Enabled = true;
#ifdef _WIN32 #if defined(_WIN32) && !defined(_WIN64)
pfFastSinCos = _SSE2_SinCos; pfFastSinCos = _SSE2_SinCos;
pfFastCos = _SSE2_cos; pfFastCos = _SSE2_cos;
#endif #endif

View File

@ -198,8 +198,8 @@ static void UpdateStats(struct QuantizedValue *v)
N+=s->Count; N+=s->Count;
for(j=0;j<current_ndims;j++) for(j=0;j<current_ndims;j++)
{ {
uint8 v=s->Value[j]; uint8 v2=s->Value[j];
Means[j]+=v*s->Count; Means[j]+=v2*s->Count;
} }
} }
for(j=0;j<current_ndims;j++) for(j=0;j<current_ndims;j++)
@ -316,7 +316,7 @@ static void SubdivideNode(struct QuantizedValue *n, int whichdim)
// extrema instead. LocalMean[i][0] will be the point with the lowest // extrema instead. LocalMean[i][0] will be the point with the lowest
// value on the dimension and LocalMean[i][1] the one with the lowest // value on the dimension and LocalMean[i][1] the one with the lowest
// value. // value.
for(int i=0;i<current_ndims;i++) for(i=0;i<current_ndims;i++)
{ {
LocalMean[i][0]=minS->Value[i]; LocalMean[i][0]=minS->Value[i];
LocalMean[i][1]=maxS->Value[i]; LocalMean[i][1]=maxS->Value[i];

View File

@ -16,6 +16,9 @@
// memdbgon must be the last include file in a .cpp file!!! // memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h" #include "tier0/memdbgon.h"
#ifndef COMPILER_MSVC64
// Implement for 64-bit Windows if needed.
static const uint32 _sincos_masks[] = { (uint32)0x0, (uint32)~0x0 }; static const uint32 _sincos_masks[] = { (uint32)0x0, (uint32)~0x0 };
static const uint32 _sincos_inv_masks[] = { (uint32)~0x0, (uint32)0x0 }; static const uint32 _sincos_inv_masks[] = { (uint32)~0x0, (uint32)0x0 };
@ -843,3 +846,4 @@ vec_t DotProduct (const vec_t *a, const vec_t *c)
} }
*/ */
#endif // COMPILER_MSVC64

View File

@ -25,7 +25,6 @@ enum NormalDecodeMode_t
// Forward declaration // Forward declaration
#ifdef _WIN32 #ifdef _WIN32
typedef enum _D3DFORMAT D3DFORMAT; typedef enum _D3DFORMAT D3DFORMAT;
typedef enum DXGI_FORMAT;
#endif #endif
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View File

@ -43,7 +43,7 @@ typedef unsigned short MDLHandle_t;
inline MDLHandle_t VoidPtrToMDLHandle( void *ptr ) inline MDLHandle_t VoidPtrToMDLHandle( void *ptr )
{ {
return (MDLHandle_t)(int)ptr; return (MDLHandle_t)(uintp)ptr;
} }
enum enum

View File

@ -478,23 +478,23 @@ FORCEINLINE fltx4 ArcTan2SIMD( const fltx4 &a, const fltx4 &b )
return result; return result;
} }
FORCEINLINE fltx4 MaxSIMD( const fltx4 & a, const fltx4 & b ) // max(a,b) FORCEINLINE fltx4 MaxSIMD( const fltx4 & a, const fltx4 & b ) // V_max(a,b)
{ {
fltx4 retVal; fltx4 retVal;
SubFloat( retVal, 0 ) = max( SubFloat( a, 0 ), SubFloat( b, 0 ) ); SubFloat( retVal, 0 ) = V_max( SubFloat( a, 0 ), SubFloat( b, 0 ) );
SubFloat( retVal, 1 ) = max( SubFloat( a, 1 ), SubFloat( b, 1 ) ); SubFloat( retVal, 1 ) = V_max( SubFloat( a, 1 ), SubFloat( b, 1 ) );
SubFloat( retVal, 2 ) = max( SubFloat( a, 2 ), SubFloat( b, 2 ) ); SubFloat( retVal, 2 ) = V_max( SubFloat( a, 2 ), SubFloat( b, 2 ) );
SubFloat( retVal, 3 ) = max( SubFloat( a, 3 ), SubFloat( b, 3 ) ); SubFloat( retVal, 3 ) = V_max( SubFloat( a, 3 ), SubFloat( b, 3 ) );
return retVal; return retVal;
} }
FORCEINLINE fltx4 MinSIMD( const fltx4 & a, const fltx4 & b ) // min(a,b) FORCEINLINE fltx4 MinSIMD( const fltx4 & a, const fltx4 & b ) // V_min(a,b)
{ {
fltx4 retVal; fltx4 retVal;
SubFloat( retVal, 0 ) = min( SubFloat( a, 0 ), SubFloat( b, 0 ) ); SubFloat( retVal, 0 ) = V_min( SubFloat( a, 0 ), SubFloat( b, 0 ) );
SubFloat( retVal, 1 ) = min( SubFloat( a, 1 ), SubFloat( b, 1 ) ); SubFloat( retVal, 1 ) = V_min( SubFloat( a, 1 ), SubFloat( b, 1 ) );
SubFloat( retVal, 2 ) = min( SubFloat( a, 2 ), SubFloat( b, 2 ) ); SubFloat( retVal, 2 ) = V_min( SubFloat( a, 2 ), SubFloat( b, 2 ) );
SubFloat( retVal, 3 ) = min( SubFloat( a, 3 ), SubFloat( b, 3 ) ); SubFloat( retVal, 3 ) = V_min( SubFloat( a, 3 ), SubFloat( b, 3 ) );
return retVal; return retVal;
} }
@ -945,7 +945,7 @@ FORCEINLINE void TransposeSIMD( fltx4 & x, fltx4 & y, fltx4 & z, fltx4 & w )
// and replicate it to the whole return value. // and replicate it to the whole return value.
FORCEINLINE fltx4 FindLowestSIMD3( const fltx4 & a ) FORCEINLINE fltx4 FindLowestSIMD3( const fltx4 & a )
{ {
float lowest = min( min( SubFloat(a, 0), SubFloat(a, 1) ), SubFloat(a, 2)); float lowest = V_min( V_min( SubFloat(a, 0), SubFloat(a, 1) ), SubFloat(a, 2));
return ReplicateX4(lowest); return ReplicateX4(lowest);
} }
@ -953,7 +953,7 @@ FORCEINLINE fltx4 FindLowestSIMD3( const fltx4 & a )
// and replicate it to the whole return value. // and replicate it to the whole return value.
FORCEINLINE fltx4 FindHighestSIMD3( const fltx4 & a ) FORCEINLINE fltx4 FindHighestSIMD3( const fltx4 & a )
{ {
float highest = max( max( SubFloat(a, 0), SubFloat(a, 1) ), SubFloat(a, 2)); float highest = V_max( V_max( SubFloat(a, 0), SubFloat(a, 1) ), SubFloat(a, 2));
return ReplicateX4(highest); return ReplicateX4(highest);
} }
@ -1167,12 +1167,12 @@ FORCEINLINE fltx4 ArcTan2SIMD( const fltx4 &a, const fltx4 &b )
// DivSIMD defined further down, since it uses ReciprocalSIMD // DivSIMD defined further down, since it uses ReciprocalSIMD
FORCEINLINE fltx4 MaxSIMD( const fltx4 & a, const fltx4 & b ) // max(a,b) FORCEINLINE fltx4 MaxSIMD( const fltx4 & a, const fltx4 & b ) // V_max(a,b)
{ {
return __vmaxfp( a, b ); return __vmaxfp( a, b );
} }
FORCEINLINE fltx4 MinSIMD( const fltx4 & a, const fltx4 & b ) // min(a,b) FORCEINLINE fltx4 MinSIMD( const fltx4 & a, const fltx4 & b ) // V_min(a,b)
{ {
return __vminfp( a, b ); return __vminfp( a, b );
} }
@ -1938,11 +1938,11 @@ FORCEINLINE fltx4 FindLowestSIMD3( const fltx4 & a )
compareOne = __vrlimi( compareOne, a, 8 | 4 , 1 ); compareOne = __vrlimi( compareOne, a, 8 | 4 , 1 );
// compareOne is [y,z,G,G] // compareOne is [y,z,G,G]
fltx4 retval = MinSIMD( a, compareOne ); fltx4 retval = MinSIMD( a, compareOne );
// retVal is [min(x,y), min(y,z), G, G] // retVal is [min(x,y), V_min(y,z), G, G]
compareOne = __vrlimi( compareOne, a, 8 , 2); compareOne = __vrlimi( compareOne, a, 8 , 2);
// compareOne is [z, G, G, G] // compareOne is [z, G, G, G]
retval = MinSIMD( retval, compareOne ); retval = MinSIMD( retval, compareOne );
// retVal = [ min(min(x,y),z), G, G, G ] // retVal = [ V_min(min(x,y),z), G, G, G ]
// splat the x component out to the whole vector and return // splat the x component out to the whole vector and return
return SplatXSIMD( retval ); return SplatXSIMD( retval );
@ -1962,11 +1962,11 @@ FORCEINLINE fltx4 FindHighestSIMD3( const fltx4 & a )
compareOne = __vrlimi( compareOne, a, 8 | 4 , 1 ); compareOne = __vrlimi( compareOne, a, 8 | 4 , 1 );
// compareOne is [y,z,G,G] // compareOne is [y,z,G,G]
fltx4 retval = MaxSIMD( a, compareOne ); fltx4 retval = MaxSIMD( a, compareOne );
// retVal is [max(x,y), max(y,z), G, G] // retVal is [max(x,y), V_max(y,z), G, G]
compareOne = __vrlimi( compareOne, a, 8 , 2); compareOne = __vrlimi( compareOne, a, 8 , 2);
// compareOne is [z, G, G, G] // compareOne is [z, G, G, G]
retval = MaxSIMD( retval, compareOne ); retval = MaxSIMD( retval, compareOne );
// retVal = [ max(max(x,y),z), G, G, G ] // retVal = [ V_max(max(x,y),z), G, G, G ]
// splat the x component out to the whole vector and return // splat the x component out to the whole vector and return
return SplatXSIMD( retval ); return SplatXSIMD( retval );
@ -2596,12 +2596,12 @@ FORCEINLINE fltx4 CmpInBoundsSIMD( const fltx4 & a, const fltx4 & b ) // (a <=
return AndSIMD( CmpLeSIMD(a,b), CmpGeSIMD(a, NegSIMD(b)) ); return AndSIMD( CmpLeSIMD(a,b), CmpGeSIMD(a, NegSIMD(b)) );
} }
FORCEINLINE fltx4 MinSIMD( const fltx4 & a, const fltx4 & b ) // min(a,b) FORCEINLINE fltx4 MinSIMD( const fltx4 & a, const fltx4 & b ) // V_min(a,b)
{ {
return _mm_min_ps( a, b ); return _mm_min_ps( a, b );
} }
FORCEINLINE fltx4 MaxSIMD( const fltx4 & a, const fltx4 & b ) // max(a,b) FORCEINLINE fltx4 MaxSIMD( const fltx4 & a, const fltx4 & b ) // V_max(a,b)
{ {
return _mm_max_ps( a, b ); return _mm_max_ps( a, b );
} }
@ -2756,7 +2756,7 @@ FORCEINLINE fltx4 FindLowestSIMD3( const fltx4 &a )
compareOne = RotateLeft2( a ); compareOne = RotateLeft2( a );
// compareOne is [z, G, x, y] // compareOne is [z, G, x, y]
retval = MinSIMD( retval, compareOne ); retval = MinSIMD( retval, compareOne );
// retVal = [ min(min(x,y),z)..] // retVal = [ V_min(min(x,y),z)..]
// splat the x component out to the whole vector and return // splat the x component out to the whole vector and return
return SplatXSIMD( retval ); return SplatXSIMD( retval );
@ -2773,7 +2773,7 @@ FORCEINLINE fltx4 FindHighestSIMD3( const fltx4 &a )
compareOne = RotateLeft2( a ); compareOne = RotateLeft2( a );
// compareOne is [z, G, x, y] // compareOne is [z, G, x, y]
retval = MaxSIMD( retval, compareOne ); retval = MaxSIMD( retval, compareOne );
// retVal = [ max(max(x,y),z)..] // retVal = [ V_max(max(x,y),z)..]
// splat the x component out to the whole vector and return // splat the x component out to the whole vector and return
return SplatXSIMD( retval ); return SplatXSIMD( retval );
@ -2931,6 +2931,12 @@ FORCEINLINE i32x4 IntShiftLeftWordSIMD(const i32x4 &vSrcA, const i32x4 &vSrcB)
// like this. // like this.
FORCEINLINE void ConvertStoreAsIntsSIMD(intx4 * RESTRICT pDest, const fltx4 &vSrc) FORCEINLINE void ConvertStoreAsIntsSIMD(intx4 * RESTRICT pDest, const fltx4 &vSrc)
{ {
#ifdef COMPILER_MSVC64
(*pDest)[0] = SubFloat(vSrc, 0);
(*pDest)[1] = SubFloat(vSrc, 1);
(*pDest)[2] = SubFloat(vSrc, 2);
(*pDest)[3] = SubFloat(vSrc, 3);
#else
__m64 bottom = _mm_cvttps_pi32( vSrc ); __m64 bottom = _mm_cvttps_pi32( vSrc );
__m64 top = _mm_cvttps_pi32( _mm_movehl_ps(vSrc,vSrc) ); __m64 top = _mm_cvttps_pi32( _mm_movehl_ps(vSrc,vSrc) );
@ -2938,6 +2944,7 @@ FORCEINLINE void ConvertStoreAsIntsSIMD(intx4 * RESTRICT pDest, const fltx4 &vSr
*reinterpret_cast<__m64 *>(&(*pDest)[2]) = top; *reinterpret_cast<__m64 *>(&(*pDest)[2]) = top;
_mm_empty(); _mm_empty();
#endif
} }

View File

@ -9,11 +9,11 @@
#ifndef MINMAX_H #ifndef MINMAX_H
#define MINMAX_H #define MINMAX_H
#ifndef min #ifndef V_min
#define min(a,b) (((a) < (b)) ? (a) : (b)) #define V_min(a,b) (((a) < (b)) ? (a) : (b))
#endif #endif
#ifndef max #ifndef V_max
#define max(a,b) (((a) > (b)) ? (a) : (b)) #define V_max(a,b) (((a) > (b)) ? (a) : (b))
#endif #endif
#endif // MINMAX_H #endif // MINMAX_H

View File

@ -123,12 +123,12 @@ inline CTimingInfo< T > CalcSmoothAverage_Struct( const T &value, int nTimes, co
{ {
if ( i != newValueIndex ) if ( i != newValueIndex )
{ {
info.m_HighAverage = max( pInfo->m_Values[i].m_Average, info.m_HighAverage ); info.m_HighAverage = V_max( pInfo->m_Values[i].m_Average, info.m_HighAverage );
info.m_LowAverage = min( pInfo->m_Values[i].m_Average, info.m_LowAverage ); info.m_LowAverage = V_min( pInfo->m_Values[i].m_Average, info.m_LowAverage );
} }
info.m_HighValue = max( pInfo->m_Values[i].m_Value, info.m_HighValue ); info.m_HighValue = V_max( pInfo->m_Values[i].m_Value, info.m_HighValue );
info.m_LowValue = min( pInfo->m_Values[i].m_Value, info.m_LowValue ); info.m_LowValue = V_min( pInfo->m_Values[i].m_Value, info.m_LowValue );
info.m_AverageValue += pInfo->m_Values[i].m_Value; info.m_AverageValue += pInfo->m_Values[i].m_Value;
} }

View File

@ -22,7 +22,7 @@ typedef unsigned char uint8;
#define POSIX 1 #define POSIX 1
#endif #endif
#if defined(__x86_64__) || defined(_WIN64) #if (defined(__x86_64__) || defined(_WIN64)) && !defined(X64BITS)
#define X64BITS #define X64BITS
#endif #endif

View File

@ -1123,7 +1123,7 @@ FORCEINLINE void CBitRead::GrabNextDWord( bool bOverFlowImmediately )
} }
else else
{ {
Assert( reinterpret_cast<int>(m_pDataIn) + 3 < reinterpret_cast<int>(m_pBufferEnd)); Assert( reinterpret_cast<uintp>(m_pDataIn) + 3 < reinterpret_cast<uintp>(m_pBufferEnd));
m_nInBufWord = LittleDWord( *( m_pDataIn++ ) ); m_nInBufWord = LittleDWord( *( m_pDataIn++ ) );
} }
} }

View File

@ -137,7 +137,7 @@ protected:
const int MAX_GROW = 128; const int MAX_GROW = 128;
if ( m_nGrowSize * sizeof(T) > MAX_GROW ) if ( m_nGrowSize * sizeof(T) > MAX_GROW )
{ {
m_nGrowSize = max( 1, MAX_GROW / sizeof(T) ); m_nGrowSize = V_max( 1, MAX_GROW / sizeof(T) );
} }
} }
#endif #endif

View File

@ -2228,7 +2228,7 @@ bool KeyValues::WriteAsBinary( CUtlBuffer &buffer )
} }
case TYPE_PTR: case TYPE_PTR:
{ {
buffer.PutUnsignedInt( (int)dat->m_pValue ); buffer.PutPtr( dat->m_pValue );
} }
default: default:
@ -2323,7 +2323,7 @@ bool KeyValues::ReadAsBinary( CUtlBuffer &buffer )
} }
case TYPE_PTR: case TYPE_PTR:
{ {
dat->m_pValue = (void*)buffer.GetUnsignedInt(); dat->m_pValue = buffer.GetPtr();
} }
default: default:

View File

@ -331,7 +331,7 @@ bool bf_write::WriteBits(const void *pInData, int nBits)
} }
// Align output to dword boundary // Align output to dword boundary
while (((unsigned long)pOut & 3) != 0 && nBitsLeft >= 8) while (((uintp)pOut & 3) != 0 && nBitsLeft >= 8)
{ {
WriteUBitLong( *pOut, 8, false ); WriteUBitLong( *pOut, 8, false );
@ -808,7 +808,7 @@ void old_bf_read::ReadBits(void *pOutData, int nBits)
// align output to dword boundary // align output to dword boundary
while( ((unsigned long)pOut & 3) != 0 && nBitsLeft >= 8 ) while( ((uintp)pOut & 3) != 0 && nBitsLeft >= 8 )
{ {
*pOut = (unsigned char)ReadUBitLong(8); *pOut = (unsigned char)ReadUBitLong(8);
++pOut; ++pOut;

View File

@ -147,7 +147,7 @@ JustAfew:
// The low-order two bits of pb and nBuffer in total control the // The low-order two bits of pb and nBuffer in total control the
// upfront work. // upfront work.
// //
nFront = ((unsigned int)pb) & 3; nFront = ((uintp)pb) & 3;
nBuffer -= nFront; nBuffer -= nFront;
switch (nFront) switch (nFront)
{ {

View File

@ -154,7 +154,7 @@ static HMODULE InternalLoadLibrary( const char *pName )
return LoadLibraryEx( pName, NULL, LOAD_WITH_ALTERED_SEARCH_PATH ); return LoadLibraryEx( pName, NULL, LOAD_WITH_ALTERED_SEARCH_PATH );
#endif #endif
} }
unsigned ThreadedLoadLibraryFunc( void *pParam ) uintp ThreadedLoadLibraryFunc( void *pParam )
{ {
ThreadedLoadLibaryContext_t *pContext = (ThreadedLoadLibaryContext_t*)pParam; ThreadedLoadLibaryContext_t *pContext = (ThreadedLoadLibaryContext_t*)pParam;
pContext->m_hLibrary = InternalLoadLibrary(pContext->m_pLibraryName); pContext->m_hLibrary = InternalLoadLibrary(pContext->m_pLibraryName);

View File

@ -483,7 +483,7 @@ void CBitRead::ReadBits(void *pOutData, int nBits)
// align output to dword boundary // align output to dword boundary
while( ((unsigned long)pOut & 3) != 0 && nBitsLeft >= 8 ) while( ((uintp)pOut & 3) != 0 && nBitsLeft >= 8 )
{ {
*pOut = (unsigned char)ReadUBitLong(8); *pOut = (unsigned char)ReadUBitLong(8);
++pOut; ++pOut;

View File

@ -10,7 +10,7 @@
#include "processor_detect_linux.cpp" #include "processor_detect_linux.cpp"
#elif defined( _X360 ) #elif defined( _X360 ) || defined( WIN64 )
bool CheckMMXTechnology(void) { return false; } bool CheckMMXTechnology(void) { return false; }
bool CheckSSETechnology(void) { return false; } bool CheckSSETechnology(void) { return false; }