XenevaOS
Loading...
Searching...
No Matches
const.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef __VDSO_CONST_H
3#define __VDSO_CONST_H
4
5/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
6/* const.h: Macros for dealing with constants. */
7
8#ifndef _UAPI_LINUX_CONST_H
9#define _UAPI_LINUX_CONST_H
10
11/* Some constant macros are used in both assembler and
12 * C code. Therefore we cannot annotate them always with
13 * 'UL' and other type specifiers unilaterally. We
14 * use the following macros to deal with this.
15 *
16 * Similarly, _AT() will cast an expression with a type in C, but
17 * leave it unchanged in asm.
18 */
19
20#ifdef __ASSEMBLY__
21#define _AC(X,Y) X
22#define _AT(T,X) X
23#else
24#define __AC(X,Y) (X##Y)
25#define _AC(X,Y) __AC(X,Y)
26#define _AT(T,X) ((T)(X))
27#endif
28
29#define _UL(x) (_AC(x, UL))
30#define _ULL(x) (_AC(x, ULL))
31
32#define _BITUL(x) (_UL(1) << (x))
33#define _BITULL(x) (_ULL(1) << (x))
34
35#if !defined(__ASSEMBLY__)
36/*
37 * Missing asm support
38 *
39 * __BIT128() would not work in the asm code, as it shifts an
40 * 'unsigned __int128' data type as direct representation of
41 * 128 bit constants is not supported in the gcc compiler, as
42 * they get silently truncated.
43 *
44 * TODO: Please revisit this implementation when gcc compiler
45 * starts representing 128 bit constants directly like long
46 * and unsigned long etc. Subsequently drop the comment for
47 * GENMASK_U128() which would then start supporting asm code.
48 */
49#define _BIT128(x) ((unsigned __int128)(1) << (x))
50#endif
51
52#define __ALIGN_KERNEL(x, a) __ALIGN_KERNEL_MASK(x, (__typeof__(x))(a) - 1)
53#define __ALIGN_KERNEL_MASK(x, mask) (((x) + (mask)) & ~(mask))
54
55#define __KERNEL_DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
56
57/*
58 * Divide positive or negative dividend by positive or negative divisor
59 * and round to closest integer. Result is undefined for negative
60 * divisors if the dividend variable type is unsigned and for negative
61 * dividends if the divisor variable type is unsigned.
62 */
63#define __KERNEL_DIV_ROUND_CLOSEST(x, divisor) \
64({ \
65 __typeof__(x) __x = x; \
66 __typeof__(divisor) __d = divisor; \
67 \
68 (((__typeof__(x))-1) > 0 || \
69 ((__typeof__(divisor))-1) > 0 || \
70 (((__x) > 0) == ((__d) > 0))) ? \
71 (((__x) + ((__d) / 2)) / (__d)) : \
72 (((__x) - ((__d) / 2)) / (__d)); \
73})
74
75#endif /* _UAPI_LINUX_CONST_H */
76
77
78#define UL(x) (_UL(x))
79#define ULL(x) (_ULL(x))
80
81#endif /* __VDSO_CONST_H */