From: Jacob Lifshay Date: Fri, 23 Sep 2022 03:05:35 +0000 (-0700) Subject: add pcdec -- doesn't yet work due to broken ISACaller RT/RS output handling X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=5b122788a7f96555bbf5ae8ed3d18703f175588f;p=openpower-isa.git add pcdec -- doesn't yet work due to broken ISACaller RT/RS output handling --- 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)