From 5b122788a7f96555bbf5ae8ed3d18703f175588f Mon Sep 17 00:00:00 2001 From: Jacob Lifshay Date: Thu, 22 Sep 2022 20:05:35 -0700 Subject: [PATCH] add pcdec -- doesn't yet work due to broken ISACaller RT/RS output handling --- openpower/isa/prefix_codes.mdwn | 52 +++++++++++++++++++ openpower/isatables/RM-1P-3S1D.csv | 2 + openpower/isatables/fields.text | 10 +++- openpower/isatables/minor_4.csv | 2 + src/openpower/decoder/isa/.gitignore | 1 + src/openpower/decoder/isa/caller.py | 2 +- .../decoder/isa/test_caller_prefix_codes.py | 25 +++++++++ src/openpower/decoder/power_enums.py | 2 + src/openpower/sv/sv_analysis.py | 5 ++ src/openpower/sv/trans/svp64.py | 19 +++++++ src/openpower/test/prefix_codes/__init__.py | 0 .../test/prefix_codes/prefix_codes_cases.py | 44 ++++++++++++++++ 12 files changed, 161 insertions(+), 3 deletions(-) create mode 100644 openpower/isa/prefix_codes.mdwn create mode 100644 src/openpower/decoder/isa/test_caller_prefix_codes.py create mode 100644 src/openpower/test/prefix_codes/__init__.py create mode 100644 src/openpower/test/prefix_codes/prefix_codes_cases.py diff --git a/openpower/isa/prefix_codes.mdwn b/openpower/isa/prefix_codes.mdwn new file mode 100644 index 00000000..f89570af --- /dev/null +++ b/openpower/isa/prefix_codes.mdwn @@ -0,0 +1,52 @@ + + +# [DRAFT] Prefix-code decode + +VA2-Form + +* pcdec RT,RA,RB,RC,once + +Pseudo-code: + + tree[0:63] <- (RA) + rb_used <- 0b0 + in_bits[0:63] <- (RC|0) + if in_bits = 0 then + in_bits[0:63] <- 1 + final_in_bits <- in_bits + final_rb_used <- rb_used + output <- [0] * 64 + out_byte <- 0 + decoded[0:7] <- 1 + so_bit <- 0b0 + do while out_byte < 8 + in_bit <- in_bits[63] + if in_bits = 1 then + if rb_used | (_RB = 0) then + leave + rb_used <- 0b1 + in_bit <- (RB)[63] + in_bits <- 0b1 || (RB)[0:62] + else + in_bits <- 0b0 || in_bits[0:62] + # walk the binary tree in `tree` from parent to the selected child + decoded <- decoded[1:7] || in_bit + if decoded int + retval = 1 + for bit in reversed(code): + assert bit in "01" + retval = retval * 2 + int(bit) + return retval + + +def make_tree(*codes): + # type: (*str) -> int + retval = 0 + for code in codes: + retval |= 1 << tree_code(code) + return retval + + +def code_seq(*codes, prefix1=False): + # type: (*str, bool) -> int + prefix = "0b1" if prefix1 else "0b" + return int(prefix + "".join(reversed(codes)), base=0) + + +class PrefixCodesCases(TestAccumulatorBase): + def case_pcdec_simple(self): + lst = list(SVP64Asm(["pcdec 4,6,7,5,0"])) + gprs = [0] * 32 + gpr5_codes = ["0", "11", "1001", "101010"] + gpr7_codes = ["1001"] * 8 + ["101010", "11"] * 4 + gprs[5] = code_seq(*gpr5_codes, prefix1=True) + gprs[6] = make_tree("0", "11", "1001", "101010") + gprs[7] = code_seq(*gpr7_codes) + e = ExpectedState(pc=4, int_regs=gprs) + e.intregs[4] = int.from_bytes( + map(tree_code, (gpr5_codes + gpr7_codes)[:8]), 'little') + e.intregs[5] = code_seq(*(gpr5_codes + gpr7_codes)[8:], prefix1=True) + e.crregs[0] = 0b1000 + self.add_case(Program(lst, False), gprs, expected=e) -- 2.30.2