Codechange: replace ROR/ROL with std::rotr/rotl

This commit is contained in:
Rubidium 2024-01-17 20:58:06 +01:00 committed by rubidium42
parent f457be5a27
commit 47c0184a0b
7 changed files with 10 additions and 41 deletions

View File

@ -130,14 +130,14 @@ static inline void Md5Set1(const uint32_t *X, uint32_t *a, const uint32_t *b, co
{
uint32_t t = (*b & *c) | (~*b & *d);
t += *a + X[k] + Ti;
*a = ROL(t, s) + *b;
*a = std::rotl(t, s) + *b;
}
static inline void Md5Set2(const uint32_t *X, uint32_t *a, const uint32_t *b, const uint32_t *c, const uint32_t *d, const uint8_t k, const uint8_t s, const uint32_t Ti)
{
uint32_t t = (*b & *d) | (*c & ~*d);
t += *a + X[k] + Ti;
*a = ROL(t, s) + *b;
*a = std::rotl(t, s) + *b;
}
@ -145,14 +145,14 @@ static inline void Md5Set3(const uint32_t *X, uint32_t *a, const uint32_t *b, co
{
uint32_t t = *b ^ *c ^ *d;
t += *a + X[k] + Ti;
*a = ROL(t, s) + *b;
*a = std::rotl(t, s) + *b;
}
static inline void Md5Set4(const uint32_t *X, uint32_t *a, const uint32_t *b, const uint32_t *c, const uint32_t *d, const uint8_t k, const uint8_t s, const uint32_t Ti)
{
uint32_t t = *c ^ (*b | ~*d);
t += *a + X[k] + Ti;
*a = ROL(t, s) + *b;
*a = std::rotl(t, s) + *b;
}
Md5::Md5()

View File

@ -288,38 +288,6 @@ inline bool HasAtMostOneBit(T value)
return (value & (value - 1)) == 0;
}
/**
* ROtate \a x Left by \a n
*
* @note Assumes a byte has 8 bits
* @param x The value which we want to rotate
* @param n The number how many we want to rotate
* @pre n < sizeof(T) * 8
* @return A bit rotated number
*/
template <typename T>
inline T ROL(const T x, const uint8_t n)
{
if (n == 0) return x;
return (T)(x << n | x >> (sizeof(x) * 8 - n));
}
/**
* ROtate \a x Right by \a n
*
* @note Assumes a byte has 8 bits
* @param x The value which we want to rotate
* @param n The number how many we want to rotate
* @pre n < sizeof(T) * 8
* @return A bit rotated number
*/
template <typename T>
inline T ROR(const T x, const uint8_t n)
{
if (n == 0) return x;
return (T)(x >> n | x << (sizeof(x) * 8 - n));
}
/**
* Iterable ensemble of each set bit in a value.
* @tparam Tbitpos Type of the position variable.

View File

@ -33,8 +33,8 @@ uint32_t Randomizer::Next()
const uint32_t s = this->state[0];
const uint32_t t = this->state[1];
this->state[0] = s + ROR(t ^ 0x1234567F, 7) + 1;
return this->state[1] = ROR(s, 3) - 1;
this->state[0] = s + std::rotr(t ^ 0x1234567F, 7) + 1;
return this->state[1] = std::rotr(s, 3) - 1;
}
/**

View File

@ -169,7 +169,7 @@ static U EvalAdjustT(const DeterministicSpriteGroupAdjust &adjust, ScopeResolver
case DSGA_OP_STO: _temp_store.StoreValue((U)value, (S)last_value); return last_value;
case DSGA_OP_RST: return value;
case DSGA_OP_STOP: scope->StorePSA((U)value, (S)last_value); return last_value;
case DSGA_OP_ROR: return ROR<uint32_t>((U)last_value, (U)value & 0x1F); // mask 'value' to 5 bits, which should behave the same on all architectures.
case DSGA_OP_ROR: return std::rotr<uint32_t>((U)last_value, (U)value & 0x1F); // mask 'value' to 5 bits, which should behave the same on all architectures.
case DSGA_OP_SCMP: return ((S)last_value == (S)value) ? 1 : ((S)last_value < (S)value ? 0 : 2);
case DSGA_OP_UCMP: return ((U)last_value == (U)value) ? 1 : ((U)last_value < (U)value ? 0 : 2);
case DSGA_OP_SHL: return (uint32_t)(U)last_value << ((U)value & 0x1F); // Same behaviour as in ParamSet, mask 'value' to 5 bits, which should behave the same on all architectures.

View File

@ -212,7 +212,7 @@ static bool VerifyOldNameChecksum(char *title, uint len)
uint16_t sum = 0;
for (uint i = 0; i < len - HEADER_CHECKSUM_SIZE; i++) {
sum += title[i];
sum = ROL(sum, 1);
sum = std::rotl(sum, 1);
}
sum ^= 0xAAAA; // computed checksum

View File

@ -48,6 +48,7 @@
#include <algorithm>
#include <array>
#include <bit>
#include <cassert>
#include <cctype>
#include <cerrno>

View File

@ -115,7 +115,7 @@ LangString *StringData::Find(const std::string_view s)
uint StringData::VersionHashStr(uint hash, const char *s) const
{
for (; *s != '\0'; s++) {
hash = ROL(hash, 3) ^ *s;
hash = std::rotl(hash, 3) ^ *s;
hash = (hash & 1 ? hash >> 1 ^ 0xDEADBEEF : hash >> 1);
}
return hash;