-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c478557
commit 19bf2e5
Showing
10 changed files
with
121 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#pragma once | ||
|
||
#include "besm-666/memory/mmu.hpp" | ||
|
||
namespace besm::dec { | ||
|
||
/** | ||
* This class provides fetching of raw instructions, keeping | ||
* the host memory address for the case if several of them | ||
* are sequentially arranged in host memory. | ||
*/ | ||
class Prefetcher { | ||
public: | ||
explicit Prefetcher(mem::MMU::SPtr mmu); | ||
|
||
/** | ||
* Loads word using mmu. | ||
* @param vaddress Virtual address. | ||
* @return word. | ||
*/ | ||
RV64UWord loadWord(RV64Ptr vaddress); | ||
|
||
private: | ||
mem::MMU::SPtr mmu_; | ||
|
||
/** | ||
* Hosted address of continuous bytes. | ||
*/ | ||
const RV64UWord *saved_; | ||
|
||
/** | ||
* Virtual address that corresponds to {@link Prefetcher::saved_}. | ||
*/ | ||
RV64Ptr start_; | ||
|
||
/** | ||
* Number of continuous bytes starting from {@link Prefetcher::start_} | ||
*/ | ||
RV64Size len_; | ||
}; | ||
|
||
} // namespace besm::dec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include "besm-666/decoder/prefetcher.hpp" | ||
#include <cassert> | ||
|
||
namespace besm::dec { | ||
|
||
Prefetcher::Prefetcher(mem::MMU::SPtr mmu) | ||
: mmu_(std::move(mmu)), saved_(nullptr), start_(-1), len_(0) {} | ||
|
||
RV64UWord Prefetcher::loadWord(RV64Ptr vaddress) { | ||
if (vaddress > start_ && vaddress < start_ + len_) { | ||
// this address was already load | ||
assert((vaddress - start_) % sizeof(RV64UWord) == 0); | ||
return *(saved_ + (vaddress - start_) / sizeof(RV64UWord)); | ||
} else { | ||
// load address | ||
auto pair = mmu_->getHostAddress(vaddress); | ||
if (pair.second > 0) { | ||
start_ = vaddress; | ||
len_ = pair.second; | ||
saved_ = static_cast<const RV64UWord *>(pair.first); | ||
return *saved_; | ||
} | ||
return mmu_->loadWord(vaddress); | ||
} | ||
} | ||
|
||
} // namespace besm::dec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
besm666_test(decoder_test.cpp) | ||
besm666_test(prefetcher_test.cpp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include "./besm-666/decoder/prefetcher.hpp" | ||
#include "besm-666/autogen/encoding.out.h" | ||
#include <gtest/gtest.h> | ||
|
||
using namespace besm; | ||
|
||
TEST(Prefecher, fetch_not_fails) { | ||
constexpr size_t RAM_SIZE = 1024 * 1024 * 1024; | ||
std::shared_ptr<mem::PhysMem> pMem = | ||
mem::PhysMemBuilder() | ||
.mapRAM(0, RAM_SIZE, 4096, 2 * 1024 * 1024) | ||
.build(); | ||
mem::MMU::SPtr mmu = mem::MMU::Create(pMem); | ||
dec::Prefetcher prefetcher{mmu}; | ||
constexpr RV64Ptr const ADDR = 1000; | ||
|
||
constexpr int to_store = 4096; | ||
for (int i = 0; i < to_store; ++i) { | ||
mmu->storeWord(ADDR + i * sizeof(RV64UWord), i); | ||
} | ||
for (int i = 0; i < to_store; ++i) { | ||
RV64UWord word = prefetcher.loadWord(ADDR + i * sizeof(RV64UWord)); | ||
EXPECT_EQ(word, i); | ||
} | ||
} |