Issues with to_01 for arrays of std_logic
Description Current implementation of to_01 for arrays of std_logic changes all values to the XMAP character if any X is encountered. If we have a bus and half of it is tristated or those bits are unused, then it is acceptable that they are X.
function TO_01 (s : STD_ULOGIC_VECTOR; xmap : STD_ULOGIC := '0')
return STD_ULOGIC_VECTOR
is
variable RESULT : STD_ULOGIC_VECTOR(s'length-1 downto 0);
variable BAD_ELEMENT : BOOLEAN := false;
alias XS : STD_ULOGIC_VECTOR(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
for I in RESULT'range loop
RESULT(I) := XMAP; -- standard fixup
end loop;
end if;
return RESULT;
end function TO_01;
-------------------------------------------------------------------
function TO_01 (s : STD_ULOGIC; xmap : STD_ULOGIC := '0') return STD_ULOGIC is
begin
case s is
when '0' | 'L' => RETURN '0';
when '1' | 'H' => RETURN '1';
when others => return xmap;
end case;
end function TO_01;
I expected the to_01 function to be:
function TO_01 (s : STD_ULOGIC_VECTOR; xmap : STD_ULOGIC := '0')
return STD_ULOGIC_VECTOR
is
variable RESULT : STD_ULOGIC_VECTOR(s'length-1 downto 0);
begin
for i in RESULT'range loop
Result(i) := to_01(s(i), xmap) ;
end loop ;
return RESULT;
end function TO_01;
This brings up the issue how do one address historical items that break backward compatibility?
It looks like many things do this in std_logic_1164 and numeric_std - such as to_integer. OTOH, to_bitvector looks like it does not do this.
Choices
Break backwards compatibility or introduce a new set of conversions that treat X as 0 - and for arrays only does this on a bitwise basis and does not corrupt the other values in the object.
Edited by JimLewis