fixed lmp_mult parameters, ram init filepath
This commit is contained in:
@@ -8,21 +8,19 @@
|
||||
#include "VX_config.h"
|
||||
|
||||
extern "C" {
|
||||
void dpi_fadd(int inst, bool enable, bool valid, int a, int b, int* result);
|
||||
void dpi_fsub(int inst, bool enable, bool valid, int a, int b, int* result);
|
||||
void dpi_fmul(int inst, bool enable, bool valid, int a, int b, int* result);
|
||||
void dpi_fmadd(int inst, bool enable, bool valid, int a, int b, int c, int* result);
|
||||
void dpi_fmsub(int inst, bool enable, bool valid, int a, int b, int c, int* result);
|
||||
void dpi_fdiv(int inst, bool enable, bool valid, int a, int b, int* result);
|
||||
void dpi_fsqrt(int inst, bool enable, bool valid, int a, int* result);
|
||||
void dpi_ftoi(int inst, bool enable, bool valid, int a, int* result);
|
||||
void dpi_ftou(int inst, bool enable, bool valid, int a, int* result);
|
||||
void dpi_itof(int inst, bool enable, bool valid, int a, int* result);
|
||||
void dpi_utof(int inst, bool enable, bool valid, int a, int* result);
|
||||
void dpi_fadd(int inst, bool enable, int a, int b, int* result);
|
||||
void dpi_fsub(int inst, bool enable, int a, int b, int* result);
|
||||
void dpi_fmul(int inst, bool enable, int a, int b, int* result);
|
||||
void dpi_fmadd(int inst, bool enable, int a, int b, int c, int* result);
|
||||
void dpi_fmsub(int inst, bool enable, int a, int b, int c, int* result);
|
||||
void dpi_fdiv(int inst, bool enable, int a, int b, int* result);
|
||||
void dpi_fsqrt(int inst, bool enable, int a, int* result);
|
||||
void dpi_ftoi(int inst, bool enable, int a, int* result);
|
||||
void dpi_ftou(int inst, bool enable, int a, int* result);
|
||||
void dpi_itof(int inst, bool enable, int a, int* result);
|
||||
void dpi_utof(int inst, bool enable, int a, int* result);
|
||||
}
|
||||
|
||||
extern double sc_time_stamp();
|
||||
|
||||
class ShiftRegister {
|
||||
public:
|
||||
ShiftRegister() : init_(false), depth_(0) {}
|
||||
@@ -35,37 +33,36 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void push(int value, bool enable, bool valid) {
|
||||
void push(int value, bool enable) {
|
||||
if (!enable)
|
||||
return;
|
||||
for (unsigned i = 0; i < depth_-1; ++i) {
|
||||
buffer_[i] = buffer_[i+1];
|
||||
}
|
||||
buffer_[depth_-1].value = value;
|
||||
buffer_[depth_-1].valid = valid;
|
||||
buffer_[depth_-1] = value;
|
||||
}
|
||||
|
||||
int top() const {
|
||||
return buffer_[0].value;
|
||||
}
|
||||
|
||||
bool valid() const {
|
||||
return buffer_[0].valid;
|
||||
return buffer_[0];
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
struct entry_t {
|
||||
int value;
|
||||
bool valid;
|
||||
};
|
||||
|
||||
std::vector<entry_t> buffer_;
|
||||
int top_;
|
||||
unsigned depth_;
|
||||
std::vector<int> buffer_;
|
||||
bool init_;
|
||||
unsigned depth_;
|
||||
};
|
||||
|
||||
union Float_t {
|
||||
float f;
|
||||
int i;
|
||||
struct {
|
||||
uint32_t man : 23;
|
||||
uint32_t exp : 8;
|
||||
uint32_t sign : 1;
|
||||
} parts;
|
||||
};
|
||||
|
||||
class Instances {
|
||||
public:
|
||||
ShiftRegister& get(int inst) {
|
||||
@@ -82,130 +79,152 @@ private:
|
||||
|
||||
Instances instances;
|
||||
|
||||
void dpi_fadd(int inst, bool enable, bool valid, int a, int b, int* result) {
|
||||
void dpi_fadd(int inst, bool enable, int a, int b, int* result) {
|
||||
ShiftRegister& sr = instances.get(inst);
|
||||
|
||||
float fa = *(float*)&a;
|
||||
float fb = *(float*)&b;
|
||||
float fr = fa + fb;
|
||||
Float_t fa, fb, fr;
|
||||
|
||||
sr.ensure_init(LATENCY_FMADD);
|
||||
sr.push(*(int*)&fr, enable, valid);
|
||||
fa.i = a;
|
||||
fb.i = b;
|
||||
fr.f = fa.f + fb.f;
|
||||
|
||||
sr.ensure_init(LATENCY_FADDMUL);
|
||||
sr.push(fr.i, enable);
|
||||
*result = sr.top();
|
||||
}
|
||||
|
||||
void dpi_fsub(int inst, bool enable, bool valid, int a, int b, int* result) {
|
||||
void dpi_fsub(int inst, bool enable, int a, int b, int* result) {
|
||||
ShiftRegister& sr = instances.get(inst);
|
||||
|
||||
float fa = *(float*)&a;
|
||||
float fb = *(float*)&b;
|
||||
float fr = fa - fb;
|
||||
Float_t fa, fb, fr;
|
||||
|
||||
sr.ensure_init(LATENCY_FMADD);
|
||||
sr.push(*(int*)&fr, enable, valid);
|
||||
fa.i = a;
|
||||
fb.i = b;
|
||||
fr.f = fa.f - fb.f;
|
||||
|
||||
sr.ensure_init(LATENCY_FADDMUL);
|
||||
sr.push(fr.i, enable);
|
||||
*result = sr.top();
|
||||
}
|
||||
|
||||
void dpi_fmul(int inst, bool enable, bool valid, int a, int b, int* result) {
|
||||
void dpi_fmul(int inst, bool enable, int a, int b, int* result) {
|
||||
ShiftRegister& sr = instances.get(inst);
|
||||
|
||||
float fa = *(float*)&a;
|
||||
float fb = *(float*)&b;
|
||||
float fr = fa * fb;
|
||||
Float_t fa, fb, fr;
|
||||
|
||||
sr.ensure_init(LATENCY_FMADD);
|
||||
sr.push(*(int*)&fr, enable, valid);
|
||||
fa.i = a;
|
||||
fb.i = b;
|
||||
fr.f = fa.f * fb.f;
|
||||
|
||||
sr.ensure_init(LATENCY_FADDMUL);
|
||||
sr.push(fr.i, enable);
|
||||
*result = sr.top();
|
||||
}
|
||||
|
||||
void dpi_fmadd(int inst, bool enable, bool valid, int a, int b, int c, int* result) {
|
||||
void dpi_fmadd(int inst, bool enable, int a, int b, int c, int* result) {
|
||||
ShiftRegister& sr = instances.get(inst);
|
||||
|
||||
float fa = *(float*)&a;
|
||||
float fb = *(float*)&b;
|
||||
float fc = *(float*)&c;
|
||||
float fr = fa * fb + fc;
|
||||
Float_t fa, fb, fc, fr;
|
||||
|
||||
fa.i = a;
|
||||
fb.i = b;
|
||||
fc.i = c;
|
||||
fr.f = fa.f * fb.f + fc.f;
|
||||
|
||||
sr.ensure_init(LATENCY_FMADD);
|
||||
sr.push(*(int*)&fr, enable, valid);
|
||||
sr.push(fr.i, enable);
|
||||
*result = sr.top();
|
||||
}
|
||||
|
||||
void dpi_fmsub(int inst, bool enable, bool valid, int a, int b, int c, int* result) {
|
||||
void dpi_fmsub(int inst, bool enable, int a, int b, int c, int* result) {
|
||||
ShiftRegister& sr = instances.get(inst);
|
||||
|
||||
float fa = *(float*)&a;
|
||||
float fb = *(float*)&b;
|
||||
float fc = *(float*)&c;
|
||||
float fr = fa * fb - fc;
|
||||
Float_t fa, fb, fc, fr;
|
||||
|
||||
fa.i = a;
|
||||
fb.i = b;
|
||||
fc.i = c;
|
||||
fr.f = fa.f * fb.f - fc.f;
|
||||
|
||||
sr.ensure_init(LATENCY_FMADD);
|
||||
sr.push(*(int*)&fr, enable, valid);
|
||||
sr.push(fr.i, enable);
|
||||
*result = sr.top();
|
||||
}
|
||||
|
||||
void dpi_fdiv(int inst, bool enable, bool valid, int a, int b, int* result) {
|
||||
void dpi_fdiv(int inst, bool enable, int a, int b, int* result) {
|
||||
ShiftRegister& sr = instances.get(inst);
|
||||
|
||||
float fa = *(float*)&a;
|
||||
float fb = *(float*)&b;
|
||||
float fr = fa / fb;
|
||||
Float_t fa, fb, fr;
|
||||
|
||||
fa.i = a;
|
||||
fb.i = b;
|
||||
fr.f = fa.f / fb.f;
|
||||
|
||||
sr.ensure_init(LATENCY_FDIV);
|
||||
sr.push(*(int*)&fr, enable, valid);
|
||||
sr.push(fr.i, enable);
|
||||
*result = sr.top();
|
||||
}
|
||||
|
||||
void dpi_fsqrt(int inst, bool enable, bool valid, int a, int* result) {
|
||||
void dpi_fsqrt(int inst, bool enable, int a, int* result) {
|
||||
ShiftRegister& sr = instances.get(inst);
|
||||
|
||||
float fa = *(float*)&a;
|
||||
float fr = sqrtf(fa);
|
||||
Float_t fa, fr;
|
||||
|
||||
fa.i = a;
|
||||
fr.f = sqrtf(fa.f);
|
||||
|
||||
sr.ensure_init(LATENCY_FSQRT);
|
||||
sr.push(*(int*)&fr, enable, valid);
|
||||
sr.push(fr.i, enable);
|
||||
*result = sr.top();
|
||||
}
|
||||
|
||||
void dpi_ftoi(int inst, bool enable, bool valid, int a, int* result) {
|
||||
void dpi_ftoi(int inst, bool enable, int a, int* result) {
|
||||
ShiftRegister& sr = instances.get(inst);
|
||||
|
||||
float fa = *(float*)&a;
|
||||
int ir = int(fa);
|
||||
Float_t fa, fr;
|
||||
|
||||
fa.i = a;
|
||||
fr.i = int(fa.f);
|
||||
|
||||
sr.ensure_init(LATENCY_FTOI);
|
||||
sr.push(ir, enable, valid);
|
||||
sr.push(fr.i, enable);
|
||||
*result = sr.top();
|
||||
}
|
||||
|
||||
void dpi_ftou(int inst, bool enable, bool valid, int a, int* result) {
|
||||
void dpi_ftou(int inst, bool enable, int a, int* result) {
|
||||
ShiftRegister& sr = instances.get(inst);
|
||||
|
||||
float fa = *(float*)&a;
|
||||
unsigned ir = unsigned(fa);
|
||||
Float_t fa, fr;
|
||||
|
||||
fa.i = a;
|
||||
fr.i = unsigned(fa.f);
|
||||
|
||||
sr.ensure_init(LATENCY_FTOI);
|
||||
sr.push(ir, enable, valid);
|
||||
sr.push(fr.i, enable);
|
||||
*result = sr.top();
|
||||
}
|
||||
|
||||
void dpi_itof(int inst, bool enable, bool valid, int a, int* result) {
|
||||
void dpi_itof(int inst, bool enable, int a, int* result) {
|
||||
ShiftRegister& sr = instances.get(inst);
|
||||
|
||||
float fr = (float)a;
|
||||
Float_t fa, fr;
|
||||
|
||||
fr.f = (float)a;
|
||||
|
||||
sr.ensure_init(LATENCY_ITOF);
|
||||
sr.push(*(int*)&fr, enable, valid);
|
||||
sr.push(fr.i, enable);
|
||||
*result = sr.top();
|
||||
}
|
||||
|
||||
void dpi_utof(int inst, bool enable, bool valid, int a, int* result) {
|
||||
void dpi_utof(int inst, bool enable, int a, int* result) {
|
||||
ShiftRegister& sr = instances.get(inst);
|
||||
|
||||
unsigned ua = *(unsigned*)&a;
|
||||
float fr = (float)ua;
|
||||
Float_t fa, fr;
|
||||
|
||||
unsigned ua = a;
|
||||
fr.f = (float)ua;
|
||||
|
||||
sr.ensure_init(LATENCY_ITOF);
|
||||
sr.push(*(int*)&fr, enable, valid);
|
||||
sr.push(fr.i, enable);
|
||||
*result = sr.top();
|
||||
}
|
||||
@@ -1,16 +1,16 @@
|
||||
`ifndef FLOAT_DPI
|
||||
`define FLOAT_DPI
|
||||
|
||||
import "DPI-C" context function void dpi_fadd(int inst, input logic enable, input logic valid, input int a, input int b, output int result);
|
||||
import "DPI-C" context function void dpi_fsub(int inst, input logic enable, input logic valid, input int a, input int b, output int result);
|
||||
import "DPI-C" context function void dpi_fmul(int inst, input logic enable, input logic valid, input int a, input int b, output int result);
|
||||
import "DPI-C" context function void dpi_fmadd(int inst, input logic enable, input logic valid, input int a, input int b, input int c, output int result);
|
||||
import "DPI-C" context function void dpi_fmsub(int inst, input logic enable, input logic valid, input int a, input int b, input int c, output int result);
|
||||
import "DPI-C" context function void dpi_fdiv(int inst, input logic enable, input logic valid, input int a, input int b, output int result);
|
||||
import "DPI-C" context function void dpi_fsqrt(int inst, input logic enable, input logic valid, input int a, output int result);
|
||||
import "DPI-C" context function void dpi_ftoi(int inst, input logic enable, input logic valid, input int a, output int result);
|
||||
import "DPI-C" context function void dpi_ftou(int inst, input logic enable, input logic valid, input int a, output int result);
|
||||
import "DPI-C" context function void dpi_itof(int inst, input logic enable, input logic valid, input int a, output int result);
|
||||
import "DPI-C" context function void dpi_utof(int inst, input logic enable, input logic valid, input int a, output int result);
|
||||
import "DPI-C" context function void dpi_fadd(int inst, input logic enable, input int a, input int b, output int result);
|
||||
import "DPI-C" context function void dpi_fsub(int inst, input logic enable, input int a, input int b, output int result);
|
||||
import "DPI-C" context function void dpi_fmul(int inst, input logic enable, input int a, input int b, output int result);
|
||||
import "DPI-C" context function void dpi_fmadd(int inst, input logic enable, input int a, input int b, input int c, output int result);
|
||||
import "DPI-C" context function void dpi_fmsub(int inst, input logic enable, input int a, input int b, input int c, output int result);
|
||||
import "DPI-C" context function void dpi_fdiv(int inst, input logic enable, input int a, input int b, output int result);
|
||||
import "DPI-C" context function void dpi_fsqrt(int inst, input logic enable, input int a, output int result);
|
||||
import "DPI-C" context function void dpi_ftoi(int inst, input logic enable, input int a, output int result);
|
||||
import "DPI-C" context function void dpi_ftou(int inst, input logic enable, input int a, output int result);
|
||||
import "DPI-C" context function void dpi_itof(int inst, input logic enable, input int a, output int result);
|
||||
import "DPI-C" context function void dpi_utof(int inst, input logic enable, input int a, output int result);
|
||||
|
||||
`endif
|
||||
Reference in New Issue
Block a user