klib,int64: implement clzsi2() and ctzsi2()

* this is to support 64-bit divisions in fceux
This commit is contained in:
Zihao Yu 2020-04-24 19:52:08 +08:00
parent a149aba788
commit bbf856f3fd
1 changed files with 8 additions and 6 deletions

View File

@ -283,17 +283,19 @@ __umoddi3(du_int a, du_int b)
}
#include <klib.h>
// for more details, refer to
// https://gcc.gnu.org/onlinedocs/gccint/Integer-library-routines.html
// only use for linking
int __clzsi2 (unsigned int a) {
_halt(1);
if (a == 0) return 0;
int bit = 31;
while ((a & (1 << bit)) == 0) bit --;
return bit;
}
int __ctzsi2 (unsigned int a) {
_halt(1);
if (a == 0) return 0;
int bit = 0;
while ((a & (1 << bit)) == 0) bit ++;
return bit;
}