mirror of
https://github.com/bkaradzic/bx.git
synced 2026-02-17 20:52:37 +01:00
Added bx::findLastSet.
This commit is contained in:
@@ -371,16 +371,24 @@ namespace bx
|
||||
}
|
||||
|
||||
template<> inline BX_CONSTEXPR_FUNC uint8_t countTrailingZeros(uint8_t _val) { return bx::min<uint8_t>(8, countTrailingZeros<uint32_t>(_val) ); }
|
||||
template<> inline BX_CONSTEXPR_FUNC uint8_t countTrailingZeros(int8_t _val) { return countTrailingZeros<uint8_t >(_val); }
|
||||
template<> inline BX_CONSTEXPR_FUNC uint8_t countTrailingZeros(int8_t _val) { return countTrailingZeros<uint8_t >(_val); }
|
||||
template<> inline BX_CONSTEXPR_FUNC uint8_t countTrailingZeros(uint16_t _val) { return bx::min<uint8_t>(16, countTrailingZeros<uint32_t>(_val) ); }
|
||||
template<> inline BX_CONSTEXPR_FUNC uint8_t countTrailingZeros(int16_t _val) { return countTrailingZeros<uint16_t>(_val); }
|
||||
template<> inline BX_CONSTEXPR_FUNC uint8_t countTrailingZeros(int32_t _val) { return countTrailingZeros<uint32_t>(_val); }
|
||||
template<> inline BX_CONSTEXPR_FUNC uint8_t countTrailingZeros(int64_t _val) { return countTrailingZeros<uint64_t>(_val); }
|
||||
template<> inline BX_CONSTEXPR_FUNC uint8_t countTrailingZeros(int16_t _val) { return countTrailingZeros<uint16_t>(_val); }
|
||||
template<> inline BX_CONSTEXPR_FUNC uint8_t countTrailingZeros(int32_t _val) { return countTrailingZeros<uint32_t>(_val); }
|
||||
template<> inline BX_CONSTEXPR_FUNC uint8_t countTrailingZeros(int64_t _val) { return countTrailingZeros<uint64_t>(_val); }
|
||||
|
||||
template<typename Ty>
|
||||
inline BX_CONSTEXPR_FUNC uint8_t findFirstSet(Ty _x)
|
||||
inline BX_CONSTEXPR_FUNC uint8_t findFirstSet(Ty _val)
|
||||
{
|
||||
return Ty(0) == _x ? uint8_t(0) : countTrailingZeros<Ty>(_x) + 1;
|
||||
BX_STATIC_ASSERT(isInteger<Ty>(), "Type Ty must be of integer type!");
|
||||
return Ty(0) == _val ? uint8_t(0) : countTrailingZeros<Ty>(_val) + 1;
|
||||
}
|
||||
|
||||
template<typename Ty>
|
||||
inline BX_CONSTEXPR_FUNC uint8_t findLastSet(Ty _val)
|
||||
{
|
||||
BX_STATIC_ASSERT(isInteger<Ty>(), "Type Ty must be of integer type!");
|
||||
return Ty(0) == _val ? uint8_t(0) : sizeof(Ty)*8 - countLeadingZeros<Ty>(_val);
|
||||
}
|
||||
|
||||
template<typename Ty>
|
||||
|
||||
@@ -299,6 +299,11 @@ namespace bx
|
||||
template<typename Ty>
|
||||
BX_CONSTEXPR_FUNC uint8_t findFirstSet(Ty _val);
|
||||
|
||||
/// Find last set.
|
||||
///
|
||||
template<typename Ty>
|
||||
BX_CONSTEXPR_FUNC uint8_t findLastSet(Ty _val);
|
||||
|
||||
/// Returns the next smallest integer base 2 logarithm of _a.
|
||||
///
|
||||
template<typename Ty>
|
||||
|
||||
Reference in New Issue
Block a user