move over to from openpower imports
[soc.git] / src / soc / regfile / util.py
1 from soc.regfile.regfiles import FastRegs
2 from openpower.decoder.power_enums import SPRfull as SPR, spr_dict
3
4 # note that we can get away with using SPRfull here because the values
5 # (numerical values) are what is used for lookup.
6 spr_to_fast = { SPR.CTR: FastRegs.CTR,
7 SPR.LR: FastRegs.LR,
8 SPR.TAR: FastRegs.TAR,
9 SPR.SRR0: FastRegs.SRR0,
10 SPR.SRR1: FastRegs.SRR1,
11 SPR.XER: FastRegs.XER,
12 SPR.DEC: FastRegs.DEC,
13 SPR.TB: FastRegs.TB,
14 }
15
16 sprstr_to_fast = {}
17 fast_to_spr = {}
18 for (k, v) in spr_to_fast.items():
19 sprstr_to_fast[k.name] = v
20 fast_to_spr[v] = k
21
22 def fast_reg_to_spr(spr_num):
23 return fast_to_spr[spr_num].value
24
25
26 def spr_to_fast_reg(spr_num):
27 if not isinstance(spr_num, str):
28 spr_num = spr_dict[spr_num].SPR
29 return sprstr_to_fast.get(spr_num, None)
30
31
32 def slow_reg_to_spr(slow_reg):
33 for i, x in enumerate(SPR):
34 if slow_reg == i:
35 return x.value
36
37
38 def spr_to_slow_reg(spr_num):
39 for i, x in enumerate(SPR):
40 if spr_num == x.value:
41 return i