2f1e52979d1b01b5eb1eadb79b3c6a116c274858
1 from nmigen
import Module
, Elaboratable
, Signal
4 from enum
import Enum
, unique
14 class InternalOp(Enum
):
85 # names of the fields in major.csv that don't correspond to an enum
86 single_bit_flags
= ['CR in', 'CR out', 'inv A', 'inv out',
87 'cry out', 'BR', 'sgn ext', 'upd', 'rsrv', '32b',
88 'sgn', 'lk', 'sgl pipe']
91 def get_signal_name(name
):
92 return name
.lower().replace(' ', '_')
96 file_dir
= os
.path
.dirname(os
.path
.realpath(__file__
))
97 with
open(os
.path
.join(file_dir
, name
)) as csvfile
:
98 reader
= csv
.DictReader(csvfile
)
102 major_opcodes
= get_csv("major.csv")
105 class PowerMajorDecoder(Elaboratable
):
107 self
.opcode_in
= Signal(6, reset_less
=True)
109 self
.function_unit
= Signal(Function
, reset_less
=True)
110 self
.internal_op
= Signal(InternalOp
, reset_less
=True)
111 self
.in1_sel
= Signal(In1Sel
, reset_less
=True)
112 self
.in2_sel
= Signal(In2Sel
, reset_less
=True)
113 self
.in3_sel
= Signal(In3Sel
, reset_less
=True)
114 self
.out_sel
= Signal(OutSel
, reset_less
=True)
115 self
.ldst_len
= Signal(LdstLen
, reset_less
=True)
116 self
.rc_sel
= Signal(RC
, reset_less
=True)
117 self
.cry_in
= Signal(CryIn
, reset_less
=True)
118 for bit
in single_bit_flags
:
119 name
= get_signal_name(bit
)
121 Signal(reset_less
=True, name
=name
))
123 def elaborate(self
, platform
):
127 with m
.Switch(self
.opcode_in
):
128 for row
in major_opcodes
:
129 opcode
= int(row
['opcode'])
131 comb
+= self
.function_unit
.eq(Function
[row
['unit']])
132 comb
+= self
.internal_op
.eq(InternalOp
[row
['internal op']])
133 comb
+= self
.in1_sel
.eq(In1Sel
[row
['in1']])
134 comb
+= self
.in2_sel
.eq(In2Sel
[row
['in2']])
135 comb
+= self
.in3_sel
.eq(In3Sel
[row
['in3']])
136 comb
+= self
.out_sel
.eq(OutSel
[row
['out']])
137 comb
+= self
.ldst_len
.eq(LdstLen
[row
['ldst len']])
138 comb
+= self
.rc_sel
.eq(RC
[row
['rc']])
139 comb
+= self
.cry_in
.eq(CryIn
[row
['cry in']])
140 for bit
in single_bit_flags
:
141 sig
= getattr(self
, get_signal_name(bit
))
142 comb
+= sig
.eq(int(row
[bit
]))
146 regular
=[self
.opcode_in
,
155 single_bit_ports
= [getattr(self
, get_signal_name(x
))
156 for x
in single_bit_flags
]
157 return regular
+ single_bit_ports