From 0f454ff548f4815a79a6746c6093409b035610b5 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Sun, 7 Jan 2024 20:20:08 -0800 Subject: [PATCH] vvp: Use word wide vector operations for logic functors The logic functors combine their input vectors bit by bit. Use the in-place `vvp_vector4_t` operators for the vector operation and invert the result once for the inverted functors. Signed-off-by: Lars-Peter Clausen --- vvp/logic.cc | 54 ++++++++++++---------------------------------------- 1 file changed, 12 insertions(+), 42 deletions(-) diff --git a/vvp/logic.cc b/vvp/logic.cc index 458cc6cb6..9b9a83e41 100644 --- a/vvp/logic.cc +++ b/vvp/logic.cc @@ -94,21 +94,11 @@ void vvp_fun_and::run_run() vvp_vector4_t result (input_[0]); - for (unsigned idx = 0 ; idx < result.size() ; idx += 1) { - vvp_bit4_t bitbit = result.value(idx); - for (unsigned pdx = 1 ; pdx < 4 ; pdx += 1) { - if (input_[pdx].size() < idx) { - bitbit = BIT4_X; - break; - } + for (unsigned pdx = 1 ; pdx < 4 ; pdx += 1) + result &= input_[pdx]; - bitbit = bitbit & input_[pdx].value(idx); - } - - if (invert_) - bitbit = ~bitbit; - result.set_bit(idx, bitbit); - } + if (invert_) + result.invert(); ptr->send_vec4(result, 0); } @@ -535,21 +525,11 @@ void vvp_fun_or::run_run() vvp_vector4_t result (input_[0]); - for (unsigned idx = 0 ; idx < result.size() ; idx += 1) { - vvp_bit4_t bitbit = result.value(idx); - for (unsigned pdx = 1 ; pdx < 4 ; pdx += 1) { - if (input_[pdx].size() < idx) { - bitbit = BIT4_X; - break; - } + for (unsigned pdx = 1 ; pdx < 4 ; pdx += 1) + result |= input_[pdx]; - bitbit = bitbit | input_[pdx].value(idx); - } - - if (invert_) - bitbit = ~bitbit; - result.set_bit(idx, bitbit); - } + if (invert_) + result.invert(); ptr->send_vec4(result, 0); } @@ -571,21 +551,11 @@ void vvp_fun_xor::run_run() vvp_vector4_t result (input_[0]); - for (unsigned idx = 0 ; idx < result.size() ; idx += 1) { - vvp_bit4_t bitbit = result.value(idx); - for (unsigned pdx = 1 ; pdx < 4 ; pdx += 1) { - if (input_[pdx].size() < idx) { - bitbit = BIT4_X; - break; - } + for (unsigned pdx = 1 ; pdx < 4 ; pdx += 1) + result ^= input_[pdx]; - bitbit = bitbit ^ input_[pdx].value(idx); - } - - if (invert_) - bitbit = ~bitbit; - result.set_bit(idx, bitbit); - } + if (invert_) + result.invert(); ptr->send_vec4(result, 0); }