def getActiveConditions(self, termname, op='>', conditionvalue=0): if not termname in self.resolved_binddict: return () tree = self.makeConditionalTree(termname, step=0) funcdict = splitter.split(tree) condlists = self.getActiveFuncdictKeys(funcdict, op=op, conditionvalue=conditionvalue) active_conditions = self.inferActiveConditions(condlists) return active_conditions # OR-style
def getActiveConditions(self, termname, condition=splitter.active_constant): if not termname in self.resolved_binddict: return {} tree = self.makeTree(termname) funcdict = splitter.split(tree) funcdict = splitter.filter(funcdict, termname, condition) funcdict = splitter.remove_reset_condition(funcdict) if len(funcdict) == 1 and len(list(funcdict.keys())[0]) == 0: func = funcdict.values()[0] return {termname: (("any", None),)} active_conditions = {} active_conditions_size = 0 for fsm_sig in self.fsms.keys(): rslt = self.getActiveConditions_fsm(fsm_sig, funcdict) if len(rslt) > 0: active_conditions[fsm_sig] = rslt active_conditions_size += len(rslt) if active_conditions_size == 0: rslt = self.getActiveConditions_fsm(termname, funcdict) if len(rslt) > 0: active_conditions[termname] = rslt return active_conditions
def getActiveConditions(self, termname, condition=splitter.active_constant): if not termname in self.resolved_binddict: return {} tree = self.makeTree(termname) funcdict = splitter.split(tree) funcdict = splitter.filter(funcdict, termname, condition) funcdict = splitter.remove_reset_condition(funcdict) if len(funcdict) == 1 and len(list(funcdict.keys())[0]) == 0: func = funcdict.values()[0] return {termname: (('any', None), )} active_conditions = {} active_conditions_size = 0 for fsm_sig in self.fsms.keys(): rslt = self.getActiveConditions_fsm(fsm_sig, funcdict) if len(rslt) > 0: active_conditions[fsm_sig] = rslt active_conditions_size += len(rslt) if active_conditions_size == 0: rslt = self.getActiveConditions_fsm(termname, funcdict) if len(rslt) > 0: active_conditions[termname] = rslt return active_conditions
def search_invert_regs(self): """[FUNCTIONS] search register pairs that always hold invert values. ex. always @(posedge CLK or negedge RST) begin if(RST) begin reg1 <= 1'b0; end else begin reg1 <= IN; end end always @(posedge CLK or negedge RST) begin if(RST) begin reg2 <= 1'b1; end else begin reg2 <= !IN; end end """ def judge_invert_reg(values, target_values): assert len(values) == len(target_values) for val, target_val in zip(values, target_values): if isinstance(val, DFEvalValue) and isinstance(target_val, DFEvalValue): if eval_value(val) == eval_value(target_val): return False elif str(val) == 'Ulnot': if val.nextnodes[0].tocode() != target_val.tocode(): return False elif str(target_val) == 'Ulnot': if val.tocode() != target_val.nextnodes[0].tocode(): return False else: return False return True functable = {} for tv, tk, bvi, bit, term_lsb in self.binds.walk_reg_each_bit(): if not 'Reg' in tv.termtype: continue target_tree = self.makeTree(tk) functable[tk, bit] = splitter.split(target_tree) ft_order = OrderedDict(sorted(functable.items(), key=lambda t: str(t[0]))) invert_regs = [] ft_values = list(ft_order.values()) ft_keys = list(ft_order.keys()) for cnt in range(len(ft_order.keys()) - 1): for target_cnt in range(cnt + 1, len(ft_keys)):#roop for same formal branch if ft_values[cnt].keys() != ft_values[target_cnt].keys(): break #not same branch if judge_invert_reg(ft_values[cnt].values(), ft_values[target_cnt].values()): invert_regs.append((ft_keys[cnt], ft_keys[target_cnt])) if invert_regs: print('Invert reg pairs:') self.deploy_reg_info(invert_regs) else: print('There isn\'t invert reg pair.') return invert_regs
def make_cnt_event_all(self): """ [FUNCTIONS] make cnt_event_dict[(cnt_val, operator)] ex. always @(posedge CLK or negedge RSTN) begin if(!RSTN) begin reg1 <= 0; end else if(cnt == 2'd3) begin reg1 <= 1'd1; end else begin reg1 <= 0; end end cnt_event_dict[3,'Eq)] = (reg1 <= 1'd1,) """ def make_cnt_ref_info(cond_dict, cnt_name): cnt_ref_info = [] for cond, term_value in cond_dict.items(): reffered_cnts = [] opes = self.binds.extract_all_dfxxx(cond, set([]), 0, DFOperator) opes = set([ope[0] for ope in opes]) for ope in opes: if not ope.operator in self.compare_ope: continue if cnt_name == str(ope.children()[0]): ope.comp_target = ope.children()[0] lsb = 0 elif (isinstance(ope.children()[0], DFPartselect) and cnt_name == str(ope.children()[0].var)): ope.comp_target = ope.children()[0].var lsb = eval_value(ope.children()[0].lsb) else: continue ope.comp_value = eval_value(ope.children()[1]) ope.comp_target.mother_node = ope reffered_cnts.append(ope.comp_target) if reffered_cnts: cnt_ref_info.append((reffered_cnts, term_value, cond, lsb)) return cnt_ref_info for cnt_name, counter in self.cnt_dict.items(): cnt_ref_dict = {} for term_name in self.term_ref_dict[cnt_name]: if term_name == cnt_name: continue #exclude self reference scope = self.binds.get_scope(term_name) target_tree = self.makeTree(scope) funcdict = splitter.split(target_tree) funcdict = splitter.remove_reset_condition(funcdict) if not funcdict: continue cond_dict = { func[-1]: term_value for func, term_value in funcdict.items() } #extract last condition cnt_ref_info = make_cnt_ref_info(cond_dict, cnt_name) if cnt_ref_info: cnt_ref_dict[term_name] = cnt_ref_info counter.make_cnt_event_dict(cnt_ref_dict)
def getUnchangedConditions(self, termname): if not termname in self.resolved_binddict: return () bindlist = self.resolved_binddict[termname] termtype = self.getTermtype(termname) tree = self.makeTree(termname) funcdict = splitter.split(tree) if len(funcdict) == 0: return () unchanged_condlists = self.getUnchangedFuncdictKeys(funcdict, termname) unchanged_conditions = self.inferActiveConditions(unchanged_condlists) return unchanged_conditions
def getChangedConditionsWithAssignments(self, termname): if not termname in self.resolved_binddict: return {} bindlist = self.resolved_binddict[termname] termtype = self.getTermtype(termname) tree = self.makeTree(termname) funcdict = splitter.split(tree) if len(funcdict) == 0: return {} changed_condfuncs = self.getChangedFuncdict(funcdict, termname) changed_conditiondict = self.inferActiveConditionDict(changed_condfuncs) return changed_conditiondict
def make_cnt_event_all(self): """ [FUNCTIONS] make cnt_event_dict[(cnt_val, operator)] ex. always @(posedge CLK or negedge RSTN) begin if(!RSTN) begin reg1 <= 0; end else if(cnt == 2'd3) begin reg1 <= 1'd1; end else begin reg1 <= 0; end end cnt_event_dict[3,'Eq)] = (reg1 <= 1'd1,) """ def make_cnt_ref_info(cond_dict, cnt_name): cnt_ref_info = [] for cond, term_value in cond_dict.items(): reffered_cnts = [] opes = self.binds.extract_all_dfxxx(cond, set([]), 0, DFOperator) opes = set([ope[0] for ope in opes]) for ope in opes: if not ope.operator in self.compare_ope: continue if cnt_name == str(ope.children()[0]): ope.comp_target = ope.children()[0] lsb = 0 elif (isinstance(ope.children()[0], DFPartselect) and cnt_name == str(ope.children()[0].var)): ope.comp_target = ope.children()[0].var lsb = eval_value(ope.children()[0].lsb) else: continue ope.comp_value = eval_value(ope.children()[1]) ope.comp_target.mother_node = ope reffered_cnts.append(ope.comp_target) if reffered_cnts: cnt_ref_info.append((reffered_cnts, term_value, cond, lsb)) return cnt_ref_info for cnt_name, counter in self.cnt_dict.items(): cnt_ref_dict = {} for term_name in self.term_ref_dict[cnt_name]: if term_name == cnt_name: continue #exclude self reference scope = self.binds.get_scope(term_name) target_tree = self.makeTree(scope) funcdict = splitter.split(target_tree) funcdict = splitter.remove_reset_condition(funcdict) if not funcdict: continue cond_dict = {func[-1]: term_value for func, term_value in funcdict.items()}#extract last condition cnt_ref_info = make_cnt_ref_info(cond_dict, cnt_name) if cnt_ref_info: cnt_ref_dict[term_name] = cnt_ref_info counter.make_cnt_event_dict(cnt_ref_dict)
def getFuncdict(self, termname, delaycnt=0): termtype = self.getTermtype(termname) if not self.isClockEdge(termname): return {}, 0 if signaltype.isRename(termtype): return {}, 0 if signaltype.isRegArray(termtype): return {}, 0 # currently unsupported tree = self.makeTree(termname) funcdict = splitter.split(tree) funcdict = splitter.remove_reset_condition(funcdict) if len(funcdict) == 1 and len(funcdict.keys()[0]) == 0: next_term = funcdict.values()[0] if isinstance(next_term, DFTerminal): return self.getFuncdict(next_term.name, delaycnt+1) return funcdict, delaycnt
def analyze_cnt(self): self.make_term_ref_dict() self.cnt_dict = {} for tv, tk, bvi, bit, term_lsb in self.binds.walk_reg_each_bit(): if not 'cnt' in str(tk) and not 'count' in str(tk): continue if not eval_value(tv.msb): continue #1bit signal is not counter. target_tree = self.makeTree(tk) funcdict = splitter.split(target_tree) funcdict = splitter.remove_reset_condition(funcdict) up_cond = self.filter(funcdict, self.active_ope, op='Plus') up_cond = {conds[-1] for conds in up_cond.keys()} down_cond = self.filter(funcdict, self.active_ope, op='Minus') down_cond = {conds[-1] for conds in down_cond.keys()} new_counter = self.cnt_factory(str(tk), up_cond, down_cond) new_counter.set_msb(eval_value(tv.msb)) new_counter.set_reset_value( self.get_reset_value(target_tree, str(bvi.getResetName()))) load_const_dict = self.filter(funcdict, self.active_load_const) load_const_dict = { conds[-1]: eval_value(value) for conds, value in load_const_dict.items() } new_counter.set_load_const_cond(load_const_dict) if load_const_dict: new_counter.set_max_load_const(max(load_const_dict.values())) ## else: #free run counter ## new_counter.set_max_load_const(2 ** new_counter.msb - 1) new_counter.make_load_dict(self.binds) new_counter.make_change_cond(self.binds) self.cnt_dict[new_counter.name] = new_counter for cnt_name, counter in self.cnt_dict.items(): for child_cnt in self.term_ref_dict[cnt_name] & set( self.cnt_dict.keys()) - set([cnt_name]): self.cnt_dict[child_cnt].mother_cnts.add(cnt_name) for counter in self.cnt_dict.values(): print(counter.tostr() + '\n') return self.cnt_dict
def getRegMaps(self): write_map = self.reg_control.create_map('write') read_map = self.reg_control.create_map('read') for tv, tk, bvi, bit, term_lsb in self.binds.walk_reg_each_bit(): target_tree = self.makeTree(tk) funcdict = splitter.split(target_tree) funcdict = splitter.remove_reset_condition(funcdict) trees = self.binds.extract_all_dfxxx(target_tree, set([]), bit - term_lsb, DFTerminal) write_map.check_new_reg(str(tv), term_lsb, trees, funcdict, bit) read_map.check_new_reg(str(tv), term_lsb, trees, funcdict, bit) self.out_file = open(self.out_file_name, "w") write_map.output_csv(self.out_file) read_map.output_csv(self.out_file) self.out_file.close() print('Write_map:\n' + str(write_map.map)) print('Read_map:\n' + str(read_map.map)) return write_map, read_map
def analyze_cnt(self): self.make_term_ref_dict() self.cnt_dict = {} for tv, tk, bvi, bit, term_lsb in self.binds.walk_reg_each_bit(): if not 'cnt' in str(tk) and not 'count' in str(tk): continue if not eval_value(tv.msb): continue #1bit signal is not counter. target_tree = self.makeTree(tk) funcdict = splitter.split(target_tree) funcdict = splitter.remove_reset_condition(funcdict) up_cond = self.filter(funcdict, self.active_ope, op='Plus') up_cond = {conds[-1] for conds in up_cond.keys()} down_cond = self.filter(funcdict, self.active_ope, op='Minus') down_cond = {conds[-1] for conds in down_cond.keys()} new_counter = self.cnt_factory(str(tk), up_cond, down_cond) new_counter.set_msb(eval_value(tv.msb)) new_counter.set_reset_value(self.get_reset_value(target_tree, str(bvi.getResetName()))) load_const_dict = self.filter(funcdict, self.active_load_const) load_const_dict = {conds[-1]: eval_value(value) for conds, value in load_const_dict.items()} new_counter.set_load_const_cond(load_const_dict) if load_const_dict: new_counter.set_max_load_const(max(load_const_dict.values())) ## else: #free run counter ## new_counter.set_max_load_const(2 ** new_counter.msb - 1) new_counter.make_load_dict(self.binds) new_counter.make_change_cond(self.binds) self.cnt_dict[new_counter.name] = new_counter for cnt_name, counter in self.cnt_dict.items(): for child_cnt in self.term_ref_dict[cnt_name] & set(self.cnt_dict.keys()) - set([cnt_name]): self.cnt_dict[child_cnt].mother_cnts.add(cnt_name) for counter in self.cnt_dict.values(): print(counter.tostr() + '\n') return self.cnt_dict