Commit 869e8f47 authored by Patrick Thier's avatar Patrick Thier Committed by V8 LUCI CQ

[masm][x64] Move methods from MacroAssembler to TurboAssembler

Move some methods that don't access the isolate from x64 MacroAssembler
to TurboAssembler.

Drive-by: Add RootAsOperand to create an operand for root-relative
constants.

Bug: v8:11112
Change-Id: Ic0b62d96af004860e5a05539f94d0ac003b06fc3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3045348Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Commit-Queue: Patrick Thier <pthier@chromium.org>
Cr-Commit-Position: refs/heads/master@{#75857}
parent d8d64b49
...@@ -155,26 +155,28 @@ void MacroAssembler::PushAddress(ExternalReference source) { ...@@ -155,26 +155,28 @@ void MacroAssembler::PushAddress(ExternalReference source) {
Push(kScratchRegister); Push(kScratchRegister);
} }
Operand TurboAssembler::RootAsOperand(RootIndex index) {
return Operand(kRootRegister, RootRegisterOffsetForRootIndex(index));
}
void TurboAssembler::LoadRoot(Register destination, RootIndex index) { void TurboAssembler::LoadRoot(Register destination, RootIndex index) {
DCHECK(root_array_available_); DCHECK(root_array_available_);
movq(destination, movq(destination, RootAsOperand(index));
Operand(kRootRegister, RootRegisterOffsetForRootIndex(index)));
} }
void MacroAssembler::PushRoot(RootIndex index) { void MacroAssembler::PushRoot(RootIndex index) {
DCHECK(root_array_available_); DCHECK(root_array_available_);
Push(Operand(kRootRegister, RootRegisterOffsetForRootIndex(index))); Push(RootAsOperand(index));
} }
void TurboAssembler::CompareRoot(Register with, RootIndex index) { void TurboAssembler::CompareRoot(Register with, RootIndex index) {
DCHECK(root_array_available_); DCHECK(root_array_available_);
if (base::IsInRange(index, RootIndex::kFirstStrongOrReadOnlyRoot, if (base::IsInRange(index, RootIndex::kFirstStrongOrReadOnlyRoot,
RootIndex::kLastStrongOrReadOnlyRoot)) { RootIndex::kLastStrongOrReadOnlyRoot)) {
cmp_tagged(with, cmp_tagged(with, RootAsOperand(index));
Operand(kRootRegister, RootRegisterOffsetForRootIndex(index)));
} else { } else {
// Some smi roots contain system pointer size values like stack limits. // Some smi roots contain system pointer size values like stack limits.
cmpq(with, Operand(kRootRegister, RootRegisterOffsetForRootIndex(index))); cmpq(with, RootAsOperand(index));
} }
} }
...@@ -1192,7 +1194,7 @@ Register TurboAssembler::GetSmiConstant(Smi source) { ...@@ -1192,7 +1194,7 @@ Register TurboAssembler::GetSmiConstant(Smi source) {
return kScratchRegister; return kScratchRegister;
} }
void MacroAssembler::Cmp(Register dst, int32_t src) { void TurboAssembler::Cmp(Register dst, int32_t src) {
if (src == 0) { if (src == 0) {
testl(dst, dst); testl(dst, dst);
} else { } else {
...@@ -1200,7 +1202,7 @@ void MacroAssembler::Cmp(Register dst, int32_t src) { ...@@ -1200,7 +1202,7 @@ void MacroAssembler::Cmp(Register dst, int32_t src) {
} }
} }
void MacroAssembler::SmiTag(Register reg) { void TurboAssembler::SmiTag(Register reg) {
STATIC_ASSERT(kSmiTag == 0); STATIC_ASSERT(kSmiTag == 0);
DCHECK(SmiValuesAre32Bits() || SmiValuesAre31Bits()); DCHECK(SmiValuesAre32Bits() || SmiValuesAre31Bits());
if (COMPRESS_POINTERS_BOOL) { if (COMPRESS_POINTERS_BOOL) {
...@@ -1210,7 +1212,7 @@ void MacroAssembler::SmiTag(Register reg) { ...@@ -1210,7 +1212,7 @@ void MacroAssembler::SmiTag(Register reg) {
} }
} }
void MacroAssembler::SmiTag(Register dst, Register src) { void TurboAssembler::SmiTag(Register dst, Register src) {
DCHECK(dst != src); DCHECK(dst != src);
if (COMPRESS_POINTERS_BOOL) { if (COMPRESS_POINTERS_BOOL) {
movl(dst, src); movl(dst, src);
...@@ -1261,18 +1263,18 @@ void TurboAssembler::SmiUntag(Register dst, Operand src) { ...@@ -1261,18 +1263,18 @@ void TurboAssembler::SmiUntag(Register dst, Operand src) {
} }
} }
void MacroAssembler::SmiCompare(Register smi1, Register smi2) { void TurboAssembler::SmiCompare(Register smi1, Register smi2) {
AssertSmi(smi1); AssertSmi(smi1);
AssertSmi(smi2); AssertSmi(smi2);
cmp_tagged(smi1, smi2); cmp_tagged(smi1, smi2);
} }
void MacroAssembler::SmiCompare(Register dst, Smi src) { void TurboAssembler::SmiCompare(Register dst, Smi src) {
AssertSmi(dst); AssertSmi(dst);
Cmp(dst, src); Cmp(dst, src);
} }
void MacroAssembler::Cmp(Register dst, Smi src) { void TurboAssembler::Cmp(Register dst, Smi src) {
if (src.value() == 0) { if (src.value() == 0) {
test_tagged(dst, dst); test_tagged(dst, dst);
} else { } else {
...@@ -1282,19 +1284,19 @@ void MacroAssembler::Cmp(Register dst, Smi src) { ...@@ -1282,19 +1284,19 @@ void MacroAssembler::Cmp(Register dst, Smi src) {
} }
} }
void MacroAssembler::SmiCompare(Register dst, Operand src) { void TurboAssembler::SmiCompare(Register dst, Operand src) {
AssertSmi(dst); AssertSmi(dst);
AssertSmi(src); AssertSmi(src);
cmp_tagged(dst, src); cmp_tagged(dst, src);
} }
void MacroAssembler::SmiCompare(Operand dst, Register src) { void TurboAssembler::SmiCompare(Operand dst, Register src) {
AssertSmi(dst); AssertSmi(dst);
AssertSmi(src); AssertSmi(src);
cmp_tagged(dst, src); cmp_tagged(dst, src);
} }
void MacroAssembler::SmiCompare(Operand dst, Smi src) { void TurboAssembler::SmiCompare(Operand dst, Smi src) {
AssertSmi(dst); AssertSmi(dst);
if (SmiValuesAre32Bits()) { if (SmiValuesAre32Bits()) {
cmpl(Operand(dst, kSmiShift / kBitsPerByte), Immediate(src.value())); cmpl(Operand(dst, kSmiShift / kBitsPerByte), Immediate(src.value()));
...@@ -1304,7 +1306,7 @@ void MacroAssembler::SmiCompare(Operand dst, Smi src) { ...@@ -1304,7 +1306,7 @@ void MacroAssembler::SmiCompare(Operand dst, Smi src) {
} }
} }
void MacroAssembler::Cmp(Operand dst, Smi src) { void TurboAssembler::Cmp(Operand dst, Smi src) {
// The Operand cannot use the smi register. // The Operand cannot use the smi register.
Register smi_reg = GetSmiConstant(src); Register smi_reg = GetSmiConstant(src);
DCHECK(!dst.AddressUsesRegister(smi_reg)); DCHECK(!dst.AddressUsesRegister(smi_reg));
...@@ -1329,19 +1331,19 @@ void TurboAssembler::JumpIfSmi(Register src, Label* on_smi, ...@@ -1329,19 +1331,19 @@ void TurboAssembler::JumpIfSmi(Register src, Label* on_smi,
j(smi, on_smi, near_jump); j(smi, on_smi, near_jump);
} }
void MacroAssembler::JumpIfNotSmi(Register src, Label* on_not_smi, void TurboAssembler::JumpIfNotSmi(Register src, Label* on_not_smi,
Label::Distance near_jump) { Label::Distance near_jump) {
Condition smi = CheckSmi(src); Condition smi = CheckSmi(src);
j(NegateCondition(smi), on_not_smi, near_jump); j(NegateCondition(smi), on_not_smi, near_jump);
} }
void MacroAssembler::JumpIfNotSmi(Operand src, Label* on_not_smi, void TurboAssembler::JumpIfNotSmi(Operand src, Label* on_not_smi,
Label::Distance near_jump) { Label::Distance near_jump) {
Condition smi = CheckSmi(src); Condition smi = CheckSmi(src);
j(NegateCondition(smi), on_not_smi, near_jump); j(NegateCondition(smi), on_not_smi, near_jump);
} }
void MacroAssembler::SmiAddConstant(Operand dst, Smi constant) { void TurboAssembler::SmiAddConstant(Operand dst, Smi constant) {
if (constant.value() != 0) { if (constant.value() != 0) {
if (SmiValuesAre32Bits()) { if (SmiValuesAre32Bits()) {
addl(Operand(dst, kSmiShift / kBitsPerByte), Immediate(constant.value())); addl(Operand(dst, kSmiShift / kBitsPerByte), Immediate(constant.value()));
...@@ -1361,7 +1363,7 @@ void MacroAssembler::SmiAddConstant(Operand dst, Smi constant) { ...@@ -1361,7 +1363,7 @@ void MacroAssembler::SmiAddConstant(Operand dst, Smi constant) {
} }
} }
SmiIndex MacroAssembler::SmiToIndex(Register dst, Register src, int shift) { SmiIndex TurboAssembler::SmiToIndex(Register dst, Register src, int shift) {
if (SmiValuesAre32Bits()) { if (SmiValuesAre32Bits()) {
DCHECK(is_uint6(shift)); DCHECK(is_uint6(shift));
// There is a possible optimization if shift is in the range 60-63, but that // There is a possible optimization if shift is in the range 60-63, but that
...@@ -2694,21 +2696,21 @@ void MacroAssembler::CmpInstanceTypeRange(Register map, ...@@ -2694,21 +2696,21 @@ void MacroAssembler::CmpInstanceTypeRange(Register map,
cmpl(kScratchRegister, Immediate(higher_limit - lower_limit)); cmpl(kScratchRegister, Immediate(higher_limit - lower_limit));
} }
void MacroAssembler::AssertNotSmi(Register object) { void TurboAssembler::AssertNotSmi(Register object) {
if (!FLAG_debug_code) return; if (!FLAG_debug_code) return;
ASM_CODE_COMMENT(this); ASM_CODE_COMMENT(this);
Condition is_smi = CheckSmi(object); Condition is_smi = CheckSmi(object);
Check(NegateCondition(is_smi), AbortReason::kOperandIsASmi); Check(NegateCondition(is_smi), AbortReason::kOperandIsASmi);
} }
void MacroAssembler::AssertSmi(Register object) { void TurboAssembler::AssertSmi(Register object) {
if (!FLAG_debug_code) return; if (!FLAG_debug_code) return;
ASM_CODE_COMMENT(this); ASM_CODE_COMMENT(this);
Condition is_smi = CheckSmi(object); Condition is_smi = CheckSmi(object);
Check(is_smi, AbortReason::kOperandIsNotASmi); Check(is_smi, AbortReason::kOperandIsNotASmi);
} }
void MacroAssembler::AssertSmi(Operand object) { void TurboAssembler::AssertSmi(Operand object) {
if (!FLAG_debug_code) return; if (!FLAG_debug_code) return;
ASM_CODE_COMMENT(this); ASM_CODE_COMMENT(this);
Condition is_smi = CheckSmi(object); Condition is_smi = CheckSmi(object);
......
...@@ -123,6 +123,7 @@ class V8_EXPORT_PRIVATE TurboAssembler : public SharedTurboAssembler { ...@@ -123,6 +123,7 @@ class V8_EXPORT_PRIVATE TurboAssembler : public SharedTurboAssembler {
void Ret(int bytes_dropped, Register scratch); void Ret(int bytes_dropped, Register scratch);
// Operations on roots in the root-array. // Operations on roots in the root-array.
Operand RootAsOperand(RootIndex index);
void LoadRoot(Register destination, RootIndex index) final; void LoadRoot(Register destination, RootIndex index) final;
void LoadRoot(Operand destination, RootIndex index) { void LoadRoot(Operand destination, RootIndex index) {
LoadRoot(kScratchRegister, index); LoadRoot(kScratchRegister, index);
...@@ -224,14 +225,74 @@ class V8_EXPORT_PRIVATE TurboAssembler : public SharedTurboAssembler { ...@@ -224,14 +225,74 @@ class V8_EXPORT_PRIVATE TurboAssembler : public SharedTurboAssembler {
void Popcntq(Register dst, Register src); void Popcntq(Register dst, Register src);
void Popcntq(Register dst, Operand src); void Popcntq(Register dst, Operand src);
// Is the value a tagged smi. void Cmp(Register dst, Smi src);
void Cmp(Operand dst, Smi src);
void Cmp(Register dst, int32_t src);
// ---------------------------------------------------------------------------
// Conversions between tagged smi values and non-tagged integer values.
// Tag an word-size value. The result must be known to be a valid smi value.
void SmiTag(Register reg);
// Requires dst != src
void SmiTag(Register dst, Register src);
// Simple comparison of smis. Both sides must be known smis to use these,
// otherwise use Cmp.
void SmiCompare(Register smi1, Register smi2);
void SmiCompare(Register dst, Smi src);
void SmiCompare(Register dst, Operand src);
void SmiCompare(Operand dst, Register src);
void SmiCompare(Operand dst, Smi src);
// Functions performing a check on a known or potential smi. Returns
// a condition that is satisfied if the check is successful.
Condition CheckSmi(Register src); Condition CheckSmi(Register src);
Condition CheckSmi(Operand src); Condition CheckSmi(Operand src);
// Abort execution if argument is a smi, enabled via --debug-code.
void AssertNotSmi(Register object);
// Abort execution if argument is not a smi, enabled via --debug-code.
void AssertSmi(Register object);
void AssertSmi(Operand object);
// Test-and-jump functions. Typically combines a check function
// above with a conditional jump.
// Jump to label if the value is a tagged smi. // Jump to label if the value is a tagged smi.
void JumpIfSmi(Register src, Label* on_smi, void JumpIfSmi(Register src, Label* on_smi,
Label::Distance near_jump = Label::kFar); Label::Distance near_jump = Label::kFar);
// Jump to label if the value is not a tagged smi.
void JumpIfNotSmi(Register src, Label* on_not_smi,
Label::Distance near_jump = Label::kFar);
// Jump to label if the value is not a tagged smi.
void JumpIfNotSmi(Operand src, Label* on_not_smi,
Label::Distance near_jump = Label::kFar);
// Operations on tagged smi values.
// Smis represent a subset of integers. The subset is always equivalent to
// a two's complement interpretation of a fixed number of bits.
// Add an integer constant to a tagged smi, giving a tagged smi as result.
// No overflow testing on the result is done.
void SmiAddConstant(Operand dst, Smi constant);
// Specialized operations
// Converts, if necessary, a smi to a combination of number and
// multiplier to be used as a scaled index.
// The src register contains a *positive* smi value. The shift is the
// power of two to multiply the index value by (e.g. to index by
// smi-value * kSystemPointerSize, pass the smi and kSystemPointerSizeLog2).
// The returned index register may be either src or dst, depending
// on what is most efficient. If src and dst are different registers,
// src is always unchanged.
SmiIndex SmiToIndex(Register dst, Register src, int shift);
void JumpIfEqual(Register a, int32_t b, Label* dest) { void JumpIfEqual(Register a, int32_t b, Label* dest) {
cmpl(a, Immediate(b)); cmpl(a, Immediate(b));
j(equal, dest); j(equal, dest);
...@@ -753,65 +814,12 @@ class V8_EXPORT_PRIVATE MacroAssembler : public TurboAssembler { ...@@ -753,65 +814,12 @@ class V8_EXPORT_PRIVATE MacroAssembler : public TurboAssembler {
Register expected_parameter_count, Register expected_parameter_count,
Register actual_parameter_count, InvokeType type); Register actual_parameter_count, InvokeType type);
// ---------------------------------------------------------------------------
// Conversions between tagged smi values and non-tagged integer values.
// Tag an word-size value. The result must be known to be a valid smi value.
void SmiTag(Register reg);
// Requires dst != src
void SmiTag(Register dst, Register src);
// Simple comparison of smis. Both sides must be known smis to use these,
// otherwise use Cmp.
void SmiCompare(Register smi1, Register smi2);
void SmiCompare(Register dst, Smi src);
void SmiCompare(Register dst, Operand src);
void SmiCompare(Operand dst, Register src);
void SmiCompare(Operand dst, Smi src);
// Functions performing a check on a known or potential smi. Returns
// a condition that is satisfied if the check is successful.
// Test-and-jump functions. Typically combines a check function
// above with a conditional jump.
// Jump to label if the value is not a tagged smi.
void JumpIfNotSmi(Register src, Label* on_not_smi,
Label::Distance near_jump = Label::kFar);
// Jump to label if the value is not a tagged smi.
void JumpIfNotSmi(Operand src, Label* on_not_smi,
Label::Distance near_jump = Label::kFar);
// Operations on tagged smi values.
// Smis represent a subset of integers. The subset is always equivalent to
// a two's complement interpretation of a fixed number of bits.
// Add an integer constant to a tagged smi, giving a tagged smi as result.
// No overflow testing on the result is done.
void SmiAddConstant(Operand dst, Smi constant);
// Specialized operations
// Converts, if necessary, a smi to a combination of number and
// multiplier to be used as a scaled index.
// The src register contains a *positive* smi value. The shift is the
// power of two to multiply the index value by (e.g. to index by
// smi-value * kSystemPointerSize, pass the smi and kSystemPointerSizeLog2).
// The returned index register may be either src or dst, depending
// on what is most efficient. If src and dst are different registers,
// src is always unchanged.
SmiIndex SmiToIndex(Register dst, Register src, int shift);
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// Macro instructions. // Macro instructions.
using TurboAssembler::Cmp;
void Cmp(Register dst, Handle<Object> source); void Cmp(Register dst, Handle<Object> source);
void Cmp(Operand dst, Handle<Object> source); void Cmp(Operand dst, Handle<Object> source);
void Cmp(Register dst, Smi src);
void Cmp(Operand dst, Smi src);
void Cmp(Register dst, int32_t src);
// Checks if value is in range [lower_limit, higher_limit] using a single // Checks if value is in range [lower_limit, higher_limit] using a single
// comparison. // comparison.
...@@ -827,7 +835,6 @@ class V8_EXPORT_PRIVATE MacroAssembler : public TurboAssembler { ...@@ -827,7 +835,6 @@ class V8_EXPORT_PRIVATE MacroAssembler : public TurboAssembler {
// clobbering the rsp register. // clobbering the rsp register.
void DropUnderReturnAddress(int stack_elements, void DropUnderReturnAddress(int stack_elements,
Register scratch = kScratchRegister); Register scratch = kScratchRegister);
void PushQuad(Operand src); void PushQuad(Operand src);
void PushImm32(int32_t imm32); void PushImm32(int32_t imm32);
void Pop(Register dst); void Pop(Register dst);
...@@ -865,13 +872,6 @@ class V8_EXPORT_PRIVATE MacroAssembler : public TurboAssembler { ...@@ -865,13 +872,6 @@ class V8_EXPORT_PRIVATE MacroAssembler : public TurboAssembler {
andq(reg, Immediate(mask)); andq(reg, Immediate(mask));
} }
// Abort execution if argument is a smi, enabled via --debug-code.
void AssertNotSmi(Register object);
// Abort execution if argument is not a smi, enabled via --debug-code.
void AssertSmi(Register object);
void AssertSmi(Operand object);
// Abort execution if argument is not a CodeT, enabled via --debug-code. // Abort execution if argument is not a CodeT, enabled via --debug-code.
void AssertCodeT(Register object); void AssertCodeT(Register object);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment