1
0
mirror of https://github.com/myhdl/myhdl.git synced 2025-01-24 21:52:56 +08:00

42 lines
931 B
Python
Raw Normal View History

2016-03-10 20:27:07 +01:00
import myhdl
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
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
AI.next = ~A
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()