mirror of https://github.com/PCSX2/pcsx2.git
GS: Add BitScanReverse polyfill
This commit is contained in:
parent
06b4c3faab
commit
f5fba1cbd1
|
@ -30,15 +30,26 @@
|
||||||
|
|
||||||
static int _BitScanForward(unsigned long* const Index, const unsigned long Mask)
|
static int _BitScanForward(unsigned long* const Index, const unsigned long Mask)
|
||||||
{
|
{
|
||||||
#if __has_builtin(__builtin_ctz)
|
|
||||||
if (Mask == 0)
|
if (Mask == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
#if __has_builtin(__builtin_ctz)
|
||||||
*Index = __builtin_ctz(Mask);
|
*Index = __builtin_ctz(Mask);
|
||||||
return 1;
|
|
||||||
#else
|
#else
|
||||||
__asm__("bsfl %k[Mask], %k[Index]" : [Index] "=r" (*Index) : [Mask] "mr" (Mask) : "cc");
|
__asm__("bsfl %k[Mask], %k[Index]" : [Index] "=r" (*Index) : [Mask] "mr" (Mask) : "cc");
|
||||||
return Mask ? 1 : 0;
|
|
||||||
#endif
|
#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
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue