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