Bug 1287048 - Part 1. Replace JS_CPU_* with compiler macro. r=glandium
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Thu, 24 Nov 2016 13:22:05 +0900
changeset 324602 ca8ed6bab9f29504d4fbcdd8124df37878374b4f
parent 324601 6deceff197dc41aac40663be22dab6c698db1eb8
child 324603 a4250c28aabc8cf5bf23cd6c7f825b3b2d181aa1
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +0000
reviewersglandium
bugs1287048
milestone53.0a1
Bug 1287048 - Part 1. Replace JS_CPU_* with compiler macro. r=glandium MozReview-Commit-ID: 3jgSpisx2Zn
js/src/builtin/TestingFunctions.cpp
js/src/jit/ExecutableAllocator.cpp
js/src/jit/ExecutableAllocator.h
js/src/jit/ExecutableAllocatorWin.cpp
js/src/jsapi-tests/tests.h
js/src/wasm/WasmSignalHandlers.cpp
--- a/js/src/builtin/TestingFunctions.cpp
+++ b/js/src/builtin/TestingFunctions.cpp
@@ -135,25 +135,25 @@ GetBuildConfiguration(JSContext* cx, uns
 #ifdef JS_HAS_CTYPES
     value = BooleanValue(true);
 #else
     value = BooleanValue(false);
 #endif
     if (!JS_SetProperty(cx, info, "has-ctypes", value))
         return false;
 
-#ifdef JS_CPU_X86
+#if defined(_M_IX86) || defined(__i386__)
     value = BooleanValue(true);
 #else
     value = BooleanValue(false);
 #endif
     if (!JS_SetProperty(cx, info, "x86", value))
         return false;
 
-#ifdef JS_CPU_X64
+#if defined(_M_X64) || defined(__x86_64__)
     value = BooleanValue(true);
 #else
     value = BooleanValue(false);
 #endif
     if (!JS_SetProperty(cx, info, "x64", value))
         return false;
 
 #ifdef JS_SIMULATOR_ARM
--- a/js/src/jit/ExecutableAllocator.cpp
+++ b/js/src/jit/ExecutableAllocator.cpp
@@ -307,17 +307,17 @@ ExecutableAllocator::initStatic()
         // (Technically, it allocates in page chunks, but the starting
         // address is always a multiple of 64K, so each allocation uses up
         // 64K of address space.)  So a size less than that would be
         // pointless.  But it turns out that 64KB is a reasonable size for
         // all platforms.  (This assumes 4KB pages.) On 64-bit windows,
         // AllocateExecutableMemory prepends an extra page for structured
         // exception handling data (see comments in function) onto whatever
         // is passed in, so subtract one page here.
-#if defined(JS_CPU_X64) && defined(XP_WIN)
+#if defined(XP_WIN) && (defined(_M_X64) || defined(__x86_64__))
         largeAllocSize = pageSize * 15;
 #else
         largeAllocSize = pageSize * 16;
 #endif
     }
 }
 
 void
--- a/js/src/jit/ExecutableAllocator.h
+++ b/js/src/jit/ExecutableAllocator.h
@@ -38,17 +38,17 @@
 
 #include "jit/arm/Simulator-arm.h"
 #include "jit/mips32/Simulator-mips32.h"
 #include "jit/mips64/Simulator-mips64.h"
 #include "js/GCAPI.h"
 #include "js/HashTable.h"
 #include "js/Vector.h"
 
-#ifdef JS_CPU_SPARC
+#if defined(__sparc__)
 #ifdef __linux__  // bugzilla 502369
 static void sync_instruction_memory(caddr_t v, u_int len)
 {
     caddr_t end = v + len;
     caddr_t p = v;
     while (p < end) {
         asm("flush %0" : : "r" (p));
         p += 32;
@@ -296,17 +296,17 @@ class ExecutableAllocator
             : "r" (code), "r" (reinterpret_cast<char*>(code) + size)
             : "r0", "r1", "r2");
     }
 #elif defined(JS_CODEGEN_ARM64) && (defined(__linux__) || defined(ANDROID)) && defined(__GNUC__)
     static void cacheFlush(void* code, size_t size)
     {
 	__clear_cache(code, (void *)((size_t)code + size));
     }
-#elif JS_CPU_SPARC
+#elif defined(__sparc__)
     static void cacheFlush(void* code, size_t size)
     {
         sync_instruction_memory((caddr_t)code, size);
     }
 #endif
 
   private:
     ExecutableAllocator(const ExecutableAllocator&) = delete;
