简体   繁体   English

VHDL转移运营商?

[英]VHDL shift operators?

I'm still trying to get used to some of the quirks of VHDL and I'm having a bit of an issue. 我还在尝试习惯VHDL的一些怪癖,而且我遇到了一些问题。 First off, I understand that shift operators like rol, ror, ssl, srl, etc. are not synthesizeable. 首先,我理解像rol,ror,ssl,srl等的移位运算符是不可合成的。 The purpose of this lab is to use a golden model to check against a synthesizeable version of the same thing in a testbench. 本实验的目的是使用黄金模型检查测试平台中同一事物的可合成版本。

Now, the purpose of this program is to convert thermometer code into a 3-bit binary number. 现在,该程序的目的是将温度计代码转换为3位二进制数。 So, in other words, thermometer code "00000001" = "001", "00000011" = "010", "00000111" = "011", etc. I'm basically trying to count the number of 1's in the string from right to left. 换句话说,温度计代码“00000001”=“001”,“00000011”=“010”,“00000111”=“011”等。我基本上试图从右边计算字符串中的1的数量向左。 There will be no case where a '0' is placed between the string of 1's, so the vector "00011101" is invalid and will never occur. 不存在在1的字符串之间放置'0'的情况,因此向量“00011101”无效并且永远不会发生。

I've devised a non-synthesizeable (and so far, non-compile-able) algorithm that I can't figure out how to get working. 我已经设计了一个不可合成的(到目前为止,不可编译的)算法,我无法弄清楚如何工作。 Basically, the idea is to read the thermometer code, shift it right and increment a counter until the thermometer code equals zero, and then assign the counter value to the 3-bit std_logic_vector. 基本上,想法是读取温度计代码,向右移动并递增计数器直到温度计代码等于零,然后将计数器值分配给3位std_logic_vector。 Below is the code I've done so-far. 以下是我迄今为止所做的代码。

library ieee;
use ieee.std_logic_1164.all; 
use ieee.numeric_std.all;

entity therm2bin_g is
    port(therm : inout std_logic_vector(6 downto 0); -- thermometer code
         bin : out std_logic_vector(2 downto 0); -- binary code 
         i : integer range 0 to 7);
end therm2bin_g;    

architecture behavioral_g of therm2bin_g is
begin

golden : process(therm)
begin

    while(therm /= "00000000") loop
        therm <= therm srl 1;
        i = i + 1;      
    end loop;

    bin <= std_logic'(to_unsigned(i,3));

end process golden;
behavioral_g;

here's a version that is synthesisable. 这是一个可综合的版本。 the while loop is replaced by a for loop. while循环由for循环替换。 srl is implemented explicitly: srl是明确实现的:

entity therm2bin_g is
port(therm : inout std_logic_vector(6 downto 0); -- thermometer code
     bin : out std_logic_vector(2 downto 0); -- binary code 
     i : out integer range 0 to 7);
end therm2bin_g;    

architecture behavioral_g of therm2bin_g is
begin

golden : process(therm)
    variable i_internal: integer range 0 to 7;
begin
    i_internal:=0;
    for idx in 0 to therm'length loop
        if therm/="0000000" then
            therm<='0' & therm(therm'left downto 1);
            i_internal := i_internal + 1;     
        end if;
    end loop;

    bin<=std_logic_vector(to_unsigned(i_internal,bin'length));
    i<=i_internal;

end process golden;
end behavioral_g;

"... operators like rol, ror, ssl, srl, etc. are not synthesizeable..." Who says that on who's authority? “......像rol,ror,ssl,srl等运营商不可合成......”谁说谁的权威? Have you checked? 你检查过吗? On which synthesis tool? 在哪个综合工具? Was it a recent version, or a version from the early 1990s? 它是最近的版本,还是20世纪90年代初的版本?

Note that the argument that some tools might not support it is just silly. 请注意, 某些工具可能不支持它的论点只是愚蠢。 The fact that some kitchens might not have an oven does not stop people from writing recipes for cake. 一些厨房可能没有烤箱这一事实并不能阻止人们编写蛋糕食谱。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM