V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
codegen-x64.cc
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 UnaryMathFunction CreateSqrtFunction() {
17  v8::PageAllocator* page_allocator = GetPlatformPageAllocator();
18  size_t allocated = 0;
19  byte* buffer = AllocatePage(page_allocator,
20  page_allocator->GetRandomMmapAddr(), &allocated);
21  if (buffer == nullptr) return nullptr;
22 
23  MacroAssembler masm(AssemblerOptions{}, buffer, static_cast<int>(allocated));
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(nullptr, &desc);
32  DCHECK(!RelocInfo::RequiresRelocationAfterCodegen(desc));
33 
34  Assembler::FlushICache(buffer, allocated);
35  CHECK(SetPermissions(page_allocator, buffer, allocated,
36  PageAllocator::kReadExecute));
37  return FUNCTION_CAST<UnaryMathFunction>(buffer);
38 }
39 
40 #undef __
41 
42 } // namespace internal
43 } // namespace v8
44 
45 #endif // V8_TARGET_ARCH_X64
virtual void * GetRandomMmapAddr()=0
Definition: libplatform.h:13