• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #pragma once
2 
3 #include <stdint.h>
4 
5 
bit_length(uint32_t n)6 inline static uint32_t bit_length(uint32_t n) {
7 	const uint32_t n_minus_1 = n - 1;
8 	if (n_minus_1 == 0) {
9 		return 0;
10 	} else {
11 		#ifdef _MSC_VER
12 			unsigned long bsr;
13 			_BitScanReverse(&bsr, n_minus_1);
14 			return bsr + 1;
15 		#else
16 			return 32 - __builtin_clz(n_minus_1);
17 		#endif
18 	}
19 }
20