class PipelineInterface(object): def __init__(self, instruction_list, starting_pc_address, register_memory, data_mem): """ Creates the interface to the pipeline. :param instruction_list: list of Instruction objects in the order they should appear in instruction memory :param starting_pc_address: integer starting address for the program counter. This will also be the base address of instruction memory :param register_memory: list representing register memory, since the registers are just reg0,reg1, etc :param data_mem: dictionary representing data memory """ self.fetch = Fetch(instruction_list, starting_pc_address) self.write_back = WriteBack(fetch_stage=self.fetch) self.memory = Memory(data_mem, self.write_back) self.execute = Execute(self.memory) self.decode = Decode(register_memory, self.execute) self.write_back.decode_stage = self.decode def trigger_clock_cycle(self): """ For single-cycle, we really only do something useful in the fetch.on_rising_clock. It will call a method of the next stage that will do what that stage needs to and then call the next stage, etc In pipelined execution, these would be used because Fetch would fetch the instruction, place it in the intermediate register, and then return back to here, where decode.on_rising_clock would be called. :return: """ self.fetch.on_rising_clock(self.decode) self.decode.on_rising_clock() self.execute.on_rising_clock() self.memory.on_rising_clock() self.write_back.on_rising_clock() def retrieve_register_list(self): """ Helper method to return the current register file for comparing that the instruction was written back successfully :return: list representing register file """ return self.decode.register_file def retrieve_data_memory(self): """ Helper method to return the current data memory dictionary to help ensure that the data was written to the correct place :return: memory dictionary """ return self.memory.memory def retrieve_current_pc_address(self): """ Helper method to retrieve the current value of the program counter from the fetch stage. :return: int (probably) """ return self.fetch.program_counter def retrive_instruction_name(self): return self.decode.instruction.asm_version()
def __init__(self, instruction_list, starting_pc_address, register_memory, data_mem): """ Creates the interface to the pipeline. :param instruction_list: list of Instruction objects in the order they should appear in instruction memory :param starting_pc_address: integer starting address for the program counter. This will also be the base address of instruction memory :param register_memory: list representing register memory, since the registers are just reg0,reg1, etc :param data_mem: dictionary representing data memory """ self.fetch = Fetch(instruction_list, starting_pc_address) self.write_back = WriteBack(fetch_stage=self.fetch) self.memory = Memory(data_mem, self.write_back) self.execute = Execute(self.memory) self.decode = Decode(register_memory, self.execute) self.write_back.decode_stage = self.decode
def test_create_decode(self): decode = Decode(self.register_file) self.assertEqual(None, decode.read_reg_1) self.assertEqual(None, decode.read_reg_2) self.assertEqual(None, decode.write_register)
def test_calculate_jump_address(self): decode = Decode(self.register_file) decode.receive_instruction(Instruction('j', '320'), 8) self.assertEqual("00000000000000000000010100000000", decode.jump_address)
def test_extend_immediate_neg(self): decode = Decode(self.register_file) decode.receive_instruction(Instruction('addi', '$t8', '$zero', '-10'), 8) self.assertEqual("11111111111111111111111111110110", decode.sign_extended_immediate)
def test_correct_values_in_register_file(self): decode = Decode(self.register_file) decode.receive_instruction(Instruction('add', '$t1', '$t2', '$t3'), 8) for value in decode.register_file[1:]: self.assertEqual('00000000000000001111111111111111', value)
def test_write_to_write_reg(self): decode = Decode(self.register_file) decode.receive_instruction(Instruction('Add', "$t1", "$t2", "t3"), 8) decode.write_to_register("Test data.") self.assertEqual("Test data.", decode.register_file[9])
def test_receive_instruction(self): decode = Decode(self.register_file) decode.receive_instruction(Instruction('Add', "$t1", "$t2", "t3"), 8) self.assertEqual("01001", decode.write_register) self.assertEqual("01010", decode.read_reg_1) self.assertEqual("01011", decode.read_reg_2)