michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * vim: set ts=8 sts=4 et sw=4 tw=99: michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef jit_x64_Architecture_x64_h michael@0: #define jit_x64_Architecture_x64_h michael@0: michael@0: #include "assembler/assembler/MacroAssembler.h" michael@0: michael@0: namespace js { michael@0: namespace jit { michael@0: michael@0: // In bytes: slots needed for potential memory->memory move spills. michael@0: // +8 for cycles michael@0: // +8 for gpr spills michael@0: // +8 for double spills michael@0: static const uint32_t ION_FRAME_SLACK_SIZE = 24; michael@0: michael@0: #ifdef _WIN64 michael@0: static const uint32_t ShadowStackSpace = 32; michael@0: #else michael@0: static const uint32_t ShadowStackSpace = 0; michael@0: #endif michael@0: michael@0: class Registers { michael@0: public: michael@0: typedef JSC::X86Registers::RegisterID Code; michael@0: michael@0: static const char *GetName(Code code) { michael@0: static const char * const Names[] = { "rax", "rcx", "rdx", "rbx", michael@0: "rsp", "rbp", "rsi", "rdi", michael@0: "r8", "r9", "r10", "r11", michael@0: "r12", "r13", "r14", "r15" }; michael@0: return Names[code]; michael@0: } michael@0: michael@0: static Code FromName(const char *name) { michael@0: for (size_t i = 0; i < Total; i++) { michael@0: if (strcmp(GetName(Code(i)), name) == 0) michael@0: return Code(i); michael@0: } michael@0: return Invalid; michael@0: } michael@0: michael@0: static const Code StackPointer = JSC::X86Registers::esp; michael@0: static const Code Invalid = JSC::X86Registers::invalid_reg; michael@0: michael@0: static const uint32_t Total = 16; michael@0: static const uint32_t Allocatable = 14; michael@0: michael@0: static const uint32_t AllMask = (1 << Total) - 1; michael@0: michael@0: static const uint32_t ArgRegMask = michael@0: # if !defined(_WIN64) michael@0: (1 << JSC::X86Registers::edi) | michael@0: (1 << JSC::X86Registers::esi) | michael@0: # endif michael@0: (1 << JSC::X86Registers::edx) | michael@0: (1 << JSC::X86Registers::ecx) | michael@0: (1 << JSC::X86Registers::r8) | michael@0: (1 << JSC::X86Registers::r9); michael@0: michael@0: static const uint32_t VolatileMask = michael@0: (1 << JSC::X86Registers::eax) | michael@0: (1 << JSC::X86Registers::ecx) | michael@0: (1 << JSC::X86Registers::edx) | michael@0: # if !defined(_WIN64) michael@0: (1 << JSC::X86Registers::esi) | michael@0: (1 << JSC::X86Registers::edi) | michael@0: # endif michael@0: (1 << JSC::X86Registers::r8) | michael@0: (1 << JSC::X86Registers::r9) | michael@0: (1 << JSC::X86Registers::r10) | michael@0: (1 << JSC::X86Registers::r11); michael@0: michael@0: static const uint32_t NonVolatileMask = michael@0: (1 << JSC::X86Registers::ebx) | michael@0: #if defined(_WIN64) michael@0: (1 << JSC::X86Registers::esi) | michael@0: (1 << JSC::X86Registers::edi) | michael@0: #endif michael@0: (1 << JSC::X86Registers::ebp) | michael@0: (1 << JSC::X86Registers::r12) | michael@0: (1 << JSC::X86Registers::r13) | michael@0: (1 << JSC::X86Registers::r14) | michael@0: (1 << JSC::X86Registers::r15); michael@0: michael@0: static const uint32_t WrapperMask = VolatileMask; michael@0: michael@0: static const uint32_t SingleByteRegs = VolatileMask | NonVolatileMask; michael@0: michael@0: static const uint32_t NonAllocatableMask = michael@0: (1 << JSC::X86Registers::esp) | michael@0: (1 << JSC::X86Registers::r11); // This is ScratchReg. michael@0: michael@0: // Registers that can be allocated without being saved, generally. michael@0: static const uint32_t TempMask = VolatileMask & ~NonAllocatableMask; michael@0: michael@0: static const uint32_t AllocatableMask = AllMask & ~NonAllocatableMask; michael@0: michael@0: // Registers returned from a JS -> JS call. michael@0: static const uint32_t JSCallMask = michael@0: (1 << JSC::X86Registers::ecx); michael@0: michael@0: // Registers returned from a JS -> C call. michael@0: static const uint32_t CallMask = michael@0: (1 << JSC::X86Registers::eax); michael@0: }; michael@0: michael@0: // Smallest integer type that can hold a register bitmask. michael@0: typedef uint16_t PackedRegisterMask; michael@0: michael@0: class FloatRegisters { michael@0: public: michael@0: typedef JSC::X86Registers::XMMRegisterID Code; michael@0: michael@0: static const char *GetName(Code code) { michael@0: static const char * const Names[] = { "xmm0", "xmm1", "xmm2", "xmm3", michael@0: "xmm4", "xmm5", "xmm6", "xmm7", michael@0: "xmm8", "xmm9", "xmm10", "xmm11", michael@0: "xmm12", "xmm13", "xmm14", "xmm15" }; michael@0: return Names[code]; michael@0: } michael@0: michael@0: static Code FromName(const char *name) { michael@0: for (size_t i = 0; i < Total; i++) { michael@0: if (strcmp(GetName(Code(i)), name) == 0) michael@0: return Code(i); michael@0: } michael@0: return Invalid; michael@0: } michael@0: michael@0: static const Code Invalid = JSC::X86Registers::invalid_xmm; michael@0: michael@0: static const uint32_t Total = 16; michael@0: static const uint32_t Allocatable = 15; michael@0: michael@0: static const uint32_t AllMask = (1 << Total) - 1; michael@0: michael@0: static const uint32_t VolatileMask = michael@0: #if defined(_WIN64) michael@0: (1 << JSC::X86Registers::xmm0) | michael@0: (1 << JSC::X86Registers::xmm1) | michael@0: (1 << JSC::X86Registers::xmm2) | michael@0: (1 << JSC::X86Registers::xmm3) | michael@0: (1 << JSC::X86Registers::xmm4) | michael@0: (1 << JSC::X86Registers::xmm5); michael@0: #else michael@0: AllMask; michael@0: #endif michael@0: michael@0: static const uint32_t NonVolatileMask = AllMask & ~VolatileMask; michael@0: michael@0: static const uint32_t WrapperMask = VolatileMask; michael@0: michael@0: static const uint32_t NonAllocatableMask = michael@0: (1 << JSC::X86Registers::xmm15); // This is ScratchFloatReg. michael@0: michael@0: static const uint32_t AllocatableMask = AllMask & ~NonAllocatableMask; michael@0: }; michael@0: michael@0: } // namespace jit michael@0: } // namespace js michael@0: michael@0: #endif /* jit_x64_Architecture_x64_h */