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