1 from openpower
.consts
import FastRegsEnum
2 from openpower
.decoder
.power_enums
import SPRfull
as SPR
, spr_dict
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
: FastRegsEnum
.CTR
,
7 SPR
.LR
: FastRegsEnum
.LR
,
8 SPR
.TAR
: FastRegsEnum
.TAR
,
9 SPR
.SRR0
: FastRegsEnum
.SRR0
,
10 SPR
.SRR1
: FastRegsEnum
.SRR1
,
11 SPR
.XER
: FastRegsEnum
.XER
,
12 SPR
.DEC
: FastRegsEnum
.DEC
,
13 SPR
.TB
: FastRegsEnum
.TB
,
18 for (k
, v
) in spr_to_fast
.items():
19 sprstr_to_fast
[k
.name
] = v
22 def fast_reg_to_spr(spr_num
):
23 return fast_to_spr
[spr_num
].value
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)
32 def slow_reg_to_spr(slow_reg
):
33 for i
, x
in enumerate(SPR
):
38 def spr_to_slow_reg(spr_num
):
39 for i
, x
in enumerate(SPR
):
40 if spr_num
== x
.value
:
44 # TODO: make this a util routine (somewhere)
45 def mask_extend(x
, nbits
, repeat
):
47 extended
= (1<<repeat
)-1
48 for i
in range(nbits
):
50 res |
= extended
<< (i
*repeat
)