Skip to content

Commit

Permalink
Use fast and simple ROTR algorithm implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
nekonomicon committed Oct 31, 2023
1 parent 984986f commit 7581cac
Showing 1 changed file with 3 additions and 18 deletions.
21 changes: 3 additions & 18 deletions dlls/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1730,25 +1730,10 @@ void CSaveRestoreBuffer::BufferRewind( int size )
}

#if !XASH_WIN32 && !__WATCOMC__
extern "C" {
unsigned _rotr( unsigned val, int shift )
static unsigned _rotr( unsigned val, int shift )
{
unsigned lobit; /* non-zero means lo bit set */
unsigned num = val; /* number to rotate */

shift &= 0x1f; /* modulo 32 -- this will also make
negative shifts work */

while( shift-- )
{
lobit = num & 1; /* get high bit */
num >>= 1; /* shift right one bit */
if( lobit )
num |= 0x80000000; /* set hi bit if lo bit was set */
}

return num;
}
// Any modern compiler will generate one single ror instruction for x86, arm and mips here.
return ( val >> shift ) | ( val << ( 32 - shift ));
}
#endif

Expand Down

0 comments on commit 7581cac

Please sign in to comment.