From d1d6c0f5d2824f37e3244a2096184f58a2fadfda Mon Sep 17 00:00:00 2001 From: Cary R Date: Mon, 3 Aug 2020 23:45:05 -0700 Subject: [PATCH] Start refactoring the queue routines --- vvp/vthread.cc | 136 ++++++++++++++++++++++++++++++------------------- 1 file changed, 84 insertions(+), 52 deletions(-) diff --git a/vvp/vthread.cc b/vvp/vthread.cc index 6446ccb4b..ac5c558ba 100644 --- a/vvp/vthread.cc +++ b/vvp/vthread.cc @@ -5958,6 +5958,26 @@ bool of_STORE_PROP_V(vthread_t thr, vvp_code_t cp) return true; } +/* + * The following are used to allow a common template to be written for + * queue real/string/vec4 operations + */ +static void pop_value(double&value, vthread_t thr, unsigned) +{ + value = thr->pop_real(); +} + +static void pop_value(string&value, vthread_t thr, unsigned) +{ + value = thr->pop_str(); +} + +static void pop_value(vvp_vector4_t&value, vthread_t thr, unsigned wid) +{ + value = thr->pop_vec4(); + assert(value.size() == wid); +} + /* * %store/qb/r , */ @@ -6011,27 +6031,73 @@ bool of_STORE_QB_V(vthread_t thr, vvp_code_t cp) return true; } +/* + * The following are used to allow the template to print correctly. + */ +static void print_queue_type(double) +{ + cerr << "queue"; +} + +static void print_queue_type(string) +{ + cerr << "queue"; +} + +static void print_queue_type(vvp_vector4_t value) +{ + cerr << "queue"; +} + +static void print_queue_value(double value) +{ + cerr << value; +} + +static void print_queue_value(string value) +{ + cerr << "\"" << value << "\""; +} + +static void print_queue_value(vvp_vector4_t value) +{ + cerr << value; +} + +template +static bool store_qdar(vthread_t thr, vvp_code_t cp, unsigned wid=0) +{ + int64_t adr = thr->words[3].w_int; + ELEM value; + vvp_net_t*net = cp->net; + unsigned max_size = thr->words[cp->bit_idx[0]].w_int; + pop_value(value, thr, wid); // Pop the value to store. + + vvp_queue*queue = get_queue_object(thr, net); + assert(queue); + if (adr < 0) { + cerr << "Warning: cannot assign to a negative "; + print_queue_type(value); + cerr << " index (" << adr << "). "; + print_queue_value(value); + cerr << " was not added." << endl; + } else if (thr->flags[4] != BIT4_0) { + cerr << "Warning: cannot assign to an undefined "; + print_queue_type(value); + cerr << " index. "; + print_queue_value(value); + cerr << " was not added." << endl; + } else + queue->set_word_max(adr, value, max_size); + return true; +} + /* * %store/qdar/real , idx */ bool of_STORE_QDAR_R(vthread_t thr, vvp_code_t cp) { - int64_t adr = thr->words[3].w_int; - double value = thr->pop_real(); // Pop the real value to store... - vvp_net_t*net = cp->net; - unsigned max_size = thr->words[cp->bit_idx[0]].w_int; - - vvp_queue*queue = get_queue_object(thr, net); - assert(queue); - if (adr < 0) - cerr << "Warning: cannot assign negative queue index (" - << adr << "). " << value << " was not added." << endl; - else if (thr->flags[4] != BIT4_0) - cerr << "Warning: cannot assign undefined queue index. " - << value << " was not added." << endl; - else - queue->set_word_max(adr, value, max_size); - return true; + return store_qdar(thr, cp); } /* @@ -6039,22 +6105,7 @@ bool of_STORE_QDAR_R(vthread_t thr, vvp_code_t cp) */ bool of_STORE_QDAR_STR(vthread_t thr, vvp_code_t cp) { - int64_t adr = thr->words[3].w_int; - string value = thr->pop_str(); // Pop the string to be stored... - vvp_net_t*net = cp->net; - unsigned max_size = thr->words[cp->bit_idx[0]].w_int; - - vvp_queue*queue = get_queue_object(thr, net); - assert(queue); - if (adr < 0) - cerr << "Warning: cannot assign to a negative queue index (" - << adr << "). \"" << value << "\" was not added." << endl; - else if (thr->flags[4] != BIT4_0) - cerr << "Warning: cannot assign to an undefined queue index. \"" - << value << "\" was not added." << endl; - else - queue->set_word_max(adr, value, max_size); - return true; + return store_qdar(thr, cp); } /* @@ -6062,26 +6113,7 @@ bool of_STORE_QDAR_STR(vthread_t thr, vvp_code_t cp) */ bool of_STORE_QDAR_VEC4(vthread_t thr, vvp_code_t cp) { - int64_t adr = thr->words[3].w_int; - vvp_vector4_t value = thr->pop_vec4(); // Pop the vector4 value to be store... - vvp_net_t*net = cp->net; - unsigned max_size = thr->words[cp->bit_idx[0]].w_int; - unsigned wid = cp->bit_idx[1]; - - assert(value.size() == wid); - vvp_queue*queue = get_queue_object(thr, net); - assert(queue); - if (adr < 0) - cerr << "Warning: cannot assign to a negative queue index (" << adr << "). " << value - << " was not added." << endl; - else if (thr->flags[4] != BIT4_0) - cerr << "Warning: cannot assign to an undefined queue index. " << value - << " was not added." << endl; - else - queue->set_word_max(adr, value, max_size); - return true; + return store_qdar(thr, cp, cp->bit_idx[1]); } /*