From: Luke Kenneth Casson Leighton Date: Wed, 22 Jun 2022 11:51:11 +0000 (+0100) Subject: add experimental bmask demo X-Git-Tag: opf_rfc_ls005_v1~1602 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=9d20ba215073133be57d80c8fcfbf4db564e6302;p=libreriscv.git add experimental bmask demo --- 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()