Skip to content

Commit 9587cba

Browse files
committed
Fix implementation of firstbit_(s)hi - thanks to Scott Kircher
* firstbit_hi counts MSB as index 0, BitScanReverse counts LSB as 0.
1 parent 6951b5b commit 9587cba

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

renderdoc/driver/shaders/dxbc/dxbc_debug.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,7 +1192,15 @@ State State::GetNext(GlobalState &global, State quad[4]) const
11921192
{
11931193
unsigned char found = BitScanReverse((DWORD *)&ret.value.uv[i], srcOpers[0].value.uv[i]);
11941194
if(found == 0)
1195+
{
11951196
ret.value.uv[i] = ~0U;
1197+
}
1198+
else
1199+
{
1200+
// firstbit_hi counts index 0 as the MSB, BitScanReverse counts index 0 as the LSB. So we
1201+
// need to invert
1202+
ret.value.uv[i] = 31 - ret.value.uv[i];
1203+
}
11961204
}
11971205

11981206
s.SetDst(op.operands[0], op, ret);
@@ -1225,7 +1233,15 @@ State State::GetNext(GlobalState &global, State quad[4]) const
12251233
unsigned char found = BitScanReverse((DWORD *)&ret.value.uv[i], u);
12261234

12271235
if(found == 0)
1236+
{
12281237
ret.value.uv[i] = ~0U;
1238+
}
1239+
else
1240+
{
1241+
// firstbit_shi counts index 0 as the MSB, BitScanReverse counts index 0 as the LSB. So we
1242+
// need to invert
1243+
ret.value.uv[i] = 31 - ret.value.uv[i];
1244+
}
12291245
}
12301246

12311247
s.SetDst(op.operands[0], op, ret);

0 commit comments

Comments
 (0)