Navigation Menu

Skip to content

Commit

Permalink
Remove useless vvp_realarray_t
Browse files Browse the repository at this point in the history
The vvp_darray_real class cal be used for static arrays as well
and this is a more general solution anyhow. Kill the now useless
vvp_realarray_t class.
  • Loading branch information
steveicarus committed Jan 3, 2013
1 parent f5717a6 commit 1527b87
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 60 deletions.
32 changes: 22 additions & 10 deletions vvp/array.cc
Expand Up @@ -18,11 +18,12 @@
*/

# include "array.h"
#include "symbols.h"
#include "schedule.h"
#include "vpi_priv.h"
#include "vvp_net_sig.h"
#include "config.h"
# include "symbols.h"
# include "schedule.h"
# include "vpi_priv.h"
# include "vvp_net_sig.h"
# include "vvp_darray.h"
# include "config.h"
#ifdef CHECK_WITH_VALGRIND
#include "vvp_cleanup.h"
#endif
Expand All @@ -34,6 +35,8 @@
# include <cassert>
# include "ivl_alloc.h"

class vvp_darray_real;

unsigned long count_net_arrays = 0;
unsigned long count_net_array_words = 0;
unsigned long count_var_arrays = 0;
Expand Down Expand Up @@ -101,7 +104,7 @@ struct __vpiArray : public __vpiHandle {
vpiHandle*nets;
// If this is a var array, then these are used instead of nets.
vvp_vector4array_t *vals4;
vvp_realarray_t *valsr;
vvp_darray_real *valsr;
struct __vpiArrayWord*vals_words;

vvp_fun_arrayport*ports_;
Expand Down Expand Up @@ -1050,7 +1053,14 @@ double array_get_word_r(vvp_array_t arr, unsigned address)
if (arr->valsr) {
assert(arr->vals4 == 0);
assert(arr->nets == 0);
return arr->valsr->get_word(address);
// In this context, address out of bounds returns 0.0
// instead of an error.
if (address >= arr->valsr->get_size())
return 0.0;

double val;
arr->valsr->get_word(address, val);
return val;
}

assert(arr->nets);
Expand Down Expand Up @@ -1199,7 +1209,7 @@ void compile_real_array(char*label, char*name, int last, int first,
struct __vpiArray*arr = dynamic_cast<__vpiArray*>(obj);

/* Make the words. */
arr->valsr = new vvp_realarray_t(arr->array_count);
arr->valsr = new vvp_darray_real(arr->array_count);
arr->vals_width = 1;

/* For a real array the MSB and LSB must be zero. */
Expand Down Expand Up @@ -1515,8 +1525,10 @@ void array_word_change(vvp_array_t array, unsigned long addr)
if (cur->test_value_callback_ready()) {
if (cur->cb_data.value) {
if (vpi_array_is_real(array)) {
vpip_real_get_value(array->valsr->get_word(addr),
cur->cb_data.value);
double val = 0.0;
if (addr < array->valsr->get_size())
array->valsr->get_word(addr, val);
vpip_real_get_value(val, cur->cb_data.value);
} else {
vpip_vec4_get_value(array->vals4->get_word(addr),
array->vals_width,
Expand Down
30 changes: 0 additions & 30 deletions vvp/vvp_net.cc
Expand Up @@ -1779,36 +1779,6 @@ bool vector2_to_value(const vvp_vector2_t&a, int32_t&val, bool is_signed)
return a.size() <= 32;
}

vvp_realarray_t::vvp_realarray_t(unsigned wor)
: words_(wor)
{
array_ = new double[words_];
// Real array words have a default value of zero.
for (unsigned idx = 0 ; idx < words_; idx += 1) {
array_[idx] = 0.0;
}
}

vvp_realarray_t::~vvp_realarray_t()
{
delete[]array_;
}

void vvp_realarray_t::set_word(unsigned word, double value)
{
if (word >= words_)
return;
array_[word] = value;
}

double vvp_realarray_t::get_word(unsigned word) const
{
if (word >= words_)
return 0.0;
else
return array_[word];
}

vvp_vector4array_t::vvp_vector4array_t(unsigned width__, unsigned words__)
: width_(width__), words_(words__)
{
Expand Down
21 changes: 1 addition & 20 deletions vvp/vvp_net.h
@@ -1,7 +1,7 @@
#ifndef __vvp_net_H
#define __vvp_net_H
/*
* Copyright (c) 2004-2012 Stephen Williams (steve@icarus.com)
* Copyright (c) 2004-2013 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
Expand Down Expand Up @@ -522,25 +522,6 @@ extern bool vector2_to_value(const vvp_vector2_t&a, int32_t&val, bool is_signed)

extern vvp_vector4_t vector4_from_text(const char*bits, unsigned wid);

/*
* The __vpiArray handle uses instances of this to keep an array of
* real valued variables.
*/
class vvp_realarray_t {

public:
vvp_realarray_t(unsigned words);
~vvp_realarray_t();

unsigned words() const { return words_; }

double get_word(unsigned idx) const;
void set_word(unsigned idx, double val);

private:
unsigned words_;
double*array_;
};

/*
* vvp_vector4array_t
Expand Down

0 comments on commit 1527b87

Please sign in to comment.