• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 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 // This file contains runtime implementations of a few macros that are defined
6 // as external in Torque, so that generated runtime code can work.
7 
8 #ifndef V8_TORQUE_RUNTIME_MACRO_SHIMS_H_
9 #define V8_TORQUE_RUNTIME_MACRO_SHIMS_H_
10 
11 #include <cstdint>
12 
13 #include "src/numbers/integer-literal.h"
14 
15 namespace v8 {
16 namespace internal {
17 
18 namespace TorqueRuntimeMacroShims {
19 namespace CodeStubAssembler {
20 
BoolConstant(bool b)21 inline bool BoolConstant(bool b) { return b; }
ChangeInt32ToIntPtr(int32_t i)22 inline intptr_t ChangeInt32ToIntPtr(int32_t i) { return i; }
ChangeUint32ToWord(uint32_t u)23 inline uintptr_t ChangeUint32ToWord(uint32_t u) { return u; }
IntPtrAdd(intptr_t a,intptr_t b)24 inline intptr_t IntPtrAdd(intptr_t a, intptr_t b) { return a + b; }
IntPtrMul(intptr_t a,intptr_t b)25 inline intptr_t IntPtrMul(intptr_t a, intptr_t b) { return a * b; }
IntPtrLessThan(intptr_t a,intptr_t b)26 inline bool IntPtrLessThan(intptr_t a, intptr_t b) { return a < b; }
IntPtrLessThanOrEqual(intptr_t a,intptr_t b)27 inline bool IntPtrLessThanOrEqual(intptr_t a, intptr_t b) { return a <= b; }
Signed(uintptr_t u)28 inline intptr_t Signed(uintptr_t u) { return static_cast<intptr_t>(u); }
29 template <typename Smi>
SmiUntag(Smi s)30 inline int32_t SmiUntag(Smi s) {
31   return s.value();
32 }
UintPtrLessThan(uintptr_t a,uintptr_t b)33 inline bool UintPtrLessThan(uintptr_t a, uintptr_t b) { return a < b; }
Unsigned(int32_t s)34 inline uint32_t Unsigned(int32_t s) { return static_cast<uint32_t>(s); }
35 #if V8_HOST_ARCH_64_BIT
Unsigned(intptr_t s)36 inline uintptr_t Unsigned(intptr_t s) { return static_cast<uintptr_t>(s); }
37 #endif
Word32Equal(uint32_t a,uint32_t b)38 inline bool Word32Equal(uint32_t a, uint32_t b) { return a == b; }
Word32NotEqual(uint32_t a,uint32_t b)39 inline bool Word32NotEqual(uint32_t a, uint32_t b) { return a != b; }
ConstexprIntegerLiteralToInt32(const IntegerLiteral & i)40 inline int32_t ConstexprIntegerLiteralToInt32(const IntegerLiteral& i) {
41   return i.To<int32_t>();
42 }
ConstexprIntegerLiteralToInt31(const IntegerLiteral & i)43 inline int31_t ConstexprIntegerLiteralToInt31(const IntegerLiteral& i) {
44   return int31_t(ConstexprIntegerLiteralToInt32(i));
45 }
ConstexprIntegerLiteralToIntptr(const IntegerLiteral & i)46 inline intptr_t ConstexprIntegerLiteralToIntptr(const IntegerLiteral& i) {
47   return i.To<intptr_t>();
48 }
49 
50 }  // namespace CodeStubAssembler
51 }  // namespace TorqueRuntimeMacroShims
52 }  // namespace internal
53 }  // namespace v8
54 
55 #endif  // V8_TORQUE_RUNTIME_MACRO_SHIMS_H_
56