runtime-utils.h 1.67 KB
Newer Older
1 2 3 4
// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6
#ifndef V8_RUNTIME_RUNTIME_UTILS_H_
#define V8_RUNTIME_RUNTIME_UTILS_H_
7

8
#include "src/base/logging.h"
9
#include "src/common/globals.h"
10
#include "src/objects/objects.h"
11
#include "src/runtime/runtime.h"
12 13 14 15 16 17 18 19 20 21 22 23 24 25

namespace v8 {
namespace internal {

// A mechanism to return a pair of Object pointers in registers (if possible).
// How this is achieved is calling convention-dependent.
// All currently supported x86 compiles uses calling conventions that are cdecl
// variants where a 64-bit value is returned in two 32-bit registers
// (edx:eax on ia32, r1:r0 on ARM).
// In AMD-64 calling convention a struct of two pointers is returned in rdx:rax.
// In Win64 calling convention, a struct of two pointers is returned in memory,
// allocated by the caller, and passed as a pointer in a hidden first parameter.
#ifdef V8_HOST_ARCH_64_BIT
struct ObjectPair {
26 27
  Address x;
  Address y;
28 29
};

30
static inline ObjectPair MakePair(Object x, Object y) {
31
  ObjectPair result = {x.ptr(), y.ptr()};
32 33 34 35 36
  // Pointers x and y returned in rax and rdx, in AMD-x64-abi.
  // In Win64 they are assigned to a hidden first argument.
  return result;
}
#else
37
using ObjectPair = uint64_t;
38
static inline ObjectPair MakePair(Object x, Object y) {
39
#if defined(V8_TARGET_LITTLE_ENDIAN)
40
  return x.ptr() | (static_cast<ObjectPair>(y.ptr()) << 32);
41
#elif defined(V8_TARGET_BIG_ENDIAN)
42
  return y->ptr() | (static_cast<ObjectPair>(x->ptr()) << 32);
43 44 45 46 47
#else
#error Unknown endianness
#endif
}
#endif
48

49 50
}  // namespace internal
}  // namespace v8
51

52
#endif  // V8_RUNTIME_RUNTIME_UTILS_H_