blob: 1b3f1a0c25f158cd6dbf3b0106bf06ca933c3ae1 [file] [log] [blame]
Aneesh V2c451f72011-06-16 23:30:47 +00001/*
2 * (C) Copyright 2010
3 * Texas Instruments, <www.ti.com>
4 * Aneesh V <aneesh@ti.com>
5 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02006 * SPDX-License-Identifier: GPL-2.0+
Aneesh V2c451f72011-06-16 23:30:47 +00007 */
8#ifndef _UTILS_H_
9#define _UTILS_H_
10
11static 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
27static 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