mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-12-24 10:40:46 +00:00
Templatize the branchless negation method used for GV_FLAG_NEGATIVE
git-svn-id: https://svn.eduke32.com/eduke32@8312 1a8010ca-5511-0410-912e-c29ae57300e0 # Conflicts: # source/build/include/compat.h
This commit is contained in:
parent
510e737360
commit
348ccdfd5b
2 changed files with 10 additions and 4 deletions
|
@ -1067,6 +1067,13 @@ FORCE_INLINE CONSTEXPR DivResult<T> divrhs(T lhs)
|
|||
{
|
||||
return divide(lhs, (T)base);
|
||||
}
|
||||
|
||||
template <typename T, typename T2>
|
||||
static FORCE_INLINE CONSTEXPR_CXX14 enable_if_t<is_signed<T>::value, T> NEGATE_ON_CONDITION(T value, T2 condition)
|
||||
{
|
||||
T const invert = !!condition;
|
||||
return (value ^ -invert) + invert;
|
||||
}
|
||||
#endif
|
||||
|
||||
template <size_t base, typename T>
|
||||
|
@ -1081,11 +1088,11 @@ CONSTEXPR size_t logbasenegative(T n)
|
|||
return n > static_cast<T>(-(native_t)base) ? 1 : 1 + logbase<base>(n / static_cast<T>(-(native_t)base));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#define isPow2OrZero(v) (((v) & ((v) - 1)) == 0)
|
||||
#define isPow2(v) (isPow2OrZero(v) && (v))
|
||||
|
||||
#endif
|
||||
|
||||
////////// Bitfield manipulation //////////
|
||||
|
||||
#if 0
|
||||
|
|
|
@ -760,7 +760,6 @@ static FORCE_INLINE int __fastcall getvar__(int const gameVar, int const spriteN
|
|||
|
||||
int returnValue = 0;
|
||||
int const varFlags = var.flags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK);
|
||||
int const invertResult = !!(gameVar & GV_FLAG_NEGATIVE);
|
||||
|
||||
if (!varFlags) returnValue = var.global;
|
||||
else if (varFlags == GAMEVAR_PERACTOR)
|
||||
|
@ -775,7 +774,7 @@ static FORCE_INLINE int __fastcall getvar__(int const gameVar, int const spriteN
|
|||
case GAMEVAR_Q16PTR: returnValue = fix16_to_int(*(fix16_t *)var.global); break;
|
||||
}
|
||||
|
||||
return (returnValue ^ -invertResult) + invertResult;
|
||||
return NEGATE_ON_CONDITION(returnValue, gameVar & GV_FLAG_NEGATIVE);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue