From 06437b7fbab03eb9238042fe80f93ad7ab6a508b Mon Sep 17 00:00:00 2001 From: steve Date: Wed, 2 May 2001 01:57:25 +0000 Subject: [PATCH] Support behavioral subtraction. --- tgt-vvp/eval_expr.c | 11 +++++++++-- vvp/codes.h | 6 +++++- vvp/compile.cc | 6 +++++- vvp/opcodes.txt | 17 ++++++++++++++++- vvp/vthread.cc | 45 ++++++++++++++++++++++++++++++++++++++++++++- 5 files changed, 79 insertions(+), 6 deletions(-) diff --git a/tgt-vvp/eval_expr.c b/tgt-vvp/eval_expr.c index 97ce850bd..fcaa71b4e 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 */ #if !defined(WINNT) -#ident "$Id: eval_expr.c,v 1.22 2001/05/01 02:07:34 steve Exp $" +#ident "$Id: eval_expr.c,v 1.23 2001/05/02 01:57:25 steve Exp $" #endif # include "vvp_priv.h" @@ -524,7 +524,10 @@ static struct vector_info draw_binary_expr_plus(ivl_expr_t exp, unsigned wid) lv = draw_eval_expr_wid(le, wid); rv = draw_eval_expr_wid(re, wid); - fprintf(vvp_out, " %%add %u, %u, %u;\n", lv.base, rv.base, wid); + if (ivl_expr_opcode(exp) == '-') + fprintf(vvp_out, " %%sub %u, %u, %u;\n", lv.base, rv.base, wid); + else + fprintf(vvp_out, " %%add %u, %u, %u;\n", lv.base, rv.base, wid); clr_vector(rv); @@ -556,6 +559,7 @@ static struct vector_info draw_binary_expr(ivl_expr_t exp, unsigned wid) break; case '+': + case '-': rv = draw_binary_expr_plus(exp, wid); break; @@ -883,6 +887,9 @@ struct vector_info draw_eval_expr(ivl_expr_t exp) /* * $Log: eval_expr.c,v $ + * Revision 1.23 2001/05/02 01:57:25 steve + * Support behavioral subtraction. + * * Revision 1.22 2001/05/01 02:07:34 steve * Comparisons cant leave their results in the opcode * result area or their values will be clobbered by other diff --git a/vvp/codes.h b/vvp/codes.h index 4d1c9db20..0f313da65 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 */ #if !defined(WINNT) -#ident "$Id: codes.h,v 1.21 2001/05/01 01:09:39 steve Exp $" +#ident "$Id: codes.h,v 1.22 2001/05/02 01:57:25 steve Exp $" #endif @@ -65,6 +65,7 @@ extern bool of_NORR(vthread_t thr, vvp_code_t code); extern bool of_OR(vthread_t thr, vvp_code_t code); extern bool of_SET(vthread_t thr, vvp_code_t code); extern bool of_SET_MEM(vthread_t thr, vvp_code_t code); +extern bool of_SUB(vthread_t thr, vvp_code_t code); extern bool of_VPI_CALL(vthread_t thr, vvp_code_t code); extern bool of_WAIT(vthread_t thr, vvp_code_t code); extern bool of_XNOR(vthread_t thr, vvp_code_t code); @@ -125,6 +126,9 @@ extern void codespace_dump(FILE*fd); /* * $Log: codes.h,v $ + * Revision 1.22 2001/05/02 01:57:25 steve + * Support behavioral subtraction. + * * Revision 1.21 2001/05/01 01:09:39 steve * Add support for memory objects. (Stephan Boettcher) * diff --git a/vvp/compile.cc b/vvp/compile.cc index 144e2706c..cca204607 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 */ #if !defined(WINNT) -#ident "$Id: compile.cc,v 1.50 2001/05/01 05:00:02 steve Exp $" +#ident "$Id: compile.cc,v 1.51 2001/05/02 01:57:25 steve Exp $" #endif # include "compile.h" @@ -97,6 +97,7 @@ const static struct opcode_table_s opcode_table[] = { { "%or", of_OR, 3, {OA_BIT1, OA_BIT2, OA_NUMBER} }, { "%set", of_SET, 2, {OA_FUNC_PTR, OA_BIT1, OA_NONE} }, { "%set/m", of_SET_MEM,2, {OA_MEM_I1, OA_BIT1, OA_NONE} }, + { "%sub", of_SUB, 3, {OA_BIT1, OA_BIT2, OA_NUMBER} }, { "%wait", of_WAIT, 1, {OA_FUNC_PTR, OA_NONE, OA_NONE} }, { "%xnor", of_XNOR, 3, {OA_BIT1, OA_BIT2, OA_NUMBER} }, { "%xor", of_XOR, 3, {OA_BIT1, OA_BIT2, OA_NUMBER} }, @@ -1064,6 +1065,9 @@ void compile_dump(FILE*fd) /* * $Log: compile.cc,v $ + * Revision 1.51 2001/05/02 01:57:25 steve + * Support behavioral subtraction. + * * Revision 1.50 2001/05/01 05:00:02 steve * Implement %ix/load. * diff --git a/vvp/opcodes.txt b/vvp/opcodes.txt index d9e749a61..0d8dfb1be 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.15 2001/05/01 05:00:02 steve Exp $ + * $Id: opcodes.txt,v 1.16 2001/05/02 01:57:26 steve Exp $ */ @@ -20,6 +20,8 @@ vectors having the width . If any of the bits of either vector are x or z, the result is x. Otherwise, the result is the arithmetic sum. +See also the %sub instruction. + * %and , , Perform the bitwise AND of the two vectors, and store the result in @@ -208,6 +210,19 @@ value. Once the set completes, the value is immediately available to be read out of the variable. The is the address of the thread register that contains the bit value to assign. + +* %sub , , + +This instruction arithmetically subtracts the right vector out of the +left vector. It accomplishes this by adding to the left vector 1 plus +the 1s complement of the right vector. The carry value is dropped, and +the result, placed in , is the subtraction of from the +input . Both vectors have the same width. If any bits in either +operand are x, then the entire result is x. + +See also the %add instruction. + + * %vpi_call [, ...] This instruction makes a call to a system task or function that was diff --git a/vvp/vthread.cc b/vvp/vthread.cc index c79fb3db4..f1bcaa95a 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 */ #if !defined(WINNT) -#ident "$Id: vthread.cc,v 1.32 2001/05/02 01:37:38 steve Exp $" +#ident "$Id: vthread.cc,v 1.33 2001/05/02 01:57:26 steve Exp $" #endif # include "vthread.h" @@ -816,6 +816,46 @@ bool of_SET_MEM(vthread_t thr, vvp_code_t cp) return true; } +bool of_SUB(vthread_t thr, vvp_code_t cp) +{ + assert(cp->bit_idx1 >= 4); + assert(cp->number <= 8*sizeof(unsigned long)); + + unsigned idx1 = cp->bit_idx1; + unsigned idx2 = cp->bit_idx2; + unsigned long lv = 0, rv = 0; + + 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) & 2) + goto x_out; + + lv |= lb << idx; + rv |= rb << idx; + + idx1 += 1; + if (idx2 >= 4) + idx2 += 1; + } + + lv -= rv; + + for (unsigned idx = 0 ; idx < cp->number ; idx += 1) { + thr_put_bit(thr, cp->bit_idx1+idx, (lv&1) ? 1 : 0); + lv >>= 1; + } + + return true; + + x_out: + for (unsigned idx = 0 ; idx < cp->number ; idx += 1) + thr_put_bit(thr, cp->bit_idx1+idx, 2); + + return true; +} + bool of_VPI_CALL(vthread_t thr, vvp_code_t cp) { // printf("thread %p: %%vpi_call\n", thr); @@ -926,6 +966,9 @@ bool of_ZOMBIE(vthread_t thr, vvp_code_t) /* * $Log: vthread.cc,v $ + * Revision 1.33 2001/05/02 01:57:26 steve + * Support behavioral subtraction. + * * Revision 1.32 2001/05/02 01:37:38 steve * initialize is_schedule. *