From bb1d3c9ac68c136931e435aceca2d85ae58bc58a Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Sat, 6 Jan 2024 17:44:29 -0800 Subject: [PATCH] vvp: Implement concat `recv_vec()` using `recv_vec_pv()` The implementation for partial receive for concat only differs from the regular receive in that it takes an additional offset. The regular receive can easily be implemented by calling the partial receive with an offset of 0. This allows to remove some duplicated code. The overhead of this is negligible, but to help the compiler to optimize this a bit better mark the `recv_vec()` and `recv_vec_pv()` functions as final. Signed-off-by: Lars-Peter Clausen --- vvp/concat.cc | 42 ++++-------------------------------------- vvp/vvp_net.h | 12 ++++++------ 2 files changed, 10 insertions(+), 44 deletions(-) diff --git a/vvp/concat.cc b/vvp/concat.cc index 1f19dd139..951453801 100644 --- a/vvp/concat.cc +++ b/vvp/concat.cc @@ -43,26 +43,9 @@ vvp_fun_concat::~vvp_fun_concat() } void vvp_fun_concat::recv_vec4(vvp_net_ptr_t port, const vvp_vector4_t&bit, - vvp_context_t) + vvp_context_t context) { - unsigned pdx = port.port(); - - if (bit.size() != wid_[pdx]) { - cerr << "internal error: port " << pdx - << " expects wid=" << wid_[pdx] - << ", got wid=" << bit.size() << endl; - assert(0); - } - - unsigned off = 0; - for (unsigned idx = 0 ; idx < pdx ; idx += 1) - off += wid_[idx]; - - for (unsigned idx = 0 ; idx < wid_[pdx] ; idx += 1) { - val_.set_bit(off+idx, bit.value(idx)); - } - - port.ptr()->send_vec4(val_, 0); + recv_vec4_pv(port, bit, 0, bit.size(), context); } void vvp_fun_concat::recv_vec4_pv(vvp_net_ptr_t port, const vvp_vector4_t&bit, @@ -131,7 +114,7 @@ void vvp_fun_concat8::recv_vec4(vvp_net_ptr_t port, const vvp_vector4_t&bit, vvp_context_t) { vvp_vector8_t bit8 (bit, 6, 6); - recv_vec8(port, bit8); + recv_vec8_pv(port, bit8, 0, bit8.size()); } void vvp_fun_concat8::recv_vec4_pv(vvp_net_ptr_t port, const vvp_vector4_t&bit, @@ -143,24 +126,7 @@ void vvp_fun_concat8::recv_vec4_pv(vvp_net_ptr_t port, const vvp_vector4_t&bit, void vvp_fun_concat8::recv_vec8(vvp_net_ptr_t port, const vvp_vector8_t&bit) { - unsigned pdx = port.port(); - - if (bit.size() != wid_[pdx]) { - cerr << "internal error: port " << pdx - << " expects wid=" << wid_[pdx] - << ", got wid=" << bit.size() << endl; - assert(0); - } - - unsigned off = 0; - for (unsigned idx = 0 ; idx < pdx ; idx += 1) - off += wid_[idx]; - - for (unsigned idx = 0 ; idx < wid_[pdx] ; idx += 1) { - val_.set_bit(off+idx, bit.value(idx)); - } - - port.ptr()->send_vec8(val_); + recv_vec8_pv(port, bit, 0, bit.size()); } void vvp_fun_concat8::recv_vec8_pv(vvp_net_ptr_t port, const vvp_vector8_t&bit, diff --git a/vvp/vvp_net.h b/vvp/vvp_net.h index fdf9f28cc..925bc3deb 100644 --- a/vvp/vvp_net.h +++ b/vvp/vvp_net.h @@ -1385,10 +1385,10 @@ class vvp_fun_concat : public vvp_net_fun_t { ~vvp_fun_concat(); void recv_vec4(vvp_net_ptr_t port, const vvp_vector4_t&bit, - vvp_context_t context); + vvp_context_t context) final; void recv_vec4_pv(vvp_net_ptr_t port, const vvp_vector4_t&bit, - unsigned base, unsigned vwid, vvp_context_t); + unsigned base, unsigned vwid, vvp_context_t) final; private: unsigned wid_[4]; vvp_vector4_t val_; @@ -1402,13 +1402,13 @@ class vvp_fun_concat8 : public vvp_net_fun_t { ~vvp_fun_concat8(); void recv_vec4(vvp_net_ptr_t port, const vvp_vector4_t&bit, - vvp_context_t context); - void recv_vec8(vvp_net_ptr_t port, const vvp_vector8_t&bit); + vvp_context_t context) final; + void recv_vec8(vvp_net_ptr_t port, const vvp_vector8_t&bit) final; void recv_vec4_pv(vvp_net_ptr_t port, const vvp_vector4_t&bit, - unsigned base, unsigned vwid, vvp_context_t); + unsigned base, unsigned vwid, vvp_context_t) final; void recv_vec8_pv(vvp_net_ptr_t p, const vvp_vector8_t&bit, - unsigned base, unsigned vwid); + unsigned base, unsigned vwid) final; private: unsigned wid_[4];