Project Alice
Loading...
Searching...
No Matches
compiler.h File Reference
#include <stddef.h>
#include "portability_macros.h"
Include dependency graph for compiler.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define INLINE_KEYWORD
 
#define FORCE_INLINE_ATTR
 
#define WIN_CDECL
 
#define UNUSED_ATTR
 
#define FORCE_INLINE_TEMPLATE   static INLINE_KEYWORD FORCE_INLINE_ATTR UNUSED_ATTR
 
#define HINT_INLINE   FORCE_INLINE_TEMPLATE
 
#define MEM_STATIC   static /* this version may generate warnings for unused static functions; disable the relevant warning */
 
#define FORCE_NOINLINE   static
 
#define TARGET_ATTRIBUTE(target)
 
#define BMI2_TARGET_ATTRIBUTE   TARGET_ATTRIBUTE("lzcnt,bmi,bmi2")
 
#define PREFETCH_L1(ptr)   do { (void)(ptr); } while (0) /* disabled */
 
#define PREFETCH_L2(ptr)   do { (void)(ptr); } while (0) /* disabled */
 
#define CACHELINE_SIZE   64
 
#define PREFETCH_AREA(p, s)
 
#define DONT_VECTORIZE
 
#define LIKELY(x)   (x)
 
#define UNLIKELY(x)   (x)
 
#define ZSTD_UNREACHABLE   do { assert(0); } while (0)
 
#define STATIC_BMI2   0
 
#define ZSTD_HAS_C_ATTRIBUTE(x)   0
 
#define ZSTD_HAS_CPP_ATTRIBUTE(x)   0
 
#define ZSTD_FALLTHROUGH
 
#define ZSTD_ALIGNOF(T)   (sizeof(void*) < sizeof(T) ? sizeof(void*) : sizeof(T))
 
#define ZSTD_ALLOW_POINTER_OVERFLOW_ATTR
 

Functions

MEM_STATIC ZSTD_ALLOW_POINTER_OVERFLOW_ATTR ptrdiff_t ZSTD_wrappedPtrDiff (unsigned char const *lhs, unsigned char const *rhs)
 
MEM_STATIC ZSTD_ALLOW_POINTER_OVERFLOW_ATTR unsigned char const * ZSTD_wrappedPtrAdd (unsigned char const *ptr, ptrdiff_t add)
 
MEM_STATIC ZSTD_ALLOW_POINTER_OVERFLOW_ATTR unsigned char const * ZSTD_wrappedPtrSub (unsigned char const *ptr, ptrdiff_t sub)
 
MEM_STATIC unsigned char * ZSTD_maybeNullPtrAdd (unsigned char *ptr, ptrdiff_t add)
 

Macro Definition Documentation

◆ BMI2_TARGET_ATTRIBUTE

#define BMI2_TARGET_ATTRIBUTE   TARGET_ATTRIBUTE("lzcnt,bmi,bmi2")

Definition at line 130 of file compiler.h.

◆ CACHELINE_SIZE

#define CACHELINE_SIZE   64

Definition at line 154 of file compiler.h.

◆ DONT_VECTORIZE

#define DONT_VECTORIZE

Definition at line 176 of file compiler.h.

◆ FORCE_INLINE_ATTR

#define FORCE_INLINE_ATTR

Definition at line 35 of file compiler.h.

◆ FORCE_INLINE_TEMPLATE

#define FORCE_INLINE_TEMPLATE   static INLINE_KEYWORD FORCE_INLINE_ATTR UNUSED_ATTR

FORCE_INLINE_TEMPLATE is used to define C "templates", which take constant parameters. They must be inlined for the compiler to eliminate the constant branches.

Definition at line 68 of file compiler.h.

◆ FORCE_NOINLINE

#define FORCE_NOINLINE   static

Definition at line 114 of file compiler.h.

◆ HINT_INLINE

#define HINT_INLINE   FORCE_INLINE_TEMPLATE

HINT_INLINE is used to help the compiler generate better code. It is not used for "templates", so it can be tweaked based on the compilers performance.

gcc-4.8 and gcc-4.9 have been shown to benefit from leaving off the always_inline attribute.

clang up to 5.0.0 (trunk) benefit tremendously from the always_inline attribute.

Definition at line 83 of file compiler.h.

◆ INLINE_KEYWORD

#define INLINE_KEYWORD

Definition at line 27 of file compiler.h.

◆ LIKELY

#define LIKELY (   x)    (x)

Definition at line 188 of file compiler.h.

◆ MEM_STATIC

#define MEM_STATIC   static /* this version may generate warnings for unused static functions; disable the relevant warning */

