Index: test/cctest/test-assembler-arm.cc |
diff --git a/test/cctest/test-assembler-arm.cc b/test/cctest/test-assembler-arm.cc |
index 250206b899f58471b0b1716c593e0df2bb022708..526d4567fa30cd63d0432c6293471fa2403efcea 100644 |
--- a/test/cctest/test-assembler-arm.cc |
+++ b/test/cctest/test-assembler-arm.cc |
@@ -1885,6 +1885,172 @@ TEST(code_relative_offset) { |
} |
+TEST(jump_tables1) { |
+ // Test jump tables with forward jumps. |
+ CcTest::InitializeVM(); |
+ Isolate* isolate = CcTest::i_isolate(); |
+ HandleScope scope(isolate); |
+ Assembler assm(isolate, nullptr, 0); |
+ |
+ const int kNumCases = 512; |
+ int values[kNumCases]; |
+ isolate->random_number_generator()->NextBytes(values, sizeof(values)); |
+ Label labels[kNumCases]; |
+ |
+ __ stm(db_w, sp, lr.bit()); |
+ |
+ Label done; |
+ __ BlockConstPoolFor(kNumCases + 2); |
+ { |
+ PredictableCodeSizeScope predictable( |
+ &assm, (kNumCases + 2) * Assembler::kInstrSize); |
+ __ ldr(pc, MemOperand(pc, r0, LSL, 2)); |
+ __ nop(); |
+ for (int i = 0; i < kNumCases; ++i) { |
+ __ dd(&labels[i]); |
+ } |
+ } |
+ |
+ for (int i = 0; i < kNumCases; ++i) { |
+ __ bind(&labels[i]); |
+ __ mov(r0, Operand(values[i])); |
+ __ b(&done); |
+ } |
+ |
+ __ bind(&done); |
+ __ ldm(ia_w, sp, pc.bit()); |
+ |
+ CodeDesc desc; |
+ assm.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) { |
+ int res = reinterpret_cast<int>(CALL_GENERATED_CODE(f, i, 0, 0, 0, 0)); |
+ ::printf("f(%d) = %d\n", i, res); |
+ CHECK_EQ(values[i], res); |
+ } |
+} |
+ |
+ |
+TEST(jump_tables2) { |
+ // Test jump tables with backward jumps. |
+ CcTest::InitializeVM(); |
+ Isolate* isolate = CcTest::i_isolate(); |
+ HandleScope scope(isolate); |
+ Assembler assm(isolate, nullptr, 0); |
+ |
+ const int kNumCases = 512; |
+ int values[kNumCases]; |
+ isolate->random_number_generator()->NextBytes(values, sizeof(values)); |
+ Label labels[kNumCases]; |
+ |
+ __ stm(db_w, sp, lr.bit()); |
+ |
+ Label done, dispatch; |
+ __ b(&dispatch); |
+ |
+ for (int i = 0; i < kNumCases; ++i) { |
+ __ bind(&labels[i]); |
+ __ mov(r0, Operand(values[i])); |
+ __ b(&done); |
+ } |
+ |
+ __ bind(&dispatch); |
+ __ BlockConstPoolFor(kNumCases + 2); |
+ { |
+ PredictableCodeSizeScope predictable( |
+ &assm, (kNumCases + 2) * Assembler::kInstrSize); |
+ __ ldr(pc, MemOperand(pc, r0, LSL, 2)); |
+ __ nop(); |
+ for (int i = 0; i < kNumCases; ++i) { |
+ __ dd(&labels[i]); |
+ } |
+ } |
+ |
+ __ bind(&done); |
+ __ ldm(ia_w, sp, pc.bit()); |
+ |
+ CodeDesc desc; |
+ assm.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) { |
+ int res = reinterpret_cast<int>(CALL_GENERATED_CODE(f, i, 0, 0, 0, 0)); |
+ ::printf("f(%d) = %d\n", i, res); |
+ CHECK_EQ(values[i], res); |
+ } |
+} |
+ |
+ |
+TEST(jump_tables3) { |
+ // Test jump tables with backward jumps and embedded heap objects. |
+ CcTest::InitializeVM(); |
+ Isolate* isolate = CcTest::i_isolate(); |
+ HandleScope scope(isolate); |
+ Assembler assm(isolate, nullptr, 0); |
+ |
+ const int kNumCases = 256; |
+ Handle<Object> values[kNumCases]; |
+ for (int i = 0; i < kNumCases; ++i) { |
+ double value = isolate->random_number_generator()->NextDouble(); |
+ values[i] = isolate->factory()->NewHeapNumber(value, IMMUTABLE, TENURED); |
+ } |
+ Label labels[kNumCases]; |
+ |
+ __ stm(db_w, sp, lr.bit()); |
+ |
+ Label done, dispatch; |
+ __ b(&dispatch); |
+ |
+ for (int i = 0; i < kNumCases; ++i) { |
+ __ bind(&labels[i]); |
+ __ mov(r0, Operand(values[i])); |
+ __ b(&done); |
+ } |
+ |
+ __ bind(&dispatch); |
+ __ BlockConstPoolFor(kNumCases + 2); |
+ { |
+ PredictableCodeSizeScope predictable( |
+ &assm, (kNumCases + 2) * Assembler::kInstrSize); |
+ __ ldr(pc, MemOperand(pc, r0, LSL, 2)); |
+ __ nop(); |
+ for (int i = 0; i < kNumCases; ++i) { |
+ __ dd(&labels[i]); |
+ } |
+ } |
+ |
+ __ bind(&done); |
+ __ ldm(ia_w, sp, pc.bit()); |
+ |
+ CodeDesc desc; |
+ assm.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) { |
+ Handle<Object> result(CALL_GENERATED_CODE(f, i, 0, 0, 0, 0), isolate); |
+#ifdef OBJECT_PRINT |
+ ::printf("f(%d) = ", i); |
+ result->Print(std::cout); |
+ ::printf("\n"); |
+#endif |
+ CHECK(values[i].is_identical_to(result)); |
+ } |
+} |
+ |
+ |
TEST(ARMv8_vrintX) { |
// Test the vrintX floating point instructions. |
CcTest::InitializeVM(); |