--- /dev/null
+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()