Case 1: Adder
Categories:
RTL Source Code
In this case, we drive a 64-bit adder (combinational circuit) with the following source code:
This adder contains a 64-bit adder with inputs of two 64-bit numbers and a carry-in signal, outputting a 64-bit sum and a carry-out signal.
Testing Process
During the testing process, we will create a folder named Adder
, containing a file called Adder.v
. This file contains the above RTL source code.
Exporting RTL to Python Module
Generating Intermediate Files
Navigate to the Adder
folder and execute the following command:
This command performs the following actions:
-
Uses
Adder.v
as the top file, withAdder
as the top module, and generates a dynamic library using the Verilator simulator with Python as the target language. -
Enables waveform output, with the target waveform file as
Adder.fst
. -
Includes files for driving the example project (-e), and does not automatically compile after code generation (-autobuild=false).
-
The final file output path is
picker_out_adder
.
Some command-line parameters were not used in this command, and they will be introduced in later sections. The output directory structure is as follows. Note that these are all intermediate files and cannot be used directly:
Building Intermediate Files
Navigate to the picker_out_adder
directory and execute the make
command to generate the final files.
Use the simulator invocation script defined by
cmake/*.cmake
to compileAdder_top.sv
and related files into thelibDPIAdder.so
dynamic library.Use the compilation script defined byCMakeLists.txt
to wraplibDPIAdder.so
into thelibUTAdder.so
dynamic library throughdut_base.cpp
. Both outputs from steps 1 and 2 are copied to theUT_Adder
directory.Generate the wrapper layer using theSWIG
tool withdut_base.hpp
anddut.hpp
header files, and finally build a Python module in theUT_Adder
directory.If the-e
parameter is included, the pre-definedexample.py
is placed in the parent directory of theUT_Adder
directory as a sample code for calling this Python module. The final directory structure is:
Setting Up Test Code
Replace the content in
example.py
with the following Python test code.
Running the Test
In the picker_out_adder
directory, execute the python3 example.py
command to run the test. After the test is complete, we can see the output of the example project.
[...]
[test 114507] a=0x7adc43f36682cffe, b=0x30a718d8cf3cc3b1, cin=0x0 => sum: 0x12358823834579604399, cout: 0x0
[test 114508] a=0x3eb778d6097e3a72, b=0x1ce6af17b4e9128, cin=0x0 => sum: 0x4649372636395916186, cout: 0x0
[test 114509] a=0x42d6f3290b18d4e9, b=0x23e4926ef419b4aa, cin=0x1 => sum: 0x7402657300381600148, cout: 0x0
[test 114510] a=0x505046adecabcc, b=0x6d1d4998ed457b06, cin=0x0 => sum: 0x7885127708256118482, cout: 0x0
[test 114511] a=0x16bb10f22bd0af50, b=0x5813373e1759387, cin=0x1 => sum: 0x2034576336764682968, cout: 0x0
[test 114512] a=0xc46c9f4aa798106, b=0x4d8f52637f0417c4, cin=0x0 => sum: 0x6473392679370463434, cout: 0x0
[test 114513] a=0x3b5387ba95a7ac39, b=0x1a378f2d11b38412, cin=0x0 => sum: 0x6164045699187683403, cout: 0x0
Test Passed