Merge branch 'master' into windows

This commit is contained in:
HappyDOGE
2022-07-27 12:58:56 +03:00
3089 changed files with 38639 additions and 844820 deletions
+39 -39
View File
@@ -42,15 +42,15 @@ inline unsigned int CountTrailingZeros( unsigned int elem )
inline unsigned int CountLeadingZeros(unsigned int x)
{
unsigned long firstBit;
if ( _BitScanReverse(&firstBit,x) )
uint32 firstBit;
if ( _BitScanReverse((unsigned long*)&firstBit,x) )
return 31 - firstBit;
return 32;
}
inline unsigned int CountTrailingZeros(unsigned int elem)
{
unsigned long out;
if ( _BitScanForward(&out, elem) )
uint32 out;
if ( _BitScanForward((unsigned long*)&out, elem) )
return out;
return 32;
}
@@ -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
{
@@ -110,7 +110,7 @@ public:
for ( unsigned int maskBit=0; maskBit < 32; maskBit++ )
g_ExtraMasks[maskBit] = BitForBitnum(maskBit) - 1;
g_ExtraMasks[32] = ~0ul;
g_ExtraMasks[32] = ~0u;
for ( unsigned int littleBit=0; littleBit < 32; littleBit++ )
StoreLittleDWord( &g_LittleBits[littleBit], 0, 1u<<littleBit );
@@ -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;
@@ -736,9 +736,9 @@ void bf_write::WriteWord(int val)
WriteUBitLong(val, sizeof(unsigned short) << 3);
}
void bf_write::WriteLong(long val)
void bf_write::WriteLong(int32 val)
{
WriteSBitLong(val, sizeof(long) << 3);
WriteSBitLong(val, sizeof(int32) << 3);
}
void bf_write::WriteLongLong(int64 val)
@@ -748,8 +748,8 @@ void bf_write::WriteLongLong(int64 val)
// Insert the two DWORDS according to network endian
const short endianIndex = 0x0100;
byte *idx = (byte*)&endianIndex;
WriteUBitLong(pLongs[*idx++], sizeof(long) << 3);
WriteUBitLong(pLongs[*idx], sizeof(long) << 3);
WriteUBitLong(pLongs[*idx++], sizeof(int32) << 3);
WriteUBitLong(pLongs[*idx], sizeof(int32) << 3);
}
void bf_write::WriteFloat(float val)
@@ -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;
}
}
@@ -1349,8 +1349,8 @@ int64 bf_read::ReadLongLong()
// Read the two DWORDs according to network endian
const short endianIndex = 0x0100;
byte *idx = (byte*)&endianIndex;
pLongs[*idx++] = ReadUBitLong(sizeof(long) << 3);
pLongs[*idx] = ReadUBitLong(sizeof(long) << 3);
pLongs[*idx++] = ReadUBitLong(sizeof(int32) << 3);
pLongs[*idx] = ReadUBitLong(sizeof(int32) << 3);
return retval;
}
@@ -1448,7 +1448,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;
@@ -1462,17 +1462,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;
@@ -1482,9 +1482,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 ];
}