Commit b7b8c8aa authored by Camillo Bruni's avatar Camillo Bruni Committed by Commit Bot

[codegen] Use smaller instructions for smi loading on x64

- Use movl which clears the upper 32bits on x64
- Use xorl + movb for Smi.ptr values <= 0xFF, saving one byte over movl

Change-Id: Iacdacfbe397670667e71d1d12ef427a01994481d
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2642250
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72282}
parent 502419a8
......@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <cstdint>
#if V8_TARGET_ARCH_X64
#include "src/base/bits.h"
......@@ -1078,17 +1079,7 @@ void TurboAssembler::Set(Operand dst, intptr_t x) {
// Smi tagging, untagging and tag detection.
Register TurboAssembler::GetSmiConstant(Smi source) {
STATIC_ASSERT(kSmiTag == 0);
int value = source.value();
if (value == 0) {
xorl(kScratchRegister, kScratchRegister);
return kScratchRegister;
}
if (SmiValuesAre32Bits()) {
Move(kScratchRegister, source);
} else {
movl(kScratchRegister, Immediate(source));
}
Move(kScratchRegister, source);
return kScratchRegister;
}
......@@ -1097,8 +1088,17 @@ void TurboAssembler::Move(Register dst, Smi source) {
int value = source.value();
if (value == 0) {
xorl(dst, dst);
} else {
} else if (SmiValuesAre32Bits() || value < 0) {
Move(dst, source.ptr(), RelocInfo::NONE);
} else {
uint32_t uvalue = static_cast<uint32_t>(source.ptr());
if (uvalue <= 0xFF) {
// Emit shorter instructions for small Smis
xorl(dst, dst);
movb(dst, Immediate(uvalue));
} else {
movl(dst, Immediate(uvalue));
}
}
}
......
......@@ -115,13 +115,20 @@ TEST(SmiMove) {
TestMoveSmi(masm, &exit, 3, Smi::FromInt(128));
TestMoveSmi(masm, &exit, 4, Smi::FromInt(255));
TestMoveSmi(masm, &exit, 5, Smi::FromInt(256));
TestMoveSmi(masm, &exit, 6, Smi::FromInt(Smi::kMaxValue));
TestMoveSmi(masm, &exit, 7, Smi::FromInt(-1));
TestMoveSmi(masm, &exit, 8, Smi::FromInt(-128));
TestMoveSmi(masm, &exit, 9, Smi::FromInt(-129));
TestMoveSmi(masm, &exit, 10, Smi::FromInt(-256));
TestMoveSmi(masm, &exit, 11, Smi::FromInt(-257));
TestMoveSmi(masm, &exit, 12, Smi::FromInt(Smi::kMinValue));
TestMoveSmi(masm, &exit, 6, Smi::FromInt(0xFFFF - 1));
TestMoveSmi(masm, &exit, 7, Smi::FromInt(0xFFFF));
TestMoveSmi(masm, &exit, 8, Smi::FromInt(0xFFFF + 1));
TestMoveSmi(masm, &exit, 9, Smi::FromInt(Smi::kMaxValue));
TestMoveSmi(masm, &exit, 10, Smi::FromInt(-1));
TestMoveSmi(masm, &exit, 11, Smi::FromInt(-128));
TestMoveSmi(masm, &exit, 12, Smi::FromInt(-129));
TestMoveSmi(masm, &exit, 13, Smi::FromInt(-256));
TestMoveSmi(masm, &exit, 14, Smi::FromInt(-257));
TestMoveSmi(masm, &exit, 15, Smi::FromInt(-0xFFFF + 1));
TestMoveSmi(masm, &exit, 16, Smi::FromInt(-0xFFFF));
TestMoveSmi(masm, &exit, 17, Smi::FromInt(-0xFFFF - 1));
TestMoveSmi(masm, &exit, 18, Smi::FromInt(Smi::kMinValue));
__ xorq(rax, rax); // Success.
__ bind(&exit);
......
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