Skip to content

Commit

Permalink
Vanadis: Refactoring VanadisInstruction, LSQ, Decoder
Browse files Browse the repository at this point in the history
  • Loading branch information
Anunalla committed Oct 3, 2024
1 parent a6587a0 commit 83bae80
Show file tree
Hide file tree
Showing 94 changed files with 4,724 additions and 3,201 deletions.
2 changes: 2 additions & 0 deletions src/sst/elements/vanadis/decoder/vdecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "vinsloader.h"
#include "vfpflags.h"


#include <cinttypes>
#include <cstdint>
#include <sst/core/interfaces/stdMem.h>
Expand Down Expand Up @@ -266,6 +267,7 @@ class VanadisDecoder : public SST::SubComponent
Statistic<uint64_t>* stat_ins_bytes_loaded;
};


} // namespace Vanadis
} // namespace SST

Expand Down
636 changes: 378 additions & 258 deletions src/sst/elements/vanadis/decoder/vriscv64decoder.h

Large diffs are not rendered by default.

135 changes: 103 additions & 32 deletions src/sst/elements/vanadis/inst/regfile.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright 2009-2024 NTESS. Under the terms
// Copyright 2009-2023 NTESS. Under the terms
// of Contract DE-NA0003525 with NTESS, the U.S.
// Government retains certain rights in this software.
//
// Copyright (c) 2009-2024, NTESS
// Copyright (c) 2009-2023, NTESS
// All rights reserved.
//
// Portions are copyright of other developers:
Expand Down Expand Up @@ -32,21 +32,28 @@ class VanadisRegisterFile

public:
VanadisRegisterFile(
const uint32_t thr, const VanadisDecoderOptions* decoder_ots, const uint16_t int_regs, const uint16_t fp_regs,
const VanadisFPRegisterMode fp_rmode) :
const uint32_t thr, const VanadisDecoderOptions* decoder_ots,
const uint16_t int_regs, const uint16_t fp_regs,
const VanadisFPRegisterMode fp_rmode, SST::Output* logger) :
hw_thread(thr),
count_int_regs(int_regs),
count_fp_regs(fp_regs),
decoder_opts(decoder_ots),
fp_reg_mode(fp_rmode),
int_reg_width(8),
fp_reg_width( (fp_rmode == VANADIS_REGISTER_MODE_FP32) ? 4 : 8 )
fp_reg_width( (fp_rmode == VANADIS_REGISTER_MODE_FP32) ? 4 : 8)
{
// Registers are always 64-bits

int_reg_storage = new char[int_reg_width * count_int_regs];
fp_reg_storage = new char[fp_reg_width * count_fp_regs];

init();
output = logger;

fpRegWidth_per_thread = fp_reg_width * count_fp_regs;
intRegWidth_per_thread = int_reg_width * count_int_regs;

}

void init( ) {
Expand All @@ -72,8 +79,9 @@ class VanadisRegisterFile

void copyFromRegister(uint16_t reg, uint32_t offset, uint8_t* values, uint32_t len, bool is_fp) {
if(is_fp) {
copyFromFPRegister(reg, offset, values, len);
} else {
copyFromFPRegister(reg, offset, values, len);
}
else {
copyFromIntRegister(reg, offset, values, len);
}
}
Expand All @@ -82,50 +90,63 @@ class VanadisRegisterFile
assert(reg < count_fp_regs);
assert((offset + len) <= fp_reg_width);

uint8_t* reg_ptr = (uint8_t*) &fp_reg_storage[reg * fp_reg_width];
int index = get_reg_index(reg,1);
uint8_t* reg_ptr = (uint8_t*) &fp_reg_storage[index];
// output->verbose(CALL_INFO, 16, 0, "CopyFromFPReg: reg=%d fp_reg_width=%d target_tid=%d WARP_SIZE=%d count_fp_regs=%d index = %d\n",
// reg, fp_reg_width,target_tid, WARP_SIZE, count_fp_regs, index);

for(auto i = 0; i < len; ++i) {
values[i] = reg_ptr[offset + i];
// printf("reg[%d][%d]=%d\n",reg, offset + i,reg_ptr[offset+i]);
}


}

