xref: /DragonStub/inc/dragonstub/linux/const.h (revision f412fd2a1a248b546b7085648dece8d908077fab)
1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 /* const.h: Macros for dealing with constants.  */
3 #pragma once
4 
5 #ifndef _UAPI_LINUX_CONST_H
6 #define _UAPI_LINUX_CONST_H
7 
8 /* Some constant macros are used in both assembler and
9  * C code.  Therefore we cannot annotate them always with
10  * 'UL' and other type specifiers unilaterally.  We
11  * use the following macros to deal with this.
12  *
13  * Similarly, _AT() will cast an expression with a type in C, but
14  * leave it unchanged in asm.
15  */
16 
17 #ifdef __ASSEMBLY__
18 #define _AC(X,Y)	X
19 #define _AT(T,X)	X
20 #else
21 #define __AC(X,Y)	(X##Y)
22 #define _AC(X,Y)	__AC(X,Y)
23 #define _AT(T,X)	((T)(X))
24 #endif
25 
26 #define _UL(x)		(_AC(x, UL))
27 #define _ULL(x)		(_AC(x, ULL))
28 
29 #define _BITUL(x)	(_UL(1) << (x))
30 #define _BITULL(x)	(_ULL(1) << (x))
31 
32 #define __ALIGN_KERNEL(x, a)		__ALIGN_KERNEL_MASK(x, (__typeof__(x))(a) - 1)
33 #define __ALIGN_KERNEL_MASK(x, mask)	(((x) + (mask)) & ~(mask))
34 
35 #define __KERNEL_DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
36 
37 /*
38  * This returns a constant expression while determining if an argument is
39  * a constant expression, most importantly without evaluating the argument.
40  * Glory to Martin Uecker <Martin.Uecker@med.uni-goettingen.de>
41  */
42 #define __is_constexpr(x) \
43 	(sizeof(int) == sizeof(*(8 ? ((void *)((long)(x) * 0l)) : (int *)8)))
44 
45 #endif /* _UAPI_LINUX_CONST_H */
46