• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/isolate.h"
9 #include "src/macro-assembler.h"
10 #include "src/x64/assembler-x64-inl.h"
11 
12 namespace v8 {
13 namespace internal {
14 
15 #define __ masm.
16 
CreateSqrtFunction(Isolate * isolate)17 UnaryMathFunctionWithIsolate CreateSqrtFunction(Isolate* isolate) {
18   size_t allocated = 0;
19   byte* buffer = AllocatePage(isolate->heap()->GetRandomMmapAddr(), &allocated);
20   if (buffer == nullptr) return nullptr;
21 
22   MacroAssembler masm(isolate, buffer, static_cast<int>(allocated),
23                       CodeObjectRequired::kNo);
24 
25   // xmm0: raw double input.
26   // Move double input into registers.
27   __ Sqrtsd(xmm0, xmm0);
28   __ Ret();
29 
30   CodeDesc desc;
31   masm.GetCode(isolate, &desc);
32   DCHECK(!RelocInfo::RequiresRelocationAfterCodegen(desc));
33 
34   Assembler::FlushICache(buffer, allocated);
35   CHECK(SetPermissions(buffer, allocated, PageAllocator::kReadExecute));
36   return FUNCTION_CAST<UnaryMathFunctionWithIsolate>(buffer);
37 }
38 
39 #undef __
40 
41 }  // namespace internal
42 }  // namespace v8
43 
44 #endif  // V8_TARGET_ARCH_X64
45