xref: /qemu/subprojects/libvduse/standard-headers/linux/const.h (revision 7be29f2f1a3f5b037d27eedbd5df9f441e8c8c16)
1b3c818a4SEric Farman /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2b3c818a4SEric Farman /* const.h: Macros for dealing with constants.  */
3b3c818a4SEric Farman 
4b3c818a4SEric Farman #ifndef _LINUX_CONST_H
5b3c818a4SEric Farman #define _LINUX_CONST_H
6b3c818a4SEric Farman 
7b3c818a4SEric Farman /* Some constant macros are used in both assembler and
8b3c818a4SEric Farman  * C code.  Therefore we cannot annotate them always with
9b3c818a4SEric Farman  * 'UL' and other type specifiers unilaterally.  We
10b3c818a4SEric Farman  * use the following macros to deal with this.
11b3c818a4SEric Farman  *
12b3c818a4SEric Farman  * Similarly, _AT() will cast an expression with a type in C, but
13b3c818a4SEric Farman  * leave it unchanged in asm.
14b3c818a4SEric Farman  */
15b3c818a4SEric Farman 
16b3c818a4SEric Farman #ifdef __ASSEMBLY__
17b3c818a4SEric Farman #define _AC(X,Y)	X
18b3c818a4SEric Farman #define _AT(T,X)	X
19b3c818a4SEric Farman #else
20b3c818a4SEric Farman #define __AC(X,Y)	(X##Y)
21b3c818a4SEric Farman #define _AC(X,Y)	__AC(X,Y)
22b3c818a4SEric Farman #define _AT(T,X)	((T)(X))
23b3c818a4SEric Farman #endif
24b3c818a4SEric Farman 
25b3c818a4SEric Farman #define _UL(x)		(_AC(x, UL))
26b3c818a4SEric Farman #define _ULL(x)		(_AC(x, ULL))
27b3c818a4SEric Farman 
28b3c818a4SEric Farman #define _BITUL(x)	(_UL(1) << (x))
29b3c818a4SEric Farman #define _BITULL(x)	(_ULL(1) << (x))
30b3c818a4SEric Farman 
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)
49b3c818a4SEric Farman #define __ALIGN_KERNEL_MASK(x, mask)	(((x) + (mask)) & ~(mask))
50b3c818a4SEric Farman 
51b3c818a4SEric Farman #define __KERNEL_DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
52b3c818a4SEric Farman 
53b3c818a4SEric Farman #endif /* _LINUX_CONST_H */
54