Files
UnrealEngineUWP/Engine/Source/Developer/Windows/LiveCoding/Private/External/LC_BitUtil.h
Ben Marsh 0e6aa011b3 Copying //UE4/Dev-Build @ CL 11166028 to Dev-Main (//UE4/Dev-Main)
#rb none
#rnx

[CL 11166227 by Ben Marsh in Main branch]
2020-01-29 14:48:18 -05:00

36 lines
928 B
C++

// Copyright 2011-2019 Molecular Matters GmbH, all rights reserved.
#pragma once
#include <type_traits>
#pragma intrinsic(_BitScanReverse)
namespace bitUtil
{
template <typename T>
inline T RoundUpToMultiple(T numToRound, T multipleOf)
{
static_assert(std::is_unsigned<T>::value == true, "T must be an unsigned type.");
return (numToRound + (multipleOf - 1u)) & ~(multipleOf - 1u);
}
// http://www.graphics.stanford.edu/~seander/bithacks.html#DetermineIfPowerOf2
template <typename T>
inline bool IsPowerOfTwo(T value)
{
static_assert(std::is_unsigned<T>::value == true, "T must be an unsigned type.");
return value && !(value & (value - 1u));
}
// Finds the first set bit, searching from MSB to LSB.
// Can be used to determine the log2 of integers that are powers of two.
inline uint32_t BitScanReverse(uint32_t value)
{
DWORD index = 0u;
::_BitScanReverse(&index, value);
return index;
}
}