1
#ifndef MY_COMPILER_INCLUDED
2
#define MY_COMPILER_INCLUDED
4
/* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; version 2 of the License.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program; if not, write to the Free Software
17
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
20
Header for compiler-dependent features.
22
Intended to contain a set of reusable wrappers for preprocessor
23
macros, attributes, pragmas, and any other features that are
24
specific to a target compiler.
27
#include <my_global.h> /* stddef.h offsetof */
30
Compiler-dependent internal convenience macros.
35
/* Convenience macro to test the minimum required GCC version. */
36
# define MY_GNUC_PREREQ(maj, min) \
37
((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
38
/* Any after 2.95... */
40
/* Comunicate to the compiler the unreachability of the code. */
41
# if MY_GNUC_PREREQ(4,5)
42
# define MY_ASSERT_UNREACHABLE() __builtin_unreachable()
45
/* Microsoft Visual C++ */
46
#elif defined _MSC_VER
47
# define MY_ALIGNOF(type) __alignof(type)
48
# define MY_ALIGNED(n) __declspec(align(n))
50
/* Oracle Solaris Studio */
51
#elif defined(__SUNPRO_C) || defined(__SUNPRO_CC)
52
# if __SUNPRO_C >= 0x590
58
# if __xlC__ >= 0x0600
63
#elif defined(__HP_aCC) || defined(__HP_cc)
64
# if (__HP_aCC >= 60000) || (__HP_cc >= 60000)
70
/** Specifies the minimum alignment of a type. */
71
# define MY_ALIGNOF(type) __alignof__(type)
72
/** Determine the alignment requirement of a type. */
73
# define MY_ALIGNED(n) __attribute__((__aligned__((n))))
77
Generic (compiler-independent) features.
80
#ifndef MY_GNUC_PREREQ
81
# define MY_GNUC_PREREQ(maj, min) (0)
86
template<typename type> struct my_alignof_helper { char m1; type m2; };
87
/* Invalid for non-POD types, but most compilers give the right answer. */
88
# define MY_ALIGNOF(type) offsetof(my_alignof_helper<type>, m2)
90
# define MY_ALIGNOF(type) offsetof(struct { char m1; type m2; }, m2)
94
#ifndef MY_ASSERT_UNREACHABLE
95
# define MY_ASSERT_UNREACHABLE() do { assert(0); } while (0)
105
Opaque storage with a particular alignment.
107
# if defined(MY_ALIGNED)
108
/* Partial specialization used due to MSVC++. */
109
template<size_t alignment> struct my_alignment_imp;
110
template<> struct MY_ALIGNED(1) my_alignment_imp<1> {};
111
template<> struct MY_ALIGNED(2) my_alignment_imp<2> {};
112
template<> struct MY_ALIGNED(4) my_alignment_imp<4> {};
113
template<> struct MY_ALIGNED(8) my_alignment_imp<8> {};
114
template<> struct MY_ALIGNED(16) my_alignment_imp<16> {};
115
/* ... expand as necessary. */
117
template<size_t alignment>
118
struct my_alignment_imp { double m1; };
122
A POD type with a given size and alignment.
124
@remark If the compiler does not support a alignment attribute
125
(MY_ALIGN macro), the default alignment of a double is
128
@tparam size The minimum size.
129
@tparam alignment The desired alignment: 1, 2, 4, 8 or 16.
131
template <size_t size, size_t alignment>
132
struct my_aligned_storage
137
my_alignment_imp<alignment> align;
141
#endif /* __cplusplus */
143
#include <my_attribute.h>
145
#endif /* MY_COMPILER_INCLUDED */