Index: test/cctest/test-macro-assembler-mips.cc |
diff --git a/test/cctest/test-macro-assembler-mips.cc b/test/cctest/test-macro-assembler-mips.cc |
index 73de1bd5498cb107986541ea6cc4884bf61dc5f2..45dbadb8f87f13fe2fe1d78fb11f5e7ff3e9a76b 100644 |
--- a/test/cctest/test-macro-assembler-mips.cc |
+++ b/test/cctest/test-macro-assembler-mips.cc |
@@ -261,4 +261,85 @@ TEST(jump_tables4) { |
} |
+static uint32_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()); |
+ |
+ uint32_t res = reinterpret_cast<uint32_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; |
+ uint32_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, 0xfffffffc}, |
+ {0x4, INT32_MAX >> 3, 4, 0xfffffff4}, |
+ {0x4, INT32_MAX >> 4, 5, 0xffffffe4}, |
+ |
+ // Signed addition overflow. |
+ {INT32_MAX - 1, 0x1, 1, 0x80000000}, |
+ {INT32_MAX - 3, 0x1, 2, 0x80000000}, |
+ {INT32_MAX - 7, 0x1, 3, 0x80000000}, |
+ {INT32_MAX - 15, 0x1, 4, 0x80000000}, |
+ {INT32_MAX - 31, 0x1, 5, 0x80000000}, |
+ |
+ // 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) { |
+ uint32_t res = run_lsa(tc[i].rt, tc[i].rs, tc[i].sa); |
+ PrintF("0x%x =? 0x%x == 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); |
+ } |
+} |
+ |
#undef __ |