2 * Copyright (C) 2008 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
26 #ifndef MacroAssembler_h
27 #define MacroAssembler_h
32 #include "MacroAssemblerARMv7.h"
33 namespace JSC
{ typedef MacroAssemblerARMv7 MacroAssemblerBase
; };
35 #elif CPU(ARM_TRADITIONAL)
36 #include "MacroAssemblerARM.h"
37 namespace JSC
{ typedef MacroAssemblerARM MacroAssemblerBase
; };
40 #include "MacroAssemblerMIPS.h"
42 typedef MacroAssemblerMIPS MacroAssemblerBase
;
46 #include "MacroAssemblerX86.h"
47 namespace JSC
{ typedef MacroAssemblerX86 MacroAssemblerBase
; };
50 #include "MacroAssemblerX86_64.h"
51 namespace JSC
{ typedef MacroAssemblerX86_64 MacroAssemblerBase
; };
54 #include "MacroAssemblerSH4.h"
56 typedef MacroAssemblerSH4 MacroAssemblerBase
;
60 #error "The MacroAssembler is not supported on this platform."
66 class MacroAssembler
: public MacroAssemblerBase
{
69 using MacroAssemblerBase::pop
;
70 using MacroAssemblerBase::jump
;
71 using MacroAssemblerBase::branch32
;
72 using MacroAssemblerBase::branch16
;
74 using MacroAssemblerBase::branchPtr
;
75 using MacroAssemblerBase::branchTestPtr
;
79 // Platform agnostic onvenience functions,
80 // described in terms of other macro assembly methods.
83 addPtr(TrustedImm32(sizeof(void*)), stackPointerRegister
);
86 void peek(RegisterID dest
, int index
= 0)
88 loadPtr(Address(stackPointerRegister
, (index
* sizeof(void*))), dest
);
91 void poke(RegisterID src
, int index
= 0)
93 storePtr(src
, Address(stackPointerRegister
, (index
* sizeof(void*))));
96 void poke(TrustedImm32 value
, int index
= 0)
98 store32(value
, Address(stackPointerRegister
, (index
* sizeof(void*))));
101 void poke(TrustedImmPtr imm
, int index
= 0)
103 storePtr(imm
, Address(stackPointerRegister
, (index
* sizeof(void*))));
107 // Backwards banches, these are currently all implemented using existing forwards branch mechanisms.
108 void branchPtr(RelationalCondition cond
, RegisterID op1
, TrustedImmPtr imm
, Label target
)
110 branchPtr(cond
, op1
, imm
).linkTo(target
, this);
113 void branch32(RelationalCondition cond
, RegisterID op1
, RegisterID op2
, Label target
)
115 branch32(cond
, op1
, op2
).linkTo(target
, this);
118 void branch32(RelationalCondition cond
, RegisterID op1
, TrustedImm32 imm
, Label target
)
120 branch32(cond
, op1
, imm
).linkTo(target
, this);
123 void branch32(RelationalCondition cond
, RegisterID left
, Address right
, Label target
)
125 branch32(cond
, left
, right
).linkTo(target
, this);
128 void branch16(RelationalCondition cond
, BaseIndex left
, RegisterID right
, Label target
)
130 branch16(cond
, left
, right
).linkTo(target
, this);
133 void branchTestPtr(ResultCondition cond
, RegisterID reg
, Label target
)
135 branchTestPtr(cond
, reg
).linkTo(target
, this);
138 void jump(Label target
)
140 jump().linkTo(target
, this);
145 // On 32-bit platforms (i.e. x86), these methods directly map onto their 32-bit equivalents.
146 // FIXME: should this use a test for 32-bitness instead of this specific exception?
148 void addPtr(RegisterID src
, RegisterID dest
)
153 void addPtr(TrustedImm32 imm
, RegisterID srcDest
)
158 void addPtr(TrustedImmPtr imm
, RegisterID dest
)
160 add32(TrustedImm32(imm
), dest
);
163 void addPtr(TrustedImm32 imm
, RegisterID src
, RegisterID dest
)
165 add32(imm
, src
, dest
);
168 void andPtr(RegisterID src
, RegisterID dest
)
173 void andPtr(TrustedImm32 imm
, RegisterID srcDest
)
178 void orPtr(RegisterID src
, RegisterID dest
)
183 void orPtr(TrustedImmPtr imm
, RegisterID dest
)
185 or32(TrustedImm32(imm
), dest
);
188 void orPtr(TrustedImm32 imm
, RegisterID dest
)
193 void subPtr(RegisterID src
, RegisterID dest
)
198 void subPtr(TrustedImm32 imm
, RegisterID dest
)
203 void subPtr(TrustedImmPtr imm
, RegisterID dest
)
205 sub32(TrustedImm32(imm
), dest
);
208 void xorPtr(RegisterID src
, RegisterID dest
)
213 void xorPtr(TrustedImm32 imm
, RegisterID srcDest
)
219 void loadPtr(ImplicitAddress address
, RegisterID dest
)
221 load32(address
, dest
);
224 void loadPtr(BaseIndex address
, RegisterID dest
)
226 load32(address
, dest
);
229 void loadPtr(void* address
, RegisterID dest
)
231 load32(address
, dest
);
234 DataLabel32
loadPtrWithAddressOffsetPatch(Address address
, RegisterID dest
)
236 return load32WithAddressOffsetPatch(address
, dest
);
239 DataLabelCompact
loadPtrWithCompactAddressOffsetPatch(Address address
, RegisterID dest
)
241 return load32WithCompactAddressOffsetPatch(address
, dest
);
244 void comparePtr(RelationalCondition cond
, RegisterID left
, TrustedImm32 right
, RegisterID dest
)
246 compare32(cond
, left
, right
, dest
);
249 void storePtr(RegisterID src
, ImplicitAddress address
)
251 store32(src
, address
);
254 void storePtr(RegisterID src
, BaseIndex address
)
256 store32(src
, address
);
259 void storePtr(RegisterID src
, void* address
)
261 store32(src
, address
);
264 void storePtr(TrustedImmPtr imm
, ImplicitAddress address
)
266 store32(TrustedImm32(imm
), address
);
269 void storePtr(TrustedImmPtr imm
, void* address
)
271 store32(TrustedImm32(imm
), address
);
274 DataLabel32
storePtrWithAddressOffsetPatch(RegisterID src
, Address address
)
276 return store32WithAddressOffsetPatch(src
, address
);
280 Jump
branchPtr(RelationalCondition cond
, RegisterID left
, RegisterID right
)
282 return branch32(cond
, left
, right
);
285 Jump
branchPtr(RelationalCondition cond
, RegisterID left
, TrustedImmPtr right
)
287 return branch32(cond
, left
, TrustedImm32(right
));
290 Jump
branchPtr(RelationalCondition cond
, RegisterID left
, Address right
)
292 return branch32(cond
, left
, right
);
295 Jump
branchPtr(RelationalCondition cond
, Address left
, RegisterID right
)
297 return branch32(cond
, left
, right
);
300 Jump
branchPtr(RelationalCondition cond
, AbsoluteAddress left
, RegisterID right
)
302 return branch32(cond
, left
, right
);
305 Jump
branchPtr(RelationalCondition cond
, Address left
, TrustedImmPtr right
)
307 return branch32(cond
, left
, TrustedImm32(right
));
310 Jump
branchPtr(RelationalCondition cond
, AbsoluteAddress left
, TrustedImmPtr right
)
312 return branch32(cond
, left
, TrustedImm32(right
));
315 Jump
branchTestPtr(ResultCondition cond
, RegisterID reg
, RegisterID mask
)
317 return branchTest32(cond
, reg
, mask
);
320 Jump
branchTestPtr(ResultCondition cond
, RegisterID reg
, TrustedImm32 mask
= TrustedImm32(-1))
322 return branchTest32(cond
, reg
, mask
);
325 Jump
branchTestPtr(ResultCondition cond
, Address address
, TrustedImm32 mask
= TrustedImm32(-1))
327 return branchTest32(cond
, address
, mask
);
330 Jump
branchTestPtr(ResultCondition cond
, BaseIndex address
, TrustedImm32 mask
= TrustedImm32(-1))
332 return branchTest32(cond
, address
, mask
);
336 Jump
branchAddPtr(ResultCondition cond
, RegisterID src
, RegisterID dest
)
338 return branchAdd32(cond
, src
, dest
);
341 Jump
branchSubPtr(ResultCondition cond
, TrustedImm32 imm
, RegisterID dest
)
343 return branchSub32(cond
, imm
, dest
);
345 using MacroAssemblerBase::branchTest8
;
346 Jump
branchTest8(ResultCondition cond
, ExtendedAddress address
, TrustedImm32 mask
= TrustedImm32(-1))
348 return MacroAssemblerBase::branchTest8(cond
, Address(address
.base
, address
.offset
), mask
);
356 #endif // ENABLE(ASSEMBLER)
358 #endif // MacroAssembler_h