codegen-arm64.cc 6.66 KB
Newer Older
1
// Copyright 2013 the V8 project authors. All rights reserved.
2 3
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
4

5 6
#include "src/arm64/codegen-arm64.h"

7
#if V8_TARGET_ARCH_ARM64
8

9
#include "src/arm64/simulator-arm64.h"
10 11
#include "src/codegen.h"
#include "src/macro-assembler.h"
12 13 14 15 16 17

namespace v8 {
namespace internal {

#define __ ACCESS_MASM(masm)

18 19
UnaryMathFunctionWithIsolate CreateSqrtFunction(Isolate* isolate) {
  return nullptr;
20 21 22 23 24 25 26 27
}


// -------------------------------------------------------------------------
// Platform-specific RuntimeCallHelper functions.

void StubRuntimeCallHelper::BeforeCall(MacroAssembler* masm) const {
  masm->EnterFrame(StackFrame::INTERNAL);
28
  DCHECK(!masm->has_frame());
29 30 31 32 33 34
  masm->set_has_frame(true);
}


void StubRuntimeCallHelper::AfterCall(MacroAssembler* masm) const {
  masm->LeaveFrame(StackFrame::INTERNAL);
35
  DCHECK(masm->has_frame());
36 37 38 39 40 41 42
  masm->set_has_frame(false);
}


// -------------------------------------------------------------------------
// Code generators

43 44
CodeAgingHelper::CodeAgingHelper(Isolate* isolate) {
  USE(isolate);
45
  DCHECK(young_sequence_.length() == kNoCodeAgeSequenceLength);
46 47 48
  // The sequence of instructions that is patched out for aging code is the
  // following boilerplate stack-building prologue that is found both in
  // FUNCTION and OPTIMIZED_FUNCTION code:
49
  PatchingAssembler patcher(isolate, young_sequence_.start(),
50 51 52 53 54 55 56
                            young_sequence_.length() / kInstructionSize);
  // The young sequence is the frame setup code for FUNCTION code types. It is
  // generated by FullCodeGenerator::Generate.
  MacroAssembler::EmitFrameSetupForCodeAgePatching(&patcher);

#ifdef DEBUG
  const int length = kCodeAgeStubEntryOffset / kInstructionSize;
57
  DCHECK(old_sequence_.length() >= kCodeAgeStubEntryOffset);
58
  PatchingAssembler patcher_old(isolate, old_sequence_.start(), length);
59 60 61 62 63 64 65 66 67 68 69 70 71 72
  MacroAssembler::EmitCodeAgeSequence(&patcher_old, NULL);
#endif
}


#ifdef DEBUG
bool CodeAgingHelper::IsOld(byte* candidate) const {
  return memcmp(candidate, old_sequence_.start(), kCodeAgeStubEntryOffset) == 0;
}
#endif


bool Code::IsYoungSequence(Isolate* isolate, byte* sequence) {
  return MacroAssembler::IsYoungSequence(isolate, sequence);
73 74
}

75 76
Code::Age Code::GetCodeAge(Isolate* isolate, byte* sequence) {
  if (IsYoungSequence(isolate, sequence)) return kNoAgeCodeAge;
77

78 79 80
  byte* target = sequence + kCodeAgeStubEntryOffset;
  Code* stub = GetCodeFromTargetAddress(Memory::Address_at(target));
  return GetAgeOfCodeAgeStub(stub);
81 82
}

83 84
void Code::PatchPlatformCodeAge(Isolate* isolate, byte* sequence,
                                Code::Age age) {
85
  PatchingAssembler patcher(isolate, sequence,
86
                            kNoCodeAgeSequenceLength / kInstructionSize);
87 88 89
  if (age == kNoAgeCodeAge) {
    MacroAssembler::EmitFrameSetupForCodeAgePatching(&patcher);
  } else {
90
    Code* stub = GetCodeAgeStub(isolate, age);
91 92 93 94 95 96 97 98 99 100
    MacroAssembler::EmitCodeAgeSequence(&patcher, stub);
  }
}


void StringCharLoadGenerator::Generate(MacroAssembler* masm,
                                       Register string,
                                       Register index,
                                       Register result,
                                       Label* call_runtime) {
101
  DCHECK(string.Is64Bits() && index.Is32Bits() && result.Is64Bits());
102 103 104
  Label indirect_string_loaded;
  __ Bind(&indirect_string_loaded);

105 106 107 108 109 110 111 112 113
  // Fetch the instance type of the receiver into result register.
  __ Ldr(result, FieldMemOperand(string, HeapObject::kMapOffset));
  __ Ldrb(result, FieldMemOperand(result, Map::kInstanceTypeOffset));

  // We need special handling for indirect strings.
  Label check_sequential;
  __ TestAndBranchIfAllClear(result, kIsIndirectStringMask, &check_sequential);

  // Dispatch on the indirect string shape: slice or cons.
114 115 116 117 118 119
  Label cons_string, thin_string;
  __ And(result, result, kStringRepresentationMask);
  __ Cmp(result, kConsStringTag);
  __ B(eq, &cons_string);
  __ Cmp(result, kThinStringTag);
  __ B(eq, &thin_string);
120 121

  // Handle slices.
122 123
  __ Ldr(result.W(),
         UntagSmiFieldMemOperand(string, SlicedString::kOffsetOffset));
124
  __ Ldr(string, FieldMemOperand(string, SlicedString::kParentOffset));
125
  __ Add(index, index, result.W());
126 127
  __ B(&indirect_string_loaded);

128 129 130 131 132
  // Handle thin strings.
  __ Bind(&thin_string);
  __ Ldr(string, FieldMemOperand(string, ThinString::kActualOffset));
  __ B(&indirect_string_loaded);

133 134 135 136 137 138 139 140 141 142
  // Handle cons strings.
  // Check whether the right hand side is the empty string (i.e. if
  // this is really a flat string in a cons string). If that is not
  // the case we would rather go to the runtime system now to flatten
  // the string.
  __ Bind(&cons_string);
  __ Ldr(result, FieldMemOperand(string, ConsString::kSecondOffset));
  __ JumpIfNotRoot(result, Heap::kempty_stringRootIndex, call_runtime);
  // Get the first of the two strings and load its instance type.
  __ Ldr(string, FieldMemOperand(string, ConsString::kFirstOffset));
143
  __ B(&indirect_string_loaded);
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166

  // Distinguish sequential and external strings. Only these two string
  // representations can reach here (slices and flat cons strings have been
  // reduced to the underlying sequential or external string).
  Label external_string, check_encoding;
  __ Bind(&check_sequential);
  STATIC_ASSERT(kSeqStringTag == 0);
  __ TestAndBranchIfAnySet(result, kStringRepresentationMask, &external_string);

  // Prepare sequential strings
  STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
  __ Add(string, string, SeqTwoByteString::kHeaderSize - kHeapObjectTag);
  __ B(&check_encoding);

  // Handle external strings.
  __ Bind(&external_string);
  if (FLAG_debug_code) {
    // Assert that we do not have a cons or slice (indirect strings) here.
    // Sequential strings have already been ruled out.
    __ Tst(result, kIsIndirectStringMask);
    __ Assert(eq, kExternalStringExpectedButNotFound);
  }
  // Rule out short external strings.
167
  STATIC_ASSERT(kShortExternalStringTag != 0);
168 169 170 171 172 173
  // TestAndBranchIfAnySet can emit Tbnz. Do not use it because call_runtime
  // can be bound far away in deferred code.
  __ Tst(result, kShortExternalStringMask);
  __ B(ne, call_runtime);
  __ Ldr(string, FieldMemOperand(string, ExternalString::kResourceDataOffset));

174
  Label one_byte, done;
175 176
  __ Bind(&check_encoding);
  STATIC_ASSERT(kTwoByteStringTag == 0);
177
  __ TestAndBranchIfAnySet(result, kStringEncodingMask, &one_byte);
178
  // Two-byte string.
179
  __ Ldrh(result, MemOperand(string, index, SXTW, 1));
180
  __ B(&done);
181 182
  __ Bind(&one_byte);
  // One-byte string.
183
  __ Ldrb(result, MemOperand(string, index, SXTW));
184 185 186 187 188
  __ Bind(&done);
}

#undef __

189 190
}  // namespace internal
}  // namespace v8
191

192
#endif  // V8_TARGET_ARCH_ARM64