GS: Add BitScanReverse polyfill

This commit is contained in:
TellowKrinkle 2022-01-10 23:35:37 -06:00 committed by refractionpcsx2
parent 06b4c3faab
commit f5fba1cbd1
1 changed files with 14 additions and 3 deletions

View File

@ -30,15 +30,26 @@
static int _BitScanForward(unsigned long* const Index, const unsigned long Mask)
{
#if __has_builtin(__builtin_ctz)
if (Mask == 0)
return 0;
#if __has_builtin(__builtin_ctz)
*Index = __builtin_ctz(Mask);
return 1;
#else
__asm__("bsfl %k[Mask], %k[Index]" : [Index] "=r" (*Index) : [Mask] "mr" (Mask) : "cc");
return Mask ? 1 : 0;
#endif
return 1;
}
static int _BitScanReverse(unsigned long* const Index, const unsigned long Mask)
{
if (Mask == 0)
return 0;
#if __has_builtin(__builtin_clz)
*Index = 31 - __builtin_clz(Mask);
#else
__asm__("bsrl %k[Mask], %k[Index]" : [Index] "=r" (*Index) : [Mask] "mr" (Mask) : "cc");
#endif
return 1;
}
#endif