--- a/js/src/jit/ExecutableAllocatorWin.cpp
+++ b/js/src/jit/ExecutableAllocatorWin.cpp
@@ -56,37 +56,37 @@ ExecutableAllocator::computeRandomAlloca
      * VirtualAlloc takes 64K chunks out of the virtual address space, so we
      * keep 16b alignment.
      *
      * x86: V8 comments say that keeping addresses in the [64MiB, 1GiB) range
      * tries to avoid system default DLL mapping space. In the end, we get 13
      * bits of randomness in our selection.
      * x64: [2GiB, 4TiB), with 25 bits of randomness.
      */
-#ifdef JS_CPU_X64
+#ifdef HAVE_64BIT_BUILD
     static const uintptr_t base = 0x0000000080000000;
     static const uintptr_t mask = 0x000003ffffff0000;
-#elif defined(JS_CPU_X86)
+#elif defined(_M_IX86) || defined(__i386__)
     static const uintptr_t base = 0x04000000;
     static const uintptr_t mask = 0x3fff0000;
 #else
 # error "Unsupported architecture"
 #endif
 
     if (randomNumberGenerator.isNothing()) {
         mozilla::Array<uint64_t, 2> seed;
         js::GenerateXorShift128PlusSeed(seed);
         randomNumberGenerator.emplace(seed[0], seed[1]);
     }
 
     uint64_t rand = randomNumberGenerator.ref().next();
     return (void*) (base | (rand & mask));
 }
 
-#ifdef JS_CPU_X64
+#ifdef HAVE_64BIT_BUILD
 static js::JitExceptionHandler sJitExceptionHandler;
 
 JS_FRIEND_API(void)
 js::SetJitExceptionHandler(JitExceptionHandler handler)
 {
     MOZ_ASSERT(!sJitExceptionHandler);
     sJitExceptionHandler = handler;
 }
