Implementation

class Helper:
    def __init__(self, XLEN):
        self.XLEN = XLEN

    def EXTSXL(self, value, bits):
        bits = min(bits, self.XLEN) # strangely this is redundant
        return SelectableInt(exts(value.value, bits), self.XLEN)

Table

func pcode
extsb RA <- EXTSX(RS, 8)
extsh RA <- EXTSX(RS, 16)
extsw RA <- EXTSX(RS, 32)

Examples in tabular form

these should contain desired and expected answers, not what the code says "this is the answer if you run this code on these values". They are also CSV files which the openpower-isa unit tests can run to confirm the implementation is correct.

0xA000000090000A93

func XLEN=64 XLEN=32 XLEN=16 XLEN=8
extsb 0xFFFFFFFFFFFFFF93 0xFFFFFF93 0xFF93 0x93
extsh 0x0000000000000A93 0x00000A93 0x0A93 0x93
extsw 0xFFFFFFFF90000A93 0x90000A93 0x0A93 0x93

Direct data download

0x0000000090000A93

func XLEN=64 XLEN=32 XLEN=16 XLEN=8
extsb 0xFFFFFFFFFFFFFF93 0xFFFFFF93 0xFF93 0x93
extsh 0x0000000000000A93 0x00000A93 0x0A93 0x93
extsw 0xFFFFFFFF90000A93 0x90000A93 0x0A93 0x93

Direct data download

0x000000000000F074

func XLEN=64 XLEN=32 XLEN=16 XLEN=8
extsb 0x0000000000000074 0x00000074 0x0074 0x74
extsh 0xFFFFFFFFFFFFF074 0xFFFFF074 0xF074 0x74
extsw 0x000000000000F074 0x0000F074 0xF074 0x74

Direct data download

0x0000000000000091

func XLEN=64 XLEN=32 XLEN=16 XLEN=8
extsb 0xFFFFFFFFFFFFFF91 0xFFFFFF91 0xFF91 0x91
extsh 0x0000000000000091 0x00000091 0x0091 0x91
extsw 0x0000000000000091 0x00000091 0x0091 0x91

Direct data download

0x9999999999999999

func XLEN=64 XLEN=32 XLEN=16 XLEN=8
extsb 0xFFFFFFFFFFFFFF99 0xFFFFFF99 0xFF99 0x99
extsh 0xFFFFFFFFFFFF9999 0xFFFF9999 0x9999 0x99
extsw 0xFFFFFFFF99999999 0x99999999 0x9999 0x99

Direct data download

0x1111111111111111

func XLEN=64 XLEN=32 XLEN=16 XLEN=8
extsb 0x0000000000000011 0x00000011 0x0011 0x11
extsh 0x0000000000001111 0x00001111 0x1111 0x11
extsw 0x0000000011111111 0x11111111 0x1111 0x11

Direct data download

Examples

for xlen in (8, 16, 32, 64):
    helper = Helper(xlen)
    REG = lambda v: SelectableInt(v, xlen)

    assert helper.EXTSXL(REG(0xA000000090000A93), 64) == REG(0xA000000090000a93)
    assert helper.EXTSXL(REG(0x0000000090000A93), 32) == REG(0xffffffff90000a93)
    assert helper.EXTSXL(REG(0x000000000000F074), 16) == REG(0xfffffffffffff074)
    assert helper.EXTSXL(REG(0x0000000000000091),  8) == REG(0xffffffffffffff91)

    assert helper.EXTSXL(REG(0x7000000090000A93), 64) == REG(0x7000000090000a93)
    assert helper.EXTSXL(REG(0x0000000050000A93), 32) == REG(0x50000a93)
    assert helper.EXTSXL(REG(0x0000000000001074), 16) == REG(0x1074)
    assert helper.EXTSXL(REG(0x0000000000000031),  8) == REG(0x31)

    assert helper.EXTSXL(REG(0xA000000090000A93), 64) == REG(0xA000000090000a93)
    assert helper.EXTSXL(REG(0x0000000090000A93), 64) == REG(0x90000a93)
    assert helper.EXTSXL(REG(0x000000000000F074), 32) == REG(0xf074)
    assert helper.EXTSXL(REG(0x0000000000000091), 16) == REG(0x91)

    assert helper.EXTSXL(REG(0x9999999999999999), 64) == REG(0x9999999999999999)
    assert helper.EXTSXL(REG(0x9999999999999999), 32) == REG(0xFFFFFFFF99999999)
    assert helper.EXTSXL(REG(0x9999999999999999), 16) == REG(0xFFFFFFFFFFFF9999)
    assert helper.EXTSXL(REG(0x9999999999999999),  8) == REG(0xFFFFFFFFFFFFFF99)