diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index 3d5ee3631b..f36b1ba4dc 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -235,10 +235,10 @@ RUN(NAME const_02 LABELS cpython llvm c) RUN(NAME const_03 LABELS cpython llvm c EXTRAFILES const_03b.c) RUN(NAME const_04 LABELS cpython llvm c) -RUN(NAME expr_01 LABELS cpython llvm c wasm) -RUN(NAME expr_02 LABELS cpython llvm c wasm) -RUN(NAME expr_03 LABELS cpython llvm c wasm) -RUN(NAME expr_04 LABELS cpython llvm c) +RUN(NAME expr_01 LABELS cpython llvm c wasm wasm_x64) +RUN(NAME expr_02 LABELS cpython llvm c wasm wasm_x64) +RUN(NAME expr_03 LABELS cpython llvm c wasm wasm_x64) +RUN(NAME expr_04 LABELS cpython llvm c wasm) RUN(NAME expr_05 LABELS cpython llvm c) RUN(NAME expr_06 LABELS cpython llvm c) RUN(NAME expr_07 LABELS cpython llvm c) @@ -252,7 +252,7 @@ RUN(NAME expr_13 LABELS llvm c RUN(NAME expr_14 LABELS cpython llvm c) RUN(NAME loop_01 LABELS cpython llvm c) RUN(NAME loop_02 LABELS cpython llvm c wasm wasm_x86 wasm_x64) -RUN(NAME loop_03 LABELS cpython llvm c wasm) +RUN(NAME loop_03 LABELS cpython llvm c wasm wasm_x64) RUN(NAME if_01 LABELS cpython llvm c wasm wasm_x86 wasm_x64) RUN(NAME if_02 LABELS cpython llvm c wasm wasm_x86 wasm_x64) RUN(NAME print_02 LABELS cpython llvm c) @@ -417,7 +417,7 @@ RUN(NAME func_dep_04 LABELS cpython llvm c) RUN(NAME float_01 LABELS cpython llvm wasm wasm_x64) RUN(NAME recursive_01 LABELS cpython llvm wasm wasm_x64 wasm_x86) RUN(NAME comp_01 LABELS cpython llvm wasm wasm_x64) -RUN(NAME bit_operations_i32 LABELS cpython llvm wasm) +RUN(NAME bit_operations_i32 LABELS cpython llvm wasm wasm_x64) RUN(NAME bit_operations_i64 LABELS cpython llvm wasm) RUN(NAME test_argv_01 LABELS llvm) # TODO: Test using CPython diff --git a/src/libasr/codegen/wasm_to_x64.cpp b/src/libasr/codegen/wasm_to_x64.cpp index 42abbf5f0f..acad7b971e 100644 --- a/src/libasr/codegen/wasm_to_x64.cpp +++ b/src/libasr/codegen/wasm_to_x64.cpp @@ -173,8 +173,8 @@ class X64Visitor : public WASMDecoder, /* From WebAssembly Docs: The exact effect of branch depends on that control construct. - In case of block or if it is a forward jump, resuming execution after the matching end. - In case of loop it is a backward jump to the beginning of the loop. + In case of block or if, it is a forward jump, resuming execution after the matching end. + In case of loop, it is a backward jump to the beginning of the loop. */ case Block::LOOP: m_a.asm_jmp_label(".loop.head_" + label); break; case Block::IF: m_a.asm_jmp_label(".else_" + label); break; @@ -297,6 +297,18 @@ class X64Visitor : public WASMDecoder, handleI32Opt([&](){ m_a.asm_div_r64(X64Reg::rbx);}); } + void visit_I32And() { + handleI32Opt([&](){ m_a.asm_and_r64_r64(X64Reg::rax, X64Reg::rbx);}); + } + + void visit_I32Or() { + handleI32Opt([&](){ m_a.asm_or_r64_r64(X64Reg::rax, X64Reg::rbx);}); + } + + void visit_I32Xor() { + handleI32Opt([&](){ m_a.asm_xor_r64_r64(X64Reg::rax, X64Reg::rbx);}); + } + void visit_I32Eqz() { m_a.asm_mov_r64_imm64(X64Reg::rax, 0); m_a.asm_push_r64(X64Reg::rax); diff --git a/src/libasr/codegen/x86_assembler.h b/src/libasr/codegen/x86_assembler.h index a0f99fd2d1..2f5925aa1b 100644 --- a/src/libasr/codegen/x86_assembler.h +++ b/src/libasr/codegen/x86_assembler.h @@ -775,13 +775,6 @@ class X86Assembler { EMIT("ret"); } - void asm_xor_r32_r32(X86Reg r32, X86Reg s32) { - m_code.push_back(m_al, 0x31); - modrm_sib_disp(m_code, m_al, - s32, &r32, nullptr, 1, 0, false); - EMIT("xor " + r2s(r32) + ", " + r2s(s32)); - } - void asm_mov_r32_imm32(X86Reg r32, uint32_t imm32) { m_code.push_back(m_al, 0xb8 + r32); push_back_uint32(m_code, m_al, imm32); @@ -1212,6 +1205,49 @@ class X86Assembler { EMIT("and " + r2s(r32) + ", " + i2s(imm32)); } + void asm_and_r64_r64(X64Reg r64, X64Reg s64) { + X86Reg r32 = X86Reg(r64 & 7), s32 = X86Reg(s64 & 7); + m_code.push_back(m_al, rex(1, r64 >> 3, 0, s64 >> 3)); + m_code.push_back(m_al, 0x23); + modrm_sib_disp(m_code, m_al, r32, &s32, nullptr, 1, 0, false); + EMIT("and " + r2s(r64) + ", " + r2s(s64)); + } + + void asm_and_r32_r32(X86Reg r32, X86Reg s32) { + m_code.push_back(m_al, 0x23); + modrm_sib_disp(m_code, m_al, r32, &s32, nullptr, 1, 0, false); + EMIT("and " + r2s(r32) + ", " + r2s(r32)); + } + + void asm_or_r64_r64(X64Reg r64, X64Reg s64) { + X86Reg r32 = X86Reg(r64 & 7), s32 = X86Reg(s64 & 7); + m_code.push_back(m_al, rex(1, r64 >> 3, 0, s64 >> 3)); + m_code.push_back(m_al, 0x0B); + modrm_sib_disp(m_code, m_al, r32, &s32, nullptr, 1, 0, false); + EMIT("or " + r2s(r64) + ", " + r2s(s64)); + } + + void asm_or_r32_r32(X86Reg r32, X86Reg s32) { + m_code.push_back(m_al, 0x0B); + modrm_sib_disp(m_code, m_al, r32, &s32, nullptr, 1, 0, false); + EMIT("or " + r2s(r32) + ", " + r2s(r32)); + } + + void asm_xor_r64_r64(X64Reg r64, X64Reg s64) { + X86Reg r32 = X86Reg(r64 & 7), s32 = X86Reg(s64 & 7); + m_code.push_back(m_al, rex(1, r64 >> 3, 0, s64 >> 3)); + m_code.push_back(m_al, 0x33); + modrm_sib_disp(m_code, m_al, r32, &s32, nullptr, 1, 0, false); + EMIT("xor " + r2s(r64) + ", " + r2s(s64)); + } + + void asm_xor_r32_r32(X86Reg r32, X86Reg s32) { + m_code.push_back(m_al, 0x31); + modrm_sib_disp(m_code, m_al, + s32, &r32, nullptr, 1, 0, false); + EMIT("xor " + r2s(r32) + ", " + r2s(s32)); + } + void asm_syscall() { m_code.push_back(m_al, 0x0F); m_code.push_back(m_al, 0x05);