x64: Make sure that the upper half of a 64bit register contains 0 for int32 values.

BUG=360611
LOG=y
R=bmeurer@chromium.org

Review URL: https://codereview.chromium.org/225393005

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20664 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent fd988331
......@@ -1389,6 +1389,15 @@ void Assembler::movl(const Operand& dst, Label* src) {
}
void Assembler::movsxbl(Register dst, const Operand& src) {
EnsureSpace ensure_space(this);
emit_optional_rex_32(dst, src);
emit(0x0F);
emit(0xBE);
emit_operand(dst, src);
}
void Assembler::movsxbq(Register dst, const Operand& src) {
EnsureSpace ensure_space(this);
emit_rex_64(dst, src);
......@@ -1398,6 +1407,15 @@ void Assembler::movsxbq(Register dst, const Operand& src) {
}
void Assembler::movsxwl(Register dst, const Operand& src) {
EnsureSpace ensure_space(this);
emit_optional_rex_32(dst, src);
emit(0x0F);
emit(0xBF);
emit_operand(dst, src);
}
void Assembler::movsxwq(Register dst, const Operand& src) {
EnsureSpace ensure_space(this);
emit_rex_64(dst, src);
......
......@@ -794,7 +794,9 @@ class Assembler : public AssemblerBase {
void movq(Register dst, int64_t value);
void movq(Register dst, uint64_t value);
void movsxbl(Register dst, const Operand& src);
void movsxbq(Register dst, const Operand& src);
void movsxwl(Register dst, const Operand& src);
void movsxwq(Register dst, const Operand& src);
void movsxlq(Register dst, Register src);
void movsxlq(Register dst, const Operand& src);
......
......@@ -284,6 +284,12 @@ void LCodeGen::GenerateBodyInstructionPre(LInstruction* instr) {
void LCodeGen::GenerateBodyInstructionPost(LInstruction* instr) {
if (FLAG_debug_code && FLAG_enable_slow_asserts && instr->HasResult() &&
instr->hydrogen_value()->representation().IsInteger32() &&
instr->result()->IsRegister()) {
__ AssertZeroExtended(ToRegister(instr->result()));
}
if (instr->HasResult() && instr->MustSignExtendResult(chunk())) {
if (instr->result()->IsRegister()) {
Register result_reg = ToRegister(instr->result());
......@@ -1321,7 +1327,7 @@ void LCodeGen::DoDivByConstI(LDivByConstI* instr) {
}
__ TruncatingDiv(dividend, Abs(divisor));
if (divisor < 0) __ negp(rdx);
if (divisor < 0) __ negl(rdx);
if (!hdiv->CheckFlag(HInstruction::kAllUsesTruncatingToInt32)) {
__ movl(rax, rdx);
......@@ -1525,13 +1531,25 @@ void LCodeGen::DoBitI(LBitI* instr) {
} else if (right->IsStackSlot()) {
switch (instr->op()) {
case Token::BIT_AND:
__ andp(ToRegister(left), ToOperand(right));
if (instr->IsInteger32()) {
__ andl(ToRegister(left), ToOperand(right));
} else {
__ andp(ToRegister(left), ToOperand(right));
}
break;
case Token::BIT_OR:
__ orp(ToRegister(left), ToOperand(right));
if (instr->IsInteger32()) {
__ orl(ToRegister(left), ToOperand(right));
} else {
__ orp(ToRegister(left), ToOperand(right));
}
break;
case Token::BIT_XOR:
__ xorp(ToRegister(left), ToOperand(right));
if (instr->IsInteger32()) {
__ xorl(ToRegister(left), ToOperand(right));
} else {
__ xorp(ToRegister(left), ToOperand(right));
}
break;
default:
UNREACHABLE();
......@@ -1541,13 +1559,25 @@ void LCodeGen::DoBitI(LBitI* instr) {
ASSERT(right->IsRegister());
switch (instr->op()) {
case Token::BIT_AND:
__ andp(ToRegister(left), ToRegister(right));
if (instr->IsInteger32()) {
__ andl(ToRegister(left), ToRegister(right));
} else {
__ andp(ToRegister(left), ToRegister(right));
}
break;
case Token::BIT_OR:
__ orp(ToRegister(left), ToRegister(right));
if (instr->IsInteger32()) {
__ orl(ToRegister(left), ToRegister(right));
} else {
__ orp(ToRegister(left), ToRegister(right));
}
break;
case Token::BIT_XOR:
__ xorp(ToRegister(left), ToRegister(right));
if (instr->IsInteger32()) {
__ xorl(ToRegister(left), ToRegister(right));
} else {
__ xorp(ToRegister(left), ToRegister(right));
}
break;
default:
UNREACHABLE();
......@@ -1654,7 +1684,12 @@ void LCodeGen::DoSubI(LSubI* instr) {
void LCodeGen::DoConstantI(LConstantI* instr) {
__ Set(ToRegister(instr->result()), instr->value());
Register dst = ToRegister(instr->result());
if (instr->value() == 0) {
__ xorl(dst, dst);
} else {
__ movl(dst, Immediate(instr->value()));
}
}
......@@ -3035,25 +3070,25 @@ void LCodeGen::DoLoadKeyedExternalArray(LLoadKeyed* instr) {
switch (elements_kind) {
case EXTERNAL_INT8_ELEMENTS:
case INT8_ELEMENTS:
__ movsxbq(result, operand);
__ movsxbl(result, operand);
break;
case EXTERNAL_UINT8_ELEMENTS:
case EXTERNAL_UINT8_CLAMPED_ELEMENTS:
case UINT8_ELEMENTS:
case UINT8_CLAMPED_ELEMENTS:
__ movzxbp(result, operand);
__ movzxbl(result, operand);
break;
case EXTERNAL_INT16_ELEMENTS:
case INT16_ELEMENTS:
__ movsxwq(result, operand);
__ movsxwl(result, operand);
break;
case EXTERNAL_UINT16_ELEMENTS:
case UINT16_ELEMENTS:
__ movzxwp(result, operand);
__ movzxwl(result, operand);
break;
case EXTERNAL_INT32_ELEMENTS:
case INT32_ELEMENTS:
__ movsxlq(result, operand);
__ movl(result, operand);
break;
case EXTERNAL_UINT32_ELEMENTS:
case UINT32_ELEMENTS:
......
......@@ -1246,6 +1246,9 @@ class LBitI V8_FINAL : public LTemplateInstruction<1, 2, 0> {
LOperand* right() { return inputs_[1]; }
Token::Value op() const { return hydrogen()->op(); }
bool IsInteger32() const {
return hydrogen()->representation().IsInteger32();
}
DECLARE_CONCRETE_INSTRUCTION(BitI, "bit-i")
DECLARE_HYDROGEN_ACCESSOR(Bitwise)
......
......@@ -3278,6 +3278,8 @@ void MacroAssembler::TruncateHeapNumberToI(Register result_reg,
}
bind(&done);
// Keep our invariant that the upper 32 bits are zero.
movl(result_reg, result_reg);
}
......@@ -3294,6 +3296,8 @@ void MacroAssembler::TruncateDoubleToI(Register result_reg,
addp(rsp, Immediate(kDoubleSize));
bind(&done);
// Keep our invariant that the upper 32 bits are zero.
movl(result_reg, result_reg);
}
......
......@@ -104,7 +104,9 @@ TEST(DisasmX64) {
__ xorq(rdx, Immediate(3));
__ nop();
__ cpuid();
__ movsxbl(rdx, Operand(rcx, 0));
__ movsxbq(rdx, Operand(rcx, 0));
__ movsxwl(rdx, Operand(rcx, 0));
__ movsxwq(rdx, Operand(rcx, 0));
__ movzxbl(rdx, Operand(rcx, 0));
__ movzxwl(rdx, Operand(rcx, 0));
......
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