Reviewers: Benedikt Meurer, paul.l..., Hablich, dusmil.imgtec,
Description:
MIPS64: Fix BlockTrampolinePoolFor() to emit trampoline before blocking, if
needed.
Port f0d1106a3fa1ffaa822efc90d61e2aca315cbe15
Fixes possible failure in AssembleArchTableSwitch().
BUG=v8:4294
LOG=y
Please review this at https://codereview.chromium.org/1235883004/
Base URL: https://chromium.googlesource.com/v8/v8.git@master
Affected files (+96, -3 lines):
M src/mips64/assembler-mips64.h
M src/mips64/assembler-mips64.cc
M src/mips64/assembler-mips64-inl.h
M test/cctest/test-assembler-mips64.cc
M test/cctest/test-macro-assembler-mips64.cc
Index: src/mips64/assembler-mips64-inl.h
diff --git a/src/mips64/assembler-mips64-inl.h
b/src/mips64/assembler-mips64-inl.h
index
40c7640f2f8272b99c2ae826605098dc3117314b..bfeb3002eb631e169302d7575d62c3b5432120ad
100644
--- a/src/mips64/assembler-mips64-inl.h
+++ b/src/mips64/assembler-mips64-inl.h
@@ -493,8 +493,8 @@ void Assembler::CheckBuffer() {
}
-void Assembler::CheckTrampolinePoolQuick() {
- if (pc_offset() >= next_buffer_check_) {
+void Assembler::CheckTrampolinePoolQuick(int extra_instructions) {
+ if (pc_offset() >= next_buffer_check_ - extra_instructions * kInstrSize)
{
CheckTrampolinePool();
}
}
Index: src/mips64/assembler-mips64.cc
diff --git a/src/mips64/assembler-mips64.cc b/src/mips64/assembler-mips64.cc
index
84be689de17bca0318490ff49ccc0035365ce0ba..e44b4294dd62b5d3ac05480158d7cf109ebe6e31
100644
--- a/src/mips64/assembler-mips64.cc
+++ b/src/mips64/assembler-mips64.cc
@@ -3097,6 +3097,7 @@ void Assembler::RecordRelocInfo(RelocInfo::Mode
rmode, intptr_t data) {
void Assembler::BlockTrampolinePoolFor(int instructions) {
+ CheckTrampolinePoolQuick(instructions);
BlockTrampolinePoolBefore(pc_offset() + instructions * kInstrSize);
}
Index: src/mips64/assembler-mips64.h
diff --git a/src/mips64/assembler-mips64.h b/src/mips64/assembler-mips64.h
index
9f0a9bb8e719f3ecd107a2305cf418aaa7f3cb18..5414d5c6a744d3c0fbb9d3a161856309ff108d1e
100644
--- a/src/mips64/assembler-mips64.h
+++ b/src/mips64/assembler-mips64.h
@@ -1342,7 +1342,7 @@ class Assembler : public AssemblerBase {
void GrowBuffer();
inline void emit(Instr x);
inline void emit(uint64_t x);
- inline void CheckTrampolinePoolQuick();
+ inline void CheckTrampolinePoolQuick(int extra_instructions = 0);
// Instruction generation.
// We have 3 different kind of encoding layout on MIPS.
Index: test/cctest/test-assembler-mips64.cc
diff --git a/test/cctest/test-assembler-mips64.cc
b/test/cctest/test-assembler-mips64.cc
index
c4db5b52c14222738919385fc8a51056ab9a4ca6..bb7b05ca768c09b897b04ce0e881e7c9f6416a5f
100644
--- a/test/cctest/test-assembler-mips64.cc
+++ b/test/cctest/test-assembler-mips64.cc
@@ -3082,6 +3082,7 @@ TEST(jump_tables1) {
Label done;
{
+ __ BlockTrampolinePoolFor(kNumCases * 2 + 7);
PredictableCodeSizeScope predictable(
&assm, (kNumCases * 2 + 7) * Assembler::kInstrSize);
Label here;
@@ -3162,6 +3163,7 @@ TEST(jump_tables2) {
}
__ bind(&dispatch);
{
+ __ BlockTrampolinePoolFor(kNumCases * 2 + 7);
PredictableCodeSizeScope predictable(
&assm, (kNumCases * 2 + 7) * Assembler::kInstrSize);
Label here;
@@ -3244,6 +3246,7 @@ TEST(jump_tables3) {
}
__ bind(&dispatch);
{
+ __ BlockTrampolinePoolFor(kNumCases * 2 + 7);
PredictableCodeSizeScope predictable(
&assm, (kNumCases * 2 + 7) * Assembler::kInstrSize);
Label here;
Index: test/cctest/test-macro-assembler-mips64.cc
diff --git a/test/cctest/test-macro-assembler-mips64.cc
b/test/cctest/test-macro-assembler-mips64.cc
index
eef658de67fef55ccada02340cdb5a43b14f20d6..fadd45f43b08a779f303a08f0f2f8d30812a2cc7
100644
--- a/test/cctest/test-macro-assembler-mips64.cc
+++ b/test/cctest/test-macro-assembler-mips64.cc
@@ -26,10 +26,12 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <stdlib.h>
+#include <iostream> // NOLINT(readability/streams)
#include "src/v8.h"
#include "test/cctest/cctest.h"
+#include "src/base/utils/random-number-generator.h"
#include "src/macro-assembler.h"
#include "src/mips64/macro-assembler-mips64.h"
#include "src/mips64/simulator-mips64.h"
@@ -38,6 +40,7 @@
using namespace v8::internal;
typedef void* (*F)(int64_t x, int64_t y, int p2, int p3, int p4);
+typedef Object* (*F1)(int x, int p1, int p2, int p3, int p4);
#define __ masm->
@@ -214,4 +217,90 @@ TEST(LoadAddress) {
// Check results.
}
+
+TEST(jump_tables4) {
+ // Similar to test-assembler-mips jump_tables1, with extra test for
branch
+ // trampoline required before emission of the dd table (where
trampolines are
+ // blocked), and proper transition to long-branch mode.
+ // Regression test for v8:4294.
+ CcTest::InitializeVM();
+ Isolate* isolate = CcTest::i_isolate();
+ HandleScope scope(isolate);
+ MacroAssembler assembler(isolate, NULL, 0);
+ MacroAssembler* masm = &assembler;
+
+ const int kNumCases = 512;
+ int values[kNumCases];
+ isolate->random_number_generator()->NextBytes(values, sizeof(values));
+ Label labels[kNumCases];
+ Label near_start, end;
+
+ __ daddiu(sp, sp, -8);
+ __ sd(ra, MemOperand(sp));
+ if ((masm->pc_offset() & 7) == 0) {
+ __ nop();
+ }
+
+ __ mov(v0, zero_reg);
+
+ __ Branch(&end);
+ __ bind(&near_start);
+
+ // Generate slightly less than 32K instructions, which will soon require
+ // trampoline for branch distance fixup.
+ for (int i = 0; i < 32768 - 256; ++i) {
+ __ addiu(v0, v0, 1);
+ }
+
+ Label done;
+ {
+ __ BlockTrampolinePoolFor(kNumCases * 2 + 6);
+ PredictableCodeSizeScope predictable(
+ masm, (kNumCases * 2 + 6) * Assembler::kInstrSize);
+ Label here;
+
+ __ bal(&here);
+ __ dsll(at, a0, 3); // In delay slot.
+ __ bind(&here);
+ __ daddu(at, at, ra);
+ __ ld(at, MemOperand(at, 4 * Assembler::kInstrSize));
+ __ jr(at);
+ __ nop(); // Branch delay slot nop.
+ for (int i = 0; i < kNumCases; ++i) {
+ __ dd(&labels[i]);
+ }
+ }
+
+ for (int i = 0; i < kNumCases; ++i) {
+ __ bind(&labels[i]);
+ __ lui(v0, (values[i] >> 16) & 0xffff);
+ __ ori(v0, v0, values[i] & 0xffff);
+ __ Branch(&done);
+ }
+
+ __ bind(&done);
+ __ ld(ra, MemOperand(sp));
+ __ daddiu(sp, sp, 8);
+ __ jr(ra);
+ __ nop();
+
+ __ bind(&end);
+ __ Branch(&near_start);
+
+ CodeDesc desc;
+ masm->GetCode(&desc);
+ Handle<Code> code = isolate->factory()->NewCode(
+ desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
+#ifdef OBJECT_PRINT
+ code->Print(std::cout);
+#endif
+ F1 f = FUNCTION_CAST<F1>(code->entry());
+ for (int i = 0; i < kNumCases; ++i) {
+ int64_t res =
+ reinterpret_cast<int64_t>(CALL_GENERATED_CODE(f, i, 0, 0, 0, 0));
+ ::printf("f(%d) = %" PRId64 "\n", i, res);
+ CHECK_EQ(values[i], res);
+ }
+}
+
#undef __
--
--
v8-dev mailing list
v8-dev@googlegroups.com
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to v8-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.