Blender  V3.3
defines.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: Apache-2.0
2  * Copyright 2011-2022 Blender Foundation */
3 
4 /* clang-format off */
5 
6 /* #define __forceinline triggers a bug in some clang-format versions, disable
7  * format for entire file to keep results consistent. */
8 
9 #ifndef __UTIL_DEFINES_H__
10 #define __UTIL_DEFINES_H__
11 
12 /* Bitness */
13 
14 #if defined(__ppc64__) || defined(__PPC64__) || defined(__x86_64__) || defined(__ia64__) || \
15  defined(_M_X64) || defined(__aarch64__)
16 # define __KERNEL_64_BIT__
17 #endif
18 
19 /* Qualifiers for kernel code shared by CPU and GPU */
20 
21 #ifndef __KERNEL_GPU__
22 
23 /* Leave inlining decisions to compiler for these, the inline keyword here
24  * is not about performance but including function definitions in headers. */
25 # define ccl_device static inline
26 # define ccl_device_noinline static inline
27 # define ccl_device_noinline_cpu ccl_device_noinline
28 
29 /* Forced inlining. */
30 # if defined(_WIN32) && !defined(FREE_WINDOWS)
31 # define ccl_device_inline static __forceinline
32 # define ccl_device_forceinline static __forceinline
33 # define ccl_device_inline_method __forceinline
34 # define ccl_align(...) __declspec(align(__VA_ARGS__))
35 # ifdef __KERNEL_64_BIT__
36 # define ccl_try_align(...) __declspec(align(__VA_ARGS__))
37 # else /* __KERNEL_64_BIT__ */
38 # undef __KERNEL_WITH_SSE_ALIGN__
39 /* No support for function arguments (error C2719). */
40 # define ccl_try_align(...)
41 # endif /* __KERNEL_64_BIT__ */
42 # define ccl_may_alias
43 # define ccl_always_inline __forceinline
44 # define ccl_never_inline __declspec(noinline)
45 # else /* _WIN32 && !FREE_WINDOWS */
46 # define ccl_device_inline static inline __attribute__((always_inline))
47 # define ccl_device_forceinline static inline __attribute__((always_inline))
48 # define ccl_device_inline_method __attribute__((always_inline))
49 # define ccl_align(...) __attribute__((aligned(__VA_ARGS__)))
50 # ifndef FREE_WINDOWS64
51 # define __forceinline inline __attribute__((always_inline))
52 # endif
53 # define ccl_try_align(...) __attribute__((aligned(__VA_ARGS__)))
54 # define ccl_may_alias __attribute__((__may_alias__))
55 # define ccl_always_inline __attribute__((always_inline))
56 # define ccl_never_inline __attribute__((noinline))
57 # endif /* _WIN32 && !FREE_WINDOWS */
58 
59 /* Address spaces for GPU. */
60 # define ccl_global
61 # define ccl_inline_constant inline constexpr
62 # define ccl_constant const
63 # define ccl_private
64 
65 # define ccl_restrict __restrict
66 # define ccl_optional_struct_init
67 # define ccl_loop_no_unroll
68 # define ccl_attr_maybe_unused [[maybe_unused]]
69 # define __KERNEL_WITH_SSE_ALIGN__
70 
71 /* Use to suppress '-Wimplicit-fallthrough' (in place of 'break'). */
72 # ifndef ATTR_FALLTHROUGH
73 # if defined(__GNUC__) && (__GNUC__ >= 7) /* gcc7.0+ only */
74 # define ATTR_FALLTHROUGH __attribute__((fallthrough))
75 # else
76 # define ATTR_FALLTHROUGH ((void)0)
77 # endif
78 # endif
79 #endif /* __KERNEL_GPU__ */
80 
81 /* macros */
82 
83 /* hints for branch prediction, only use in code that runs a _lot_ */
84 #if defined(__GNUC__) && !defined(__KERNEL_GPU__)
85 # define LIKELY(x) __builtin_expect(!!(x), 1)
86 # define UNLIKELY(x) __builtin_expect(!!(x), 0)
87 #else
88 # define LIKELY(x) (x)
89 # define UNLIKELY(x) (x)
90 #endif
91 
92 #ifndef __KERNEL_GPU__
93 # include <cassert>
94 # define util_assert(statement) assert(statement)
95 #else
96 # define util_assert(statement)
97 #endif
98 
99 #endif /* __UTIL_DEFINES_H__ */