libfoedus-core
FOEDUS Core Library
compiler.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2015, Hewlett-Packard Development Company, LP.
3  * This program is free software; you can redistribute it and/or modify it
4  * under the terms of the GNU General Public License as published by the Free
5  * Software Foundation; either version 2 of the License, or (at your option)
6  * any later version.
7  *
8  * This program is distributed in the hope that it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11  * more details. You should have received a copy of the GNU General Public
12  * License along with this program; if not, write to the Free Software
13  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14  *
15  * HP designates this particular file as subject to the "Classpath" exception
16  * as provided by HP in the LICENSE.txt file that accompanied this code.
17  */
18 #ifndef FOEDUS_COMPILER_HPP_
19 #define FOEDUS_COMPILER_HPP_
20 
91 #ifdef __INTEL_COMPILER
92 // ICC
93 #define LIKELY(x) (x)
94 #define UNLIKELY(x) (x)
95 #define NO_INLINE
96 #define ALWAYS_INLINE
97 #define ASSUME_ALIGNED(x, y) x
98 #define MAY_ALIAS
99 #define RESTRICT_ALIAS
100 #else // __INTEL_COMPILER
101 #if defined(__GNUC__) || defined(__clang__)
102 // GCC and Clang (not sure Clang supports all of below, tho..)
103 #define LIKELY(x) __builtin_expect(!!(x), 1)
104 #define UNLIKELY(x) __builtin_expect(!!(x), 0)
105 #define NO_INLINE __attribute__((noinline))
106 #define ALWAYS_INLINE __attribute__((always_inline))
107 #define MAY_ALIAS __attribute__((__may_alias__))
108 #define RESTRICT_ALIAS __restrict
109 
110 #ifndef __clang__
111 #define ASSUME_ALIGNED(x, y) __builtin_assume_aligned(x, y)
112 #else // __clang__
113 // Umm, when will clang support it?
114 // #define ASSUME_ALIGNED(x, y) __builtin_assume_aligned(x, y)
115 // https://llvm.org/bugs/show_bug.cgi?id=16294
116 #define ASSUME_ALIGNED(x, y) x
117 #endif // __clang__
118 
119 #else // defined(__GNUC__) || defined(__clang__)
120 // Others. MSVC?
121 #define LIKELY(x) (x)
122 #define UNLIKELY(x) (x)
123 #define NO_INLINE
124 #define ALWAYS_INLINE
125 #define ASSUME_ALIGNED(x, y) x
126 #define MAY_ALIAS
127 #define RESTRICT_ALIAS
128 #endif // __GNUC__
129 #endif // __INTEL_COMPILER
130 
131 #endif // FOEDUS_COMPILER_HPP_