From 7581cacd6f7531e0cee6908ad441c36e569969b2 Mon Sep 17 00:00:00 2001 From: Andrey Akhmichin <15944199+nekonomicon@users.noreply.github.com> Date: Wed, 1 Nov 2023 01:31:10 +0500 Subject: [PATCH] Use fast and simple ROTR algorithm implementation. --- dlls/util.cpp | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/dlls/util.cpp b/dlls/util.cpp index cb651940..6cfebc10 100644 --- a/dlls/util.cpp +++ b/dlls/util.cpp @@ -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