Add support for any width 2-state darray objects

This commit is contained in:
Cary R 2015-02-27 11:39:57 -08:00
parent 62abb199d7
commit feb710a186
4 changed files with 56 additions and 15 deletions

View File

@ -57,21 +57,6 @@ static int eval_darray_new(ivl_expr_t ex)
lsb = ivl_type_packed_lsb(element_type, 0);
wid = msb>=lsb? msb - lsb : lsb - msb;
wid += 1;
// At the moment vvp only supports widths of 8, 16, 32 or 64
switch (wid) {
case 8:
case 16:
case 32:
case 64:
break;
default:
fprintf(stderr, "%s:%u: tgt-vvp sorry: vvp currently only "
"supports dynamic array widths of 8, 16, 32 or 64 "
"bits, given (%d).\n",
ivl_expr_file(ex), ivl_expr_lineno(ex), wid);
errors += 1;;
}
fprintf(vvp_out, " %%new/darray %u, \"%sb%d\";\n", size_reg,
ivl_type_signed(element_type) ? "s" : "", wid);
break;

View File

@ -4071,6 +4071,12 @@ bool of_NEW_DARRAY(vthread_t thr, vvp_code_t cp)
obj = new vvp_darray_atom<int32_t>(size);
} else if (strcmp(text,"sb64") == 0) {
obj = new vvp_darray_atom<int64_t>(size);
} else if ((1 == sscanf(text, "b%u%zn", &word_wid, &n)) &&
(n == strlen(text))) {
obj = new vvp_darray_vec2(size, word_wid);
} else if ((1 == sscanf(text, "sb%u%zn", &word_wid, &n)) &&
(n == strlen(text))) {
obj = new vvp_darray_vec2(size, word_wid);
} else if ((1 == sscanf(text, "v%u%zn", &word_wid, &n)) &&
(n == strlen(text))) {
obj = new vvp_darray_vec4(size, word_wid);

View File

@ -140,6 +140,40 @@ void vvp_darray_vec4::get_word(unsigned adr, vvp_vector4_t&value)
assert(value.size() == word_wid_);
}
vvp_darray_vec2::~vvp_darray_vec2()
{
}
size_t vvp_darray_vec2::get_size(void) const
{
return array_.size();
}
void vvp_darray_vec2::set_word(unsigned adr, const vvp_vector4_t&value)
{
if (adr >= array_.size()) return;
assert(value.size() == word_wid_);
array_[adr] = value;
}
void vvp_darray_vec2::get_word(unsigned adr, vvp_vector4_t&value)
{
/*
* Return a zero value for an out of range address or if the
* value has not been written yet (has a size of zero).
*/
if ((adr >= array_.size()) || (array_[adr].size() == 0)) {
value = vvp_vector4_t(word_wid_, BIT4_0);
return;
}
assert(array_[adr].size() == word_wid_);
value.resize(word_wid_);
for (unsigned idx = 0; idx < word_wid_; idx += 1) {
value.set_bit(idx, array_[adr].value4(idx));
}
}
vvp_darray_object::~vvp_darray_object()
{
}

View File

@ -76,6 +76,22 @@ class vvp_darray_vec4 : public vvp_darray {
unsigned word_wid_;
};
class vvp_darray_vec2 : public vvp_darray {
public:
inline vvp_darray_vec2(size_t siz, unsigned word_wid) :
array_(siz), word_wid_(word_wid) { }
~vvp_darray_vec2();
size_t get_size(void) const;
void set_word(unsigned adr, const vvp_vector4_t&value);
void get_word(unsigned adr, vvp_vector4_t&value);
private:
std::vector<vvp_vector2_t> array_;
unsigned word_wid_;
};
class vvp_darray_real : public vvp_darray {
public: