ReactOS
0.4.17-dev-1343-g8fe3cee
compiler.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2016-2020, Yann Collet, Facebook, Inc.
3
* All rights reserved.
4
*
5
* This source code is licensed under both the BSD-style license (found in the
6
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
7
* in the COPYING file in the root directory of this source tree).
8
* You may select, at your option, one of the above-listed licenses.
9
*/
10
11
#ifndef ZSTD_COMPILER_H
12
#define ZSTD_COMPILER_H
13
14
/*-*******************************************************
15
* Compiler specifics
16
*********************************************************/
17
/* force inlining */
18
19
#if !defined(ZSTD_NO_INLINE)
20
#if (defined(__GNUC__) && !defined(__STRICT_ANSI__)) || defined(__cplusplus) || defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
/* C99 */
21
# define INLINE_KEYWORD inline
22
#else
23
# define INLINE_KEYWORD
24
#endif
25
26
#if defined(__GNUC__) || defined(__ICCARM__)
27
# define FORCE_INLINE_ATTR __attribute__((always_inline))
28
#elif defined(_MSC_VER)
29
# define FORCE_INLINE_ATTR __forceinline
30
#else
31
# define FORCE_INLINE_ATTR
32
#endif
33
34
#else
35
36
#define INLINE_KEYWORD
37
#define FORCE_INLINE_ATTR
38
39
#endif
40
46
#define FORCE_INLINE_TEMPLATE static INLINE_KEYWORD FORCE_INLINE_ATTR
58
#if !defined(__clang__) && defined(__GNUC__) && __GNUC__ >= 4 && __GNUC_MINOR__ >= 8 && __GNUC__ < 5
59
# define HINT_INLINE static INLINE_KEYWORD
60
#else
61
# define HINT_INLINE static INLINE_KEYWORD FORCE_INLINE_ATTR
62
#endif
63
64
/* UNUSED_ATTR tells the compiler it is okay if the function is unused. */
65
#if defined(__GNUC__)
66
# define UNUSED_ATTR __attribute__((unused))
67
#else
68
# define UNUSED_ATTR
69
#endif
70
71
/* force no inlining */
72
#ifdef _MSC_VER
73
# define FORCE_NOINLINE static __declspec(noinline)
74
#else
75
# if defined(__GNUC__) || defined(__ICCARM__)
76
# define FORCE_NOINLINE static __attribute__((__noinline__))
77
# else
78
# define FORCE_NOINLINE static
79
# endif
80
#endif
81
82
/* target attribute */
83
#ifndef __has_attribute
84
#define __has_attribute(x) 0
/* Compatibility with non-clang compilers. */
85
#endif
86
#if defined(__GNUC__) || defined(__ICCARM__)
87
# define TARGET_ATTRIBUTE(target) __attribute__((__target__(target)))
88
#else
89
# define TARGET_ATTRIBUTE(target)
90
#endif
91
92
/* Enable runtime BMI2 dispatch based on the CPU.
93
* Enabled for clang & gcc >=4.8 on x86 when BMI2 isn't enabled by default.
94
*/
95
#ifndef DYNAMIC_BMI2
96
#if ((defined(__clang__) && __has_attribute(__target__)) \
97
|| (defined(__GNUC__) \
98
&& (__GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)))) \
99
&& (defined(__x86_64__) || defined(_M_X86)) \
100
&& !defined(__BMI2__)
101
# define DYNAMIC_BMI2 1
102
#else
103
# define DYNAMIC_BMI2 0
104
#endif
105
#endif
106
107
/* prefetch
108
* can be disabled, by declaring NO_PREFETCH build macro */
109
#if defined(NO_PREFETCH)
110
# define PREFETCH_L1(ptr) (void)(ptr)
/* disabled */
111
# define PREFETCH_L2(ptr) (void)(ptr)
/* disabled */
112
#else
113
# if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_I86))
/* _mm_prefetch() is not defined outside of x86/x64 */
114
# include <
mmintrin.h
>
/* https://learn.microsoft.com/fr-fr/previous-versions/visualstudio/visual-studio-2008/84szxsww(v=vs.90) */
115
# define PREFETCH_L1(ptr) _mm_prefetch((const char*)(ptr), _MM_HINT_T0)
116
# define PREFETCH_L2(ptr) _mm_prefetch((const char*)(ptr), _MM_HINT_T1)
117
# elif defined(_MSC_VER) && defined(_M_ARM64)
118
# include <intrin.h>
119
# define PREFETCH_L1(ptr) __prefetch((const void*)(ptr))
120
# define PREFETCH_L2(ptr) __prefetch2((const void*)(ptr), 2
/* pldl2keep */
)
121
# elif defined(__aarch64__)
122
# define PREFETCH_L1(ptr) __asm__ __volatile__("prfm pldl1keep, %0"
::"Q"(*(ptr)))
123
# define PREFETCH_L2(ptr) __asm__ __volatile__("prfm pldl2keep, %0"
::"Q"(*(ptr)))
124
# elif defined(__GNUC__) && ( (__GNUC__ >= 4) || ( (__GNUC__ == 3) && (__GNUC_MINOR__ >= 1) ) )
125
# define PREFETCH_L1(ptr) __builtin_prefetch((ptr), 0
/* rw==read */
, 3
/* locality */
)
126
# define PREFETCH_L2(ptr) __builtin_prefetch((ptr), 0
/* rw==read */
, 2
/* locality */
)
127
# else
128
# define PREFETCH_L1(ptr) (void)(ptr)
/* disabled */
129
# define PREFETCH_L2(ptr) (void)(ptr)
/* disabled */
130
# endif
131
#endif
/* NO_PREFETCH */
132
133
#define CACHELINE_SIZE 64
134
135
#define PREFETCH_AREA(p, s) { \
136
const char* const _ptr = (const char*)(p); \
137
size_t const _size = (size_t)(s); \
138
size_t _pos; \
139
for (_pos=0; _pos<_size; _pos+=CACHELINE_SIZE) { \
140
PREFETCH_L2(_ptr + _pos); \
141
} \
142
}
143
144
/* vectorization
145
* older GCC (pre gcc-4.3 picked as the cutoff) uses a different syntax */
146
#if !defined(__INTEL_COMPILER) && !defined(__clang__) && defined(__GNUC__)
147
# if (__GNUC__ == 4 && __GNUC_MINOR__ > 3) || (__GNUC__ >= 5)
148
# define DONT_VECTORIZE __attribute__((optimize("no-tree-vectorize"
)))
149
# else
150
# define DONT_VECTORIZE _Pragma("GCC optimize(\"no-tree-vectorize\")"
)
151
# endif
152
#else
153
# define DONT_VECTORIZE
154
#endif
155
156
/* Tell the compiler that a branch is likely or unlikely.
157
* Only use these macros if it causes the compiler to generate better code.
158
* If you can remove a LIKELY/UNLIKELY annotation without speed changes in gcc
159
* and clang, please do.
160
*/
161
#if defined(__GNUC__)
162
#define LIKELY(x) (__builtin_expect((x), 1))
163
#define UNLIKELY(x) (__builtin_expect((x), 0))
164
#else
165
#define LIKELY(x) (x)
166
#define UNLIKELY(x) (x)
167
#endif
168
169
/* disable warnings */
170
#ifdef _MSC_VER
/* Visual Studio */
171
# include <intrin.h>
/* For Visual 2005 */
172
# pragma warning(disable : 4100)
/* disable: C4100: unreferenced formal parameter */
173
# pragma warning(disable : 4127)
/* disable: C4127: conditional expression is constant */
174
# pragma warning(disable : 4204)
/* disable: C4204: non-constant aggregate initializer */
175
# pragma warning(disable : 4214)
/* disable: C4214: non-int bitfields */
176
# pragma warning(disable : 4324)
/* disable: C4324: padded structure */
177
#endif
178
179
#endif
/* ZSTD_COMPILER_H */
mmintrin.h
drivers
filesystems
btrfs
zstd
compiler.h
Generated on Wed Nov 11 2026 06:22:46 for ReactOS by
1.9.6