Skip to content

Add unit tests for Branch module #512

Closed
pavelkryukov opened this issue Jul 26, 2018 · 8 comments
Closed

Add unit tests for Branch module #512

pavelkryukov opened this issue Jul 26, 2018 · 8 comments
Assignees
Labels
4 Features of medium complexity which usually require infrastructure enhancements. S1 — Pipeline To solve the issue, you need knowledge about pipeline, data bypass, scoreboarding testing Improves testing coverage

Comments

@pavelkryukov
Copy link
Member

pavelkryukov commented Jul 26, 2018

Branch module is the simplest module to test. Its inputs are completed instructions, and its outputs are very few.

The idea is to wrap Branch module inside a single environment with ports

class BranchTesting {
    Branch branch;
    WritePort<Instr>* wp_exe_datapath;
    ReadPort<Instr>* rp_wb_datapath;
    ReadPort<BPInteface>* rp_bp_inteface;
};

Then, you may generate a test case in a following manner:

TEST_CASE(" Branch move")
{
    MIPS32Instr beq( "beq");
    wp_exe_datapath->wirte( beq, 0);
    branch.clock( 0);
    CHECK( rp_bp_bypass->is_ready( 1) ); // Data ready next cycle
}
@pavelkryukov pavelkryukov added testing Improves testing coverage 4 Features of medium complexity which usually require infrastructure enhancements. S1 — ISA To solve the issue, you need knowledge about MIPS or RISC-V ISA labels Jul 26, 2018
@pavelkryukov pavelkryukov added S1 — Pipeline To solve the issue, you need knowledge about pipeline, data bypass, scoreboarding and removed S1 — ISA To solve the issue, you need knowledge about MIPS or RISC-V ISA labels Oct 7, 2018
@pavelkryukov pavelkryukov changed the title Add unit tests for writeback module Add unit tests for Branch module Feb 6, 2019
@graudtv graudtv self-assigned this Dec 1, 2020
@graudtv
Copy link
Contributor

graudtv commented Dec 2, 2020

Hi. I've written some facilities for testing, what is the best way to share this code with you? It is quite big to paste it here, but not finished yet to make a pull request.

@pavelkryukov
Copy link
Member Author

Thanks. I see it in a fork repo and can comment.

@pavelkryukov
Copy link
Member Author

We finalizing rating on 07.12.2020.
In order to get points for this, please complete this before this Sunday.

@graudtv
Copy link
Contributor

graudtv commented Dec 4, 2020

Ok. Could you please have a look? If it's ok, I will add some more tests

@pavelkryukov
Copy link
Member Author

If everything looks, please submit pull request to see all changes at once.

@graudtv
Copy link
Contributor

graudtv commented Dec 6, 2020

I am trying to write tests for predicted and not predicted instructions, and I a bit don't understand how Branch::is_misprediction() works.
Let we have an instruction, which is predicted as taken and is actually taken. This is not a misprediction. Condition on line 51 returns false (it is in BP). Condition on line 57 also returns false, because actual information is the same as in bp_data. The last expression returns true, because target != new_PC. So functions says it is misprediction.

bool is_misprediction( const Instr& instr, const BPInterface& bp_data) const
{
if ( !bp_data.is_hit)
if ( ( instr.is_common_branch() && instr.is_taken())
|| ( instr.is_likely_branch() && !instr.is_taken())
|| instr.is_indirect_jump())
return true;
if ( bp_data.is_hit && ( bp_data.is_taken != instr.is_taken()))
return true;
return ( bp_data.is_taken || instr.is_indirect_jump()) && ( bp_data.target != instr.get_new_PC());
}

@pavelkryukov
Copy link
Member Author

which is predicted as taken and is actually taken. This is not a misprediction.
because target != new_PC. So functions says it is misprediction

Correct: you predicted direction, but not the target (i.e. taken, but somewhere else).
That may happen in case of aliasing in branch prediction table.

@pavelkryukov
Copy link
Member Author

It is a great achievement for our project, as your infrastructure has high quality and may be easily extended for more modules.
Thank you, and keep that level in future work!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
4 Features of medium complexity which usually require infrastructure enhancements. S1 — Pipeline To solve the issue, you need knowledge about pipeline, data bypass, scoreboarding testing Improves testing coverage
Projects
None yet
Development

No branches or pull requests

2 participants