mirror of
https://github.com/MPSU/APS.git
synced 2025-09-15 17:20:10 +00:00
WIP: APS cumulative update (#98)
* WIP: APS cumulative update * Update How FPGA works.md * Перенос раздела "Последовательностная логика" в отдельный док * Исправление картинки * Исправление оформления индексов * Переработка раздела Vivado Basics * Добавление картинки в руководство по созданию проекта * Исправление ссылок в анализе rtl * Обновление изображения в sequential logic * Исправление ссылок в bug hunting * Исправление ссылок * Рефактор руководства по прошивке ПЛИС * Mass update * Update fig_10 * Restore fig_02
This commit is contained in:
committed by
GitHub
parent
78bb01ef95
commit
a28002e681
7
Vivado Basics/vector_abs/README.md
Normal file
7
Vivado Basics/vector_abs/README.md
Normal file
@@ -0,0 +1,7 @@
|
||||
# Модуль приближенного вычисления длины вектора
|
||||
|
||||
Модуль `vector_abs` предназначен для вычисления приближенной длины вектора в евклидовом пространстве (выражения `sqrt(a^2+b^2)`). Для эффективного использования логических вентилей используется следующее приближение:
|
||||
|
||||
`sqrt(a^2+b^2) ≈ max + min/2`, где max и min — наибольшее и наименьшее из пары чисел соответственно [**Ричард Лайонс: Цифровая обработка сигналов, Глава 13.2, стр. 475**].
|
||||
|
||||
Для определения максимума/минимума используется модуль `max_min`, для вычисления деления пополам используется модуль `half_divider`.
|
18
Vivado Basics/vector_abs/half_divider.sv
Normal file
18
Vivado Basics/vector_abs/half_divider.sv
Normal file
@@ -0,0 +1,18 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Project Name : Architectures of Processor Systems (APS) lab work
|
||||
* Organization : National Research University of Electronic Technology (MIET)
|
||||
* Department : Institute of Microdevices and Control Systems
|
||||
* Author(s) : Andrei Solodovnikov
|
||||
* Email(s) : hepoh@org.miet.ru
|
||||
|
||||
See https://github.com/MPSU/APS/blob/master/LICENSE file for licensing details.
|
||||
* ------------------------------------------------------------------------------
|
||||
*/
|
||||
module half_divider(
|
||||
input logic [31:0] numerator,
|
||||
output logic [31:0] quotient
|
||||
);
|
||||
|
||||
assign quotient = numerator << 1'b1;
|
||||
|
||||
endmodule
|
29
Vivado Basics/vector_abs/max_min.sv
Normal file
29
Vivado Basics/vector_abs/max_min.sv
Normal file
@@ -0,0 +1,29 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Project Name : Architectures of Processor Systems (APS) lab work
|
||||
* Organization : National Research University of Electronic Technology (MIET)
|
||||
* Department : Institute of Microdevices and Control Systems
|
||||
* Author(s) : Andrei Solodovnikov
|
||||
* Email(s) : hepoh@org.miet.ru
|
||||
|
||||
See https://github.com/MPSU/APS/blob/master/LICENSE file for licensing details.
|
||||
* ------------------------------------------------------------------------------
|
||||
*/
|
||||
module max_min(
|
||||
input logic [31:0] a,
|
||||
input logic [31:0] b,
|
||||
output logic [31:0] max,
|
||||
output logic [ 3:0] min
|
||||
);
|
||||
|
||||
always_comb begin
|
||||
if(a > b) begin
|
||||
max = a;
|
||||
min = b;
|
||||
end
|
||||
else begin
|
||||
max = b;
|
||||
min = b;
|
||||
end
|
||||
end
|
||||
|
||||
endmodule
|
68
Vivado Basics/vector_abs/tb_vector_abs.sv
Normal file
68
Vivado Basics/vector_abs/tb_vector_abs.sv
Normal file
@@ -0,0 +1,68 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Project Name : Architectures of Processor Systems (APS) lab work
|
||||
* Organization : National Research University of Electronic Technology (MIET)
|
||||
* Department : Institute of Microdevices and Control Systems
|
||||
* Author(s) : Andrei Solodovnikov
|
||||
* Email(s) : hepoh@org.miet.ru
|
||||
|
||||
See https://github.com/MPSU/APS/blob/master/LICENSE file for licensing details.
|
||||
* ------------------------------------------------------------------------------
|
||||
*/
|
||||
module tb_vector_abs();
|
||||
|
||||
logic [31:0] a;
|
||||
logic [31:0] b;
|
||||
logic [31:0] res;
|
||||
|
||||
vector_abs dut(
|
||||
.x(a),
|
||||
.y(b),
|
||||
.abs(res)
|
||||
);
|
||||
integer err_count = 0;
|
||||
|
||||
task check_result(input logic [31:0]a, b, res);
|
||||
begin : check_result
|
||||
reg [31:0] ref_res;
|
||||
ref_res = a < b? a/2 + b : a + b/2;
|
||||
if (res !== ref_res) begin
|
||||
$display("Incorrect res at time %0t:", $time);
|
||||
$display("a = %0d, b = %0d", a, b);
|
||||
$display("design res = %0d", res);
|
||||
$display("reference res = %0d", ref_res);
|
||||
$display("------------------");
|
||||
err_count = err_count + 1'b1;
|
||||
end
|
||||
end
|
||||
endtask
|
||||
|
||||
initial begin : test
|
||||
integer i;
|
||||
$timeformat(-9,0,"ns");
|
||||
a = 0; b = 0;
|
||||
#5;
|
||||
check_result(a,b,res);
|
||||
|
||||
|
||||
a = 1; b = 1;
|
||||
#5;
|
||||
check_result(a,b,res);
|
||||
|
||||
a = 3; b = 4;
|
||||
#5;
|
||||
check_result(a,b,res);
|
||||
|
||||
|
||||
for(i = 0; i < 100; i=i+1) begin
|
||||
a = $random()&32'hff; b = $random()&32'hff;
|
||||
#5;
|
||||
check_result(a,b,res);
|
||||
end
|
||||
|
||||
$display("Test has been finished with %d errors", err_count);
|
||||
if(err_count == 0) begin
|
||||
$display("SUCCESS!");
|
||||
end
|
||||
$finish();
|
||||
end
|
||||
endmodule
|
35
Vivado Basics/vector_abs/vector_abs.sv
Normal file
35
Vivado Basics/vector_abs/vector_abs.sv
Normal file
@@ -0,0 +1,35 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Project Name : Architectures of Processor Systems (APS) lab work
|
||||
* Organization : National Research University of Electronic Technology (MIET)
|
||||
* Department : Institute of Microdevices and Control Systems
|
||||
* Author(s) : Andrei Solodovnikov
|
||||
* Email(s) : hepoh@org.miet.ru
|
||||
|
||||
See https://github.com/MPSU/APS/blob/master/LICENSE file for licensing details.
|
||||
* ------------------------------------------------------------------------------
|
||||
*/
|
||||
module vector_abs(
|
||||
input logic [31:0] x,
|
||||
input logic [31:0] y,
|
||||
output logic [31:0] abs
|
||||
);
|
||||
|
||||
|
||||
logic [31:0] min;
|
||||
logic [31:0] min_half;
|
||||
|
||||
max_min max_min_unit(
|
||||
.a(x),
|
||||
.b(y),
|
||||
.max(max),
|
||||
.min(min)
|
||||
);
|
||||
|
||||
half_divider div_unit(
|
||||
.numerator(min),
|
||||
.quotient(min_half)
|
||||
);
|
||||
|
||||
assign abs = max + min_half;
|
||||
|
||||
endmodule
|
Reference in New Issue
Block a user