-
Notifications
You must be signed in to change notification settings - Fork 142
[vanadis] Implement the missing Zicntr extension instructions. #2372
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ldalessa
wants to merge
1
commit into
sstsimulator:devel
Choose a base branch
from
ldalessa:zicntr
base: devel
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+192
−17
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
hughes-c marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or 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,17 @@ | ||
|
|
||
| #ifndef _H_VANADIS_ZICNTR | ||
| #define _H_VANADIS_ZICNTR | ||
|
|
||
| #include <utility> | ||
|
|
||
| namespace SST::Vanadis | ||
| { | ||
| // Tags to be used to with the regfile and VanadisReadCounterInstruction | ||
| namespace Zicntr { | ||
| inline constexpr std::integral_constant<uint32_t, 0> CYCLE; | ||
gvoskuilen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| inline constexpr std::integral_constant<uint32_t, 1> TIME; | ||
| inline constexpr std::integral_constant<uint32_t, 2> INSTRET; | ||
| } | ||
hughes-c marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } // namespace Vanadis::SST | ||
|
|
||
| #endif | ||
This file contains hidden or 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,91 @@ | ||
|
|
||
| #ifndef _H_VANADIS_ZICNTR_READ_COUNTER | ||
| #define _H_VANADIS_ZICNTR_READ_COUNTER | ||
|
|
||
| #include "inst/vinst.h" | ||
| #include "inst/vzicntr.h" | ||
|
|
||
| namespace SST::Vanadis | ||
| { | ||
| namespace Zicntr | ||
| { | ||
| template <uint32_t id, size_t XLEN = 64, bool H = false> | ||
| class VanadisReadCounterInstruction : public VanadisInstruction | ||
| { | ||
| static_assert( id < 3 ); | ||
| static_assert( XLEN == 64 or XLEN == 32 ); | ||
| static_assert( XLEN != 64 or H == false ); | ||
|
|
||
| public: | ||
| VanadisReadCounterInstruction( | ||
| const std::integral_constant<uint32_t, id>, | ||
| const uint64_t addr, | ||
| const uint32_t hw_thr, | ||
| const VanadisDecoderOptions* isa_opts, | ||
| const uint16_t dest) | ||
| : VanadisInstruction(addr, hw_thr, isa_opts, 0, 1, 0, 1, 0, 0, 0, 0) | ||
| { | ||
| isa_int_regs_out[0] = dest; | ||
| } | ||
|
|
||
| VanadisReadCounterInstruction* clone() override | ||
| { | ||
| return new VanadisReadCounterInstruction(*this); | ||
| } | ||
|
|
||
| VanadisFunctionalUnitType getInstFuncType() const override | ||
| { | ||
| return INST_INT_ARITH; // Is this appropriate? | ||
hughes-c marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| const char* getInstCode() const override | ||
| { | ||
| switch ( id ) { | ||
| case Zicntr::CYCLE: return H ? "RDCYCLEH" : "RDCYCLE"; | ||
| case Zicntr::TIME: return H ? "RDTIMEH" : "RDTIME"; | ||
| case Zicntr::INSTRET: return H ? "RDINSTRETH" : "RDINSTRET"; | ||
| } | ||
| __builtin_unreachable(); | ||
| } | ||
|
|
||
| void printToBuffer(char* const buffer, const size_t buffer_size) override | ||
| { | ||
| snprintf( | ||
| buffer, buffer_size, | ||
| "%s %5" PRIu16 " (phys: %5" PRIu16 ")", | ||
| getInstCode(), isa_int_regs_out[0], phys_int_regs_out[0]); | ||
| } | ||
|
|
||
| void execute(SST::Output* const output, VanadisRegisterFile* const regFile) override | ||
| { | ||
| #ifdef VANADIS_BUILD_DEBUG | ||
| if(output->getVerboseLevel() >= 16) { | ||
| output->verbose( | ||
| CALL_INFO, 16, 0, | ||
| "Execute: 0x%" PRI_ADDR " %s phys: out=%" PRIu16 ", isa: out=%" PRIu16 "\n", | ||
| getInstructionAddress(), getInstCode(), phys_int_regs_out[0], isa_int_regs_out[0]); | ||
| } | ||
| #endif | ||
|
|
||
| static constexpr uint64_t mask = 0x00000000'FFFFFFFF; | ||
| const uint64_t count64 = regFile->getCounter(id); | ||
| const uint32_t count32 = count64 & mask; | ||
| const uint32_t count32H = count64 >> 32; | ||
|
|
||
| if constexpr ( XLEN == 64 ) { | ||
| regFile->setIntReg(phys_int_regs_out[0], count64); | ||
| } | ||
| else if constexpr ( XLEN == 32 and H ) { | ||
| regFile->setIntReg(phys_int_regs_out[0], count32H); | ||
| } | ||
| else { | ||
| regFile->setIntReg(phys_int_regs_out[0], count32); | ||
| } | ||
|
|
||
| markExecuted(); | ||
| } | ||
| }; | ||
| } // namespace Zicntr | ||
| } // namespace Vanadis::SST | ||
|
|
||
| #endif | ||
Binary file not shown.
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -55,6 +55,7 @@ | |
| #exe = "uname" | ||
| #exe = "mem-test" | ||
| #exe = "checkpoint" | ||
| #exe = "zicntr" | ||
|
|
||
| physMemSize = "4GiB" | ||
|
|
||
|
|
||
Binary file not shown.
This file contains hidden or 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,29 @@ | ||
| #include <inttypes.h> | ||
| #include <stdint.h> | ||
| #include <stdio.h> | ||
|
|
||
| uint64_t read_cycles() { | ||
| uint64_t cycles; | ||
| asm volatile ("rdcycle %0" : "=r" (cycles)); | ||
| return cycles; | ||
| } | ||
|
|
||
| uint64_t read_time() { | ||
| uint64_t time; | ||
| asm volatile ("rdtime %0" : "=r" (time)); | ||
| return time; | ||
| } | ||
|
|
||
| uint64_t read_instructions() { | ||
| uint64_t instructions; | ||
| asm volatile ("rdinstret %0" : "=r" (instructions)); | ||
| return instructions; | ||
| } | ||
|
|
||
| int main() | ||
| { | ||
| uint64_t cycles = read_cycles(); | ||
| uint64_t time = read_time(); | ||
| uint64_t instructions = read_instructions(); | ||
| printf("cycles: %" PRIu64 " time: %" PRIu64 " instructions: %" PRIu64 "\n", cycles, time, instructions); | ||
| } |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.