Exemple #1
0
 def test_without_branch(self):
     text = '''00100000010000100000000000000101 ; I1: addi R2,R2,5
               00100000001000010000000000001010 ; I2: addi R1,R1,10
               00011100001000100000000000000100 ; I3: ble R1,R2,4
               00100000001000010000000001000000 ; I4: addi R1,R1,64'''
     mips = Mips(text)
     mips.run()
     self.assertEqual(mips.registers[1], 74)
Exemple #2
0
class TestEmptyPipelineUntilRunning(unittest.TestCase):
    def setUp(self):
        text = """00000000000000000000000000000000 ; I1: nop
                  00000000000000000000000000000000 ; I2: nop"""
        self.mips = Mips(text)
        
    def test_run(self):
        self.mips.run()
        self.assertEqual(self.mips.clock, 7)
Exemple #3
0
def execution():
    text = request.POST.get("text")
    data_forwarding = bool(int(request.POST.get("data_forwarding", 0)))

    if text:
        mips = Mips(text, data_forwarding=data_forwarding)
        mips.run()
        return {"text":text, "result":mips.history}
        
    return {"error":"INVALID_TEXT"}
Exemple #4
0
 def test_if_example_with_beq_false(self):
     text = """00100000000000010000000000000011 ; I1: addi R1,R0,3
               00100000000000100000000000000010 ; I2: addi R2,R0,2
               00010100001000100000000000000000 ; I3: beq R1,R2,0
               00001000000000000000000000011000 ; I4: jmp 24
               00100000000000010000000000000101 ; I5: addi R1,R0,5
               00001000000000000000000000011100 ; I6: jmp 28
               00100000000000010000000000000111 ; I7: addi R1,R0,7"""
     mips = Mips(text)
     mips.run()
     self.assertEqual(mips.registers[1], 7)
Exemple #5
0
 def test_project_example(self):
     text = """00100000000010100000000001100100 ; I1: addi R10,R0,100
               10101100000000000000000000011000 ; I2: sw R0,24(R0)
               10101100000000000000000000011100 ; I3: sw R0,28(R0)
               10001100000001100000000000011100 ; I4: lw R6,28(R0)
               00000000110001100011100000011000 ; I5: mul R7,R6,R6
               10001100000000010000000000011000 ; I6: lw R1,24(R0)
               00000000001001110100100000100000 ; I7: add R9,R1,R7
               10101100000010010000000000011000 ; I8: sw R9,24(R0)
               00100000110001100000000000000001 ; I9: addi R6,R6,1
               10101100000001100000000000011100 ; I10: sw R6,28(R0)
               00011100110010100000000000001100 ; I11: ble R6,R10,12"""
     mips = Mips(text)
     mips.run()
     self.assertEqual(mips.memory[24], 338350)
Exemple #6
0
 def test_beq_jump(self):
     """
     LABEL:
     addi R1,R0,2
     add R2,R1,R3
     beq R1,R2,LABEL
     """
     text = """00100000000000010000000000000010 ; I1: addi R1,R0,2
               00000000001000110001000000100000 ; I2: add R2,R1,R3
               00010100001000101111111111111000 ; I3: beq R1,R2,-8"""
     mips = Mips(text)
     for i in range(11):
         mips.execute_pipeline()
     self.assertTrue(isinstance(mips.pipeline[2].instruction, BeqInstruction))
     mips.execute_pipeline()
     print [i.instruction for i in mips.pipeline]
Exemple #7
0
class TestMipsPipelineSteps(unittest.TestCase):
    def setUp(self):
        self.mips = Mips()
        self.add = Instruction('00000000001001110100100000100000 ; I1: add R9,R1,R7')
        self.addi = Instruction('00100000000010100000000001100100 ; I2: addi R10,R0,100')
        
    def test_an_intermediary_step(self):
        self.add.instruction_decode(self.mips)
        self.add.execute(self.mips)
        self.addi.instruction_decode(self.mips)

        self.mips.pipeline[2].instruction = self.addi
        self.mips.pipeline[3].instruction = self.add
        self.mips.execute_pipeline()
        self.assertEqual(self.mips.pipeline[2].instruction, self.addi)
        self.assertTrue(self.mips.pipeline[2].done)
        self.assertEqual(self.mips.pipeline[3].instruction, self.add)
        self.assertTrue(self.mips.pipeline[3].done)
Exemple #8
0
 def setUp(self):
     self.mips = Mips()
     self.mips.pipeline[0].instruction = NopInstruction()
     self.mips.pipeline[0].done = True
     self.mips.pipeline[1].instruction = NopInstruction()
     self.mips.pipeline[1].done = True
     self.mips.pipeline[2].instruction = NopInstruction()
     self.mips.pipeline[2].done = False
     self.mips.pipeline[3].instruction = NopInstruction()
     self.mips.pipeline[3].done = True
Exemple #9
0
class TestGoForwardPipeline(unittest.TestCase):
    def setUp(self):
        self.mips = Mips()
        self.mips.pipeline[0].instruction = NopInstruction()
        self.mips.pipeline[0].done = True
        self.mips.pipeline[1].instruction = NopInstruction()
        self.mips.pipeline[1].done = True
        self.mips.pipeline[2].instruction = NopInstruction()
        self.mips.pipeline[2].done = False
        self.mips.pipeline[3].instruction = NopInstruction()
        self.mips.pipeline[3].done = True
        
    def test_bubble_problems(self):
        self.mips._go_forward_pipeline()
        self.assertTrue(isinstance(self.mips.pipeline[0].instruction, NopInstruction))
        self.assertTrue(isinstance(self.mips.pipeline[1].instruction, NopInstruction))
        self.assertTrue(isinstance(self.mips.pipeline[2].instruction, NopInstruction))
        self.assertTrue(self.mips.pipeline[3].instruction is None)
        self.assertTrue(isinstance(self.mips.pipeline[4].instruction, NopInstruction))
Exemple #10
0
def execution():
    text = request.POST.get("text")

    if text:
        slower_mips = Mips(text, data_forwarding=False)
        slower_mips.run()
        slower_mips_state = slower_mips.current_state()

        faster_mips = Mips(text, data_forwarding=True)
        faster_mips.run()
        faster_mips_state = faster_mips.current_state()

        return {"text":text,
                "slower_mips":{"clocks":slower_mips_state["clock"],
                               "throughput":slower_mips_state["throughput"]},
                "faster_mips":{"clocks":faster_mips_state["clock"],
                               "throughput":faster_mips_state["throughput"]}}

    return {"error":"INVALID_TEXT"}
Exemple #11
0
def Top(clk,
        reset,
        writedata,
        daddr,
        memwrite,
        ROM,
        dmem_depth=64,
        word_size=32):

    pc = Signal(modbv(0)[word_size:])
    instr = Signal(modbv(0)[word_size:])
    readdata = Signal(modbv(0)[word_size:])

    mips_inst = Mips(clk, reset, pc, instr, memwrite, daddr, writedata,
                     readdata)
    imem_inst = Imem(pc(8, 2), instr, ROM)
    dmem_inst = Dmem(clk, memwrite, daddr, writedata, readdata, dmem_depth)

    return instances()
Exemple #12
0
class TestMips(unittest.TestCase):
    def setUp(self):
        text = """00000000001001110100100000100000 ; I1: add R9,R1,R7
                  00000000000000010001000000011000 ; I2: mul R2,R0,R1
                  00100000000010100000000001100100 ; I3: addi R10,R0,100"""
        self.mips = Mips(text)

    def test_first_step(self):
        self.mips.execute_pipeline()
        self.assertTrue(isinstance(self.mips.pipeline[0].instruction, AddInstruction))
        
    def test_mul_blocking(self):
        self.mips.execute_pipeline()
        self.mips.execute_pipeline()
        self.mips.execute_pipeline()
        self.mips.execute_pipeline()
        self.assertTrue(isinstance(self.mips.pipeline[1].instruction, AddiInstruction))
        self.assertTrue(isinstance(self.mips.pipeline[2].instruction, MulInstruction))
        self.assertTrue(isinstance(self.mips.pipeline[3].instruction, AddInstruction))
        self.mips.execute_pipeline()
        self.assertTrue(isinstance(self.mips.pipeline[1].instruction, AddiInstruction))
        self.assertTrue(isinstance(self.mips.pipeline[2].instruction, MulInstruction))
        self.assertTrue(isinstance(self.mips.pipeline[4].instruction, AddInstruction))
Exemple #13
0
from mips_cli import MipsCli
from mips import Mips
import serial
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("dev")
args = parser.parse_args()

ser = serial.Serial(args.dev)
ser.reset_input_buffer()
ser.reset_output_buffer()

mips = Mips(ser)
cli = MipsCli(mips)
cli.cmdloop()
Exemple #14
0
class TestDataForwarding(unittest.TestCase):
    def setUp(self):
        text = """00100000000000010000000000000011 ; I1: addi R1,R0,3
                  00100000001000100000000000000010 ; I2: addi R2,R1,2"""
        self.mips = Mips(text)
        
    def test_without_data_forwarding(self):
        self.mips.data_forwarding = False
        self.mips.execute_pipeline()
        self.mips.execute_pipeline()
        self.mips.execute_pipeline()
        self.assertTrue(isinstance(self.mips.pipeline[1].instruction, AddiInstruction))
        self.assertTrue(isinstance(self.mips.pipeline[2].instruction, AddiInstruction))
        self.mips.execute_pipeline()
        self.mips.execute_pipeline()
        self.assertTrue(isinstance(self.mips.pipeline[1].instruction, AddiInstruction))
        self.assertTrue(isinstance(self.mips.pipeline[4].instruction, AddiInstruction))
        self.mips.execute_pipeline()
        self.assertTrue(isinstance(self.mips.pipeline[1].instruction, AddiInstruction))
        self.mips.execute_pipeline()
        self.assertTrue(isinstance(self.mips.pipeline[2].instruction, AddiInstruction))

    def test_without_data_forwarding(self):
        self.mips.data_forwarding = True
        self.mips.execute_pipeline()
        self.mips.execute_pipeline()
        self.mips.execute_pipeline()
        self.assertTrue(isinstance(self.mips.pipeline[1].instruction, AddiInstruction))
        self.assertTrue(isinstance(self.mips.pipeline[2].instruction, AddiInstruction))
        self.mips.execute_pipeline()
        self.assertTrue(isinstance(self.mips.pipeline[1].instruction, AddiInstruction))
        self.assertTrue(isinstance(self.mips.pipeline[3].instruction, AddiInstruction))
        self.mips.execute_pipeline()
        self.assertTrue(isinstance(self.mips.pipeline[2].instruction, AddiInstruction))
        self.assertTrue(isinstance(self.mips.pipeline[4].instruction, AddiInstruction))
        self.mips.execute_pipeline()
        self.assertTrue(isinstance(self.mips.pipeline[3].instruction, AddiInstruction))
Exemple #15
0
 def setUp(self):
     text = """00100000000000010000000000000011 ; I1: addi R1,R0,3
               00100000001000100000000000000010 ; I2: addi R2,R1,2"""
     self.mips = Mips(text)
Exemple #16
0
 def setUp(self):
     text = """00000000000000000000000000000000 ; I1: nop
               00000000000000000000000000000000 ; I2: nop"""
     self.mips = Mips(text)
Exemple #17
0
 def setUp(self):
     self.mips = Mips()
     self.add = Instruction('00000000001001110100100000100000 ; I1: add R9,R1,R7')
     self.addi = Instruction('00100000000010100000000001100100 ; I2: addi R10,R0,100')
Exemple #18
0
 def setUp(self):
     text = """00000000001001110100100000100000 ; I1: add R9,R1,R7
               00000000000000010001000000011000 ; I2: mul R2,R0,R1
               00100000000010100000000001100100 ; I3: addi R10,R0,100"""
     self.mips = Mips(text)