@@ -204,26 +204,26 @@ UnregisterExecutableMemory(void* p, size
 #endif
 
 void*
 js::jit::AllocateExecutableMemory(void* addr, size_t bytes, unsigned permissions, const char* tag,
                                   size_t pageSize)
 {
     MOZ_ASSERT(bytes % pageSize == 0);
 
-#ifdef JS_CPU_X64
+#ifdef HAVE_64BIT_BUILD
     if (sJitExceptionHandler)
         bytes += pageSize;
 #endif
 
     void* p = VirtualAlloc(addr, bytes, MEM_COMMIT | MEM_RESERVE, permissions);
     if (!p)
         return nullptr;
 
-#ifdef JS_CPU_X64
+#ifdef HAVE_64BIT_BUILD
     if (sJitExceptionHandler) {
         if (!RegisterExecutableMemory(p, bytes, pageSize)) {
             VirtualFree(p, 0, MEM_RELEASE);
             return nullptr;
         }
 
         p = (uint8_t*)p + pageSize;
     }
@@ -232,17 +232,17 @@ js::jit::AllocateExecutableMemory(void* 
     return p;
 }
 
 void
 js::jit::DeallocateExecutableMemory(void* addr, size_t bytes, size_t pageSize)
 {
     MOZ_ASSERT(bytes % pageSize == 0);
 
-#ifdef JS_CPU_X64
+#ifdef HAVE_64BIT_BUILD
     if (sJitExceptionHandler) {
         addr = (uint8_t*)addr - pageSize;
         UnregisterExecutableMemory(addr, bytes, pageSize);
     }
 #endif
 
     VirtualFree(addr, 0, MEM_RELEASE);
 }
--- a/js/src/jsapi-tests/tests.h
+++ b/js/src/jsapi-tests/tests.h
@@ -264,17 +264,17 @@ class JSAPITest
     }
 
     bool definePrint();
 
     static void setNativeStackQuota(JSContext* cx)
     {
         const size_t MAX_STACK_SIZE =
 /* Assume we can't use more than 5e5 bytes of C stack by default. */
-#if (defined(DEBUG) && defined(__SUNPRO_CC))  || defined(JS_CPU_SPARC)
+#if (defined(DEBUG) && defined(__SUNPRO_CC)) || defined(__sparc__)
             /*
              * Sun compiler uses a larger stack space for js::Interpret() with
              * debug.  Use a bigger gMaxStackSize to make "make check" happy.
              */
             5000000
 #else
             500000
 #endif
--- a/js/src/wasm/WasmSignalHandlers.cpp
+++ b/js/src/wasm/WasmSignalHandlers.cpp
@@ -217,17 +217,17 @@ class AutoSetHandlingSegFault
 # include <signal.h>
 # include <sys/mman.h>
 #endif
 
 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
 # include <sys/ucontext.h> // for ucontext_t, mcontext_t
 #endif
 
-#if defined(JS_CPU_X64)
+#if defined(__x86_64__)
 # if defined(__DragonFly__)
 #  include <machine/npx.h> // for union savefpu
 # elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \
        defined(__NetBSD__) || defined(__OpenBSD__)
 #  include <machine/fpu.h> // for struct savefpu/fxsave64
 # endif
 #endif
 
@@ -315,50 +315,50 @@ enum { REG_EIP = 14 };
 # define CONTEXT ucontext_t
 #endif
 
 // Define a context type for use in the emulator code. This is usually just
 // the same as CONTEXT, but on Mac we use a different structure since we call
 // into the emulator code from a Mach exception handler rather than a
 // sigaction-style signal handler.
 #if defined(XP_DARWIN)
-# if defined(JS_CPU_X64)
+# if defined(__x86_64__)
 struct macos_x64_context {
     x86_thread_state64_t thread;
     x86_float_state64_t float_;
 };
 #  define EMULATOR_CONTEXT macos_x64_context
-# elif defined(JS_CPU_X86)
+# elif defined(__i386__)
 struct macos_x86_context {
     x86_thread_state_t thread;
     x86_float_state_t float_;
 };
 #  define EMULATOR_CONTEXT macos_x86_context
-# elif defined(JS_CPU_ARM)
+# elif defined(__arm__)
 struct macos_arm_context {
     arm_thread_state_t thread;
     arm_neon_state_t float_;
 };
 #  define EMULATOR_CONTEXT macos_arm_context
 # else
 #  error Unsupported architecture
 # endif
 #else
 # define EMULATOR_CONTEXT CONTEXT
 #endif
 
-#if defined(JS_CPU_X64)
+#if defined(_M_X64) || defined(__x86_64__)
 # define PC_sig(p) RIP_sig(p)
-#elif defined(JS_CPU_X86)
+#elif defined(_M_IX86) || defined(__i386__)
 # define PC_sig(p) EIP_sig(p)
-#elif defined(JS_CPU_ARM)
+#elif defined(__arm__)
 # define PC_sig(p) R15_sig(p)
 #elif defined(__aarch64__)
 # define PC_sig(p) EPC_sig(p)
-#elif defined(JS_CPU_MIPS)
+#elif defined(__mips__)
 # define PC_sig(p) EPC_sig(p)
 #endif
 
 static uint8_t**
 ContextToPC(CONTEXT* context)
 {
 #ifdef JS_CODEGEN_NONE
     MOZ_CRASH();
@@ -842,25 +842,25 @@ WasmFaultHandler(LPEXCEPTION_POINTERS ex
 }
 
 #elif defined(XP_DARWIN)
 # include <mach/exc.h>
 
 static uint8_t**
 ContextToPC(EMULATOR_CONTEXT* context)
 {
-# if defined(JS_CPU_X64)
+# if defined(__x86_64__)
     static_assert(sizeof(context->thread.__rip) == sizeof(void*),
                   "stored IP should be compile-time pointer-sized");
     return reinterpret_cast<uint8_t**>(&context->thread.__rip);
-# elif defined(JS_CPU_X86)
+# elif defined(__i386__)
     static_assert(sizeof(context->thread.uts.ts32.__eip) == sizeof(void*),
                   "stored IP should be compile-time pointer-sized");
     return reinterpret_cast<uint8_t**>(&context->thread.uts.ts32.__eip);
-# elif defined(JS_CPU_ARM)
+# elif defined(__arm__)
     static_assert(sizeof(context->thread.__pc) == sizeof(void*),
                   "stored IP should be compile-time pointer-sized");
     return reinterpret_cast<uint8_t**>(&context->thread.__pc);
 # else
 #  error Unsupported architecture
 # endif
 }
 
@@ -896,27 +896,27 @@ HandleMachException(JSRuntime* rt, const
         return false;
     AutoSetHandlingSegFault handling(rt);
 
     // Get the port of the JSRuntime's thread from the message.
     mach_port_t rtThread = request.body.thread.name;
 
     // Read out the JSRuntime thread's register state.
     EMULATOR_CONTEXT context;
-# if defined(JS_CPU_X64)
+# if defined(__x86_64__)
     unsigned int thread_state_count = x86_THREAD_STATE64_COUNT;
     unsigned int float_state_count = x86_FLOAT_STATE64_COUNT;
     int thread_state = x86_THREAD_STATE64;
     int float_state = x86_FLOAT_STATE64;
-# elif defined(JS_CPU_X86)
+# elif defined(__i386__)
     unsigned int thread_state_count = x86_THREAD_STATE_COUNT;
     unsigned int float_state_count = x86_FLOAT_STATE_COUNT;
     int thread_state = x86_THREAD_STATE;
     int float_state = x86_FLOAT_STATE;
-# elif defined(JS_CPU_ARM)
+# elif defined(__arm__)
     unsigned int thread_state_count = ARM_THREAD_STATE_COUNT;
     unsigned int float_state_count = ARM_NEON_STATE_COUNT;
     int thread_state = ARM_THREAD_STATE;
     int float_state = ARM_NEON_STATE;
 # else
 #  error Unsupported architecture
 # endif
     kern_return_t kret;