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

Unified Diff: test/cctest/test-assembler-x64.cc

Issue 1040603002: [x64] Introduce BMI instructions. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix previous Patch Set Created 5 years, 8 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 | « src/x64/macro-assembler-x64.cc ('k') | test/cctest/test-disasm-x64.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-assembler-x64.cc
diff --git a/test/cctest/test-assembler-x64.cc b/test/cctest/test-assembler-x64.cc
index a6490f06cffea951835b236865eed0ac108846f0..f62b86db416de562e7e70f4d3725259a25b87e00 100644
--- a/test/cctest/test-assembler-x64.cc
+++ b/test/cctest/test-assembler-x64.cc
@@ -1411,6 +1411,575 @@ TEST(AssemblerX64AVX_sd) {
}
+TEST(AssemblerX64BMI1) {
+ CcTest::InitializeVM();
+ if (!CpuFeatures::IsSupported(BMI1)) return;
+
+ Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate());
+ HandleScope scope(isolate);
+ v8::internal::byte buffer[1024];
+ MacroAssembler assm(isolate, buffer, sizeof buffer);
+ {
+ CpuFeatureScope fscope(&assm, BMI1);
+ Label exit;
+
+ __ movq(rcx, V8_UINT64_C(0x1122334455667788)); // source operand
+ __ pushq(rcx); // For memory operand
+
+ // andn
+ __ movq(rdx, V8_UINT64_C(0x1000000020000000));
+
+ __ movl(rax, Immediate(1)); // Test number
+ __ andnq(r8, rdx, rcx);
+ __ movq(r9, V8_UINT64_C(0x0122334455667788)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ __ incq(rax);
+ __ andnq(r8, rdx, Operand(rsp, 0));
+ __ movq(r9, V8_UINT64_C(0x0122334455667788)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ __ incq(rax);
+ __ andnl(r8, rdx, rcx);
+ __ movq(r9, V8_UINT64_C(0x0000000055667788)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ __ incq(rax);
+ __ andnl(r8, rdx, Operand(rsp, 0));
+ __ movq(r9, V8_UINT64_C(0x0000000055667788)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ // bextr
+ __ movq(rdx, V8_UINT64_C(0x0000000000002808));
+
+ __ incq(rax);
+ __ bextrq(r8, rcx, rdx);
+ __ movq(r9, V8_UINT64_C(0x0000003344556677)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ __ incq(rax);
+ __ bextrq(r8, Operand(rsp, 0), rdx);
+ __ movq(r9, V8_UINT64_C(0x0000003344556677)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ __ incq(rax);
+ __ bextrl(r8, rcx, rdx);
+ __ movq(r9, V8_UINT64_C(0x0000000000556677)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ __ incq(rax);
+ __ bextrl(r8, Operand(rsp, 0), rdx);
+ __ movq(r9, V8_UINT64_C(0x0000000000556677)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ // blsi
+ __ incq(rax);
+ __ blsiq(r8, rcx);
+ __ movq(r9, V8_UINT64_C(0x0000000000000008)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ __ incq(rax);
+ __ blsiq(r8, Operand(rsp, 0));
+ __ movq(r9, V8_UINT64_C(0x0000000000000008)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ __ incq(rax);
+ __ blsil(r8, rcx);
+ __ movq(r9, V8_UINT64_C(0x0000000000000008)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ __ incq(rax);
+ __ blsil(r8, Operand(rsp, 0));
+ __ movq(r9, V8_UINT64_C(0x0000000000000008)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ // blsmsk
+ __ incq(rax);
+ __ blsmskq(r8, rcx);
+ __ movq(r9, V8_UINT64_C(0x000000000000000f)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ __ incq(rax);
+ __ blsmskq(r8, Operand(rsp, 0));
+ __ movq(r9, V8_UINT64_C(0x000000000000000f)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ __ incq(rax);
+ __ blsmskl(r8, rcx);
+ __ movq(r9, V8_UINT64_C(0x000000000000000f)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ __ incq(rax);
+ __ blsmskl(r8, Operand(rsp, 0));
+ __ movq(r9, V8_UINT64_C(0x000000000000000f)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ // blsr
+ __ incq(rax);
+ __ blsrq(r8, rcx);
+ __ movq(r9, V8_UINT64_C(0x1122334455667780)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ __ incq(rax);
+ __ blsrq(r8, Operand(rsp, 0));
+ __ movq(r9, V8_UINT64_C(0x1122334455667780)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ __ incq(rax);
+ __ blsrl(r8, rcx);
+ __ movq(r9, V8_UINT64_C(0x0000000055667780)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ __ incq(rax);
+ __ blsrl(r8, Operand(rsp, 0));
+ __ movq(r9, V8_UINT64_C(0x0000000055667780)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ // tzcnt
+ __ incq(rax);
+ __ tzcntq(r8, rcx);
+ __ movq(r9, V8_UINT64_C(0x0000000000000003)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ __ incq(rax);
+ __ tzcntq(r8, Operand(rsp, 0));
+ __ movq(r9, V8_UINT64_C(0x0000000000000003)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ __ incq(rax);
+ __ tzcntl(r8, rcx);
+ __ movq(r9, V8_UINT64_C(0x0000000000000003)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ __ incq(rax);
+ __ tzcntl(r8, Operand(rsp, 0));
+ __ movq(r9, V8_UINT64_C(0x0000000000000003)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ __ xorl(rax, rax);
+ __ bind(&exit);
+ __ popq(rcx);
+ __ ret(0);
+ }
+
+ CodeDesc desc;
+ assm.GetCode(&desc);
+ Handle<Code> code = isolate->factory()->NewCode(
+ desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
+#ifdef OBJECT_PRINT
+ OFStream os(stdout);
+ code->Print(os);
+#endif
+
+ F0 f = FUNCTION_CAST<F0>(code->entry());
+ CHECK_EQ(0, f());
+}
+
+
+TEST(AssemblerX64LZCNT) {
+ CcTest::InitializeVM();
+ if (!CpuFeatures::IsSupported(LZCNT)) return;
+
+ Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate());
+ HandleScope scope(isolate);
+ v8::internal::byte buffer[256];
+ MacroAssembler assm(isolate, buffer, sizeof buffer);
+ {
+ CpuFeatureScope fscope(&assm, LZCNT);
+ Label exit;
+
+ __ movq(rcx, V8_UINT64_C(0x1122334455667788)); // source operand
+ __ pushq(rcx); // For memory operand
+
+ __ movl(rax, Immediate(1)); // Test number
+ __ lzcntq(r8, rcx);
+ __ movq(r9, V8_UINT64_C(0x0000000000000003)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ __ incq(rax);
+ __ lzcntq(r8, Operand(rsp, 0));
+ __ movq(r9, V8_UINT64_C(0x0000000000000003)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ __ incq(rax);
+ __ lzcntl(r8, rcx);
+ __ movq(r9, V8_UINT64_C(0x0000000000000001)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ __ incq(rax);
+ __ lzcntl(r8, Operand(rsp, 0));
+ __ movq(r9, V8_UINT64_C(0x0000000000000001)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ __ xorl(rax, rax);
+ __ bind(&exit);
+ __ popq(rcx);
+ __ ret(0);
+ }
+
+ CodeDesc desc;
+ assm.GetCode(&desc);
+ Handle<Code> code = isolate->factory()->NewCode(
+ desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
+#ifdef OBJECT_PRINT
+ OFStream os(stdout);
+ code->Print(os);
+#endif
+
+ F0 f = FUNCTION_CAST<F0>(code->entry());
+ CHECK_EQ(0, f());
+}
+
+
+TEST(AssemblerX64POPCNT) {
+ CcTest::InitializeVM();
+ if (!CpuFeatures::IsSupported(POPCNT)) return;
+
+ Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate());
+ HandleScope scope(isolate);
+ v8::internal::byte buffer[256];
+ MacroAssembler assm(isolate, buffer, sizeof buffer);
+ {
+ CpuFeatureScope fscope(&assm, POPCNT);
+ Label exit;
+
+ __ movq(rcx, V8_UINT64_C(0x1111111111111100)); // source operand
+ __ pushq(rcx); // For memory operand
+
+ __ movl(rax, Immediate(1)); // Test number
+ __ popcntq(r8, rcx);
+ __ movq(r9, V8_UINT64_C(0x000000000000000e)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ __ incq(rax);
+ __ popcntq(r8, Operand(rsp, 0));
+ __ movq(r9, V8_UINT64_C(0x000000000000000e)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ __ incq(rax);
+ __ popcntl(r8, rcx);
+ __ movq(r9, V8_UINT64_C(0x0000000000000006)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ __ incq(rax);
+ __ popcntl(r8, Operand(rsp, 0));
+ __ movq(r9, V8_UINT64_C(0x0000000000000006)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ __ xorl(rax, rax);
+ __ bind(&exit);
+ __ popq(rcx);
+ __ ret(0);
+ }
+
+ CodeDesc desc;
+ assm.GetCode(&desc);
+ Handle<Code> code = isolate->factory()->NewCode(
+ desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
+#ifdef OBJECT_PRINT
+ OFStream os(stdout);
+ code->Print(os);
+#endif
+
+ F0 f = FUNCTION_CAST<F0>(code->entry());
+ CHECK_EQ(0, f());
+}
+
+
+TEST(AssemblerX64BMI2) {
+ CcTest::InitializeVM();
+ if (!CpuFeatures::IsSupported(BMI2)) return;
+
+ Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate());
+ HandleScope scope(isolate);
+ v8::internal::byte buffer[2048];
+ MacroAssembler assm(isolate, buffer, sizeof buffer);
+ {
+ CpuFeatureScope fscope(&assm, BMI2);
+ Label exit;
+ __ pushq(rbx); // save rbx
+ __ movq(rcx, V8_UINT64_C(0x1122334455667788)); // source operand
+ __ pushq(rcx); // For memory operand
+
+ // bzhi
+ __ movq(rdx, V8_UINT64_C(0x0000000000000009));
+
+ __ movl(rax, Immediate(1)); // Test number
+ __ bzhiq(r8, rcx, rdx);
+ __ movq(r9, V8_UINT64_C(0x0000000000000188)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ __ incq(rax);
+ __ bzhiq(r8, Operand(rsp, 0), rdx);
+ __ movq(r9, V8_UINT64_C(0x0000000000000188)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ __ incq(rax);
+ __ bzhil(r8, rcx, rdx);
+ __ movq(r9, V8_UINT64_C(0x0000000000000188)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ __ incq(rax);
+ __ bzhil(r8, Operand(rsp, 0), rdx);
+ __ movq(r9, V8_UINT64_C(0x0000000000000188)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ // mulx
+ __ movq(rdx, V8_UINT64_C(0x0000000000001000));
+
+ __ incq(rax);
+ __ mulxq(r8, r9, rcx);
+ __ movq(rbx, V8_UINT64_C(0x0000000000000112)); // expected result
+ __ cmpq(r8, rbx);
+ __ j(not_equal, &exit);
+ __ movq(rbx, V8_UINT64_C(0x2334455667788000)); // expected result
+ __ cmpq(r9, rbx);
+ __ j(not_equal, &exit);
+
+ __ incq(rax);
+ __ mulxq(r8, r9, Operand(rsp, 0));
+ __ movq(rbx, V8_UINT64_C(0x0000000000000112)); // expected result
+ __ cmpq(r8, rbx);
+ __ j(not_equal, &exit);
+ __ movq(rbx, V8_UINT64_C(0x2334455667788000)); // expected result
+ __ cmpq(r9, rbx);
+ __ j(not_equal, &exit);
+
+ __ incq(rax);
+ __ mulxl(r8, r9, rcx);
+ __ movq(rbx, V8_UINT64_C(0x0000000000000556)); // expected result
+ __ cmpq(r8, rbx);
+ __ j(not_equal, &exit);
+ __ movq(rbx, V8_UINT64_C(0x0000000067788000)); // expected result
+ __ cmpq(r9, rbx);
+ __ j(not_equal, &exit);
+
+ __ incq(rax);
+ __ mulxl(r8, r9, Operand(rsp, 0));
+ __ movq(rbx, V8_UINT64_C(0x0000000000000556)); // expected result
+ __ cmpq(r8, rbx);
+ __ j(not_equal, &exit);
+ __ movq(rbx, V8_UINT64_C(0x0000000067788000)); // expected result
+ __ cmpq(r9, rbx);
+ __ j(not_equal, &exit);
+
+ // pdep
+ __ movq(rdx, V8_UINT64_C(0xfffffffffffffff0));
+
+ __ incq(rax);
+ __ pdepq(r8, rdx, rcx);
+ __ movq(r9, V8_UINT64_C(0x1122334455667400)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ __ incq(rax);
+ __ pdepq(r8, rdx, Operand(rsp, 0));
+ __ movq(r9, V8_UINT64_C(0x1122334455667400)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ __ incq(rax);
+ __ pdepl(r8, rdx, rcx);
+ __ movq(r9, V8_UINT64_C(0x0000000055667400)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ __ incq(rax);
+ __ pdepl(r8, rdx, Operand(rsp, 0));
+ __ movq(r9, V8_UINT64_C(0x0000000055667400)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ // pext
+ __ movq(rdx, V8_UINT64_C(0xfffffffffffffff0));
+
+ __ incq(rax);
+ __ pextq(r8, rdx, rcx);
+ __ movq(r9, V8_UINT64_C(0x0000000003fffffe)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ __ incq(rax);
+ __ pextq(r8, rdx, Operand(rsp, 0));
+ __ movq(r9, V8_UINT64_C(0x0000000003fffffe)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ __ incq(rax);
+ __ pextl(r8, rdx, rcx);
+ __ movq(r9, V8_UINT64_C(0x000000000000fffe)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ __ incq(rax);
+ __ pextl(r8, rdx, Operand(rsp, 0));
+ __ movq(r9, V8_UINT64_C(0x000000000000fffe)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ // sarx
+ __ movq(rdx, V8_UINT64_C(0x0000000000000004));
+
+ __ incq(rax);
+ __ sarxq(r8, rcx, rdx);
+ __ movq(r9, V8_UINT64_C(0x0112233445566778)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ __ incq(rax);
+ __ sarxq(r8, Operand(rsp, 0), rdx);
+ __ movq(r9, V8_UINT64_C(0x0112233445566778)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ __ incq(rax);
+ __ sarxl(r8, rcx, rdx);
+ __ movq(r9, V8_UINT64_C(0x0000000005566778)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ __ incq(rax);
+ __ sarxl(r8, Operand(rsp, 0), rdx);
+ __ movq(r9, V8_UINT64_C(0x0000000005566778)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ // shlx
+ __ movq(rdx, V8_UINT64_C(0x0000000000000004));
+
+ __ incq(rax);
+ __ shlxq(r8, rcx, rdx);
+ __ movq(r9, V8_UINT64_C(0x1223344556677880)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ __ incq(rax);
+ __ shlxq(r8, Operand(rsp, 0), rdx);
+ __ movq(r9, V8_UINT64_C(0x1223344556677880)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ __ incq(rax);
+ __ shlxl(r8, rcx, rdx);
+ __ movq(r9, V8_UINT64_C(0x0000000056677880)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ __ incq(rax);
+ __ shlxl(r8, Operand(rsp, 0), rdx);
+ __ movq(r9, V8_UINT64_C(0x0000000056677880)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ // shrx
+ __ movq(rdx, V8_UINT64_C(0x0000000000000004));
+
+ __ incq(rax);
+ __ shrxq(r8, rcx, rdx);
+ __ movq(r9, V8_UINT64_C(0x0112233445566778)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ __ incq(rax);
+ __ shrxq(r8, Operand(rsp, 0), rdx);
+ __ movq(r9, V8_UINT64_C(0x0112233445566778)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ __ incq(rax);
+ __ shrxl(r8, rcx, rdx);
+ __ movq(r9, V8_UINT64_C(0x0000000005566778)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ __ incq(rax);
+ __ shrxl(r8, Operand(rsp, 0), rdx);
+ __ movq(r9, V8_UINT64_C(0x0000000005566778)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ // rorx
+ __ incq(rax);
+ __ rorxq(r8, rcx, 0x4);
+ __ movq(r9, V8_UINT64_C(0x8112233445566778)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ __ incq(rax);
+ __ rorxq(r8, Operand(rsp, 0), 0x4);
+ __ movq(r9, V8_UINT64_C(0x8112233445566778)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ __ incq(rax);
+ __ rorxl(r8, rcx, 0x4);
+ __ movq(r9, V8_UINT64_C(0x0000000085566778)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ __ incq(rax);
+ __ rorxl(r8, Operand(rsp, 0), 0x4);
+ __ movq(r9, V8_UINT64_C(0x0000000085566778)); // expected result
+ __ cmpq(r8, r9);
+ __ j(not_equal, &exit);
+
+ __ xorl(rax, rax);
+ __ bind(&exit);
+ __ popq(rcx);
+ __ popq(rbx);
+ __ ret(0);
+ }
+
+ CodeDesc desc;
+ assm.GetCode(&desc);
+ Handle<Code> code = isolate->factory()->NewCode(
+ desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
+#ifdef OBJECT_PRINT
+ OFStream os(stdout);
+ code->Print(os);
+#endif
+
+ F0 f = FUNCTION_CAST<F0>(code->entry());
+ CHECK_EQ(0, f());
+}
+
+
TEST(AssemblerX64JumpTables1) {
// Test jump tables with forward jumps.
CcTest::InitializeVM();
« no previous file with comments | « src/x64/macro-assembler-x64.cc ('k') | test/cctest/test-disasm-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698