Skip to content

Implement RISC-V M instructions #925

Closed
pavelkryukov opened this issue Mar 16, 2019 · 4 comments
Closed

Implement RISC-V M instructions #925

pavelkryukov opened this issue Mar 16, 2019 · 4 comments
Assignees
Labels
3 Features of medium complexity or infrastructure enhancements enhancement Adds a new feature to simulation. S1 — ISA To solve the issue, you need knowledge about MIPS or RISC-V ISA

Comments

@pavelkryukov
Copy link
Member

pavelkryukov commented Mar 16, 2019

RISC-V ISA has 'M' extension for multiplication and division instructions. We currently decode them, but we do not execute them. Your objective is to implement the executors in https://github.com/MIPT-ILab/mipt-mips/blob/master/simulator/risc_v/riscv_instr.cpp and https://github.com/MIPT-ILab/mipt-mips/tree/master/simulator/func_sim/multiplication.h.

To test instructions, enable these FuncSim tests

// See tracker #925
#if 0
TEST_CASE( "Torture_Test: rv32um")
{
CHECK( riscv_torture_test_passes("riscv32", RISCV_TEST_PATH "/isa/rv32um-p-div") );
CHECK( riscv_torture_test_passes("riscv32", RISCV_TEST_PATH "/isa/rv32um-p-divu") );
CHECK( riscv_torture_test_passes("riscv32", RISCV_TEST_PATH "/isa/rv32um-p-mul") );
CHECK( riscv_torture_test_passes("riscv32", RISCV_TEST_PATH "/isa/rv32um-p-mulh") );
CHECK( riscv_torture_test_passes("riscv32", RISCV_TEST_PATH "/isa/rv32um-p-mulhsu") );
CHECK( riscv_torture_test_passes("riscv32", RISCV_TEST_PATH "/isa/rv32um-p-mulhu") );
CHECK( riscv_torture_test_passes("riscv32", RISCV_TEST_PATH "/isa/rv32um-p-rem") );
CHECK( riscv_torture_test_passes("riscv32", RISCV_TEST_PATH "/isa/rv32um-p-remu") );
}
TEST_CASE( "Torture_Test: rv64um")
{
CHECK( riscv_torture_test_passes("riscv32", RISCV_TEST_PATH "/isa/rv64um-p-div") );
CHECK( riscv_torture_test_passes("riscv32", RISCV_TEST_PATH "/isa/rv64um-p-divu") );
CHECK( riscv_torture_test_passes("riscv32", RISCV_TEST_PATH "/isa/rv64um-p-divuw") );
CHECK( riscv_torture_test_passes("riscv32", RISCV_TEST_PATH "/isa/rv64um-p-divw") );
CHECK( riscv_torture_test_passes("riscv32", RISCV_TEST_PATH "/isa/rv64um-p-mul") );
CHECK( riscv_torture_test_passes("riscv32", RISCV_TEST_PATH "/isa/rv64um-p-mulh") );
CHECK( riscv_torture_test_passes("riscv32", RISCV_TEST_PATH "/isa/rv64um-p-mulhsu") );
CHECK( riscv_torture_test_passes("riscv32", RISCV_TEST_PATH "/isa/rv64um-p-mulhu") );
CHECK( riscv_torture_test_passes("riscv32", RISCV_TEST_PATH "/isa/rv64um-p-mulw") );
CHECK( riscv_torture_test_passes("riscv32", RISCV_TEST_PATH "/isa/rv64um-p-rem") );
CHECK( riscv_torture_test_passes("riscv32", RISCV_TEST_PATH "/isa/rv64um-p-remu") );
CHECK( riscv_torture_test_passes("riscv32", RISCV_TEST_PATH "/isa/rv64um-p-remuw" );
CHECK( riscv_torture_test_passes("riscv32", RISCV_TEST_PATH "/isa/rv64um-p-remw") );
}
#endif

For reference, see RISC-V ISA document: https://content.riscv.org/wp-content/uploads/2017/05/riscv-spec-v2.2.pdf or in Google.

@pavelkryukov pavelkryukov added enhancement Adds a new feature to simulation. 3 Features of medium complexity or infrastructure enhancements S1 — ISA To solve the issue, you need knowledge about MIPS or RISC-V ISA labels Mar 16, 2019
pavelkryukov added a commit that referenced this issue Mar 16, 2019
@vodogrey2012 vodogrey2012 self-assigned this Apr 16, 2019
@vodogrey2012
Copy link
Contributor

vodogrey2012 commented Apr 17, 2019

Hello. As I see now, this tests were removed in 124f38a commit. Should I put it back to .../risc_v/unit_test.cpp ?

@pavelkryukov
Copy link
Member Author

There are 2 options:

  1. Put the M tests back to FuncSim tests, that should work fine.
  2. More advanced: copy tests macro from these files https://github.com/MIPT-ILab/riscv-tests-prebuilt/tree/master/isa/rv64um to that file https://github.com/MIPT-ILab/mipt-mips/blob/master/simulator/risc_v/t/riscv64_test.cpp. It is nicer since we do not have to run FuncSim to test implementations, and we do not need prebuilt binary files.

@vodogrey2012
Copy link
Contributor

Hello. When I add prebuilt tests for mulhu, for example, it causes this:

/home/yauheni/programs/mips/mipt-mips/simulator/risc_v/t/riscv64_test.cpp:1260:44: error: left shift count >= width of type [-Werror=shift-count-overflow]
   TEST_RR_SRC1_EQ_DEST( 8, mulhu, 143, 13<<32, 11<<32 )

this solves by adding UL : 13UL<<32.
But in case that in parent repo there is now information about it, I am not sure is it a bug or my fault?
Thank you.

@pavelkryukov
Copy link
Member Author

Your fix is correct. The original repo is not a C++ code, so they may have these glitches.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
3 Features of medium complexity or infrastructure enhancements enhancement Adds a new feature to simulation. S1 — ISA To solve the issue, you need knowledge about MIPS or RISC-V ISA
Projects
None yet
Development

No branches or pull requests

2 participants