Add support for 4-state dynamic arrays

This commit is contained in:
Cary R 2015-02-26 17:55:45 -08:00
parent 7373bf2224
commit 62abb199d7
4 changed files with 70 additions and 12 deletions

View File

@ -38,6 +38,7 @@ static int eval_darray_new(ivl_expr_t ex)
assert(element_type);
switch (ivl_type_base(element_type)) {
int msb, lsb, wid;
case IVL_VT_REAL:
// REAL objects are not packable.
assert(ivl_type_packed_dimensions(element_type) == 0);
@ -52,9 +53,9 @@ static int eval_darray_new(ivl_expr_t ex)
// bool objects are vectorable, but for now only support
// a single dimensions.
assert(ivl_type_packed_dimensions(element_type) == 1);
int msb = ivl_type_packed_msb(element_type, 0);
int lsb = ivl_type_packed_lsb(element_type, 0);
int wid = msb>=lsb? msb - lsb : lsb - msb;
msb = ivl_type_packed_msb(element_type, 0);
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) {
@ -75,10 +76,15 @@ static int eval_darray_new(ivl_expr_t ex)
ivl_type_signed(element_type) ? "s" : "", wid);
break;
case IVL_VT_LOGIC:
fprintf(stderr, "%s:%u: tgt-vvp sorry: vvp does not currently "
"supports 4-state dynamic arrays.\n",
ivl_expr_file(ex), ivl_expr_lineno(ex));
errors += 1;;
// logic objects are vectorable, but for now only support
// a single dimensions.
assert(ivl_type_packed_dimensions(element_type) == 1);
msb = ivl_type_packed_msb(element_type, 0);
lsb = ivl_type_packed_lsb(element_type, 0);
wid = msb>=lsb? msb - lsb : lsb - msb;
wid += 1;
fprintf(vvp_out, " %%new/darray %u, \"%sv%d\";\n", size_reg,
ivl_type_signed(element_type) ? "s" : "", wid);
break;
default:

View File

@ -4051,6 +4051,8 @@ bool of_NEW_DARRAY(vthread_t thr, vvp_code_t cp)
{
const char*text = cp->text;
size_t size = thr->words[cp->bit_idx[0]].w_int;
unsigned word_wid;
size_t n;
vvp_object_t obj;
if (strcmp(text,"b8") == 0) {
@ -4069,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, "v%u%zn", &word_wid, &n)) &&
(n == strlen(text))) {
obj = new vvp_darray_vec4(size, word_wid);
} else if ((1 == sscanf(text, "sv%u%zn", &word_wid, &n)) &&
(n == strlen(text))) {
obj = new vvp_darray_vec4(size, word_wid);
} else if (strcmp(text,"r") == 0) {
obj = new vvp_darray_real(size);
} else if (strcmp(text,"S") == 0) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012-2014 Stephen Williams (steve@icarus.com)
* Copyright (c) 2012-2015 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@ -18,7 +18,6 @@
*/
# include "vvp_darray.h"
# include "vvp_net.h"
# include <iostream>
# include <typeinfo>
@ -111,6 +110,36 @@ template class vvp_darray_atom<int16_t>;
template class vvp_darray_atom<int32_t>;
template class vvp_darray_atom<int64_t>;
vvp_darray_vec4::~vvp_darray_vec4()
{
}
size_t vvp_darray_vec4::get_size(void) const
{
return array_.size();
}
void vvp_darray_vec4::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_vec4::get_word(unsigned adr, vvp_vector4_t&value)
{
/*
* Return an undefined 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_X);
return;
}
value = array_[adr];
assert(value.size() == word_wid_);
}
vvp_darray_object::~vvp_darray_object()
{
}

View File

@ -1,7 +1,7 @@
#ifndef IVL_vvp_darray_H
#define IVL_vvp_darray_H
/*
* Copyright (c) 2012-2014 Stephen Williams (steve@icarus.com)
* Copyright (c) 2012-2015 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@ -20,12 +20,11 @@
*/
# include "vvp_object.h"
# include "vvp_net.h"
# include <list>
# include <string>
# include <vector>
class vvp_vector4_t;
class vvp_darray : public vvp_object {
public:
@ -61,6 +60,22 @@ template <class TYPE> class vvp_darray_atom : public vvp_darray {
std::vector<TYPE> array_;
};
class vvp_darray_vec4 : public vvp_darray {
public:
inline vvp_darray_vec4(size_t siz, unsigned word_wid) :
array_(siz), word_wid_(word_wid) { }
~vvp_darray_vec4();
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_vector4_t> array_;
unsigned word_wid_;
};
class vvp_darray_real : public vvp_darray {
public: