Sign extend signed vectors when getting vpiIntVal.
When getting values using vpi_get_value, the vpiIntVal is the integer value and should be sign-extended if the source value is signed.
This commit is contained in:
parent
f78994b66c
commit
62d7c081dc
|
|
@ -294,21 +294,13 @@ static void format_vpiDecStrVal(vvp_fun_signal_vec*sig, int base, unsigned wid,
|
||||||
}
|
}
|
||||||
|
|
||||||
static void format_vpiIntVal(vvp_fun_signal_vec*sig, int base, unsigned wid,
|
static void format_vpiIntVal(vvp_fun_signal_vec*sig, int base, unsigned wid,
|
||||||
s_vpi_value*vp)
|
int signed_flag, s_vpi_value*vp)
|
||||||
{
|
{
|
||||||
unsigned iwid = 8 * sizeof(vp->value.integer);
|
vvp_vector4_t sub = sig->vec4_value().subvalue(base, wid);
|
||||||
long ssize = (signed)sig->size();
|
long val = 0;
|
||||||
|
bool flag = vector4_to_value(sub, val, signed_flag);
|
||||||
if (wid > iwid) wid = iwid;
|
if (! flag) val = 0;
|
||||||
long end = base + (signed)wid;
|
vp->value.integer = val;
|
||||||
if (end > ssize) end = ssize;
|
|
||||||
|
|
||||||
vp->value.integer = 0;
|
|
||||||
for (long idx = (base < 0) ? 0 : base ; idx < end ; idx += 1) {
|
|
||||||
if (sig->value(idx) == BIT4_1) {
|
|
||||||
vp->value.integer |= 1<<(idx-base);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void format_vpiRealVal(vvp_fun_signal_vec*sig, int base, unsigned wid,
|
static void format_vpiRealVal(vvp_fun_signal_vec*sig, int base, unsigned wid,
|
||||||
|
|
@ -653,7 +645,7 @@ static void signal_get_value(vpiHandle ref, s_vpi_value*vp)
|
||||||
switch (vp->format) {
|
switch (vp->format) {
|
||||||
|
|
||||||
case vpiIntVal:
|
case vpiIntVal:
|
||||||
format_vpiIntVal(vsig, 0, wid, vp);
|
format_vpiIntVal(vsig, 0, wid, rfp->signed_flag, vp);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case vpiScalarVal:
|
case vpiScalarVal:
|
||||||
|
|
@ -1036,7 +1028,7 @@ static void PV_get_value(vpiHandle ref, p_vpi_value vp)
|
||||||
switch (vp->format) {
|
switch (vp->format) {
|
||||||
|
|
||||||
case vpiIntVal:
|
case vpiIntVal:
|
||||||
format_vpiIntVal(sig, PV_get_base(rfp), rfp->width, vp);
|
format_vpiIntVal(sig, PV_get_base(rfp), rfp->width, 0, vp);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case vpiBinStrVal:
|
case vpiBinStrVal:
|
||||||
|
|
|
||||||
|
|
@ -1078,6 +1078,34 @@ vvp_vector4_t double_to_vector4(double val, unsigned wid)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool vector4_to_value(const vvp_vector4_t&vec, long&val, bool is_signed)
|
||||||
|
{
|
||||||
|
long res = 0;
|
||||||
|
long msk = 1;
|
||||||
|
|
||||||
|
for (unsigned idx = 0 ; idx < vec.size() ; idx += 1) {
|
||||||
|
switch (vec.value(idx)) {
|
||||||
|
case BIT4_0:
|
||||||
|
break;
|
||||||
|
case BIT4_1:
|
||||||
|
res |= msk;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
msk <<= 1L;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_signed && vec.value(vec.size()-1) == BIT4_1) {
|
||||||
|
if (vec.size() < 8*sizeof(val))
|
||||||
|
res |= (-1L) << vec.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
val = res;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool vector4_to_value(const vvp_vector4_t&vec, unsigned long&val)
|
bool vector4_to_value(const vvp_vector4_t&vec, unsigned long&val)
|
||||||
{
|
{
|
||||||
unsigned long res = 0;
|
unsigned long res = 0;
|
||||||
|
|
|
||||||
|
|
@ -379,6 +379,7 @@ extern vvp_vector4_t double_to_vector4(double val, unsigned wid);
|
||||||
* to real and integers) and the return value becomes false to
|
* to real and integers) and the return value becomes false to
|
||||||
* indicate an error.
|
* indicate an error.
|
||||||
*/
|
*/
|
||||||
|
extern bool vector4_to_value(const vvp_vector4_t&a, long&val, bool is_signed);
|
||||||
extern bool vector4_to_value(const vvp_vector4_t&a, unsigned long&val);
|
extern bool vector4_to_value(const vvp_vector4_t&a, unsigned long&val);
|
||||||
extern bool vector4_to_value(const vvp_vector4_t&a, double&val, bool is_signed);
|
extern bool vector4_to_value(const vvp_vector4_t&a, double&val, bool is_signed);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue