1
0
mirror of https://github.com/myhdl/myhdl.git synced 2024-12-14 07:44:38 +08:00
2005-10-22 19:19:39 +00:00

40 lines
944 B
Python

from __future__ import generators
from myhdl import Signal, intbv, concat
from arith_utils import BEHAVIOR
from PrefixAnd import PrefixAnd
def Dec(width, speed, A, Z, architecture=BEHAVIOR):
""" Decrementer module.
width -- bitwidth of input and output
speed -- SLOW, MEDIUM, or FAST performance
A -- input
Z -- output
architecture -- BEHAVIOR or STRUCTURE architecture selection
"""
def Behavioral():
while 1:
yield A
Z.next = A - 1
def Structural():
AI = Signal(intbv(0))
PO = Signal(intbv(0))
prefix = PrefixAnd(width, speed, AI, PO)
def logic():
while 1:
yield A, PO
AI.next = ~A
Z.next = A ^ concat(PO[width-1:], '1')
return [prefix, logic()]
if architecture == BEHAVIOR:
return Behavioral()
else:
return Structural()