Line data Source code
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 : #if V8_TARGET_ARCH_X64
6 :
7 : #include "src/codegen.h"
8 : #include "src/macro-assembler.h"
9 : #include "src/x64/assembler-x64-inl.h"
10 :
11 : namespace v8 {
12 : namespace internal {
13 :
14 : #define __ masm.
15 :
16 :
17 0 : UnaryMathFunctionWithIsolate CreateSqrtFunction(Isolate* isolate) {
18 : size_t actual_size;
19 : // Allocate buffer in executable space.
20 : byte* buffer = static_cast<byte*>(base::OS::Allocate(
21 0 : 1 * KB, &actual_size, true, isolate->heap()->GetRandomMmapAddr()));
22 0 : if (buffer == nullptr) return nullptr;
23 :
24 : MacroAssembler masm(isolate, buffer, static_cast<int>(actual_size),
25 0 : CodeObjectRequired::kNo);
26 : // xmm0: raw double input.
27 : // Move double input into registers.
28 0 : __ Sqrtsd(xmm0, xmm0);
29 0 : __ Ret();
30 :
31 : CodeDesc desc;
32 0 : masm.GetCode(isolate, &desc);
33 : DCHECK(!RelocInfo::RequiresRelocation(isolate, desc));
34 :
35 0 : Assembler::FlushICache(isolate, buffer, actual_size);
36 0 : base::OS::SetReadAndExecutable(buffer, actual_size);
37 : return FUNCTION_CAST<UnaryMathFunctionWithIsolate>(buffer);
38 : }
39 :
40 : #undef __
41 :
42 : } // namespace internal
43 : } // namespace v8
44 :
45 : #endif // V8_TARGET_ARCH_X64
|