From 512cd83627c9827b6af1e8788d9451316c778836 Mon Sep 17 00:00:00 2001 From: Michael Nolan Date: Mon, 30 Mar 2020 19:15:03 -0400 Subject: [PATCH] Begin adding helper functions for PPC pseudocode compiler --- src/soc/decoder/helpers.py | 49 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/soc/decoder/helpers.py diff --git a/src/soc/decoder/helpers.py b/src/soc/decoder/helpers.py new file mode 100644 index 00000000..a3fbd1db --- /dev/null +++ b/src/soc/decoder/helpers.py @@ -0,0 +1,49 @@ +import unittest +def exts(value, bits): + sign = 1 << (bits - 1) + return (value * (sign - 1)) - (value * sign) + +def EXTS64(value): + return exts(value, 64) & ((1<<64)-1) + +def ROTL64(value, bits): + mask = (1 << 64) - 1 + bits = bits & 63 + return ((value << bits) | (value >> (64-bits))) & mask + +def mask(x, y): + if x < y: + x = 64-x + y = 63-y + mask_a = ((1<