16f52b16cSGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2607ca46eSDavid Howells /* const.h: Macros for dealing with constants. */ 3607ca46eSDavid Howells 42a6cc8a6SMasahiro Yamada #ifndef _UAPI_LINUX_CONST_H 52a6cc8a6SMasahiro Yamada #define _UAPI_LINUX_CONST_H 6607ca46eSDavid Howells 7607ca46eSDavid Howells /* Some constant macros are used in both assembler and 8607ca46eSDavid Howells * C code. Therefore we cannot annotate them always with 9607ca46eSDavid Howells * 'UL' and other type specifiers unilaterally. We 10607ca46eSDavid Howells * use the following macros to deal with this. 11607ca46eSDavid Howells * 12607ca46eSDavid Howells * Similarly, _AT() will cast an expression with a type in C, but 13607ca46eSDavid Howells * leave it unchanged in asm. 14607ca46eSDavid Howells */ 15607ca46eSDavid Howells 16607ca46eSDavid Howells #ifdef __ASSEMBLY__ 17607ca46eSDavid Howells #define _AC(X,Y) X 18607ca46eSDavid Howells #define _AT(T,X) X 19607ca46eSDavid Howells #else 20607ca46eSDavid Howells #define __AC(X,Y) (X##Y) 21607ca46eSDavid Howells #define _AC(X,Y) __AC(X,Y) 22607ca46eSDavid Howells #define _AT(T,X) ((T)(X)) 23607ca46eSDavid Howells #endif 24607ca46eSDavid Howells 252dd8a62cSMasahiro Yamada #define _UL(x) (_AC(x, UL)) 262dd8a62cSMasahiro Yamada #define _ULL(x) (_AC(x, ULL)) 272dd8a62cSMasahiro Yamada 2821e7bc60SMasahiro Yamada #define _BITUL(x) (_UL(1) << (x)) 2921e7bc60SMasahiro Yamada #define _BITULL(x) (_ULL(1) << (x)) 302fc016c5SH. Peter Anvin 31947697c6SAnshuman Khandual #if !defined(__ASSEMBLY__) 32947697c6SAnshuman Khandual /* 33947697c6SAnshuman Khandual * Missing asm support 34947697c6SAnshuman Khandual * 35947697c6SAnshuman Khandual * __BIT128() would not work in the asm code, as it shifts an 36*0312e94aSVincent Mailhol * 'unsigned __int128' data type as direct representation of 37947697c6SAnshuman Khandual * 128 bit constants is not supported in the gcc compiler, as 38947697c6SAnshuman Khandual * they get silently truncated. 39947697c6SAnshuman Khandual * 40947697c6SAnshuman Khandual * TODO: Please revisit this implementation when gcc compiler 41947697c6SAnshuman Khandual * starts representing 128 bit constants directly like long 42947697c6SAnshuman Khandual * and unsigned long etc. Subsequently drop the comment for 43947697c6SAnshuman Khandual * GENMASK_U128() which would then start supporting asm code. 44947697c6SAnshuman Khandual */ 45947697c6SAnshuman Khandual #define _BIT128(x) ((unsigned __int128)(1) << (x)) 46947697c6SAnshuman Khandual #endif 47947697c6SAnshuman Khandual 4831088f6fSKevin Brodsky #define __ALIGN_KERNEL(x, a) __ALIGN_KERNEL_MASK(x, (__typeof__(x))(a) - 1) 49a85cbe61SPetr Vorel #define __ALIGN_KERNEL_MASK(x, mask) (((x) + (mask)) & ~(mask)) 50a85cbe61SPetr Vorel 51a85cbe61SPetr Vorel #define __KERNEL_DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) 52a85cbe61SPetr Vorel 532a6cc8a6SMasahiro Yamada #endif /* _UAPI_LINUX_CONST_H */ 54