xref: /openbmc/u-boot/arch/arm/include/asm/utils.h (revision 23ff8633)
1 /*
2  * (C) Copyright 2010
3  * Texas Instruments, <www.ti.com>
4  * Aneesh V <aneesh@ti.com>
5  *
6  * SPDX-License-Identifier:	GPL-2.0+
7  */
8 #ifndef _UTILS_H_
9 #define _UTILS_H_
10 
11 static inline s32 log_2_n_round_up(u32 n)
12 {
13 	s32 log2n = -1;
14 	u32 temp = n;
15 
16 	while (temp) {
17 		log2n++;
18 		temp >>= 1;
19 	}
20 
21 	if (n & (n - 1))
22 		return log2n + 1; /* not power of 2 - round up */
23 	else
24 		return log2n; /* power of 2 */
25 }
26 
27 static inline s32 log_2_n_round_down(u32 n)
28 {
29 	s32 log2n = -1;
30 	u32 temp = n;
31 
32 	while (temp) {
33 		log2n++;
34 		temp >>= 1;
35 	}
36 
37 	return log2n;
38 }
39 
40 #endif
41