1 /* 2 * Copyright (c) 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_PORTABILITY_MACROS_H 12 #define ZSTD_PORTABILITY_MACROS_H 13 14 /* 15 * This header file contains macro defintions to support portability. 16 * This header is shared between C and ASM code, so it MUST only 17 * contain macro definitions. It MUST not contain any C code. 18 * 19 * This header ONLY defines macros to detect platforms/feature support. 20 * 21 */ 22 23 /* compat. with non-clang compilers */ 24 #ifndef __has_attribute 25 #define __has_attribute(x) 0 26 #endif 27 28 /* compat. with non-clang compilers */ 29 #ifndef __has_builtin 30 # define __has_builtin(x) 0 31 #endif 32 33 /* compat. with non-clang compilers */ 34 #ifndef __has_feature 35 # define __has_feature(x) 0 36 #endif 37 38 /* detects whether we are being compiled under msan */ 39 40 /* detects whether we are being compiled under asan */ 41 42 /* detects whether we are being compiled under dfsan */ 43 44 /* Mark the internal assembly functions as hidden */ 45 #ifdef __ELF__ 46 # define ZSTD_HIDE_ASM_FUNCTION(func) .hidden func 47 #else 48 # define ZSTD_HIDE_ASM_FUNCTION(func) 49 #endif 50 51 /* Enable runtime BMI2 dispatch based on the CPU. 52 * Enabled for clang & gcc >=4.8 on x86 when BMI2 isn't enabled by default. 53 */ 54 #ifndef DYNAMIC_BMI2 55 #if ((defined(__clang__) && __has_attribute(__target__)) \ 56 || (defined(__GNUC__) \ 57 && (__GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)))) \ 58 && (defined(__x86_64__) || defined(_M_X64)) \ 59 && !defined(__BMI2__) 60 # define DYNAMIC_BMI2 1 61 #else 62 # define DYNAMIC_BMI2 0 63 #endif 64 #endif 65 66 /* 67 * Only enable assembly for GNUC comptabile compilers, 68 * because other platforms may not support GAS assembly syntax. 69 * 70 * Only enable assembly for Linux / MacOS, other platforms may 71 * work, but they haven't been tested. This could likely be 72 * extended to BSD systems. 73 * 74 * Disable assembly when MSAN is enabled, because MSAN requires 75 * 100% of code to be instrumented to work. 76 */ 77 #define ZSTD_ASM_SUPPORTED 1 78 79 /* 80 * Determines whether we should enable assembly for x86-64 81 * with BMI2. 82 * 83 * Enable if all of the following conditions hold: 84 * - ASM hasn't been explicitly disabled by defining ZSTD_DISABLE_ASM 85 * - Assembly is supported 86 * - We are compiling for x86-64 and either: 87 * - DYNAMIC_BMI2 is enabled 88 * - BMI2 is supported at compile time 89 */ 90 #define ZSTD_ENABLE_ASM_X86_64_BMI2 0 91 92 #endif /* ZSTD_PORTABILITY_MACROS_H */ 93