-
Notifications
You must be signed in to change notification settings - Fork 0
/
ata.py
117 lines (86 loc) · 2.89 KB
/
ata.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
from typing import Union
from enum import Enum
from abc import ABC, abstractmethod
from atmi import ATMI
class OpInput:
pass
class FUinput:
# TODO: make sure this num value doesn't go out of range
def __init__(self, num: int):
self.num: int = num
class RFInput:
pass
class ATAI(ABC):
def __init__(self, cycle: int):
self.cycle: int = cycle
def __lt__(self, other):
return self.cycle < other.cycle
@abstractmethod
def to_atmi(self, rf_depth: int, input_ports: int) -> ATMI:
pass
class ATAFetch(ATAI):
class REG(Enum):
REG0 = 0
REG1 = 1
def __init__(self, addr: int, reg: REG, cycle: int):
super().__init__(cycle)
self.addr: int = addr
self.reg: ATAFetch.REG = reg
def to_atmi(self, rf_depth: int, input_ports: int) -> ATMI:
# TODO: Don't hardcode these parameters
atmi = ATMI(rf_depth, input_ports)
atmi.cycle = self.cycle
if self.reg == ATAFetch.REG.REG0:
atmi.r_reg0_s = self.addr
else:
atmi.r_reg1_s = self.addr
atmi.insts['Fetch'] = 1
return atmi
class ATAStore(ATAI):
def __init__(self,
inp: Union[FUinput, OpInput],
addr: int,
cycle: int):
super().__init__(cycle)
self.input: Union[FUinput, OpInput] = inp
self.addr: int = addr
def to_atmi(self, rf_depth: int, input_ports: int) -> ATMI:
# TODO: Don't hardcode these parameters
atmi = ATMI(rf_depth, input_ports)
atmi.cycle = self.cycle
if type(self.input) == FUinput:
atmi.cbOut2 = self.input.num
atmi.reg0 = True
atmi.w_reg0_s = self.addr
else:
atmi.reg1 = True
atmi.w_reg1_s = self.addr
atmi.insts['Store'] = 1
return atmi
class ATAOp(ATAI):
def __init__(self, input0: Union[FUinput, OpInput, RFInput], input1: Union[FUinput, OpInput, RFInput], cycle: int):
super().__init__(cycle)
self.input0: Union[FUinput, OpInput, RFInput] = input0
self.input1: Union[FUinput, OpInput, RFInput] = input1
def to_atmi(self, rf_depth: int, input_ports: int) -> ATMI:
# TODO: Don't hardcode these parameters
atmi = ATMI(rf_depth, input_ports)
atmi.cycle = self.cycle
type0 = type(self.input0)
type1 = type(self.input1)
if type0 == FUinput:
atmi.muxa = atmi.MuxA.FU
atmi.cbOut0 = self.input0.num
elif type0 == OpInput:
atmi.muxa = atmi.MuxA.OP
else:
atmi.muxa = atmi.MuxA.RF
if type1 == FUinput:
atmi.muxb = atmi.MuxB.FU
atmi.cbOut1 = self.input1.num
elif type1 == OpInput:
atmi.muxb = atmi.MuxB.OP
else:
atmi.muxb = atmi.MuxB.RF
atmi.insts['Op'] = 1
return atmi