Moved some bit field helper functions to common code

To be shared between DXBC and DXIL Debugger
BitwiseReverseLSB16
PopCount
This commit is contained in:
Jake Turner
2024-10-24 16:13:37 +01:00
parent 84c7906a7a
commit f933aa1c76
3 changed files with 22 additions and 19 deletions
@@ -412,6 +412,25 @@ float flush_denorm(const float f)
return ret;
}
uint32_t BitwiseReverseLSB16(uint32_t x)
{
// Reverse the bits in x, then discard the lower half
// https://graphics.stanford.edu/~seander/bithacks.html#ReverseParallel
x = ((x >> 1) & 0x55555555) | ((x & 0x55555555) << 1);
x = ((x >> 2) & 0x33333333) | ((x & 0x33333333) << 2);
x = ((x >> 4) & 0x0F0F0F0F) | ((x & 0x0F0F0F0F) << 4);
x = ((x >> 8) & 0x00FF00FF) | ((x & 0x00FF00FF) << 8);
return x << 16;
}
uint32_t PopCount(uint32_t x)
{
// https://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel
x = x - ((x >> 1) & 0x55555555);
x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
return (((x + (x >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24;
}
void get_sample_position(uint32_t sampleIndex, uint32_t sampleCount, float *position)
{
// assume standard sample pattern - this might not hold in all cases
+3
View File
@@ -117,5 +117,8 @@ float round_ne(float x);
double round_ne(double x);
float flush_denorm(const float f);
uint32_t BitwiseReverseLSB16(uint32_t x);
uint32_t PopCount(uint32_t x);
void get_sample_position(uint32_t sampleIndex, uint32_t sampleCount, float *position);
};
@@ -1639,25 +1639,6 @@ ShaderVariable ThreadState::GetSrc(const Operand &oper, const Operation &op, boo
return v;
}
static uint32_t BitwiseReverseLSB16(uint32_t x)
{
// Reverse the bits in x, then discard the lower half
// https://graphics.stanford.edu/~seander/bithacks.html#ReverseParallel
x = ((x >> 1) & 0x55555555) | ((x & 0x55555555) << 1);
x = ((x >> 2) & 0x33333333) | ((x & 0x33333333) << 2);
x = ((x >> 4) & 0x0F0F0F0F) | ((x & 0x0F0F0F0F) << 4);
x = ((x >> 8) & 0x00FF00FF) | ((x & 0x00FF00FF) << 8);
return x << 16;
}
static uint32_t PopCount(uint32_t x)
{
// https://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel
x = x - ((x >> 1) & 0x55555555);
x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
return (((x + (x >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24;
}
void FlattenSingleVariable(const rdcstr &cbufferName, uint32_t byteOffset, const rdcstr &basename,
const ShaderVariable &v, rdcarray<ShaderVariable> &outvars,
rdcarray<SourceVariableMapping> &sourcevars)