Skip to content

Commit

Permalink
Threaded code (#86)
Browse files Browse the repository at this point in the history
Closes #81

---------

Co-authored-by: mmamayka <[email protected]>
c71n93 and mmamayka authored Dec 21, 2023

Verified

This commit was signed with the committer’s verified signature.
ohmykreee Kre³
1 parent 67b06a4 commit a0d1106
Showing 30 changed files with 1,141 additions and 1,186 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
*.gch

# CMake build files
build/
build*

# ide stuff
.idea
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -24,6 +24,7 @@ if(NOT DEFINED BESM666__PARENT_BUILD)
CMAKE_CACHE_ARGS
-DBESM666__SIMULATOR_BUILD:BOOL=ON
-DBESM666__PARENT_BUILD:BOOL=ON
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
INSTALL_COMMAND ""
BUILD_ALWAYS ON
)
@@ -93,7 +94,7 @@ if(DEFINED BESM666__SIMULATOR_BUILD)
set(CMAKE_CTEST_ARGUMENTS --test-action memcheck)
endif()

add_subdirectory(unit_test)
#add_subdirectory(unit_test)
endif()

if (DEFINED BESM666__E2E_TESTS_BUILD)
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ format:

.PHONY: build
build:
cmake -S $(PWD) -B $(PWD)/$(BUILD_DIR)
cmake -S $(PWD) -B $(PWD)/$(BUILD_DIR) -DCMAKE_BUILD_TYPE=Release
cmake --build $(PWD)/$(BUILD_DIR) --parallel $(JOBS)

.PHONY: build-val
3 changes: 1 addition & 2 deletions e2e_test/bootstrap.s
Original file line number Diff line number Diff line change
@@ -51,8 +51,7 @@ _start:
// jalr ra, t0
call start // THE POWER OF PSEUDO INSTRUCTIONS!

.0:
j .0
ebreak

.section .data

2 changes: 1 addition & 1 deletion e2e_test/mult-test.s
Original file line number Diff line number Diff line change
@@ -50,4 +50,4 @@ start:
.finish:
ld ra, 0(sp)
add sp, sp, 8
jalr zero, ra, 0
ebreak
2 changes: 1 addition & 1 deletion e2e_test/primenumber-test.c
Original file line number Diff line number Diff line change
@@ -17,5 +17,5 @@ int is_prime(rv64dw value) {
}

rv64dw start() {
return is_prime(1787); //155003 or 65003 for long count
return is_prime(155003); //155003 or 65003 for long count
}
59 changes: 0 additions & 59 deletions include/besm-666/basic-block.hpp

This file was deleted.

10 changes: 0 additions & 10 deletions include/besm-666/decoder/decoder.hpp
Original file line number Diff line number Diff line change
@@ -5,8 +5,6 @@
#include <stdexcept>

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

namespace besm::dec {
@@ -25,8 +23,6 @@ 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.
@@ -41,14 +37,8 @@ class Decoder {
* \param [in] address address to start
* \returns basic block
*/
besm::BasicBlock assembleBB(RV64Ptr address);
void assembleBB(BasicBlock &bb);

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

private:
Prefetcher prefetcher_;

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

63 changes: 63 additions & 0 deletions include/besm-666/exec/basic-block.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#pragma once

#include <array>
#include <cstddef>
#include <functional>
#include <vector>

#include "besm-666/instruction.hpp"
#include "besm-666/util/math.hpp"

namespace besm::exec {

class BasicBlock {
public:
static constexpr size_t kCapacity = 8;
using InstrStorage = std::array<Instruction, kCapacity>;

BasicBlock();

RV64Ptr getPC() const noexcept { return pc_; }
Instruction const *getInstructions() const noexcept {
return instrs_.data();
}

private:
friend class BasicBlockRebuilder;

InstrStorage instrs_;
RV64Ptr pc_;
};

class BasicBlockCache {
public:
static constexpr size_t kSetBits = 7;
static constexpr size_t kWayBits = 3;

static constexpr size_t kSets = (1ull << kSetBits);
static constexpr size_t kWays = (1ull << kWayBits);

static constexpr size_t kSetMask = kSets - 1;
static constexpr size_t kWayMask = kWays - 1;

BasicBlockCache();

std::pair<bool, BasicBlock &> lookup(RV64Ptr pc);

private:
std::array<BasicBlock, kSets * kWays> bbs_;
std::array<size_t, kSets> lruRowers_;
};

class BasicBlockRebuilder {
public:
BasicBlockRebuilder(BasicBlock &targetBB, size_t pc);

bool append(Instruction const &instr) noexcept;

private:
BasicBlock &bb_;
size_t count_;
};

} // namespace besm::exec
109 changes: 0 additions & 109 deletions include/besm-666/exec/executor.hpp

This file was deleted.

Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@

#include "besm-666/memory/mmu.hpp"

namespace besm::dec {
namespace besm::mem {

/**
* This class provides fetching of raw instructions, keeping
@@ -39,4 +39,4 @@ class Prefetcher {
RV64Size len_;
};

} // namespace besm::dec
} // namespace besm::mem
3 changes: 2 additions & 1 deletion include/besm-666/rv-instruction-op.hpp
Original file line number Diff line number Diff line change
@@ -70,7 +70,8 @@ enum InstructionOp {
CSRRSI, // 1110011 , 110 , I
CSRRCI, // 1110011 , 111 , I
SRET,
MRET
MRET,
BB_END // keep it last instruction
};

}
Loading

3 comments on commit a0d1106

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on a0d1106 Dec 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 82-d0f6b6a9 disappeared from src/sim/hart.cpp), that's why I closed #85. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on a0d1106 Dec 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 39-909bf924 discovered in include/besm-666/sim/hart.hpp) and submitted as #88. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on a0d1106 Dec 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 81-442096c2 discovered in include/besm-666/sim/hart.hpp) and submitted as #89. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

Please sign in to comment.