From b2f7d09f0de1696dc078e172cc0af65e11deb4a4 Mon Sep 17 00:00:00 2001 From: Martin Whitaker Date: Mon, 4 Apr 2016 22:29:54 +0100 Subject: [PATCH] Fix GitHub issue #99 - recv_vec4_pv not implemented for arithmetic functors. Also initialise the stored operand values to 'bz instead of 'bx to get the correct results when bits are not driven. --- vvp/arith.cc | 42 ++++++++++++++++++++++++++++++++++++------ vvp/arith.h | 6 +++++- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/vvp/arith.cc b/vvp/arith.cc index 7fe9ebcef..1377d1623 100644 --- a/vvp/arith.cc +++ b/vvp/arith.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001-2013 Stephen Williams (steve@icarus.com) + * Copyright (c) 2001-2016 Stephen Williams (steve@icarus.com) * * This source code is free software; you can redistribute it * and/or modify it in source code form under the terms of the GNU @@ -26,13 +26,13 @@ # include vvp_arith_::vvp_arith_(unsigned wid) -: wid_(wid), x_val_(wid) +: wid_(wid), op_a_(wid), op_b_(wid), x_val_(wid) { - for (unsigned idx = 0 ; idx < wid ; idx += 1) + for (unsigned idx = 0 ; idx < wid ; idx += 1) { + op_a_ .set_bit(idx, BIT4_Z); + op_b_ .set_bit(idx, BIT4_Z); x_val_.set_bit(idx, BIT4_X); - - op_a_ = x_val_; - op_b_ = x_val_; + } } void vvp_arith_::dispatch_operand_(vvp_net_ptr_t ptr, vvp_vector4_t bit) @@ -51,6 +51,36 @@ void vvp_arith_::dispatch_operand_(vvp_net_ptr_t ptr, vvp_vector4_t bit) } } +void vvp_arith_::recv_vec4_pv(vvp_net_ptr_t ptr, const vvp_vector4_t&bit, + unsigned base, unsigned wid, unsigned vwid, + vvp_context_t) +{ + unsigned port = ptr.port(); + + assert(bit.size() == wid); + assert(base + wid <= vwid); + + vvp_vector4_t tmp; + switch (port) { + case 0: + tmp = op_a_; + break; + case 1: + tmp = op_b_; + break; + default: + fprintf(stderr, "Unsupported port type %u.\n", port); + assert(0); + } + + // Set the part for the input. If nothing changes, then break. + bool flag = tmp.set_vec(base, bit); + if (flag == false) + return; + + recv_vec4(ptr, tmp, 0); +} + vvp_arith_abs::vvp_arith_abs() { diff --git a/vvp/arith.h b/vvp/arith.h index 612f060b9..097434206 100644 --- a/vvp/arith.h +++ b/vvp/arith.h @@ -1,7 +1,7 @@ #ifndef IVL_arith_H #define IVL_arith_H /* - * Copyright (c) 2001-2014 Stephen Williams (steve@icarus.com) + * Copyright (c) 2001-2016 Stephen Williams (steve@icarus.com) * * This source code is free software; you can redistribute it * and/or modify it in source code form under the terms of the GNU @@ -37,6 +37,10 @@ class vvp_arith_ : public vvp_net_fun_t { public: explicit vvp_arith_(unsigned wid); + void recv_vec4_pv(vvp_net_ptr_t p, const vvp_vector4_t&bit, + unsigned base, unsigned wid, unsigned vwid, + vvp_context_t); + protected: void dispatch_operand_(vvp_net_ptr_t ptr, vvp_vector4_t bit);