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:
hendricks266 2019-11-26 08:25:13 +00:00 committed by Christoph Oelckers
parent 510e737360
commit 348ccdfd5b
2 changed files with 10 additions and 4 deletions

View file

@ -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

View file

@ -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);
}
}