Skip to content

Commit 5f377c9

Browse files
committed
fixes
1 parent 36758f4 commit 5f377c9

File tree

12 files changed

+103
-31
lines changed

12 files changed

+103
-31
lines changed

main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from unit_tests import test_codes
77

88
if __name__ == '__main__':
9-
for test_case in [0]:
9+
for test_case in [1]:
1010
print()
1111
str_result = f"Running Test Case {test_case}...\n"
1212
code = test_codes[test_case]

requirements.txt

-1
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
python-docx

src/computation_units/memory.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,10 @@ def print_str_tables(self):
155155
if v != 0:
156156
i_str = f"{i * 4}".zfill(math.ceil(math.log10(len(self.data) * 4)))
157157
v_str = v if v == int(v) else f"{v:0.2f}"
158-
str_result += f"{i_str}: {v_str}".ljust(10)
158+
str_result += f"{i_str}: {v_str}".ljust(14)
159159
count += 1
160160

161-
if count % 16 == 0:
161+
if count % 12 == 0:
162162
str_result += "\n"
163163

164164
str_result += "\n"

src/instruction/instruction.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ def print_str_instructions(instructions: List[Instruction]):
9797
"Instruction",
9898
*StageEvent.rows,
9999
"Result",
100+
"Prediction",
100101
"Operands",
101102
]
102103
]
@@ -109,7 +110,8 @@ def print_str_instructions(instructions: List[Instruction]):
109110
v.index,
110111
v.instruction,
111112
*v.stage_event.print_str(),
112-
v.result,
113+
v.result if not isinstance(v.result, float) else f"{v.result:.4f}",
114+
v.related_data["branch_jump"] if v.type is InstructionType.BNE else "",
113115
v.operands if v.execution else "",
114116
]
115117
strike_row.append(v.execution)
@@ -120,7 +122,7 @@ def print_str_instructions(instructions: List[Instruction]):
120122
for i in rows:
121123
for j, v in enumerate(i):
122124
if lengths[j] < len(str(v)):
123-
lengths[j] = len(str(v)) + 6
125+
lengths[j] = len(str(v)) + 5
124126

125127
lengths[0] = 2
126128
lengths[rows[0].index("Instruction")] += 6

src/tomasulo.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -216,14 +216,15 @@ def check_asserts(self) -> Tuple[bool, List[AssertResult]]:
216216

217217
if value is None:
218218
value = self.rat.get(check_key, raise_error=False)
219-
if value is None:
220-
value = self.memory_unit.get_value(check_key)
219+
if value is None and "mem[" in check_key.lower():
220+
key = int(check_key.lower()[4:-1])
221+
value = self.memory_unit.get_value(key)
221222

222223
append_value = AssertResult(
223-
result=check_value == str(value),
224+
result=f"{float(check_value):.4f}" == f"{value:.4f}",
224225
key=check_key,
225226
check_value=check_value,
226-
value=str(value)
227+
value=f"{value:.4f}" if isinstance(value, float) else str(value)
227228
)
228229
assert_list.append(append_value)
229230
return all(i.result for i in assert_list), assert_list

unit_tests/test_0.txt

+11
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,14 @@ SUBI R4, R4, 1
1313
LD R3, 4(R0)
1414
SD R3, 4(R0)
1515

16+
17+
$ Mem[0] = 5
18+
19+
! R2 = 5
20+
21+
# THis is Test Case 1 for Functionality
22+
LD R1 0(R1)
23+
Loop1: ADDI R2, R2, 1
24+
BNE R1, R2, Loop1
25+
ADDI R1, R1, 5
26+

unit_tests/test_1.txt

+41-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,43 @@
1-
$ Mem[0] = 5
1+
# Straight-line base cases where no dependencies exist among instructions
22

3-
! R2 = 5
3+
$ Mem[4] = 2.3
44

