1 from nmigen
import Module
, Elaboratable
, Signal
4 from enum
import Enum
, unique
14 class InternalOp(Enum
):
63 # names of the fields in major.csv that don't correspond to an enum
64 single_bit_flags
= ['CR in', 'CR out', 'inv A', 'inv out', 'cry in',
65 'cry out', 'BR', 'sgn ext', 'upd', 'rsrv', '32b',
66 'sgn', 'lk', 'sgl pipe']
69 def get_signal_name(name
):
70 return name
.lower().replace(' ', '_')
74 file_dir
= os
.path
.dirname(os
.path
.realpath(__file__
))
75 with
open(os
.path
.join(file_dir
, name
)) as csvfile
:
76 reader
= csv
.DictReader(csvfile
)
80 major_opcodes
= get_csv("major.csv")
83 class PowerMajorDecoder(Elaboratable
):
85 self
.opcode_in
= Signal(6, reset_less
=True)
87 self
.function_unit
= Signal(Function
, reset_less
=True)
88 self
.internal_op
= Signal(InternalOp
, reset_less
=True)
89 self
.in1_sel
= Signal(In1Sel
, reset_less
=True)
90 self
.in2_sel
= Signal(In2Sel
, reset_less
=True)
91 self
.in3_sel
= Signal(In3Sel
, reset_less
=True)
92 self
.out_sel
= Signal(OutSel
, reset_less
=True)
93 for bit
in single_bit_flags
:
94 name
= get_signal_name(bit
)
96 Signal(reset_less
=True, name
=name
))
98 def elaborate(self
, platform
):
102 with m
.Switch(self
.opcode_in
):
103 for row
in major_opcodes
:
104 opcode
= int(row
['opcode'])
106 comb
+= self
.function_unit
.eq(Function
[row
['unit']])
107 comb
+= self
.internal_op
.eq(InternalOp
[row
['internal op']])
108 comb
+= self
.in1_sel
.eq(In1Sel
[row
['in1']])
109 comb
+= self
.in2_sel
.eq(In2Sel
[row
['in2']])
110 comb
+= self
.in3_sel
.eq(In3Sel
[row
['in3']])
111 comb
+= self
.out_sel
.eq(OutSel
[row
['out']])
112 for bit
in single_bit_flags
:
113 sig
= getattr(self
, get_signal_name(bit
))
114 comb
+= sig
.eq(int(row
[bit
]))
118 regular
=[self
.opcode_in
,
125 single_bit_ports
= [getattr(self
, get_signal_name(x
))
126 for x
in single_bit_flags
]
127 return regular
+ single_bit_ports