From 39ffe91230d5be2172716ba3905dfc5efe95d95d Mon Sep 17 00:00:00 2001 From: steve Date: Thu, 24 May 2001 04:20:10 +0000 Subject: [PATCH] Add behavioral modulus. --- tgt-vvp/eval_expr.c | 28 ++++++++++++++++++++++------ vvp/codes.h | 6 +++++- vvp/compile.cc | 6 +++++- vvp/opcodes.txt | 18 +++++++++++++++++- vvp/vthread.cc | 45 ++++++++++++++++++++++++++++++++++++++++++++- 5 files changed, 93 insertions(+), 10 deletions(-) diff --git a/tgt-vvp/eval_expr.c b/tgt-vvp/eval_expr.c index d0f1ec90e..3583c464c 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.28 2001/05/20 01:18:38 steve Exp $" +#ident "$Id: eval_expr.c,v 1.29 2001/05/24 04:20:10 steve Exp $" #endif # include "vvp_priv.h" @@ -510,7 +510,7 @@ static struct vector_info draw_binary_expr_rs(ivl_expr_t exp, unsigned wid) } } -static struct vector_info draw_binary_expr_plus(ivl_expr_t exp, unsigned wid) +static struct vector_info draw_binary_expr_arith(ivl_expr_t exp, unsigned wid) { ivl_expr_t le = ivl_expr_oper1(exp); ivl_expr_t re = ivl_expr_oper2(exp); @@ -524,10 +524,22 @@ 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); - if (ivl_expr_opcode(exp) == '-') - fprintf(vvp_out, " %%sub %u, %u, %u;\n", lv.base, rv.base, wid); - else + switch (ivl_expr_opcode(exp)) { + case '+': fprintf(vvp_out, " %%add %u, %u, %u;\n", lv.base, rv.base, wid); + break; + + case '-': + fprintf(vvp_out, " %%sub %u, %u, %u;\n", lv.base, rv.base, wid); + break; + + case '%': + fprintf(vvp_out, " %%mod %u, %u, %u;\n", lv.base, rv.base, wid); + break; + + default: + assert(0); + } clr_vector(rv); @@ -560,7 +572,8 @@ static struct vector_info draw_binary_expr(ivl_expr_t exp, unsigned wid) case '+': case '-': - rv = draw_binary_expr_plus(exp, wid); + case '%': + rv = draw_binary_expr_arith(exp, wid); break; case 'l': /* << */ @@ -1030,6 +1043,9 @@ struct vector_info draw_eval_expr(ivl_expr_t exp) /* * $Log: eval_expr.c,v $ + * Revision 1.29 2001/05/24 04:20:10 steve + * Add behavioral modulus. + * * Revision 1.28 2001/05/20 01:18:38 steve * Implement reduction nor. * diff --git a/vvp/codes.h b/vvp/codes.h index 08309b33e..ca9fb34bf 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.26 2001/05/09 04:23:18 steve Exp $" +#ident "$Id: codes.h,v 1.27 2001/05/24 04:20:10 steve Exp $" #endif @@ -61,6 +61,7 @@ extern bool of_JMP1(vthread_t thr, vvp_code_t code); extern bool of_JOIN(vthread_t thr, vvp_code_t code); extern bool of_LOAD(vthread_t thr, vvp_code_t code); extern bool of_LOAD_MEM(vthread_t thr, vvp_code_t code); +extern bool of_MOD(vthread_t thr, vvp_code_t code); extern bool of_MOV(vthread_t thr, vvp_code_t code); extern bool of_NOOP(vthread_t thr, vvp_code_t code); extern bool of_NORR(vthread_t thr, vvp_code_t code); @@ -127,6 +128,9 @@ extern vvp_code_t codespace_index(vvp_cpoint_t ptr); /* * $Log: codes.h,v $ + * Revision 1.27 2001/05/24 04:20:10 steve + * Add behavioral modulus. + * * Revision 1.26 2001/05/09 04:23:18 steve * Now that the interactive debugger exists, * there is no use for the output dump. diff --git a/vvp/compile.cc b/vvp/compile.cc index bb547cc3a..91f5ab953 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.67 2001/05/22 04:08:16 steve Exp $" +#ident "$Id: compile.cc,v 1.68 2001/05/24 04:20:10 steve Exp $" #endif # include "compile.h" @@ -98,6 +98,7 @@ const static struct opcode_table_s opcode_table[] = { { "%join", of_JOIN, 0, {OA_NONE, OA_NONE, OA_NONE} }, { "%load", of_LOAD, 2, {OA_BIT1, OA_FUNC_PTR, OA_NONE} }, { "%load/m", of_LOAD_MEM,2, {OA_BIT1, OA_MEM_PTR, OA_NONE} }, + { "%mod", of_MOD, 3, {OA_BIT1, OA_BIT2, OA_NUMBER} }, { "%mov", of_MOV, 3, {OA_BIT1, OA_BIT2, OA_NUMBER} }, { "%noop", of_NOOP, 0, {OA_NONE, OA_NONE, OA_NONE} }, { "%nor/r", of_NORR, 3, {OA_BIT1, OA_BIT2, OA_NUMBER} }, @@ -1206,6 +1207,9 @@ vvp_ipoint_t debug_lookup_functor(const char*name) /* * $Log: compile.cc,v $ + * Revision 1.68 2001/05/24 04:20:10 steve + * Add behavioral modulus. + * * Revision 1.67 2001/05/22 04:08:16 steve * Get the initial inputs to functors set at xxxx. * diff --git a/vvp/opcodes.txt b/vvp/opcodes.txt index 535bf4d94..f27886f51 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.21 2001/05/20 00:46:12 steve Exp $ + * $Id: opcodes.txt,v 1.22 2001/05/24 04:20:10 steve Exp $ */ @@ -13,6 +13,14 @@ operands. In no case are there more then 3 operands. This chapter describes the specific behavior of each opcode, in hopefully enough detail that its complete effect can be predicted. +General principles of Arithmetic: + +The binary arithmetic instruction in general take three parameters, +the left operand, the right operand, and the base. The left operand is +replaced with the result, which is the same width as the left and +right operands. + + * %add , , This instruction adds the right vector into the left vector, the @@ -219,6 +227,14 @@ Bit address zero is the LSB of the first memory word. This instruction loads only a single bit. +* %mod , , + + +This instruction calculates the modulus %r of the left operand, and +replaces the left operand with the result. The gives the width +of the left and the right vectors, and the left vector is completely +replaced with the result. + * %mov , , This instruction copies a vector from one place in register space to diff --git a/vvp/vthread.cc b/vvp/vthread.cc index f18a688d4..9a4daa4d7 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.40 2001/05/20 00:56:48 steve Exp $" +#ident "$Id: vthread.cc,v 1.41 2001/05/24 04:20:10 steve Exp $" #endif # include "vthread.h" @@ -760,6 +760,46 @@ bool of_LOAD_MEM(vthread_t thr, vvp_code_t cp) return true; } +bool of_MOD(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_MOV(vthread_t thr, vvp_code_t cp) { assert(cp->bit_idx1 >= 4); @@ -1005,6 +1045,9 @@ bool of_ZOMBIE(vthread_t thr, vvp_code_t) /* * $Log: vthread.cc,v $ + * Revision 1.41 2001/05/24 04:20:10 steve + * Add behavioral modulus. + * * Revision 1.40 2001/05/20 00:56:48 steve * Make vthread_put_but expand the space if needed. *