Globals-vixl.h (10146B)
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 kBitsPerByteLog2 = 3; 74 const int kBitsPerByte = 1 << kBitsPerByteLog2; 75 76 template <int SizeInBits> 77 struct Unsigned; 78 79 template <> 80 struct Unsigned<32> { 81 typedef uint32_t type; 82 }; 83 84 template <> 85 struct Unsigned<64> { 86 typedef uint64_t type; 87 }; 88 89 } // namespace vixl 90 91 // Detect the host's pointer size. 92 #if (UINTPTR_MAX == UINT32_MAX) 93 #define VIXL_HOST_POINTER_32 94 #elif (UINTPTR_MAX == UINT64_MAX) 95 #define VIXL_HOST_POINTER_64 96 #else 97 #error "Unsupported host pointer size." 98 #endif 99 100 #ifdef VIXL_NEGATIVE_TESTING 101 #define VIXL_ABORT() \ 102 do { \ 103 std::ostringstream oss; \ 104 oss << "Aborting in " << __FILE__ << ", line " << __LINE__ << std::endl; \ 105 throw std::runtime_error(oss.str()); \ 106 } while (false) 107 #define VIXL_ABORT_WITH_MSG(msg) \ 108 do { \ 109 std::ostringstream oss; \ 110 oss << (msg) << "in " << __FILE__ << ", line " << __LINE__ << std::endl; \ 111 throw std::runtime_error(oss.str()); \ 112 } while (false) 113 #define VIXL_CHECK(condition) \ 114 do { \ 115 if (!(condition)) { \ 116 std::ostringstream oss; \ 117 oss << "Assertion failed (" #condition ")\nin "; \ 118 oss << __FILE__ << ", line " << __LINE__ << std::endl; \ 119 throw std::runtime_error(oss.str()); \ 120 } \ 121 } while (false) 122 #else 123 #define VIXL_ABORT() \ 124 do { \ 125 MOZ_CRASH(); \ 126 } while (false) 127 #define VIXL_ABORT_WITH_MSG(msg) \ 128 do { \ 129 MOZ_CRASH(msg); \ 130 } while (false) 131 #define VIXL_CHECK(condition) \ 132 do { \ 133 if (!(condition)) { \ 134 MOZ_CRASH(); \ 135 } \ 136 } while (false) 137 #endif 138 #ifdef DEBUG 139 #define VIXL_ASSERT(condition) MOZ_ASSERT(condition) 140 #define VIXL_UNIMPLEMENTED() \ 141 do { \ 142 VIXL_ABORT_WITH_MSG("UNIMPLEMENTED "); \ 143 } while (false) 144 #define VIXL_UNREACHABLE() \ 145 do { \ 146 VIXL_ABORT_WITH_MSG("UNREACHABLE "); \ 147 } while (false) 148 #else 149 #define VIXL_ASSERT(condition) ((void)0) 150 #define VIXL_UNIMPLEMENTED() ((void)0) 151 #define VIXL_UNREACHABLE() MOZ_CRASH("vixl unreachable") 152 #endif 153 // This is not as powerful as template based assertions, but it is simple. 154 // It assumes that the descriptions are unique. If this starts being a problem, 155 // we can switch to a different implementation. 156 #define VIXL_CONCAT(a, b) a##b 157 #if __cplusplus >= 201103L 158 #define VIXL_STATIC_ASSERT_LINE(line_unused, condition, message) \ 159 static_assert(condition, message) 160 #else 161 #define VIXL_STATIC_ASSERT_LINE(line, condition, message_unused) \ 162 typedef char VIXL_CONCAT(STATIC_ASSERT_LINE_, line)[(condition) ? 1 : -1] \ 163 __attribute__((unused)) 164 #endif 165 #define VIXL_STATIC_ASSERT(condition) \ 166 VIXL_STATIC_ASSERT_LINE(__LINE__, condition, "") 167 #define VIXL_STATIC_ASSERT_MESSAGE(condition, message) \ 168 VIXL_STATIC_ASSERT_LINE(__LINE__, condition, message) 169 170 #define VIXL_WARNING(message) \ 171 do { \ 172 printf("WARNING in %s, line %i: %s", __FILE__, __LINE__, message); \ 173 } while (false) 174 175 template <typename T1> 176 inline void USE(const T1&) {} 177 178 template <typename T1, typename T2> 179 inline void USE(const T1&, const T2&) {} 180 181 template <typename T1, typename T2, typename T3> 182 inline void USE(const T1&, const T2&, const T3&) {} 183 184 template <typename T1, typename T2, typename T3, typename T4> 185 inline void USE(const T1&, const T2&, const T3&, const T4&) {} 186 187 #define VIXL_ALIGNMENT_EXCEPTION() \ 188 do { \ 189 VIXL_ABORT_WITH_MSG("ALIGNMENT EXCEPTION\t"); \ 190 } while (0) 191 192 // The clang::fallthrough attribute is used along with the Wimplicit-fallthrough 193 // argument to annotate intentional fall-through between switch labels. 194 // For more information please refer to: 195 // http://clang.llvm.org/docs/AttributeReference.html#fallthrough-clang-fallthrough 196 #ifndef __has_warning 197 #define __has_warning(x) 0 198 #endif 199 200 // Fallthrough annotation for Clang and C++11(201103L). 201 #if __has_warning("-Wimplicit-fallthrough") && __cplusplus >= 201103L 202 #define VIXL_FALLTHROUGH() [[clang::fallthrough]] 203 // Fallthrough annotation for GCC >= 7. 204 #elif defined(__GNUC__) && __GNUC__ >= 7 205 #define VIXL_FALLTHROUGH() __attribute__((fallthrough)) 206 #else 207 #define VIXL_FALLTHROUGH() \ 208 do { \ 209 } while (0) 210 #endif 211 212 // Evaluate 'init' to an std::optional and return if it's empty. If 'init' is 213 // not empty then define a variable 'name' with the value inside the 214 // std::optional. 215 #define VIXL_DEFINE_OR_RETURN(name, init) \ 216 auto opt##name = init; \ 217 if (!opt##name) return; \ 218 auto name = *opt##name; 219 #define VIXL_DEFINE_OR_RETURN_FALSE(name, init) \ 220 auto opt##name = init; \ 221 if (!opt##name) return false; \ 222 auto name = *opt##name; 223 224 #if __cplusplus >= 201103L 225 #define VIXL_NO_RETURN [[noreturn]] 226 #else 227 #define VIXL_NO_RETURN __attribute__((noreturn)) 228 #endif 229 #ifdef VIXL_DEBUG 230 #define VIXL_NO_RETURN_IN_DEBUG_MODE VIXL_NO_RETURN 231 #else 232 #define VIXL_NO_RETURN_IN_DEBUG_MODE 233 #endif 234 235 #if __cplusplus >= 201103L 236 #define VIXL_OVERRIDE override 237 #define VIXL_CONSTEXPR constexpr 238 #define VIXL_HAS_CONSTEXPR 1 239 #else 240 #define VIXL_OVERRIDE 241 #define VIXL_CONSTEXPR 242 #endif 243 244 // With VIXL_NEGATIVE_TESTING on, VIXL_ASSERT and VIXL_CHECK will throw 245 // exceptions but C++11 marks destructors as noexcept(true) by default. 246 #if defined(VIXL_NEGATIVE_TESTING) && __cplusplus >= 201103L 247 #define VIXL_NEGATIVE_TESTING_ALLOW_EXCEPTION noexcept(false) 248 #else 249 #define VIXL_NEGATIVE_TESTING_ALLOW_EXCEPTION 250 #endif 251 252 #ifdef VIXL_INCLUDE_SIMULATOR_AARCH64 253 #ifndef VIXL_AARCH64_GENERATE_SIMULATOR_CODE 254 #define VIXL_AARCH64_GENERATE_SIMULATOR_CODE 1 255 #endif 256 #else 257 #ifndef VIXL_AARCH64_GENERATE_SIMULATOR_CODE 258 #define VIXL_AARCH64_GENERATE_SIMULATOR_CODE 0 259 #endif 260 #if VIXL_AARCH64_GENERATE_SIMULATOR_CODE 261 #warning "Generating Simulator instructions without Simulator support." 262 #endif 263 #endif 264 265 // We do not have a simulator for AArch32, although we can pretend we do so that 266 // tests that require running natively can be skipped. 267 #ifndef __arm__ 268 #define VIXL_INCLUDE_SIMULATOR_AARCH32 269 #ifndef VIXL_AARCH32_GENERATE_SIMULATOR_CODE 270 #define VIXL_AARCH32_GENERATE_SIMULATOR_CODE 1 271 #endif 272 #else 273 #ifndef VIXL_AARCH32_GENERATE_SIMULATOR_CODE 274 #define VIXL_AARCH32_GENERATE_SIMULATOR_CODE 0 275 #endif 276 #endif 277 278 // Target Architecture/ISA 279 280 // Hack: always include AArch64. 281 #define VIXL_INCLUDE_TARGET_A64 282 283 #ifdef VIXL_INCLUDE_TARGET_A64 284 #define VIXL_INCLUDE_TARGET_AARCH64 285 #endif 286 287 #if defined(VIXL_INCLUDE_TARGET_A32) && defined(VIXL_INCLUDE_TARGET_T32) 288 #define VIXL_INCLUDE_TARGET_AARCH32 289 #elif defined(VIXL_INCLUDE_TARGET_A32) 290 #define VIXL_INCLUDE_TARGET_A32_ONLY 291 #else 292 #define VIXL_INCLUDE_TARGET_T32_ONLY 293 #endif 294 295 296 #endif // VIXL_GLOBALS_H