Skip to content

Commit 80983ac

Browse files
committed
Merge branch 'feature_axi_memory_model_addrwidth' into develop
2 parents aaa9ce6 + ec4ef81 commit 80983ac

File tree

6 files changed

+85
-12
lines changed

6 files changed

+85
-12
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ language: python
33
sudo: false
44

55
python:
6-
- 3.6
6+
- 3.7
77

88
addons:
99
apt:
@@ -12,7 +12,7 @@ addons:
1212
- verilator
1313

1414
install:
15-
- pip install jinja2 pytest pytest-pythonpath pyverilog ipgen numpy
15+
- pip install pytest pytest-pythonpath jinja2 pyverilog numpy
1616

1717
script:
1818
- python -m pytest tests examples

README.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ Requirements
8383
sudo apt install iverilog
8484
```
8585

86-
- Pyverilog: 1.1.4 or later
8786
- Jinja2: 2.10 or later
87+
- Pyverilog: 1.1.4 or later
8888
- NumPy: 1.14 or later
8989

9090
```
@@ -104,6 +104,14 @@ We recommend to install these testing library to verify experimental features.
104104
pip3 install pytest pytest-pythonpath
105105
```
106106

107+
For fast RTL simulation, we recommend to install Verilator.
108+
109+
- Verilator: 3.916 or later
110+
111+
```
112+
sudo apt install verilator
113+
```
114+
107115
Optional installation for visualization
108116
--------------------
109117

@@ -140,6 +148,26 @@ make
140148
```
141149

142150

151+
Examples and testing
152+
==============================
153+
154+
There are some exapmles in **examples** and various testing codes in **tests**.
155+
The testing codes are actually good small examples suggesting how to represent a desired function.
156+
157+
To run the testing codes, please type the following commands.
158+
159+
```
160+
cd tests
161+
python3 -m pytest .
162+
```
163+
164+
If you use Verilator instead of Icarus Verilog for RTL simulation, set "--sim" option.
165+
166+
```
167+
python3 -m pytest --sim=verilator .
168+
```
169+
170+
143171
Getting started
144172
==============================
145173

README.rst

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ Requirements
9696

9797
sudo apt install iverilog
9898

99-
- Pyverilog: 1.1.4 or later
10099
- Jinja2: 2.10 or later
100+
- Pyverilog: 1.1.4 or later
101101
- NumPy: 1.14 or later
102102

103103
::
@@ -118,6 +118,14 @@ features.
118118

119119
pip3 install pytest pytest-pythonpath
120120

121+
For fast RTL simulation, we recommend to install Verilator.
122+
123+
- Verilator: 3.916 or later
124+
125+
::
126+
127+
sudo apt install verilator
128+
121129
Optional installation for visualization
122130
---------------------------------------
123131

@@ -155,6 +163,27 @@ without any installation on your host platform.
155163
cd veriloggen/examples/led/
156164
make
157165

166+
Examples and testing
167+
====================
168+
169+
There are some exapmles in **examples** and various testing codes in
170+
**tests**. The testing codes are actually good small examples suggesting
171+
how to represent a desired function.
172+
173+
To run the testing codes, please type the following commands.
174+
175+
::
176+
177+
cd tests
178+
python3 -m pytest .
179+
180+
If you use Verilator instead of Icarus Verilog for RTL simulation, set
181+
“–sim” option.
182+
183+
::
184+
185+
python3 -m pytest --sim=verilator .
186+
158187
Getting started
159188
===============
160189

docker/Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ RUN apt update && apt upgrade -y
33
RUN apt install build-essential -y
44
RUN apt install git -y
55
RUN apt install python3 python3-pip -y
6-
RUN apt install iverilog gtkwave -y
7-
RUN pip3 install jinja2 numpy pytest pytest-pythonpath pyverilog
6+
RUN apt install iverilog verilator gtkwave -y
7+
RUN pip3 install jinja2 pyverilog numpy
8+
RUN pip3 install pytest pytest-pythonpath
89
RUN mkdir /home/veriloggen/
910
WORKDIR "/home/veriloggen"
1011
RUN git clone https://github.com/PyHDI/veriloggen.git

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ def read(filename):
2323
packages=find_packages(),
2424
package_data={'veriloggen.utils': ['VERSION'],
2525
'veriloggen.simulation': ['*.cpp'], },
26-
install_requires=['pyverilog>=1.1.4',
27-
'Jinja2>=2.10',
26+
install_requires=['jinja2>=2.10',
27+
'pyverilog>=1.1.4',
2828
'numpy>=1.14'],
2929
extras_require={
3030
'test': ['pytest>=3.2', 'pytest-pythonpath>=0.7'],

veriloggen/types/axi.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2255,9 +2255,6 @@ def __init__(self, m, name, clk, rst, datawidth=32, addrwidth=32,
22552255
self.wresp.bvalid(1)
22562256
)
22572257

2258-
self.mem = self.m.Reg(
2259-
'_'.join(['', self.name, 'mem']), 8, vtypes.Int(2) ** self.mem_addrwidth)
2260-
22612258
if memimg is None:
22622259
if memimg_name is None:
22632260
memimg_name = '_'.join(['', self.name, 'memimg', '.out'])
@@ -2268,12 +2265,24 @@ def __init__(self, m, name, clk, rst, datawidth=32, addrwidth=32,
22682265
elif isinstance(memimg, str):
22692266
memimg_name = memimg
22702267

2268+
num_words = sum(1 for line in open(memimg, 'r'))
2269+
# resize mem_addrwidth according to the memimg size
2270+
self.mem_addrwidth = max(self.mem_addrwidth,
2271+
int(math.ceil(math.log(num_words, 2))))
2272+
22712273
else:
22722274
if memimg_datawidth is None:
22732275
memimg_datawidth = mem_datawidth
22742276
if memimg_name is None:
22752277
memimg_name = '_'.join(['', self.name, 'memimg', '.out'])
2276-
to_memory_image(memimg_name, memimg, datawidth=memimg_datawidth)
2278+
2279+
num_words = to_memory_image(memimg_name, memimg, datawidth=memimg_datawidth)
2280+
# resize mem_addrwidth according to the memimg size
2281+
self.mem_addrwidth = max(self.mem_addrwidth,
2282+
int(math.ceil(math.log(num_words, 2))))
2283+
2284+
self.mem = self.m.Reg(
2285+
'_'.join(['', self.name, 'mem']), 8, vtypes.Int(2) ** self.mem_addrwidth)
22772286

22782287
self.m.Initial(
22792288
vtypes.Systask('readmemh', memimg_name, self.mem)
@@ -2582,6 +2591,9 @@ def to_memory_image(filename, array, length=None,
25822591
for v in values:
25832592
f.write(fmt % v)
25842593

2594+
num_lines = len(array) * num
2595+
return num_lines
2596+
25852597
else:
25862598
num = int(math.ceil(wordwidth / datawidth))
25872599
mask = (2 ** datawidth) - 1
@@ -2602,6 +2614,9 @@ def to_memory_image(filename, array, length=None,
26022614
f.write(fmt % cat)
26032615
values = []
26042616

2617+
num_lines = len(array) // num
2618+
return num_lines
2619+
26052620

26062621
def aligned_shape(shape, datawidth, mem_datawidth):
26072622
aligned_shape = list(shape[:])

0 commit comments

Comments
 (0)