Skip to content

Commit

Permalink
Merge branch 'main' into assotiative-cache
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-egorov42 authored Oct 31, 2023
2 parents bde8613 + 19bf2e5 commit 948f077
Show file tree
Hide file tree
Showing 55 changed files with 1,471 additions and 403 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,31 @@ env:
jobs:
build:
name: Running unit tests with ${{matrix.ctest_option}} option
runs-on: ubuntu-latest
strategy:
matrix:
ctect_option:
- "-DBESM666_TEST_WITH_VALGRIND=OFF"
- "-DBESM666_TEST_WITH_VALGRIND=ON"
os: [ ubuntu-latest, macos-12 ]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
with:
submodules: recursive

- name: install valgrind
if: ${{ matrix.os != 'macos-12' }}
run: sudo apt update && sudo apt install -y valgrind

- name: Configure CMake
if: ${{ !(matrix.os == 'macos-12' && matrix.ctect_option == '-DBESM666_TEST_WITH_VALGRIND=ON') }}
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} ${{matrix.ctect_option}}

- name: Build
if: ${{ !(matrix.os == 'macos-12' && matrix.ctect_option == '-DBESM666_TEST_WITH_VALGRIND=ON') }}
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}

- name: Test
if: ${{ !(matrix.os == 'macos-12' && matrix.ctect_option == '-DBESM666_TEST_WITH_VALGRIND=ON') }}
working-directory: ${{github.workspace}}/build
run: ctest --test-dir ${{github.workspace}}/build/besm-666
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,5 @@ endif()

if (DEFINED BESM666__E2E_TESTS_BUILD)
enable_testing()
add_subdirectory(e2e_test)
endif()
add_subdirectory(e2e_test)
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ RISCV_SYSROOT ?= $(PWD)/../sysroot
JOBS ?= 8

.PHONY: all
all: test test-e2e
all: init format test test-e2e

.PHONY: init
init:
git submodule update --init --recursive

.PHONY: format
.SILENT: format
Expand Down
15 changes: 2 additions & 13 deletions e2e_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ if (DEFINED BESM666__E2E_TESTS_BUILD)
"-x" "assembler-with-cpp")
add_test(
NAME ${TARGET_NAME}
COMMAND ${CMAKE_BINARY_DIR}/../besm-666/e2e_test/besm666-a0-validator ${TARGET_NAME}
COMMAND ${CMAKE_BINARY_DIR}/../besm-666/standalone/besm666_standalone --a0-validation --executable ${TARGET_NAME}
)
endfunction(besm666_e2etest_asm)

Expand All @@ -38,22 +38,11 @@ if (DEFINED BESM666__E2E_TESTS_BUILD)
target_link_libraries(${TARGET_NAME} PRIVATE besm666-e2eif)
add_test(
NAME ${TARGET_NAME}
COMMAND ${CMAKE_BINARY_DIR}/../besm-666/e2e_test/besm666-a0-validator ${TARGET_NAME}
COMMAND ${CMAKE_BINARY_DIR}/../besm-666/standalone/besm666_standalone --a0-validation --executable ${TARGET_NAME}
)
endfunction(besm666_e2etest_c)

besm666_e2etest_asm(./mult-test.s)
besm666_e2etest_c(./bubblesort-test.c)
besm666_e2etest_c(./primenumber-test.c)
endif()

if (DEFINED BESM666__SIMULATOR_BUILD)
add_executable(besm666-a0-validator)
target_sources(besm666-a0-validator PRIVATE
./a0-validator.cpp
)
target_link_libraries(besm666-a0-validator PRIVATE
besm666_shared
)
endif()

29 changes: 0 additions & 29 deletions e2e_test/a0-validator.cpp

This file was deleted.

