From 985c34bfd90e8b549f017161cc9bd8785ac505a9 Mon Sep 17 00:00:00 2001 From: steve Date: Thu, 22 Aug 2002 03:38:40 +0000 Subject: [PATCH] Fix behavioral eval of x?a:b expressions. --- tgt-vvp/eval_expr.c | 30 ++++++++++++++++++++++++++---- vvp/codes.h | 6 +++++- vvp/compile.cc | 6 +++++- vvp/opcodes.txt | 16 +++++++++++++++- vvp/vthread.cc | 27 ++++++++++++++++++++++++++- 5 files changed, 77 insertions(+), 8 deletions(-) diff --git a/tgt-vvp/eval_expr.c b/tgt-vvp/eval_expr.c index aa08e3c72..b3a9f3b99 100644 --- a/tgt-vvp/eval_expr.c +++ b/tgt-vvp/eval_expr.c @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CVS_IDENT -#ident "$Id: eval_expr.c,v 1.69 2002/08/12 01:35:03 steve Exp $" +#ident "$Id: eval_expr.c,v 1.70 2002/08/22 03:38:40 steve Exp $" #endif # include "vvp_priv.h" @@ -1241,11 +1241,12 @@ static struct vector_info draw_ternary_expr(ivl_expr_t exp, unsigned wid) { struct vector_info res, tmp; - unsigned lab_false, lab_out; + unsigned lab_true, lab_false, lab_out; ivl_expr_t cond = ivl_expr_oper1(exp); ivl_expr_t true_ex = ivl_expr_oper2(exp); ivl_expr_t false_ex = ivl_expr_oper3(exp); + lab_true = local_count++; lab_false = local_count++; lab_out = local_count++; @@ -1261,21 +1262,39 @@ static struct vector_info draw_ternary_expr(ivl_expr_t exp, unsigned wid) res.base = allocate_vector(wid); res.wid = wid; - fprintf(vvp_out, " %%jmp/0xz T_%d.%d, %u;\n", + fprintf(vvp_out, " %%jmp/1 T_%d.%d, %u;\n", + thread_count, lab_true, tmp.base); + fprintf(vvp_out, " %%jmp/0 T_%d.%d, %u;\n", thread_count, lab_false, tmp.base); + /* Ambiguous case. Evaluate both true and false expressions, + and use %blend to merge them. */ + + tmp = draw_eval_expr_wid(true_ex, wid); + fprintf(vvp_out, " %%mov %u, %u, %u;\n", res.base, tmp.base, wid); + clr_vector(tmp); + + tmp = draw_eval_expr_wid(false_ex, wid); + fprintf(vvp_out, " %%blend %u, %u, %u;\n", res.base, tmp.base, wid); + fprintf(vvp_out, " %%jmp T_%d.%d;\n", thread_count, lab_out); + + /* This is the true case. Just evaluate the true expression. */ + fprintf(vvp_out, "T_%d.%d ;\n", thread_count, lab_true); + tmp = draw_eval_expr_wid(true_ex, wid); fprintf(vvp_out, " %%mov %u, %u, %u;\n", res.base, tmp.base, wid); fprintf(vvp_out, " %%jmp T_%d.%d;\n", thread_count, lab_out); clr_vector(tmp); + + /* This is the false case. Just evaluate the false expression. */ fprintf(vvp_out, "T_%d.%d ;\n", thread_count, lab_false); tmp = draw_eval_expr_wid(false_ex, wid); fprintf(vvp_out, " %%mov %u, %u, %u;\n", res.base, tmp.base, wid); clr_vector(tmp); - + /* This is the out label. */ fprintf(vvp_out, "T_%d.%d ;\n", thread_count, lab_out); return res; @@ -1726,6 +1745,9 @@ struct vector_info draw_eval_expr(ivl_expr_t exp) /* * $Log: eval_expr.c,v $ + * Revision 1.70 2002/08/22 03:38:40 steve + * Fix behavioral eval of x?a:b expressions. + * * Revision 1.69 2002/08/12 01:35:03 steve * conditional ident string using autoconfig. * diff --git a/vvp/codes.h b/vvp/codes.h index 123d0adba..dada3ca31 100644 --- a/vvp/codes.h +++ b/vvp/codes.h @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CVS_IDENT -#ident "$Id: codes.h,v 1.46 2002/08/12 01:35:07 steve Exp $" +#ident "$Id: codes.h,v 1.47 2002/08/22 03:38:40 steve Exp $" #endif @@ -43,6 +43,7 @@ extern bool of_ASSIGN(vthread_t thr, vvp_code_t code); extern bool of_ASSIGN_D(vthread_t thr, vvp_code_t code); extern bool of_ASSIGN_MEM(vthread_t thr, vvp_code_t code); extern bool of_ASSIGN_X0(vthread_t thr, vvp_code_t code); +extern bool of_BLEND(vthread_t thr, vvp_code_t code); extern bool of_BREAKPOINT(vthread_t thr, vvp_code_t code); extern bool of_CASSIGN(vthread_t thr, vvp_code_t code); extern bool of_CMPIU(vthread_t thr, vvp_code_t code); @@ -152,6 +153,9 @@ extern vvp_code_t codespace_index(vvp_cpoint_t ptr); /* * $Log: codes.h,v $ + * Revision 1.47 2002/08/22 03:38:40 steve + * Fix behavioral eval of x?a:b expressions. + * * Revision 1.46 2002/08/12 01:35:07 steve * conditional ident string using autoconfig. * diff --git a/vvp/compile.cc b/vvp/compile.cc index a96f4ff4a..ed38d4872 100644 --- a/vvp/compile.cc +++ b/vvp/compile.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CVS_IDENT -#ident "$Id: compile.cc,v 1.137 2002/08/12 01:35:07 steve Exp $" +#ident "$Id: compile.cc,v 1.138 2002/08/22 03:38:40 steve Exp $" #endif # include "arith.h" @@ -88,6 +88,7 @@ const static struct opcode_table_s opcode_table[] = { { "%assign/d", of_ASSIGN_D, 3, {OA_FUNC_PTR, OA_BIT1, OA_BIT2} }, { "%assign/m",of_ASSIGN_MEM,3,{OA_MEM_PTR,OA_BIT1, OA_BIT2} }, { "%assign/x0",of_ASSIGN_X0,3,{OA_FUNC_PTR,OA_BIT1, OA_BIT2} }, + { "%blend", of_BLEND, 3, {OA_BIT1, OA_BIT2, OA_NUMBER} }, { "%breakpoint", of_BREAKPOINT, 0, {OA_NONE, OA_NONE, OA_NONE} }, { "%cassign",of_CASSIGN,2, {OA_FUNC_PTR, OA_FUNC_PTR2,OA_NONE} }, { "%cmp/s", of_CMPS, 3, {OA_BIT1, OA_BIT2, OA_NUMBER} }, @@ -1433,6 +1434,9 @@ void compile_net(char*label, char*name, int msb, int lsb, bool signed_flag, /* * $Log: compile.cc,v $ + * Revision 1.138 2002/08/22 03:38:40 steve + * Fix behavioral eval of x?a:b expressions. + * * Revision 1.137 2002/08/12 01:35:07 steve * conditional ident string using autoconfig. * diff --git a/vvp/opcodes.txt b/vvp/opcodes.txt index 15004c7f8..c21751b5d 100644 --- a/vvp/opcodes.txt +++ b/vvp/opcodes.txt @@ -1,7 +1,7 @@ /* * Copyright (c) 2001 Stephen Williams (steve@icarus.com) * - * $Id: opcodes.txt,v 1.36 2002/05/31 20:04:22 steve Exp $ + * $Id: opcodes.txt,v 1.37 2002/08/22 03:38:40 steve Exp $ */ @@ -82,6 +82,20 @@ The is the address of the thread register that contains the bit value to assign. +* %blend , , + +This instruction blends the bits of a vector into the destination in a +manner like the expression (x ? : ). The truth table is: + + 1 1 --> 1 + 0 0 --> 0 + z z --> z + x x --> x + .... --> x + +In other words, if the bits are identical, then take that +value. Otherwise, the value is x. + * %breakpoint This instruction unconditionally breaks the simulator into the diff --git a/vvp/vthread.cc b/vvp/vthread.cc index 9dc5420ec..11fc9c17a 100644 --- a/vvp/vthread.cc +++ b/vvp/vthread.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CVS_IDENT -#ident "$Id: vthread.cc,v 1.80 2002/08/18 01:05:50 steve Exp $" +#ident "$Id: vthread.cc,v 1.81 2002/08/22 03:38:40 steve Exp $" #endif # include "vthread.h" @@ -495,6 +495,28 @@ bool of_ASSIGN_MEM(vthread_t thr, vvp_code_t cp) return true; } +bool of_BLEND(vthread_t thr, vvp_code_t cp) +{ + assert(cp->bit_idx[0] >= 4); + + unsigned idx1 = cp->bit_idx[0]; + unsigned idx2 = cp->bit_idx[1]; + + for (unsigned idx = 0 ; idx < cp->number ; idx += 1) { + unsigned lb = thr_get_bit(thr, idx1); + unsigned rb = thr_get_bit(thr, idx2); + + if (lb != rb) + thr_put_bit(thr, idx1, 2); + + idx1 += 1; + if (idx2 >= 4) + idx2 += 1; + } + + return true; +} + bool of_BREAKPOINT(vthread_t thr, vvp_code_t cp) { #if defined(WITH_DEBUG) @@ -2221,6 +2243,9 @@ bool of_CALL_UFUNC(vthread_t thr, vvp_code_t cp) /* * $Log: vthread.cc,v $ + * Revision 1.81 2002/08/22 03:38:40 steve + * Fix behavioral eval of x?a:b expressions. + * * Revision 1.80 2002/08/18 01:05:50 steve * x in index values leads to 0. *