Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Side by Side Diff: src/x64/codegen-x64.cc

Issue 11418149: Faster implementation of Math.exp() (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: fix Win build Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/x64/codegen-x64.h ('k') | src/x64/lithium-codegen-x64.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 CodeDesc desc; 92 CodeDesc desc;
93 masm.GetCode(&desc); 93 masm.GetCode(&desc);
94 ASSERT(desc.reloc_size == 0); 94 ASSERT(desc.reloc_size == 0);
95 95
96 CPU::FlushICache(buffer, actual_size); 96 CPU::FlushICache(buffer, actual_size);
97 OS::ProtectCode(buffer, actual_size); 97 OS::ProtectCode(buffer, actual_size);
98 return FUNCTION_CAST<UnaryMathFunction>(buffer); 98 return FUNCTION_CAST<UnaryMathFunction>(buffer);
99 } 99 }
100 100
101 101
102 UnaryMathFunction CreateExpFunction() {
103 if (!FLAG_fast_math) return &exp;
104 size_t actual_size;
105 byte* buffer = static_cast<byte*>(OS::Allocate(1 * KB, &actual_size, true));
106 if (buffer == NULL) return &exp;
107 ExternalReference::InitializeMathExpData();
108
109 MacroAssembler masm(NULL, buffer, static_cast<int>(actual_size));
110 // xmm0: raw double input.
111 XMMRegister input = xmm0;
112 XMMRegister result = xmm1;
113 __ push(rax);
114 __ push(rbx);
115
116 MathExpGenerator::EmitMathExp(&masm, input, result, xmm2, rax, rbx);
117
118 __ pop(rbx);
119 __ pop(rax);
120 __ movsd(xmm0, result);
121 __ Ret();
122
123 CodeDesc desc;
124 masm.GetCode(&desc);
125
126 CPU::FlushICache(buffer, actual_size);
127 OS::ProtectCode(buffer, actual_size);
128 return FUNCTION_CAST<UnaryMathFunction>(buffer);
129 }
130
131
102 UnaryMathFunction CreateSqrtFunction() { 132 UnaryMathFunction CreateSqrtFunction() {
103 size_t actual_size; 133 size_t actual_size;
104 // Allocate buffer in executable space. 134 // Allocate buffer in executable space.
105 byte* buffer = static_cast<byte*>(OS::Allocate(1 * KB, 135 byte* buffer = static_cast<byte*>(OS::Allocate(1 * KB,
106 &actual_size, 136 &actual_size,
107 true)); 137 true));
108 if (buffer == NULL) return &sqrt; 138 if (buffer == NULL) return &sqrt;
109 139
110 MacroAssembler masm(NULL, buffer, static_cast<int>(actual_size)); 140 MacroAssembler masm(NULL, buffer, static_cast<int>(actual_size));
111 // xmm0: raw double input. 141 // xmm0: raw double input.
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 // ASCII string. 598 // ASCII string.
569 // Load the byte into the result register. 599 // Load the byte into the result register.
570 __ bind(&ascii); 600 __ bind(&ascii);
571 __ movzxbl(result, FieldOperand(string, 601 __ movzxbl(result, FieldOperand(string,
572 index, 602 index,
573 times_1, 603 times_1,
574 SeqOneByteString::kHeaderSize)); 604 SeqOneByteString::kHeaderSize));
575 __ bind(&done); 605 __ bind(&done);
576 } 606 }
577 607
608
609 void MathExpGenerator::EmitMathExp(MacroAssembler* masm,
610 XMMRegister input,
611 XMMRegister result,
612 XMMRegister double_scratch,
613 Register temp1,
614 Register temp2) {
615 ASSERT(!input.is(result));
616 ASSERT(!input.is(double_scratch));
617 ASSERT(!result.is(double_scratch));
618 ASSERT(!temp1.is(temp2));
619 ASSERT(ExternalReference::math_exp_constants(0).address() != NULL);
620
621 Label done;
622
623 __ movq(kScratchRegister, ExternalReference::math_exp_constants(0));
624 __ movsd(double_scratch, Operand(kScratchRegister, 0 * kDoubleSize));
625 __ xorpd(result, result);
626 __ ucomisd(double_scratch, input);
627 __ j(above_equal, &done);
628 __ ucomisd(input, Operand(kScratchRegister, 1 * kDoubleSize));
629 __ movsd(result, Operand(kScratchRegister, 2 * kDoubleSize));
630 __ j(above_equal, &done);
631 __ movsd(double_scratch, Operand(kScratchRegister, 3 * kDoubleSize));
632 __ movsd(result, Operand(kScratchRegister, 4 * kDoubleSize));
633 __ mulsd(double_scratch, input);
634 __ addsd(double_scratch, result);
635 __ movq(temp2, double_scratch);
636 __ subsd(double_scratch, result);
637 __ movsd(result, Operand(kScratchRegister, 6 * kDoubleSize));
638 __ lea(temp1, Operand(temp2, 0x1ff800));
639 __ and_(temp2, Immediate(0x7ff));
640 __ shr(temp1, Immediate(11));
641 __ mulsd(double_scratch, Operand(kScratchRegister, 5 * kDoubleSize));
642 __ movq(kScratchRegister, ExternalReference::math_exp_log_table());
643 __ shl(temp1, Immediate(52));
644 __ or_(temp1, Operand(kScratchRegister, temp2, times_8, 0));
645 __ movq(kScratchRegister, ExternalReference::math_exp_constants(0));
646 __ subsd(double_scratch, input);
647 __ movsd(input, double_scratch);
648 __ subsd(result, double_scratch);
649 __ mulsd(input, double_scratch);
650 __ mulsd(result, input);
651 __ movq(input, temp1);
652 __ mulsd(result, Operand(kScratchRegister, 7 * kDoubleSize));
653 __ subsd(result, double_scratch);
654 __ addsd(result, Operand(kScratchRegister, 8 * kDoubleSize));
655 __ mulsd(result, input);
656
657 __ bind(&done);
658 }
659
578 #undef __ 660 #undef __
579 661
580 662
581 static const int kNoCodeAgeSequenceLength = 6; 663 static const int kNoCodeAgeSequenceLength = 6;
582 664
583 static byte* GetNoCodeAgeSequence(uint32_t* length) { 665 static byte* GetNoCodeAgeSequence(uint32_t* length) {
584 static bool initialized = false; 666 static bool initialized = false;
585 static byte sequence[kNoCodeAgeSequenceLength]; 667 static byte sequence[kNoCodeAgeSequenceLength];
586 *length = kNoCodeAgeSequenceLength; 668 *length = kNoCodeAgeSequenceLength;
587 if (!initialized) { 669 if (!initialized) {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 CodePatcher patcher(sequence, young_length); 740 CodePatcher patcher(sequence, young_length);
659 patcher.masm()->call(stub->instruction_start()); 741 patcher.masm()->call(stub->instruction_start());
660 patcher.masm()->nop(); 742 patcher.masm()->nop();
661 } 743 }
662 } 744 }
663 745
664 746
665 } } // namespace v8::internal 747 } } // namespace v8::internal
666 748
667 #endif // V8_TARGET_ARCH_X64 749 #endif // V8_TARGET_ARCH_X64
OLDNEW
« no previous file with comments | « src/x64/codegen-x64.h ('k') | src/x64/lithium-codegen-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698