Line data Source code
1 : // Copyright 2018 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 : #include "src/memcopy.h"
6 :
7 : #include "src/snapshot/embedded-data.h"
8 :
9 : namespace v8 {
10 : namespace internal {
11 :
12 : #if V8_TARGET_ARCH_IA32
13 : static void MemMoveWrapper(void* dest, const void* src, size_t size) {
14 : memmove(dest, src, size);
15 : }
16 :
17 : // Initialize to library version so we can call this at any time during startup.
18 : static MemMoveFunction memmove_function = &MemMoveWrapper;
19 :
20 : // Copy memory area to disjoint memory area.
21 : V8_EXPORT_PRIVATE void MemMove(void* dest, const void* src, size_t size) {
22 : if (size == 0) return;
23 : // Note: here we rely on dependent reads being ordered. This is true
24 : // on all architectures we currently support.
25 : (*memmove_function)(dest, src, size);
26 : }
27 : #elif V8_OS_POSIX && V8_HOST_ARCH_ARM
28 : void MemCopyUint16Uint8Wrapper(uint16_t* dest, const uint8_t* src,
29 : size_t chars) {
30 : uint16_t* limit = dest + chars;
31 : while (dest < limit) {
32 : *dest++ = static_cast<uint16_t>(*src++);
33 : }
34 : }
35 :
36 : V8_EXPORT_PRIVATE MemCopyUint8Function memcopy_uint8_function =
37 : &MemCopyUint8Wrapper;
38 : MemCopyUint16Uint8Function memcopy_uint16_uint8_function =
39 : &MemCopyUint16Uint8Wrapper;
40 : #elif V8_OS_POSIX && V8_HOST_ARCH_MIPS
41 : V8_EXPORT_PRIVATE MemCopyUint8Function memcopy_uint8_function =
42 : &MemCopyUint8Wrapper;
43 : #endif
44 :
45 62426 : void init_memcopy_functions() {
46 : #if V8_TARGET_ARCH_IA32
47 : if (Isolate::CurrentEmbeddedBlobIsBinaryEmbedded()) {
48 : EmbeddedData d = EmbeddedData::FromBlob();
49 : memmove_function = reinterpret_cast<MemMoveFunction>(
50 : d.InstructionStartOfBuiltin(Builtins::kMemMove));
51 : }
52 : #elif V8_OS_POSIX && V8_HOST_ARCH_ARM
53 : if (Isolate::CurrentEmbeddedBlobIsBinaryEmbedded()) {
54 : EmbeddedData d = EmbeddedData::FromBlob();
55 : memcopy_uint8_function = reinterpret_cast<MemCopyUint8Function>(
56 : d.InstructionStartOfBuiltin(Builtins::kMemCopyUint8Uint8));
57 : memcopy_uint16_uint8_function =
58 : reinterpret_cast<MemCopyUint16Uint8Function>(
59 : d.InstructionStartOfBuiltin(Builtins::kMemCopyUint16Uint8));
60 : }
61 : #elif V8_OS_POSIX && V8_HOST_ARCH_MIPS
62 : if (Isolate::CurrentEmbeddedBlobIsBinaryEmbedded()) {
63 : EmbeddedData d = EmbeddedData::FromBlob();
64 : memcopy_uint8_function = reinterpret_cast<MemCopyUint8Function>(
65 : d.InstructionStartOfBuiltin(Builtins::kMemCopyUint8Uint8));
66 : }
67 : #endif
68 62426 : }
69 :
70 : } // namespace internal
71 122004 : } // namespace v8
|