shithub: dav1d

ref: a3856f049d188b971c0956b1b5cef350212f03a3
dir: /src/plan9_builtins.c/

View raw version
int
__builtin_ctz(unsigned int x)
{
	unsigned int r;
	if(x == 0)
		return 32;
	for(r = 0; (x & 1) == 0; x >>= 1, r++);
	return r;
}

int
__builtin_clz(unsigned int x)
{
	unsigned int r;
	if(x == 0)
		return 32;
	for(r = 0; (x & (1UL<<31)) == 0; x <<= 1, r++);
	return r;
}

int
__builtin_clzll(unsigned long long x)
{
	unsigned long long r;
	if(x == 0)
		return 64;
	for(r = 0; (x & (1ULL<<63)) == 0; x <<= 1, r++);
	return r;
}