From 29a50a52cae9cc15ebd323f14f7027efb1bec1e1 Mon Sep 17 00:00:00 2001 From: steve Date: Sun, 1 Apr 2001 04:34:28 +0000 Subject: [PATCH] Implement %cmp/x and %cmp/z instructions. --- vvp/codes.h | 7 ++++++- vvp/compile.cc | 7 ++++++- vvp/vthread.cc | 55 +++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 66 insertions(+), 3 deletions(-) diff --git a/vvp/codes.h b/vvp/codes.h index b84bedbec..bf37de492 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.10 2001/03/31 17:36:02 steve Exp $" +#ident "$Id: codes.h,v 1.11 2001/04/01 04:34:28 steve Exp $" #endif @@ -38,6 +38,8 @@ typedef bool (*vvp_code_fun)(vthread_t thr, vvp_code_t code); 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_CMPX(vthread_t thr, vvp_code_t code); +extern bool of_CMPZ(vthread_t thr, vvp_code_t code); extern bool of_DELAY(vthread_t thr, vvp_code_t code); extern bool of_END(vthread_t thr, vvp_code_t code); extern bool of_FORK(vthread_t thr, vvp_code_t code); @@ -97,6 +99,9 @@ extern void codespace_dump(FILE*fd); /* * $Log: codes.h,v $ + * Revision 1.11 2001/04/01 04:34:28 steve + * Implement %cmp/x and %cmp/z instructions. + * * Revision 1.10 2001/03/31 17:36:02 steve * Add the jmp/1 instruction. * diff --git a/vvp/compile.cc b/vvp/compile.cc index f2f0a7c77..f55c4e827 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.22 2001/03/31 19:00:43 steve Exp $" +#ident "$Id: compile.cc,v 1.23 2001/04/01 04:34:28 steve Exp $" #endif # include "compile.h" @@ -68,6 +68,8 @@ 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} }, + { "%cmp/x", of_CMPX, 3, {OA_BIT1, OA_BIT2, OA_NUMBER} }, + { "%cmp/z", of_CMPZ, 3, {OA_BIT1, OA_BIT2, OA_NUMBER} }, { "%delay", of_DELAY, 1, {OA_NUMBER, OA_NONE, OA_NONE} }, { "%end", of_END, 0, {OA_NONE, OA_NONE, OA_NONE} }, { "%fork", of_FORK, 1, {OA_CODE_PTR, OA_NONE, OA_NONE} }, @@ -692,6 +694,9 @@ void compile_dump(FILE*fd) /* * $Log: compile.cc,v $ + * Revision 1.23 2001/04/01 04:34:28 steve + * Implement %cmp/x and %cmp/z instructions. + * * Revision 1.22 2001/03/31 19:00:43 steve * Add VPI support for the simulation time. * diff --git a/vvp/vthread.cc b/vvp/vthread.cc index 3c5ccea24..9e96261f8 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.16 2001/03/31 17:36:02 steve Exp $" +#ident "$Id: vthread.cc,v 1.17 2001/04/01 04:34:28 steve Exp $" #endif # include "vthread.h" @@ -213,6 +213,56 @@ bool of_CMPU(vthread_t thr, vvp_code_t cp) return true; } +bool of_CMPX(vthread_t thr, vvp_code_t cp) +{ + unsigned eq = 1; + + unsigned idx1 = cp->bit_idx1; + unsigned idx2 = cp->bit_idx2; + + for (unsigned idx = 0 ; idx < cp->number ; idx += 1) { + unsigned lv = thr_get_bit(thr, idx1); + unsigned rv = thr_get_bit(thr, idx2); + + if ((lv < 2) && (rv < 2) && (lv != rv)) { + eq = 0; + break; + } + + if (idx1 >= 4) idx1 += 1; + if (idx2 >= 4) idx2 += 1; + } + + thr_put_bit(thr, 4, eq); + + return true; +} + +bool of_CMPZ(vthread_t thr, vvp_code_t cp) +{ + unsigned eq = 1; + + unsigned idx1 = cp->bit_idx1; + unsigned idx2 = cp->bit_idx2; + + for (unsigned idx = 0 ; idx < cp->number ; idx += 1) { + unsigned lv = thr_get_bit(thr, idx1); + unsigned rv = thr_get_bit(thr, idx2); + + if ((lv < 3) && (rv < 3) && (lv != rv)) { + eq = 0; + break; + } + + if (idx1 >= 4) idx1 += 1; + if (idx2 >= 4) idx2 += 1; + } + + thr_put_bit(thr, 4, eq); + + return true; +} + bool of_DELAY(vthread_t thr, vvp_code_t cp) { //printf("thread %p: %%delay %lu\n", thr, cp->number); @@ -362,6 +412,9 @@ bool of_WAIT(vthread_t thr, vvp_code_t cp) /* * $Log: vthread.cc,v $ + * Revision 1.17 2001/04/01 04:34:28 steve + * Implement %cmp/x and %cmp/z instructions. + * * Revision 1.16 2001/03/31 17:36:02 steve * Add the jmp/1 instruction. *