vhdl

VHDL-2008 to_01 conversion


I am getting some unexpected behavior when using the to_01 conversion function in VHDL-2008. My expectation would be that vector bits that can clearly be interpreted as high or low are mapped to '1' and '0' respectively. The remaining vector bits should be converted to '0' bits. However, with the code depicted below, I get the whole vector converted to all '0's.

Is this behavior correct? Or is this a bug in the simulator software (ALDEC Riviera-PRO)?

Is there any IEEE function that meets my expectations or do I have to write my own function to achieve that?

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


Solution

  • The observed behavior is the correct behavior. A little history about this follows.

    In 2008, we propagated all of the strength reduction operations to all std_logic family packages. For better or worse, the historical implementation of to_01 comes from numeric_std and was implemented exactly as it is now. The following is an older implementation I was able to find on the web:

    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;
    

    One of the prime directives of the VHDL WG is to not break old code. In this case it looks like this objective put forward an implementation that perhaps is less desirable.

    If you want something different, you can always put it forward for the next revision of the standard. It would have to have a different name. Note we are currently closing on VHDL-2018 now, so it would be the revision after that.

    Note that IEEE P1076 WG is an individual based working group. This means experienced users, such as yourself, are participating. Typically the amount of work done in a standards revision is overwhelming. As a result, we always need more active participants. Particularly working on the packages. See eda-twiki.org and http://www.eda-twiki.org/cgi-bin/view.cgi/P1076/WebHome