XilinxProcessorIPLib/drivers/v_warp_init/src/xv_warp_init_utils.c
unsigned char XVWarpInit_DominantBit(unsigned int val) {
	unsigned char cnt = 0;
#if USE_BUILTIN_CLZ
	if (val)
		cnt = (32 - __builtin_clz(val));

	return cnt;
#else
	int tmp, block;
	unsigned short x, x1;

	if (!val)
		return 0;

	block = 0;
	if (val >> 16) {
		x = val >> 24;
		if (x) {
			x1 = (x >> 4) & 0x000F;
			if (x1) {
				block = 7;
				tmp = 3;
				while (!(x1 >> tmp) && tmp)
					tmp--;
			}
			else {
				block = 6;
				tmp = 3;
				while (!(x >> tmp) && tmp)
					tmp--;
			}
		}
		else {
			x1 = (val >> 20) & 0x000F;
			if (x1) {
				block = 5;
				tmp = 3;
				while (!(x1 >> tmp) && tmp)
					tmp--;
			}
			else {
				x1 = (val >> 16) & 0x000F;
				block = 4;
				tmp = 3;
				while (!(x1 >> tmp) && tmp)
					tmp--;
			}
		}
		cnt = 4 * block + tmp + 1;
	}
	else {
		x = val >> 8;
		if (x) {
			x1 = (x >> 4) & 0x000F;
			if (x1) {
				block = 3;
				tmp = 3;
				while (!(x1 >> tmp) && tmp)
					tmp--;
			}
			else {
				block = 2;
				tmp = 3;
				while (!(x >> tmp) && tmp)
					tmp--;
			}
		}
		else {
			x1 = (val >> 4) & 0x000F;
			if (x1) {
				block = 1;
				tmp = 3;
				while (!(x1 >> tmp) && tmp)
					tmp--;
			}
			else {
				//x1 = (val >> 16) & 0x000F;
				block = 0;
				tmp = 3;
				while (!(val >> tmp) && tmp)
					tmp--;
			}
		}
	}

	cnt = 4 * block + tmp + 1;

	return cnt;
#endif
}
/*****************************************************************************/
/**
* This function counts leading zeros in given positive integer
*
* @param  val, integer value
*
* @return returns number of leading zeros
*
******************************************************************************/
This function counts leading zeros in given positive integer
This function counts leading zeros in given positive integer
unsigned char XVWarpInit_DominantBit(unsigned int val) {
	unsigned char cnt = 0;
#if USE_BUILTIN_CLZ
	if (val)
		cnt = (32 - __builtin_clz(val));
	return cnt;
#else
	int tmp, block;
	unsigned short x, x1;
	if (!val)
		return 0;
	block = 0;
	if (val >> 16) {
		x = val >> 24;
		if (x) {
			x1 = (x >> 4) & 0x000F;
			if (x1) {
				block = 7;
				tmp = 3;
				while (!(x1 >> tmp) && tmp)
					tmp--;
			}
			else {
				block = 6;
				tmp = 3;
				while (!(x >> tmp) && tmp)
					tmp--;
			}
		}
		else {
			x1 = (val >> 20) & 0x000F;
			if (x1) {
				block = 5;
				tmp = 3;
				while (!(x1 >> tmp) && tmp)
					tmp--;
			}
			else {
				x1 = (val >> 16) & 0x000F;
				block = 4;
				tmp = 3;
				while (!(x1 >> tmp) && tmp)
					tmp--;
			}
		}
		cnt = 4 * block + tmp + 1;
	}
	else {
		x = val >> 8;
		if (x) {
			x1 = (x >> 4) & 0x000F;
			if (x1) {
				block = 3;
				tmp = 3;
				while (!(x1 >> tmp) && tmp)
					tmp--;
			}
			else {
				block = 2;
				tmp = 3;
				while (!(x >> tmp) && tmp)
					tmp--;
			}
		}
		else {
			x1 = (val >> 4) & 0x000F;
			if (x1) {
				block = 1;
				tmp = 3;
				while (!(x1 >> tmp) && tmp)
					tmp--;
			}
			else {
				block = 0;
				tmp = 3;
				while (!(val >> tmp) && tmp)
					tmp--;
			}
		}
	}
	cnt = 4 * block + tmp + 1;
	return cnt;
#endif
}
unsigned char XVWarpInit_DominantBit ( unsigned int val ) { unsigned char cnt = 0 ; #if USE_BUILTIN_CLZ if ( val ) cnt = ( 32 - __builtin_clz ( val ) ) ; return cnt ; #else int tmp , block ; unsigned short x , x1 ; if ( ! val ) return 0 ; block = 0 ; if ( val >> 16 ) { x = val >> 24 ; if ( x ) { x1 = ( x >> 4 ) & 0x000F ; if ( x1 ) { block = 7 ; tmp = 3 ; while ( ! ( x1 >> tmp ) && tmp ) tmp -- ; } else { block = 6 ; tmp = 3 ; while ( ! ( x >> tmp ) && tmp ) tmp -- ; } } else { x1 = ( val >> 20 ) & 0x000F ; if ( x1 ) { block = 5 ; tmp = 3 ; while ( ! ( x1 >> tmp ) && tmp ) tmp -- ; } else { x1 = ( val >> 16 ) & 0x000F ; block = 4 ; tmp = 3 ; while ( ! ( x1 >> tmp ) && tmp ) tmp -- ; } } cnt = 4 * block + tmp + 1 ; } else { x = val >> 8 ; if ( x ) { x1 = ( x >> 4 ) & 0x000F ; if ( x1 ) { block = 3 ; tmp = 3 ; while ( ! ( x1 >> tmp ) && tmp ) tmp -- ; } else { block = 2 ; tmp = 3 ; while ( ! ( x >> tmp ) && tmp ) tmp -- ; } } else { x1 = ( val >> 4 ) & 0x000F ; if ( x1 ) { block = 1 ; tmp = 3 ; while ( ! ( x1 >> tmp ) && tmp ) tmp -- ; } else { block = 0 ; tmp = 3 ; while ( ! ( val >> tmp ) && tmp ) tmp -- ; } } } cnt = 4 * block + tmp + 1 ; return cnt ; #endif }
This function counts leading zeros in given positive integer
This function counts leading zeros in given positive integer
//x1 = (val >> 16) & 0x000F;