Handle darray objects of all integral atom types.

Clean up the vector4_to_value to use templates and explicit
instantiations. This makes the interface much cleaner for a
wider variety of integral types.
This commit is contained in:
Stephen Williams 2012-10-06 15:25:56 -07:00
parent e071bd81ee
commit 1326f9aef1
4 changed files with 37 additions and 55 deletions

View File

@ -3963,12 +3963,16 @@ bool of_NEW_DARRAY(vthread_t thr, vvp_code_t cp)
obj = new vvp_darray_atom<uint16_t>(size);
} else if (strcmp(text,"b32") == 0) {
obj = new vvp_darray_atom<uint32_t>(size);
} else if (strcmp(text,"b64") == 0) {
obj = new vvp_darray_atom<uint64_t>(size);
} else if (strcmp(text,"sb8") == 0) {
obj = new vvp_darray_atom<int8_t>(size);
} else if (strcmp(text,"sb16") == 0) {
obj = new vvp_darray_atom<int16_t>(size);
} else if (strcmp(text,"sb32") == 0) {
obj = new vvp_darray_atom<int32_t>(size);
} else if (strcmp(text,"sb64") == 0) {
obj = new vvp_darray_atom<int64_t>(size);
} else {
obj = new vvp_darray (size);
}

View File

@ -1619,8 +1619,8 @@ ostream& operator<< (ostream&out, const vvp_vector4_t&that)
return out;
}
template <class INT>bool do_vector4_to_value(const vvp_vector4_t&vec, INT&val,
bool is_signed, bool is_arithmetic)
template <class INT>bool vector4_to_value(const vvp_vector4_t&vec, INT&val,
bool is_signed, bool is_arithmetic)
{
long res = 0;
INT msk = 1;
@ -1654,22 +1654,27 @@ template <class INT>bool do_vector4_to_value(const vvp_vector4_t&vec, INT&val,
return rc_flag;
}
bool vector4_to_value(const vvp_vector4_t&vec, long&val,
bool is_signed, bool is_arithmetic)
{
return do_vector4_to_value(vec, val, is_signed, is_arithmetic);
}
template bool vector4_to_value(const vvp_vector4_t&vec, int8_t&val,
bool is_signed, bool is_arithmetic);
template bool vector4_to_value(const vvp_vector4_t&vec, int16_t&val,
bool is_signed, bool is_arithmetic);
template bool vector4_to_value(const vvp_vector4_t&vec, int32_t&val,
bool is_signed, bool is_arithmetic);
template bool vector4_to_value(const vvp_vector4_t&vec, int64_t&val,
bool is_signed, bool is_arithmetic);
template bool vector4_to_value(const vvp_vector4_t&vec, uint8_t&val,
bool is_signed, bool is_arithmetic);
template bool vector4_to_value(const vvp_vector4_t&vec, uint16_t&val,
bool is_signed, bool is_arithmetic);
template bool vector4_to_value(const vvp_vector4_t&vec, uint32_t&val,
bool is_signed, bool is_arithmetic);
template bool vector4_to_value(const vvp_vector4_t&vec, uint64_t&val,
bool is_signed, bool is_arithmetic);
bool vector4_to_value(const vvp_vector4_t&vec, int32_t&val,
bool is_signed, bool is_arithmetic)
template <class T> bool vector4_to_value(const vvp_vector4_t&vec, T&val)
{
return do_vector4_to_value(vec, val, is_signed, is_arithmetic);
}
bool vector4_to_value(const vvp_vector4_t&vec, unsigned long&val)
{
unsigned long res = 0;
unsigned long msk = 1;
T res = 0;
T msk = 1;
unsigned size = vec.size();
if (size > 8*sizeof(val)) size = 8*sizeof(val);
@ -1684,44 +1689,16 @@ bool vector4_to_value(const vvp_vector4_t&vec, unsigned long&val)
return false;
}
msk <<= 1UL;
msk <<= static_cast<T>(1);
}
val = res;
return true;
}
template bool vector4_to_value(const vvp_vector4_t&vec, unsigned long&val);
#ifndef UL_AND_TIME64_SAME
bool vector4_to_value(const vvp_vector4_t&vec, int64_t&val,
bool is_signed, bool is_arithmetic)
{
return do_vector4_to_value(vec, val, is_signed, is_arithmetic);
}
bool vector4_to_value(const vvp_vector4_t&vec, vvp_time64_t&val)
{
vvp_time64_t res = 0;
vvp_time64_t msk = 1;
unsigned size = vec.size();
if (size > 8*sizeof(val)) size = 8*sizeof(val);
for (unsigned idx = 0 ; idx < size ; idx += 1) {
switch (vec.value(idx)) {
case BIT4_0:
break;
case BIT4_1:
res |= msk;
break;
default:
return false;
}
msk <<= 1UL;
}
val = res;
return true;
}
template bool vector4_to_value(const vvp_vector4_t&vec, vvp_time64_t&val);
#endif
bool vector4_to_value(const vvp_vector4_t&vec, double&val, bool signed_flag)

View File

@ -510,13 +510,12 @@ template <class T> extern T coerce_to_width(const T&that, unsigned width);
* value will be "false", but the other bits will be transferred. This
* is what you want if you are doing "vpi_get_value", for example.
*/
extern bool vector4_to_value(const vvp_vector4_t&a, long&val, bool is_signed, bool is_arithmetic =true);
extern bool vector4_to_value(const vvp_vector4_t&a, unsigned long&val);
extern bool vector4_to_value(const vvp_vector4_t&a, int32_t&val, bool is_signed, bool is_arithmetic =true);
#ifndef UL_AND_TIME64_SAME
extern bool vector4_to_value(const vvp_vector4_t&a, int64_t&val, bool is_signed, bool is_arithmetic =true);
extern bool vector4_to_value(const vvp_vector4_t&a, vvp_time64_t&val);
#endif
template <class T> extern bool vector4_to_value(const vvp_vector4_t&a, T&val,
bool is_signed,
bool is_arithmetic =true);
template <class T> extern bool vector4_to_value(const vvp_vector4_t&a, T&val);
extern bool vector4_to_value(const vvp_vector4_t&a, double&val, bool is_signed);
extern bool vector2_to_value(const vvp_vector2_t&a, int32_t&val, bool is_signed);

View File

@ -50,7 +50,7 @@ template <class TYPE> void vvp_darray_atom<TYPE>::set_word(unsigned adr, const v
{
if (adr >= array_.size())
return;
int32_t tmp;
TYPE tmp;
vector4_to_value(value, tmp, true, false);
array_[adr] = tmp;
}
@ -74,6 +74,8 @@ template <class TYPE> void vvp_darray_atom<TYPE>::get_word(unsigned adr, vvp_vec
template class vvp_darray_atom<uint8_t>;
template class vvp_darray_atom<uint16_t>;
template class vvp_darray_atom<uint32_t>;
template class vvp_darray_atom<uint64_t>;
template class vvp_darray_atom<int8_t>;
template class vvp_darray_atom<int16_t>;
template class vvp_darray_atom<int32_t>;
template class vvp_darray_atom<int64_t>;