From 9afa95dff720d20a9228ba67395a2641da945d4c Mon Sep 17 00:00:00 2001 From: Cary R Date: Wed, 6 Jan 2010 11:52:02 -0800 Subject: [PATCH] A signal select is signed if the select not the signal is signed. The padding for a signal select was using the signal to determine if the padding should be singed or not. In reality this should be unsigned padding unless the select was enclosed in a $signed(). (cherry picked from commit 458258d554e50eeec7b18ea30f781e19c8943bf4) --- tgt-vvp/eval_expr.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/tgt-vvp/eval_expr.c b/tgt-vvp/eval_expr.c index ebe9bb03f..f9524d06b 100644 --- a/tgt-vvp/eval_expr.c +++ b/tgt-vvp/eval_expr.c @@ -2322,7 +2322,8 @@ static struct vector_info draw_select_array(ivl_expr_t sube, return res; } -static struct vector_info draw_select_signal(ivl_expr_t sube, +static struct vector_info draw_select_signal(ivl_expr_t exp, + ivl_expr_t sube, ivl_expr_t bit_idx, unsigned bit_wid, unsigned wid) @@ -2368,10 +2369,9 @@ static struct vector_info draw_select_signal(ivl_expr_t sube, res.base, sig, use_word, bit_wid, bit_wid, ivl_expr_width(sube)); save_signal_lookaside(res.base, sig, use_word, bit_wid); - /* Pad the part select to the desired width. Note that - this *should* always turn into an unsigned pad - because part selects are always unsigned. */ - pad_expr_in_place(sube, res, bit_wid); + /* Pad the part select to the desired width. Because of + $signed() this may be signed or unsigned (default). */ + pad_expr_in_place(exp, res, bit_wid); return res; } @@ -2395,9 +2395,9 @@ static struct vector_info draw_select_signal(ivl_expr_t sube, fprintf(vvp_out, " %%load/x1p %u, v%p_%u, %u;\n", res.base, sig, use_word, use_wid); - if (use_wid < res.wid) - fprintf(vvp_out, " %%movi %u, 0, %u;\n", - res.base + use_wid, res.wid - use_wid); + /* Pad the part select to the desired width. Because of + $signed() this may be signed or unsigned (default). */ + pad_expr_in_place(exp, res, use_wid); fprintf(vvp_out, " %%jmp T_%d.%d;\n", thread_count, lab_end); fprintf(vvp_out, "T_%d.%d ;\n", thread_count, lab_x); @@ -2407,7 +2407,8 @@ static struct vector_info draw_select_signal(ivl_expr_t sube, return res; } -static void draw_select_signal_dest(ivl_expr_t sube, +static void draw_select_signal_dest(ivl_expr_t exp, + ivl_expr_t sube, ivl_expr_t bit_idx, struct vector_info dest, int stuff_ok_flag) @@ -2433,7 +2434,7 @@ static void draw_select_signal_dest(ivl_expr_t sube, /* Fallback, just draw the expression and copy the result into the destination. */ - tmp = draw_select_signal(sube, bit_idx, dest.wid, dest.wid); + tmp = draw_select_signal(exp, sube, bit_idx, dest.wid, dest.wid); assert(tmp.wid == dest.wid); fprintf(vvp_out, " %%mov %u, %u, %u; Move signal select into place\n", @@ -2468,7 +2469,7 @@ static struct vector_info draw_select_expr(ivl_expr_t exp, unsigned wid, } if (ivl_expr_type(sube) == IVL_EX_SIGNAL) { - res = draw_select_signal(sube, shift, ivl_expr_width(exp), wid); + res = draw_select_signal(exp, sube, shift, ivl_expr_width(exp), wid); fprintf(vvp_out, "; Save base=%u wid=%u in lookaside.\n", res.base, wid); save_expression_lookaside(res.base, exp, wid); @@ -2587,7 +2588,7 @@ static void draw_select_expr_dest(ivl_expr_t exp, struct vector_info dest, } if (ivl_expr_type(sube) == IVL_EX_SIGNAL) { - draw_select_signal_dest(sube, shift, dest, stuff_ok_flag); + draw_select_signal_dest(exp, sube, shift, dest, stuff_ok_flag); return; }