Skip to content

Commit e92db71

Browse files
committed
cross platform restrict
1 parent 9bde758 commit e92db71

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

serialize.h

+21-15
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@
2727

2828
/** @file */
2929

30+
#if defined(_MSC_VER)
31+
#define serialize_restrict __restrict
32+
#else // #if defined(_MSC_VER)
33+
#define serialize_restrict __restrict__
34+
#endif // #if defined(_MSC_VER)
35+
3036
#ifndef serialize_assert
3137
#include <assert.h>
3238
#define serialize_assert assert
@@ -352,7 +358,7 @@ namespace serialize
352358
memset( (void*) this, 0, sizeof(BitWriter) );
353359
}
354360

355-
void Initialize( void * __restrict__ data, int bytes )
361+
void Initialize( void * serialize_restrict data, int bytes )
356362
{
357363
serialize_assert( data );
358364
serialize_assert( ( bytes % 4 ) == 0 );
@@ -372,7 +378,7 @@ namespace serialize
372378
@param bytes The size of the buffer in bytes. Must be a multiple of 4, because the bitpacker reads and writes memory as dwords, not bytes.
373379
*/
374380

375-
BitWriter( void * __restrict__ data, int bytes ) : m_data( (uint32_t*) data ), m_numWords( bytes / 4 )
381+
BitWriter( void * serialize_restrict data, int bytes ) : m_data( (uint32_t*) data ), m_numWords( bytes / 4 )
376382
{
377383
serialize_assert( data );
378384
serialize_assert( ( bytes % 4 ) == 0 );
@@ -444,7 +450,7 @@ namespace serialize
444450
@see BitReader::ReadBytes
445451
*/
446452

447-
void WriteBytes( const uint8_t * __restrict__ data, int bytes )
453+
void WriteBytes( const uint8_t * serialize_restrict data, int bytes )
448454
{
449455
serialize_assert( GetAlignBits() == 0 );
450456
serialize_assert( m_bitsWritten + bytes * 8 <= m_numBits );
@@ -590,7 +596,7 @@ namespace serialize
590596
m_wordIndex = 0;
591597
}
592598

593-
void Initialize( const void * __restrict__ data, int bytes )
599+
void Initialize( const void * serialize_restrict data, int bytes )
594600
{
595601
serialize_assert( data );
596602
m_data = (const uint32_t*) data;
@@ -615,9 +621,9 @@ namespace serialize
615621
*/
616622

617623
#ifdef SERIALIZE_DEBUG
618-
BitReader( const void * __restrict__ data, int bytes ) : m_data( (const uint32_t*) data ), m_numBytes( bytes ), m_numWords( ( bytes + 3 ) / 4 )
624+
BitReader( const void * serialize_restrict data, int bytes ) : m_data( (const uint32_t*) data ), m_numBytes( bytes ), m_numWords( ( bytes + 3 ) / 4 )
619625
#else // #ifdef SERIALIZE_DEBUG
620-
BitReader( const void * __restrict__ data, int bytes ) : m_data( (const uint32_t*) data ), m_numBytes( bytes )
626+
BitReader( const void * serialize_restrict data, int bytes ) : m_data( (const uint32_t*) data ), m_numBytes( bytes )
621627
#endif // #ifdef SERIALIZE_DEBUG
622628
{
623629
serialize_assert( data );
@@ -706,7 +712,7 @@ namespace serialize
706712
@see BitWriter::WriteBytes
707713
*/
708714

709-
void ReadBytes( uint8_t * __restrict__ data, int bytes )
715+
void ReadBytes( uint8_t * serialize_restrict data, int bytes )
710716
{
711717
serialize_assert( GetAlignBits() == 0 );
712718
serialize_assert( m_bitsRead + bytes * 8 <= m_numBits );
@@ -778,16 +784,16 @@ namespace serialize
778784

779785
private:
780786

781-
const uint32_t * __restrict__ m_data; ///< The bitpacked data we're reading as a dword array.
782-
uint64_t m_scratch; ///< The scratch value. New data is read in 32 bits at a top to the left of this buffer, and data is read off to the right.
783-
int m_numBits; ///< Number of bits to read in the buffer. Of course, we can't *really* know this so it's actually m_numBytes * 8.
784-
int m_numBytes; ///< Number of bytes to read in the buffer. We know this, and this is the non-rounded up version.
787+
const uint32_t * serialize_restrict m_data; ///< The bitpacked data we're reading as a dword array.
788+
uint64_t m_scratch; ///< The scratch value. New data is read in 32 bits at a top to the left of this buffer, and data is read off to the right.
789+
int m_numBits; ///< Number of bits to read in the buffer. Of course, we can't *really* know this so it's actually m_numBytes * 8.
790+
int m_numBytes; ///< Number of bytes to read in the buffer. We know this, and this is the non-rounded up version.
785791
#ifdef SERIALIZE_DEBUG
786-
int m_numWords; ///< Number of words to read in the buffer. This is rounded up to the next word if necessary.
792+
int m_numWords; ///< Number of words to read in the buffer. This is rounded up to the next word if necessary.
787793
#endif // #ifdef SERIALIZE_DEBUG
788-
int m_bitsRead; ///< Number of bits read from the buffer so far.
789-
int m_scratchBits; ///< Number of bits currently in the scratch value. If the user wants to read more bits than this, we have to go fetch another dword from memory.
790-
int m_wordIndex; ///< Index of the next word to read from memory.
794+
int m_bitsRead; ///< Number of bits read from the buffer so far.
795+
int m_scratchBits; ///< Number of bits currently in the scratch value. If the user wants to read more bits than this, we have to go fetch another dword from memory.
796+
int m_wordIndex; ///< Index of the next word to read from memory.
791797
};
792798

793799
/**

0 commit comments

Comments
 (0)