From efdc1769e63b369eedabe5a80e66bb56d02b1728 Mon Sep 17 00:00:00 2001 From: steve Date: Fri, 1 Oct 1999 15:26:28 +0000 Subject: [PATCH] Add some vvm operators from Eric Aardoom. --- README.txt | 2 ++ t-vvm.cc | 17 ++++++++++- vvm/vvm_func.h | 77 +++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 94 insertions(+), 2 deletions(-) diff --git a/README.txt b/README.txt index 14694d5dd..e23ba1964 100644 --- a/README.txt +++ b/README.txt @@ -307,8 +307,10 @@ Williams. The proper notices are in the head of each file. However, I have received aid in the form of fixes, Verilog guidance, and especially testing from many people, including (in alphabetical order): + Eric Aardoom Ed Carter Larry Doolittle + Guy Hutchison Ales Hvezda James Lee Peter Monta diff --git a/t-vvm.cc b/t-vvm.cc index 449693450..39ab3e1fb 100644 --- a/t-vvm.cc +++ b/t-vvm.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) -#ident "$Id: t-vvm.cc,v 1.55 1999/10/01 03:58:37 steve Exp $" +#ident "$Id: t-vvm.cc,v 1.56 1999/10/01 15:26:28 steve Exp $" #endif # include @@ -316,10 +316,22 @@ void vvm_proc_rval::expr_unary(const NetEUnary*expr) os_ << "vvm_unop_and(" << result << ");" << endl; break; + case '^': + os_ << "vvm_unop_xor(" << result << ");" + << endl; + break; case '!': os_ << "vvm_unop_lnot(" << result << ");" << endl; break; + case '-': + os_ << "vvm_unop_uminus(" << result << ");" + << endl; + break; + case 'X': + os_ << "vvm_unop_xnor(" << result << ");" + << endl; + break; default: cerr << "vvm: Unhandled unary op `" << expr->op() << "'" << endl; @@ -1669,6 +1681,9 @@ extern const struct target tgt_vvm = { }; /* * $Log: t-vvm.cc,v $ + * Revision 1.56 1999/10/01 15:26:28 steve + * Add some vvm operators from Eric Aardoom. + * * Revision 1.55 1999/10/01 03:58:37 steve * More resilient assignment to memory location. * diff --git a/vvm/vvm_func.h b/vvm/vvm_func.h index 699b38397..ebe669739 100644 --- a/vvm/vvm_func.h +++ b/vvm/vvm_func.h @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) -#ident "$Id: vvm_func.h,v 1.12 1999/09/29 22:57:26 steve Exp $" +#ident "$Id: vvm_func.h,v 1.13 1999/10/01 15:26:29 steve Exp $" #endif # include "vvm.h" @@ -85,6 +85,44 @@ vvm_bitset_t<1> vvm_unop_lnot(const vvm_bitset_t&r) return vvm_unop_not(res); } +/* + * The unary XOR is the reduction XOR. It returns a single bit. + */ +template +vvm_bitset_t<1> vvm_unop_xor(const vvm_bitset_t&r) +{ + vvm_bitset_t<1> res; + res[0] = V0; + + for (unsigned idx = 0 ; idx < WIDTH ; idx += 1) { + if (r[idx] == V1) + res[0] = not(res[0]); + } + + return res; +} + +template +vvm_bitset_t<1> vvm_unop_xnor(const vvm_bitset_t&r) +{ + return not(vvm_unop_xor(r)); +} + +// +// simple-minded unary minus operator (two's complement) +// +template +vvm_bitset_t vvm_unop_uminus(const vvm_bitset_t&l) +{ + vvm_bitset_t res; + res = vvm_unop_not(l); + vvm_bit_t carry = V1; + for (int i = 0; i < WIDTH; i++) + res[i] = add_with_carry(res[i], V0, carry); + + return res; +} + /* * Implement the binary AND operator. This is a bitwise and with all * the parameters and the result having the same width. @@ -165,6 +203,40 @@ vvm_bitset_t vvm_binop_xor(const vvm_bitset_t&l, return result; } +/* + * the binary 'l' operator is a logic left-shift by the number of positions + * indicated by argument r. r is an unsigned integer, which is represented + * internally as a 32-bit bitvector. + */ +template +vvm_bitset_t vvm_binop_shiftl(const vvm_bitset_t&l, + const vvm_bitset_t<32>&r) +{ + vvm_bitset_t result; + vvm_u32 s = r.as_unsigned(); + for (unsigned idx = 0; idx < WIDTH; idx++) + result[idx] = (idx < s) ? V0 : l[idx-s]; + + return result; +} + +/* + * The binary 'r' operator is a logic right-shift by the number of positions + * indicated by argument r. r is an unsigned integer, which is represented + * internally by a 32-bit bitvector. + */ +template +vvm_bitset_t vvm_binop_shiftr(const vvm_bitset_t&l, + const vvm_bitset_t<32>&r) +{ + vvm_bitset_t result; + vvm_u32 s = r.as_unsigned(); + for (unsigned idx = 0; idx < WIDTH; idx++) + result[idx] = (idx < (WIDTH-s)) ? l[idx+s] : V0; + + return result; +} + /* * Tests for equality are a bit tricky, as they allow for the left and * right subexpressions to have different size. The shorter bitset is @@ -529,6 +601,9 @@ vvm_bitset_t vvm_ternary(vvm_bit_t c, const vvm_bitset_t&t, /* * $Log: vvm_func.h,v $ + * Revision 1.13 1999/10/01 15:26:29 steve + * Add some vvm operators from Eric Aardoom. + * * Revision 1.12 1999/09/29 22:57:26 steve * LT supports different width objects. *