Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1499)

Unified Diff: test/cctest/test-macro-assembler-mips64.cc

Issue 1545013002: Add assembler test. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebased Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/cctest/test-macro-assembler-mips.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 fa045a25633452e7bfc0e7c00b5c6cb1cfa0d1c2..f6befcda75b3811f97a0ef758d19b02abdc01474 100644
--- a/test/cctest/test-macro-assembler-mips64.cc
+++ b/test/cctest/test-macro-assembler-mips64.cc
@@ -306,4 +306,169 @@ TEST(jump_tables4) {
}
}
+
+static uint64_t run_lsa(uint32_t rt, uint32_t rs, int8_t sa) {
+ Isolate* isolate = CcTest::i_isolate();
+ HandleScope scope(isolate);
+ MacroAssembler assembler(isolate, nullptr, 0,
+ v8::internal::CodeObjectRequired::kYes);
+ MacroAssembler* masm = &assembler;
+
+ __ Lsa(v0, a0, a1, sa);
+ __ jr(ra);
+ __ nop();
+
+ CodeDesc desc;
+ assembler.GetCode(&desc);
+ Handle<Code> code = isolate->factory()->NewCode(
+ desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
+
+ F1 f = FUNCTION_CAST<F1>(code->entry());
+
+ uint64_t res = reinterpret_cast<uint64_t>(
+ CALL_GENERATED_CODE(isolate, f, rt, rs, 0, 0, 0));
+
+ return res;
+}
+
+
+TEST(Lsa) {
+ CcTest::InitializeVM();
+ struct TestCaseLsa {
+ int32_t rt;
+ int32_t rs;
+ uint8_t sa;
+ uint64_t expected_res;
+ };
+
+ struct TestCaseLsa tc[] = {// rt, rs, sa, expected_res
+ {0x4, 0x1, 1, 0x6},
+ {0x4, 0x1, 2, 0x8},
+ {0x4, 0x1, 3, 0xc},
+ {0x4, 0x1, 4, 0x14},
+ {0x4, 0x1, 5, 0x24},
+ {0x0, 0x1, 1, 0x2},
+ {0x0, 0x1, 2, 0x4},
+ {0x0, 0x1, 3, 0x8},
+ {0x0, 0x1, 4, 0x10},
+ {0x0, 0x1, 5, 0x20},
+ {0x4, 0x0, 1, 0x4},
+ {0x4, 0x0, 2, 0x4},
+ {0x4, 0x0, 3, 0x4},
+ {0x4, 0x0, 4, 0x4},
+ {0x4, 0x0, 5, 0x4},
+
+ // Shift overflow.
+ {0x4, INT32_MAX, 1, 0x2},
+ {0x4, INT32_MAX >> 1, 2, 0x0},
+ {0x4, INT32_MAX >> 2, 3, 0xfffffffffffffffc},
+ {0x4, INT32_MAX >> 3, 4, 0xfffffffffffffff4},
+ {0x4, INT32_MAX >> 4, 5, 0xffffffffffffffe4},
+
+ // Signed addition overflow.
+ {INT32_MAX - 1, 0x1, 1, 0xffffffff80000000},
+ {INT32_MAX - 3, 0x1, 2, 0xffffffff80000000},
+ {INT32_MAX - 7, 0x1, 3, 0xffffffff80000000},
+ {INT32_MAX - 15, 0x1, 4, 0xffffffff80000000},
+ {INT32_MAX - 31, 0x1, 5, 0xffffffff80000000},
+
+ // Addition overflow.
+ {-2, 0x1, 1, 0x0},
+ {-4, 0x1, 2, 0x0},
+ {-8, 0x1, 3, 0x0},
+ {-16, 0x1, 4, 0x0},
+ {-32, 0x1, 5, 0x0}};
+
+ size_t nr_test_cases = sizeof(tc) / sizeof(TestCaseLsa);
+ for (size_t i = 0; i < nr_test_cases; ++i) {
+ uint64_t res = run_lsa(tc[i].rt, tc[i].rs, tc[i].sa);
+ PrintF("0x%" PRIx64 " =? 0x%" PRIx64 " == Lsa(v0, %x, %x, %hhu)\n",
+ tc[i].expected_res, res, tc[i].rt, tc[i].rs, tc[i].sa);
+ CHECK_EQ(tc[i].expected_res, res);
+ }
+}
+
+
+static uint64_t run_dlsa(uint64_t rt, uint64_t rs, int8_t sa) {
+ Isolate* isolate = CcTest::i_isolate();
+ HandleScope scope(isolate);
+ MacroAssembler assembler(isolate, nullptr, 0,
+ v8::internal::CodeObjectRequired::kYes);
+ MacroAssembler* masm = &assembler;
+
+ __ Dlsa(v0, a0, a1, sa);
+ __ jr(ra);
+ __ nop();
+
+ CodeDesc desc;
+ assembler.GetCode(&desc);
+ Handle<Code> code = isolate->factory()->NewCode(
+ desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
+
+ ::F f = FUNCTION_CAST<::F>(code->entry());
+
+ uint64_t res = reinterpret_cast<uint64_t>(
+ CALL_GENERATED_CODE(isolate, f, rt, rs, 0, 0, 0));
+
+ return res;
+}
+
+
+TEST(Dlsa) {
+ CcTest::InitializeVM();
+ struct TestCaseLsa {
+ int64_t rt;
+ int64_t rs;
+ uint8_t sa;
+ uint64_t expected_res;
+ };
+
+ struct TestCaseLsa tc[] = {// rt, rs, sa, expected_res
+ {0x4, 0x1, 1, 0x6},
+ {0x4, 0x1, 2, 0x8},
+ {0x4, 0x1, 3, 0xc},
+ {0x4, 0x1, 4, 0x14},
+ {0x4, 0x1, 5, 0x24},
+ {0x0, 0x1, 1, 0x2},
+ {0x0, 0x1, 2, 0x4},
+ {0x0, 0x1, 3, 0x8},
+ {0x0, 0x1, 4, 0x10},
+ {0x0, 0x1, 5, 0x20},
+ {0x4, 0x0, 1, 0x4},
+ {0x4, 0x0, 2, 0x4},
+ {0x4, 0x0, 3, 0x4},
+ {0x4, 0x0, 4, 0x4},
+ {0x4, 0x0, 5, 0x4},
+
+ // Shift overflow.
+ {0x4, INT64_MAX, 1, 0x2},
+ {0x4, INT64_MAX >> 1, 2, 0x0},
+ {0x4, INT64_MAX >> 2, 3, 0xfffffffffffffffc},
+ {0x4, INT64_MAX >> 3, 4, 0xfffffffffffffff4},
+ {0x4, INT64_MAX >> 4, 5, 0xffffffffffffffe4},
+
+ // Signed addition overflow.
+ {INT64_MAX - 1, 0x1, 1, 0x8000000000000000},
+ {INT64_MAX - 3, 0x1, 2, 0x8000000000000000},
+ {INT64_MAX - 7, 0x1, 3, 0x8000000000000000},
+ {INT64_MAX - 15, 0x1, 4, 0x8000000000000000},
+ {INT64_MAX - 31, 0x1, 5, 0x8000000000000000},
+
+ // Addition overflow.
+ {-2, 0x1, 1, 0x0},
+ {-4, 0x1, 2, 0x0},
+ {-8, 0x1, 3, 0x0},
+ {-16, 0x1, 4, 0x0},
+ {-32, 0x1, 5, 0x0}};
+
+ size_t nr_test_cases = sizeof(tc) / sizeof(TestCaseLsa);
+ for (size_t i = 0; i < nr_test_cases; ++i) {
+ uint64_t res = run_dlsa(tc[i].rt, tc[i].rs, tc[i].sa);
+ PrintF("0x%" PRIx64 " =? 0x%" PRIx64 " == Dlsa(v0, %" PRIx64 ", %" PRIx64
+ ", %hhu)\n",
+ tc[i].expected_res, res, tc[i].rt, tc[i].rs, tc[i].sa);
+ CHECK_EQ(tc[i].expected_res, res);
+ }
+}
+
#undef __
« no previous file with comments | « test/cctest/test-macro-assembler-mips.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698