xref: /qemu/linux-headers/linux/const.h (revision 7be29f2f1a3f5b037d27eedbd5df9f441e8c8c16)
1c5c0fdbeSDavid 'Digit' Turner /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2c5c0fdbeSDavid 'Digit' Turner /* const.h: Macros for dealing with constants.  */
3c5c0fdbeSDavid 'Digit' Turner 
4c5c0fdbeSDavid 'Digit' Turner #ifndef _LINUX_CONST_H
5c5c0fdbeSDavid 'Digit' Turner #define _LINUX_CONST_H
6c5c0fdbeSDavid 'Digit' Turner 
7c5c0fdbeSDavid 'Digit' Turner /* Some constant macros are used in both assembler and
8c5c0fdbeSDavid 'Digit' Turner  * C code.  Therefore we cannot annotate them always with
9c5c0fdbeSDavid 'Digit' Turner  * 'UL' and other type specifiers unilaterally.  We
10c5c0fdbeSDavid 'Digit' Turner  * use the following macros to deal with this.
11c5c0fdbeSDavid 'Digit' Turner  *
12c5c0fdbeSDavid 'Digit' Turner  * Similarly, _AT() will cast an expression with a type in C, but
13c5c0fdbeSDavid 'Digit' Turner  * leave it unchanged in asm.
14c5c0fdbeSDavid 'Digit' Turner  */
15c5c0fdbeSDavid 'Digit' Turner 
16c5c0fdbeSDavid 'Digit' Turner #ifdef __ASSEMBLY__
17c5c0fdbeSDavid 'Digit' Turner #define _AC(X,Y)	X
18c5c0fdbeSDavid 'Digit' Turner #define _AT(T,X)	X
19c5c0fdbeSDavid 'Digit' Turner #else
20c5c0fdbeSDavid 'Digit' Turner #define __AC(X,Y)	(X##Y)
21c5c0fdbeSDavid 'Digit' Turner #define _AC(X,Y)	__AC(X,Y)
22c5c0fdbeSDavid 'Digit' Turner #define _AT(T,X)	((T)(X))
23c5c0fdbeSDavid 'Digit' Turner #endif
24c5c0fdbeSDavid 'Digit' Turner 
25c5c0fdbeSDavid 'Digit' Turner #define _UL(x)		(_AC(x, UL))
26c5c0fdbeSDavid 'Digit' Turner #define _ULL(x)		(_AC(x, ULL))
27c5c0fdbeSDavid 'Digit' Turner 
28c5c0fdbeSDavid 'Digit' Turner #define _BITUL(x)	(_UL(1) << (x))
29c5c0fdbeSDavid 'Digit' Turner #define _BITULL(x)	(_ULL(1) << (x))
30c5c0fdbeSDavid 'Digit' Turner 
310d2eeef7SBibo Mao #if !defined(__ASSEMBLY__)
320d2eeef7SBibo Mao /*
330d2eeef7SBibo Mao  * Missing __asm__ support
340d2eeef7SBibo Mao  *
350d2eeef7SBibo Mao  * __BIT128() would not work in the __asm__ code, as it shifts an
36*1cab5a02SRorie Reyes  * 'unsigned __int128' data type as direct representation of
370d2eeef7SBibo Mao  * 128 bit constants is not supported in the gcc compiler, as
380d2eeef7SBibo Mao  * they get silently truncated.
390d2eeef7SBibo Mao  *
400d2eeef7SBibo Mao  * TODO: Please revisit this implementation when gcc compiler
410d2eeef7SBibo Mao  * starts representing 128 bit constants directly like long
420d2eeef7SBibo Mao  * and unsigned long etc. Subsequently drop the comment for
430d2eeef7SBibo Mao  * GENMASK_U128() which would then start supporting __asm__ code.
440d2eeef7SBibo Mao  */
450d2eeef7SBibo Mao #define _BIT128(x)	((unsigned __int128)(1) << (x))
460d2eeef7SBibo Mao #endif
470d2eeef7SBibo Mao 
48d0bf492fSCédric Le Goater #define __ALIGN_KERNEL(x, a)		__ALIGN_KERNEL_MASK(x, (__typeof__(x))(a) - 1)
49c5c0fdbeSDavid 'Digit' Turner #define __ALIGN_KERNEL_MASK(x, mask)	(((x) + (mask)) & ~(mask))
50c5c0fdbeSDavid 'Digit' Turner 
51c5c0fdbeSDavid 'Digit' Turner #define __KERNEL_DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
52c5c0fdbeSDavid 'Digit' Turner 
53c5c0fdbeSDavid 'Digit' Turner #endif /* _LINUX_CONST_H */
54