Definition at line 103 of file compiler.h.

◆ PREFETCH_AREA

#define PREFETCH_AREA (   p,
 
)
Value:
do { \
const char* const _ptr = (const char*)(p); \
size_t const _size = (size_t)(s); \
size_t _pos; \
for (_pos=0; _pos<_size; _pos+=CACHELINE_SIZE) { \
PREFETCH_L2(_ptr + _pos); \
} \
} while (0)
#define CACHELINE_SIZE
Definition: compiler.h:154

Definition at line 156 of file compiler.h.

◆ PREFETCH_L1

#define PREFETCH_L1 (   ptr)    do { (void)(ptr); } while (0) /* disabled */

Definition at line 149 of file compiler.h.

◆ PREFETCH_L2

#define PREFETCH_L2 (   ptr)    do { (void)(ptr); } while (0) /* disabled */

Definition at line 150 of file compiler.h.

◆ STATIC_BMI2

#define STATIC_BMI2   0

Definition at line 220 of file compiler.h.

◆ TARGET_ATTRIBUTE

#define TARGET_ATTRIBUTE (   target)

Definition at line 123 of file compiler.h.

◆ UNLIKELY

#define UNLIKELY (   x)    (x)

Definition at line 189 of file compiler.h.

◆ UNUSED_ATTR

#define UNUSED_ATTR

Definition at line 60 of file compiler.h.

◆ WIN_CDECL

#define WIN_CDECL

On MSVC qsort requires that functions passed into it use the __cdecl calling conversion(CC). This explicitly marks such functions as __cdecl so that the code will still compile if a CC other than __cdecl has been made the default.

Definition at line 53 of file compiler.h.

◆ ZSTD_ALIGNOF

#define ZSTD_ALIGNOF (   T)    (sizeof(void*) < sizeof(T) ? sizeof(void*) : sizeof(T))

Definition at line 299 of file compiler.h.

◆ ZSTD_ALLOW_POINTER_OVERFLOW_ATTR

#define ZSTD_ALLOW_POINTER_OVERFLOW_ATTR

Zstd relies on pointer overflow in its decompressor. We add this attribute to functions that rely on pointer overflow.

Definition at line 322 of file compiler.h.

◆ ZSTD_FALLTHROUGH

#define ZSTD_FALLTHROUGH

Definition at line 271 of file compiler.h.

◆ ZSTD_HAS_C_ATTRIBUTE

#define ZSTD_HAS_C_ATTRIBUTE (   x)    0

Definition at line 243 of file compiler.h.

◆ ZSTD_HAS_CPP_ATTRIBUTE

#define ZSTD_HAS_CPP_ATTRIBUTE (   x)    0

Definition at line 252 of file compiler.h.

◆ ZSTD_UNREACHABLE

#define ZSTD_UNREACHABLE   do { assert(0); } while (0)

Definition at line 195 of file compiler.h.

Function Documentation

◆ ZSTD_maybeNullPtrAdd()

MEM_STATIC unsigned char * ZSTD_maybeNullPtrAdd ( unsigned char *  ptr,
ptrdiff_t  add 
)

Helper function to add to a pointer that works around C's undefined behavior of adding 0 to NULL.

Returns
ptr + add except it defines NULL + 0 == NULL.

Definition at line 371 of file compiler.h.

Here is the caller graph for this function:

◆ ZSTD_wrappedPtrAdd()

MEM_STATIC ZSTD_ALLOW_POINTER_OVERFLOW_ATTR unsigned char const * ZSTD_wrappedPtrAdd ( unsigned char const *  ptr,
ptrdiff_t  add 
)

Helper function to perform a wrapped pointer add without triggering UBSAN.

Returns
ptr + add with wrapping

Definition at line 346 of file compiler.h.

◆ ZSTD_wrappedPtrDiff()

MEM_STATIC ZSTD_ALLOW_POINTER_OVERFLOW_ATTR ptrdiff_t ZSTD_wrappedPtrDiff ( unsigned char const *  lhs,
unsigned char const *  rhs 
)

Helper function to perform a wrapped pointer difference without trigging UBSAN.

Returns
lhs - rhs with wrapping

Definition at line 334 of file compiler.h.

◆ ZSTD_wrappedPtrSub()

MEM_STATIC ZSTD_ALLOW_POINTER_OVERFLOW_ATTR unsigned char const * ZSTD_wrappedPtrSub ( unsigned char const *  ptr,
ptrdiff_t  sub 
)

Helper function to perform a wrapped pointer subtraction without triggering UBSAN.

Returns
ptr - sub with wrapping

Definition at line 359 of file compiler.h.