vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 1 | // Copyright 2011 the V8 project authors. All rights reserved. |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +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 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 28 | #include "v8.h" |
| 29 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 30 | #if defined(V8_TARGET_ARCH_X64) |
| 31 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 32 | #include "bootstrapper.h" |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 33 | #include "codegen.h" |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 34 | #include "assembler-x64.h" |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 35 | #include "macro-assembler-x64.h" |
sgjesse@chromium.org | b9d7da1 | 2009-08-05 08:38:10 +0000 | [diff] [blame] | 36 | #include "serialize.h" |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 37 | #include "debug.h" |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 38 | #include "heap.h" |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 39 | |
| 40 | namespace v8 { |
| 41 | namespace internal { |
| 42 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 43 | MacroAssembler::MacroAssembler(Isolate* arg_isolate, void* buffer, int size) |
| 44 | : Assembler(arg_isolate, buffer, size), |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 45 | generating_stub_(false), |
| 46 | allow_stub_calls_(true), |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 47 | has_frame_(false), |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 48 | root_array_available_(true) { |
| 49 | if (isolate() != NULL) { |
| 50 | code_object_ = Handle<Object>(isolate()->heap()->undefined_value(), |
| 51 | isolate()); |
| 52 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 56 | static intptr_t RootRegisterDelta(ExternalReference other, Isolate* isolate) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 57 | Address roots_register_value = kRootRegisterBias + |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 58 | reinterpret_cast<Address>(isolate->heap()->roots_address()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 59 | intptr_t delta = other.address() - roots_register_value; |
| 60 | return delta; |
| 61 | } |
| 62 | |
| 63 | |
| 64 | Operand MacroAssembler::ExternalOperand(ExternalReference target, |
| 65 | Register scratch) { |
| 66 | if (root_array_available_ && !Serializer::enabled()) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 67 | intptr_t delta = RootRegisterDelta(target, isolate()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 68 | if (is_int32(delta)) { |
| 69 | Serializer::TooLateToEnableNow(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 70 | return Operand(kRootRegister, static_cast<int32_t>(delta)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 71 | } |
| 72 | } |
| 73 | movq(scratch, target); |
| 74 | return Operand(scratch, 0); |
| 75 | } |
| 76 | |
| 77 | |
| 78 | void MacroAssembler::Load(Register destination, ExternalReference source) { |
| 79 | if (root_array_available_ && !Serializer::enabled()) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 80 | intptr_t delta = RootRegisterDelta(source, isolate()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 81 | if (is_int32(delta)) { |
| 82 | Serializer::TooLateToEnableNow(); |
| 83 | movq(destination, Operand(kRootRegister, static_cast<int32_t>(delta))); |
| 84 | return; |
| 85 | } |
| 86 | } |
| 87 | // Safe code. |
| 88 | if (destination.is(rax)) { |
| 89 | load_rax(source); |
| 90 | } else { |
| 91 | movq(kScratchRegister, source); |
| 92 | movq(destination, Operand(kScratchRegister, 0)); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | |
| 97 | void MacroAssembler::Store(ExternalReference destination, Register source) { |
| 98 | if (root_array_available_ && !Serializer::enabled()) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 99 | intptr_t delta = RootRegisterDelta(destination, isolate()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 100 | if (is_int32(delta)) { |
| 101 | Serializer::TooLateToEnableNow(); |
| 102 | movq(Operand(kRootRegister, static_cast<int32_t>(delta)), source); |
| 103 | return; |
| 104 | } |
| 105 | } |
| 106 | // Safe code. |
| 107 | if (source.is(rax)) { |
| 108 | store_rax(destination); |
| 109 | } else { |
| 110 | movq(kScratchRegister, destination); |
| 111 | movq(Operand(kScratchRegister, 0), source); |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | |
| 116 | void MacroAssembler::LoadAddress(Register destination, |
| 117 | ExternalReference source) { |
| 118 | if (root_array_available_ && !Serializer::enabled()) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 119 | intptr_t delta = RootRegisterDelta(source, isolate()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 120 | if (is_int32(delta)) { |
| 121 | Serializer::TooLateToEnableNow(); |
| 122 | lea(destination, Operand(kRootRegister, static_cast<int32_t>(delta))); |
| 123 | return; |
| 124 | } |
| 125 | } |
| 126 | // Safe code. |
| 127 | movq(destination, source); |
| 128 | } |
| 129 | |
| 130 | |
| 131 | int MacroAssembler::LoadAddressSize(ExternalReference source) { |
| 132 | if (root_array_available_ && !Serializer::enabled()) { |
| 133 | // This calculation depends on the internals of LoadAddress. |
| 134 | // It's correctness is ensured by the asserts in the Call |
| 135 | // instruction below. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 136 | intptr_t delta = RootRegisterDelta(source, isolate()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 137 | if (is_int32(delta)) { |
| 138 | Serializer::TooLateToEnableNow(); |
| 139 | // Operand is lea(scratch, Operand(kRootRegister, delta)); |
| 140 | // Opcodes : REX.W 8D ModRM Disp8/Disp32 - 4 or 7. |
| 141 | int size = 4; |
| 142 | if (!is_int8(static_cast<int32_t>(delta))) { |
| 143 | size += 3; // Need full four-byte displacement in lea. |
| 144 | } |
| 145 | return size; |
| 146 | } |
| 147 | } |
| 148 | // Size of movq(destination, src); |
| 149 | return 10; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 150 | } |
| 151 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 152 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 153 | void MacroAssembler::LoadRoot(Register destination, Heap::RootListIndex index) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 154 | ASSERT(root_array_available_); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 155 | movq(destination, Operand(kRootRegister, |
| 156 | (index << kPointerSizeLog2) - kRootRegisterBias)); |
| 157 | } |
| 158 | |
| 159 | |
| 160 | void MacroAssembler::LoadRootIndexed(Register destination, |
| 161 | Register variable_offset, |
| 162 | int fixed_offset) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 163 | ASSERT(root_array_available_); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 164 | movq(destination, |
| 165 | Operand(kRootRegister, |
| 166 | variable_offset, times_pointer_size, |
| 167 | (fixed_offset << kPointerSizeLog2) - kRootRegisterBias)); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 171 | void MacroAssembler::StoreRoot(Register source, Heap::RootListIndex index) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 172 | ASSERT(root_array_available_); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 173 | movq(Operand(kRootRegister, (index << kPointerSizeLog2) - kRootRegisterBias), |
| 174 | source); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 178 | void MacroAssembler::PushRoot(Heap::RootListIndex index) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 179 | ASSERT(root_array_available_); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 180 | push(Operand(kRootRegister, (index << kPointerSizeLog2) - kRootRegisterBias)); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 184 | void MacroAssembler::CompareRoot(Register with, Heap::RootListIndex index) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 185 | ASSERT(root_array_available_); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 186 | cmpq(with, Operand(kRootRegister, |
| 187 | (index << kPointerSizeLog2) - kRootRegisterBias)); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 188 | } |
| 189 | |
sgjesse@chromium.org | b9d7da1 | 2009-08-05 08:38:10 +0000 | [diff] [blame] | 190 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 191 | void MacroAssembler::CompareRoot(const Operand& with, |
| 192 | Heap::RootListIndex index) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 193 | ASSERT(root_array_available_); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 194 | ASSERT(!with.AddressUsesRegister(kScratchRegister)); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 195 | LoadRoot(kScratchRegister, index); |
| 196 | cmpq(with, kScratchRegister); |
| 197 | } |
| 198 | |
| 199 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 200 | void MacroAssembler::RememberedSetHelper(Register object, // For debug tests. |
| 201 | Register addr, |
| 202 | Register scratch, |
| 203 | SaveFPRegsMode save_fp, |
| 204 | RememberedSetFinalAction and_then) { |
| 205 | if (FLAG_debug_code) { |
| 206 | Label ok; |
| 207 | JumpIfNotInNewSpace(object, scratch, &ok, Label::kNear); |
| 208 | int3(); |
| 209 | bind(&ok); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 210 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 211 | // Load store buffer top. |
| 212 | LoadRoot(scratch, Heap::kStoreBufferTopRootIndex); |
| 213 | // Store pointer to buffer. |
| 214 | movq(Operand(scratch, 0), addr); |
| 215 | // Increment buffer top. |
| 216 | addq(scratch, Immediate(kPointerSize)); |
| 217 | // Write back new top of buffer. |
| 218 | StoreRoot(scratch, Heap::kStoreBufferTopRootIndex); |
| 219 | // Call stub on end of buffer. |
| 220 | Label done; |
| 221 | // Check for end of buffer. |
| 222 | testq(scratch, Immediate(StoreBuffer::kStoreBufferOverflowBit)); |
| 223 | if (and_then == kReturnAtEnd) { |
| 224 | Label buffer_overflowed; |
| 225 | j(not_equal, &buffer_overflowed, Label::kNear); |
| 226 | ret(0); |
| 227 | bind(&buffer_overflowed); |
| 228 | } else { |
| 229 | ASSERT(and_then == kFallThroughAtEnd); |
| 230 | j(equal, &done, Label::kNear); |
| 231 | } |
| 232 | StoreBufferOverflowStub store_buffer_overflow = |
| 233 | StoreBufferOverflowStub(save_fp); |
| 234 | CallStub(&store_buffer_overflow); |
| 235 | if (and_then == kReturnAtEnd) { |
| 236 | ret(0); |
| 237 | } else { |
| 238 | ASSERT(and_then == kFallThroughAtEnd); |
| 239 | bind(&done); |
| 240 | } |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 244 | void MacroAssembler::InNewSpace(Register object, |
| 245 | Register scratch, |
| 246 | Condition cc, |
| 247 | Label* branch, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 248 | Label::Distance distance) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 249 | if (Serializer::enabled()) { |
| 250 | // Can't do arithmetic on external references if it might get serialized. |
| 251 | // The mask isn't really an address. We load it as an external reference in |
| 252 | // case the size of the new space is different between the snapshot maker |
| 253 | // and the running system. |
| 254 | if (scratch.is(object)) { |
| 255 | movq(kScratchRegister, ExternalReference::new_space_mask(isolate())); |
| 256 | and_(scratch, kScratchRegister); |
| 257 | } else { |
| 258 | movq(scratch, ExternalReference::new_space_mask(isolate())); |
| 259 | and_(scratch, object); |
| 260 | } |
| 261 | movq(kScratchRegister, ExternalReference::new_space_start(isolate())); |
| 262 | cmpq(scratch, kScratchRegister); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 263 | j(cc, branch, distance); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 264 | } else { |
| 265 | ASSERT(is_int32(static_cast<int64_t>(HEAP->NewSpaceMask()))); |
| 266 | intptr_t new_space_start = |
| 267 | reinterpret_cast<intptr_t>(HEAP->NewSpaceStart()); |
| 268 | movq(kScratchRegister, -new_space_start, RelocInfo::NONE); |
| 269 | if (scratch.is(object)) { |
| 270 | addq(scratch, kScratchRegister); |
| 271 | } else { |
| 272 | lea(scratch, Operand(object, kScratchRegister, times_1, 0)); |
| 273 | } |
| 274 | and_(scratch, Immediate(static_cast<int32_t>(HEAP->NewSpaceMask()))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 275 | j(cc, branch, distance); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 276 | } |
| 277 | } |
| 278 | |
| 279 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 280 | void MacroAssembler::RecordWriteField( |
| 281 | Register object, |
| 282 | int offset, |
| 283 | Register value, |
| 284 | Register dst, |
| 285 | SaveFPRegsMode save_fp, |
| 286 | RememberedSetAction remembered_set_action, |
| 287 | SmiCheck smi_check) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 288 | // The compiled code assumes that record write doesn't change the |
| 289 | // context register, so we check that none of the clobbered |
| 290 | // registers are rsi. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 291 | ASSERT(!value.is(rsi) && !dst.is(rsi)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 292 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 293 | // First, check if a write barrier is even needed. The tests below |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 294 | // catch stores of Smis. |
sgjesse@chromium.org | b9d7da1 | 2009-08-05 08:38:10 +0000 | [diff] [blame] | 295 | Label done; |
| 296 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 297 | // Skip barrier if writing a smi. |
| 298 | if (smi_check == INLINE_SMI_CHECK) { |
| 299 | JumpIfSmi(value, &done); |
| 300 | } |
| 301 | |
| 302 | // Although the object register is tagged, the offset is relative to the start |
| 303 | // of the object, so so offset must be a multiple of kPointerSize. |
| 304 | ASSERT(IsAligned(offset, kPointerSize)); |
| 305 | |
| 306 | lea(dst, FieldOperand(object, offset)); |
| 307 | if (emit_debug_code()) { |
| 308 | Label ok; |
| 309 | testb(dst, Immediate((1 << kPointerSizeLog2) - 1)); |
| 310 | j(zero, &ok, Label::kNear); |
| 311 | int3(); |
| 312 | bind(&ok); |
| 313 | } |
| 314 | |
| 315 | RecordWrite( |
| 316 | object, dst, value, save_fp, remembered_set_action, OMIT_SMI_CHECK); |
| 317 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 318 | bind(&done); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 319 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 320 | // Clobber clobbered input registers when running with the debug-code flag |
| 321 | // turned on to provoke errors. |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 322 | if (emit_debug_code()) { |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 323 | movq(value, BitCast<int64_t>(kZapValue), RelocInfo::NONE); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 324 | movq(dst, BitCast<int64_t>(kZapValue), RelocInfo::NONE); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 325 | } |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 329 | void MacroAssembler::RecordWrite(Register object, |
| 330 | Register address, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 331 | Register value, |
| 332 | SaveFPRegsMode fp_mode, |
| 333 | RememberedSetAction remembered_set_action, |
| 334 | SmiCheck smi_check) { |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 335 | // The compiled code assumes that record write doesn't change the |
| 336 | // context register, so we check that none of the clobbered |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 337 | // registers are rsi. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 338 | ASSERT(!value.is(rsi) && !address.is(rsi)); |
| 339 | |
| 340 | ASSERT(!object.is(value)); |
| 341 | ASSERT(!object.is(address)); |
| 342 | ASSERT(!value.is(address)); |
| 343 | if (emit_debug_code()) { |
| 344 | AbortIfSmi(object); |
| 345 | } |
| 346 | |
| 347 | if (remembered_set_action == OMIT_REMEMBERED_SET && |
| 348 | !FLAG_incremental_marking) { |
| 349 | return; |
| 350 | } |
| 351 | |
| 352 | if (FLAG_debug_code) { |
| 353 | Label ok; |
| 354 | cmpq(value, Operand(address, 0)); |
| 355 | j(equal, &ok, Label::kNear); |
| 356 | int3(); |
| 357 | bind(&ok); |
| 358 | } |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 359 | |
| 360 | // First, check if a write barrier is even needed. The tests below |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 361 | // catch stores of smis and stores into the young generation. |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 362 | Label done; |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 363 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 364 | if (smi_check == INLINE_SMI_CHECK) { |
| 365 | // Skip barrier if writing a smi. |
| 366 | JumpIfSmi(value, &done); |
| 367 | } |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 368 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 369 | CheckPageFlag(value, |
| 370 | value, // Used as scratch. |
| 371 | MemoryChunk::kPointersToHereAreInterestingMask, |
| 372 | zero, |
| 373 | &done, |
| 374 | Label::kNear); |
| 375 | |
| 376 | CheckPageFlag(object, |
| 377 | value, // Used as scratch. |
| 378 | MemoryChunk::kPointersFromHereAreInterestingMask, |
| 379 | zero, |
| 380 | &done, |
| 381 | Label::kNear); |
| 382 | |
| 383 | RecordWriteStub stub(object, value, address, remembered_set_action, fp_mode); |
| 384 | CallStub(&stub); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 385 | |
| 386 | bind(&done); |
| 387 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 388 | // Clobber clobbered registers when running with the debug-code flag |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 389 | // turned on to provoke errors. |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 390 | if (emit_debug_code()) { |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 391 | movq(address, BitCast<int64_t>(kZapValue), RelocInfo::NONE); |
| 392 | movq(value, BitCast<int64_t>(kZapValue), RelocInfo::NONE); |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 397 | void MacroAssembler::Assert(Condition cc, const char* msg) { |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 398 | if (emit_debug_code()) Check(cc, msg); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 402 | void MacroAssembler::AssertFastElements(Register elements) { |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 403 | if (emit_debug_code()) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 404 | Label ok; |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 405 | CompareRoot(FieldOperand(elements, HeapObject::kMapOffset), |
| 406 | Heap::kFixedArrayMapRootIndex); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 407 | j(equal, &ok, Label::kNear); |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 408 | CompareRoot(FieldOperand(elements, HeapObject::kMapOffset), |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 409 | Heap::kFixedDoubleArrayMapRootIndex); |
| 410 | j(equal, &ok, Label::kNear); |
| 411 | CompareRoot(FieldOperand(elements, HeapObject::kMapOffset), |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 412 | Heap::kFixedCOWArrayMapRootIndex); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 413 | j(equal, &ok, Label::kNear); |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 414 | Abort("JSObject with fast elements map has slow elements"); |
| 415 | bind(&ok); |
| 416 | } |
| 417 | } |
| 418 | |
| 419 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 420 | void MacroAssembler::Check(Condition cc, const char* msg) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 421 | Label L; |
| 422 | j(cc, &L, Label::kNear); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 423 | Abort(msg); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 424 | // Control will not return here. |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 425 | bind(&L); |
| 426 | } |
| 427 | |
| 428 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 429 | void MacroAssembler::CheckStackAlignment() { |
| 430 | int frame_alignment = OS::ActivationFrameAlignment(); |
| 431 | int frame_alignment_mask = frame_alignment - 1; |
| 432 | if (frame_alignment > kPointerSize) { |
| 433 | ASSERT(IsPowerOf2(frame_alignment)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 434 | Label alignment_as_expected; |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 435 | testq(rsp, Immediate(frame_alignment_mask)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 436 | j(zero, &alignment_as_expected, Label::kNear); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 437 | // Abort if stack is not aligned. |
| 438 | int3(); |
| 439 | bind(&alignment_as_expected); |
| 440 | } |
| 441 | } |
| 442 | |
| 443 | |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 444 | void MacroAssembler::NegativeZeroTest(Register result, |
| 445 | Register op, |
| 446 | Label* then_label) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 447 | Label ok; |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 448 | testl(result, result); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 449 | j(not_zero, &ok, Label::kNear); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 450 | testl(op, op); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 451 | j(sign, then_label); |
| 452 | bind(&ok); |
| 453 | } |
| 454 | |
| 455 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 456 | void MacroAssembler::Abort(const char* msg) { |
| 457 | // We want to pass the msg string like a smi to avoid GC |
| 458 | // problems, however msg is not guaranteed to be aligned |
| 459 | // properly. Instead, we pass an aligned pointer that is |
| 460 | // a proper v8 smi, but also pass the alignment difference |
| 461 | // from the real pointer as a smi. |
| 462 | intptr_t p1 = reinterpret_cast<intptr_t>(msg); |
| 463 | intptr_t p0 = (p1 & ~kSmiTagMask) + kSmiTag; |
| 464 | // Note: p0 might not be a valid Smi *value*, but it has a valid Smi tag. |
| 465 | ASSERT(reinterpret_cast<Object*>(p0)->IsSmi()); |
| 466 | #ifdef DEBUG |
| 467 | if (msg != NULL) { |
| 468 | RecordComment("Abort message: "); |
| 469 | RecordComment(msg); |
| 470 | } |
| 471 | #endif |
| 472 | push(rax); |
| 473 | movq(kScratchRegister, p0, RelocInfo::NONE); |
| 474 | push(kScratchRegister); |
| 475 | movq(kScratchRegister, |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 476 | reinterpret_cast<intptr_t>(Smi::FromInt(static_cast<int>(p1 - p0))), |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 477 | RelocInfo::NONE); |
| 478 | push(kScratchRegister); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 479 | |
| 480 | if (!has_frame_) { |
| 481 | // We don't actually want to generate a pile of code for this, so just |
| 482 | // claim there is a stack frame, without generating one. |
| 483 | FrameScope scope(this, StackFrame::NONE); |
| 484 | CallRuntime(Runtime::kAbort, 2); |
| 485 | } else { |
| 486 | CallRuntime(Runtime::kAbort, 2); |
| 487 | } |
| 488 | // Control will not return here. |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 489 | int3(); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 493 | void MacroAssembler::CallStub(CodeStub* stub, unsigned ast_id) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 494 | ASSERT(AllowThisStubCall(stub)); // Calls are not allowed in some stubs |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 495 | Call(stub->GetCode(), RelocInfo::CODE_TARGET, ast_id); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 499 | MaybeObject* MacroAssembler::TryCallStub(CodeStub* stub) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 500 | ASSERT(AllowThisStubCall(stub)); // Calls are not allowed in some stubs. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 501 | MaybeObject* result = stub->TryGetCode(); |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 502 | if (!result->IsFailure()) { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 503 | call(Handle<Code>(Code::cast(result->ToObjectUnchecked())), |
| 504 | RelocInfo::CODE_TARGET); |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 505 | } |
| 506 | return result; |
| 507 | } |
| 508 | |
| 509 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 510 | void MacroAssembler::TailCallStub(CodeStub* stub) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 511 | ASSERT(allow_stub_calls_ || stub->CompilingCallsToThisStubIsGCSafe()); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 512 | Jump(stub->GetCode(), RelocInfo::CODE_TARGET); |
| 513 | } |
| 514 | |
| 515 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 516 | MaybeObject* MacroAssembler::TryTailCallStub(CodeStub* stub) { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 517 | MaybeObject* result = stub->TryGetCode(); |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 518 | if (!result->IsFailure()) { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 519 | jmp(Handle<Code>(Code::cast(result->ToObjectUnchecked())), |
| 520 | RelocInfo::CODE_TARGET); |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 521 | } |
| 522 | return result; |
| 523 | } |
| 524 | |
| 525 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 526 | void MacroAssembler::StubReturn(int argc) { |
| 527 | ASSERT(argc >= 1 && generating_stub()); |
| 528 | ret((argc - 1) * kPointerSize); |
| 529 | } |
| 530 | |
| 531 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 532 | bool MacroAssembler::AllowThisStubCall(CodeStub* stub) { |
| 533 | if (!has_frame_ && stub->SometimesSetsUpAFrame()) return false; |
| 534 | return allow_stub_calls_ || stub->CompilingCallsToThisStubIsGCSafe(); |
| 535 | } |
| 536 | |
| 537 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 538 | void MacroAssembler::IllegalOperation(int num_arguments) { |
| 539 | if (num_arguments > 0) { |
| 540 | addq(rsp, Immediate(num_arguments * kPointerSize)); |
| 541 | } |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 542 | LoadRoot(rax, Heap::kUndefinedValueRootIndex); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 546 | void MacroAssembler::IndexFromHash(Register hash, Register index) { |
| 547 | // The assert checks that the constants for the maximum number of digits |
| 548 | // for an array index cached in the hash field and the number of bits |
| 549 | // reserved for it does not conflict. |
| 550 | ASSERT(TenToThe(String::kMaxCachedArrayIndexLength) < |
| 551 | (1 << String::kArrayIndexValueBits)); |
| 552 | // We want the smi-tagged index in key. Even if we subsequently go to |
| 553 | // the slow case, converting the key to a smi is always valid. |
| 554 | // key: string key |
| 555 | // hash: key's hash field, including its array index value. |
| 556 | and_(hash, Immediate(String::kArrayIndexValueMask)); |
| 557 | shr(hash, Immediate(String::kHashShift)); |
| 558 | // Here we actually clobber the key which will be used if calling into |
| 559 | // runtime later. However as the new key is the numeric value of a string key |
| 560 | // there is no difference in using either key. |
| 561 | Integer32ToSmi(index, hash); |
| 562 | } |
| 563 | |
| 564 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 565 | void MacroAssembler::CallRuntime(Runtime::FunctionId id, int num_arguments) { |
| 566 | CallRuntime(Runtime::FunctionForId(id), num_arguments); |
| 567 | } |
| 568 | |
| 569 | |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 570 | void MacroAssembler::CallRuntimeSaveDoubles(Runtime::FunctionId id) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 571 | const Runtime::Function* function = Runtime::FunctionForId(id); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 572 | Set(rax, function->nargs); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 573 | LoadAddress(rbx, ExternalReference(function, isolate())); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 574 | CEntryStub ces(1, kSaveFPRegs); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 575 | CallStub(&ces); |
| 576 | } |
| 577 | |
| 578 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 579 | MaybeObject* MacroAssembler::TryCallRuntime(Runtime::FunctionId id, |
| 580 | int num_arguments) { |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 581 | return TryCallRuntime(Runtime::FunctionForId(id), num_arguments); |
| 582 | } |
| 583 | |
| 584 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 585 | void MacroAssembler::CallRuntime(const Runtime::Function* f, |
| 586 | int num_arguments) { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 587 | // If the expected number of arguments of the runtime function is |
| 588 | // constant, we check that the actual number of arguments match the |
| 589 | // expectation. |
| 590 | if (f->nargs >= 0 && f->nargs != num_arguments) { |
| 591 | IllegalOperation(num_arguments); |
| 592 | return; |
| 593 | } |
| 594 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 595 | // TODO(1236192): Most runtime routines don't need the number of |
| 596 | // arguments passed in because it is constant. At some point we |
| 597 | // should remove this need and make the runtime routine entry code |
| 598 | // smarter. |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 599 | Set(rax, num_arguments); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 600 | LoadAddress(rbx, ExternalReference(f, isolate())); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 601 | CEntryStub ces(f->result_size); |
| 602 | CallStub(&ces); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 606 | MaybeObject* MacroAssembler::TryCallRuntime(const Runtime::Function* f, |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 607 | int num_arguments) { |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 608 | if (f->nargs >= 0 && f->nargs != num_arguments) { |
| 609 | IllegalOperation(num_arguments); |
| 610 | // Since we did not call the stub, there was no allocation failure. |
| 611 | // Return some non-failure object. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 612 | return HEAP->undefined_value(); |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | // TODO(1236192): Most runtime routines don't need the number of |
| 616 | // arguments passed in because it is constant. At some point we |
| 617 | // should remove this need and make the runtime routine entry code |
| 618 | // smarter. |
| 619 | Set(rax, num_arguments); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 620 | LoadAddress(rbx, ExternalReference(f, isolate())); |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 621 | CEntryStub ces(f->result_size); |
| 622 | return TryCallStub(&ces); |
| 623 | } |
| 624 | |
| 625 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 626 | void MacroAssembler::CallExternalReference(const ExternalReference& ext, |
| 627 | int num_arguments) { |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 628 | Set(rax, num_arguments); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 629 | LoadAddress(rbx, ext); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 630 | |
| 631 | CEntryStub stub(1); |
| 632 | CallStub(&stub); |
| 633 | } |
| 634 | |
| 635 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 636 | void MacroAssembler::TailCallExternalReference(const ExternalReference& ext, |
| 637 | int num_arguments, |
| 638 | int result_size) { |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 639 | // ----------- S t a t e ------------- |
| 640 | // -- rsp[0] : return address |
| 641 | // -- rsp[8] : argument num_arguments - 1 |
| 642 | // ... |
| 643 | // -- rsp[8 * num_arguments] : argument 0 (receiver) |
| 644 | // ----------------------------------- |
| 645 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 646 | // TODO(1236192): Most runtime routines don't need the number of |
| 647 | // arguments passed in because it is constant. At some point we |
| 648 | // should remove this need and make the runtime routine entry code |
| 649 | // smarter. |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 650 | Set(rax, num_arguments); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 651 | JumpToExternalReference(ext, result_size); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 655 | MaybeObject* MacroAssembler::TryTailCallExternalReference( |
| 656 | const ExternalReference& ext, int num_arguments, int result_size) { |
| 657 | // ----------- S t a t e ------------- |
| 658 | // -- rsp[0] : return address |
| 659 | // -- rsp[8] : argument num_arguments - 1 |
| 660 | // ... |
| 661 | // -- rsp[8 * num_arguments] : argument 0 (receiver) |
| 662 | // ----------------------------------- |
| 663 | |
| 664 | // TODO(1236192): Most runtime routines don't need the number of |
| 665 | // arguments passed in because it is constant. At some point we |
| 666 | // should remove this need and make the runtime routine entry code |
| 667 | // smarter. |
| 668 | Set(rax, num_arguments); |
| 669 | return TryJumpToExternalReference(ext, result_size); |
| 670 | } |
| 671 | |
| 672 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 673 | void MacroAssembler::TailCallRuntime(Runtime::FunctionId fid, |
| 674 | int num_arguments, |
| 675 | int result_size) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 676 | TailCallExternalReference(ExternalReference(fid, isolate()), |
| 677 | num_arguments, |
| 678 | result_size); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 679 | } |
| 680 | |
| 681 | |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 682 | MaybeObject* MacroAssembler::TryTailCallRuntime(Runtime::FunctionId fid, |
| 683 | int num_arguments, |
| 684 | int result_size) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 685 | return TryTailCallExternalReference(ExternalReference(fid, isolate()), |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 686 | num_arguments, |
| 687 | result_size); |
| 688 | } |
| 689 | |
| 690 | |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 691 | static int Offset(ExternalReference ref0, ExternalReference ref1) { |
| 692 | int64_t offset = (ref0.address() - ref1.address()); |
| 693 | // Check that fits into int. |
| 694 | ASSERT(static_cast<int>(offset) == offset); |
| 695 | return static_cast<int>(offset); |
| 696 | } |
| 697 | |
| 698 | |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 699 | void MacroAssembler::PrepareCallApiFunction(int arg_stack_space) { |
| 700 | #ifdef _WIN64 |
| 701 | // We need to prepare a slot for result handle on stack and put |
| 702 | // a pointer to it into 1st arg register. |
| 703 | EnterApiExitFrame(arg_stack_space + 1); |
| 704 | |
| 705 | // rcx must be used to pass the pointer to the return value slot. |
| 706 | lea(rcx, StackSpaceOperand(arg_stack_space)); |
| 707 | #else |
| 708 | EnterApiExitFrame(arg_stack_space); |
| 709 | #endif |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 713 | MaybeObject* MacroAssembler::TryCallApiFunctionAndReturn( |
| 714 | ApiFunction* function, int stack_space) { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 715 | Label empty_result; |
| 716 | Label prologue; |
| 717 | Label promote_scheduled_exception; |
| 718 | Label delete_allocated_handles; |
| 719 | Label leave_exit_frame; |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 720 | Label write_back; |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 721 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 722 | Factory* factory = isolate()->factory(); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 723 | ExternalReference next_address = |
| 724 | ExternalReference::handle_scope_next_address(); |
| 725 | const int kNextOffset = 0; |
| 726 | const int kLimitOffset = Offset( |
| 727 | ExternalReference::handle_scope_limit_address(), |
| 728 | next_address); |
| 729 | const int kLevelOffset = Offset( |
| 730 | ExternalReference::handle_scope_level_address(), |
| 731 | next_address); |
| 732 | ExternalReference scheduled_exception_address = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 733 | ExternalReference::scheduled_exception_address(isolate()); |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 734 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 735 | // Allocate HandleScope in callee-save registers. |
| 736 | Register prev_next_address_reg = r14; |
| 737 | Register prev_limit_reg = rbx; |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 738 | Register base_reg = r15; |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 739 | movq(base_reg, next_address); |
| 740 | movq(prev_next_address_reg, Operand(base_reg, kNextOffset)); |
| 741 | movq(prev_limit_reg, Operand(base_reg, kLimitOffset)); |
| 742 | addl(Operand(base_reg, kLevelOffset), Immediate(1)); |
| 743 | // Call the api function! |
| 744 | movq(rax, |
| 745 | reinterpret_cast<int64_t>(function->address()), |
| 746 | RelocInfo::RUNTIME_ENTRY); |
| 747 | call(rax); |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 748 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 749 | #ifdef _WIN64 |
| 750 | // rax keeps a pointer to v8::Handle, unpack it. |
| 751 | movq(rax, Operand(rax, 0)); |
| 752 | #endif |
| 753 | // Check if the result handle holds 0. |
| 754 | testq(rax, rax); |
| 755 | j(zero, &empty_result); |
| 756 | // It was non-zero. Dereference to get the result value. |
| 757 | movq(rax, Operand(rax, 0)); |
| 758 | bind(&prologue); |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 759 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 760 | // No more valid handles (the result handle was the last one). Restore |
| 761 | // previous handle scope. |
| 762 | subl(Operand(base_reg, kLevelOffset), Immediate(1)); |
| 763 | movq(Operand(base_reg, kNextOffset), prev_next_address_reg); |
| 764 | cmpq(prev_limit_reg, Operand(base_reg, kLimitOffset)); |
| 765 | j(not_equal, &delete_allocated_handles); |
| 766 | bind(&leave_exit_frame); |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 767 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 768 | // Check if the function scheduled an exception. |
| 769 | movq(rsi, scheduled_exception_address); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 770 | Cmp(Operand(rsi, 0), factory->the_hole_value()); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 771 | j(not_equal, &promote_scheduled_exception); |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 772 | |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 773 | LeaveApiExitFrame(); |
| 774 | ret(stack_space * kPointerSize); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 775 | |
| 776 | bind(&promote_scheduled_exception); |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 777 | MaybeObject* result = TryTailCallRuntime(Runtime::kPromoteScheduledException, |
| 778 | 0, 1); |
| 779 | if (result->IsFailure()) { |
| 780 | return result; |
| 781 | } |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 782 | |
| 783 | bind(&empty_result); |
| 784 | // It was zero; the result is undefined. |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 785 | Move(rax, factory->undefined_value()); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 786 | jmp(&prologue); |
| 787 | |
| 788 | // HandleScope limit has changed. Delete allocated extensions. |
| 789 | bind(&delete_allocated_handles); |
| 790 | movq(Operand(base_reg, kLimitOffset), prev_limit_reg); |
| 791 | movq(prev_limit_reg, rax); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 792 | #ifdef _WIN64 |
| 793 | LoadAddress(rcx, ExternalReference::isolate_address()); |
| 794 | #else |
| 795 | LoadAddress(rdi, ExternalReference::isolate_address()); |
| 796 | #endif |
| 797 | LoadAddress(rax, |
| 798 | ExternalReference::delete_handle_scope_extensions(isolate())); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 799 | call(rax); |
| 800 | movq(rax, prev_limit_reg); |
| 801 | jmp(&leave_exit_frame); |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 802 | |
| 803 | return result; |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 807 | void MacroAssembler::JumpToExternalReference(const ExternalReference& ext, |
| 808 | int result_size) { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 809 | // Set the entry point and jump to the C entry runtime stub. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 810 | LoadAddress(rbx, ext); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 811 | CEntryStub ces(result_size); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 812 | jmp(ces.GetCode(), RelocInfo::CODE_TARGET); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 813 | } |
| 814 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 815 | |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 816 | MaybeObject* MacroAssembler::TryJumpToExternalReference( |
| 817 | const ExternalReference& ext, int result_size) { |
| 818 | // Set the entry point and jump to the C entry runtime stub. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 819 | LoadAddress(rbx, ext); |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 820 | CEntryStub ces(result_size); |
| 821 | return TryTailCallStub(&ces); |
| 822 | } |
| 823 | |
| 824 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 825 | void MacroAssembler::InvokeBuiltin(Builtins::JavaScript id, |
| 826 | InvokeFlag flag, |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 827 | const CallWrapper& call_wrapper) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 828 | // You can't call a builtin without a valid frame. |
| 829 | ASSERT(flag == JUMP_FUNCTION || has_frame()); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 830 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 831 | // Rely on the assertion to check that the number of provided |
| 832 | // arguments match the expected number of arguments. Fake a |
| 833 | // parameter count to avoid emitting code to do the check. |
| 834 | ParameterCount expected(0); |
| 835 | GetBuiltinEntry(rdx, id); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 836 | InvokeCode(rdx, expected, expected, flag, call_wrapper, CALL_AS_METHOD); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 837 | } |
| 838 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 839 | |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 840 | void MacroAssembler::GetBuiltinFunction(Register target, |
| 841 | Builtins::JavaScript id) { |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 842 | // Load the builtins object into target register. |
| 843 | movq(target, Operand(rsi, Context::SlotOffset(Context::GLOBAL_INDEX))); |
| 844 | movq(target, FieldOperand(target, GlobalObject::kBuiltinsOffset)); |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 845 | movq(target, FieldOperand(target, |
| 846 | JSBuiltinsObject::OffsetOfFunctionWithId(id))); |
| 847 | } |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 848 | |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 849 | |
| 850 | void MacroAssembler::GetBuiltinEntry(Register target, Builtins::JavaScript id) { |
| 851 | ASSERT(!target.is(rdi)); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 852 | // Load the JavaScript builtin function from the builtins object. |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 853 | GetBuiltinFunction(rdi, id); |
| 854 | movq(target, FieldOperand(rdi, JSFunction::kCodeEntryOffset)); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 855 | } |
| 856 | |
| 857 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 858 | static const Register saved_regs[] = |
| 859 | { rax, rcx, rdx, rbx, rbp, rsi, rdi, r8, r9, r10, r11 }; |
| 860 | static const int kNumberOfSavedRegs = sizeof(saved_regs) / sizeof(Register); |
| 861 | |
| 862 | |
| 863 | void MacroAssembler::PushCallerSaved(SaveFPRegsMode fp_mode, |
| 864 | Register exclusion1, |
| 865 | Register exclusion2, |
| 866 | Register exclusion3) { |
| 867 | // We don't allow a GC during a store buffer overflow so there is no need to |
| 868 | // store the registers in any particular way, but we do have to store and |
| 869 | // restore them. |
| 870 | for (int i = 0; i < kNumberOfSavedRegs; i++) { |
| 871 | Register reg = saved_regs[i]; |
| 872 | if (!reg.is(exclusion1) && !reg.is(exclusion2) && !reg.is(exclusion3)) { |
| 873 | push(reg); |
| 874 | } |
| 875 | } |
| 876 | // R12 to r15 are callee save on all platforms. |
| 877 | if (fp_mode == kSaveFPRegs) { |
| 878 | CpuFeatures::Scope scope(SSE2); |
| 879 | subq(rsp, Immediate(kDoubleSize * XMMRegister::kNumRegisters)); |
| 880 | for (int i = 0; i < XMMRegister::kNumRegisters; i++) { |
| 881 | XMMRegister reg = XMMRegister::from_code(i); |
| 882 | movsd(Operand(rsp, i * kDoubleSize), reg); |
| 883 | } |
| 884 | } |
| 885 | } |
| 886 | |
| 887 | |
| 888 | void MacroAssembler::PopCallerSaved(SaveFPRegsMode fp_mode, |
| 889 | Register exclusion1, |
| 890 | Register exclusion2, |
| 891 | Register exclusion3) { |
| 892 | if (fp_mode == kSaveFPRegs) { |
| 893 | CpuFeatures::Scope scope(SSE2); |
| 894 | for (int i = 0; i < XMMRegister::kNumRegisters; i++) { |
| 895 | XMMRegister reg = XMMRegister::from_code(i); |
| 896 | movsd(reg, Operand(rsp, i * kDoubleSize)); |
| 897 | } |
| 898 | addq(rsp, Immediate(kDoubleSize * XMMRegister::kNumRegisters)); |
| 899 | } |
| 900 | for (int i = kNumberOfSavedRegs - 1; i >= 0; i--) { |
| 901 | Register reg = saved_regs[i]; |
| 902 | if (!reg.is(exclusion1) && !reg.is(exclusion2) && !reg.is(exclusion3)) { |
| 903 | pop(reg); |
| 904 | } |
| 905 | } |
| 906 | } |
| 907 | |
| 908 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 909 | void MacroAssembler::Set(Register dst, int64_t x) { |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 910 | if (x == 0) { |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 911 | xorl(dst, dst); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 912 | } else if (is_uint32(x)) { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 913 | movl(dst, Immediate(static_cast<uint32_t>(x))); |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 914 | } else if (is_int32(x)) { |
| 915 | movq(dst, Immediate(static_cast<int32_t>(x))); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 916 | } else { |
| 917 | movq(dst, x, RelocInfo::NONE); |
| 918 | } |
| 919 | } |
| 920 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 921 | void MacroAssembler::Set(const Operand& dst, int64_t x) { |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 922 | if (is_int32(x)) { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 923 | movq(dst, Immediate(static_cast<int32_t>(x))); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 924 | } else { |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 925 | Set(kScratchRegister, x); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 926 | movq(dst, kScratchRegister); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 927 | } |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 928 | } |
| 929 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 930 | // ---------------------------------------------------------------------------- |
| 931 | // Smi tagging, untagging and tag detection. |
| 932 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 933 | Register MacroAssembler::GetSmiConstant(Smi* source) { |
| 934 | int value = source->value(); |
| 935 | if (value == 0) { |
| 936 | xorl(kScratchRegister, kScratchRegister); |
| 937 | return kScratchRegister; |
| 938 | } |
| 939 | if (value == 1) { |
| 940 | return kSmiConstantRegister; |
| 941 | } |
| 942 | LoadSmiConstant(kScratchRegister, source); |
| 943 | return kScratchRegister; |
| 944 | } |
| 945 | |
| 946 | void MacroAssembler::LoadSmiConstant(Register dst, Smi* source) { |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 947 | if (emit_debug_code()) { |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 948 | movq(dst, |
| 949 | reinterpret_cast<uint64_t>(Smi::FromInt(kSmiConstantRegisterValue)), |
| 950 | RelocInfo::NONE); |
| 951 | cmpq(dst, kSmiConstantRegister); |
| 952 | if (allow_stub_calls()) { |
| 953 | Assert(equal, "Uninitialized kSmiConstantRegister"); |
| 954 | } else { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 955 | Label ok; |
| 956 | j(equal, &ok, Label::kNear); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 957 | int3(); |
| 958 | bind(&ok); |
| 959 | } |
| 960 | } |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 961 | int value = source->value(); |
| 962 | if (value == 0) { |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 963 | xorl(dst, dst); |
| 964 | return; |
| 965 | } |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 966 | bool negative = value < 0; |
| 967 | unsigned int uvalue = negative ? -value : value; |
| 968 | |
| 969 | switch (uvalue) { |
| 970 | case 9: |
| 971 | lea(dst, Operand(kSmiConstantRegister, kSmiConstantRegister, times_8, 0)); |
| 972 | break; |
| 973 | case 8: |
| 974 | xorl(dst, dst); |
| 975 | lea(dst, Operand(dst, kSmiConstantRegister, times_8, 0)); |
| 976 | break; |
| 977 | case 4: |
| 978 | xorl(dst, dst); |
| 979 | lea(dst, Operand(dst, kSmiConstantRegister, times_4, 0)); |
| 980 | break; |
| 981 | case 5: |
| 982 | lea(dst, Operand(kSmiConstantRegister, kSmiConstantRegister, times_4, 0)); |
| 983 | break; |
| 984 | case 3: |
| 985 | lea(dst, Operand(kSmiConstantRegister, kSmiConstantRegister, times_2, 0)); |
| 986 | break; |
| 987 | case 2: |
| 988 | lea(dst, Operand(kSmiConstantRegister, kSmiConstantRegister, times_1, 0)); |
| 989 | break; |
| 990 | case 1: |
| 991 | movq(dst, kSmiConstantRegister); |
| 992 | break; |
| 993 | case 0: |
| 994 | UNREACHABLE(); |
| 995 | return; |
| 996 | default: |
| 997 | movq(dst, reinterpret_cast<uint64_t>(source), RelocInfo::NONE); |
| 998 | return; |
| 999 | } |
| 1000 | if (negative) { |
| 1001 | neg(dst); |
| 1002 | } |
| 1003 | } |
| 1004 | |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 1005 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1006 | void MacroAssembler::Integer32ToSmi(Register dst, Register src) { |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 1007 | STATIC_ASSERT(kSmiTag == 0); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1008 | if (!dst.is(src)) { |
| 1009 | movl(dst, src); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1010 | } |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1011 | shl(dst, Immediate(kSmiShift)); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1012 | } |
| 1013 | |
| 1014 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 1015 | void MacroAssembler::Integer32ToSmiField(const Operand& dst, Register src) { |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 1016 | if (emit_debug_code()) { |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 1017 | testb(dst, Immediate(0x01)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1018 | Label ok; |
| 1019 | j(zero, &ok, Label::kNear); |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 1020 | if (allow_stub_calls()) { |
| 1021 | Abort("Integer32ToSmiField writing to non-smi location"); |
| 1022 | } else { |
| 1023 | int3(); |
| 1024 | } |
| 1025 | bind(&ok); |
| 1026 | } |
| 1027 | ASSERT(kSmiShift % kBitsPerByte == 0); |
| 1028 | movl(Operand(dst, kSmiShift / kBitsPerByte), src); |
| 1029 | } |
| 1030 | |
| 1031 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1032 | void MacroAssembler::Integer64PlusConstantToSmi(Register dst, |
| 1033 | Register src, |
| 1034 | int constant) { |
| 1035 | if (dst.is(src)) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1036 | addl(dst, Immediate(constant)); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1037 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1038 | leal(dst, Operand(src, constant)); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1039 | } |
| 1040 | shl(dst, Immediate(kSmiShift)); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1041 | } |
| 1042 | |
| 1043 | |
| 1044 | void MacroAssembler::SmiToInteger32(Register dst, Register src) { |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 1045 | STATIC_ASSERT(kSmiTag == 0); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1046 | if (!dst.is(src)) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1047 | movq(dst, src); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1048 | } |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1049 | shr(dst, Immediate(kSmiShift)); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1050 | } |
| 1051 | |
| 1052 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1053 | void MacroAssembler::SmiToInteger32(Register dst, const Operand& src) { |
| 1054 | movl(dst, Operand(src, kSmiShift / kBitsPerByte)); |
| 1055 | } |
| 1056 | |
| 1057 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1058 | void MacroAssembler::SmiToInteger64(Register dst, Register src) { |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 1059 | STATIC_ASSERT(kSmiTag == 0); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1060 | if (!dst.is(src)) { |
| 1061 | movq(dst, src); |
| 1062 | } |
| 1063 | sar(dst, Immediate(kSmiShift)); |
| 1064 | } |
| 1065 | |
| 1066 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 1067 | void MacroAssembler::SmiToInteger64(Register dst, const Operand& src) { |
| 1068 | movsxlq(dst, Operand(src, kSmiShift / kBitsPerByte)); |
| 1069 | } |
| 1070 | |
| 1071 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1072 | void MacroAssembler::SmiTest(Register src) { |
| 1073 | testq(src, src); |
| 1074 | } |
| 1075 | |
| 1076 | |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 1077 | void MacroAssembler::SmiCompare(Register smi1, Register smi2) { |
| 1078 | if (emit_debug_code()) { |
| 1079 | AbortIfNotSmi(smi1); |
| 1080 | AbortIfNotSmi(smi2); |
| 1081 | } |
| 1082 | cmpq(smi1, smi2); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1083 | } |
| 1084 | |
| 1085 | |
| 1086 | void MacroAssembler::SmiCompare(Register dst, Smi* src) { |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 1087 | if (emit_debug_code()) { |
| 1088 | AbortIfNotSmi(dst); |
| 1089 | } |
| 1090 | Cmp(dst, src); |
| 1091 | } |
| 1092 | |
| 1093 | |
| 1094 | void MacroAssembler::Cmp(Register dst, Smi* src) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1095 | ASSERT(!dst.is(kScratchRegister)); |
| 1096 | if (src->value() == 0) { |
| 1097 | testq(dst, dst); |
| 1098 | } else { |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1099 | Register constant_reg = GetSmiConstant(src); |
| 1100 | cmpq(dst, constant_reg); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1101 | } |
| 1102 | } |
| 1103 | |
| 1104 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1105 | void MacroAssembler::SmiCompare(Register dst, const Operand& src) { |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 1106 | if (emit_debug_code()) { |
| 1107 | AbortIfNotSmi(dst); |
| 1108 | AbortIfNotSmi(src); |
| 1109 | } |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1110 | cmpq(dst, src); |
| 1111 | } |
| 1112 | |
| 1113 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1114 | void MacroAssembler::SmiCompare(const Operand& dst, Register src) { |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 1115 | if (emit_debug_code()) { |
| 1116 | AbortIfNotSmi(dst); |
| 1117 | AbortIfNotSmi(src); |
| 1118 | } |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1119 | cmpq(dst, src); |
| 1120 | } |
| 1121 | |
| 1122 | |
| 1123 | void MacroAssembler::SmiCompare(const Operand& dst, Smi* src) { |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 1124 | if (emit_debug_code()) { |
| 1125 | AbortIfNotSmi(dst); |
| 1126 | } |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1127 | cmpl(Operand(dst, kSmiShift / kBitsPerByte), Immediate(src->value())); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1128 | } |
| 1129 | |
| 1130 | |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 1131 | void MacroAssembler::Cmp(const Operand& dst, Smi* src) { |
| 1132 | // The Operand cannot use the smi register. |
| 1133 | Register smi_reg = GetSmiConstant(src); |
| 1134 | ASSERT(!dst.AddressUsesRegister(smi_reg)); |
| 1135 | cmpq(dst, smi_reg); |
| 1136 | } |
| 1137 | |
| 1138 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 1139 | void MacroAssembler::SmiCompareInteger32(const Operand& dst, Register src) { |
| 1140 | cmpl(Operand(dst, kSmiShift / kBitsPerByte), src); |
| 1141 | } |
| 1142 | |
| 1143 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1144 | void MacroAssembler::PositiveSmiTimesPowerOfTwoToInteger64(Register dst, |
| 1145 | Register src, |
| 1146 | int power) { |
| 1147 | ASSERT(power >= 0); |
| 1148 | ASSERT(power < 64); |
| 1149 | if (power == 0) { |
| 1150 | SmiToInteger64(dst, src); |
| 1151 | return; |
| 1152 | } |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1153 | if (!dst.is(src)) { |
| 1154 | movq(dst, src); |
| 1155 | } |
| 1156 | if (power < kSmiShift) { |
| 1157 | sar(dst, Immediate(kSmiShift - power)); |
| 1158 | } else if (power > kSmiShift) { |
| 1159 | shl(dst, Immediate(power - kSmiShift)); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1160 | } |
| 1161 | } |
| 1162 | |
| 1163 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1164 | void MacroAssembler::PositiveSmiDivPowerOfTwoToInteger32(Register dst, |
| 1165 | Register src, |
| 1166 | int power) { |
| 1167 | ASSERT((0 <= power) && (power < 32)); |
| 1168 | if (dst.is(src)) { |
| 1169 | shr(dst, Immediate(power + kSmiShift)); |
| 1170 | } else { |
| 1171 | UNIMPLEMENTED(); // Not used. |
| 1172 | } |
| 1173 | } |
| 1174 | |
| 1175 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1176 | void MacroAssembler::SmiOrIfSmis(Register dst, Register src1, Register src2, |
| 1177 | Label* on_not_smis, |
| 1178 | Label::Distance near_jump) { |
| 1179 | if (dst.is(src1) || dst.is(src2)) { |
| 1180 | ASSERT(!src1.is(kScratchRegister)); |
| 1181 | ASSERT(!src2.is(kScratchRegister)); |
| 1182 | movq(kScratchRegister, src1); |
| 1183 | or_(kScratchRegister, src2); |
| 1184 | JumpIfNotSmi(kScratchRegister, on_not_smis, near_jump); |
| 1185 | movq(dst, kScratchRegister); |
| 1186 | } else { |
| 1187 | movq(dst, src1); |
| 1188 | or_(dst, src2); |
| 1189 | JumpIfNotSmi(dst, on_not_smis, near_jump); |
| 1190 | } |
| 1191 | } |
| 1192 | |
| 1193 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1194 | Condition MacroAssembler::CheckSmi(Register src) { |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 1195 | STATIC_ASSERT(kSmiTag == 0); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1196 | testb(src, Immediate(kSmiTagMask)); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1197 | return zero; |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1198 | } |
| 1199 | |
| 1200 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1201 | Condition MacroAssembler::CheckSmi(const Operand& src) { |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 1202 | STATIC_ASSERT(kSmiTag == 0); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1203 | testb(src, Immediate(kSmiTagMask)); |
| 1204 | return zero; |
| 1205 | } |
| 1206 | |
| 1207 | |
ricow@chromium.org | eb7c144 | 2010-10-04 08:54:21 +0000 | [diff] [blame] | 1208 | Condition MacroAssembler::CheckNonNegativeSmi(Register src) { |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 1209 | STATIC_ASSERT(kSmiTag == 0); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 1210 | // Test that both bits of the mask 0x8000000000000001 are zero. |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1211 | movq(kScratchRegister, src); |
| 1212 | rol(kScratchRegister, Immediate(1)); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1213 | testb(kScratchRegister, Immediate(3)); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1214 | return zero; |
| 1215 | } |
| 1216 | |
| 1217 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1218 | Condition MacroAssembler::CheckBothSmi(Register first, Register second) { |
| 1219 | if (first.is(second)) { |
| 1220 | return CheckSmi(first); |
| 1221 | } |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 1222 | STATIC_ASSERT(kSmiTag == 0 && kHeapObjectTag == 1 && kHeapObjectTagMask == 3); |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 1223 | leal(kScratchRegister, Operand(first, second, times_1, 0)); |
| 1224 | testb(kScratchRegister, Immediate(0x03)); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1225 | return zero; |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1226 | } |
| 1227 | |
| 1228 | |
ricow@chromium.org | eb7c144 | 2010-10-04 08:54:21 +0000 | [diff] [blame] | 1229 | Condition MacroAssembler::CheckBothNonNegativeSmi(Register first, |
| 1230 | Register second) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1231 | if (first.is(second)) { |
ricow@chromium.org | eb7c144 | 2010-10-04 08:54:21 +0000 | [diff] [blame] | 1232 | return CheckNonNegativeSmi(first); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1233 | } |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1234 | movq(kScratchRegister, first); |
| 1235 | or_(kScratchRegister, second); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1236 | rol(kScratchRegister, Immediate(1)); |
ricow@chromium.org | eb7c144 | 2010-10-04 08:54:21 +0000 | [diff] [blame] | 1237 | testl(kScratchRegister, Immediate(3)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1238 | return zero; |
| 1239 | } |
| 1240 | |
| 1241 | |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 1242 | Condition MacroAssembler::CheckEitherSmi(Register first, |
| 1243 | Register second, |
| 1244 | Register scratch) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1245 | if (first.is(second)) { |
| 1246 | return CheckSmi(first); |
| 1247 | } |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 1248 | if (scratch.is(second)) { |
| 1249 | andl(scratch, first); |
| 1250 | } else { |
| 1251 | if (!scratch.is(first)) { |
| 1252 | movl(scratch, first); |
| 1253 | } |
| 1254 | andl(scratch, second); |
| 1255 | } |
| 1256 | testb(scratch, Immediate(kSmiTagMask)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1257 | return zero; |
| 1258 | } |
| 1259 | |
| 1260 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1261 | Condition MacroAssembler::CheckIsMinSmi(Register src) { |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1262 | ASSERT(!src.is(kScratchRegister)); |
| 1263 | // If we overflow by subtracting one, it's the minimal smi value. |
| 1264 | cmpq(src, kSmiConstantRegister); |
| 1265 | return overflow; |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1266 | } |
| 1267 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 1268 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1269 | Condition MacroAssembler::CheckInteger32ValidSmiValue(Register src) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1270 | // A 32-bit integer value can always be converted to a smi. |
| 1271 | return always; |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1272 | } |
| 1273 | |
| 1274 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1275 | Condition MacroAssembler::CheckUInteger32ValidSmiValue(Register src) { |
| 1276 | // An unsigned 32-bit integer value is valid as long as the high bit |
| 1277 | // is not set. |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1278 | testl(src, src); |
| 1279 | return positive; |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1280 | } |
| 1281 | |
| 1282 | |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1283 | void MacroAssembler::CheckSmiToIndicator(Register dst, Register src) { |
| 1284 | if (dst.is(src)) { |
| 1285 | andl(dst, Immediate(kSmiTagMask)); |
| 1286 | } else { |
| 1287 | movl(dst, Immediate(kSmiTagMask)); |
| 1288 | andl(dst, src); |
| 1289 | } |
| 1290 | } |
| 1291 | |
| 1292 | |
| 1293 | void MacroAssembler::CheckSmiToIndicator(Register dst, const Operand& src) { |
| 1294 | if (!(src.AddressUsesRegister(dst))) { |
| 1295 | movl(dst, Immediate(kSmiTagMask)); |
| 1296 | andl(dst, src); |
| 1297 | } else { |
| 1298 | movl(dst, src); |
| 1299 | andl(dst, Immediate(kSmiTagMask)); |
| 1300 | } |
| 1301 | } |
| 1302 | |
| 1303 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1304 | void MacroAssembler::JumpIfNotValidSmiValue(Register src, |
| 1305 | Label* on_invalid, |
| 1306 | Label::Distance near_jump) { |
| 1307 | Condition is_valid = CheckInteger32ValidSmiValue(src); |
| 1308 | j(NegateCondition(is_valid), on_invalid, near_jump); |
| 1309 | } |
| 1310 | |
| 1311 | |
| 1312 | void MacroAssembler::JumpIfUIntNotValidSmiValue(Register src, |
| 1313 | Label* on_invalid, |
| 1314 | Label::Distance near_jump) { |
| 1315 | Condition is_valid = CheckUInteger32ValidSmiValue(src); |
| 1316 | j(NegateCondition(is_valid), on_invalid, near_jump); |
| 1317 | } |
| 1318 | |
| 1319 | |
| 1320 | void MacroAssembler::JumpIfSmi(Register src, |
| 1321 | Label* on_smi, |
| 1322 | Label::Distance near_jump) { |
| 1323 | Condition smi = CheckSmi(src); |
| 1324 | j(smi, on_smi, near_jump); |
| 1325 | } |
| 1326 | |
| 1327 | |
| 1328 | void MacroAssembler::JumpIfNotSmi(Register src, |
| 1329 | Label* on_not_smi, |
| 1330 | Label::Distance near_jump) { |
| 1331 | Condition smi = CheckSmi(src); |
| 1332 | j(NegateCondition(smi), on_not_smi, near_jump); |
| 1333 | } |
| 1334 | |
| 1335 | |
| 1336 | void MacroAssembler::JumpUnlessNonNegativeSmi( |
| 1337 | Register src, Label* on_not_smi_or_negative, |
| 1338 | Label::Distance near_jump) { |
| 1339 | Condition non_negative_smi = CheckNonNegativeSmi(src); |
| 1340 | j(NegateCondition(non_negative_smi), on_not_smi_or_negative, near_jump); |
| 1341 | } |
| 1342 | |
| 1343 | |
| 1344 | void MacroAssembler::JumpIfSmiEqualsConstant(Register src, |
| 1345 | Smi* constant, |
| 1346 | Label* on_equals, |
| 1347 | Label::Distance near_jump) { |
| 1348 | SmiCompare(src, constant); |
| 1349 | j(equal, on_equals, near_jump); |
| 1350 | } |
| 1351 | |
| 1352 | |
| 1353 | void MacroAssembler::JumpIfNotBothSmi(Register src1, |
| 1354 | Register src2, |
| 1355 | Label* on_not_both_smi, |
| 1356 | Label::Distance near_jump) { |
| 1357 | Condition both_smi = CheckBothSmi(src1, src2); |
| 1358 | j(NegateCondition(both_smi), on_not_both_smi, near_jump); |
| 1359 | } |
| 1360 | |
| 1361 | |
| 1362 | void MacroAssembler::JumpUnlessBothNonNegativeSmi(Register src1, |
| 1363 | Register src2, |
| 1364 | Label* on_not_both_smi, |
| 1365 | Label::Distance near_jump) { |
| 1366 | Condition both_smi = CheckBothNonNegativeSmi(src1, src2); |
| 1367 | j(NegateCondition(both_smi), on_not_both_smi, near_jump); |
| 1368 | } |
| 1369 | |
| 1370 | |
| 1371 | void MacroAssembler::SmiTryAddConstant(Register dst, |
| 1372 | Register src, |
| 1373 | Smi* constant, |
| 1374 | Label* on_not_smi_result, |
| 1375 | Label::Distance near_jump) { |
| 1376 | // Does not assume that src is a smi. |
| 1377 | ASSERT_EQ(static_cast<int>(1), static_cast<int>(kSmiTagMask)); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 1378 | STATIC_ASSERT(kSmiTag == 0); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1379 | ASSERT(!dst.is(kScratchRegister)); |
| 1380 | ASSERT(!src.is(kScratchRegister)); |
| 1381 | |
| 1382 | JumpIfNotSmi(src, on_not_smi_result, near_jump); |
| 1383 | Register tmp = (dst.is(src) ? kScratchRegister : dst); |
| 1384 | LoadSmiConstant(tmp, constant); |
| 1385 | addq(tmp, src); |
| 1386 | j(overflow, on_not_smi_result, near_jump); |
| 1387 | if (dst.is(src)) { |
| 1388 | movq(dst, tmp); |
| 1389 | } |
| 1390 | } |
| 1391 | |
| 1392 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1393 | void MacroAssembler::SmiAddConstant(Register dst, Register src, Smi* constant) { |
| 1394 | if (constant->value() == 0) { |
| 1395 | if (!dst.is(src)) { |
| 1396 | movq(dst, src); |
| 1397 | } |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1398 | return; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1399 | } else if (dst.is(src)) { |
| 1400 | ASSERT(!dst.is(kScratchRegister)); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1401 | switch (constant->value()) { |
| 1402 | case 1: |
| 1403 | addq(dst, kSmiConstantRegister); |
| 1404 | return; |
| 1405 | case 2: |
| 1406 | lea(dst, Operand(src, kSmiConstantRegister, times_2, 0)); |
| 1407 | return; |
| 1408 | case 4: |
| 1409 | lea(dst, Operand(src, kSmiConstantRegister, times_4, 0)); |
| 1410 | return; |
| 1411 | case 8: |
| 1412 | lea(dst, Operand(src, kSmiConstantRegister, times_8, 0)); |
| 1413 | return; |
| 1414 | default: |
| 1415 | Register constant_reg = GetSmiConstant(constant); |
| 1416 | addq(dst, constant_reg); |
| 1417 | return; |
| 1418 | } |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1419 | } else { |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1420 | switch (constant->value()) { |
| 1421 | case 1: |
| 1422 | lea(dst, Operand(src, kSmiConstantRegister, times_1, 0)); |
| 1423 | return; |
| 1424 | case 2: |
| 1425 | lea(dst, Operand(src, kSmiConstantRegister, times_2, 0)); |
| 1426 | return; |
| 1427 | case 4: |
| 1428 | lea(dst, Operand(src, kSmiConstantRegister, times_4, 0)); |
| 1429 | return; |
| 1430 | case 8: |
| 1431 | lea(dst, Operand(src, kSmiConstantRegister, times_8, 0)); |
| 1432 | return; |
| 1433 | default: |
| 1434 | LoadSmiConstant(dst, constant); |
| 1435 | addq(dst, src); |
| 1436 | return; |
| 1437 | } |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1438 | } |
| 1439 | } |
| 1440 | |
| 1441 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1442 | void MacroAssembler::SmiAddConstant(const Operand& dst, Smi* constant) { |
| 1443 | if (constant->value() != 0) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1444 | addl(Operand(dst, kSmiShift / kBitsPerByte), Immediate(constant->value())); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1445 | } |
| 1446 | } |
| 1447 | |
| 1448 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1449 | void MacroAssembler::SmiAddConstant(Register dst, |
| 1450 | Register src, |
| 1451 | Smi* constant, |
| 1452 | Label* on_not_smi_result, |
| 1453 | Label::Distance near_jump) { |
| 1454 | if (constant->value() == 0) { |
| 1455 | if (!dst.is(src)) { |
| 1456 | movq(dst, src); |
| 1457 | } |
| 1458 | } else if (dst.is(src)) { |
| 1459 | ASSERT(!dst.is(kScratchRegister)); |
| 1460 | |
| 1461 | LoadSmiConstant(kScratchRegister, constant); |
| 1462 | addq(kScratchRegister, src); |
| 1463 | j(overflow, on_not_smi_result, near_jump); |
| 1464 | movq(dst, kScratchRegister); |
| 1465 | } else { |
| 1466 | LoadSmiConstant(dst, constant); |
| 1467 | addq(dst, src); |
| 1468 | j(overflow, on_not_smi_result, near_jump); |
| 1469 | } |
| 1470 | } |
| 1471 | |
| 1472 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1473 | void MacroAssembler::SmiSubConstant(Register dst, Register src, Smi* constant) { |
| 1474 | if (constant->value() == 0) { |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1475 | if (!dst.is(src)) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1476 | movq(dst, src); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1477 | } |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1478 | } else if (dst.is(src)) { |
| 1479 | ASSERT(!dst.is(kScratchRegister)); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1480 | Register constant_reg = GetSmiConstant(constant); |
| 1481 | subq(dst, constant_reg); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1482 | } else { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1483 | if (constant->value() == Smi::kMinValue) { |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1484 | LoadSmiConstant(dst, constant); |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 1485 | // Adding and subtracting the min-value gives the same result, it only |
| 1486 | // differs on the overflow bit, which we don't check here. |
| 1487 | addq(dst, src); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1488 | } else { |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 1489 | // Subtract by adding the negation. |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1490 | LoadSmiConstant(dst, Smi::FromInt(-constant->value())); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1491 | addq(dst, src); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1492 | } |
| 1493 | } |
| 1494 | } |
| 1495 | |
| 1496 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1497 | void MacroAssembler::SmiSubConstant(Register dst, |
| 1498 | Register src, |
| 1499 | Smi* constant, |
| 1500 | Label* on_not_smi_result, |
| 1501 | Label::Distance near_jump) { |
| 1502 | if (constant->value() == 0) { |
| 1503 | if (!dst.is(src)) { |
| 1504 | movq(dst, src); |
| 1505 | } |
| 1506 | } else if (dst.is(src)) { |
| 1507 | ASSERT(!dst.is(kScratchRegister)); |
| 1508 | if (constant->value() == Smi::kMinValue) { |
| 1509 | // Subtracting min-value from any non-negative value will overflow. |
| 1510 | // We test the non-negativeness before doing the subtraction. |
| 1511 | testq(src, src); |
| 1512 | j(not_sign, on_not_smi_result, near_jump); |
| 1513 | LoadSmiConstant(kScratchRegister, constant); |
| 1514 | subq(dst, kScratchRegister); |
| 1515 | } else { |
| 1516 | // Subtract by adding the negation. |
| 1517 | LoadSmiConstant(kScratchRegister, Smi::FromInt(-constant->value())); |
| 1518 | addq(kScratchRegister, dst); |
| 1519 | j(overflow, on_not_smi_result, near_jump); |
| 1520 | movq(dst, kScratchRegister); |
| 1521 | } |
| 1522 | } else { |
| 1523 | if (constant->value() == Smi::kMinValue) { |
| 1524 | // Subtracting min-value from any non-negative value will overflow. |
| 1525 | // We test the non-negativeness before doing the subtraction. |
| 1526 | testq(src, src); |
| 1527 | j(not_sign, on_not_smi_result, near_jump); |
| 1528 | LoadSmiConstant(dst, constant); |
| 1529 | // Adding and subtracting the min-value gives the same result, it only |
| 1530 | // differs on the overflow bit, which we don't check here. |
| 1531 | addq(dst, src); |
| 1532 | } else { |
| 1533 | // Subtract by adding the negation. |
| 1534 | LoadSmiConstant(dst, Smi::FromInt(-(constant->value()))); |
| 1535 | addq(dst, src); |
| 1536 | j(overflow, on_not_smi_result, near_jump); |
| 1537 | } |
| 1538 | } |
| 1539 | } |
| 1540 | |
| 1541 | |
| 1542 | void MacroAssembler::SmiNeg(Register dst, |
| 1543 | Register src, |
| 1544 | Label* on_smi_result, |
| 1545 | Label::Distance near_jump) { |
| 1546 | if (dst.is(src)) { |
| 1547 | ASSERT(!dst.is(kScratchRegister)); |
| 1548 | movq(kScratchRegister, src); |
| 1549 | neg(dst); // Low 32 bits are retained as zero by negation. |
| 1550 | // Test if result is zero or Smi::kMinValue. |
| 1551 | cmpq(dst, kScratchRegister); |
| 1552 | j(not_equal, on_smi_result, near_jump); |
| 1553 | movq(src, kScratchRegister); |
| 1554 | } else { |
| 1555 | movq(dst, src); |
| 1556 | neg(dst); |
| 1557 | cmpq(dst, src); |
| 1558 | // If the result is zero or Smi::kMinValue, negation failed to create a smi. |
| 1559 | j(not_equal, on_smi_result, near_jump); |
| 1560 | } |
| 1561 | } |
| 1562 | |
| 1563 | |
| 1564 | void MacroAssembler::SmiAdd(Register dst, |
| 1565 | Register src1, |
| 1566 | Register src2, |
| 1567 | Label* on_not_smi_result, |
| 1568 | Label::Distance near_jump) { |
| 1569 | ASSERT_NOT_NULL(on_not_smi_result); |
| 1570 | ASSERT(!dst.is(src2)); |
| 1571 | if (dst.is(src1)) { |
| 1572 | movq(kScratchRegister, src1); |
| 1573 | addq(kScratchRegister, src2); |
| 1574 | j(overflow, on_not_smi_result, near_jump); |
| 1575 | movq(dst, kScratchRegister); |
| 1576 | } else { |
| 1577 | movq(dst, src1); |
| 1578 | addq(dst, src2); |
| 1579 | j(overflow, on_not_smi_result, near_jump); |
| 1580 | } |
| 1581 | } |
| 1582 | |
| 1583 | |
| 1584 | void MacroAssembler::SmiAdd(Register dst, |
| 1585 | Register src1, |
| 1586 | const Operand& src2, |
| 1587 | Label* on_not_smi_result, |
| 1588 | Label::Distance near_jump) { |
| 1589 | ASSERT_NOT_NULL(on_not_smi_result); |
| 1590 | if (dst.is(src1)) { |
| 1591 | movq(kScratchRegister, src1); |
| 1592 | addq(kScratchRegister, src2); |
| 1593 | j(overflow, on_not_smi_result, near_jump); |
| 1594 | movq(dst, kScratchRegister); |
| 1595 | } else { |
| 1596 | ASSERT(!src2.AddressUsesRegister(dst)); |
| 1597 | movq(dst, src1); |
| 1598 | addq(dst, src2); |
| 1599 | j(overflow, on_not_smi_result, near_jump); |
| 1600 | } |
| 1601 | } |
| 1602 | |
| 1603 | |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 1604 | void MacroAssembler::SmiAdd(Register dst, |
| 1605 | Register src1, |
| 1606 | Register src2) { |
| 1607 | // No overflow checking. Use only when it's known that |
| 1608 | // overflowing is impossible. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1609 | if (!dst.is(src1)) { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1610 | if (emit_debug_code()) { |
| 1611 | movq(kScratchRegister, src1); |
| 1612 | addq(kScratchRegister, src2); |
| 1613 | Check(no_overflow, "Smi addition overflow"); |
| 1614 | } |
| 1615 | lea(dst, Operand(src1, src2, times_1, 0)); |
| 1616 | } else { |
| 1617 | addq(dst, src2); |
| 1618 | Assert(no_overflow, "Smi addition overflow"); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1619 | } |
| 1620 | } |
| 1621 | |
| 1622 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1623 | void MacroAssembler::SmiSub(Register dst, |
| 1624 | Register src1, |
| 1625 | Register src2, |
| 1626 | Label* on_not_smi_result, |
| 1627 | Label::Distance near_jump) { |
| 1628 | ASSERT_NOT_NULL(on_not_smi_result); |
| 1629 | ASSERT(!dst.is(src2)); |
| 1630 | if (dst.is(src1)) { |
| 1631 | cmpq(dst, src2); |
| 1632 | j(overflow, on_not_smi_result, near_jump); |
| 1633 | subq(dst, src2); |
| 1634 | } else { |
| 1635 | movq(dst, src1); |
| 1636 | subq(dst, src2); |
| 1637 | j(overflow, on_not_smi_result, near_jump); |
| 1638 | } |
| 1639 | } |
| 1640 | |
| 1641 | |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 1642 | void MacroAssembler::SmiSub(Register dst, Register src1, Register src2) { |
| 1643 | // No overflow checking. Use only when it's known that |
| 1644 | // overflowing is impossible (e.g., subtracting two positive smis). |
| 1645 | ASSERT(!dst.is(src2)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1646 | if (!dst.is(src1)) { |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 1647 | movq(dst, src1); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1648 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1649 | subq(dst, src2); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 1650 | Assert(no_overflow, "Smi subtraction overflow"); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1651 | } |
| 1652 | |
| 1653 | |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 1654 | void MacroAssembler::SmiSub(Register dst, |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1655 | Register src1, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1656 | const Operand& src2, |
| 1657 | Label* on_not_smi_result, |
| 1658 | Label::Distance near_jump) { |
| 1659 | ASSERT_NOT_NULL(on_not_smi_result); |
| 1660 | if (dst.is(src1)) { |
| 1661 | movq(kScratchRegister, src2); |
| 1662 | cmpq(src1, kScratchRegister); |
| 1663 | j(overflow, on_not_smi_result, near_jump); |
| 1664 | subq(src1, kScratchRegister); |
| 1665 | } else { |
| 1666 | movq(dst, src1); |
| 1667 | subq(dst, src2); |
| 1668 | j(overflow, on_not_smi_result, near_jump); |
| 1669 | } |
| 1670 | } |
| 1671 | |
| 1672 | |
| 1673 | void MacroAssembler::SmiSub(Register dst, |
| 1674 | Register src1, |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 1675 | const Operand& src2) { |
| 1676 | // No overflow checking. Use only when it's known that |
| 1677 | // overflowing is impossible (e.g., subtracting two positive smis). |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1678 | if (!dst.is(src1)) { |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 1679 | movq(dst, src1); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1680 | } |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1681 | subq(dst, src2); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 1682 | Assert(no_overflow, "Smi subtraction overflow"); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1683 | } |
| 1684 | |
| 1685 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1686 | void MacroAssembler::SmiMul(Register dst, |
| 1687 | Register src1, |
| 1688 | Register src2, |
| 1689 | Label* on_not_smi_result, |
| 1690 | Label::Distance near_jump) { |
| 1691 | ASSERT(!dst.is(src2)); |
| 1692 | ASSERT(!dst.is(kScratchRegister)); |
| 1693 | ASSERT(!src1.is(kScratchRegister)); |
| 1694 | ASSERT(!src2.is(kScratchRegister)); |
| 1695 | |
| 1696 | if (dst.is(src1)) { |
| 1697 | Label failure, zero_correct_result; |
| 1698 | movq(kScratchRegister, src1); // Create backup for later testing. |
| 1699 | SmiToInteger64(dst, src1); |
| 1700 | imul(dst, src2); |
| 1701 | j(overflow, &failure, Label::kNear); |
| 1702 | |
| 1703 | // Check for negative zero result. If product is zero, and one |
| 1704 | // argument is negative, go to slow case. |
| 1705 | Label correct_result; |
| 1706 | testq(dst, dst); |
| 1707 | j(not_zero, &correct_result, Label::kNear); |
| 1708 | |
| 1709 | movq(dst, kScratchRegister); |
| 1710 | xor_(dst, src2); |
| 1711 | // Result was positive zero. |
| 1712 | j(positive, &zero_correct_result, Label::kNear); |
| 1713 | |
| 1714 | bind(&failure); // Reused failure exit, restores src1. |
| 1715 | movq(src1, kScratchRegister); |
| 1716 | jmp(on_not_smi_result, near_jump); |
| 1717 | |
| 1718 | bind(&zero_correct_result); |
| 1719 | Set(dst, 0); |
| 1720 | |
| 1721 | bind(&correct_result); |
| 1722 | } else { |
| 1723 | SmiToInteger64(dst, src1); |
| 1724 | imul(dst, src2); |
| 1725 | j(overflow, on_not_smi_result, near_jump); |
| 1726 | // Check for negative zero result. If product is zero, and one |
| 1727 | // argument is negative, go to slow case. |
| 1728 | Label correct_result; |
| 1729 | testq(dst, dst); |
| 1730 | j(not_zero, &correct_result, Label::kNear); |
| 1731 | // One of src1 and src2 is zero, the check whether the other is |
| 1732 | // negative. |
| 1733 | movq(kScratchRegister, src1); |
| 1734 | xor_(kScratchRegister, src2); |
| 1735 | j(negative, on_not_smi_result, near_jump); |
| 1736 | bind(&correct_result); |
| 1737 | } |
| 1738 | } |
| 1739 | |
| 1740 | |
| 1741 | void MacroAssembler::SmiDiv(Register dst, |
| 1742 | Register src1, |
| 1743 | Register src2, |
| 1744 | Label* on_not_smi_result, |
| 1745 | Label::Distance near_jump) { |
| 1746 | ASSERT(!src1.is(kScratchRegister)); |
| 1747 | ASSERT(!src2.is(kScratchRegister)); |
| 1748 | ASSERT(!dst.is(kScratchRegister)); |
| 1749 | ASSERT(!src2.is(rax)); |
| 1750 | ASSERT(!src2.is(rdx)); |
| 1751 | ASSERT(!src1.is(rdx)); |
| 1752 | |
| 1753 | // Check for 0 divisor (result is +/-Infinity). |
| 1754 | testq(src2, src2); |
| 1755 | j(zero, on_not_smi_result, near_jump); |
| 1756 | |
| 1757 | if (src1.is(rax)) { |
| 1758 | movq(kScratchRegister, src1); |
| 1759 | } |
| 1760 | SmiToInteger32(rax, src1); |
| 1761 | // We need to rule out dividing Smi::kMinValue by -1, since that would |
| 1762 | // overflow in idiv and raise an exception. |
| 1763 | // We combine this with negative zero test (negative zero only happens |
| 1764 | // when dividing zero by a negative number). |
| 1765 | |
| 1766 | // We overshoot a little and go to slow case if we divide min-value |
| 1767 | // by any negative value, not just -1. |
| 1768 | Label safe_div; |
| 1769 | testl(rax, Immediate(0x7fffffff)); |
| 1770 | j(not_zero, &safe_div, Label::kNear); |
| 1771 | testq(src2, src2); |
| 1772 | if (src1.is(rax)) { |
| 1773 | j(positive, &safe_div, Label::kNear); |
| 1774 | movq(src1, kScratchRegister); |
| 1775 | jmp(on_not_smi_result, near_jump); |
| 1776 | } else { |
| 1777 | j(negative, on_not_smi_result, near_jump); |
| 1778 | } |
| 1779 | bind(&safe_div); |
| 1780 | |
| 1781 | SmiToInteger32(src2, src2); |
| 1782 | // Sign extend src1 into edx:eax. |
| 1783 | cdq(); |
| 1784 | idivl(src2); |
| 1785 | Integer32ToSmi(src2, src2); |
| 1786 | // Check that the remainder is zero. |
| 1787 | testl(rdx, rdx); |
| 1788 | if (src1.is(rax)) { |
| 1789 | Label smi_result; |
| 1790 | j(zero, &smi_result, Label::kNear); |
| 1791 | movq(src1, kScratchRegister); |
| 1792 | jmp(on_not_smi_result, near_jump); |
| 1793 | bind(&smi_result); |
| 1794 | } else { |
| 1795 | j(not_zero, on_not_smi_result, near_jump); |
| 1796 | } |
| 1797 | if (!dst.is(src1) && src1.is(rax)) { |
| 1798 | movq(src1, kScratchRegister); |
| 1799 | } |
| 1800 | Integer32ToSmi(dst, rax); |
| 1801 | } |
| 1802 | |
| 1803 | |
| 1804 | void MacroAssembler::SmiMod(Register dst, |
| 1805 | Register src1, |
| 1806 | Register src2, |
| 1807 | Label* on_not_smi_result, |
| 1808 | Label::Distance near_jump) { |
| 1809 | ASSERT(!dst.is(kScratchRegister)); |
| 1810 | ASSERT(!src1.is(kScratchRegister)); |
| 1811 | ASSERT(!src2.is(kScratchRegister)); |
| 1812 | ASSERT(!src2.is(rax)); |
| 1813 | ASSERT(!src2.is(rdx)); |
| 1814 | ASSERT(!src1.is(rdx)); |
| 1815 | ASSERT(!src1.is(src2)); |
| 1816 | |
| 1817 | testq(src2, src2); |
| 1818 | j(zero, on_not_smi_result, near_jump); |
| 1819 | |
| 1820 | if (src1.is(rax)) { |
| 1821 | movq(kScratchRegister, src1); |
| 1822 | } |
| 1823 | SmiToInteger32(rax, src1); |
| 1824 | SmiToInteger32(src2, src2); |
| 1825 | |
| 1826 | // Test for the edge case of dividing Smi::kMinValue by -1 (will overflow). |
| 1827 | Label safe_div; |
| 1828 | cmpl(rax, Immediate(Smi::kMinValue)); |
| 1829 | j(not_equal, &safe_div, Label::kNear); |
| 1830 | cmpl(src2, Immediate(-1)); |
| 1831 | j(not_equal, &safe_div, Label::kNear); |
| 1832 | // Retag inputs and go slow case. |
| 1833 | Integer32ToSmi(src2, src2); |
| 1834 | if (src1.is(rax)) { |
| 1835 | movq(src1, kScratchRegister); |
| 1836 | } |
| 1837 | jmp(on_not_smi_result, near_jump); |
| 1838 | bind(&safe_div); |
| 1839 | |
| 1840 | // Sign extend eax into edx:eax. |
| 1841 | cdq(); |
| 1842 | idivl(src2); |
| 1843 | // Restore smi tags on inputs. |
| 1844 | Integer32ToSmi(src2, src2); |
| 1845 | if (src1.is(rax)) { |
| 1846 | movq(src1, kScratchRegister); |
| 1847 | } |
| 1848 | // Check for a negative zero result. If the result is zero, and the |
| 1849 | // dividend is negative, go slow to return a floating point negative zero. |
| 1850 | Label smi_result; |
| 1851 | testl(rdx, rdx); |
| 1852 | j(not_zero, &smi_result, Label::kNear); |
| 1853 | testq(src1, src1); |
| 1854 | j(negative, on_not_smi_result, near_jump); |
| 1855 | bind(&smi_result); |
| 1856 | Integer32ToSmi(dst, rdx); |
| 1857 | } |
| 1858 | |
| 1859 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1860 | void MacroAssembler::SmiNot(Register dst, Register src) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1861 | ASSERT(!dst.is(kScratchRegister)); |
| 1862 | ASSERT(!src.is(kScratchRegister)); |
| 1863 | // Set tag and padding bits before negating, so that they are zero afterwards. |
| 1864 | movl(kScratchRegister, Immediate(~0)); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1865 | if (dst.is(src)) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1866 | xor_(dst, kScratchRegister); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1867 | } else { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1868 | lea(dst, Operand(src, kScratchRegister, times_1, 0)); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1869 | } |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1870 | not_(dst); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1871 | } |
| 1872 | |
| 1873 | |
| 1874 | void MacroAssembler::SmiAnd(Register dst, Register src1, Register src2) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1875 | ASSERT(!dst.is(src2)); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1876 | if (!dst.is(src1)) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1877 | movq(dst, src1); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1878 | } |
| 1879 | and_(dst, src2); |
| 1880 | } |
| 1881 | |
| 1882 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1883 | void MacroAssembler::SmiAndConstant(Register dst, Register src, Smi* constant) { |
| 1884 | if (constant->value() == 0) { |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 1885 | Set(dst, 0); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1886 | } else if (dst.is(src)) { |
| 1887 | ASSERT(!dst.is(kScratchRegister)); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1888 | Register constant_reg = GetSmiConstant(constant); |
| 1889 | and_(dst, constant_reg); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1890 | } else { |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1891 | LoadSmiConstant(dst, constant); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1892 | and_(dst, src); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1893 | } |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1894 | } |
| 1895 | |
| 1896 | |
| 1897 | void MacroAssembler::SmiOr(Register dst, Register src1, Register src2) { |
| 1898 | if (!dst.is(src1)) { |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1899 | ASSERT(!src1.is(src2)); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1900 | movq(dst, src1); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1901 | } |
| 1902 | or_(dst, src2); |
| 1903 | } |
| 1904 | |
| 1905 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1906 | void MacroAssembler::SmiOrConstant(Register dst, Register src, Smi* constant) { |
| 1907 | if (dst.is(src)) { |
| 1908 | ASSERT(!dst.is(kScratchRegister)); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1909 | Register constant_reg = GetSmiConstant(constant); |
| 1910 | or_(dst, constant_reg); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1911 | } else { |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1912 | LoadSmiConstant(dst, constant); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1913 | or_(dst, src); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1914 | } |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1915 | } |
| 1916 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1917 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1918 | void MacroAssembler::SmiXor(Register dst, Register src1, Register src2) { |
| 1919 | if (!dst.is(src1)) { |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1920 | ASSERT(!src1.is(src2)); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1921 | movq(dst, src1); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1922 | } |
| 1923 | xor_(dst, src2); |
| 1924 | } |
| 1925 | |
| 1926 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1927 | void MacroAssembler::SmiXorConstant(Register dst, Register src, Smi* constant) { |
| 1928 | if (dst.is(src)) { |
| 1929 | ASSERT(!dst.is(kScratchRegister)); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1930 | Register constant_reg = GetSmiConstant(constant); |
| 1931 | xor_(dst, constant_reg); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1932 | } else { |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1933 | LoadSmiConstant(dst, constant); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1934 | xor_(dst, src); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1935 | } |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1936 | } |
| 1937 | |
| 1938 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1939 | void MacroAssembler::SmiShiftArithmeticRightConstant(Register dst, |
| 1940 | Register src, |
| 1941 | int shift_value) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1942 | ASSERT(is_uint5(shift_value)); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1943 | if (shift_value > 0) { |
| 1944 | if (dst.is(src)) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1945 | sar(dst, Immediate(shift_value + kSmiShift)); |
| 1946 | shl(dst, Immediate(kSmiShift)); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1947 | } else { |
| 1948 | UNIMPLEMENTED(); // Not used. |
| 1949 | } |
| 1950 | } |
| 1951 | } |
| 1952 | |
| 1953 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1954 | void MacroAssembler::SmiShiftLeftConstant(Register dst, |
| 1955 | Register src, |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1956 | int shift_value) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1957 | if (!dst.is(src)) { |
| 1958 | movq(dst, src); |
| 1959 | } |
| 1960 | if (shift_value > 0) { |
| 1961 | shl(dst, Immediate(shift_value)); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1962 | } |
| 1963 | } |
| 1964 | |
| 1965 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1966 | void MacroAssembler::SmiShiftLogicalRightConstant( |
| 1967 | Register dst, Register src, int shift_value, |
| 1968 | Label* on_not_smi_result, Label::Distance near_jump) { |
| 1969 | // Logic right shift interprets its result as an *unsigned* number. |
| 1970 | if (dst.is(src)) { |
| 1971 | UNIMPLEMENTED(); // Not used. |
| 1972 | } else { |
| 1973 | movq(dst, src); |
| 1974 | if (shift_value == 0) { |
| 1975 | testq(dst, dst); |
| 1976 | j(negative, on_not_smi_result, near_jump); |
| 1977 | } |
| 1978 | shr(dst, Immediate(shift_value + kSmiShift)); |
| 1979 | shl(dst, Immediate(kSmiShift)); |
| 1980 | } |
| 1981 | } |
| 1982 | |
| 1983 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1984 | void MacroAssembler::SmiShiftLeft(Register dst, |
| 1985 | Register src1, |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1986 | Register src2) { |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1987 | ASSERT(!dst.is(rcx)); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1988 | // Untag shift amount. |
| 1989 | if (!dst.is(src1)) { |
| 1990 | movq(dst, src1); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1991 | } |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1992 | SmiToInteger32(rcx, src2); |
| 1993 | // Shift amount specified by lower 5 bits, not six as the shl opcode. |
| 1994 | and_(rcx, Immediate(0x1f)); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1995 | shl_cl(dst); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1996 | } |
| 1997 | |
| 1998 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1999 | void MacroAssembler::SmiShiftLogicalRight(Register dst, |
| 2000 | Register src1, |
| 2001 | Register src2, |
| 2002 | Label* on_not_smi_result, |
| 2003 | Label::Distance near_jump) { |
| 2004 | ASSERT(!dst.is(kScratchRegister)); |
| 2005 | ASSERT(!src1.is(kScratchRegister)); |
| 2006 | ASSERT(!src2.is(kScratchRegister)); |
| 2007 | ASSERT(!dst.is(rcx)); |
| 2008 | // dst and src1 can be the same, because the one case that bails out |
| 2009 | // is a shift by 0, which leaves dst, and therefore src1, unchanged. |
| 2010 | if (src1.is(rcx) || src2.is(rcx)) { |
| 2011 | movq(kScratchRegister, rcx); |
| 2012 | } |
| 2013 | if (!dst.is(src1)) { |
| 2014 | movq(dst, src1); |
| 2015 | } |
| 2016 | SmiToInteger32(rcx, src2); |
| 2017 | orl(rcx, Immediate(kSmiShift)); |
| 2018 | shr_cl(dst); // Shift is rcx modulo 0x1f + 32. |
| 2019 | shl(dst, Immediate(kSmiShift)); |
| 2020 | testq(dst, dst); |
| 2021 | if (src1.is(rcx) || src2.is(rcx)) { |
| 2022 | Label positive_result; |
| 2023 | j(positive, &positive_result, Label::kNear); |
| 2024 | if (src1.is(rcx)) { |
| 2025 | movq(src1, kScratchRegister); |
| 2026 | } else { |
| 2027 | movq(src2, kScratchRegister); |
| 2028 | } |
| 2029 | jmp(on_not_smi_result, near_jump); |
| 2030 | bind(&positive_result); |
| 2031 | } else { |
| 2032 | // src2 was zero and src1 negative. |
| 2033 | j(negative, on_not_smi_result, near_jump); |
| 2034 | } |
| 2035 | } |
| 2036 | |
| 2037 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 2038 | void MacroAssembler::SmiShiftArithmeticRight(Register dst, |
| 2039 | Register src1, |
| 2040 | Register src2) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2041 | ASSERT(!dst.is(kScratchRegister)); |
| 2042 | ASSERT(!src1.is(kScratchRegister)); |
| 2043 | ASSERT(!src2.is(kScratchRegister)); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 2044 | ASSERT(!dst.is(rcx)); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2045 | if (src1.is(rcx)) { |
| 2046 | movq(kScratchRegister, src1); |
| 2047 | } else if (src2.is(rcx)) { |
| 2048 | movq(kScratchRegister, src2); |
| 2049 | } |
| 2050 | if (!dst.is(src1)) { |
| 2051 | movq(dst, src1); |
| 2052 | } |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 2053 | SmiToInteger32(rcx, src2); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2054 | orl(rcx, Immediate(kSmiShift)); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 2055 | sar_cl(dst); // Shift 32 + original rcx & 0x1f. |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2056 | shl(dst, Immediate(kSmiShift)); |
| 2057 | if (src1.is(rcx)) { |
| 2058 | movq(src1, kScratchRegister); |
| 2059 | } else if (src2.is(rcx)) { |
| 2060 | movq(src2, kScratchRegister); |
| 2061 | } |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 2062 | } |
| 2063 | |
| 2064 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2065 | void MacroAssembler::SelectNonSmi(Register dst, |
| 2066 | Register src1, |
| 2067 | Register src2, |
| 2068 | Label* on_not_smis, |
| 2069 | Label::Distance near_jump) { |
| 2070 | ASSERT(!dst.is(kScratchRegister)); |
| 2071 | ASSERT(!src1.is(kScratchRegister)); |
| 2072 | ASSERT(!src2.is(kScratchRegister)); |
| 2073 | ASSERT(!dst.is(src1)); |
| 2074 | ASSERT(!dst.is(src2)); |
| 2075 | // Both operands must not be smis. |
| 2076 | #ifdef DEBUG |
| 2077 | if (allow_stub_calls()) { // Check contains a stub call. |
| 2078 | Condition not_both_smis = NegateCondition(CheckBothSmi(src1, src2)); |
| 2079 | Check(not_both_smis, "Both registers were smis in SelectNonSmi."); |
| 2080 | } |
| 2081 | #endif |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 2082 | STATIC_ASSERT(kSmiTag == 0); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2083 | ASSERT_EQ(0, Smi::FromInt(0)); |
| 2084 | movl(kScratchRegister, Immediate(kSmiTagMask)); |
| 2085 | and_(kScratchRegister, src1); |
| 2086 | testl(kScratchRegister, src2); |
| 2087 | // If non-zero then both are smis. |
| 2088 | j(not_zero, on_not_smis, near_jump); |
| 2089 | |
| 2090 | // Exactly one operand is a smi. |
| 2091 | ASSERT_EQ(1, static_cast<int>(kSmiTagMask)); |
| 2092 | // kScratchRegister still holds src1 & kSmiTag, which is either zero or one. |
| 2093 | subq(kScratchRegister, Immediate(1)); |
| 2094 | // If src1 is a smi, then scratch register all 1s, else it is all 0s. |
| 2095 | movq(dst, src1); |
| 2096 | xor_(dst, src2); |
| 2097 | and_(dst, kScratchRegister); |
| 2098 | // If src1 is a smi, dst holds src1 ^ src2, else it is zero. |
| 2099 | xor_(dst, src1); |
| 2100 | // If src1 is a smi, dst is src2, else it is src1, i.e., the non-smi. |
| 2101 | } |
| 2102 | |
| 2103 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2104 | SmiIndex MacroAssembler::SmiToIndex(Register dst, |
| 2105 | Register src, |
| 2106 | int shift) { |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 2107 | ASSERT(is_uint6(shift)); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2108 | // There is a possible optimization if shift is in the range 60-63, but that |
| 2109 | // will (and must) never happen. |
| 2110 | if (!dst.is(src)) { |
| 2111 | movq(dst, src); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 2112 | } |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2113 | if (shift < kSmiShift) { |
| 2114 | sar(dst, Immediate(kSmiShift - shift)); |
| 2115 | } else { |
| 2116 | shl(dst, Immediate(shift - kSmiShift)); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 2117 | } |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 2118 | return SmiIndex(dst, times_1); |
| 2119 | } |
| 2120 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 2121 | SmiIndex MacroAssembler::SmiToNegativeIndex(Register dst, |
| 2122 | Register src, |
| 2123 | int shift) { |
| 2124 | // Register src holds a positive smi. |
| 2125 | ASSERT(is_uint6(shift)); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2126 | if (!dst.is(src)) { |
| 2127 | movq(dst, src); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 2128 | } |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 2129 | neg(dst); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2130 | if (shift < kSmiShift) { |
| 2131 | sar(dst, Immediate(kSmiShift - shift)); |
| 2132 | } else { |
| 2133 | shl(dst, Immediate(shift - kSmiShift)); |
| 2134 | } |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 2135 | return SmiIndex(dst, times_1); |
| 2136 | } |
| 2137 | |
| 2138 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2139 | void MacroAssembler::AddSmiField(Register dst, const Operand& src) { |
| 2140 | ASSERT_EQ(0, kSmiShift % kBitsPerByte); |
| 2141 | addl(dst, Operand(src, kSmiShift / kBitsPerByte)); |
| 2142 | } |
| 2143 | |
| 2144 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2145 | void MacroAssembler::JumpIfNotString(Register object, |
| 2146 | Register object_map, |
| 2147 | Label* not_string, |
| 2148 | Label::Distance near_jump) { |
| 2149 | Condition is_smi = CheckSmi(object); |
| 2150 | j(is_smi, not_string, near_jump); |
| 2151 | CmpObjectType(object, FIRST_NONSTRING_TYPE, object_map); |
| 2152 | j(above_equal, not_string, near_jump); |
| 2153 | } |
| 2154 | |
| 2155 | |
| 2156 | void MacroAssembler::JumpIfNotBothSequentialAsciiStrings( |
| 2157 | Register first_object, |
| 2158 | Register second_object, |
| 2159 | Register scratch1, |
| 2160 | Register scratch2, |
| 2161 | Label* on_fail, |
| 2162 | Label::Distance near_jump) { |
| 2163 | // Check that both objects are not smis. |
| 2164 | Condition either_smi = CheckEitherSmi(first_object, second_object); |
| 2165 | j(either_smi, on_fail, near_jump); |
| 2166 | |
| 2167 | // Load instance type for both strings. |
| 2168 | movq(scratch1, FieldOperand(first_object, HeapObject::kMapOffset)); |
| 2169 | movq(scratch2, FieldOperand(second_object, HeapObject::kMapOffset)); |
| 2170 | movzxbl(scratch1, FieldOperand(scratch1, Map::kInstanceTypeOffset)); |
| 2171 | movzxbl(scratch2, FieldOperand(scratch2, Map::kInstanceTypeOffset)); |
| 2172 | |
| 2173 | // Check that both are flat ascii strings. |
| 2174 | ASSERT(kNotStringTag != 0); |
| 2175 | const int kFlatAsciiStringMask = |
| 2176 | kIsNotStringMask | kStringRepresentationMask | kStringEncodingMask; |
| 2177 | const int kFlatAsciiStringTag = ASCII_STRING_TYPE; |
| 2178 | |
| 2179 | andl(scratch1, Immediate(kFlatAsciiStringMask)); |
| 2180 | andl(scratch2, Immediate(kFlatAsciiStringMask)); |
| 2181 | // Interleave the bits to check both scratch1 and scratch2 in one test. |
| 2182 | ASSERT_EQ(0, kFlatAsciiStringMask & (kFlatAsciiStringMask << 3)); |
| 2183 | lea(scratch1, Operand(scratch1, scratch2, times_8, 0)); |
| 2184 | cmpl(scratch1, |
| 2185 | Immediate(kFlatAsciiStringTag + (kFlatAsciiStringTag << 3))); |
| 2186 | j(not_equal, on_fail, near_jump); |
| 2187 | } |
| 2188 | |
| 2189 | |
| 2190 | void MacroAssembler::JumpIfInstanceTypeIsNotSequentialAscii( |
| 2191 | Register instance_type, |
| 2192 | Register scratch, |
| 2193 | Label* failure, |
| 2194 | Label::Distance near_jump) { |
| 2195 | if (!scratch.is(instance_type)) { |
| 2196 | movl(scratch, instance_type); |
| 2197 | } |
| 2198 | |
| 2199 | const int kFlatAsciiStringMask = |
| 2200 | kIsNotStringMask | kStringRepresentationMask | kStringEncodingMask; |
| 2201 | |
| 2202 | andl(scratch, Immediate(kFlatAsciiStringMask)); |
| 2203 | cmpl(scratch, Immediate(kStringTag | kSeqStringTag | kAsciiStringTag)); |
| 2204 | j(not_equal, failure, near_jump); |
| 2205 | } |
| 2206 | |
| 2207 | |
| 2208 | void MacroAssembler::JumpIfBothInstanceTypesAreNotSequentialAscii( |
| 2209 | Register first_object_instance_type, |
| 2210 | Register second_object_instance_type, |
| 2211 | Register scratch1, |
| 2212 | Register scratch2, |
| 2213 | Label* on_fail, |
| 2214 | Label::Distance near_jump) { |
| 2215 | // Load instance type for both strings. |
| 2216 | movq(scratch1, first_object_instance_type); |
| 2217 | movq(scratch2, second_object_instance_type); |
| 2218 | |
| 2219 | // Check that both are flat ascii strings. |
| 2220 | ASSERT(kNotStringTag != 0); |
| 2221 | const int kFlatAsciiStringMask = |
| 2222 | kIsNotStringMask | kStringRepresentationMask | kStringEncodingMask; |
| 2223 | const int kFlatAsciiStringTag = ASCII_STRING_TYPE; |
| 2224 | |
| 2225 | andl(scratch1, Immediate(kFlatAsciiStringMask)); |
| 2226 | andl(scratch2, Immediate(kFlatAsciiStringMask)); |
| 2227 | // Interleave the bits to check both scratch1 and scratch2 in one test. |
| 2228 | ASSERT_EQ(0, kFlatAsciiStringMask & (kFlatAsciiStringMask << 3)); |
| 2229 | lea(scratch1, Operand(scratch1, scratch2, times_8, 0)); |
| 2230 | cmpl(scratch1, |
| 2231 | Immediate(kFlatAsciiStringTag + (kFlatAsciiStringTag << 3))); |
| 2232 | j(not_equal, on_fail, near_jump); |
| 2233 | } |
| 2234 | |
| 2235 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2236 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2237 | void MacroAssembler::Move(Register dst, Register src) { |
| 2238 | if (!dst.is(src)) { |
| 2239 | movq(dst, src); |
| 2240 | } |
| 2241 | } |
| 2242 | |
| 2243 | |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 2244 | void MacroAssembler::Move(Register dst, Handle<Object> source) { |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 2245 | ASSERT(!source->IsFailure()); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 2246 | if (source->IsSmi()) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2247 | Move(dst, Smi::cast(*source)); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 2248 | } else { |
| 2249 | movq(dst, source, RelocInfo::EMBEDDED_OBJECT); |
| 2250 | } |
| 2251 | } |
| 2252 | |
| 2253 | |
| 2254 | void MacroAssembler::Move(const Operand& dst, Handle<Object> source) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2255 | ASSERT(!source->IsFailure()); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 2256 | if (source->IsSmi()) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2257 | Move(dst, Smi::cast(*source)); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 2258 | } else { |
| 2259 | movq(kScratchRegister, source, RelocInfo::EMBEDDED_OBJECT); |
| 2260 | movq(dst, kScratchRegister); |
| 2261 | } |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 2262 | } |
| 2263 | |
| 2264 | |
| 2265 | void MacroAssembler::Cmp(Register dst, Handle<Object> source) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2266 | if (source->IsSmi()) { |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 2267 | Cmp(dst, Smi::cast(*source)); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2268 | } else { |
| 2269 | Move(kScratchRegister, source); |
| 2270 | cmpq(dst, kScratchRegister); |
| 2271 | } |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 2272 | } |
| 2273 | |
| 2274 | |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 2275 | void MacroAssembler::Cmp(const Operand& dst, Handle<Object> source) { |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 2276 | if (source->IsSmi()) { |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 2277 | Cmp(dst, Smi::cast(*source)); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 2278 | } else { |
| 2279 | ASSERT(source->IsHeapObject()); |
| 2280 | movq(kScratchRegister, source, RelocInfo::EMBEDDED_OBJECT); |
| 2281 | cmpq(dst, kScratchRegister); |
| 2282 | } |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 2283 | } |
| 2284 | |
| 2285 | |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 2286 | void MacroAssembler::Push(Handle<Object> source) { |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 2287 | if (source->IsSmi()) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2288 | Push(Smi::cast(*source)); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 2289 | } else { |
| 2290 | ASSERT(source->IsHeapObject()); |
| 2291 | movq(kScratchRegister, source, RelocInfo::EMBEDDED_OBJECT); |
| 2292 | push(kScratchRegister); |
| 2293 | } |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 2294 | } |
| 2295 | |
| 2296 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2297 | void MacroAssembler::Push(Smi* source) { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2298 | intptr_t smi = reinterpret_cast<intptr_t>(source); |
| 2299 | if (is_int32(smi)) { |
| 2300 | push(Immediate(static_cast<int32_t>(smi))); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2301 | } else { |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 2302 | Register constant = GetSmiConstant(source); |
| 2303 | push(constant); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2304 | } |
| 2305 | } |
| 2306 | |
| 2307 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 2308 | void MacroAssembler::Drop(int stack_elements) { |
| 2309 | if (stack_elements > 0) { |
| 2310 | addq(rsp, Immediate(stack_elements * kPointerSize)); |
| 2311 | } |
| 2312 | } |
| 2313 | |
| 2314 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2315 | void MacroAssembler::Test(const Operand& src, Smi* source) { |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2316 | testl(Operand(src, kIntSize), Immediate(source->value())); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2317 | } |
| 2318 | |
| 2319 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2320 | void MacroAssembler::Jump(ExternalReference ext) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2321 | LoadAddress(kScratchRegister, ext); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2322 | jmp(kScratchRegister); |
| 2323 | } |
| 2324 | |
| 2325 | |
| 2326 | void MacroAssembler::Jump(Address destination, RelocInfo::Mode rmode) { |
| 2327 | movq(kScratchRegister, destination, rmode); |
| 2328 | jmp(kScratchRegister); |
| 2329 | } |
| 2330 | |
| 2331 | |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 2332 | void MacroAssembler::Jump(Handle<Code> code_object, RelocInfo::Mode rmode) { |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 2333 | // TODO(X64): Inline this |
| 2334 | jmp(code_object, rmode); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 2335 | } |
| 2336 | |
| 2337 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2338 | int MacroAssembler::CallSize(ExternalReference ext) { |
| 2339 | // Opcode for call kScratchRegister is: Rex.B FF D4 (three bytes). |
| 2340 | const int kCallInstructionSize = 3; |
| 2341 | return LoadAddressSize(ext) + kCallInstructionSize; |
| 2342 | } |
| 2343 | |
| 2344 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2345 | void MacroAssembler::Call(ExternalReference ext) { |
ricow@chromium.org | eb96f4f | 2011-03-09 13:41:48 +0000 | [diff] [blame] | 2346 | #ifdef DEBUG |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2347 | int end_position = pc_offset() + CallSize(ext); |
ricow@chromium.org | eb96f4f | 2011-03-09 13:41:48 +0000 | [diff] [blame] | 2348 | #endif |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2349 | LoadAddress(kScratchRegister, ext); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2350 | call(kScratchRegister); |
ricow@chromium.org | eb96f4f | 2011-03-09 13:41:48 +0000 | [diff] [blame] | 2351 | #ifdef DEBUG |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2352 | CHECK_EQ(end_position, pc_offset()); |
ricow@chromium.org | eb96f4f | 2011-03-09 13:41:48 +0000 | [diff] [blame] | 2353 | #endif |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2354 | } |
| 2355 | |
| 2356 | |
| 2357 | void MacroAssembler::Call(Address destination, RelocInfo::Mode rmode) { |
ricow@chromium.org | eb96f4f | 2011-03-09 13:41:48 +0000 | [diff] [blame] | 2358 | #ifdef DEBUG |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2359 | int end_position = pc_offset() + CallSize(destination, rmode); |
ricow@chromium.org | eb96f4f | 2011-03-09 13:41:48 +0000 | [diff] [blame] | 2360 | #endif |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2361 | movq(kScratchRegister, destination, rmode); |
| 2362 | call(kScratchRegister); |
ricow@chromium.org | eb96f4f | 2011-03-09 13:41:48 +0000 | [diff] [blame] | 2363 | #ifdef DEBUG |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2364 | CHECK_EQ(pc_offset(), end_position); |
ricow@chromium.org | eb96f4f | 2011-03-09 13:41:48 +0000 | [diff] [blame] | 2365 | #endif |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2366 | } |
| 2367 | |
| 2368 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2369 | void MacroAssembler::Call(Handle<Code> code_object, |
| 2370 | RelocInfo::Mode rmode, |
| 2371 | unsigned ast_id) { |
ricow@chromium.org | eb96f4f | 2011-03-09 13:41:48 +0000 | [diff] [blame] | 2372 | #ifdef DEBUG |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2373 | int end_position = pc_offset() + CallSize(code_object); |
ricow@chromium.org | eb96f4f | 2011-03-09 13:41:48 +0000 | [diff] [blame] | 2374 | #endif |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 2375 | ASSERT(RelocInfo::IsCodeTarget(rmode)); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2376 | call(code_object, rmode, ast_id); |
ricow@chromium.org | eb96f4f | 2011-03-09 13:41:48 +0000 | [diff] [blame] | 2377 | #ifdef DEBUG |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2378 | CHECK_EQ(end_position, pc_offset()); |
ricow@chromium.org | eb96f4f | 2011-03-09 13:41:48 +0000 | [diff] [blame] | 2379 | #endif |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 2380 | } |
| 2381 | |
| 2382 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2383 | void MacroAssembler::Pushad() { |
| 2384 | push(rax); |
| 2385 | push(rcx); |
| 2386 | push(rdx); |
| 2387 | push(rbx); |
| 2388 | // Not pushing rsp or rbp. |
| 2389 | push(rsi); |
| 2390 | push(rdi); |
| 2391 | push(r8); |
| 2392 | push(r9); |
| 2393 | // r10 is kScratchRegister. |
| 2394 | push(r11); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 2395 | // r12 is kSmiConstantRegister. |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2396 | // r13 is kRootRegister. |
| 2397 | push(r14); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 2398 | push(r15); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 2399 | STATIC_ASSERT(11 == kNumSafepointSavedRegisters); |
| 2400 | // Use lea for symmetry with Popad. |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2401 | int sp_delta = |
| 2402 | (kNumSafepointRegisters - kNumSafepointSavedRegisters) * kPointerSize; |
| 2403 | lea(rsp, Operand(rsp, -sp_delta)); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2404 | } |
| 2405 | |
| 2406 | |
| 2407 | void MacroAssembler::Popad() { |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 2408 | // Popad must not change the flags, so use lea instead of addq. |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2409 | int sp_delta = |
| 2410 | (kNumSafepointRegisters - kNumSafepointSavedRegisters) * kPointerSize; |
| 2411 | lea(rsp, Operand(rsp, sp_delta)); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 2412 | pop(r15); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2413 | pop(r14); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2414 | pop(r11); |
| 2415 | pop(r9); |
| 2416 | pop(r8); |
| 2417 | pop(rdi); |
| 2418 | pop(rsi); |
| 2419 | pop(rbx); |
| 2420 | pop(rdx); |
| 2421 | pop(rcx); |
| 2422 | pop(rax); |
| 2423 | } |
| 2424 | |
| 2425 | |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2426 | void MacroAssembler::Dropad() { |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 2427 | addq(rsp, Immediate(kNumSafepointRegisters * kPointerSize)); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2428 | } |
| 2429 | |
| 2430 | |
| 2431 | // Order general registers are pushed by Pushad: |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 2432 | // rax, rcx, rdx, rbx, rsi, rdi, r8, r9, r11, r14, r15. |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2433 | int MacroAssembler::kSafepointPushRegisterIndices[Register::kNumRegisters] = { |
| 2434 | 0, |
| 2435 | 1, |
| 2436 | 2, |
| 2437 | 3, |
| 2438 | -1, |
| 2439 | -1, |
| 2440 | 4, |
| 2441 | 5, |
| 2442 | 6, |
| 2443 | 7, |
| 2444 | -1, |
| 2445 | 8, |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2446 | -1, |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 2447 | -1, |
| 2448 | 9, |
| 2449 | 10 |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2450 | }; |
| 2451 | |
| 2452 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2453 | void MacroAssembler::StoreToSafepointRegisterSlot(Register dst, Register src) { |
| 2454 | movq(SafepointRegisterSlot(dst), src); |
| 2455 | } |
| 2456 | |
| 2457 | |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 2458 | void MacroAssembler::LoadFromSafepointRegisterSlot(Register dst, Register src) { |
| 2459 | movq(dst, SafepointRegisterSlot(src)); |
| 2460 | } |
| 2461 | |
| 2462 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2463 | Operand MacroAssembler::SafepointRegisterSlot(Register reg) { |
| 2464 | return Operand(rsp, SafepointRegisterStackIndex(reg.code()) * kPointerSize); |
| 2465 | } |
| 2466 | |
| 2467 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2468 | void MacroAssembler::PushTryHandler(CodeLocation try_location, |
| 2469 | HandlerType type) { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2470 | // Adjust this code if not the case. |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 2471 | STATIC_ASSERT(StackHandlerConstants::kSize == 5 * kPointerSize); |
| 2472 | STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0 * kPointerSize); |
| 2473 | STATIC_ASSERT(StackHandlerConstants::kContextOffset == 1 * kPointerSize); |
| 2474 | STATIC_ASSERT(StackHandlerConstants::kFPOffset == 2 * kPointerSize); |
| 2475 | STATIC_ASSERT(StackHandlerConstants::kStateOffset == 3 * kPointerSize); |
| 2476 | STATIC_ASSERT(StackHandlerConstants::kPCOffset == 4 * kPointerSize); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2477 | |
| 2478 | // The pc (return address) is already on TOS. This code pushes state, |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 2479 | // frame pointer, context, and current handler. |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2480 | if (try_location == IN_JAVASCRIPT) { |
| 2481 | if (type == TRY_CATCH_HANDLER) { |
| 2482 | push(Immediate(StackHandler::TRY_CATCH)); |
| 2483 | } else { |
| 2484 | push(Immediate(StackHandler::TRY_FINALLY)); |
| 2485 | } |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2486 | push(rbp); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 2487 | push(rsi); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2488 | } else { |
| 2489 | ASSERT(try_location == IN_JS_ENTRY); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2490 | // The frame pointer does not point to a JS frame so we save NULL |
| 2491 | // for rbp. We expect the code throwing an exception to check rbp |
| 2492 | // before dereferencing it to restore the context. |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2493 | push(Immediate(StackHandler::ENTRY)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2494 | push(Immediate(0)); // NULL frame pointer. |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 2495 | Push(Smi::FromInt(0)); // No context. |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2496 | } |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2497 | // Save the current handler. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2498 | Operand handler_operand = |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 2499 | ExternalOperand(ExternalReference(Isolate::kHandlerAddress, isolate())); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2500 | push(handler_operand); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2501 | // Link this handler. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2502 | movq(handler_operand, rsp); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2503 | } |
| 2504 | |
| 2505 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 2506 | void MacroAssembler::PopTryHandler() { |
| 2507 | ASSERT_EQ(0, StackHandlerConstants::kNextOffset); |
| 2508 | // Unlink this handler. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2509 | Operand handler_operand = |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 2510 | ExternalOperand(ExternalReference(Isolate::kHandlerAddress, isolate())); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2511 | pop(handler_operand); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 2512 | // Remove the remaining fields. |
| 2513 | addq(rsp, Immediate(StackHandlerConstants::kSize - kPointerSize)); |
| 2514 | } |
| 2515 | |
| 2516 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 2517 | void MacroAssembler::Throw(Register value) { |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 2518 | // Adjust this code if not the case. |
| 2519 | STATIC_ASSERT(StackHandlerConstants::kSize == 5 * kPointerSize); |
| 2520 | STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0 * kPointerSize); |
| 2521 | STATIC_ASSERT(StackHandlerConstants::kContextOffset == 1 * kPointerSize); |
| 2522 | STATIC_ASSERT(StackHandlerConstants::kFPOffset == 2 * kPointerSize); |
| 2523 | STATIC_ASSERT(StackHandlerConstants::kStateOffset == 3 * kPointerSize); |
| 2524 | STATIC_ASSERT(StackHandlerConstants::kPCOffset == 4 * kPointerSize); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 2525 | // Keep thrown value in rax. |
| 2526 | if (!value.is(rax)) { |
| 2527 | movq(rax, value); |
| 2528 | } |
| 2529 | |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 2530 | ExternalReference handler_address(Isolate::kHandlerAddress, isolate()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2531 | Operand handler_operand = ExternalOperand(handler_address); |
| 2532 | movq(rsp, handler_operand); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 2533 | // get next in chain |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2534 | pop(handler_operand); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 2535 | pop(rsi); // Context. |
| 2536 | pop(rbp); // Frame pointer. |
| 2537 | pop(rdx); // State. |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 2538 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 2539 | // If the handler is a JS frame, restore the context to the frame. |
| 2540 | // (rdx == ENTRY) == (rbp == 0) == (rsi == 0), so we could test any |
| 2541 | // of them. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2542 | Label skip; |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 2543 | cmpq(rdx, Immediate(StackHandler::ENTRY)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2544 | j(equal, &skip, Label::kNear); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 2545 | movq(Operand(rbp, StandardFrameConstants::kContextOffset), rsi); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 2546 | bind(&skip); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 2547 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 2548 | ret(0); |
| 2549 | } |
| 2550 | |
| 2551 | |
| 2552 | void MacroAssembler::ThrowUncatchable(UncatchableExceptionType type, |
| 2553 | Register value) { |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 2554 | // Adjust this code if not the case. |
| 2555 | STATIC_ASSERT(StackHandlerConstants::kSize == 5 * kPointerSize); |
| 2556 | STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0 * kPointerSize); |
| 2557 | STATIC_ASSERT(StackHandlerConstants::kContextOffset == 1 * kPointerSize); |
| 2558 | STATIC_ASSERT(StackHandlerConstants::kFPOffset == 2 * kPointerSize); |
| 2559 | STATIC_ASSERT(StackHandlerConstants::kStateOffset == 3 * kPointerSize); |
| 2560 | STATIC_ASSERT(StackHandlerConstants::kPCOffset == 4 * kPointerSize); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 2561 | // Keep thrown value in rax. |
| 2562 | if (!value.is(rax)) { |
| 2563 | movq(rax, value); |
| 2564 | } |
| 2565 | // Fetch top stack handler. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 2566 | ExternalReference handler_address(Isolate::kHandlerAddress, isolate()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2567 | Load(rsp, handler_address); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 2568 | |
| 2569 | // Unwind the handlers until the ENTRY handler is found. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2570 | Label loop, done; |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 2571 | bind(&loop); |
| 2572 | // Load the type of the current stack handler. |
| 2573 | const int kStateOffset = StackHandlerConstants::kStateOffset; |
| 2574 | cmpq(Operand(rsp, kStateOffset), Immediate(StackHandler::ENTRY)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2575 | j(equal, &done, Label::kNear); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 2576 | // Fetch the next handler in the list. |
| 2577 | const int kNextOffset = StackHandlerConstants::kNextOffset; |
| 2578 | movq(rsp, Operand(rsp, kNextOffset)); |
| 2579 | jmp(&loop); |
| 2580 | bind(&done); |
| 2581 | |
| 2582 | // Set the top handler address to next handler past the current ENTRY handler. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2583 | Operand handler_operand = ExternalOperand(handler_address); |
| 2584 | pop(handler_operand); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 2585 | |
| 2586 | if (type == OUT_OF_MEMORY) { |
| 2587 | // Set external caught exception to false. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2588 | ExternalReference external_caught( |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 2589 | Isolate::kExternalCaughtExceptionAddress, isolate()); |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 2590 | Set(rax, static_cast<int64_t>(false)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2591 | Store(external_caught, rax); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 2592 | |
| 2593 | // Set pending exception and rax to out of memory exception. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 2594 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2595 | isolate()); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 2596 | movq(rax, Failure::OutOfMemoryException(), RelocInfo::NONE); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2597 | Store(pending_exception, rax); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 2598 | } |
| 2599 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 2600 | // Discard the context saved in the handler and clear the context pointer. |
| 2601 | pop(rdx); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 2602 | Set(rsi, 0); |
| 2603 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 2604 | pop(rbp); // Restore frame pointer. |
| 2605 | pop(rdx); // Discard state. |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 2606 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 2607 | ret(0); |
| 2608 | } |
| 2609 | |
| 2610 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2611 | void MacroAssembler::Ret() { |
| 2612 | ret(0); |
| 2613 | } |
| 2614 | |
| 2615 | |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 2616 | void MacroAssembler::Ret(int bytes_dropped, Register scratch) { |
| 2617 | if (is_uint16(bytes_dropped)) { |
| 2618 | ret(bytes_dropped); |
| 2619 | } else { |
| 2620 | pop(scratch); |
| 2621 | addq(rsp, Immediate(bytes_dropped)); |
| 2622 | push(scratch); |
| 2623 | ret(0); |
| 2624 | } |
| 2625 | } |
| 2626 | |
| 2627 | |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 2628 | void MacroAssembler::FCmp() { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2629 | fucomip(); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 2630 | fstp(0); |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 2631 | } |
| 2632 | |
| 2633 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2634 | void MacroAssembler::CmpObjectType(Register heap_object, |
| 2635 | InstanceType type, |
| 2636 | Register map) { |
| 2637 | movq(map, FieldOperand(heap_object, HeapObject::kMapOffset)); |
| 2638 | CmpInstanceType(map, type); |
| 2639 | } |
| 2640 | |
| 2641 | |
| 2642 | void MacroAssembler::CmpInstanceType(Register map, InstanceType type) { |
| 2643 | cmpb(FieldOperand(map, Map::kInstanceTypeOffset), |
| 2644 | Immediate(static_cast<int8_t>(type))); |
| 2645 | } |
| 2646 | |
| 2647 | |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 2648 | void MacroAssembler::CheckFastElements(Register map, |
| 2649 | Label* fail, |
| 2650 | Label::Distance distance) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2651 | STATIC_ASSERT(FAST_SMI_ONLY_ELEMENTS == 0); |
| 2652 | STATIC_ASSERT(FAST_ELEMENTS == 1); |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 2653 | cmpb(FieldOperand(map, Map::kBitField2Offset), |
| 2654 | Immediate(Map::kMaximumBitField2FastElementValue)); |
| 2655 | j(above, fail, distance); |
| 2656 | } |
| 2657 | |
| 2658 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2659 | void MacroAssembler::CheckFastObjectElements(Register map, |
| 2660 | Label* fail, |
| 2661 | Label::Distance distance) { |
| 2662 | STATIC_ASSERT(FAST_SMI_ONLY_ELEMENTS == 0); |
| 2663 | STATIC_ASSERT(FAST_ELEMENTS == 1); |
| 2664 | cmpb(FieldOperand(map, Map::kBitField2Offset), |
| 2665 | Immediate(Map::kMaximumBitField2FastSmiOnlyElementValue)); |
| 2666 | j(below_equal, fail, distance); |
| 2667 | cmpb(FieldOperand(map, Map::kBitField2Offset), |
| 2668 | Immediate(Map::kMaximumBitField2FastElementValue)); |
| 2669 | j(above, fail, distance); |
| 2670 | } |
| 2671 | |
| 2672 | |
| 2673 | void MacroAssembler::CheckFastSmiOnlyElements(Register map, |
| 2674 | Label* fail, |
| 2675 | Label::Distance distance) { |
| 2676 | STATIC_ASSERT(FAST_SMI_ONLY_ELEMENTS == 0); |
| 2677 | cmpb(FieldOperand(map, Map::kBitField2Offset), |
| 2678 | Immediate(Map::kMaximumBitField2FastSmiOnlyElementValue)); |
| 2679 | j(above, fail, distance); |
| 2680 | } |
| 2681 | |
| 2682 | |
| 2683 | void MacroAssembler::StoreNumberToDoubleElements( |
| 2684 | Register maybe_number, |
| 2685 | Register elements, |
| 2686 | Register key, |
| 2687 | XMMRegister xmm_scratch, |
| 2688 | Label* fail) { |
| 2689 | Label smi_value, is_nan, maybe_nan, not_nan, have_double_value, done; |
| 2690 | |
| 2691 | JumpIfSmi(maybe_number, &smi_value, Label::kNear); |
| 2692 | |
| 2693 | CheckMap(maybe_number, |
| 2694 | isolate()->factory()->heap_number_map(), |
| 2695 | fail, |
| 2696 | DONT_DO_SMI_CHECK); |
| 2697 | |
| 2698 | // Double value, canonicalize NaN. |
| 2699 | uint32_t offset = HeapNumber::kValueOffset + sizeof(kHoleNanLower32); |
| 2700 | cmpl(FieldOperand(maybe_number, offset), |
| 2701 | Immediate(kNaNOrInfinityLowerBoundUpper32)); |
| 2702 | j(greater_equal, &maybe_nan, Label::kNear); |
| 2703 | |
| 2704 | bind(¬_nan); |
| 2705 | movsd(xmm_scratch, FieldOperand(maybe_number, HeapNumber::kValueOffset)); |
| 2706 | bind(&have_double_value); |
| 2707 | movsd(FieldOperand(elements, key, times_8, FixedDoubleArray::kHeaderSize), |
| 2708 | xmm_scratch); |
| 2709 | jmp(&done); |
| 2710 | |
| 2711 | bind(&maybe_nan); |
| 2712 | // Could be NaN or Infinity. If fraction is not zero, it's NaN, otherwise |
| 2713 | // it's an Infinity, and the non-NaN code path applies. |
| 2714 | j(greater, &is_nan, Label::kNear); |
| 2715 | cmpl(FieldOperand(maybe_number, HeapNumber::kValueOffset), Immediate(0)); |
| 2716 | j(zero, ¬_nan); |
| 2717 | bind(&is_nan); |
| 2718 | // Convert all NaNs to the same canonical NaN value when they are stored in |
| 2719 | // the double array. |
| 2720 | Set(kScratchRegister, BitCast<uint64_t>( |
| 2721 | FixedDoubleArray::canonical_not_the_hole_nan_as_double())); |
| 2722 | movq(xmm_scratch, kScratchRegister); |
| 2723 | jmp(&have_double_value, Label::kNear); |
| 2724 | |
| 2725 | bind(&smi_value); |
| 2726 | // Value is a smi. convert to a double and store. |
| 2727 | // Preserve original value. |
| 2728 | SmiToInteger32(kScratchRegister, maybe_number); |
| 2729 | cvtlsi2sd(xmm_scratch, kScratchRegister); |
| 2730 | movsd(FieldOperand(elements, key, times_8, FixedDoubleArray::kHeaderSize), |
| 2731 | xmm_scratch); |
| 2732 | bind(&done); |
| 2733 | } |
| 2734 | |
| 2735 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2736 | void MacroAssembler::CheckMap(Register obj, |
| 2737 | Handle<Map> map, |
| 2738 | Label* fail, |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2739 | SmiCheckType smi_check_type) { |
| 2740 | if (smi_check_type == DO_SMI_CHECK) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2741 | JumpIfSmi(obj, fail); |
| 2742 | } |
| 2743 | Cmp(FieldOperand(obj, HeapObject::kMapOffset), map); |
| 2744 | j(not_equal, fail); |
| 2745 | } |
| 2746 | |
| 2747 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2748 | void MacroAssembler::ClampUint8(Register reg) { |
| 2749 | Label done; |
| 2750 | testl(reg, Immediate(0xFFFFFF00)); |
| 2751 | j(zero, &done, Label::kNear); |
| 2752 | setcc(negative, reg); // 1 if negative, 0 if positive. |
| 2753 | decb(reg); // 0 if negative, 255 if positive. |
| 2754 | bind(&done); |
| 2755 | } |
| 2756 | |
| 2757 | |
| 2758 | void MacroAssembler::ClampDoubleToUint8(XMMRegister input_reg, |
| 2759 | XMMRegister temp_xmm_reg, |
| 2760 | Register result_reg, |
| 2761 | Register temp_reg) { |
| 2762 | Label done; |
| 2763 | Set(result_reg, 0); |
| 2764 | xorps(temp_xmm_reg, temp_xmm_reg); |
| 2765 | ucomisd(input_reg, temp_xmm_reg); |
| 2766 | j(below, &done, Label::kNear); |
| 2767 | uint64_t one_half = BitCast<uint64_t, double>(0.5); |
| 2768 | Set(temp_reg, one_half); |
| 2769 | movq(temp_xmm_reg, temp_reg); |
| 2770 | addsd(temp_xmm_reg, input_reg); |
| 2771 | cvttsd2si(result_reg, temp_xmm_reg); |
| 2772 | testl(result_reg, Immediate(0xFFFFFF00)); |
| 2773 | j(zero, &done, Label::kNear); |
| 2774 | Set(result_reg, 255); |
| 2775 | bind(&done); |
| 2776 | } |
| 2777 | |
| 2778 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2779 | void MacroAssembler::LoadInstanceDescriptors(Register map, |
| 2780 | Register descriptors) { |
| 2781 | movq(descriptors, FieldOperand(map, |
| 2782 | Map::kInstanceDescriptorsOrBitField3Offset)); |
| 2783 | Label not_smi; |
| 2784 | JumpIfNotSmi(descriptors, ¬_smi, Label::kNear); |
| 2785 | Move(descriptors, isolate()->factory()->empty_descriptor_array()); |
| 2786 | bind(¬_smi); |
| 2787 | } |
| 2788 | |
| 2789 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 2790 | void MacroAssembler::DispatchMap(Register obj, |
| 2791 | Handle<Map> map, |
| 2792 | Handle<Code> success, |
| 2793 | SmiCheckType smi_check_type) { |
| 2794 | Label fail; |
| 2795 | if (smi_check_type == DO_SMI_CHECK) { |
| 2796 | JumpIfSmi(obj, &fail); |
| 2797 | } |
| 2798 | Cmp(FieldOperand(obj, HeapObject::kMapOffset), map); |
| 2799 | j(equal, success, RelocInfo::CODE_TARGET); |
| 2800 | |
| 2801 | bind(&fail); |
| 2802 | } |
| 2803 | |
| 2804 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2805 | void MacroAssembler::AbortIfNotNumber(Register object) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2806 | Label ok; |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2807 | Condition is_smi = CheckSmi(object); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2808 | j(is_smi, &ok, Label::kNear); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2809 | Cmp(FieldOperand(object, HeapObject::kMapOffset), |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 2810 | isolate()->factory()->heap_number_map()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2811 | Assert(equal, "Operand not a number"); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2812 | bind(&ok); |
| 2813 | } |
| 2814 | |
| 2815 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2816 | void MacroAssembler::AbortIfSmi(Register object) { |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2817 | Condition is_smi = CheckSmi(object); |
| 2818 | Assert(NegateCondition(is_smi), "Operand is a smi"); |
| 2819 | } |
| 2820 | |
| 2821 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2822 | void MacroAssembler::AbortIfNotSmi(Register object) { |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 2823 | Condition is_smi = CheckSmi(object); |
| 2824 | Assert(is_smi, "Operand is not a smi"); |
| 2825 | } |
| 2826 | |
| 2827 | |
| 2828 | void MacroAssembler::AbortIfNotSmi(const Operand& object) { |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 2829 | Condition is_smi = CheckSmi(object); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2830 | Assert(is_smi, "Operand is not a smi"); |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 2831 | } |
| 2832 | |
| 2833 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 2834 | void MacroAssembler::AbortIfNotString(Register object) { |
| 2835 | testb(object, Immediate(kSmiTagMask)); |
| 2836 | Assert(not_equal, "Operand is not a string"); |
| 2837 | push(object); |
| 2838 | movq(object, FieldOperand(object, HeapObject::kMapOffset)); |
| 2839 | CmpInstanceType(object, FIRST_NONSTRING_TYPE); |
| 2840 | pop(object); |
| 2841 | Assert(below, "Operand is not a string"); |
| 2842 | } |
| 2843 | |
| 2844 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 2845 | void MacroAssembler::AbortIfNotRootValue(Register src, |
| 2846 | Heap::RootListIndex root_value_index, |
| 2847 | const char* message) { |
| 2848 | ASSERT(!src.is(kScratchRegister)); |
| 2849 | LoadRoot(kScratchRegister, root_value_index); |
| 2850 | cmpq(src, kScratchRegister); |
| 2851 | Check(equal, message); |
| 2852 | } |
| 2853 | |
| 2854 | |
| 2855 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2856 | Condition MacroAssembler::IsObjectStringType(Register heap_object, |
| 2857 | Register map, |
| 2858 | Register instance_type) { |
| 2859 | movq(map, FieldOperand(heap_object, HeapObject::kMapOffset)); |
| 2860 | movzxbl(instance_type, FieldOperand(map, Map::kInstanceTypeOffset)); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 2861 | STATIC_ASSERT(kNotStringTag != 0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2862 | testb(instance_type, Immediate(kIsNotStringMask)); |
| 2863 | return zero; |
| 2864 | } |
| 2865 | |
| 2866 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2867 | void MacroAssembler::TryGetFunctionPrototype(Register function, |
| 2868 | Register result, |
| 2869 | Label* miss) { |
| 2870 | // Check that the receiver isn't a smi. |
| 2871 | testl(function, Immediate(kSmiTagMask)); |
| 2872 | j(zero, miss); |
| 2873 | |
| 2874 | // Check that the function really is a function. |
| 2875 | CmpObjectType(function, JS_FUNCTION_TYPE, result); |
| 2876 | j(not_equal, miss); |
| 2877 | |
| 2878 | // Make sure that the function has an instance prototype. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2879 | Label non_instance; |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2880 | testb(FieldOperand(result, Map::kBitFieldOffset), |
| 2881 | Immediate(1 << Map::kHasNonInstancePrototype)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2882 | j(not_zero, &non_instance, Label::kNear); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2883 | |
| 2884 | // Get the prototype or initial map from the function. |
| 2885 | movq(result, |
| 2886 | FieldOperand(function, JSFunction::kPrototypeOrInitialMapOffset)); |
| 2887 | |
| 2888 | // If the prototype or initial map is the hole, don't return it and |
| 2889 | // simply miss the cache instead. This will allow us to allocate a |
| 2890 | // prototype object on-demand in the runtime system. |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2891 | CompareRoot(result, Heap::kTheHoleValueRootIndex); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2892 | j(equal, miss); |
| 2893 | |
| 2894 | // If the function does not have an initial map, we're done. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2895 | Label done; |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2896 | CmpObjectType(result, MAP_TYPE, kScratchRegister); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2897 | j(not_equal, &done, Label::kNear); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2898 | |
| 2899 | // Get the prototype from the initial map. |
| 2900 | movq(result, FieldOperand(result, Map::kPrototypeOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2901 | jmp(&done, Label::kNear); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2902 | |
| 2903 | // Non-instance prototype: Fetch prototype from constructor field |
| 2904 | // in initial map. |
| 2905 | bind(&non_instance); |
| 2906 | movq(result, FieldOperand(result, Map::kConstructorOffset)); |
| 2907 | |
| 2908 | // All done. |
| 2909 | bind(&done); |
| 2910 | } |
| 2911 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2912 | |
| 2913 | void MacroAssembler::SetCounter(StatsCounter* counter, int value) { |
| 2914 | if (FLAG_native_code_counters && counter->Enabled()) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2915 | Operand counter_operand = ExternalOperand(ExternalReference(counter)); |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 2916 | movl(counter_operand, Immediate(value)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2917 | } |
| 2918 | } |
| 2919 | |
| 2920 | |
| 2921 | void MacroAssembler::IncrementCounter(StatsCounter* counter, int value) { |
| 2922 | ASSERT(value > 0); |
| 2923 | if (FLAG_native_code_counters && counter->Enabled()) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2924 | Operand counter_operand = ExternalOperand(ExternalReference(counter)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2925 | if (value == 1) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2926 | incl(counter_operand); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2927 | } else { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2928 | addl(counter_operand, Immediate(value)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2929 | } |
| 2930 | } |
| 2931 | } |
| 2932 | |
| 2933 | |
| 2934 | void MacroAssembler::DecrementCounter(StatsCounter* counter, int value) { |
| 2935 | ASSERT(value > 0); |
| 2936 | if (FLAG_native_code_counters && counter->Enabled()) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2937 | Operand counter_operand = ExternalOperand(ExternalReference(counter)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2938 | if (value == 1) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2939 | decl(counter_operand); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2940 | } else { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2941 | subl(counter_operand, Immediate(value)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2942 | } |
| 2943 | } |
| 2944 | } |
| 2945 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2946 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2947 | #ifdef ENABLE_DEBUGGER_SUPPORT |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2948 | void MacroAssembler::DebugBreak() { |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 2949 | Set(rax, 0); // No arguments. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2950 | LoadAddress(rbx, ExternalReference(Runtime::kDebugBreak, isolate())); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2951 | CEntryStub ces(1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2952 | ASSERT(AllowThisStubCall(&ces)); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2953 | Call(ces.GetCode(), RelocInfo::DEBUG_BREAK); |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 2954 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2955 | #endif // ENABLE_DEBUGGER_SUPPORT |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 2956 | |
| 2957 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2958 | void MacroAssembler::SetCallKind(Register dst, CallKind call_kind) { |
| 2959 | // This macro takes the dst register to make the code more readable |
| 2960 | // at the call sites. However, the dst register has to be rcx to |
| 2961 | // follow the calling convention which requires the call type to be |
| 2962 | // in rcx. |
| 2963 | ASSERT(dst.is(rcx)); |
| 2964 | if (call_kind == CALL_AS_FUNCTION) { |
| 2965 | LoadSmiConstant(dst, Smi::FromInt(1)); |
| 2966 | } else { |
| 2967 | LoadSmiConstant(dst, Smi::FromInt(0)); |
| 2968 | } |
| 2969 | } |
| 2970 | |
| 2971 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2972 | void MacroAssembler::InvokeCode(Register code, |
| 2973 | const ParameterCount& expected, |
| 2974 | const ParameterCount& actual, |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2975 | InvokeFlag flag, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2976 | const CallWrapper& call_wrapper, |
| 2977 | CallKind call_kind) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2978 | // You can't call a function without a valid frame. |
| 2979 | ASSERT(flag == JUMP_FUNCTION || has_frame()); |
| 2980 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2981 | Label done; |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2982 | InvokePrologue(expected, |
| 2983 | actual, |
| 2984 | Handle<Code>::null(), |
| 2985 | code, |
| 2986 | &done, |
| 2987 | flag, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2988 | Label::kNear, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2989 | call_wrapper, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2990 | call_kind); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2991 | if (flag == CALL_FUNCTION) { |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2992 | call_wrapper.BeforeCall(CallSize(code)); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2993 | SetCallKind(rcx, call_kind); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2994 | call(code); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2995 | call_wrapper.AfterCall(); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2996 | } else { |
| 2997 | ASSERT(flag == JUMP_FUNCTION); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2998 | SetCallKind(rcx, call_kind); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2999 | jmp(code); |
| 3000 | } |
| 3001 | bind(&done); |
| 3002 | } |
| 3003 | |
| 3004 | |
| 3005 | void MacroAssembler::InvokeCode(Handle<Code> code, |
| 3006 | const ParameterCount& expected, |
| 3007 | const ParameterCount& actual, |
| 3008 | RelocInfo::Mode rmode, |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3009 | InvokeFlag flag, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3010 | const CallWrapper& call_wrapper, |
| 3011 | CallKind call_kind) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3012 | // You can't call a function without a valid frame. |
| 3013 | ASSERT(flag == JUMP_FUNCTION || has_frame()); |
| 3014 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3015 | Label done; |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 3016 | Register dummy = rax; |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3017 | InvokePrologue(expected, |
| 3018 | actual, |
| 3019 | code, |
| 3020 | dummy, |
| 3021 | &done, |
| 3022 | flag, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3023 | Label::kNear, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3024 | call_wrapper, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3025 | call_kind); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 3026 | if (flag == CALL_FUNCTION) { |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 3027 | call_wrapper.BeforeCall(CallSize(code)); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3028 | SetCallKind(rcx, call_kind); |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 3029 | Call(code, rmode); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 3030 | call_wrapper.AfterCall(); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 3031 | } else { |
| 3032 | ASSERT(flag == JUMP_FUNCTION); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3033 | SetCallKind(rcx, call_kind); |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 3034 | Jump(code, rmode); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 3035 | } |
| 3036 | bind(&done); |
| 3037 | } |
| 3038 | |
| 3039 | |
| 3040 | void MacroAssembler::InvokeFunction(Register function, |
| 3041 | const ParameterCount& actual, |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3042 | InvokeFlag flag, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3043 | const CallWrapper& call_wrapper, |
| 3044 | CallKind call_kind) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3045 | // You can't call a function without a valid frame. |
| 3046 | ASSERT(flag == JUMP_FUNCTION || has_frame()); |
| 3047 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 3048 | ASSERT(function.is(rdi)); |
| 3049 | movq(rdx, FieldOperand(function, JSFunction::kSharedFunctionInfoOffset)); |
| 3050 | movq(rsi, FieldOperand(function, JSFunction::kContextOffset)); |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 3051 | movsxlq(rbx, |
| 3052 | FieldOperand(rdx, SharedFunctionInfo::kFormalParameterCountOffset)); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 3053 | // Advances rdx to the end of the Code object header, to the start of |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 3054 | // the executable code. |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 3055 | movq(rdx, FieldOperand(rdi, JSFunction::kCodeEntryOffset)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 3056 | |
| 3057 | ParameterCount expected(rbx); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3058 | InvokeCode(rdx, expected, actual, flag, call_wrapper, call_kind); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 3059 | } |
| 3060 | |
| 3061 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3062 | void MacroAssembler::InvokeFunction(JSFunction* function, |
| 3063 | const ParameterCount& actual, |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3064 | InvokeFlag flag, |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3065 | const CallWrapper& call_wrapper, |
| 3066 | CallKind call_kind) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3067 | // You can't call a function without a valid frame. |
| 3068 | ASSERT(flag == JUMP_FUNCTION || has_frame()); |
| 3069 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3070 | ASSERT(function->is_compiled()); |
| 3071 | // Get the function and setup the context. |
| 3072 | Move(rdi, Handle<JSFunction>(function)); |
| 3073 | movq(rsi, FieldOperand(rdi, JSFunction::kContextOffset)); |
| 3074 | |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3075 | if (V8::UseCrankshaft()) { |
| 3076 | // Since Crankshaft can recompile a function, we need to load |
| 3077 | // the Code object every time we call the function. |
| 3078 | movq(rdx, FieldOperand(rdi, JSFunction::kCodeEntryOffset)); |
| 3079 | ParameterCount expected(function->shared()->formal_parameter_count()); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3080 | InvokeCode(rdx, expected, actual, flag, call_wrapper, call_kind); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3081 | } else { |
| 3082 | // Invoke the cached code. |
| 3083 | Handle<Code> code(function->code()); |
| 3084 | ParameterCount expected(function->shared()->formal_parameter_count()); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3085 | InvokeCode(code, |
| 3086 | expected, |
| 3087 | actual, |
| 3088 | RelocInfo::CODE_TARGET, |
| 3089 | flag, |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3090 | call_wrapper, |
| 3091 | call_kind); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3092 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3093 | } |
| 3094 | |
| 3095 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3096 | void MacroAssembler::InvokePrologue(const ParameterCount& expected, |
| 3097 | const ParameterCount& actual, |
| 3098 | Handle<Code> code_constant, |
| 3099 | Register code_register, |
| 3100 | Label* done, |
| 3101 | InvokeFlag flag, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3102 | Label::Distance near_jump, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3103 | const CallWrapper& call_wrapper, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3104 | CallKind call_kind) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3105 | bool definitely_matches = false; |
| 3106 | Label invoke; |
| 3107 | if (expected.is_immediate()) { |
| 3108 | ASSERT(actual.is_immediate()); |
| 3109 | if (expected.immediate() == actual.immediate()) { |
| 3110 | definitely_matches = true; |
| 3111 | } else { |
| 3112 | Set(rax, actual.immediate()); |
| 3113 | if (expected.immediate() == |
| 3114 | SharedFunctionInfo::kDontAdaptArgumentsSentinel) { |
| 3115 | // Don't worry about adapting arguments for built-ins that |
| 3116 | // don't want that done. Skip adaption code by making it look |
| 3117 | // like we have a match between expected and actual number of |
| 3118 | // arguments. |
| 3119 | definitely_matches = true; |
| 3120 | } else { |
| 3121 | Set(rbx, expected.immediate()); |
| 3122 | } |
| 3123 | } |
| 3124 | } else { |
| 3125 | if (actual.is_immediate()) { |
| 3126 | // Expected is in register, actual is immediate. This is the |
| 3127 | // case when we invoke function values without going through the |
| 3128 | // IC mechanism. |
| 3129 | cmpq(expected.reg(), Immediate(actual.immediate())); |
| 3130 | j(equal, &invoke, Label::kNear); |
| 3131 | ASSERT(expected.reg().is(rbx)); |
| 3132 | Set(rax, actual.immediate()); |
| 3133 | } else if (!expected.reg().is(actual.reg())) { |
| 3134 | // Both expected and actual are in (different) registers. This |
| 3135 | // is the case when we invoke functions using call and apply. |
| 3136 | cmpq(expected.reg(), actual.reg()); |
| 3137 | j(equal, &invoke, Label::kNear); |
| 3138 | ASSERT(actual.reg().is(rax)); |
| 3139 | ASSERT(expected.reg().is(rbx)); |
| 3140 | } |
| 3141 | } |
| 3142 | |
| 3143 | if (!definitely_matches) { |
| 3144 | Handle<Code> adaptor = isolate()->builtins()->ArgumentsAdaptorTrampoline(); |
| 3145 | if (!code_constant.is_null()) { |
| 3146 | movq(rdx, code_constant, RelocInfo::EMBEDDED_OBJECT); |
| 3147 | addq(rdx, Immediate(Code::kHeaderSize - kHeapObjectTag)); |
| 3148 | } else if (!code_register.is(rdx)) { |
| 3149 | movq(rdx, code_register); |
| 3150 | } |
| 3151 | |
| 3152 | if (flag == CALL_FUNCTION) { |
| 3153 | call_wrapper.BeforeCall(CallSize(adaptor)); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3154 | SetCallKind(rcx, call_kind); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3155 | Call(adaptor, RelocInfo::CODE_TARGET); |
| 3156 | call_wrapper.AfterCall(); |
| 3157 | jmp(done, near_jump); |
| 3158 | } else { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3159 | SetCallKind(rcx, call_kind); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3160 | Jump(adaptor, RelocInfo::CODE_TARGET); |
| 3161 | } |
| 3162 | bind(&invoke); |
| 3163 | } |
| 3164 | } |
| 3165 | |
| 3166 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 3167 | void MacroAssembler::EnterFrame(StackFrame::Type type) { |
| 3168 | push(rbp); |
| 3169 | movq(rbp, rsp); |
| 3170 | push(rsi); // Context. |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 3171 | Push(Smi::FromInt(type)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 3172 | movq(kScratchRegister, CodeObject(), RelocInfo::EMBEDDED_OBJECT); |
| 3173 | push(kScratchRegister); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 3174 | if (emit_debug_code()) { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 3175 | movq(kScratchRegister, |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3176 | isolate()->factory()->undefined_value(), |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 3177 | RelocInfo::EMBEDDED_OBJECT); |
| 3178 | cmpq(Operand(rsp, 0), kScratchRegister); |
| 3179 | Check(not_equal, "code object not properly patched"); |
| 3180 | } |
| 3181 | } |
| 3182 | |
| 3183 | |
| 3184 | void MacroAssembler::LeaveFrame(StackFrame::Type type) { |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 3185 | if (emit_debug_code()) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 3186 | Move(kScratchRegister, Smi::FromInt(type)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 3187 | cmpq(Operand(rbp, StandardFrameConstants::kMarkerOffset), kScratchRegister); |
| 3188 | Check(equal, "stack frame types must match"); |
| 3189 | } |
| 3190 | movq(rsp, rbp); |
| 3191 | pop(rbp); |
| 3192 | } |
| 3193 | |
| 3194 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3195 | void MacroAssembler::EnterExitFramePrologue(bool save_rax) { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 3196 | // Setup the frame structure on the stack. |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3197 | // All constants are relative to the frame pointer of the exit frame. |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 3198 | ASSERT(ExitFrameConstants::kCallerSPDisplacement == +2 * kPointerSize); |
| 3199 | ASSERT(ExitFrameConstants::kCallerPCOffset == +1 * kPointerSize); |
| 3200 | ASSERT(ExitFrameConstants::kCallerFPOffset == 0 * kPointerSize); |
| 3201 | push(rbp); |
| 3202 | movq(rbp, rsp); |
| 3203 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3204 | // Reserve room for entry stack pointer and push the code object. |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 3205 | ASSERT(ExitFrameConstants::kSPOffset == -1 * kPointerSize); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3206 | push(Immediate(0)); // Saved entry sp, patched before call. |
| 3207 | movq(kScratchRegister, CodeObject(), RelocInfo::EMBEDDED_OBJECT); |
| 3208 | push(kScratchRegister); // Accessed from EditFrame::code_slot. |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 3209 | |
| 3210 | // Save the frame pointer and the context in top. |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 3211 | if (save_rax) { |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3212 | movq(r14, rax); // Backup rax in callee-save register. |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 3213 | } |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 3214 | |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3215 | Store(ExternalReference(Isolate::kCEntryFPAddress, isolate()), rbp); |
| 3216 | Store(ExternalReference(Isolate::kContextAddress, isolate()), rsi); |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 3217 | } |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 3218 | |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 3219 | |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 3220 | void MacroAssembler::EnterExitFrameEpilogue(int arg_stack_space, |
| 3221 | bool save_doubles) { |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 3222 | #ifdef _WIN64 |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 3223 | const int kShadowSpace = 4; |
| 3224 | arg_stack_space += kShadowSpace; |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 3225 | #endif |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 3226 | // Optionally save all XMM registers. |
| 3227 | if (save_doubles) { |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 3228 | int space = XMMRegister::kNumRegisters * kDoubleSize + |
| 3229 | arg_stack_space * kPointerSize; |
| 3230 | subq(rsp, Immediate(space)); |
| 3231 | int offset = -2 * kPointerSize; |
| 3232 | for (int i = 0; i < XMMRegister::kNumAllocatableRegisters; i++) { |
| 3233 | XMMRegister reg = XMMRegister::FromAllocationIndex(i); |
| 3234 | movsd(Operand(rbp, offset - ((i + 1) * kDoubleSize)), reg); |
| 3235 | } |
| 3236 | } else if (arg_stack_space > 0) { |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 3237 | subq(rsp, Immediate(arg_stack_space * kPointerSize)); |
| 3238 | } |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 3239 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 3240 | // Get the required frame alignment for the OS. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3241 | const int kFrameAlignment = OS::ActivationFrameAlignment(); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 3242 | if (kFrameAlignment > 0) { |
| 3243 | ASSERT(IsPowerOf2(kFrameAlignment)); |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 3244 | ASSERT(is_int8(kFrameAlignment)); |
| 3245 | and_(rsp, Immediate(-kFrameAlignment)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 3246 | } |
| 3247 | |
| 3248 | // Patch the saved entry sp. |
| 3249 | movq(Operand(rbp, ExitFrameConstants::kSPOffset), rsp); |
| 3250 | } |
| 3251 | |
| 3252 | |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 3253 | void MacroAssembler::EnterExitFrame(int arg_stack_space, bool save_doubles) { |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3254 | EnterExitFramePrologue(true); |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 3255 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 3256 | // Setup argv in callee-saved register r15. It is reused in LeaveExitFrame, |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 3257 | // so it must be retained across the C-call. |
| 3258 | int offset = StandardFrameConstants::kCallerSPOffset - kPointerSize; |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 3259 | lea(r15, Operand(rbp, r14, times_pointer_size, offset)); |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 3260 | |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 3261 | EnterExitFrameEpilogue(arg_stack_space, save_doubles); |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 3262 | } |
| 3263 | |
| 3264 | |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 3265 | void MacroAssembler::EnterApiExitFrame(int arg_stack_space) { |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3266 | EnterExitFramePrologue(false); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 3267 | EnterExitFrameEpilogue(arg_stack_space, false); |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 3268 | } |
| 3269 | |
| 3270 | |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 3271 | void MacroAssembler::LeaveExitFrame(bool save_doubles) { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 3272 | // Registers: |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 3273 | // r15 : argv |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 3274 | if (save_doubles) { |
| 3275 | int offset = -2 * kPointerSize; |
| 3276 | for (int i = 0; i < XMMRegister::kNumAllocatableRegisters; i++) { |
| 3277 | XMMRegister reg = XMMRegister::FromAllocationIndex(i); |
| 3278 | movsd(reg, Operand(rbp, offset - ((i + 1) * kDoubleSize))); |
| 3279 | } |
| 3280 | } |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 3281 | // Get the return address from the stack and restore the frame pointer. |
| 3282 | movq(rcx, Operand(rbp, 1 * kPointerSize)); |
| 3283 | movq(rbp, Operand(rbp, 0 * kPointerSize)); |
| 3284 | |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 3285 | // Drop everything up to and including the arguments and the receiver |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 3286 | // from the caller stack. |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 3287 | lea(rsp, Operand(r15, 1 * kPointerSize)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 3288 | |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 3289 | // Push the return address to get ready to return. |
| 3290 | push(rcx); |
| 3291 | |
| 3292 | LeaveExitFrameEpilogue(); |
| 3293 | } |
| 3294 | |
| 3295 | |
| 3296 | void MacroAssembler::LeaveApiExitFrame() { |
| 3297 | movq(rsp, rbp); |
| 3298 | pop(rbp); |
| 3299 | |
| 3300 | LeaveExitFrameEpilogue(); |
| 3301 | } |
| 3302 | |
| 3303 | |
| 3304 | void MacroAssembler::LeaveExitFrameEpilogue() { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 3305 | // Restore current context from top and clear it in debug mode. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3306 | ExternalReference context_address(Isolate::kContextAddress, isolate()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3307 | Operand context_operand = ExternalOperand(context_address); |
| 3308 | movq(rsi, context_operand); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 3309 | #ifdef DEBUG |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3310 | movq(context_operand, Immediate(0)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 3311 | #endif |
| 3312 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 3313 | // Clear the top frame. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3314 | ExternalReference c_entry_fp_address(Isolate::kCEntryFPAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3315 | isolate()); |
| 3316 | Operand c_entry_fp_operand = ExternalOperand(c_entry_fp_address); |
| 3317 | movq(c_entry_fp_operand, Immediate(0)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 3318 | } |
| 3319 | |
| 3320 | |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 3321 | void MacroAssembler::CheckAccessGlobalProxy(Register holder_reg, |
| 3322 | Register scratch, |
| 3323 | Label* miss) { |
| 3324 | Label same_contexts; |
| 3325 | |
| 3326 | ASSERT(!holder_reg.is(scratch)); |
| 3327 | ASSERT(!scratch.is(kScratchRegister)); |
| 3328 | // Load current lexical context from the stack frame. |
| 3329 | movq(scratch, Operand(rbp, StandardFrameConstants::kContextOffset)); |
| 3330 | |
| 3331 | // When generating debug code, make sure the lexical context is set. |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 3332 | if (emit_debug_code()) { |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 3333 | cmpq(scratch, Immediate(0)); |
| 3334 | Check(not_equal, "we should not have an empty lexical context"); |
| 3335 | } |
| 3336 | // Load the global context of the current context. |
| 3337 | int offset = Context::kHeaderSize + Context::GLOBAL_INDEX * kPointerSize; |
| 3338 | movq(scratch, FieldOperand(scratch, offset)); |
| 3339 | movq(scratch, FieldOperand(scratch, GlobalObject::kGlobalContextOffset)); |
| 3340 | |
| 3341 | // Check the context is a global context. |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 3342 | if (emit_debug_code()) { |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 3343 | Cmp(FieldOperand(scratch, HeapObject::kMapOffset), |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3344 | isolate()->factory()->global_context_map()); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 3345 | Check(equal, "JSGlobalObject::global_context should be a global context."); |
| 3346 | } |
| 3347 | |
| 3348 | // Check if both contexts are the same. |
| 3349 | cmpq(scratch, FieldOperand(holder_reg, JSGlobalProxy::kContextOffset)); |
| 3350 | j(equal, &same_contexts); |
| 3351 | |
| 3352 | // Compare security tokens. |
| 3353 | // Check that the security token in the calling global object is |
| 3354 | // compatible with the security token in the receiving global |
| 3355 | // object. |
| 3356 | |
| 3357 | // Check the context is a global context. |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 3358 | if (emit_debug_code()) { |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 3359 | // Preserve original value of holder_reg. |
| 3360 | push(holder_reg); |
| 3361 | movq(holder_reg, FieldOperand(holder_reg, JSGlobalProxy::kContextOffset)); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3362 | CompareRoot(holder_reg, Heap::kNullValueRootIndex); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 3363 | Check(not_equal, "JSGlobalProxy::context() should not be null."); |
| 3364 | |
| 3365 | // Read the first word and compare to global_context_map(), |
| 3366 | movq(holder_reg, FieldOperand(holder_reg, HeapObject::kMapOffset)); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3367 | CompareRoot(holder_reg, Heap::kGlobalContextMapRootIndex); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 3368 | Check(equal, "JSGlobalObject::global_context should be a global context."); |
| 3369 | pop(holder_reg); |
| 3370 | } |
| 3371 | |
| 3372 | movq(kScratchRegister, |
| 3373 | FieldOperand(holder_reg, JSGlobalProxy::kContextOffset)); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 3374 | int token_offset = |
| 3375 | Context::kHeaderSize + Context::SECURITY_TOKEN_INDEX * kPointerSize; |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 3376 | movq(scratch, FieldOperand(scratch, token_offset)); |
| 3377 | cmpq(scratch, FieldOperand(kScratchRegister, token_offset)); |
| 3378 | j(not_equal, miss); |
| 3379 | |
| 3380 | bind(&same_contexts); |
| 3381 | } |
| 3382 | |
| 3383 | |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 3384 | void MacroAssembler::LoadFromNumberDictionary(Label* miss, |
| 3385 | Register elements, |
| 3386 | Register key, |
| 3387 | Register r0, |
| 3388 | Register r1, |
| 3389 | Register r2, |
| 3390 | Register result) { |
| 3391 | // Register use: |
| 3392 | // |
| 3393 | // elements - holds the slow-case elements of the receiver on entry. |
| 3394 | // Unchanged unless 'result' is the same register. |
| 3395 | // |
| 3396 | // key - holds the smi key on entry. |
| 3397 | // Unchanged unless 'result' is the same register. |
| 3398 | // |
| 3399 | // Scratch registers: |
| 3400 | // |
| 3401 | // r0 - holds the untagged key on entry and holds the hash once computed. |
| 3402 | // |
| 3403 | // r1 - used to hold the capacity mask of the dictionary |
| 3404 | // |
| 3405 | // r2 - used for the index into the dictionary. |
| 3406 | // |
| 3407 | // result - holds the result on exit if the load succeeded. |
| 3408 | // Allowed to be the same as 'key' or 'result'. |
| 3409 | // Unchanged on bailout so 'key' or 'result' can be used |
| 3410 | // in further computation. |
| 3411 | |
| 3412 | Label done; |
| 3413 | |
| 3414 | // Compute the hash code from the untagged key. This must be kept in sync |
| 3415 | // with ComputeIntegerHash in utils.h. |
| 3416 | // |
| 3417 | // hash = ~hash + (hash << 15); |
| 3418 | movl(r1, r0); |
| 3419 | notl(r0); |
| 3420 | shll(r1, Immediate(15)); |
| 3421 | addl(r0, r1); |
| 3422 | // hash = hash ^ (hash >> 12); |
| 3423 | movl(r1, r0); |
| 3424 | shrl(r1, Immediate(12)); |
| 3425 | xorl(r0, r1); |
| 3426 | // hash = hash + (hash << 2); |
| 3427 | leal(r0, Operand(r0, r0, times_4, 0)); |
| 3428 | // hash = hash ^ (hash >> 4); |
| 3429 | movl(r1, r0); |
| 3430 | shrl(r1, Immediate(4)); |
| 3431 | xorl(r0, r1); |
| 3432 | // hash = hash * 2057; |
| 3433 | imull(r0, r0, Immediate(2057)); |
| 3434 | // hash = hash ^ (hash >> 16); |
| 3435 | movl(r1, r0); |
| 3436 | shrl(r1, Immediate(16)); |
| 3437 | xorl(r0, r1); |
| 3438 | |
| 3439 | // Compute capacity mask. |
| 3440 | SmiToInteger32(r1, |
| 3441 | FieldOperand(elements, NumberDictionary::kCapacityOffset)); |
| 3442 | decl(r1); |
| 3443 | |
| 3444 | // Generate an unrolled loop that performs a few probes before giving up. |
| 3445 | const int kProbes = 4; |
| 3446 | for (int i = 0; i < kProbes; i++) { |
| 3447 | // Use r2 for index calculations and keep the hash intact in r0. |
| 3448 | movq(r2, r0); |
| 3449 | // Compute the masked index: (hash + i + i * i) & mask. |
| 3450 | if (i > 0) { |
| 3451 | addl(r2, Immediate(NumberDictionary::GetProbeOffset(i))); |
| 3452 | } |
| 3453 | and_(r2, r1); |
| 3454 | |
| 3455 | // Scale the index by multiplying by the entry size. |
| 3456 | ASSERT(NumberDictionary::kEntrySize == 3); |
| 3457 | lea(r2, Operand(r2, r2, times_2, 0)); // r2 = r2 * 3 |
| 3458 | |
| 3459 | // Check if the key matches. |
| 3460 | cmpq(key, FieldOperand(elements, |
| 3461 | r2, |
| 3462 | times_pointer_size, |
| 3463 | NumberDictionary::kElementsStartOffset)); |
| 3464 | if (i != (kProbes - 1)) { |
| 3465 | j(equal, &done); |
| 3466 | } else { |
| 3467 | j(not_equal, miss); |
| 3468 | } |
| 3469 | } |
| 3470 | |
| 3471 | bind(&done); |
| 3472 | // Check that the value is a normal propety. |
| 3473 | const int kDetailsOffset = |
| 3474 | NumberDictionary::kElementsStartOffset + 2 * kPointerSize; |
| 3475 | ASSERT_EQ(NORMAL, 0); |
| 3476 | Test(FieldOperand(elements, r2, times_pointer_size, kDetailsOffset), |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3477 | Smi::FromInt(PropertyDetails::TypeField::kMask)); |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 3478 | j(not_zero, miss); |
| 3479 | |
| 3480 | // Get the value at the masked, scaled index. |
| 3481 | const int kValueOffset = |
| 3482 | NumberDictionary::kElementsStartOffset + kPointerSize; |
| 3483 | movq(result, FieldOperand(elements, r2, times_pointer_size, kValueOffset)); |
| 3484 | } |
| 3485 | |
| 3486 | |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 3487 | void MacroAssembler::LoadAllocationTopHelper(Register result, |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 3488 | Register scratch, |
| 3489 | AllocationFlags flags) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3490 | ExternalReference new_space_allocation_top = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3491 | ExternalReference::new_space_allocation_top_address(isolate()); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3492 | |
| 3493 | // Just return if allocation top is already known. |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 3494 | if ((flags & RESULT_CONTAINS_TOP) != 0) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3495 | // No use of scratch if allocation top is provided. |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3496 | ASSERT(!scratch.is_valid()); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 3497 | #ifdef DEBUG |
| 3498 | // Assert that result actually contains top on entry. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3499 | Operand top_operand = ExternalOperand(new_space_allocation_top); |
| 3500 | cmpq(result, top_operand); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 3501 | Check(equal, "Unexpected allocation top"); |
| 3502 | #endif |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3503 | return; |
| 3504 | } |
| 3505 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3506 | // Move address of new object to result. Use scratch register if available, |
| 3507 | // and keep address in scratch until call to UpdateAllocationTopHelper. |
| 3508 | if (scratch.is_valid()) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3509 | LoadAddress(scratch, new_space_allocation_top); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3510 | movq(result, Operand(scratch, 0)); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3511 | } else { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3512 | Load(result, new_space_allocation_top); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3513 | } |
| 3514 | } |
| 3515 | |
| 3516 | |
| 3517 | void MacroAssembler::UpdateAllocationTopHelper(Register result_end, |
| 3518 | Register scratch) { |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 3519 | if (emit_debug_code()) { |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 3520 | testq(result_end, Immediate(kObjectAlignmentMask)); |
| 3521 | Check(zero, "Unaligned allocation in new space"); |
| 3522 | } |
| 3523 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3524 | ExternalReference new_space_allocation_top = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3525 | ExternalReference::new_space_allocation_top_address(isolate()); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3526 | |
| 3527 | // Update new top. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3528 | if (scratch.is_valid()) { |
| 3529 | // Scratch already contains address of allocation top. |
| 3530 | movq(Operand(scratch, 0), result_end); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3531 | } else { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3532 | Store(new_space_allocation_top, result_end); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3533 | } |
| 3534 | } |
| 3535 | |
| 3536 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3537 | void MacroAssembler::AllocateInNewSpace(int object_size, |
| 3538 | Register result, |
| 3539 | Register result_end, |
| 3540 | Register scratch, |
| 3541 | Label* gc_required, |
| 3542 | AllocationFlags flags) { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3543 | if (!FLAG_inline_new) { |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 3544 | if (emit_debug_code()) { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3545 | // Trash the registers to simulate an allocation failure. |
| 3546 | movl(result, Immediate(0x7091)); |
| 3547 | if (result_end.is_valid()) { |
| 3548 | movl(result_end, Immediate(0x7191)); |
| 3549 | } |
| 3550 | if (scratch.is_valid()) { |
| 3551 | movl(scratch, Immediate(0x7291)); |
| 3552 | } |
| 3553 | } |
| 3554 | jmp(gc_required); |
| 3555 | return; |
| 3556 | } |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3557 | ASSERT(!result.is(result_end)); |
| 3558 | |
| 3559 | // Load address of new object into result. |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 3560 | LoadAllocationTopHelper(result, scratch, flags); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3561 | |
| 3562 | // Calculate new top and bail out if new space is exhausted. |
| 3563 | ExternalReference new_space_allocation_limit = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3564 | ExternalReference::new_space_allocation_limit_address(isolate()); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3565 | |
| 3566 | Register top_reg = result_end.is_valid() ? result_end : result; |
| 3567 | |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 3568 | if (!top_reg.is(result)) { |
| 3569 | movq(top_reg, result); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3570 | } |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 3571 | addq(top_reg, Immediate(object_size)); |
| 3572 | j(carry, gc_required); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3573 | Operand limit_operand = ExternalOperand(new_space_allocation_limit); |
| 3574 | cmpq(top_reg, limit_operand); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3575 | j(above, gc_required); |
| 3576 | |
| 3577 | // Update allocation top. |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3578 | UpdateAllocationTopHelper(top_reg, scratch); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 3579 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3580 | if (top_reg.is(result)) { |
| 3581 | if ((flags & TAG_OBJECT) != 0) { |
| 3582 | subq(result, Immediate(object_size - kHeapObjectTag)); |
| 3583 | } else { |
| 3584 | subq(result, Immediate(object_size)); |
| 3585 | } |
| 3586 | } else if ((flags & TAG_OBJECT) != 0) { |
| 3587 | // Tag the result if requested. |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 3588 | addq(result, Immediate(kHeapObjectTag)); |
| 3589 | } |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3590 | } |
| 3591 | |
| 3592 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3593 | void MacroAssembler::AllocateInNewSpace(int header_size, |
| 3594 | ScaleFactor element_size, |
| 3595 | Register element_count, |
| 3596 | Register result, |
| 3597 | Register result_end, |
| 3598 | Register scratch, |
| 3599 | Label* gc_required, |
| 3600 | AllocationFlags flags) { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3601 | if (!FLAG_inline_new) { |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 3602 | if (emit_debug_code()) { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3603 | // Trash the registers to simulate an allocation failure. |
| 3604 | movl(result, Immediate(0x7091)); |
| 3605 | movl(result_end, Immediate(0x7191)); |
| 3606 | if (scratch.is_valid()) { |
| 3607 | movl(scratch, Immediate(0x7291)); |
| 3608 | } |
| 3609 | // Register element_count is not modified by the function. |
| 3610 | } |
| 3611 | jmp(gc_required); |
| 3612 | return; |
| 3613 | } |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3614 | ASSERT(!result.is(result_end)); |
| 3615 | |
| 3616 | // Load address of new object into result. |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 3617 | LoadAllocationTopHelper(result, scratch, flags); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3618 | |
| 3619 | // Calculate new top and bail out if new space is exhausted. |
| 3620 | ExternalReference new_space_allocation_limit = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3621 | ExternalReference::new_space_allocation_limit_address(isolate()); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 3622 | |
| 3623 | // We assume that element_count*element_size + header_size does not |
| 3624 | // overflow. |
| 3625 | lea(result_end, Operand(element_count, element_size, header_size)); |
| 3626 | addq(result_end, result); |
| 3627 | j(carry, gc_required); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3628 | Operand limit_operand = ExternalOperand(new_space_allocation_limit); |
| 3629 | cmpq(result_end, limit_operand); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3630 | j(above, gc_required); |
| 3631 | |
| 3632 | // Update allocation top. |
| 3633 | UpdateAllocationTopHelper(result_end, scratch); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 3634 | |
| 3635 | // Tag the result if requested. |
| 3636 | if ((flags & TAG_OBJECT) != 0) { |
| 3637 | addq(result, Immediate(kHeapObjectTag)); |
| 3638 | } |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3639 | } |
| 3640 | |
| 3641 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3642 | void MacroAssembler::AllocateInNewSpace(Register object_size, |
| 3643 | Register result, |
| 3644 | Register result_end, |
| 3645 | Register scratch, |
| 3646 | Label* gc_required, |
| 3647 | AllocationFlags flags) { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3648 | if (!FLAG_inline_new) { |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 3649 | if (emit_debug_code()) { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3650 | // Trash the registers to simulate an allocation failure. |
| 3651 | movl(result, Immediate(0x7091)); |
| 3652 | movl(result_end, Immediate(0x7191)); |
| 3653 | if (scratch.is_valid()) { |
| 3654 | movl(scratch, Immediate(0x7291)); |
| 3655 | } |
| 3656 | // object_size is left unchanged by this function. |
| 3657 | } |
| 3658 | jmp(gc_required); |
| 3659 | return; |
| 3660 | } |
| 3661 | ASSERT(!result.is(result_end)); |
| 3662 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3663 | // Load address of new object into result. |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 3664 | LoadAllocationTopHelper(result, scratch, flags); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3665 | |
| 3666 | // Calculate new top and bail out if new space is exhausted. |
| 3667 | ExternalReference new_space_allocation_limit = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3668 | ExternalReference::new_space_allocation_limit_address(isolate()); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3669 | if (!object_size.is(result_end)) { |
| 3670 | movq(result_end, object_size); |
| 3671 | } |
| 3672 | addq(result_end, result); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 3673 | j(carry, gc_required); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3674 | Operand limit_operand = ExternalOperand(new_space_allocation_limit); |
| 3675 | cmpq(result_end, limit_operand); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3676 | j(above, gc_required); |
| 3677 | |
| 3678 | // Update allocation top. |
| 3679 | UpdateAllocationTopHelper(result_end, scratch); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 3680 | |
| 3681 | // Tag the result if requested. |
| 3682 | if ((flags & TAG_OBJECT) != 0) { |
| 3683 | addq(result, Immediate(kHeapObjectTag)); |
| 3684 | } |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3685 | } |
| 3686 | |
| 3687 | |
| 3688 | void MacroAssembler::UndoAllocationInNewSpace(Register object) { |
| 3689 | ExternalReference new_space_allocation_top = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3690 | ExternalReference::new_space_allocation_top_address(isolate()); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3691 | |
| 3692 | // Make sure the object has no tag before resetting top. |
| 3693 | and_(object, Immediate(~kHeapObjectTagMask)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3694 | Operand top_operand = ExternalOperand(new_space_allocation_top); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3695 | #ifdef DEBUG |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3696 | cmpq(object, top_operand); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3697 | Check(below, "Undo allocation of non allocated memory"); |
| 3698 | #endif |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3699 | movq(top_operand, object); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3700 | } |
| 3701 | |
| 3702 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3703 | void MacroAssembler::AllocateHeapNumber(Register result, |
| 3704 | Register scratch, |
| 3705 | Label* gc_required) { |
| 3706 | // Allocate heap number in new space. |
| 3707 | AllocateInNewSpace(HeapNumber::kSize, |
| 3708 | result, |
| 3709 | scratch, |
| 3710 | no_reg, |
| 3711 | gc_required, |
| 3712 | TAG_OBJECT); |
| 3713 | |
| 3714 | // Set the map. |
| 3715 | LoadRoot(kScratchRegister, Heap::kHeapNumberMapRootIndex); |
| 3716 | movq(FieldOperand(result, HeapObject::kMapOffset), kScratchRegister); |
| 3717 | } |
| 3718 | |
| 3719 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 3720 | void MacroAssembler::AllocateTwoByteString(Register result, |
| 3721 | Register length, |
| 3722 | Register scratch1, |
| 3723 | Register scratch2, |
| 3724 | Register scratch3, |
| 3725 | Label* gc_required) { |
| 3726 | // Calculate the number of bytes needed for the characters in the string while |
| 3727 | // observing object alignment. |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3728 | const int kHeaderAlignment = SeqTwoByteString::kHeaderSize & |
| 3729 | kObjectAlignmentMask; |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 3730 | ASSERT(kShortSize == 2); |
| 3731 | // scratch1 = length * 2 + kObjectAlignmentMask. |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3732 | lea(scratch1, Operand(length, length, times_1, kObjectAlignmentMask + |
| 3733 | kHeaderAlignment)); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 3734 | and_(scratch1, Immediate(~kObjectAlignmentMask)); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3735 | if (kHeaderAlignment > 0) { |
| 3736 | subq(scratch1, Immediate(kHeaderAlignment)); |
| 3737 | } |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 3738 | |
| 3739 | // Allocate two byte string in new space. |
| 3740 | AllocateInNewSpace(SeqTwoByteString::kHeaderSize, |
| 3741 | times_1, |
| 3742 | scratch1, |
| 3743 | result, |
| 3744 | scratch2, |
| 3745 | scratch3, |
| 3746 | gc_required, |
| 3747 | TAG_OBJECT); |
| 3748 | |
| 3749 | // Set the map, length and hash field. |
| 3750 | LoadRoot(kScratchRegister, Heap::kStringMapRootIndex); |
| 3751 | movq(FieldOperand(result, HeapObject::kMapOffset), kScratchRegister); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3752 | Integer32ToSmi(scratch1, length); |
| 3753 | movq(FieldOperand(result, String::kLengthOffset), scratch1); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3754 | movq(FieldOperand(result, String::kHashFieldOffset), |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 3755 | Immediate(String::kEmptyHashField)); |
| 3756 | } |
| 3757 | |
| 3758 | |
| 3759 | void MacroAssembler::AllocateAsciiString(Register result, |
| 3760 | Register length, |
| 3761 | Register scratch1, |
| 3762 | Register scratch2, |
| 3763 | Register scratch3, |
| 3764 | Label* gc_required) { |
| 3765 | // Calculate the number of bytes needed for the characters in the string while |
| 3766 | // observing object alignment. |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3767 | const int kHeaderAlignment = SeqAsciiString::kHeaderSize & |
| 3768 | kObjectAlignmentMask; |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 3769 | movl(scratch1, length); |
| 3770 | ASSERT(kCharSize == 1); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3771 | addq(scratch1, Immediate(kObjectAlignmentMask + kHeaderAlignment)); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 3772 | and_(scratch1, Immediate(~kObjectAlignmentMask)); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3773 | if (kHeaderAlignment > 0) { |
| 3774 | subq(scratch1, Immediate(kHeaderAlignment)); |
| 3775 | } |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 3776 | |
| 3777 | // Allocate ascii string in new space. |
| 3778 | AllocateInNewSpace(SeqAsciiString::kHeaderSize, |
| 3779 | times_1, |
| 3780 | scratch1, |
| 3781 | result, |
| 3782 | scratch2, |
| 3783 | scratch3, |
| 3784 | gc_required, |
| 3785 | TAG_OBJECT); |
| 3786 | |
| 3787 | // Set the map, length and hash field. |
| 3788 | LoadRoot(kScratchRegister, Heap::kAsciiStringMapRootIndex); |
| 3789 | movq(FieldOperand(result, HeapObject::kMapOffset), kScratchRegister); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3790 | Integer32ToSmi(scratch1, length); |
| 3791 | movq(FieldOperand(result, String::kLengthOffset), scratch1); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3792 | movq(FieldOperand(result, String::kHashFieldOffset), |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 3793 | Immediate(String::kEmptyHashField)); |
| 3794 | } |
| 3795 | |
| 3796 | |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 3797 | void MacroAssembler::AllocateTwoByteConsString(Register result, |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 3798 | Register scratch1, |
| 3799 | Register scratch2, |
| 3800 | Label* gc_required) { |
| 3801 | // Allocate heap number in new space. |
| 3802 | AllocateInNewSpace(ConsString::kSize, |
| 3803 | result, |
| 3804 | scratch1, |
| 3805 | scratch2, |
| 3806 | gc_required, |
| 3807 | TAG_OBJECT); |
| 3808 | |
| 3809 | // Set the map. The other fields are left uninitialized. |
| 3810 | LoadRoot(kScratchRegister, Heap::kConsStringMapRootIndex); |
| 3811 | movq(FieldOperand(result, HeapObject::kMapOffset), kScratchRegister); |
| 3812 | } |
| 3813 | |
| 3814 | |
| 3815 | void MacroAssembler::AllocateAsciiConsString(Register result, |
| 3816 | Register scratch1, |
| 3817 | Register scratch2, |
| 3818 | Label* gc_required) { |
| 3819 | // Allocate heap number in new space. |
| 3820 | AllocateInNewSpace(ConsString::kSize, |
| 3821 | result, |
| 3822 | scratch1, |
| 3823 | scratch2, |
| 3824 | gc_required, |
| 3825 | TAG_OBJECT); |
| 3826 | |
| 3827 | // Set the map. The other fields are left uninitialized. |
| 3828 | LoadRoot(kScratchRegister, Heap::kConsAsciiStringMapRootIndex); |
| 3829 | movq(FieldOperand(result, HeapObject::kMapOffset), kScratchRegister); |
| 3830 | } |
| 3831 | |
| 3832 | |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 3833 | void MacroAssembler::AllocateTwoByteSlicedString(Register result, |
| 3834 | Register scratch1, |
| 3835 | Register scratch2, |
| 3836 | Label* gc_required) { |
| 3837 | // Allocate heap number in new space. |
| 3838 | AllocateInNewSpace(SlicedString::kSize, |
| 3839 | result, |
| 3840 | scratch1, |
| 3841 | scratch2, |
| 3842 | gc_required, |
| 3843 | TAG_OBJECT); |
| 3844 | |
| 3845 | // Set the map. The other fields are left uninitialized. |
| 3846 | LoadRoot(kScratchRegister, Heap::kSlicedStringMapRootIndex); |
| 3847 | movq(FieldOperand(result, HeapObject::kMapOffset), kScratchRegister); |
| 3848 | } |
| 3849 | |
| 3850 | |
| 3851 | void MacroAssembler::AllocateAsciiSlicedString(Register result, |
| 3852 | Register scratch1, |
| 3853 | Register scratch2, |
| 3854 | Label* gc_required) { |
| 3855 | // Allocate heap number in new space. |
| 3856 | AllocateInNewSpace(SlicedString::kSize, |
| 3857 | result, |
| 3858 | scratch1, |
| 3859 | scratch2, |
| 3860 | gc_required, |
| 3861 | TAG_OBJECT); |
| 3862 | |
| 3863 | // Set the map. The other fields are left uninitialized. |
| 3864 | LoadRoot(kScratchRegister, Heap::kSlicedAsciiStringMapRootIndex); |
| 3865 | movq(FieldOperand(result, HeapObject::kMapOffset), kScratchRegister); |
| 3866 | } |
| 3867 | |
| 3868 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3869 | // Copy memory, byte-by-byte, from source to destination. Not optimized for |
| 3870 | // long or aligned copies. The contents of scratch and length are destroyed. |
| 3871 | // Destination is incremented by length, source, length and scratch are |
| 3872 | // clobbered. |
| 3873 | // A simpler loop is faster on small copies, but slower on large ones. |
| 3874 | // The cld() instruction must have been emitted, to set the direction flag(), |
| 3875 | // before calling this function. |
| 3876 | void MacroAssembler::CopyBytes(Register destination, |
| 3877 | Register source, |
| 3878 | Register length, |
| 3879 | int min_length, |
| 3880 | Register scratch) { |
| 3881 | ASSERT(min_length >= 0); |
| 3882 | if (FLAG_debug_code) { |
| 3883 | cmpl(length, Immediate(min_length)); |
| 3884 | Assert(greater_equal, "Invalid min_length"); |
| 3885 | } |
| 3886 | Label loop, done, short_string, short_loop; |
| 3887 | |
| 3888 | const int kLongStringLimit = 20; |
| 3889 | if (min_length <= kLongStringLimit) { |
| 3890 | cmpl(length, Immediate(kLongStringLimit)); |
| 3891 | j(less_equal, &short_string); |
| 3892 | } |
| 3893 | |
| 3894 | ASSERT(source.is(rsi)); |
| 3895 | ASSERT(destination.is(rdi)); |
| 3896 | ASSERT(length.is(rcx)); |
| 3897 | |
| 3898 | // Because source is 8-byte aligned in our uses of this function, |
| 3899 | // we keep source aligned for the rep movs operation by copying the odd bytes |
| 3900 | // at the end of the ranges. |
| 3901 | movq(scratch, length); |
| 3902 | shrl(length, Immediate(3)); |
| 3903 | repmovsq(); |
| 3904 | // Move remaining bytes of length. |
| 3905 | andl(scratch, Immediate(0x7)); |
| 3906 | movq(length, Operand(source, scratch, times_1, -8)); |
| 3907 | movq(Operand(destination, scratch, times_1, -8), length); |
| 3908 | addq(destination, scratch); |
| 3909 | |
| 3910 | if (min_length <= kLongStringLimit) { |
| 3911 | jmp(&done); |
| 3912 | |
| 3913 | bind(&short_string); |
| 3914 | if (min_length == 0) { |
| 3915 | testl(length, length); |
| 3916 | j(zero, &done); |
| 3917 | } |
| 3918 | lea(scratch, Operand(destination, length, times_1, 0)); |
| 3919 | |
| 3920 | bind(&short_loop); |
| 3921 | movb(length, Operand(source, 0)); |
| 3922 | movb(Operand(destination, 0), length); |
| 3923 | incq(source); |
| 3924 | incq(destination); |
| 3925 | cmpq(destination, scratch); |
| 3926 | j(not_equal, &short_loop); |
| 3927 | |
| 3928 | bind(&done); |
| 3929 | } |
| 3930 | } |
| 3931 | |
| 3932 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3933 | void MacroAssembler::InitializeFieldsWithFiller(Register start_offset, |
| 3934 | Register end_offset, |
| 3935 | Register filler) { |
| 3936 | Label loop, entry; |
| 3937 | jmp(&entry); |
| 3938 | bind(&loop); |
| 3939 | movq(Operand(start_offset, 0), filler); |
| 3940 | addq(start_offset, Immediate(kPointerSize)); |
| 3941 | bind(&entry); |
| 3942 | cmpq(start_offset, end_offset); |
| 3943 | j(less, &loop); |
| 3944 | } |
| 3945 | |
| 3946 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 3947 | void MacroAssembler::LoadContext(Register dst, int context_chain_length) { |
| 3948 | if (context_chain_length > 0) { |
| 3949 | // Move up the chain of contexts to the context containing the slot. |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 3950 | movq(dst, Operand(rsi, Context::SlotOffset(Context::PREVIOUS_INDEX))); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 3951 | for (int i = 1; i < context_chain_length; i++) { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 3952 | movq(dst, Operand(dst, Context::SlotOffset(Context::PREVIOUS_INDEX))); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 3953 | } |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 3954 | } else { |
| 3955 | // Slot is in the current function context. Move it into the |
| 3956 | // destination register in case we store into it (the write barrier |
| 3957 | // cannot be allowed to destroy the context in rsi). |
| 3958 | movq(dst, rsi); |
| 3959 | } |
| 3960 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 3961 | // We should not have found a with context by walking the context |
| 3962 | // chain (i.e., the static scope chain and runtime context chain do |
| 3963 | // not agree). A variable occurring in such a scope should have |
| 3964 | // slot type LOOKUP and not CONTEXT. |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 3965 | if (emit_debug_code()) { |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 3966 | CompareRoot(FieldOperand(dst, HeapObject::kMapOffset), |
| 3967 | Heap::kWithContextMapRootIndex); |
| 3968 | Check(not_equal, "Variable resolved to with context."); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 3969 | } |
| 3970 | } |
| 3971 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3972 | #ifdef _WIN64 |
| 3973 | static const int kRegisterPassedArguments = 4; |
| 3974 | #else |
| 3975 | static const int kRegisterPassedArguments = 6; |
| 3976 | #endif |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3977 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3978 | void MacroAssembler::LoadGlobalFunction(int index, Register function) { |
| 3979 | // Load the global or builtins object from the current context. |
| 3980 | movq(function, Operand(rsi, Context::SlotOffset(Context::GLOBAL_INDEX))); |
| 3981 | // Load the global context from the global or builtins object. |
| 3982 | movq(function, FieldOperand(function, GlobalObject::kGlobalContextOffset)); |
| 3983 | // Load the function from the global context. |
| 3984 | movq(function, Operand(function, Context::SlotOffset(index))); |
| 3985 | } |
| 3986 | |
| 3987 | |
| 3988 | void MacroAssembler::LoadGlobalFunctionInitialMap(Register function, |
| 3989 | Register map) { |
| 3990 | // Load the initial map. The global functions all have initial maps. |
| 3991 | movq(map, FieldOperand(function, JSFunction::kPrototypeOrInitialMapOffset)); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 3992 | if (emit_debug_code()) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3993 | Label ok, fail; |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3994 | CheckMap(map, isolate()->factory()->meta_map(), &fail, DO_SMI_CHECK); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3995 | jmp(&ok); |
| 3996 | bind(&fail); |
| 3997 | Abort("Global functions must have initial map"); |
| 3998 | bind(&ok); |
| 3999 | } |
| 4000 | } |
| 4001 | |
| 4002 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4003 | int MacroAssembler::ArgumentStackSlotsForCFunctionCall(int num_arguments) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4004 | // On Windows 64 stack slots are reserved by the caller for all arguments |
| 4005 | // including the ones passed in registers, and space is always allocated for |
| 4006 | // the four register arguments even if the function takes fewer than four |
| 4007 | // arguments. |
| 4008 | // On AMD64 ABI (Linux/Mac) the first six arguments are passed in registers |
| 4009 | // and the caller does not reserve stack slots for them. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4010 | ASSERT(num_arguments >= 0); |
| 4011 | #ifdef _WIN64 |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4012 | const int kMinimumStackSlots = kRegisterPassedArguments; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4013 | if (num_arguments < kMinimumStackSlots) return kMinimumStackSlots; |
| 4014 | return num_arguments; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4015 | #else |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4016 | if (num_arguments < kRegisterPassedArguments) return 0; |
| 4017 | return num_arguments - kRegisterPassedArguments; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4018 | #endif |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4019 | } |
| 4020 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4021 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4022 | void MacroAssembler::PrepareCallCFunction(int num_arguments) { |
| 4023 | int frame_alignment = OS::ActivationFrameAlignment(); |
| 4024 | ASSERT(frame_alignment != 0); |
| 4025 | ASSERT(num_arguments >= 0); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4026 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4027 | // Make stack end at alignment and allocate space for arguments and old rsp. |
| 4028 | movq(kScratchRegister, rsp); |
| 4029 | ASSERT(IsPowerOf2(frame_alignment)); |
| 4030 | int argument_slots_on_stack = |
| 4031 | ArgumentStackSlotsForCFunctionCall(num_arguments); |
| 4032 | subq(rsp, Immediate((argument_slots_on_stack + 1) * kPointerSize)); |
| 4033 | and_(rsp, Immediate(-frame_alignment)); |
| 4034 | movq(Operand(rsp, argument_slots_on_stack * kPointerSize), kScratchRegister); |
| 4035 | } |
| 4036 | |
| 4037 | |
| 4038 | void MacroAssembler::CallCFunction(ExternalReference function, |
| 4039 | int num_arguments) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4040 | LoadAddress(rax, function); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4041 | CallCFunction(rax, num_arguments); |
| 4042 | } |
| 4043 | |
| 4044 | |
| 4045 | void MacroAssembler::CallCFunction(Register function, int num_arguments) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4046 | ASSERT(has_frame()); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 4047 | // Check stack alignment. |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 4048 | if (emit_debug_code()) { |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 4049 | CheckStackAlignment(); |
| 4050 | } |
| 4051 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4052 | call(function); |
| 4053 | ASSERT(OS::ActivationFrameAlignment() != 0); |
| 4054 | ASSERT(num_arguments >= 0); |
| 4055 | int argument_slots_on_stack = |
| 4056 | ArgumentStackSlotsForCFunctionCall(num_arguments); |
| 4057 | movq(rsp, Operand(rsp, argument_slots_on_stack * kPointerSize)); |
| 4058 | } |
| 4059 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 4060 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4061 | bool AreAliased(Register r1, Register r2, Register r3, Register r4) { |
| 4062 | if (r1.is(r2)) return true; |
| 4063 | if (r1.is(r3)) return true; |
| 4064 | if (r1.is(r4)) return true; |
| 4065 | if (r2.is(r3)) return true; |
| 4066 | if (r2.is(r4)) return true; |
| 4067 | if (r3.is(r4)) return true; |
| 4068 | return false; |
| 4069 | } |
| 4070 | |
| 4071 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 4072 | CodePatcher::CodePatcher(byte* address, int size) |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 4073 | : address_(address), |
| 4074 | size_(size), |
| 4075 | masm_(Isolate::Current(), address, size + Assembler::kGap) { |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 4076 | // Create a new macro assembler pointing to the address of the code to patch. |
| 4077 | // The size is adjusted with kGap on order for the assembler to generate size |
| 4078 | // bytes of instructions without failing with buffer size constraints. |
| 4079 | ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap); |
| 4080 | } |
| 4081 | |
| 4082 | |
| 4083 | CodePatcher::~CodePatcher() { |
| 4084 | // Indicate that code has changed. |
| 4085 | CPU::FlushICache(address_, size_); |
| 4086 | |
| 4087 | // Check that the code was patched as expected. |
| 4088 | ASSERT(masm_.pc_ == address_ + size_); |
| 4089 | ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap); |
| 4090 | } |
| 4091 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4092 | |
| 4093 | void MacroAssembler::CheckPageFlag( |
| 4094 | Register object, |
| 4095 | Register scratch, |
| 4096 | int mask, |
| 4097 | Condition cc, |
| 4098 | Label* condition_met, |
| 4099 | Label::Distance condition_met_distance) { |
| 4100 | ASSERT(cc == zero || cc == not_zero); |
| 4101 | if (scratch.is(object)) { |
| 4102 | and_(scratch, Immediate(~Page::kPageAlignmentMask)); |
| 4103 | } else { |
| 4104 | movq(scratch, Immediate(~Page::kPageAlignmentMask)); |
| 4105 | and_(scratch, object); |
| 4106 | } |
| 4107 | if (mask < (1 << kBitsPerByte)) { |
| 4108 | testb(Operand(scratch, MemoryChunk::kFlagsOffset), |
| 4109 | Immediate(static_cast<uint8_t>(mask))); |
| 4110 | } else { |
| 4111 | testl(Operand(scratch, MemoryChunk::kFlagsOffset), Immediate(mask)); |
| 4112 | } |
| 4113 | j(cc, condition_met, condition_met_distance); |
| 4114 | } |
| 4115 | |
| 4116 | |
| 4117 | void MacroAssembler::JumpIfBlack(Register object, |
| 4118 | Register bitmap_scratch, |
| 4119 | Register mask_scratch, |
| 4120 | Label* on_black, |
| 4121 | Label::Distance on_black_distance) { |
| 4122 | ASSERT(!AreAliased(object, bitmap_scratch, mask_scratch, rcx)); |
| 4123 | GetMarkBits(object, bitmap_scratch, mask_scratch); |
| 4124 | |
| 4125 | ASSERT(strcmp(Marking::kBlackBitPattern, "10") == 0); |
| 4126 | // The mask_scratch register contains a 1 at the position of the first bit |
| 4127 | // and a 0 at all other positions, including the position of the second bit. |
| 4128 | movq(rcx, mask_scratch); |
| 4129 | // Make rcx into a mask that covers both marking bits using the operation |
| 4130 | // rcx = mask | (mask << 1). |
| 4131 | lea(rcx, Operand(mask_scratch, mask_scratch, times_2, 0)); |
| 4132 | // Note that we are using a 4-byte aligned 8-byte load. |
| 4133 | and_(rcx, Operand(bitmap_scratch, MemoryChunk::kHeaderSize)); |
| 4134 | cmpq(mask_scratch, rcx); |
| 4135 | j(equal, on_black, on_black_distance); |
| 4136 | } |
| 4137 | |
| 4138 | |
| 4139 | // Detect some, but not all, common pointer-free objects. This is used by the |
| 4140 | // incremental write barrier which doesn't care about oddballs (they are always |
| 4141 | // marked black immediately so this code is not hit). |
| 4142 | void MacroAssembler::JumpIfDataObject( |
| 4143 | Register value, |
| 4144 | Register scratch, |
| 4145 | Label* not_data_object, |
| 4146 | Label::Distance not_data_object_distance) { |
| 4147 | Label is_data_object; |
| 4148 | movq(scratch, FieldOperand(value, HeapObject::kMapOffset)); |
| 4149 | CompareRoot(scratch, Heap::kHeapNumberMapRootIndex); |
| 4150 | j(equal, &is_data_object, Label::kNear); |
| 4151 | ASSERT(kIsIndirectStringTag == 1 && kIsIndirectStringMask == 1); |
| 4152 | ASSERT(kNotStringTag == 0x80 && kIsNotStringMask == 0x80); |
| 4153 | // If it's a string and it's not a cons string then it's an object containing |
| 4154 | // no GC pointers. |
| 4155 | testb(FieldOperand(scratch, Map::kInstanceTypeOffset), |
| 4156 | Immediate(kIsIndirectStringMask | kIsNotStringMask)); |
| 4157 | j(not_zero, not_data_object, not_data_object_distance); |
| 4158 | bind(&is_data_object); |
| 4159 | } |
| 4160 | |
| 4161 | |
| 4162 | void MacroAssembler::GetMarkBits(Register addr_reg, |
| 4163 | Register bitmap_reg, |
| 4164 | Register mask_reg) { |
| 4165 | ASSERT(!AreAliased(addr_reg, bitmap_reg, mask_reg, rcx)); |
| 4166 | movq(bitmap_reg, addr_reg); |
| 4167 | // Sign extended 32 bit immediate. |
| 4168 | and_(bitmap_reg, Immediate(~Page::kPageAlignmentMask)); |
| 4169 | movq(rcx, addr_reg); |
| 4170 | int shift = |
| 4171 | Bitmap::kBitsPerCellLog2 + kPointerSizeLog2 - Bitmap::kBytesPerCellLog2; |
| 4172 | shrl(rcx, Immediate(shift)); |
| 4173 | and_(rcx, |
| 4174 | Immediate((Page::kPageAlignmentMask >> shift) & |
| 4175 | ~(Bitmap::kBytesPerCell - 1))); |
| 4176 | |
| 4177 | addq(bitmap_reg, rcx); |
| 4178 | movq(rcx, addr_reg); |
| 4179 | shrl(rcx, Immediate(kPointerSizeLog2)); |
| 4180 | and_(rcx, Immediate((1 << Bitmap::kBitsPerCellLog2) - 1)); |
| 4181 | movl(mask_reg, Immediate(1)); |
| 4182 | shl_cl(mask_reg); |
| 4183 | } |
| 4184 | |
| 4185 | |
| 4186 | void MacroAssembler::EnsureNotWhite( |
| 4187 | Register value, |
| 4188 | Register bitmap_scratch, |
| 4189 | Register mask_scratch, |
| 4190 | Label* value_is_white_and_not_data, |
| 4191 | Label::Distance distance) { |
| 4192 | ASSERT(!AreAliased(value, bitmap_scratch, mask_scratch, rcx)); |
| 4193 | GetMarkBits(value, bitmap_scratch, mask_scratch); |
| 4194 | |
| 4195 | // If the value is black or grey we don't need to do anything. |
| 4196 | ASSERT(strcmp(Marking::kWhiteBitPattern, "00") == 0); |
| 4197 | ASSERT(strcmp(Marking::kBlackBitPattern, "10") == 0); |
| 4198 | ASSERT(strcmp(Marking::kGreyBitPattern, "11") == 0); |
| 4199 | ASSERT(strcmp(Marking::kImpossibleBitPattern, "01") == 0); |
| 4200 | |
| 4201 | Label done; |
| 4202 | |
| 4203 | // Since both black and grey have a 1 in the first position and white does |
| 4204 | // not have a 1 there we only need to check one bit. |
| 4205 | testq(Operand(bitmap_scratch, MemoryChunk::kHeaderSize), mask_scratch); |
| 4206 | j(not_zero, &done, Label::kNear); |
| 4207 | |
| 4208 | if (FLAG_debug_code) { |
| 4209 | // Check for impossible bit pattern. |
| 4210 | Label ok; |
| 4211 | push(mask_scratch); |
| 4212 | // shl. May overflow making the check conservative. |
| 4213 | addq(mask_scratch, mask_scratch); |
| 4214 | testq(Operand(bitmap_scratch, MemoryChunk::kHeaderSize), mask_scratch); |
| 4215 | j(zero, &ok, Label::kNear); |
| 4216 | int3(); |
| 4217 | bind(&ok); |
| 4218 | pop(mask_scratch); |
| 4219 | } |
| 4220 | |
| 4221 | // Value is white. We check whether it is data that doesn't need scanning. |
| 4222 | // Currently only checks for HeapNumber and non-cons strings. |
| 4223 | Register map = rcx; // Holds map while checking type. |
| 4224 | Register length = rcx; // Holds length of object after checking type. |
| 4225 | Label not_heap_number; |
| 4226 | Label is_data_object; |
| 4227 | |
| 4228 | // Check for heap-number |
| 4229 | movq(map, FieldOperand(value, HeapObject::kMapOffset)); |
| 4230 | CompareRoot(map, Heap::kHeapNumberMapRootIndex); |
| 4231 | j(not_equal, ¬_heap_number, Label::kNear); |
| 4232 | movq(length, Immediate(HeapNumber::kSize)); |
| 4233 | jmp(&is_data_object, Label::kNear); |
| 4234 | |
| 4235 | bind(¬_heap_number); |
| 4236 | // Check for strings. |
| 4237 | ASSERT(kIsIndirectStringTag == 1 && kIsIndirectStringMask == 1); |
| 4238 | ASSERT(kNotStringTag == 0x80 && kIsNotStringMask == 0x80); |
| 4239 | // If it's a string and it's not a cons string then it's an object containing |
| 4240 | // no GC pointers. |
| 4241 | Register instance_type = rcx; |
| 4242 | movzxbl(instance_type, FieldOperand(map, Map::kInstanceTypeOffset)); |
| 4243 | testb(instance_type, Immediate(kIsIndirectStringMask | kIsNotStringMask)); |
| 4244 | j(not_zero, value_is_white_and_not_data); |
| 4245 | // It's a non-indirect (non-cons and non-slice) string. |
| 4246 | // If it's external, the length is just ExternalString::kSize. |
| 4247 | // Otherwise it's String::kHeaderSize + string->length() * (1 or 2). |
| 4248 | Label not_external; |
| 4249 | // External strings are the only ones with the kExternalStringTag bit |
| 4250 | // set. |
| 4251 | ASSERT_EQ(0, kSeqStringTag & kExternalStringTag); |
| 4252 | ASSERT_EQ(0, kConsStringTag & kExternalStringTag); |
| 4253 | testb(instance_type, Immediate(kExternalStringTag)); |
| 4254 | j(zero, ¬_external, Label::kNear); |
| 4255 | movq(length, Immediate(ExternalString::kSize)); |
| 4256 | jmp(&is_data_object, Label::kNear); |
| 4257 | |
| 4258 | bind(¬_external); |
| 4259 | // Sequential string, either ASCII or UC16. |
| 4260 | ASSERT(kAsciiStringTag == 0x04); |
| 4261 | and_(length, Immediate(kStringEncodingMask)); |
| 4262 | xor_(length, Immediate(kStringEncodingMask)); |
| 4263 | addq(length, Immediate(0x04)); |
| 4264 | // Value now either 4 (if ASCII) or 8 (if UC16), i.e. char-size shifted by 2. |
| 4265 | imul(length, FieldOperand(value, String::kLengthOffset)); |
| 4266 | shr(length, Immediate(2 + kSmiTagSize + kSmiShiftSize)); |
| 4267 | addq(length, Immediate(SeqString::kHeaderSize + kObjectAlignmentMask)); |
| 4268 | and_(length, Immediate(~kObjectAlignmentMask)); |
| 4269 | |
| 4270 | bind(&is_data_object); |
| 4271 | // Value is a data object, and it is white. Mark it black. Since we know |
| 4272 | // that the object is white we can make it black by flipping one bit. |
| 4273 | or_(Operand(bitmap_scratch, MemoryChunk::kHeaderSize), mask_scratch); |
| 4274 | |
| 4275 | and_(bitmap_scratch, Immediate(~Page::kPageAlignmentMask)); |
| 4276 | addl(Operand(bitmap_scratch, MemoryChunk::kLiveBytesOffset), length); |
| 4277 | |
| 4278 | bind(&done); |
| 4279 | } |
| 4280 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 4281 | } } // namespace v8::internal |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4282 | |
| 4283 | #endif // V8_TARGET_ARCH_X64 |