Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5 | #include "src/v8.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7 | #if V8_TARGET_ARCH_IA32 |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 8 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9 | #include "src/base/bits.h" |
| 10 | #include "src/base/division-by-constant.h" |
| 11 | #include "src/bootstrapper.h" |
| 12 | #include "src/codegen.h" |
| 13 | #include "src/cpu-profiler.h" |
| 14 | #include "src/debug.h" |
| 15 | #include "src/isolate-inl.h" |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 16 | #include "src/runtime/runtime.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 17 | #include "src/serialize.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 18 | |
| 19 | namespace v8 { |
| 20 | namespace internal { |
| 21 | |
| 22 | // ------------------------------------------------------------------------- |
| 23 | // MacroAssembler implementation. |
| 24 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 25 | MacroAssembler::MacroAssembler(Isolate* arg_isolate, void* buffer, int size) |
| 26 | : Assembler(arg_isolate, buffer, size), |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 27 | generating_stub_(false), |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 28 | has_frame_(false) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 29 | if (isolate() != NULL) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 30 | // TODO(titzer): should we just use a null handle here instead? |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 31 | code_object_ = Handle<Object>(isolate()->heap()->undefined_value(), |
| 32 | isolate()); |
| 33 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 37 | void MacroAssembler::Load(Register dst, const Operand& src, Representation r) { |
| 38 | DCHECK(!r.IsDouble()); |
| 39 | if (r.IsInteger8()) { |
| 40 | movsx_b(dst, src); |
| 41 | } else if (r.IsUInteger8()) { |
| 42 | movzx_b(dst, src); |
| 43 | } else if (r.IsInteger16()) { |
| 44 | movsx_w(dst, src); |
| 45 | } else if (r.IsUInteger16()) { |
| 46 | movzx_w(dst, src); |
| 47 | } else { |
| 48 | mov(dst, src); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | |
| 53 | void MacroAssembler::Store(Register src, const Operand& dst, Representation r) { |
| 54 | DCHECK(!r.IsDouble()); |
| 55 | if (r.IsInteger8() || r.IsUInteger8()) { |
| 56 | mov_b(dst, src); |
| 57 | } else if (r.IsInteger16() || r.IsUInteger16()) { |
| 58 | mov_w(dst, src); |
| 59 | } else { |
| 60 | if (r.IsHeapObject()) { |
| 61 | AssertNotSmi(src); |
| 62 | } else if (r.IsSmi()) { |
| 63 | AssertSmi(src); |
| 64 | } |
| 65 | mov(dst, src); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | |
| 70 | void MacroAssembler::LoadRoot(Register destination, Heap::RootListIndex index) { |
| 71 | if (isolate()->heap()->RootCanBeTreatedAsConstant(index)) { |
| 72 | Handle<Object> value(&isolate()->heap()->roots_array_start()[index]); |
| 73 | mov(destination, value); |
| 74 | return; |
| 75 | } |
| 76 | ExternalReference roots_array_start = |
| 77 | ExternalReference::roots_array_start(isolate()); |
| 78 | mov(destination, Immediate(index)); |
| 79 | mov(destination, Operand::StaticArray(destination, |
| 80 | times_pointer_size, |
| 81 | roots_array_start)); |
| 82 | } |
| 83 | |
| 84 | |
| 85 | void MacroAssembler::StoreRoot(Register source, |
| 86 | Register scratch, |
| 87 | Heap::RootListIndex index) { |
| 88 | DCHECK(Heap::RootCanBeWrittenAfterInitialization(index)); |
| 89 | ExternalReference roots_array_start = |
| 90 | ExternalReference::roots_array_start(isolate()); |
| 91 | mov(scratch, Immediate(index)); |
| 92 | mov(Operand::StaticArray(scratch, times_pointer_size, roots_array_start), |
| 93 | source); |
| 94 | } |
| 95 | |
| 96 | |
| 97 | void MacroAssembler::CompareRoot(Register with, |
| 98 | Register scratch, |
| 99 | Heap::RootListIndex index) { |
| 100 | ExternalReference roots_array_start = |
| 101 | ExternalReference::roots_array_start(isolate()); |
| 102 | mov(scratch, Immediate(index)); |
| 103 | cmp(with, Operand::StaticArray(scratch, |
| 104 | times_pointer_size, |
| 105 | roots_array_start)); |
| 106 | } |
| 107 | |
| 108 | |
| 109 | void MacroAssembler::CompareRoot(Register with, Heap::RootListIndex index) { |
| 110 | DCHECK(isolate()->heap()->RootCanBeTreatedAsConstant(index)); |
| 111 | Handle<Object> value(&isolate()->heap()->roots_array_start()[index]); |
| 112 | cmp(with, value); |
| 113 | } |
| 114 | |
| 115 | |
| 116 | void MacroAssembler::CompareRoot(const Operand& with, |
| 117 | Heap::RootListIndex index) { |
| 118 | DCHECK(isolate()->heap()->RootCanBeTreatedAsConstant(index)); |
| 119 | Handle<Object> value(&isolate()->heap()->roots_array_start()[index]); |
| 120 | cmp(with, value); |
| 121 | } |
| 122 | |
| 123 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 124 | void MacroAssembler::InNewSpace( |
| 125 | Register object, |
| 126 | Register scratch, |
| 127 | Condition cc, |
| 128 | Label* condition_met, |
| 129 | Label::Distance condition_met_distance) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 130 | DCHECK(cc == equal || cc == not_equal); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 131 | if (scratch.is(object)) { |
| 132 | and_(scratch, Immediate(~Page::kPageAlignmentMask)); |
| 133 | } else { |
| 134 | mov(scratch, Immediate(~Page::kPageAlignmentMask)); |
| 135 | and_(scratch, object); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 136 | } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 137 | // Check that we can use a test_b. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 138 | DCHECK(MemoryChunk::IN_FROM_SPACE < 8); |
| 139 | DCHECK(MemoryChunk::IN_TO_SPACE < 8); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 140 | int mask = (1 << MemoryChunk::IN_FROM_SPACE) |
| 141 | | (1 << MemoryChunk::IN_TO_SPACE); |
| 142 | // If non-zero, the page belongs to new-space. |
| 143 | test_b(Operand(scratch, MemoryChunk::kFlagsOffset), |
| 144 | static_cast<uint8_t>(mask)); |
| 145 | j(cc, condition_met, condition_met_distance); |
| 146 | } |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 147 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 148 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 149 | void MacroAssembler::RememberedSetHelper( |
| 150 | Register object, // Only used for debug checks. |
| 151 | Register addr, |
| 152 | Register scratch, |
| 153 | SaveFPRegsMode save_fp, |
| 154 | MacroAssembler::RememberedSetFinalAction and_then) { |
| 155 | Label done; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 156 | if (emit_debug_code()) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 157 | Label ok; |
| 158 | JumpIfNotInNewSpace(object, scratch, &ok, Label::kNear); |
| 159 | int3(); |
| 160 | bind(&ok); |
| 161 | } |
| 162 | // Load store buffer top. |
| 163 | ExternalReference store_buffer = |
| 164 | ExternalReference::store_buffer_top(isolate()); |
| 165 | mov(scratch, Operand::StaticVariable(store_buffer)); |
| 166 | // Store pointer to buffer. |
| 167 | mov(Operand(scratch, 0), addr); |
| 168 | // Increment buffer top. |
| 169 | add(scratch, Immediate(kPointerSize)); |
| 170 | // Write back new top of buffer. |
| 171 | mov(Operand::StaticVariable(store_buffer), scratch); |
| 172 | // Call stub on end of buffer. |
| 173 | // Check for end of buffer. |
| 174 | test(scratch, Immediate(StoreBuffer::kStoreBufferOverflowBit)); |
| 175 | if (and_then == kReturnAtEnd) { |
| 176 | Label buffer_overflowed; |
| 177 | j(not_equal, &buffer_overflowed, Label::kNear); |
| 178 | ret(0); |
| 179 | bind(&buffer_overflowed); |
| 180 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 181 | DCHECK(and_then == kFallThroughAtEnd); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 182 | j(equal, &done, Label::kNear); |
| 183 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 184 | StoreBufferOverflowStub store_buffer_overflow(isolate(), save_fp); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 185 | CallStub(&store_buffer_overflow); |
| 186 | if (and_then == kReturnAtEnd) { |
| 187 | ret(0); |
| 188 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 189 | DCHECK(and_then == kFallThroughAtEnd); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 190 | bind(&done); |
| 191 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | |
| 195 | void MacroAssembler::ClampDoubleToUint8(XMMRegister input_reg, |
| 196 | XMMRegister scratch_reg, |
| 197 | Register result_reg) { |
| 198 | Label done; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 199 | Label conv_failure; |
| 200 | xorps(scratch_reg, scratch_reg); |
| 201 | cvtsd2si(result_reg, input_reg); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 202 | test(result_reg, Immediate(0xFFFFFF00)); |
| 203 | j(zero, &done, Label::kNear); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 204 | cmp(result_reg, Immediate(0x1)); |
| 205 | j(overflow, &conv_failure, Label::kNear); |
| 206 | mov(result_reg, Immediate(0)); |
| 207 | setcc(sign, result_reg); |
| 208 | sub(result_reg, Immediate(1)); |
| 209 | and_(result_reg, Immediate(255)); |
| 210 | jmp(&done, Label::kNear); |
| 211 | bind(&conv_failure); |
| 212 | Move(result_reg, Immediate(0)); |
| 213 | ucomisd(input_reg, scratch_reg); |
| 214 | j(below, &done, Label::kNear); |
| 215 | Move(result_reg, Immediate(255)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 216 | bind(&done); |
| 217 | } |
| 218 | |
| 219 | |
| 220 | void MacroAssembler::ClampUint8(Register reg) { |
| 221 | Label done; |
| 222 | test(reg, Immediate(0xFFFFFF00)); |
| 223 | j(zero, &done, Label::kNear); |
| 224 | setcc(negative, reg); // 1 if negative, 0 if positive. |
| 225 | dec_b(reg); // 0 if negative, 255 if positive. |
| 226 | bind(&done); |
| 227 | } |
| 228 | |
| 229 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 230 | void MacroAssembler::SlowTruncateToI(Register result_reg, |
| 231 | Register input_reg, |
| 232 | int offset) { |
| 233 | DoubleToIStub stub(isolate(), input_reg, result_reg, offset, true); |
| 234 | call(stub.GetCode(), RelocInfo::CODE_TARGET); |
| 235 | } |
| 236 | |
| 237 | |
| 238 | void MacroAssembler::TruncateDoubleToI(Register result_reg, |
| 239 | XMMRegister input_reg) { |
| 240 | Label done; |
| 241 | cvttsd2si(result_reg, Operand(input_reg)); |
| 242 | cmp(result_reg, 0x1); |
| 243 | j(no_overflow, &done, Label::kNear); |
| 244 | |
| 245 | sub(esp, Immediate(kDoubleSize)); |
| 246 | movsd(MemOperand(esp, 0), input_reg); |
| 247 | SlowTruncateToI(result_reg, esp, 0); |
| 248 | add(esp, Immediate(kDoubleSize)); |
| 249 | bind(&done); |
| 250 | } |
| 251 | |
| 252 | |
| 253 | void MacroAssembler::DoubleToI(Register result_reg, XMMRegister input_reg, |
| 254 | XMMRegister scratch, |
| 255 | MinusZeroMode minus_zero_mode, |
| 256 | Label* lost_precision, Label* is_nan, |
| 257 | Label* minus_zero, Label::Distance dst) { |
| 258 | DCHECK(!input_reg.is(scratch)); |
| 259 | cvttsd2si(result_reg, Operand(input_reg)); |
| 260 | Cvtsi2sd(scratch, Operand(result_reg)); |
| 261 | ucomisd(scratch, input_reg); |
| 262 | j(not_equal, lost_precision, dst); |
| 263 | j(parity_even, is_nan, dst); |
| 264 | if (minus_zero_mode == FAIL_ON_MINUS_ZERO) { |
| 265 | Label done; |
| 266 | // The integer converted back is equal to the original. We |
| 267 | // only have to test if we got -0 as an input. |
| 268 | test(result_reg, Operand(result_reg)); |
| 269 | j(not_zero, &done, Label::kNear); |
| 270 | movmskpd(result_reg, input_reg); |
| 271 | // Bit 0 contains the sign of the double in input_reg. |
| 272 | // If input was positive, we are ok and return 0, otherwise |
| 273 | // jump to minus_zero. |
| 274 | and_(result_reg, 1); |
| 275 | j(not_zero, minus_zero, dst); |
| 276 | bind(&done); |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | |
| 281 | void MacroAssembler::TruncateHeapNumberToI(Register result_reg, |
| 282 | Register input_reg) { |
| 283 | Label done, slow_case; |
| 284 | |
| 285 | if (CpuFeatures::IsSupported(SSE3)) { |
| 286 | CpuFeatureScope scope(this, SSE3); |
| 287 | Label convert; |
| 288 | // Use more powerful conversion when sse3 is available. |
| 289 | // Load x87 register with heap number. |
| 290 | fld_d(FieldOperand(input_reg, HeapNumber::kValueOffset)); |
| 291 | // Get exponent alone and check for too-big exponent. |
| 292 | mov(result_reg, FieldOperand(input_reg, HeapNumber::kExponentOffset)); |
| 293 | and_(result_reg, HeapNumber::kExponentMask); |
| 294 | const uint32_t kTooBigExponent = |
| 295 | (HeapNumber::kExponentBias + 63) << HeapNumber::kExponentShift; |
| 296 | cmp(Operand(result_reg), Immediate(kTooBigExponent)); |
| 297 | j(greater_equal, &slow_case, Label::kNear); |
| 298 | |
| 299 | // Reserve space for 64 bit answer. |
| 300 | sub(Operand(esp), Immediate(kDoubleSize)); |
| 301 | // Do conversion, which cannot fail because we checked the exponent. |
| 302 | fisttp_d(Operand(esp, 0)); |
| 303 | mov(result_reg, Operand(esp, 0)); // Low word of answer is the result. |
| 304 | add(Operand(esp), Immediate(kDoubleSize)); |
| 305 | jmp(&done, Label::kNear); |
| 306 | |
| 307 | // Slow case. |
| 308 | bind(&slow_case); |
| 309 | if (input_reg.is(result_reg)) { |
| 310 | // Input is clobbered. Restore number from fpu stack |
| 311 | sub(Operand(esp), Immediate(kDoubleSize)); |
| 312 | fstp_d(Operand(esp, 0)); |
| 313 | SlowTruncateToI(result_reg, esp, 0); |
| 314 | add(esp, Immediate(kDoubleSize)); |
| 315 | } else { |
| 316 | fstp(0); |
| 317 | SlowTruncateToI(result_reg, input_reg); |
| 318 | } |
| 319 | } else { |
| 320 | movsd(xmm0, FieldOperand(input_reg, HeapNumber::kValueOffset)); |
| 321 | cvttsd2si(result_reg, Operand(xmm0)); |
| 322 | cmp(result_reg, 0x1); |
| 323 | j(no_overflow, &done, Label::kNear); |
| 324 | // Check if the input was 0x8000000 (kMinInt). |
| 325 | // If no, then we got an overflow and we deoptimize. |
| 326 | ExternalReference min_int = ExternalReference::address_of_min_int(); |
| 327 | ucomisd(xmm0, Operand::StaticVariable(min_int)); |
| 328 | j(not_equal, &slow_case, Label::kNear); |
| 329 | j(parity_even, &slow_case, Label::kNear); // NaN. |
| 330 | jmp(&done, Label::kNear); |
| 331 | |
| 332 | // Slow case. |
| 333 | bind(&slow_case); |
| 334 | if (input_reg.is(result_reg)) { |
| 335 | // Input is clobbered. Restore number from double scratch. |
| 336 | sub(esp, Immediate(kDoubleSize)); |
| 337 | movsd(MemOperand(esp, 0), xmm0); |
| 338 | SlowTruncateToI(result_reg, esp, 0); |
| 339 | add(esp, Immediate(kDoubleSize)); |
| 340 | } else { |
| 341 | SlowTruncateToI(result_reg, input_reg); |
| 342 | } |
| 343 | } |
| 344 | bind(&done); |
| 345 | } |
| 346 | |
| 347 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 348 | void MacroAssembler::LoadUint32(XMMRegister dst, const Operand& src) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 349 | Label done; |
| 350 | cmp(src, Immediate(0)); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 351 | ExternalReference uint32_bias = ExternalReference::address_of_uint32_bias(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 352 | Cvtsi2sd(dst, src); |
| 353 | j(not_sign, &done, Label::kNear); |
| 354 | addsd(dst, Operand::StaticVariable(uint32_bias)); |
| 355 | bind(&done); |
| 356 | } |
| 357 | |
| 358 | |
| 359 | void MacroAssembler::RecordWriteArray( |
| 360 | Register object, |
| 361 | Register value, |
| 362 | Register index, |
| 363 | SaveFPRegsMode save_fp, |
| 364 | RememberedSetAction remembered_set_action, |
| 365 | SmiCheck smi_check, |
| 366 | PointersToHereCheck pointers_to_here_check_for_value) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 367 | // First, check if a write barrier is even needed. The tests below |
| 368 | // catch stores of Smis. |
| 369 | Label done; |
| 370 | |
| 371 | // Skip barrier if writing a smi. |
| 372 | if (smi_check == INLINE_SMI_CHECK) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 373 | DCHECK_EQ(0, kSmiTag); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 374 | test(value, Immediate(kSmiTagMask)); |
| 375 | j(zero, &done); |
| 376 | } |
| 377 | |
| 378 | // Array access: calculate the destination address in the same manner as |
| 379 | // KeyedStoreIC::GenerateGeneric. Multiply a smi by 2 to get an offset |
| 380 | // into an array of words. |
| 381 | Register dst = index; |
| 382 | lea(dst, Operand(object, index, times_half_pointer_size, |
| 383 | FixedArray::kHeaderSize - kHeapObjectTag)); |
| 384 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 385 | RecordWrite(object, dst, value, save_fp, remembered_set_action, |
| 386 | OMIT_SMI_CHECK, pointers_to_here_check_for_value); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 387 | |
| 388 | bind(&done); |
| 389 | |
| 390 | // Clobber clobbered input registers when running with the debug-code flag |
| 391 | // turned on to provoke errors. |
| 392 | if (emit_debug_code()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 393 | mov(value, Immediate(bit_cast<int32_t>(kZapValue))); |
| 394 | mov(index, Immediate(bit_cast<int32_t>(kZapValue))); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 395 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 399 | void MacroAssembler::RecordWriteField( |
| 400 | Register object, |
| 401 | int offset, |
| 402 | Register value, |
| 403 | Register dst, |
| 404 | SaveFPRegsMode save_fp, |
| 405 | RememberedSetAction remembered_set_action, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 406 | SmiCheck smi_check, |
| 407 | PointersToHereCheck pointers_to_here_check_for_value) { |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 408 | // First, check if a write barrier is even needed. The tests below |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 409 | // catch stores of Smis. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 410 | Label done; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 411 | |
| 412 | // Skip barrier if writing a smi. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 413 | if (smi_check == INLINE_SMI_CHECK) { |
| 414 | JumpIfSmi(value, &done, Label::kNear); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 415 | } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 416 | |
| 417 | // Although the object register is tagged, the offset is relative to the start |
| 418 | // of the object, so so offset must be a multiple of kPointerSize. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 419 | DCHECK(IsAligned(offset, kPointerSize)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 420 | |
| 421 | lea(dst, FieldOperand(object, offset)); |
| 422 | if (emit_debug_code()) { |
| 423 | Label ok; |
| 424 | test_b(dst, (1 << kPointerSizeLog2) - 1); |
| 425 | j(zero, &ok, Label::kNear); |
| 426 | int3(); |
| 427 | bind(&ok); |
| 428 | } |
| 429 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 430 | RecordWrite(object, dst, value, save_fp, remembered_set_action, |
| 431 | OMIT_SMI_CHECK, pointers_to_here_check_for_value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 432 | |
| 433 | bind(&done); |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 434 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 435 | // Clobber clobbered input registers when running with the debug-code flag |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 436 | // turned on to provoke errors. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 437 | if (emit_debug_code()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 438 | mov(value, Immediate(bit_cast<int32_t>(kZapValue))); |
| 439 | mov(dst, Immediate(bit_cast<int32_t>(kZapValue))); |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 440 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 444 | void MacroAssembler::RecordWriteForMap( |
| 445 | Register object, |
| 446 | Handle<Map> map, |
| 447 | Register scratch1, |
| 448 | Register scratch2, |
| 449 | SaveFPRegsMode save_fp) { |
| 450 | Label done; |
| 451 | |
| 452 | Register address = scratch1; |
| 453 | Register value = scratch2; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 454 | if (emit_debug_code()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 455 | Label ok; |
| 456 | lea(address, FieldOperand(object, HeapObject::kMapOffset)); |
| 457 | test_b(address, (1 << kPointerSizeLog2) - 1); |
| 458 | j(zero, &ok, Label::kNear); |
| 459 | int3(); |
| 460 | bind(&ok); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 461 | } |
| 462 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 463 | DCHECK(!object.is(value)); |
| 464 | DCHECK(!object.is(address)); |
| 465 | DCHECK(!value.is(address)); |
| 466 | AssertNotSmi(object); |
| 467 | |
| 468 | if (!FLAG_incremental_marking) { |
| 469 | return; |
| 470 | } |
| 471 | |
| 472 | // Compute the address. |
| 473 | lea(address, FieldOperand(object, HeapObject::kMapOffset)); |
| 474 | |
| 475 | // A single check of the map's pages interesting flag suffices, since it is |
| 476 | // only set during incremental collection, and then it's also guaranteed that |
| 477 | // the from object's page's interesting flag is also set. This optimization |
| 478 | // relies on the fact that maps can never be in new space. |
| 479 | DCHECK(!isolate()->heap()->InNewSpace(*map)); |
| 480 | CheckPageFlagForMap(map, |
| 481 | MemoryChunk::kPointersToHereAreInterestingMask, |
| 482 | zero, |
| 483 | &done, |
| 484 | Label::kNear); |
| 485 | |
| 486 | RecordWriteStub stub(isolate(), object, value, address, OMIT_REMEMBERED_SET, |
| 487 | save_fp); |
| 488 | CallStub(&stub); |
| 489 | |
| 490 | bind(&done); |
| 491 | |
| 492 | // Count number of write barriers in generated code. |
| 493 | isolate()->counters()->write_barriers_static()->Increment(); |
| 494 | IncrementCounter(isolate()->counters()->write_barriers_dynamic(), 1); |
| 495 | |
| 496 | // Clobber clobbered input registers when running with the debug-code flag |
| 497 | // turned on to provoke errors. |
| 498 | if (emit_debug_code()) { |
| 499 | mov(value, Immediate(bit_cast<int32_t>(kZapValue))); |
| 500 | mov(scratch1, Immediate(bit_cast<int32_t>(kZapValue))); |
| 501 | mov(scratch2, Immediate(bit_cast<int32_t>(kZapValue))); |
| 502 | } |
| 503 | } |
| 504 | |
| 505 | |
| 506 | void MacroAssembler::RecordWrite( |
| 507 | Register object, |
| 508 | Register address, |
| 509 | Register value, |
| 510 | SaveFPRegsMode fp_mode, |
| 511 | RememberedSetAction remembered_set_action, |
| 512 | SmiCheck smi_check, |
| 513 | PointersToHereCheck pointers_to_here_check_for_value) { |
| 514 | DCHECK(!object.is(value)); |
| 515 | DCHECK(!object.is(address)); |
| 516 | DCHECK(!value.is(address)); |
| 517 | AssertNotSmi(object); |
| 518 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 519 | if (remembered_set_action == OMIT_REMEMBERED_SET && |
| 520 | !FLAG_incremental_marking) { |
| 521 | return; |
| 522 | } |
| 523 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 524 | if (emit_debug_code()) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 525 | Label ok; |
| 526 | cmp(value, Operand(address, 0)); |
| 527 | j(equal, &ok, Label::kNear); |
| 528 | int3(); |
| 529 | bind(&ok); |
| 530 | } |
| 531 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 532 | // First, check if a write barrier is even needed. The tests below |
| 533 | // catch stores of Smis and stores into young gen. |
| 534 | Label done; |
| 535 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 536 | if (smi_check == INLINE_SMI_CHECK) { |
| 537 | // Skip barrier if writing a smi. |
| 538 | JumpIfSmi(value, &done, Label::kNear); |
| 539 | } |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 540 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 541 | if (pointers_to_here_check_for_value != kPointersToHereAreAlwaysInteresting) { |
| 542 | CheckPageFlag(value, |
| 543 | value, // Used as scratch. |
| 544 | MemoryChunk::kPointersToHereAreInterestingMask, |
| 545 | zero, |
| 546 | &done, |
| 547 | Label::kNear); |
| 548 | } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 549 | CheckPageFlag(object, |
| 550 | value, // Used as scratch. |
| 551 | MemoryChunk::kPointersFromHereAreInterestingMask, |
| 552 | zero, |
| 553 | &done, |
| 554 | Label::kNear); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 555 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 556 | RecordWriteStub stub(isolate(), object, value, address, remembered_set_action, |
| 557 | fp_mode); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 558 | CallStub(&stub); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 559 | |
| 560 | bind(&done); |
| 561 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 562 | // Count number of write barriers in generated code. |
| 563 | isolate()->counters()->write_barriers_static()->Increment(); |
| 564 | IncrementCounter(isolate()->counters()->write_barriers_dynamic(), 1); |
| 565 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 566 | // Clobber clobbered registers when running with the debug-code flag |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 567 | // turned on to provoke errors. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 568 | if (emit_debug_code()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 569 | mov(address, Immediate(bit_cast<int32_t>(kZapValue))); |
| 570 | mov(value, Immediate(bit_cast<int32_t>(kZapValue))); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 571 | } |
| 572 | } |
| 573 | |
| 574 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 575 | void MacroAssembler::DebugBreak() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 576 | Move(eax, Immediate(0)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 577 | mov(ebx, Immediate(ExternalReference(Runtime::kDebugBreak, isolate()))); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 578 | CEntryStub ces(isolate(), 1); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 579 | call(ces.GetCode(), RelocInfo::DEBUG_BREAK); |
| 580 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 581 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 582 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 583 | void MacroAssembler::Cvtsi2sd(XMMRegister dst, const Operand& src) { |
| 584 | xorps(dst, dst); |
| 585 | cvtsi2sd(dst, src); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 586 | } |
| 587 | |
| 588 | |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 589 | bool MacroAssembler::IsUnsafeImmediate(const Immediate& x) { |
| 590 | static const int kMaxImmediateBits = 17; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 591 | if (!RelocInfo::IsNone(x.rmode_)) return false; |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 592 | return !is_intn(x.x_, kMaxImmediateBits); |
| 593 | } |
| 594 | |
| 595 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 596 | void MacroAssembler::SafeMove(Register dst, const Immediate& x) { |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 597 | if (IsUnsafeImmediate(x) && jit_cookie() != 0) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 598 | Move(dst, Immediate(x.x_ ^ jit_cookie())); |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 599 | xor_(dst, jit_cookie()); |
| 600 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 601 | Move(dst, x); |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 602 | } |
| 603 | } |
| 604 | |
| 605 | |
| 606 | void MacroAssembler::SafePush(const Immediate& x) { |
| 607 | if (IsUnsafeImmediate(x) && jit_cookie() != 0) { |
| 608 | push(Immediate(x.x_ ^ jit_cookie())); |
| 609 | xor_(Operand(esp, 0), Immediate(jit_cookie())); |
| 610 | } else { |
| 611 | push(x); |
| 612 | } |
| 613 | } |
| 614 | |
| 615 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 616 | void MacroAssembler::CmpObjectType(Register heap_object, |
| 617 | InstanceType type, |
| 618 | Register map) { |
| 619 | mov(map, FieldOperand(heap_object, HeapObject::kMapOffset)); |
| 620 | CmpInstanceType(map, type); |
| 621 | } |
| 622 | |
| 623 | |
| 624 | void MacroAssembler::CmpInstanceType(Register map, InstanceType type) { |
| 625 | cmpb(FieldOperand(map, Map::kInstanceTypeOffset), |
| 626 | static_cast<int8_t>(type)); |
| 627 | } |
| 628 | |
| 629 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 630 | void MacroAssembler::CheckFastElements(Register map, |
| 631 | Label* fail, |
| 632 | Label::Distance distance) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 633 | STATIC_ASSERT(FAST_SMI_ELEMENTS == 0); |
| 634 | STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1); |
| 635 | STATIC_ASSERT(FAST_ELEMENTS == 2); |
| 636 | STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 637 | cmpb(FieldOperand(map, Map::kBitField2Offset), |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 638 | Map::kMaximumBitField2FastHoleyElementValue); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 639 | j(above, fail, distance); |
| 640 | } |
| 641 | |
| 642 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 643 | void MacroAssembler::CheckFastObjectElements(Register map, |
| 644 | Label* fail, |
| 645 | Label::Distance distance) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 646 | STATIC_ASSERT(FAST_SMI_ELEMENTS == 0); |
| 647 | STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1); |
| 648 | STATIC_ASSERT(FAST_ELEMENTS == 2); |
| 649 | STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 650 | cmpb(FieldOperand(map, Map::kBitField2Offset), |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 651 | Map::kMaximumBitField2FastHoleySmiElementValue); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 652 | j(below_equal, fail, distance); |
| 653 | cmpb(FieldOperand(map, Map::kBitField2Offset), |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 654 | Map::kMaximumBitField2FastHoleyElementValue); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 655 | j(above, fail, distance); |
| 656 | } |
| 657 | |
| 658 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 659 | void MacroAssembler::CheckFastSmiElements(Register map, |
| 660 | Label* fail, |
| 661 | Label::Distance distance) { |
| 662 | STATIC_ASSERT(FAST_SMI_ELEMENTS == 0); |
| 663 | STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 664 | cmpb(FieldOperand(map, Map::kBitField2Offset), |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 665 | Map::kMaximumBitField2FastHoleySmiElementValue); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 666 | j(above, fail, distance); |
| 667 | } |
| 668 | |
| 669 | |
| 670 | void MacroAssembler::StoreNumberToDoubleElements( |
| 671 | Register maybe_number, |
| 672 | Register elements, |
| 673 | Register key, |
| 674 | Register scratch1, |
| 675 | XMMRegister scratch2, |
| 676 | Label* fail, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 677 | int elements_offset) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 678 | Label smi_value, done, maybe_nan, not_nan, is_nan, have_double_value; |
| 679 | JumpIfSmi(maybe_number, &smi_value, Label::kNear); |
| 680 | |
| 681 | CheckMap(maybe_number, |
| 682 | isolate()->factory()->heap_number_map(), |
| 683 | fail, |
| 684 | DONT_DO_SMI_CHECK); |
| 685 | |
| 686 | // Double value, canonicalize NaN. |
| 687 | uint32_t offset = HeapNumber::kValueOffset + sizeof(kHoleNanLower32); |
| 688 | cmp(FieldOperand(maybe_number, offset), |
| 689 | Immediate(kNaNOrInfinityLowerBoundUpper32)); |
| 690 | j(greater_equal, &maybe_nan, Label::kNear); |
| 691 | |
| 692 | bind(¬_nan); |
| 693 | ExternalReference canonical_nan_reference = |
| 694 | ExternalReference::address_of_canonical_non_hole_nan(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 695 | movsd(scratch2, FieldOperand(maybe_number, HeapNumber::kValueOffset)); |
| 696 | bind(&have_double_value); |
| 697 | movsd(FieldOperand(elements, key, times_4, |
| 698 | FixedDoubleArray::kHeaderSize - elements_offset), |
| 699 | scratch2); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 700 | jmp(&done); |
| 701 | |
| 702 | bind(&maybe_nan); |
| 703 | // Could be NaN or Infinity. If fraction is not zero, it's NaN, otherwise |
| 704 | // it's an Infinity, and the non-NaN code path applies. |
| 705 | j(greater, &is_nan, Label::kNear); |
| 706 | cmp(FieldOperand(maybe_number, HeapNumber::kValueOffset), Immediate(0)); |
| 707 | j(zero, ¬_nan); |
| 708 | bind(&is_nan); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 709 | movsd(scratch2, Operand::StaticVariable(canonical_nan_reference)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 710 | jmp(&have_double_value, Label::kNear); |
| 711 | |
| 712 | bind(&smi_value); |
| 713 | // Value is a smi. Convert to a double and store. |
| 714 | // Preserve original value. |
| 715 | mov(scratch1, maybe_number); |
| 716 | SmiUntag(scratch1); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 717 | Cvtsi2sd(scratch2, scratch1); |
| 718 | movsd(FieldOperand(elements, key, times_4, |
| 719 | FixedDoubleArray::kHeaderSize - elements_offset), |
| 720 | scratch2); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 721 | bind(&done); |
| 722 | } |
| 723 | |
| 724 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 725 | void MacroAssembler::CompareMap(Register obj, Handle<Map> map) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 726 | cmp(FieldOperand(obj, HeapObject::kMapOffset), map); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 727 | } |
| 728 | |
| 729 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 730 | void MacroAssembler::CheckMap(Register obj, |
| 731 | Handle<Map> map, |
| 732 | Label* fail, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 733 | SmiCheckType smi_check_type) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 734 | if (smi_check_type == DO_SMI_CHECK) { |
| 735 | JumpIfSmi(obj, fail); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 736 | } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 737 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 738 | CompareMap(obj, map); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 739 | j(not_equal, fail); |
| 740 | } |
| 741 | |
| 742 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 743 | void MacroAssembler::DispatchWeakMap(Register obj, Register scratch1, |
| 744 | Register scratch2, Handle<WeakCell> cell, |
| 745 | Handle<Code> success, |
| 746 | SmiCheckType smi_check_type) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 747 | Label fail; |
| 748 | if (smi_check_type == DO_SMI_CHECK) { |
| 749 | JumpIfSmi(obj, &fail); |
| 750 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 751 | mov(scratch1, FieldOperand(obj, HeapObject::kMapOffset)); |
| 752 | CmpWeakValue(scratch1, cell, scratch2); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 753 | j(equal, success); |
| 754 | |
| 755 | bind(&fail); |
| 756 | } |
| 757 | |
| 758 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 759 | Condition MacroAssembler::IsObjectStringType(Register heap_object, |
| 760 | Register map, |
| 761 | Register instance_type) { |
| 762 | mov(map, FieldOperand(heap_object, HeapObject::kMapOffset)); |
| 763 | movzx_b(instance_type, FieldOperand(map, Map::kInstanceTypeOffset)); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 764 | STATIC_ASSERT(kNotStringTag != 0); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 765 | test(instance_type, Immediate(kIsNotStringMask)); |
| 766 | return zero; |
| 767 | } |
| 768 | |
| 769 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 770 | Condition MacroAssembler::IsObjectNameType(Register heap_object, |
| 771 | Register map, |
| 772 | Register instance_type) { |
| 773 | mov(map, FieldOperand(heap_object, HeapObject::kMapOffset)); |
| 774 | movzx_b(instance_type, FieldOperand(map, Map::kInstanceTypeOffset)); |
| 775 | cmpb(instance_type, static_cast<uint8_t>(LAST_NAME_TYPE)); |
| 776 | return below_equal; |
| 777 | } |
| 778 | |
| 779 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 780 | void MacroAssembler::IsObjectJSObjectType(Register heap_object, |
| 781 | Register map, |
| 782 | Register scratch, |
| 783 | Label* fail) { |
| 784 | mov(map, FieldOperand(heap_object, HeapObject::kMapOffset)); |
| 785 | IsInstanceJSObjectType(map, scratch, fail); |
| 786 | } |
| 787 | |
| 788 | |
| 789 | void MacroAssembler::IsInstanceJSObjectType(Register map, |
| 790 | Register scratch, |
| 791 | Label* fail) { |
| 792 | movzx_b(scratch, FieldOperand(map, Map::kInstanceTypeOffset)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 793 | sub(scratch, Immediate(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE)); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 794 | cmp(scratch, |
| 795 | LAST_NONCALLABLE_SPEC_OBJECT_TYPE - FIRST_NONCALLABLE_SPEC_OBJECT_TYPE); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 796 | j(above, fail); |
| 797 | } |
| 798 | |
| 799 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 800 | void MacroAssembler::FCmp() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 801 | fucomip(); |
| 802 | fstp(0); |
| 803 | } |
| 804 | |
| 805 | |
| 806 | void MacroAssembler::AssertNumber(Register object) { |
| 807 | if (emit_debug_code()) { |
| 808 | Label ok; |
| 809 | JumpIfSmi(object, &ok); |
| 810 | cmp(FieldOperand(object, HeapObject::kMapOffset), |
| 811 | isolate()->factory()->heap_number_map()); |
| 812 | Check(equal, kOperandNotANumber); |
| 813 | bind(&ok); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 814 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 818 | void MacroAssembler::AssertSmi(Register object) { |
| 819 | if (emit_debug_code()) { |
| 820 | test(object, Immediate(kSmiTagMask)); |
| 821 | Check(equal, kOperandIsNotASmi); |
| 822 | } |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 823 | } |
| 824 | |
| 825 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 826 | void MacroAssembler::AssertString(Register object) { |
| 827 | if (emit_debug_code()) { |
| 828 | test(object, Immediate(kSmiTagMask)); |
| 829 | Check(not_equal, kOperandIsASmiAndNotAString); |
| 830 | push(object); |
| 831 | mov(object, FieldOperand(object, HeapObject::kMapOffset)); |
| 832 | CmpInstanceType(object, FIRST_NONSTRING_TYPE); |
| 833 | pop(object); |
| 834 | Check(below, kOperandIsNotAString); |
| 835 | } |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 836 | } |
| 837 | |
| 838 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 839 | void MacroAssembler::AssertName(Register object) { |
| 840 | if (emit_debug_code()) { |
| 841 | test(object, Immediate(kSmiTagMask)); |
| 842 | Check(not_equal, kOperandIsASmiAndNotAName); |
| 843 | push(object); |
| 844 | mov(object, FieldOperand(object, HeapObject::kMapOffset)); |
| 845 | CmpInstanceType(object, LAST_NAME_TYPE); |
| 846 | pop(object); |
| 847 | Check(below_equal, kOperandIsNotAName); |
| 848 | } |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 849 | } |
| 850 | |
| 851 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 852 | void MacroAssembler::AssertUndefinedOrAllocationSite(Register object) { |
| 853 | if (emit_debug_code()) { |
| 854 | Label done_checking; |
| 855 | AssertNotSmi(object); |
| 856 | cmp(object, isolate()->factory()->undefined_value()); |
| 857 | j(equal, &done_checking); |
| 858 | cmp(FieldOperand(object, 0), |
| 859 | Immediate(isolate()->factory()->allocation_site_map())); |
| 860 | Assert(equal, kExpectedUndefinedOrCell); |
| 861 | bind(&done_checking); |
| 862 | } |
| 863 | } |
| 864 | |
| 865 | |
| 866 | void MacroAssembler::AssertNotSmi(Register object) { |
| 867 | if (emit_debug_code()) { |
| 868 | test(object, Immediate(kSmiTagMask)); |
| 869 | Check(not_equal, kOperandIsASmi); |
| 870 | } |
| 871 | } |
| 872 | |
| 873 | |
| 874 | void MacroAssembler::StubPrologue() { |
| 875 | push(ebp); // Caller's frame pointer. |
| 876 | mov(ebp, esp); |
| 877 | push(esi); // Callee's context. |
| 878 | push(Immediate(Smi::FromInt(StackFrame::STUB))); |
| 879 | } |
| 880 | |
| 881 | |
| 882 | void MacroAssembler::Prologue(bool code_pre_aging) { |
| 883 | PredictableCodeSizeScope predictible_code_size_scope(this, |
| 884 | kNoCodeAgeSequenceLength); |
| 885 | if (code_pre_aging) { |
| 886 | // Pre-age the code. |
| 887 | call(isolate()->builtins()->MarkCodeAsExecutedOnce(), |
| 888 | RelocInfo::CODE_AGE_SEQUENCE); |
| 889 | Nop(kNoCodeAgeSequenceLength - Assembler::kCallInstructionLength); |
| 890 | } else { |
| 891 | push(ebp); // Caller's frame pointer. |
| 892 | mov(ebp, esp); |
| 893 | push(esi); // Callee's context. |
| 894 | push(edi); // Callee's JS function. |
| 895 | } |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 896 | } |
| 897 | |
| 898 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 899 | void MacroAssembler::EnterFrame(StackFrame::Type type, |
| 900 | bool load_constant_pool_pointer_reg) { |
| 901 | // Out-of-line constant pool not implemented on ia32. |
| 902 | UNREACHABLE(); |
| 903 | } |
| 904 | |
| 905 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 906 | void MacroAssembler::EnterFrame(StackFrame::Type type) { |
| 907 | push(ebp); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 908 | mov(ebp, esp); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 909 | push(esi); |
| 910 | push(Immediate(Smi::FromInt(type))); |
| 911 | push(Immediate(CodeObject())); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 912 | if (emit_debug_code()) { |
| 913 | cmp(Operand(esp, 0), Immediate(isolate()->factory()->undefined_value())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 914 | Check(not_equal, kCodeObjectNotProperlyPatched); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 915 | } |
| 916 | } |
| 917 | |
| 918 | |
| 919 | void MacroAssembler::LeaveFrame(StackFrame::Type type) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 920 | if (emit_debug_code()) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 921 | cmp(Operand(ebp, StandardFrameConstants::kMarkerOffset), |
| 922 | Immediate(Smi::FromInt(type))); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 923 | Check(equal, kStackFrameTypesMustMatch); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 924 | } |
| 925 | leave(); |
| 926 | } |
| 927 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 928 | |
| 929 | void MacroAssembler::EnterExitFramePrologue() { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 930 | // Set up the frame structure on the stack. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 931 | DCHECK(ExitFrameConstants::kCallerSPDisplacement == +2 * kPointerSize); |
| 932 | DCHECK(ExitFrameConstants::kCallerPCOffset == +1 * kPointerSize); |
| 933 | DCHECK(ExitFrameConstants::kCallerFPOffset == 0 * kPointerSize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 934 | push(ebp); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 935 | mov(ebp, esp); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 936 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 937 | // Reserve room for entry stack pointer and push the code object. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 938 | DCHECK(ExitFrameConstants::kSPOffset == -1 * kPointerSize); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 939 | push(Immediate(0)); // Saved entry sp, patched before call. |
| 940 | push(Immediate(CodeObject())); // Accessed from ExitFrame::code_slot. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 941 | |
| 942 | // Save the frame pointer and the context in top. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 943 | ExternalReference c_entry_fp_address(Isolate::kCEntryFPAddress, isolate()); |
| 944 | ExternalReference context_address(Isolate::kContextAddress, isolate()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 945 | ExternalReference c_function_address(Isolate::kCFunctionAddress, isolate()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 946 | mov(Operand::StaticVariable(c_entry_fp_address), ebp); |
| 947 | mov(Operand::StaticVariable(context_address), esi); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 948 | mov(Operand::StaticVariable(c_function_address), ebx); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 949 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 950 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 951 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 952 | void MacroAssembler::EnterExitFrameEpilogue(int argc, bool save_doubles) { |
| 953 | // Optionally save all XMM registers. |
| 954 | if (save_doubles) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 955 | int space = XMMRegister::kMaxNumRegisters * kDoubleSize + |
| 956 | argc * kPointerSize; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 957 | sub(esp, Immediate(space)); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 958 | const int offset = -2 * kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 959 | for (int i = 0; i < XMMRegister::kMaxNumRegisters; i++) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 960 | XMMRegister reg = XMMRegister::from_code(i); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 961 | movsd(Operand(ebp, offset - ((i + 1) * kDoubleSize)), reg); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 962 | } |
| 963 | } else { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 964 | sub(esp, Immediate(argc * kPointerSize)); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 965 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 966 | |
| 967 | // Get the required frame alignment for the OS. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 968 | const int kFrameAlignment = base::OS::ActivationFrameAlignment(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 969 | if (kFrameAlignment > 0) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 970 | DCHECK(base::bits::IsPowerOfTwo32(kFrameAlignment)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 971 | and_(esp, -kFrameAlignment); |
| 972 | } |
| 973 | |
| 974 | // Patch the saved entry sp. |
| 975 | mov(Operand(ebp, ExitFrameConstants::kSPOffset), esp); |
| 976 | } |
| 977 | |
| 978 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 979 | void MacroAssembler::EnterExitFrame(bool save_doubles) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 980 | EnterExitFramePrologue(); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 981 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 982 | // Set up argc and argv in callee-saved registers. |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 983 | int offset = StandardFrameConstants::kCallerSPOffset - kPointerSize; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 984 | mov(edi, eax); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 985 | lea(esi, Operand(ebp, eax, times_4, offset)); |
| 986 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 987 | // Reserve space for argc, argv and isolate. |
| 988 | EnterExitFrameEpilogue(3, save_doubles); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 989 | } |
| 990 | |
| 991 | |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 992 | void MacroAssembler::EnterApiExitFrame(int argc) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 993 | EnterExitFramePrologue(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 994 | EnterExitFrameEpilogue(argc, false); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 995 | } |
| 996 | |
| 997 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 998 | void MacroAssembler::LeaveExitFrame(bool save_doubles) { |
| 999 | // Optionally restore all XMM registers. |
| 1000 | if (save_doubles) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1001 | const int offset = -2 * kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1002 | for (int i = 0; i < XMMRegister::kMaxNumRegisters; i++) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1003 | XMMRegister reg = XMMRegister::from_code(i); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1004 | movsd(reg, Operand(ebp, offset - ((i + 1) * kDoubleSize))); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1005 | } |
| 1006 | } |
| 1007 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1008 | // Get the return address from the stack and restore the frame pointer. |
| 1009 | mov(ecx, Operand(ebp, 1 * kPointerSize)); |
| 1010 | mov(ebp, Operand(ebp, 0 * kPointerSize)); |
| 1011 | |
| 1012 | // Pop the arguments and the receiver from the caller stack. |
| 1013 | lea(esp, Operand(esi, 1 * kPointerSize)); |
| 1014 | |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 1015 | // Push the return address to get ready to return. |
| 1016 | push(ecx); |
| 1017 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1018 | LeaveExitFrameEpilogue(true); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 1019 | } |
| 1020 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1021 | |
| 1022 | void MacroAssembler::LeaveExitFrameEpilogue(bool restore_context) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1023 | // Restore current context from top and clear it in debug mode. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1024 | ExternalReference context_address(Isolate::kContextAddress, isolate()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1025 | if (restore_context) { |
| 1026 | mov(esi, Operand::StaticVariable(context_address)); |
| 1027 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1028 | #ifdef DEBUG |
| 1029 | mov(Operand::StaticVariable(context_address), Immediate(0)); |
| 1030 | #endif |
| 1031 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1032 | // Clear the top frame. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1033 | ExternalReference c_entry_fp_address(Isolate::kCEntryFPAddress, |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1034 | isolate()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1035 | mov(Operand::StaticVariable(c_entry_fp_address), Immediate(0)); |
| 1036 | } |
| 1037 | |
| 1038 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1039 | void MacroAssembler::LeaveApiExitFrame(bool restore_context) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1040 | mov(esp, ebp); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 1041 | pop(ebp); |
| 1042 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1043 | LeaveExitFrameEpilogue(restore_context); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 1044 | } |
| 1045 | |
| 1046 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1047 | void MacroAssembler::PushTryHandler(StackHandler::Kind kind, |
| 1048 | int handler_index) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1049 | // Adjust this code if not the case. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1050 | STATIC_ASSERT(StackHandlerConstants::kSize == 5 * kPointerSize); |
| 1051 | STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1052 | STATIC_ASSERT(StackHandlerConstants::kCodeOffset == 1 * kPointerSize); |
| 1053 | STATIC_ASSERT(StackHandlerConstants::kStateOffset == 2 * kPointerSize); |
| 1054 | STATIC_ASSERT(StackHandlerConstants::kContextOffset == 3 * kPointerSize); |
| 1055 | STATIC_ASSERT(StackHandlerConstants::kFPOffset == 4 * kPointerSize); |
| 1056 | |
| 1057 | // We will build up the handler from the bottom by pushing on the stack. |
| 1058 | // First push the frame pointer and context. |
| 1059 | if (kind == StackHandler::JS_ENTRY) { |
| 1060 | // The frame pointer does not point to a JS frame so we save NULL for |
| 1061 | // ebp. We expect the code throwing an exception to check ebp before |
| 1062 | // dereferencing it to restore the context. |
Ben Murdoch | 85b7179 | 2012-04-11 18:30:58 +0100 | [diff] [blame] | 1063 | push(Immediate(0)); // NULL frame pointer. |
| 1064 | push(Immediate(Smi::FromInt(0))); // No context. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1065 | } else { |
| 1066 | push(ebp); |
| 1067 | push(esi); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1068 | } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1069 | // Push the state and the code object. |
| 1070 | unsigned state = |
| 1071 | StackHandler::IndexField::encode(handler_index) | |
| 1072 | StackHandler::KindField::encode(kind); |
| 1073 | push(Immediate(state)); |
| 1074 | Push(CodeObject()); |
| 1075 | |
| 1076 | // Link the current handler as the next handler. |
| 1077 | ExternalReference handler_address(Isolate::kHandlerAddress, isolate()); |
| 1078 | push(Operand::StaticVariable(handler_address)); |
| 1079 | // Set this new handler as the current one. |
| 1080 | mov(Operand::StaticVariable(handler_address), esp); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1081 | } |
| 1082 | |
| 1083 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1084 | void MacroAssembler::PopTryHandler() { |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1085 | STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1086 | ExternalReference handler_address(Isolate::kHandlerAddress, isolate()); |
| 1087 | pop(Operand::StaticVariable(handler_address)); |
| 1088 | add(esp, Immediate(StackHandlerConstants::kSize - kPointerSize)); |
| 1089 | } |
| 1090 | |
| 1091 | |
| 1092 | void MacroAssembler::JumpToHandlerEntry() { |
| 1093 | // Compute the handler entry address and jump to it. The handler table is |
| 1094 | // a fixed array of (smi-tagged) code offsets. |
| 1095 | // eax = exception, edi = code object, edx = state. |
| 1096 | mov(ebx, FieldOperand(edi, Code::kHandlerTableOffset)); |
| 1097 | shr(edx, StackHandler::kKindWidth); |
| 1098 | mov(edx, FieldOperand(ebx, edx, times_4, FixedArray::kHeaderSize)); |
| 1099 | SmiUntag(edx); |
| 1100 | lea(edi, FieldOperand(edi, edx, times_1, Code::kHeaderSize)); |
| 1101 | jmp(edi); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1102 | } |
| 1103 | |
| 1104 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1105 | void MacroAssembler::Throw(Register value) { |
| 1106 | // Adjust this code if not the case. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1107 | STATIC_ASSERT(StackHandlerConstants::kSize == 5 * kPointerSize); |
| 1108 | STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1109 | STATIC_ASSERT(StackHandlerConstants::kCodeOffset == 1 * kPointerSize); |
| 1110 | STATIC_ASSERT(StackHandlerConstants::kStateOffset == 2 * kPointerSize); |
| 1111 | STATIC_ASSERT(StackHandlerConstants::kContextOffset == 3 * kPointerSize); |
| 1112 | STATIC_ASSERT(StackHandlerConstants::kFPOffset == 4 * kPointerSize); |
| 1113 | |
| 1114 | // The exception is expected in eax. |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1115 | if (!value.is(eax)) { |
| 1116 | mov(eax, value); |
| 1117 | } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1118 | // Drop the stack pointer to the top of the top handler. |
| 1119 | ExternalReference handler_address(Isolate::kHandlerAddress, isolate()); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1120 | mov(esp, Operand::StaticVariable(handler_address)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1121 | // Restore the next handler. |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1122 | pop(Operand::StaticVariable(handler_address)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1123 | |
| 1124 | // Remove the code object and state, compute the handler address in edi. |
| 1125 | pop(edi); // Code object. |
| 1126 | pop(edx); // Index and state. |
| 1127 | |
| 1128 | // Restore the context and frame pointer. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1129 | pop(esi); // Context. |
| 1130 | pop(ebp); // Frame pointer. |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1131 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1132 | // If the handler is a JS frame, restore the context to the frame. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1133 | // (kind == ENTRY) == (ebp == 0) == (esi == 0), so we could test either |
| 1134 | // ebp or esi. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1135 | Label skip; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1136 | test(esi, esi); |
| 1137 | j(zero, &skip, Label::kNear); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1138 | mov(Operand(ebp, StandardFrameConstants::kContextOffset), esi); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1139 | bind(&skip); |
| 1140 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1141 | JumpToHandlerEntry(); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1142 | } |
| 1143 | |
| 1144 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1145 | void MacroAssembler::ThrowUncatchable(Register value) { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1146 | // Adjust this code if not the case. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1147 | STATIC_ASSERT(StackHandlerConstants::kSize == 5 * kPointerSize); |
| 1148 | STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1149 | STATIC_ASSERT(StackHandlerConstants::kCodeOffset == 1 * kPointerSize); |
| 1150 | STATIC_ASSERT(StackHandlerConstants::kStateOffset == 2 * kPointerSize); |
| 1151 | STATIC_ASSERT(StackHandlerConstants::kContextOffset == 3 * kPointerSize); |
| 1152 | STATIC_ASSERT(StackHandlerConstants::kFPOffset == 4 * kPointerSize); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1153 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1154 | // The exception is expected in eax. |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame] | 1155 | if (!value.is(eax)) { |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1156 | mov(eax, value); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1157 | } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1158 | // Drop the stack pointer to the top of the top stack handler. |
| 1159 | ExternalReference handler_address(Isolate::kHandlerAddress, isolate()); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1160 | mov(esp, Operand::StaticVariable(handler_address)); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1161 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1162 | // Unwind the handlers until the top ENTRY handler is found. |
| 1163 | Label fetch_next, check_kind; |
| 1164 | jmp(&check_kind, Label::kNear); |
| 1165 | bind(&fetch_next); |
| 1166 | mov(esp, Operand(esp, StackHandlerConstants::kNextOffset)); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1167 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1168 | bind(&check_kind); |
| 1169 | STATIC_ASSERT(StackHandler::JS_ENTRY == 0); |
| 1170 | test(Operand(esp, StackHandlerConstants::kStateOffset), |
| 1171 | Immediate(StackHandler::KindField::kMask)); |
| 1172 | j(not_zero, &fetch_next); |
| 1173 | |
| 1174 | // Set the top handler address to next handler past the top ENTRY handler. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1175 | pop(Operand::StaticVariable(handler_address)); |
| 1176 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1177 | // Remove the code object and state, compute the handler address in edi. |
| 1178 | pop(edi); // Code object. |
| 1179 | pop(edx); // Index and state. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1180 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1181 | // Clear the context pointer and frame pointer (0 was saved in the handler). |
| 1182 | pop(esi); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1183 | pop(ebp); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1184 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1185 | JumpToHandlerEntry(); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1186 | } |
| 1187 | |
| 1188 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1189 | void MacroAssembler::CheckAccessGlobalProxy(Register holder_reg, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1190 | Register scratch1, |
| 1191 | Register scratch2, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1192 | Label* miss) { |
| 1193 | Label same_contexts; |
| 1194 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1195 | DCHECK(!holder_reg.is(scratch1)); |
| 1196 | DCHECK(!holder_reg.is(scratch2)); |
| 1197 | DCHECK(!scratch1.is(scratch2)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1198 | |
| 1199 | // Load current lexical context from the stack frame. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1200 | mov(scratch1, Operand(ebp, StandardFrameConstants::kContextOffset)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1201 | |
| 1202 | // When generating debug code, make sure the lexical context is set. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1203 | if (emit_debug_code()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1204 | cmp(scratch1, Immediate(0)); |
| 1205 | Check(not_equal, kWeShouldNotHaveAnEmptyLexicalContext); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1206 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1207 | // Load the native context of the current context. |
| 1208 | int offset = |
| 1209 | Context::kHeaderSize + Context::GLOBAL_OBJECT_INDEX * kPointerSize; |
| 1210 | mov(scratch1, FieldOperand(scratch1, offset)); |
| 1211 | mov(scratch1, FieldOperand(scratch1, GlobalObject::kNativeContextOffset)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1212 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1213 | // Check the context is a native context. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1214 | if (emit_debug_code()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1215 | // Read the first word and compare to native_context_map. |
| 1216 | cmp(FieldOperand(scratch1, HeapObject::kMapOffset), |
| 1217 | isolate()->factory()->native_context_map()); |
| 1218 | Check(equal, kJSGlobalObjectNativeContextShouldBeANativeContext); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1219 | } |
| 1220 | |
| 1221 | // Check if both contexts are the same. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1222 | cmp(scratch1, FieldOperand(holder_reg, JSGlobalProxy::kNativeContextOffset)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1223 | j(equal, &same_contexts); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1224 | |
| 1225 | // Compare security tokens, save holder_reg on the stack so we can use it |
| 1226 | // as a temporary register. |
| 1227 | // |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1228 | // Check that the security token in the calling global object is |
| 1229 | // compatible with the security token in the receiving global |
| 1230 | // object. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1231 | mov(scratch2, |
| 1232 | FieldOperand(holder_reg, JSGlobalProxy::kNativeContextOffset)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1233 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1234 | // Check the context is a native context. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1235 | if (emit_debug_code()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1236 | cmp(scratch2, isolate()->factory()->null_value()); |
| 1237 | Check(not_equal, kJSGlobalProxyContextShouldNotBeNull); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1238 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1239 | // Read the first word and compare to native_context_map(), |
| 1240 | cmp(FieldOperand(scratch2, HeapObject::kMapOffset), |
| 1241 | isolate()->factory()->native_context_map()); |
| 1242 | Check(equal, kJSGlobalObjectNativeContextShouldBeANativeContext); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1243 | } |
| 1244 | |
| 1245 | int token_offset = Context::kHeaderSize + |
| 1246 | Context::SECURITY_TOKEN_INDEX * kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1247 | mov(scratch1, FieldOperand(scratch1, token_offset)); |
| 1248 | cmp(scratch1, FieldOperand(scratch2, token_offset)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1249 | j(not_equal, miss); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1250 | |
| 1251 | bind(&same_contexts); |
| 1252 | } |
| 1253 | |
| 1254 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1255 | // Compute the hash code from the untagged key. This must be kept in sync with |
| 1256 | // ComputeIntegerHash in utils.h and KeyedLoadGenericStub in |
| 1257 | // code-stub-hydrogen.cc |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 1258 | // |
| 1259 | // Note: r0 will contain hash code |
| 1260 | void MacroAssembler::GetNumberHash(Register r0, Register scratch) { |
| 1261 | // Xor original key with a seed. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1262 | if (serializer_enabled()) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1263 | ExternalReference roots_array_start = |
| 1264 | ExternalReference::roots_array_start(isolate()); |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 1265 | mov(scratch, Immediate(Heap::kHashSeedRootIndex)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1266 | mov(scratch, |
| 1267 | Operand::StaticArray(scratch, times_pointer_size, roots_array_start)); |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 1268 | SmiUntag(scratch); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1269 | xor_(r0, scratch); |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 1270 | } else { |
| 1271 | int32_t seed = isolate()->heap()->HashSeed(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1272 | xor_(r0, Immediate(seed)); |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 1273 | } |
| 1274 | |
| 1275 | // hash = ~hash + (hash << 15); |
| 1276 | mov(scratch, r0); |
| 1277 | not_(r0); |
| 1278 | shl(scratch, 15); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1279 | add(r0, scratch); |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 1280 | // hash = hash ^ (hash >> 12); |
| 1281 | mov(scratch, r0); |
| 1282 | shr(scratch, 12); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1283 | xor_(r0, scratch); |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 1284 | // hash = hash + (hash << 2); |
| 1285 | lea(r0, Operand(r0, r0, times_4, 0)); |
| 1286 | // hash = hash ^ (hash >> 4); |
| 1287 | mov(scratch, r0); |
| 1288 | shr(scratch, 4); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1289 | xor_(r0, scratch); |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 1290 | // hash = hash * 2057; |
| 1291 | imul(r0, r0, 2057); |
| 1292 | // hash = hash ^ (hash >> 16); |
| 1293 | mov(scratch, r0); |
| 1294 | shr(scratch, 16); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1295 | xor_(r0, scratch); |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 1296 | } |
| 1297 | |
| 1298 | |
| 1299 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1300 | void MacroAssembler::LoadFromNumberDictionary(Label* miss, |
| 1301 | Register elements, |
| 1302 | Register key, |
| 1303 | Register r0, |
| 1304 | Register r1, |
| 1305 | Register r2, |
| 1306 | Register result) { |
| 1307 | // Register use: |
| 1308 | // |
| 1309 | // elements - holds the slow-case elements of the receiver and is unchanged. |
| 1310 | // |
| 1311 | // key - holds the smi key on entry and is unchanged. |
| 1312 | // |
| 1313 | // Scratch registers: |
| 1314 | // |
| 1315 | // r0 - holds the untagged key on entry and holds the hash once computed. |
| 1316 | // |
| 1317 | // r1 - used to hold the capacity mask of the dictionary |
| 1318 | // |
| 1319 | // r2 - used for the index into the dictionary. |
| 1320 | // |
| 1321 | // result - holds the result on exit if the load succeeds and we fall through. |
| 1322 | |
| 1323 | Label done; |
| 1324 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 1325 | GetNumberHash(r0, r1); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1326 | |
| 1327 | // Compute capacity mask. |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 1328 | mov(r1, FieldOperand(elements, SeededNumberDictionary::kCapacityOffset)); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1329 | shr(r1, kSmiTagSize); // convert smi to int |
| 1330 | dec(r1); |
| 1331 | |
| 1332 | // Generate an unrolled loop that performs a few probes before giving up. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1333 | for (int i = 0; i < kNumberDictionaryProbes; i++) { |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1334 | // Use r2 for index calculations and keep the hash intact in r0. |
| 1335 | mov(r2, r0); |
| 1336 | // Compute the masked index: (hash + i + i * i) & mask. |
| 1337 | if (i > 0) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1338 | add(r2, Immediate(SeededNumberDictionary::GetProbeOffset(i))); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1339 | } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1340 | and_(r2, r1); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1341 | |
| 1342 | // Scale the index by multiplying by the entry size. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1343 | DCHECK(SeededNumberDictionary::kEntrySize == 3); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1344 | lea(r2, Operand(r2, r2, times_2, 0)); // r2 = r2 * 3 |
| 1345 | |
| 1346 | // Check if the key matches. |
| 1347 | cmp(key, FieldOperand(elements, |
| 1348 | r2, |
| 1349 | times_pointer_size, |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 1350 | SeededNumberDictionary::kElementsStartOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1351 | if (i != (kNumberDictionaryProbes - 1)) { |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1352 | j(equal, &done); |
| 1353 | } else { |
| 1354 | j(not_equal, miss); |
| 1355 | } |
| 1356 | } |
| 1357 | |
| 1358 | bind(&done); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1359 | // Check that the value is a field property. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1360 | const int kDetailsOffset = |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 1361 | SeededNumberDictionary::kElementsStartOffset + 2 * kPointerSize; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1362 | DCHECK_EQ(FIELD, 0); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1363 | test(FieldOperand(elements, r2, times_pointer_size, kDetailsOffset), |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1364 | Immediate(PropertyDetails::TypeField::kMask << kSmiTagSize)); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1365 | j(not_zero, miss); |
| 1366 | |
| 1367 | // Get the value at the masked, scaled index. |
| 1368 | const int kValueOffset = |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 1369 | SeededNumberDictionary::kElementsStartOffset + kPointerSize; |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1370 | mov(result, FieldOperand(elements, r2, times_pointer_size, kValueOffset)); |
| 1371 | } |
| 1372 | |
| 1373 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1374 | void MacroAssembler::LoadAllocationTopHelper(Register result, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1375 | Register scratch, |
| 1376 | AllocationFlags flags) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1377 | ExternalReference allocation_top = |
| 1378 | AllocationUtils::GetAllocationTopReference(isolate(), flags); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1379 | |
| 1380 | // Just return if allocation top is already known. |
| 1381 | if ((flags & RESULT_CONTAINS_TOP) != 0) { |
| 1382 | // No use of scratch if allocation top is provided. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1383 | DCHECK(scratch.is(no_reg)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1384 | #ifdef DEBUG |
| 1385 | // Assert that result actually contains top on entry. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1386 | cmp(result, Operand::StaticVariable(allocation_top)); |
| 1387 | Check(equal, kUnexpectedAllocationTop); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1388 | #endif |
| 1389 | return; |
| 1390 | } |
| 1391 | |
| 1392 | // Move address of new object to result. Use scratch register if available. |
| 1393 | if (scratch.is(no_reg)) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1394 | mov(result, Operand::StaticVariable(allocation_top)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1395 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1396 | mov(scratch, Immediate(allocation_top)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1397 | mov(result, Operand(scratch, 0)); |
| 1398 | } |
| 1399 | } |
| 1400 | |
| 1401 | |
| 1402 | void MacroAssembler::UpdateAllocationTopHelper(Register result_end, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1403 | Register scratch, |
| 1404 | AllocationFlags flags) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1405 | if (emit_debug_code()) { |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1406 | test(result_end, Immediate(kObjectAlignmentMask)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1407 | Check(zero, kUnalignedAllocationInNewSpace); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1408 | } |
| 1409 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1410 | ExternalReference allocation_top = |
| 1411 | AllocationUtils::GetAllocationTopReference(isolate(), flags); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1412 | |
| 1413 | // Update new top. Use scratch if available. |
| 1414 | if (scratch.is(no_reg)) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1415 | mov(Operand::StaticVariable(allocation_top), result_end); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1416 | } else { |
| 1417 | mov(Operand(scratch, 0), result_end); |
| 1418 | } |
| 1419 | } |
| 1420 | |
| 1421 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1422 | void MacroAssembler::Allocate(int object_size, |
| 1423 | Register result, |
| 1424 | Register result_end, |
| 1425 | Register scratch, |
| 1426 | Label* gc_required, |
| 1427 | AllocationFlags flags) { |
| 1428 | DCHECK((flags & (RESULT_CONTAINS_TOP | SIZE_IN_WORDS)) == 0); |
| 1429 | DCHECK(object_size <= Page::kMaxRegularHeapObjectSize); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1430 | if (!FLAG_inline_new) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1431 | if (emit_debug_code()) { |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1432 | // Trash the registers to simulate an allocation failure. |
| 1433 | mov(result, Immediate(0x7091)); |
| 1434 | if (result_end.is_valid()) { |
| 1435 | mov(result_end, Immediate(0x7191)); |
| 1436 | } |
| 1437 | if (scratch.is_valid()) { |
| 1438 | mov(scratch, Immediate(0x7291)); |
| 1439 | } |
| 1440 | } |
| 1441 | jmp(gc_required); |
| 1442 | return; |
| 1443 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1444 | DCHECK(!result.is(result_end)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1445 | |
| 1446 | // Load address of new object into result. |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 1447 | LoadAllocationTopHelper(result, scratch, flags); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1448 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1449 | ExternalReference allocation_limit = |
| 1450 | AllocationUtils::GetAllocationLimitReference(isolate(), flags); |
| 1451 | |
| 1452 | // Align the next allocation. Storing the filler map without checking top is |
| 1453 | // safe in new-space because the limit of the heap is aligned there. |
| 1454 | if ((flags & DOUBLE_ALIGNMENT) != 0) { |
| 1455 | DCHECK((flags & PRETENURE_OLD_POINTER_SPACE) == 0); |
| 1456 | DCHECK(kPointerAlignment * 2 == kDoubleAlignment); |
| 1457 | Label aligned; |
| 1458 | test(result, Immediate(kDoubleAlignmentMask)); |
| 1459 | j(zero, &aligned, Label::kNear); |
| 1460 | if ((flags & PRETENURE_OLD_DATA_SPACE) != 0) { |
| 1461 | cmp(result, Operand::StaticVariable(allocation_limit)); |
| 1462 | j(above_equal, gc_required); |
| 1463 | } |
| 1464 | mov(Operand(result, 0), |
| 1465 | Immediate(isolate()->factory()->one_pointer_filler_map())); |
| 1466 | add(result, Immediate(kDoubleSize / 2)); |
| 1467 | bind(&aligned); |
| 1468 | } |
| 1469 | |
| 1470 | // Calculate new top and bail out if space is exhausted. |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 1471 | Register top_reg = result_end.is_valid() ? result_end : result; |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1472 | if (!top_reg.is(result)) { |
| 1473 | mov(top_reg, result); |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 1474 | } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1475 | add(top_reg, Immediate(object_size)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1476 | j(carry, gc_required); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1477 | cmp(top_reg, Operand::StaticVariable(allocation_limit)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1478 | j(above, gc_required); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1479 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1480 | // Update allocation top. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1481 | UpdateAllocationTopHelper(top_reg, scratch, flags); |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 1482 | |
| 1483 | // Tag result if requested. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1484 | bool tag_result = (flags & TAG_OBJECT) != 0; |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 1485 | if (top_reg.is(result)) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1486 | if (tag_result) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1487 | sub(result, Immediate(object_size - kHeapObjectTag)); |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 1488 | } else { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1489 | sub(result, Immediate(object_size)); |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 1490 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1491 | } else if (tag_result) { |
| 1492 | DCHECK(kHeapObjectTag == 1); |
| 1493 | inc(result); |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 1494 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1495 | } |
| 1496 | |
| 1497 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1498 | void MacroAssembler::Allocate(int header_size, |
| 1499 | ScaleFactor element_size, |
| 1500 | Register element_count, |
| 1501 | RegisterValueType element_count_type, |
| 1502 | Register result, |
| 1503 | Register result_end, |
| 1504 | Register scratch, |
| 1505 | Label* gc_required, |
| 1506 | AllocationFlags flags) { |
| 1507 | DCHECK((flags & SIZE_IN_WORDS) == 0); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1508 | if (!FLAG_inline_new) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1509 | if (emit_debug_code()) { |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1510 | // Trash the registers to simulate an allocation failure. |
| 1511 | mov(result, Immediate(0x7091)); |
| 1512 | mov(result_end, Immediate(0x7191)); |
| 1513 | if (scratch.is_valid()) { |
| 1514 | mov(scratch, Immediate(0x7291)); |
| 1515 | } |
| 1516 | // Register element_count is not modified by the function. |
| 1517 | } |
| 1518 | jmp(gc_required); |
| 1519 | return; |
| 1520 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1521 | DCHECK(!result.is(result_end)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1522 | |
| 1523 | // Load address of new object into result. |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 1524 | LoadAllocationTopHelper(result, scratch, flags); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1525 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1526 | ExternalReference allocation_limit = |
| 1527 | AllocationUtils::GetAllocationLimitReference(isolate(), flags); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1528 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1529 | // Align the next allocation. Storing the filler map without checking top is |
| 1530 | // safe in new-space because the limit of the heap is aligned there. |
| 1531 | if ((flags & DOUBLE_ALIGNMENT) != 0) { |
| 1532 | DCHECK((flags & PRETENURE_OLD_POINTER_SPACE) == 0); |
| 1533 | DCHECK(kPointerAlignment * 2 == kDoubleAlignment); |
| 1534 | Label aligned; |
| 1535 | test(result, Immediate(kDoubleAlignmentMask)); |
| 1536 | j(zero, &aligned, Label::kNear); |
| 1537 | if ((flags & PRETENURE_OLD_DATA_SPACE) != 0) { |
| 1538 | cmp(result, Operand::StaticVariable(allocation_limit)); |
| 1539 | j(above_equal, gc_required); |
| 1540 | } |
| 1541 | mov(Operand(result, 0), |
| 1542 | Immediate(isolate()->factory()->one_pointer_filler_map())); |
| 1543 | add(result, Immediate(kDoubleSize / 2)); |
| 1544 | bind(&aligned); |
| 1545 | } |
| 1546 | |
| 1547 | // Calculate new top and bail out if space is exhausted. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1548 | // We assume that element_count*element_size + header_size does not |
| 1549 | // overflow. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1550 | if (element_count_type == REGISTER_VALUE_IS_SMI) { |
| 1551 | STATIC_ASSERT(static_cast<ScaleFactor>(times_2 - 1) == times_1); |
| 1552 | STATIC_ASSERT(static_cast<ScaleFactor>(times_4 - 1) == times_2); |
| 1553 | STATIC_ASSERT(static_cast<ScaleFactor>(times_8 - 1) == times_4); |
| 1554 | DCHECK(element_size >= times_2); |
| 1555 | DCHECK(kSmiTagSize == 1); |
| 1556 | element_size = static_cast<ScaleFactor>(element_size - 1); |
| 1557 | } else { |
| 1558 | DCHECK(element_count_type == REGISTER_VALUE_IS_INT32); |
| 1559 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1560 | lea(result_end, Operand(element_count, element_size, header_size)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1561 | add(result_end, result); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1562 | j(carry, gc_required); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1563 | cmp(result_end, Operand::StaticVariable(allocation_limit)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1564 | j(above, gc_required); |
| 1565 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1566 | if ((flags & TAG_OBJECT) != 0) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1567 | DCHECK(kHeapObjectTag == 1); |
| 1568 | inc(result); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1569 | } |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1570 | |
| 1571 | // Update allocation top. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1572 | UpdateAllocationTopHelper(result_end, scratch, flags); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1573 | } |
| 1574 | |
| 1575 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1576 | void MacroAssembler::Allocate(Register object_size, |
| 1577 | Register result, |
| 1578 | Register result_end, |
| 1579 | Register scratch, |
| 1580 | Label* gc_required, |
| 1581 | AllocationFlags flags) { |
| 1582 | DCHECK((flags & (RESULT_CONTAINS_TOP | SIZE_IN_WORDS)) == 0); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1583 | if (!FLAG_inline_new) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1584 | if (emit_debug_code()) { |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1585 | // Trash the registers to simulate an allocation failure. |
| 1586 | mov(result, Immediate(0x7091)); |
| 1587 | mov(result_end, Immediate(0x7191)); |
| 1588 | if (scratch.is_valid()) { |
| 1589 | mov(scratch, Immediate(0x7291)); |
| 1590 | } |
| 1591 | // object_size is left unchanged by this function. |
| 1592 | } |
| 1593 | jmp(gc_required); |
| 1594 | return; |
| 1595 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1596 | DCHECK(!result.is(result_end)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1597 | |
| 1598 | // Load address of new object into result. |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 1599 | LoadAllocationTopHelper(result, scratch, flags); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1600 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1601 | ExternalReference allocation_limit = |
| 1602 | AllocationUtils::GetAllocationLimitReference(isolate(), flags); |
| 1603 | |
| 1604 | // Align the next allocation. Storing the filler map without checking top is |
| 1605 | // safe in new-space because the limit of the heap is aligned there. |
| 1606 | if ((flags & DOUBLE_ALIGNMENT) != 0) { |
| 1607 | DCHECK((flags & PRETENURE_OLD_POINTER_SPACE) == 0); |
| 1608 | DCHECK(kPointerAlignment * 2 == kDoubleAlignment); |
| 1609 | Label aligned; |
| 1610 | test(result, Immediate(kDoubleAlignmentMask)); |
| 1611 | j(zero, &aligned, Label::kNear); |
| 1612 | if ((flags & PRETENURE_OLD_DATA_SPACE) != 0) { |
| 1613 | cmp(result, Operand::StaticVariable(allocation_limit)); |
| 1614 | j(above_equal, gc_required); |
| 1615 | } |
| 1616 | mov(Operand(result, 0), |
| 1617 | Immediate(isolate()->factory()->one_pointer_filler_map())); |
| 1618 | add(result, Immediate(kDoubleSize / 2)); |
| 1619 | bind(&aligned); |
| 1620 | } |
| 1621 | |
| 1622 | // Calculate new top and bail out if space is exhausted. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1623 | if (!object_size.is(result_end)) { |
| 1624 | mov(result_end, object_size); |
| 1625 | } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1626 | add(result_end, result); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1627 | j(carry, gc_required); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1628 | cmp(result_end, Operand::StaticVariable(allocation_limit)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1629 | j(above, gc_required); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1630 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1631 | // Tag result if requested. |
| 1632 | if ((flags & TAG_OBJECT) != 0) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1633 | DCHECK(kHeapObjectTag == 1); |
| 1634 | inc(result); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1635 | } |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1636 | |
| 1637 | // Update allocation top. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1638 | UpdateAllocationTopHelper(result_end, scratch, flags); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1639 | } |
| 1640 | |
| 1641 | |
| 1642 | void MacroAssembler::UndoAllocationInNewSpace(Register object) { |
| 1643 | ExternalReference new_space_allocation_top = |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1644 | ExternalReference::new_space_allocation_top_address(isolate()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1645 | |
| 1646 | // Make sure the object has no tag before resetting top. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1647 | and_(object, Immediate(~kHeapObjectTagMask)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1648 | #ifdef DEBUG |
| 1649 | cmp(object, Operand::StaticVariable(new_space_allocation_top)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1650 | Check(below, kUndoAllocationOfNonAllocatedMemory); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1651 | #endif |
| 1652 | mov(Operand::StaticVariable(new_space_allocation_top), object); |
| 1653 | } |
| 1654 | |
| 1655 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1656 | void MacroAssembler::AllocateHeapNumber(Register result, |
| 1657 | Register scratch1, |
| 1658 | Register scratch2, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1659 | Label* gc_required, |
| 1660 | MutableMode mode) { |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1661 | // Allocate heap number in new space. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1662 | Allocate(HeapNumber::kSize, result, scratch1, scratch2, gc_required, |
| 1663 | TAG_OBJECT); |
| 1664 | |
| 1665 | Handle<Map> map = mode == MUTABLE |
| 1666 | ? isolate()->factory()->mutable_heap_number_map() |
| 1667 | : isolate()->factory()->heap_number_map(); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1668 | |
| 1669 | // Set the map. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1670 | mov(FieldOperand(result, HeapObject::kMapOffset), Immediate(map)); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1671 | } |
| 1672 | |
| 1673 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1674 | void MacroAssembler::AllocateTwoByteString(Register result, |
| 1675 | Register length, |
| 1676 | Register scratch1, |
| 1677 | Register scratch2, |
| 1678 | Register scratch3, |
| 1679 | Label* gc_required) { |
| 1680 | // Calculate the number of bytes needed for the characters in the string while |
| 1681 | // observing object alignment. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1682 | DCHECK((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0); |
| 1683 | DCHECK(kShortSize == 2); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1684 | // scratch1 = length * 2 + kObjectAlignmentMask. |
| 1685 | lea(scratch1, Operand(length, length, times_1, kObjectAlignmentMask)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1686 | and_(scratch1, Immediate(~kObjectAlignmentMask)); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1687 | |
| 1688 | // Allocate two byte string in new space. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1689 | Allocate(SeqTwoByteString::kHeaderSize, |
| 1690 | times_1, |
| 1691 | scratch1, |
| 1692 | REGISTER_VALUE_IS_INT32, |
| 1693 | result, |
| 1694 | scratch2, |
| 1695 | scratch3, |
| 1696 | gc_required, |
| 1697 | TAG_OBJECT); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1698 | |
| 1699 | // Set the map, length and hash field. |
| 1700 | mov(FieldOperand(result, HeapObject::kMapOffset), |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1701 | Immediate(isolate()->factory()->string_map())); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1702 | mov(scratch1, length); |
| 1703 | SmiTag(scratch1); |
| 1704 | mov(FieldOperand(result, String::kLengthOffset), scratch1); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1705 | mov(FieldOperand(result, String::kHashFieldOffset), |
| 1706 | Immediate(String::kEmptyHashField)); |
| 1707 | } |
| 1708 | |
| 1709 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1710 | void MacroAssembler::AllocateOneByteString(Register result, Register length, |
| 1711 | Register scratch1, Register scratch2, |
| 1712 | Register scratch3, |
| 1713 | Label* gc_required) { |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1714 | // Calculate the number of bytes needed for the characters in the string while |
| 1715 | // observing object alignment. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1716 | DCHECK((SeqOneByteString::kHeaderSize & kObjectAlignmentMask) == 0); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1717 | mov(scratch1, length); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1718 | DCHECK(kCharSize == 1); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1719 | add(scratch1, Immediate(kObjectAlignmentMask)); |
| 1720 | and_(scratch1, Immediate(~kObjectAlignmentMask)); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1721 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1722 | // Allocate one-byte string in new space. |
| 1723 | Allocate(SeqOneByteString::kHeaderSize, |
| 1724 | times_1, |
| 1725 | scratch1, |
| 1726 | REGISTER_VALUE_IS_INT32, |
| 1727 | result, |
| 1728 | scratch2, |
| 1729 | scratch3, |
| 1730 | gc_required, |
| 1731 | TAG_OBJECT); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1732 | |
| 1733 | // Set the map, length and hash field. |
| 1734 | mov(FieldOperand(result, HeapObject::kMapOffset), |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1735 | Immediate(isolate()->factory()->one_byte_string_map())); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1736 | mov(scratch1, length); |
| 1737 | SmiTag(scratch1); |
| 1738 | mov(FieldOperand(result, String::kLengthOffset), scratch1); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1739 | mov(FieldOperand(result, String::kHashFieldOffset), |
| 1740 | Immediate(String::kEmptyHashField)); |
| 1741 | } |
| 1742 | |
| 1743 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1744 | void MacroAssembler::AllocateOneByteString(Register result, int length, |
| 1745 | Register scratch1, Register scratch2, |
| 1746 | Label* gc_required) { |
| 1747 | DCHECK(length > 0); |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 1748 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1749 | // Allocate one-byte string in new space. |
| 1750 | Allocate(SeqOneByteString::SizeFor(length), result, scratch1, scratch2, |
| 1751 | gc_required, TAG_OBJECT); |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 1752 | |
| 1753 | // Set the map, length and hash field. |
| 1754 | mov(FieldOperand(result, HeapObject::kMapOffset), |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1755 | Immediate(isolate()->factory()->one_byte_string_map())); |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 1756 | mov(FieldOperand(result, String::kLengthOffset), |
| 1757 | Immediate(Smi::FromInt(length))); |
| 1758 | mov(FieldOperand(result, String::kHashFieldOffset), |
| 1759 | Immediate(String::kEmptyHashField)); |
| 1760 | } |
| 1761 | |
| 1762 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1763 | void MacroAssembler::AllocateTwoByteConsString(Register result, |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1764 | Register scratch1, |
| 1765 | Register scratch2, |
| 1766 | Label* gc_required) { |
| 1767 | // Allocate heap number in new space. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1768 | Allocate(ConsString::kSize, result, scratch1, scratch2, gc_required, |
| 1769 | TAG_OBJECT); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1770 | |
| 1771 | // Set the map. The other fields are left uninitialized. |
| 1772 | mov(FieldOperand(result, HeapObject::kMapOffset), |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1773 | Immediate(isolate()->factory()->cons_string_map())); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1774 | } |
| 1775 | |
| 1776 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1777 | void MacroAssembler::AllocateOneByteConsString(Register result, |
| 1778 | Register scratch1, |
| 1779 | Register scratch2, |
| 1780 | Label* gc_required) { |
| 1781 | Allocate(ConsString::kSize, |
| 1782 | result, |
| 1783 | scratch1, |
| 1784 | scratch2, |
| 1785 | gc_required, |
| 1786 | TAG_OBJECT); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1787 | |
| 1788 | // Set the map. The other fields are left uninitialized. |
| 1789 | mov(FieldOperand(result, HeapObject::kMapOffset), |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1790 | Immediate(isolate()->factory()->cons_one_byte_string_map())); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1791 | } |
| 1792 | |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 1793 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1794 | void MacroAssembler::AllocateTwoByteSlicedString(Register result, |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1795 | Register scratch1, |
| 1796 | Register scratch2, |
| 1797 | Label* gc_required) { |
| 1798 | // Allocate heap number in new space. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1799 | Allocate(SlicedString::kSize, result, scratch1, scratch2, gc_required, |
| 1800 | TAG_OBJECT); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1801 | |
| 1802 | // Set the map. The other fields are left uninitialized. |
| 1803 | mov(FieldOperand(result, HeapObject::kMapOffset), |
| 1804 | Immediate(isolate()->factory()->sliced_string_map())); |
| 1805 | } |
| 1806 | |
| 1807 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1808 | void MacroAssembler::AllocateOneByteSlicedString(Register result, |
| 1809 | Register scratch1, |
| 1810 | Register scratch2, |
| 1811 | Label* gc_required) { |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1812 | // Allocate heap number in new space. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1813 | Allocate(SlicedString::kSize, result, scratch1, scratch2, gc_required, |
| 1814 | TAG_OBJECT); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1815 | |
| 1816 | // Set the map. The other fields are left uninitialized. |
| 1817 | mov(FieldOperand(result, HeapObject::kMapOffset), |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1818 | Immediate(isolate()->factory()->sliced_one_byte_string_map())); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1819 | } |
| 1820 | |
| 1821 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 1822 | // Copy memory, byte-by-byte, from source to destination. Not optimized for |
| 1823 | // long or aligned copies. The contents of scratch and length are destroyed. |
| 1824 | // Source and destination are incremented by length. |
| 1825 | // Many variants of movsb, loop unrolling, word moves, and indexed operands |
| 1826 | // have been tried here already, and this is fastest. |
| 1827 | // A simpler loop is faster on small copies, but 30% slower on large ones. |
| 1828 | // The cld() instruction must have been emitted, to set the direction flag(), |
| 1829 | // before calling this function. |
| 1830 | void MacroAssembler::CopyBytes(Register source, |
| 1831 | Register destination, |
| 1832 | Register length, |
| 1833 | Register scratch) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1834 | Label short_loop, len4, len8, len12, done, short_string; |
| 1835 | DCHECK(source.is(esi)); |
| 1836 | DCHECK(destination.is(edi)); |
| 1837 | DCHECK(length.is(ecx)); |
| 1838 | cmp(length, Immediate(4)); |
| 1839 | j(below, &short_string, Label::kNear); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 1840 | |
| 1841 | // Because source is 4-byte aligned in our uses of this function, |
| 1842 | // we keep source aligned for the rep_movs call by copying the odd bytes |
| 1843 | // at the end of the ranges. |
| 1844 | mov(scratch, Operand(source, length, times_1, -4)); |
| 1845 | mov(Operand(destination, length, times_1, -4), scratch); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1846 | |
| 1847 | cmp(length, Immediate(8)); |
| 1848 | j(below_equal, &len4, Label::kNear); |
| 1849 | cmp(length, Immediate(12)); |
| 1850 | j(below_equal, &len8, Label::kNear); |
| 1851 | cmp(length, Immediate(16)); |
| 1852 | j(below_equal, &len12, Label::kNear); |
| 1853 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 1854 | mov(scratch, ecx); |
| 1855 | shr(ecx, 2); |
| 1856 | rep_movs(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1857 | and_(scratch, Immediate(0x3)); |
| 1858 | add(destination, scratch); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1859 | jmp(&done, Label::kNear); |
| 1860 | |
| 1861 | bind(&len12); |
| 1862 | mov(scratch, Operand(source, 8)); |
| 1863 | mov(Operand(destination, 8), scratch); |
| 1864 | bind(&len8); |
| 1865 | mov(scratch, Operand(source, 4)); |
| 1866 | mov(Operand(destination, 4), scratch); |
| 1867 | bind(&len4); |
| 1868 | mov(scratch, Operand(source, 0)); |
| 1869 | mov(Operand(destination, 0), scratch); |
| 1870 | add(destination, length); |
| 1871 | jmp(&done, Label::kNear); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 1872 | |
| 1873 | bind(&short_string); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1874 | test(length, length); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1875 | j(zero, &done, Label::kNear); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 1876 | |
| 1877 | bind(&short_loop); |
| 1878 | mov_b(scratch, Operand(source, 0)); |
| 1879 | mov_b(Operand(destination, 0), scratch); |
| 1880 | inc(source); |
| 1881 | inc(destination); |
| 1882 | dec(length); |
| 1883 | j(not_zero, &short_loop); |
| 1884 | |
| 1885 | bind(&done); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 1886 | } |
| 1887 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1888 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1889 | void MacroAssembler::InitializeFieldsWithFiller(Register start_offset, |
| 1890 | Register end_offset, |
| 1891 | Register filler) { |
| 1892 | Label loop, entry; |
| 1893 | jmp(&entry); |
| 1894 | bind(&loop); |
| 1895 | mov(Operand(start_offset, 0), filler); |
| 1896 | add(start_offset, Immediate(kPointerSize)); |
| 1897 | bind(&entry); |
| 1898 | cmp(start_offset, end_offset); |
| 1899 | j(less, &loop); |
| 1900 | } |
| 1901 | |
| 1902 | |
| 1903 | void MacroAssembler::BooleanBitTest(Register object, |
| 1904 | int field_offset, |
| 1905 | int bit_index) { |
| 1906 | bit_index += kSmiTagSize + kSmiShiftSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1907 | DCHECK(base::bits::IsPowerOfTwo32(kBitsPerByte)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1908 | int byte_index = bit_index / kBitsPerByte; |
| 1909 | int byte_bit_index = bit_index & (kBitsPerByte - 1); |
| 1910 | test_b(FieldOperand(object, field_offset + byte_index), |
| 1911 | static_cast<byte>(1 << byte_bit_index)); |
| 1912 | } |
| 1913 | |
| 1914 | |
| 1915 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1916 | void MacroAssembler::NegativeZeroTest(Register result, |
| 1917 | Register op, |
| 1918 | Label* then_label) { |
| 1919 | Label ok; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1920 | test(result, result); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1921 | j(not_zero, &ok); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1922 | test(op, op); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1923 | j(sign, then_label); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1924 | bind(&ok); |
| 1925 | } |
| 1926 | |
| 1927 | |
| 1928 | void MacroAssembler::NegativeZeroTest(Register result, |
| 1929 | Register op1, |
| 1930 | Register op2, |
| 1931 | Register scratch, |
| 1932 | Label* then_label) { |
| 1933 | Label ok; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1934 | test(result, result); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1935 | j(not_zero, &ok); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1936 | mov(scratch, op1); |
| 1937 | or_(scratch, op2); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1938 | j(sign, then_label); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1939 | bind(&ok); |
| 1940 | } |
| 1941 | |
| 1942 | |
| 1943 | void MacroAssembler::TryGetFunctionPrototype(Register function, |
| 1944 | Register result, |
| 1945 | Register scratch, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1946 | Label* miss, |
| 1947 | bool miss_on_bound_function) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1948 | Label non_instance; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1949 | if (miss_on_bound_function) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1950 | // Check that the receiver isn't a smi. |
| 1951 | JumpIfSmi(function, miss); |
| 1952 | |
| 1953 | // Check that the function really is a function. |
| 1954 | CmpObjectType(function, JS_FUNCTION_TYPE, result); |
| 1955 | j(not_equal, miss); |
| 1956 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1957 | // If a bound function, go to miss label. |
| 1958 | mov(scratch, |
| 1959 | FieldOperand(function, JSFunction::kSharedFunctionInfoOffset)); |
| 1960 | BooleanBitTest(scratch, SharedFunctionInfo::kCompilerHintsOffset, |
| 1961 | SharedFunctionInfo::kBoundFunction); |
| 1962 | j(not_zero, miss); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1963 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1964 | // Make sure that the function has an instance prototype. |
| 1965 | movzx_b(scratch, FieldOperand(result, Map::kBitFieldOffset)); |
| 1966 | test(scratch, Immediate(1 << Map::kHasNonInstancePrototype)); |
| 1967 | j(not_zero, &non_instance); |
| 1968 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1969 | |
| 1970 | // Get the prototype or initial map from the function. |
| 1971 | mov(result, |
| 1972 | FieldOperand(function, JSFunction::kPrototypeOrInitialMapOffset)); |
| 1973 | |
| 1974 | // If the prototype or initial map is the hole, don't return it and |
| 1975 | // simply miss the cache instead. This will allow us to allocate a |
| 1976 | // prototype object on-demand in the runtime system. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1977 | cmp(result, Immediate(isolate()->factory()->the_hole_value())); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1978 | j(equal, miss); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1979 | |
| 1980 | // If the function does not have an initial map, we're done. |
| 1981 | Label done; |
| 1982 | CmpObjectType(result, MAP_TYPE, scratch); |
| 1983 | j(not_equal, &done); |
| 1984 | |
| 1985 | // Get the prototype from the initial map. |
| 1986 | mov(result, FieldOperand(result, Map::kPrototypeOffset)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1987 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1988 | if (miss_on_bound_function) { |
| 1989 | jmp(&done); |
| 1990 | |
| 1991 | // Non-instance prototype: Fetch prototype from constructor field |
| 1992 | // in initial map. |
| 1993 | bind(&non_instance); |
| 1994 | mov(result, FieldOperand(result, Map::kConstructorOffset)); |
| 1995 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1996 | |
| 1997 | // All done. |
| 1998 | bind(&done); |
| 1999 | } |
| 2000 | |
| 2001 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2002 | void MacroAssembler::CallStub(CodeStub* stub, TypeFeedbackId ast_id) { |
| 2003 | DCHECK(AllowThisStubCall(stub)); // Calls are not allowed in some stubs. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2004 | call(stub->GetCode(), RelocInfo::CODE_TARGET, ast_id); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2005 | } |
| 2006 | |
| 2007 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2008 | void MacroAssembler::TailCallStub(CodeStub* stub) { |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2009 | jmp(stub->GetCode(), RelocInfo::CODE_TARGET); |
| 2010 | } |
| 2011 | |
| 2012 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2013 | void MacroAssembler::StubReturn(int argc) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2014 | DCHECK(argc >= 1 && generating_stub()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2015 | ret((argc - 1) * kPointerSize); |
| 2016 | } |
| 2017 | |
| 2018 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2019 | bool MacroAssembler::AllowThisStubCall(CodeStub* stub) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2020 | return has_frame_ || !stub->SometimesSetsUpAFrame(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2021 | } |
| 2022 | |
| 2023 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2024 | void MacroAssembler::IndexFromHash(Register hash, Register index) { |
| 2025 | // The assert checks that the constants for the maximum number of digits |
| 2026 | // for an array index cached in the hash field and the number of bits |
| 2027 | // reserved for it does not conflict. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2028 | DCHECK(TenToThe(String::kMaxCachedArrayIndexLength) < |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2029 | (1 << String::kArrayIndexValueBits)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2030 | if (!index.is(hash)) { |
| 2031 | mov(index, hash); |
| 2032 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2033 | DecodeFieldToSmi<String::ArrayIndexValueBits>(index); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2034 | } |
| 2035 | |
| 2036 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2037 | void MacroAssembler::CallRuntime(const Runtime::Function* f, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2038 | int num_arguments, |
| 2039 | SaveFPRegsMode save_doubles) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2040 | // If the expected number of arguments of the runtime function is |
| 2041 | // constant, we check that the actual number of arguments match the |
| 2042 | // expectation. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2043 | CHECK(f->nargs < 0 || f->nargs == num_arguments); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2044 | |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 2045 | // TODO(1236192): Most runtime routines don't need the number of |
| 2046 | // arguments passed in because it is constant. At some point we |
| 2047 | // should remove this need and make the runtime routine entry code |
| 2048 | // smarter. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2049 | Move(eax, Immediate(num_arguments)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2050 | mov(ebx, Immediate(ExternalReference(f, isolate()))); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2051 | CEntryStub ces(isolate(), 1, save_doubles); |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 2052 | CallStub(&ces); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2053 | } |
| 2054 | |
| 2055 | |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 2056 | void MacroAssembler::CallExternalReference(ExternalReference ref, |
| 2057 | int num_arguments) { |
| 2058 | mov(eax, Immediate(num_arguments)); |
| 2059 | mov(ebx, Immediate(ref)); |
| 2060 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2061 | CEntryStub stub(isolate(), 1); |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 2062 | CallStub(&stub); |
| 2063 | } |
| 2064 | |
| 2065 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2066 | void MacroAssembler::TailCallExternalReference(const ExternalReference& ext, |
| 2067 | int num_arguments, |
| 2068 | int result_size) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2069 | // TODO(1236192): Most runtime routines don't need the number of |
| 2070 | // arguments passed in because it is constant. At some point we |
| 2071 | // should remove this need and make the runtime routine entry code |
| 2072 | // smarter. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2073 | Move(eax, Immediate(num_arguments)); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2074 | JumpToExternalReference(ext); |
| 2075 | } |
| 2076 | |
| 2077 | |
| 2078 | void MacroAssembler::TailCallRuntime(Runtime::FunctionId fid, |
| 2079 | int num_arguments, |
| 2080 | int result_size) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2081 | TailCallExternalReference(ExternalReference(fid, isolate()), |
| 2082 | num_arguments, |
| 2083 | result_size); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2084 | } |
| 2085 | |
| 2086 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2087 | Operand ApiParameterOperand(int index) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2088 | return Operand(esp, index * kPointerSize); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2089 | } |
| 2090 | |
| 2091 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2092 | void MacroAssembler::PrepareCallApiFunction(int argc) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2093 | EnterApiExitFrame(argc); |
| 2094 | if (emit_debug_code()) { |
| 2095 | mov(esi, Immediate(bit_cast<int32_t>(kZapValue))); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 2096 | } |
| 2097 | } |
| 2098 | |
| 2099 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2100 | void MacroAssembler::CallApiFunctionAndReturn( |
| 2101 | Register function_address, |
| 2102 | ExternalReference thunk_ref, |
| 2103 | Operand thunk_last_arg, |
| 2104 | int stack_space, |
| 2105 | Operand return_value_operand, |
| 2106 | Operand* context_restore_operand) { |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2107 | ExternalReference next_address = |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2108 | ExternalReference::handle_scope_next_address(isolate()); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2109 | ExternalReference limit_address = |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2110 | ExternalReference::handle_scope_limit_address(isolate()); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2111 | ExternalReference level_address = |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2112 | ExternalReference::handle_scope_level_address(isolate()); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2113 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2114 | DCHECK(edx.is(function_address)); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2115 | // Allocate HandleScope in callee-save registers. |
| 2116 | mov(ebx, Operand::StaticVariable(next_address)); |
| 2117 | mov(edi, Operand::StaticVariable(limit_address)); |
| 2118 | add(Operand::StaticVariable(level_address), Immediate(1)); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2119 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2120 | if (FLAG_log_timer_events) { |
| 2121 | FrameScope frame(this, StackFrame::MANUAL); |
| 2122 | PushSafepointRegisters(); |
| 2123 | PrepareCallCFunction(1, eax); |
| 2124 | mov(Operand(esp, 0), |
| 2125 | Immediate(ExternalReference::isolate_address(isolate()))); |
| 2126 | CallCFunction(ExternalReference::log_enter_external_function(isolate()), 1); |
| 2127 | PopSafepointRegisters(); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2128 | } |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2129 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2130 | |
| 2131 | Label profiler_disabled; |
| 2132 | Label end_profiler_check; |
| 2133 | mov(eax, Immediate(ExternalReference::is_profiling_address(isolate()))); |
| 2134 | cmpb(Operand(eax, 0), 0); |
| 2135 | j(zero, &profiler_disabled); |
| 2136 | |
| 2137 | // Additional parameter is the address of the actual getter function. |
| 2138 | mov(thunk_last_arg, function_address); |
| 2139 | // Call the api function. |
| 2140 | mov(eax, Immediate(thunk_ref)); |
| 2141 | call(eax); |
| 2142 | jmp(&end_profiler_check); |
| 2143 | |
| 2144 | bind(&profiler_disabled); |
| 2145 | // Call the api function. |
| 2146 | call(function_address); |
| 2147 | bind(&end_profiler_check); |
| 2148 | |
| 2149 | if (FLAG_log_timer_events) { |
| 2150 | FrameScope frame(this, StackFrame::MANUAL); |
| 2151 | PushSafepointRegisters(); |
| 2152 | PrepareCallCFunction(1, eax); |
| 2153 | mov(Operand(esp, 0), |
| 2154 | Immediate(ExternalReference::isolate_address(isolate()))); |
| 2155 | CallCFunction(ExternalReference::log_leave_external_function(isolate()), 1); |
| 2156 | PopSafepointRegisters(); |
| 2157 | } |
| 2158 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2159 | Label prologue; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2160 | // Load the value from ReturnValue |
| 2161 | mov(eax, return_value_operand); |
| 2162 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2163 | Label promote_scheduled_exception; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2164 | Label exception_handled; |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2165 | Label delete_allocated_handles; |
| 2166 | Label leave_exit_frame; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2167 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2168 | bind(&prologue); |
| 2169 | // No more valid handles (the result handle was the last one). Restore |
| 2170 | // previous handle scope. |
| 2171 | mov(Operand::StaticVariable(next_address), ebx); |
| 2172 | sub(Operand::StaticVariable(level_address), Immediate(1)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2173 | Assert(above_equal, kInvalidHandleScopeLevel); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2174 | cmp(edi, Operand::StaticVariable(limit_address)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2175 | j(not_equal, &delete_allocated_handles); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2176 | bind(&leave_exit_frame); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2177 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2178 | // Check if the function scheduled an exception. |
| 2179 | ExternalReference scheduled_exception_address = |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2180 | ExternalReference::scheduled_exception_address(isolate()); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2181 | cmp(Operand::StaticVariable(scheduled_exception_address), |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2182 | Immediate(isolate()->factory()->the_hole_value())); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2183 | j(not_equal, &promote_scheduled_exception); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2184 | bind(&exception_handled); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2185 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2186 | #if ENABLE_EXTRA_CHECKS |
| 2187 | // Check if the function returned a valid JavaScript value. |
| 2188 | Label ok; |
| 2189 | Register return_value = eax; |
| 2190 | Register map = ecx; |
| 2191 | |
| 2192 | JumpIfSmi(return_value, &ok, Label::kNear); |
| 2193 | mov(map, FieldOperand(return_value, HeapObject::kMapOffset)); |
| 2194 | |
| 2195 | CmpInstanceType(map, FIRST_NONSTRING_TYPE); |
| 2196 | j(below, &ok, Label::kNear); |
| 2197 | |
| 2198 | CmpInstanceType(map, FIRST_SPEC_OBJECT_TYPE); |
| 2199 | j(above_equal, &ok, Label::kNear); |
| 2200 | |
| 2201 | cmp(map, isolate()->factory()->heap_number_map()); |
| 2202 | j(equal, &ok, Label::kNear); |
| 2203 | |
| 2204 | cmp(return_value, isolate()->factory()->undefined_value()); |
| 2205 | j(equal, &ok, Label::kNear); |
| 2206 | |
| 2207 | cmp(return_value, isolate()->factory()->true_value()); |
| 2208 | j(equal, &ok, Label::kNear); |
| 2209 | |
| 2210 | cmp(return_value, isolate()->factory()->false_value()); |
| 2211 | j(equal, &ok, Label::kNear); |
| 2212 | |
| 2213 | cmp(return_value, isolate()->factory()->null_value()); |
| 2214 | j(equal, &ok, Label::kNear); |
| 2215 | |
| 2216 | Abort(kAPICallReturnedInvalidObject); |
| 2217 | |
| 2218 | bind(&ok); |
| 2219 | #endif |
| 2220 | |
| 2221 | bool restore_context = context_restore_operand != NULL; |
| 2222 | if (restore_context) { |
| 2223 | mov(esi, *context_restore_operand); |
| 2224 | } |
| 2225 | LeaveApiExitFrame(!restore_context); |
| 2226 | ret(stack_space * kPointerSize); |
| 2227 | |
| 2228 | bind(&promote_scheduled_exception); |
| 2229 | { |
| 2230 | FrameScope frame(this, StackFrame::INTERNAL); |
| 2231 | CallRuntime(Runtime::kPromoteScheduledException, 0); |
| 2232 | } |
| 2233 | jmp(&exception_handled); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2234 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2235 | // HandleScope limit has changed. Delete allocated extensions. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2236 | ExternalReference delete_extensions = |
| 2237 | ExternalReference::delete_handle_scope_extensions(isolate()); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2238 | bind(&delete_allocated_handles); |
| 2239 | mov(Operand::StaticVariable(limit_address), edi); |
| 2240 | mov(edi, eax); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2241 | mov(Operand(esp, 0), |
| 2242 | Immediate(ExternalReference::isolate_address(isolate()))); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2243 | mov(eax, Immediate(delete_extensions)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2244 | call(eax); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2245 | mov(eax, edi); |
| 2246 | jmp(&leave_exit_frame); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2247 | } |
| 2248 | |
| 2249 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2250 | void MacroAssembler::JumpToExternalReference(const ExternalReference& ext) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2251 | // Set the entry point and jump to the C entry runtime stub. |
| 2252 | mov(ebx, Immediate(ext)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2253 | CEntryStub ces(isolate(), 1); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2254 | jmp(ces.GetCode(), RelocInfo::CODE_TARGET); |
| 2255 | } |
| 2256 | |
| 2257 | |
| 2258 | void MacroAssembler::InvokePrologue(const ParameterCount& expected, |
| 2259 | const ParameterCount& actual, |
| 2260 | Handle<Code> code_constant, |
| 2261 | const Operand& code_operand, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2262 | Label* done, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2263 | bool* definitely_mismatches, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2264 | InvokeFlag flag, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2265 | Label::Distance done_near, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2266 | const CallWrapper& call_wrapper) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2267 | bool definitely_matches = false; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2268 | *definitely_mismatches = false; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2269 | Label invoke; |
| 2270 | if (expected.is_immediate()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2271 | DCHECK(actual.is_immediate()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2272 | if (expected.immediate() == actual.immediate()) { |
| 2273 | definitely_matches = true; |
| 2274 | } else { |
| 2275 | mov(eax, actual.immediate()); |
| 2276 | const int sentinel = SharedFunctionInfo::kDontAdaptArgumentsSentinel; |
| 2277 | if (expected.immediate() == sentinel) { |
| 2278 | // Don't worry about adapting arguments for builtins that |
| 2279 | // don't want that done. Skip adaption code by making it look |
| 2280 | // like we have a match between expected and actual number of |
| 2281 | // arguments. |
| 2282 | definitely_matches = true; |
| 2283 | } else { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2284 | *definitely_mismatches = true; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2285 | mov(ebx, expected.immediate()); |
| 2286 | } |
| 2287 | } |
| 2288 | } else { |
| 2289 | if (actual.is_immediate()) { |
| 2290 | // Expected is in register, actual is immediate. This is the |
| 2291 | // case when we invoke function values without going through the |
| 2292 | // IC mechanism. |
| 2293 | cmp(expected.reg(), actual.immediate()); |
| 2294 | j(equal, &invoke); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2295 | DCHECK(expected.reg().is(ebx)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2296 | mov(eax, actual.immediate()); |
| 2297 | } else if (!expected.reg().is(actual.reg())) { |
| 2298 | // Both expected and actual are in (different) registers. This |
| 2299 | // is the case when we invoke functions using call and apply. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2300 | cmp(expected.reg(), actual.reg()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2301 | j(equal, &invoke); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2302 | DCHECK(actual.reg().is(eax)); |
| 2303 | DCHECK(expected.reg().is(ebx)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2304 | } |
| 2305 | } |
| 2306 | |
| 2307 | if (!definitely_matches) { |
| 2308 | Handle<Code> adaptor = |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2309 | isolate()->builtins()->ArgumentsAdaptorTrampoline(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2310 | if (!code_constant.is_null()) { |
| 2311 | mov(edx, Immediate(code_constant)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2312 | add(edx, Immediate(Code::kHeaderSize - kHeapObjectTag)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2313 | } else if (!code_operand.is_reg(edx)) { |
| 2314 | mov(edx, code_operand); |
| 2315 | } |
| 2316 | |
| 2317 | if (flag == CALL_FUNCTION) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2318 | call_wrapper.BeforeCall(CallSize(adaptor, RelocInfo::CODE_TARGET)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2319 | call(adaptor, RelocInfo::CODE_TARGET); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2320 | call_wrapper.AfterCall(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2321 | if (!*definitely_mismatches) { |
| 2322 | jmp(done, done_near); |
| 2323 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2324 | } else { |
| 2325 | jmp(adaptor, RelocInfo::CODE_TARGET); |
| 2326 | } |
| 2327 | bind(&invoke); |
| 2328 | } |
| 2329 | } |
| 2330 | |
| 2331 | |
| 2332 | void MacroAssembler::InvokeCode(const Operand& code, |
| 2333 | const ParameterCount& expected, |
| 2334 | const ParameterCount& actual, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2335 | InvokeFlag flag, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2336 | const CallWrapper& call_wrapper) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2337 | // You can't call a function without a valid frame. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2338 | DCHECK(flag == JUMP_FUNCTION || has_frame()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2339 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2340 | Label done; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2341 | bool definitely_mismatches = false; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2342 | InvokePrologue(expected, actual, Handle<Code>::null(), code, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2343 | &done, &definitely_mismatches, flag, Label::kNear, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2344 | call_wrapper); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2345 | if (!definitely_mismatches) { |
| 2346 | if (flag == CALL_FUNCTION) { |
| 2347 | call_wrapper.BeforeCall(CallSize(code)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2348 | call(code); |
| 2349 | call_wrapper.AfterCall(); |
| 2350 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2351 | DCHECK(flag == JUMP_FUNCTION); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2352 | jmp(code); |
| 2353 | } |
| 2354 | bind(&done); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2355 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2356 | } |
| 2357 | |
| 2358 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2359 | void MacroAssembler::InvokeFunction(Register fun, |
| 2360 | const ParameterCount& actual, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2361 | InvokeFlag flag, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2362 | const CallWrapper& call_wrapper) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2363 | // You can't call a function without a valid frame. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2364 | DCHECK(flag == JUMP_FUNCTION || has_frame()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2365 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2366 | DCHECK(fun.is(edi)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2367 | mov(edx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); |
| 2368 | mov(esi, FieldOperand(edi, JSFunction::kContextOffset)); |
| 2369 | mov(ebx, FieldOperand(edx, SharedFunctionInfo::kFormalParameterCountOffset)); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 2370 | SmiUntag(ebx); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2371 | |
| 2372 | ParameterCount expected(ebx); |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 2373 | InvokeCode(FieldOperand(edi, JSFunction::kCodeEntryOffset), |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2374 | expected, actual, flag, call_wrapper); |
| 2375 | } |
| 2376 | |
| 2377 | |
| 2378 | void MacroAssembler::InvokeFunction(Register fun, |
| 2379 | const ParameterCount& expected, |
| 2380 | const ParameterCount& actual, |
| 2381 | InvokeFlag flag, |
| 2382 | const CallWrapper& call_wrapper) { |
| 2383 | // You can't call a function without a valid frame. |
| 2384 | DCHECK(flag == JUMP_FUNCTION || has_frame()); |
| 2385 | |
| 2386 | DCHECK(fun.is(edi)); |
| 2387 | mov(esi, FieldOperand(edi, JSFunction::kContextOffset)); |
| 2388 | |
| 2389 | InvokeCode(FieldOperand(edi, JSFunction::kCodeEntryOffset), |
| 2390 | expected, actual, flag, call_wrapper); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2391 | } |
| 2392 | |
| 2393 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2394 | void MacroAssembler::InvokeFunction(Handle<JSFunction> function, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2395 | const ParameterCount& expected, |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 2396 | const ParameterCount& actual, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2397 | InvokeFlag flag, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2398 | const CallWrapper& call_wrapper) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2399 | LoadHeapObject(edi, function); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2400 | InvokeFunction(edi, expected, actual, flag, call_wrapper); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 2401 | } |
| 2402 | |
| 2403 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2404 | void MacroAssembler::InvokeBuiltin(Builtins::JavaScript id, |
| 2405 | InvokeFlag flag, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2406 | const CallWrapper& call_wrapper) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2407 | // You can't call a builtin without a valid frame. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2408 | DCHECK(flag == JUMP_FUNCTION || has_frame()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2409 | |
| 2410 | // Rely on the assertion to check that the number of provided |
| 2411 | // arguments match the expected number of arguments. Fake a |
| 2412 | // parameter count to avoid emitting code to do the check. |
| 2413 | ParameterCount expected(0); |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 2414 | GetBuiltinFunction(edi, id); |
| 2415 | InvokeCode(FieldOperand(edi, JSFunction::kCodeEntryOffset), |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2416 | expected, expected, flag, call_wrapper); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2417 | } |
| 2418 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2419 | |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 2420 | void MacroAssembler::GetBuiltinFunction(Register target, |
| 2421 | Builtins::JavaScript id) { |
| 2422 | // Load the JavaScript builtin function from the builtins object. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2423 | mov(target, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 2424 | mov(target, FieldOperand(target, GlobalObject::kBuiltinsOffset)); |
| 2425 | mov(target, FieldOperand(target, |
| 2426 | JSBuiltinsObject::OffsetOfFunctionWithId(id))); |
| 2427 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2428 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2429 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2430 | void MacroAssembler::GetBuiltinEntry(Register target, Builtins::JavaScript id) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2431 | DCHECK(!target.is(edi)); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 2432 | // Load the JavaScript builtin function from the builtins object. |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 2433 | GetBuiltinFunction(edi, id); |
| 2434 | // Load the code entry point from the function into the target register. |
| 2435 | mov(target, FieldOperand(edi, JSFunction::kCodeEntryOffset)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2436 | } |
| 2437 | |
| 2438 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2439 | void MacroAssembler::LoadContext(Register dst, int context_chain_length) { |
| 2440 | if (context_chain_length > 0) { |
| 2441 | // Move up the chain of contexts to the context containing the slot. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2442 | mov(dst, Operand(esi, Context::SlotOffset(Context::PREVIOUS_INDEX))); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2443 | for (int i = 1; i < context_chain_length; i++) { |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2444 | mov(dst, Operand(dst, Context::SlotOffset(Context::PREVIOUS_INDEX))); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2445 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2446 | } else { |
| 2447 | // Slot is in the current function context. Move it into the |
| 2448 | // destination register in case we store into it (the write barrier |
| 2449 | // cannot be allowed to destroy the context in esi). |
| 2450 | mov(dst, esi); |
| 2451 | } |
| 2452 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2453 | // We should not have found a with context by walking the context chain |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2454 | // (i.e., the static scope chain and runtime context chain do not agree). |
| 2455 | // A variable occurring in such a scope should have slot type LOOKUP and |
| 2456 | // not CONTEXT. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2457 | if (emit_debug_code()) { |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2458 | cmp(FieldOperand(dst, HeapObject::kMapOffset), |
| 2459 | isolate()->factory()->with_context_map()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2460 | Check(not_equal, kVariableResolvedToWithContext); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2461 | } |
| 2462 | } |
| 2463 | |
| 2464 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2465 | void MacroAssembler::LoadTransitionedArrayMapConditional( |
| 2466 | ElementsKind expected_kind, |
| 2467 | ElementsKind transitioned_kind, |
| 2468 | Register map_in_out, |
| 2469 | Register scratch, |
| 2470 | Label* no_map_match) { |
| 2471 | // Load the global or builtins object from the current context. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2472 | mov(scratch, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 2473 | mov(scratch, FieldOperand(scratch, GlobalObject::kNativeContextOffset)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2474 | |
| 2475 | // Check that the function's map is the same as the expected cached map. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2476 | mov(scratch, Operand(scratch, |
| 2477 | Context::SlotOffset(Context::JS_ARRAY_MAPS_INDEX))); |
| 2478 | |
| 2479 | size_t offset = expected_kind * kPointerSize + |
| 2480 | FixedArrayBase::kHeaderSize; |
| 2481 | cmp(map_in_out, FieldOperand(scratch, offset)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2482 | j(not_equal, no_map_match); |
| 2483 | |
| 2484 | // Use the transitioned cached map. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2485 | offset = transitioned_kind * kPointerSize + |
| 2486 | FixedArrayBase::kHeaderSize; |
| 2487 | mov(map_in_out, FieldOperand(scratch, offset)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2488 | } |
| 2489 | |
| 2490 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2491 | void MacroAssembler::LoadGlobalFunction(int index, Register function) { |
| 2492 | // Load the global or builtins object from the current context. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2493 | mov(function, |
| 2494 | Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 2495 | // Load the native context from the global or builtins object. |
| 2496 | mov(function, |
| 2497 | FieldOperand(function, GlobalObject::kNativeContextOffset)); |
| 2498 | // Load the function from the native context. |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2499 | mov(function, Operand(function, Context::SlotOffset(index))); |
| 2500 | } |
| 2501 | |
| 2502 | |
| 2503 | void MacroAssembler::LoadGlobalFunctionInitialMap(Register function, |
| 2504 | Register map) { |
| 2505 | // Load the initial map. The global functions all have initial maps. |
| 2506 | mov(map, FieldOperand(function, JSFunction::kPrototypeOrInitialMapOffset)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2507 | if (emit_debug_code()) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2508 | Label ok, fail; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2509 | CheckMap(map, isolate()->factory()->meta_map(), &fail, DO_SMI_CHECK); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2510 | jmp(&ok); |
| 2511 | bind(&fail); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2512 | Abort(kGlobalFunctionsMustHaveInitialMap); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2513 | bind(&ok); |
| 2514 | } |
| 2515 | } |
| 2516 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2517 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2518 | // Store the value in register src in the safepoint register stack |
| 2519 | // slot for register dst. |
| 2520 | void MacroAssembler::StoreToSafepointRegisterSlot(Register dst, Register src) { |
| 2521 | mov(SafepointRegisterSlot(dst), src); |
| 2522 | } |
| 2523 | |
| 2524 | |
| 2525 | void MacroAssembler::StoreToSafepointRegisterSlot(Register dst, Immediate src) { |
| 2526 | mov(SafepointRegisterSlot(dst), src); |
| 2527 | } |
| 2528 | |
| 2529 | |
| 2530 | void MacroAssembler::LoadFromSafepointRegisterSlot(Register dst, Register src) { |
| 2531 | mov(dst, SafepointRegisterSlot(src)); |
| 2532 | } |
| 2533 | |
| 2534 | |
| 2535 | Operand MacroAssembler::SafepointRegisterSlot(Register reg) { |
| 2536 | return Operand(esp, SafepointRegisterStackIndex(reg.code()) * kPointerSize); |
| 2537 | } |
| 2538 | |
| 2539 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2540 | int MacroAssembler::SafepointRegisterStackIndex(int reg_code) { |
| 2541 | // The registers are pushed starting with the lowest encoding, |
| 2542 | // which means that lowest encodings are furthest away from |
| 2543 | // the stack pointer. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2544 | DCHECK(reg_code >= 0 && reg_code < kNumSafepointRegisters); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2545 | return kNumSafepointRegisters - reg_code - 1; |
| 2546 | } |
| 2547 | |
| 2548 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2549 | void MacroAssembler::LoadHeapObject(Register result, |
| 2550 | Handle<HeapObject> object) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2551 | AllowDeferredHandleDereference embedding_raw_address; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2552 | if (isolate()->heap()->InNewSpace(*object)) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2553 | Handle<Cell> cell = isolate()->factory()->NewCell(object); |
| 2554 | mov(result, Operand::ForCell(cell)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2555 | } else { |
| 2556 | mov(result, object); |
| 2557 | } |
| 2558 | } |
| 2559 | |
| 2560 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2561 | void MacroAssembler::CmpHeapObject(Register reg, Handle<HeapObject> object) { |
| 2562 | AllowDeferredHandleDereference using_raw_address; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2563 | if (isolate()->heap()->InNewSpace(*object)) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2564 | Handle<Cell> cell = isolate()->factory()->NewCell(object); |
| 2565 | cmp(reg, Operand::ForCell(cell)); |
| 2566 | } else { |
| 2567 | cmp(reg, object); |
| 2568 | } |
| 2569 | } |
| 2570 | |
| 2571 | |
| 2572 | void MacroAssembler::PushHeapObject(Handle<HeapObject> object) { |
| 2573 | AllowDeferredHandleDereference using_raw_address; |
| 2574 | if (isolate()->heap()->InNewSpace(*object)) { |
| 2575 | Handle<Cell> cell = isolate()->factory()->NewCell(object); |
| 2576 | push(Operand::ForCell(cell)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2577 | } else { |
| 2578 | Push(object); |
| 2579 | } |
| 2580 | } |
| 2581 | |
| 2582 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2583 | void MacroAssembler::CmpWeakValue(Register value, Handle<WeakCell> cell, |
| 2584 | Register scratch) { |
| 2585 | mov(scratch, cell); |
| 2586 | cmp(value, FieldOperand(scratch, WeakCell::kValueOffset)); |
| 2587 | } |
| 2588 | |
| 2589 | |
| 2590 | void MacroAssembler::LoadWeakValue(Register value, Handle<WeakCell> cell, |
| 2591 | Label* miss) { |
| 2592 | mov(value, cell); |
| 2593 | mov(value, FieldOperand(value, WeakCell::kValueOffset)); |
| 2594 | JumpIfSmi(value, miss); |
| 2595 | } |
| 2596 | |
| 2597 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2598 | void MacroAssembler::Ret() { |
| 2599 | ret(0); |
| 2600 | } |
| 2601 | |
| 2602 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2603 | void MacroAssembler::Ret(int bytes_dropped, Register scratch) { |
| 2604 | if (is_uint16(bytes_dropped)) { |
| 2605 | ret(bytes_dropped); |
| 2606 | } else { |
| 2607 | pop(scratch); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2608 | add(esp, Immediate(bytes_dropped)); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2609 | push(scratch); |
| 2610 | ret(0); |
| 2611 | } |
| 2612 | } |
| 2613 | |
| 2614 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2615 | void MacroAssembler::Drop(int stack_elements) { |
| 2616 | if (stack_elements > 0) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2617 | add(esp, Immediate(stack_elements * kPointerSize)); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2618 | } |
| 2619 | } |
| 2620 | |
| 2621 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 2622 | void MacroAssembler::Move(Register dst, Register src) { |
| 2623 | if (!dst.is(src)) { |
| 2624 | mov(dst, src); |
| 2625 | } |
| 2626 | } |
| 2627 | |
| 2628 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2629 | void MacroAssembler::Move(Register dst, const Immediate& x) { |
| 2630 | if (x.is_zero()) { |
| 2631 | xor_(dst, dst); // Shorter than mov of 32-bit immediate 0. |
| 2632 | } else { |
| 2633 | mov(dst, x); |
| 2634 | } |
| 2635 | } |
| 2636 | |
| 2637 | |
| 2638 | void MacroAssembler::Move(const Operand& dst, const Immediate& x) { |
| 2639 | mov(dst, x); |
| 2640 | } |
| 2641 | |
| 2642 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2643 | void MacroAssembler::Move(XMMRegister dst, uint32_t src) { |
| 2644 | if (src == 0) { |
| 2645 | pxor(dst, dst); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2646 | } else { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2647 | unsigned cnt = base::bits::CountPopulation32(src); |
| 2648 | unsigned nlz = base::bits::CountLeadingZeros32(src); |
| 2649 | unsigned ntz = base::bits::CountTrailingZeros32(src); |
| 2650 | if (nlz + cnt + ntz == 32) { |
| 2651 | pcmpeqd(dst, dst); |
| 2652 | if (ntz == 0) { |
| 2653 | psrld(dst, 32 - cnt); |
| 2654 | } else { |
| 2655 | pslld(dst, 32 - cnt); |
| 2656 | if (nlz != 0) psrld(dst, nlz); |
| 2657 | } |
| 2658 | } else { |
| 2659 | push(eax); |
| 2660 | mov(eax, Immediate(src)); |
| 2661 | movd(dst, Operand(eax)); |
| 2662 | pop(eax); |
| 2663 | } |
| 2664 | } |
| 2665 | } |
| 2666 | |
| 2667 | |
| 2668 | void MacroAssembler::Move(XMMRegister dst, uint64_t src) { |
| 2669 | uint32_t lower = static_cast<uint32_t>(src); |
| 2670 | uint32_t upper = static_cast<uint32_t>(src >> 32); |
| 2671 | if (upper == 0) { |
| 2672 | Move(dst, lower); |
| 2673 | } else { |
| 2674 | unsigned cnt = base::bits::CountPopulation64(src); |
| 2675 | unsigned nlz = base::bits::CountLeadingZeros64(src); |
| 2676 | unsigned ntz = base::bits::CountTrailingZeros64(src); |
| 2677 | if (nlz + cnt + ntz == 64) { |
| 2678 | pcmpeqd(dst, dst); |
| 2679 | if (ntz == 0) { |
| 2680 | psrlq(dst, 64 - cnt); |
| 2681 | } else { |
| 2682 | psllq(dst, 64 - cnt); |
| 2683 | if (nlz != 0) psrlq(dst, nlz); |
| 2684 | } |
| 2685 | } else if (lower == 0) { |
| 2686 | Move(dst, upper); |
| 2687 | psllq(dst, 32); |
| 2688 | } else if (CpuFeatures::IsSupported(SSE4_1)) { |
| 2689 | CpuFeatureScope scope(this, SSE4_1); |
| 2690 | push(eax); |
| 2691 | Move(eax, Immediate(lower)); |
| 2692 | movd(dst, Operand(eax)); |
| 2693 | Move(eax, Immediate(upper)); |
| 2694 | pinsrd(dst, Operand(eax), 1); |
| 2695 | pop(eax); |
| 2696 | } else { |
| 2697 | push(Immediate(upper)); |
| 2698 | push(Immediate(lower)); |
| 2699 | movsd(dst, Operand(esp, 0)); |
| 2700 | add(esp, Immediate(kDoubleSize)); |
| 2701 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2702 | } |
| 2703 | } |
| 2704 | |
| 2705 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2706 | void MacroAssembler::SetCounter(StatsCounter* counter, int value) { |
| 2707 | if (FLAG_native_code_counters && counter->Enabled()) { |
| 2708 | mov(Operand::StaticVariable(ExternalReference(counter)), Immediate(value)); |
| 2709 | } |
| 2710 | } |
| 2711 | |
| 2712 | |
| 2713 | void MacroAssembler::IncrementCounter(StatsCounter* counter, int value) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2714 | DCHECK(value > 0); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2715 | if (FLAG_native_code_counters && counter->Enabled()) { |
| 2716 | Operand operand = Operand::StaticVariable(ExternalReference(counter)); |
| 2717 | if (value == 1) { |
| 2718 | inc(operand); |
| 2719 | } else { |
| 2720 | add(operand, Immediate(value)); |
| 2721 | } |
| 2722 | } |
| 2723 | } |
| 2724 | |
| 2725 | |
| 2726 | void MacroAssembler::DecrementCounter(StatsCounter* counter, int value) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2727 | DCHECK(value > 0); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2728 | if (FLAG_native_code_counters && counter->Enabled()) { |
| 2729 | Operand operand = Operand::StaticVariable(ExternalReference(counter)); |
| 2730 | if (value == 1) { |
| 2731 | dec(operand); |
| 2732 | } else { |
| 2733 | sub(operand, Immediate(value)); |
| 2734 | } |
| 2735 | } |
| 2736 | } |
| 2737 | |
| 2738 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 2739 | void MacroAssembler::IncrementCounter(Condition cc, |
| 2740 | StatsCounter* counter, |
| 2741 | int value) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2742 | DCHECK(value > 0); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 2743 | if (FLAG_native_code_counters && counter->Enabled()) { |
| 2744 | Label skip; |
| 2745 | j(NegateCondition(cc), &skip); |
| 2746 | pushfd(); |
| 2747 | IncrementCounter(counter, value); |
| 2748 | popfd(); |
| 2749 | bind(&skip); |
| 2750 | } |
| 2751 | } |
| 2752 | |
| 2753 | |
| 2754 | void MacroAssembler::DecrementCounter(Condition cc, |
| 2755 | StatsCounter* counter, |
| 2756 | int value) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2757 | DCHECK(value > 0); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 2758 | if (FLAG_native_code_counters && counter->Enabled()) { |
| 2759 | Label skip; |
| 2760 | j(NegateCondition(cc), &skip); |
| 2761 | pushfd(); |
| 2762 | DecrementCounter(counter, value); |
| 2763 | popfd(); |
| 2764 | bind(&skip); |
| 2765 | } |
| 2766 | } |
| 2767 | |
| 2768 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2769 | void MacroAssembler::Assert(Condition cc, BailoutReason reason) { |
| 2770 | if (emit_debug_code()) Check(cc, reason); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2771 | } |
| 2772 | |
| 2773 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 2774 | void MacroAssembler::AssertFastElements(Register elements) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2775 | if (emit_debug_code()) { |
| 2776 | Factory* factory = isolate()->factory(); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 2777 | Label ok; |
| 2778 | cmp(FieldOperand(elements, HeapObject::kMapOffset), |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2779 | Immediate(factory->fixed_array_map())); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 2780 | j(equal, &ok); |
| 2781 | cmp(FieldOperand(elements, HeapObject::kMapOffset), |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2782 | Immediate(factory->fixed_double_array_map())); |
| 2783 | j(equal, &ok); |
| 2784 | cmp(FieldOperand(elements, HeapObject::kMapOffset), |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2785 | Immediate(factory->fixed_cow_array_map())); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 2786 | j(equal, &ok); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2787 | Abort(kJSObjectWithFastElementsMapHasSlowElements); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 2788 | bind(&ok); |
| 2789 | } |
| 2790 | } |
| 2791 | |
| 2792 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2793 | void MacroAssembler::Check(Condition cc, BailoutReason reason) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2794 | Label L; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2795 | j(cc, &L); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2796 | Abort(reason); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2797 | // will not return here |
| 2798 | bind(&L); |
| 2799 | } |
| 2800 | |
| 2801 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2802 | void MacroAssembler::CheckStackAlignment() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2803 | int frame_alignment = base::OS::ActivationFrameAlignment(); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2804 | int frame_alignment_mask = frame_alignment - 1; |
| 2805 | if (frame_alignment > kPointerSize) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2806 | DCHECK(base::bits::IsPowerOfTwo32(frame_alignment)); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2807 | Label alignment_as_expected; |
| 2808 | test(esp, Immediate(frame_alignment_mask)); |
| 2809 | j(zero, &alignment_as_expected); |
| 2810 | // Abort if stack is not aligned. |
| 2811 | int3(); |
| 2812 | bind(&alignment_as_expected); |
| 2813 | } |
| 2814 | } |
| 2815 | |
| 2816 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2817 | void MacroAssembler::Abort(BailoutReason reason) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2818 | #ifdef DEBUG |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2819 | const char* msg = GetBailoutReason(reason); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2820 | if (msg != NULL) { |
| 2821 | RecordComment("Abort message: "); |
| 2822 | RecordComment(msg); |
| 2823 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2824 | |
| 2825 | if (FLAG_trap_on_abort) { |
| 2826 | int3(); |
| 2827 | return; |
| 2828 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2829 | #endif |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2830 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2831 | push(Immediate(reinterpret_cast<intptr_t>(Smi::FromInt(reason)))); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2832 | // Disable stub call restrictions to always allow calls to abort. |
| 2833 | if (!has_frame_) { |
| 2834 | // We don't actually want to generate a pile of code for this, so just |
| 2835 | // claim there is a stack frame, without generating one. |
| 2836 | FrameScope scope(this, StackFrame::NONE); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2837 | CallRuntime(Runtime::kAbort, 1); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2838 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2839 | CallRuntime(Runtime::kAbort, 1); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2840 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2841 | // will not return here |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2842 | int3(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2843 | } |
| 2844 | |
| 2845 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2846 | void MacroAssembler::LoadInstanceDescriptors(Register map, |
| 2847 | Register descriptors) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2848 | mov(descriptors, FieldOperand(map, Map::kDescriptorsOffset)); |
| 2849 | } |
| 2850 | |
| 2851 | |
| 2852 | void MacroAssembler::NumberOfOwnDescriptors(Register dst, Register map) { |
| 2853 | mov(dst, FieldOperand(map, Map::kBitField3Offset)); |
| 2854 | DecodeField<Map::NumberOfOwnDescriptorsBits>(dst); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 2855 | } |
| 2856 | |
| 2857 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 2858 | void MacroAssembler::LoadPowerOf2(XMMRegister dst, |
| 2859 | Register scratch, |
| 2860 | int power) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2861 | DCHECK(is_uintn(power + HeapNumber::kExponentBias, |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 2862 | HeapNumber::kExponentBits)); |
| 2863 | mov(scratch, Immediate(power + HeapNumber::kExponentBias)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2864 | movd(dst, scratch); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 2865 | psllq(dst, HeapNumber::kMantissaBits); |
| 2866 | } |
| 2867 | |
| 2868 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2869 | void MacroAssembler::LookupNumberStringCache(Register object, |
| 2870 | Register result, |
| 2871 | Register scratch1, |
| 2872 | Register scratch2, |
| 2873 | Label* not_found) { |
| 2874 | // Use of registers. Register result is used as a temporary. |
| 2875 | Register number_string_cache = result; |
| 2876 | Register mask = scratch1; |
| 2877 | Register scratch = scratch2; |
| 2878 | |
| 2879 | // Load the number string cache. |
| 2880 | LoadRoot(number_string_cache, Heap::kNumberStringCacheRootIndex); |
| 2881 | // Make the hash mask from the length of the number string cache. It |
| 2882 | // contains two elements (number and string) for each cache entry. |
| 2883 | mov(mask, FieldOperand(number_string_cache, FixedArray::kLengthOffset)); |
| 2884 | shr(mask, kSmiTagSize + 1); // Untag length and divide it by two. |
| 2885 | sub(mask, Immediate(1)); // Make mask. |
| 2886 | |
| 2887 | // Calculate the entry in the number string cache. The hash value in the |
| 2888 | // number string cache for smis is just the smi value, and the hash for |
| 2889 | // doubles is the xor of the upper and lower words. See |
| 2890 | // Heap::GetNumberStringCache. |
| 2891 | Label smi_hash_calculated; |
| 2892 | Label load_result_from_cache; |
| 2893 | Label not_smi; |
| 2894 | STATIC_ASSERT(kSmiTag == 0); |
| 2895 | JumpIfNotSmi(object, ¬_smi, Label::kNear); |
| 2896 | mov(scratch, object); |
| 2897 | SmiUntag(scratch); |
| 2898 | jmp(&smi_hash_calculated, Label::kNear); |
| 2899 | bind(¬_smi); |
| 2900 | cmp(FieldOperand(object, HeapObject::kMapOffset), |
| 2901 | isolate()->factory()->heap_number_map()); |
| 2902 | j(not_equal, not_found); |
| 2903 | STATIC_ASSERT(8 == kDoubleSize); |
| 2904 | mov(scratch, FieldOperand(object, HeapNumber::kValueOffset)); |
| 2905 | xor_(scratch, FieldOperand(object, HeapNumber::kValueOffset + 4)); |
| 2906 | // Object is heap number and hash is now in scratch. Calculate cache index. |
| 2907 | and_(scratch, mask); |
| 2908 | Register index = scratch; |
| 2909 | Register probe = mask; |
| 2910 | mov(probe, |
| 2911 | FieldOperand(number_string_cache, |
| 2912 | index, |
| 2913 | times_twice_pointer_size, |
| 2914 | FixedArray::kHeaderSize)); |
| 2915 | JumpIfSmi(probe, not_found); |
| 2916 | movsd(xmm0, FieldOperand(object, HeapNumber::kValueOffset)); |
| 2917 | ucomisd(xmm0, FieldOperand(probe, HeapNumber::kValueOffset)); |
| 2918 | j(parity_even, not_found); // Bail out if NaN is involved. |
| 2919 | j(not_equal, not_found); // The cache did not contain this value. |
| 2920 | jmp(&load_result_from_cache, Label::kNear); |
| 2921 | |
| 2922 | bind(&smi_hash_calculated); |
| 2923 | // Object is smi and hash is now in scratch. Calculate cache index. |
| 2924 | and_(scratch, mask); |
| 2925 | // Check if the entry is the smi we are looking for. |
| 2926 | cmp(object, |
| 2927 | FieldOperand(number_string_cache, |
| 2928 | index, |
| 2929 | times_twice_pointer_size, |
| 2930 | FixedArray::kHeaderSize)); |
| 2931 | j(not_equal, not_found); |
| 2932 | |
| 2933 | // Get the result from the cache. |
| 2934 | bind(&load_result_from_cache); |
| 2935 | mov(result, |
| 2936 | FieldOperand(number_string_cache, |
| 2937 | index, |
| 2938 | times_twice_pointer_size, |
| 2939 | FixedArray::kHeaderSize + kPointerSize)); |
| 2940 | IncrementCounter(isolate()->counters()->number_to_string_native(), 1); |
| 2941 | } |
| 2942 | |
| 2943 | |
| 2944 | void MacroAssembler::JumpIfInstanceTypeIsNotSequentialOneByte( |
| 2945 | Register instance_type, Register scratch, Label* failure) { |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 2946 | if (!scratch.is(instance_type)) { |
| 2947 | mov(scratch, instance_type); |
| 2948 | } |
| 2949 | and_(scratch, |
| 2950 | kIsNotStringMask | kStringRepresentationMask | kStringEncodingMask); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2951 | cmp(scratch, kStringTag | kSeqStringTag | kOneByteStringTag); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 2952 | j(not_equal, failure); |
| 2953 | } |
| 2954 | |
| 2955 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2956 | void MacroAssembler::JumpIfNotBothSequentialOneByteStrings(Register object1, |
| 2957 | Register object2, |
| 2958 | Register scratch1, |
| 2959 | Register scratch2, |
| 2960 | Label* failure) { |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 2961 | // Check that both objects are not smis. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 2962 | STATIC_ASSERT(kSmiTag == 0); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2963 | mov(scratch1, object1); |
| 2964 | and_(scratch1, object2); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2965 | JumpIfSmi(scratch1, failure); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 2966 | |
| 2967 | // Load instance type for both strings. |
| 2968 | mov(scratch1, FieldOperand(object1, HeapObject::kMapOffset)); |
| 2969 | mov(scratch2, FieldOperand(object2, HeapObject::kMapOffset)); |
| 2970 | movzx_b(scratch1, FieldOperand(scratch1, Map::kInstanceTypeOffset)); |
| 2971 | movzx_b(scratch2, FieldOperand(scratch2, Map::kInstanceTypeOffset)); |
| 2972 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2973 | // Check that both are flat one-byte strings. |
| 2974 | const int kFlatOneByteStringMask = |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 2975 | kIsNotStringMask | kStringRepresentationMask | kStringEncodingMask; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2976 | const int kFlatOneByteStringTag = |
| 2977 | kStringTag | kOneByteStringTag | kSeqStringTag; |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 2978 | // Interleave bits from both instance types and compare them in one check. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2979 | DCHECK_EQ(0, kFlatOneByteStringMask & (kFlatOneByteStringMask << 3)); |
| 2980 | and_(scratch1, kFlatOneByteStringMask); |
| 2981 | and_(scratch2, kFlatOneByteStringMask); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 2982 | lea(scratch1, Operand(scratch1, scratch2, times_8, 0)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2983 | cmp(scratch1, kFlatOneByteStringTag | (kFlatOneByteStringTag << 3)); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 2984 | j(not_equal, failure); |
| 2985 | } |
| 2986 | |
| 2987 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2988 | void MacroAssembler::JumpIfNotUniqueNameInstanceType(Operand operand, |
| 2989 | Label* not_unique_name, |
| 2990 | Label::Distance distance) { |
| 2991 | STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0); |
| 2992 | Label succeed; |
| 2993 | test(operand, Immediate(kIsNotStringMask | kIsNotInternalizedMask)); |
| 2994 | j(zero, &succeed); |
| 2995 | cmpb(operand, static_cast<uint8_t>(SYMBOL_TYPE)); |
| 2996 | j(not_equal, not_unique_name, distance); |
| 2997 | |
| 2998 | bind(&succeed); |
| 2999 | } |
| 3000 | |
| 3001 | |
| 3002 | void MacroAssembler::EmitSeqStringSetCharCheck(Register string, |
| 3003 | Register index, |
| 3004 | Register value, |
| 3005 | uint32_t encoding_mask) { |
| 3006 | Label is_object; |
| 3007 | JumpIfNotSmi(string, &is_object, Label::kNear); |
| 3008 | Abort(kNonObject); |
| 3009 | bind(&is_object); |
| 3010 | |
| 3011 | push(value); |
| 3012 | mov(value, FieldOperand(string, HeapObject::kMapOffset)); |
| 3013 | movzx_b(value, FieldOperand(value, Map::kInstanceTypeOffset)); |
| 3014 | |
| 3015 | and_(value, Immediate(kStringRepresentationMask | kStringEncodingMask)); |
| 3016 | cmp(value, Immediate(encoding_mask)); |
| 3017 | pop(value); |
| 3018 | Check(equal, kUnexpectedStringType); |
| 3019 | |
| 3020 | // The index is assumed to be untagged coming in, tag it to compare with the |
| 3021 | // string length without using a temp register, it is restored at the end of |
| 3022 | // this function. |
| 3023 | SmiTag(index); |
| 3024 | Check(no_overflow, kIndexIsTooLarge); |
| 3025 | |
| 3026 | cmp(index, FieldOperand(string, String::kLengthOffset)); |
| 3027 | Check(less, kIndexIsTooLarge); |
| 3028 | |
| 3029 | cmp(index, Immediate(Smi::FromInt(0))); |
| 3030 | Check(greater_equal, kIndexIsNegative); |
| 3031 | |
| 3032 | // Restore the index |
| 3033 | SmiUntag(index); |
| 3034 | } |
| 3035 | |
| 3036 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3037 | void MacroAssembler::PrepareCallCFunction(int num_arguments, Register scratch) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3038 | int frame_alignment = base::OS::ActivationFrameAlignment(); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 3039 | if (frame_alignment != 0) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3040 | // Make stack end at alignment and make room for num_arguments words |
| 3041 | // and the original value of esp. |
| 3042 | mov(scratch, esp); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3043 | sub(esp, Immediate((num_arguments + 1) * kPointerSize)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3044 | DCHECK(base::bits::IsPowerOfTwo32(frame_alignment)); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 3045 | and_(esp, -frame_alignment); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3046 | mov(Operand(esp, num_arguments * kPointerSize), scratch); |
| 3047 | } else { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3048 | sub(esp, Immediate(num_arguments * kPointerSize)); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3049 | } |
| 3050 | } |
| 3051 | |
| 3052 | |
| 3053 | void MacroAssembler::CallCFunction(ExternalReference function, |
| 3054 | int num_arguments) { |
| 3055 | // Trashing eax is ok as it will be the return value. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3056 | mov(eax, Immediate(function)); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3057 | CallCFunction(eax, num_arguments); |
| 3058 | } |
| 3059 | |
| 3060 | |
| 3061 | void MacroAssembler::CallCFunction(Register function, |
| 3062 | int num_arguments) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3063 | DCHECK(has_frame()); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3064 | // Check stack alignment. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3065 | if (emit_debug_code()) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3066 | CheckStackAlignment(); |
| 3067 | } |
| 3068 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3069 | call(function); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3070 | if (base::OS::ActivationFrameAlignment() != 0) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3071 | mov(esp, Operand(esp, num_arguments * kPointerSize)); |
| 3072 | } else { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3073 | add(esp, Immediate(num_arguments * kPointerSize)); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3074 | } |
| 3075 | } |
| 3076 | |
| 3077 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3078 | #ifdef DEBUG |
| 3079 | bool AreAliased(Register reg1, |
| 3080 | Register reg2, |
| 3081 | Register reg3, |
| 3082 | Register reg4, |
| 3083 | Register reg5, |
| 3084 | Register reg6, |
| 3085 | Register reg7, |
| 3086 | Register reg8) { |
| 3087 | int n_of_valid_regs = reg1.is_valid() + reg2.is_valid() + |
| 3088 | reg3.is_valid() + reg4.is_valid() + reg5.is_valid() + reg6.is_valid() + |
| 3089 | reg7.is_valid() + reg8.is_valid(); |
| 3090 | |
| 3091 | RegList regs = 0; |
| 3092 | if (reg1.is_valid()) regs |= reg1.bit(); |
| 3093 | if (reg2.is_valid()) regs |= reg2.bit(); |
| 3094 | if (reg3.is_valid()) regs |= reg3.bit(); |
| 3095 | if (reg4.is_valid()) regs |= reg4.bit(); |
| 3096 | if (reg5.is_valid()) regs |= reg5.bit(); |
| 3097 | if (reg6.is_valid()) regs |= reg6.bit(); |
| 3098 | if (reg7.is_valid()) regs |= reg7.bit(); |
| 3099 | if (reg8.is_valid()) regs |= reg8.bit(); |
| 3100 | int n_of_non_aliasing_regs = NumRegs(regs); |
| 3101 | |
| 3102 | return n_of_valid_regs != n_of_non_aliasing_regs; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3103 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3104 | #endif |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3105 | |
| 3106 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3107 | CodePatcher::CodePatcher(byte* address, int size) |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 3108 | : address_(address), |
| 3109 | size_(size), |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3110 | masm_(NULL, address, size + Assembler::kGap) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3111 | // Create a new macro assembler pointing to the address of the code to patch. |
| 3112 | // The size is adjusted with kGap on order for the assembler to generate size |
| 3113 | // bytes of instructions without failing with buffer size constraints. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3114 | DCHECK(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3115 | } |
| 3116 | |
| 3117 | |
| 3118 | CodePatcher::~CodePatcher() { |
| 3119 | // Indicate that code has changed. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3120 | CpuFeatures::FlushICache(address_, size_); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3121 | |
| 3122 | // Check that the code was patched as expected. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3123 | DCHECK(masm_.pc_ == address_ + size_); |
| 3124 | DCHECK(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3125 | } |
| 3126 | |
| 3127 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3128 | void MacroAssembler::CheckPageFlag( |
| 3129 | Register object, |
| 3130 | Register scratch, |
| 3131 | int mask, |
| 3132 | Condition cc, |
| 3133 | Label* condition_met, |
| 3134 | Label::Distance condition_met_distance) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3135 | DCHECK(cc == zero || cc == not_zero); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3136 | if (scratch.is(object)) { |
| 3137 | and_(scratch, Immediate(~Page::kPageAlignmentMask)); |
| 3138 | } else { |
| 3139 | mov(scratch, Immediate(~Page::kPageAlignmentMask)); |
| 3140 | and_(scratch, object); |
| 3141 | } |
| 3142 | if (mask < (1 << kBitsPerByte)) { |
| 3143 | test_b(Operand(scratch, MemoryChunk::kFlagsOffset), |
| 3144 | static_cast<uint8_t>(mask)); |
| 3145 | } else { |
| 3146 | test(Operand(scratch, MemoryChunk::kFlagsOffset), Immediate(mask)); |
| 3147 | } |
| 3148 | j(cc, condition_met, condition_met_distance); |
| 3149 | } |
| 3150 | |
| 3151 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3152 | void MacroAssembler::CheckPageFlagForMap( |
| 3153 | Handle<Map> map, |
| 3154 | int mask, |
| 3155 | Condition cc, |
| 3156 | Label* condition_met, |
| 3157 | Label::Distance condition_met_distance) { |
| 3158 | DCHECK(cc == zero || cc == not_zero); |
| 3159 | Page* page = Page::FromAddress(map->address()); |
| 3160 | DCHECK(!serializer_enabled()); // Serializer cannot match page_flags. |
| 3161 | ExternalReference reference(ExternalReference::page_flags(page)); |
| 3162 | // The inlined static address check of the page's flags relies |
| 3163 | // on maps never being compacted. |
| 3164 | DCHECK(!isolate()->heap()->mark_compact_collector()-> |
| 3165 | IsOnEvacuationCandidate(*map)); |
| 3166 | if (mask < (1 << kBitsPerByte)) { |
| 3167 | test_b(Operand::StaticVariable(reference), static_cast<uint8_t>(mask)); |
| 3168 | } else { |
| 3169 | test(Operand::StaticVariable(reference), Immediate(mask)); |
| 3170 | } |
| 3171 | j(cc, condition_met, condition_met_distance); |
| 3172 | } |
| 3173 | |
| 3174 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3175 | void MacroAssembler::JumpIfBlack(Register object, |
| 3176 | Register scratch0, |
| 3177 | Register scratch1, |
| 3178 | Label* on_black, |
| 3179 | Label::Distance on_black_near) { |
| 3180 | HasColor(object, scratch0, scratch1, |
| 3181 | on_black, on_black_near, |
| 3182 | 1, 0); // kBlackBitPattern. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3183 | DCHECK(strcmp(Marking::kBlackBitPattern, "10") == 0); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3184 | } |
| 3185 | |
| 3186 | |
| 3187 | void MacroAssembler::HasColor(Register object, |
| 3188 | Register bitmap_scratch, |
| 3189 | Register mask_scratch, |
| 3190 | Label* has_color, |
| 3191 | Label::Distance has_color_distance, |
| 3192 | int first_bit, |
| 3193 | int second_bit) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3194 | DCHECK(!AreAliased(object, bitmap_scratch, mask_scratch, ecx)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3195 | |
| 3196 | GetMarkBits(object, bitmap_scratch, mask_scratch); |
| 3197 | |
| 3198 | Label other_color, word_boundary; |
| 3199 | test(mask_scratch, Operand(bitmap_scratch, MemoryChunk::kHeaderSize)); |
| 3200 | j(first_bit == 1 ? zero : not_zero, &other_color, Label::kNear); |
| 3201 | add(mask_scratch, mask_scratch); // Shift left 1 by adding. |
| 3202 | j(zero, &word_boundary, Label::kNear); |
| 3203 | test(mask_scratch, Operand(bitmap_scratch, MemoryChunk::kHeaderSize)); |
| 3204 | j(second_bit == 1 ? not_zero : zero, has_color, has_color_distance); |
| 3205 | jmp(&other_color, Label::kNear); |
| 3206 | |
| 3207 | bind(&word_boundary); |
| 3208 | test_b(Operand(bitmap_scratch, MemoryChunk::kHeaderSize + kPointerSize), 1); |
| 3209 | |
| 3210 | j(second_bit == 1 ? not_zero : zero, has_color, has_color_distance); |
| 3211 | bind(&other_color); |
| 3212 | } |
| 3213 | |
| 3214 | |
| 3215 | void MacroAssembler::GetMarkBits(Register addr_reg, |
| 3216 | Register bitmap_reg, |
| 3217 | Register mask_reg) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3218 | DCHECK(!AreAliased(addr_reg, mask_reg, bitmap_reg, ecx)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3219 | mov(bitmap_reg, Immediate(~Page::kPageAlignmentMask)); |
| 3220 | and_(bitmap_reg, addr_reg); |
| 3221 | mov(ecx, addr_reg); |
| 3222 | int shift = |
| 3223 | Bitmap::kBitsPerCellLog2 + kPointerSizeLog2 - Bitmap::kBytesPerCellLog2; |
| 3224 | shr(ecx, shift); |
| 3225 | and_(ecx, |
| 3226 | (Page::kPageAlignmentMask >> shift) & ~(Bitmap::kBytesPerCell - 1)); |
| 3227 | |
| 3228 | add(bitmap_reg, ecx); |
| 3229 | mov(ecx, addr_reg); |
| 3230 | shr(ecx, kPointerSizeLog2); |
| 3231 | and_(ecx, (1 << Bitmap::kBitsPerCellLog2) - 1); |
| 3232 | mov(mask_reg, Immediate(1)); |
| 3233 | shl_cl(mask_reg); |
| 3234 | } |
| 3235 | |
| 3236 | |
| 3237 | void MacroAssembler::EnsureNotWhite( |
| 3238 | Register value, |
| 3239 | Register bitmap_scratch, |
| 3240 | Register mask_scratch, |
| 3241 | Label* value_is_white_and_not_data, |
| 3242 | Label::Distance distance) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3243 | DCHECK(!AreAliased(value, bitmap_scratch, mask_scratch, ecx)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3244 | GetMarkBits(value, bitmap_scratch, mask_scratch); |
| 3245 | |
| 3246 | // If the value is black or grey we don't need to do anything. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3247 | DCHECK(strcmp(Marking::kWhiteBitPattern, "00") == 0); |
| 3248 | DCHECK(strcmp(Marking::kBlackBitPattern, "10") == 0); |
| 3249 | DCHECK(strcmp(Marking::kGreyBitPattern, "11") == 0); |
| 3250 | DCHECK(strcmp(Marking::kImpossibleBitPattern, "01") == 0); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3251 | |
| 3252 | Label done; |
| 3253 | |
| 3254 | // Since both black and grey have a 1 in the first position and white does |
| 3255 | // not have a 1 there we only need to check one bit. |
| 3256 | test(mask_scratch, Operand(bitmap_scratch, MemoryChunk::kHeaderSize)); |
| 3257 | j(not_zero, &done, Label::kNear); |
| 3258 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3259 | if (emit_debug_code()) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3260 | // Check for impossible bit pattern. |
| 3261 | Label ok; |
| 3262 | push(mask_scratch); |
| 3263 | // shl. May overflow making the check conservative. |
| 3264 | add(mask_scratch, mask_scratch); |
| 3265 | test(mask_scratch, Operand(bitmap_scratch, MemoryChunk::kHeaderSize)); |
| 3266 | j(zero, &ok, Label::kNear); |
| 3267 | int3(); |
| 3268 | bind(&ok); |
| 3269 | pop(mask_scratch); |
| 3270 | } |
| 3271 | |
| 3272 | // Value is white. We check whether it is data that doesn't need scanning. |
| 3273 | // Currently only checks for HeapNumber and non-cons strings. |
| 3274 | Register map = ecx; // Holds map while checking type. |
| 3275 | Register length = ecx; // Holds length of object after checking type. |
| 3276 | Label not_heap_number; |
| 3277 | Label is_data_object; |
| 3278 | |
| 3279 | // Check for heap-number |
| 3280 | mov(map, FieldOperand(value, HeapObject::kMapOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3281 | cmp(map, isolate()->factory()->heap_number_map()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3282 | j(not_equal, ¬_heap_number, Label::kNear); |
| 3283 | mov(length, Immediate(HeapNumber::kSize)); |
| 3284 | jmp(&is_data_object, Label::kNear); |
| 3285 | |
| 3286 | bind(¬_heap_number); |
| 3287 | // Check for strings. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3288 | DCHECK(kIsIndirectStringTag == 1 && kIsIndirectStringMask == 1); |
| 3289 | DCHECK(kNotStringTag == 0x80 && kIsNotStringMask == 0x80); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3290 | // If it's a string and it's not a cons string then it's an object containing |
| 3291 | // no GC pointers. |
| 3292 | Register instance_type = ecx; |
| 3293 | movzx_b(instance_type, FieldOperand(map, Map::kInstanceTypeOffset)); |
| 3294 | test_b(instance_type, kIsIndirectStringMask | kIsNotStringMask); |
| 3295 | j(not_zero, value_is_white_and_not_data); |
| 3296 | // It's a non-indirect (non-cons and non-slice) string. |
| 3297 | // If it's external, the length is just ExternalString::kSize. |
| 3298 | // Otherwise it's String::kHeaderSize + string->length() * (1 or 2). |
| 3299 | Label not_external; |
| 3300 | // External strings are the only ones with the kExternalStringTag bit |
| 3301 | // set. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3302 | DCHECK_EQ(0, kSeqStringTag & kExternalStringTag); |
| 3303 | DCHECK_EQ(0, kConsStringTag & kExternalStringTag); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3304 | test_b(instance_type, kExternalStringTag); |
| 3305 | j(zero, ¬_external, Label::kNear); |
| 3306 | mov(length, Immediate(ExternalString::kSize)); |
| 3307 | jmp(&is_data_object, Label::kNear); |
| 3308 | |
| 3309 | bind(¬_external); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3310 | // Sequential string, either Latin1 or UC16. |
| 3311 | DCHECK(kOneByteStringTag == 0x04); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3312 | and_(length, Immediate(kStringEncodingMask)); |
| 3313 | xor_(length, Immediate(kStringEncodingMask)); |
| 3314 | add(length, Immediate(0x04)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3315 | // Value now either 4 (if Latin1) or 8 (if UC16), i.e., char-size shifted |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3316 | // by 2. If we multiply the string length as smi by this, it still |
| 3317 | // won't overflow a 32-bit value. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3318 | DCHECK_EQ(SeqOneByteString::kMaxSize, SeqTwoByteString::kMaxSize); |
| 3319 | DCHECK(SeqOneByteString::kMaxSize <= |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3320 | static_cast<int>(0xffffffffu >> (2 + kSmiTagSize))); |
| 3321 | imul(length, FieldOperand(value, String::kLengthOffset)); |
| 3322 | shr(length, 2 + kSmiTagSize + kSmiShiftSize); |
| 3323 | add(length, Immediate(SeqString::kHeaderSize + kObjectAlignmentMask)); |
| 3324 | and_(length, Immediate(~kObjectAlignmentMask)); |
| 3325 | |
| 3326 | bind(&is_data_object); |
| 3327 | // Value is a data object, and it is white. Mark it black. Since we know |
| 3328 | // that the object is white we can make it black by flipping one bit. |
| 3329 | or_(Operand(bitmap_scratch, MemoryChunk::kHeaderSize), mask_scratch); |
| 3330 | |
| 3331 | and_(bitmap_scratch, Immediate(~Page::kPageAlignmentMask)); |
| 3332 | add(Operand(bitmap_scratch, MemoryChunk::kLiveBytesOffset), |
| 3333 | length); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3334 | if (emit_debug_code()) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3335 | mov(length, Operand(bitmap_scratch, MemoryChunk::kLiveBytesOffset)); |
| 3336 | cmp(length, Operand(bitmap_scratch, MemoryChunk::kSizeOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3337 | Check(less_equal, kLiveBytesCountOverflowChunkSize); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3338 | } |
| 3339 | |
| 3340 | bind(&done); |
| 3341 | } |
| 3342 | |
| 3343 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3344 | void MacroAssembler::EnumLength(Register dst, Register map) { |
| 3345 | STATIC_ASSERT(Map::EnumLengthBits::kShift == 0); |
| 3346 | mov(dst, FieldOperand(map, Map::kBitField3Offset)); |
| 3347 | and_(dst, Immediate(Map::EnumLengthBits::kMask)); |
| 3348 | SmiTag(dst); |
| 3349 | } |
| 3350 | |
| 3351 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3352 | void MacroAssembler::CheckEnumCache(Label* call_runtime) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3353 | Label next, start; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3354 | mov(ecx, eax); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3355 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3356 | // Check if the enum length field is properly initialized, indicating that |
| 3357 | // there is an enum cache. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3358 | mov(ebx, FieldOperand(ecx, HeapObject::kMapOffset)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3359 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3360 | EnumLength(edx, ebx); |
| 3361 | cmp(edx, Immediate(Smi::FromInt(kInvalidEnumCacheSentinel))); |
| 3362 | j(equal, call_runtime); |
| 3363 | |
| 3364 | jmp(&start); |
| 3365 | |
| 3366 | bind(&next); |
| 3367 | mov(ebx, FieldOperand(ecx, HeapObject::kMapOffset)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3368 | |
| 3369 | // For all objects but the receiver, check that the cache is empty. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3370 | EnumLength(edx, ebx); |
| 3371 | cmp(edx, Immediate(Smi::FromInt(0))); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3372 | j(not_equal, call_runtime); |
| 3373 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3374 | bind(&start); |
| 3375 | |
| 3376 | // Check that there are no elements. Register rcx contains the current JS |
| 3377 | // object we've reached through the prototype chain. |
| 3378 | Label no_elements; |
| 3379 | mov(ecx, FieldOperand(ecx, JSObject::kElementsOffset)); |
| 3380 | cmp(ecx, isolate()->factory()->empty_fixed_array()); |
| 3381 | j(equal, &no_elements); |
| 3382 | |
| 3383 | // Second chance, the object may be using the empty slow element dictionary. |
| 3384 | cmp(ecx, isolate()->factory()->empty_slow_element_dictionary()); |
| 3385 | j(not_equal, call_runtime); |
| 3386 | |
| 3387 | bind(&no_elements); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3388 | mov(ecx, FieldOperand(ebx, Map::kPrototypeOffset)); |
| 3389 | cmp(ecx, isolate()->factory()->null_value()); |
| 3390 | j(not_equal, &next); |
| 3391 | } |
| 3392 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3393 | |
| 3394 | void MacroAssembler::TestJSArrayForAllocationMemento( |
| 3395 | Register receiver_reg, |
| 3396 | Register scratch_reg, |
| 3397 | Label* no_memento_found) { |
| 3398 | ExternalReference new_space_start = |
| 3399 | ExternalReference::new_space_start(isolate()); |
| 3400 | ExternalReference new_space_allocation_top = |
| 3401 | ExternalReference::new_space_allocation_top_address(isolate()); |
| 3402 | |
| 3403 | lea(scratch_reg, Operand(receiver_reg, |
| 3404 | JSArray::kSize + AllocationMemento::kSize - kHeapObjectTag)); |
| 3405 | cmp(scratch_reg, Immediate(new_space_start)); |
| 3406 | j(less, no_memento_found); |
| 3407 | cmp(scratch_reg, Operand::StaticVariable(new_space_allocation_top)); |
| 3408 | j(greater, no_memento_found); |
| 3409 | cmp(MemOperand(scratch_reg, -AllocationMemento::kSize), |
| 3410 | Immediate(isolate()->factory()->allocation_memento_map())); |
| 3411 | } |
| 3412 | |
| 3413 | |
| 3414 | void MacroAssembler::JumpIfDictionaryInPrototypeChain( |
| 3415 | Register object, |
| 3416 | Register scratch0, |
| 3417 | Register scratch1, |
| 3418 | Label* found) { |
| 3419 | DCHECK(!scratch1.is(scratch0)); |
| 3420 | Factory* factory = isolate()->factory(); |
| 3421 | Register current = scratch0; |
| 3422 | Label loop_again; |
| 3423 | |
| 3424 | // scratch contained elements pointer. |
| 3425 | mov(current, object); |
| 3426 | |
| 3427 | // Loop based on the map going up the prototype chain. |
| 3428 | bind(&loop_again); |
| 3429 | mov(current, FieldOperand(current, HeapObject::kMapOffset)); |
| 3430 | mov(scratch1, FieldOperand(current, Map::kBitField2Offset)); |
| 3431 | DecodeField<Map::ElementsKindBits>(scratch1); |
| 3432 | cmp(scratch1, Immediate(DICTIONARY_ELEMENTS)); |
| 3433 | j(equal, found); |
| 3434 | mov(current, FieldOperand(current, Map::kPrototypeOffset)); |
| 3435 | cmp(current, Immediate(factory->null_value())); |
| 3436 | j(not_equal, &loop_again); |
| 3437 | } |
| 3438 | |
| 3439 | |
| 3440 | void MacroAssembler::TruncatingDiv(Register dividend, int32_t divisor) { |
| 3441 | DCHECK(!dividend.is(eax)); |
| 3442 | DCHECK(!dividend.is(edx)); |
| 3443 | base::MagicNumbersForDivision<uint32_t> mag = |
| 3444 | base::SignedDivisionByConstant(static_cast<uint32_t>(divisor)); |
| 3445 | mov(eax, Immediate(mag.multiplier)); |
| 3446 | imul(dividend); |
| 3447 | bool neg = (mag.multiplier & (static_cast<uint32_t>(1) << 31)) != 0; |
| 3448 | if (divisor > 0 && neg) add(edx, dividend); |
| 3449 | if (divisor < 0 && !neg && mag.multiplier > 0) sub(edx, dividend); |
| 3450 | if (mag.shift > 0) sar(edx, mag.shift); |
| 3451 | mov(eax, dividend); |
| 3452 | shr(eax, 31); |
| 3453 | add(edx, eax); |
| 3454 | } |
| 3455 | |
| 3456 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3457 | } } // namespace v8::internal |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3458 | |
| 3459 | #endif // V8_TARGET_ARCH_IA32 |