Skip to content

Commit 8cbe742

Browse files
committed
Merged with master
2 parents efebb66 + 26579a7 commit 8cbe742

File tree

13 files changed

+232
-36
lines changed

13 files changed

+232
-36
lines changed

bench/cpp/Makefile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ icompare: $(CMPOBJS) $(VOBJDR)/Vicomparison__ALL.a
7878
test: icompare
7979
./icompare
8080

81-
#
81+
.PHONY: depends
82+
# {{{
8283
# The "depends" target, to know what files things depend upon. The depends
8384
# file itself is kept in $(OBJDIR)/depends.txt
8485
#
@@ -90,11 +91,11 @@ define build-depends
9091
@rm $(OBJDIR)/xdepends.txt
9192
endef
9293

93-
.PHONY: depends
9494
depends: tags
9595
$(build-depends)
9696

9797
$(OBJDIR)/depends.txt: depends
98+
## }}}
9899

99100
#
100101
define mk-objdir
@@ -103,14 +104,17 @@ endef
103104

104105
#
105106
# The "tags" target
106-
#
107+
# {{{
107108
tags: $(SOURCES) $(HEADERS)
108109
@echo "Generating tags"
109110
@ctags $(SOURCES) $(HEADERS)
111+
## }}}
110112

111113
.PHONY: clean
114+
## {{{
112115
clean:
113116
rm -f ./icompare
114117
rm -rf $(OBJDIR)/
118+
## }}}
115119

116120
-include $(OBJDIR)/depends.txt

bench/cpp/icompare.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
// {{{
3434
// http://www.gnu.org/licenses/gpl.html
3535
//
36-
//
3736
////////////////////////////////////////////////////////////////////////////////
3837
//
3938
// }}}

bench/rtl/Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,13 @@ VFLAGS := -MMD -Wall -trace $(VSEARCH) -cc
5252
.DELETE_ON_ERROR:
5353

5454
.PHONY: icomparison
55+
## {{{
5556
icomparison: $(VDIRFB)/Vicomparison__ALL.a
5657

5758
$(VDIRFB)/Vicomparison__ALL.a: $(VDIRFB)/Vicomparison.h $(VDIRFB)/Vicomparison.cpp
5859
$(VDIRFB)/Vicomparison__ALL.a: $(VDIRFB)/Vicomparison.mk
5960
$(VDIRFB)/Vicomparison.h $(VDIRFB)/Vicomparison.cpp $(VDIRFB)/Vicomparison.mk: icomparison.v
61+
## }}}
6062

6163
$(VDIRFB)/V%.cpp $(VDIRFB)/V%.h $(VDIRFB)/V%.mk: $(FBDIR)/%.v
6264
$(VERILATOR) $(VFLAGS) $*.v
@@ -65,13 +67,18 @@ $(VDIRFB)/V%__ALL.a: $(VDIRFB)/V%.mk
6567
cd $(VDIRFB); make -f V$*.mk
6668

