Implement some vpi_get_value formats for vec4 stack values.

This commit is contained in:
Stephen Williams 2014-01-06 20:27:14 -08:00
parent a2845cee70
commit 4820d46353
5 changed files with 171 additions and 12 deletions

View File

@ -29,7 +29,7 @@
struct args_info { struct args_info {
char*text; char*text;
/* True if this argument is a calculated vec4. */ /* True ('s' or 'u' if this argument is a calculated vec4. */
char vec_flag; char vec_flag;
/* True if this argument is a calculated string. */ /* True if this argument is a calculated string. */
char str_flag; char str_flag;
@ -399,7 +399,7 @@ static void draw_vpi_taskfunc_args(const char*call_string,
case IVL_VT_LOGIC: case IVL_VT_LOGIC:
case IVL_VT_BOOL: case IVL_VT_BOOL:
draw_eval_vec4(expr, 0); draw_eval_vec4(expr, 0);
args[idx].vec_flag = 1; args[idx].vec_flag = ivl_expr_signed(expr)? 's' : 'u';
args[idx].str_flag = 0; args[idx].str_flag = 0;
args[idx].real_flag = 0; args[idx].real_flag = 0;
args[idx].stack = vec4_stack_need; args[idx].stack = vec4_stack_need;
@ -452,7 +452,8 @@ static void draw_vpi_taskfunc_args(const char*call_string,
fprintf(vvp_out, ", W<%u,r>",pos); fprintf(vvp_out, ", W<%u,r>",pos);
} else if (args[idx].vec_flag) { } else if (args[idx].vec_flag) {
unsigned pos = vec4_stack_need - args[idx].stack - 1; unsigned pos = vec4_stack_need - args[idx].stack - 1;
fprintf(vvp_out, ", S<%u,vec4>",pos); char sign_flag = args[idx].vec_flag;
fprintf(vvp_out, ", S<%u,vec4,%c>",pos, sign_flag);
} else { } else {
fprintf(vvp_out, ", %s", args[idx].text); fprintf(vvp_out, ", %s", args[idx].text);
} }

View File

@ -572,10 +572,21 @@ bool vpi_handle_resolv_list_s::resolve(bool mes)
val.ptr = vpip_make_vthr_str_stack(base); val.ptr = vpip_make_vthr_str_stack(base);
sym_set_value(sym_vpi, label(), val); sym_set_value(sym_vpi, label(), val);
} else if (1 == sscanf(label(), "S<%u,vec4>%n", &base, &n) } else if (2 == sscanf(label(), "S<%u,vec4,%[su]>%n", &base, ss, &n)
&& n == strlen(label())) { && n == strlen(label())) {
val.ptr = vpip_make_vthr_vec4_stack(base); bool signed_flag = false;
for (char*fp = ss ; *fp ; fp += 1) switch (*fp) {
case 's':
signed_flag = true;
break;
case 'u':
signed_flag = false;
break;
default:
break;
}
val.ptr = vpip_make_vthr_vec4_stack(base, signed_flag);
sym_set_value(sym_vpi, label(), val); sym_set_value(sym_vpi, label(), val);
} }

View File

@ -269,7 +269,7 @@ static char* strdupnew(char const *str)
assert(yylval.text); assert(yylval.text);
return T_SYMBOL; } return T_SYMBOL; }
"S<"[0-9]*",vec4>" { "S<"[0-9]*",vec4,"[us]">" {
yylval.text = strdup(yytext); yylval.text = strdup(yytext);
assert(yylval.text); assert(yylval.text);
return T_SYMBOL; } return T_SYMBOL; }

View File

@ -660,7 +660,7 @@ vpiHandle vpip_make_vthr_vector(unsigned base, unsigned wid, bool signed_flag);
vpiHandle vpip_make_vthr_word(unsigned base, const char*type); vpiHandle vpip_make_vthr_word(unsigned base, const char*type);
vpiHandle vpip_make_vthr_str_stack(unsigned depth); vpiHandle vpip_make_vthr_str_stack(unsigned depth);
vpiHandle vpip_make_vthr_vec4_stack(unsigned depth); vpiHandle vpip_make_vthr_vec4_stack(unsigned depth, bool signed_flag);
vpiHandle vpip_make_vthr_A(char*label, unsigned index); vpiHandle vpip_make_vthr_A(char*label, unsigned index);
vpiHandle vpip_make_vthr_A(char*label, char*symbol); vpiHandle vpip_make_vthr_A(char*label, char*symbol);

