forked from andreiw/RaspberryPiPkg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Utils.h
45 lines (37 loc) · 1.68 KB
/
Utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/** @file
*
* Copyright (c), 2018, Andrei Warkentin <andrey.warkentin@gmail.com>
*
* This program and the accompanying materials
* are licensed and made available under the terms and conditions of the BSD License
* which accompanies this distribution. The full text of the license may be found at
* http://opensource.org/licenses/bsd-license.php
*
* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
*
**/
#ifndef UTILS_H
#define UTILS_H
#define _IX_BITS(sm, bg) ((bg) - (sm) + 1)
#define _IX_MASK(sm, bg) ((1ul << _IX_BITS((sm), (bg))) - 1)
#define _X(val, sm, bg) ((val) >> (sm)) & _IX_MASK((sm), (bg))
#define X(val, ix1, ix2) (((ix1) < (ix2)) ? _X((val), (ix1), (ix2)) : \
_X((val), (ix2), (ix1)))
#define _I(val, sm, bg) (((val) & _IX_MASK((sm), (bg))) << (sm))
#define I(val, ix1, ix2) (((ix1) < (ix2)) ? _I((val), (ix1), (ix2)) : \
_I((val), (ix2), (ix1)))
#define _M(val, sm, bg) ((val) & (_IX_MASK((sm), (bg)) << (sm)))
#define M(val, ix1, ix2) (((ix1) < (ix2)) ? _M((val), (ix1), (ix2)) : \
_M((val), (ix2), (ix1)))
#define A_UP(Value, Alignment) (((Value) + (Alignment) - 1) & (~((Alignment) - 1)))
#define A_DOWN(Value, Alignment) ((Value) & (~((Alignment) - 1)))
#define IS_ALIGNED(Value, Alignment) (((UINTN) (Value) & (Alignment - 1)) == 0)
#define VP(x) ((VOID *)(x))
#define U8P(x) ((UINT8 *)(x))
#define U16P(x) ((UINT16 *)(x))
#define U32P(x) ((UINT32 *)(x))
#define U64P(x) ((UINT64 *)(x))
#define UN(x) ((UINTN)(x))
#define ELES(x) (sizeof((x)) / sizeof((x)[0]))
#endif /* UTILS_H */