diff --git a/tgt-vvp/eval_object.c b/tgt-vvp/eval_object.c index be0886dd3..bbc9a70ab 100644 --- a/tgt-vvp/eval_object.c +++ b/tgt-vvp/eval_object.c @@ -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; diff --git a/vvp/vthread.cc b/vvp/vthread.cc index eec43b761..21eef0b28 100644 --- a/vvp/vthread.cc +++ b/vvp/vthread.cc @@ -4071,6 +4071,12 @@ bool of_NEW_DARRAY(vthread_t thr, vvp_code_t cp) obj = new vvp_darray_atom(size); } else if (strcmp(text,"sb64") == 0) { obj = new vvp_darray_atom(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); diff --git a/vvp/vvp_darray.cc b/vvp/vvp_darray.cc index 34ecdcf8b..3c8086c03 100644 --- a/vvp/vvp_darray.cc +++ b/vvp/vvp_darray.cc @@ -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() { } diff --git a/vvp/vvp_darray.h b/vvp/vvp_darray.h index be9962ddc..e6d164698 100644 --- a/vvp/vvp_darray.h +++ b/vvp/vvp_darray.h @@ -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 array_; + unsigned word_wid_; +}; + class vvp_darray_real : public vvp_darray { public: