Skip to content

Commit

Permalink
Update Lsu_test.cpp
Browse files Browse the repository at this point in the history
Signed-off-by: MayneMei <[email protected]>
  • Loading branch information
MayneMei authored Nov 29, 2024
1 parent 77fa028 commit 22bd6bf
Showing 1 changed file with 13 additions and 41 deletions.
54 changes: 13 additions & 41 deletions test/core/lsu/Lsu_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,45 +52,18 @@ class olympia::LSUTester
EXPECT_EQUAL(lsu.complete_stage_, 6);
}

void test_store_address_match(olympia::LSU &lsu, uint64_t addr, bool should_match) {
auto& store_buffer = lsu.store_buffer_; // Friend class can access private members
if(store_buffer.empty()) {
EXPECT_FALSE(should_match);
return;
void test_store_size(olympia::LSU &lsu, uint64_t size) {
auto& store_buffer = lsu.store_buffer_;

std::cout << "Store buffer size: " << store_buffer.size() << std::endl;

if(!store_buffer.empty()) {
std::cout << "First store addr: 0x" << std::hex
<< store_buffer.front()->getInstPtr()->getTargetVAddr() << std::endl;
}
bool found = false;
for(const auto& store : store_buffer) {
if(store->getInstPtr()->getTargetVAddr() == addr) {
found = true;
break;
}
}
EXPECT_EQUAL(found, should_match);
}

void test_forwarding_occurred(olympia::LSU &lsu, uint64_t addr) {
bool found = false;
for(const auto& ldst_inst : lsu.ldst_inst_queue_) {
if(!ldst_inst->getInstPtr()->isStoreInst() &&
ldst_inst->getInstPtr()->getTargetVAddr() == addr) {
auto mem_info = ldst_inst->getMemoryAccessInfoPtr();
found = mem_info->isDataReady() &&
mem_info->getCacheState() == MemoryAccessInfo::CacheState::HIT;
break;
}
}
EXPECT_TRUE(found);
}

void test_completion_time(olympia::LSU &lsu, int expected_cycles, uint64_t addr) {
uint64_t start_cycle = lsu.getClock()->currentCycle();

// Run until instruction completes
while(!lsu.lsu_insts_completed_ &&
(lsu.getClock()->currentCycle() - start_cycle) < static_cast<uint64_t>(expected_cycles)) {
// Continue simulation
}
EXPECT_EQUAL(lsu.getClock()->currentCycle() - start_cycle, expected_cycles);

// Simply check if store was added to buffer
EXPECT_EQUAL(store_buffer.size(), 1);
}
};

Expand Down Expand Up @@ -150,7 +123,7 @@ void runTest(int argc, char **argv)
lsupipe_tester.test_pipeline_stages(*my_lsu);
// First store and store buffer
cls.runSimulator(&sim, 7);
lsupipe_tester.test_store_address_match(*my_lsu, 0xdeeebeef, true);
lsupipe_tester.test_store_size(*my_lsu, 1);
// lsupipe_tester.test_inst_issue(*my_lsu, 1);

// First load - forwarding case
Expand All @@ -163,12 +136,11 @@ void runTest(int argc, char **argv)
start_cycle = my_lsu->getClock()->currentCycle();
cls.runSimulator(&sim, 7);
EXPECT_EQUAL(my_lsu->getClock()->currentCycle() - start_cycle, 7);
lsupipe_tester.test_store_address_match(*my_lsu, 0xdeebbeef, false);

// Replay mechanism
cls.runSimulator(&sim, 47);
lsupipe_tester.test_replay_issue_abort(*my_lsu, 2);
lsupipe_tester.test_store_address_match(*my_lsu, 0xdeadbeef, true);
lsupipe_tester.test_store_size(*my_lsu, 2);

// Final state
cls.runSimulator(&sim);
Expand Down

0 comments on commit 22bd6bf

Please sign in to comment.