|
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
|
2 * vim: set ts=8 sts=4 et sw=4 tw=99: |
|
3 * This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 #ifndef jit_x64_Architecture_x64_h |
|
8 #define jit_x64_Architecture_x64_h |
|
9 |
|
10 #include "assembler/assembler/MacroAssembler.h" |
|
11 |
|
12 namespace js { |
|
13 namespace jit { |
|
14 |
|
15 // In bytes: slots needed for potential memory->memory move spills. |
|
16 // +8 for cycles |
|
17 // +8 for gpr spills |
|
18 // +8 for double spills |
|
19 static const uint32_t ION_FRAME_SLACK_SIZE = 24; |
|
20 |
|
21 #ifdef _WIN64 |
|
22 static const uint32_t ShadowStackSpace = 32; |
|
23 #else |
|
24 static const uint32_t ShadowStackSpace = 0; |
|
25 #endif |
|
26 |
|
27 class Registers { |
|
28 public: |
|
29 typedef JSC::X86Registers::RegisterID Code; |
|
30 |
|
31 static const char *GetName(Code code) { |
|
32 static const char * const Names[] = { "rax", "rcx", "rdx", "rbx", |
|
33 "rsp", "rbp", "rsi", "rdi", |
|
34 "r8", "r9", "r10", "r11", |
|
35 "r12", "r13", "r14", "r15" }; |
|
36 return Names[code]; |
|
37 } |
|
38 |
|
39 static Code FromName(const char *name) { |
|
40 for (size_t i = 0; i < Total; i++) { |
|
41 if (strcmp(GetName(Code(i)), name) == 0) |
|
42 return Code(i); |
|
43 } |
|
44 return Invalid; |
|
45 } |
|
46 |
|
47 static const Code StackPointer = JSC::X86Registers::esp; |
|
48 static const Code Invalid = JSC::X86Registers::invalid_reg; |
|
49 |
|
50 static const uint32_t Total = 16; |
|
51 static const uint32_t Allocatable = 14; |
|
52 |
|
53 static const uint32_t AllMask = (1 << Total) - 1; |
|
54 |
|
55 static const uint32_t ArgRegMask = |
|
56 # if !defined(_WIN64) |
|
57 (1 << JSC::X86Registers::edi) | |
|
58 (1 << JSC::X86Registers::esi) | |
|
59 # endif |
|
60 (1 << JSC::X86Registers::edx) | |
|
61 (1 << JSC::X86Registers::ecx) | |
|
62 (1 << JSC::X86Registers::r8) | |
|
63 (1 << JSC::X86Registers::r9); |
|
64 |
|
65 static const uint32_t VolatileMask = |
|
66 (1 << JSC::X86Registers::eax) | |
|
67 (1 << JSC::X86Registers::ecx) | |
|
68 (1 << JSC::X86Registers::edx) | |
|
69 # if !defined(_WIN64) |
|
70 (1 << JSC::X86Registers::esi) | |
|
71 (1 << JSC::X86Registers::edi) | |
|
72 # endif |
|
73 (1 << JSC::X86Registers::r8) | |
|
74 (1 << JSC::X86Registers::r9) | |
|
75 (1 << JSC::X86Registers::r10) | |
|
76 (1 << JSC::X86Registers::r11); |
|
77 |
|
78 static const uint32_t NonVolatileMask = |
|
79 (1 << JSC::X86Registers::ebx) | |
|
80 #if defined(_WIN64) |
|
81 (1 << JSC::X86Registers::esi) | |
|
82 (1 << JSC::X86Registers::edi) | |
|
83 #endif |
|
84 (1 << JSC::X86Registers::ebp) | |
|
85 (1 << JSC::X86Registers::r12) | |
|
86 (1 << JSC::X86Registers::r13) | |
|
87 (1 << JSC::X86Registers::r14) | |
|
88 (1 << JSC::X86Registers::r15); |
|
89 |
|
90 static const uint32_t WrapperMask = VolatileMask; |
|
91 |
|
92 static const uint32_t SingleByteRegs = VolatileMask | NonVolatileMask; |
|
93 |
|
94 static const uint32_t NonAllocatableMask = |
|
95 (1 << JSC::X86Registers::esp) | |
|
96 (1 << JSC::X86Registers::r11); // This is ScratchReg. |
|
97 |
|
98 // Registers that can be allocated without being saved, generally. |
|
99 static const uint32_t TempMask = VolatileMask & ~NonAllocatableMask; |
|
100 |
|
101 static const uint32_t AllocatableMask = AllMask & ~NonAllocatableMask; |
|
102 |
|
103 // Registers returned from a JS -> JS call. |
|
104 static const uint32_t JSCallMask = |
|
105 (1 << JSC::X86Registers::ecx); |
|
106 |
|
107 // Registers returned from a JS -> C call. |
|
108 static const uint32_t CallMask = |
|
109 (1 << JSC::X86Registers::eax); |
|
110 }; |
|
111 |
|
112 // Smallest integer type that can hold a register bitmask. |
|
113 typedef uint16_t PackedRegisterMask; |
|
114 |
|
115 class FloatRegisters { |
|
116 public: |
|
117 typedef JSC::X86Registers::XMMRegisterID Code; |
|
118 |
|
119 static const char *GetName(Code code) { |
|
120 static const char * const Names[] = { "xmm0", "xmm1", "xmm2", "xmm3", |
|
121 "xmm4", "xmm5", "xmm6", "xmm7", |
|
122 "xmm8", "xmm9", "xmm10", "xmm11", |
|
123 "xmm12", "xmm13", "xmm14", "xmm15" }; |
|
124 return Names[code]; |
|
125 } |
|
126 |
|
127 static Code FromName(const char *name) { |
|
128 for (size_t i = 0; i < Total; i++) { |
|
129 if (strcmp(GetName(Code(i)), name) == 0) |
|
130 return Code(i); |
|
131 } |
|
132 return Invalid; |
|
133 } |
|
134 |
|
135 static const Code Invalid = JSC::X86Registers::invalid_xmm; |
|
136 |
|
137 static const uint32_t Total = 16; |
|
138 static const uint32_t Allocatable = 15; |
|
139 |
|
140 static const uint32_t AllMask = (1 << Total) - 1; |
|
141 |
|
142 static const uint32_t VolatileMask = |
|
143 #if defined(_WIN64) |
|
144 (1 << JSC::X86Registers::xmm0) | |
|
145 (1 << JSC::X86Registers::xmm1) | |
|
146 (1 << JSC::X86Registers::xmm2) | |
|
147 (1 << JSC::X86Registers::xmm3) | |
|
148 (1 << JSC::X86Registers::xmm4) | |
|
149 (1 << JSC::X86Registers::xmm5); |
|
150 #else |
|
151 AllMask; |
|
152 #endif |
|
153 |
|
154 static const uint32_t NonVolatileMask = AllMask & ~VolatileMask; |
|
155 |
|
156 static const uint32_t WrapperMask = VolatileMask; |
|
157 |
|
158 static const uint32_t NonAllocatableMask = |
|
159 (1 << JSC::X86Registers::xmm15); // This is ScratchFloatReg. |
|
160 |
|
161 static const uint32_t AllocatableMask = AllMask & ~NonAllocatableMask; |
|
162 }; |
|
163 |
|
164 } // namespace jit |
|
165 } // namespace js |
|
166 |
|
167 #endif /* jit_x64_Architecture_x64_h */ |