| 1 |
// Copyright 2015, VIXL authors |
| 2 |
// All rights reserved. |
| 3 |
// |
| 4 |
// Redistribution and use in source and binary forms, with or without |
| 5 |
// modification, are permitted provided that the following conditions are met: |
| 6 |
// |
| 7 |
// * Redistributions of source code must retain the above copyright notice, |
| 8 |
// this list of conditions and the following disclaimer. |
| 9 |
// * Redistributions in binary form must reproduce the above copyright notice, |
| 10 |
// this list of conditions and the following disclaimer in the documentation |
| 11 |
// and/or other materials provided with the distribution. |
| 12 |
// * Neither the name of ARM Limited nor the names of its contributors may be |
| 13 |
// used to endorse or promote products derived from this software without |
| 14 |
// specific prior written permission. |
| 15 |
// |
| 16 |
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS CONTRIBUTORS "AS IS" AND |
| 17 |
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 18 |
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 19 |
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE |
| 20 |
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 21 |
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 22 |
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 23 |
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 24 |
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 25 |
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 |
|
| 27 |
#ifndef VIXL_GLOBALS_H |
| 28 |
#define VIXL_GLOBALS_H |
| 29 |
|
| 30 |
// Get standard C99 macros for integer types. |
| 31 |
#ifndef __STDC_CONSTANT_MACROS |
| 32 |
#define __STDC_CONSTANT_MACROS |
| 33 |
#endif |
| 34 |
|
| 35 |
#ifndef __STDC_LIMIT_MACROS |
| 36 |
#define __STDC_LIMIT_MACROS |
| 37 |
#endif |
| 38 |
|
| 39 |
#ifndef __STDC_FORMAT_MACROS |
| 40 |
#define __STDC_FORMAT_MACROS |
| 41 |
#endif |
| 42 |
|
| 43 |
#include "mozilla/Assertions.h" |
| 44 |
|
| 45 |
#include <cstdarg> |
| 46 |
#include <cstddef> |
| 47 |
#include <cstdio> |
| 48 |
#include <cstdlib> |
| 49 |
|
| 50 |
extern "C" { |
| 51 |
#include <inttypes.h> |
| 52 |
#include <stdint.h> |
| 53 |
} |
| 54 |
|
| 55 |
#include "jstypes.h" |
| 56 |
|
| 57 |
#include "jit/arm64/vixl/Platform-vixl.h" |
| 58 |
#include "js/Utility.h" |
| 59 |
|
| 60 |
#ifdef VIXL_NEGATIVE_TESTING |
| 61 |
#include <sstream> |
| 62 |
#include <stdexcept> |
| 63 |
#include <string> |
| 64 |
#endif |
| 65 |
|
| 66 |
namespace vixl { |
| 67 |
|
| 68 |
typedef uint8_t byte; |
| 69 |
|
| 70 |
const int KBytes = 1024; |
| 71 |
const int MBytes = 1024 * KBytes; |
| 72 |
|
| 73 |
const int kBitsPerByte = 8; |
| 74 |
|
| 75 |
template <int SizeInBits> |
| 76 |
struct Unsigned; |
| 77 |
|
| 78 |
template <> |
| 79 |
struct Unsigned<32> { |
| 80 |
typedef uint32_t type; |
| 81 |
}; |
| 82 |
|
| 83 |
template <> |
| 84 |
struct Unsigned<64> { |
| 85 |
typedef uint64_t type; |
| 86 |
}; |
| 87 |
|
| 88 |
} // namespace vixl |
| 89 |
|
| 90 |
// Detect the host's pointer size. |
| 91 |
#if (UINTPTR_MAX == UINT32_MAX) |
| 92 |
#define VIXL_HOST_POINTER_32 |
| 93 |
#elif (UINTPTR_MAX == UINT64_MAX) |
| 94 |
#define VIXL_HOST_POINTER_64 |
| 95 |
#else |
| 96 |
#error "Unsupported host pointer size." |
| 97 |
#endif |
| 98 |
|
| 99 |
#ifdef VIXL_NEGATIVE_TESTING |
| 100 |
#define VIXL_ABORT() \ |
| 101 |
do { \ |
| 102 |
std::ostringstream oss; \ |
| 103 |
oss << "Aborting in " << __FILE__ << ", line " << __LINE__ << std::endl; \ |
| 104 |
throw std::runtime_error(oss.str()); \ |
| 105 |
} while (false) |
| 106 |
#define VIXL_ABORT_WITH_MSG(msg) \ |
| 107 |
do { \ |
| 108 |
std::ostringstream oss; \ |
| 109 |
oss << (msg) << "in " << __FILE__ << ", line " << __LINE__ << std::endl; \ |
| 110 |
throw std::runtime_error(oss.str()); \ |
| 111 |
} while (false) |
| 112 |
#define VIXL_CHECK(condition) \ |
| 113 |
do { \ |
| 114 |
if (!(condition)) { \ |
| 115 |
std::ostringstream oss; \ |
| 116 |
oss << "Assertion failed (" #condition ")\nin "; \ |
| 117 |
oss << __FILE__ << ", line " << __LINE__ << std::endl; \ |
| 118 |
throw std::runtime_error(oss.str()); \ |
| 119 |
} \ |
| 120 |
} while (false) |
| 121 |
#else |
| 122 |
#define VIXL_ABORT() \ |
| 123 |
do { \ |
| 124 |
MOZ_CRASH(); \ |
| 125 |
} while (false) |
| 126 |
#define VIXL_ABORT_WITH_MSG(msg) \ |
| 127 |
do { \ |
| 128 |
MOZ_CRASH(msg); \ |
| 129 |
} while (false) |
| 130 |
#define VIXL_CHECK(condition) \ |
| 131 |
do { \ |
| 132 |
if (!(condition)) { \ |
| 133 |
MOZ_CRASH(); \ |
| 134 |
} \ |
| 135 |
} while (false) |
| 136 |
#endif |
| 137 |
#ifdef DEBUG |
| 138 |
#define VIXL_ASSERT(condition) MOZ_ASSERT(condition) |
| 139 |
#define VIXL_UNIMPLEMENTED() \ |
| 140 |
do { \ |
| 141 |
VIXL_ABORT_WITH_MSG("UNIMPLEMENTED "); \ |
| 142 |
} while (false) |
| 143 |
#define VIXL_UNREACHABLE() \ |
| 144 |
do { \ |
| 145 |
VIXL_ABORT_WITH_MSG("UNREACHABLE "); \ |
| 146 |
} while (false) |
| 147 |
#else |
| 148 |
#define VIXL_ASSERT(condition) ((void)0) |
| 149 |
#define VIXL_UNIMPLEMENTED() ((void)0) |
| 150 |
#define VIXL_UNREACHABLE() MOZ_CRASH("vixl unreachable") |
| 151 |
#endif |
| 152 |
// This is not as powerful as template based assertions, but it is simple. |
| 153 |
// It assumes that the descriptions are unique. If this starts being a problem, |
| 154 |
// we can switch to a different implemention. |
| 155 |
#define VIXL_CONCAT(a, b) a##b |
| 156 |
#if __cplusplus >= 201103L |
| 157 |
#define VIXL_STATIC_ASSERT_LINE(line_unused, condition, message) \ |
| 158 |
static_assert(condition, message) |
| 159 |
#else |
| 160 |
#define VIXL_STATIC_ASSERT_LINE(line, condition, message_unused) \ |
| 161 |
typedef char VIXL_CONCAT(STATIC_ASSERT_LINE_, line)[(condition) ? 1 : -1] \ |
| 162 |
__attribute__((unused)) |
| 163 |
#endif |
| 164 |
#define VIXL_STATIC_ASSERT(condition) \ |
| 165 |
VIXL_STATIC_ASSERT_LINE(__LINE__, condition, "") |
| 166 |
#define VIXL_STATIC_ASSERT_MESSAGE(condition, message) \ |
| 167 |
VIXL_STATIC_ASSERT_LINE(__LINE__, condition, message) |
| 168 |
|
| 169 |
#define VIXL_WARNING(message) \ |
| 170 |
do { \ |
| 171 |
printf("WARNING in %s, line %i: %s", __FILE__, __LINE__, message); \ |
| 172 |
} while (false) |
| 173 |
|
| 174 |
template <typename T1> |
| 175 |
inline void USE(const T1&) {} |
| 176 |
|
| 177 |
template <typename T1, typename T2> |
| 178 |
inline void USE(const T1&, const T2&) {} |
| 179 |
|
| 180 |
template <typename T1, typename T2, typename T3> |
| 181 |
inline void USE(const T1&, const T2&, const T3&) {} |
| 182 |
|
| 183 |
template <typename T1, typename T2, typename T3, typename T4> |
| 184 |
inline void USE(const T1&, const T2&, const T3&, const T4&) {} |
| 185 |
|
| 186 |
#define VIXL_ALIGNMENT_EXCEPTION() \ |
| 187 |
do { \ |
| 188 |
VIXL_ABORT_WITH_MSG("ALIGNMENT EXCEPTION\t"); \ |
| 189 |
} while (0) |
| 190 |
|
| 191 |
// The clang::fallthrough attribute is used along with the Wimplicit-fallthrough |
| 192 |
// argument to annotate intentional fall-through between switch labels. |
| 193 |
// For more information please refer to: |
| 194 |
// http://clang.llvm.org/docs/AttributeReference.html#fallthrough-clang-fallthrough |
| 195 |
#ifndef __has_warning |
| 196 |
#define __has_warning(x) 0 |
| 197 |
#endif |
| 198 |
|
| 199 |
// Fallthrough annotation for Clang and C++11(201103L). |
| 200 |
#if __has_warning("-Wimplicit-fallthrough") && __cplusplus >= 201103L |
| 201 |
#define VIXL_FALLTHROUGH() [[clang::fallthrough]] |
| 202 |
// Fallthrough annotation for GCC >= 7. |
| 203 |
#elif __GNUC__ >= 7 |
| 204 |
#define VIXL_FALLTHROUGH() __attribute__((fallthrough)) |
| 205 |
#else |
| 206 |
#define VIXL_FALLTHROUGH() \ |
| 207 |
do { \ |
| 208 |
} while (0) |
| 209 |
#endif |
| 210 |
|
| 211 |
#if __cplusplus >= 201103L |
| 212 |
#define VIXL_NO_RETURN [[noreturn]] |
| 213 |
#else |
| 214 |
#define VIXL_NO_RETURN __attribute__((noreturn)) |
| 215 |
#endif |
| 216 |
#ifdef VIXL_DEBUG |
| 217 |
#define VIXL_NO_RETURN_IN_DEBUG_MODE VIXL_NO_RETURN |
| 218 |
#else |
| 219 |
#define VIXL_NO_RETURN_IN_DEBUG_MODE |
| 220 |
#endif |
| 221 |
|
| 222 |
#if __cplusplus >= 201103L |
| 223 |
#define VIXL_OVERRIDE override |
| 224 |
#else |
| 225 |
#define VIXL_OVERRIDE |
| 226 |
#endif |
| 227 |
|
| 228 |
#ifdef VIXL_INCLUDE_SIMULATOR_AARCH64 |
| 229 |
#ifndef VIXL_AARCH64_GENERATE_SIMULATOR_CODE |
| 230 |
#define VIXL_AARCH64_GENERATE_SIMULATOR_CODE 1 |
| 231 |
#endif |
| 232 |
#else |
| 233 |
#ifndef VIXL_AARCH64_GENERATE_SIMULATOR_CODE |
| 234 |
#define VIXL_AARCH64_GENERATE_SIMULATOR_CODE 0 |
| 235 |
#endif |
| 236 |
#if VIXL_AARCH64_GENERATE_SIMULATOR_CODE |
| 237 |
#warning "Generating Simulator instructions without Simulator support." |
| 238 |
#endif |
| 239 |
#endif |
| 240 |
|
| 241 |
// We do not have a simulator for AArch32, although we can pretend we do so that |
| 242 |
// tests that require running natively can be skipped. |
| 243 |
#ifndef __arm__ |
| 244 |
#define VIXL_INCLUDE_SIMULATOR_AARCH32 |
| 245 |
#ifndef VIXL_AARCH32_GENERATE_SIMULATOR_CODE |
| 246 |
#define VIXL_AARCH32_GENERATE_SIMULATOR_CODE 1 |
| 247 |
#endif |
| 248 |
#else |
| 249 |
#ifndef VIXL_AARCH32_GENERATE_SIMULATOR_CODE |
| 250 |
#define VIXL_AARCH32_GENERATE_SIMULATOR_CODE 0 |
| 251 |
#endif |
| 252 |
#endif |
| 253 |
|
| 254 |
// Target Architecture/ISA |
| 255 |
|
| 256 |
// Hack: always include AArch64. |
| 257 |
#define VIXL_INCLUDE_TARGET_A64 |
| 258 |
|
| 259 |
#ifdef VIXL_INCLUDE_TARGET_A64 |
| 260 |
#define VIXL_INCLUDE_TARGET_AARCH64 |
| 261 |
#endif |
| 262 |
|
| 263 |
#if defined(VIXL_INCLUDE_TARGET_A32) && defined(VIXL_INCLUDE_TARGET_T32) |
| 264 |
#define VIXL_INCLUDE_TARGET_AARCH32 |
| 265 |
#elif defined(VIXL_INCLUDE_TARGET_A32) |
| 266 |
#define VIXL_INCLUDE_TARGET_A32_ONLY |
| 267 |
#else |
| 268 |
#define VIXL_INCLUDE_TARGET_T32_ONLY |
| 269 |
#endif |
| 270 |
|
| 271 |
|
| 272 |
#endif // VIXL_GLOBALS_H |