6769
.PHONY: clean
70+
## {{{
6871
clean:
6972
rm -rf $(VDIRFB)/*.mk
7073
rm -rf $(VDIRFB)/*.cpp
7174
rm -rf $(VDIRFB)/*.h
7275
rm -rf $(VDIRFB)/
76+
## }}}
7377

78+
## Automatic dependency handling
79+
## {{{
7480
DEPS := $(wildcard $(VDIRFB)/*.d)
7581
ifneq ($(DEPS),)
7682
include $(DEPS)
7783
endif
84+
## }}}

rtl/lininterp/Makefile

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,26 +47,40 @@ SUBMAKE := $(MAKE) --no-print-directory -C
4747
VFILES := $(VROOT)/include/verilated.cpp $(VROOT)/include/verilated_vcd_c.cpp
4848
CFLAGS := -g -I$(VROOT)/include -I$(VDIR)
4949

50+
## Run Verilator
51+
## {{{
5052
$(VDIR)/Vlininterp.h: lininterp.v
5153
$(VERILATOR) $(VFLAGS) lininterp.v
54+
## }}}
5255

56+
## Build the result into a library
57+
## {{{
5358
$(VDIR)/Vlininterp.cpp: $(VDIR)/Vlininterp.h
5459
$(VDIR)/Vlininterp.mk: $(VDIR)/Vlininterp.cpp
5560

5661
.PHONY: library
5762
library: $(VDIR)/Vlininterp.h $(VDIR)/Vlininterp.cpp $(VDIR)/Vlininterp.mk
5863
$(SUBMAKE) $(VDIR) -f Vlininterp.mk
64+
## }}}
5965

66+
## Link with the library to build our simulation
67+
## {{{
6068
lininterp: lininterp.cpp library
6169
$(CXX) $(CFLAGS) $< $(VFILES) $(VDIR)/Vlininterp__ALL.a -o $@
70+
## }}}
6271

72+
## The test target
73+
## {{{
6374
dbgfp.32t: lininterp
6475
./lininterp
6576

6677
.PHONY: test
6778
test: dbgfp.32t
79+
## }}}
6880

81+
## Clean
82+
## {{{
6983
.PHONY: clean
7084
clean:
7185
rm -rf $(VDIR) lininterp dbgfp.32t
72-
86+
## }}}

rtl/lininterp/lininterp.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
// {{{
3535
// http://www.gnu.org/licenses/gpl.html
3636
//
37-
//
3837
////////////////////////////////////////////////////////////////////////////////
3938
//
4039
// }}}

rtl/lininterp/lininterp.v

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,13 @@ module lininterp #(
120120

121121
always @(posedge i_clk)
122122
pre_ce <= i_ce;
123+
////////////////////////////////////////////////////////////////////////
124+
//
125+
// r_* stage.
126+
// {{{
127+
////////////////////////////////////////////////////////////////////////
128+
//
129+
//
123130

124131
////////////////////////////////////////////////////////////////////////
125132
//
@@ -129,6 +136,8 @@ module lininterp #(
129136
// r_ variables are not input (i_) variables, but may have been input
130137
// variables one clock ago.
131138

139+
// r_next, r_last, r_slope
140+
// {{{
132141
initial r_next = 0;
133142
initial r_last = 0;
134143
initial r_slope = 0;
@@ -142,7 +151,10 @@ module lininterp #(
142151
r_slope <= { i_data[(INW-1)], i_data }
143152
- { r_next[(INW-1)], r_next };
144153
end
154+
// }}}
145155

156+
// r_ovfl, r_counter
157+
// {{{
146158
// Start with ovfl true, so that we wait for the first valid input
147159
initial r_ovfl = 1'b1;
148160
initial r_counter = 0;
@@ -151,15 +163,19 @@ module lininterp #(
151163
{ r_ovfl, r_counter } <= r_counter + i_step;
152164
else if (!r_ovfl)
153165
{ r_ovfl, r_counter } <= r_counter + i_step;
166+
// }}}
154167

155-
//
168+
// r_ce
169+
// {{{
156170
// Calculate when we want to do our next step. In other words,
157171
// when do we want to use these r_* values
158172
initial r_ce = 1'b0;
159173
always @(posedge i_clk)
160174
r_ce <= ((pre_ce)||(!r_ovfl));
175+
// }}}
161176

162-
//
177+
// pre_offset, r_offset
178+
// {{{
163179
// Do a bit select of our counter to get the offset which will be
164180
// multiplied by our slope
165181
assign pre_offset = { 1'b0, r_counter[(CTRBITS-1):(CTRBITS-MPREC)] };
@@ -168,28 +184,41 @@ module lininterp #(
168184
if (r_ce)
169185
r_offset <= pre_offset;
170186
// }}}
187+
// }}}
171188
////////////////////////////////////////////////////////////////////////
172189
//
173-
// x_* stage
190+
// x_* stage.
174191
// {{{
192+
////////////////////////////////////////////////////////////////////////
193+
//
175194
// The X stage where we multiply the incoming data. It follows on
176195
// the clock following the r_ stage, and so the inputs to this stage
177196
// are the r_ variables from above.
178197
//
198+
199+
// x_base, x_offset
200+
// {{{
179201
always @(posedge i_clk)
180202
if (r_ce)
181203
begin
182204
x_base <= r_last;
183205
x_offset <= r_slope * r_offset;
184206
end
207+
// }}}
185208

209+
// x_ce
210+
// {{{
186211
always @(posedge i_clk)
187212
x_ce <= r_ce;
188213
// }}}
189214
////////////////////////////////////////////////////////////////////////
190215
//
191-
// Pre-rounding
216+
// pre-rounding stage, and output the results
192217
// {{{
218+
////////////////////////////////////////////////////////////////////////
219+
//
220+
//
221+
193222
// The pre_rounding stage, where we add things back together.
194223
// Specifically, we'll add the result of our multiply to the last data
195224
// value, to get the pre_rounding value.
@@ -227,7 +256,11 @@ module lininterp #(
227256
// later discussion.
228257
assign o_data = rounded_result[(FWID-1):(FWID-OWID)];
229258
// }}}
230-
259+
////////////////////////////////////////////////////////////////////////
260+
//
261+
// Test points for debugging--if so defined
262+
// {{{
263+
////////////////////////////////////////////////////////////////////////
231264
`ifdef TESTPOINTS
232265
// {{{
233266
// These test points are not normally part of the linear interpolator,
@@ -249,6 +282,20 @@ module lininterp #(
249282
reg [(INW):0] pr_slope;
250283
reg [(MPREC-1):0] pr_offset;
251284

285+
286+
always @(posedge i_clk)
287+
if (r_ce)
288+
begin
289+
x_last <= r_last;
290+
x_next <= r_next;
291+
x_slope <= r_slope;
292+
// Avoid name collision, with two x_offsets having
293+
// different meanings.
294+
x_sclock <= r_offset[(MPREC-1):0];
295+
end
296+
297+
// One more clock for the pre-rounding step
298+
//
252299
always @(posedge i_clk)
253300
if (r_ce)
254301
begin
@@ -281,6 +328,7 @@ module lininterp #(
281328
end
282329
// }}}
283330
`endif
331+
// }}}
284332

285333
// Make verilator -Wall happy
286334
// {{{

rtl/lininterp/lintest.m

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,42 @@
1+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2+
%
3+
% Filename: lintest.m
4+
% {{{
5+
% Project: Example Interpolators
6+
%
7+
% Purpose: Read and process/examine/plot the outputs from the test bench.
8+
%
9+
% Creator: Dan Gisselquist, Ph.D.
10+
% Gisselquist Technology, LLC
11+
%
12+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13+
% }}}
14+
% Copyright (C) 2017-2021, Gisselquist Technology, LLC
15+
% {{{
16+
% This program is free software (firmware): you can redistribute it and/or
17+
% modify it under the terms of the GNU General Public License as published
18+
% by the Free Software Foundation, either version 3 of the License, or (at
19+
% your option) any later version.
20+
%
21+
% This program is distributed in the hope that it will be useful, but WITHOUT
22+
% ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
23+
% FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24+
% for more details.
25+
%
26+
% You should have received a copy of the GNU General Public License along
27+
% with this program. (It's in the $(ROOT)/doc directory. Run make with no
28+
% target there if the PDF file isn't present.) If not, see
29+
% <http://www.gnu.org/licenses/> for a copy.
30+
% }}}
31+
% License: GPL, v3, as defined and found on www.gnu.org,
32+
% {{{
33+
% http://www.gnu.org/licenses/gpl.html
34+
%
35+
%
36+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37+
%
38+
% }}}
39+
140
fid = fopen('dbgfp.32t','r');
241
dat = fread(fid,[ 6 inf] ,'int32');
342
fclose(fid);

rtl/lininterp/rounding.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#define OWID 5
4646

4747
void test(Vrounding *tb, int k) {
48+
// {{{
4849
tb->i_clk = 0;
4950
tb->i_data = k;
5051
tb->eval();
@@ -63,6 +64,7 @@ void test(Vrounding *tb, int k) {
6364
tb->o_tozero,
6465
tb->o_fromzero,
6566
tb->o_convergent);
67+
// }}}
6668
}
6769

6870
int main(int argc, char **argv) {

rtl/lininterp/rounding.v

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
// {{{
55
// Project: Example Interpolators
66
//
7-
// Purpose:
7+
// Purpose: To demonstrate the results of various rounding methods
8+
//
9+
// KNOWN ISSUES:
10+
// As currently implemented, these rounding methods might overflow
11+
// internally even if the item in question does not.
812
//
913
// Creator: Dan Gisselquist, Ph.D.
1014
// Gisselquist Technology, LLC
@@ -37,7 +41,9 @@
3741
`default_nettype none
3842
// }}}
3943
module rounding #(
40-
parameter IWID=8, OWID=5;
44+
// {{{
45+
parameter IWID=8, OWID=5
46+
// }}}
4147
) (
4248
// {{{
4349
input wire i_clk,

rtl/nearest-neighbor/simpleinterp.v

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@
3838
`default_nettype none
3939
// }}}
4040
module simpleinterp #(
41+
// {{{
4142
parameter INW = 28, // Input width
4243
CTRBITS = 32 // Bits in our counter
44+
// }}}
4345
) (
4446
// {{{
4547
input wire i_clk,

0 commit comments

Comments
 (0)