From 4a058632b286c1df606c7acf426fc993c98ea077 Mon Sep 17 00:00:00 2001 From: steve Date: Sat, 31 Mar 2001 01:59:58 +0000 Subject: [PATCH] Add the ADD instrunction. --- vvp/codes.h | 6 +++++- vvp/compile.cc | 6 +++++- vvp/opcodes.txt | 8 +++++++- vvp/vthread.cc | 45 ++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 61 insertions(+), 4 deletions(-) diff --git a/vvp/codes.h b/vvp/codes.h index 3fd3508a6..d204223de 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.8 2001/03/30 04:55:22 steve Exp $" +#ident "$Id: codes.h,v 1.9 2001/03/31 01:59:58 steve Exp $" #endif @@ -35,6 +35,7 @@ typedef bool (*vvp_code_fun)(vthread_t thr, vvp_code_t code); * implementation lives in the vthread.cc file so that they have * access to the thread context. */ +extern bool of_ADD(vthread_t thr, vvp_code_t code); extern bool of_ASSIGN(vthread_t thr, vvp_code_t code); extern bool of_CMPU(vthread_t thr, vvp_code_t code); extern bool of_DELAY(vthread_t thr, vvp_code_t code); @@ -95,6 +96,9 @@ extern void codespace_dump(FILE*fd); /* * $Log: codes.h,v $ + * Revision 1.9 2001/03/31 01:59:58 steve + * Add the ADD instrunction. + * * Revision 1.8 2001/03/30 04:55:22 steve * Add fork and join instructions. * diff --git a/vvp/compile.cc b/vvp/compile.cc index ec055ffc3..64b62ea82 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.19 2001/03/30 04:55:22 steve Exp $" +#ident "$Id: compile.cc,v 1.20 2001/03/31 01:59:59 steve Exp $" #endif # include "compile.h" @@ -65,6 +65,7 @@ struct opcode_table_s { }; const static struct opcode_table_s opcode_table[] = { + { "%add", of_ADD, 3, {OA_BIT1, OA_BIT2, OA_NUMBER} }, { "%assign", of_ASSIGN, 3, {OA_FUNC_PTR, OA_BIT1, OA_BIT2} }, { "%cmp/u", of_CMPU, 3, {OA_BIT1, OA_BIT2, OA_NUMBER} }, { "%delay", of_DELAY, 1, {OA_NUMBER, OA_NONE, OA_NONE} }, @@ -687,6 +688,9 @@ void compile_dump(FILE*fd) /* * $Log: compile.cc,v $ + * Revision 1.20 2001/03/31 01:59:59 steve + * Add the ADD instrunction. + * * Revision 1.19 2001/03/30 04:55:22 steve * Add fork and join instructions. * diff --git a/vvp/opcodes.txt b/vvp/opcodes.txt index 7635a22e3..832668f4d 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.7 2001/03/30 04:55:22 steve Exp $ + * $Id: opcodes.txt,v 1.8 2001/03/31 01:59:59 steve Exp $ */ @@ -13,6 +13,12 @@ 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. +* %add , , + +This instruction adds the right vector into the left vector, the +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. * %assign , , diff --git a/vvp/vthread.cc b/vvp/vthread.cc index 83c1af2db..28af58d24 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.14 2001/03/30 04:55:22 steve Exp $" +#ident "$Id: vthread.cc,v 1.15 2001/03/31 01:59:59 steve Exp $" #endif # include "vthread.h" @@ -131,6 +131,46 @@ void vthread_schedule_list(vthread_t thr) } } +bool of_ADD(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_ASSIGN(vthread_t thr, vvp_code_t cp) { unsigned char bit_val = thr_get_bit(thr, cp->bit_idx2); @@ -315,6 +355,9 @@ bool of_WAIT(vthread_t thr, vvp_code_t cp) /* * $Log: vthread.cc,v $ + * Revision 1.15 2001/03/31 01:59:59 steve + * Add the ADD instrunction. + * * Revision 1.14 2001/03/30 04:55:22 steve * Add fork and join instructions. *