From 5ddd4b183040156ecd089b9611f33195f71b0c50 Mon Sep 17 00:00:00 2001 From: Kia <kia@special-circumstanc.es> Date: Thu, 11 Mar 2021 19:12:30 -0700 Subject: [PATCH] simulation for indices/edgecases seems to work --- width_converter_simulator.py | 48 ++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/width_converter_simulator.py b/width_converter_simulator.py index 23e0d08..29d60f3 100644 --- a/width_converter_simulator.py +++ b/width_converter_simulator.py @@ -1,8 +1,7 @@ import math real_width = 8 - -fake_width = 19 +fake_width = 13 @@ -23,13 +22,13 @@ def first_word(fake_idx): print("starting bit index", starting_bit_index) - unwrapped_end_bit_index = (fake_width + starting_bit_index) + unwrapped_end_bit_index = (fake_width + starting_bit_index) - 1 print("unwrapped_end_bit_index", unwrapped_end_bit_index) - number_of_words = math.floor(unwrapped_end_bit_index/real_width) + additional_words = math.floor(unwrapped_end_bit_index/real_width) - print("number_of_words", number_of_words) + print("additional_words", additional_words) end_bit_index = unwrapped_end_bit_index % real_width @@ -47,21 +46,44 @@ def first_word(fake_idx): # We special-case the first fetch outside of the loop, since it always happens # and has special-case logic used nowhere else. + bits_snarfed = 0 - # The microsequencer then iterate over the "middle words", and if there's a partial slice needed to be taken - # from the end word, we do that as well before returning + if (additional_words == 0): + # Start word starting_bit_index unwrapped_end_bit_index + assert(unwrapped_end_bit_index == end_bit_index) + print("single obligatory read of word", starting_word, "from bit index", starting_bit_index, "to", unwrapped_end_bit_index) + bits_snarfed += unwrapped_end_bit_index - starting_bit_index + 1 + print("Snarfed", bits_snarfed) + + else: + current_word = starting_word + # Start word starting_bit_index real_width + + print("first obligatory read of word", current_word, "from bit index", starting_bit_index, "to", real_width - 1) + bits_snarfed += (real_width - 1) - starting_bit_index + 1 + print("Snarfed", bits_snarfed) - bits_snarfed = 0 - words_fetched = 0 - while True: + # if additional_words !=0, we start the loop. + # The microsequencer then iterate over the "middle words", and if there's a partial slice needed to be taken + # from the end word (end_bit_index !=0) , we do that as well before returning + additional_words_fetched = 0 - start_cut = starting_bit_index + # Middle words 0 real_width + while(additional_words_fetched != (additional_words-1)): + additional_words_fetched += 1 + current_word += 1 + print("FULLWORD read of word", current_word, "from bit index", 0, "to", real_width - 1) + bits_snarfed += (real_width - 1) - 0 + 1 + print("Snarfed", bits_snarfed) - print("fetching") - bits_snarfed += + current_word += 1 + print("SPECIAL last fetch of word", current_word, "from bit index", 0, "to", end_bit_index) + bits_snarfed += (end_bit_index) + 1 + print("Snarfed", bits_snarfed) + print("FINAL Snarfed", bits_snarfed) for i in range(4): print("fake index is", i) -- GitLab