OLD | NEW |
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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 | 47 |
48 void StubRuntimeCallHelper::AfterCall(MacroAssembler* masm) const { | 48 void StubRuntimeCallHelper::AfterCall(MacroAssembler* masm) const { |
49 masm->LeaveFrame(StackFrame::INTERNAL); | 49 masm->LeaveFrame(StackFrame::INTERNAL); |
50 ASSERT(masm->has_frame()); | 50 ASSERT(masm->has_frame()); |
51 masm->set_has_frame(false); | 51 masm->set_has_frame(false); |
52 } | 52 } |
53 | 53 |
54 | 54 |
55 #define __ masm. | 55 #define __ masm. |
56 | 56 |
57 | |
58 TranscendentalFunction CreateTranscendentalFunction( | |
59 TranscendentalCache::Type type) { | |
60 size_t actual_size; | |
61 // Allocate buffer in executable space. | |
62 byte* buffer = static_cast<byte*>(OS::Allocate(1 * KB, | |
63 &actual_size, | |
64 true)); | |
65 if (buffer == NULL) { | |
66 // Fallback to library function if function cannot be created. | |
67 switch (type) { | |
68 case TranscendentalCache::SIN: return &sin; | |
69 case TranscendentalCache::COS: return &cos; | |
70 case TranscendentalCache::TAN: return &tan; | |
71 case TranscendentalCache::LOG: return &log; | |
72 default: UNIMPLEMENTED(); | |
73 } | |
74 } | |
75 | |
76 MacroAssembler masm(NULL, buffer, static_cast<int>(actual_size)); | |
77 // xmm0: raw double input. | |
78 // Move double input into registers. | |
79 __ push(rbx); | |
80 __ push(rdi); | |
81 __ movq(rbx, xmm0); | |
82 __ push(rbx); | |
83 __ fld_d(Operand(rsp, 0)); | |
84 TranscendentalCacheStub::GenerateOperation(&masm, type); | |
85 // The return value is expected to be in xmm0. | |
86 __ fstp_d(Operand(rsp, 0)); | |
87 __ pop(rbx); | |
88 __ movq(xmm0, rbx); | |
89 __ pop(rdi); | |
90 __ pop(rbx); | |
91 __ Ret(); | |
92 | |
93 CodeDesc desc; | |
94 masm.GetCode(&desc); | |
95 ASSERT(desc.reloc_size == 0); | |
96 | |
97 CPU::FlushICache(buffer, actual_size); | |
98 OS::ProtectCode(buffer, actual_size); | |
99 return FUNCTION_CAST<TranscendentalFunction>(buffer); | |
100 } | |
101 | |
102 | |
103 #ifdef _WIN64 | 57 #ifdef _WIN64 |
104 typedef double (*ModuloFunction)(double, double); | 58 typedef double (*ModuloFunction)(double, double); |
105 // Define custom fmod implementation. | 59 // Define custom fmod implementation. |
106 ModuloFunction CreateModuloFunction() { | 60 ModuloFunction CreateModuloFunction() { |
107 size_t actual_size; | 61 size_t actual_size; |
108 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, | 62 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, |
109 &actual_size, | 63 &actual_size, |
110 true)); | 64 true)); |
111 CHECK(buffer); | 65 CHECK(buffer); |
112 Assembler masm(NULL, buffer, static_cast<int>(actual_size)); | 66 Assembler masm(NULL, buffer, static_cast<int>(actual_size)); |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 times_1, | 496 times_1, |
543 SeqAsciiString::kHeaderSize)); | 497 SeqAsciiString::kHeaderSize)); |
544 __ bind(&done); | 498 __ bind(&done); |
545 } | 499 } |
546 | 500 |
547 #undef __ | 501 #undef __ |
548 | 502 |
549 } } // namespace v8::internal | 503 } } // namespace v8::internal |
550 | 504 |
551 #endif // V8_TARGET_ARCH_X64 | 505 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |