xref: /rk3399_ARM-atf/include/lib/utils.h (revision ed81f3ebbfb5abc7d0d250fbc71f297a904d71ae)
1*ed81f3ebSSandrine Bailleux /*
2*ed81f3ebSSandrine Bailleux  * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved.
3*ed81f3ebSSandrine Bailleux  *
4*ed81f3ebSSandrine Bailleux  * Redistribution and use in source and binary forms, with or without
5*ed81f3ebSSandrine Bailleux  * modification, are permitted provided that the following conditions are met:
6*ed81f3ebSSandrine Bailleux  *
7*ed81f3ebSSandrine Bailleux  * Redistributions of source code must retain the above copyright notice, this
8*ed81f3ebSSandrine Bailleux  * list of conditions and the following disclaimer.
9*ed81f3ebSSandrine Bailleux  *
10*ed81f3ebSSandrine Bailleux  * Redistributions in binary form must reproduce the above copyright notice,
11*ed81f3ebSSandrine Bailleux  * this list of conditions and the following disclaimer in the documentation
12*ed81f3ebSSandrine Bailleux  * and/or other materials provided with the distribution.
13*ed81f3ebSSandrine Bailleux  *
14*ed81f3ebSSandrine Bailleux  * Neither the name of ARM nor the names of its contributors may be used
15*ed81f3ebSSandrine Bailleux  * to endorse or promote products derived from this software without specific
16*ed81f3ebSSandrine Bailleux  * prior written permission.
17*ed81f3ebSSandrine Bailleux  *
18*ed81f3ebSSandrine Bailleux  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19*ed81f3ebSSandrine Bailleux  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20*ed81f3ebSSandrine Bailleux  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21*ed81f3ebSSandrine Bailleux  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22*ed81f3ebSSandrine Bailleux  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23*ed81f3ebSSandrine Bailleux  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24*ed81f3ebSSandrine Bailleux  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25*ed81f3ebSSandrine Bailleux  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26*ed81f3ebSSandrine Bailleux  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27*ed81f3ebSSandrine Bailleux  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28*ed81f3ebSSandrine Bailleux  * POSSIBILITY OF SUCH DAMAGE.
29*ed81f3ebSSandrine Bailleux  */
30*ed81f3ebSSandrine Bailleux 
31*ed81f3ebSSandrine Bailleux #ifndef __UTILS_H__
32*ed81f3ebSSandrine Bailleux #define __UTILS_H__
33*ed81f3ebSSandrine Bailleux 
34*ed81f3ebSSandrine Bailleux /* Compute the number of elements in the given array */
35*ed81f3ebSSandrine Bailleux #define ARRAY_SIZE(a)				\
36*ed81f3ebSSandrine Bailleux 	(sizeof(a) / sizeof((a)[0]))
37*ed81f3ebSSandrine Bailleux 
38*ed81f3ebSSandrine Bailleux #define IS_POWER_OF_TWO(x)			\
39*ed81f3ebSSandrine Bailleux 	(((x) & ((x) - 1)) == 0)
40*ed81f3ebSSandrine Bailleux 
41*ed81f3ebSSandrine Bailleux #endif /* __UTILS_H__ */
42