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