Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1 | // Copyright 2011 the V8 project authors. All rights reserved. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #ifndef V8_ARM_MACRO_ASSEMBLER_ARM_H_ |
| 29 | #define V8_ARM_MACRO_ASSEMBLER_ARM_H_ |
| 30 | |
| 31 | #include "assembler.h" |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame^] | 32 | #include "frames.h" |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 33 | #include "v8globals.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 34 | |
| 35 | namespace v8 { |
| 36 | namespace internal { |
| 37 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 38 | // ---------------------------------------------------------------------------- |
| 39 | // Static helper functions |
| 40 | |
| 41 | // Generate a MemOperand for loading a field from an object. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame^] | 42 | inline MemOperand FieldMemOperand(Register object, int offset) { |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 43 | return MemOperand(object, offset - kHeapObjectTag); |
| 44 | } |
| 45 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 46 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame^] | 47 | inline Operand SmiUntagOperand(Register object) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 48 | return Operand(object, ASR, kSmiTagSize); |
| 49 | } |
| 50 | |
| 51 | |
| 52 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 53 | // Give alias names to registers |
| 54 | const Register cp = { 8 }; // JavaScript context pointer |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame^] | 55 | const Register roots = { 10 }; // Roots array pointer. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 56 | |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 57 | // Flags used for the AllocateInNewSpace functions. |
| 58 | enum AllocationFlags { |
| 59 | // No special flags. |
| 60 | NO_ALLOCATION_FLAGS = 0, |
| 61 | // Return the pointer to the allocated already tagged as a heap object. |
| 62 | TAG_OBJECT = 1 << 0, |
| 63 | // The content of the result register already contains the allocation top in |
| 64 | // new space. |
| 65 | RESULT_CONTAINS_TOP = 1 << 1, |
| 66 | // Specify that the requested size of the space to allocate is specified in |
| 67 | // words instead of bytes. |
| 68 | SIZE_IN_WORDS = 1 << 2 |
| 69 | }; |
| 70 | |
| 71 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 72 | // Flags used for the ObjectToDoubleVFPRegister function. |
| 73 | enum ObjectToDoubleFlags { |
| 74 | // No special flags. |
| 75 | NO_OBJECT_TO_DOUBLE_FLAGS = 0, |
| 76 | // Object is known to be a non smi. |
| 77 | OBJECT_NOT_SMI = 1 << 0, |
| 78 | // Don't load NaNs or infinities, branch to the non number case instead. |
| 79 | AVOID_NANS_AND_INFINITIES = 1 << 1 |
| 80 | }; |
| 81 | |
| 82 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame^] | 83 | enum RememberedSetAction { EMIT_REMEMBERED_SET, OMIT_REMEMBERED_SET }; |
| 84 | enum SmiCheck { INLINE_SMI_CHECK, OMIT_SMI_CHECK }; |
| 85 | enum LinkRegisterStatus { kLRHasNotBeenSaved, kLRHasBeenSaved }; |
| 86 | |
| 87 | |
| 88 | bool AreAliased(Register r1, Register r2, Register r3, Register r4); |
| 89 | |
| 90 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 91 | // MacroAssembler implements a collection of frequently used macros. |
| 92 | class MacroAssembler: public Assembler { |
| 93 | public: |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 94 | // The isolate parameter can be NULL if the macro assembler should |
| 95 | // not use isolate-dependent functionality. In this case, it's the |
| 96 | // responsibility of the caller to never invoke such function on the |
| 97 | // macro assembler. |
| 98 | MacroAssembler(Isolate* isolate, void* buffer, int size); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 99 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 100 | // Jump, Call, and Ret pseudo instructions implementing inter-working. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 101 | void Jump(Register target, Condition cond = al); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 102 | void Jump(Address target, RelocInfo::Mode rmode, Condition cond = al); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 103 | void Jump(Handle<Code> code, RelocInfo::Mode rmode, Condition cond = al); |
Ben Murdoch | 42effa5 | 2011-08-19 16:40:31 +0100 | [diff] [blame] | 104 | static int CallSize(Register target, Condition cond = al); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 105 | void Call(Register target, Condition cond = al); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 106 | static int CallSize(Address target, |
Ben Murdoch | 42effa5 | 2011-08-19 16:40:31 +0100 | [diff] [blame] | 107 | RelocInfo::Mode rmode, |
| 108 | Condition cond = al); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 109 | void Call(Address target, RelocInfo::Mode rmode, Condition cond = al); |
| 110 | static int CallSize(Handle<Code> code, |
| 111 | RelocInfo::Mode rmode = RelocInfo::CODE_TARGET, |
| 112 | unsigned ast_id = kNoASTId, |
| 113 | Condition cond = al); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 114 | void Call(Handle<Code> code, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 115 | RelocInfo::Mode rmode = RelocInfo::CODE_TARGET, |
| 116 | unsigned ast_id = kNoASTId, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 117 | Condition cond = al); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 118 | void Ret(Condition cond = al); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 119 | |
| 120 | // Emit code to discard a non-negative number of pointer-sized elements |
| 121 | // from the stack, clobbering only the sp register. |
| 122 | void Drop(int count, Condition cond = al); |
| 123 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 124 | void Ret(int drop, Condition cond = al); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 125 | |
| 126 | // Swap two registers. If the scratch register is omitted then a slightly |
| 127 | // less efficient form using xor instead of mov is emitted. |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 128 | void Swap(Register reg1, |
| 129 | Register reg2, |
| 130 | Register scratch = no_reg, |
| 131 | Condition cond = al); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 132 | |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 133 | |
| 134 | void And(Register dst, Register src1, const Operand& src2, |
| 135 | Condition cond = al); |
| 136 | void Ubfx(Register dst, Register src, int lsb, int width, |
| 137 | Condition cond = al); |
| 138 | void Sbfx(Register dst, Register src, int lsb, int width, |
| 139 | Condition cond = al); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 140 | // The scratch register is not used for ARMv7. |
| 141 | // scratch can be the same register as src (in which case it is trashed), but |
| 142 | // not the same as dst. |
| 143 | void Bfi(Register dst, |
| 144 | Register src, |
| 145 | Register scratch, |
| 146 | int lsb, |
| 147 | int width, |
| 148 | Condition cond = al); |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 149 | void Bfc(Register dst, int lsb, int width, Condition cond = al); |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame] | 150 | void Usat(Register dst, int satpos, const Operand& src, |
| 151 | Condition cond = al); |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 152 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 153 | void Call(Label* target); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 154 | |
| 155 | // Register move. May do nothing if the registers are identical. |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 156 | void Move(Register dst, Handle<Object> value); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 157 | void Move(Register dst, Register src, Condition cond = al); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 158 | void Move(DoubleRegister dst, DoubleRegister src); |
| 159 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 160 | // Load an object from the root table. |
| 161 | void LoadRoot(Register destination, |
| 162 | Heap::RootListIndex index, |
| 163 | Condition cond = al); |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 164 | // Store an object to the root table. |
| 165 | void StoreRoot(Register source, |
| 166 | Heap::RootListIndex index, |
| 167 | Condition cond = al); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 168 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame^] | 169 | // --------------------------------------------------------------------------- |
| 170 | // GC Support |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 171 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame^] | 172 | void IncrementalMarkingRecordWriteHelper(Register object, |
| 173 | Register value, |
| 174 | Register address); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 175 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame^] | 176 | enum RememberedSetFinalAction { |
| 177 | kReturnAtEnd, |
| 178 | kFallThroughAtEnd |
| 179 | }; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 180 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame^] | 181 | // Record in the remembered set the fact that we have a pointer to new space |
| 182 | // at the address pointed to by the addr register. Only works if addr is not |
| 183 | // in new space. |
| 184 | void RememberedSetHelper(Register object, // Used for debug code. |
| 185 | Register addr, |
| 186 | Register scratch, |
| 187 | SaveFPRegsMode save_fp, |
| 188 | RememberedSetFinalAction and_then); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 189 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame^] | 190 | void CheckPageFlag(Register object, |
| 191 | Register scratch, |
| 192 | int mask, |
| 193 | Condition cc, |
| 194 | Label* condition_met); |
| 195 | |
| 196 | // Check if object is in new space. Jumps if the object is not in new space. |
| 197 | // The register scratch can be object itself, but scratch will be clobbered. |
| 198 | void JumpIfNotInNewSpace(Register object, |
| 199 | Register scratch, |
| 200 | Label* branch) { |
| 201 | InNewSpace(object, scratch, ne, branch); |
| 202 | } |
| 203 | |
| 204 | // Check if object is in new space. Jumps if the object is in new space. |
| 205 | // The register scratch can be object itself, but it will be clobbered. |
| 206 | void JumpIfInNewSpace(Register object, |
| 207 | Register scratch, |
| 208 | Label* branch) { |
| 209 | InNewSpace(object, scratch, eq, branch); |
| 210 | } |
| 211 | |
| 212 | // Check if an object has a given incremental marking color. |
| 213 | void HasColor(Register object, |
| 214 | Register scratch0, |
| 215 | Register scratch1, |
| 216 | Label* has_color, |
| 217 | int first_bit, |
| 218 | int second_bit); |
| 219 | |
| 220 | void JumpIfBlack(Register object, |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 221 | Register scratch0, |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame^] | 222 | Register scratch1, |
| 223 | Label* on_black); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 224 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame^] | 225 | // Checks the color of an object. If the object is already grey or black |
| 226 | // then we just fall through, since it is already live. If it is white and |
| 227 | // we can determine that it doesn't need to be scanned, then we just mark it |
| 228 | // black and fall through. For the rest we jump to the label so the |
| 229 | // incremental marker can fix its assumptions. |
| 230 | void EnsureNotWhite(Register object, |
| 231 | Register scratch1, |
| 232 | Register scratch2, |
| 233 | Register scratch3, |
| 234 | Label* object_is_white_and_not_data); |
| 235 | |
| 236 | // Detects conservatively whether an object is data-only, ie it does need to |
| 237 | // be scanned by the garbage collector. |
| 238 | void JumpIfDataObject(Register value, |
| 239 | Register scratch, |
| 240 | Label* not_data_object); |
| 241 | |
| 242 | // Notify the garbage collector that we wrote a pointer into an object. |
| 243 | // |object| is the object being stored into, |value| is the object being |
| 244 | // stored. value and scratch registers are clobbered by the operation. |
| 245 | // The offset is the offset from the start of the object, not the offset from |
| 246 | // the tagged HeapObject pointer. For use with FieldOperand(reg, off). |
| 247 | void RecordWriteField( |
| 248 | Register object, |
| 249 | int offset, |
| 250 | Register value, |
| 251 | Register scratch, |
| 252 | LinkRegisterStatus lr_status, |
| 253 | SaveFPRegsMode save_fp, |
| 254 | RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET, |
| 255 | SmiCheck smi_check = INLINE_SMI_CHECK); |
| 256 | |
| 257 | // As above, but the offset has the tag presubtracted. For use with |
| 258 | // MemOperand(reg, off). |
| 259 | inline void RecordWriteContextSlot( |
| 260 | Register context, |
| 261 | int offset, |
| 262 | Register value, |
| 263 | Register scratch, |
| 264 | LinkRegisterStatus lr_status, |
| 265 | SaveFPRegsMode save_fp, |
| 266 | RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET, |
| 267 | SmiCheck smi_check = INLINE_SMI_CHECK) { |
| 268 | RecordWriteField(context, |
| 269 | offset + kHeapObjectTag, |
| 270 | value, |
| 271 | scratch, |
| 272 | lr_status, |
| 273 | save_fp, |
| 274 | remembered_set_action, |
| 275 | smi_check); |
| 276 | } |
| 277 | |
| 278 | // For a given |object| notify the garbage collector that the slot |address| |
| 279 | // has been written. |value| is the object being stored. The value and |
| 280 | // address registers are clobbered by the operation. |
| 281 | void RecordWrite( |
| 282 | Register object, |
| 283 | Register address, |
| 284 | Register value, |
| 285 | LinkRegisterStatus lr_status, |
| 286 | SaveFPRegsMode save_fp, |
| 287 | RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET, |
| 288 | SmiCheck smi_check = INLINE_SMI_CHECK); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 289 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 290 | // Push a handle. |
| 291 | void Push(Handle<Object> handle); |
| 292 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 293 | // Push two registers. Pushes leftmost register first (to highest address). |
| 294 | void Push(Register src1, Register src2, Condition cond = al) { |
| 295 | ASSERT(!src1.is(src2)); |
| 296 | if (src1.code() > src2.code()) { |
| 297 | stm(db_w, sp, src1.bit() | src2.bit(), cond); |
| 298 | } else { |
| 299 | str(src1, MemOperand(sp, 4, NegPreIndex), cond); |
| 300 | str(src2, MemOperand(sp, 4, NegPreIndex), cond); |
| 301 | } |
| 302 | } |
| 303 | |
| 304 | // Push three registers. Pushes leftmost register first (to highest address). |
| 305 | void Push(Register src1, Register src2, Register src3, Condition cond = al) { |
| 306 | ASSERT(!src1.is(src2)); |
| 307 | ASSERT(!src2.is(src3)); |
| 308 | ASSERT(!src1.is(src3)); |
| 309 | if (src1.code() > src2.code()) { |
| 310 | if (src2.code() > src3.code()) { |
| 311 | stm(db_w, sp, src1.bit() | src2.bit() | src3.bit(), cond); |
| 312 | } else { |
| 313 | stm(db_w, sp, src1.bit() | src2.bit(), cond); |
| 314 | str(src3, MemOperand(sp, 4, NegPreIndex), cond); |
| 315 | } |
| 316 | } else { |
| 317 | str(src1, MemOperand(sp, 4, NegPreIndex), cond); |
| 318 | Push(src2, src3, cond); |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | // Push four registers. Pushes leftmost register first (to highest address). |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame^] | 323 | void Push(Register src1, |
| 324 | Register src2, |
| 325 | Register src3, |
| 326 | Register src4, |
| 327 | Condition cond = al) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 328 | ASSERT(!src1.is(src2)); |
| 329 | ASSERT(!src2.is(src3)); |
| 330 | ASSERT(!src1.is(src3)); |
| 331 | ASSERT(!src1.is(src4)); |
| 332 | ASSERT(!src2.is(src4)); |
| 333 | ASSERT(!src3.is(src4)); |
| 334 | if (src1.code() > src2.code()) { |
| 335 | if (src2.code() > src3.code()) { |
| 336 | if (src3.code() > src4.code()) { |
| 337 | stm(db_w, |
| 338 | sp, |
| 339 | src1.bit() | src2.bit() | src3.bit() | src4.bit(), |
| 340 | cond); |
| 341 | } else { |
| 342 | stm(db_w, sp, src1.bit() | src2.bit() | src3.bit(), cond); |
| 343 | str(src4, MemOperand(sp, 4, NegPreIndex), cond); |
| 344 | } |
| 345 | } else { |
| 346 | stm(db_w, sp, src1.bit() | src2.bit(), cond); |
| 347 | Push(src3, src4, cond); |
| 348 | } |
| 349 | } else { |
| 350 | str(src1, MemOperand(sp, 4, NegPreIndex), cond); |
| 351 | Push(src2, src3, src4, cond); |
| 352 | } |
| 353 | } |
| 354 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 355 | // Pop two registers. Pops rightmost register first (from lower address). |
| 356 | void Pop(Register src1, Register src2, Condition cond = al) { |
| 357 | ASSERT(!src1.is(src2)); |
| 358 | if (src1.code() > src2.code()) { |
| 359 | ldm(ia_w, sp, src1.bit() | src2.bit(), cond); |
| 360 | } else { |
| 361 | ldr(src2, MemOperand(sp, 4, PostIndex), cond); |
| 362 | ldr(src1, MemOperand(sp, 4, PostIndex), cond); |
| 363 | } |
| 364 | } |
| 365 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame^] | 366 | // Pop three registers. Pops rightmost register first (from lower address). |
| 367 | void Pop(Register src1, Register src2, Register src3, Condition cond = al) { |
| 368 | ASSERT(!src1.is(src2)); |
| 369 | ASSERT(!src2.is(src3)); |
| 370 | ASSERT(!src1.is(src3)); |
| 371 | if (src1.code() > src2.code()) { |
| 372 | if (src2.code() > src3.code()) { |
| 373 | ldm(ia_w, sp, src1.bit() | src2.bit() | src3.bit(), cond); |
| 374 | } else { |
| 375 | ldr(src3, MemOperand(sp, 4, PostIndex), cond); |
| 376 | ldm(ia_w, sp, src1.bit() | src2.bit(), cond); |
| 377 | } |
| 378 | } else { |
| 379 | Pop(src2, src3, cond); |
| 380 | str(src1, MemOperand(sp, 4, PostIndex), cond); |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | // Pop four registers. Pops rightmost register first (from lower address). |
| 385 | void Pop(Register src1, |
| 386 | Register src2, |
| 387 | Register src3, |
| 388 | Register src4, |
| 389 | Condition cond = al) { |
| 390 | ASSERT(!src1.is(src2)); |
| 391 | ASSERT(!src2.is(src3)); |
| 392 | ASSERT(!src1.is(src3)); |
| 393 | ASSERT(!src1.is(src4)); |
| 394 | ASSERT(!src2.is(src4)); |
| 395 | ASSERT(!src3.is(src4)); |
| 396 | if (src1.code() > src2.code()) { |
| 397 | if (src2.code() > src3.code()) { |
| 398 | if (src3.code() > src4.code()) { |
| 399 | ldm(ia_w, |
| 400 | sp, |
| 401 | src1.bit() | src2.bit() | src3.bit() | src4.bit(), |
| 402 | cond); |
| 403 | } else { |
| 404 | ldr(src4, MemOperand(sp, 4, PostIndex), cond); |
| 405 | ldm(ia_w, sp, src1.bit() | src2.bit() | src3.bit(), cond); |
| 406 | } |
| 407 | } else { |
| 408 | Pop(src3, src4, cond); |
| 409 | ldm(ia_w, sp, src1.bit() | src2.bit(), cond); |
| 410 | } |
| 411 | } else { |
| 412 | Pop(src2, src3, src4, cond); |
| 413 | ldr(src1, MemOperand(sp, 4, PostIndex), cond); |
| 414 | } |
| 415 | } |
| 416 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 417 | // Push and pop the registers that can hold pointers, as defined by the |
| 418 | // RegList constant kSafepointSavedRegisters. |
| 419 | void PushSafepointRegisters(); |
| 420 | void PopSafepointRegisters(); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 421 | void PushSafepointRegistersAndDoubles(); |
| 422 | void PopSafepointRegistersAndDoubles(); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 423 | // Store value in register src in the safepoint stack slot for |
| 424 | // register dst. |
| 425 | void StoreToSafepointRegisterSlot(Register src, Register dst); |
| 426 | void StoreToSafepointRegistersAndDoublesSlot(Register src, Register dst); |
| 427 | // Load the value of the src register from its safepoint stack slot |
| 428 | // into register dst. |
| 429 | void LoadFromSafepointRegisterSlot(Register dst, Register src); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 430 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 431 | // Load two consecutive registers with two consecutive memory locations. |
| 432 | void Ldrd(Register dst1, |
| 433 | Register dst2, |
| 434 | const MemOperand& src, |
| 435 | Condition cond = al); |
| 436 | |
| 437 | // Store two consecutive registers to two consecutive memory locations. |
| 438 | void Strd(Register src1, |
| 439 | Register src2, |
| 440 | const MemOperand& dst, |
| 441 | Condition cond = al); |
| 442 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 443 | // Clear specified FPSCR bits. |
| 444 | void ClearFPSCRBits(const uint32_t bits_to_clear, |
| 445 | const Register scratch, |
| 446 | const Condition cond = al); |
| 447 | |
| 448 | // Compare double values and move the result to the normal condition flags. |
| 449 | void VFPCompareAndSetFlags(const DwVfpRegister src1, |
| 450 | const DwVfpRegister src2, |
| 451 | const Condition cond = al); |
| 452 | void VFPCompareAndSetFlags(const DwVfpRegister src1, |
| 453 | const double src2, |
| 454 | const Condition cond = al); |
| 455 | |
| 456 | // Compare double values and then load the fpscr flags to a register. |
| 457 | void VFPCompareAndLoadFlags(const DwVfpRegister src1, |
| 458 | const DwVfpRegister src2, |
| 459 | const Register fpscr_flags, |
| 460 | const Condition cond = al); |
| 461 | void VFPCompareAndLoadFlags(const DwVfpRegister src1, |
| 462 | const double src2, |
| 463 | const Register fpscr_flags, |
| 464 | const Condition cond = al); |
| 465 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 466 | void Vmov(const DwVfpRegister dst, |
| 467 | const double imm, |
| 468 | const Condition cond = al); |
| 469 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 470 | // Enter exit frame. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 471 | // stack_space - extra stack space, used for alignment before call to C. |
| 472 | void EnterExitFrame(bool save_doubles, int stack_space = 0); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 473 | |
| 474 | // Leave the current exit frame. Expects the return value in r0. |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 475 | // Expect the number of values, pushed prior to the exit frame, to |
| 476 | // remove in a register (or no_reg, if there is nothing to remove). |
| 477 | void LeaveExitFrame(bool save_doubles, Register argument_count); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 478 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 479 | // Get the actual activation frame alignment for target environment. |
| 480 | static int ActivationFrameAlignment(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 481 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 482 | void LoadContext(Register dst, int context_chain_length); |
| 483 | |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 484 | void LoadGlobalFunction(int index, Register function); |
| 485 | |
| 486 | // Load the initial map from the global function. The registers |
| 487 | // function and map can be the same, function is then overwritten. |
| 488 | void LoadGlobalFunctionInitialMap(Register function, |
| 489 | Register map, |
| 490 | Register scratch); |
| 491 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 492 | // --------------------------------------------------------------------------- |
| 493 | // JavaScript invokes |
| 494 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 495 | // Setup call kind marking in ecx. The method takes ecx as an |
| 496 | // explicit first parameter to make the code more readable at the |
| 497 | // call sites. |
| 498 | void SetCallKind(Register dst, CallKind kind); |
| 499 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 500 | // Invoke the JavaScript function code by either calling or jumping. |
| 501 | void InvokeCode(Register code, |
| 502 | const ParameterCount& expected, |
| 503 | const ParameterCount& actual, |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 504 | InvokeFlag flag, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 505 | const CallWrapper& call_wrapper, |
| 506 | CallKind call_kind); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 507 | |
| 508 | void InvokeCode(Handle<Code> code, |
| 509 | const ParameterCount& expected, |
| 510 | const ParameterCount& actual, |
| 511 | RelocInfo::Mode rmode, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 512 | InvokeFlag flag, |
| 513 | CallKind call_kind); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 514 | |
| 515 | // Invoke the JavaScript function in the given register. Changes the |
| 516 | // current context to the context in the function before invoking. |
| 517 | void InvokeFunction(Register function, |
| 518 | const ParameterCount& actual, |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 519 | InvokeFlag flag, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 520 | const CallWrapper& call_wrapper, |
| 521 | CallKind call_kind); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 522 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame^] | 523 | void InvokeFunction(Handle<JSFunction> function, |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 524 | const ParameterCount& actual, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 525 | InvokeFlag flag, |
| 526 | CallKind call_kind); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 527 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 528 | void IsObjectJSObjectType(Register heap_object, |
| 529 | Register map, |
| 530 | Register scratch, |
| 531 | Label* fail); |
| 532 | |
| 533 | void IsInstanceJSObjectType(Register map, |
| 534 | Register scratch, |
| 535 | Label* fail); |
| 536 | |
| 537 | void IsObjectJSStringType(Register object, |
| 538 | Register scratch, |
| 539 | Label* fail); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 540 | |
| 541 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 542 | // --------------------------------------------------------------------------- |
| 543 | // Debugger Support |
| 544 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 545 | void DebugBreak(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 546 | #endif |
| 547 | |
| 548 | // --------------------------------------------------------------------------- |
| 549 | // Exception handling |
| 550 | |
| 551 | // Push a new try handler and link into try handler chain. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame^] | 552 | void PushTryHandler(CodeLocation try_location, |
| 553 | HandlerType type, |
| 554 | int handler_index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 555 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 556 | // Unlink the stack handler on top of the stack from the try handler chain. |
| 557 | // Must preserve the result register. |
| 558 | void PopTryHandler(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 559 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 560 | // Passes thrown value (in r0) to the handler of top of the try handler chain. |
| 561 | void Throw(Register value); |
| 562 | |
| 563 | // Propagates an uncatchable exception to the top of the current JS stack's |
| 564 | // handler chain. |
| 565 | void ThrowUncatchable(UncatchableExceptionType type, Register value); |
| 566 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 567 | // --------------------------------------------------------------------------- |
| 568 | // Inline caching support |
| 569 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 570 | // Generate code for checking access rights - used for security checks |
| 571 | // on access to global objects across environments. The holder register |
| 572 | // is left untouched, whereas both scratch registers are clobbered. |
| 573 | void CheckAccessGlobalProxy(Register holder_reg, |
| 574 | Register scratch, |
| 575 | Label* miss); |
| 576 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 577 | |
| 578 | void LoadFromNumberDictionary(Label* miss, |
| 579 | Register elements, |
| 580 | Register key, |
| 581 | Register result, |
| 582 | Register t0, |
| 583 | Register t1, |
| 584 | Register t2); |
| 585 | |
| 586 | |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 587 | inline void MarkCode(NopMarkerTypes type) { |
| 588 | nop(type); |
| 589 | } |
| 590 | |
| 591 | // Check if the given instruction is a 'type' marker. |
| 592 | // ie. check if is is a mov r<type>, r<type> (referenced as nop(type)) |
| 593 | // These instructions are generated to mark special location in the code, |
| 594 | // like some special IC code. |
| 595 | static inline bool IsMarkedCode(Instr instr, int type) { |
| 596 | ASSERT((FIRST_IC_MARKER <= type) && (type < LAST_CODE_MARKER)); |
| 597 | return IsNop(instr, type); |
| 598 | } |
| 599 | |
| 600 | |
| 601 | static inline int GetCodeMarker(Instr instr) { |
| 602 | int dst_reg_offset = 12; |
| 603 | int dst_mask = 0xf << dst_reg_offset; |
| 604 | int src_mask = 0xf; |
| 605 | int dst_reg = (instr & dst_mask) >> dst_reg_offset; |
| 606 | int src_reg = instr & src_mask; |
| 607 | uint32_t non_register_mask = ~(dst_mask | src_mask); |
| 608 | uint32_t mov_mask = al | 13 << 21; |
| 609 | |
| 610 | // Return <n> if we have a mov rn rn, else return -1. |
| 611 | int type = ((instr & non_register_mask) == mov_mask) && |
| 612 | (dst_reg == src_reg) && |
| 613 | (FIRST_IC_MARKER <= dst_reg) && (dst_reg < LAST_CODE_MARKER) |
| 614 | ? src_reg |
| 615 | : -1; |
| 616 | ASSERT((type == -1) || |
| 617 | ((FIRST_IC_MARKER <= type) && (type < LAST_CODE_MARKER))); |
| 618 | return type; |
| 619 | } |
| 620 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 621 | |
| 622 | // --------------------------------------------------------------------------- |
| 623 | // Allocation support |
| 624 | |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 625 | // Allocate an object in new space. The object_size is specified |
| 626 | // either in bytes or in words if the allocation flag SIZE_IN_WORDS |
| 627 | // is passed. If the new space is exhausted control continues at the |
| 628 | // gc_required label. The allocated object is returned in result. If |
| 629 | // the flag tag_allocated_object is true the result is tagged as as |
| 630 | // a heap object. All registers are clobbered also when control |
| 631 | // continues at the gc_required label. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 632 | void AllocateInNewSpace(int object_size, |
| 633 | Register result, |
| 634 | Register scratch1, |
| 635 | Register scratch2, |
| 636 | Label* gc_required, |
| 637 | AllocationFlags flags); |
| 638 | void AllocateInNewSpace(Register object_size, |
| 639 | Register result, |
| 640 | Register scratch1, |
| 641 | Register scratch2, |
| 642 | Label* gc_required, |
| 643 | AllocationFlags flags); |
| 644 | |
| 645 | // Undo allocation in new space. The object passed and objects allocated after |
| 646 | // it will no longer be allocated. The caller must make sure that no pointers |
| 647 | // are left to the object(s) no longer allocated as they would be invalid when |
| 648 | // allocation is undone. |
| 649 | void UndoAllocationInNewSpace(Register object, Register scratch); |
| 650 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 651 | |
| 652 | void AllocateTwoByteString(Register result, |
| 653 | Register length, |
| 654 | Register scratch1, |
| 655 | Register scratch2, |
| 656 | Register scratch3, |
| 657 | Label* gc_required); |
| 658 | void AllocateAsciiString(Register result, |
| 659 | Register length, |
| 660 | Register scratch1, |
| 661 | Register scratch2, |
| 662 | Register scratch3, |
| 663 | Label* gc_required); |
| 664 | void AllocateTwoByteConsString(Register result, |
| 665 | Register length, |
| 666 | Register scratch1, |
| 667 | Register scratch2, |
| 668 | Label* gc_required); |
| 669 | void AllocateAsciiConsString(Register result, |
| 670 | Register length, |
| 671 | Register scratch1, |
| 672 | Register scratch2, |
| 673 | Label* gc_required); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 674 | void AllocateTwoByteSlicedString(Register result, |
| 675 | Register length, |
| 676 | Register scratch1, |
| 677 | Register scratch2, |
| 678 | Label* gc_required); |
| 679 | void AllocateAsciiSlicedString(Register result, |
| 680 | Register length, |
| 681 | Register scratch1, |
| 682 | Register scratch2, |
| 683 | Label* gc_required); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 684 | |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 685 | // Allocates a heap number or jumps to the gc_required label if the young |
| 686 | // space is full and a scavenge is needed. All registers are clobbered also |
| 687 | // when control continues at the gc_required label. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 688 | void AllocateHeapNumber(Register result, |
| 689 | Register scratch1, |
| 690 | Register scratch2, |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 691 | Register heap_number_map, |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 692 | Label* gc_required); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 693 | void AllocateHeapNumberWithValue(Register result, |
| 694 | DwVfpRegister value, |
| 695 | Register scratch1, |
| 696 | Register scratch2, |
| 697 | Register heap_number_map, |
| 698 | Label* gc_required); |
| 699 | |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 700 | // Copies a fixed number of fields of heap objects from src to dst. |
| 701 | void CopyFields(Register dst, Register src, RegList temps, int field_count); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 702 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 703 | // Copies a number of bytes from src to dst. All registers are clobbered. On |
| 704 | // exit src and dst will point to the place just after where the last byte was |
| 705 | // read or written and length will be zero. |
| 706 | void CopyBytes(Register src, |
| 707 | Register dst, |
| 708 | Register length, |
| 709 | Register scratch); |
| 710 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame^] | 711 | // Initialize fields with filler values. Fields starting at |start_offset| |
| 712 | // not including end_offset are overwritten with the value in |filler|. At |
| 713 | // the end the loop, |start_offset| takes the value of |end_offset|. |
| 714 | void InitializeFieldsWithFiller(Register start_offset, |
| 715 | Register end_offset, |
| 716 | Register filler); |
| 717 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 718 | // --------------------------------------------------------------------------- |
| 719 | // Support functions. |
| 720 | |
| 721 | // Try to get function prototype of a function and puts the value in |
| 722 | // the result register. Checks that the function really is a |
| 723 | // function and jumps to the miss label if the fast checks fail. The |
| 724 | // function register will be untouched; the other registers may be |
| 725 | // clobbered. |
| 726 | void TryGetFunctionPrototype(Register function, |
| 727 | Register result, |
| 728 | Register scratch, |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame^] | 729 | Label* miss, |
| 730 | bool miss_on_bound_function = false); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 731 | |
| 732 | // Compare object type for heap object. heap_object contains a non-Smi |
| 733 | // whose object type should be compared with the given type. This both |
| 734 | // sets the flags and leaves the object type in the type_reg register. |
| 735 | // It leaves the map in the map register (unless the type_reg and map register |
| 736 | // are the same register). It leaves the heap object in the heap_object |
| 737 | // register unless the heap_object register is the same register as one of the |
| 738 | // other registers. |
| 739 | void CompareObjectType(Register heap_object, |
| 740 | Register map, |
| 741 | Register type_reg, |
| 742 | InstanceType type); |
| 743 | |
| 744 | // Compare instance type in a map. map contains a valid map object whose |
| 745 | // object type should be compared with the given type. This both |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 746 | // sets the flags and leaves the object type in the type_reg register. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 747 | void CompareInstanceType(Register map, |
| 748 | Register type_reg, |
| 749 | InstanceType type); |
| 750 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 751 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 752 | // Check if a map for a JSObject indicates that the object has fast elements. |
| 753 | // Jump to the specified label if it does not. |
| 754 | void CheckFastElements(Register map, |
| 755 | Register scratch, |
| 756 | Label* fail); |
| 757 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame^] | 758 | // Check if a map for a JSObject indicates that the object can have both smi |
| 759 | // and HeapObject elements. Jump to the specified label if it does not. |
| 760 | void CheckFastObjectElements(Register map, |
| 761 | Register scratch, |
| 762 | Label* fail); |
| 763 | |
| 764 | // Check if a map for a JSObject indicates that the object has fast smi only |
| 765 | // elements. Jump to the specified label if it does not. |
| 766 | void CheckFastSmiOnlyElements(Register map, |
| 767 | Register scratch, |
| 768 | Label* fail); |
| 769 | |
| 770 | // Check to see if maybe_number can be stored as a double in |
| 771 | // FastDoubleElements. If it can, store it at the index specified by key in |
| 772 | // the FastDoubleElements array elements, otherwise jump to fail. |
| 773 | void StoreNumberToDoubleElements(Register value_reg, |
| 774 | Register key_reg, |
| 775 | Register receiver_reg, |
| 776 | Register elements_reg, |
| 777 | Register scratch1, |
| 778 | Register scratch2, |
| 779 | Register scratch3, |
| 780 | Register scratch4, |
| 781 | Label* fail); |
| 782 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 783 | // Check if the map of an object is equal to a specified map (either |
| 784 | // given directly or as an index into the root list) and branch to |
| 785 | // label if not. Skip the smi check if not required (object is known |
| 786 | // to be a heap object) |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 787 | void CheckMap(Register obj, |
| 788 | Register scratch, |
| 789 | Handle<Map> map, |
| 790 | Label* fail, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 791 | SmiCheckType smi_check_type); |
| 792 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 793 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 794 | void CheckMap(Register obj, |
| 795 | Register scratch, |
| 796 | Heap::RootListIndex index, |
| 797 | Label* fail, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 798 | SmiCheckType smi_check_type); |
| 799 | |
| 800 | |
| 801 | // Check if the map of an object is equal to a specified map and branch to a |
| 802 | // specified target if equal. Skip the smi check if not required (object is |
| 803 | // known to be a heap object) |
| 804 | void DispatchMap(Register obj, |
| 805 | Register scratch, |
| 806 | Handle<Map> map, |
| 807 | Handle<Code> success, |
| 808 | SmiCheckType smi_check_type); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 809 | |
| 810 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 811 | // Compare the object in a register to a value from the root list. |
| 812 | // Uses the ip register as scratch. |
| 813 | void CompareRoot(Register obj, Heap::RootListIndex index); |
| 814 | |
| 815 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 816 | // Load and check the instance type of an object for being a string. |
| 817 | // Loads the type into the second argument register. |
| 818 | // Returns a condition that will be enabled if the object was a string. |
| 819 | Condition IsObjectStringType(Register obj, |
| 820 | Register type) { |
| 821 | ldr(type, FieldMemOperand(obj, HeapObject::kMapOffset)); |
| 822 | ldrb(type, FieldMemOperand(type, Map::kInstanceTypeOffset)); |
| 823 | tst(type, Operand(kIsNotStringMask)); |
| 824 | ASSERT_EQ(0, kStringTag); |
| 825 | return eq; |
| 826 | } |
| 827 | |
| 828 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 829 | // Generates code for reporting that an illegal operation has |
| 830 | // occurred. |
| 831 | void IllegalOperation(int num_arguments); |
| 832 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 833 | // Picks out an array index from the hash field. |
| 834 | // Register use: |
| 835 | // hash - holds the index's hash. Clobbered. |
| 836 | // index - holds the overwritten index on exit. |
| 837 | void IndexFromHash(Register hash, Register index); |
| 838 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 839 | // Get the number of least significant bits from a register |
| 840 | void GetLeastBitsFromSmi(Register dst, Register src, int num_least_bits); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 841 | void GetLeastBitsFromInt32(Register dst, Register src, int mun_least_bits); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 842 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 843 | // Uses VFP instructions to Convert a Smi to a double. |
| 844 | void IntegerToDoubleConversionWithVFP3(Register inReg, |
| 845 | Register outHighReg, |
| 846 | Register outLowReg); |
| 847 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 848 | // Load the value of a number object into a VFP double register. If the object |
| 849 | // is not a number a jump to the label not_number is performed and the VFP |
| 850 | // double register is unchanged. |
| 851 | void ObjectToDoubleVFPRegister( |
| 852 | Register object, |
| 853 | DwVfpRegister value, |
| 854 | Register scratch1, |
| 855 | Register scratch2, |
| 856 | Register heap_number_map, |
| 857 | SwVfpRegister scratch3, |
| 858 | Label* not_number, |
| 859 | ObjectToDoubleFlags flags = NO_OBJECT_TO_DOUBLE_FLAGS); |
| 860 | |
| 861 | // Load the value of a smi object into a VFP double register. The register |
| 862 | // scratch1 can be the same register as smi in which case smi will hold the |
| 863 | // untagged value afterwards. |
| 864 | void SmiToDoubleVFPRegister(Register smi, |
| 865 | DwVfpRegister value, |
| 866 | Register scratch1, |
| 867 | SwVfpRegister scratch2); |
| 868 | |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 869 | // Convert the HeapNumber pointed to by source to a 32bits signed integer |
| 870 | // dest. If the HeapNumber does not fit into a 32bits signed integer branch |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 871 | // to not_int32 label. If VFP3 is available double_scratch is used but not |
| 872 | // scratch2. |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 873 | void ConvertToInt32(Register source, |
| 874 | Register dest, |
| 875 | Register scratch, |
| 876 | Register scratch2, |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 877 | DwVfpRegister double_scratch, |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 878 | Label *not_int32); |
| 879 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 880 | // Truncates a double using a specific rounding mode. |
| 881 | // Clears the z flag (ne condition) if an overflow occurs. |
| 882 | // If exact_conversion is true, the z flag is also cleared if the conversion |
| 883 | // was inexact, ie. if the double value could not be converted exactly |
| 884 | // to a 32bit integer. |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 885 | void EmitVFPTruncate(VFPRoundingMode rounding_mode, |
| 886 | SwVfpRegister result, |
| 887 | DwVfpRegister double_input, |
| 888 | Register scratch1, |
| 889 | Register scratch2, |
| 890 | CheckForInexactConversion check |
| 891 | = kDontCheckForInexactConversion); |
| 892 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 893 | // Helper for EmitECMATruncate. |
| 894 | // This will truncate a floating-point value outside of the singed 32bit |
| 895 | // integer range to a 32bit signed integer. |
| 896 | // Expects the double value loaded in input_high and input_low. |
| 897 | // Exits with the answer in 'result'. |
| 898 | // Note that this code does not work for values in the 32bit range! |
| 899 | void EmitOutOfInt32RangeTruncate(Register result, |
| 900 | Register input_high, |
| 901 | Register input_low, |
| 902 | Register scratch); |
| 903 | |
| 904 | // Performs a truncating conversion of a floating point number as used by |
| 905 | // the JS bitwise operations. See ECMA-262 9.5: ToInt32. |
| 906 | // Exits with 'result' holding the answer and all other registers clobbered. |
| 907 | void EmitECMATruncate(Register result, |
| 908 | DwVfpRegister double_input, |
| 909 | SwVfpRegister single_scratch, |
| 910 | Register scratch, |
| 911 | Register scratch2, |
| 912 | Register scratch3); |
| 913 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 914 | // Count leading zeros in a 32 bit word. On ARM5 and later it uses the clz |
| 915 | // instruction. On pre-ARM5 hardware this routine gives the wrong answer |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 916 | // for 0 (31 instead of 32). Source and scratch can be the same in which case |
| 917 | // the source is clobbered. Source and zeros can also be the same in which |
| 918 | // case scratch should be a different register. |
| 919 | void CountLeadingZeros(Register zeros, |
| 920 | Register source, |
| 921 | Register scratch); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 922 | |
| 923 | // --------------------------------------------------------------------------- |
| 924 | // Runtime calls |
| 925 | |
| 926 | // Call a code stub. |
| 927 | void CallStub(CodeStub* stub, Condition cond = al); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 928 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 929 | // Call a code stub. |
| 930 | void TailCallStub(CodeStub* stub, Condition cond = al); |
| 931 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 932 | // Call a runtime routine. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 933 | void CallRuntime(const Runtime::Function* f, int num_arguments); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 934 | void CallRuntimeSaveDoubles(Runtime::FunctionId id); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 935 | |
| 936 | // Convenience function: Same as above, but takes the fid instead. |
| 937 | void CallRuntime(Runtime::FunctionId fid, int num_arguments); |
| 938 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 939 | // Convenience function: call an external reference. |
| 940 | void CallExternalReference(const ExternalReference& ext, |
| 941 | int num_arguments); |
| 942 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 943 | // Tail call of a runtime routine (jump). |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 944 | // Like JumpToExternalReference, but also takes care of passing the number |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 945 | // of parameters. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 946 | void TailCallExternalReference(const ExternalReference& ext, |
| 947 | int num_arguments, |
| 948 | int result_size); |
| 949 | |
| 950 | // Convenience function: tail call a runtime routine (jump). |
| 951 | void TailCallRuntime(Runtime::FunctionId fid, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 952 | int num_arguments, |
| 953 | int result_size); |
| 954 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 955 | int CalculateStackPassedWords(int num_reg_arguments, |
| 956 | int num_double_arguments); |
| 957 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 958 | // Before calling a C-function from generated code, align arguments on stack. |
| 959 | // After aligning the frame, non-register arguments must be stored in |
| 960 | // sp[0], sp[4], etc., not pushed. The argument count assumes all arguments |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 961 | // are word sized. If double arguments are used, this function assumes that |
| 962 | // all double arguments are stored before core registers; otherwise the |
| 963 | // correct alignment of the double values is not guaranteed. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 964 | // Some compilers/platforms require the stack to be aligned when calling |
| 965 | // C++ code. |
| 966 | // Needs a scratch register to do some arithmetic. This register will be |
| 967 | // trashed. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 968 | void PrepareCallCFunction(int num_reg_arguments, |
| 969 | int num_double_registers, |
| 970 | Register scratch); |
| 971 | void PrepareCallCFunction(int num_reg_arguments, |
| 972 | Register scratch); |
| 973 | |
| 974 | // There are two ways of passing double arguments on ARM, depending on |
| 975 | // whether soft or hard floating point ABI is used. These functions |
| 976 | // abstract parameter passing for the three different ways we call |
| 977 | // C functions from generated code. |
| 978 | void SetCallCDoubleArguments(DoubleRegister dreg); |
| 979 | void SetCallCDoubleArguments(DoubleRegister dreg1, DoubleRegister dreg2); |
| 980 | void SetCallCDoubleArguments(DoubleRegister dreg, Register reg); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 981 | |
| 982 | // Calls a C function and cleans up the space for arguments allocated |
| 983 | // by PrepareCallCFunction. The called function is not allowed to trigger a |
| 984 | // garbage collection, since that might move the code and invalidate the |
| 985 | // return address (unless this is somehow accounted for by the called |
| 986 | // function). |
| 987 | void CallCFunction(ExternalReference function, int num_arguments); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame^] | 988 | void CallCFunction(Register function, int num_arguments); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 989 | void CallCFunction(ExternalReference function, |
| 990 | int num_reg_arguments, |
| 991 | int num_double_arguments); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame^] | 992 | void CallCFunction(Register function, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 993 | int num_reg_arguments, |
| 994 | int num_double_arguments); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 995 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 996 | void GetCFunctionDoubleResult(const DoubleRegister dst); |
| 997 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame^] | 998 | // Calls an API function. Allocates HandleScope, extracts returned value |
| 999 | // from handle and propagates exceptions. Restores context. stack_space |
| 1000 | // - space to be unwound on exit (includes the call js arguments space and |
| 1001 | // the additional space allocated for the fast call). |
| 1002 | void CallApiFunctionAndReturn(ExternalReference function, int stack_space); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1003 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1004 | // Jump to a runtime routine. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1005 | void JumpToExternalReference(const ExternalReference& builtin); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1006 | |
| 1007 | // Invoke specified builtin JavaScript function. Adds an entry to |
| 1008 | // the unresolved list if the name does not resolve. |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 1009 | void InvokeBuiltin(Builtins::JavaScript id, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1010 | InvokeFlag flag, |
| 1011 | const CallWrapper& call_wrapper = NullCallWrapper()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1012 | |
| 1013 | // Store the code object for the given builtin in the target register and |
| 1014 | // setup the function in r1. |
| 1015 | void GetBuiltinEntry(Register target, Builtins::JavaScript id); |
| 1016 | |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 1017 | // Store the function for the given builtin in the target register. |
| 1018 | void GetBuiltinFunction(Register target, Builtins::JavaScript id); |
| 1019 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1020 | Handle<Object> CodeObject() { |
| 1021 | ASSERT(!code_object_.is_null()); |
| 1022 | return code_object_; |
| 1023 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1024 | |
| 1025 | |
| 1026 | // --------------------------------------------------------------------------- |
| 1027 | // StatsCounter support |
| 1028 | |
| 1029 | void SetCounter(StatsCounter* counter, int value, |
| 1030 | Register scratch1, Register scratch2); |
| 1031 | void IncrementCounter(StatsCounter* counter, int value, |
| 1032 | Register scratch1, Register scratch2); |
| 1033 | void DecrementCounter(StatsCounter* counter, int value, |
| 1034 | Register scratch1, Register scratch2); |
| 1035 | |
| 1036 | |
| 1037 | // --------------------------------------------------------------------------- |
| 1038 | // Debugging |
| 1039 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1040 | // Calls Abort(msg) if the condition cond is not satisfied. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1041 | // Use --debug_code to enable. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1042 | void Assert(Condition cond, const char* msg); |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 1043 | void AssertRegisterIsRoot(Register reg, Heap::RootListIndex index); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 1044 | void AssertFastElements(Register elements); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1045 | |
| 1046 | // Like Assert(), but always enabled. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1047 | void Check(Condition cond, const char* msg); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1048 | |
| 1049 | // Print a message to stdout and abort execution. |
| 1050 | void Abort(const char* msg); |
| 1051 | |
| 1052 | // Verify restrictions about code generated in stubs. |
| 1053 | void set_generating_stub(bool value) { generating_stub_ = value; } |
| 1054 | bool generating_stub() { return generating_stub_; } |
| 1055 | void set_allow_stub_calls(bool value) { allow_stub_calls_ = value; } |
| 1056 | bool allow_stub_calls() { return allow_stub_calls_; } |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame^] | 1057 | void set_has_frame(bool value) { has_frame_ = value; } |
| 1058 | bool has_frame() { return has_frame_; } |
| 1059 | inline bool AllowThisStubCall(CodeStub* stub); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1060 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1061 | // EABI variant for double arguments in use. |
| 1062 | bool use_eabi_hardfloat() { |
| 1063 | #if USE_EABI_HARDFLOAT |
| 1064 | return true; |
| 1065 | #else |
| 1066 | return false; |
| 1067 | #endif |
| 1068 | } |
| 1069 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1070 | // --------------------------------------------------------------------------- |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1071 | // Number utilities |
| 1072 | |
| 1073 | // Check whether the value of reg is a power of two and not zero. If not |
| 1074 | // control continues at the label not_power_of_two. If reg is a power of two |
| 1075 | // the register scratch contains the value of (reg - 1) when control falls |
| 1076 | // through. |
| 1077 | void JumpIfNotPowerOfTwoOrZero(Register reg, |
| 1078 | Register scratch, |
| 1079 | Label* not_power_of_two_or_zero); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1080 | // Check whether the value of reg is a power of two and not zero. |
| 1081 | // Control falls through if it is, with scratch containing the mask |
| 1082 | // value (reg - 1). |
| 1083 | // Otherwise control jumps to the 'zero_and_neg' label if the value of reg is |
| 1084 | // zero or negative, or jumps to the 'not_power_of_two' label if the value is |
| 1085 | // strictly positive but not a power of two. |
| 1086 | void JumpIfNotPowerOfTwoOrZeroAndNeg(Register reg, |
| 1087 | Register scratch, |
| 1088 | Label* zero_and_neg, |
| 1089 | Label* not_power_of_two); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1090 | |
| 1091 | // --------------------------------------------------------------------------- |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1092 | // Smi utilities |
| 1093 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1094 | void SmiTag(Register reg, SBit s = LeaveCC) { |
| 1095 | add(reg, reg, Operand(reg), s); |
| 1096 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1097 | void SmiTag(Register dst, Register src, SBit s = LeaveCC) { |
| 1098 | add(dst, src, Operand(src), s); |
| 1099 | } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1100 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 1101 | // Try to convert int32 to smi. If the value is to large, preserve |
| 1102 | // the original value and jump to not_a_smi. Destroys scratch and |
| 1103 | // sets flags. |
| 1104 | void TrySmiTag(Register reg, Label* not_a_smi, Register scratch) { |
| 1105 | mov(scratch, reg); |
| 1106 | SmiTag(scratch, SetCC); |
| 1107 | b(vs, not_a_smi); |
| 1108 | mov(reg, scratch); |
| 1109 | } |
| 1110 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1111 | void SmiUntag(Register reg, SBit s = LeaveCC) { |
| 1112 | mov(reg, Operand(reg, ASR, kSmiTagSize), s); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1113 | } |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1114 | void SmiUntag(Register dst, Register src, SBit s = LeaveCC) { |
| 1115 | mov(dst, Operand(src, ASR, kSmiTagSize), s); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1116 | } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1117 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1118 | // Jump the register contains a smi. |
| 1119 | inline void JumpIfSmi(Register value, Label* smi_label) { |
| 1120 | tst(value, Operand(kSmiTagMask)); |
| 1121 | b(eq, smi_label); |
| 1122 | } |
| 1123 | // Jump if either of the registers contain a non-smi. |
| 1124 | inline void JumpIfNotSmi(Register value, Label* not_smi_label) { |
| 1125 | tst(value, Operand(kSmiTagMask)); |
| 1126 | b(ne, not_smi_label); |
| 1127 | } |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1128 | // Jump if either of the registers contain a non-smi. |
| 1129 | void JumpIfNotBothSmi(Register reg1, Register reg2, Label* on_not_both_smi); |
| 1130 | // Jump if either of the registers contain a smi. |
| 1131 | void JumpIfEitherSmi(Register reg1, Register reg2, Label* on_either_smi); |
| 1132 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 1133 | // Abort execution if argument is a smi. Used in debug code. |
| 1134 | void AbortIfSmi(Register object); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1135 | void AbortIfNotSmi(Register object); |
| 1136 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1137 | // Abort execution if argument is a string. Used in debug code. |
| 1138 | void AbortIfNotString(Register object); |
| 1139 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1140 | // Abort execution if argument is not the root value with the given index. |
| 1141 | void AbortIfNotRootValue(Register src, |
| 1142 | Heap::RootListIndex root_value_index, |
| 1143 | const char* message); |
| 1144 | |
| 1145 | // --------------------------------------------------------------------------- |
| 1146 | // HeapNumber utilities |
| 1147 | |
| 1148 | void JumpIfNotHeapNumber(Register object, |
| 1149 | Register heap_number_map, |
| 1150 | Register scratch, |
| 1151 | Label* on_not_heap_number); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 1152 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1153 | // --------------------------------------------------------------------------- |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1154 | // String utilities |
| 1155 | |
| 1156 | // Checks if both objects are sequential ASCII strings and jumps to label |
| 1157 | // if either is not. Assumes that neither object is a smi. |
| 1158 | void JumpIfNonSmisNotBothSequentialAsciiStrings(Register object1, |
| 1159 | Register object2, |
| 1160 | Register scratch1, |
| 1161 | Register scratch2, |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1162 | Label* failure); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1163 | |
| 1164 | // Checks if both objects are sequential ASCII strings and jumps to label |
| 1165 | // if either is not. |
| 1166 | void JumpIfNotBothSequentialAsciiStrings(Register first, |
| 1167 | Register second, |
| 1168 | Register scratch1, |
| 1169 | Register scratch2, |
| 1170 | Label* not_flat_ascii_strings); |
| 1171 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1172 | // Checks if both instance types are sequential ASCII strings and jumps to |
| 1173 | // label if either is not. |
| 1174 | void JumpIfBothInstanceTypesAreNotSequentialAscii( |
| 1175 | Register first_object_instance_type, |
| 1176 | Register second_object_instance_type, |
| 1177 | Register scratch1, |
| 1178 | Register scratch2, |
| 1179 | Label* failure); |
| 1180 | |
| 1181 | // Check if instance type is sequential ASCII string and jump to label if |
| 1182 | // it is not. |
| 1183 | void JumpIfInstanceTypeIsNotSequentialAscii(Register type, |
| 1184 | Register scratch, |
| 1185 | Label* failure); |
| 1186 | |
| 1187 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1188 | // --------------------------------------------------------------------------- |
| 1189 | // Patching helpers. |
| 1190 | |
| 1191 | // Get the location of a relocated constant (its address in the constant pool) |
| 1192 | // from its load site. |
| 1193 | void GetRelocatedValueLocation(Register ldr_location, |
| 1194 | Register result); |
| 1195 | |
| 1196 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1197 | void ClampUint8(Register output_reg, Register input_reg); |
| 1198 | |
| 1199 | void ClampDoubleToUint8(Register result_reg, |
| 1200 | DoubleRegister input_reg, |
| 1201 | DoubleRegister temp_double_reg); |
| 1202 | |
| 1203 | |
| 1204 | void LoadInstanceDescriptors(Register map, Register descriptors); |
| 1205 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame^] | 1206 | // Activation support. |
| 1207 | void EnterFrame(StackFrame::Type type); |
| 1208 | void LeaveFrame(StackFrame::Type type); |
| 1209 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1210 | private: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1211 | void CallCFunctionHelper(Register function, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1212 | int num_reg_arguments, |
| 1213 | int num_double_arguments); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1214 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1215 | void Jump(intptr_t target, RelocInfo::Mode rmode, Condition cond = al); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1216 | |
| 1217 | // Helper functions for generating invokes. |
| 1218 | void InvokePrologue(const ParameterCount& expected, |
| 1219 | const ParameterCount& actual, |
| 1220 | Handle<Code> code_constant, |
| 1221 | Register code_reg, |
| 1222 | Label* done, |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 1223 | InvokeFlag flag, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1224 | const CallWrapper& call_wrapper, |
| 1225 | CallKind call_kind); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1226 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1227 | void InitializeNewString(Register string, |
| 1228 | Register length, |
| 1229 | Heap::RootListIndex map_index, |
| 1230 | Register scratch1, |
| 1231 | Register scratch2); |
| 1232 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame^] | 1233 | // Helper for implementing JumpIfNotInNewSpace and JumpIfInNewSpace. |
| 1234 | void InNewSpace(Register object, |
| 1235 | Register scratch, |
| 1236 | Condition cond, // eq for new space, ne otherwise. |
| 1237 | Label* branch); |
| 1238 | |
| 1239 | // Helper for finding the mark bits for an address. Afterwards, the |
| 1240 | // bitmap register points at the word with the mark bits and the mask |
| 1241 | // the position of the first bit. Leaves addr_reg unchanged. |
| 1242 | inline void GetMarkBits(Register addr_reg, |
| 1243 | Register bitmap_reg, |
| 1244 | Register mask_reg); |
| 1245 | |
| 1246 | // Helper for throwing exceptions. Compute a handler address and jump to |
| 1247 | // it. See the implementation for register usage. |
| 1248 | void JumpToHandlerEntry(); |
| 1249 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1250 | // Compute memory operands for safepoint stack slots. |
| 1251 | static int SafepointRegisterStackIndex(int reg_code); |
| 1252 | MemOperand SafepointRegisterSlot(Register reg); |
| 1253 | MemOperand SafepointRegistersAndDoublesSlot(Register reg); |
| 1254 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1255 | bool generating_stub_; |
| 1256 | bool allow_stub_calls_; |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame^] | 1257 | bool has_frame_; |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1258 | // This handle will be patched with the code object on installation. |
| 1259 | Handle<Object> code_object_; |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1260 | |
| 1261 | // Needs access to SafepointRegisterStackIndex for optimized frame |
| 1262 | // traversal. |
| 1263 | friend class OptimizedFrame; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1264 | }; |
| 1265 | |
| 1266 | |
| 1267 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 1268 | // The code patcher is used to patch (typically) small parts of code e.g. for |
| 1269 | // debugging and other types of instrumentation. When using the code patcher |
| 1270 | // the exact number of bytes specified must be emitted. It is not legal to emit |
| 1271 | // relocation information. If any of these constraints are violated it causes |
| 1272 | // an assertion to fail. |
| 1273 | class CodePatcher { |
| 1274 | public: |
| 1275 | CodePatcher(byte* address, int instructions); |
| 1276 | virtual ~CodePatcher(); |
| 1277 | |
| 1278 | // Macro assembler to emit code. |
| 1279 | MacroAssembler* masm() { return &masm_; } |
| 1280 | |
| 1281 | // Emit an instruction directly. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1282 | void Emit(Instr instr); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1283 | |
| 1284 | // Emit an address directly. |
| 1285 | void Emit(Address addr); |
| 1286 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1287 | // Emit the condition part of an instruction leaving the rest of the current |
| 1288 | // instruction unchanged. |
| 1289 | void EmitCondition(Condition cond); |
| 1290 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1291 | private: |
| 1292 | byte* address_; // The address of the code being patched. |
| 1293 | int instructions_; // Number of instructions of the expected patch size. |
| 1294 | int size_; // Number of bytes of the expected patch size. |
| 1295 | MacroAssembler masm_; // Macro assembler used to generate the code. |
| 1296 | }; |
| 1297 | #endif // ENABLE_DEBUGGER_SUPPORT |
| 1298 | |
| 1299 | |
| 1300 | // ----------------------------------------------------------------------------- |
| 1301 | // Static helper functions. |
| 1302 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame^] | 1303 | inline MemOperand ContextOperand(Register context, int index) { |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 1304 | return MemOperand(context, Context::SlotOffset(index)); |
| 1305 | } |
| 1306 | |
| 1307 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame^] | 1308 | inline MemOperand GlobalObjectOperand() { |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 1309 | return ContextOperand(cp, Context::GLOBAL_INDEX); |
| 1310 | } |
| 1311 | |
| 1312 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1313 | #ifdef GENERATED_CODE_COVERAGE |
| 1314 | #define CODE_COVERAGE_STRINGIFY(x) #x |
| 1315 | #define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x) |
| 1316 | #define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__) |
| 1317 | #define ACCESS_MASM(masm) masm->stop(__FILE_LINE__); masm-> |
| 1318 | #else |
| 1319 | #define ACCESS_MASM(masm) masm-> |
| 1320 | #endif |
| 1321 | |
| 1322 | |
| 1323 | } } // namespace v8::internal |
| 1324 | |
| 1325 | #endif // V8_ARM_MACRO_ASSEMBLER_ARM_H_ |