VHDL-2008 to_01转换

问题描述 投票:2回答:2

在VHDL-2008中使用to_01转换函数时,我遇到了一些意想不到的行为。我的期望是可以清楚地解释为高或低的向量位分别映射到'1'和'0'。其余的矢量位应转换为'0'位。但是,使用下面描述的代码,我将整个矢量转换为全0'。

这种行为是否正确?或者这是模拟器软件(ALDEC Riviera-PRO)中的错误?

有没有符合我期望的IEEE功能,或者我必须编写自己的功能来实现这一目标吗?

library ieee;
use ieee.std_logic_1164.all;

entity test_to_01 is
end entity test_to_01;

architecture rtl of test_to_01 is
    signal s_test_in    : std_logic_vector(8 downto 0)  := "UX01ZWLH-";
    signal s_test_out   : std_logic_vector(8 downto 0);
begin
    s_test_out  <=  to_01(s_test_in);
end architecture rtl;

enter image description here

vhdl
2个回答
3
投票

观察到的行为是正确的行为。关于此的一点历史如下。

2008年,我们将所有强度降低操作传播到所有std_logic系列包。无论好坏,to_01的历史实现来自numeric_std,并且与现在完全一样。以下是我能够在网上找到的较旧的实现:

function TO_01(S : SIGNED ; xmap : STD_LOGIC:= '0') return SIGNED is
variable RESULT: SIGNED(S'length-1 downto 0);
variable bad_element : boolean := FALSE;
alias xs : SIGNED(s'length-1 downto 0) is S;
begin
  for i in RESULT'range loop
    case xs(i) is
      when '0' | 'L' => RESULT(i):='0';
      when '1' | 'H' => RESULT(i):='1';
      when others => bad_element := TRUE;
      end case;
    end loop;
  if bad_element then
    assert NO_WARNING
      report "numeric_std.TO_01: Array Element not in {0,1,H,L}"
      severity warning;
    for i in RESULT'range loop
      RESULT(i) := xmap;        -- standard fixup
      end loop;
    end if;
  return RESULT;
  end TO_01;

VHDL WG的主要指令之一是不破坏旧代码。在这种情况下,看起来这个目标提出了一个可能不太理想的实现。

如果您想要不同的东西,您可以随时将其用于下一版标准。它必须有一个不同的名称。请注意,我们现在正在关闭VHDL-2018,因此它将在此之后进行修订。

请注意,IEEE P1076 WG是基于个人的工作组。这意味着有经验的用户,例如您自己,正在参与。通常,标准修订版中的工作量是压倒性的。因此,我们总是需要更积极的参与者。特别是在包装上工作。请参阅eda-twiki.org和http://www.eda-twiki.org/cgi-bin/view.cgi/P1076/WebHome


3
投票

我找到了一个解决方法:

s_test_out  <=  to_stdlogicvector(to_bitvector(s_test_in));

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.