Commit 39f58c24 authored by balazs.kilvady's avatar balazs.kilvady Committed by Commit bot

MIPS: Fix label position types in binding code.

Also some target_at and target_at_put uniformed on mips and mips64.

BUG=

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

Cr-Commit-Position: refs/heads/master@{#26785}
parent 4e946e3e
...@@ -663,14 +663,14 @@ bool Assembler::IsAndImmediate(Instr instr) { ...@@ -663,14 +663,14 @@ bool Assembler::IsAndImmediate(Instr instr) {
} }
int Assembler::target_at(int32_t pos, bool is_internal) { int Assembler::target_at(int pos, bool is_internal) {
Instr instr = instr_at(pos); Instr instr = instr_at(pos);
if (is_internal) { if (is_internal) {
if (instr == 0) { if (instr == 0) {
return kEndOfChain; return kEndOfChain;
} else { } else {
int32_t instr_address = reinterpret_cast<int32_t>(buffer_ + pos); int32_t instr_address = reinterpret_cast<int32_t>(buffer_ + pos);
int32_t delta = instr_address - instr; int delta = static_cast<int>(instr_address - instr);
DCHECK(pos > delta); DCHECK(pos > delta);
return pos - delta; return pos - delta;
} }
...@@ -684,6 +684,8 @@ int Assembler::target_at(int32_t pos, bool is_internal) { ...@@ -684,6 +684,8 @@ int Assembler::target_at(int32_t pos, bool is_internal) {
return (imm18 + pos); return (imm18 + pos);
} }
} }
// Check we have a branch or jump instruction.
DCHECK(IsBranch(instr) || IsJ(instr) || IsLui(instr));
// Do NOT change this to <<2. We rely on arithmetic shifts here, assuming // Do NOT change this to <<2. We rely on arithmetic shifts here, assuming
// the compiler uses arithmectic shifts for signed integers. // the compiler uses arithmectic shifts for signed integers.
if (IsBranch(instr)) { if (IsBranch(instr)) {
...@@ -711,7 +713,7 @@ int Assembler::target_at(int32_t pos, bool is_internal) { ...@@ -711,7 +713,7 @@ int Assembler::target_at(int32_t pos, bool is_internal) {
DCHECK(pos > delta); DCHECK(pos > delta);
return pos - delta; return pos - delta;
} }
} else if (IsJ(instr)) { } else {
int32_t imm28 = (instr & static_cast<int32_t>(kImm26Mask)) << 2; int32_t imm28 = (instr & static_cast<int32_t>(kImm26Mask)) << 2;
if (imm28 == kEndOfJumpChain) { if (imm28 == kEndOfJumpChain) {
// EndOfChain sentinel is returned directly, not relative to pc or pos. // EndOfChain sentinel is returned directly, not relative to pc or pos.
...@@ -719,13 +721,10 @@ int Assembler::target_at(int32_t pos, bool is_internal) { ...@@ -719,13 +721,10 @@ int Assembler::target_at(int32_t pos, bool is_internal) {
} else { } else {
uint32_t instr_address = reinterpret_cast<int32_t>(buffer_ + pos); uint32_t instr_address = reinterpret_cast<int32_t>(buffer_ + pos);
instr_address &= kImm28Mask; instr_address &= kImm28Mask;
int32_t delta = instr_address - imm28; int delta = static_cast<int>(instr_address - imm28);
DCHECK(pos > delta); DCHECK(pos > delta);
return pos - delta; return pos - delta;
} }
} else {
UNREACHABLE();
return 0;
} }
} }
...@@ -747,6 +746,7 @@ void Assembler::target_at_put(int32_t pos, int32_t target_pos, ...@@ -747,6 +746,7 @@ void Assembler::target_at_put(int32_t pos, int32_t target_pos,
return; return;
} }
DCHECK(IsBranch(instr) || IsJ(instr) || IsLui(instr));
if (IsBranch(instr)) { if (IsBranch(instr)) {
int32_t imm18 = target_pos - (pos + kBranchPCOffset); int32_t imm18 = target_pos - (pos + kBranchPCOffset);
DCHECK((imm18 & 3) == 0); DCHECK((imm18 & 3) == 0);
...@@ -770,7 +770,7 @@ void Assembler::target_at_put(int32_t pos, int32_t target_pos, ...@@ -770,7 +770,7 @@ void Assembler::target_at_put(int32_t pos, int32_t target_pos,
instr_lui | ((imm & kHiMask) >> kLuiShift)); instr_lui | ((imm & kHiMask) >> kLuiShift));
instr_at_put(pos + 1 * Assembler::kInstrSize, instr_at_put(pos + 1 * Assembler::kInstrSize,
instr_ori | (imm & kImm16Mask)); instr_ori | (imm & kImm16Mask));
} else if (IsJ(instr)) { } else {
uint32_t imm28 = reinterpret_cast<uint32_t>(buffer_) + target_pos; uint32_t imm28 = reinterpret_cast<uint32_t>(buffer_) + target_pos;
imm28 &= kImm28Mask; imm28 &= kImm28Mask;
DCHECK((imm28 & 3) == 0); DCHECK((imm28 & 3) == 0);
...@@ -780,8 +780,6 @@ void Assembler::target_at_put(int32_t pos, int32_t target_pos, ...@@ -780,8 +780,6 @@ void Assembler::target_at_put(int32_t pos, int32_t target_pos,
DCHECK(is_uint26(imm26)); DCHECK(is_uint26(imm26));
instr_at_put(pos, instr | (imm26 & kImm26Mask)); instr_at_put(pos, instr | (imm26 & kImm26Mask));
} else {
UNREACHABLE();
} }
} }
......
...@@ -1129,10 +1129,10 @@ class Assembler : public AssemblerBase { ...@@ -1129,10 +1129,10 @@ class Assembler : public AssemblerBase {
int32_t buffer_space() const { return reloc_info_writer.pos() - pc_; } int32_t buffer_space() const { return reloc_info_writer.pos() - pc_; }
// Decode branch instruction at pos and return branch target pos. // Decode branch instruction at pos and return branch target pos.
int target_at(int32_t pos, bool is_internal); int target_at(int pos, bool is_internal);
// Patch branch instruction at pos to branch to given branch target pos. // Patch branch instruction at pos to branch to given branch target pos.
void target_at_put(int32_t pos, int32_t target_pos, bool is_internal); void target_at_put(int pos, int target_pos, bool is_internal);
// Say if we need to relocate with this mode. // Say if we need to relocate with this mode.
bool MustUseReg(RelocInfo::Mode rmode); bool MustUseReg(RelocInfo::Mode rmode);
......
...@@ -32,7 +32,6 @@ ...@@ -32,7 +32,6 @@
// modified significantly by Google Inc. // modified significantly by Google Inc.
// Copyright 2012 the V8 project authors. All rights reserved. // Copyright 2012 the V8 project authors. All rights reserved.
#include "src/v8.h" #include "src/v8.h"
#if V8_TARGET_ARCH_MIPS64 #if V8_TARGET_ARCH_MIPS64
...@@ -635,7 +634,7 @@ bool Assembler::IsAndImmediate(Instr instr) { ...@@ -635,7 +634,7 @@ bool Assembler::IsAndImmediate(Instr instr) {
} }
int64_t Assembler::target_at(int64_t pos, bool is_internal) { int Assembler::target_at(int pos, bool is_internal) {
if (is_internal) { if (is_internal) {
int64_t* p = reinterpret_cast<int64_t*>(buffer_ + pos); int64_t* p = reinterpret_cast<int64_t*>(buffer_ + pos);
int64_t address = *p; int64_t address = *p;
...@@ -643,7 +642,8 @@ int64_t Assembler::target_at(int64_t pos, bool is_internal) { ...@@ -643,7 +642,8 @@ int64_t Assembler::target_at(int64_t pos, bool is_internal) {
return kEndOfChain; return kEndOfChain;
} else { } else {
int64_t instr_address = reinterpret_cast<int64_t>(p); int64_t instr_address = reinterpret_cast<int64_t>(p);
int64_t delta = instr_address - address; DCHECK(instr_address - address < INT_MAX);
int delta = static_cast<int>(instr_address - address);
DCHECK(pos > delta); DCHECK(pos > delta);
return pos - delta; return pos - delta;
} }
...@@ -689,7 +689,8 @@ int64_t Assembler::target_at(int64_t pos, bool is_internal) { ...@@ -689,7 +689,8 @@ int64_t Assembler::target_at(int64_t pos, bool is_internal) {
return kEndOfChain; return kEndOfChain;
} else { } else {
uint64_t instr_address = reinterpret_cast<int64_t>(buffer_ + pos); uint64_t instr_address = reinterpret_cast<int64_t>(buffer_ + pos);
int64_t delta = instr_address - imm; DCHECK(instr_address - imm < INT_MAX);
int delta = static_cast<int>(instr_address - imm);
DCHECK(pos > delta); DCHECK(pos > delta);
return pos - delta; return pos - delta;
} }
...@@ -701,7 +702,7 @@ int64_t Assembler::target_at(int64_t pos, bool is_internal) { ...@@ -701,7 +702,7 @@ int64_t Assembler::target_at(int64_t pos, bool is_internal) {
} else { } else {
uint64_t instr_address = reinterpret_cast<int64_t>(buffer_ + pos); uint64_t instr_address = reinterpret_cast<int64_t>(buffer_ + pos);
instr_address &= kImm28Mask; instr_address &= kImm28Mask;
int64_t delta = instr_address - imm28; int delta = static_cast<int>(instr_address - imm28);
DCHECK(pos > delta); DCHECK(pos > delta);
return pos - delta; return pos - delta;
} }
...@@ -709,8 +710,7 @@ int64_t Assembler::target_at(int64_t pos, bool is_internal) { ...@@ -709,8 +710,7 @@ int64_t Assembler::target_at(int64_t pos, bool is_internal) {
} }
void Assembler::target_at_put(int64_t pos, int64_t target_pos, void Assembler::target_at_put(int pos, int target_pos, bool is_internal) {
bool is_internal) {
if (is_internal) { if (is_internal) {
uint64_t imm = reinterpret_cast<uint64_t>(buffer_) + target_pos; uint64_t imm = reinterpret_cast<uint64_t>(buffer_) + target_pos;
*reinterpret_cast<uint64_t*>(buffer_ + pos) = imm; *reinterpret_cast<uint64_t*>(buffer_ + pos) = imm;
...@@ -796,7 +796,7 @@ void Assembler::print(Label* L) { ...@@ -796,7 +796,7 @@ void Assembler::print(Label* L) {
void Assembler::bind_to(Label* L, int pos) { void Assembler::bind_to(Label* L, int pos) {
DCHECK(0 <= pos && pos <= pc_offset()); // Must have valid binding position. DCHECK(0 <= pos && pos <= pc_offset()); // Must have valid binding position.
int32_t trampoline_pos = kInvalidSlotPos; int trampoline_pos = kInvalidSlotPos;
bool is_internal = false; bool is_internal = false;
if (L->is_linked() && !trampoline_emitted_) { if (L->is_linked() && !trampoline_emitted_) {
unbound_labels_count_--; unbound_labels_count_--;
...@@ -804,8 +804,8 @@ void Assembler::bind_to(Label* L, int pos) { ...@@ -804,8 +804,8 @@ void Assembler::bind_to(Label* L, int pos) {
} }
while (L->is_linked()) { while (L->is_linked()) {
int32_t fixup_pos = L->pos(); int fixup_pos = L->pos();
int32_t dist = pos - fixup_pos; int dist = pos - fixup_pos;
is_internal = internal_reference_positions_.find(fixup_pos) != is_internal = internal_reference_positions_.find(fixup_pos) !=
internal_reference_positions_.end(); internal_reference_positions_.end();
next(L, is_internal); // Call next before overwriting link with target at next(L, is_internal); // Call next before overwriting link with target at
......
...@@ -1168,10 +1168,10 @@ class Assembler : public AssemblerBase { ...@@ -1168,10 +1168,10 @@ class Assembler : public AssemblerBase {
int64_t buffer_space() const { return reloc_info_writer.pos() - pc_; } int64_t buffer_space() const { return reloc_info_writer.pos() - pc_; }
// Decode branch instruction at pos and return branch target pos. // Decode branch instruction at pos and return branch target pos.
int64_t target_at(int64_t pos, bool is_internal); int target_at(int pos, bool is_internal);
// Patch branch instruction at pos to branch to given branch target pos. // Patch branch instruction at pos to branch to given branch target pos.
void target_at_put(int64_t pos, int64_t target_pos, bool is_internal); void target_at_put(int pos, int target_pos, bool is_internal);
// Say if we need to relocate with this mode. // Say if we need to relocate with this mode.
bool MustUseReg(RelocInfo::Mode rmode); bool MustUseReg(RelocInfo::Mode rmode);
......
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