vhdl - 如何在vhdl中找到两个向量的点积?
问题描述
我是 VHDL 的新手。我正在尝试为 Xilinx FPGA 上的向量点或标量产品设计通用代码。假设我们有一个向量 两个向量
V1=[1,4,5,1] and V2=[3,6,9,1].
我们可以使用
V1.V2=(1x3)+(4x6)+(5x9)+(1x1)=73
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.numeric_std.ALL;
entity dot_product is
Port ( vector_x : in STD_LOGIC_VECTOR (3 downto 0);
vector_y : in STD_LOGIC_VECTOR (3 downto 0);
r0 : out STD_LOGIC_VECTOR (3 downto 0);
r1 : out STD_LOGIC_VECTOR (3 downto 0);
r2 : out STD_LOGIC_VECTOR (3 downto 0);
result : out STD_LOGIC_VECTOR (7 downto 0));
end dot_product;
architecture Behavioral of dot_product is
begin
r0 <= std_logic_vector(signed(vector_x(0)* vector_y(0)));
r1 <= std_logic_vector(signed(vector_x(1)* vector_y(1)));
r2 <= std_logic_vector(signed(vector_x(2)* vector_y(2)));
r3 <= std_logic_vector(signed(vector_x(3)* vector_y(3)));
result<=r0+r1+r2+r3;
end Behavioral;
我们如何在 VHDL 中找到它的点积,然后我可以根据我的要求更改矢量大小。请帮忙。谢谢:)
解决方案
这些是一些注释:
- vector_x : 在 STD_LOGIC_VECTOR (3 down to 0);
这不是数学中的向量。它是一个由 0 和 1 组成的数组。所以你可以用它来表示从 0 (0000) 到 15 (1111) 的数字。
如果您想要一个向量,请考虑声明一个 std_logic_vector 数组。
类型 t_vector 是 std_logic_vector(3 downto 0) 的数组(整数范围 <>);
考虑阅读:https ://www.nandland.com/vhdl/examples/example-array-type-vhdl.html
然后将向量声明为类型为 t_vector 的数组。
之后,您可以在一个过程中使用 for 循环来进行乘法和加法。考虑阅读这个:http ://habeebq.github.io/writing-a-2x2-matrix-multiplier-in-vhdl.html
要具有通用数组大小,请考虑使用不受约束的数组或通用的大小。
entity dot_product is
generic (width : positive := 8);
port (vector_x : in t_vector (width downto 0);
vector_y : in t_vector (width downto 0);
result : out STD_LOGIC_VECTOR (7 downto 0));
end dot_product ;
推荐阅读
- sql - 在给定期间的其他列中有超过 2 个不同值时选择值
- javascript - 未捕获的 SyntaxError:无效或意外的令牌
我正在尝试在 input[type='checkbox'] 上的单击功能上提交表单,而不使用 ajax-jquery 刷新页面。顺便说一句,我正在开发一个 Django 网络应用程序。
这是我的表单元素代码-
{% if vendor.accountEnabled %} <fo
- elixir - Elixir 中的动态调度就是这样
- javascript - 使用异步等待时发布路由错误现在我无法发布新产品
- c# - 如何在新的弹出窗口中绑定数据?
- java - 我是骆驼框架的新手,我尝试了一个程序将文件从一个目录复制到另一个目录,但是在运行该程序时出现以下错误
- python - 如何在 Pyspark 中使用 RDD 的嵌套列表获取不同的字典?
- linux - 仅当 AIDE 检测到文件修改时,如何让 cron 向我发送电子邮件?
- scala - 火花流:- 错误原因:java.util.ConcurrentModificationException:KafkaConsumer 对多线程访问不安全
- syntax - Nek5000:.usr 文件中边界条件代码的 makenek 错误