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. |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5 | #if V8_TARGET_ARCH_IA32 |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 6 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 7 | #include "src/code-stubs.h" |
| 8 | #include "src/api-arguments.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9 | #include "src/base/bits.h" |
| 10 | #include "src/bootstrapper.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 11 | #include "src/codegen.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 12 | #include "src/ia32/code-stubs-ia32.h" |
| 13 | #include "src/ia32/frames-ia32.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 14 | #include "src/ic/handler-compiler.h" |
| 15 | #include "src/ic/ic.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 16 | #include "src/ic/stub-cache.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 17 | #include "src/isolate.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 18 | #include "src/regexp/jsregexp.h" |
| 19 | #include "src/regexp/regexp-macro-assembler.h" |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 20 | #include "src/runtime/runtime.h" |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 21 | |
| 22 | namespace v8 { |
| 23 | namespace internal { |
| 24 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 25 | |
| 26 | static void InitializeArrayConstructorDescriptor( |
| 27 | Isolate* isolate, CodeStubDescriptor* descriptor, |
| 28 | int constant_stack_parameter_count) { |
| 29 | // register state |
| 30 | // eax -- number of arguments |
| 31 | // edi -- function |
| 32 | // ebx -- allocation site with elements kind |
| 33 | Address deopt_handler = Runtime::FunctionForId( |
| 34 | Runtime::kArrayConstructor)->entry; |
| 35 | |
| 36 | if (constant_stack_parameter_count == 0) { |
| 37 | descriptor->Initialize(deopt_handler, constant_stack_parameter_count, |
| 38 | JS_FUNCTION_STUB_MODE); |
| 39 | } else { |
| 40 | descriptor->Initialize(eax, deopt_handler, constant_stack_parameter_count, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 41 | JS_FUNCTION_STUB_MODE); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 42 | } |
| 43 | } |
| 44 | |
| 45 | |
| 46 | static void InitializeInternalArrayConstructorDescriptor( |
| 47 | Isolate* isolate, CodeStubDescriptor* descriptor, |
| 48 | int constant_stack_parameter_count) { |
| 49 | // register state |
| 50 | // eax -- number of arguments |
| 51 | // edi -- constructor function |
| 52 | Address deopt_handler = Runtime::FunctionForId( |
| 53 | Runtime::kInternalArrayConstructor)->entry; |
| 54 | |
| 55 | if (constant_stack_parameter_count == 0) { |
| 56 | descriptor->Initialize(deopt_handler, constant_stack_parameter_count, |
| 57 | JS_FUNCTION_STUB_MODE); |
| 58 | } else { |
| 59 | descriptor->Initialize(eax, deopt_handler, constant_stack_parameter_count, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 60 | JS_FUNCTION_STUB_MODE); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 61 | } |
| 62 | } |
| 63 | |
| 64 | |
| 65 | void ArrayNoArgumentConstructorStub::InitializeDescriptor( |
| 66 | CodeStubDescriptor* descriptor) { |
| 67 | InitializeArrayConstructorDescriptor(isolate(), descriptor, 0); |
| 68 | } |
| 69 | |
| 70 | |
| 71 | void ArraySingleArgumentConstructorStub::InitializeDescriptor( |
| 72 | CodeStubDescriptor* descriptor) { |
| 73 | InitializeArrayConstructorDescriptor(isolate(), descriptor, 1); |
| 74 | } |
| 75 | |
| 76 | |
| 77 | void ArrayNArgumentsConstructorStub::InitializeDescriptor( |
| 78 | CodeStubDescriptor* descriptor) { |
| 79 | InitializeArrayConstructorDescriptor(isolate(), descriptor, -1); |
| 80 | } |
| 81 | |
| 82 | |
| 83 | void InternalArrayNoArgumentConstructorStub::InitializeDescriptor( |
| 84 | CodeStubDescriptor* descriptor) { |
| 85 | InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 0); |
| 86 | } |
| 87 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 88 | void FastArrayPushStub::InitializeDescriptor(CodeStubDescriptor* descriptor) { |
| 89 | Address deopt_handler = Runtime::FunctionForId(Runtime::kArrayPush)->entry; |
| 90 | descriptor->Initialize(eax, deopt_handler, -1, JS_FUNCTION_STUB_MODE); |
| 91 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 92 | |
| 93 | void InternalArraySingleArgumentConstructorStub::InitializeDescriptor( |
| 94 | CodeStubDescriptor* descriptor) { |
| 95 | InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 1); |
| 96 | } |
| 97 | |
| 98 | |
| 99 | void InternalArrayNArgumentsConstructorStub::InitializeDescriptor( |
| 100 | CodeStubDescriptor* descriptor) { |
| 101 | InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, -1); |
| 102 | } |
| 103 | |
| 104 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 105 | #define __ ACCESS_MASM(masm) |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 106 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 107 | |
| 108 | void HydrogenCodeStub::GenerateLightweightMiss(MacroAssembler* masm, |
| 109 | ExternalReference miss) { |
| 110 | // Update the static counter each time a new code stub is generated. |
| 111 | isolate()->counters()->code_stubs()->Increment(); |
| 112 | |
| 113 | CallInterfaceDescriptor descriptor = GetCallInterfaceDescriptor(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 114 | int param_count = descriptor.GetRegisterParameterCount(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 115 | { |
| 116 | // Call the runtime system in a fresh internal frame. |
| 117 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 118 | DCHECK(param_count == 0 || |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 119 | eax.is(descriptor.GetRegisterParameter(param_count - 1))); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 120 | // Push arguments |
| 121 | for (int i = 0; i < param_count; ++i) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 122 | __ push(descriptor.GetRegisterParameter(i)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 123 | } |
| 124 | __ CallExternalReference(miss, param_count); |
| 125 | } |
| 126 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 127 | __ ret(0); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 131 | void StoreBufferOverflowStub::Generate(MacroAssembler* masm) { |
| 132 | // We don't allow a GC during a store buffer overflow so there is no need to |
| 133 | // store the registers in any particular way, but we do have to store and |
| 134 | // restore them. |
| 135 | __ pushad(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 136 | if (save_doubles()) { |
| 137 | __ sub(esp, Immediate(kDoubleSize * XMMRegister::kMaxNumRegisters)); |
| 138 | for (int i = 0; i < XMMRegister::kMaxNumRegisters; i++) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 139 | XMMRegister reg = XMMRegister::from_code(i); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 140 | __ movsd(Operand(esp, i * kDoubleSize), reg); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 141 | } |
| 142 | } |
| 143 | const int argument_count = 1; |
| 144 | |
| 145 | AllowExternalCallThatCantCauseGC scope(masm); |
| 146 | __ PrepareCallCFunction(argument_count, ecx); |
| 147 | __ mov(Operand(esp, 0 * kPointerSize), |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 148 | Immediate(ExternalReference::isolate_address(isolate()))); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 149 | __ CallCFunction( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 150 | ExternalReference::store_buffer_overflow_function(isolate()), |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 151 | argument_count); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 152 | if (save_doubles()) { |
| 153 | for (int i = 0; i < XMMRegister::kMaxNumRegisters; i++) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 154 | XMMRegister reg = XMMRegister::from_code(i); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 155 | __ movsd(reg, Operand(esp, i * kDoubleSize)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 156 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 157 | __ add(esp, Immediate(kDoubleSize * XMMRegister::kMaxNumRegisters)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 158 | } |
| 159 | __ popad(); |
| 160 | __ ret(0); |
| 161 | } |
| 162 | |
| 163 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 164 | class FloatingPointHelper : public AllStatic { |
| 165 | public: |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 166 | enum ArgLocation { |
| 167 | ARGS_ON_STACK, |
| 168 | ARGS_IN_REGISTERS |
| 169 | }; |
| 170 | |
| 171 | // Code pattern for loading a floating point value. Input value must |
| 172 | // be either a smi or a heap number object (fp value). Requirements: |
| 173 | // operand in register number. Returns operand as floating point number |
| 174 | // on FPU stack. |
| 175 | static void LoadFloatOperand(MacroAssembler* masm, Register number); |
| 176 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 177 | // Test if operands are smi or number objects (fp). Requirements: |
| 178 | // operand_1 in eax, operand_2 in edx; falls through on float |
| 179 | // operands, jumps to the non_float label otherwise. |
| 180 | static void CheckFloatOperands(MacroAssembler* masm, |
| 181 | Label* non_float, |
| 182 | Register scratch); |
| 183 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 184 | // Test if operands are numbers (smi or HeapNumber objects), and load |
| 185 | // them into xmm0 and xmm1 if they are. Jump to label not_numbers if |
| 186 | // either operand is not a number. Operands are in edx and eax. |
| 187 | // Leaves operands unchanged. |
| 188 | static void LoadSSE2Operands(MacroAssembler* masm, Label* not_numbers); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 189 | }; |
| 190 | |
| 191 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 192 | void DoubleToIStub::Generate(MacroAssembler* masm) { |
| 193 | Register input_reg = this->source(); |
| 194 | Register final_result_reg = this->destination(); |
| 195 | DCHECK(is_truncating()); |
| 196 | |
| 197 | Label check_negative, process_64_bits, done, done_no_stash; |
| 198 | |
| 199 | int double_offset = offset(); |
| 200 | |
| 201 | // Account for return address and saved regs if input is esp. |
| 202 | if (input_reg.is(esp)) double_offset += 3 * kPointerSize; |
| 203 | |
| 204 | MemOperand mantissa_operand(MemOperand(input_reg, double_offset)); |
| 205 | MemOperand exponent_operand(MemOperand(input_reg, |
| 206 | double_offset + kDoubleSize / 2)); |
| 207 | |
| 208 | Register scratch1; |
| 209 | { |
| 210 | Register scratch_candidates[3] = { ebx, edx, edi }; |
| 211 | for (int i = 0; i < 3; i++) { |
| 212 | scratch1 = scratch_candidates[i]; |
| 213 | if (!final_result_reg.is(scratch1) && !input_reg.is(scratch1)) break; |
| 214 | } |
| 215 | } |
| 216 | // Since we must use ecx for shifts below, use some other register (eax) |
| 217 | // to calculate the result if ecx is the requested return register. |
| 218 | Register result_reg = final_result_reg.is(ecx) ? eax : final_result_reg; |
| 219 | // Save ecx if it isn't the return register and therefore volatile, or if it |
| 220 | // is the return register, then save the temp register we use in its stead for |
| 221 | // the result. |
| 222 | Register save_reg = final_result_reg.is(ecx) ? eax : ecx; |
| 223 | __ push(scratch1); |
| 224 | __ push(save_reg); |
| 225 | |
| 226 | bool stash_exponent_copy = !input_reg.is(esp); |
| 227 | __ mov(scratch1, mantissa_operand); |
| 228 | if (CpuFeatures::IsSupported(SSE3)) { |
| 229 | CpuFeatureScope scope(masm, SSE3); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 230 | // Load x87 register with heap number. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 231 | __ fld_d(mantissa_operand); |
| 232 | } |
| 233 | __ mov(ecx, exponent_operand); |
| 234 | if (stash_exponent_copy) __ push(ecx); |
| 235 | |
| 236 | __ and_(ecx, HeapNumber::kExponentMask); |
| 237 | __ shr(ecx, HeapNumber::kExponentShift); |
| 238 | __ lea(result_reg, MemOperand(ecx, -HeapNumber::kExponentBias)); |
| 239 | __ cmp(result_reg, Immediate(HeapNumber::kMantissaBits)); |
| 240 | __ j(below, &process_64_bits); |
| 241 | |
| 242 | // Result is entirely in lower 32-bits of mantissa |
| 243 | int delta = HeapNumber::kExponentBias + Double::kPhysicalSignificandSize; |
| 244 | if (CpuFeatures::IsSupported(SSE3)) { |
| 245 | __ fstp(0); |
| 246 | } |
| 247 | __ sub(ecx, Immediate(delta)); |
| 248 | __ xor_(result_reg, result_reg); |
| 249 | __ cmp(ecx, Immediate(31)); |
| 250 | __ j(above, &done); |
| 251 | __ shl_cl(scratch1); |
| 252 | __ jmp(&check_negative); |
| 253 | |
| 254 | __ bind(&process_64_bits); |
| 255 | if (CpuFeatures::IsSupported(SSE3)) { |
| 256 | CpuFeatureScope scope(masm, SSE3); |
| 257 | if (stash_exponent_copy) { |
| 258 | // Already a copy of the exponent on the stack, overwrite it. |
| 259 | STATIC_ASSERT(kDoubleSize == 2 * kPointerSize); |
| 260 | __ sub(esp, Immediate(kDoubleSize / 2)); |
| 261 | } else { |
| 262 | // Reserve space for 64 bit answer. |
| 263 | __ sub(esp, Immediate(kDoubleSize)); // Nolint. |
| 264 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 265 | // Do conversion, which cannot fail because we checked the exponent. |
| 266 | __ fisttp_d(Operand(esp, 0)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 267 | __ mov(result_reg, Operand(esp, 0)); // Load low word of answer as result |
| 268 | __ add(esp, Immediate(kDoubleSize)); |
| 269 | __ jmp(&done_no_stash); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 270 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 271 | // Result must be extracted from shifted 32-bit mantissa |
| 272 | __ sub(ecx, Immediate(delta)); |
| 273 | __ neg(ecx); |
| 274 | if (stash_exponent_copy) { |
| 275 | __ mov(result_reg, MemOperand(esp, 0)); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 276 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 277 | __ mov(result_reg, exponent_operand); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 278 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 279 | __ and_(result_reg, |
| 280 | Immediate(static_cast<uint32_t>(Double::kSignificandMask >> 32))); |
| 281 | __ add(result_reg, |
| 282 | Immediate(static_cast<uint32_t>(Double::kHiddenBit >> 32))); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 283 | __ shrd_cl(scratch1, result_reg); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 284 | __ shr_cl(result_reg); |
| 285 | __ test(ecx, Immediate(32)); |
| 286 | __ cmov(not_equal, scratch1, result_reg); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 287 | } |
| 288 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 289 | // If the double was negative, negate the integer result. |
| 290 | __ bind(&check_negative); |
| 291 | __ mov(result_reg, scratch1); |
| 292 | __ neg(result_reg); |
| 293 | if (stash_exponent_copy) { |
| 294 | __ cmp(MemOperand(esp, 0), Immediate(0)); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 295 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 296 | __ cmp(exponent_operand, Immediate(0)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 297 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 298 | __ cmov(greater, result_reg, scratch1); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 299 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 300 | // Restore registers |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 301 | __ bind(&done); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 302 | if (stash_exponent_copy) { |
| 303 | __ add(esp, Immediate(kDoubleSize / 2)); |
| 304 | } |
| 305 | __ bind(&done_no_stash); |
| 306 | if (!final_result_reg.is(result_reg)) { |
| 307 | DCHECK(final_result_reg.is(ecx)); |
| 308 | __ mov(final_result_reg, result_reg); |
| 309 | } |
| 310 | __ pop(save_reg); |
| 311 | __ pop(scratch1); |
| 312 | __ ret(0); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 316 | void FloatingPointHelper::LoadFloatOperand(MacroAssembler* masm, |
| 317 | Register number) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 318 | Label load_smi, done; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 319 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 320 | __ JumpIfSmi(number, &load_smi, Label::kNear); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 321 | __ fld_d(FieldOperand(number, HeapNumber::kValueOffset)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 322 | __ jmp(&done, Label::kNear); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 323 | |
| 324 | __ bind(&load_smi); |
| 325 | __ SmiUntag(number); |
| 326 | __ push(number); |
| 327 | __ fild_s(Operand(esp, 0)); |
| 328 | __ pop(number); |
| 329 | |
| 330 | __ bind(&done); |
| 331 | } |
| 332 | |
| 333 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 334 | void FloatingPointHelper::LoadSSE2Operands(MacroAssembler* masm, |
| 335 | Label* not_numbers) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 336 | Label load_smi_edx, load_eax, load_smi_eax, load_float_eax, done; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 337 | // Load operand in edx into xmm0, or branch to not_numbers. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 338 | __ JumpIfSmi(edx, &load_smi_edx, Label::kNear); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 339 | Factory* factory = masm->isolate()->factory(); |
| 340 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), factory->heap_number_map()); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 341 | __ j(not_equal, not_numbers); // Argument in edx is not a number. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 342 | __ movsd(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 343 | __ bind(&load_eax); |
| 344 | // Load operand in eax into xmm1, or branch to not_numbers. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 345 | __ JumpIfSmi(eax, &load_smi_eax, Label::kNear); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 346 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), factory->heap_number_map()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 347 | __ j(equal, &load_float_eax, Label::kNear); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 348 | __ jmp(not_numbers); // Argument in eax is not a number. |
| 349 | __ bind(&load_smi_edx); |
| 350 | __ SmiUntag(edx); // Untag smi before converting to float. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 351 | __ Cvtsi2sd(xmm0, edx); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 352 | __ SmiTag(edx); // Retag smi for heap number overwriting test. |
| 353 | __ jmp(&load_eax); |
| 354 | __ bind(&load_smi_eax); |
| 355 | __ SmiUntag(eax); // Untag smi before converting to float. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 356 | __ Cvtsi2sd(xmm1, eax); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 357 | __ SmiTag(eax); // Retag smi for heap number overwriting test. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 358 | __ jmp(&done, Label::kNear); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 359 | __ bind(&load_float_eax); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 360 | __ movsd(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 361 | __ bind(&done); |
| 362 | } |
| 363 | |
| 364 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 365 | void FloatingPointHelper::CheckFloatOperands(MacroAssembler* masm, |
| 366 | Label* non_float, |
| 367 | Register scratch) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 368 | Label test_other, done; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 369 | // Test if both operands are floats or smi -> scratch=k_is_float; |
| 370 | // Otherwise scratch = k_not_float. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 371 | __ JumpIfSmi(edx, &test_other, Label::kNear); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 372 | __ mov(scratch, FieldOperand(edx, HeapObject::kMapOffset)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 373 | Factory* factory = masm->isolate()->factory(); |
| 374 | __ cmp(scratch, factory->heap_number_map()); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 375 | __ j(not_equal, non_float); // argument in edx is not a number -> NaN |
| 376 | |
| 377 | __ bind(&test_other); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 378 | __ JumpIfSmi(eax, &done, Label::kNear); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 379 | __ mov(scratch, FieldOperand(eax, HeapObject::kMapOffset)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 380 | __ cmp(scratch, factory->heap_number_map()); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 381 | __ j(not_equal, non_float); // argument in eax is not a number -> NaN |
| 382 | |
| 383 | // Fall-through: Both operands are numbers. |
| 384 | __ bind(&done); |
| 385 | } |
| 386 | |
| 387 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 388 | void MathPowStub::Generate(MacroAssembler* masm) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 389 | Factory* factory = isolate()->factory(); |
| 390 | const Register exponent = MathPowTaggedDescriptor::exponent(); |
| 391 | DCHECK(exponent.is(eax)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 392 | const Register base = edx; |
| 393 | const Register scratch = ecx; |
| 394 | const XMMRegister double_result = xmm3; |
| 395 | const XMMRegister double_base = xmm2; |
| 396 | const XMMRegister double_exponent = xmm1; |
| 397 | const XMMRegister double_scratch = xmm4; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 398 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 399 | Label call_runtime, done, exponent_not_smi, int_exponent; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 400 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 401 | // Save 1 in double_result - we need this several times later on. |
| 402 | __ mov(scratch, Immediate(1)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 403 | __ Cvtsi2sd(double_result, scratch); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 404 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 405 | if (exponent_type() == ON_STACK) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 406 | Label base_is_smi, unpack_exponent; |
| 407 | // The exponent and base are supplied as arguments on the stack. |
| 408 | // This can only happen if the stub is called from non-optimized code. |
| 409 | // Load input parameters from stack. |
| 410 | __ mov(base, Operand(esp, 2 * kPointerSize)); |
| 411 | __ mov(exponent, Operand(esp, 1 * kPointerSize)); |
| 412 | |
| 413 | __ JumpIfSmi(base, &base_is_smi, Label::kNear); |
| 414 | __ cmp(FieldOperand(base, HeapObject::kMapOffset), |
| 415 | factory->heap_number_map()); |
| 416 | __ j(not_equal, &call_runtime); |
| 417 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 418 | __ movsd(double_base, FieldOperand(base, HeapNumber::kValueOffset)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 419 | __ jmp(&unpack_exponent, Label::kNear); |
| 420 | |
| 421 | __ bind(&base_is_smi); |
| 422 | __ SmiUntag(base); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 423 | __ Cvtsi2sd(double_base, base); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 424 | |
| 425 | __ bind(&unpack_exponent); |
| 426 | __ JumpIfNotSmi(exponent, &exponent_not_smi, Label::kNear); |
| 427 | __ SmiUntag(exponent); |
| 428 | __ jmp(&int_exponent); |
| 429 | |
| 430 | __ bind(&exponent_not_smi); |
| 431 | __ cmp(FieldOperand(exponent, HeapObject::kMapOffset), |
| 432 | factory->heap_number_map()); |
| 433 | __ j(not_equal, &call_runtime); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 434 | __ movsd(double_exponent, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 435 | FieldOperand(exponent, HeapNumber::kValueOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 436 | } else if (exponent_type() == TAGGED) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 437 | __ JumpIfNotSmi(exponent, &exponent_not_smi, Label::kNear); |
| 438 | __ SmiUntag(exponent); |
| 439 | __ jmp(&int_exponent); |
| 440 | |
| 441 | __ bind(&exponent_not_smi); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 442 | __ movsd(double_exponent, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 443 | FieldOperand(exponent, HeapNumber::kValueOffset)); |
| 444 | } |
| 445 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 446 | if (exponent_type() != INTEGER) { |
| 447 | Label fast_power, try_arithmetic_simplification; |
| 448 | __ DoubleToI(exponent, double_exponent, double_scratch, |
| 449 | TREAT_MINUS_ZERO_AS_ZERO, &try_arithmetic_simplification, |
| 450 | &try_arithmetic_simplification, |
| 451 | &try_arithmetic_simplification); |
| 452 | __ jmp(&int_exponent); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 453 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 454 | __ bind(&try_arithmetic_simplification); |
| 455 | // Skip to runtime if possibly NaN (indicated by the indefinite integer). |
| 456 | __ cvttsd2si(exponent, Operand(double_exponent)); |
| 457 | __ cmp(exponent, Immediate(0x1)); |
| 458 | __ j(overflow, &call_runtime); |
| 459 | |
| 460 | if (exponent_type() == ON_STACK) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 461 | // Detect square root case. Crankshaft detects constant +/-0.5 at |
| 462 | // compile time and uses DoMathPowHalf instead. We then skip this check |
| 463 | // for non-constant cases of +/-0.5 as these hardly occur. |
| 464 | Label continue_sqrt, continue_rsqrt, not_plus_half; |
| 465 | // Test for 0.5. |
| 466 | // Load double_scratch with 0.5. |
| 467 | __ mov(scratch, Immediate(0x3F000000u)); |
| 468 | __ movd(double_scratch, scratch); |
| 469 | __ cvtss2sd(double_scratch, double_scratch); |
| 470 | // Already ruled out NaNs for exponent. |
| 471 | __ ucomisd(double_scratch, double_exponent); |
| 472 | __ j(not_equal, ¬_plus_half, Label::kNear); |
| 473 | |
| 474 | // Calculates square root of base. Check for the special case of |
| 475 | // Math.pow(-Infinity, 0.5) == Infinity (ECMA spec, 15.8.2.13). |
| 476 | // According to IEEE-754, single-precision -Infinity has the highest |
| 477 | // 9 bits set and the lowest 23 bits cleared. |
| 478 | __ mov(scratch, 0xFF800000u); |
| 479 | __ movd(double_scratch, scratch); |
| 480 | __ cvtss2sd(double_scratch, double_scratch); |
| 481 | __ ucomisd(double_base, double_scratch); |
| 482 | // Comparing -Infinity with NaN results in "unordered", which sets the |
| 483 | // zero flag as if both were equal. However, it also sets the carry flag. |
| 484 | __ j(not_equal, &continue_sqrt, Label::kNear); |
| 485 | __ j(carry, &continue_sqrt, Label::kNear); |
| 486 | |
| 487 | // Set result to Infinity in the special case. |
| 488 | __ xorps(double_result, double_result); |
| 489 | __ subsd(double_result, double_scratch); |
| 490 | __ jmp(&done); |
| 491 | |
| 492 | __ bind(&continue_sqrt); |
| 493 | // sqrtsd returns -0 when input is -0. ECMA spec requires +0. |
| 494 | __ xorps(double_scratch, double_scratch); |
| 495 | __ addsd(double_scratch, double_base); // Convert -0 to +0. |
| 496 | __ sqrtsd(double_result, double_scratch); |
| 497 | __ jmp(&done); |
| 498 | |
| 499 | // Test for -0.5. |
| 500 | __ bind(¬_plus_half); |
| 501 | // Load double_exponent with -0.5 by substracting 1. |
| 502 | __ subsd(double_scratch, double_result); |
| 503 | // Already ruled out NaNs for exponent. |
| 504 | __ ucomisd(double_scratch, double_exponent); |
| 505 | __ j(not_equal, &fast_power, Label::kNear); |
| 506 | |
| 507 | // Calculates reciprocal of square root of base. Check for the special |
| 508 | // case of Math.pow(-Infinity, -0.5) == 0 (ECMA spec, 15.8.2.13). |
| 509 | // According to IEEE-754, single-precision -Infinity has the highest |
| 510 | // 9 bits set and the lowest 23 bits cleared. |
| 511 | __ mov(scratch, 0xFF800000u); |
| 512 | __ movd(double_scratch, scratch); |
| 513 | __ cvtss2sd(double_scratch, double_scratch); |
| 514 | __ ucomisd(double_base, double_scratch); |
| 515 | // Comparing -Infinity with NaN results in "unordered", which sets the |
| 516 | // zero flag as if both were equal. However, it also sets the carry flag. |
| 517 | __ j(not_equal, &continue_rsqrt, Label::kNear); |
| 518 | __ j(carry, &continue_rsqrt, Label::kNear); |
| 519 | |
| 520 | // Set result to 0 in the special case. |
| 521 | __ xorps(double_result, double_result); |
| 522 | __ jmp(&done); |
| 523 | |
| 524 | __ bind(&continue_rsqrt); |
| 525 | // sqrtsd returns -0 when input is -0. ECMA spec requires +0. |
| 526 | __ xorps(double_exponent, double_exponent); |
| 527 | __ addsd(double_exponent, double_base); // Convert -0 to +0. |
| 528 | __ sqrtsd(double_exponent, double_exponent); |
| 529 | __ divsd(double_result, double_exponent); |
| 530 | __ jmp(&done); |
| 531 | } |
| 532 | |
| 533 | // Using FPU instructions to calculate power. |
| 534 | Label fast_power_failed; |
| 535 | __ bind(&fast_power); |
| 536 | __ fnclex(); // Clear flags to catch exceptions later. |
| 537 | // Transfer (B)ase and (E)xponent onto the FPU register stack. |
| 538 | __ sub(esp, Immediate(kDoubleSize)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 539 | __ movsd(Operand(esp, 0), double_exponent); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 540 | __ fld_d(Operand(esp, 0)); // E |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 541 | __ movsd(Operand(esp, 0), double_base); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 542 | __ fld_d(Operand(esp, 0)); // B, E |
| 543 | |
| 544 | // Exponent is in st(1) and base is in st(0) |
| 545 | // B ^ E = (2^(E * log2(B)) - 1) + 1 = (2^X - 1) + 1 for X = E * log2(B) |
| 546 | // FYL2X calculates st(1) * log2(st(0)) |
| 547 | __ fyl2x(); // X |
| 548 | __ fld(0); // X, X |
| 549 | __ frndint(); // rnd(X), X |
| 550 | __ fsub(1); // rnd(X), X-rnd(X) |
| 551 | __ fxch(1); // X - rnd(X), rnd(X) |
| 552 | // F2XM1 calculates 2^st(0) - 1 for -1 < st(0) < 1 |
| 553 | __ f2xm1(); // 2^(X-rnd(X)) - 1, rnd(X) |
| 554 | __ fld1(); // 1, 2^(X-rnd(X)) - 1, rnd(X) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 555 | __ faddp(1); // 2^(X-rnd(X)), rnd(X) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 556 | // FSCALE calculates st(0) * 2^st(1) |
| 557 | __ fscale(); // 2^X, rnd(X) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 558 | __ fstp(1); // 2^X |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 559 | // Bail out to runtime in case of exceptions in the status word. |
| 560 | __ fnstsw_ax(); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 561 | __ test_b(eax, |
| 562 | Immediate(0x5F)); // We check for all but precision exception. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 563 | __ j(not_zero, &fast_power_failed, Label::kNear); |
| 564 | __ fstp_d(Operand(esp, 0)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 565 | __ movsd(double_result, Operand(esp, 0)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 566 | __ add(esp, Immediate(kDoubleSize)); |
| 567 | __ jmp(&done); |
| 568 | |
| 569 | __ bind(&fast_power_failed); |
| 570 | __ fninit(); |
| 571 | __ add(esp, Immediate(kDoubleSize)); |
| 572 | __ jmp(&call_runtime); |
| 573 | } |
| 574 | |
| 575 | // Calculate power with integer exponent. |
| 576 | __ bind(&int_exponent); |
| 577 | const XMMRegister double_scratch2 = double_exponent; |
| 578 | __ mov(scratch, exponent); // Back up exponent. |
| 579 | __ movsd(double_scratch, double_base); // Back up base. |
| 580 | __ movsd(double_scratch2, double_result); // Load double_exponent with 1. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 581 | |
| 582 | // Get absolute value of exponent. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 583 | Label no_neg, while_true, while_false; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 584 | __ test(scratch, scratch); |
| 585 | __ j(positive, &no_neg, Label::kNear); |
| 586 | __ neg(scratch); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 587 | __ bind(&no_neg); |
| 588 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 589 | __ j(zero, &while_false, Label::kNear); |
| 590 | __ shr(scratch, 1); |
| 591 | // Above condition means CF==0 && ZF==0. This means that the |
| 592 | // bit that has been shifted out is 0 and the result is not 0. |
| 593 | __ j(above, &while_true, Label::kNear); |
| 594 | __ movsd(double_result, double_scratch); |
| 595 | __ j(zero, &while_false, Label::kNear); |
| 596 | |
Ben Murdoch | 85b7179 | 2012-04-11 18:30:58 +0100 | [diff] [blame] | 597 | __ bind(&while_true); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 598 | __ shr(scratch, 1); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 599 | __ mulsd(double_scratch, double_scratch); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 600 | __ j(above, &while_true, Label::kNear); |
| 601 | __ mulsd(double_result, double_scratch); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 602 | __ j(not_zero, &while_true); |
| 603 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 604 | __ bind(&while_false); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 605 | // scratch has the original value of the exponent - if the exponent is |
| 606 | // negative, return 1/result. |
| 607 | __ test(exponent, exponent); |
| 608 | __ j(positive, &done); |
| 609 | __ divsd(double_scratch2, double_result); |
| 610 | __ movsd(double_result, double_scratch2); |
| 611 | // Test whether result is zero. Bail out to check for subnormal result. |
| 612 | // Due to subnormals, x^-y == (1/x)^y does not hold in all cases. |
| 613 | __ xorps(double_scratch2, double_scratch2); |
| 614 | __ ucomisd(double_scratch2, double_result); // Result cannot be NaN. |
| 615 | // double_exponent aliased as double_scratch2 has already been overwritten |
| 616 | // and may not have contained the exponent value in the first place when the |
| 617 | // exponent is a smi. We reset it with exponent value before bailing out. |
| 618 | __ j(not_equal, &done); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 619 | __ Cvtsi2sd(double_exponent, exponent); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 620 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 621 | // Returning or bailing out. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 622 | if (exponent_type() == ON_STACK) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 623 | // The arguments are still on the stack. |
| 624 | __ bind(&call_runtime); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 625 | __ TailCallRuntime(Runtime::kMathPowRT); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 626 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 627 | // The stub is called from non-optimized code, which expects the result |
| 628 | // as heap number in exponent. |
| 629 | __ bind(&done); |
| 630 | __ AllocateHeapNumber(eax, scratch, base, &call_runtime); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 631 | __ movsd(FieldOperand(eax, HeapNumber::kValueOffset), double_result); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 632 | __ ret(2 * kPointerSize); |
| 633 | } else { |
| 634 | __ bind(&call_runtime); |
| 635 | { |
| 636 | AllowExternalCallThatCantCauseGC scope(masm); |
| 637 | __ PrepareCallCFunction(4, scratch); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 638 | __ movsd(Operand(esp, 0 * kDoubleSize), double_base); |
| 639 | __ movsd(Operand(esp, 1 * kDoubleSize), double_exponent); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 640 | __ CallCFunction( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 641 | ExternalReference::power_double_double_function(isolate()), 4); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 642 | } |
| 643 | // Return value is in st(0) on ia32. |
| 644 | // Store it into the (fixed) result register. |
| 645 | __ sub(esp, Immediate(kDoubleSize)); |
| 646 | __ fstp_d(Operand(esp, 0)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 647 | __ movsd(double_result, Operand(esp, 0)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 648 | __ add(esp, Immediate(kDoubleSize)); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 649 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 650 | __ bind(&done); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 651 | __ ret(0); |
| 652 | } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 653 | } |
| 654 | |
| 655 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 656 | void FunctionPrototypeStub::Generate(MacroAssembler* masm) { |
| 657 | Label miss; |
| 658 | Register receiver = LoadDescriptor::ReceiverRegister(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 659 | // With careful management, we won't have to save slot and vector on |
| 660 | // the stack. Simply handle the possibly missing case first. |
| 661 | // TODO(mvstanton): this code can be more efficient. |
| 662 | __ cmp(FieldOperand(receiver, JSFunction::kPrototypeOrInitialMapOffset), |
| 663 | Immediate(isolate()->factory()->the_hole_value())); |
| 664 | __ j(equal, &miss); |
| 665 | __ TryGetFunctionPrototype(receiver, eax, ebx, &miss); |
| 666 | __ ret(0); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 667 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 668 | __ bind(&miss); |
| 669 | PropertyAccessCompiler::TailCallBuiltin( |
| 670 | masm, PropertyAccessCompiler::MissBuiltin(Code::LOAD_IC)); |
| 671 | } |
| 672 | |
| 673 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 674 | void LoadIndexedStringStub::Generate(MacroAssembler* masm) { |
| 675 | // Return address is on the stack. |
| 676 | Label miss; |
| 677 | |
| 678 | Register receiver = LoadDescriptor::ReceiverRegister(); |
| 679 | Register index = LoadDescriptor::NameRegister(); |
| 680 | Register scratch = edi; |
| 681 | DCHECK(!scratch.is(receiver) && !scratch.is(index)); |
| 682 | Register result = eax; |
| 683 | DCHECK(!result.is(scratch)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 684 | DCHECK(!scratch.is(LoadWithVectorDescriptor::VectorRegister()) && |
| 685 | result.is(LoadDescriptor::SlotRegister())); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 686 | |
| 687 | // StringCharAtGenerator doesn't use the result register until it's passed |
| 688 | // the different miss possibilities. If it did, we would have a conflict |
| 689 | // when FLAG_vector_ics is true. |
| 690 | StringCharAtGenerator char_at_generator(receiver, index, scratch, result, |
| 691 | &miss, // When not a string. |
| 692 | &miss, // When not a number. |
| 693 | &miss, // When index out of range. |
| 694 | STRING_INDEX_IS_ARRAY_INDEX, |
| 695 | RECEIVER_IS_STRING); |
| 696 | char_at_generator.GenerateFast(masm); |
| 697 | __ ret(0); |
| 698 | |
| 699 | StubRuntimeCallHelper call_helper; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 700 | char_at_generator.GenerateSlow(masm, PART_OF_IC_HANDLER, call_helper); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 701 | |
| 702 | __ bind(&miss); |
| 703 | PropertyAccessCompiler::TailCallBuiltin( |
| 704 | masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC)); |
| 705 | } |
| 706 | |
| 707 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 708 | void RegExpExecStub::Generate(MacroAssembler* masm) { |
| 709 | // Just jump directly to runtime if native RegExp is not selected at compile |
| 710 | // time or if regexp entry in generated code is turned off runtime switch or |
| 711 | // at compilation. |
| 712 | #ifdef V8_INTERPRETED_REGEXP |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 713 | __ TailCallRuntime(Runtime::kRegExpExec); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 714 | #else // V8_INTERPRETED_REGEXP |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 715 | |
| 716 | // Stack frame on entry. |
| 717 | // esp[0]: return address |
| 718 | // esp[4]: last_match_info (expected JSArray) |
| 719 | // esp[8]: previous index |
| 720 | // esp[12]: subject string |
| 721 | // esp[16]: JSRegExp object |
| 722 | |
| 723 | static const int kLastMatchInfoOffset = 1 * kPointerSize; |
| 724 | static const int kPreviousIndexOffset = 2 * kPointerSize; |
| 725 | static const int kSubjectOffset = 3 * kPointerSize; |
| 726 | static const int kJSRegExpOffset = 4 * kPointerSize; |
| 727 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 728 | Label runtime; |
| 729 | Factory* factory = isolate()->factory(); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 730 | |
| 731 | // Ensure that a RegExp stack is allocated. |
| 732 | ExternalReference address_of_regexp_stack_memory_address = |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 733 | ExternalReference::address_of_regexp_stack_memory_address(isolate()); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 734 | ExternalReference address_of_regexp_stack_memory_size = |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 735 | ExternalReference::address_of_regexp_stack_memory_size(isolate()); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 736 | __ mov(ebx, Operand::StaticVariable(address_of_regexp_stack_memory_size)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 737 | __ test(ebx, ebx); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 738 | __ j(zero, &runtime); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 739 | |
| 740 | // Check that the first argument is a JSRegExp object. |
| 741 | __ mov(eax, Operand(esp, kJSRegExpOffset)); |
| 742 | STATIC_ASSERT(kSmiTag == 0); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 743 | __ JumpIfSmi(eax, &runtime); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 744 | __ CmpObjectType(eax, JS_REGEXP_TYPE, ecx); |
| 745 | __ j(not_equal, &runtime); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 746 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 747 | // Check that the RegExp has been compiled (data contains a fixed array). |
| 748 | __ mov(ecx, FieldOperand(eax, JSRegExp::kDataOffset)); |
| 749 | if (FLAG_debug_code) { |
| 750 | __ test(ecx, Immediate(kSmiTagMask)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 751 | __ Check(not_zero, kUnexpectedTypeForRegExpDataFixedArrayExpected); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 752 | __ CmpObjectType(ecx, FIXED_ARRAY_TYPE, ebx); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 753 | __ Check(equal, kUnexpectedTypeForRegExpDataFixedArrayExpected); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 754 | } |
| 755 | |
| 756 | // ecx: RegExp data (FixedArray) |
| 757 | // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP. |
| 758 | __ mov(ebx, FieldOperand(ecx, JSRegExp::kDataTagOffset)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 759 | __ cmp(ebx, Immediate(Smi::FromInt(JSRegExp::IRREGEXP))); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 760 | __ j(not_equal, &runtime); |
| 761 | |
| 762 | // ecx: RegExp data (FixedArray) |
| 763 | // Check that the number of captures fit in the static offsets vector buffer. |
| 764 | __ mov(edx, FieldOperand(ecx, JSRegExp::kIrregexpCaptureCountOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 765 | // Check (number_of_captures + 1) * 2 <= offsets vector size |
| 766 | // Or number_of_captures * 2 <= offsets vector size - 2 |
| 767 | // Multiplying by 2 comes for free since edx is smi-tagged. |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 768 | STATIC_ASSERT(kSmiTag == 0); |
| 769 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 770 | STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2); |
| 771 | __ cmp(edx, Isolate::kJSRegexpStaticOffsetsVectorSize - 2); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 772 | __ j(above, &runtime); |
| 773 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 774 | // Reset offset for possibly sliced string. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 775 | __ Move(edi, Immediate(0)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 776 | __ mov(eax, Operand(esp, kSubjectOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 777 | __ JumpIfSmi(eax, &runtime); |
| 778 | __ mov(edx, eax); // Make a copy of the original subject string. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 779 | |
| 780 | // eax: subject string |
| 781 | // edx: subject string |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 782 | // ecx: RegExp data (FixedArray) |
| 783 | // Handle subject string according to its encoding and representation: |
| 784 | // (1) Sequential two byte? If yes, go to (9). |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 785 | // (2) Sequential one byte? If yes, go to (5). |
| 786 | // (3) Sequential or cons? If not, go to (6). |
| 787 | // (4) Cons string. If the string is flat, replace subject with first string |
| 788 | // and go to (1). Otherwise bail out to runtime. |
| 789 | // (5) One byte sequential. Load regexp code for one byte. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 790 | // (E) Carry on. |
| 791 | /// [...] |
| 792 | |
| 793 | // Deferred code at the end of the stub: |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 794 | // (6) Long external string? If not, go to (10). |
| 795 | // (7) External string. Make it, offset-wise, look like a sequential string. |
| 796 | // (8) Is the external string one byte? If yes, go to (5). |
| 797 | // (9) Two byte sequential. Load regexp code for two byte. Go to (E). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 798 | // (10) Short external string or not a string? If yes, bail out to runtime. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 799 | // (11) Sliced string. Replace subject with parent. Go to (1). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 800 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 801 | Label seq_one_byte_string /* 5 */, seq_two_byte_string /* 9 */, |
| 802 | external_string /* 7 */, check_underlying /* 1 */, |
| 803 | not_seq_nor_cons /* 6 */, check_code /* E */, not_long_external /* 10 */; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 804 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 805 | __ bind(&check_underlying); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 806 | // (1) Sequential two byte? If yes, go to (9). |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 807 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 808 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 809 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 810 | __ and_(ebx, kIsNotStringMask | |
| 811 | kStringRepresentationMask | |
| 812 | kStringEncodingMask | |
| 813 | kShortExternalStringMask); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 814 | STATIC_ASSERT((kStringTag | kSeqStringTag | kTwoByteStringTag) == 0); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 815 | __ j(zero, &seq_two_byte_string); // Go to (9). |
| 816 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 817 | // (2) Sequential one byte? If yes, go to (5). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 818 | // Any other sequential string must be one byte. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 819 | __ and_(ebx, Immediate(kIsNotStringMask | |
| 820 | kStringRepresentationMask | |
| 821 | kShortExternalStringMask)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 822 | __ j(zero, &seq_one_byte_string, Label::kNear); // Go to (5). |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 823 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 824 | // (3) Sequential or cons? If not, go to (6). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 825 | // We check whether the subject string is a cons, since sequential strings |
| 826 | // have already been covered. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 827 | STATIC_ASSERT(kConsStringTag < kExternalStringTag); |
| 828 | STATIC_ASSERT(kSlicedStringTag > kExternalStringTag); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 829 | STATIC_ASSERT(kIsNotStringMask > kExternalStringTag); |
| 830 | STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag); |
| 831 | __ cmp(ebx, Immediate(kExternalStringTag)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 832 | __ j(greater_equal, ¬_seq_nor_cons); // Go to (6). |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 833 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 834 | // (4) Cons string. Check that it's flat. |
| 835 | // Replace subject with first string and reload instance type. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 836 | __ cmp(FieldOperand(eax, ConsString::kSecondOffset), factory->empty_string()); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 837 | __ j(not_equal, &runtime); |
| 838 | __ mov(eax, FieldOperand(eax, ConsString::kFirstOffset)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 839 | __ jmp(&check_underlying); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 840 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 841 | // eax: sequential subject string (or look-alike, external string) |
| 842 | // edx: original subject string |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 843 | // ecx: RegExp data (FixedArray) |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 844 | // (5) One byte sequential. Load regexp code for one byte. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 845 | __ bind(&seq_one_byte_string); |
| 846 | // Load previous index and check range before edx is overwritten. We have |
| 847 | // to use edx instead of eax here because it might have been only made to |
| 848 | // look like a sequential string when it actually is an external string. |
| 849 | __ mov(ebx, Operand(esp, kPreviousIndexOffset)); |
| 850 | __ JumpIfNotSmi(ebx, &runtime); |
| 851 | __ cmp(ebx, FieldOperand(edx, String::kLengthOffset)); |
| 852 | __ j(above_equal, &runtime); |
| 853 | __ mov(edx, FieldOperand(ecx, JSRegExp::kDataOneByteCodeOffset)); |
| 854 | __ Move(ecx, Immediate(1)); // Type is one byte. |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 855 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 856 | // (E) Carry on. String handling is done. |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 857 | __ bind(&check_code); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 858 | // edx: irregexp code |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 859 | // Check that the irregexp code has been generated for the actual string |
| 860 | // encoding. If it has, the field contains a code object otherwise it contains |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 861 | // a smi (code flushing support). |
| 862 | __ JumpIfSmi(edx, &runtime); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 863 | |
| 864 | // eax: subject string |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 865 | // ebx: previous index (smi) |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 866 | // edx: code |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 867 | // ecx: encoding of subject string (1 if one_byte, 0 if two_byte); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 868 | // All checks done. Now push arguments for native regexp code. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 869 | Counters* counters = isolate()->counters(); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 870 | __ IncrementCounter(counters->regexp_entry_native(), 1); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 871 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 872 | // Isolates: note we add an additional parameter here (isolate pointer). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 873 | static const int kRegExpExecuteArguments = 9; |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 874 | __ EnterApiExitFrame(kRegExpExecuteArguments); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 875 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 876 | // Argument 9: Pass current isolate address. |
| 877 | __ mov(Operand(esp, 8 * kPointerSize), |
| 878 | Immediate(ExternalReference::isolate_address(isolate()))); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 879 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 880 | // Argument 8: Indicate that this is a direct call from JavaScript. |
| 881 | __ mov(Operand(esp, 7 * kPointerSize), Immediate(1)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 882 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 883 | // Argument 7: Start (high end) of backtracking stack memory area. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 884 | __ mov(esi, Operand::StaticVariable(address_of_regexp_stack_memory_address)); |
| 885 | __ add(esi, Operand::StaticVariable(address_of_regexp_stack_memory_size)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 886 | __ mov(Operand(esp, 6 * kPointerSize), esi); |
| 887 | |
| 888 | // Argument 6: Set the number of capture registers to zero to force global |
| 889 | // regexps to behave as non-global. This does not affect non-global regexps. |
| 890 | __ mov(Operand(esp, 5 * kPointerSize), Immediate(0)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 891 | |
| 892 | // Argument 5: static offsets vector buffer. |
| 893 | __ mov(Operand(esp, 4 * kPointerSize), |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 894 | Immediate(ExternalReference::address_of_static_offsets_vector( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 895 | isolate()))); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 896 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 897 | // Argument 2: Previous index. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 898 | __ SmiUntag(ebx); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 899 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 900 | |
| 901 | // Argument 1: Original subject string. |
| 902 | // The original subject is in the previous stack frame. Therefore we have to |
| 903 | // use ebp, which points exactly to one pointer size below the previous esp. |
| 904 | // (Because creating a new stack frame pushes the previous ebp onto the stack |
| 905 | // and thereby moves up esp by one kPointerSize.) |
| 906 | __ mov(esi, Operand(ebp, kSubjectOffset + kPointerSize)); |
| 907 | __ mov(Operand(esp, 0 * kPointerSize), esi); |
| 908 | |
| 909 | // esi: original subject string |
| 910 | // eax: underlying subject string |
| 911 | // ebx: previous index |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 912 | // ecx: encoding of subject string (1 if one_byte 0 if two_byte); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 913 | // edx: code |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 914 | // Argument 4: End of string data |
| 915 | // Argument 3: Start of string data |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 916 | // Prepare start and end index of the input. |
| 917 | // Load the length from the original sliced string if that is the case. |
| 918 | __ mov(esi, FieldOperand(esi, String::kLengthOffset)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 919 | __ add(esi, edi); // Calculate input end wrt offset. |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 920 | __ SmiUntag(edi); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 921 | __ add(ebx, edi); // Calculate input start wrt offset. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 922 | |
| 923 | // ebx: start index of the input string |
| 924 | // esi: end index of the input string |
| 925 | Label setup_two_byte, setup_rest; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 926 | __ test(ecx, ecx); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 927 | __ j(zero, &setup_two_byte, Label::kNear); |
| 928 | __ SmiUntag(esi); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 929 | __ lea(ecx, FieldOperand(eax, esi, times_1, SeqOneByteString::kHeaderSize)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 930 | __ mov(Operand(esp, 3 * kPointerSize), ecx); // Argument 4. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 931 | __ lea(ecx, FieldOperand(eax, ebx, times_1, SeqOneByteString::kHeaderSize)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 932 | __ mov(Operand(esp, 2 * kPointerSize), ecx); // Argument 3. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 933 | __ jmp(&setup_rest, Label::kNear); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 934 | |
| 935 | __ bind(&setup_two_byte); |
| 936 | STATIC_ASSERT(kSmiTag == 0); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 937 | STATIC_ASSERT(kSmiTagSize == 1); // esi is smi (powered by 2). |
| 938 | __ lea(ecx, FieldOperand(eax, esi, times_1, SeqTwoByteString::kHeaderSize)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 939 | __ mov(Operand(esp, 3 * kPointerSize), ecx); // Argument 4. |
| 940 | __ lea(ecx, FieldOperand(eax, ebx, times_2, SeqTwoByteString::kHeaderSize)); |
| 941 | __ mov(Operand(esp, 2 * kPointerSize), ecx); // Argument 3. |
| 942 | |
| 943 | __ bind(&setup_rest); |
| 944 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 945 | // Locate the code entry and call it. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 946 | __ add(edx, Immediate(Code::kHeaderSize - kHeapObjectTag)); |
| 947 | __ call(edx); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 948 | |
| 949 | // Drop arguments and come back to JS mode. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 950 | __ LeaveApiExitFrame(true); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 951 | |
| 952 | // Check the result. |
| 953 | Label success; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 954 | __ cmp(eax, 1); |
| 955 | // We expect exactly one result since we force the called regexp to behave |
| 956 | // as non-global. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 957 | __ j(equal, &success); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 958 | Label failure; |
| 959 | __ cmp(eax, NativeRegExpMacroAssembler::FAILURE); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 960 | __ j(equal, &failure); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 961 | __ cmp(eax, NativeRegExpMacroAssembler::EXCEPTION); |
| 962 | // If not exception it can only be retry. Handle that in the runtime system. |
| 963 | __ j(not_equal, &runtime); |
| 964 | // Result must now be exception. If there is no pending exception already a |
| 965 | // stack overflow (on the backtrack stack) was detected in RegExp code but |
| 966 | // haven't created the exception yet. Handle that in the runtime system. |
| 967 | // TODO(592): Rerunning the RegExp to get the stack overflow exception. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 968 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 969 | isolate()); |
| 970 | __ mov(edx, Immediate(isolate()->factory()->the_hole_value())); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 971 | __ mov(eax, Operand::StaticVariable(pending_exception)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 972 | __ cmp(edx, eax); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 973 | __ j(equal, &runtime); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 974 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 975 | // For exception, throw the exception again. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 976 | __ TailCallRuntime(Runtime::kRegExpExecReThrow); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 977 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 978 | __ bind(&failure); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 979 | // For failure to match, return null. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 980 | __ mov(eax, factory->null_value()); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 981 | __ ret(4 * kPointerSize); |
| 982 | |
| 983 | // Load RegExp data. |
| 984 | __ bind(&success); |
| 985 | __ mov(eax, Operand(esp, kJSRegExpOffset)); |
| 986 | __ mov(ecx, FieldOperand(eax, JSRegExp::kDataOffset)); |
| 987 | __ mov(edx, FieldOperand(ecx, JSRegExp::kIrregexpCaptureCountOffset)); |
| 988 | // Calculate number of capture registers (number_of_captures + 1) * 2. |
| 989 | STATIC_ASSERT(kSmiTag == 0); |
| 990 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 991 | __ add(edx, Immediate(2)); // edx was a smi. |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 992 | |
| 993 | // edx: Number of capture registers |
| 994 | // Load last_match_info which is still known to be a fast case JSArray. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 995 | // Check that the fourth object is a JSArray object. |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 996 | __ mov(eax, Operand(esp, kLastMatchInfoOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 997 | __ JumpIfSmi(eax, &runtime); |
| 998 | __ CmpObjectType(eax, JS_ARRAY_TYPE, ebx); |
| 999 | __ j(not_equal, &runtime); |
| 1000 | // Check that the JSArray is in fast case. |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1001 | __ mov(ebx, FieldOperand(eax, JSArray::kElementsOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1002 | __ mov(eax, FieldOperand(ebx, HeapObject::kMapOffset)); |
| 1003 | __ cmp(eax, factory->fixed_array_map()); |
| 1004 | __ j(not_equal, &runtime); |
| 1005 | // Check that the last match info has space for the capture registers and the |
| 1006 | // additional information. |
| 1007 | __ mov(eax, FieldOperand(ebx, FixedArray::kLengthOffset)); |
| 1008 | __ SmiUntag(eax); |
| 1009 | __ sub(eax, Immediate(RegExpImpl::kLastMatchOverhead)); |
| 1010 | __ cmp(edx, eax); |
| 1011 | __ j(greater, &runtime); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1012 | |
| 1013 | // ebx: last_match_info backing store (FixedArray) |
| 1014 | // edx: number of capture registers |
| 1015 | // Store the capture count. |
| 1016 | __ SmiTag(edx); // Number of capture registers to smi. |
| 1017 | __ mov(FieldOperand(ebx, RegExpImpl::kLastCaptureCountOffset), edx); |
| 1018 | __ SmiUntag(edx); // Number of capture registers back from smi. |
| 1019 | // Store last subject and last input. |
| 1020 | __ mov(eax, Operand(esp, kSubjectOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1021 | __ mov(ecx, eax); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1022 | __ mov(FieldOperand(ebx, RegExpImpl::kLastSubjectOffset), eax); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1023 | __ RecordWriteField(ebx, |
| 1024 | RegExpImpl::kLastSubjectOffset, |
| 1025 | eax, |
| 1026 | edi, |
| 1027 | kDontSaveFPRegs); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1028 | __ mov(eax, ecx); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1029 | __ mov(FieldOperand(ebx, RegExpImpl::kLastInputOffset), eax); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1030 | __ RecordWriteField(ebx, |
| 1031 | RegExpImpl::kLastInputOffset, |
| 1032 | eax, |
| 1033 | edi, |
| 1034 | kDontSaveFPRegs); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1035 | |
| 1036 | // Get the static offsets vector filled by the native regexp code. |
| 1037 | ExternalReference address_of_static_offsets_vector = |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1038 | ExternalReference::address_of_static_offsets_vector(isolate()); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1039 | __ mov(ecx, Immediate(address_of_static_offsets_vector)); |
| 1040 | |
| 1041 | // ebx: last_match_info backing store (FixedArray) |
| 1042 | // ecx: offsets vector |
| 1043 | // edx: number of capture registers |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1044 | Label next_capture, done; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1045 | // Capture register counter starts from number of capture registers and |
| 1046 | // counts down until wraping after zero. |
| 1047 | __ bind(&next_capture); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1048 | __ sub(edx, Immediate(1)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1049 | __ j(negative, &done, Label::kNear); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1050 | // Read the value from the static offsets vector buffer. |
| 1051 | __ mov(edi, Operand(ecx, edx, times_int_size, 0)); |
| 1052 | __ SmiTag(edi); |
| 1053 | // Store the smi value in the last match info. |
| 1054 | __ mov(FieldOperand(ebx, |
| 1055 | edx, |
| 1056 | times_pointer_size, |
| 1057 | RegExpImpl::kFirstCaptureOffset), |
| 1058 | edi); |
| 1059 | __ jmp(&next_capture); |
| 1060 | __ bind(&done); |
| 1061 | |
| 1062 | // Return last match info. |
| 1063 | __ mov(eax, Operand(esp, kLastMatchInfoOffset)); |
| 1064 | __ ret(4 * kPointerSize); |
| 1065 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1066 | // Do the runtime call to execute the regexp. |
| 1067 | __ bind(&runtime); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1068 | __ TailCallRuntime(Runtime::kRegExpExec); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1069 | |
| 1070 | // Deferred code for string handling. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1071 | // (6) Long external string? If not, go to (10). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1072 | __ bind(¬_seq_nor_cons); |
| 1073 | // Compare flags are still set from (3). |
| 1074 | __ j(greater, ¬_long_external, Label::kNear); // Go to (10). |
| 1075 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1076 | // (7) External string. Short external strings have been ruled out. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1077 | __ bind(&external_string); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1078 | // Reload instance type. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1079 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 1080 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 1081 | if (FLAG_debug_code) { |
| 1082 | // Assert that we do not have a cons or slice (indirect strings) here. |
| 1083 | // Sequential strings have already been ruled out. |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1084 | __ test_b(ebx, Immediate(kIsIndirectStringMask)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1085 | __ Assert(zero, kExternalStringExpectedButNotFound); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1086 | } |
| 1087 | __ mov(eax, FieldOperand(eax, ExternalString::kResourceDataOffset)); |
| 1088 | // Move the pointer so that offset-wise, it looks like a sequential string. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1089 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1090 | __ sub(eax, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 1091 | STATIC_ASSERT(kTwoByteStringTag == 0); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1092 | // (8) Is the external string one byte? If yes, go to (5). |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1093 | __ test_b(ebx, Immediate(kStringEncodingMask)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1094 | __ j(not_zero, &seq_one_byte_string); // Go to (5). |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1095 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1096 | // eax: sequential subject string (or look-alike, external string) |
| 1097 | // edx: original subject string |
| 1098 | // ecx: RegExp data (FixedArray) |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1099 | // (9) Two byte sequential. Load regexp code for two byte. Go to (E). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1100 | __ bind(&seq_two_byte_string); |
| 1101 | // Load previous index and check range before edx is overwritten. We have |
| 1102 | // to use edx instead of eax here because it might have been only made to |
| 1103 | // look like a sequential string when it actually is an external string. |
| 1104 | __ mov(ebx, Operand(esp, kPreviousIndexOffset)); |
| 1105 | __ JumpIfNotSmi(ebx, &runtime); |
| 1106 | __ cmp(ebx, FieldOperand(edx, String::kLengthOffset)); |
| 1107 | __ j(above_equal, &runtime); |
| 1108 | __ mov(edx, FieldOperand(ecx, JSRegExp::kDataUC16CodeOffset)); |
| 1109 | __ Move(ecx, Immediate(0)); // Type is two byte. |
| 1110 | __ jmp(&check_code); // Go to (E). |
| 1111 | |
| 1112 | // (10) Not a string or a short external string? If yes, bail out to runtime. |
| 1113 | __ bind(¬_long_external); |
| 1114 | // Catch non-string subject or short external string. |
| 1115 | STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0); |
| 1116 | __ test(ebx, Immediate(kIsNotStringMask | kShortExternalStringTag)); |
| 1117 | __ j(not_zero, &runtime); |
| 1118 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1119 | // (11) Sliced string. Replace subject with parent. Go to (1). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1120 | // Load offset into edi and replace subject string with parent. |
| 1121 | __ mov(edi, FieldOperand(eax, SlicedString::kOffsetOffset)); |
| 1122 | __ mov(eax, FieldOperand(eax, SlicedString::kParentOffset)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1123 | __ jmp(&check_underlying); // Go to (1). |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1124 | #endif // V8_INTERPRETED_REGEXP |
| 1125 | } |
| 1126 | |
| 1127 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1128 | static int NegativeComparisonResult(Condition cc) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1129 | DCHECK(cc != equal); |
| 1130 | DCHECK((cc == less) || (cc == less_equal) |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1131 | || (cc == greater) || (cc == greater_equal)); |
| 1132 | return (cc == greater || cc == greater_equal) ? LESS : GREATER; |
| 1133 | } |
| 1134 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1135 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1136 | static void CheckInputType(MacroAssembler* masm, Register input, |
| 1137 | CompareICState::State expected, Label* fail) { |
| 1138 | Label ok; |
| 1139 | if (expected == CompareICState::SMI) { |
| 1140 | __ JumpIfNotSmi(input, fail); |
| 1141 | } else if (expected == CompareICState::NUMBER) { |
| 1142 | __ JumpIfSmi(input, &ok); |
| 1143 | __ cmp(FieldOperand(input, HeapObject::kMapOffset), |
| 1144 | Immediate(masm->isolate()->factory()->heap_number_map())); |
| 1145 | __ j(not_equal, fail); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1146 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1147 | // We could be strict about internalized/non-internalized here, but as long as |
| 1148 | // hydrogen doesn't care, the stub doesn't have to care either. |
| 1149 | __ bind(&ok); |
| 1150 | } |
| 1151 | |
| 1152 | |
| 1153 | static void BranchIfNotInternalizedString(MacroAssembler* masm, |
| 1154 | Label* label, |
| 1155 | Register object, |
| 1156 | Register scratch) { |
| 1157 | __ JumpIfSmi(object, label); |
| 1158 | __ mov(scratch, FieldOperand(object, HeapObject::kMapOffset)); |
| 1159 | __ movzx_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset)); |
| 1160 | STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0); |
| 1161 | __ test(scratch, Immediate(kIsNotStringMask | kIsNotInternalizedMask)); |
| 1162 | __ j(not_zero, label); |
| 1163 | } |
| 1164 | |
| 1165 | |
| 1166 | void CompareICStub::GenerateGeneric(MacroAssembler* masm) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1167 | Label runtime_call, check_unequal_objects; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1168 | Condition cc = GetCondition(); |
| 1169 | |
| 1170 | Label miss; |
| 1171 | CheckInputType(masm, edx, left(), &miss); |
| 1172 | CheckInputType(masm, eax, right(), &miss); |
| 1173 | |
| 1174 | // Compare two smis. |
| 1175 | Label non_smi, smi_done; |
| 1176 | __ mov(ecx, edx); |
| 1177 | __ or_(ecx, eax); |
| 1178 | __ JumpIfNotSmi(ecx, &non_smi, Label::kNear); |
| 1179 | __ sub(edx, eax); // Return on the result of the subtraction. |
| 1180 | __ j(no_overflow, &smi_done, Label::kNear); |
| 1181 | __ not_(edx); // Correct sign in case of overflow. edx is never 0 here. |
| 1182 | __ bind(&smi_done); |
| 1183 | __ mov(eax, edx); |
| 1184 | __ ret(0); |
| 1185 | __ bind(&non_smi); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1186 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1187 | // NOTICE! This code is only reached after a smi-fast-case check, so |
| 1188 | // it is certain that at least one operand isn't a smi. |
| 1189 | |
| 1190 | // Identical objects can be compared fast, but there are some tricky cases |
| 1191 | // for NaN and undefined. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1192 | Label generic_heap_number_comparison; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1193 | { |
| 1194 | Label not_identical; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1195 | __ cmp(eax, edx); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1196 | __ j(not_equal, ¬_identical); |
| 1197 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1198 | if (cc != equal) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1199 | // Check for undefined. undefined OP undefined is false even though |
| 1200 | // undefined == undefined. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1201 | __ cmp(edx, isolate()->factory()->undefined_value()); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1202 | Label check_for_nan; |
| 1203 | __ j(not_equal, &check_for_nan, Label::kNear); |
| 1204 | __ Move(eax, Immediate(Smi::FromInt(NegativeComparisonResult(cc)))); |
| 1205 | __ ret(0); |
| 1206 | __ bind(&check_for_nan); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1207 | } |
| 1208 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1209 | // Test for NaN. Compare heap numbers in a general way, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1210 | // to handle NaNs correctly. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1211 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 1212 | Immediate(isolate()->factory()->heap_number_map())); |
| 1213 | __ j(equal, &generic_heap_number_comparison, Label::kNear); |
| 1214 | if (cc != equal) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1215 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 1216 | __ movzx_b(ecx, FieldOperand(ecx, Map::kInstanceTypeOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1217 | // Call runtime on identical JSObjects. Otherwise return equal. |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1218 | __ cmpb(ecx, Immediate(FIRST_JS_RECEIVER_TYPE)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1219 | __ j(above_equal, &runtime_call, Label::kFar); |
| 1220 | // Call runtime on identical symbols since we need to throw a TypeError. |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1221 | __ cmpb(ecx, Immediate(SYMBOL_TYPE)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1222 | __ j(equal, &runtime_call, Label::kFar); |
| 1223 | // Call runtime on identical SIMD values since we must throw a TypeError. |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1224 | __ cmpb(ecx, Immediate(SIMD128_VALUE_TYPE)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1225 | __ j(equal, &runtime_call, Label::kFar); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1226 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1227 | __ Move(eax, Immediate(Smi::FromInt(EQUAL))); |
| 1228 | __ ret(0); |
| 1229 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1230 | |
| 1231 | __ bind(¬_identical); |
| 1232 | } |
| 1233 | |
| 1234 | // Strict equality can quickly decide whether objects are equal. |
| 1235 | // Non-strict object equality is slower, so it is handled later in the stub. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1236 | if (cc == equal && strict()) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1237 | Label slow; // Fallthrough label. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1238 | Label not_smis; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1239 | // If we're doing a strict equality comparison, we don't have to do |
| 1240 | // type conversion, so we generate code to do fast comparison for objects |
| 1241 | // and oddballs. Non-smi numbers and strings still go through the usual |
| 1242 | // slow-case code. |
| 1243 | // If either is a Smi (we know that not both are), then they can only |
| 1244 | // be equal if the other is a HeapNumber. If so, use the slow case. |
| 1245 | STATIC_ASSERT(kSmiTag == 0); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1246 | DCHECK_EQ(static_cast<Smi*>(0), Smi::FromInt(0)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1247 | __ mov(ecx, Immediate(kSmiTagMask)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1248 | __ and_(ecx, eax); |
| 1249 | __ test(ecx, edx); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1250 | __ j(not_zero, ¬_smis, Label::kNear); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1251 | // One operand is a smi. |
| 1252 | |
| 1253 | // Check whether the non-smi is a heap number. |
| 1254 | STATIC_ASSERT(kSmiTagMask == 1); |
| 1255 | // ecx still holds eax & kSmiTag, which is either zero or one. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1256 | __ sub(ecx, Immediate(0x01)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1257 | __ mov(ebx, edx); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1258 | __ xor_(ebx, eax); |
| 1259 | __ and_(ebx, ecx); // ebx holds either 0 or eax ^ edx. |
| 1260 | __ xor_(ebx, eax); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1261 | // if eax was smi, ebx is now edx, else eax. |
| 1262 | |
| 1263 | // Check if the non-smi operand is a heap number. |
| 1264 | __ cmp(FieldOperand(ebx, HeapObject::kMapOffset), |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1265 | Immediate(isolate()->factory()->heap_number_map())); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1266 | // If heap number, handle it in the slow case. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1267 | __ j(equal, &slow, Label::kNear); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1268 | // Return non-equal (ebx is not zero) |
| 1269 | __ mov(eax, ebx); |
| 1270 | __ ret(0); |
| 1271 | |
| 1272 | __ bind(¬_smis); |
| 1273 | // If either operand is a JSObject or an oddball value, then they are not |
| 1274 | // equal since their pointers are different |
| 1275 | // There is no test for undetectability in strict equality. |
| 1276 | |
| 1277 | // Get the type of the first operand. |
| 1278 | // If the first object is a JS object, we have done pointer comparison. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1279 | Label first_non_object; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1280 | STATIC_ASSERT(LAST_TYPE == LAST_JS_RECEIVER_TYPE); |
| 1281 | __ CmpObjectType(eax, FIRST_JS_RECEIVER_TYPE, ecx); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1282 | __ j(below, &first_non_object, Label::kNear); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1283 | |
| 1284 | // Return non-zero (eax is not zero) |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1285 | Label return_not_equal; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1286 | STATIC_ASSERT(kHeapObjectTag != 0); |
| 1287 | __ bind(&return_not_equal); |
| 1288 | __ ret(0); |
| 1289 | |
| 1290 | __ bind(&first_non_object); |
| 1291 | // Check for oddballs: true, false, null, undefined. |
| 1292 | __ CmpInstanceType(ecx, ODDBALL_TYPE); |
| 1293 | __ j(equal, &return_not_equal); |
| 1294 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1295 | __ CmpObjectType(edx, FIRST_JS_RECEIVER_TYPE, ecx); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1296 | __ j(above_equal, &return_not_equal); |
| 1297 | |
| 1298 | // Check for oddballs: true, false, null, undefined. |
| 1299 | __ CmpInstanceType(ecx, ODDBALL_TYPE); |
| 1300 | __ j(equal, &return_not_equal); |
| 1301 | |
| 1302 | // Fall through to the general case. |
| 1303 | __ bind(&slow); |
| 1304 | } |
| 1305 | |
| 1306 | // Generate the number comparison code. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1307 | Label non_number_comparison; |
| 1308 | Label unordered; |
| 1309 | __ bind(&generic_heap_number_comparison); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1310 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1311 | FloatingPointHelper::LoadSSE2Operands(masm, &non_number_comparison); |
| 1312 | __ ucomisd(xmm0, xmm1); |
| 1313 | // Don't base result on EFLAGS when a NaN is involved. |
| 1314 | __ j(parity_even, &unordered, Label::kNear); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1315 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1316 | __ mov(eax, 0); // equal |
| 1317 | __ mov(ecx, Immediate(Smi::FromInt(1))); |
| 1318 | __ cmov(above, eax, ecx); |
| 1319 | __ mov(ecx, Immediate(Smi::FromInt(-1))); |
| 1320 | __ cmov(below, eax, ecx); |
| 1321 | __ ret(0); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1322 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1323 | // If one of the numbers was NaN, then the result is always false. |
| 1324 | // The cc is never not-equal. |
| 1325 | __ bind(&unordered); |
| 1326 | DCHECK(cc != not_equal); |
| 1327 | if (cc == less || cc == less_equal) { |
| 1328 | __ mov(eax, Immediate(Smi::FromInt(1))); |
| 1329 | } else { |
| 1330 | __ mov(eax, Immediate(Smi::FromInt(-1))); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1331 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1332 | __ ret(0); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1333 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1334 | // The number comparison code did not provide a valid result. |
| 1335 | __ bind(&non_number_comparison); |
| 1336 | |
| 1337 | // Fast negative check for internalized-to-internalized equality. |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1338 | Label check_for_strings; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1339 | if (cc == equal) { |
| 1340 | BranchIfNotInternalizedString(masm, &check_for_strings, eax, ecx); |
| 1341 | BranchIfNotInternalizedString(masm, &check_for_strings, edx, ecx); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1342 | |
| 1343 | // We've already checked for object identity, so if both operands |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1344 | // are internalized they aren't equal. Register eax already holds a |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1345 | // non-zero value, which indicates not equal, so just return. |
| 1346 | __ ret(0); |
| 1347 | } |
| 1348 | |
| 1349 | __ bind(&check_for_strings); |
| 1350 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1351 | __ JumpIfNotBothSequentialOneByteStrings(edx, eax, ecx, ebx, |
| 1352 | &check_unequal_objects); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1353 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1354 | // Inline comparison of one-byte strings. |
| 1355 | if (cc == equal) { |
| 1356 | StringHelper::GenerateFlatOneByteStringEquals(masm, edx, eax, ecx, ebx); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1357 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1358 | StringHelper::GenerateCompareFlatOneByteStrings(masm, edx, eax, ecx, ebx, |
| 1359 | edi); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1360 | } |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1361 | #ifdef DEBUG |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1362 | __ Abort(kUnexpectedFallThroughFromStringComparison); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1363 | #endif |
| 1364 | |
| 1365 | __ bind(&check_unequal_objects); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1366 | if (cc == equal && !strict()) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1367 | // Non-strict equality. Objects are unequal if |
| 1368 | // they are both JSObjects and not undetectable, |
| 1369 | // and their pointers are different. |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1370 | Label return_equal, return_unequal, undetectable; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1371 | // At most one is a smi, so we can test for smi by adding the two. |
| 1372 | // A smi plus a heap object has the low bit set, a heap object plus |
| 1373 | // a heap object has the low bit clear. |
| 1374 | STATIC_ASSERT(kSmiTag == 0); |
| 1375 | STATIC_ASSERT(kSmiTagMask == 1); |
| 1376 | __ lea(ecx, Operand(eax, edx, times_1, 0)); |
| 1377 | __ test(ecx, Immediate(kSmiTagMask)); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1378 | __ j(not_zero, &runtime_call); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1379 | |
| 1380 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 1381 | __ mov(ebx, FieldOperand(edx, HeapObject::kMapOffset)); |
| 1382 | |
| 1383 | __ test_b(FieldOperand(ebx, Map::kBitFieldOffset), |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1384 | Immediate(1 << Map::kIsUndetectable)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1385 | __ j(not_zero, &undetectable, Label::kNear); |
| 1386 | __ test_b(FieldOperand(ecx, Map::kBitFieldOffset), |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1387 | Immediate(1 << Map::kIsUndetectable)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1388 | __ j(not_zero, &return_unequal, Label::kNear); |
| 1389 | |
| 1390 | __ CmpInstanceType(ebx, FIRST_JS_RECEIVER_TYPE); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1391 | __ j(below, &runtime_call, Label::kNear); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1392 | __ CmpInstanceType(ecx, FIRST_JS_RECEIVER_TYPE); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1393 | __ j(below, &runtime_call, Label::kNear); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1394 | |
| 1395 | __ bind(&return_unequal); |
| 1396 | // Return non-equal by returning the non-zero object pointer in eax. |
| 1397 | __ ret(0); // eax, edx were pushed |
| 1398 | |
| 1399 | __ bind(&undetectable); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1400 | __ test_b(FieldOperand(ecx, Map::kBitFieldOffset), |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1401 | Immediate(1 << Map::kIsUndetectable)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1402 | __ j(zero, &return_unequal, Label::kNear); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1403 | |
| 1404 | // If both sides are JSReceivers, then the result is false according to |
| 1405 | // the HTML specification, which says that only comparisons with null or |
| 1406 | // undefined are affected by special casing for document.all. |
| 1407 | __ CmpInstanceType(ebx, ODDBALL_TYPE); |
| 1408 | __ j(zero, &return_equal, Label::kNear); |
| 1409 | __ CmpInstanceType(ecx, ODDBALL_TYPE); |
| 1410 | __ j(not_zero, &return_unequal, Label::kNear); |
| 1411 | |
| 1412 | __ bind(&return_equal); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1413 | __ Move(eax, Immediate(EQUAL)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1414 | __ ret(0); // eax, edx were pushed |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1415 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1416 | __ bind(&runtime_call); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1417 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1418 | if (cc == equal) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1419 | { |
| 1420 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 1421 | __ Push(edx); |
| 1422 | __ Push(eax); |
| 1423 | __ CallRuntime(strict() ? Runtime::kStrictEqual : Runtime::kEqual); |
| 1424 | } |
| 1425 | // Turn true into 0 and false into some non-zero value. |
| 1426 | STATIC_ASSERT(EQUAL == 0); |
| 1427 | __ sub(eax, Immediate(isolate()->factory()->true_value())); |
| 1428 | __ Ret(); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1429 | } else { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1430 | // Push arguments below the return address. |
| 1431 | __ pop(ecx); |
| 1432 | __ push(edx); |
| 1433 | __ push(eax); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1434 | __ push(Immediate(Smi::FromInt(NegativeComparisonResult(cc)))); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1435 | __ push(ecx); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1436 | // Call the native; it returns -1 (less), 0 (equal), or 1 (greater) |
| 1437 | // tagged as a small integer. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1438 | __ TailCallRuntime(Runtime::kCompare); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1439 | } |
| 1440 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1441 | __ bind(&miss); |
| 1442 | GenerateMiss(masm); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1443 | } |
| 1444 | |
| 1445 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1446 | static void CallStubInRecordCallTarget(MacroAssembler* masm, CodeStub* stub) { |
| 1447 | // eax : number of arguments to the construct function |
| 1448 | // ebx : feedback vector |
| 1449 | // edx : slot in feedback vector (Smi) |
| 1450 | // edi : the function to call |
| 1451 | |
| 1452 | { |
| 1453 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 1454 | |
| 1455 | // Number-of-arguments register must be smi-tagged to call out. |
| 1456 | __ SmiTag(eax); |
| 1457 | __ push(eax); |
| 1458 | __ push(edi); |
| 1459 | __ push(edx); |
| 1460 | __ push(ebx); |
| 1461 | |
| 1462 | __ CallStub(stub); |
| 1463 | |
| 1464 | __ pop(ebx); |
| 1465 | __ pop(edx); |
| 1466 | __ pop(edi); |
| 1467 | __ pop(eax); |
| 1468 | __ SmiUntag(eax); |
| 1469 | } |
| 1470 | } |
| 1471 | |
| 1472 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1473 | static void GenerateRecordCallTarget(MacroAssembler* masm) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1474 | // Cache the called function in a feedback vector slot. Cache states |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1475 | // are uninitialized, monomorphic (indicated by a JSFunction), and |
| 1476 | // megamorphic. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1477 | // eax : number of arguments to the construct function |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1478 | // ebx : feedback vector |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1479 | // edx : slot in feedback vector (Smi) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1480 | // edi : the function to call |
| 1481 | Isolate* isolate = masm->isolate(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1482 | Label initialize, done, miss, megamorphic, not_array_function; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1483 | |
| 1484 | // Load the cache state into ecx. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1485 | __ mov(ecx, FieldOperand(ebx, edx, times_half_pointer_size, |
| 1486 | FixedArray::kHeaderSize)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1487 | |
| 1488 | // A monomorphic cache hit or an already megamorphic state: invoke the |
| 1489 | // function without changing the state. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1490 | // We don't know if ecx is a WeakCell or a Symbol, but it's harmless to read |
| 1491 | // at this position in a symbol (see static asserts in |
| 1492 | // type-feedback-vector.h). |
| 1493 | Label check_allocation_site; |
| 1494 | __ cmp(edi, FieldOperand(ecx, WeakCell::kValueOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1495 | __ j(equal, &done, Label::kFar); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1496 | __ CompareRoot(ecx, Heap::kmegamorphic_symbolRootIndex); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1497 | __ j(equal, &done, Label::kFar); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1498 | __ CompareRoot(FieldOperand(ecx, HeapObject::kMapOffset), |
| 1499 | Heap::kWeakCellMapRootIndex); |
| 1500 | __ j(not_equal, &check_allocation_site); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1501 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1502 | // If the weak cell is cleared, we have a new chance to become monomorphic. |
| 1503 | __ JumpIfSmi(FieldOperand(ecx, WeakCell::kValueOffset), &initialize); |
| 1504 | __ jmp(&megamorphic); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1505 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1506 | __ bind(&check_allocation_site); |
| 1507 | // If we came here, we need to see if we are the array function. |
| 1508 | // If we didn't have a matching function, and we didn't find the megamorph |
| 1509 | // sentinel, then we have in the slot either some other function or an |
| 1510 | // AllocationSite. |
| 1511 | __ CompareRoot(FieldOperand(ecx, 0), Heap::kAllocationSiteMapRootIndex); |
| 1512 | __ j(not_equal, &miss); |
| 1513 | |
| 1514 | // Make sure the function is the Array() function |
| 1515 | __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, ecx); |
| 1516 | __ cmp(edi, ecx); |
| 1517 | __ j(not_equal, &megamorphic); |
| 1518 | __ jmp(&done, Label::kFar); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1519 | |
| 1520 | __ bind(&miss); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1521 | |
| 1522 | // A monomorphic miss (i.e, here the cache is not uninitialized) goes |
| 1523 | // megamorphic. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1524 | __ CompareRoot(ecx, Heap::kuninitialized_symbolRootIndex); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1525 | __ j(equal, &initialize); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1526 | // MegamorphicSentinel is an immortal immovable object (undefined) so no |
| 1527 | // write-barrier is needed. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1528 | __ bind(&megamorphic); |
| 1529 | __ mov( |
| 1530 | FieldOperand(ebx, edx, times_half_pointer_size, FixedArray::kHeaderSize), |
| 1531 | Immediate(TypeFeedbackVector::MegamorphicSentinel(isolate))); |
| 1532 | __ jmp(&done, Label::kFar); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1533 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1534 | // An uninitialized cache is patched with the function or sentinel to |
| 1535 | // indicate the ElementsKind if function is the Array constructor. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1536 | __ bind(&initialize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1537 | // Make sure the function is the Array() function |
| 1538 | __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, ecx); |
| 1539 | __ cmp(edi, ecx); |
| 1540 | __ j(not_equal, ¬_array_function); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1541 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1542 | // The target function is the Array constructor, |
| 1543 | // Create an AllocationSite if we don't already have it, store it in the |
| 1544 | // slot. |
| 1545 | CreateAllocationSiteStub create_stub(isolate); |
| 1546 | CallStubInRecordCallTarget(masm, &create_stub); |
| 1547 | __ jmp(&done); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1548 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1549 | __ bind(¬_array_function); |
| 1550 | CreateWeakCellStub weak_cell_stub(isolate); |
| 1551 | CallStubInRecordCallTarget(masm, &weak_cell_stub); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1552 | __ bind(&done); |
| 1553 | } |
| 1554 | |
| 1555 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1556 | void CallConstructStub::Generate(MacroAssembler* masm) { |
| 1557 | // eax : number of arguments |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1558 | // ebx : feedback vector |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1559 | // edx : slot in feedback vector (Smi, for RecordCallTarget) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1560 | // edi : constructor function |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1561 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1562 | Label non_function; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1563 | // Check that function is not a smi. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1564 | __ JumpIfSmi(edi, &non_function); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1565 | // Check that function is a JSFunction. |
| 1566 | __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1567 | __ j(not_equal, &non_function); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1568 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1569 | GenerateRecordCallTarget(masm); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1570 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1571 | Label feedback_register_initialized; |
| 1572 | // Put the AllocationSite from the feedback vector into ebx, or undefined. |
| 1573 | __ mov(ebx, FieldOperand(ebx, edx, times_half_pointer_size, |
| 1574 | FixedArray::kHeaderSize)); |
| 1575 | Handle<Map> allocation_site_map = isolate()->factory()->allocation_site_map(); |
| 1576 | __ cmp(FieldOperand(ebx, 0), Immediate(allocation_site_map)); |
| 1577 | __ j(equal, &feedback_register_initialized); |
| 1578 | __ mov(ebx, isolate()->factory()->undefined_value()); |
| 1579 | __ bind(&feedback_register_initialized); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1580 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1581 | __ AssertUndefinedOrAllocationSite(ebx); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1582 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1583 | // Pass new target to construct stub. |
| 1584 | __ mov(edx, edi); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1585 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1586 | // Tail call to the function-specific construct stub (still in the caller |
| 1587 | // context at this point). |
| 1588 | __ mov(ecx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); |
| 1589 | __ mov(ecx, FieldOperand(ecx, SharedFunctionInfo::kConstructStubOffset)); |
| 1590 | __ lea(ecx, FieldOperand(ecx, Code::kHeaderSize)); |
| 1591 | __ jmp(ecx); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1592 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1593 | __ bind(&non_function); |
| 1594 | __ mov(edx, edi); |
| 1595 | __ Jump(isolate()->builtins()->Construct(), RelocInfo::CODE_TARGET); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1596 | } |
| 1597 | |
| 1598 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1599 | void CallICStub::HandleArrayCase(MacroAssembler* masm, Label* miss) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1600 | // edi - function |
| 1601 | // edx - slot id |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1602 | // ebx - vector |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1603 | __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, ecx); |
| 1604 | __ cmp(edi, ecx); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1605 | __ j(not_equal, miss); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1606 | |
| 1607 | __ mov(eax, arg_count()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1608 | // Reload ecx. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1609 | __ mov(ecx, FieldOperand(ebx, edx, times_half_pointer_size, |
| 1610 | FixedArray::kHeaderSize)); |
| 1611 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1612 | // Increment the call count for monomorphic function calls. |
| 1613 | __ add(FieldOperand(ebx, edx, times_half_pointer_size, |
| 1614 | FixedArray::kHeaderSize + kPointerSize), |
| 1615 | Immediate(Smi::FromInt(CallICNexus::kCallCountIncrement))); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1616 | |
| 1617 | __ mov(ebx, ecx); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1618 | __ mov(edx, edi); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1619 | ArrayConstructorStub stub(masm->isolate(), arg_count()); |
| 1620 | __ TailCallStub(&stub); |
| 1621 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1622 | // Unreachable. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1623 | } |
| 1624 | |
| 1625 | |
| 1626 | void CallICStub::Generate(MacroAssembler* masm) { |
| 1627 | // edi - function |
| 1628 | // edx - slot id |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1629 | // ebx - vector |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1630 | Isolate* isolate = masm->isolate(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1631 | Label extra_checks_or_miss, call, call_function; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1632 | int argc = arg_count(); |
| 1633 | ParameterCount actual(argc); |
| 1634 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1635 | // The checks. First, does edi match the recorded monomorphic target? |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1636 | __ mov(ecx, FieldOperand(ebx, edx, times_half_pointer_size, |
| 1637 | FixedArray::kHeaderSize)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1638 | |
| 1639 | // We don't know that we have a weak cell. We might have a private symbol |
| 1640 | // or an AllocationSite, but the memory is safe to examine. |
| 1641 | // AllocationSite::kTransitionInfoOffset - contains a Smi or pointer to |
| 1642 | // FixedArray. |
| 1643 | // WeakCell::kValueOffset - contains a JSFunction or Smi(0) |
| 1644 | // Symbol::kHashFieldSlot - if the low bit is 1, then the hash is not |
| 1645 | // computed, meaning that it can't appear to be a pointer. If the low bit is |
| 1646 | // 0, then hash is computed, but the 0 bit prevents the field from appearing |
| 1647 | // to be a pointer. |
| 1648 | STATIC_ASSERT(WeakCell::kSize >= kPointerSize); |
| 1649 | STATIC_ASSERT(AllocationSite::kTransitionInfoOffset == |
| 1650 | WeakCell::kValueOffset && |
| 1651 | WeakCell::kValueOffset == Symbol::kHashFieldSlot); |
| 1652 | |
| 1653 | __ cmp(edi, FieldOperand(ecx, WeakCell::kValueOffset)); |
| 1654 | __ j(not_equal, &extra_checks_or_miss); |
| 1655 | |
| 1656 | // The compare above could have been a SMI/SMI comparison. Guard against this |
| 1657 | // convincing us that we have a monomorphic JSFunction. |
| 1658 | __ JumpIfSmi(edi, &extra_checks_or_miss); |
| 1659 | |
| 1660 | // Increment the call count for monomorphic function calls. |
| 1661 | __ add(FieldOperand(ebx, edx, times_half_pointer_size, |
| 1662 | FixedArray::kHeaderSize + kPointerSize), |
| 1663 | Immediate(Smi::FromInt(CallICNexus::kCallCountIncrement))); |
| 1664 | |
| 1665 | __ bind(&call_function); |
| 1666 | __ Set(eax, argc); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1667 | __ Jump(masm->isolate()->builtins()->CallFunction(convert_mode(), |
| 1668 | tail_call_mode()), |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1669 | RelocInfo::CODE_TARGET); |
| 1670 | |
| 1671 | __ bind(&extra_checks_or_miss); |
| 1672 | Label uninitialized, miss, not_allocation_site; |
| 1673 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1674 | __ cmp(ecx, Immediate(TypeFeedbackVector::MegamorphicSentinel(isolate))); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1675 | __ j(equal, &call); |
| 1676 | |
| 1677 | // Check if we have an allocation site. |
| 1678 | __ CompareRoot(FieldOperand(ecx, HeapObject::kMapOffset), |
| 1679 | Heap::kAllocationSiteMapRootIndex); |
| 1680 | __ j(not_equal, ¬_allocation_site); |
| 1681 | |
| 1682 | // We have an allocation site. |
| 1683 | HandleArrayCase(masm, &miss); |
| 1684 | |
| 1685 | __ bind(¬_allocation_site); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1686 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1687 | // The following cases attempt to handle MISS cases without going to the |
| 1688 | // runtime. |
| 1689 | if (FLAG_trace_ic) { |
| 1690 | __ jmp(&miss); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1691 | } |
| 1692 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1693 | __ cmp(ecx, Immediate(TypeFeedbackVector::UninitializedSentinel(isolate))); |
| 1694 | __ j(equal, &uninitialized); |
| 1695 | |
| 1696 | // We are going megamorphic. If the feedback is a JSFunction, it is fine |
| 1697 | // to handle it here. More complex cases are dealt with in the runtime. |
| 1698 | __ AssertNotSmi(ecx); |
| 1699 | __ CmpObjectType(ecx, JS_FUNCTION_TYPE, ecx); |
| 1700 | __ j(not_equal, &miss); |
| 1701 | __ mov( |
| 1702 | FieldOperand(ebx, edx, times_half_pointer_size, FixedArray::kHeaderSize), |
| 1703 | Immediate(TypeFeedbackVector::MegamorphicSentinel(isolate))); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1704 | |
| 1705 | __ bind(&call); |
| 1706 | __ Set(eax, argc); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1707 | __ Jump(masm->isolate()->builtins()->Call(convert_mode(), tail_call_mode()), |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1708 | RelocInfo::CODE_TARGET); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1709 | |
| 1710 | __ bind(&uninitialized); |
| 1711 | |
| 1712 | // We are going monomorphic, provided we actually have a JSFunction. |
| 1713 | __ JumpIfSmi(edi, &miss); |
| 1714 | |
| 1715 | // Goto miss case if we do not have a function. |
| 1716 | __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
| 1717 | __ j(not_equal, &miss); |
| 1718 | |
| 1719 | // Make sure the function is not the Array() function, which requires special |
| 1720 | // behavior on MISS. |
| 1721 | __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, ecx); |
| 1722 | __ cmp(edi, ecx); |
| 1723 | __ j(equal, &miss); |
| 1724 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1725 | // Make sure the function belongs to the same native context. |
| 1726 | __ mov(ecx, FieldOperand(edi, JSFunction::kContextOffset)); |
| 1727 | __ mov(ecx, ContextOperand(ecx, Context::NATIVE_CONTEXT_INDEX)); |
| 1728 | __ cmp(ecx, NativeContextOperand()); |
| 1729 | __ j(not_equal, &miss); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1730 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1731 | // Initialize the call counter. |
| 1732 | __ mov(FieldOperand(ebx, edx, times_half_pointer_size, |
| 1733 | FixedArray::kHeaderSize + kPointerSize), |
| 1734 | Immediate(Smi::FromInt(CallICNexus::kCallCountIncrement))); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1735 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1736 | // Store the function. Use a stub since we need a frame for allocation. |
| 1737 | // ebx - vector |
| 1738 | // edx - slot |
| 1739 | // edi - function |
| 1740 | { |
| 1741 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 1742 | CreateWeakCellStub create_stub(isolate); |
| 1743 | __ push(edi); |
| 1744 | __ CallStub(&create_stub); |
| 1745 | __ pop(edi); |
| 1746 | } |
| 1747 | |
| 1748 | __ jmp(&call_function); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1749 | |
| 1750 | // We are here because tracing is on or we encountered a MISS case we can't |
| 1751 | // handle here. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1752 | __ bind(&miss); |
| 1753 | GenerateMiss(masm); |
| 1754 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1755 | __ jmp(&call); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1756 | |
| 1757 | // Unreachable |
| 1758 | __ int3(); |
| 1759 | } |
| 1760 | |
| 1761 | |
| 1762 | void CallICStub::GenerateMiss(MacroAssembler* masm) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1763 | FrameScope scope(masm, StackFrame::INTERNAL); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1764 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1765 | // Push the function and feedback info. |
| 1766 | __ push(edi); |
| 1767 | __ push(ebx); |
| 1768 | __ push(edx); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1769 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1770 | // Call the entry. |
| 1771 | __ CallRuntime(Runtime::kCallIC_Miss); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1772 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1773 | // Move result to edi and exit the internal frame. |
| 1774 | __ mov(edi, eax); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1775 | } |
| 1776 | |
| 1777 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1778 | bool CEntryStub::NeedsImmovableCode() { |
| 1779 | return false; |
| 1780 | } |
| 1781 | |
| 1782 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1783 | void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) { |
| 1784 | CEntryStub::GenerateAheadOfTime(isolate); |
| 1785 | StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate); |
| 1786 | StubFailureTrampolineStub::GenerateAheadOfTime(isolate); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1787 | // It is important that the store buffer overflow stubs are generated first. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1788 | ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate); |
| 1789 | CreateAllocationSiteStub::GenerateAheadOfTime(isolate); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1790 | CreateWeakCellStub::GenerateAheadOfTime(isolate); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1791 | BinaryOpICStub::GenerateAheadOfTime(isolate); |
| 1792 | BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime(isolate); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1793 | StoreFastElementStub::GenerateAheadOfTime(isolate); |
| 1794 | TypeofStub::GenerateAheadOfTime(isolate); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1795 | } |
| 1796 | |
| 1797 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1798 | void CodeStub::GenerateFPStubs(Isolate* isolate) { |
| 1799 | // Generate if not already in cache. |
| 1800 | CEntryStub(isolate, 1, kSaveFPRegs).GetCode(); |
| 1801 | isolate->set_fp_stubs_generated(true); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1802 | } |
| 1803 | |
| 1804 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1805 | void CEntryStub::GenerateAheadOfTime(Isolate* isolate) { |
| 1806 | CEntryStub stub(isolate, 1, kDontSaveFPRegs); |
| 1807 | stub.GetCode(); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1808 | } |
| 1809 | |
| 1810 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1811 | void CEntryStub::Generate(MacroAssembler* masm) { |
| 1812 | // eax: number of arguments including receiver |
| 1813 | // ebx: pointer to C function (C callee-saved) |
| 1814 | // ebp: frame pointer (restored after C call) |
| 1815 | // esp: stack pointer (restored after C call) |
| 1816 | // esi: current context (C callee-saved) |
| 1817 | // edi: JS function of the caller (C callee-saved) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1818 | // |
| 1819 | // If argv_in_register(): |
| 1820 | // ecx: pointer to the first argument |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1821 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1822 | ProfileEntryHookStub::MaybeCallEntryHook(masm); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1823 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1824 | // Reserve space on the stack for the three arguments passed to the call. If |
| 1825 | // result size is greater than can be returned in registers, also reserve |
| 1826 | // space for the hidden argument for the result location, and space for the |
| 1827 | // result itself. |
| 1828 | int arg_stack_space = result_size() < 3 ? 3 : 4 + result_size(); |
| 1829 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1830 | // Enter the exit frame that transitions from JavaScript to C++. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1831 | if (argv_in_register()) { |
| 1832 | DCHECK(!save_doubles()); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1833 | __ EnterApiExitFrame(arg_stack_space); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1834 | |
| 1835 | // Move argc and argv into the correct registers. |
| 1836 | __ mov(esi, ecx); |
| 1837 | __ mov(edi, eax); |
| 1838 | } else { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1839 | __ EnterExitFrame(arg_stack_space, save_doubles()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1840 | } |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1841 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1842 | // ebx: pointer to C function (C callee-saved) |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1843 | // ebp: frame pointer (restored after C call) |
| 1844 | // esp: stack pointer (restored after C call) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1845 | // edi: number of arguments including receiver (C callee-saved) |
| 1846 | // esi: pointer to the first argument (C callee-saved) |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1847 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1848 | // Result returned in eax, or eax+edx if result size is 2. |
| 1849 | |
| 1850 | // Check stack alignment. |
| 1851 | if (FLAG_debug_code) { |
| 1852 | __ CheckStackAlignment(); |
| 1853 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1854 | // Call C function. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1855 | if (result_size() <= 2) { |
| 1856 | __ mov(Operand(esp, 0 * kPointerSize), edi); // argc. |
| 1857 | __ mov(Operand(esp, 1 * kPointerSize), esi); // argv. |
| 1858 | __ mov(Operand(esp, 2 * kPointerSize), |
| 1859 | Immediate(ExternalReference::isolate_address(isolate()))); |
| 1860 | } else { |
| 1861 | DCHECK_EQ(3, result_size()); |
| 1862 | // Pass a pointer to the result location as the first argument. |
| 1863 | __ lea(eax, Operand(esp, 4 * kPointerSize)); |
| 1864 | __ mov(Operand(esp, 0 * kPointerSize), eax); |
| 1865 | __ mov(Operand(esp, 1 * kPointerSize), edi); // argc. |
| 1866 | __ mov(Operand(esp, 2 * kPointerSize), esi); // argv. |
| 1867 | __ mov(Operand(esp, 3 * kPointerSize), |
| 1868 | Immediate(ExternalReference::isolate_address(isolate()))); |
| 1869 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1870 | __ call(ebx); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1871 | |
| 1872 | if (result_size() > 2) { |
| 1873 | DCHECK_EQ(3, result_size()); |
| 1874 | #ifndef _WIN32 |
| 1875 | // Restore the "hidden" argument on the stack which was popped by caller. |
| 1876 | __ sub(esp, Immediate(kPointerSize)); |
| 1877 | #endif |
| 1878 | // Read result values stored on stack. Result is stored above the arguments. |
| 1879 | __ mov(kReturnRegister0, Operand(esp, 4 * kPointerSize)); |
| 1880 | __ mov(kReturnRegister1, Operand(esp, 5 * kPointerSize)); |
| 1881 | __ mov(kReturnRegister2, Operand(esp, 6 * kPointerSize)); |
| 1882 | } |
| 1883 | // Result is in eax, edx:eax or edi:edx:eax - do not destroy these registers! |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1884 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1885 | // Check result for exception sentinel. |
| 1886 | Label exception_returned; |
| 1887 | __ cmp(eax, isolate()->factory()->exception()); |
| 1888 | __ j(equal, &exception_returned); |
| 1889 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1890 | // Check that there is no pending exception, otherwise we |
| 1891 | // should have returned the exception sentinel. |
| 1892 | if (FLAG_debug_code) { |
| 1893 | __ push(edx); |
| 1894 | __ mov(edx, Immediate(isolate()->factory()->the_hole_value())); |
| 1895 | Label okay; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1896 | ExternalReference pending_exception_address( |
| 1897 | Isolate::kPendingExceptionAddress, isolate()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1898 | __ cmp(edx, Operand::StaticVariable(pending_exception_address)); |
| 1899 | // Cannot use check here as it attempts to generate call into runtime. |
| 1900 | __ j(equal, &okay, Label::kNear); |
| 1901 | __ int3(); |
| 1902 | __ bind(&okay); |
| 1903 | __ pop(edx); |
| 1904 | } |
| 1905 | |
| 1906 | // Exit the JavaScript to C++ exit frame. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1907 | __ LeaveExitFrame(save_doubles(), !argv_in_register()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1908 | __ ret(0); |
| 1909 | |
| 1910 | // Handling of exception. |
| 1911 | __ bind(&exception_returned); |
| 1912 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1913 | ExternalReference pending_handler_context_address( |
| 1914 | Isolate::kPendingHandlerContextAddress, isolate()); |
| 1915 | ExternalReference pending_handler_code_address( |
| 1916 | Isolate::kPendingHandlerCodeAddress, isolate()); |
| 1917 | ExternalReference pending_handler_offset_address( |
| 1918 | Isolate::kPendingHandlerOffsetAddress, isolate()); |
| 1919 | ExternalReference pending_handler_fp_address( |
| 1920 | Isolate::kPendingHandlerFPAddress, isolate()); |
| 1921 | ExternalReference pending_handler_sp_address( |
| 1922 | Isolate::kPendingHandlerSPAddress, isolate()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1923 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1924 | // Ask the runtime for help to determine the handler. This will set eax to |
| 1925 | // contain the current pending exception, don't clobber it. |
| 1926 | ExternalReference find_handler(Runtime::kUnwindAndFindExceptionHandler, |
| 1927 | isolate()); |
| 1928 | { |
| 1929 | FrameScope scope(masm, StackFrame::MANUAL); |
| 1930 | __ PrepareCallCFunction(3, eax); |
| 1931 | __ mov(Operand(esp, 0 * kPointerSize), Immediate(0)); // argc. |
| 1932 | __ mov(Operand(esp, 1 * kPointerSize), Immediate(0)); // argv. |
| 1933 | __ mov(Operand(esp, 2 * kPointerSize), |
| 1934 | Immediate(ExternalReference::isolate_address(isolate()))); |
| 1935 | __ CallCFunction(find_handler, 3); |
| 1936 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1937 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1938 | // Retrieve the handler context, SP and FP. |
| 1939 | __ mov(esi, Operand::StaticVariable(pending_handler_context_address)); |
| 1940 | __ mov(esp, Operand::StaticVariable(pending_handler_sp_address)); |
| 1941 | __ mov(ebp, Operand::StaticVariable(pending_handler_fp_address)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1942 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1943 | // If the handler is a JS frame, restore the context to the frame. Note that |
| 1944 | // the context will be set to (esi == 0) for non-JS frames. |
| 1945 | Label skip; |
| 1946 | __ test(esi, esi); |
| 1947 | __ j(zero, &skip, Label::kNear); |
| 1948 | __ mov(Operand(ebp, StandardFrameConstants::kContextOffset), esi); |
| 1949 | __ bind(&skip); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1950 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1951 | // Compute the handler entry address and jump to it. |
| 1952 | __ mov(edi, Operand::StaticVariable(pending_handler_code_address)); |
| 1953 | __ mov(edx, Operand::StaticVariable(pending_handler_offset_address)); |
| 1954 | __ lea(edi, FieldOperand(edi, edx, times_1, Code::kHeaderSize)); |
| 1955 | __ jmp(edi); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1956 | } |
| 1957 | |
| 1958 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1959 | void JSEntryStub::Generate(MacroAssembler* masm) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1960 | Label invoke, handler_entry, exit; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1961 | Label not_outermost_js, not_outermost_js_2; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1962 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1963 | ProfileEntryHookStub::MaybeCallEntryHook(masm); |
| 1964 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1965 | // Set up frame. |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1966 | __ push(ebp); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1967 | __ mov(ebp, esp); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1968 | |
| 1969 | // Push marker in two places. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1970 | int marker = type(); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1971 | __ push(Immediate(Smi::FromInt(marker))); // marker |
| 1972 | ExternalReference context_address(Isolate::kContextAddress, isolate()); |
| 1973 | __ push(Operand::StaticVariable(context_address)); // context |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1974 | // Save callee-saved registers (C calling conventions). |
| 1975 | __ push(edi); |
| 1976 | __ push(esi); |
| 1977 | __ push(ebx); |
| 1978 | |
| 1979 | // Save copies of the top frame descriptor on the stack. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1980 | ExternalReference c_entry_fp(Isolate::kCEntryFPAddress, isolate()); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1981 | __ push(Operand::StaticVariable(c_entry_fp)); |
| 1982 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1983 | // If this is the outermost JS call, set js_entry_sp value. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1984 | ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, isolate()); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1985 | __ cmp(Operand::StaticVariable(js_entry_sp), Immediate(0)); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1986 | __ j(not_equal, ¬_outermost_js, Label::kNear); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1987 | __ mov(Operand::StaticVariable(js_entry_sp), ebp); |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 1988 | __ push(Immediate(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1989 | __ jmp(&invoke, Label::kNear); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1990 | __ bind(¬_outermost_js); |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 1991 | __ push(Immediate(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME))); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1992 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1993 | // Jump to a faked try block that does the invoke, with a faked catch |
| 1994 | // block that sets the pending exception. |
| 1995 | __ jmp(&invoke); |
| 1996 | __ bind(&handler_entry); |
| 1997 | handler_offset_ = handler_entry.pos(); |
| 1998 | // Caught exception: Store result (exception) in the pending exception |
| 1999 | // field in the JSEnv and return a failure sentinel. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2000 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2001 | isolate()); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2002 | __ mov(Operand::StaticVariable(pending_exception), eax); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2003 | __ mov(eax, Immediate(isolate()->factory()->exception())); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2004 | __ jmp(&exit); |
| 2005 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2006 | // Invoke: Link this frame into the handler chain. |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2007 | __ bind(&invoke); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2008 | __ PushStackHandler(); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2009 | |
| 2010 | // Clear any pending exceptions. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2011 | __ mov(edx, Immediate(isolate()->factory()->the_hole_value())); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2012 | __ mov(Operand::StaticVariable(pending_exception), edx); |
| 2013 | |
| 2014 | // Fake a receiver (NULL). |
| 2015 | __ push(Immediate(0)); // receiver |
| 2016 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2017 | // Invoke the function by calling through JS entry trampoline builtin and |
| 2018 | // pop the faked function when we return. Notice that we cannot store a |
| 2019 | // reference to the trampoline code directly in this stub, because the |
| 2020 | // builtin stubs may not have been generated yet. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2021 | if (type() == StackFrame::ENTRY_CONSTRUCT) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2022 | ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2023 | isolate()); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2024 | __ mov(edx, Immediate(construct_entry)); |
| 2025 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2026 | ExternalReference entry(Builtins::kJSEntryTrampoline, isolate()); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2027 | __ mov(edx, Immediate(entry)); |
| 2028 | } |
| 2029 | __ mov(edx, Operand(edx, 0)); // deref address |
| 2030 | __ lea(edx, FieldOperand(edx, Code::kHeaderSize)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2031 | __ call(edx); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2032 | |
| 2033 | // Unlink this frame from the handler chain. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2034 | __ PopStackHandler(); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2035 | |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 2036 | __ bind(&exit); |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 2037 | // Check if the current stack frame is marked as the outermost JS frame. |
| 2038 | __ pop(ebx); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2039 | __ cmp(ebx, Immediate(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2040 | __ j(not_equal, ¬_outermost_js_2); |
| 2041 | __ mov(Operand::StaticVariable(js_entry_sp), Immediate(0)); |
| 2042 | __ bind(¬_outermost_js_2); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2043 | |
| 2044 | // Restore the top frame descriptor from the stack. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2045 | __ pop(Operand::StaticVariable(ExternalReference( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2046 | Isolate::kCEntryFPAddress, isolate()))); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2047 | |
| 2048 | // Restore callee-saved registers (C calling conventions). |
| 2049 | __ pop(ebx); |
| 2050 | __ pop(esi); |
| 2051 | __ pop(edi); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2052 | __ add(esp, Immediate(2 * kPointerSize)); // remove markers |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2053 | |
| 2054 | // Restore frame pointer and return. |
| 2055 | __ pop(ebp); |
| 2056 | __ ret(0); |
| 2057 | } |
| 2058 | |
| 2059 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2060 | void InstanceOfStub::Generate(MacroAssembler* masm) { |
| 2061 | Register const object = edx; // Object (lhs). |
| 2062 | Register const function = eax; // Function (rhs). |
| 2063 | Register const object_map = ecx; // Map of {object}. |
| 2064 | Register const function_map = ebx; // Map of {function}. |
| 2065 | Register const function_prototype = function_map; // Prototype of {function}. |
| 2066 | Register const scratch = edi; |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 2067 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2068 | DCHECK(object.is(InstanceOfDescriptor::LeftRegister())); |
| 2069 | DCHECK(function.is(InstanceOfDescriptor::RightRegister())); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2070 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2071 | // Check if {object} is a smi. |
| 2072 | Label object_is_smi; |
| 2073 | __ JumpIfSmi(object, &object_is_smi, Label::kNear); |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 2074 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2075 | // Lookup the {function} and the {object} map in the global instanceof cache. |
| 2076 | // Note: This is safe because we clear the global instanceof cache whenever |
| 2077 | // we change the prototype of any object. |
| 2078 | Label fast_case, slow_case; |
| 2079 | __ mov(object_map, FieldOperand(object, HeapObject::kMapOffset)); |
| 2080 | __ CompareRoot(function, scratch, Heap::kInstanceofCacheFunctionRootIndex); |
| 2081 | __ j(not_equal, &fast_case, Label::kNear); |
| 2082 | __ CompareRoot(object_map, scratch, Heap::kInstanceofCacheMapRootIndex); |
| 2083 | __ j(not_equal, &fast_case, Label::kNear); |
| 2084 | __ LoadRoot(eax, Heap::kInstanceofCacheAnswerRootIndex); |
| 2085 | __ ret(0); |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 2086 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2087 | // If {object} is a smi we can safely return false if {function} is a JS |
| 2088 | // function, otherwise we have to miss to the runtime and throw an exception. |
| 2089 | __ bind(&object_is_smi); |
| 2090 | __ JumpIfSmi(function, &slow_case); |
| 2091 | __ CmpObjectType(function, JS_FUNCTION_TYPE, function_map); |
| 2092 | __ j(not_equal, &slow_case); |
| 2093 | __ LoadRoot(eax, Heap::kFalseValueRootIndex); |
| 2094 | __ ret(0); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2095 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2096 | // Fast-case: The {function} must be a valid JSFunction. |
| 2097 | __ bind(&fast_case); |
| 2098 | __ JumpIfSmi(function, &slow_case); |
| 2099 | __ CmpObjectType(function, JS_FUNCTION_TYPE, function_map); |
| 2100 | __ j(not_equal, &slow_case); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2101 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 2102 | // Go to the runtime if the function is not a constructor. |
| 2103 | __ test_b(FieldOperand(function_map, Map::kBitFieldOffset), |
| 2104 | Immediate(1 << Map::kIsConstructor)); |
| 2105 | __ j(zero, &slow_case); |
| 2106 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2107 | // Ensure that {function} has an instance prototype. |
| 2108 | __ test_b(FieldOperand(function_map, Map::kBitFieldOffset), |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 2109 | Immediate(1 << Map::kHasNonInstancePrototype)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2110 | __ j(not_zero, &slow_case); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2111 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2112 | // Get the "prototype" (or initial map) of the {function}. |
| 2113 | __ mov(function_prototype, |
| 2114 | FieldOperand(function, JSFunction::kPrototypeOrInitialMapOffset)); |
| 2115 | __ AssertNotSmi(function_prototype); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2116 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2117 | // Resolve the prototype if the {function} has an initial map. Afterwards the |
| 2118 | // {function_prototype} will be either the JSReceiver prototype object or the |
| 2119 | // hole value, which means that no instances of the {function} were created so |
| 2120 | // far and hence we should return false. |
| 2121 | Label function_prototype_valid; |
| 2122 | Register const function_prototype_map = scratch; |
| 2123 | __ CmpObjectType(function_prototype, MAP_TYPE, function_prototype_map); |
| 2124 | __ j(not_equal, &function_prototype_valid, Label::kNear); |
| 2125 | __ mov(function_prototype, |
| 2126 | FieldOperand(function_prototype, Map::kPrototypeOffset)); |
| 2127 | __ bind(&function_prototype_valid); |
| 2128 | __ AssertNotSmi(function_prototype); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2129 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2130 | // Update the global instanceof cache with the current {object} map and |
| 2131 | // {function}. The cached answer will be set when it is known below. |
| 2132 | __ StoreRoot(function, scratch, Heap::kInstanceofCacheFunctionRootIndex); |
| 2133 | __ StoreRoot(object_map, scratch, Heap::kInstanceofCacheMapRootIndex); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2134 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2135 | // Loop through the prototype chain looking for the {function} prototype. |
| 2136 | // Assume true, and change to false if not found. |
| 2137 | Label done, loop, fast_runtime_fallback; |
| 2138 | __ mov(eax, isolate()->factory()->true_value()); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2139 | __ bind(&loop); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2140 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2141 | // Check if the object needs to be access checked. |
| 2142 | __ test_b(FieldOperand(object_map, Map::kBitFieldOffset), |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 2143 | Immediate(1 << Map::kIsAccessCheckNeeded)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2144 | __ j(not_zero, &fast_runtime_fallback, Label::kNear); |
| 2145 | // Check if the current object is a Proxy. |
| 2146 | __ CmpInstanceType(object_map, JS_PROXY_TYPE); |
| 2147 | __ j(equal, &fast_runtime_fallback, Label::kNear); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2148 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2149 | __ mov(object, FieldOperand(object_map, Map::kPrototypeOffset)); |
| 2150 | __ cmp(object, function_prototype); |
| 2151 | __ j(equal, &done, Label::kNear); |
| 2152 | __ mov(object_map, FieldOperand(object, HeapObject::kMapOffset)); |
| 2153 | __ cmp(object, isolate()->factory()->null_value()); |
| 2154 | __ j(not_equal, &loop); |
| 2155 | __ mov(eax, isolate()->factory()->false_value()); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2156 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2157 | __ bind(&done); |
| 2158 | __ StoreRoot(eax, scratch, Heap::kInstanceofCacheAnswerRootIndex); |
| 2159 | __ ret(0); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2160 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2161 | // Found Proxy or access check needed: Call the runtime. |
| 2162 | __ bind(&fast_runtime_fallback); |
| 2163 | __ PopReturnAddressTo(scratch); |
| 2164 | __ Push(object); |
| 2165 | __ Push(function_prototype); |
| 2166 | __ PushReturnAddressFrom(scratch); |
| 2167 | // Invalidate the instanceof cache. |
| 2168 | __ Move(eax, Immediate(Smi::FromInt(0))); |
| 2169 | __ StoreRoot(eax, scratch, Heap::kInstanceofCacheFunctionRootIndex); |
| 2170 | __ TailCallRuntime(Runtime::kHasInPrototypeChain); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2171 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2172 | // Slow-case: Call the %InstanceOf runtime function. |
| 2173 | __ bind(&slow_case); |
| 2174 | __ PopReturnAddressTo(scratch); |
| 2175 | __ Push(object); |
| 2176 | __ Push(function); |
| 2177 | __ PushReturnAddressFrom(scratch); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 2178 | __ TailCallRuntime(is_es6_instanceof() ? Runtime::kOrdinaryHasInstance |
| 2179 | : Runtime::kInstanceOf); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2180 | } |
| 2181 | |
| 2182 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2183 | // ------------------------------------------------------------------------- |
| 2184 | // StringCharCodeAtGenerator |
| 2185 | |
| 2186 | void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2187 | // If the receiver is a smi trigger the non-string case. |
| 2188 | STATIC_ASSERT(kSmiTag == 0); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2189 | if (check_mode_ == RECEIVER_IS_UNKNOWN) { |
| 2190 | __ JumpIfSmi(object_, receiver_not_string_); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2191 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2192 | // Fetch the instance type of the receiver into result register. |
| 2193 | __ mov(result_, FieldOperand(object_, HeapObject::kMapOffset)); |
| 2194 | __ movzx_b(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); |
| 2195 | // If the receiver is not a string trigger the non-string case. |
| 2196 | __ test(result_, Immediate(kIsNotStringMask)); |
| 2197 | __ j(not_zero, receiver_not_string_); |
| 2198 | } |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2199 | |
| 2200 | // If the index is non-smi trigger the non-smi case. |
| 2201 | STATIC_ASSERT(kSmiTag == 0); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2202 | __ JumpIfNotSmi(index_, &index_not_smi_); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2203 | __ bind(&got_smi_index_); |
| 2204 | |
| 2205 | // Check for index out of range. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2206 | __ cmp(index_, FieldOperand(object_, String::kLengthOffset)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2207 | __ j(above_equal, index_out_of_range_); |
| 2208 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2209 | __ SmiUntag(index_); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2210 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2211 | Factory* factory = masm->isolate()->factory(); |
| 2212 | StringCharLoadGenerator::Generate( |
| 2213 | masm, factory, object_, index_, result_, &call_runtime_); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2214 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2215 | __ SmiTag(result_); |
| 2216 | __ bind(&exit_); |
| 2217 | } |
| 2218 | |
| 2219 | |
| 2220 | void StringCharCodeAtGenerator::GenerateSlow( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2221 | MacroAssembler* masm, EmbedMode embed_mode, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2222 | const RuntimeCallHelper& call_helper) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2223 | __ Abort(kUnexpectedFallthroughToCharCodeAtSlowCase); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2224 | |
| 2225 | // Index is not a smi. |
| 2226 | __ bind(&index_not_smi_); |
| 2227 | // If index is a heap number, try converting it to an integer. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2228 | __ CheckMap(index_, |
| 2229 | masm->isolate()->factory()->heap_number_map(), |
| 2230 | index_not_number_, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2231 | DONT_DO_SMI_CHECK); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2232 | call_helper.BeforeCall(masm); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2233 | if (embed_mode == PART_OF_IC_HANDLER) { |
| 2234 | __ push(LoadWithVectorDescriptor::VectorRegister()); |
| 2235 | __ push(LoadDescriptor::SlotRegister()); |
| 2236 | } |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2237 | __ push(object_); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2238 | __ push(index_); // Consumed by runtime conversion function. |
| 2239 | if (index_flags_ == STRING_INDEX_IS_NUMBER) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2240 | __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2241 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2242 | DCHECK(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2243 | // NumberToSmi discards numbers that are not exact integers. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2244 | __ CallRuntime(Runtime::kNumberToSmi); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2245 | } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2246 | if (!index_.is(eax)) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2247 | // Save the conversion result before the pop instructions below |
| 2248 | // have a chance to overwrite it. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2249 | __ mov(index_, eax); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2250 | } |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2251 | __ pop(object_); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2252 | if (embed_mode == PART_OF_IC_HANDLER) { |
| 2253 | __ pop(LoadDescriptor::SlotRegister()); |
| 2254 | __ pop(LoadWithVectorDescriptor::VectorRegister()); |
| 2255 | } |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2256 | // Reload the instance type. |
| 2257 | __ mov(result_, FieldOperand(object_, HeapObject::kMapOffset)); |
| 2258 | __ movzx_b(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); |
| 2259 | call_helper.AfterCall(masm); |
| 2260 | // If index is still not a smi, it must be out of range. |
| 2261 | STATIC_ASSERT(kSmiTag == 0); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2262 | __ JumpIfNotSmi(index_, index_out_of_range_); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2263 | // Otherwise, return to the fast path. |
| 2264 | __ jmp(&got_smi_index_); |
| 2265 | |
| 2266 | // Call runtime. We get here when the receiver is a string and the |
| 2267 | // index is a number, but the code of getting the actual character |
| 2268 | // is too complex (e.g., when the string needs to be flattened). |
| 2269 | __ bind(&call_runtime_); |
| 2270 | call_helper.BeforeCall(masm); |
| 2271 | __ push(object_); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2272 | __ SmiTag(index_); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2273 | __ push(index_); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2274 | __ CallRuntime(Runtime::kStringCharCodeAtRT); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2275 | if (!result_.is(eax)) { |
| 2276 | __ mov(result_, eax); |
| 2277 | } |
| 2278 | call_helper.AfterCall(masm); |
| 2279 | __ jmp(&exit_); |
| 2280 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2281 | __ Abort(kUnexpectedFallthroughFromCharCodeAtSlowCase); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2282 | } |
| 2283 | |
| 2284 | |
| 2285 | // ------------------------------------------------------------------------- |
| 2286 | // StringCharFromCodeGenerator |
| 2287 | |
| 2288 | void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) { |
| 2289 | // Fast case of Heap::LookupSingleCharacterStringFromCode. |
| 2290 | STATIC_ASSERT(kSmiTag == 0); |
| 2291 | STATIC_ASSERT(kSmiShiftSize == 0); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2292 | DCHECK(base::bits::IsPowerOfTwo32(String::kMaxOneByteCharCodeU + 1)); |
| 2293 | __ test(code_, Immediate(kSmiTagMask | |
| 2294 | ((~String::kMaxOneByteCharCodeU) << kSmiTagSize))); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2295 | __ j(not_zero, &slow_case_); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2296 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2297 | Factory* factory = masm->isolate()->factory(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2298 | __ Move(result_, Immediate(factory->single_character_string_cache())); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2299 | STATIC_ASSERT(kSmiTag == 0); |
| 2300 | STATIC_ASSERT(kSmiTagSize == 1); |
| 2301 | STATIC_ASSERT(kSmiShiftSize == 0); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2302 | // At this point code register contains smi tagged one byte char code. |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2303 | __ mov(result_, FieldOperand(result_, |
| 2304 | code_, times_half_pointer_size, |
| 2305 | FixedArray::kHeaderSize)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2306 | __ cmp(result_, factory->undefined_value()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2307 | __ j(equal, &slow_case_); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2308 | __ bind(&exit_); |
| 2309 | } |
| 2310 | |
| 2311 | |
| 2312 | void StringCharFromCodeGenerator::GenerateSlow( |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2313 | MacroAssembler* masm, |
| 2314 | const RuntimeCallHelper& call_helper) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2315 | __ Abort(kUnexpectedFallthroughToCharFromCodeSlowCase); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2316 | |
| 2317 | __ bind(&slow_case_); |
| 2318 | call_helper.BeforeCall(masm); |
| 2319 | __ push(code_); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2320 | __ CallRuntime(Runtime::kStringCharFromCode); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2321 | if (!result_.is(eax)) { |
| 2322 | __ mov(result_, eax); |
| 2323 | } |
| 2324 | call_helper.AfterCall(masm); |
| 2325 | __ jmp(&exit_); |
| 2326 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2327 | __ Abort(kUnexpectedFallthroughFromCharFromCodeSlowCase); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2328 | } |
| 2329 | |
| 2330 | |
| 2331 | void StringHelper::GenerateCopyCharacters(MacroAssembler* masm, |
| 2332 | Register dest, |
| 2333 | Register src, |
| 2334 | Register count, |
| 2335 | Register scratch, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2336 | String::Encoding encoding) { |
| 2337 | DCHECK(!scratch.is(dest)); |
| 2338 | DCHECK(!scratch.is(src)); |
| 2339 | DCHECK(!scratch.is(count)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2340 | |
| 2341 | // Nothing to do for zero characters. |
| 2342 | Label done; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2343 | __ test(count, count); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2344 | __ j(zero, &done); |
| 2345 | |
| 2346 | // Make count the number of bytes to copy. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2347 | if (encoding == String::TWO_BYTE_ENCODING) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2348 | __ shl(count, 1); |
| 2349 | } |
| 2350 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2351 | Label loop; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2352 | __ bind(&loop); |
| 2353 | __ mov_b(scratch, Operand(src, 0)); |
| 2354 | __ mov_b(Operand(dest, 0), scratch); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2355 | __ inc(src); |
| 2356 | __ inc(dest); |
| 2357 | __ dec(count); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2358 | __ j(not_zero, &loop); |
| 2359 | |
| 2360 | __ bind(&done); |
| 2361 | } |
| 2362 | |
| 2363 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2364 | void SubStringStub::Generate(MacroAssembler* masm) { |
| 2365 | Label runtime; |
| 2366 | |
| 2367 | // Stack frame on entry. |
| 2368 | // esp[0]: return address |
| 2369 | // esp[4]: to |
| 2370 | // esp[8]: from |
| 2371 | // esp[12]: string |
| 2372 | |
| 2373 | // Make sure first argument is a string. |
| 2374 | __ mov(eax, Operand(esp, 3 * kPointerSize)); |
| 2375 | STATIC_ASSERT(kSmiTag == 0); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2376 | __ JumpIfSmi(eax, &runtime); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2377 | Condition is_string = masm->IsObjectStringType(eax, ebx, ebx); |
| 2378 | __ j(NegateCondition(is_string), &runtime); |
| 2379 | |
| 2380 | // eax: string |
| 2381 | // ebx: instance type |
| 2382 | |
| 2383 | // Calculate length of sub string using the smi values. |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2384 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); // To index. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2385 | __ JumpIfNotSmi(ecx, &runtime); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2386 | __ mov(edx, Operand(esp, 2 * kPointerSize)); // From index. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2387 | __ JumpIfNotSmi(edx, &runtime); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2388 | __ sub(ecx, edx); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2389 | __ cmp(ecx, FieldOperand(eax, String::kLengthOffset)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2390 | Label not_original_string; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2391 | // Shorter than original string's length: an actual substring. |
| 2392 | __ j(below, ¬_original_string, Label::kNear); |
| 2393 | // Longer than original string's length or negative: unsafe arguments. |
| 2394 | __ j(above, &runtime); |
| 2395 | // Return original string. |
| 2396 | Counters* counters = isolate()->counters(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2397 | __ IncrementCounter(counters->sub_string_native(), 1); |
| 2398 | __ ret(3 * kPointerSize); |
| 2399 | __ bind(¬_original_string); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2400 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2401 | Label single_char; |
| 2402 | __ cmp(ecx, Immediate(Smi::FromInt(1))); |
| 2403 | __ j(equal, &single_char); |
| 2404 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 2405 | // eax: string |
| 2406 | // ebx: instance type |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2407 | // ecx: sub string length (smi) |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 2408 | // edx: from index (smi) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2409 | // Deal with different string types: update the index if necessary |
| 2410 | // and put the underlying string into edi. |
| 2411 | Label underlying_unpacked, sliced_string, seq_or_external_string; |
| 2412 | // If the string is not indirect, it can only be sequential or external. |
| 2413 | STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag)); |
| 2414 | STATIC_ASSERT(kIsIndirectStringMask != 0); |
| 2415 | __ test(ebx, Immediate(kIsIndirectStringMask)); |
| 2416 | __ j(zero, &seq_or_external_string, Label::kNear); |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 2417 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2418 | Factory* factory = isolate()->factory(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2419 | __ test(ebx, Immediate(kSlicedNotConsMask)); |
| 2420 | __ j(not_zero, &sliced_string, Label::kNear); |
| 2421 | // Cons string. Check whether it is flat, then fetch first part. |
| 2422 | // Flat cons strings have an empty second part. |
| 2423 | __ cmp(FieldOperand(eax, ConsString::kSecondOffset), |
| 2424 | factory->empty_string()); |
| 2425 | __ j(not_equal, &runtime); |
| 2426 | __ mov(edi, FieldOperand(eax, ConsString::kFirstOffset)); |
| 2427 | // Update instance type. |
| 2428 | __ mov(ebx, FieldOperand(edi, HeapObject::kMapOffset)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2429 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2430 | __ jmp(&underlying_unpacked, Label::kNear); |
| 2431 | |
| 2432 | __ bind(&sliced_string); |
| 2433 | // Sliced string. Fetch parent and adjust start index by offset. |
| 2434 | __ add(edx, FieldOperand(eax, SlicedString::kOffsetOffset)); |
| 2435 | __ mov(edi, FieldOperand(eax, SlicedString::kParentOffset)); |
| 2436 | // Update instance type. |
| 2437 | __ mov(ebx, FieldOperand(edi, HeapObject::kMapOffset)); |
| 2438 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 2439 | __ jmp(&underlying_unpacked, Label::kNear); |
| 2440 | |
| 2441 | __ bind(&seq_or_external_string); |
| 2442 | // Sequential or external string. Just move string to the expected register. |
| 2443 | __ mov(edi, eax); |
| 2444 | |
| 2445 | __ bind(&underlying_unpacked); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2446 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 2447 | if (FLAG_string_slices) { |
| 2448 | Label copy_routine; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2449 | // edi: underlying subject string |
| 2450 | // ebx: instance type of underlying subject string |
| 2451 | // edx: adjusted start index (smi) |
| 2452 | // ecx: length (smi) |
| 2453 | __ cmp(ecx, Immediate(Smi::FromInt(SlicedString::kMinLength))); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 2454 | // Short slice. Copy instead of slicing. |
| 2455 | __ j(less, ©_routine); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 2456 | // Allocate new sliced string. At this point we do not reload the instance |
| 2457 | // type including the string encoding because we simply rely on the info |
| 2458 | // provided by the original string. It does not matter if the original |
| 2459 | // string's encoding is wrong because we always have to recheck encoding of |
| 2460 | // the newly created string's parent anyways due to externalized strings. |
| 2461 | Label two_byte_slice, set_slice_header; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2462 | STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2463 | STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
| 2464 | __ test(ebx, Immediate(kStringEncodingMask)); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 2465 | __ j(zero, &two_byte_slice, Label::kNear); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2466 | __ AllocateOneByteSlicedString(eax, ebx, no_reg, &runtime); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 2467 | __ jmp(&set_slice_header, Label::kNear); |
| 2468 | __ bind(&two_byte_slice); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2469 | __ AllocateTwoByteSlicedString(eax, ebx, no_reg, &runtime); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 2470 | __ bind(&set_slice_header); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 2471 | __ mov(FieldOperand(eax, SlicedString::kLengthOffset), ecx); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 2472 | __ mov(FieldOperand(eax, SlicedString::kHashFieldOffset), |
| 2473 | Immediate(String::kEmptyHashField)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2474 | __ mov(FieldOperand(eax, SlicedString::kParentOffset), edi); |
| 2475 | __ mov(FieldOperand(eax, SlicedString::kOffsetOffset), edx); |
| 2476 | __ IncrementCounter(counters->sub_string_native(), 1); |
| 2477 | __ ret(3 * kPointerSize); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 2478 | |
| 2479 | __ bind(©_routine); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 2480 | } |
| 2481 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2482 | // edi: underlying subject string |
| 2483 | // ebx: instance type of underlying subject string |
| 2484 | // edx: adjusted start index (smi) |
| 2485 | // ecx: length (smi) |
| 2486 | // The subject string can only be external or sequential string of either |
| 2487 | // encoding at this point. |
| 2488 | Label two_byte_sequential, runtime_drop_two, sequential_string; |
| 2489 | STATIC_ASSERT(kExternalStringTag != 0); |
| 2490 | STATIC_ASSERT(kSeqStringTag == 0); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 2491 | __ test_b(ebx, Immediate(kExternalStringTag)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2492 | __ j(zero, &sequential_string); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2493 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2494 | // Handle external string. |
| 2495 | // Rule out short external strings. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2496 | STATIC_ASSERT(kShortExternalStringTag != 0); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 2497 | __ test_b(ebx, Immediate(kShortExternalStringMask)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2498 | __ j(not_zero, &runtime); |
| 2499 | __ mov(edi, FieldOperand(edi, ExternalString::kResourceDataOffset)); |
| 2500 | // Move the pointer so that offset-wise, it looks like a sequential string. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2501 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2502 | __ sub(edi, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 2503 | |
| 2504 | __ bind(&sequential_string); |
| 2505 | // Stash away (adjusted) index and (underlying) string. |
| 2506 | __ push(edx); |
| 2507 | __ push(edi); |
| 2508 | __ SmiUntag(ecx); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2509 | STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 2510 | __ test_b(ebx, Immediate(kStringEncodingMask)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2511 | __ j(zero, &two_byte_sequential); |
| 2512 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2513 | // Sequential one byte string. Allocate the result. |
| 2514 | __ AllocateOneByteString(eax, ecx, ebx, edx, edi, &runtime_drop_two); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2515 | |
| 2516 | // eax: result string |
| 2517 | // ecx: result string length |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2518 | // Locate first character of result. |
| 2519 | __ mov(edi, eax); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2520 | __ add(edi, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2521 | // Load string argument and locate character of sub string start. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2522 | __ pop(edx); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2523 | __ pop(ebx); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2524 | __ SmiUntag(ebx); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2525 | __ lea(edx, FieldOperand(edx, ebx, times_1, SeqOneByteString::kHeaderSize)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2526 | |
| 2527 | // eax: result string |
| 2528 | // ecx: result length |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2529 | // edi: first character of result |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2530 | // edx: character of sub string start |
| 2531 | StringHelper::GenerateCopyCharacters( |
| 2532 | masm, edi, edx, ecx, ebx, String::ONE_BYTE_ENCODING); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2533 | __ IncrementCounter(counters->sub_string_native(), 1); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2534 | __ ret(3 * kPointerSize); |
| 2535 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2536 | __ bind(&two_byte_sequential); |
| 2537 | // Sequential two-byte string. Allocate the result. |
| 2538 | __ AllocateTwoByteString(eax, ecx, ebx, edx, edi, &runtime_drop_two); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2539 | |
| 2540 | // eax: result string |
| 2541 | // ecx: result string length |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2542 | // Locate first character of result. |
| 2543 | __ mov(edi, eax); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2544 | __ add(edi, |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2545 | Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 2546 | // Load string argument and locate character of sub string start. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2547 | __ pop(edx); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2548 | __ pop(ebx); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2549 | // As from is a smi it is 2 times the value which matches the size of a two |
| 2550 | // byte character. |
| 2551 | STATIC_ASSERT(kSmiTag == 0); |
| 2552 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2553 | __ lea(edx, FieldOperand(edx, ebx, times_1, SeqTwoByteString::kHeaderSize)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2554 | |
| 2555 | // eax: result string |
| 2556 | // ecx: result length |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2557 | // edi: first character of result |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2558 | // edx: character of sub string start |
| 2559 | StringHelper::GenerateCopyCharacters( |
| 2560 | masm, edi, edx, ecx, ebx, String::TWO_BYTE_ENCODING); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2561 | __ IncrementCounter(counters->sub_string_native(), 1); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2562 | __ ret(3 * kPointerSize); |
| 2563 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2564 | // Drop pushed values on the stack before tail call. |
| 2565 | __ bind(&runtime_drop_two); |
| 2566 | __ Drop(2); |
| 2567 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2568 | // Just jump to runtime to create the sub string. |
| 2569 | __ bind(&runtime); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2570 | __ TailCallRuntime(Runtime::kSubString); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2571 | |
| 2572 | __ bind(&single_char); |
| 2573 | // eax: string |
| 2574 | // ebx: instance type |
| 2575 | // ecx: sub string length (smi) |
| 2576 | // edx: from index (smi) |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2577 | StringCharAtGenerator generator(eax, edx, ecx, eax, &runtime, &runtime, |
| 2578 | &runtime, STRING_INDEX_IS_NUMBER, |
| 2579 | RECEIVER_IS_STRING); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2580 | generator.GenerateFast(masm); |
| 2581 | __ ret(3 * kPointerSize); |
| 2582 | generator.SkipSlow(masm, &runtime); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2583 | } |
| 2584 | |
| 2585 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2586 | void ToNumberStub::Generate(MacroAssembler* masm) { |
| 2587 | // The ToNumber stub takes one argument in eax. |
| 2588 | Label not_smi; |
| 2589 | __ JumpIfNotSmi(eax, ¬_smi, Label::kNear); |
| 2590 | __ Ret(); |
| 2591 | __ bind(¬_smi); |
| 2592 | |
| 2593 | Label not_heap_number; |
| 2594 | __ CompareMap(eax, masm->isolate()->factory()->heap_number_map()); |
| 2595 | __ j(not_equal, ¬_heap_number, Label::kNear); |
| 2596 | __ Ret(); |
| 2597 | __ bind(¬_heap_number); |
| 2598 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 2599 | NonNumberToNumberStub stub(masm->isolate()); |
| 2600 | __ TailCallStub(&stub); |
| 2601 | } |
| 2602 | |
| 2603 | void NonNumberToNumberStub::Generate(MacroAssembler* masm) { |
| 2604 | // The NonNumberToNumber stub takes one argument in eax. |
| 2605 | __ AssertNotNumber(eax); |
| 2606 | |
| 2607 | Label not_string; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2608 | __ CmpObjectType(eax, FIRST_NONSTRING_TYPE, edi); |
| 2609 | // eax: object |
| 2610 | // edi: object map |
| 2611 | __ j(above_equal, ¬_string, Label::kNear); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 2612 | StringToNumberStub stub(masm->isolate()); |
| 2613 | __ TailCallStub(&stub); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2614 | __ bind(¬_string); |
| 2615 | |
| 2616 | Label not_oddball; |
| 2617 | __ CmpInstanceType(edi, ODDBALL_TYPE); |
| 2618 | __ j(not_equal, ¬_oddball, Label::kNear); |
| 2619 | __ mov(eax, FieldOperand(eax, Oddball::kToNumberOffset)); |
| 2620 | __ Ret(); |
| 2621 | __ bind(¬_oddball); |
| 2622 | |
| 2623 | __ pop(ecx); // Pop return address. |
| 2624 | __ push(eax); // Push argument. |
| 2625 | __ push(ecx); // Push return address. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2626 | __ TailCallRuntime(Runtime::kToNumber); |
| 2627 | } |
| 2628 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 2629 | void StringToNumberStub::Generate(MacroAssembler* masm) { |
| 2630 | // The StringToNumber stub takes one argument in eax. |
| 2631 | __ AssertString(eax); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2632 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 2633 | // Check if string has a cached array index. |
| 2634 | Label runtime; |
| 2635 | __ test(FieldOperand(eax, String::kHashFieldOffset), |
| 2636 | Immediate(String::kContainsCachedArrayIndexMask)); |
| 2637 | __ j(not_zero, &runtime, Label::kNear); |
| 2638 | __ mov(eax, FieldOperand(eax, String::kHashFieldOffset)); |
| 2639 | __ IndexFromHash(eax, eax); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2640 | __ Ret(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2641 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 2642 | __ bind(&runtime); |
| 2643 | __ PopReturnAddressTo(ecx); // Pop return address. |
| 2644 | __ Push(eax); // Push argument. |
| 2645 | __ PushReturnAddressFrom(ecx); // Push return address. |
| 2646 | __ TailCallRuntime(Runtime::kStringToNumber); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2647 | } |
| 2648 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2649 | void ToStringStub::Generate(MacroAssembler* masm) { |
| 2650 | // The ToString stub takes one argument in eax. |
| 2651 | Label is_number; |
| 2652 | __ JumpIfSmi(eax, &is_number, Label::kNear); |
| 2653 | |
| 2654 | Label not_string; |
| 2655 | __ CmpObjectType(eax, FIRST_NONSTRING_TYPE, edi); |
| 2656 | // eax: receiver |
| 2657 | // edi: receiver map |
| 2658 | __ j(above_equal, ¬_string, Label::kNear); |
| 2659 | __ Ret(); |
| 2660 | __ bind(¬_string); |
| 2661 | |
| 2662 | Label not_heap_number; |
| 2663 | __ CompareMap(eax, masm->isolate()->factory()->heap_number_map()); |
| 2664 | __ j(not_equal, ¬_heap_number, Label::kNear); |
| 2665 | __ bind(&is_number); |
| 2666 | NumberToStringStub stub(isolate()); |
| 2667 | __ TailCallStub(&stub); |
| 2668 | __ bind(¬_heap_number); |
| 2669 | |
| 2670 | Label not_oddball; |
| 2671 | __ CmpInstanceType(edi, ODDBALL_TYPE); |
| 2672 | __ j(not_equal, ¬_oddball, Label::kNear); |
| 2673 | __ mov(eax, FieldOperand(eax, Oddball::kToStringOffset)); |
| 2674 | __ Ret(); |
| 2675 | __ bind(¬_oddball); |
| 2676 | |
| 2677 | __ pop(ecx); // Pop return address. |
| 2678 | __ push(eax); // Push argument. |
| 2679 | __ push(ecx); // Push return address. |
| 2680 | __ TailCallRuntime(Runtime::kToString); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2681 | } |
| 2682 | |
| 2683 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2684 | void ToNameStub::Generate(MacroAssembler* masm) { |
| 2685 | // The ToName stub takes one argument in eax. |
| 2686 | Label is_number; |
| 2687 | __ JumpIfSmi(eax, &is_number, Label::kNear); |
| 2688 | |
| 2689 | Label not_name; |
| 2690 | STATIC_ASSERT(FIRST_NAME_TYPE == FIRST_TYPE); |
| 2691 | __ CmpObjectType(eax, LAST_NAME_TYPE, edi); |
| 2692 | // eax: receiver |
| 2693 | // edi: receiver map |
| 2694 | __ j(above, ¬_name, Label::kNear); |
| 2695 | __ Ret(); |
| 2696 | __ bind(¬_name); |
| 2697 | |
| 2698 | Label not_heap_number; |
| 2699 | __ CompareMap(eax, masm->isolate()->factory()->heap_number_map()); |
| 2700 | __ j(not_equal, ¬_heap_number, Label::kNear); |
| 2701 | __ bind(&is_number); |
| 2702 | NumberToStringStub stub(isolate()); |
| 2703 | __ TailCallStub(&stub); |
| 2704 | __ bind(¬_heap_number); |
| 2705 | |
| 2706 | Label not_oddball; |
| 2707 | __ CmpInstanceType(edi, ODDBALL_TYPE); |
| 2708 | __ j(not_equal, ¬_oddball, Label::kNear); |
| 2709 | __ mov(eax, FieldOperand(eax, Oddball::kToStringOffset)); |
| 2710 | __ Ret(); |
| 2711 | __ bind(¬_oddball); |
| 2712 | |
| 2713 | __ pop(ecx); // Pop return address. |
| 2714 | __ push(eax); // Push argument. |
| 2715 | __ push(ecx); // Push return address. |
| 2716 | __ TailCallRuntime(Runtime::kToName); |
| 2717 | } |
| 2718 | |
| 2719 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2720 | void StringHelper::GenerateFlatOneByteStringEquals(MacroAssembler* masm, |
| 2721 | Register left, |
| 2722 | Register right, |
| 2723 | Register scratch1, |
| 2724 | Register scratch2) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2725 | Register length = scratch1; |
| 2726 | |
| 2727 | // Compare lengths. |
| 2728 | Label strings_not_equal, check_zero_length; |
| 2729 | __ mov(length, FieldOperand(left, String::kLengthOffset)); |
| 2730 | __ cmp(length, FieldOperand(right, String::kLengthOffset)); |
| 2731 | __ j(equal, &check_zero_length, Label::kNear); |
| 2732 | __ bind(&strings_not_equal); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2733 | __ Move(eax, Immediate(Smi::FromInt(NOT_EQUAL))); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2734 | __ ret(0); |
| 2735 | |
| 2736 | // Check if the length is zero. |
| 2737 | Label compare_chars; |
| 2738 | __ bind(&check_zero_length); |
| 2739 | STATIC_ASSERT(kSmiTag == 0); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2740 | __ test(length, length); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2741 | __ j(not_zero, &compare_chars, Label::kNear); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2742 | __ Move(eax, Immediate(Smi::FromInt(EQUAL))); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2743 | __ ret(0); |
| 2744 | |
| 2745 | // Compare characters. |
| 2746 | __ bind(&compare_chars); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2747 | GenerateOneByteCharsCompareLoop(masm, left, right, length, scratch2, |
| 2748 | &strings_not_equal, Label::kNear); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2749 | |
| 2750 | // Characters are equal. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2751 | __ Move(eax, Immediate(Smi::FromInt(EQUAL))); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2752 | __ ret(0); |
| 2753 | } |
| 2754 | |
| 2755 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2756 | void StringHelper::GenerateCompareFlatOneByteStrings( |
| 2757 | MacroAssembler* masm, Register left, Register right, Register scratch1, |
| 2758 | Register scratch2, Register scratch3) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2759 | Counters* counters = masm->isolate()->counters(); |
| 2760 | __ IncrementCounter(counters->string_compare_native(), 1); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2761 | |
| 2762 | // Find minimum length. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2763 | Label left_shorter; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2764 | __ mov(scratch1, FieldOperand(left, String::kLengthOffset)); |
| 2765 | __ mov(scratch3, scratch1); |
| 2766 | __ sub(scratch3, FieldOperand(right, String::kLengthOffset)); |
| 2767 | |
| 2768 | Register length_delta = scratch3; |
| 2769 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2770 | __ j(less_equal, &left_shorter, Label::kNear); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2771 | // Right string is shorter. Change scratch1 to be length of right string. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2772 | __ sub(scratch1, length_delta); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2773 | __ bind(&left_shorter); |
| 2774 | |
| 2775 | Register min_length = scratch1; |
| 2776 | |
| 2777 | // If either length is zero, just compare lengths. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2778 | Label compare_lengths; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2779 | __ test(min_length, min_length); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2780 | __ j(zero, &compare_lengths, Label::kNear); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2781 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2782 | // Compare characters. |
| 2783 | Label result_not_equal; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2784 | GenerateOneByteCharsCompareLoop(masm, left, right, min_length, scratch2, |
| 2785 | &result_not_equal, Label::kNear); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2786 | |
| 2787 | // Compare lengths - strings up to min-length are equal. |
| 2788 | __ bind(&compare_lengths); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2789 | __ test(length_delta, length_delta); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2790 | Label length_not_equal; |
| 2791 | __ j(not_zero, &length_not_equal, Label::kNear); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2792 | |
| 2793 | // Result is EQUAL. |
| 2794 | STATIC_ASSERT(EQUAL == 0); |
| 2795 | STATIC_ASSERT(kSmiTag == 0); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2796 | __ Move(eax, Immediate(Smi::FromInt(EQUAL))); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2797 | __ ret(0); |
| 2798 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2799 | Label result_greater; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2800 | Label result_less; |
| 2801 | __ bind(&length_not_equal); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2802 | __ j(greater, &result_greater, Label::kNear); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2803 | __ jmp(&result_less, Label::kNear); |
| 2804 | __ bind(&result_not_equal); |
| 2805 | __ j(above, &result_greater, Label::kNear); |
| 2806 | __ bind(&result_less); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2807 | |
| 2808 | // Result is LESS. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2809 | __ Move(eax, Immediate(Smi::FromInt(LESS))); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2810 | __ ret(0); |
| 2811 | |
| 2812 | // Result is GREATER. |
| 2813 | __ bind(&result_greater); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2814 | __ Move(eax, Immediate(Smi::FromInt(GREATER))); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2815 | __ ret(0); |
| 2816 | } |
| 2817 | |
| 2818 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2819 | void StringHelper::GenerateOneByteCharsCompareLoop( |
| 2820 | MacroAssembler* masm, Register left, Register right, Register length, |
| 2821 | Register scratch, Label* chars_not_equal, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2822 | Label::Distance chars_not_equal_near) { |
| 2823 | // Change index to run from -length to -1 by adding length to string |
| 2824 | // start. This means that loop ends when index reaches zero, which |
| 2825 | // doesn't need an additional compare. |
| 2826 | __ SmiUntag(length); |
| 2827 | __ lea(left, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2828 | FieldOperand(left, length, times_1, SeqOneByteString::kHeaderSize)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2829 | __ lea(right, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2830 | FieldOperand(right, length, times_1, SeqOneByteString::kHeaderSize)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2831 | __ neg(length); |
| 2832 | Register index = length; // index = -length; |
| 2833 | |
| 2834 | // Compare loop. |
| 2835 | Label loop; |
| 2836 | __ bind(&loop); |
| 2837 | __ mov_b(scratch, Operand(left, index, times_1, 0)); |
| 2838 | __ cmpb(scratch, Operand(right, index, times_1, 0)); |
| 2839 | __ j(not_equal, chars_not_equal, chars_not_equal_near); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2840 | __ inc(index); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2841 | __ j(not_zero, &loop); |
| 2842 | } |
| 2843 | |
| 2844 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2845 | void BinaryOpICWithAllocationSiteStub::Generate(MacroAssembler* masm) { |
| 2846 | // ----------- S t a t e ------------- |
| 2847 | // -- edx : left |
| 2848 | // -- eax : right |
| 2849 | // -- esp[0] : return address |
| 2850 | // ----------------------------------- |
| 2851 | |
| 2852 | // Load ecx with the allocation site. We stick an undefined dummy value here |
| 2853 | // and replace it with the real allocation site later when we instantiate this |
| 2854 | // stub in BinaryOpICWithAllocationSiteStub::GetCodeCopyFromTemplate(). |
| 2855 | __ mov(ecx, handle(isolate()->heap()->undefined_value())); |
| 2856 | |
| 2857 | // Make sure that we actually patched the allocation site. |
| 2858 | if (FLAG_debug_code) { |
| 2859 | __ test(ecx, Immediate(kSmiTagMask)); |
| 2860 | __ Assert(not_equal, kExpectedAllocationSite); |
| 2861 | __ cmp(FieldOperand(ecx, HeapObject::kMapOffset), |
| 2862 | isolate()->factory()->allocation_site_map()); |
| 2863 | __ Assert(equal, kExpectedAllocationSite); |
| 2864 | } |
| 2865 | |
| 2866 | // Tail call into the stub that handles binary operations with allocation |
| 2867 | // sites. |
| 2868 | BinaryOpWithAllocationSiteStub stub(isolate(), state()); |
| 2869 | __ TailCallStub(&stub); |
| 2870 | } |
| 2871 | |
| 2872 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2873 | void CompareICStub::GenerateBooleans(MacroAssembler* masm) { |
| 2874 | DCHECK_EQ(CompareICState::BOOLEAN, state()); |
| 2875 | Label miss; |
| 2876 | Label::Distance const miss_distance = |
| 2877 | masm->emit_debug_code() ? Label::kFar : Label::kNear; |
| 2878 | |
| 2879 | __ JumpIfSmi(edx, &miss, miss_distance); |
| 2880 | __ mov(ecx, FieldOperand(edx, HeapObject::kMapOffset)); |
| 2881 | __ JumpIfSmi(eax, &miss, miss_distance); |
| 2882 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 2883 | __ JumpIfNotRoot(ecx, Heap::kBooleanMapRootIndex, &miss, miss_distance); |
| 2884 | __ JumpIfNotRoot(ebx, Heap::kBooleanMapRootIndex, &miss, miss_distance); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2885 | if (!Token::IsEqualityOp(op())) { |
| 2886 | __ mov(eax, FieldOperand(eax, Oddball::kToNumberOffset)); |
| 2887 | __ AssertSmi(eax); |
| 2888 | __ mov(edx, FieldOperand(edx, Oddball::kToNumberOffset)); |
| 2889 | __ AssertSmi(edx); |
| 2890 | __ push(eax); |
| 2891 | __ mov(eax, edx); |
| 2892 | __ pop(edx); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2893 | } |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2894 | __ sub(eax, edx); |
| 2895 | __ Ret(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2896 | |
| 2897 | __ bind(&miss); |
| 2898 | GenerateMiss(masm); |
| 2899 | } |
| 2900 | |
| 2901 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2902 | void CompareICStub::GenerateSmis(MacroAssembler* masm) { |
| 2903 | DCHECK(state() == CompareICState::SMI); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2904 | Label miss; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2905 | __ mov(ecx, edx); |
| 2906 | __ or_(ecx, eax); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2907 | __ JumpIfNotSmi(ecx, &miss, Label::kNear); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2908 | |
| 2909 | if (GetCondition() == equal) { |
| 2910 | // For equality we do not care about the sign of the result. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2911 | __ sub(eax, edx); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2912 | } else { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2913 | Label done; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2914 | __ sub(edx, eax); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2915 | __ j(no_overflow, &done, Label::kNear); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2916 | // Correct sign of result in case of overflow. |
| 2917 | __ not_(edx); |
| 2918 | __ bind(&done); |
| 2919 | __ mov(eax, edx); |
| 2920 | } |
| 2921 | __ ret(0); |
| 2922 | |
| 2923 | __ bind(&miss); |
| 2924 | GenerateMiss(masm); |
| 2925 | } |
| 2926 | |
| 2927 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2928 | void CompareICStub::GenerateNumbers(MacroAssembler* masm) { |
| 2929 | DCHECK(state() == CompareICState::NUMBER); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2930 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2931 | Label generic_stub; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2932 | Label unordered, maybe_undefined1, maybe_undefined2; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2933 | Label miss; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2934 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2935 | if (left() == CompareICState::SMI) { |
| 2936 | __ JumpIfNotSmi(edx, &miss); |
| 2937 | } |
| 2938 | if (right() == CompareICState::SMI) { |
| 2939 | __ JumpIfNotSmi(eax, &miss); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2940 | } |
| 2941 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2942 | // Load left and right operand. |
| 2943 | Label done, left, left_smi, right_smi; |
| 2944 | __ JumpIfSmi(eax, &right_smi, Label::kNear); |
| 2945 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), |
| 2946 | isolate()->factory()->heap_number_map()); |
| 2947 | __ j(not_equal, &maybe_undefined1, Label::kNear); |
| 2948 | __ movsd(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2949 | __ jmp(&left, Label::kNear); |
| 2950 | __ bind(&right_smi); |
| 2951 | __ mov(ecx, eax); // Can't clobber eax because we can still jump away. |
| 2952 | __ SmiUntag(ecx); |
| 2953 | __ Cvtsi2sd(xmm1, ecx); |
| 2954 | |
| 2955 | __ bind(&left); |
| 2956 | __ JumpIfSmi(edx, &left_smi, Label::kNear); |
| 2957 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 2958 | isolate()->factory()->heap_number_map()); |
| 2959 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
| 2960 | __ movsd(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
| 2961 | __ jmp(&done); |
| 2962 | __ bind(&left_smi); |
| 2963 | __ mov(ecx, edx); // Can't clobber edx because we can still jump away. |
| 2964 | __ SmiUntag(ecx); |
| 2965 | __ Cvtsi2sd(xmm0, ecx); |
| 2966 | |
| 2967 | __ bind(&done); |
| 2968 | // Compare operands. |
| 2969 | __ ucomisd(xmm0, xmm1); |
| 2970 | |
| 2971 | // Don't base result on EFLAGS when a NaN is involved. |
| 2972 | __ j(parity_even, &unordered, Label::kNear); |
| 2973 | |
| 2974 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 2975 | // Performing mov, because xor would destroy the flag register. |
| 2976 | __ mov(eax, 0); // equal |
| 2977 | __ mov(ecx, Immediate(Smi::FromInt(1))); |
| 2978 | __ cmov(above, eax, ecx); |
| 2979 | __ mov(ecx, Immediate(Smi::FromInt(-1))); |
| 2980 | __ cmov(below, eax, ecx); |
| 2981 | __ ret(0); |
| 2982 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2983 | __ bind(&unordered); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2984 | __ bind(&generic_stub); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2985 | CompareICStub stub(isolate(), op(), CompareICState::GENERIC, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2986 | CompareICState::GENERIC, CompareICState::GENERIC); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2987 | __ jmp(stub.GetCode(), RelocInfo::CODE_TARGET); |
| 2988 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2989 | __ bind(&maybe_undefined1); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2990 | if (Token::IsOrderedRelationalCompareOp(op())) { |
| 2991 | __ cmp(eax, Immediate(isolate()->factory()->undefined_value())); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2992 | __ j(not_equal, &miss); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2993 | __ JumpIfSmi(edx, &unordered); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2994 | __ CmpObjectType(edx, HEAP_NUMBER_TYPE, ecx); |
| 2995 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
| 2996 | __ jmp(&unordered); |
| 2997 | } |
| 2998 | |
| 2999 | __ bind(&maybe_undefined2); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3000 | if (Token::IsOrderedRelationalCompareOp(op())) { |
| 3001 | __ cmp(edx, Immediate(isolate()->factory()->undefined_value())); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3002 | __ j(equal, &unordered); |
| 3003 | } |
| 3004 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3005 | __ bind(&miss); |
| 3006 | GenerateMiss(masm); |
| 3007 | } |
| 3008 | |
| 3009 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3010 | void CompareICStub::GenerateInternalizedStrings(MacroAssembler* masm) { |
| 3011 | DCHECK(state() == CompareICState::INTERNALIZED_STRING); |
| 3012 | DCHECK(GetCondition() == equal); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3013 | |
| 3014 | // Registers containing left and right operands respectively. |
| 3015 | Register left = edx; |
| 3016 | Register right = eax; |
| 3017 | Register tmp1 = ecx; |
| 3018 | Register tmp2 = ebx; |
| 3019 | |
| 3020 | // Check that both operands are heap objects. |
| 3021 | Label miss; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3022 | __ mov(tmp1, left); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3023 | STATIC_ASSERT(kSmiTag == 0); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3024 | __ and_(tmp1, right); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 3025 | __ JumpIfSmi(tmp1, &miss, Label::kNear); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3026 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3027 | // Check that both operands are internalized strings. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3028 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 3029 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 3030 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 3031 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3032 | STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0); |
| 3033 | __ or_(tmp1, tmp2); |
| 3034 | __ test(tmp1, Immediate(kIsNotStringMask | kIsNotInternalizedMask)); |
| 3035 | __ j(not_zero, &miss, Label::kNear); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3036 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3037 | // Internalized strings are compared by identity. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3038 | Label done; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3039 | __ cmp(left, right); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3040 | // Make sure eax is non-zero. At this point input operands are |
| 3041 | // guaranteed to be non-zero. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3042 | DCHECK(right.is(eax)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3043 | __ j(not_equal, &done, Label::kNear); |
| 3044 | STATIC_ASSERT(EQUAL == 0); |
| 3045 | STATIC_ASSERT(kSmiTag == 0); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3046 | __ Move(eax, Immediate(Smi::FromInt(EQUAL))); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3047 | __ bind(&done); |
| 3048 | __ ret(0); |
| 3049 | |
| 3050 | __ bind(&miss); |
| 3051 | GenerateMiss(masm); |
| 3052 | } |
| 3053 | |
| 3054 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3055 | void CompareICStub::GenerateUniqueNames(MacroAssembler* masm) { |
| 3056 | DCHECK(state() == CompareICState::UNIQUE_NAME); |
| 3057 | DCHECK(GetCondition() == equal); |
| 3058 | |
| 3059 | // Registers containing left and right operands respectively. |
| 3060 | Register left = edx; |
| 3061 | Register right = eax; |
| 3062 | Register tmp1 = ecx; |
| 3063 | Register tmp2 = ebx; |
| 3064 | |
| 3065 | // Check that both operands are heap objects. |
| 3066 | Label miss; |
| 3067 | __ mov(tmp1, left); |
| 3068 | STATIC_ASSERT(kSmiTag == 0); |
| 3069 | __ and_(tmp1, right); |
| 3070 | __ JumpIfSmi(tmp1, &miss, Label::kNear); |
| 3071 | |
| 3072 | // Check that both operands are unique names. This leaves the instance |
| 3073 | // types loaded in tmp1 and tmp2. |
| 3074 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 3075 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 3076 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 3077 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
| 3078 | |
| 3079 | __ JumpIfNotUniqueNameInstanceType(tmp1, &miss, Label::kNear); |
| 3080 | __ JumpIfNotUniqueNameInstanceType(tmp2, &miss, Label::kNear); |
| 3081 | |
| 3082 | // Unique names are compared by identity. |
| 3083 | Label done; |
| 3084 | __ cmp(left, right); |
| 3085 | // Make sure eax is non-zero. At this point input operands are |
| 3086 | // guaranteed to be non-zero. |
| 3087 | DCHECK(right.is(eax)); |
| 3088 | __ j(not_equal, &done, Label::kNear); |
| 3089 | STATIC_ASSERT(EQUAL == 0); |
| 3090 | STATIC_ASSERT(kSmiTag == 0); |
| 3091 | __ Move(eax, Immediate(Smi::FromInt(EQUAL))); |
| 3092 | __ bind(&done); |
| 3093 | __ ret(0); |
| 3094 | |
| 3095 | __ bind(&miss); |
| 3096 | GenerateMiss(masm); |
| 3097 | } |
| 3098 | |
| 3099 | |
| 3100 | void CompareICStub::GenerateStrings(MacroAssembler* masm) { |
| 3101 | DCHECK(state() == CompareICState::STRING); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3102 | Label miss; |
| 3103 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3104 | bool equality = Token::IsEqualityOp(op()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3105 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3106 | // Registers containing left and right operands respectively. |
| 3107 | Register left = edx; |
| 3108 | Register right = eax; |
| 3109 | Register tmp1 = ecx; |
| 3110 | Register tmp2 = ebx; |
| 3111 | Register tmp3 = edi; |
| 3112 | |
| 3113 | // Check that both operands are heap objects. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3114 | __ mov(tmp1, left); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3115 | STATIC_ASSERT(kSmiTag == 0); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3116 | __ and_(tmp1, right); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 3117 | __ JumpIfSmi(tmp1, &miss); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3118 | |
| 3119 | // Check that both operands are strings. This leaves the instance |
| 3120 | // types loaded in tmp1 and tmp2. |
| 3121 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 3122 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 3123 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 3124 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
| 3125 | __ mov(tmp3, tmp1); |
| 3126 | STATIC_ASSERT(kNotStringTag != 0); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3127 | __ or_(tmp3, tmp2); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3128 | __ test(tmp3, Immediate(kIsNotStringMask)); |
| 3129 | __ j(not_zero, &miss); |
| 3130 | |
| 3131 | // Fast check for identical strings. |
| 3132 | Label not_same; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3133 | __ cmp(left, right); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3134 | __ j(not_equal, ¬_same, Label::kNear); |
| 3135 | STATIC_ASSERT(EQUAL == 0); |
| 3136 | STATIC_ASSERT(kSmiTag == 0); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3137 | __ Move(eax, Immediate(Smi::FromInt(EQUAL))); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3138 | __ ret(0); |
| 3139 | |
| 3140 | // Handle not identical strings. |
| 3141 | __ bind(¬_same); |
| 3142 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3143 | // Check that both strings are internalized. If they are, we're done |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3144 | // because we already know they are not identical. But in the case of |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3145 | // non-equality compare, we still need to determine the order. We |
| 3146 | // also know they are both strings. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3147 | if (equality) { |
| 3148 | Label do_compare; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3149 | STATIC_ASSERT(kInternalizedTag == 0); |
| 3150 | __ or_(tmp1, tmp2); |
| 3151 | __ test(tmp1, Immediate(kIsNotInternalizedMask)); |
| 3152 | __ j(not_zero, &do_compare, Label::kNear); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3153 | // Make sure eax is non-zero. At this point input operands are |
| 3154 | // guaranteed to be non-zero. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3155 | DCHECK(right.is(eax)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3156 | __ ret(0); |
| 3157 | __ bind(&do_compare); |
| 3158 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3159 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3160 | // Check that both strings are sequential one-byte. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3161 | Label runtime; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3162 | __ JumpIfNotBothSequentialOneByteStrings(left, right, tmp1, tmp2, &runtime); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3163 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3164 | // Compare flat one byte strings. Returns when done. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3165 | if (equality) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3166 | StringHelper::GenerateFlatOneByteStringEquals(masm, left, right, tmp1, |
| 3167 | tmp2); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3168 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3169 | StringHelper::GenerateCompareFlatOneByteStrings(masm, left, right, tmp1, |
| 3170 | tmp2, tmp3); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3171 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3172 | |
| 3173 | // Handle more complex cases in runtime. |
| 3174 | __ bind(&runtime); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3175 | if (equality) { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 3176 | { |
| 3177 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 3178 | __ Push(left); |
| 3179 | __ Push(right); |
| 3180 | __ CallRuntime(Runtime::kStringEqual); |
| 3181 | } |
| 3182 | __ sub(eax, Immediate(masm->isolate()->factory()->true_value())); |
| 3183 | __ Ret(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3184 | } else { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 3185 | __ pop(tmp1); // Return address. |
| 3186 | __ push(left); |
| 3187 | __ push(right); |
| 3188 | __ push(tmp1); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3189 | __ TailCallRuntime(Runtime::kStringCompare); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3190 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3191 | |
| 3192 | __ bind(&miss); |
| 3193 | GenerateMiss(masm); |
| 3194 | } |
| 3195 | |
| 3196 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3197 | void CompareICStub::GenerateReceivers(MacroAssembler* masm) { |
| 3198 | DCHECK_EQ(CompareICState::RECEIVER, state()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3199 | Label miss; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3200 | __ mov(ecx, edx); |
| 3201 | __ and_(ecx, eax); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 3202 | __ JumpIfSmi(ecx, &miss, Label::kNear); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3203 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3204 | STATIC_ASSERT(LAST_TYPE == LAST_JS_RECEIVER_TYPE); |
| 3205 | __ CmpObjectType(eax, FIRST_JS_RECEIVER_TYPE, ecx); |
| 3206 | __ j(below, &miss, Label::kNear); |
| 3207 | __ CmpObjectType(edx, FIRST_JS_RECEIVER_TYPE, ecx); |
| 3208 | __ j(below, &miss, Label::kNear); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3209 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3210 | DCHECK_EQ(equal, GetCondition()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3211 | __ sub(eax, edx); |
| 3212 | __ ret(0); |
| 3213 | |
| 3214 | __ bind(&miss); |
| 3215 | GenerateMiss(masm); |
| 3216 | } |
| 3217 | |
| 3218 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3219 | void CompareICStub::GenerateKnownReceivers(MacroAssembler* masm) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3220 | Label miss; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3221 | Handle<WeakCell> cell = Map::WeakCellForMap(known_map_); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3222 | __ mov(ecx, edx); |
| 3223 | __ and_(ecx, eax); |
| 3224 | __ JumpIfSmi(ecx, &miss, Label::kNear); |
| 3225 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3226 | __ GetWeakValue(edi, cell); |
| 3227 | __ cmp(edi, FieldOperand(eax, HeapObject::kMapOffset)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3228 | __ j(not_equal, &miss, Label::kNear); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3229 | __ cmp(edi, FieldOperand(edx, HeapObject::kMapOffset)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3230 | __ j(not_equal, &miss, Label::kNear); |
| 3231 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3232 | if (Token::IsEqualityOp(op())) { |
| 3233 | __ sub(eax, edx); |
| 3234 | __ ret(0); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3235 | } else { |
| 3236 | __ PopReturnAddressTo(ecx); |
| 3237 | __ Push(edx); |
| 3238 | __ Push(eax); |
| 3239 | __ Push(Immediate(Smi::FromInt(NegativeComparisonResult(GetCondition())))); |
| 3240 | __ PushReturnAddressFrom(ecx); |
| 3241 | __ TailCallRuntime(Runtime::kCompare); |
| 3242 | } |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 3243 | |
| 3244 | __ bind(&miss); |
| 3245 | GenerateMiss(masm); |
| 3246 | } |
| 3247 | |
| 3248 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3249 | void CompareICStub::GenerateMiss(MacroAssembler* masm) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3250 | { |
| 3251 | // Call the runtime system in a fresh internal frame. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3252 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 3253 | __ push(edx); // Preserve edx and eax. |
| 3254 | __ push(eax); |
| 3255 | __ push(edx); // And also use them as the arguments. |
| 3256 | __ push(eax); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3257 | __ push(Immediate(Smi::FromInt(op()))); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3258 | __ CallRuntime(Runtime::kCompareIC_Miss); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3259 | // Compute the entry point of the rewritten stub. |
| 3260 | __ lea(edi, FieldOperand(eax, Code::kHeaderSize)); |
| 3261 | __ pop(eax); |
| 3262 | __ pop(edx); |
| 3263 | } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3264 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3265 | // Do a tail call to the rewritten stub. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3266 | __ jmp(edi); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3267 | } |
| 3268 | |
| 3269 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3270 | // Helper function used to check that the dictionary doesn't contain |
| 3271 | // the property. This function may return false negatives, so miss_label |
| 3272 | // must always call a backup property check that is complete. |
| 3273 | // This function is safe to call if the receiver has fast properties. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3274 | // Name must be a unique name and receiver must be a heap object. |
| 3275 | void NameDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm, |
| 3276 | Label* miss, |
| 3277 | Label* done, |
| 3278 | Register properties, |
| 3279 | Handle<Name> name, |
| 3280 | Register r0) { |
| 3281 | DCHECK(name->IsUniqueName()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3282 | |
| 3283 | // If names of slots in range from 1 to kProbes - 1 for the hash value are |
| 3284 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 3285 | // undefined value), it guarantees the hash table doesn't contain the |
| 3286 | // property. It's true even if some slots represent deleted properties |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3287 | // (their names are the hole value). |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3288 | for (int i = 0; i < kInlinedProbes; i++) { |
| 3289 | // Compute the masked index: (hash + i + i * i) & mask. |
| 3290 | Register index = r0; |
| 3291 | // Capacity is smi 2^n. |
| 3292 | __ mov(index, FieldOperand(properties, kCapacityOffset)); |
| 3293 | __ dec(index); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3294 | __ and_(index, |
| 3295 | Immediate(Smi::FromInt(name->Hash() + |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3296 | NameDictionary::GetProbeOffset(i)))); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3297 | |
| 3298 | // Scale the index by multiplying by the entry size. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3299 | STATIC_ASSERT(NameDictionary::kEntrySize == 3); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3300 | __ lea(index, Operand(index, index, times_2, 0)); // index *= 3. |
| 3301 | Register entity_name = r0; |
| 3302 | // Having undefined at this place means the name is not contained. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3303 | STATIC_ASSERT(kSmiTagSize == 1); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3304 | __ mov(entity_name, Operand(properties, index, times_half_pointer_size, |
| 3305 | kElementsStartOffset - kHeapObjectTag)); |
| 3306 | __ cmp(entity_name, masm->isolate()->factory()->undefined_value()); |
| 3307 | __ j(equal, done); |
| 3308 | |
| 3309 | // Stop if found the property. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3310 | __ cmp(entity_name, Handle<Name>(name)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3311 | __ j(equal, miss); |
| 3312 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3313 | Label good; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3314 | // Check for the hole and skip. |
| 3315 | __ cmp(entity_name, masm->isolate()->factory()->the_hole_value()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3316 | __ j(equal, &good, Label::kNear); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3317 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3318 | // Check if the entry name is not a unique name. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3319 | __ mov(entity_name, FieldOperand(entity_name, HeapObject::kMapOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3320 | __ JumpIfNotUniqueNameInstanceType( |
| 3321 | FieldOperand(entity_name, Map::kInstanceTypeOffset), miss); |
| 3322 | __ bind(&good); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3323 | } |
| 3324 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3325 | NameDictionaryLookupStub stub(masm->isolate(), properties, r0, r0, |
| 3326 | NEGATIVE_LOOKUP); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3327 | __ push(Immediate(Handle<Object>(name))); |
| 3328 | __ push(Immediate(name->Hash())); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3329 | __ CallStub(&stub); |
| 3330 | __ test(r0, r0); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3331 | __ j(not_zero, miss); |
| 3332 | __ jmp(done); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3333 | } |
| 3334 | |
| 3335 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3336 | // Probe the name dictionary in the |elements| register. Jump to the |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3337 | // |done| label if a property with the given name is found leaving the |
| 3338 | // index into the dictionary in |r0|. Jump to the |miss| label |
| 3339 | // otherwise. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3340 | void NameDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm, |
| 3341 | Label* miss, |
| 3342 | Label* done, |
| 3343 | Register elements, |
| 3344 | Register name, |
| 3345 | Register r0, |
| 3346 | Register r1) { |
| 3347 | DCHECK(!elements.is(r0)); |
| 3348 | DCHECK(!elements.is(r1)); |
| 3349 | DCHECK(!name.is(r0)); |
| 3350 | DCHECK(!name.is(r1)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3351 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3352 | __ AssertName(name); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3353 | |
| 3354 | __ mov(r1, FieldOperand(elements, kCapacityOffset)); |
| 3355 | __ shr(r1, kSmiTagSize); // convert smi to int |
| 3356 | __ dec(r1); |
| 3357 | |
| 3358 | // Generate an unrolled loop that performs a few probes before |
| 3359 | // giving up. Measurements done on Gmail indicate that 2 probes |
| 3360 | // cover ~93% of loads from dictionaries. |
| 3361 | for (int i = 0; i < kInlinedProbes; i++) { |
| 3362 | // Compute the masked index: (hash + i + i * i) & mask. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3363 | __ mov(r0, FieldOperand(name, Name::kHashFieldOffset)); |
| 3364 | __ shr(r0, Name::kHashShift); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3365 | if (i > 0) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3366 | __ add(r0, Immediate(NameDictionary::GetProbeOffset(i))); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3367 | } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3368 | __ and_(r0, r1); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3369 | |
| 3370 | // Scale the index by multiplying by the entry size. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3371 | STATIC_ASSERT(NameDictionary::kEntrySize == 3); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3372 | __ lea(r0, Operand(r0, r0, times_2, 0)); // r0 = r0 * 3 |
| 3373 | |
| 3374 | // Check if the key is identical to the name. |
| 3375 | __ cmp(name, Operand(elements, |
| 3376 | r0, |
| 3377 | times_4, |
| 3378 | kElementsStartOffset - kHeapObjectTag)); |
| 3379 | __ j(equal, done); |
| 3380 | } |
| 3381 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3382 | NameDictionaryLookupStub stub(masm->isolate(), elements, r1, r0, |
| 3383 | POSITIVE_LOOKUP); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3384 | __ push(name); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3385 | __ mov(r0, FieldOperand(name, Name::kHashFieldOffset)); |
| 3386 | __ shr(r0, Name::kHashShift); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3387 | __ push(r0); |
| 3388 | __ CallStub(&stub); |
| 3389 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3390 | __ test(r1, r1); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3391 | __ j(zero, miss); |
| 3392 | __ jmp(done); |
| 3393 | } |
| 3394 | |
| 3395 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3396 | void NameDictionaryLookupStub::Generate(MacroAssembler* masm) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3397 | // This stub overrides SometimesSetsUpAFrame() to return false. That means |
| 3398 | // we cannot call anything that could cause a GC from this stub. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3399 | // Stack frame on entry: |
| 3400 | // esp[0 * kPointerSize]: return address. |
| 3401 | // esp[1 * kPointerSize]: key's hash. |
| 3402 | // esp[2 * kPointerSize]: key. |
| 3403 | // Registers: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3404 | // dictionary_: NameDictionary to probe. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3405 | // result_: used as scratch. |
| 3406 | // index_: will hold an index of entry if lookup is successful. |
| 3407 | // might alias with result_. |
| 3408 | // Returns: |
| 3409 | // result_ is zero if lookup failed, non zero otherwise. |
| 3410 | |
| 3411 | Label in_dictionary, maybe_in_dictionary, not_in_dictionary; |
| 3412 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3413 | Register scratch = result(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3414 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3415 | __ mov(scratch, FieldOperand(dictionary(), kCapacityOffset)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3416 | __ dec(scratch); |
| 3417 | __ SmiUntag(scratch); |
| 3418 | __ push(scratch); |
| 3419 | |
| 3420 | // If names of slots in range from 1 to kProbes - 1 for the hash value are |
| 3421 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 3422 | // undefined value), it guarantees the hash table doesn't contain the |
| 3423 | // property. It's true even if some slots represent deleted properties |
| 3424 | // (their names are the null value). |
| 3425 | for (int i = kInlinedProbes; i < kTotalProbes; i++) { |
| 3426 | // Compute the masked index: (hash + i + i * i) & mask. |
| 3427 | __ mov(scratch, Operand(esp, 2 * kPointerSize)); |
| 3428 | if (i > 0) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3429 | __ add(scratch, Immediate(NameDictionary::GetProbeOffset(i))); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3430 | } |
| 3431 | __ and_(scratch, Operand(esp, 0)); |
| 3432 | |
| 3433 | // Scale the index by multiplying by the entry size. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3434 | STATIC_ASSERT(NameDictionary::kEntrySize == 3); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3435 | __ lea(index(), Operand(scratch, scratch, times_2, 0)); // index *= 3. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3436 | |
| 3437 | // Having undefined at this place means the name is not contained. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3438 | STATIC_ASSERT(kSmiTagSize == 1); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3439 | __ mov(scratch, Operand(dictionary(), index(), times_pointer_size, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3440 | kElementsStartOffset - kHeapObjectTag)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3441 | __ cmp(scratch, isolate()->factory()->undefined_value()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3442 | __ j(equal, ¬_in_dictionary); |
| 3443 | |
| 3444 | // Stop if found the property. |
| 3445 | __ cmp(scratch, Operand(esp, 3 * kPointerSize)); |
| 3446 | __ j(equal, &in_dictionary); |
| 3447 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3448 | if (i != kTotalProbes - 1 && mode() == NEGATIVE_LOOKUP) { |
| 3449 | // If we hit a key that is not a unique name during negative |
| 3450 | // lookup we have to bailout as this key might be equal to the |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3451 | // key we are looking for. |
| 3452 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3453 | // Check if the entry name is not a unique name. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3454 | __ mov(scratch, FieldOperand(scratch, HeapObject::kMapOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3455 | __ JumpIfNotUniqueNameInstanceType( |
| 3456 | FieldOperand(scratch, Map::kInstanceTypeOffset), |
| 3457 | &maybe_in_dictionary); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3458 | } |
| 3459 | } |
| 3460 | |
| 3461 | __ bind(&maybe_in_dictionary); |
| 3462 | // If we are doing negative lookup then probing failure should be |
| 3463 | // treated as a lookup success. For positive lookup probing failure |
| 3464 | // should be treated as lookup failure. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3465 | if (mode() == POSITIVE_LOOKUP) { |
| 3466 | __ mov(result(), Immediate(0)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3467 | __ Drop(1); |
| 3468 | __ ret(2 * kPointerSize); |
| 3469 | } |
| 3470 | |
| 3471 | __ bind(&in_dictionary); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3472 | __ mov(result(), Immediate(1)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3473 | __ Drop(1); |
| 3474 | __ ret(2 * kPointerSize); |
| 3475 | |
| 3476 | __ bind(¬_in_dictionary); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3477 | __ mov(result(), Immediate(0)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3478 | __ Drop(1); |
| 3479 | __ ret(2 * kPointerSize); |
| 3480 | } |
| 3481 | |
| 3482 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3483 | void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime( |
| 3484 | Isolate* isolate) { |
| 3485 | StoreBufferOverflowStub stub(isolate, kDontSaveFPRegs); |
| 3486 | stub.GetCode(); |
| 3487 | StoreBufferOverflowStub stub2(isolate, kSaveFPRegs); |
| 3488 | stub2.GetCode(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3489 | } |
| 3490 | |
| 3491 | |
| 3492 | // Takes the input in 3 registers: address_ value_ and object_. A pointer to |
| 3493 | // the value has just been written into the object, now this stub makes sure |
| 3494 | // we keep the GC informed. The word in the object where the value has been |
| 3495 | // written is in the address register. |
| 3496 | void RecordWriteStub::Generate(MacroAssembler* masm) { |
| 3497 | Label skip_to_incremental_noncompacting; |
| 3498 | Label skip_to_incremental_compacting; |
| 3499 | |
| 3500 | // The first two instructions are generated with labels so as to get the |
| 3501 | // offset fixed up correctly by the bind(Label*) call. We patch it back and |
| 3502 | // forth between a compare instructions (a nop in this position) and the |
| 3503 | // real branch when we start and stop incremental heap marking. |
| 3504 | __ jmp(&skip_to_incremental_noncompacting, Label::kNear); |
| 3505 | __ jmp(&skip_to_incremental_compacting, Label::kFar); |
| 3506 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3507 | if (remembered_set_action() == EMIT_REMEMBERED_SET) { |
| 3508 | __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(), |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3509 | MacroAssembler::kReturnAtEnd); |
| 3510 | } else { |
| 3511 | __ ret(0); |
| 3512 | } |
| 3513 | |
| 3514 | __ bind(&skip_to_incremental_noncompacting); |
| 3515 | GenerateIncremental(masm, INCREMENTAL); |
| 3516 | |
| 3517 | __ bind(&skip_to_incremental_compacting); |
| 3518 | GenerateIncremental(masm, INCREMENTAL_COMPACTION); |
| 3519 | |
| 3520 | // Initial mode of the stub is expected to be STORE_BUFFER_ONLY. |
| 3521 | // Will be checked in IncrementalMarking::ActivateGeneratedStub. |
| 3522 | masm->set_byte_at(0, kTwoByteNopInstruction); |
| 3523 | masm->set_byte_at(2, kFiveByteNopInstruction); |
| 3524 | } |
| 3525 | |
| 3526 | |
| 3527 | void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) { |
| 3528 | regs_.Save(masm); |
| 3529 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3530 | if (remembered_set_action() == EMIT_REMEMBERED_SET) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3531 | Label dont_need_remembered_set; |
| 3532 | |
| 3533 | __ mov(regs_.scratch0(), Operand(regs_.address(), 0)); |
| 3534 | __ JumpIfNotInNewSpace(regs_.scratch0(), // Value. |
| 3535 | regs_.scratch0(), |
| 3536 | &dont_need_remembered_set); |
| 3537 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 3538 | __ JumpIfInNewSpace(regs_.object(), regs_.scratch0(), |
| 3539 | &dont_need_remembered_set); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3540 | |
| 3541 | // First notify the incremental marker if necessary, then update the |
| 3542 | // remembered set. |
| 3543 | CheckNeedsToInformIncrementalMarker( |
| 3544 | masm, |
| 3545 | kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, |
| 3546 | mode); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3547 | InformIncrementalMarker(masm); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3548 | regs_.Restore(masm); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3549 | __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(), |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3550 | MacroAssembler::kReturnAtEnd); |
| 3551 | |
| 3552 | __ bind(&dont_need_remembered_set); |
| 3553 | } |
| 3554 | |
| 3555 | CheckNeedsToInformIncrementalMarker( |
| 3556 | masm, |
| 3557 | kReturnOnNoNeedToInformIncrementalMarker, |
| 3558 | mode); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3559 | InformIncrementalMarker(masm); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3560 | regs_.Restore(masm); |
| 3561 | __ ret(0); |
| 3562 | } |
| 3563 | |
| 3564 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3565 | void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm) { |
| 3566 | regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3567 | int argument_count = 3; |
| 3568 | __ PrepareCallCFunction(argument_count, regs_.scratch0()); |
| 3569 | __ mov(Operand(esp, 0 * kPointerSize), regs_.object()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3570 | __ mov(Operand(esp, 1 * kPointerSize), regs_.address()); // Slot. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3571 | __ mov(Operand(esp, 2 * kPointerSize), |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3572 | Immediate(ExternalReference::isolate_address(isolate()))); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3573 | |
| 3574 | AllowExternalCallThatCantCauseGC scope(masm); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3575 | __ CallCFunction( |
| 3576 | ExternalReference::incremental_marking_record_write_function(isolate()), |
| 3577 | argument_count); |
| 3578 | |
| 3579 | regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3580 | } |
| 3581 | |
| 3582 | |
| 3583 | void RecordWriteStub::CheckNeedsToInformIncrementalMarker( |
| 3584 | MacroAssembler* masm, |
| 3585 | OnNoNeedToInformIncrementalMarker on_no_need, |
| 3586 | Mode mode) { |
| 3587 | Label object_is_black, need_incremental, need_incremental_pop_object; |
| 3588 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3589 | __ mov(regs_.scratch0(), Immediate(~Page::kPageAlignmentMask)); |
| 3590 | __ and_(regs_.scratch0(), regs_.object()); |
| 3591 | __ mov(regs_.scratch1(), |
| 3592 | Operand(regs_.scratch0(), |
| 3593 | MemoryChunk::kWriteBarrierCounterOffset)); |
| 3594 | __ sub(regs_.scratch1(), Immediate(1)); |
| 3595 | __ mov(Operand(regs_.scratch0(), |
| 3596 | MemoryChunk::kWriteBarrierCounterOffset), |
| 3597 | regs_.scratch1()); |
| 3598 | __ j(negative, &need_incremental); |
| 3599 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3600 | // Let's look at the color of the object: If it is not black we don't have |
| 3601 | // to inform the incremental marker. |
| 3602 | __ JumpIfBlack(regs_.object(), |
| 3603 | regs_.scratch0(), |
| 3604 | regs_.scratch1(), |
| 3605 | &object_is_black, |
| 3606 | Label::kNear); |
| 3607 | |
| 3608 | regs_.Restore(masm); |
| 3609 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3610 | __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(), |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3611 | MacroAssembler::kReturnAtEnd); |
| 3612 | } else { |
| 3613 | __ ret(0); |
| 3614 | } |
| 3615 | |
| 3616 | __ bind(&object_is_black); |
| 3617 | |
| 3618 | // Get the value from the slot. |
| 3619 | __ mov(regs_.scratch0(), Operand(regs_.address(), 0)); |
| 3620 | |
| 3621 | if (mode == INCREMENTAL_COMPACTION) { |
| 3622 | Label ensure_not_white; |
| 3623 | |
| 3624 | __ CheckPageFlag(regs_.scratch0(), // Contains value. |
| 3625 | regs_.scratch1(), // Scratch. |
| 3626 | MemoryChunk::kEvacuationCandidateMask, |
| 3627 | zero, |
| 3628 | &ensure_not_white, |
| 3629 | Label::kNear); |
| 3630 | |
| 3631 | __ CheckPageFlag(regs_.object(), |
| 3632 | regs_.scratch1(), // Scratch. |
| 3633 | MemoryChunk::kSkipEvacuationSlotsRecordingMask, |
| 3634 | not_zero, |
| 3635 | &ensure_not_white, |
| 3636 | Label::kNear); |
| 3637 | |
| 3638 | __ jmp(&need_incremental); |
| 3639 | |
| 3640 | __ bind(&ensure_not_white); |
| 3641 | } |
| 3642 | |
| 3643 | // We need an extra register for this, so we push the object register |
| 3644 | // temporarily. |
| 3645 | __ push(regs_.object()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3646 | __ JumpIfWhite(regs_.scratch0(), // The value. |
| 3647 | regs_.scratch1(), // Scratch. |
| 3648 | regs_.object(), // Scratch. |
| 3649 | &need_incremental_pop_object, Label::kNear); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3650 | __ pop(regs_.object()); |
| 3651 | |
| 3652 | regs_.Restore(masm); |
| 3653 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3654 | __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(), |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3655 | MacroAssembler::kReturnAtEnd); |
| 3656 | } else { |
| 3657 | __ ret(0); |
| 3658 | } |
| 3659 | |
| 3660 | __ bind(&need_incremental_pop_object); |
| 3661 | __ pop(regs_.object()); |
| 3662 | |
| 3663 | __ bind(&need_incremental); |
| 3664 | |
| 3665 | // Fall through when we need to inform the incremental marker. |
| 3666 | } |
| 3667 | |
| 3668 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3669 | void StubFailureTrampolineStub::Generate(MacroAssembler* masm) { |
| 3670 | CEntryStub ces(isolate(), 1, kSaveFPRegs); |
| 3671 | __ call(ces.GetCode(), RelocInfo::CODE_TARGET); |
| 3672 | int parameter_count_offset = |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 3673 | StubFailureTrampolineFrameConstants::kArgumentsLengthOffset; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3674 | __ mov(ebx, MemOperand(ebp, parameter_count_offset)); |
| 3675 | masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE); |
| 3676 | __ pop(ecx); |
| 3677 | int additional_offset = |
| 3678 | function_mode() == JS_FUNCTION_STUB_MODE ? kPointerSize : 0; |
| 3679 | __ lea(esp, MemOperand(esp, ebx, times_pointer_size, additional_offset)); |
| 3680 | __ jmp(ecx); // Return to IC Miss stub, continuation still on stack. |
| 3681 | } |
| 3682 | |
| 3683 | |
| 3684 | void LoadICTrampolineStub::Generate(MacroAssembler* masm) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3685 | __ EmitLoadTypeFeedbackVector(LoadWithVectorDescriptor::VectorRegister()); |
| 3686 | LoadICStub stub(isolate(), state()); |
| 3687 | stub.GenerateForTrampoline(masm); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3688 | } |
| 3689 | |
| 3690 | |
| 3691 | void KeyedLoadICTrampolineStub::Generate(MacroAssembler* masm) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3692 | __ EmitLoadTypeFeedbackVector(LoadWithVectorDescriptor::VectorRegister()); |
| 3693 | KeyedLoadICStub stub(isolate(), state()); |
| 3694 | stub.GenerateForTrampoline(masm); |
| 3695 | } |
| 3696 | |
| 3697 | |
| 3698 | static void HandleArrayCases(MacroAssembler* masm, Register receiver, |
| 3699 | Register key, Register vector, Register slot, |
| 3700 | Register feedback, bool is_polymorphic, |
| 3701 | Label* miss) { |
| 3702 | // feedback initially contains the feedback array |
| 3703 | Label next, next_loop, prepare_next; |
| 3704 | Label load_smi_map, compare_map; |
| 3705 | Label start_polymorphic; |
| 3706 | |
| 3707 | __ push(receiver); |
| 3708 | __ push(vector); |
| 3709 | |
| 3710 | Register receiver_map = receiver; |
| 3711 | Register cached_map = vector; |
| 3712 | |
| 3713 | // Receiver might not be a heap object. |
| 3714 | __ JumpIfSmi(receiver, &load_smi_map); |
| 3715 | __ mov(receiver_map, FieldOperand(receiver, 0)); |
| 3716 | __ bind(&compare_map); |
| 3717 | __ mov(cached_map, FieldOperand(feedback, FixedArray::OffsetOfElementAt(0))); |
| 3718 | |
| 3719 | // A named keyed load might have a 2 element array, all other cases can count |
| 3720 | // on an array with at least 2 {map, handler} pairs, so they can go right |
| 3721 | // into polymorphic array handling. |
| 3722 | __ cmp(receiver_map, FieldOperand(cached_map, WeakCell::kValueOffset)); |
| 3723 | __ j(not_equal, is_polymorphic ? &start_polymorphic : &next); |
| 3724 | |
| 3725 | // found, now call handler. |
| 3726 | Register handler = feedback; |
| 3727 | __ mov(handler, FieldOperand(feedback, FixedArray::OffsetOfElementAt(1))); |
| 3728 | __ pop(vector); |
| 3729 | __ pop(receiver); |
| 3730 | __ lea(handler, FieldOperand(handler, Code::kHeaderSize)); |
| 3731 | __ jmp(handler); |
| 3732 | |
| 3733 | if (!is_polymorphic) { |
| 3734 | __ bind(&next); |
| 3735 | __ cmp(FieldOperand(feedback, FixedArray::kLengthOffset), |
| 3736 | Immediate(Smi::FromInt(2))); |
| 3737 | __ j(not_equal, &start_polymorphic); |
| 3738 | __ pop(vector); |
| 3739 | __ pop(receiver); |
| 3740 | __ jmp(miss); |
| 3741 | } |
| 3742 | |
| 3743 | // Polymorphic, we have to loop from 2 to N |
| 3744 | __ bind(&start_polymorphic); |
| 3745 | __ push(key); |
| 3746 | Register counter = key; |
| 3747 | __ mov(counter, Immediate(Smi::FromInt(2))); |
| 3748 | __ bind(&next_loop); |
| 3749 | __ mov(cached_map, FieldOperand(feedback, counter, times_half_pointer_size, |
| 3750 | FixedArray::kHeaderSize)); |
| 3751 | __ cmp(receiver_map, FieldOperand(cached_map, WeakCell::kValueOffset)); |
| 3752 | __ j(not_equal, &prepare_next); |
| 3753 | __ mov(handler, FieldOperand(feedback, counter, times_half_pointer_size, |
| 3754 | FixedArray::kHeaderSize + kPointerSize)); |
| 3755 | __ pop(key); |
| 3756 | __ pop(vector); |
| 3757 | __ pop(receiver); |
| 3758 | __ lea(handler, FieldOperand(handler, Code::kHeaderSize)); |
| 3759 | __ jmp(handler); |
| 3760 | |
| 3761 | __ bind(&prepare_next); |
| 3762 | __ add(counter, Immediate(Smi::FromInt(2))); |
| 3763 | __ cmp(counter, FieldOperand(feedback, FixedArray::kLengthOffset)); |
| 3764 | __ j(less, &next_loop); |
| 3765 | |
| 3766 | // We exhausted our array of map handler pairs. |
| 3767 | __ pop(key); |
| 3768 | __ pop(vector); |
| 3769 | __ pop(receiver); |
| 3770 | __ jmp(miss); |
| 3771 | |
| 3772 | __ bind(&load_smi_map); |
| 3773 | __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex); |
| 3774 | __ jmp(&compare_map); |
| 3775 | } |
| 3776 | |
| 3777 | |
| 3778 | static void HandleMonomorphicCase(MacroAssembler* masm, Register receiver, |
| 3779 | Register key, Register vector, Register slot, |
| 3780 | Register weak_cell, Label* miss) { |
| 3781 | // feedback initially contains the feedback array |
| 3782 | Label compare_smi_map; |
| 3783 | |
| 3784 | // Move the weak map into the weak_cell register. |
| 3785 | Register ic_map = weak_cell; |
| 3786 | __ mov(ic_map, FieldOperand(weak_cell, WeakCell::kValueOffset)); |
| 3787 | |
| 3788 | // Receiver might not be a heap object. |
| 3789 | __ JumpIfSmi(receiver, &compare_smi_map); |
| 3790 | __ cmp(ic_map, FieldOperand(receiver, 0)); |
| 3791 | __ j(not_equal, miss); |
| 3792 | Register handler = weak_cell; |
| 3793 | __ mov(handler, FieldOperand(vector, slot, times_half_pointer_size, |
| 3794 | FixedArray::kHeaderSize + kPointerSize)); |
| 3795 | __ lea(handler, FieldOperand(handler, Code::kHeaderSize)); |
| 3796 | __ jmp(handler); |
| 3797 | |
| 3798 | // In microbenchmarks, it made sense to unroll this code so that the call to |
| 3799 | // the handler is duplicated for a HeapObject receiver and a Smi receiver. |
| 3800 | __ bind(&compare_smi_map); |
| 3801 | __ CompareRoot(ic_map, Heap::kHeapNumberMapRootIndex); |
| 3802 | __ j(not_equal, miss); |
| 3803 | __ mov(handler, FieldOperand(vector, slot, times_half_pointer_size, |
| 3804 | FixedArray::kHeaderSize + kPointerSize)); |
| 3805 | __ lea(handler, FieldOperand(handler, Code::kHeaderSize)); |
| 3806 | __ jmp(handler); |
| 3807 | } |
| 3808 | |
| 3809 | |
| 3810 | void LoadICStub::Generate(MacroAssembler* masm) { GenerateImpl(masm, false); } |
| 3811 | |
| 3812 | |
| 3813 | void LoadICStub::GenerateForTrampoline(MacroAssembler* masm) { |
| 3814 | GenerateImpl(masm, true); |
| 3815 | } |
| 3816 | |
| 3817 | |
| 3818 | void LoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) { |
| 3819 | Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // edx |
| 3820 | Register name = LoadWithVectorDescriptor::NameRegister(); // ecx |
| 3821 | Register vector = LoadWithVectorDescriptor::VectorRegister(); // ebx |
| 3822 | Register slot = LoadWithVectorDescriptor::SlotRegister(); // eax |
| 3823 | Register scratch = edi; |
| 3824 | __ mov(scratch, FieldOperand(vector, slot, times_half_pointer_size, |
| 3825 | FixedArray::kHeaderSize)); |
| 3826 | |
| 3827 | // Is it a weak cell? |
| 3828 | Label try_array; |
| 3829 | Label not_array, smi_key, key_okay, miss; |
| 3830 | __ CompareRoot(FieldOperand(scratch, 0), Heap::kWeakCellMapRootIndex); |
| 3831 | __ j(not_equal, &try_array); |
| 3832 | HandleMonomorphicCase(masm, receiver, name, vector, slot, scratch, &miss); |
| 3833 | |
| 3834 | // Is it a fixed array? |
| 3835 | __ bind(&try_array); |
| 3836 | __ CompareRoot(FieldOperand(scratch, 0), Heap::kFixedArrayMapRootIndex); |
| 3837 | __ j(not_equal, ¬_array); |
| 3838 | HandleArrayCases(masm, receiver, name, vector, slot, scratch, true, &miss); |
| 3839 | |
| 3840 | __ bind(¬_array); |
| 3841 | __ CompareRoot(scratch, Heap::kmegamorphic_symbolRootIndex); |
| 3842 | __ j(not_equal, &miss); |
| 3843 | __ push(slot); |
| 3844 | __ push(vector); |
| 3845 | Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags( |
| 3846 | Code::ComputeHandlerFlags(Code::LOAD_IC)); |
| 3847 | masm->isolate()->stub_cache()->GenerateProbe(masm, Code::LOAD_IC, code_flags, |
| 3848 | receiver, name, vector, scratch); |
| 3849 | __ pop(vector); |
| 3850 | __ pop(slot); |
| 3851 | |
| 3852 | __ bind(&miss); |
| 3853 | LoadIC::GenerateMiss(masm); |
| 3854 | } |
| 3855 | |
| 3856 | |
| 3857 | void KeyedLoadICStub::Generate(MacroAssembler* masm) { |
| 3858 | GenerateImpl(masm, false); |
| 3859 | } |
| 3860 | |
| 3861 | |
| 3862 | void KeyedLoadICStub::GenerateForTrampoline(MacroAssembler* masm) { |
| 3863 | GenerateImpl(masm, true); |
| 3864 | } |
| 3865 | |
| 3866 | |
| 3867 | void KeyedLoadICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) { |
| 3868 | Register receiver = LoadWithVectorDescriptor::ReceiverRegister(); // edx |
| 3869 | Register key = LoadWithVectorDescriptor::NameRegister(); // ecx |
| 3870 | Register vector = LoadWithVectorDescriptor::VectorRegister(); // ebx |
| 3871 | Register slot = LoadWithVectorDescriptor::SlotRegister(); // eax |
| 3872 | Register feedback = edi; |
| 3873 | __ mov(feedback, FieldOperand(vector, slot, times_half_pointer_size, |
| 3874 | FixedArray::kHeaderSize)); |
| 3875 | // Is it a weak cell? |
| 3876 | Label try_array; |
| 3877 | Label not_array, smi_key, key_okay, miss; |
| 3878 | __ CompareRoot(FieldOperand(feedback, 0), Heap::kWeakCellMapRootIndex); |
| 3879 | __ j(not_equal, &try_array); |
| 3880 | HandleMonomorphicCase(masm, receiver, key, vector, slot, feedback, &miss); |
| 3881 | |
| 3882 | __ bind(&try_array); |
| 3883 | // Is it a fixed array? |
| 3884 | __ CompareRoot(FieldOperand(feedback, 0), Heap::kFixedArrayMapRootIndex); |
| 3885 | __ j(not_equal, ¬_array); |
| 3886 | |
| 3887 | // We have a polymorphic element handler. |
| 3888 | Label polymorphic, try_poly_name; |
| 3889 | __ bind(&polymorphic); |
| 3890 | HandleArrayCases(masm, receiver, key, vector, slot, feedback, true, &miss); |
| 3891 | |
| 3892 | __ bind(¬_array); |
| 3893 | // Is it generic? |
| 3894 | __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex); |
| 3895 | __ j(not_equal, &try_poly_name); |
| 3896 | Handle<Code> megamorphic_stub = |
| 3897 | KeyedLoadIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState()); |
| 3898 | __ jmp(megamorphic_stub, RelocInfo::CODE_TARGET); |
| 3899 | |
| 3900 | __ bind(&try_poly_name); |
| 3901 | // We might have a name in feedback, and a fixed array in the next slot. |
| 3902 | __ cmp(key, feedback); |
| 3903 | __ j(not_equal, &miss); |
| 3904 | // If the name comparison succeeded, we know we have a fixed array with |
| 3905 | // at least one map/handler pair. |
| 3906 | __ mov(feedback, FieldOperand(vector, slot, times_half_pointer_size, |
| 3907 | FixedArray::kHeaderSize + kPointerSize)); |
| 3908 | HandleArrayCases(masm, receiver, key, vector, slot, feedback, false, &miss); |
| 3909 | |
| 3910 | __ bind(&miss); |
| 3911 | KeyedLoadIC::GenerateMiss(masm); |
| 3912 | } |
| 3913 | |
| 3914 | |
| 3915 | void VectorStoreICTrampolineStub::Generate(MacroAssembler* masm) { |
| 3916 | __ EmitLoadTypeFeedbackVector(VectorStoreICDescriptor::VectorRegister()); |
| 3917 | VectorStoreICStub stub(isolate(), state()); |
| 3918 | stub.GenerateForTrampoline(masm); |
| 3919 | } |
| 3920 | |
| 3921 | |
| 3922 | void VectorKeyedStoreICTrampolineStub::Generate(MacroAssembler* masm) { |
| 3923 | __ EmitLoadTypeFeedbackVector(VectorStoreICDescriptor::VectorRegister()); |
| 3924 | VectorKeyedStoreICStub stub(isolate(), state()); |
| 3925 | stub.GenerateForTrampoline(masm); |
| 3926 | } |
| 3927 | |
| 3928 | |
| 3929 | void VectorStoreICStub::Generate(MacroAssembler* masm) { |
| 3930 | GenerateImpl(masm, false); |
| 3931 | } |
| 3932 | |
| 3933 | |
| 3934 | void VectorStoreICStub::GenerateForTrampoline(MacroAssembler* masm) { |
| 3935 | GenerateImpl(masm, true); |
| 3936 | } |
| 3937 | |
| 3938 | |
| 3939 | // value is on the stack already. |
| 3940 | static void HandlePolymorphicStoreCase(MacroAssembler* masm, Register receiver, |
| 3941 | Register key, Register vector, |
| 3942 | Register slot, Register feedback, |
| 3943 | bool is_polymorphic, Label* miss) { |
| 3944 | // feedback initially contains the feedback array |
| 3945 | Label next, next_loop, prepare_next; |
| 3946 | Label load_smi_map, compare_map; |
| 3947 | Label start_polymorphic; |
| 3948 | Label pop_and_miss; |
| 3949 | ExternalReference virtual_register = |
| 3950 | ExternalReference::virtual_handler_register(masm->isolate()); |
| 3951 | |
| 3952 | __ push(receiver); |
| 3953 | __ push(vector); |
| 3954 | |
| 3955 | Register receiver_map = receiver; |
| 3956 | Register cached_map = vector; |
| 3957 | |
| 3958 | // Receiver might not be a heap object. |
| 3959 | __ JumpIfSmi(receiver, &load_smi_map); |
| 3960 | __ mov(receiver_map, FieldOperand(receiver, 0)); |
| 3961 | __ bind(&compare_map); |
| 3962 | __ mov(cached_map, FieldOperand(feedback, FixedArray::OffsetOfElementAt(0))); |
| 3963 | |
| 3964 | // A named keyed store might have a 2 element array, all other cases can count |
| 3965 | // on an array with at least 2 {map, handler} pairs, so they can go right |
| 3966 | // into polymorphic array handling. |
| 3967 | __ cmp(receiver_map, FieldOperand(cached_map, WeakCell::kValueOffset)); |
| 3968 | __ j(not_equal, &start_polymorphic); |
| 3969 | |
| 3970 | // found, now call handler. |
| 3971 | Register handler = feedback; |
| 3972 | DCHECK(handler.is(VectorStoreICDescriptor::ValueRegister())); |
| 3973 | __ mov(handler, FieldOperand(feedback, FixedArray::OffsetOfElementAt(1))); |
| 3974 | __ pop(vector); |
| 3975 | __ pop(receiver); |
| 3976 | __ lea(handler, FieldOperand(handler, Code::kHeaderSize)); |
| 3977 | __ mov(Operand::StaticVariable(virtual_register), handler); |
| 3978 | __ pop(handler); // Pop "value". |
| 3979 | __ jmp(Operand::StaticVariable(virtual_register)); |
| 3980 | |
| 3981 | // Polymorphic, we have to loop from 2 to N |
| 3982 | __ bind(&start_polymorphic); |
| 3983 | __ push(key); |
| 3984 | Register counter = key; |
| 3985 | __ mov(counter, Immediate(Smi::FromInt(2))); |
| 3986 | |
| 3987 | if (!is_polymorphic) { |
| 3988 | // If is_polymorphic is false, we may only have a two element array. |
| 3989 | // Check against length now in that case. |
| 3990 | __ cmp(counter, FieldOperand(feedback, FixedArray::kLengthOffset)); |
| 3991 | __ j(greater_equal, &pop_and_miss); |
| 3992 | } |
| 3993 | |
| 3994 | __ bind(&next_loop); |
| 3995 | __ mov(cached_map, FieldOperand(feedback, counter, times_half_pointer_size, |
| 3996 | FixedArray::kHeaderSize)); |
| 3997 | __ cmp(receiver_map, FieldOperand(cached_map, WeakCell::kValueOffset)); |
| 3998 | __ j(not_equal, &prepare_next); |
| 3999 | __ mov(handler, FieldOperand(feedback, counter, times_half_pointer_size, |
| 4000 | FixedArray::kHeaderSize + kPointerSize)); |
| 4001 | __ lea(handler, FieldOperand(handler, Code::kHeaderSize)); |
| 4002 | __ pop(key); |
| 4003 | __ pop(vector); |
| 4004 | __ pop(receiver); |
| 4005 | __ mov(Operand::StaticVariable(virtual_register), handler); |
| 4006 | __ pop(handler); // Pop "value". |
| 4007 | __ jmp(Operand::StaticVariable(virtual_register)); |
| 4008 | |
| 4009 | __ bind(&prepare_next); |
| 4010 | __ add(counter, Immediate(Smi::FromInt(2))); |
| 4011 | __ cmp(counter, FieldOperand(feedback, FixedArray::kLengthOffset)); |
| 4012 | __ j(less, &next_loop); |
| 4013 | |
| 4014 | // We exhausted our array of map handler pairs. |
| 4015 | __ bind(&pop_and_miss); |
| 4016 | __ pop(key); |
| 4017 | __ pop(vector); |
| 4018 | __ pop(receiver); |
| 4019 | __ jmp(miss); |
| 4020 | |
| 4021 | __ bind(&load_smi_map); |
| 4022 | __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex); |
| 4023 | __ jmp(&compare_map); |
| 4024 | } |
| 4025 | |
| 4026 | |
| 4027 | static void HandleMonomorphicStoreCase(MacroAssembler* masm, Register receiver, |
| 4028 | Register key, Register vector, |
| 4029 | Register slot, Register weak_cell, |
| 4030 | Label* miss) { |
| 4031 | // The store ic value is on the stack. |
| 4032 | DCHECK(weak_cell.is(VectorStoreICDescriptor::ValueRegister())); |
| 4033 | ExternalReference virtual_register = |
| 4034 | ExternalReference::virtual_handler_register(masm->isolate()); |
| 4035 | |
| 4036 | // feedback initially contains the feedback array |
| 4037 | Label compare_smi_map; |
| 4038 | |
| 4039 | // Move the weak map into the weak_cell register. |
| 4040 | Register ic_map = weak_cell; |
| 4041 | __ mov(ic_map, FieldOperand(weak_cell, WeakCell::kValueOffset)); |
| 4042 | |
| 4043 | // Receiver might not be a heap object. |
| 4044 | __ JumpIfSmi(receiver, &compare_smi_map); |
| 4045 | __ cmp(ic_map, FieldOperand(receiver, 0)); |
| 4046 | __ j(not_equal, miss); |
| 4047 | __ mov(weak_cell, FieldOperand(vector, slot, times_half_pointer_size, |
| 4048 | FixedArray::kHeaderSize + kPointerSize)); |
| 4049 | __ lea(weak_cell, FieldOperand(weak_cell, Code::kHeaderSize)); |
| 4050 | // Put the store ic value back in it's register. |
| 4051 | __ mov(Operand::StaticVariable(virtual_register), weak_cell); |
| 4052 | __ pop(weak_cell); // Pop "value". |
| 4053 | // jump to the handler. |
| 4054 | __ jmp(Operand::StaticVariable(virtual_register)); |
| 4055 | |
| 4056 | // In microbenchmarks, it made sense to unroll this code so that the call to |
| 4057 | // the handler is duplicated for a HeapObject receiver and a Smi receiver. |
| 4058 | __ bind(&compare_smi_map); |
| 4059 | __ CompareRoot(ic_map, Heap::kHeapNumberMapRootIndex); |
| 4060 | __ j(not_equal, miss); |
| 4061 | __ mov(weak_cell, FieldOperand(vector, slot, times_half_pointer_size, |
| 4062 | FixedArray::kHeaderSize + kPointerSize)); |
| 4063 | __ lea(weak_cell, FieldOperand(weak_cell, Code::kHeaderSize)); |
| 4064 | __ mov(Operand::StaticVariable(virtual_register), weak_cell); |
| 4065 | __ pop(weak_cell); // Pop "value". |
| 4066 | // jump to the handler. |
| 4067 | __ jmp(Operand::StaticVariable(virtual_register)); |
| 4068 | } |
| 4069 | |
| 4070 | |
| 4071 | void VectorStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) { |
| 4072 | Register receiver = VectorStoreICDescriptor::ReceiverRegister(); // edx |
| 4073 | Register key = VectorStoreICDescriptor::NameRegister(); // ecx |
| 4074 | Register value = VectorStoreICDescriptor::ValueRegister(); // eax |
| 4075 | Register vector = VectorStoreICDescriptor::VectorRegister(); // ebx |
| 4076 | Register slot = VectorStoreICDescriptor::SlotRegister(); // edi |
| 4077 | Label miss; |
| 4078 | |
| 4079 | __ push(value); |
| 4080 | |
| 4081 | Register scratch = value; |
| 4082 | __ mov(scratch, FieldOperand(vector, slot, times_half_pointer_size, |
| 4083 | FixedArray::kHeaderSize)); |
| 4084 | |
| 4085 | // Is it a weak cell? |
| 4086 | Label try_array; |
| 4087 | Label not_array, smi_key, key_okay; |
| 4088 | __ CompareRoot(FieldOperand(scratch, 0), Heap::kWeakCellMapRootIndex); |
| 4089 | __ j(not_equal, &try_array); |
| 4090 | HandleMonomorphicStoreCase(masm, receiver, key, vector, slot, scratch, &miss); |
| 4091 | |
| 4092 | // Is it a fixed array? |
| 4093 | __ bind(&try_array); |
| 4094 | __ CompareRoot(FieldOperand(scratch, 0), Heap::kFixedArrayMapRootIndex); |
| 4095 | __ j(not_equal, ¬_array); |
| 4096 | HandlePolymorphicStoreCase(masm, receiver, key, vector, slot, scratch, true, |
| 4097 | &miss); |
| 4098 | |
| 4099 | __ bind(¬_array); |
| 4100 | __ CompareRoot(scratch, Heap::kmegamorphic_symbolRootIndex); |
| 4101 | __ j(not_equal, &miss); |
| 4102 | |
| 4103 | __ pop(value); |
| 4104 | __ push(slot); |
| 4105 | __ push(vector); |
| 4106 | Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags( |
| 4107 | Code::ComputeHandlerFlags(Code::STORE_IC)); |
| 4108 | masm->isolate()->stub_cache()->GenerateProbe(masm, Code::STORE_IC, code_flags, |
| 4109 | receiver, key, slot, no_reg); |
| 4110 | __ pop(vector); |
| 4111 | __ pop(slot); |
| 4112 | Label no_pop_miss; |
| 4113 | __ jmp(&no_pop_miss); |
| 4114 | |
| 4115 | __ bind(&miss); |
| 4116 | __ pop(value); |
| 4117 | __ bind(&no_pop_miss); |
| 4118 | StoreIC::GenerateMiss(masm); |
| 4119 | } |
| 4120 | |
| 4121 | |
| 4122 | void VectorKeyedStoreICStub::Generate(MacroAssembler* masm) { |
| 4123 | GenerateImpl(masm, false); |
| 4124 | } |
| 4125 | |
| 4126 | |
| 4127 | void VectorKeyedStoreICStub::GenerateForTrampoline(MacroAssembler* masm) { |
| 4128 | GenerateImpl(masm, true); |
| 4129 | } |
| 4130 | |
| 4131 | |
| 4132 | static void HandlePolymorphicKeyedStoreCase(MacroAssembler* masm, |
| 4133 | Register receiver, Register key, |
| 4134 | Register vector, Register slot, |
| 4135 | Register feedback, Label* miss) { |
| 4136 | // feedback initially contains the feedback array |
| 4137 | Label next, next_loop, prepare_next; |
| 4138 | Label load_smi_map, compare_map; |
| 4139 | Label transition_call; |
| 4140 | Label pop_and_miss; |
| 4141 | ExternalReference virtual_register = |
| 4142 | ExternalReference::virtual_handler_register(masm->isolate()); |
| 4143 | ExternalReference virtual_slot = |
| 4144 | ExternalReference::virtual_slot_register(masm->isolate()); |
| 4145 | |
| 4146 | __ push(receiver); |
| 4147 | __ push(vector); |
| 4148 | |
| 4149 | Register receiver_map = receiver; |
| 4150 | Register cached_map = vector; |
| 4151 | Register value = StoreDescriptor::ValueRegister(); |
| 4152 | |
| 4153 | // Receiver might not be a heap object. |
| 4154 | __ JumpIfSmi(receiver, &load_smi_map); |
| 4155 | __ mov(receiver_map, FieldOperand(receiver, 0)); |
| 4156 | __ bind(&compare_map); |
| 4157 | |
| 4158 | // Polymorphic, we have to loop from 0 to N - 1 |
| 4159 | __ push(key); |
| 4160 | // Current stack layout: |
| 4161 | // - esp[0] -- key |
| 4162 | // - esp[4] -- vector |
| 4163 | // - esp[8] -- receiver |
| 4164 | // - esp[12] -- value |
| 4165 | // - esp[16] -- return address |
| 4166 | // |
| 4167 | // Required stack layout for handler call: |
| 4168 | // - esp[0] -- return address |
| 4169 | // - receiver, key, value, vector, slot in registers. |
| 4170 | // - handler in virtual register. |
| 4171 | Register counter = key; |
| 4172 | __ mov(counter, Immediate(Smi::FromInt(0))); |
| 4173 | __ bind(&next_loop); |
| 4174 | __ mov(cached_map, FieldOperand(feedback, counter, times_half_pointer_size, |
| 4175 | FixedArray::kHeaderSize)); |
| 4176 | __ cmp(receiver_map, FieldOperand(cached_map, WeakCell::kValueOffset)); |
| 4177 | __ j(not_equal, &prepare_next); |
| 4178 | __ mov(cached_map, FieldOperand(feedback, counter, times_half_pointer_size, |
| 4179 | FixedArray::kHeaderSize + kPointerSize)); |
| 4180 | __ CompareRoot(cached_map, Heap::kUndefinedValueRootIndex); |
| 4181 | __ j(not_equal, &transition_call); |
| 4182 | __ mov(feedback, FieldOperand(feedback, counter, times_half_pointer_size, |
| 4183 | FixedArray::kHeaderSize + 2 * kPointerSize)); |
| 4184 | __ pop(key); |
| 4185 | __ pop(vector); |
| 4186 | __ pop(receiver); |
| 4187 | __ lea(feedback, FieldOperand(feedback, Code::kHeaderSize)); |
| 4188 | __ mov(Operand::StaticVariable(virtual_register), feedback); |
| 4189 | __ pop(value); |
| 4190 | __ jmp(Operand::StaticVariable(virtual_register)); |
| 4191 | |
| 4192 | __ bind(&transition_call); |
| 4193 | // Current stack layout: |
| 4194 | // - esp[0] -- key |
| 4195 | // - esp[4] -- vector |
| 4196 | // - esp[8] -- receiver |
| 4197 | // - esp[12] -- value |
| 4198 | // - esp[16] -- return address |
| 4199 | // |
| 4200 | // Required stack layout for handler call: |
| 4201 | // - esp[0] -- return address |
| 4202 | // - receiver, key, value, map, vector in registers. |
| 4203 | // - handler and slot in virtual registers. |
| 4204 | __ mov(Operand::StaticVariable(virtual_slot), slot); |
| 4205 | __ mov(feedback, FieldOperand(feedback, counter, times_half_pointer_size, |
| 4206 | FixedArray::kHeaderSize + 2 * kPointerSize)); |
| 4207 | __ lea(feedback, FieldOperand(feedback, Code::kHeaderSize)); |
| 4208 | __ mov(Operand::StaticVariable(virtual_register), feedback); |
| 4209 | |
| 4210 | __ mov(cached_map, FieldOperand(cached_map, WeakCell::kValueOffset)); |
| 4211 | // The weak cell may have been cleared. |
| 4212 | __ JumpIfSmi(cached_map, &pop_and_miss); |
| 4213 | DCHECK(!cached_map.is(VectorStoreTransitionDescriptor::MapRegister())); |
| 4214 | __ mov(VectorStoreTransitionDescriptor::MapRegister(), cached_map); |
| 4215 | |
| 4216 | // Pop key into place. |
| 4217 | __ pop(key); |
| 4218 | __ pop(vector); |
| 4219 | __ pop(receiver); |
| 4220 | __ pop(value); |
| 4221 | __ jmp(Operand::StaticVariable(virtual_register)); |
| 4222 | |
| 4223 | __ bind(&prepare_next); |
| 4224 | __ add(counter, Immediate(Smi::FromInt(3))); |
| 4225 | __ cmp(counter, FieldOperand(feedback, FixedArray::kLengthOffset)); |
| 4226 | __ j(less, &next_loop); |
| 4227 | |
| 4228 | // We exhausted our array of map handler pairs. |
| 4229 | __ bind(&pop_and_miss); |
| 4230 | __ pop(key); |
| 4231 | __ pop(vector); |
| 4232 | __ pop(receiver); |
| 4233 | __ jmp(miss); |
| 4234 | |
| 4235 | __ bind(&load_smi_map); |
| 4236 | __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex); |
| 4237 | __ jmp(&compare_map); |
| 4238 | } |
| 4239 | |
| 4240 | |
| 4241 | void VectorKeyedStoreICStub::GenerateImpl(MacroAssembler* masm, bool in_frame) { |
| 4242 | Register receiver = VectorStoreICDescriptor::ReceiverRegister(); // edx |
| 4243 | Register key = VectorStoreICDescriptor::NameRegister(); // ecx |
| 4244 | Register value = VectorStoreICDescriptor::ValueRegister(); // eax |
| 4245 | Register vector = VectorStoreICDescriptor::VectorRegister(); // ebx |
| 4246 | Register slot = VectorStoreICDescriptor::SlotRegister(); // edi |
| 4247 | Label miss; |
| 4248 | |
| 4249 | __ push(value); |
| 4250 | |
| 4251 | Register scratch = value; |
| 4252 | __ mov(scratch, FieldOperand(vector, slot, times_half_pointer_size, |
| 4253 | FixedArray::kHeaderSize)); |
| 4254 | |
| 4255 | // Is it a weak cell? |
| 4256 | Label try_array; |
| 4257 | Label not_array, smi_key, key_okay; |
| 4258 | __ CompareRoot(FieldOperand(scratch, 0), Heap::kWeakCellMapRootIndex); |
| 4259 | __ j(not_equal, &try_array); |
| 4260 | HandleMonomorphicStoreCase(masm, receiver, key, vector, slot, scratch, &miss); |
| 4261 | |
| 4262 | // Is it a fixed array? |
| 4263 | __ bind(&try_array); |
| 4264 | __ CompareRoot(FieldOperand(scratch, 0), Heap::kFixedArrayMapRootIndex); |
| 4265 | __ j(not_equal, ¬_array); |
| 4266 | HandlePolymorphicKeyedStoreCase(masm, receiver, key, vector, slot, scratch, |
| 4267 | &miss); |
| 4268 | |
| 4269 | __ bind(¬_array); |
| 4270 | Label try_poly_name; |
| 4271 | __ CompareRoot(scratch, Heap::kmegamorphic_symbolRootIndex); |
| 4272 | __ j(not_equal, &try_poly_name); |
| 4273 | |
| 4274 | __ pop(value); |
| 4275 | |
| 4276 | Handle<Code> megamorphic_stub = |
| 4277 | KeyedStoreIC::ChooseMegamorphicStub(masm->isolate(), GetExtraICState()); |
| 4278 | __ jmp(megamorphic_stub, RelocInfo::CODE_TARGET); |
| 4279 | |
| 4280 | __ bind(&try_poly_name); |
| 4281 | // We might have a name in feedback, and a fixed array in the next slot. |
| 4282 | __ cmp(key, scratch); |
| 4283 | __ j(not_equal, &miss); |
| 4284 | // If the name comparison succeeded, we know we have a fixed array with |
| 4285 | // at least one map/handler pair. |
| 4286 | __ mov(scratch, FieldOperand(vector, slot, times_half_pointer_size, |
| 4287 | FixedArray::kHeaderSize + kPointerSize)); |
| 4288 | HandlePolymorphicStoreCase(masm, receiver, key, vector, slot, scratch, false, |
| 4289 | &miss); |
| 4290 | |
| 4291 | __ bind(&miss); |
| 4292 | __ pop(value); |
| 4293 | KeyedStoreIC::GenerateMiss(masm); |
| 4294 | } |
| 4295 | |
| 4296 | |
| 4297 | void CallICTrampolineStub::Generate(MacroAssembler* masm) { |
| 4298 | __ EmitLoadTypeFeedbackVector(ebx); |
| 4299 | CallICStub stub(isolate(), state()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4300 | __ jmp(stub.GetCode(), RelocInfo::CODE_TARGET); |
| 4301 | } |
| 4302 | |
| 4303 | |
| 4304 | void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) { |
| 4305 | if (masm->isolate()->function_entry_hook() != NULL) { |
| 4306 | ProfileEntryHookStub stub(masm->isolate()); |
| 4307 | masm->CallStub(&stub); |
| 4308 | } |
| 4309 | } |
| 4310 | |
| 4311 | |
| 4312 | void ProfileEntryHookStub::Generate(MacroAssembler* masm) { |
| 4313 | // Save volatile registers. |
| 4314 | const int kNumSavedRegisters = 3; |
| 4315 | __ push(eax); |
| 4316 | __ push(ecx); |
| 4317 | __ push(edx); |
| 4318 | |
| 4319 | // Calculate and push the original stack pointer. |
| 4320 | __ lea(eax, Operand(esp, (kNumSavedRegisters + 1) * kPointerSize)); |
| 4321 | __ push(eax); |
| 4322 | |
| 4323 | // Retrieve our return address and use it to calculate the calling |
| 4324 | // function's address. |
| 4325 | __ mov(eax, Operand(esp, (kNumSavedRegisters + 1) * kPointerSize)); |
| 4326 | __ sub(eax, Immediate(Assembler::kCallInstructionLength)); |
| 4327 | __ push(eax); |
| 4328 | |
| 4329 | // Call the entry hook. |
| 4330 | DCHECK(isolate()->function_entry_hook() != NULL); |
| 4331 | __ call(FUNCTION_ADDR(isolate()->function_entry_hook()), |
| 4332 | RelocInfo::RUNTIME_ENTRY); |
| 4333 | __ add(esp, Immediate(2 * kPointerSize)); |
| 4334 | |
| 4335 | // Restore ecx. |
| 4336 | __ pop(edx); |
| 4337 | __ pop(ecx); |
| 4338 | __ pop(eax); |
| 4339 | |
| 4340 | __ ret(0); |
| 4341 | } |
| 4342 | |
| 4343 | |
| 4344 | template<class T> |
| 4345 | static void CreateArrayDispatch(MacroAssembler* masm, |
| 4346 | AllocationSiteOverrideMode mode) { |
| 4347 | if (mode == DISABLE_ALLOCATION_SITES) { |
| 4348 | T stub(masm->isolate(), |
| 4349 | GetInitialFastElementsKind(), |
| 4350 | mode); |
| 4351 | __ TailCallStub(&stub); |
| 4352 | } else if (mode == DONT_OVERRIDE) { |
| 4353 | int last_index = GetSequenceIndexFromFastElementsKind( |
| 4354 | TERMINAL_FAST_ELEMENTS_KIND); |
| 4355 | for (int i = 0; i <= last_index; ++i) { |
| 4356 | Label next; |
| 4357 | ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); |
| 4358 | __ cmp(edx, kind); |
| 4359 | __ j(not_equal, &next); |
| 4360 | T stub(masm->isolate(), kind); |
| 4361 | __ TailCallStub(&stub); |
| 4362 | __ bind(&next); |
| 4363 | } |
| 4364 | |
| 4365 | // If we reached this point there is a problem. |
| 4366 | __ Abort(kUnexpectedElementsKindInArrayConstructor); |
| 4367 | } else { |
| 4368 | UNREACHABLE(); |
| 4369 | } |
| 4370 | } |
| 4371 | |
| 4372 | |
| 4373 | static void CreateArrayDispatchOneArgument(MacroAssembler* masm, |
| 4374 | AllocationSiteOverrideMode mode) { |
| 4375 | // ebx - allocation site (if mode != DISABLE_ALLOCATION_SITES) |
| 4376 | // edx - kind (if mode != DISABLE_ALLOCATION_SITES) |
| 4377 | // eax - number of arguments |
| 4378 | // edi - constructor? |
| 4379 | // esp[0] - return address |
| 4380 | // esp[4] - last argument |
| 4381 | Label normal_sequence; |
| 4382 | if (mode == DONT_OVERRIDE) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4383 | STATIC_ASSERT(FAST_SMI_ELEMENTS == 0); |
| 4384 | STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1); |
| 4385 | STATIC_ASSERT(FAST_ELEMENTS == 2); |
| 4386 | STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3); |
| 4387 | STATIC_ASSERT(FAST_DOUBLE_ELEMENTS == 4); |
| 4388 | STATIC_ASSERT(FAST_HOLEY_DOUBLE_ELEMENTS == 5); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4389 | |
| 4390 | // is the low bit set? If so, we are holey and that is good. |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 4391 | __ test_b(edx, Immediate(1)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4392 | __ j(not_zero, &normal_sequence); |
| 4393 | } |
| 4394 | |
| 4395 | // look at the first argument |
| 4396 | __ mov(ecx, Operand(esp, kPointerSize)); |
| 4397 | __ test(ecx, ecx); |
| 4398 | __ j(zero, &normal_sequence); |
| 4399 | |
| 4400 | if (mode == DISABLE_ALLOCATION_SITES) { |
| 4401 | ElementsKind initial = GetInitialFastElementsKind(); |
| 4402 | ElementsKind holey_initial = GetHoleyElementsKind(initial); |
| 4403 | |
| 4404 | ArraySingleArgumentConstructorStub stub_holey(masm->isolate(), |
| 4405 | holey_initial, |
| 4406 | DISABLE_ALLOCATION_SITES); |
| 4407 | __ TailCallStub(&stub_holey); |
| 4408 | |
| 4409 | __ bind(&normal_sequence); |
| 4410 | ArraySingleArgumentConstructorStub stub(masm->isolate(), |
| 4411 | initial, |
| 4412 | DISABLE_ALLOCATION_SITES); |
| 4413 | __ TailCallStub(&stub); |
| 4414 | } else if (mode == DONT_OVERRIDE) { |
| 4415 | // We are going to create a holey array, but our kind is non-holey. |
| 4416 | // Fix kind and retry. |
| 4417 | __ inc(edx); |
| 4418 | |
| 4419 | if (FLAG_debug_code) { |
| 4420 | Handle<Map> allocation_site_map = |
| 4421 | masm->isolate()->factory()->allocation_site_map(); |
| 4422 | __ cmp(FieldOperand(ebx, 0), Immediate(allocation_site_map)); |
| 4423 | __ Assert(equal, kExpectedAllocationSite); |
| 4424 | } |
| 4425 | |
| 4426 | // Save the resulting elements kind in type info. We can't just store r3 |
| 4427 | // in the AllocationSite::transition_info field because elements kind is |
| 4428 | // restricted to a portion of the field...upper bits need to be left alone. |
| 4429 | STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0); |
| 4430 | __ add(FieldOperand(ebx, AllocationSite::kTransitionInfoOffset), |
| 4431 | Immediate(Smi::FromInt(kFastElementsKindPackedToHoley))); |
| 4432 | |
| 4433 | __ bind(&normal_sequence); |
| 4434 | int last_index = GetSequenceIndexFromFastElementsKind( |
| 4435 | TERMINAL_FAST_ELEMENTS_KIND); |
| 4436 | for (int i = 0; i <= last_index; ++i) { |
| 4437 | Label next; |
| 4438 | ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); |
| 4439 | __ cmp(edx, kind); |
| 4440 | __ j(not_equal, &next); |
| 4441 | ArraySingleArgumentConstructorStub stub(masm->isolate(), kind); |
| 4442 | __ TailCallStub(&stub); |
| 4443 | __ bind(&next); |
| 4444 | } |
| 4445 | |
| 4446 | // If we reached this point there is a problem. |
| 4447 | __ Abort(kUnexpectedElementsKindInArrayConstructor); |
| 4448 | } else { |
| 4449 | UNREACHABLE(); |
| 4450 | } |
| 4451 | } |
| 4452 | |
| 4453 | |
| 4454 | template<class T> |
| 4455 | static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) { |
| 4456 | int to_index = GetSequenceIndexFromFastElementsKind( |
| 4457 | TERMINAL_FAST_ELEMENTS_KIND); |
| 4458 | for (int i = 0; i <= to_index; ++i) { |
| 4459 | ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); |
| 4460 | T stub(isolate, kind); |
| 4461 | stub.GetCode(); |
| 4462 | if (AllocationSite::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) { |
| 4463 | T stub1(isolate, kind, DISABLE_ALLOCATION_SITES); |
| 4464 | stub1.GetCode(); |
| 4465 | } |
| 4466 | } |
| 4467 | } |
| 4468 | |
| 4469 | |
| 4470 | void ArrayConstructorStubBase::GenerateStubsAheadOfTime(Isolate* isolate) { |
| 4471 | ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>( |
| 4472 | isolate); |
| 4473 | ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>( |
| 4474 | isolate); |
| 4475 | ArrayConstructorStubAheadOfTimeHelper<ArrayNArgumentsConstructorStub>( |
| 4476 | isolate); |
| 4477 | } |
| 4478 | |
| 4479 | |
| 4480 | void InternalArrayConstructorStubBase::GenerateStubsAheadOfTime( |
| 4481 | Isolate* isolate) { |
| 4482 | ElementsKind kinds[2] = { FAST_ELEMENTS, FAST_HOLEY_ELEMENTS }; |
| 4483 | for (int i = 0; i < 2; i++) { |
| 4484 | // For internal arrays we only need a few things |
| 4485 | InternalArrayNoArgumentConstructorStub stubh1(isolate, kinds[i]); |
| 4486 | stubh1.GetCode(); |
| 4487 | InternalArraySingleArgumentConstructorStub stubh2(isolate, kinds[i]); |
| 4488 | stubh2.GetCode(); |
| 4489 | InternalArrayNArgumentsConstructorStub stubh3(isolate, kinds[i]); |
| 4490 | stubh3.GetCode(); |
| 4491 | } |
| 4492 | } |
| 4493 | |
| 4494 | |
| 4495 | void ArrayConstructorStub::GenerateDispatchToArrayStub( |
| 4496 | MacroAssembler* masm, |
| 4497 | AllocationSiteOverrideMode mode) { |
| 4498 | if (argument_count() == ANY) { |
| 4499 | Label not_zero_case, not_one_case; |
| 4500 | __ test(eax, eax); |
| 4501 | __ j(not_zero, ¬_zero_case); |
| 4502 | CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode); |
| 4503 | |
| 4504 | __ bind(¬_zero_case); |
| 4505 | __ cmp(eax, 1); |
| 4506 | __ j(greater, ¬_one_case); |
| 4507 | CreateArrayDispatchOneArgument(masm, mode); |
| 4508 | |
| 4509 | __ bind(¬_one_case); |
| 4510 | CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode); |
| 4511 | } else if (argument_count() == NONE) { |
| 4512 | CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode); |
| 4513 | } else if (argument_count() == ONE) { |
| 4514 | CreateArrayDispatchOneArgument(masm, mode); |
| 4515 | } else if (argument_count() == MORE_THAN_ONE) { |
| 4516 | CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode); |
| 4517 | } else { |
| 4518 | UNREACHABLE(); |
| 4519 | } |
| 4520 | } |
| 4521 | |
| 4522 | |
| 4523 | void ArrayConstructorStub::Generate(MacroAssembler* masm) { |
| 4524 | // ----------- S t a t e ------------- |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4525 | // -- eax : argc (only if argument_count() is ANY or MORE_THAN_ONE) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4526 | // -- ebx : AllocationSite or undefined |
| 4527 | // -- edi : constructor |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4528 | // -- edx : Original constructor |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4529 | // -- esp[0] : return address |
| 4530 | // -- esp[4] : last argument |
| 4531 | // ----------------------------------- |
| 4532 | if (FLAG_debug_code) { |
| 4533 | // The array construct code is only set for the global and natives |
| 4534 | // builtin Array functions which always have maps. |
| 4535 | |
| 4536 | // Initial map for the builtin Array function should be a map. |
| 4537 | __ mov(ecx, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset)); |
| 4538 | // Will both indicate a NULL and a Smi. |
| 4539 | __ test(ecx, Immediate(kSmiTagMask)); |
| 4540 | __ Assert(not_zero, kUnexpectedInitialMapForArrayFunction); |
| 4541 | __ CmpObjectType(ecx, MAP_TYPE, ecx); |
| 4542 | __ Assert(equal, kUnexpectedInitialMapForArrayFunction); |
| 4543 | |
| 4544 | // We should either have undefined in ebx or a valid AllocationSite |
| 4545 | __ AssertUndefinedOrAllocationSite(ebx); |
| 4546 | } |
| 4547 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4548 | Label subclassing; |
| 4549 | |
| 4550 | // Enter the context of the Array function. |
| 4551 | __ mov(esi, FieldOperand(edi, JSFunction::kContextOffset)); |
| 4552 | |
| 4553 | __ cmp(edx, edi); |
| 4554 | __ j(not_equal, &subclassing); |
| 4555 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4556 | Label no_info; |
| 4557 | // If the feedback vector is the undefined value call an array constructor |
| 4558 | // that doesn't use AllocationSites. |
| 4559 | __ cmp(ebx, isolate()->factory()->undefined_value()); |
| 4560 | __ j(equal, &no_info); |
| 4561 | |
| 4562 | // Only look at the lower 16 bits of the transition info. |
| 4563 | __ mov(edx, FieldOperand(ebx, AllocationSite::kTransitionInfoOffset)); |
| 4564 | __ SmiUntag(edx); |
| 4565 | STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0); |
| 4566 | __ and_(edx, Immediate(AllocationSite::ElementsKindBits::kMask)); |
| 4567 | GenerateDispatchToArrayStub(masm, DONT_OVERRIDE); |
| 4568 | |
| 4569 | __ bind(&no_info); |
| 4570 | GenerateDispatchToArrayStub(masm, DISABLE_ALLOCATION_SITES); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4571 | |
| 4572 | // Subclassing. |
| 4573 | __ bind(&subclassing); |
| 4574 | switch (argument_count()) { |
| 4575 | case ANY: |
| 4576 | case MORE_THAN_ONE: |
| 4577 | __ mov(Operand(esp, eax, times_pointer_size, kPointerSize), edi); |
| 4578 | __ add(eax, Immediate(3)); |
| 4579 | break; |
| 4580 | case NONE: |
| 4581 | __ mov(Operand(esp, 1 * kPointerSize), edi); |
| 4582 | __ mov(eax, Immediate(3)); |
| 4583 | break; |
| 4584 | case ONE: |
| 4585 | __ mov(Operand(esp, 2 * kPointerSize), edi); |
| 4586 | __ mov(eax, Immediate(4)); |
| 4587 | break; |
| 4588 | } |
| 4589 | __ PopReturnAddressTo(ecx); |
| 4590 | __ Push(edx); |
| 4591 | __ Push(ebx); |
| 4592 | __ PushReturnAddressFrom(ecx); |
| 4593 | __ JumpToExternalReference(ExternalReference(Runtime::kNewArray, isolate())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4594 | } |
| 4595 | |
| 4596 | |
| 4597 | void InternalArrayConstructorStub::GenerateCase( |
| 4598 | MacroAssembler* masm, ElementsKind kind) { |
| 4599 | Label not_zero_case, not_one_case; |
| 4600 | Label normal_sequence; |
| 4601 | |
| 4602 | __ test(eax, eax); |
| 4603 | __ j(not_zero, ¬_zero_case); |
| 4604 | InternalArrayNoArgumentConstructorStub stub0(isolate(), kind); |
| 4605 | __ TailCallStub(&stub0); |
| 4606 | |
| 4607 | __ bind(¬_zero_case); |
| 4608 | __ cmp(eax, 1); |
| 4609 | __ j(greater, ¬_one_case); |
| 4610 | |
| 4611 | if (IsFastPackedElementsKind(kind)) { |
| 4612 | // We might need to create a holey array |
| 4613 | // look at the first argument |
| 4614 | __ mov(ecx, Operand(esp, kPointerSize)); |
| 4615 | __ test(ecx, ecx); |
| 4616 | __ j(zero, &normal_sequence); |
| 4617 | |
| 4618 | InternalArraySingleArgumentConstructorStub |
| 4619 | stub1_holey(isolate(), GetHoleyElementsKind(kind)); |
| 4620 | __ TailCallStub(&stub1_holey); |
| 4621 | } |
| 4622 | |
| 4623 | __ bind(&normal_sequence); |
| 4624 | InternalArraySingleArgumentConstructorStub stub1(isolate(), kind); |
| 4625 | __ TailCallStub(&stub1); |
| 4626 | |
| 4627 | __ bind(¬_one_case); |
| 4628 | InternalArrayNArgumentsConstructorStub stubN(isolate(), kind); |
| 4629 | __ TailCallStub(&stubN); |
| 4630 | } |
| 4631 | |
| 4632 | |
| 4633 | void InternalArrayConstructorStub::Generate(MacroAssembler* masm) { |
| 4634 | // ----------- S t a t e ------------- |
| 4635 | // -- eax : argc |
| 4636 | // -- edi : constructor |
| 4637 | // -- esp[0] : return address |
| 4638 | // -- esp[4] : last argument |
| 4639 | // ----------------------------------- |
| 4640 | |
| 4641 | if (FLAG_debug_code) { |
| 4642 | // The array construct code is only set for the global and natives |
| 4643 | // builtin Array functions which always have maps. |
| 4644 | |
| 4645 | // Initial map for the builtin Array function should be a map. |
| 4646 | __ mov(ecx, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset)); |
| 4647 | // Will both indicate a NULL and a Smi. |
| 4648 | __ test(ecx, Immediate(kSmiTagMask)); |
| 4649 | __ Assert(not_zero, kUnexpectedInitialMapForArrayFunction); |
| 4650 | __ CmpObjectType(ecx, MAP_TYPE, ecx); |
| 4651 | __ Assert(equal, kUnexpectedInitialMapForArrayFunction); |
| 4652 | } |
| 4653 | |
| 4654 | // Figure out the right elements kind |
| 4655 | __ mov(ecx, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset)); |
| 4656 | |
| 4657 | // Load the map's "bit field 2" into |result|. We only need the first byte, |
| 4658 | // but the following masking takes care of that anyway. |
| 4659 | __ mov(ecx, FieldOperand(ecx, Map::kBitField2Offset)); |
| 4660 | // Retrieve elements_kind from bit field 2. |
| 4661 | __ DecodeField<Map::ElementsKindBits>(ecx); |
| 4662 | |
| 4663 | if (FLAG_debug_code) { |
| 4664 | Label done; |
| 4665 | __ cmp(ecx, Immediate(FAST_ELEMENTS)); |
| 4666 | __ j(equal, &done); |
| 4667 | __ cmp(ecx, Immediate(FAST_HOLEY_ELEMENTS)); |
| 4668 | __ Assert(equal, |
| 4669 | kInvalidElementsKindForInternalArrayOrInternalPackedArray); |
| 4670 | __ bind(&done); |
| 4671 | } |
| 4672 | |
| 4673 | Label fast_elements_case; |
| 4674 | __ cmp(ecx, Immediate(FAST_ELEMENTS)); |
| 4675 | __ j(equal, &fast_elements_case); |
| 4676 | GenerateCase(masm, FAST_HOLEY_ELEMENTS); |
| 4677 | |
| 4678 | __ bind(&fast_elements_case); |
| 4679 | GenerateCase(masm, FAST_ELEMENTS); |
| 4680 | } |
| 4681 | |
| 4682 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4683 | void FastNewObjectStub::Generate(MacroAssembler* masm) { |
| 4684 | // ----------- S t a t e ------------- |
| 4685 | // -- edi : target |
| 4686 | // -- edx : new target |
| 4687 | // -- esi : context |
| 4688 | // -- esp[0] : return address |
| 4689 | // ----------------------------------- |
| 4690 | __ AssertFunction(edi); |
| 4691 | __ AssertReceiver(edx); |
| 4692 | |
| 4693 | // Verify that the new target is a JSFunction. |
| 4694 | Label new_object; |
| 4695 | __ CmpObjectType(edx, JS_FUNCTION_TYPE, ebx); |
| 4696 | __ j(not_equal, &new_object); |
| 4697 | |
| 4698 | // Load the initial map and verify that it's in fact a map. |
| 4699 | __ mov(ecx, FieldOperand(edx, JSFunction::kPrototypeOrInitialMapOffset)); |
| 4700 | __ JumpIfSmi(ecx, &new_object); |
| 4701 | __ CmpObjectType(ecx, MAP_TYPE, ebx); |
| 4702 | __ j(not_equal, &new_object); |
| 4703 | |
| 4704 | // Fall back to runtime if the target differs from the new target's |
| 4705 | // initial map constructor. |
| 4706 | __ cmp(edi, FieldOperand(ecx, Map::kConstructorOrBackPointerOffset)); |
| 4707 | __ j(not_equal, &new_object); |
| 4708 | |
| 4709 | // Allocate the JSObject on the heap. |
| 4710 | Label allocate, done_allocate; |
| 4711 | __ movzx_b(ebx, FieldOperand(ecx, Map::kInstanceSizeOffset)); |
| 4712 | __ lea(ebx, Operand(ebx, times_pointer_size, 0)); |
| 4713 | __ Allocate(ebx, eax, edi, no_reg, &allocate, NO_ALLOCATION_FLAGS); |
| 4714 | __ bind(&done_allocate); |
| 4715 | |
| 4716 | // Initialize the JSObject fields. |
| 4717 | __ mov(Operand(eax, JSObject::kMapOffset), ecx); |
| 4718 | __ mov(Operand(eax, JSObject::kPropertiesOffset), |
| 4719 | masm->isolate()->factory()->empty_fixed_array()); |
| 4720 | __ mov(Operand(eax, JSObject::kElementsOffset), |
| 4721 | masm->isolate()->factory()->empty_fixed_array()); |
| 4722 | STATIC_ASSERT(JSObject::kHeaderSize == 3 * kPointerSize); |
| 4723 | __ lea(ebx, Operand(eax, JSObject::kHeaderSize)); |
| 4724 | |
| 4725 | // ----------- S t a t e ------------- |
| 4726 | // -- eax : result (untagged) |
| 4727 | // -- ebx : result fields (untagged) |
| 4728 | // -- edi : result end (untagged) |
| 4729 | // -- ecx : initial map |
| 4730 | // -- esi : context |
| 4731 | // -- esp[0] : return address |
| 4732 | // ----------------------------------- |
| 4733 | |
| 4734 | // Perform in-object slack tracking if requested. |
| 4735 | Label slack_tracking; |
| 4736 | STATIC_ASSERT(Map::kNoSlackTracking == 0); |
| 4737 | __ test(FieldOperand(ecx, Map::kBitField3Offset), |
| 4738 | Immediate(Map::ConstructionCounter::kMask)); |
| 4739 | __ j(not_zero, &slack_tracking, Label::kNear); |
| 4740 | { |
| 4741 | // Initialize all in-object fields with undefined. |
| 4742 | __ LoadRoot(edx, Heap::kUndefinedValueRootIndex); |
| 4743 | __ InitializeFieldsWithFiller(ebx, edi, edx); |
| 4744 | |
| 4745 | // Add the object tag to make the JSObject real. |
| 4746 | STATIC_ASSERT(kHeapObjectTag == 1); |
| 4747 | __ inc(eax); |
| 4748 | __ Ret(); |
| 4749 | } |
| 4750 | __ bind(&slack_tracking); |
| 4751 | { |
| 4752 | // Decrease generous allocation count. |
| 4753 | STATIC_ASSERT(Map::ConstructionCounter::kNext == 32); |
| 4754 | __ sub(FieldOperand(ecx, Map::kBitField3Offset), |
| 4755 | Immediate(1 << Map::ConstructionCounter::kShift)); |
| 4756 | |
| 4757 | // Initialize the in-object fields with undefined. |
| 4758 | __ movzx_b(edx, FieldOperand(ecx, Map::kUnusedPropertyFieldsOffset)); |
| 4759 | __ neg(edx); |
| 4760 | __ lea(edx, Operand(edi, edx, times_pointer_size, 0)); |
| 4761 | __ LoadRoot(edi, Heap::kUndefinedValueRootIndex); |
| 4762 | __ InitializeFieldsWithFiller(ebx, edx, edi); |
| 4763 | |
| 4764 | // Initialize the remaining (reserved) fields with one pointer filler map. |
| 4765 | __ movzx_b(edx, FieldOperand(ecx, Map::kUnusedPropertyFieldsOffset)); |
| 4766 | __ lea(edx, Operand(ebx, edx, times_pointer_size, 0)); |
| 4767 | __ LoadRoot(edi, Heap::kOnePointerFillerMapRootIndex); |
| 4768 | __ InitializeFieldsWithFiller(ebx, edx, edi); |
| 4769 | |
| 4770 | // Add the object tag to make the JSObject real. |
| 4771 | STATIC_ASSERT(kHeapObjectTag == 1); |
| 4772 | __ inc(eax); |
| 4773 | |
| 4774 | // Check if we can finalize the instance size. |
| 4775 | Label finalize; |
| 4776 | STATIC_ASSERT(Map::kSlackTrackingCounterEnd == 1); |
| 4777 | __ test(FieldOperand(ecx, Map::kBitField3Offset), |
| 4778 | Immediate(Map::ConstructionCounter::kMask)); |
| 4779 | __ j(zero, &finalize, Label::kNear); |
| 4780 | __ Ret(); |
| 4781 | |
| 4782 | // Finalize the instance size. |
| 4783 | __ bind(&finalize); |
| 4784 | { |
| 4785 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 4786 | __ Push(eax); |
| 4787 | __ Push(ecx); |
| 4788 | __ CallRuntime(Runtime::kFinalizeInstanceSize); |
| 4789 | __ Pop(eax); |
| 4790 | } |
| 4791 | __ Ret(); |
| 4792 | } |
| 4793 | |
| 4794 | // Fall back to %AllocateInNewSpace. |
| 4795 | __ bind(&allocate); |
| 4796 | { |
| 4797 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 4798 | __ SmiTag(ebx); |
| 4799 | __ Push(ecx); |
| 4800 | __ Push(ebx); |
| 4801 | __ CallRuntime(Runtime::kAllocateInNewSpace); |
| 4802 | __ Pop(ecx); |
| 4803 | } |
| 4804 | STATIC_ASSERT(kHeapObjectTag == 1); |
| 4805 | __ dec(eax); |
| 4806 | __ movzx_b(ebx, FieldOperand(ecx, Map::kInstanceSizeOffset)); |
| 4807 | __ lea(edi, Operand(eax, ebx, times_pointer_size, 0)); |
| 4808 | __ jmp(&done_allocate); |
| 4809 | |
| 4810 | // Fall back to %NewObject. |
| 4811 | __ bind(&new_object); |
| 4812 | __ PopReturnAddressTo(ecx); |
| 4813 | __ Push(edi); |
| 4814 | __ Push(edx); |
| 4815 | __ PushReturnAddressFrom(ecx); |
| 4816 | __ TailCallRuntime(Runtime::kNewObject); |
| 4817 | } |
| 4818 | |
| 4819 | |
| 4820 | void FastNewRestParameterStub::Generate(MacroAssembler* masm) { |
| 4821 | // ----------- S t a t e ------------- |
| 4822 | // -- edi : function |
| 4823 | // -- esi : context |
| 4824 | // -- ebp : frame pointer |
| 4825 | // -- esp[0] : return address |
| 4826 | // ----------------------------------- |
| 4827 | __ AssertFunction(edi); |
| 4828 | |
| 4829 | // For Ignition we need to skip all possible handler/stub frames until |
| 4830 | // we reach the JavaScript frame for the function (similar to what the |
| 4831 | // runtime fallback implementation does). So make edx point to that |
| 4832 | // JavaScript frame. |
| 4833 | { |
| 4834 | Label loop, loop_entry; |
| 4835 | __ mov(edx, ebp); |
| 4836 | __ jmp(&loop_entry, Label::kNear); |
| 4837 | __ bind(&loop); |
| 4838 | __ mov(edx, Operand(edx, StandardFrameConstants::kCallerFPOffset)); |
| 4839 | __ bind(&loop_entry); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 4840 | __ cmp(edi, Operand(edx, StandardFrameConstants::kFunctionOffset)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4841 | __ j(not_equal, &loop); |
| 4842 | } |
| 4843 | |
| 4844 | // Check if we have rest parameters (only possible if we have an |
| 4845 | // arguments adaptor frame below the function frame). |
| 4846 | Label no_rest_parameters; |
| 4847 | __ mov(ebx, Operand(edx, StandardFrameConstants::kCallerFPOffset)); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 4848 | __ cmp(Operand(ebx, CommonFrameConstants::kContextOrFrameTypeOffset), |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4849 | Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 4850 | __ j(not_equal, &no_rest_parameters, Label::kNear); |
| 4851 | |
| 4852 | // Check if the arguments adaptor frame contains more arguments than |
| 4853 | // specified by the function's internal formal parameter count. |
| 4854 | Label rest_parameters; |
| 4855 | __ mov(ecx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); |
| 4856 | __ mov(eax, Operand(ebx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 4857 | __ sub(eax, |
| 4858 | FieldOperand(ecx, SharedFunctionInfo::kFormalParameterCountOffset)); |
| 4859 | __ j(greater, &rest_parameters); |
| 4860 | |
| 4861 | // Return an empty rest parameter array. |
| 4862 | __ bind(&no_rest_parameters); |
| 4863 | { |
| 4864 | // ----------- S t a t e ------------- |
| 4865 | // -- esi : context |
| 4866 | // -- esp[0] : return address |
| 4867 | // ----------------------------------- |
| 4868 | |
| 4869 | // Allocate an empty rest parameter array. |
| 4870 | Label allocate, done_allocate; |
| 4871 | __ Allocate(JSArray::kSize, eax, edx, ecx, &allocate, TAG_OBJECT); |
| 4872 | __ bind(&done_allocate); |
| 4873 | |
| 4874 | // Setup the rest parameter array in rax. |
| 4875 | __ LoadGlobalFunction(Context::JS_ARRAY_FAST_ELEMENTS_MAP_INDEX, ecx); |
| 4876 | __ mov(FieldOperand(eax, JSArray::kMapOffset), ecx); |
| 4877 | __ mov(ecx, isolate()->factory()->empty_fixed_array()); |
| 4878 | __ mov(FieldOperand(eax, JSArray::kPropertiesOffset), ecx); |
| 4879 | __ mov(FieldOperand(eax, JSArray::kElementsOffset), ecx); |
| 4880 | __ mov(FieldOperand(eax, JSArray::kLengthOffset), |
| 4881 | Immediate(Smi::FromInt(0))); |
| 4882 | STATIC_ASSERT(JSArray::kSize == 4 * kPointerSize); |
| 4883 | __ Ret(); |
| 4884 | |
| 4885 | // Fall back to %AllocateInNewSpace. |
| 4886 | __ bind(&allocate); |
| 4887 | { |
| 4888 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 4889 | __ Push(Smi::FromInt(JSArray::kSize)); |
| 4890 | __ CallRuntime(Runtime::kAllocateInNewSpace); |
| 4891 | } |
| 4892 | __ jmp(&done_allocate); |
| 4893 | } |
| 4894 | |
| 4895 | __ bind(&rest_parameters); |
| 4896 | { |
| 4897 | // Compute the pointer to the first rest parameter (skippping the receiver). |
| 4898 | __ lea(ebx, |
| 4899 | Operand(ebx, eax, times_half_pointer_size, |
| 4900 | StandardFrameConstants::kCallerSPOffset - 1 * kPointerSize)); |
| 4901 | |
| 4902 | // ----------- S t a t e ------------- |
| 4903 | // -- esi : context |
| 4904 | // -- eax : number of rest parameters (tagged) |
| 4905 | // -- ebx : pointer to first rest parameters |
| 4906 | // -- esp[0] : return address |
| 4907 | // ----------------------------------- |
| 4908 | |
| 4909 | // Allocate space for the rest parameter array plus the backing store. |
| 4910 | Label allocate, done_allocate; |
| 4911 | __ lea(ecx, Operand(eax, times_half_pointer_size, |
| 4912 | JSArray::kSize + FixedArray::kHeaderSize)); |
| 4913 | __ Allocate(ecx, edx, edi, no_reg, &allocate, TAG_OBJECT); |
| 4914 | __ bind(&done_allocate); |
| 4915 | |
| 4916 | // Setup the elements array in edx. |
| 4917 | __ mov(FieldOperand(edx, FixedArray::kMapOffset), |
| 4918 | isolate()->factory()->fixed_array_map()); |
| 4919 | __ mov(FieldOperand(edx, FixedArray::kLengthOffset), eax); |
| 4920 | { |
| 4921 | Label loop, done_loop; |
| 4922 | __ Move(ecx, Smi::FromInt(0)); |
| 4923 | __ bind(&loop); |
| 4924 | __ cmp(ecx, eax); |
| 4925 | __ j(equal, &done_loop, Label::kNear); |
| 4926 | __ mov(edi, Operand(ebx, 0 * kPointerSize)); |
| 4927 | __ mov(FieldOperand(edx, ecx, times_half_pointer_size, |
| 4928 | FixedArray::kHeaderSize), |
| 4929 | edi); |
| 4930 | __ sub(ebx, Immediate(1 * kPointerSize)); |
| 4931 | __ add(ecx, Immediate(Smi::FromInt(1))); |
| 4932 | __ jmp(&loop); |
| 4933 | __ bind(&done_loop); |
| 4934 | } |
| 4935 | |
| 4936 | // Setup the rest parameter array in edi. |
| 4937 | __ lea(edi, |
| 4938 | Operand(edx, eax, times_half_pointer_size, FixedArray::kHeaderSize)); |
| 4939 | __ LoadGlobalFunction(Context::JS_ARRAY_FAST_ELEMENTS_MAP_INDEX, ecx); |
| 4940 | __ mov(FieldOperand(edi, JSArray::kMapOffset), ecx); |
| 4941 | __ mov(FieldOperand(edi, JSArray::kPropertiesOffset), |
| 4942 | isolate()->factory()->empty_fixed_array()); |
| 4943 | __ mov(FieldOperand(edi, JSArray::kElementsOffset), edx); |
| 4944 | __ mov(FieldOperand(edi, JSArray::kLengthOffset), eax); |
| 4945 | STATIC_ASSERT(JSArray::kSize == 4 * kPointerSize); |
| 4946 | __ mov(eax, edi); |
| 4947 | __ Ret(); |
| 4948 | |
| 4949 | // Fall back to %AllocateInNewSpace. |
| 4950 | __ bind(&allocate); |
| 4951 | { |
| 4952 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 4953 | __ SmiTag(ecx); |
| 4954 | __ Push(eax); |
| 4955 | __ Push(ebx); |
| 4956 | __ Push(ecx); |
| 4957 | __ CallRuntime(Runtime::kAllocateInNewSpace); |
| 4958 | __ mov(edx, eax); |
| 4959 | __ Pop(ebx); |
| 4960 | __ Pop(eax); |
| 4961 | } |
| 4962 | __ jmp(&done_allocate); |
| 4963 | } |
| 4964 | } |
| 4965 | |
| 4966 | |
| 4967 | void FastNewSloppyArgumentsStub::Generate(MacroAssembler* masm) { |
| 4968 | // ----------- S t a t e ------------- |
| 4969 | // -- edi : function |
| 4970 | // -- esi : context |
| 4971 | // -- ebp : frame pointer |
| 4972 | // -- esp[0] : return address |
| 4973 | // ----------------------------------- |
| 4974 | __ AssertFunction(edi); |
| 4975 | |
| 4976 | // TODO(bmeurer): Cleanup to match the FastNewStrictArgumentsStub. |
| 4977 | __ mov(ecx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); |
| 4978 | __ mov(ecx, |
| 4979 | FieldOperand(ecx, SharedFunctionInfo::kFormalParameterCountOffset)); |
| 4980 | __ lea(edx, Operand(ebp, ecx, times_half_pointer_size, |
| 4981 | StandardFrameConstants::kCallerSPOffset)); |
| 4982 | |
| 4983 | // ecx : number of parameters (tagged) |
| 4984 | // edx : parameters pointer |
| 4985 | // edi : function |
| 4986 | // esp[0] : return address |
| 4987 | |
| 4988 | // Check if the calling frame is an arguments adaptor frame. |
| 4989 | Label adaptor_frame, try_allocate, runtime; |
| 4990 | __ mov(ebx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 4991 | __ mov(eax, Operand(ebx, CommonFrameConstants::kContextOrFrameTypeOffset)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4992 | __ cmp(eax, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 4993 | __ j(equal, &adaptor_frame, Label::kNear); |
| 4994 | |
| 4995 | // No adaptor, parameter count = argument count. |
| 4996 | __ mov(ebx, ecx); |
| 4997 | __ push(ecx); |
| 4998 | __ jmp(&try_allocate, Label::kNear); |
| 4999 | |
| 5000 | // We have an adaptor frame. Patch the parameters pointer. |
| 5001 | __ bind(&adaptor_frame); |
| 5002 | __ mov(ebx, ecx); |
| 5003 | __ push(ecx); |
| 5004 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 5005 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 5006 | __ lea(edx, Operand(edx, ecx, times_2, |
| 5007 | StandardFrameConstants::kCallerSPOffset)); |
| 5008 | |
| 5009 | // ebx = parameter count (tagged) |
| 5010 | // ecx = argument count (smi-tagged) |
| 5011 | // Compute the mapped parameter count = min(ebx, ecx) in ebx. |
| 5012 | __ cmp(ebx, ecx); |
| 5013 | __ j(less_equal, &try_allocate, Label::kNear); |
| 5014 | __ mov(ebx, ecx); |
| 5015 | |
| 5016 | // Save mapped parameter count and function. |
| 5017 | __ bind(&try_allocate); |
| 5018 | __ push(edi); |
| 5019 | __ push(ebx); |
| 5020 | |
| 5021 | // Compute the sizes of backing store, parameter map, and arguments object. |
| 5022 | // 1. Parameter map, has 2 extra words containing context and backing store. |
| 5023 | const int kParameterMapHeaderSize = |
| 5024 | FixedArray::kHeaderSize + 2 * kPointerSize; |
| 5025 | Label no_parameter_map; |
| 5026 | __ test(ebx, ebx); |
| 5027 | __ j(zero, &no_parameter_map, Label::kNear); |
| 5028 | __ lea(ebx, Operand(ebx, times_2, kParameterMapHeaderSize)); |
| 5029 | __ bind(&no_parameter_map); |
| 5030 | |
| 5031 | // 2. Backing store. |
| 5032 | __ lea(ebx, Operand(ebx, ecx, times_2, FixedArray::kHeaderSize)); |
| 5033 | |
| 5034 | // 3. Arguments object. |
| 5035 | __ add(ebx, Immediate(JSSloppyArgumentsObject::kSize)); |
| 5036 | |
| 5037 | // Do the allocation of all three objects in one go. |
| 5038 | __ Allocate(ebx, eax, edi, no_reg, &runtime, TAG_OBJECT); |
| 5039 | |
| 5040 | // eax = address of new object(s) (tagged) |
| 5041 | // ecx = argument count (smi-tagged) |
| 5042 | // esp[0] = mapped parameter count (tagged) |
| 5043 | // esp[4] = function |
| 5044 | // esp[8] = parameter count (tagged) |
| 5045 | // Get the arguments map from the current native context into edi. |
| 5046 | Label has_mapped_parameters, instantiate; |
| 5047 | __ mov(edi, NativeContextOperand()); |
| 5048 | __ mov(ebx, Operand(esp, 0 * kPointerSize)); |
| 5049 | __ test(ebx, ebx); |
| 5050 | __ j(not_zero, &has_mapped_parameters, Label::kNear); |
| 5051 | __ mov( |
| 5052 | edi, |
| 5053 | Operand(edi, Context::SlotOffset(Context::SLOPPY_ARGUMENTS_MAP_INDEX))); |
| 5054 | __ jmp(&instantiate, Label::kNear); |
| 5055 | |
| 5056 | __ bind(&has_mapped_parameters); |
| 5057 | __ mov(edi, Operand(edi, Context::SlotOffset( |
| 5058 | Context::FAST_ALIASED_ARGUMENTS_MAP_INDEX))); |
| 5059 | __ bind(&instantiate); |
| 5060 | |
| 5061 | // eax = address of new object (tagged) |
| 5062 | // ebx = mapped parameter count (tagged) |
| 5063 | // ecx = argument count (smi-tagged) |
| 5064 | // edi = address of arguments map (tagged) |
| 5065 | // esp[0] = mapped parameter count (tagged) |
| 5066 | // esp[4] = function |
| 5067 | // esp[8] = parameter count (tagged) |
| 5068 | // Copy the JS object part. |
| 5069 | __ mov(FieldOperand(eax, JSObject::kMapOffset), edi); |
| 5070 | __ mov(FieldOperand(eax, JSObject::kPropertiesOffset), |
| 5071 | masm->isolate()->factory()->empty_fixed_array()); |
| 5072 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), |
| 5073 | masm->isolate()->factory()->empty_fixed_array()); |
| 5074 | |
| 5075 | // Set up the callee in-object property. |
| 5076 | STATIC_ASSERT(JSSloppyArgumentsObject::kCalleeIndex == 1); |
| 5077 | __ mov(edi, Operand(esp, 1 * kPointerSize)); |
| 5078 | __ AssertNotSmi(edi); |
| 5079 | __ mov(FieldOperand(eax, JSSloppyArgumentsObject::kCalleeOffset), edi); |
| 5080 | |
| 5081 | // Use the length (smi tagged) and set that as an in-object property too. |
| 5082 | __ AssertSmi(ecx); |
| 5083 | __ mov(FieldOperand(eax, JSSloppyArgumentsObject::kLengthOffset), ecx); |
| 5084 | |
| 5085 | // Set up the elements pointer in the allocated arguments object. |
| 5086 | // If we allocated a parameter map, edi will point there, otherwise to the |
| 5087 | // backing store. |
| 5088 | __ lea(edi, Operand(eax, JSSloppyArgumentsObject::kSize)); |
| 5089 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), edi); |
| 5090 | |
| 5091 | // eax = address of new object (tagged) |
| 5092 | // ebx = mapped parameter count (tagged) |
| 5093 | // ecx = argument count (tagged) |
| 5094 | // edx = address of receiver argument |
| 5095 | // edi = address of parameter map or backing store (tagged) |
| 5096 | // esp[0] = mapped parameter count (tagged) |
| 5097 | // esp[4] = function |
| 5098 | // esp[8] = parameter count (tagged) |
| 5099 | // Free two registers. |
| 5100 | __ push(edx); |
| 5101 | __ push(eax); |
| 5102 | |
| 5103 | // Initialize parameter map. If there are no mapped arguments, we're done. |
| 5104 | Label skip_parameter_map; |
| 5105 | __ test(ebx, ebx); |
| 5106 | __ j(zero, &skip_parameter_map); |
| 5107 | |
| 5108 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
| 5109 | Immediate(isolate()->factory()->sloppy_arguments_elements_map())); |
| 5110 | __ lea(eax, Operand(ebx, reinterpret_cast<intptr_t>(Smi::FromInt(2)))); |
| 5111 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), eax); |
| 5112 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize + 0 * kPointerSize), esi); |
| 5113 | __ lea(eax, Operand(edi, ebx, times_2, kParameterMapHeaderSize)); |
| 5114 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize + 1 * kPointerSize), eax); |
| 5115 | |
| 5116 | // Copy the parameter slots and the holes in the arguments. |
| 5117 | // We need to fill in mapped_parameter_count slots. They index the context, |
| 5118 | // where parameters are stored in reverse order, at |
| 5119 | // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1 |
| 5120 | // The mapped parameter thus need to get indices |
| 5121 | // MIN_CONTEXT_SLOTS+parameter_count-1 .. |
| 5122 | // MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count |
| 5123 | // We loop from right to left. |
| 5124 | Label parameters_loop, parameters_test; |
| 5125 | __ push(ecx); |
| 5126 | __ mov(eax, Operand(esp, 3 * kPointerSize)); |
| 5127 | __ mov(ebx, Immediate(Smi::FromInt(Context::MIN_CONTEXT_SLOTS))); |
| 5128 | __ add(ebx, Operand(esp, 5 * kPointerSize)); |
| 5129 | __ sub(ebx, eax); |
| 5130 | __ mov(ecx, isolate()->factory()->the_hole_value()); |
| 5131 | __ mov(edx, edi); |
| 5132 | __ lea(edi, Operand(edi, eax, times_2, kParameterMapHeaderSize)); |
| 5133 | // eax = loop variable (tagged) |
| 5134 | // ebx = mapping index (tagged) |
| 5135 | // ecx = the hole value |
| 5136 | // edx = address of parameter map (tagged) |
| 5137 | // edi = address of backing store (tagged) |
| 5138 | // esp[0] = argument count (tagged) |
| 5139 | // esp[4] = address of new object (tagged) |
| 5140 | // esp[8] = address of receiver argument |
| 5141 | // esp[12] = mapped parameter count (tagged) |
| 5142 | // esp[16] = function |
| 5143 | // esp[20] = parameter count (tagged) |
| 5144 | __ jmp(¶meters_test, Label::kNear); |
| 5145 | |
| 5146 | __ bind(¶meters_loop); |
| 5147 | __ sub(eax, Immediate(Smi::FromInt(1))); |
| 5148 | __ mov(FieldOperand(edx, eax, times_2, kParameterMapHeaderSize), ebx); |
| 5149 | __ mov(FieldOperand(edi, eax, times_2, FixedArray::kHeaderSize), ecx); |
| 5150 | __ add(ebx, Immediate(Smi::FromInt(1))); |
| 5151 | __ bind(¶meters_test); |
| 5152 | __ test(eax, eax); |
| 5153 | __ j(not_zero, ¶meters_loop, Label::kNear); |
| 5154 | __ pop(ecx); |
| 5155 | |
| 5156 | __ bind(&skip_parameter_map); |
| 5157 | |
| 5158 | // ecx = argument count (tagged) |
| 5159 | // edi = address of backing store (tagged) |
| 5160 | // esp[0] = address of new object (tagged) |
| 5161 | // esp[4] = address of receiver argument |
| 5162 | // esp[8] = mapped parameter count (tagged) |
| 5163 | // esp[12] = function |
| 5164 | // esp[16] = parameter count (tagged) |
| 5165 | // Copy arguments header and remaining slots (if there are any). |
| 5166 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
| 5167 | Immediate(isolate()->factory()->fixed_array_map())); |
| 5168 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), ecx); |
| 5169 | |
| 5170 | Label arguments_loop, arguments_test; |
| 5171 | __ mov(ebx, Operand(esp, 2 * kPointerSize)); |
| 5172 | __ mov(edx, Operand(esp, 1 * kPointerSize)); |
| 5173 | __ sub(edx, ebx); // Is there a smarter way to do negative scaling? |
| 5174 | __ sub(edx, ebx); |
| 5175 | __ jmp(&arguments_test, Label::kNear); |
| 5176 | |
| 5177 | __ bind(&arguments_loop); |
| 5178 | __ sub(edx, Immediate(kPointerSize)); |
| 5179 | __ mov(eax, Operand(edx, 0)); |
| 5180 | __ mov(FieldOperand(edi, ebx, times_2, FixedArray::kHeaderSize), eax); |
| 5181 | __ add(ebx, Immediate(Smi::FromInt(1))); |
| 5182 | |
| 5183 | __ bind(&arguments_test); |
| 5184 | __ cmp(ebx, ecx); |
| 5185 | __ j(less, &arguments_loop, Label::kNear); |
| 5186 | |
| 5187 | // Restore. |
| 5188 | __ pop(eax); // Address of arguments object. |
| 5189 | __ Drop(4); |
| 5190 | |
| 5191 | // Return. |
| 5192 | __ ret(0); |
| 5193 | |
| 5194 | // Do the runtime call to allocate the arguments object. |
| 5195 | __ bind(&runtime); |
| 5196 | __ pop(eax); // Remove saved mapped parameter count. |
| 5197 | __ pop(edi); // Pop saved function. |
| 5198 | __ pop(eax); // Remove saved parameter count. |
| 5199 | __ pop(eax); // Pop return address. |
| 5200 | __ push(edi); // Push function. |
| 5201 | __ push(edx); // Push parameters pointer. |
| 5202 | __ push(ecx); // Push parameter count. |
| 5203 | __ push(eax); // Push return address. |
| 5204 | __ TailCallRuntime(Runtime::kNewSloppyArguments); |
| 5205 | } |
| 5206 | |
| 5207 | |
| 5208 | void FastNewStrictArgumentsStub::Generate(MacroAssembler* masm) { |
| 5209 | // ----------- S t a t e ------------- |
| 5210 | // -- edi : function |
| 5211 | // -- esi : context |
| 5212 | // -- ebp : frame pointer |
| 5213 | // -- esp[0] : return address |
| 5214 | // ----------------------------------- |
| 5215 | __ AssertFunction(edi); |
| 5216 | |
| 5217 | // For Ignition we need to skip all possible handler/stub frames until |
| 5218 | // we reach the JavaScript frame for the function (similar to what the |
| 5219 | // runtime fallback implementation does). So make edx point to that |
| 5220 | // JavaScript frame. |
| 5221 | { |
| 5222 | Label loop, loop_entry; |
| 5223 | __ mov(edx, ebp); |
| 5224 | __ jmp(&loop_entry, Label::kNear); |
| 5225 | __ bind(&loop); |
| 5226 | __ mov(edx, Operand(edx, StandardFrameConstants::kCallerFPOffset)); |
| 5227 | __ bind(&loop_entry); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 5228 | __ cmp(edi, Operand(edx, StandardFrameConstants::kFunctionOffset)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5229 | __ j(not_equal, &loop); |
| 5230 | } |
| 5231 | |
| 5232 | // Check if we have an arguments adaptor frame below the function frame. |
| 5233 | Label arguments_adaptor, arguments_done; |
| 5234 | __ mov(ebx, Operand(edx, StandardFrameConstants::kCallerFPOffset)); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 5235 | __ cmp(Operand(ebx, CommonFrameConstants::kContextOrFrameTypeOffset), |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5236 | Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 5237 | __ j(equal, &arguments_adaptor, Label::kNear); |
| 5238 | { |
| 5239 | __ mov(eax, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); |
| 5240 | __ mov(eax, |
| 5241 | FieldOperand(eax, SharedFunctionInfo::kFormalParameterCountOffset)); |
| 5242 | __ lea(ebx, |
| 5243 | Operand(edx, eax, times_half_pointer_size, |
| 5244 | StandardFrameConstants::kCallerSPOffset - 1 * kPointerSize)); |
| 5245 | } |
| 5246 | __ jmp(&arguments_done, Label::kNear); |
| 5247 | __ bind(&arguments_adaptor); |
| 5248 | { |
| 5249 | __ mov(eax, Operand(ebx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 5250 | __ lea(ebx, |
| 5251 | Operand(ebx, eax, times_half_pointer_size, |
| 5252 | StandardFrameConstants::kCallerSPOffset - 1 * kPointerSize)); |
| 5253 | } |
| 5254 | __ bind(&arguments_done); |
| 5255 | |
| 5256 | // ----------- S t a t e ------------- |
| 5257 | // -- eax : number of arguments (tagged) |
| 5258 | // -- ebx : pointer to the first argument |
| 5259 | // -- esi : context |
| 5260 | // -- esp[0] : return address |
| 5261 | // ----------------------------------- |
| 5262 | |
| 5263 | // Allocate space for the strict arguments object plus the backing store. |
| 5264 | Label allocate, done_allocate; |
| 5265 | __ lea(ecx, |
| 5266 | Operand(eax, times_half_pointer_size, |
| 5267 | JSStrictArgumentsObject::kSize + FixedArray::kHeaderSize)); |
| 5268 | __ Allocate(ecx, edx, edi, no_reg, &allocate, TAG_OBJECT); |
| 5269 | __ bind(&done_allocate); |
| 5270 | |
| 5271 | // Setup the elements array in edx. |
| 5272 | __ mov(FieldOperand(edx, FixedArray::kMapOffset), |
| 5273 | isolate()->factory()->fixed_array_map()); |
| 5274 | __ mov(FieldOperand(edx, FixedArray::kLengthOffset), eax); |
| 5275 | { |
| 5276 | Label loop, done_loop; |
| 5277 | __ Move(ecx, Smi::FromInt(0)); |
| 5278 | __ bind(&loop); |
| 5279 | __ cmp(ecx, eax); |
| 5280 | __ j(equal, &done_loop, Label::kNear); |
| 5281 | __ mov(edi, Operand(ebx, 0 * kPointerSize)); |
| 5282 | __ mov(FieldOperand(edx, ecx, times_half_pointer_size, |
| 5283 | FixedArray::kHeaderSize), |
| 5284 | edi); |
| 5285 | __ sub(ebx, Immediate(1 * kPointerSize)); |
| 5286 | __ add(ecx, Immediate(Smi::FromInt(1))); |
| 5287 | __ jmp(&loop); |
| 5288 | __ bind(&done_loop); |
| 5289 | } |
| 5290 | |
| 5291 | // Setup the rest parameter array in edi. |
| 5292 | __ lea(edi, |
| 5293 | Operand(edx, eax, times_half_pointer_size, FixedArray::kHeaderSize)); |
| 5294 | __ LoadGlobalFunction(Context::STRICT_ARGUMENTS_MAP_INDEX, ecx); |
| 5295 | __ mov(FieldOperand(edi, JSStrictArgumentsObject::kMapOffset), ecx); |
| 5296 | __ mov(FieldOperand(edi, JSStrictArgumentsObject::kPropertiesOffset), |
| 5297 | isolate()->factory()->empty_fixed_array()); |
| 5298 | __ mov(FieldOperand(edi, JSStrictArgumentsObject::kElementsOffset), edx); |
| 5299 | __ mov(FieldOperand(edi, JSStrictArgumentsObject::kLengthOffset), eax); |
| 5300 | STATIC_ASSERT(JSStrictArgumentsObject::kSize == 4 * kPointerSize); |
| 5301 | __ mov(eax, edi); |
| 5302 | __ Ret(); |
| 5303 | |
| 5304 | // Fall back to %AllocateInNewSpace. |
| 5305 | __ bind(&allocate); |
| 5306 | { |
| 5307 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 5308 | __ SmiTag(ecx); |
| 5309 | __ Push(eax); |
| 5310 | __ Push(ebx); |
| 5311 | __ Push(ecx); |
| 5312 | __ CallRuntime(Runtime::kAllocateInNewSpace); |
| 5313 | __ mov(edx, eax); |
| 5314 | __ Pop(ebx); |
| 5315 | __ Pop(eax); |
| 5316 | } |
| 5317 | __ jmp(&done_allocate); |
| 5318 | } |
| 5319 | |
| 5320 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5321 | void LoadGlobalViaContextStub::Generate(MacroAssembler* masm) { |
| 5322 | Register context_reg = esi; |
| 5323 | Register slot_reg = ebx; |
| 5324 | Register result_reg = eax; |
| 5325 | Label slow_case; |
| 5326 | |
| 5327 | // Go up context chain to the script context. |
| 5328 | for (int i = 0; i < depth(); ++i) { |
| 5329 | __ mov(result_reg, ContextOperand(context_reg, Context::PREVIOUS_INDEX)); |
| 5330 | context_reg = result_reg; |
| 5331 | } |
| 5332 | |
| 5333 | // Load the PropertyCell value at the specified slot. |
| 5334 | __ mov(result_reg, ContextOperand(context_reg, slot_reg)); |
| 5335 | __ mov(result_reg, FieldOperand(result_reg, PropertyCell::kValueOffset)); |
| 5336 | |
| 5337 | // Check that value is not the_hole. |
| 5338 | __ CompareRoot(result_reg, Heap::kTheHoleValueRootIndex); |
| 5339 | __ j(equal, &slow_case, Label::kNear); |
| 5340 | __ Ret(); |
| 5341 | |
| 5342 | // Fallback to the runtime. |
| 5343 | __ bind(&slow_case); |
| 5344 | __ SmiTag(slot_reg); |
| 5345 | __ Pop(result_reg); // Pop return address. |
| 5346 | __ Push(slot_reg); |
| 5347 | __ Push(result_reg); // Push return address. |
| 5348 | __ TailCallRuntime(Runtime::kLoadGlobalViaContext); |
| 5349 | } |
| 5350 | |
| 5351 | |
| 5352 | void StoreGlobalViaContextStub::Generate(MacroAssembler* masm) { |
| 5353 | Register context_reg = esi; |
| 5354 | Register slot_reg = ebx; |
| 5355 | Register value_reg = eax; |
| 5356 | Register cell_reg = edi; |
| 5357 | Register cell_details_reg = edx; |
| 5358 | Register cell_value_reg = ecx; |
| 5359 | Label fast_heapobject_case, fast_smi_case, slow_case; |
| 5360 | |
| 5361 | if (FLAG_debug_code) { |
| 5362 | __ CompareRoot(value_reg, Heap::kTheHoleValueRootIndex); |
| 5363 | __ Check(not_equal, kUnexpectedValue); |
| 5364 | } |
| 5365 | |
| 5366 | // Go up context chain to the script context. |
| 5367 | for (int i = 0; i < depth(); ++i) { |
| 5368 | __ mov(cell_reg, ContextOperand(context_reg, Context::PREVIOUS_INDEX)); |
| 5369 | context_reg = cell_reg; |
| 5370 | } |
| 5371 | |
| 5372 | // Load the PropertyCell at the specified slot. |
| 5373 | __ mov(cell_reg, ContextOperand(context_reg, slot_reg)); |
| 5374 | |
| 5375 | // Load PropertyDetails for the cell (actually only the cell_type and kind). |
| 5376 | __ mov(cell_details_reg, |
| 5377 | FieldOperand(cell_reg, PropertyCell::kDetailsOffset)); |
| 5378 | __ SmiUntag(cell_details_reg); |
| 5379 | __ and_(cell_details_reg, |
| 5380 | Immediate(PropertyDetails::PropertyCellTypeField::kMask | |
| 5381 | PropertyDetails::KindField::kMask | |
| 5382 | PropertyDetails::kAttributesReadOnlyMask)); |
| 5383 | |
| 5384 | // Check if PropertyCell holds mutable data. |
| 5385 | Label not_mutable_data; |
| 5386 | __ cmp(cell_details_reg, |
| 5387 | Immediate(PropertyDetails::PropertyCellTypeField::encode( |
| 5388 | PropertyCellType::kMutable) | |
| 5389 | PropertyDetails::KindField::encode(kData))); |
| 5390 | __ j(not_equal, ¬_mutable_data); |
| 5391 | __ JumpIfSmi(value_reg, &fast_smi_case); |
| 5392 | __ bind(&fast_heapobject_case); |
| 5393 | __ mov(FieldOperand(cell_reg, PropertyCell::kValueOffset), value_reg); |
| 5394 | __ RecordWriteField(cell_reg, PropertyCell::kValueOffset, value_reg, |
| 5395 | cell_details_reg, kDontSaveFPRegs, EMIT_REMEMBERED_SET, |
| 5396 | OMIT_SMI_CHECK); |
| 5397 | // RecordWriteField clobbers the value register, so we need to reload. |
| 5398 | __ mov(value_reg, FieldOperand(cell_reg, PropertyCell::kValueOffset)); |
| 5399 | __ Ret(); |
| 5400 | __ bind(¬_mutable_data); |
| 5401 | |
| 5402 | // Check if PropertyCell value matches the new value (relevant for Constant, |
| 5403 | // ConstantType and Undefined cells). |
| 5404 | Label not_same_value; |
| 5405 | __ mov(cell_value_reg, FieldOperand(cell_reg, PropertyCell::kValueOffset)); |
| 5406 | __ cmp(cell_value_reg, value_reg); |
| 5407 | __ j(not_equal, ¬_same_value, |
| 5408 | FLAG_debug_code ? Label::kFar : Label::kNear); |
| 5409 | // Make sure the PropertyCell is not marked READ_ONLY. |
| 5410 | __ test(cell_details_reg, |
| 5411 | Immediate(PropertyDetails::kAttributesReadOnlyMask)); |
| 5412 | __ j(not_zero, &slow_case); |
| 5413 | if (FLAG_debug_code) { |
| 5414 | Label done; |
| 5415 | // This can only be true for Constant, ConstantType and Undefined cells, |
| 5416 | // because we never store the_hole via this stub. |
| 5417 | __ cmp(cell_details_reg, |
| 5418 | Immediate(PropertyDetails::PropertyCellTypeField::encode( |
| 5419 | PropertyCellType::kConstant) | |
| 5420 | PropertyDetails::KindField::encode(kData))); |
| 5421 | __ j(equal, &done); |
| 5422 | __ cmp(cell_details_reg, |
| 5423 | Immediate(PropertyDetails::PropertyCellTypeField::encode( |
| 5424 | PropertyCellType::kConstantType) | |
| 5425 | PropertyDetails::KindField::encode(kData))); |
| 5426 | __ j(equal, &done); |
| 5427 | __ cmp(cell_details_reg, |
| 5428 | Immediate(PropertyDetails::PropertyCellTypeField::encode( |
| 5429 | PropertyCellType::kUndefined) | |
| 5430 | PropertyDetails::KindField::encode(kData))); |
| 5431 | __ Check(equal, kUnexpectedValue); |
| 5432 | __ bind(&done); |
| 5433 | } |
| 5434 | __ Ret(); |
| 5435 | __ bind(¬_same_value); |
| 5436 | |
| 5437 | // Check if PropertyCell contains data with constant type (and is not |
| 5438 | // READ_ONLY). |
| 5439 | __ cmp(cell_details_reg, |
| 5440 | Immediate(PropertyDetails::PropertyCellTypeField::encode( |
| 5441 | PropertyCellType::kConstantType) | |
| 5442 | PropertyDetails::KindField::encode(kData))); |
| 5443 | __ j(not_equal, &slow_case, Label::kNear); |
| 5444 | |
| 5445 | // Now either both old and new values must be SMIs or both must be heap |
| 5446 | // objects with same map. |
| 5447 | Label value_is_heap_object; |
| 5448 | __ JumpIfNotSmi(value_reg, &value_is_heap_object, Label::kNear); |
| 5449 | __ JumpIfNotSmi(cell_value_reg, &slow_case, Label::kNear); |
| 5450 | // Old and new values are SMIs, no need for a write barrier here. |
| 5451 | __ bind(&fast_smi_case); |
| 5452 | __ mov(FieldOperand(cell_reg, PropertyCell::kValueOffset), value_reg); |
| 5453 | __ Ret(); |
| 5454 | __ bind(&value_is_heap_object); |
| 5455 | __ JumpIfSmi(cell_value_reg, &slow_case, Label::kNear); |
| 5456 | Register cell_value_map_reg = cell_value_reg; |
| 5457 | __ mov(cell_value_map_reg, |
| 5458 | FieldOperand(cell_value_reg, HeapObject::kMapOffset)); |
| 5459 | __ cmp(cell_value_map_reg, FieldOperand(value_reg, HeapObject::kMapOffset)); |
| 5460 | __ j(equal, &fast_heapobject_case); |
| 5461 | |
| 5462 | // Fallback to the runtime. |
| 5463 | __ bind(&slow_case); |
| 5464 | __ SmiTag(slot_reg); |
| 5465 | __ Pop(cell_reg); // Pop return address. |
| 5466 | __ Push(slot_reg); |
| 5467 | __ Push(value_reg); |
| 5468 | __ Push(cell_reg); // Push return address. |
| 5469 | __ TailCallRuntime(is_strict(language_mode()) |
| 5470 | ? Runtime::kStoreGlobalViaContext_Strict |
| 5471 | : Runtime::kStoreGlobalViaContext_Sloppy); |
| 5472 | } |
| 5473 | |
| 5474 | |
| 5475 | // Generates an Operand for saving parameters after PrepareCallApiFunction. |
| 5476 | static Operand ApiParameterOperand(int index) { |
| 5477 | return Operand(esp, index * kPointerSize); |
| 5478 | } |
| 5479 | |
| 5480 | |
| 5481 | // Prepares stack to put arguments (aligns and so on). Reserves |
| 5482 | // space for return value if needed (assumes the return value is a handle). |
| 5483 | // Arguments must be stored in ApiParameterOperand(0), ApiParameterOperand(1) |
| 5484 | // etc. Saves context (esi). If space was reserved for return value then |
| 5485 | // stores the pointer to the reserved slot into esi. |
| 5486 | static void PrepareCallApiFunction(MacroAssembler* masm, int argc) { |
| 5487 | __ EnterApiExitFrame(argc); |
| 5488 | if (__ emit_debug_code()) { |
| 5489 | __ mov(esi, Immediate(bit_cast<int32_t>(kZapValue))); |
| 5490 | } |
| 5491 | } |
| 5492 | |
| 5493 | |
| 5494 | // Calls an API function. Allocates HandleScope, extracts returned value |
| 5495 | // from handle and propagates exceptions. Clobbers ebx, edi and |
| 5496 | // caller-save registers. Restores context. On return removes |
| 5497 | // stack_space * kPointerSize (GCed). |
| 5498 | static void CallApiFunctionAndReturn(MacroAssembler* masm, |
| 5499 | Register function_address, |
| 5500 | ExternalReference thunk_ref, |
| 5501 | Operand thunk_last_arg, int stack_space, |
| 5502 | Operand* stack_space_operand, |
| 5503 | Operand return_value_operand, |
| 5504 | Operand* context_restore_operand) { |
| 5505 | Isolate* isolate = masm->isolate(); |
| 5506 | |
| 5507 | ExternalReference next_address = |
| 5508 | ExternalReference::handle_scope_next_address(isolate); |
| 5509 | ExternalReference limit_address = |
| 5510 | ExternalReference::handle_scope_limit_address(isolate); |
| 5511 | ExternalReference level_address = |
| 5512 | ExternalReference::handle_scope_level_address(isolate); |
| 5513 | |
| 5514 | DCHECK(edx.is(function_address)); |
| 5515 | // Allocate HandleScope in callee-save registers. |
| 5516 | __ mov(ebx, Operand::StaticVariable(next_address)); |
| 5517 | __ mov(edi, Operand::StaticVariable(limit_address)); |
| 5518 | __ add(Operand::StaticVariable(level_address), Immediate(1)); |
| 5519 | |
| 5520 | if (FLAG_log_timer_events) { |
| 5521 | FrameScope frame(masm, StackFrame::MANUAL); |
| 5522 | __ PushSafepointRegisters(); |
| 5523 | __ PrepareCallCFunction(1, eax); |
| 5524 | __ mov(Operand(esp, 0), |
| 5525 | Immediate(ExternalReference::isolate_address(isolate))); |
| 5526 | __ CallCFunction(ExternalReference::log_enter_external_function(isolate), |
| 5527 | 1); |
| 5528 | __ PopSafepointRegisters(); |
| 5529 | } |
| 5530 | |
| 5531 | |
| 5532 | Label profiler_disabled; |
| 5533 | Label end_profiler_check; |
| 5534 | __ mov(eax, Immediate(ExternalReference::is_profiling_address(isolate))); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 5535 | __ cmpb(Operand(eax, 0), Immediate(0)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5536 | __ j(zero, &profiler_disabled); |
| 5537 | |
| 5538 | // Additional parameter is the address of the actual getter function. |
| 5539 | __ mov(thunk_last_arg, function_address); |
| 5540 | // Call the api function. |
| 5541 | __ mov(eax, Immediate(thunk_ref)); |
| 5542 | __ call(eax); |
| 5543 | __ jmp(&end_profiler_check); |
| 5544 | |
| 5545 | __ bind(&profiler_disabled); |
| 5546 | // Call the api function. |
| 5547 | __ call(function_address); |
| 5548 | __ bind(&end_profiler_check); |
| 5549 | |
| 5550 | if (FLAG_log_timer_events) { |
| 5551 | FrameScope frame(masm, StackFrame::MANUAL); |
| 5552 | __ PushSafepointRegisters(); |
| 5553 | __ PrepareCallCFunction(1, eax); |
| 5554 | __ mov(Operand(esp, 0), |
| 5555 | Immediate(ExternalReference::isolate_address(isolate))); |
| 5556 | __ CallCFunction(ExternalReference::log_leave_external_function(isolate), |
| 5557 | 1); |
| 5558 | __ PopSafepointRegisters(); |
| 5559 | } |
| 5560 | |
| 5561 | Label prologue; |
| 5562 | // Load the value from ReturnValue |
| 5563 | __ mov(eax, return_value_operand); |
| 5564 | |
| 5565 | Label promote_scheduled_exception; |
| 5566 | Label delete_allocated_handles; |
| 5567 | Label leave_exit_frame; |
| 5568 | |
| 5569 | __ bind(&prologue); |
| 5570 | // No more valid handles (the result handle was the last one). Restore |
| 5571 | // previous handle scope. |
| 5572 | __ mov(Operand::StaticVariable(next_address), ebx); |
| 5573 | __ sub(Operand::StaticVariable(level_address), Immediate(1)); |
| 5574 | __ Assert(above_equal, kInvalidHandleScopeLevel); |
| 5575 | __ cmp(edi, Operand::StaticVariable(limit_address)); |
| 5576 | __ j(not_equal, &delete_allocated_handles); |
| 5577 | |
| 5578 | // Leave the API exit frame. |
| 5579 | __ bind(&leave_exit_frame); |
| 5580 | bool restore_context = context_restore_operand != NULL; |
| 5581 | if (restore_context) { |
| 5582 | __ mov(esi, *context_restore_operand); |
| 5583 | } |
| 5584 | if (stack_space_operand != nullptr) { |
| 5585 | __ mov(ebx, *stack_space_operand); |
| 5586 | } |
| 5587 | __ LeaveApiExitFrame(!restore_context); |
| 5588 | |
| 5589 | // Check if the function scheduled an exception. |
| 5590 | ExternalReference scheduled_exception_address = |
| 5591 | ExternalReference::scheduled_exception_address(isolate); |
| 5592 | __ cmp(Operand::StaticVariable(scheduled_exception_address), |
| 5593 | Immediate(isolate->factory()->the_hole_value())); |
| 5594 | __ j(not_equal, &promote_scheduled_exception); |
| 5595 | |
| 5596 | #if DEBUG |
| 5597 | // Check if the function returned a valid JavaScript value. |
| 5598 | Label ok; |
| 5599 | Register return_value = eax; |
| 5600 | Register map = ecx; |
| 5601 | |
| 5602 | __ JumpIfSmi(return_value, &ok, Label::kNear); |
| 5603 | __ mov(map, FieldOperand(return_value, HeapObject::kMapOffset)); |
| 5604 | |
| 5605 | __ CmpInstanceType(map, LAST_NAME_TYPE); |
| 5606 | __ j(below_equal, &ok, Label::kNear); |
| 5607 | |
| 5608 | __ CmpInstanceType(map, FIRST_JS_RECEIVER_TYPE); |
| 5609 | __ j(above_equal, &ok, Label::kNear); |
| 5610 | |
| 5611 | __ cmp(map, isolate->factory()->heap_number_map()); |
| 5612 | __ j(equal, &ok, Label::kNear); |
| 5613 | |
| 5614 | __ cmp(return_value, isolate->factory()->undefined_value()); |
| 5615 | __ j(equal, &ok, Label::kNear); |
| 5616 | |
| 5617 | __ cmp(return_value, isolate->factory()->true_value()); |
| 5618 | __ j(equal, &ok, Label::kNear); |
| 5619 | |
| 5620 | __ cmp(return_value, isolate->factory()->false_value()); |
| 5621 | __ j(equal, &ok, Label::kNear); |
| 5622 | |
| 5623 | __ cmp(return_value, isolate->factory()->null_value()); |
| 5624 | __ j(equal, &ok, Label::kNear); |
| 5625 | |
| 5626 | __ Abort(kAPICallReturnedInvalidObject); |
| 5627 | |
| 5628 | __ bind(&ok); |
| 5629 | #endif |
| 5630 | |
| 5631 | if (stack_space_operand != nullptr) { |
| 5632 | DCHECK_EQ(0, stack_space); |
| 5633 | __ pop(ecx); |
| 5634 | __ add(esp, ebx); |
| 5635 | __ jmp(ecx); |
| 5636 | } else { |
| 5637 | __ ret(stack_space * kPointerSize); |
| 5638 | } |
| 5639 | |
| 5640 | // Re-throw by promoting a scheduled exception. |
| 5641 | __ bind(&promote_scheduled_exception); |
| 5642 | __ TailCallRuntime(Runtime::kPromoteScheduledException); |
| 5643 | |
| 5644 | // HandleScope limit has changed. Delete allocated extensions. |
| 5645 | ExternalReference delete_extensions = |
| 5646 | ExternalReference::delete_handle_scope_extensions(isolate); |
| 5647 | __ bind(&delete_allocated_handles); |
| 5648 | __ mov(Operand::StaticVariable(limit_address), edi); |
| 5649 | __ mov(edi, eax); |
| 5650 | __ mov(Operand(esp, 0), |
| 5651 | Immediate(ExternalReference::isolate_address(isolate))); |
| 5652 | __ mov(eax, Immediate(delete_extensions)); |
| 5653 | __ call(eax); |
| 5654 | __ mov(eax, edi); |
| 5655 | __ jmp(&leave_exit_frame); |
| 5656 | } |
| 5657 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 5658 | void CallApiCallbackStub::Generate(MacroAssembler* masm) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5659 | // ----------- S t a t e ------------- |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5660 | // -- edi : callee |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5661 | // -- ebx : call_data |
| 5662 | // -- ecx : holder |
| 5663 | // -- edx : api_function_address |
| 5664 | // -- esi : context |
| 5665 | // -- |
| 5666 | // -- esp[0] : return address |
| 5667 | // -- esp[4] : last argument |
| 5668 | // -- ... |
| 5669 | // -- esp[argc * 4] : first argument |
| 5670 | // -- esp[(argc + 1) * 4] : receiver |
| 5671 | // ----------------------------------- |
| 5672 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5673 | Register callee = edi; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5674 | Register call_data = ebx; |
| 5675 | Register holder = ecx; |
| 5676 | Register api_function_address = edx; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5677 | Register context = esi; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5678 | Register return_address = eax; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5679 | |
| 5680 | typedef FunctionCallbackArguments FCA; |
| 5681 | |
| 5682 | STATIC_ASSERT(FCA::kContextSaveIndex == 6); |
| 5683 | STATIC_ASSERT(FCA::kCalleeIndex == 5); |
| 5684 | STATIC_ASSERT(FCA::kDataIndex == 4); |
| 5685 | STATIC_ASSERT(FCA::kReturnValueOffset == 3); |
| 5686 | STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2); |
| 5687 | STATIC_ASSERT(FCA::kIsolateIndex == 1); |
| 5688 | STATIC_ASSERT(FCA::kHolderIndex == 0); |
| 5689 | STATIC_ASSERT(FCA::kArgsLength == 7); |
| 5690 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 5691 | __ pop(return_address); |
| 5692 | // context save. |
| 5693 | __ push(context); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5694 | |
| 5695 | // callee |
| 5696 | __ push(callee); |
| 5697 | |
| 5698 | // call data |
| 5699 | __ push(call_data); |
| 5700 | |
| 5701 | Register scratch = call_data; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 5702 | if (!call_data_undefined()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5703 | // return value |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5704 | __ push(Immediate(masm->isolate()->factory()->undefined_value())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5705 | // return value default |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5706 | __ push(Immediate(masm->isolate()->factory()->undefined_value())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5707 | } else { |
| 5708 | // return value |
| 5709 | __ push(scratch); |
| 5710 | // return value default |
| 5711 | __ push(scratch); |
| 5712 | } |
| 5713 | // isolate |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5714 | __ push(Immediate(reinterpret_cast<int>(masm->isolate()))); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5715 | // holder |
| 5716 | __ push(holder); |
| 5717 | |
| 5718 | __ mov(scratch, esp); |
| 5719 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5720 | // push return address |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5721 | __ push(return_address); |
| 5722 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 5723 | if (!is_lazy()) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5724 | // load context from callee |
| 5725 | __ mov(context, FieldOperand(callee, JSFunction::kContextOffset)); |
| 5726 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5727 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5728 | // API function gets reference to the v8::Arguments. If CPU profiler |
| 5729 | // is enabled wrapper function will be called and we need to pass |
| 5730 | // address of the callback as additional parameter, always allocate |
| 5731 | // space for it. |
| 5732 | const int kApiArgc = 1 + 1; |
| 5733 | |
| 5734 | // Allocate the v8::Arguments structure in the arguments' space since |
| 5735 | // it's not controlled by GC. |
| 5736 | const int kApiStackSpace = 4; |
| 5737 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5738 | PrepareCallApiFunction(masm, kApiArgc + kApiStackSpace); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5739 | |
| 5740 | // FunctionCallbackInfo::implicit_args_. |
| 5741 | __ mov(ApiParameterOperand(2), scratch); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 5742 | __ add(scratch, Immediate((argc() + FCA::kArgsLength - 1) * kPointerSize)); |
| 5743 | // FunctionCallbackInfo::values_. |
| 5744 | __ mov(ApiParameterOperand(3), scratch); |
| 5745 | // FunctionCallbackInfo::length_. |
| 5746 | __ Move(ApiParameterOperand(4), Immediate(argc())); |
| 5747 | // FunctionCallbackInfo::is_construct_call_. |
| 5748 | __ Move(ApiParameterOperand(5), Immediate(0)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5749 | |
| 5750 | // v8::InvocationCallback's argument. |
| 5751 | __ lea(scratch, ApiParameterOperand(2)); |
| 5752 | __ mov(ApiParameterOperand(0), scratch); |
| 5753 | |
| 5754 | ExternalReference thunk_ref = |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5755 | ExternalReference::invoke_function_callback(masm->isolate()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5756 | |
| 5757 | Operand context_restore_operand(ebp, |
| 5758 | (2 + FCA::kContextSaveIndex) * kPointerSize); |
| 5759 | // Stores return the first js argument |
| 5760 | int return_value_offset = 0; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 5761 | if (is_store()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5762 | return_value_offset = 2 + FCA::kArgsLength; |
| 5763 | } else { |
| 5764 | return_value_offset = 2 + FCA::kReturnValueOffset; |
| 5765 | } |
| 5766 | Operand return_value_operand(ebp, return_value_offset * kPointerSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5767 | int stack_space = 0; |
| 5768 | Operand is_construct_call_operand = ApiParameterOperand(5); |
| 5769 | Operand* stack_space_operand = &is_construct_call_operand; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 5770 | stack_space = argc() + FCA::kArgsLength + 1; |
| 5771 | stack_space_operand = nullptr; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5772 | CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, |
| 5773 | ApiParameterOperand(1), stack_space, |
| 5774 | stack_space_operand, return_value_operand, |
| 5775 | &context_restore_operand); |
| 5776 | } |
| 5777 | |
| 5778 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5779 | void CallApiGetterStub::Generate(MacroAssembler* masm) { |
| 5780 | // ----------- S t a t e ------------- |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5781 | // -- esp[0] : return address |
| 5782 | // -- esp[4] : name |
| 5783 | // -- esp[8 .. (8 + kArgsLength*4)] : v8::PropertyCallbackInfo::args_ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5784 | // -- ... |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5785 | // -- edx : api_function_address |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5786 | // ----------------------------------- |
| 5787 | DCHECK(edx.is(ApiGetterDescriptor::function_address())); |
| 5788 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5789 | // v8::PropertyCallbackInfo::args_ array and name handle. |
| 5790 | const int kStackUnwindSpace = PropertyCallbackArguments::kArgsLength + 1; |
| 5791 | |
| 5792 | // Allocate v8::PropertyCallbackInfo object, arguments for callback and |
| 5793 | // space for optional callback address parameter (in case CPU profiler is |
| 5794 | // active) in non-GCed stack space. |
| 5795 | const int kApiArgc = 3 + 1; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5796 | |
| 5797 | Register api_function_address = edx; |
| 5798 | Register scratch = ebx; |
| 5799 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5800 | // Load address of v8::PropertyAccessorInfo::args_ array. |
| 5801 | __ lea(scratch, Operand(esp, 2 * kPointerSize)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5802 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5803 | PrepareCallApiFunction(masm, kApiArgc); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5804 | // Create v8::PropertyCallbackInfo object on the stack and initialize |
| 5805 | // it's args_ field. |
| 5806 | Operand info_object = ApiParameterOperand(3); |
| 5807 | __ mov(info_object, scratch); |
| 5808 | |
| 5809 | __ sub(scratch, Immediate(kPointerSize)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5810 | __ mov(ApiParameterOperand(0), scratch); // name. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5811 | __ lea(scratch, info_object); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5812 | __ mov(ApiParameterOperand(1), scratch); // arguments pointer. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5813 | // Reserve space for optional callback address parameter. |
| 5814 | Operand thunk_last_arg = ApiParameterOperand(2); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5815 | |
| 5816 | ExternalReference thunk_ref = |
| 5817 | ExternalReference::invoke_accessor_getter_callback(isolate()); |
| 5818 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5819 | // +3 is to skip prolog, return address and name handle. |
| 5820 | Operand return_value_operand( |
| 5821 | ebp, (PropertyCallbackArguments::kReturnValueOffset + 3) * kPointerSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5822 | CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5823 | thunk_last_arg, kStackUnwindSpace, nullptr, |
| 5824 | return_value_operand, NULL); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5825 | } |
| 5826 | |
| 5827 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5828 | #undef __ |
| 5829 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5830 | } // namespace internal |
| 5831 | } // namespace v8 |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5832 | |
| 5833 | #endif // V8_TARGET_ARCH_IA32 |