12 changes: 6 additions & 6 deletions include/besm-666/autogen/operations-matrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1169,13 +1169,13 @@ constexpr static Cell INSTR_WHO[128][8] = {
}, // opcode: 0b1110010
{
{I, INV_OP},
{I, CSRRW},
{I, CSRRS},
{I, CSRRC},
{I, INV_OP},
{I, INV_OP},
{I, INV_OP},
{I, INV_OP},
{I, INV_OP},
{I, INV_OP},
{I, INV_OP},
{I, CSRRWI},
{I, CSRRSI},
{I, CSRRCI},
}, // opcode: 0b1110011
{
{ILLEGAL, INV_OP},
Expand Down
13 changes: 11 additions & 2 deletions include/besm-666/decoder/decoder.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#pragma once
#include "besm-666/autogen/operations-matrix.hpp"
#include "besm-666/instruction.hpp"

#include <cassert>
#include <cstdlib>
#include <stdexcept>

#include "besm-666/autogen/operations-matrix.hpp"
#include "besm-666/decoder/prefetcher.hpp"
#include "besm-666/instruction.hpp"

namespace besm::dec {

class Decoder {
Expand All @@ -21,14 +24,20 @@ class Decoder {
static constexpr RV64UWord RS2_MASK = 0b11111 << RS2_SHIFT;

public:
explicit Decoder(mem::MMU::SPtr mmu) : prefetcher_(std::move(mmu)) {}

/**
* Give the {@link Instruction} by the bytecode word.
* @param bytecode word.
* @return {@link Instruction} struct.
*/
[[nodiscard]] besm::Instruction parse(RV64UWord bytecode) const;

RV64UWord fetch(RV64Ptr address) { return prefetcher_.loadWord(address); }

private:
Prefetcher prefetcher_;

static inline Instruction parse_R(RV64UWord bytecode, Opcode opcode,
uint8_t func3);

Expand Down
42 changes: 42 additions & 0 deletions include/besm-666/decoder/prefetcher.hpp
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
172 changes: 172 additions & 0 deletions include/besm-666/exec/csr.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
#pragma once

#include <cassert>
#include <cstddef>
#include <type_traits>

#include "besm-666/exec/icsr.hpp"
#include "besm-666/riscv-types.hpp"
#include "besm-666/util/bit-magic.hpp"

namespace besm::exec {

enum class CSRFieldSpec { WPRI, WLRL, WARL, UNCHECKED };

using CSRFieldValidator = bool (*)(RV64UDWord);

class CSRFieldLike {};

template <RV64UDWord Mask, CSRFieldSpec Spec, CSRFieldValidator Val,
RV64UDWord ResetValue = 0>
class CSRField : public CSRFieldLike {
public:
// implication implementation
static_assert(!(Spec != CSRFieldSpec::UNCHECKED &&
Spec != CSRFieldSpec::WPRI) ||
Val != nullptr);

bool set(RV64UDWord value) noexcept;
RV64UDWord get() const noexcept;

~CSRField() = default;

explicit CSRField(RV64UDWord &rawRegister);

bool extract(RV64UDWord registerValue) noexcept;
void reset() const noexcept;

private:
RV64UDWord &rawRegister_;
};

template <RV64UDWord Mask, RV64UDWord ResetValue = 0>
using CSRUncheckedField =
CSRField<Mask, CSRFieldSpec::UNCHECKED, nullptr, ResetValue>;

template <RV64UDWord Mask>
using CSRWPRIField = CSRField<Mask, CSRFieldSpec::WPRI, nullptr>;

template <RV64UDWord Mask, CSRFieldValidator Validator,
RV64UDWord ResetValue = 0>
using CSRWLRLField = CSRField<Mask, CSRFieldSpec::WLRL, Validator, ResetValue>;

template <RV64UDWord Mask, CSRFieldValidator Validator,
RV64UDWord ResetValue = 0>
using CSRWARLField = CSRField<Mask, CSRFieldSpec::WARL, Validator, ResetValue>;

template <RV64UDWord Mask, CSRFieldSpec Spec, CSRFieldValidator Val,
RV64UDWord ResetValue>
CSRField<Mask, Spec, Val, ResetValue>::CSRField(RV64UDWord &rawRegister)
: rawRegister_(rawRegister) {}

template <RV64UDWord Mask, CSRFieldSpec Spec, CSRFieldValidator Val,
RV64UDWord ResetValue>
bool CSRField<Mask, Spec, Val, ResetValue>::extract(
RV64UDWord registerValue) noexcept {
return this->set(util::ExtractMasked<RV64UDWord, Mask>(registerValue));
}

template <RV64UDWord Mask, CSRFieldSpec Spec, CSRFieldValidator Val,
RV64UDWord ResetValue>
RV64UDWord CSRField<Mask, Spec, Val, ResetValue>::get() const noexcept {
if constexpr (Spec == CSRFieldSpec::WPRI) {
return 0;
} else {
return util::ExtractMasked<RV64UDWord, Mask>(rawRegister_);
}
}

template <RV64UDWord Mask, CSRFieldSpec Spec, CSRFieldValidator Val,
RV64UDWord ResetValue>
bool CSRField<Mask, Spec, Val, ResetValue>::set(RV64UDWord value) noexcept {
if constexpr (Spec == CSRFieldSpec::WLRL) {
if (!Val(value)) {
return false;
}
} else if constexpr (Spec == CSRFieldSpec::WPRI) {
return true;
} else if constexpr (Spec == CSRFieldSpec::WARL) {
if (!Val(value)) {
return true;
}
}

rawRegister_ = util::InsertMasked<RV64UDWord, Mask>(value, rawRegister_);
return true;
}

template <RV64UDWord Mask, CSRFieldSpec Spec, CSRFieldValidator Val,
RV64UDWord ResetValue>
void CSRField<Mask, Spec, Val, ResetValue>::reset() const noexcept {
rawRegister_ = util::ExtractMasked<RV64UDWord, Mask>(ResetValue);
}

template <typename FieldType, typename... OtherFields>
class CSRStructureUnroller : public CSRStructureUnroller<OtherFields...>,
public FieldType {
public:
static_assert(std::is_base_of_v<CSRFieldLike, FieldType>);

CSRStructureUnroller(RV64UDWord &rawRegister)
: CSRStructureUnroller<OtherFields...>(rawRegister),
FieldType(rawRegister) {}
~CSRStructureUnroller() = default;

inline bool extract(RV64UDWord value) {
return FieldType::extract(value) &&
CSRStructureUnroller<OtherFields...>::extract(value);
}
inline void reset() {
FieldType::reset();
CSRStructureUnroller<OtherFields...>::reset();
}
};

template <typename FieldType>
class CSRStructureUnroller<FieldType> : public FieldType {
public:
static_assert(std::is_base_of_v<CSRFieldLike, FieldType>);

CSRStructureUnroller(RV64UDWord &rawField) noexcept : FieldType(rawField) {}
~CSRStructureUnroller() = default;

inline bool extract(RV64UDWord value) { return FieldType::extract(value); }
inline void reset() { FieldType::reset(); }
};

template <typename... Fields>
class CSRStructure : public CSRStructureUnroller<Fields...>, public ICSR {
public:
CSRStructure(CSRF &csrf, ICSR::Id id)
: CSRStructureUnroller<Fields...>(value_), ICSR(csrf, id) {
this->reset();
}

void reset() { CSRStructureUnroller<Fields...>::reset(); }

bool write(RV64UDWord value) noexcept override final {
bool e = CSRStructureUnroller<Fields...>::extract(value);
this->onUpdate();
return e;
}

RV64UDWord read() const noexcept override final { return value_; }

template <typename FieldType> bool set(RV64UDWord value) noexcept {
bool e = static_cast<FieldType *>(this)->set(value);
this->onUpdate();
return e;
}

template <typename FieldType> RV64UDWord get() const noexcept {
return static_cast<FieldType const *>(this)->get();
}

protected:
void onUpdate() noexcept override {}

private:
RV64UDWord value_;
};

} // namespace besm::exec
Loading

0 comments on commit 948f077

Please sign in to comment.