From 9d20ba215073133be57d80c8fcfbf4db564e6302 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Wed, 22 Jun 2022 12:51:11 +0100 Subject: [PATCH] add experimental bmask demo --- openpower/sv/bmask.py | 47 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 openpower/sv/bmask.py diff --git a/openpower/sv/bmask.py b/openpower/sv/bmask.py new file mode 100644 index 000000000..4b431837c --- /dev/null +++ b/openpower/sv/bmask.py @@ -0,0 +1,47 @@ +def bmask(mode, RA, RB=None, zero=False): + RT = RA if RB is not None and not zero else 0 + mask = RB if RB is not None else 0xffffffffffffffff + a1 = RA if mode&1 else ~RA + mode2 = (mode >> 1) & 0b11 + if mode2 == 0: + a2 = -RA + if mode2 == 1: + a2 = RA-1 + if mode2 == 2: + a2 = RA+1 + if mode2 == 3: + a2 = ~(RA+1) + a1 = a1 & mask + a2 = a2 & mask + mode3 = (mode >> 3) & 0b11 + if mode3 == 0: + RT = a1 | a2 + if mode3 == 1: + RT = a1 & a2 + if mode3 == 2: + RT = a1 ^ a2 + return RT & mask + +SBF = 0b001110 + +if __name__ == '__main__': + for SBF in range(32): + print("mode", bin(SBF)) + m = 0b11000011 + v3 = 0b10010100 # vmsbf.m v2, v3 + v2 = 0b01000011 # v2 + RT = bmask(SBF, v3, m, zero=True) + print(bin(v3), bin(v2), bin(RT)) + v3 = 0b10010100 # vmsbf.m v2, v3 + v2 = 0b00000011 # v2 contents + RT = bmask(SBF, v3) + print(bin(v3), bin(v2), bin(RT)) + v3 = 0b10010101 # vmsbf.m v2, v3 + v2 = 0b00000000 # v2 + RT = bmask(SBF, v3) + print(bin(v3), bin(v2), bin(RT)) + v3 = 0b00000000 # vmsbf.m v2, v3 + v2 = 0b11111111 # v2 + RT = bmask(SBF, v3) + print(bin(v3), bin(v2), bin(RT)) + print() -- 2.30.2