From 2346cc8b69f9de311b786eb4aa0f82dec12bf231 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Sat, 1 Jan 2022 10:00:22 +0100 Subject: [PATCH] vvp: Implement partial writes to 2-state arrays Writes to 2-state arrays currently only support full writes. If the write is a partial write it will trigger an assert. E.g. ``` int a[3:0] int i = -1; a[i+:8] = 8'h0; // Triggers assert ``` Add support for partial writes by doing a read-modify-write in the same way as for 4-state arrays. Signed-off-by: Lars-Peter Clausen --- vvp/array.cc | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/vvp/array.cc b/vvp/array.cc index 6f7d01c5d..4727a4ebf 100644 --- a/vvp/array.cc +++ b/vvp/array.cc @@ -602,10 +602,21 @@ void __vpiArray::set_word(unsigned address, unsigned part_off, const vvp_vector4 if (vals) { assert(nets == 0); - // FIXME: For now, assume no part select of word? - assert(part_off==0); - assert(val.size() == vals_width); - vals->set_word(address, val); + if (part_off != 0 || val.size() != vals_width) { + vvp_vector4_t tmp; + vals->get_word(address, tmp); + if ((part_off + val.size()) > tmp.size()) { + cerr << "part_off=" << part_off + << " val.size()=" << val.size() + << " vals[address].size()=" << tmp.size() + << " vals_width=" << vals_width << endl; + assert(0); + } + tmp.set_vec(part_off, val); + vals->set_word(address, tmp); + } else { + vals->set_word(address, val); + } word_change(address); return; }