use binary search for result
diff --git a/ODIN_II/SRC/include/simulator_bit_map.h b/ODIN_II/SRC/include/simulator_bit_map.h index b58bd61..f1bff1a 100644 --- a/ODIN_II/SRC/include/simulator_bit_map.h +++ b/ODIN_II/SRC/include/simulator_bit_map.h
@@ -7,16 +7,17 @@ typedef struct bit_tree_map_t bit_tree_map; struct bit_tree_map_t { - bit_tree_map *childs[3]; - char my_value; - int depth; - int result_len; - char *result; - char *related_node_name; - bool is_root; + bit_tree_map *branch[3]; bool is_leaf; }; +typedef struct bit_tree_root_t +{ + bit_tree_map *branch[2]; + int depth; + char *related_node_name; +}bit_tree_root; + typedef enum { _0 = 0, @@ -26,8 +27,8 @@ bit_map_values get_mapped_value(signed char value); -bit_tree_map *free_bit_tree(bit_tree_map *bit_map); -bit_tree_map *consume_bit_map_line(std::vector<std::string> lines, std::vector<std::string> results, const char *related_node_name); -std::string find_result(bit_tree_map *bit_map, std::string line); +bit_tree_root *free_bit_tree(bit_tree_root *bit_map); +bit_tree_root *consume_bit_map_line(std::vector<std::string> lines, std::vector<char> results, const char *related_node_name); +char find_result(bit_tree_root *bit_map, std::string line); #endif \ No newline at end of file
diff --git a/ODIN_II/SRC/include/types.h b/ODIN_II/SRC/include/types.h index 720633b..aec542b 100644 --- a/ODIN_II/SRC/include/types.h +++ b/ODIN_II/SRC/include/types.h
@@ -490,7 +490,7 @@ short *associated_function; - bit_tree_map *bit_map; /*storing the bit map */ + bit_tree_root *bit_map; /*storing the bit map */ std::vector<std::string> orig_bit_map; // For simulation
diff --git a/ODIN_II/SRC/read_blif.cpp b/ODIN_II/SRC/read_blif.cpp index 4415970..32fd31c 100644 --- a/ODIN_II/SRC/read_blif.cpp +++ b/ODIN_II/SRC/read_blif.cpp
@@ -295,7 +295,7 @@ } /* assigning the new_node */ - if(input_token_count != 5) + if(input_token_count == 5) { /* supported added for the ABC .latch output without control */ if(input_token_count == 3) @@ -743,7 +743,7 @@ } std::vector<std::string> bit_map; - std::vector<std::string> output_bit_map; + std::vector<char> output_bit_map; char buffer[READ_BLIF_BUFFER]; while(1) { @@ -752,16 +752,14 @@ break; bit_map.push_back(vtr::strtok(buffer,TOKENS, file, buffer)); - output_bit_map.push_back(vtr::strtok(NULL,TOKENS, file, buffer)); + char *tmp = vtr::strtok(NULL,TOKENS, file, buffer); + output_bit_map.push_back(tmp[0]); } file_line_number = last_line; fsetpos(file,&pos); node->orig_bit_map = bit_map; - - bit_tree_map *root = consume_bit_map_line(bit_map, output_bit_map, parent_node_name); - - node->bit_map = root; + node->bit_map = consume_bit_map_line(bit_map, output_bit_map, parent_node_name); return GENERIC; }
diff --git a/ODIN_II/SRC/simulate_blif.cpp b/ODIN_II/SRC/simulate_blif.cpp index ddf4446..921e664 100644 --- a/ODIN_II/SRC/simulate_blif.cpp +++ b/ODIN_II/SRC/simulate_blif.cpp
@@ -1813,21 +1813,9 @@ std::string input_bit_string = ""; for(int i =0; i < node->num_input_pins; i++) input_bit_string.push_back(convert_result_to_chr(get_pin_value(node->input_pins[i],cycle))); - - if(node->num_input_pins != node->bit_map->depth) - { - error_message(SIMULATION_ERROR, -1, -1, "input length miss-match: (pin_len<%d> != bit_map_depth<%d>) current input<%s>" - ,node->num_input_pins ,node->bit_map->depth, input_bit_string.c_str()); - } - else if(node->num_output_pins != node->bit_map->result_len) - { - error_message(SIMULATION_ERROR, -1, -1, "output length miss-match: (pin_len<%d> != bit_map_depth<%d>) current input<%s>" - ,node->num_output_pins ,node->bit_map->result_len, input_bit_string.c_str()); - } - std::string result = find_result(node->bit_map, input_bit_string); - for(int i =0; i < node->num_output_pins; i++) - update_pin_value(node->output_pins[0], convert_result(result[i]), cycle); + char result = find_result(node->bit_map, input_bit_string); + update_pin_value(node->output_pins[0], convert_result(result), cycle); } /*
diff --git a/ODIN_II/SRC/simulator_bit_map.cpp b/ODIN_II/SRC/simulator_bit_map.cpp index 9d66d5c..174e41a 100644 --- a/ODIN_II/SRC/simulator_bit_map.cpp +++ b/ODIN_II/SRC/simulator_bit_map.cpp
@@ -14,141 +14,152 @@ return _x; } -inline static bit_tree_map *bit_map_node(const char *related_node_name, char value, int depth, int result_len) +inline static bit_tree_map *bit_map_node() { bit_tree_map *node = (bit_tree_map *)vtr::malloc(sizeof(bit_tree_map)); for(int i=0; i<3; i++) - { - node->childs[i] = NULL; - } - node->my_value = value; - node->depth = depth; - node->related_node_name = vtr::strdup(related_node_name); - node->result_len = result_len; + node->branch[i] = NULL; + return node; } -bit_tree_map *free_bit_tree(bit_tree_map *bit_map) +inline static bit_tree_root *bit_map_root(const char *related_node_name, int depth) { - if(!bit_map) - return NULL; - - if(bit_map->is_leaf) - { - vtr::free(bit_map->related_node_name); - vtr::free(bit_map); - return NULL; - } - else - { - bit_map->childs[_0] = free_bit_tree(bit_map->childs[_0]); - bit_map->childs[_1] = free_bit_tree(bit_map->childs[_1]); - bit_map->childs[_x] = free_bit_tree(bit_map->childs[_x]); - vtr::free(bit_map); - return NULL; - } + bit_tree_root *root = (bit_tree_root *)vtr::malloc(sizeof(bit_tree_root)); + root->depth = depth; + root->related_node_name = vtr::strdup(related_node_name); + root->branch[_0] = bit_map_node(); + root->branch[_1] = bit_map_node(); + return root; } -bit_tree_map *consume_bit_map_line(std::vector<std::string> lines, std::vector<std::string> results, const char *related_node_name) +inline static bit_tree_map *free_bit_branches(bit_tree_map *bit_map) +{ + if(bit_map) + { + if(!bit_map->is_leaf) + { + bit_map->branch[_0] = free_bit_branches(bit_map->branch[_0]); + bit_map->branch[_1] = free_bit_branches(bit_map->branch[_1]); + bit_map->branch[_x] = free_bit_branches(bit_map->branch[_x]); + } + vtr::free(bit_map); + } + return NULL; +} + +bit_tree_root *free_bit_tree(bit_tree_root *bit_map) +{ + if(bit_map) + { + vtr::free(bit_map->related_node_name); + bit_map->branch[_0] = free_bit_branches(bit_map->branch[_0]); + bit_map->branch[_1] = free_bit_branches(bit_map->branch[_1]); + vtr::free(bit_map); + } + return NULL; +} + + +bit_tree_root *consume_bit_map_line(std::vector<std::string> lines, std::vector<char> results, const char *related_node_name) { if(lines.empty() || results.empty()) return NULL; - bit_tree_map *root = bit_map_node(related_node_name, 0, lines[0].size(), results[0].size()); - root->is_root = true; + bit_tree_root *root = bit_map_root(related_node_name, lines[0].size()); for(int i=0; i < lines.size(); i++) { - bit_tree_map *cur_node = root; + bit_map_values cur_trunk = get_mapped_value(results[i]); + bit_tree_map *cur_node = root->branch[cur_trunk]; + if(lines[i].size() != lines[0].size()) error_message(SIMULATION_ERROR, -1, -1, "mismatched length in input lut @ line %d for node <%s>",i,root->related_node_name); - if(results[i].size() != results[0].size()) - error_message(SIMULATION_ERROR, -1, -1, "mismatched length in input lut @ line %d for node <%s>",i,root->related_node_name); - - for(int j=1; j <= lines[i].size(); j++) + for(int j=0; j < lines[i].size(); j++) { - char input_value = lines[i][j-1]; - bit_map_values cur_value = get_mapped_value(input_value); + bit_map_values cur_value = get_mapped_value(lines[i][j]); - if(!cur_node->childs[cur_value]) - cur_node->childs[cur_value] = bit_map_node(root->related_node_name, input_value, lines[i].size(), results[i].size()); + if(!cur_node->branch[cur_value]) + cur_node->branch[cur_value] = bit_map_node(); - /* this holds the result */ - if(j == lines[i].size()) - { - cur_node->result = vtr::strdup(results[i].c_str()); + if(j+1 == lines[i].size()) cur_node->is_leaf = true; - } + } } return root; } -std::string find_result(bit_tree_map *root, std::string line) +static signed char explore_trunk(bit_tree_map *trunk, char result, const std::string& line, char set_to) { - if(!root) - error_message(SIMULATION_ERROR, -1, -1, "root bit_map is empty"); - - if(line == "") - return ""; - - std::vector<bit_tree_map*> Q = {root}; + int end = line.size()-1; + bool error = false; + std::vector<bit_tree_map*> Q = {trunk}; std::vector<bit_tree_map*> new_Q; - - std::string result = ""; - - for(int j=0; j < line.size(); j++) + for(int j=0; j <= end && !Q.empty() && !error; j++) { - if(Q.empty()) - break; - - char input_value = line[j]; - bit_map_values cur_value = get_mapped_value(input_value); - - for(int i=0; i < Q.size(); i++) + bit_map_values cur_value = get_mapped_value(line[j]); + for(int i=0; i < Q.size() && !error; i++) { bit_tree_map *bit_map = Q[i]; - - if(!bit_map->is_leaf && j == line.size()-1) - error_message(SIMULATION_ERROR, -1, -1, "input missmatch: bit map length != input length "); - - if(!bit_map->is_root) - printf("######## exploring node #%d @%d for node:%s with input: %s @input id:%d\n", i, bit_map->depth, bit_map->related_node_name, line.c_str(), j); - - /* this node holds the result */ if(bit_map->is_leaf) { - if(result == "") - result = bit_map->result; + if(result) + { + error = true; + result = '!'; + } else { - warning_message(SIMULATION_ERROR, -1, -1, "ambiguous bit map for .name <%s> with multiple result for pattern", bit_map->related_node_name); - break; + result = set_to; } } else { - if(bit_map->childs[cur_value]) - new_Q.push_back(bit_map->childs[cur_value]); + if(bit_map->branch[cur_value]) + new_Q.push_back(bit_map->branch[cur_value]); //include unknown in defined search - if(cur_value != _x && bit_map->childs[_x]) - new_Q.push_back(bit_map->childs[_x]); - + if(cur_value != _x && bit_map->branch[_x]) + new_Q.push_back(bit_map->branch[_x]); } } Q.clear(); Q = new_Q; new_Q.clear(); - } + return result; +} - if(result == "") +char find_result(bit_tree_root *root, std::string line) +{ + if(!root) + error_message(SIMULATION_ERROR, -1, -1, "root bit_map is empty"); + + if(line == "") + return 3; + + char result = 0; + + + if(root->depth > line.size()) + error_message(SIMULATION_ERROR, -1, -1, "input missmatch: bit map length > input length "); + else if(root->depth < line.size()) + error_message(SIMULATION_ERROR, -1, -1, "input missmatch: bit map length < input length "); + + result = explore_trunk(root->branch[_0], result, line, '0'); + result = explore_trunk(root->branch[_1], result, line, '1'); + if(result == '!') { - warning_message(SIMULATION_ERROR, -1, -1, "missmatch between input and lut depth"); - result = "x"; + warning_message(SIMULATION_ERROR, -1, -1, "ambiguous bit map for .name <%s> with multiple, or no result for pattern", root->related_node_name); + result = 'x'; } + else if(!result) + { + result = 'x'; + } + return result; } \ No newline at end of file
diff --git a/ODIN_II/regression_test/benchmark/syntax/bm_simple_memory.v b/ODIN_II/regression_test/benchmark/syntax/bm_simple_memory.v index d9e790f..fb7c6af 100644 --- a/ODIN_II/regression_test/benchmark/syntax/bm_simple_memory.v +++ b/ODIN_II/regression_test/benchmark/syntax/bm_simple_memory.v
@@ -6,7 +6,6 @@ clock, reset, addr_in, - addr_out, value_out, value_in ); @@ -16,7 +15,6 @@ input reset; input [`WORD_SIZE-1:0] value_in; input [`BITS-1:0] addr_in; -input [`BITS-1:0] addr_out; output [`WORD_SIZE-1:0] value_out; @@ -25,7 +23,7 @@ always @(posedge clock) begin memory[addr_in] = value_in; - value_out = memory[addr_out]; + value_out = memory[0]; end