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) {
Push(kScratchRegister);
}
Operand TurboAssembler::RootAsOperand(RootIndex index) {
return Operand(kRootRegister, RootRegisterOffsetForRootIndex(index));
}
void TurboAssembler::LoadRoot(Register destination, RootIndex index) {
DCHECK(root_array_available_);
movq(destination,
Operand(kRootRegister, RootRegisterOffsetForRootIndex(index)));
movq(destination, RootAsOperand(index));
}
void MacroAssembler::PushRoot(RootIndex index) {
DCHECK(root_array_available_);
Push(Operand(kRootRegister, RootRegisterOffsetForRootIndex(index)));
Push(RootAsOperand(index));
}
void TurboAssembler::CompareRoot(Register with, RootIndex index) {
DCHECK(root_array_available_);
if (base::IsInRange(index, RootIndex::kFirstStrongOrReadOnlyRoot,
RootIndex::kLastStrongOrReadOnlyRoot)) {
cmp_tagged(with,
Operand(kRootRegister, RootRegisterOffsetForRootIndex(index)));
cmp_tagged(with, RootAsOperand(index));
} else {
// 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) {
return kScratchRegister;
}
void MacroAssembler::Cmp(Register dst, int32_t src) {
void TurboAssembler::Cmp(Register dst, int32_t src) {
if (src == 0) {
testl(dst, dst);
} else {
......@@ -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);
DCHECK(SmiValuesAre32Bits() || SmiValuesAre31Bits());
if (COMPRESS_POINTERS_BOOL) {
......@@ -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);
if (COMPRESS_POINTERS_BOOL) {
movl(dst, 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(smi2);
cmp_tagged(smi1, smi2);
}
void MacroAssembler::SmiCompare(Register dst, Smi src) {
void TurboAssembler::SmiCompare(Register dst, Smi src) {
AssertSmi(dst);
Cmp(dst, src);
}
void MacroAssembler::Cmp(Register dst, Smi src) {
void TurboAssembler::Cmp(Register dst, Smi src) {
if (src.value() == 0) {
test_tagged(dst, dst);
} else {
......@@ -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(src);
cmp_tagged(dst, src);
}
void MacroAssembler::SmiCompare(Operand dst, Register src) {
void TurboAssembler::SmiCompare(Operand dst, Register src) {
AssertSmi(dst);
AssertSmi(src);
cmp_tagged(dst, src);
}
void MacroAssembler::SmiCompare(Operand dst, Smi src) {
void TurboAssembler::SmiCompare(Operand dst, Smi src) {
AssertSmi(dst);
if (SmiValuesAre32Bits()) {
cmpl(Operand(dst, kSmiShift / kBitsPerByte), Immediate(src.value()));
......@@ -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.
Register smi_reg = GetSmiConstant(src);
DCHECK(!dst.AddressUsesRegister(smi_reg));
......@@ -1329,19 +1331,19 @@ void TurboAssembler::JumpIfSmi(Register src, Label* on_smi,
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) {
Condition smi = CheckSmi(src);
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) {
Condition smi = CheckSmi(src);
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 (SmiValuesAre32Bits()) {
addl(Operand(dst, kSmiShift / kBitsPerByte), Immediate(constant.value()));
......@@ -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()) {
DCHECK(is_uint6(shift));
// There is a possible optimization if shift is in the range 60-63, but that
......@@ -2694,21 +2696,21 @@ void MacroAssembler::CmpInstanceTypeRange(Register map,
cmpl(kScratchRegister, Immediate(higher_limit - lower_limit));
}
void MacroAssembler::AssertNotSmi(Register object) {
void TurboAssembler::AssertNotSmi(Register object) {
if (!FLAG_debug_code) return;
ASM_CODE_COMMENT(this);
Condition is_smi = CheckSmi(object);
Check(NegateCondition(is_smi), AbortReason::kOperandIsASmi);
}
void MacroAssembler::AssertSmi(Register object) {
void TurboAssembler::AssertSmi(Register object) {
if (!FLAG_debug_code) return;
ASM_CODE_COMMENT(this);
Condition is_smi = CheckSmi(object);
Check(is_smi, AbortReason::kOperandIsNotASmi);
}
void MacroAssembler::AssertSmi(Operand object) {
void TurboAssembler::AssertSmi(Operand object) {
if (!FLAG_debug_code) return;
ASM_CODE_COMMENT(this);
Condition is_smi = CheckSmi(object);
......
......@@ -123,6 +123,7 @@ class V8_EXPORT_PRIVATE TurboAssembler : public SharedTurboAssembler {
void Ret(int bytes_dropped, Register scratch);
// Operations on roots in the root-array.
Operand RootAsOperand(RootIndex index);
void LoadRoot(Register destination, RootIndex index) final;
void LoadRoot(Operand destination, RootIndex index) {
LoadRoot(kScratchRegister, index);
......@@ -224,14 +225,74 @@ class V8_EXPORT_PRIVATE TurboAssembler : public SharedTurboAssembler {
void Popcntq(Register dst, Register 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(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.
void JumpIfSmi(Register src, Label* on_smi,
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) {
cmpl(a, Immediate(b));
j(equal, dest);
......@@ -753,65 +814,12 @@ class V8_EXPORT_PRIVATE MacroAssembler : public TurboAssembler {
Register expected_parameter_count,
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.
using TurboAssembler::Cmp;
void Cmp(Register 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
// comparison.
......@@ -827,7 +835,6 @@ class V8_EXPORT_PRIVATE MacroAssembler : public TurboAssembler {
// clobbering the rsp register.
void DropUnderReturnAddress(int stack_elements,
Register scratch = kScratchRegister);
void PushQuad(Operand src);
void PushImm32(int32_t imm32);
void Pop(Register dst);
......@@ -865,13 +872,6 @@ class V8_EXPORT_PRIVATE MacroAssembler : public TurboAssembler {
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.
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