From edc40f1792429dcbd33b7f909f3582cab513f684 Mon Sep 17 00:00:00 2001 From: steve Date: Fri, 24 Mar 2000 02:43:36 +0000 Subject: [PATCH] vvm_unop and vvm_binop pass result by reference instead of returning a value. --- t-vvm.cc | 70 ++++++++++++--------- vvm/vvm_func.cc | 100 +++++++++++++++--------------- vvm/vvm_func.h | 154 +++++++++++++++++++++-------------------------- vvm/vvm_signal.h | 13 ++-- 4 files changed, 170 insertions(+), 167 deletions(-) diff --git a/t-vvm.cc b/t-vvm.cc index 9b02cff26..e21e8b838 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) && !defined(macintosh) -#ident "$Id: t-vvm.cc,v 1.121 2000/03/23 03:24:39 steve Exp $" +#ident "$Id: t-vvm.cc,v 1.122 2000/03/24 02:43:36 steve Exp $" #endif # include @@ -305,8 +305,8 @@ void vvm_proc_rval::expr_ternary(const NetETernary*expr) os_ << setw(indent_) << "" << "vvm_bitset_t<" << expr->expr_width() << ">" << result << ";" << endl; - os_ << setw(indent_) << "" << result << " = vvm_ternary(" << - cond_val << "[0], " << true_val << ", " << false_val << ");" + os_ << setw(indent_) << "" << "vvm_ternary(" << result << ", " + << cond_val << "[0], " << true_val << ", " << false_val << ");" << endl; } @@ -350,31 +350,38 @@ void vvm_proc_rval::expr_unary(const NetEUnary*expr) string tname = make_temp(); os_ << " vvm_bitset_t<" << expr->expr_width() << "> " - << tname << " = "; + << tname << ";" << endl; + switch (expr->op()) { case '~': - os_ << "vvm_unop_not(" << result << ");" << endl; + os_ << "vvm_unop_not(" << tname << "," << result << ");" << endl; break; case '&': - os_ << "vvm_unop_and(" << result << ");" << endl; + os_ << " " << tname << "[0] " + "= vvm_unop_and("<op() << "'" @@ -419,8 +426,8 @@ void vvm_proc_rval::expr_binary(const NetEBinary*expr) << lres << "," << rres << ");" << endl; break; case 'l': // left shift(<<) - os_ << setw(indent_) << "" << result << " = vvm_binop_shiftl(" - << lres << "," << rres << ");" << endl; + os_ << setw(indent_) << "" << "vvm_binop_shiftl(" << result + << ", " << lres << "," << rres << ");" << endl; break; case 'L': // <= os_ << setw(indent_) << "" << result << " = vvm_binop_le(" @@ -447,32 +454,32 @@ void vvm_proc_rval::expr_binary(const NetEBinary*expr) << lres << "," << rres << ");" << endl; break; case 'r': // right shift(>>) - os_ << setw(indent_) << "" << result << " = vvm_binop_shiftr(" - << lres << "," << rres << ");" << endl; + os_ << setw(indent_) << "" << "vvm_binop_shiftr(" << result + << ", " << lres << "," << rres << ");" << endl; break; case 'X': - os_ << setw(indent_) << "" << result << " = vvm_binop_xnor(" - << lres << "," << rres << ");" << endl; + os_ << setw(indent_) << "" << "vvm_binop_xnor(" << result + << ", " << lres << "," << rres << ");" << endl; break; case '+': - os_ << setw(indent_) << "" << result << " = vvm_binop_plus(" - << lres << "," << rres << ");" << endl; + os_ << setw(indent_) << "" << "vvm_binop_plus(" << result + << ", " << lres << "," << rres << ");" << endl; break; case '-': - os_ << setw(indent_) << "" << result << " = vvm_binop_minus(" - << lres << "," << rres << ");" << endl; + os_ << setw(indent_) << "" << "vvm_binop_minus(" << result + << ", " << lres << "," << rres << ");" << endl; break; case '&': - os_ << setw(indent_) << "" << result << " = vvm_binop_and(" - << lres << "," << rres << ");" << endl; + os_ << setw(indent_) << "" << "vvm_binop_and(" << result + << ", " << lres << ", " << rres << ");" << endl; break; case '|': - os_ << setw(indent_) << "" << result << " = vvm_binop_or(" - << lres << "," << rres << ");" << endl; + os_ << setw(indent_) << "" << "vvm_binop_or(" << result + << ", " << lres << ", " << rres << ");" << endl; break; case '^': - os_ << setw(indent_) << "" << result << " = vvm_binop_xor(" - << lres << "," << rres << ");" << endl; + os_ << setw(indent_) << "" << "vvm_binop_xor(" << result + << ", " << lres << ", " << rres << ");" << endl; break; case '*': os_ << setw(indent_) << "" << "vvm_binop_mult(" << result @@ -926,6 +933,9 @@ string target_vvm::defn_gate_outputfun_(ostream&os, const NetNode*gate, unsigned gpin) { + cerr << "internal error: outputfun_ called for gate " << + gate->name() << " (" << typeid(*gate).name() << ")" << + endl; assert(0); return ""; } @@ -2307,6 +2317,10 @@ extern const struct target tgt_vvm = { }; /* * $Log: t-vvm.cc,v $ + * Revision 1.122 2000/03/24 02:43:36 steve + * vvm_unop and vvm_binop pass result by reference + * instead of returning a value. + * * Revision 1.121 2000/03/23 03:24:39 steve * Do not create 0 length parameters to system tasks. * diff --git a/vvm/vvm_func.cc b/vvm/vvm_func.cc index d1f8561c0..d7fc9975d 100644 --- a/vvm/vvm_func.cc +++ b/vvm/vvm_func.cc @@ -17,68 +17,64 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) && !defined(macintosh) -#ident "$Id: vvm_func.cc,v 1.2 2000/03/22 04:26:41 steve Exp $" +#ident "$Id: vvm_func.cc,v 1.3 2000/03/24 02:43:37 steve Exp $" #endif # include "vvm_func.h" -vvm_bitset_t<1> vvm_unop_and(const vvm_bits_t&r) +vpip_bit_t vvm_unop_and(const vvm_bits_t&r) { - vvm_bitset_t<1> res; - res[0] = r.get_bit(0); + vpip_bit_t v = r.get_bit(0); for (unsigned idx = 1 ; idx < r.get_width() ; idx += 1) - res[0] = B_AND(res[0], r.get_bit(idx)); + v = B_AND(v, r.get_bit(idx)); - return res; + return v; } -vvm_bitset_t<1> vvm_unop_nand(const vvm_bits_t&r) +vpip_bit_t vvm_unop_nand(const vvm_bits_t&r) { - vvm_bitset_t<1>res = vvm_unop_and(r); - res[0] = B_NOT(res[0]); - return res; + vpip_bit_t v = vvm_unop_and(r); + return B_NOT(v); } -vvm_bitset_t<1> vvm_unop_or(const vvm_bits_t&r) +vpip_bit_t vvm_unop_lnot(const vvm_bits_t&r) { - vvm_bitset_t<1> res; - res[0] = St1; + vpip_bit_t v = vvm_unop_or(r); + return B_NOT(v); +} + +vpip_bit_t vvm_unop_or(const vvm_bits_t&r) +{ + for (unsigned idx = 0 ; idx < r.get_width() ; idx += 1) { + if (B_IS1(r.get_bit(idx))) + return St1; + } + + return St0; +} + +vpip_bit_t vvm_unop_nor(const vvm_bits_t&r) +{ + vpip_bit_t v = vvm_unop_or(r); + return B_NOT(v); +} + +vpip_bit_t vvm_unop_xor(const vvm_bits_t&r) +{ + vpip_bit_t v = St0; for (unsigned idx = 0 ; idx < r.get_width() ; idx += 1) { if (B_IS1(r.get_bit(idx))) - return res; + v = B_NOT(v); } - - res[0] = St0; - return res; + return v; } -vvm_bitset_t<1> vvm_unop_nor(const vvm_bits_t&r) +vpip_bit_t vvm_unop_xnor(const vvm_bits_t&r) { - vvm_bitset_t<1>res = vvm_unop_or(r); - res[0] = B_NOT(res[0]); - return res; -} - -vvm_bitset_t<1> vvm_unop_xor(const vvm_bits_t&r) -{ - vvm_bitset_t<1> res; - res[0] = St0; - - for (unsigned idx = 0 ; idx < r.get_width() ; idx += 1) { - if (B_IS1(r.get_bit(idx))) - res[0] = B_NOT(res[0]); - } - - return res; -} - -vvm_bitset_t<1> vvm_unop_xnor(const vvm_bits_t&r) -{ - vvm_bitset_t<1>res = vvm_unop_xor(r); - res[0] = B_NOT(res[0]); - return res; + vpip_bit_t v = vvm_unop_xor(r); + return B_NOT(v); } vvm_bitset_t<1> vvm_binop_eq(const vvm_bits_t&l, const vvm_bits_t&r) @@ -420,29 +416,31 @@ vvm_bitset_t<1> vvm_binop_ge(const vvm_bits_t&l, const vvm_bits_t&r) vvm_bitset_t<1> vvm_binop_land(const vvm_bits_t&l, const vvm_bits_t&r) { - vvm_bitset_t<1> res1 = vvm_unop_or(l); - vvm_bitset_t<1> res2 = vvm_unop_or(r); + vvm_bitset_t<1> res1; + res1[0] = vvm_unop_or(l); + vvm_bitset_t<1> res2; + res2[0] = vvm_unop_or(r); res1[0] = B_AND(res1[0], res2[0]); return res1; } vvm_bitset_t<1> vvm_binop_lor(const vvm_bits_t&l, const vvm_bits_t&r) { - vvm_bitset_t<1> res1 = vvm_unop_or(l); - vvm_bitset_t<1> res2 = vvm_unop_or(r); + vvm_bitset_t<1> res1; + res1[0] = vvm_unop_or(l); + vvm_bitset_t<1> res2; + res2[0] = vvm_unop_or(r); res1[0] = B_OR(res1[0], res2[0]); return res1; } -vvm_bitset_t<1> vvm_unop_lnot(const vvm_bits_t&r) -{ - vvm_bitset_t<1> res = vvm_unop_or(r); - return vvm_unop_not(res); -} - /* * $Log: vvm_func.cc,v $ + * Revision 1.3 2000/03/24 02:43:37 steve + * vvm_unop and vvm_binop pass result by reference + * instead of returning a value. + * * Revision 1.2 2000/03/22 04:26:41 steve * Replace the vpip_bit_t with a typedef and * define values for all the different bit diff --git a/vvm/vvm_func.h b/vvm/vvm_func.h index 11afab0d1..40b460329 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) && !defined(macintosh) -#ident "$Id: vvm_func.h,v 1.23 2000/03/22 04:26:41 steve Exp $" +#ident "$Id: vvm_func.h,v 1.24 2000/03/24 02:43:37 steve Exp $" #endif # include "vvm.h" @@ -30,47 +30,44 @@ * vector of a certain width and returns a result of the same width. */ template -vvm_bitset_t vvm_unop_not(const vvm_bitset_t&p) +void vvm_unop_not(vvm_bitset_t&v, const vvm_bitset_t&p) { - vvm_bitset_t result; for (unsigned idx = 0 ; idx < WIDTH ; idx += 1) - result[idx] = B_NOT(p[idx]); - - return result; + v[idx] = B_NOT(p[idx]); } /* * The unary AND is the reduction AND. It returns a single bit. */ -extern vvm_bitset_t<1> vvm_unop_and(const vvm_bits_t&r); -extern vvm_bitset_t<1> vvm_unop_nand(const vvm_bits_t&r); +extern vpip_bit_t vvm_unop_and(const vvm_bits_t&r); +extern vpip_bit_t vvm_unop_nand(const vvm_bits_t&r); + +extern vpip_bit_t vvm_unop_lnot(const vvm_bits_t&r); /* * The unary OR is the reduction OR. It returns a single bit. */ -extern vvm_bitset_t<1> vvm_unop_or(const vvm_bits_t&r); -extern vvm_bitset_t<1> vvm_unop_nor(const vvm_bits_t&r); +extern vpip_bit_t vvm_unop_or(const vvm_bits_t&r); +extern vpip_bit_t vvm_unop_nor(const vvm_bits_t&r); /* * The unary XOR is the reduction XOR. It returns a single bit. */ -extern vvm_bitset_t<1> vvm_unop_xor(const vvm_bits_t&r); -extern vvm_bitset_t<1> vvm_unop_xnor(const vvm_bits_t&r); +extern vpip_bit_t vvm_unop_xor(const vvm_bits_t&r); +extern vpip_bit_t vvm_unop_xnor(const vvm_bits_t&r); // // simple-minded unary minus operator (two's complement) // template -vvm_bitset_t vvm_unop_uminus(const vvm_bitset_t&l) +void vvm_unop_uminus(vvm_bitset_t&v, const vvm_bitset_t&l) { - vvm_bitset_t res; - res = vvm_unop_not(l); + vvm_unop_not(v, l); vpip_bit_t carry = St1; for (int i = 0; i < WIDTH; i++) - res[i] = add_with_carry(res[i], St0, carry); + v[i] = add_with_carry(v[i], St0, carry); - return res; } /* @@ -78,14 +75,12 @@ vvm_bitset_t vvm_unop_uminus(const vvm_bitset_t&l) * the parameters and the result having the same width. */ template -vvm_bitset_t vvm_binop_and(const vvm_bitset_t&l, - const vvm_bitset_t&r) +void vvm_binop_and(vvm_bitset_t&v, + const vvm_bitset_t&l, + const vvm_bitset_t&r) { - vvm_bitset_t result; for (unsigned idx = 0 ; idx < WIDTH ; idx += 1) - result[idx] = B_AND(l[idx], r[idx]); - - return result; + v[idx] = B_AND(l[idx], r[idx]); } /* @@ -93,25 +88,21 @@ vvm_bitset_t vvm_binop_and(const vvm_bitset_t&l, * the parameters and the result having the same width. */ template -vvm_bitset_t vvm_binop_or(const vvm_bitset_t&l, - const vvm_bitset_t&r) +void vvm_binop_or(vvm_bitset_t&v, + const vvm_bitset_t&l, + const vvm_bitset_t&r) { - vvm_bitset_t result; for (unsigned idx = 0 ; idx < WIDTH ; idx += 1) - result[idx] = B_OR(l[idx], r[idx]); - - return result; + v[idx] = B_OR(l[idx], r[idx]); } template -vvm_bitset_t vvm_binop_nor(const vvm_bitset_t&l, - const vvm_bitset_t&r) +void vvm_binop_nor(vvm_bitset_t&v, + const vvm_bitset_t&l, + const vvm_bitset_t&r) { - vvm_bitset_t result; for (unsigned idx = 0 ; idx < WIDTH ; idx += 1) - result[idx] = B_NOT(B_OR(l[idx], r[idx])); - - return result; + v[idx] = B_NOT(B_OR(l[idx], r[idx])); } /* @@ -120,15 +111,13 @@ vvm_bitset_t vvm_binop_nor(const vvm_bitset_t&l, * that contains the arithmetic sum. Z values are converted to X. */ template -vvm_bitset_t vvm_binop_plus(const vvm_bitset_t&l, - const vvm_bitset_t&r) +void vvm_binop_plus(vvm_bitset_t&v, + const vvm_bitset_t&l, + const vvm_bitset_t&r) { - vvm_bitset_t result; vpip_bit_t carry = St0; for (unsigned idx = 0 ; idx < WIDTH ; idx += 1) - result[idx] = add_with_carry(l[idx], r[idx], carry); - - return result; + v[idx] = add_with_carry(l[idx], r[idx], carry); } /* @@ -137,16 +126,14 @@ vvm_bitset_t vvm_binop_plus(const vvm_bitset_t&l, * carry of 1 to the 0 bit position. */ template -vvm_bitset_t vvm_binop_minus(const vvm_bitset_t&l, - const vvm_bitset_t&r) +void vvm_binop_minus(vvm_bitset_t&v, + const vvm_bitset_t&l, + const vvm_bitset_t&r) { - vvm_bitset_t res; - res = vvm_unop_not(r); + vvm_unop_not(v, r); vpip_bit_t carry = St1; for (unsigned idx = 0 ; idx < WIDTH ; idx += 1) - res[idx] = add_with_carry(l[idx], res[idx], carry); - - return res; + v[idx] = add_with_carry(l[idx], v[idx], carry); } /* @@ -172,25 +159,21 @@ void vvm_binop_mult(vvm_bitset_t&r, * to generate the corresponsing output. */ template -vvm_bitset_t vvm_binop_xor(const vvm_bitset_t&l, - const vvm_bitset_t&r) +void vvm_binop_xor(vvm_bitset_t&v, + const vvm_bitset_t&l, + const vvm_bitset_t&r) { - vvm_bitset_t result; for (unsigned idx = 0 ; idx < WIDTH ; idx += 1) - result[idx] = B_XOR(l[idx], r[idx]); - - return result; + v[idx] = B_XOR(l[idx], r[idx]); } template -vvm_bitset_t vvm_binop_xnor(const vvm_bitset_t&l, - const vvm_bitset_t&r) +void vvm_binop_xnor(vvm_bitset_t&v, + const vvm_bitset_t&l, + const vvm_bitset_t&r) { - vvm_bitset_t result; for (unsigned idx = 0 ; idx < WIDTH ; idx += 1) - result[idx] = B_NOT(B_XOR(l[idx], r[idx])); - - return result; + v[idx] = B_NOT(B_XOR(l[idx], r[idx])); } /* @@ -199,15 +182,13 @@ vvm_bitset_t vvm_binop_xnor(const vvm_bitset_t&l, * internally as a 32-bit bitvector. */ template -vvm_bitset_t vvm_binop_shiftl(const vvm_bitset_t&l, - const vvm_bits_t&r) +void vvm_binop_shiftl(vvm_bitset_t&v, + const vvm_bitset_t&l, + const vvm_bits_t&r) { - vvm_bitset_t result; vvm_u32 s = r.as_unsigned(); for (unsigned idx = 0; idx < WIDTH; idx++) - result[idx] = (idx < s) ? St0 : l[idx-s]; - - return result; + v[idx] = (idx < s) ? St0 : l[idx-s]; } /* @@ -216,15 +197,13 @@ vvm_bitset_t vvm_binop_shiftl(const vvm_bitset_t&l, * internally by a 32-bit bitvector. */ template -vvm_bitset_t vvm_binop_shiftr(const vvm_bitset_t&l, - const vvm_bits_t&r) +void vvm_binop_shiftr(vvm_bitset_t&v, + const vvm_bitset_t&l, + const vvm_bits_t&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] : St0; - - return result; + v[idx] = (idx < (WIDTH-s)) ? l[idx+s] : St0; } /* @@ -273,29 +252,36 @@ extern vvm_bitset_t<1> vvm_binop_land(const vvm_bits_t&l, const vvm_bits_t&r); extern vvm_bitset_t<1> vvm_binop_lor(const vvm_bits_t&l, const vvm_bits_t&r); -extern vvm_bitset_t<1> vvm_unop_lnot(const vvm_bits_t&r); - template -vvm_bitset_t vvm_ternary(vpip_bit_t c, const vvm_bitset_t&t, - const vvm_bitset_t&f) +void vvm_ternary(vvm_bitset_t&v, vpip_bit_t c, + const vvm_bitset_t&t, + const vvm_bitset_t&f) { - if (B_IS0(c)) - return f; - if (B_IS1(c)) - return t; + if (B_IS0(c)) { + for (unsigned idx = 0 ; idx < W ; idx += 1) + v[idx] = f[idx]; + return; + } + if (B_IS1(c)) { + for (unsigned idx = 0 ; idx < W ; idx += 1) + v[idx] = t[idx]; + return; + } - vvm_bitset_t res; for (unsigned idx = 0 ; idx < W ; idx += 1) { if (B_EQ(t[idx], f[idx])) - res[idx] = t[idx]; + v[idx] = t[idx]; else - res[idx] = StX; + v[idx] = StX; } - return res; } /* * $Log: vvm_func.h,v $ + * Revision 1.24 2000/03/24 02:43:37 steve + * vvm_unop and vvm_binop pass result by reference + * instead of returning a value. + * * Revision 1.23 2000/03/22 04:26:41 steve * Replace the vpip_bit_t with a typedef and * define values for all the different bit diff --git a/vvm/vvm_signal.h b/vvm/vvm_signal.h index 2564a9a7c..60d63e114 100644 --- a/vvm/vvm_signal.h +++ b/vvm/vvm_signal.h @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) && !defined(macintosh) -#ident "$Id: vvm_signal.h,v 1.3 2000/03/22 04:26:41 steve Exp $" +#ident "$Id: vvm_signal.h,v 1.4 2000/03/24 02:43:37 steve Exp $" #endif # include "vvm.h" @@ -38,7 +38,7 @@ template class vvm_bitset_t : public vvm_bits_t { { for (unsigned idx = 0 ; idx < WIDTH ; idx += 1) bits[idx] = HiZ; } - +#if 0 vvm_bitset_t(const vvm_bits_t&that) { unsigned wid = WIDTH; if (that.get_width() < WIDTH) @@ -48,12 +48,13 @@ template class vvm_bitset_t : public vvm_bits_t { for (unsigned idx = wid ; idx < WIDTH ; idx += 1) bits[idx] = St0; } - - +#endif +#if 0 vvm_bitset_t(const vvm_bitset_t&that) { for (unsigned idx = 0; idx < WIDTH; idx += 1) bits[idx] = that.bits[idx]; } +#endif vpip_bit_t operator[] (unsigned idx) const { return bits[idx]; } vpip_bit_t&operator[] (unsigned idx) { return bits[idx]; } @@ -155,6 +156,10 @@ class vvm_memory_t : public __vpiMemory { /* * $Log: vvm_signal.h,v $ + * Revision 1.4 2000/03/24 02:43:37 steve + * vvm_unop and vvm_binop pass result by reference + * instead of returning a value. + * * Revision 1.3 2000/03/22 04:26:41 steve * Replace the vpip_bit_t with a typedef and * define values for all the different bit