5-
# THis is Test Case 1 for Functionality
6-
LD R1 0(R1)
7-
Loop1: ADDI R2, R2, 1
8-
BNE R1, R2, Loop1
9-
ADDI R1, R1, 5
5+
$ R1 = 4
6+
$ R2 = 20
7+
$ R3 = 12
8+
$ R4 = 9
9+
$ R5 = 13
10+
$ R6 = 8
11+
$ R7 = 5
12+
$ R8 = 9
13+
14+
$ F2 = 7.3
15+
$ F3 = 1.8
16+
$ F4 = 3.5
17+
$ F5 = 4.6
18+
$ F6 = 4.5
19+
$ F7 = 1.5
20+
$ F8 = 2.5
21+
22+
! F1 = 2.3
23+
! MEM[20] = 7.3
24+
! R9 = 21
25+
! R10 = 5
26+
! R11 = 3
27+
! R12 = 1
28+
! F9 = 5.3
29+
! F10 = 0.1
30+
! F11 = 3.75
31+
32+
LD F1, 0 (R1)
33+
SD F2, 0 (R2)
34+
35+
ADD R9, R3, R4
36+
ADDI R10, R5, -8
37+
SUB R11, R6, R7
38+
SUBI R12, R8, 8
39+
40+
ADDD F9, F3, F4
41+
SUBD F10, F5, F6
42+
43+
MULTD F11, F7, F8

unit_tests/test_2.txt

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
# Straight-line code where there are dependencies (true and false)
12

3+
$F4 = 8.14
4+
$F3 = 6.86
5+
$R1 = 4
26

3-
4-
# Straight-line code where there are dependencies (true and false)
57
LD F0, 0 (R1)
6-
DIVD F2, F0, F4
8+
MULTD F2, F0, F4
79
ADDD F1, F0, F3
810

911
#Write-After-Read (WAR: anti-dependence) on F3

unit_tests/test_3.txt

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
# straight-line code where there are forwarding among load/store instructions
22

3+
$ F2 = 10
4+
$ R1 = 4
5+
$ R2 = 8
6+
37
LD F4, 0(R1)
8+
#Get value from memory
49
MULTD F1, F4, F2
10+
SD F1, 0(R2)
511
LD F3, 0(R2)
6-
SUB F3, F1, F3
12+
#Get the calculated value of F1 due to SD instruction
13+
LD F5, 4(R2)
14+
#Get value from memory
15+
SUB F3, F3, F5
716
SD F3, 0(R2)
8-
ADDI R1, R1, 8
9-
ADDI R2, R2, 8
17+
LD F6, 0(R2)
18+
#Get the calculated value of F3 due to SD instruction
19+
MULTD F6, F6, F6
20+
SD F6, 0(R1)

unit_tests/test_4.txt

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
#straight-line code where there are structure hazards in reservation stations and functional unit
22

3+
$ F4 = 16.5
4+
$ F5 = 4.28
5+
$ F6 = 2.00
6+
37
LD F6, 0 (R1)
48
MULTD F2, F3, F4
59
MULTD F1, F5, F5
610
SD F2, 0(R2)
7-
DIVD F1, F1, F6
11+
MULTD F1, F1, F6
12+
# 2 reservation stations for FP multiplier, 3rd MULTD must wait
813
ADDD F5, F4, F1
914
SD F5, 0(R1)

unit_tests/test_5.txt

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
# simple loop on top of either 1), 2), 3), or 4), or all of them
22

3+
$ R1 = 4
4+
$ R2 = 12
5+
6+
#! cycle = 4
7+
38
Loop: LD F1, 0(R1)
49
LD F2, 0(R2)
5-
DIVD F3,F1,F2
10+
MULTD F3,F1,F2
611
ADDD F4,F1,F2
7-
SD F3, 3(R1)
8-
SD F4, 4(R1)
12+
SD F3, 4(R1)
13+
SD F4, 8(R1)
914
ADD R3,R2,R1
10-
SUBI R2,R2,-8
11-
BNE R2,R3, Loop
15+
SUBI R2,R2,4
16+
BNE R2,R1, Loop

unit_tests/test_6.txt

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
$R1 = 20
44
$R2 = 8
5-
$F3 = 10
5+
$F3 = 10.5
66

77
Loop: LD F1, 0(R1)
88
MULTD F2, F1, F3
99
ADDD F4, F1, F2
1010
ADDI R1, R1, -4
1111
BNE R1, R2, Loop
12+
1213
SUB F6, F4, F3
13-
SD F6, 0(R2)
14+
SD F6, 0(R2)
15+

0 commit comments

Comments
 (0)