2003-01-23 22:33:19 +00:00
|
|
|
from myhdl import Signal, intbv
|
|
|
|
|
|
|
|
from arith_utils import log2ceil
|
|
|
|
from arith_utils import SLOW, MEDIUM, FAST
|
|
|
|
|
|
|
|
def PrefixAnd(width, speed, PI, PO):
|
|
|
|
|
|
|
|
n = width
|
|
|
|
m = log2ceil(width)
|
|
|
|
|
|
|
|
def fastPrefix():
|
2005-10-22 19:19:39 +00:00
|
|
|
PT = Signal(intbv(0))
|
2003-01-23 22:33:19 +00:00
|
|
|
while 1:
|
|
|
|
yield PI, PT
|
2003-02-16 21:36:58 +00:00
|
|
|
PT.next[n:] = PI
|
2003-01-23 22:33:19 +00:00
|
|
|
for l in range(1, m+1):
|
|
|
|
for k in range(2**(m-l)):
|
|
|
|
for i in range(2**(l-1)):
|
|
|
|
if (k*2**l + i) < n:
|
|
|
|
PT.next[l*n + k*2**l + i] = \
|
2003-02-15 14:54:40 +00:00
|
|
|
PT[(l-1)*n + k*2**l + i]
|
2003-01-23 22:33:19 +00:00
|
|
|
if (k*2**l + 2**(l-1) + i) < n:
|
|
|
|
PT.next[l*n + k*2**l + 2**(l-1) + i] = \
|
2003-02-15 14:54:40 +00:00
|
|
|
PT[(l-1)*n + k*2**l + 2**(l-1) + i] & \
|
|
|
|
PT[(l-1)*n + k*2**l + 2**(l-1) - 1]
|
|
|
|
PO.next = PT[(m+1)*n:m*n]
|
2003-01-23 22:33:19 +00:00
|
|
|
|
|
|
|
def slowPrefix():
|
2005-10-22 19:19:39 +00:00
|
|
|
PT = Signal(intbv(0))
|
2003-01-23 22:33:19 +00:00
|
|
|
while 1:
|
|
|
|
yield PI, PT
|
2003-02-15 14:54:40 +00:00
|
|
|
PT.next[0] = PI[0]
|
2003-01-23 22:33:19 +00:00
|
|
|
for i in range(1, n):
|
2003-02-15 14:54:40 +00:00
|
|
|
PT.next[i] = PI[i] & PT[i-1]
|
2003-02-16 21:36:58 +00:00
|
|
|
PO.next = PT
|
2003-01-23 22:33:19 +00:00
|
|
|
|
|
|
|
if speed == SLOW:
|
|
|
|
return slowPrefix()
|
|
|
|
elif speed == FAST:
|
|
|
|
return fastPrefix()
|
|
|
|
else:
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
|