Update vecval size calculation in vvp and vpi code.
The standard specifies that the size of a vecval should be calculated as (size - 1)/32 + 1. When size is a PLI_INT32 this is needed to prevent an overflow, but when the size is unsigned this can be simplified to (size + 31)/32 since the size must fit into an integer, but we have an extra significant bit in an unsigned so no overflow can happen. This patch changes the code to use the correct version of the equation depending on the context. The previous patch does this in vvp/vpi_priv.cc
This commit is contained in:
parent
b85e7efca8
commit
c222169608
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2003-2010 Stephen Williams (steve@icarus.com)
|
||||
* Copyright (c) 2003-2012 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
|
||||
|
|
@ -680,7 +680,8 @@ static PLI_INT32 sys_fread_calltf(ICARUS_VPI_CONST PLI_BYTE8*name)
|
|||
vpi_free_object(argv);
|
||||
}
|
||||
|
||||
words = (width+31)/32;
|
||||
assert(width > 0);
|
||||
words = (width - 1)/32 + 1;
|
||||
vector = calloc(words, sizeof(s_vpi_vecval));
|
||||
bpe = (width+7)/8;
|
||||
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ void __vpiStringConst::vpi_get_value(p_vpi_value vp)
|
|||
{
|
||||
unsigned uint_value;
|
||||
p_vpi_vecval vecp;
|
||||
int size = strlen(value_);
|
||||
unsigned size = strlen(value_);
|
||||
char*rbuf = 0;
|
||||
char*cp;
|
||||
|
||||
|
|
@ -145,7 +145,7 @@ void __vpiStringConst::vpi_get_value(p_vpi_value vp)
|
|||
}
|
||||
rbuf = need_result_buf(size + 1, RBUF_VAL);
|
||||
uint_value = 0;
|
||||
for(int i=0; i<size;i ++){
|
||||
for(unsigned i=0; i<size; i += 1){
|
||||
uint_value <<=8;
|
||||
uint_value += (unsigned char)(value_[i]);
|
||||
}
|
||||
|
|
@ -156,8 +156,8 @@ void __vpiStringConst::vpi_get_value(p_vpi_value vp)
|
|||
case vpiBinStrVal:
|
||||
rbuf = need_result_buf(8 * size + 1, RBUF_VAL);
|
||||
cp = rbuf;
|
||||
for(int i=0; i<size;i ++){
|
||||
for(int bit=7;bit>=0; bit--){
|
||||
for(unsigned i=0; i<size; i += 1){
|
||||
for(int bit=7; bit>=0; bit -= 1){
|
||||
*cp++ = "01"[ (value_[i]>>bit)&1 ];
|
||||
}
|
||||
}
|
||||
|
|
@ -168,8 +168,8 @@ void __vpiStringConst::vpi_get_value(p_vpi_value vp)
|
|||
case vpiHexStrVal:
|
||||
rbuf = need_result_buf(2 * size + 1, RBUF_VAL);
|
||||
cp = rbuf;
|
||||
for(int i=0; i<size;i++){
|
||||
for(int nibble=1;nibble>=0; nibble--){
|
||||
for(unsigned i=0; i<size; i += 1){
|
||||
for(int nibble=1; nibble>=0; nibble -= 1){
|
||||
*cp++ = "0123456789abcdef"[ (value_[i]>>(nibble*4))&15 ];
|
||||
}
|
||||
}
|
||||
|
|
@ -184,8 +184,8 @@ void __vpiStringConst::vpi_get_value(p_vpi_value vp)
|
|||
|
||||
case vpiIntVal:
|
||||
vp->value.integer = 0;
|
||||
for(int i=0; i<size;i ++){
|
||||
for(int bit=7;bit>=0; bit--){
|
||||
for(unsigned i=0; i<size; i += 1){
|
||||
for(int bit=7; bit>=0; bit -= 1){
|
||||
vp->value.integer <<= 1;
|
||||
vp->value.integer += (value_[i]>>bit)&1;
|
||||
}
|
||||
|
|
@ -200,7 +200,7 @@ void __vpiStringConst::vpi_get_value(p_vpi_value vp)
|
|||
uint_value = 0;
|
||||
vecp = vp->value.vector;
|
||||
vecp->aval = vecp->bval = 0;
|
||||
for(int i=0; i<size;i ++){
|
||||
for(unsigned i=0; i<size; i += 1){
|
||||
vecp->aval |= value_[i] << uint_value*8;
|
||||
uint_value += 1;
|
||||
if (uint_value > 3) {
|
||||
|
|
|
|||
|
|
@ -467,7 +467,7 @@ static void format_vpiVectorVal(vvp_signal_value*sig, int base, unsigned wid,
|
|||
{
|
||||
long end = base + (signed)wid;
|
||||
unsigned int obit = 0;
|
||||
unsigned hwid = (wid - 1)/32 + 1;
|
||||
unsigned hwid = (wid + 31)/32;
|
||||
|
||||
s_vpi_vecval *op = (p_vpi_vecval)
|
||||
need_result_buf(hwid * sizeof(s_vpi_vecval), RBUF_VAL);
|
||||
|
|
|
|||
Loading…
Reference in New Issue