]> git.saurik.com Git - apple/javascriptcore.git/blame - assembler/MacroAssembler.h
JavaScriptCore-903.tar.gz
[apple/javascriptcore.git] / assembler / MacroAssembler.h
CommitLineData
9dae56ea
A
1/*
2 * Copyright (C) 2008 Apple Inc. 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
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#ifndef MacroAssembler_h
27#define MacroAssembler_h
28
9dae56ea
A
29#if ENABLE(ASSEMBLER)
30
f9bf01c6 31#if CPU(ARM_THUMB2)
ba379fdc
A
32#include "MacroAssemblerARMv7.h"
33namespace JSC { typedef MacroAssemblerARMv7 MacroAssemblerBase; };
9dae56ea 34
f9bf01c6
A
35#elif CPU(ARM_TRADITIONAL)
36#include "MacroAssemblerARM.h"
37namespace JSC { typedef MacroAssemblerARM MacroAssemblerBase; };
38
4e4e5a6f
A
39#elif CPU(MIPS)
40#include "MacroAssemblerMIPS.h"
41namespace JSC {
42typedef MacroAssemblerMIPS MacroAssemblerBase;
43};
44
f9bf01c6 45#elif CPU(X86)
ba379fdc
A
46#include "MacroAssemblerX86.h"
47namespace JSC { typedef MacroAssemblerX86 MacroAssemblerBase; };
9dae56ea 48
f9bf01c6 49#elif CPU(X86_64)
ba379fdc
A
50#include "MacroAssemblerX86_64.h"
51namespace JSC { typedef MacroAssemblerX86_64 MacroAssemblerBase; };
9dae56ea 52
14957cd0
A
53#elif CPU(SH4)
54#include "MacroAssemblerSH4.h"
55namespace JSC {
56typedef MacroAssemblerSH4 MacroAssemblerBase;
57};
58
ba379fdc
A
59#else
60#error "The MacroAssembler is not supported on this platform."
9dae56ea
A
61#endif
62
ba379fdc
A
63
64namespace JSC {
65
66class MacroAssembler : public MacroAssemblerBase {
9dae56ea 67public:
ba379fdc
A
68
69 using MacroAssemblerBase::pop;
70 using MacroAssemblerBase::jump;
71 using MacroAssemblerBase::branch32;
72 using MacroAssemblerBase::branch16;
f9bf01c6 73#if CPU(X86_64)
ba379fdc
A
74 using MacroAssemblerBase::branchPtr;
75 using MacroAssemblerBase::branchTestPtr;
9dae56ea 76#endif
9dae56ea 77
ba379fdc
A
78
79 // Platform agnostic onvenience functions,
80 // described in terms of other macro assembly methods.
81 void pop()
9dae56ea 82 {
14957cd0 83 addPtr(TrustedImm32(sizeof(void*)), stackPointerRegister);
9dae56ea
A
84 }
85
ba379fdc 86 void peek(RegisterID dest, int index = 0)
9dae56ea 87 {
ba379fdc 88 loadPtr(Address(stackPointerRegister, (index * sizeof(void*))), dest);
9dae56ea
A
89 }
90
ba379fdc 91 void poke(RegisterID src, int index = 0)
9dae56ea 92 {
ba379fdc 93 storePtr(src, Address(stackPointerRegister, (index * sizeof(void*))));
9dae56ea
A
94 }
95
14957cd0 96 void poke(TrustedImm32 value, int index = 0)
9dae56ea 97 {
ba379fdc 98 store32(value, Address(stackPointerRegister, (index * sizeof(void*))));
9dae56ea
A
99 }
100
14957cd0 101 void poke(TrustedImmPtr imm, int index = 0)
9dae56ea 102 {
ba379fdc 103 storePtr(imm, Address(stackPointerRegister, (index * sizeof(void*))));
9dae56ea
A
104 }
105
9dae56ea 106
ba379fdc 107 // Backwards banches, these are currently all implemented using existing forwards branch mechanisms.
14957cd0 108 void branchPtr(RelationalCondition cond, RegisterID op1, TrustedImmPtr imm, Label target)
9dae56ea 109 {
ba379fdc 110 branchPtr(cond, op1, imm).linkTo(target, this);
9dae56ea
A
111 }
112
14957cd0 113 void branch32(RelationalCondition cond, RegisterID op1, RegisterID op2, Label target)
9dae56ea 114 {
ba379fdc 115 branch32(cond, op1, op2).linkTo(target, this);
9dae56ea
A
116 }
117
14957cd0 118 void branch32(RelationalCondition cond, RegisterID op1, TrustedImm32 imm, Label target)
9dae56ea 119 {
ba379fdc 120 branch32(cond, op1, imm).linkTo(target, this);
9dae56ea 121 }
ba379fdc 122
14957cd0 123 void branch32(RelationalCondition cond, RegisterID left, Address right, Label target)
9dae56ea 124 {
ba379fdc 125 branch32(cond, left, right).linkTo(target, this);
9dae56ea 126 }
ba379fdc 127
14957cd0 128 void branch16(RelationalCondition cond, BaseIndex left, RegisterID right, Label target)
9dae56ea 129 {
ba379fdc 130 branch16(cond, left, right).linkTo(target, this);
9dae56ea
A
131 }
132
14957cd0 133 void branchTestPtr(ResultCondition cond, RegisterID reg, Label target)
9dae56ea 134 {
ba379fdc 135 branchTestPtr(cond, reg).linkTo(target, this);
9dae56ea
A
136 }
137
ba379fdc 138 void jump(Label target)
9dae56ea 139 {
ba379fdc 140 jump().linkTo(target, this);
9dae56ea
A
141 }
142
9dae56ea 143
ba379fdc
A
144 // Ptr methods
145 // On 32-bit platforms (i.e. x86), these methods directly map onto their 32-bit equivalents.
f9bf01c6
A
146 // FIXME: should this use a test for 32-bitness instead of this specific exception?
147#if !CPU(X86_64)
ba379fdc 148 void addPtr(RegisterID src, RegisterID dest)
9dae56ea 149 {
ba379fdc 150 add32(src, dest);
9dae56ea
A
151 }
152
14957cd0 153 void addPtr(TrustedImm32 imm, RegisterID srcDest)
9dae56ea 154 {
ba379fdc 155 add32(imm, srcDest);
9dae56ea 156 }
9dae56ea 157
14957cd0 158 void addPtr(TrustedImmPtr imm, RegisterID dest)
ba379fdc 159 {
14957cd0 160 add32(TrustedImm32(imm), dest);
9dae56ea
A
161 }
162
14957cd0 163 void addPtr(TrustedImm32 imm, RegisterID src, RegisterID dest)
9dae56ea 164 {
ba379fdc 165 add32(imm, src, dest);
9dae56ea 166 }
ba379fdc
A
167
168 void andPtr(RegisterID src, RegisterID dest)
9dae56ea 169 {
ba379fdc 170 and32(src, dest);
9dae56ea 171 }
ba379fdc 172
14957cd0 173 void andPtr(TrustedImm32 imm, RegisterID srcDest)
9dae56ea 174 {
ba379fdc 175 and32(imm, srcDest);
9dae56ea 176 }
ba379fdc 177
9dae56ea
A
178 void orPtr(RegisterID src, RegisterID dest)
179 {
9dae56ea 180 or32(src, dest);
9dae56ea
A
181 }
182
14957cd0 183 void orPtr(TrustedImmPtr imm, RegisterID dest)
9dae56ea 184 {
14957cd0 185 or32(TrustedImm32(imm), dest);
9dae56ea
A
186 }
187
14957cd0 188 void orPtr(TrustedImm32 imm, RegisterID dest)
9dae56ea 189 {
9dae56ea 190 or32(imm, dest);
9dae56ea
A
191 }
192
9dae56ea
A
193 void subPtr(RegisterID src, RegisterID dest)
194 {
9dae56ea 195 sub32(src, dest);
9dae56ea
A
196 }
197
14957cd0 198 void subPtr(TrustedImm32 imm, RegisterID dest)
9dae56ea 199 {
9dae56ea 200 sub32(imm, dest);
9dae56ea
A
201 }
202
14957cd0 203 void subPtr(TrustedImmPtr imm, RegisterID dest)
9dae56ea 204 {
14957cd0 205 sub32(TrustedImm32(imm), dest);
9dae56ea
A
206 }
207
208 void xorPtr(RegisterID src, RegisterID dest)
209 {
9dae56ea 210 xor32(src, dest);
9dae56ea
A
211 }
212
14957cd0 213 void xorPtr(TrustedImm32 imm, RegisterID srcDest)
9dae56ea 214 {
9dae56ea 215 xor32(imm, srcDest);
9dae56ea 216 }
9dae56ea 217
9dae56ea
A
218
219 void loadPtr(ImplicitAddress address, RegisterID dest)
220 {
9dae56ea 221 load32(address, dest);
9dae56ea
A
222 }
223
224 void loadPtr(BaseIndex address, RegisterID dest)
225 {
9dae56ea 226 load32(address, dest);
9dae56ea
A
227 }
228
229 void loadPtr(void* address, RegisterID dest)
230 {
9dae56ea 231 load32(address, dest);
9dae56ea
A
232 }
233
ba379fdc 234 DataLabel32 loadPtrWithAddressOffsetPatch(Address address, RegisterID dest)
9dae56ea 235 {
ba379fdc 236 return load32WithAddressOffsetPatch(address, dest);
9dae56ea 237 }
14957cd0
A
238
239 DataLabelCompact loadPtrWithCompactAddressOffsetPatch(Address address, RegisterID dest)
240 {
241 return load32WithCompactAddressOffsetPatch(address, dest);
242 }
9dae56ea 243
14957cd0 244 void comparePtr(RelationalCondition cond, RegisterID left, TrustedImm32 right, RegisterID dest)
9dae56ea 245 {
14957cd0 246 compare32(cond, left, right, dest);
9dae56ea
A
247 }
248
249 void storePtr(RegisterID src, ImplicitAddress address)
250 {
9dae56ea 251 store32(src, address);
9dae56ea
A
252 }
253
ba379fdc 254 void storePtr(RegisterID src, BaseIndex address)
9dae56ea 255 {
ba379fdc 256 store32(src, address);
9dae56ea
A
257 }
258
ba379fdc 259 void storePtr(RegisterID src, void* address)
9dae56ea 260 {
9dae56ea 261 store32(src, address);
9dae56ea
A
262 }
263
14957cd0 264 void storePtr(TrustedImmPtr imm, ImplicitAddress address)
9dae56ea 265 {
14957cd0 266 store32(TrustedImm32(imm), address);
9dae56ea
A
267 }
268
14957cd0 269 void storePtr(TrustedImmPtr imm, void* address)
9dae56ea 270 {
14957cd0 271 store32(TrustedImm32(imm), address);
9dae56ea 272 }
9dae56ea 273
ba379fdc 274 DataLabel32 storePtrWithAddressOffsetPatch(RegisterID src, Address address)
9dae56ea 275 {
ba379fdc 276 return store32WithAddressOffsetPatch(src, address);
9dae56ea
A
277 }
278
9dae56ea 279
14957cd0 280 Jump branchPtr(RelationalCondition cond, RegisterID left, RegisterID right)
9dae56ea 281 {
ba379fdc 282 return branch32(cond, left, right);
9dae56ea
A
283 }
284
14957cd0 285 Jump branchPtr(RelationalCondition cond, RegisterID left, TrustedImmPtr right)
9dae56ea 286 {
14957cd0 287 return branch32(cond, left, TrustedImm32(right));
9dae56ea
A
288 }
289
14957cd0 290 Jump branchPtr(RelationalCondition cond, RegisterID left, Address right)
9dae56ea 291 {
ba379fdc 292 return branch32(cond, left, right);
9dae56ea
A
293 }
294
14957cd0 295 Jump branchPtr(RelationalCondition cond, Address left, RegisterID right)
9dae56ea 296 {
ba379fdc 297 return branch32(cond, left, right);
9dae56ea
A
298 }
299
14957cd0 300 Jump branchPtr(RelationalCondition cond, AbsoluteAddress left, RegisterID right)
9dae56ea 301 {
ba379fdc 302 return branch32(cond, left, right);
9dae56ea
A
303 }
304
14957cd0 305 Jump branchPtr(RelationalCondition cond, Address left, TrustedImmPtr right)
9dae56ea 306 {
14957cd0 307 return branch32(cond, left, TrustedImm32(right));
9dae56ea
A
308 }
309
14957cd0 310 Jump branchPtr(RelationalCondition cond, AbsoluteAddress left, TrustedImmPtr right)
9dae56ea 311 {
14957cd0 312 return branch32(cond, left, TrustedImm32(right));
9dae56ea
A
313 }
314
14957cd0 315 Jump branchTestPtr(ResultCondition cond, RegisterID reg, RegisterID mask)
9dae56ea 316 {
ba379fdc 317 return branchTest32(cond, reg, mask);
9dae56ea
A
318 }
319
14957cd0 320 Jump branchTestPtr(ResultCondition cond, RegisterID reg, TrustedImm32 mask = TrustedImm32(-1))
9dae56ea 321 {
ba379fdc 322 return branchTest32(cond, reg, mask);
9dae56ea
A
323 }
324
14957cd0 325 Jump branchTestPtr(ResultCondition cond, Address address, TrustedImm32 mask = TrustedImm32(-1))
9dae56ea 326 {
ba379fdc 327 return branchTest32(cond, address, mask);
9dae56ea
A
328 }
329
14957cd0 330 Jump branchTestPtr(ResultCondition cond, BaseIndex address, TrustedImm32 mask = TrustedImm32(-1))
9dae56ea 331 {
ba379fdc 332 return branchTest32(cond, address, mask);
9dae56ea
A
333 }
334
9dae56ea 335
14957cd0 336 Jump branchAddPtr(ResultCondition cond, RegisterID src, RegisterID dest)
9dae56ea 337 {
ba379fdc 338 return branchAdd32(cond, src, dest);
9dae56ea
A
339 }
340
14957cd0 341 Jump branchSubPtr(ResultCondition cond, TrustedImm32 imm, RegisterID dest)
9dae56ea 342 {
ba379fdc 343 return branchSub32(cond, imm, dest);
9dae56ea 344 }
4e4e5a6f 345 using MacroAssemblerBase::branchTest8;
14957cd0 346 Jump branchTest8(ResultCondition cond, ExtendedAddress address, TrustedImm32 mask = TrustedImm32(-1))
4e4e5a6f
A
347 {
348 return MacroAssemblerBase::branchTest8(cond, Address(address.base, address.offset), mask);
349 }
9dae56ea 350#endif
9dae56ea 351
9dae56ea
A
352};
353
354} // namespace JSC
355
356#endif // ENABLE(ASSEMBLER)
357
358#endif // MacroAssembler_h