mirror of
https://github.com/alliedmodders/hl2sdk.git
synced 2026-10-11 23:38:00 +08:00
Replace unsigned long with uint32 in bitbuf (#364)
This commit is contained in:
1 parent
6e735c1f97
commit
0175c141fc
3 files changed
+41
-41
No files matched your search
+28
-28
@@ -83,14 +83,14 @@ void SetBitBufErrorHandler( BitBufErrorHandler fn )
|
||||
|
||||
// #define BB_PROFILING
|
||||
|
||||
unsigned long g_LittleBits[32];
|
||||
uint32 g_LittleBits[32];
|
||||
|
||||
// Precalculated bit masks for WriteUBitLong. Using these tables instead of
|
||||
// doing the calculations gives a 33% speedup in WriteUBitLong.
|
||||
unsigned long g_BitWriteMasks[32][33];
|
||||
uint32 g_BitWriteMasks[32][33];
|
||||
|
||||
// (1 << i) - 1
|
||||
unsigned long g_ExtraMasks[33];
|
||||
uint32 g_ExtraMasks[33];
|
||||
|
||||
class CBitWriteMasksInit
|
||||
{
|
||||
@@ -152,12 +152,12 @@ void bf_write::StartWriting( void *pData, int nBytes, int iStartBit, int nBits )
|
||||
{
|
||||
// Make sure it's dword aligned and padded.
|
||||
Assert( (nBytes % 4) == 0 );
|
||||
Assert(((unsigned long)pData & 3) == 0);
|
||||
Assert(((uintp)pData & 3) == 0);
|
||||
|
||||
// The writing code will overrun the end of the buffer if it isn't dword aligned, so truncate to force alignment
|
||||
nBytes &= ~3;
|
||||
|
||||
m_pData = (unsigned long*)pData;
|
||||
m_pData = (uint32*)pData;
|
||||
m_nDataBytes = nBytes;
|
||||
|
||||
if ( nBits == -1 )
|
||||
@@ -462,7 +462,7 @@ bool bf_write::WriteBits(const void *pInData, int nBits)
|
||||
}
|
||||
|
||||
// Align output to dword boundary
|
||||
while (((unsigned long)pOut & 3) != 0 && nBitsLeft >= 8)
|
||||
while (((uintp)pOut & 3) != 0 && nBitsLeft >= 8)
|
||||
{
|
||||
|
||||
WriteUBitLong( *pOut, 8, false );
|
||||
@@ -485,18 +485,18 @@ bool bf_write::WriteBits(const void *pInData, int nBits)
|
||||
// X360TBD: Can't write dwords in WriteBits because they'll get swapped
|
||||
if ( IsPC() && nBitsLeft >= 32 )
|
||||
{
|
||||
unsigned long iBitsRight = (m_iCurBit & 31);
|
||||
unsigned long iBitsLeft = 32 - iBitsRight;
|
||||
unsigned long bitMaskLeft = g_BitWriteMasks[iBitsRight][32];
|
||||
unsigned long bitMaskRight = g_BitWriteMasks[0][iBitsRight];
|
||||
uint32 iBitsRight = (m_iCurBit & 31);
|
||||
uint32 iBitsLeft = 32 - iBitsRight;
|
||||
uint32 bitMaskLeft = g_BitWriteMasks[iBitsRight][32];
|
||||
uint32 bitMaskRight = g_BitWriteMasks[0][iBitsRight];
|
||||
|
||||
unsigned long *pData = &m_pData[m_iCurBit>>5];
|
||||
uint32 *pData = &m_pData[m_iCurBit>>5];
|
||||
|
||||
// Read dwords.
|
||||
while(nBitsLeft >= 32)
|
||||
{
|
||||
unsigned long curData = *(unsigned long*)pOut;
|
||||
pOut += sizeof(unsigned long);
|
||||
uint32 curData = *(uint32*)pOut;
|
||||
pOut += sizeof(uint32);
|
||||
|
||||
*pData &= bitMaskLeft;
|
||||
*pData |= curData << iBitsRight;
|
||||
@@ -898,8 +898,8 @@ void bf_read::ReadBits(void *pOutData, int nBits)
|
||||
// read dwords
|
||||
while ( nBitsLeft >= 32 )
|
||||
{
|
||||
*((unsigned long*)pOut) = ReadUBitLong(32);
|
||||
pOut += sizeof(unsigned long);
|
||||
*((uint32*)pOut) = ReadUBitLong(32);
|
||||
pOut += sizeof(uint32);
|
||||
nBitsLeft -= 32;
|
||||
}
|
||||
}
|
||||
@@ -1440,7 +1440,7 @@ void bf_read::ExciseBits( int startbit, int bitstoremove )
|
||||
|
||||
int bf_read::CompareBitsAt( int offset, bf_read * RESTRICT other, int otherOffset, int numbits ) RESTRICT
|
||||
{
|
||||
extern unsigned long g_ExtraMasks[33];
|
||||
extern uint32 g_ExtraMasks[33];
|
||||
|
||||
if ( numbits == 0 )
|
||||
return 0;
|
||||
@@ -1454,17 +1454,17 @@ int bf_read::CompareBitsAt( int offset, bf_read * RESTRICT other, int otherOffse
|
||||
|
||||
unsigned int iStartBit1 = offset & 31u;
|
||||
unsigned int iStartBit2 = otherOffset & 31u;
|
||||
unsigned long *pData1 = (unsigned long*)m_pData + (offset >> 5);
|
||||
unsigned long *pData2 = (unsigned long*)other->m_pData + (otherOffset >> 5);
|
||||
unsigned long *pData1End = pData1 + ((offset + numbits - 1) >> 5);
|
||||
unsigned long *pData2End = pData2 + ((otherOffset + numbits - 1) >> 5);
|
||||
uint32 *pData1 = (uint32*)m_pData + (offset >> 5);
|
||||
uint32 *pData2 = (uint32*)other->m_pData + (otherOffset >> 5);
|
||||
uint32 *pData1End = pData1 + ((offset + numbits - 1) >> 5);
|
||||
uint32 *pData2End = pData2 + ((otherOffset + numbits - 1) >> 5);
|
||||
|
||||
while ( numbits > 32 )
|
||||
{
|
||||
x = LoadLittleDWord( (unsigned long*)pData1, 0 ) >> iStartBit1;
|
||||
x ^= LoadLittleDWord( (unsigned long*)pData1, 1 ) << (32 - iStartBit1);
|
||||
x ^= LoadLittleDWord( (unsigned long*)pData2, 0 ) >> iStartBit2;
|
||||
x ^= LoadLittleDWord( (unsigned long*)pData2, 1 ) << (32 - iStartBit2);
|
||||
x = LoadLittleDWord( (uint32*)pData1, 0 ) >> iStartBit1;
|
||||
x ^= LoadLittleDWord( (uint32*)pData1, 1 ) << (32 - iStartBit1);
|
||||
x ^= LoadLittleDWord( (uint32*)pData2, 0 ) >> iStartBit2;
|
||||
x ^= LoadLittleDWord( (uint32*)pData2, 1 ) << (32 - iStartBit2);
|
||||
if ( x != 0 )
|
||||
{
|
||||
return x;
|
||||
@@ -1474,9 +1474,9 @@ int bf_read::CompareBitsAt( int offset, bf_read * RESTRICT other, int otherOffse
|
||||
numbits -= 32;
|
||||
}
|
||||
|
||||
x = LoadLittleDWord( (unsigned long*)pData1, 0 ) >> iStartBit1;
|
||||
x ^= LoadLittleDWord( (unsigned long*)pData1End, 0 ) << (32 - iStartBit1);
|
||||
x ^= LoadLittleDWord( (unsigned long*)pData2, 0 ) >> iStartBit2;
|
||||
x ^= LoadLittleDWord( (unsigned long*)pData2End, 0 ) << (32 - iStartBit2);
|
||||
x = LoadLittleDWord( (uint32*)pData1, 0 ) >> iStartBit1;
|
||||
x ^= LoadLittleDWord( (uint32*)pData1End, 0 ) << (32 - iStartBit1);
|
||||
x ^= LoadLittleDWord( (uint32*)pData2, 0 ) >> iStartBit2;
|
||||
x ^= LoadLittleDWord( (uint32*)pData2End, 0 ) << (32 - iStartBit2);
|
||||
return x & g_ExtraMasks[ numbits ];
|
||||
}
|
||||
Reference in new issue
Block a user