1 from collections
import OrderedDict
2 from openpower
.decoder
.power_fields
import DecodeFields
3 from nmigen
import Module
, Elaboratable
, Signal
, Cat
4 from nmigen
.cli
import rtlil
5 from copy
import deepcopy
7 from openpower
.decoder
.selectable_int
import BitRange
10 class SignalBitRange(BitRange
):
11 def __init__(self
, signal
):
12 BitRange
.__init
__(self
)
15 def __deepcopy__(self
, memo
):
16 signal
= deepcopy(self
.signal
, memo
)
17 retval
= SignalBitRange(signal
=signal
)
18 for k
, v
in self
.items():
25 width
= self
.signal
.width
28 def __getitem__(self
, subs
):
29 # *sigh* field numberings are bit-inverted. PowerISA 3.0B section 1.3.2
30 if isinstance(subs
, slice):
32 start
, stop
, step
= subs
.start
, subs
.stop
, subs
.step
40 start
= len(self
) + start
+ 1
42 stop
= len(self
) + stop
+ 1
43 for t
in range(start
, stop
, step
):
44 t
= len(self
) - 1 - t
# invert field back
45 k
= OrderedDict
.__getitem
__(self
, t
)
46 res
.append(self
.signal
[self
._rev
(k
)]) # reverse-order here
50 subs
= len(self
) + subs
51 subs
= len(self
) - 1 - subs
# invert field back
52 k
= OrderedDict
.__getitem
__(self
, subs
)
53 return self
.signal
[self
._rev
(k
)] # reverse-order here
56 class SigDecode(Elaboratable
):
58 def __init__(self
, width
):
59 self
.opcode_in
= Signal(width
, reset_less
=False)
60 self
.df
= DecodeFields(SignalBitRange
, [self
.opcode_in
])
61 self
.df
.create_specs()
63 def elaborate(self
, platform
):
69 return [self
.opcode_in
]
72 def create_sigdecode():
77 if __name__
== '__main__':
78 sigdecode
= create_sigdecode()
79 vl
= rtlil
.convert(sigdecode
, ports
=sigdecode
.ports())
80 with
open("decoder.il", "w") as f
: