Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "src/v8.h" | |
| 6 | |
| 7 #if V8_TARGET_ARCH_PPC | |
| 8 | |
| 9 #include "src/codegen.h" | |
| 10 #include "src/macro-assembler.h" | |
| 11 #include "src/ppc/simulator-ppc.h" | |
| 12 | |
| 13 namespace v8 { | |
| 14 namespace internal { | |
| 15 | |
| 16 | |
| 17 #define __ masm. | |
| 18 | |
| 19 | |
| 20 #if defined(USE_SIMULATOR) | |
| 21 byte* fast_exp_ppc_machine_code = NULL; | |
| 22 double fast_exp_simulator(double x) { | |
| 23 return Simulator::current(Isolate::Current()) | |
| 24 ->CallFPReturnsDouble(fast_exp_ppc_machine_code, x, 0); | |
| 25 } | |
| 26 #endif | |
| 27 | |
| 28 | |
| 29 UnaryMathFunction CreateExpFunction() { | |
| 30 if (!FLAG_fast_math) return &std::exp; | |
| 31 size_t actual_size; | |
| 32 byte* buffer = | |
| 33 static_cast<byte*>(base::OS::Allocate(1 * KB, &actual_size, true)); | |
| 34 if (buffer == NULL) return &std::exp; | |
| 35 ExternalReference::InitializeMathExpData(); | |
| 36 | |
| 37 MacroAssembler masm(NULL, buffer, static_cast<int>(actual_size)); | |
| 38 | |
| 39 { | |
| 40 DoubleRegister input = d1; | |
| 41 DoubleRegister result = d2; | |
| 42 DoubleRegister double_scratch1 = d3; | |
| 43 DoubleRegister double_scratch2 = d4; | |
| 44 Register temp1 = r7; | |
| 45 Register temp2 = r8; | |
| 46 Register temp3 = r9; | |
| 47 | |
| 48 // Called from C | |
| 49 #if ABI_USES_FUNCTION_DESCRIPTORS | |
| 50 __ function_descriptor(); | |
| 51 #endif | |
| 52 | |
| 53 __ Push(temp3, temp2, temp1); | |
| 54 MathExpGenerator::EmitMathExp(&masm, input, result, double_scratch1, | |
| 55 double_scratch2, temp1, temp2, temp3); | |
| 56 __ Pop(temp3, temp2, temp1); | |
| 57 __ fmr(d1, result); | |
| 58 __ Ret(); | |
| 59 } | |
| 60 | |
| 61 CodeDesc desc; | |
| 62 masm.GetCode(&desc); | |
| 63 #if !ABI_USES_FUNCTION_DESCRIPTORS | |
| 64 DCHECK(!RelocInfo::RequiresRelocation(desc)); | |
| 65 #endif | |
| 66 | |
| 67 CpuFeatures::FlushICache(buffer, actual_size); | |
| 68 base::OS::ProtectCode(buffer, actual_size); | |
| 69 | |
| 70 #if !defined(USE_SIMULATOR) | |
| 71 return FUNCTION_CAST<UnaryMathFunction>(buffer); | |
| 72 #else | |
| 73 fast_exp_ppc_machine_code = buffer; | |
| 74 return &fast_exp_simulator; | |
| 75 #endif | |
| 76 } | |
| 77 | |
| 78 | |
| 79 UnaryMathFunction CreateSqrtFunction() { | |
| 80 #if defined(USE_SIMULATOR) | |
| 81 return &std::sqrt; | |
| 82 #else | |
| 83 size_t actual_size; | |
| 84 byte* buffer = | |
| 85 static_cast<byte*>(base::OS::Allocate(1 * KB, &actual_size, true)); | |
| 86 if (buffer == NULL) return &std::sqrt; | |
| 87 | |
| 88 MacroAssembler masm(NULL, buffer, static_cast<int>(actual_size)); | |
| 89 | |
| 90 // Called from C | |
| 91 #if ABI_USES_FUNCTION_DESCRIPTORS | |
| 92 __ function_descriptor(); | |
| 93 #endif | |
| 94 | |
| 95 __ MovFromFloatParameter(d1); | |
| 96 __ fsqrt(d1, d1); | |
| 97 __ MovToFloatResult(d1); | |
| 98 __ Ret(); | |
| 99 | |
| 100 CodeDesc desc; | |
| 101 masm.GetCode(&desc); | |
| 102 #if !ABI_USES_FUNCTION_DESCRIPTORS | |
| 103 DCHECK(!RelocInfo::RequiresRelocation(desc)); | |
| 104 #endif | |
| 105 | |
| 106 CpuFeatures::FlushICache(buffer, actual_size); | |
| 107 base::OS::ProtectCode(buffer, actual_size); | |
| 108 return FUNCTION_CAST<UnaryMathFunction>(buffer); | |
| 109 #endif | |
| 110 } | |
| 111 | |
| 112 #undef __ | |
| 113 | |
| 114 | |
| 115 // ------------------------------------------------------------------------- | |
| 116 // Platform-specific RuntimeCallHelper functions. | |
| 117 | |
| 118 void StubRuntimeCallHelper::BeforeCall(MacroAssembler* masm) const { | |
| 119 masm->EnterFrame(StackFrame::INTERNAL); | |
| 120 DCHECK(!masm->has_frame()); | |
| 121 masm->set_has_frame(true); | |
| 122 } | |
| 123 | |
| 124 | |
| 125 void StubRuntimeCallHelper::AfterCall(MacroAssembler* masm) const { | |
| 126 masm->LeaveFrame(StackFrame::INTERNAL); | |
| 127 DCHECK(masm->has_frame()); | |
| 128 masm->set_has_frame(false); | |
| 129 } | |
| 130 | |
| 131 | |
| 132 // ------------------------------------------------------------------------- | |
| 133 // Code generators | |
| 134 | |
| 135 #define __ ACCESS_MASM(masm) | |
| 136 | |
| 137 void ElementsTransitionGenerator::GenerateMapChangeElementsTransition( | |
| 138 MacroAssembler* masm, Register receiver, Register key, Register value, | |
| 139 Register target_map, AllocationSiteMode mode, | |
| 140 Label* allocation_memento_found) { | |
| 141 Register scratch_elements = r7; | |
| 142 DCHECK(!AreAliased(receiver, key, value, target_map, scratch_elements)); | |
| 143 | |
| 144 if (mode == TRACK_ALLOCATION_SITE) { | |
| 145 DCHECK(allocation_memento_found != NULL); | |
| 146 __ JumpIfJSArrayHasAllocationMemento(receiver, scratch_elements, | |
| 147 allocation_memento_found); | |
| 148 } | |
| 149 | |
| 150 // Set transitioned map. | |
| 151 __ StoreP(target_map, FieldMemOperand(receiver, HeapObject::kMapOffset), r0); | |
| 152 __ RecordWriteField(receiver, HeapObject::kMapOffset, target_map, r11, | |
| 153 kLRHasNotBeenSaved, kDontSaveFPRegs, EMIT_REMEMBERED_SET, | |
| 154 OMIT_SMI_CHECK); | |
| 155 } | |
| 156 | |
| 157 | |
| 158 void ElementsTransitionGenerator::GenerateSmiToDouble( | |
| 159 MacroAssembler* masm, Register receiver, Register key, Register value, | |
| 160 Register target_map, AllocationSiteMode mode, Label* fail) { | |
| 161 // lr contains the return address | |
| 162 Label loop, entry, convert_hole, gc_required, only_change_map, done; | |
| 163 Register elements = r7; | |
| 164 Register length = r8; | |
| 165 Register array = r9; | |
| 166 Register array_end = array; | |
| 167 | |
| 168 // target_map parameter can be clobbered. | |
| 169 Register scratch1 = target_map; | |
| 170 Register scratch2 = r11; | |
| 171 | |
| 172 // Verify input registers don't conflict with locals. | |
| 173 DCHECK(!AreAliased(receiver, key, value, target_map, elements, length, array, | |
| 174 scratch2)); | |
| 175 | |
| 176 if (mode == TRACK_ALLOCATION_SITE) { | |
| 177 __ JumpIfJSArrayHasAllocationMemento(receiver, elements, fail); | |
| 178 } | |
| 179 | |
| 180 // Check for empty arrays, which only require a map transition and no changes | |
| 181 // to the backing store. | |
| 182 __ LoadP(elements, FieldMemOperand(receiver, JSObject::kElementsOffset)); | |
| 183 __ CompareRoot(elements, Heap::kEmptyFixedArrayRootIndex); | |
| 184 __ beq(&only_change_map); | |
| 185 | |
| 186 // Preserve lr and use r17 as a temporary register. | |
| 187 __ mflr(r0); | |
| 188 __ Push(r0); | |
| 189 | |
| 190 __ LoadP(length, FieldMemOperand(elements, FixedArray::kLengthOffset)); | |
| 191 // length: number of elements (smi-tagged) | |
| 192 | |
| 193 // Allocate new FixedDoubleArray. | |
| 194 __ SmiToDoubleArrayOffset(r17, length); | |
| 195 __ addi(r17, r17, Operand(FixedDoubleArray::kHeaderSize)); | |
| 196 __ Allocate(r17, array, r10, scratch2, &gc_required, DOUBLE_ALIGNMENT); | |
| 197 | |
| 198 // Set destination FixedDoubleArray's length and map. | |
| 199 __ LoadRoot(scratch2, Heap::kFixedDoubleArrayMapRootIndex); | |
| 200 __ StoreP(length, MemOperand(array, FixedDoubleArray::kLengthOffset)); | |
| 201 // Update receiver's map. | |
| 202 __ StoreP(scratch2, MemOperand(array, HeapObject::kMapOffset)); | |
| 203 | |
| 204 __ StoreP(target_map, FieldMemOperand(receiver, HeapObject::kMapOffset), r0); | |
| 205 __ RecordWriteField(receiver, HeapObject::kMapOffset, target_map, scratch2, | |
| 206 kLRHasBeenSaved, kDontSaveFPRegs, OMIT_REMEMBERED_SET, | |
| 207 OMIT_SMI_CHECK); | |
| 208 // Replace receiver's backing store with newly created FixedDoubleArray. | |
| 209 __ addi(scratch1, array, Operand(kHeapObjectTag)); | |
| 210 __ StoreP(scratch1, FieldMemOperand(receiver, JSObject::kElementsOffset), r0); | |
| 211 __ RecordWriteField(receiver, JSObject::kElementsOffset, scratch1, scratch2, | |
| 212 kLRHasBeenSaved, kDontSaveFPRegs, EMIT_REMEMBERED_SET, | |
| 213 OMIT_SMI_CHECK); | |
| 214 | |
| 215 // Prepare for conversion loop. | |
| 216 __ addi(target_map, elements, | |
| 217 Operand(FixedArray::kHeaderSize - kHeapObjectTag)); | |
| 218 __ addi(r10, array, Operand(FixedDoubleArray::kHeaderSize)); | |
| 219 __ SmiToDoubleArrayOffset(array, length); | |
| 220 __ add(array_end, r10, array); | |
| 221 // Repurpose registers no longer in use. | |
| 222 #if V8_TARGET_ARCH_PPC64 | |
| 223 Register hole_int64 = elements; | |
| 224 #else | |
| 225 Register hole_lower = elements; | |
| 226 Register hole_upper = length; | |
| 227 #endif | |
| 228 // scratch1: begin of source FixedArray element fields, not tagged | |
| 229 // hole_lower: kHoleNanLower32 OR hol_int64 | |
| 230 // hole_upper: kHoleNanUpper32 | |
| 231 // array_end: end of destination FixedDoubleArray, not tagged | |
| 232 // scratch2: begin of FixedDoubleArray element fields, not tagged | |
| 233 | |
| 234 __ b(&entry); | |
| 235 | |
| 236 __ bind(&only_change_map); | |
| 237 __ StoreP(target_map, FieldMemOperand(receiver, HeapObject::kMapOffset), r0); | |
| 238 __ RecordWriteField(receiver, HeapObject::kMapOffset, target_map, scratch2, | |
| 239 kLRHasNotBeenSaved, kDontSaveFPRegs, OMIT_REMEMBERED_SET, | |
| 240 OMIT_SMI_CHECK); | |
| 241 __ b(&done); | |
| 242 | |
| 243 // Call into runtime if GC is required. | |
| 244 __ bind(&gc_required); | |
| 245 __ Pop(r0); | |
| 246 __ mtlr(r0); | |
| 247 __ b(fail); | |
| 248 | |
| 249 // Convert and copy elements. | |
| 250 __ bind(&loop); | |
| 251 __ LoadP(r11, MemOperand(scratch1)); | |
| 252 __ addi(scratch1, scratch1, Operand(kPointerSize)); | |
| 253 // r11: current element | |
| 254 __ UntagAndJumpIfNotSmi(r11, r11, &convert_hole); | |
| 255 | |
| 256 // Normal smi, convert to double and store. | |
| 257 __ ConvertIntToDouble(r11, d0); | |
| 258 __ stfd(d0, MemOperand(scratch2, 0)); | |
| 259 __ addi(r10, r10, Operand(8)); | |
| 260 | |
| 261 __ b(&entry); | |
| 262 | |
| 263 // Hole found, store the-hole NaN. | |
| 264 __ bind(&convert_hole); | |
| 265 if (FLAG_debug_code) { | |
| 266 // Restore a "smi-untagged" heap object. | |
| 267 __ LoadP(r11, MemOperand(r6, -kPointerSize)); | |
| 268 __ CompareRoot(r11, Heap::kTheHoleValueRootIndex); | |
| 269 __ Assert(eq, kObjectFoundInSmiOnlyArray); | |
| 270 } | |
| 271 #if V8_TARGET_ARCH_PPC64 | |
| 272 __ std(hole_int64, MemOperand(r10, 0)); | |
| 273 #else | |
| 274 __ stw(hole_upper, MemOperand(r10, Register::kExponentOffset)); | |
| 275 __ stw(hole_lower, MemOperand(r10, Register::kMantissaOffset)); | |
| 276 #endif | |
| 277 __ addi(r10, r10, Operand(8)); | |
| 278 | |
| 279 __ bind(&entry); | |
| 280 __ cmp(r10, array_end); | |
| 281 __ blt(&loop); | |
| 282 | |
| 283 __ Pop(r0); | |
| 284 __ mtlr(r0); | |
| 285 __ bind(&done); | |
| 286 } | |
| 287 | |
| 288 | |
| 289 void ElementsTransitionGenerator::GenerateDoubleToObject( | |
| 290 MacroAssembler* masm, Register receiver, Register key, Register value, | |
| 291 Register target_map, AllocationSiteMode mode, Label* fail) { | |
| 292 // Register lr contains the return address. | |
| 293 Label entry, loop, convert_hole, gc_required, only_change_map; | |
| 294 Register elements = r7; | |
| 295 Register array = r9; | |
| 296 Register length = r8; | |
| 297 Register scratch = r11; | |
| 298 | |
| 299 // Verify input registers don't conflict with locals. | |
| 300 DCHECK(!AreAliased(receiver, key, value, target_map, elements, array, length, | |
| 301 scratch)); | |
| 302 | |
| 303 if (mode == TRACK_ALLOCATION_SITE) { | |
| 304 __ JumpIfJSArrayHasAllocationMemento(receiver, elements, fail); | |
| 305 } | |
| 306 | |
| 307 // Check for empty arrays, which only require a map transition and no changes | |
| 308 // to the backing store. | |
| 309 __ LoadP(elements, FieldMemOperand(receiver, JSObject::kElementsOffset)); | |
| 310 __ CompareRoot(elements, Heap::kEmptyFixedArrayRootIndex); | |
| 311 __ beq(&only_change_map); | |
| 312 | |
| 313 __ Push(target_map, receiver, key, value); | |
| 314 __ LoadP(length, FieldMemOperand(elements, FixedArray::kLengthOffset)); | |
| 315 // elements: source FixedDoubleArray | |
| 316 // length: number of elements (smi-tagged) | |
| 317 | |
| 318 // Allocate new FixedArray. | |
| 319 // Re-use value and target_map registers, as they have been saved on the | |
| 320 // stack. | |
| 321 Register array_size = value; | |
| 322 Register allocate_scratch = target_map; | |
| 323 __ li(array_size, Operand(FixedDoubleArray::kHeaderSize)); | |
| 324 __ SmiToPtrArrayOffset(r0, length); | |
| 325 __ add(array_size, array_size, r0); | |
| 326 __ Allocate(array_size, array, allocate_scratch, scratch, &gc_required, | |
| 327 NO_ALLOCATION_FLAGS); | |
| 328 // array: destination FixedArray, not tagged as heap object | |
| 329 // Set destination FixedDoubleArray's length and map. | |
| 330 __ LoadRoot(scratch, Heap::kFixedArrayMapRootIndex); | |
| 331 __ StoreP(length, MemOperand(array, FixedDoubleArray::kLengthOffset)); | |
| 332 __ StoreP(scratch, MemOperand(array, HeapObject::kMapOffset)); | |
| 333 | |
| 334 // Prepare for conversion loop. | |
| 335 Register src_elements = elements; | |
| 336 Register dst_elements = target_map; | |
| 337 Register dst_end = length; | |
| 338 Register heap_number_map = scratch; | |
| 339 __ addi(src_elements, elements, | |
| 340 Operand(FixedDoubleArray::kHeaderSize - kHeapObjectTag)); | |
| 341 __ addi(dst_elements, array, Operand(FixedArray::kHeaderSize)); | |
| 342 __ addi(array, array, Operand(kHeapObjectTag)); | |
| 343 __ SmiToPtrArrayOffset(length, length); | |
| 344 __ add(dst_end, dst_elements, length); | |
| 345 __ LoadRoot(r10, Heap::kTheHoleValueRootIndex); | |
| 346 __ LoadRoot(heap_number_map, Heap::kHeapNumberMapRootIndex); | |
| 347 // Using offsetted addresses in src_elements to fully take advantage of | |
| 348 // post-indexing. | |
| 349 // dst_elements: begin of destination FixedArray element fields, not tagged | |
| 350 // src_elements: begin of source FixedDoubleArray element fields, | |
| 351 // not tagged, +4 | |
| 352 // dst_end: end of destination FixedArray, not tagged | |
| 353 // array: destination FixedArray | |
| 354 // r10: the-hole pointer | |
| 355 // heap_number_map: heap number map | |
| 356 __ b(&entry); | |
| 357 | |
| 358 // Call into runtime if GC is required. | |
| 359 __ bind(&gc_required); | |
| 360 __ Pop(target_map, receiver, key, value); | |
| 361 __ b(fail); | |
| 362 | |
| 363 __ bind(&loop); | |
| 364 Register upper_bits = key; | |
| 365 __ lwz(upper_bits, MemOperand(src_elements, Register::kExponentOffset)); | |
| 366 __ addi(src_elements, src_elements, Operand(kDoubleSize)); | |
| 367 // upper_bits: current element's upper 32 bit | |
| 368 // src_elements: address of next element's upper 32 bit | |
| 369 __ Cmpi(upper_bits, Operand(kHoleNanUpper32), r0); | |
| 370 __ beq(&convert_hole); | |
| 371 | |
| 372 // Non-hole double, copy value into a heap number. | |
| 373 Register heap_number = receiver; | |
| 374 Register scratch2 = value; | |
| 375 __ AllocateHeapNumber(heap_number, scratch2, r11, heap_number_map, | |
| 376 &gc_required); | |
| 377 // heap_number: new heap number | |
|
danno
2014/10/20 08:28:43
Indentation?
andrew_low
2014/11/07 18:03:17
Done.
| |
| 378 #if V8_TARGET_ARCH_PPC64 | |
| 379 __ ld(scratch2, MemOperand(src_elements, -kDoubleSize)); | |
| 380 __ addi(upper_bits, heap_number, Operand(-1)); // subtract tag for std | |
| 381 __ std(scratch2, MemOperand(upper_bits, HeapNumber::kValueOffset)); | |
| 382 #else | |
| 383 __ lwz(scratch2, | |
| 384 MemOperand(src_elements, Register::kMantissaOffset - kDoubleSize)); | |
| 385 __ lwz(upper_bits, | |
| 386 MemOperand(src_elements, Register::kExponentOffset - kDoubleSize)); | |
| 387 __ stw(scratch2, FieldMemOperand(heap_number, HeapNumber::kMantissaOffset)); | |
| 388 __ stw(upper_bits, FieldMemOperand(heap_number, HeapNumber::kExponentOffset)); | |
| 389 #endif | |
| 390 __ mr(scratch2, dst_elements); | |
| 391 __ StoreP(heap_number, MemOperand(dst_elements)); | |
| 392 __ addi(dst_elements, dst_elements, Operand(kPointerSize)); | |
| 393 __ RecordWrite(array, scratch2, heap_number, kLRHasNotBeenSaved, | |
| 394 kDontSaveFPRegs, EMIT_REMEMBERED_SET, OMIT_SMI_CHECK); | |
| 395 __ b(&entry); | |
| 396 | |
| 397 // Replace the-hole NaN with the-hole pointer. | |
| 398 __ bind(&convert_hole); | |
| 399 __ StoreP(r10, MemOperand(dst_elements)); | |
| 400 __ addi(dst_elements, dst_elements, Operand(kPointerSize)); | |
| 401 | |
| 402 __ bind(&entry); | |
| 403 __ cmpl(dst_elements, dst_end); | |
| 404 __ blt(&loop); | |
| 405 | |
| 406 __ Pop(target_map, receiver, key, value); | |
| 407 // Replace receiver's backing store with newly created and filled FixedArray. | |
| 408 __ StoreP(array, FieldMemOperand(receiver, JSObject::kElementsOffset), r0); | |
| 409 __ RecordWriteField(receiver, JSObject::kElementsOffset, array, scratch, | |
| 410 kLRHasNotBeenSaved, kDontSaveFPRegs, EMIT_REMEMBERED_SET, | |
| 411 OMIT_SMI_CHECK); | |
| 412 | |
| 413 __ bind(&only_change_map); | |
| 414 // Update receiver's map. | |
| 415 __ StoreP(target_map, FieldMemOperand(receiver, HeapObject::kMapOffset), r0); | |
| 416 __ RecordWriteField(receiver, HeapObject::kMapOffset, target_map, scratch, | |
| 417 kLRHasNotBeenSaved, kDontSaveFPRegs, OMIT_REMEMBERED_SET, | |
| 418 OMIT_SMI_CHECK); | |
| 419 } | |
| 420 | |
| 421 | |
| 422 // assume ip can be used as a scratch register below | |
| 423 void StringCharLoadGenerator::Generate(MacroAssembler* masm, Register string, | |
| 424 Register index, Register result, | |
| 425 Label* call_runtime) { | |
| 426 // Fetch the instance type of the receiver into result register. | |
| 427 __ LoadP(result, FieldMemOperand(string, HeapObject::kMapOffset)); | |
| 428 __ lbz(result, FieldMemOperand(result, Map::kInstanceTypeOffset)); | |
| 429 | |
| 430 // We need special handling for indirect strings. | |
| 431 Label check_sequential; | |
| 432 __ andi(r0, result, Operand(kIsIndirectStringMask)); | |
| 433 __ beq(&check_sequential, cr0); | |
| 434 | |
| 435 // Dispatch on the indirect string shape: slice or cons. | |
| 436 Label cons_string; | |
| 437 __ mov(ip, Operand(kSlicedNotConsMask)); | |
| 438 __ and_(r0, result, ip, SetRC); | |
| 439 __ beq(&cons_string, cr0); | |
| 440 | |
| 441 // Handle slices. | |
| 442 Label indirect_string_loaded; | |
| 443 __ LoadP(result, FieldMemOperand(string, SlicedString::kOffsetOffset)); | |
| 444 __ LoadP(string, FieldMemOperand(string, SlicedString::kParentOffset)); | |
| 445 __ SmiUntag(ip, result); | |
| 446 __ add(index, index, ip); | |
| 447 __ b(&indirect_string_loaded); | |
| 448 | |
| 449 // Handle cons strings. | |
| 450 // Check whether the right hand side is the empty string (i.e. if | |
| 451 // this is really a flat string in a cons string). If that is not | |
| 452 // the case we would rather go to the runtime system now to flatten | |
| 453 // the string. | |
| 454 __ bind(&cons_string); | |
| 455 __ LoadP(result, FieldMemOperand(string, ConsString::kSecondOffset)); | |
| 456 __ CompareRoot(result, Heap::kempty_stringRootIndex); | |
| 457 __ bne(call_runtime); | |
| 458 // Get the first of the two strings and load its instance type. | |
| 459 __ LoadP(string, FieldMemOperand(string, ConsString::kFirstOffset)); | |
| 460 | |
| 461 __ bind(&indirect_string_loaded); | |
| 462 __ LoadP(result, FieldMemOperand(string, HeapObject::kMapOffset)); | |
| 463 __ lbz(result, FieldMemOperand(result, Map::kInstanceTypeOffset)); | |
| 464 | |
| 465 // Distinguish sequential and external strings. Only these two string | |
| 466 // representations can reach here (slices and flat cons strings have been | |
| 467 // reduced to the underlying sequential or external string). | |
| 468 Label external_string, check_encoding; | |
| 469 __ bind(&check_sequential); | |
| 470 STATIC_ASSERT(kSeqStringTag == 0); | |
| 471 __ andi(r0, result, Operand(kStringRepresentationMask)); | |
| 472 __ bne(&external_string, cr0); | |
| 473 | |
| 474 // Prepare sequential strings | |
| 475 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize); | |
| 476 __ addi(string, string, | |
| 477 Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); | |
| 478 __ b(&check_encoding); | |
| 479 | |
| 480 // Handle external strings. | |
| 481 __ bind(&external_string); | |
| 482 if (FLAG_debug_code) { | |
| 483 // Assert that we do not have a cons or slice (indirect strings) here. | |
| 484 // Sequential strings have already been ruled out. | |
| 485 __ andi(r0, result, Operand(kIsIndirectStringMask)); | |
| 486 __ Assert(eq, kExternalStringExpectedButNotFound, cr0); | |
| 487 } | |
| 488 // Rule out short external strings. | |
| 489 STATIC_ASSERT(kShortExternalStringTag != 0); | |
| 490 __ andi(r0, result, Operand(kShortExternalStringMask)); | |
| 491 __ bne(call_runtime, cr0); | |
| 492 __ LoadP(string, | |
| 493 FieldMemOperand(string, ExternalString::kResourceDataOffset)); | |
| 494 | |
| 495 Label one_byte, done; | |
| 496 __ bind(&check_encoding); | |
| 497 STATIC_ASSERT(kTwoByteStringTag == 0); | |
| 498 __ andi(r0, result, Operand(kStringEncodingMask)); | |
| 499 __ bne(&one_byte, cr0); | |
| 500 // Two-byte string. | |
| 501 __ ShiftLeftImm(result, index, Operand(1)); | |
| 502 __ lhzx(result, MemOperand(string, result)); | |
| 503 __ b(&done); | |
| 504 __ bind(&one_byte); | |
| 505 // One-byte string. | |
| 506 __ lbzx(result, MemOperand(string, index)); | |
| 507 __ bind(&done); | |
| 508 } | |
| 509 | |
| 510 | |
| 511 static MemOperand ExpConstant(int index, Register base) { | |
| 512 return MemOperand(base, index * kDoubleSize); | |
| 513 } | |
| 514 | |
| 515 | |
| 516 void MathExpGenerator::EmitMathExp(MacroAssembler* masm, DoubleRegister input, | |
| 517 DoubleRegister result, | |
| 518 DoubleRegister double_scratch1, | |
| 519 DoubleRegister double_scratch2, | |
| 520 Register temp1, Register temp2, | |
| 521 Register temp3) { | |
| 522 DCHECK(!input.is(result)); | |
| 523 DCHECK(!input.is(double_scratch1)); | |
| 524 DCHECK(!input.is(double_scratch2)); | |
| 525 DCHECK(!result.is(double_scratch1)); | |
| 526 DCHECK(!result.is(double_scratch2)); | |
| 527 DCHECK(!double_scratch1.is(double_scratch2)); | |
| 528 DCHECK(!temp1.is(temp2)); | |
| 529 DCHECK(!temp1.is(temp3)); | |
| 530 DCHECK(!temp2.is(temp3)); | |
| 531 DCHECK(ExternalReference::math_exp_constants(0).address() != NULL); | |
| 532 DCHECK(!masm->serializer_enabled()); // External references not serializable. | |
| 533 | |
| 534 Label zero, infinity, done; | |
| 535 | |
| 536 __ mov(temp3, Operand(ExternalReference::math_exp_constants(0))); | |
| 537 | |
| 538 __ lfd(double_scratch1, ExpConstant(0, temp3)); | |
| 539 __ fcmpu(double_scratch1, input); | |
| 540 __ fmr(result, input); | |
| 541 __ bunordered(&done); | |
| 542 __ bge(&zero); | |
| 543 | |
| 544 __ lfd(double_scratch2, ExpConstant(1, temp3)); | |
| 545 __ fcmpu(input, double_scratch2); | |
| 546 __ bge(&infinity); | |
| 547 | |
| 548 __ lfd(double_scratch1, ExpConstant(3, temp3)); | |
| 549 __ lfd(result, ExpConstant(4, temp3)); | |
| 550 __ fmul(double_scratch1, double_scratch1, input); | |
| 551 __ fadd(double_scratch1, double_scratch1, result); | |
| 552 __ MovDoubleLowToInt(temp2, double_scratch1); | |
| 553 __ fsub(double_scratch1, double_scratch1, result); | |
| 554 __ lfd(result, ExpConstant(6, temp3)); | |
| 555 __ lfd(double_scratch2, ExpConstant(5, temp3)); | |
| 556 __ fmul(double_scratch1, double_scratch1, double_scratch2); | |
| 557 __ fsub(double_scratch1, double_scratch1, input); | |
| 558 __ fsub(result, result, double_scratch1); | |
| 559 __ fmul(double_scratch2, double_scratch1, double_scratch1); | |
| 560 __ fmul(result, result, double_scratch2); | |
| 561 __ lfd(double_scratch2, ExpConstant(7, temp3)); | |
| 562 __ fmul(result, result, double_scratch2); | |
| 563 __ fsub(result, result, double_scratch1); | |
| 564 __ lfd(double_scratch2, ExpConstant(8, temp3)); | |
| 565 __ fadd(result, result, double_scratch2); | |
| 566 __ srwi(temp1, temp2, Operand(11)); | |
| 567 __ andi(temp2, temp2, Operand(0x7ff)); | |
| 568 __ addi(temp1, temp1, Operand(0x3ff)); | |
| 569 | |
| 570 // Must not call ExpConstant() after overwriting temp3! | |
| 571 __ mov(temp3, Operand(ExternalReference::math_exp_log_table())); | |
| 572 __ slwi(temp2, temp2, Operand(3)); | |
| 573 #if V8_TARGET_ARCH_PPC64 | |
| 574 __ ldx(temp2, MemOperand(temp3, temp2)); | |
| 575 __ sldi(temp1, temp1, Operand(52)); | |
| 576 __ orx(temp2, temp1, temp2); | |
| 577 __ MovInt64ToDouble(double_scratch1, temp2); | |
| 578 #else | |
| 579 __ add(ip, temp3, temp2); | |
| 580 __ lwz(temp3, MemOperand(ip, Register::kExponentOffset)); | |
| 581 __ lwz(temp2, MemOperand(ip, Register::kMantissaOffset)); | |
| 582 __ slwi(temp1, temp1, Operand(20)); | |
| 583 __ orx(temp3, temp1, temp3); | |
| 584 __ MovInt64ToDouble(double_scratch1, temp3, temp2); | |
| 585 #endif | |
| 586 | |
| 587 __ fmul(result, result, double_scratch1); | |
| 588 __ b(&done); | |
| 589 | |
| 590 __ bind(&zero); | |
| 591 __ fmr(result, kDoubleRegZero); | |
| 592 __ b(&done); | |
| 593 | |
| 594 __ bind(&infinity); | |
| 595 __ lfd(result, ExpConstant(2, temp3)); | |
| 596 | |
| 597 __ bind(&done); | |
| 598 } | |
| 599 | |
| 600 #undef __ | |
| 601 | |
| 602 CodeAgingHelper::CodeAgingHelper() { | |
| 603 DCHECK(young_sequence_.length() == kNoCodeAgeSequenceLength); | |
| 604 // Since patcher is a large object, allocate it dynamically when needed, | |
| 605 // to avoid overloading the stack in stress conditions. | |
| 606 // DONT_FLUSH is used because the CodeAgingHelper is initialized early in | |
| 607 // the process, before ARM simulator ICache is setup. | |
| 608 SmartPointer<CodePatcher> patcher(new CodePatcher( | |
| 609 young_sequence_.start(), young_sequence_.length() / Assembler::kInstrSize, | |
| 610 CodePatcher::DONT_FLUSH)); | |
| 611 PredictableCodeSizeScope scope(patcher->masm(), young_sequence_.length()); | |
| 612 patcher->masm()->PushFixedFrame(r4); | |
| 613 patcher->masm()->addi(fp, sp, | |
| 614 Operand(StandardFrameConstants::kFixedFrameSizeFromFp)); | |
| 615 for (int i = 0; i < kNoCodeAgeSequenceNops; i++) { | |
| 616 patcher->masm()->nop(); | |
| 617 } | |
| 618 } | |
| 619 | |
| 620 | |
| 621 #ifdef DEBUG | |
| 622 bool CodeAgingHelper::IsOld(byte* candidate) const { | |
| 623 return Assembler::IsNop(Assembler::instr_at(candidate)); | |
| 624 } | |
| 625 #endif | |
| 626 | |
| 627 | |
| 628 bool Code::IsYoungSequence(Isolate* isolate, byte* sequence) { | |
| 629 bool result = isolate->code_aging_helper()->IsYoung(sequence); | |
| 630 DCHECK(result || isolate->code_aging_helper()->IsOld(sequence)); | |
| 631 return result; | |
| 632 } | |
| 633 | |
| 634 | |
| 635 void Code::GetCodeAgeAndParity(Isolate* isolate, byte* sequence, Age* age, | |
| 636 MarkingParity* parity) { | |
| 637 if (IsYoungSequence(isolate, sequence)) { | |
| 638 *age = kNoAgeCodeAge; | |
| 639 *parity = NO_MARKING_PARITY; | |
| 640 } else { | |
| 641 ConstantPoolArray* constant_pool = NULL; | |
| 642 Address target_address = Assembler::target_address_at( | |
| 643 sequence + kCodeAgingTargetDelta, constant_pool); | |
| 644 Code* stub = GetCodeFromTargetAddress(target_address); | |
| 645 GetCodeAgeAndParity(stub, age, parity); | |
| 646 } | |
| 647 } | |
| 648 | |
| 649 | |
| 650 void Code::PatchPlatformCodeAge(Isolate* isolate, byte* sequence, Code::Age age, | |
| 651 MarkingParity parity) { | |
| 652 uint32_t young_length = isolate->code_aging_helper()->young_sequence_length(); | |
| 653 if (age == kNoAgeCodeAge) { | |
| 654 isolate->code_aging_helper()->CopyYoungSequenceTo(sequence); | |
| 655 CpuFeatures::FlushICache(sequence, young_length); | |
| 656 } else { | |
| 657 // FIXED_SEQUENCE | |
| 658 Code* stub = GetCodeAgeStub(isolate, age, parity); | |
| 659 CodePatcher patcher(sequence, young_length / Assembler::kInstrSize); | |
| 660 Assembler::BlockTrampolinePoolScope block_trampoline_pool(patcher.masm()); | |
| 661 intptr_t target = reinterpret_cast<intptr_t>(stub->instruction_start()); | |
| 662 // Don't use Call -- we need to preserve ip and lr. | |
| 663 // GenerateMakeCodeYoungAgainCommon for the stub code. | |
| 664 patcher.masm()->nop(); // marker to detect sequence (see IsOld) | |
| 665 patcher.masm()->mov(r3, Operand(target)); | |
| 666 patcher.masm()->Jump(r3); | |
| 667 for (int i = 0; i < kCodeAgingSequenceNops; i++) { | |
| 668 patcher.masm()->nop(); | |
| 669 } | |
| 670 } | |
| 671 } | |
| 672 } | |
| 673 } // namespace v8::internal | |
| 674 | |
| 675 #endif // V8_TARGET_ARCH_PPC | |
| OLD | NEW |