1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  * Copyright(c) 2018 Intel Corporation. All rights reserved.
4  *
5  * Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
6  */
7 
8 #ifndef __SOF_BIT_H__
9 #define __SOF_BIT_H__
10 
11 /* Zephyr defines this - remove local copy once Zephyr integration complete */
12 #ifdef BIT
13 #undef BIT
14 #endif
15 
16 #if ASSEMBLY
17 #define BIT(b)			(1 << (b))
18 #else
19 #define BIT(b)			(1UL << (b))
20 #endif
21 
22 #define MASK(b_hi, b_lo)	\
23 	(((1ULL << ((b_hi) - (b_lo) + 1ULL)) - 1ULL) << (b_lo))
24 #define SET_BIT(b, x)		(((x) & 1) << (b))
25 #define SET_BITS(b_hi, b_lo, x)	\
26 	(((x) & ((1ULL << ((b_hi) - (b_lo) + 1ULL)) - 1ULL)) << (b_lo))
27 #define GET_BIT(b, x) \
28 	(((x) & (1ULL << (b))) >> (b))
29 #define GET_BITS(b_hi, b_lo, x) \
30 	(((x) & MASK(b_hi, b_lo)) >> (b_lo))
31 
32 #endif /* __SOF_BIT_H__ */
33