if p1&~p2: o3 |= a3b2[7:0]
if p2: o3 |= a3b3[7:0]
+Code that prints the above:
+
+ def decoderange(col, k):
+ xs = (col-k)*8
+ return "%d:%d" % (xs+7, xs)
+
+ def decodelist(l):
+ res = []
+ for (idx, sgn) in l:
+ sgn = " " if sgn else "~"
+ res.append("%sp%d" % (sgn, idx))
+ return '&'.join(res)
+
+ N = 4
+ M = 4
+
+ for col in range(M):
+ r = decoderange(col, 0)
+ print "if True: o%d = a0b0[%s]" % (col, r)
+ for i in range(1,col+1):
+ l = []
+ for j in range(i):
+ l.append([j, False])
+ k = 0
+ s = decodelist(l)
+ r = decoderange(col, i)
+ print "if %s: o%d |= a%db%d[%s]" % (s, col, i, k, r)
+ k += 1
+ while l:
+ l[0][1] = True
+ s = decodelist(l)
+ r = decoderange(col, i)
+ print "if %s: o%d |= a%db%d[%s]" % (s, col, i, k, r)
+ k += 1
+ del l[0]
+ print
+
## Note
One important part to remember is that the upper bits of the shift amount need to specifically *ignored* rather than assuming that they are zeros, this is because, for shift instructions: `a << b` actually is `a << (b % bit_len(a))`