void copyFromIntRegister(uint16_t reg, uint32_t offset, uint8_t* values, uint32_t len) {
assert(reg < count_int_regs);
assert((offset + len) <= int_reg_width);

uint8_t* reg_ptr = (uint8_t*) &int_reg_storage[reg * int_reg_width];

int index = get_reg_index(reg, 0);
uint8_t* reg_ptr = (uint8_t*) &int_reg_storage[index];
// output->verbose(CALL_INFO, 16, 0, "CopyFromIntReg: reg=%d int_reg_width=%d target_tid=%d WARP_SIZE=%d count_int_regs=%d index= %d len=%d\n",
// reg, int_reg_width, target_tid, WARP_SIZE, count_int_regs, index, len);

for(auto i = 0; i < len; ++i) {
values[i] = reg_ptr[offset + i];
// printf("reg[%d][%d]=%d\n",reg, offset + i,values[i]);
}
}

void copyToRegister(uint16_t reg, uint32_t offset, uint8_t* values, uint32_t len, bool is_fp) {
if(is_fp) {
copyToFPRegister(reg, offset, values, len);
} else {
copyToIntRegister(reg, offset, values, len);
}

}

void copyToIntRegister(uint16_t reg, uint32_t offset, uint8_t* values, uint32_t len) {
assert((offset + len) <= int_reg_width);
assert(reg < count_int_regs);

uint8_t* reg_ptr = (uint8_t*) &int_reg_storage[reg * int_reg_width];

int index = get_reg_index(reg, 0);
uint8_t* reg_ptr = (uint8_t*) &int_reg_storage[index];
for(auto i = 0; i < len; ++i) {
reg_ptr[offset + i] = values[i];
// printf("reg[%d][%d]=%d\n",reg, offset + i,values[i]);
}

// output->verbose(CALL_INFO, 16, 0, "CopyToIntReg: reg=%d int_reg_width=%d target_tid=%d WARP_SIZE=%d count_int_regs=%d index= %d\n",
// reg, int_reg_width, target_tid, WARP_SIZE, count_int_regs, index);
}

void copyToFPRegister(uint16_t reg, uint32_t offset, uint8_t* values, uint32_t len) {
assert((offset + len) <= fp_reg_width);
assert(reg < count_fp_regs);

uint8_t* reg_ptr = (uint8_t*) &fp_reg_storage[reg * fp_reg_width];
int index = get_reg_index(reg, 1);
uint8_t* reg_ptr = (uint8_t*) &fp_reg_storage[index];
// output->verbose(CALL_INFO, 16, 0, "CopyToFPReg: reg=%d fp_reg_width=%d target_tid=%d WARP_SIZE=%d count_fp_regs=%d index = %d\n",
// reg, fp_reg_width,target_tid, WARP_SIZE, count_fp_regs, index);
for(auto i = 0; i < len; ++i) {
reg_ptr[offset + i] = values[i];
// printf("reg[%d][%d]=%d\n",reg, offset + i,values[i]);
}
// output->verbose(CALL_INFO, 16, 0, "CopyToFPReg: done\n");
}

template <typename T>
Expand All @@ -134,9 +155,17 @@ class VanadisRegisterFile
assert(reg < count_int_regs);
assert(sizeof(T) <= int_reg_width);

if ( reg != decoder_opts->getRegisterIgnoreWrites() ) {
char* reg_start = &int_reg_storage[reg * int_reg_width];
if ( reg != decoder_opts->getRegisterIgnoreWrites() )
{
int index = get_reg_index(reg, 0);
char* reg_start = &int_reg_storage[index];
T* reg_start_T = (T*)reg_start;

// printf("getIntReg: reg=%d\n",reg);
// for(auto i = 0; i < 64; ++i) {
// printf("reg[%d][%d]=%d\n",reg, i,reg_start[i]);
// }
// printf("getIntReg: reg=%d done\n",reg);
return *(reg_start_T);
}
else {
Expand All @@ -147,11 +176,22 @@ class VanadisRegisterFile
template <typename T>
T getFPReg(const uint16_t reg)
{
output->verbose(CALL_INFO, 16, 0, "getFPReg: reg=%d tid=%d, fpregwidth=%d \n",
reg, hw_thread, fp_reg_width);
assert(reg < count_fp_regs);
assert(sizeof(T) <= fp_reg_width);

char* reg_start = &fp_reg_storage[reg * fp_reg_width];
int index = get_reg_index(reg, 1);
char* reg_start = &fp_reg_storage[index];
T* reg_start_T = (T*)reg_start;

// printf("getFPReg: reg=%d\n",reg);
// for(auto i = 0; i < 64; ++i) {
// printf("reg[%d][%d]=%d\n",reg, i,reg_start[i]);
// }
// printf("getFPReg: reg=%d done\n",reg);
// output->verbose(CALL_INFO, 16, 0, "getFPReg: reg=%d fp_reg_width=%d target_tid=%d WARP_SIZE=%d count_fp_regs=%d index = %d\n",
// reg, fp_reg_width,target_tid, WARP_SIZE, count_fp_regs, index);
return *(reg_start_T);
}

Expand All @@ -161,7 +201,8 @@ class VanadisRegisterFile
assert(reg < count_int_regs);

if ( LIKELY(reg != decoder_opts->getRegisterIgnoreWrites()) ) {
T* reg_ptr_t = (T*)(&int_reg_storage[int_reg_width * reg]);
int index = get_reg_index(reg, 0);
T* reg_ptr_t = (T*)(&int_reg_storage[index]);
char* reg_ptr_c = (char*)(reg_ptr_t);

reg_ptr_t[0] = val;
Expand All @@ -172,28 +213,38 @@ class VanadisRegisterFile
&reg_ptr_c[sizeof(T)],
sign_extend ? ((val & (static_cast<T>(1) << (sizeof(T) * 8 - 1))) == 0) ? 0x00 : 0xFF : 0x00,
int_reg_width - sizeof(T));
output->verbose(CALL_INFO, 16, 0, "setIntReg: reg=%d tid=%d, val=%lu \n",
reg, hw_thread,val);
}
}

