Browse Source

amd64: fix mempool, utlbuffer align

pull/77/head
nillerusr 2 years ago
parent
commit
9a1ab79372
  1. 2
      materialsystem/stdshaders/commandbuilder.h
  2. 8
      public/dt_send.cpp
  3. 4
      public/tier1/mempool.h
  4. 7
      public/tier1/utlbuffer.h
  5. 7
      tier1/mempool.cpp
  6. 21
      togl/linuxwin/dx9asmtogl2.cpp

2
materialsystem/stdshaders/commandbuilder.h

@ -49,7 +49,7 @@ public: @@ -49,7 +49,7 @@ public:
template<class T> FORCEINLINE void Put( T const &nValue )
{
EnsureCapacity( sizeof( T ) );
*( reinterpret_cast<T *>( m_pDataOut ) ) = nValue;
memcpy( m_pDataOut, &nValue, sizeof(T) );
m_pDataOut += sizeof( nValue );
#ifdef DBGFLAG_ASSERT
m_nNumBytesRemaining -= sizeof( nValue );

8
public/dt_send.cpp

@ -317,18 +317,18 @@ void* SendProxy_SendLocalDataTable( const SendProp *pProp, const void *pStruct, @@ -317,18 +317,18 @@ void* SendProxy_SendLocalDataTable( const SendProp *pProp, const void *pStruct,
// ---------------------------------------------------------------------- //
float AssignRangeMultiplier( int nBits, double range )
{
unsigned long iHighValue;
uint32 iHighValue;
if ( nBits == 32 )
iHighValue = 0xFFFFFFFE;
else
iHighValue = ((1 << (unsigned long)nBits) - 1);
iHighValue = ((1 << (uint32)nBits) - 1);
float fHighLowMul = iHighValue / range;
if ( CloseEnough( range, 0 ) )
fHighLowMul = iHighValue;
// If the precision is messing us up, then adjust it so it won't.
if ( (unsigned long)(fHighLowMul * range) > iHighValue ||
if ( (uint32)(fHighLowMul * range) > iHighValue ||
(fHighLowMul * range) > (double)iHighValue )
{
// Squeeze it down smaller and smaller until it's going to produce an integer
@ -338,7 +338,7 @@ float AssignRangeMultiplier( int nBits, double range ) @@ -338,7 +338,7 @@ float AssignRangeMultiplier( int nBits, double range )
for ( i=0; i < ARRAYSIZE( multipliers ); i++ )
{
fHighLowMul = (float)( iHighValue / range ) * multipliers[i];
if ( (unsigned long)(fHighLowMul * range) > iHighValue ||
if ( (uint32)(fHighLowMul * range) > iHighValue ||
(fHighLowMul * range) > (double)iHighValue )
{
}

4
public/tier1/mempool.h

@ -432,7 +432,7 @@ inline void CClassMemoryPool<T>::Clear() @@ -432,7 +432,7 @@ inline void CClassMemoryPool<T>::Clear()
static CUtlMemoryPool s_Allocator
#define DEFINE_FIXEDSIZE_ALLOCATOR( _class, _initsize, _grow ) \
CUtlMemoryPool _class::s_Allocator(sizeof(_class), _initsize, _grow, #_class " pool")
CUtlMemoryPool _class::s_Allocator(sizeof(_class), _initsize, _grow, #_class " pool", alignof(_class))
#define DEFINE_FIXEDSIZE_ALLOCATOR_ALIGNED( _class, _initsize, _grow, _alignment ) \
CUtlMemoryPool _class::s_Allocator(sizeof(_class), _initsize, _grow, #_class " pool", _alignment )
@ -447,7 +447,7 @@ inline void CClassMemoryPool<T>::Clear() @@ -447,7 +447,7 @@ inline void CClassMemoryPool<T>::Clear()
static CMemoryPoolMT s_Allocator
#define DEFINE_FIXEDSIZE_ALLOCATOR_MT( _class, _initsize, _grow ) \
CMemoryPoolMT _class::s_Allocator(sizeof(_class), _initsize, _grow, #_class " pool")
CMemoryPoolMT _class::s_Allocator(sizeof(_class), _initsize, _grow, #_class " pool", alignof(_class))
//-----------------------------------------------------------------------------
// Macros that make it simple to make a class use a fixed-size allocator

7
public/tier1/utlbuffer.h

@ -672,7 +672,7 @@ inline void CUtlBuffer::GetObject( T *dest ) @@ -672,7 +672,7 @@ inline void CUtlBuffer::GetObject( T *dest )
{
if ( !m_Byteswap.IsSwappingBytes() || ( sizeof( T ) == 1 ) )
{
*dest = *(T *)PeekGet();
memcpy( dest, PeekGet(), sizeof( T ) );
}
else
{
@ -704,6 +704,7 @@ inline void CUtlBuffer::GetTypeBin( T &dest ) @@ -704,6 +704,7 @@ inline void CUtlBuffer::GetTypeBin( T &dest )
{
if ( !m_Byteswap.IsSwappingBytes() || ( sizeof( T ) == 1 ) )
{
memcpy(&dest, PeekGet(), sizeof(T) );
dest = *(T *)PeekGet();
}
else
@ -1050,7 +1051,7 @@ inline void CUtlBuffer::PutObject( T *src ) @@ -1050,7 +1051,7 @@ inline void CUtlBuffer::PutObject( T *src )
{
if ( !m_Byteswap.IsSwappingBytes() || ( sizeof( T ) == 1 ) )
{
*(T *)PeekPut() = *src;
memcpy( PeekPut(), src, sizeof( T ) );
}
else
{
@ -1079,7 +1080,7 @@ inline void CUtlBuffer::PutTypeBin( T src ) @@ -1079,7 +1080,7 @@ inline void CUtlBuffer::PutTypeBin( T src )
{
if ( !m_Byteswap.IsSwappingBytes() || ( sizeof( T ) == 1 ) )
{
*(T *)PeekPut() = src;
memcpy( PeekPut(), &src, sizeof( T ) );
}
else
{

7
tier1/mempool.cpp

@ -41,7 +41,12 @@ CUtlMemoryPool::CUtlMemoryPool( int blockSize, int numElements, int growMode, co @@ -41,7 +41,12 @@ CUtlMemoryPool::CUtlMemoryPool( int blockSize, int numElements, int growMode, co
}
#endif
m_nAlignment = ( nAlignment != 0 ) ? nAlignment : 1;
#ifdef PLATFORM_64BITS
m_nAlignment = ( nAlignment != 0 ) ? nAlignment : 8;
#else
m_nAlignment = ( nAlignment != 0 ) ? nAlignment : 4;
#endif
Assert( IsPowerOfTwo( m_nAlignment ) );
m_BlockSize = blockSize < sizeof(void*) ? sizeof(void*) : blockSize;
m_BlockSize = AlignValue( m_BlockSize, m_nAlignment );

21
togl/linuxwin/dx9asmtogl2.cpp

@ -2092,23 +2092,32 @@ static uint PrintDoubleInt( char *pBuf, uint nBufSize, double f, uint nMinChars @@ -2092,23 +2092,32 @@ static uint PrintDoubleInt( char *pBuf, uint nBufSize, double f, uint nMinChars
if ( bAnyDigitsLeft )
{
uint n = remainder % 100U; remainder /= 100U; *reinterpret_cast<uint16*>(pDst - 1) = reinterpret_cast<const uint16*>(pDigits)[n];
n = remainder % 100U; remainder /= 100U; *reinterpret_cast<uint16*>(pDst - 1 - 2) = reinterpret_cast<const uint16*>(pDigits)[n];
uint n = remainder % 100U; remainder /= 100U;
memcpy( reinterpret_cast<uint16*>(pDst - 1), &(reinterpret_cast<const uint16*>(pDigits)[n]), sizeof(uint16) );
n = remainder % 100U; remainder /= 100U;
memcpy( reinterpret_cast<uint16*>(pDst - 3), &(reinterpret_cast<const uint16*>(pDigits)[n]), sizeof(uint16) );
Assert( remainder < 100U );
*reinterpret_cast<uint16*>(pDst - 1 - 4) = reinterpret_cast<const uint16*>(pDigits)[remainder];
memcpy( reinterpret_cast<uint16*>(pDst - 5), &(reinterpret_cast<const uint16*>(pDigits)[remainder]), sizeof(uint16) );
pDst -= 6;
}
else
{
uint n = remainder % 100U; remainder /= 100U; *reinterpret_cast<uint16*>(pDst - 1) = reinterpret_cast<const uint16*>(pDigits)[n]; --pDst; if ( ( n >= 10 ) || ( remainder ) ) --pDst;
uint n = remainder % 100U; remainder /= 100U;
memcpy( reinterpret_cast<uint16*>(pDst - 1), &(reinterpret_cast<const uint16*>(pDigits)[n]), sizeof(uint16) );
--pDst; if ( ( n >= 10 ) || ( remainder ) ) --pDst;
if ( remainder )
{
n = remainder % 100U; remainder /= 100U; *reinterpret_cast<uint16*>(pDst - 1) = reinterpret_cast<const uint16*>(pDigits)[n]; --pDst; if ( ( n >= 10 ) || ( remainder ) ) --pDst;
n = remainder % 100U; remainder /= 100U;
memcpy( reinterpret_cast<uint16*>(pDst - 1), &(reinterpret_cast<const uint16*>(pDigits)[n]), sizeof(uint16) );
--pDst; if ( ( n >= 10 ) || ( remainder ) ) --pDst;
if ( remainder )
{
Assert( remainder < 100U );
*reinterpret_cast<uint16*>(pDst - 1) = reinterpret_cast<const uint16*>(pDigits)[remainder]; --pDst; if ( remainder >= 10 ) --pDst;
memcpy( reinterpret_cast<uint16*>(pDst - 1), &(reinterpret_cast<const uint16*>(pDigits)[remainder]), sizeof(uint16) );
--pDst; if ( remainder >= 10 ) --pDst;
}
}
}

Loading…
Cancel
Save