Serialbox
2.2.0
Data serialization library and tools for C/C++, Python and Fortran
Compiler.h
Go to the documentation of this file.
1
//===-- serialbox/core/Compiler.h ---------------------------------------------------*- C++ -*-===//
2
//
3
// S E R I A L B O X
4
//
5
// This file is distributed under terms of BSD license.
6
// See LICENSE.txt for more information
7
//
8
//===------------------------------------------------------------------------------------------===//
9
//
14
//===------------------------------------------------------------------------------------------===//
15
16
#ifndef SERIALBOX_CORE_COMPILER_H
17
#define SERIALBOX_CORE_COMPILER_H
18
19
#include "serialbox/core/Config.h"
20
#include <boost/version.hpp>
21
22
#ifndef __has_feature
23
#define __has_feature(x) 0
24
#endif
25
26
#ifndef __has_extension
27
#define __has_extension(x) 0
28
#endif
29
30
#ifndef __has_attribute
31
#define __has_attribute(x) 0
32
#endif
33
34
#ifndef __has_builtin
35
#define __has_builtin(x) 0
36
#endif
37
38
#if defined(__clang__)
39
#define SERIALBOX_COMPILER_CLANG 1
40
#endif
41
42
#if defined(__ICC) || defined(__INTEL_COMPILER)
43
#define SERIALBOX_COMPILER_INTEL 1
44
#endif
45
46
#if defined(__GNUC__) || defined(__GNUG__)
47
#define SERIALBOX_COMPILER_GNU 1
48
#endif
49
50
#if defined(_MSC_VER)
51
#define SERIALBOX_COMPILER_MSVC 1
52
#endif
53
54
// Make sure the same Boost is used for linking the library
55
#if defined(SERIALBOX_BOOST_VERSION) && SERIALBOX_BOOST_VERSION != BOOST_VERSION
56
#warning "Boost version used for compilation does not match current Boost version!"
57
#endif
58
61
#ifndef SERIALBOX_GNUC_PREREQ
62
#if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__)
63
#define SERIALBOX_GNUC_PREREQ(maj, min, patch) \
64
((__GNUC__ << 20) + (__GNUC_MINOR__ << 10) + __GNUC_PATCHLEVEL__ >= \
65
((maj) << 20) + ((min) << 10) + (patch))
66
#elif defined(__GNUC__) && defined(__GNUC_MINOR__)
67
#define SERIALBOX_GNUC_PREREQ(maj, min, patch) \
68
((__GNUC__ << 20) + (__GNUC_MINOR__ << 10) >= ((maj) << 20) + ((min) << 10))
69
#else
70
#define SERIALBOX_GNUC_PREREQ(maj, min, patch) 0
71
#endif
72
#endif
73
79
#if __has_builtin(__builtin_unreachable) || SERIALBOX_GNUC_PREREQ(4, 5, 0)
80
#define SERIALBOX_BUILTIN_UNREACHABLE __builtin_unreachable()
81
#elif defined(_MSC_VER)
82
#define SERIALBOX_BUILTIN_UNREACHABLE __assume(false)
83
#endif
84
87
#if __has_attribute(always_inline) || SERIALBOX_GNUC_PREREQ(4, 0, 0)
88
#define SERIALBOX_ATTRIBUTE_ALWAYS_INLINE __attribute__((always_inline))
89
#elif defined(_MSC_VER)
90
#define SERIALBOX_ATTRIBUTE_ALWAYS_INLINE __forceinline
91
#else
92
#define SERIALBOX_ATTRIBUTE_ALWAYS_INLINE
93
#endif
94
97
#ifdef __GNUC__
98
#define SERIALBOX_ATTRIBUTE_NORETURN __attribute__((noreturn))
99
#elif defined(_MSC_VER)
100
#define SERIALBOX_ATTRIBUTE_NORETURN __declspec(noreturn)
101
#else
102
#define SERIALBOX_ATTRIBUTE_NORETURN
103
#endif
104
107
#if __has_builtin(__builtin_expect) || SERIALBOX_GNUC_PREREQ(4, 5, 0)
108
#define SERIALBOX_BUILTIN_LIKELY(x) __builtin_expect(!!(x), 1)
109
#else
110
#define SERIALBOX_BUILTIN_LIKELY(x) (x)
111
#endif
112
115
#if __has_builtin(__builtin_expect) || SERIALBOX_GNUC_PREREQ(4, 5, 0)
116
#define SERIALBOX_BUILTIN_UNLIKELY(x) __builtin_expect(!!(x), 0)
117
#else
118
#define SERIALBOX_BUILTIN_UNLIKELY(x) (x)
119
#endif
120
121
#endif
src
serialbox
core
Compiler.h
Generated on Fri Dec 15 2017 10:48:30 for Serialbox by
1.8.13