-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Supporting the execution as software for veriloggen.thread methods. S…
…ome intrinsic methods are also able to be executed as software.
- Loading branch information
Showing
22 changed files
with
679 additions
and
208 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
TARGET=$(shell ls *.py | grep -v test | grep -v parsetab.py) | ||
ARGS= | ||
|
||
PYTHON=python3 | ||
#PYTHON=python | ||
#OPT=-m pdb | ||
#OPT=-m cProfile -s time | ||
#OPT=-m cProfile -o profile.rslt | ||
|
||
.PHONY: all | ||
all: test | ||
|
||
.PHONY: run | ||
run: | ||
$(PYTHON) $(OPT) $(TARGET) $(ARGS) | ||
|
||
.PHONY: test | ||
test: | ||
$(PYTHON) -m pytest -vv | ||
|
||
.PHONY: check | ||
check: | ||
$(PYTHON) $(OPT) $(TARGET) $(ARGS) > tmp.v | ||
iverilog -tnull -Wall tmp.v | ||
rm -f tmp.v | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -rf *.pyc __pycache__ parsetab.py .cache *.out *.png *.dot tmp.v *.vcd |
18 changes: 18 additions & 0 deletions
18
tests/extension/thread_/exec_as_sw/test_thread_exec_as_sw.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from __future__ import absolute_import | ||
from __future__ import print_function | ||
|
||
import os | ||
import veriloggen | ||
import thread_exec_as_sw | ||
|
||
|
||
def test(request): | ||
veriloggen.reset() | ||
|
||
simtype = request.config.getoption('--sim') | ||
|
||
rslt = thread_exec_as_sw.run(filename=None, simtype=simtype, | ||
outputfile=os.path.splitext(os.path.basename(__file__))[0] + '.out') | ||
|
||
verify_rslt = [line for line in rslt.splitlines() if line.startswith('# verify:')][0] | ||
assert(verify_rslt == '# verify: PASSED') |
120 changes: 120 additions & 0 deletions
120
tests/extension/thread_/exec_as_sw/thread_exec_as_sw.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
from __future__ import absolute_import | ||
from __future__ import print_function | ||
import sys | ||
import os | ||
|
||
# the next line can be removed after installation | ||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname( | ||
os.path.dirname(os.path.dirname(os.path.abspath(__file__))))))) | ||
|
||
from veriloggen import * | ||
import veriloggen.thread as vthread | ||
|
||
|
||
def mkLed(): | ||
m = Module('blinkled') | ||
clk = m.Input('CLK') | ||
rst = m.Input('RST') | ||
led = m.OutputReg('LED', 8, initval=0) | ||
|
||
datawidth = 32 | ||
addrwidth = 10 | ||
myram = vthread.RAM(m, 'myram', clk, rst, datawidth, addrwidth) | ||
|
||
def blink(times): | ||
all_ok = True | ||
|
||
write_sum = 0 | ||
for i in range(times): | ||
wdata = i | ||
myram.write(i, wdata) | ||
write_sum += wdata | ||
print('wdata = %d' % wdata) | ||
|
||
read_sum = 0 | ||
for i in range(times): | ||
rdata = myram.read(i) | ||
read_sum += rdata | ||
print('rdata = %d' % rdata) | ||
#if vthread.verilog.NotEql(rdata, i): | ||
if rdata != i: | ||
all_ok = False | ||
|
||
print('read_sum = %d' % read_sum) | ||
|
||
#if vthread.verilog.NotEql(read_sum, write_sum): | ||
if read_sum != write_sum: | ||
all_ok = False | ||
|
||
led.value = 0 | ||
for i in range(times): | ||
led.value += 1 | ||
print(led, i) | ||
|
||
if all_ok and led == times: | ||
print('# verify: PASSED') | ||
else: | ||
print('# verify: FAILED') | ||
|
||
# as SW | ||
print("as SW") | ||
blink(100) | ||
|
||
print("as HW") | ||
|
||
# as HW | ||
th = vthread.Thread(m, 'th_blink', clk, rst, blink) | ||
fsm = th.start(100) | ||
|
||
return m | ||
|
||
|
||
def mkTest(): | ||
m = Module('test') | ||
|
||
# target instance | ||
led = mkLed() | ||
|
||
# copy paras and ports | ||
params = m.copy_params(led) | ||
ports = m.copy_sim_ports(led) | ||
|
||
clk = ports['CLK'] | ||
rst = ports['RST'] | ||
|
||
uut = m.Instance(led, 'uut', | ||
params=m.connect_params(led), | ||
ports=m.connect_ports(led)) | ||
|
||
# vcd_name = os.path.splitext(os.path.basename(__file__))[0] + '.vcd' | ||
# simulation.setup_waveform(m, uut, dumpfile=vcd_name) | ||
simulation.setup_clock(m, clk, hperiod=5) | ||
init = simulation.setup_reset(m, rst, m.make_reset(), period=100) | ||
|
||
init.add( | ||
Delay(1000000), | ||
Systask('finish'), | ||
) | ||
|
||
return m | ||
|
||
|
||
def run(filename='tmp.v', simtype='iverilog', outputfile=None): | ||
|
||
if outputfile is None: | ||
outputfile = os.path.splitext(os.path.basename(__file__))[0] + '.out' | ||
|
||
test = mkTest() | ||
|
||
if filename is not None: | ||
test.to_verilog(filename) | ||
|
||
sim = simulation.Simulator(test, sim=simtype) | ||
rslt = sim.run(outputfile=outputfile) | ||
|
||
return rslt | ||
|
||
|
||
if __name__ == '__main__': | ||
rslt = run(filename='tmp.v') | ||
print(rslt) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.