OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/ppc/codegen-ppc.h" | 5 #include "src/ppc/codegen-ppc.h" |
6 | 6 |
7 #if V8_TARGET_ARCH_PPC | 7 #if V8_TARGET_ARCH_PPC |
8 | 8 |
9 #include "src/codegen.h" | 9 #include "src/codegen.h" |
10 #include "src/macro-assembler.h" | 10 #include "src/macro-assembler.h" |
11 #include "src/ppc/simulator-ppc.h" | 11 #include "src/ppc/simulator-ppc.h" |
12 | 12 |
13 namespace v8 { | 13 namespace v8 { |
14 namespace internal { | 14 namespace internal { |
15 | 15 |
16 | 16 |
17 #define __ masm. | 17 #define __ masm. |
18 | 18 |
19 | |
20 #if defined(USE_SIMULATOR) | |
21 byte* fast_exp_ppc_machine_code = nullptr; | |
22 double fast_exp_simulator(double x, Isolate* isolate) { | |
23 return Simulator::current(isolate) | |
24 ->CallFPReturnsDouble(fast_exp_ppc_machine_code, x, 0); | |
25 } | |
26 #endif | |
27 | |
28 | |
29 UnaryMathFunctionWithIsolate CreateExpFunction(Isolate* isolate) { | |
30 size_t actual_size; | |
31 byte* buffer = | |
32 static_cast<byte*>(base::OS::Allocate(1 * KB, &actual_size, true)); | |
33 if (buffer == nullptr) return nullptr; | |
34 ExternalReference::InitializeMathExpData(); | |
35 | |
36 MacroAssembler masm(isolate, buffer, static_cast<int>(actual_size), | |
37 CodeObjectRequired::kNo); | |
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 __ function_descriptor(); | |
50 | |
51 __ Push(temp3, temp2, temp1); | |
52 MathExpGenerator::EmitMathExp(&masm, input, result, double_scratch1, | |
53 double_scratch2, temp1, temp2, temp3); | |
54 __ Pop(temp3, temp2, temp1); | |
55 __ fmr(d1, result); | |
56 __ Ret(); | |
57 } | |
58 | |
59 CodeDesc desc; | |
60 masm.GetCode(&desc); | |
61 DCHECK(ABI_USES_FUNCTION_DESCRIPTORS || !RelocInfo::RequiresRelocation(desc)); | |
62 | |
63 Assembler::FlushICache(isolate, buffer, actual_size); | |
64 base::OS::ProtectCode(buffer, actual_size); | |
65 | |
66 #if !defined(USE_SIMULATOR) | |
67 return FUNCTION_CAST<UnaryMathFunctionWithIsolate>(buffer); | |
68 #else | |
69 fast_exp_ppc_machine_code = buffer; | |
70 return &fast_exp_simulator; | |
71 #endif | |
72 } | |
73 | |
74 | |
75 UnaryMathFunctionWithIsolate CreateSqrtFunction(Isolate* isolate) { | 19 UnaryMathFunctionWithIsolate CreateSqrtFunction(Isolate* isolate) { |
76 #if defined(USE_SIMULATOR) | 20 #if defined(USE_SIMULATOR) |
77 return nullptr; | 21 return nullptr; |
78 #else | 22 #else |
79 size_t actual_size; | 23 size_t actual_size; |
80 byte* buffer = | 24 byte* buffer = |
81 static_cast<byte*>(base::OS::Allocate(1 * KB, &actual_size, true)); | 25 static_cast<byte*>(base::OS::Allocate(1 * KB, &actual_size, true)); |
82 if (buffer == nullptr) return nullptr; | 26 if (buffer == nullptr) return nullptr; |
83 | 27 |
84 MacroAssembler masm(isolate, buffer, static_cast<int>(actual_size), | 28 MacroAssembler masm(isolate, buffer, static_cast<int>(actual_size), |
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 // Two-byte string. | 450 // Two-byte string. |
507 __ ShiftLeftImm(result, index, Operand(1)); | 451 __ ShiftLeftImm(result, index, Operand(1)); |
508 __ lhzx(result, MemOperand(string, result)); | 452 __ lhzx(result, MemOperand(string, result)); |
509 __ b(&done); | 453 __ b(&done); |
510 __ bind(&one_byte); | 454 __ bind(&one_byte); |
511 // One-byte string. | 455 // One-byte string. |
512 __ lbzx(result, MemOperand(string, index)); | 456 __ lbzx(result, MemOperand(string, index)); |
513 __ bind(&done); | 457 __ bind(&done); |
514 } | 458 } |
515 | 459 |
516 | |
517 static MemOperand ExpConstant(int index, Register base) { | |
518 return MemOperand(base, index * kDoubleSize); | |
519 } | |
520 | |
521 | |
522 void MathExpGenerator::EmitMathExp(MacroAssembler* masm, DoubleRegister input, | |
523 DoubleRegister result, | |
524 DoubleRegister double_scratch1, | |
525 DoubleRegister double_scratch2, | |
526 Register temp1, Register temp2, | |
527 Register temp3) { | |
528 DCHECK(!input.is(result)); | |
529 DCHECK(!input.is(double_scratch1)); | |
530 DCHECK(!input.is(double_scratch2)); | |
531 DCHECK(!result.is(double_scratch1)); | |
532 DCHECK(!result.is(double_scratch2)); | |
533 DCHECK(!double_scratch1.is(double_scratch2)); | |
534 DCHECK(!temp1.is(temp2)); | |
535 DCHECK(!temp1.is(temp3)); | |
536 DCHECK(!temp2.is(temp3)); | |
537 DCHECK(ExternalReference::math_exp_constants(0).address() != NULL); | |
538 DCHECK(!masm->serializer_enabled()); // External references not serializable. | |
539 | |
540 Label zero, infinity, done; | |
541 | |
542 __ mov(temp3, Operand(ExternalReference::math_exp_constants(0))); | |
543 | |
544 __ lfd(double_scratch1, ExpConstant(0, temp3)); | |
545 __ fcmpu(double_scratch1, input); | |
546 __ fmr(result, input); | |
547 __ bunordered(&done); | |
548 __ bge(&zero); | |
549 | |
550 __ lfd(double_scratch2, ExpConstant(1, temp3)); | |
551 __ fcmpu(input, double_scratch2); | |
552 __ bge(&infinity); | |
553 | |
554 __ lfd(double_scratch1, ExpConstant(3, temp3)); | |
555 __ lfd(result, ExpConstant(4, temp3)); | |
556 __ fmul(double_scratch1, double_scratch1, input); | |
557 __ fadd(double_scratch1, double_scratch1, result); | |
558 __ MovDoubleLowToInt(temp2, double_scratch1); | |
559 __ fsub(double_scratch1, double_scratch1, result); | |
560 __ lfd(result, ExpConstant(6, temp3)); | |
561 __ lfd(double_scratch2, ExpConstant(5, temp3)); | |
562 __ fmul(double_scratch1, double_scratch1, double_scratch2); | |
563 __ fsub(double_scratch1, double_scratch1, input); | |
564 __ fsub(result, result, double_scratch1); | |
565 __ fmul(double_scratch2, double_scratch1, double_scratch1); | |
566 __ fmul(result, result, double_scratch2); | |
567 __ lfd(double_scratch2, ExpConstant(7, temp3)); | |
568 __ fmul(result, result, double_scratch2); | |
569 __ fsub(result, result, double_scratch1); | |
570 __ lfd(double_scratch2, ExpConstant(8, temp3)); | |
571 __ fadd(result, result, double_scratch2); | |
572 __ srwi(temp1, temp2, Operand(11)); | |
573 __ andi(temp2, temp2, Operand(0x7ff)); | |
574 __ addi(temp1, temp1, Operand(0x3ff)); | |
575 | |
576 // Must not call ExpConstant() after overwriting temp3! | |
577 __ mov(temp3, Operand(ExternalReference::math_exp_log_table())); | |
578 __ slwi(temp2, temp2, Operand(3)); | |
579 #if V8_TARGET_ARCH_PPC64 | |
580 __ ldx(temp2, MemOperand(temp3, temp2)); | |
581 __ sldi(temp1, temp1, Operand(52)); | |
582 __ orx(temp2, temp1, temp2); | |
583 __ MovInt64ToDouble(double_scratch1, temp2); | |
584 #else | |
585 __ add(ip, temp3, temp2); | |
586 __ lwz(temp3, MemOperand(ip, Register::kExponentOffset)); | |
587 __ lwz(temp2, MemOperand(ip, Register::kMantissaOffset)); | |
588 __ slwi(temp1, temp1, Operand(20)); | |
589 __ orx(temp3, temp1, temp3); | |
590 __ MovInt64ToDouble(double_scratch1, temp3, temp2); | |
591 #endif | |
592 | |
593 __ fmul(result, result, double_scratch1); | |
594 __ b(&done); | |
595 | |
596 __ bind(&zero); | |
597 __ fmr(result, kDoubleRegZero); | |
598 __ b(&done); | |
599 | |
600 __ bind(&infinity); | |
601 __ lfd(result, ExpConstant(2, temp3)); | |
602 | |
603 __ bind(&done); | |
604 } | |
605 | |
606 #undef __ | 460 #undef __ |
607 | 461 |
608 CodeAgingHelper::CodeAgingHelper(Isolate* isolate) { | 462 CodeAgingHelper::CodeAgingHelper(Isolate* isolate) { |
609 USE(isolate); | 463 USE(isolate); |
610 DCHECK(young_sequence_.length() == kNoCodeAgeSequenceLength); | 464 DCHECK(young_sequence_.length() == kNoCodeAgeSequenceLength); |
611 // Since patcher is a large object, allocate it dynamically when needed, | 465 // Since patcher is a large object, allocate it dynamically when needed, |
612 // to avoid overloading the stack in stress conditions. | 466 // to avoid overloading the stack in stress conditions. |
613 // DONT_FLUSH is used because the CodeAgingHelper is initialized early in | 467 // DONT_FLUSH is used because the CodeAgingHelper is initialized early in |
614 // the process, before ARM simulator ICache is setup. | 468 // the process, before ARM simulator ICache is setup. |
615 base::SmartPointer<CodePatcher> patcher( | 469 base::SmartPointer<CodePatcher> patcher( |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
673 patcher.masm()->Jump(r3); | 527 patcher.masm()->Jump(r3); |
674 for (int i = 0; i < kCodeAgingSequenceNops; i++) { | 528 for (int i = 0; i < kCodeAgingSequenceNops; i++) { |
675 patcher.masm()->nop(); | 529 patcher.masm()->nop(); |
676 } | 530 } |
677 } | 531 } |
678 } | 532 } |
679 } // namespace internal | 533 } // namespace internal |
680 } // namespace v8 | 534 } // namespace v8 |
681 | 535 |
682 #endif // V8_TARGET_ARCH_PPC | 536 #endif // V8_TARGET_ARCH_PPC |
OLD | NEW |