View File

@ -35,6 +35,9 @@
# include <cassert> # include <cassert>
# include "ivl_alloc.h" # include "ivl_alloc.h"
extern const char hex_digits[256];
extern const char oct_digits[64];
struct __vpiVThrVec : public __vpiHandle { struct __vpiVThrVec : public __vpiHandle {
__vpiVThrVec(); __vpiVThrVec();
int get_type_code(void) const; int get_type_code(void) const;
@ -704,18 +707,25 @@ void __vpiVThrStrStack::vpi_get_value(p_vpi_value vp)
class __vpiVThrVec4Stack : public __vpiHandle { class __vpiVThrVec4Stack : public __vpiHandle {
public: public:
__vpiVThrVec4Stack(unsigned depth); __vpiVThrVec4Stack(unsigned depth, bool signed_flag);
int get_type_code(void) const; int get_type_code(void) const;
int vpi_get(int code); int vpi_get(int code);
void vpi_get_value(p_vpi_value val); void vpi_get_value(p_vpi_value val);
vpiHandle vpi_put_value(p_vpi_value val, int flags);
private: private:
void vpi_get_value_string_(p_vpi_value vp, const vvp_vector4_t&val); void vpi_get_value_string_(p_vpi_value vp, const vvp_vector4_t&val);
void vpi_get_value_binstr_(p_vpi_value vp, const vvp_vector4_t&val);
void vpi_get_value_decstr_(p_vpi_value vp, const vvp_vector4_t&val);
void vpi_get_value_real_ (p_vpi_value vp, const vvp_vector4_t&val);
void vpi_get_value_hexstr_(p_vpi_value vp, const vvp_vector4_t&val);
void vpi_get_value_vector_(p_vpi_value vp, const vvp_vector4_t&val);
private: private:
unsigned depth_; unsigned depth_;
bool signed_flag_;
}; };
__vpiVThrVec4Stack::__vpiVThrVec4Stack(unsigned d) __vpiVThrVec4Stack::__vpiVThrVec4Stack(unsigned d, bool sf)
: depth_(d) : depth_(d), signed_flag_(sf)
{ {
} }
@ -748,9 +758,25 @@ void __vpiVThrVec4Stack::vpi_get_value(p_vpi_value vp)
vvp_vector4_t val = vthread_get_vec4_stack(vpip_current_vthread, depth_); vvp_vector4_t val = vthread_get_vec4_stack(vpip_current_vthread, depth_);
switch (vp->format) { switch (vp->format) {
case vpiBinStrVal:
vpi_get_value_binstr_(vp, val);
break;
case vpiDecStrVal:
vpi_get_value_decstr_(vp, val);
break;
case vpiHexStrVal:
vpi_get_value_hexstr_(vp, val);
break;
case vpiRealVal:
vpi_get_value_real_(vp, val);
break;
case vpiStringVal: case vpiStringVal:
vpi_get_value_string_(vp, val); vpi_get_value_string_(vp, val);
break; break;
case vpiVectorVal:
vpi_get_value_vector_(vp, val);
break;
default: default:
fprintf(stderr, "internal error: vpi_get_value(<format=%d>)" fprintf(stderr, "internal error: vpi_get_value(<format=%d>)"
@ -760,6 +786,80 @@ void __vpiVThrVec4Stack::vpi_get_value(p_vpi_value vp)
} }
void __vpiVThrVec4Stack::vpi_get_value_binstr_(p_vpi_value vp, const vvp_vector4_t&val)
{
unsigned wid = val.size();
char*rbuf = need_result_buf(wid+1, RBUF_VAL);
for (unsigned idx = 0 ; idx < wid ; idx += 1) {
rbuf[wid-idx-1] = vvp_bit4_to_ascii(val.value(idx));
}
rbuf[wid] = 0;
vp->value.str = rbuf;
}
void __vpiVThrVec4Stack::vpi_get_value_decstr_(p_vpi_value vp, const vvp_vector4_t&val)
{
unsigned wid = val.size();
int nbuf = (wid+2)/3 + 1;
char *rbuf = need_result_buf(nbuf, RBUF_VAL);
vpip_vec4_to_dec_str(val, rbuf, nbuf, signed_flag_);
vp->value.str = rbuf;
}
void __vpiVThrVec4Stack::vpi_get_value_hexstr_(p_vpi_value vp, const vvp_vector4_t&val)
{
unsigned wid = val.size();
unsigned hwid = (wid + 3) /4;
char*rbuf = need_result_buf(hwid+1, RBUF_VAL);
rbuf[hwid] = 0;
unsigned hval = 0;
for (unsigned idx = 0; idx < wid ; idx += 1) {
unsigned tmp = 0;
switch (val.value(idx)) {
case BIT4_0:
tmp = 0;
break;
case BIT4_1:
tmp = 1;
break;
case BIT4_X:
tmp = 2;
break;
case BIT4_Z:
tmp = 3;
break;
}
hval = hval | (tmp << 2*(idx%4));
if (idx%4 == 3) {
hwid -= 1;
rbuf[hwid] = hex_digits[hval];
hval = 0;
}
}
if (hwid > 0) {
hwid -= 1;
rbuf[hwid] = hex_digits[hval];
hval = 0;
}
vp->value.str = rbuf;
}
void __vpiVThrVec4Stack::vpi_get_value_real_(p_vpi_value vp, const vvp_vector4_t&val)
{
unsigned wid = val.size();
vp->value.real = 0.0;
for (unsigned idx = wid ; idx > 0 ; idx -= 1) {
vp->value.real *= 2.0;
if (val.value(idx-1) == BIT4_1)
vp->value.real += 1.0;
}
}
void __vpiVThrVec4Stack::vpi_get_value_string_(p_vpi_value vp, const vvp_vector4_t&val) void __vpiVThrVec4Stack::vpi_get_value_string_(p_vpi_value vp, const vvp_vector4_t&val)
{ {
char*rbuf = need_result_buf((val.size() / 8) + 1, RBUF_VAL); char*rbuf = need_result_buf((val.size() / 8) + 1, RBUF_VAL);
@ -791,15 +891,62 @@ void __vpiVThrVec4Stack::vpi_get_value_string_(p_vpi_value vp, const vvp_vector4
vp->value.str = rbuf; vp->value.str = rbuf;
} }
void __vpiVThrVec4Stack::vpi_get_value_vector_(p_vpi_value vp, const vvp_vector4_t&val)
{
unsigned wid = val.size();
vp->value.vector = (s_vpi_vecval*)
need_result_buf((wid+31)/32*sizeof(s_vpi_vecval), RBUF_VAL);
assert(vp->value.vector);
for (unsigned idx = 0 ; idx < wid ; idx += 1) {
int word = idx/32;
PLI_INT32 mask = 1 << (idx%32);
switch (val.value(idx)) {
case BIT4_0:
vp->value.vector[word].aval &= ~mask;
vp->value.vector[word].bval &= ~mask;
break;
case BIT4_1:
vp->value.vector[word].aval |= mask;
vp->value.vector[word].bval &= ~mask;
break;
case BIT4_X:
vp->value.vector[word].aval |= mask;
vp->value.vector[word].bval |= mask;
break;
case BIT4_Z:
vp->value.vector[word].aval &= ~mask;
vp->value.vector[word].bval |= mask;
break;
}
}
}
vpiHandle __vpiVThrVec4Stack::vpi_put_value(p_vpi_value vp, int /*flags*/)
{
assert(vpip_current_vthread);
switch (vp->format) {
default:
fprintf(stderr, "internal error: vpi_put_value(<format=%d>)"
" not implemented for __vpiVThrVec4Stack.\n", vp->format);
assert(0);
return 0;
}
}
vpiHandle vpip_make_vthr_str_stack(unsigned depth) vpiHandle vpip_make_vthr_str_stack(unsigned depth)
{ {
class __vpiVThrStrStack*obj = new __vpiVThrStrStack(depth); class __vpiVThrStrStack*obj = new __vpiVThrStrStack(depth);
return obj; return obj;
} }
vpiHandle vpip_make_vthr_vec4_stack(unsigned depth) vpiHandle vpip_make_vthr_vec4_stack(unsigned depth, bool signed_flag)
{ {
class __vpiVThrVec4Stack*obj = new __vpiVThrVec4Stack(depth); class __vpiVThrVec4Stack*obj = new __vpiVThrVec4Stack(depth, signed_flag);
return obj; return obj;
} }