2008-08-28 21:43:19 +02:00
|
|
|
from myhdl import *
|
2003-01-23 22:33:19 +00:00
|
|
|
from arith_utils import BEHAVIOR
|
|
|
|
from PrefixAnd import PrefixAnd
|
|
|
|
|
|
|
|
def Dec(width, speed, A, Z, architecture=BEHAVIOR):
|
2003-02-03 19:32:51 +00:00
|
|
|
|
2003-02-03 21:54:19 +00:00
|
|
|
""" Decrementer module.
|
2003-02-03 19:32:51 +00:00
|
|
|
|
|
|
|
width -- bitwidth of input and output
|
|
|
|
speed -- SLOW, MEDIUM, or FAST performance
|
|
|
|
A -- input
|
|
|
|
Z -- output
|
|
|
|
architecture -- BEHAVIOR or STRUCTURE architecture selection
|
|
|
|
|
|
|
|
"""
|
2003-01-23 22:33:19 +00:00
|
|
|
|
2008-08-28 21:43:19 +02:00
|
|
|
@instance
|
2003-01-23 22:33:19 +00:00
|
|
|
def Behavioral():
|
|
|
|
while 1:
|
|
|
|
yield A
|
2003-02-16 21:36:58 +00:00
|
|
|
Z.next = A - 1
|
2003-01-23 22:33:19 +00:00
|
|
|
|
|
|
|
def Structural():
|
2005-10-22 19:19:39 +00:00
|
|
|
AI = Signal(intbv(0))
|
|
|
|
PO = Signal(intbv(0))
|
2003-01-23 22:33:19 +00:00
|
|
|
prefix = PrefixAnd(width, speed, AI, PO)
|
2008-08-28 21:43:19 +02:00
|
|
|
@instance
|
2003-01-23 22:33:19 +00:00
|
|
|
def logic():
|
|
|
|
while 1:
|
|
|
|
yield A, PO
|
2003-02-16 21:36:58 +00:00
|
|
|
AI.next = ~A
|
2003-07-28 11:01:57 +00:00
|
|
|
Z.next = A ^ concat(PO[width-1:], '1')
|
2008-08-28 21:43:19 +02:00
|
|
|
return [prefix, logic]
|
2003-01-23 22:33:19 +00:00
|
|
|
|
|
|
|
if architecture == BEHAVIOR:
|
2008-08-28 21:43:19 +02:00
|
|
|
return Behavioral
|
2003-01-23 22:33:19 +00:00
|
|
|
else:
|
|
|
|
return Structural()
|
|
|
|
|
|
|
|
|