def remplace_entrie_lru(self, jump, ret): retval = 0 ret_address_remove = {} address_remove = None address_insert = None num_free_entries = None ret_num_free_entries = {} self.pred_buffer.get_num_free_entries(ret_num_free_entries) num_free_entries = ret_num_free_entries["value"] if num_free_entries: return FLAGS.GET_ERROR_REMPLACE() self.pred_buffer.get_entrie_by_index_lru_branch_stack( 0, ret_address_remove) address_remove = ret_address_remove["value"] address_insert = jump["address_src"] retval |= self.pred_buffer.insert_jump(jump) if FLAGS.IS_ENTRIE_EXIST(retval): self.pred_buffer.remove_entrie_lru_branch_stack(address_insert) else: self.pred_buffer.remove_entrie_lru_branch_stack(address_remove) self.pred_buffer.remove_entrie(address_remove, ret) self.pred_buffer.insert_jump(jump) self.pred_buffer.insert_jump_lru_branch_stack(address_insert) return retval
def insert_jump_lru(self, jump): retval = 0 address_src = jump["address_src"] retval |= self.insert_jump_ale(jump) if not FLAGS.IS_BUFFER_LIMIT(retval): if FLAGS.IS_ENTRIE_EXIST(retval): self.pred_buffer.remove_entrie_lru_branch_stack(address_src) self.pred_buffer.insert_jump_lru_branch_stack(address_src) return retval
def handler_session_init(request): retval = 0 retval |= test_session(request.session) if FLAGS.IS_SESSION_NOT_INIT(retval): init_session(request.session)
def insert_jump_lru_branch_stack(self, address): retval = 0 if address in self.lru_branch_stack: retval |= FLAGS.GET_ENTRIE_EXIST_LRU() self.lru_branch_stack.append(address) return retval
def handler_simalador_step_by_step(simulador): retval = 0 ret_jump = {} retval |= simulador.next_step_jump(ret_jump) if (FLAGS.IS_END_TRACE(retval)): pass return simulador
def run_simulator(request, simulador, option): retval = 0 ret_jump = {} counter = 0 while (True): retval |= simulador.next_step_jump(ret_jump) if (FLAGS.IS_END_TRACE(retval) or step_by_step_option(option)(retval)): if FLAGS.IS_END_TRACE(retval): simulador_resultados(request, simulador) break counter += 1 return simulador
def remove_entrie_lru(self, address, ret): retval = 0 retval |= self.pred_buffer.remove_entrie(address, ret) if not FLAGS.IS_NOT_ADDRESS_REGISTER(retval): self.pred_buffer.remove_entrie(address, ret) return retval
def set_failure_jump_lru(self, address, ret): retval = 0 retval |= self.set_failure_jump_ale(address, ret) if not FLAGS.IS_NOT_ADDRESS_REGISTER(retval): self.pred_buffer.remove_entrie_lru_branch_stack(address) self.pred_buffer.insert_jump_lru_branch_stack(address) return retval
class BITS_BUFFER_HISTORY(): history_index = None bits_buffer = None counter = 0 def __init__(self,history_index_len): self.bits_buffer = {} self.history_index = ['0']*history_index_len def handler_case(self,case): retval = 0 if case == 1: self.history_index[self.counter] = '1' self.counter = (self.counter + 1) % len(self.history_index) elif case == 2: self.history_index[self.counter] = '0' self.counter = (self.counter + 1) % len(self.history_index) return retval def get_bits(self,case,ret): retval = 0 index = "".join(self.history_index) try: ret['value'] = self.bits_buffer[index] except: retval |= FLAGS.GET_NEW_ENTRIE_HISTORY_BUFFER() self.bits_buffer[index] = {'bits' : 0} ret['value'] = self.bits_buffer[index] self.handler_case(case) return retval
def test_session(session): retval = 0 try: os.stat(session.get("home_dir")) except: retval |= FLAGS.GET_SESSION_NOT_INIT() return retval
def get_data_entrie(self, address, ret): retval = 0 try: ret['value'] = self.branch_buffer[address] except KeyError: retval = FLAGS.GET_NOT_ADDRESS_REGISTER() return retval
def remove_entrie_lru_branch_stack(self, address): retval = 0 try: self.lru_branch_stack.remove(address) except ValueError: retval |= FLAGS.GET_NOT_ADDRESS_REGISTER_LRU() return retval
def remove_entrie(self, address, ret): retval = 0 try: ret['value'] = self.branch_buffer.pop(address) self.current_num_entries -= 1 except KeyError: retval = FLAGS.GET_NOT_ADDRESS_REGISTER() return retval
def insert_jump(self, jump): retval = 0 instruccion = jump["instruccion"] address_src = jump["address_src"] address_dts = jump["address_dts"] entrie_exist = (address_src in list(self.branch_buffer.keys())) ret_bits = {} bits = -1 if (not entrie_exist and self.current_num_entries == self.size_buffer): retval |= FLAGS.GET_BUFFER_LIMIT() else: if not entrie_exist: self.current_num_entries += 1 else: retval |= FLAGS.GET_ENTRIE_EXIST() retval |= self.get_init_bits(address_src, ret_bits) bits = ret_bits['value'] data = { 'instruccion': instruccion, 'address_src': address_src, 'address_dts': address_dts, 'bits': bits } self.branch_buffer[address_src] = data return retval
def get_new_jump(self, ret): retval = 0 jump_dict = {} try: jump_dict['instruccion'] = self.traza_list[self.jump_counter][1] jump_dict['address_src'] = self.traza_list[self.jump_counter][2] jump_dict['address_dts'] = self.traza_list[self.jump_counter][3] jump_dict['was_jump'] = int(self.traza_list[self.jump_counter][4]) ret['value'] = jump_dict except IndexError: retval |= FLAGS.GET_END_TRACE() return retval
def increment_bits_predictor(self, address, ret): retval = 0 data = None ret_data = {} bits = -1 retval = self.extract_bits(address, 1, ret_data) if (retval): return retval data = ret_data["value"] bits = data["bits"] ret["value"] = bits if (bits < (2**(self.num_pred_bits)) - 1): data["bits"] = bits + 1 else: retval = FLAGS.GET_COUNTER_SATURED() return retval
def decrement_bits_predictor(self, address, ret): retval = 0 data = None ret_data = {} bits = -1 retval = self.extract_bits(address, 2, ret_data) if (retval): return retval data = ret_data["value"] bits = data["bits"] ret["value"] = bits if (bits > 0): data["bits"] = bits - 1 else: retval = FLAGS.GET_COUNTER_SATURED() return retval
def btb_test(): retval = 0 file_prove = None ret_jump = {} jump = None counter = 0 config = { 'filename':'../../Traza/traza.out', 'pred_id':'Predictor BTB', 'is_lru':0, 'size_buffer':8, 'num_pred_bits':2, 'init_bits_value':2 } simulador = Simulador(config) print("#################################################\n\n") while(True): retval |= simulador.next_step_jump(ret_jump) if(FLAGS.IS_END_TRACE(retval)): break jump = ret_jump['value'] if(True or "235" in jump[0]): print_all(simulador,jump) print(counter) counter += 1 return simulador
def next_step_jump(self, ret): retval = 0 ret_jump = {} ret_prediction_dict = {} prediction_dict = None jump = None retval |= self.get_new_jump(ret_jump) if not (FLAGS.IS_END_TRACE(retval)): jump = ret_jump['value'] address_src = jump['address_src'] retval |= self.predictor.get_jump_prediction( address_src, ret_prediction_dict) if retval: if (FLAGS.IS_NOT_ADDRESS_REGISTER(retval)): retval |= self.predictor.insert_jump(jump) if (FLAGS.IS_BUFFER_LIMIT(retval)): retval |= self.predictor.remplace_entrie(jump, ret_jump) self.remplace_jump += 1 self.predictor.get_jump_prediction(address_src, ret_prediction_dict) prediction_dict = ret_prediction_dict['value'] if (str(jump['address_dts']) == str(prediction_dict['address_dts']) and str(jump['was_jump']) == str( prediction_dict['prediction'])): retval |= FLAGS.GET_SUCCESS_PREDICTION() self.success_prediction += 1 else: retval |= FLAGS.GET_FAIL_PREDICTION() self.fails_prediction += 1 if str(jump['address_dts']) != str(prediction_dict['address_dts']): pass if str(jump['was_jump']) == '1': self.predictor.set_success_jump(address_src, {}) else: self.predictor.set_failure_jump(address_src, {}) ret['value'] = [ jump['address_src'], jump['address_dts'], prediction_dict['address_dts'], jump['was_jump'], prediction_dict['prediction'] ] self.instrucciones_totales += int( self.traza_list[self.jump_counter][0]) + 1 self.jump_counter += 1 return retval