template <typename T>
void setFPReg(const uint16_t reg, const T val)
{
output->verbose(CALL_INFO, 16, 0, "setFPReg: reg=%d tid=%d, val=%lu \n",
reg, hw_thread,val);
assert(reg < count_fp_regs);
assert(sizeof(T) <= fp_reg_width);

uint8_t* val_ptr = (uint8_t*) &val;

int index = get_reg_index(reg, 1);
output->verbose(CALL_INFO, 16, 0, "setFPReg: reg=%d tid=%d, val=%lu \n",
reg, hw_thread,val);
for(auto i = 0; i < sizeof(T); ++i) {
fp_reg_storage[fp_reg_width * reg + i] = val_ptr[i];
fp_reg_storage[index + i] = val_ptr[i];
// printf("reg[%d][%d]=%d\n",reg, index + i,val_ptr[i]);
}

// Pad with extra zeros if needed
for(auto i = sizeof(T); i < fp_reg_width; ++i) {
fp_reg_storage[fp_reg_width * reg + i] = 0;
fp_reg_storage[index + i] = 0;
// printf("reg[%d][%d]=%d\n",reg, index + i,0);
}
}

uint32_t getHWThread() const { return hw_thread; }
uint16_t getThreadCount() const { return threadCount; }
void setThreadCount(uint16_t threads) { threadCount= threads; }
uint16_t countIntRegs() const { return count_int_regs; }
uint16_t countFPRegs() const { return count_fp_regs; }

Expand All @@ -216,13 +267,15 @@ class VanadisRegisterFile
char* getIntReg(const uint16_t reg)
{
assert(reg < count_int_regs);
return int_reg_storage + (int_reg_width * reg);
int index = get_reg_index(reg, 0);
return int_reg_storage + (index);
}

char* getFPReg(const uint16_t reg)
{
assert(reg < count_fp_regs);
return fp_reg_storage + (fp_reg_width * reg);
int index = get_reg_index(reg, 1);
return fp_reg_storage + (index);
}

void printRegister(SST::Output* output, bool isInt, uint16_t reg, int level = 8)
Expand Down Expand Up @@ -251,7 +304,19 @@ class VanadisRegisterFile
output->verbose(CALL_INFO, level, 0, "R[%5" PRIu16 "]: %s\n", reg, val_string);
delete[] val_string;
}


int get_reg_index(uint16_t reg, bool is_fp)
{
int index = 0;
if(is_fp) {
index = fp_reg_width * reg;
}
else {
index = int_reg_width * reg;
}
return index;

}
const uint32_t hw_thread;
const uint16_t count_int_regs;
const uint16_t count_fp_regs;
Expand All @@ -263,6 +328,12 @@ class VanadisRegisterFile
VanadisFPRegisterMode fp_reg_mode;
const uint32_t fp_reg_width;
const uint32_t int_reg_width;

int fpRegWidth_per_thread;
int intRegWidth_per_thread;
SST::Output* output;
uint16_t threadCount;

};

} // namespace Vanadis
Expand Down
Loading

0 comments on commit 83bae80

Please sign in to comment.