Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data loss in AXI Slave VC #953

Open
hcommin opened this issue Aug 15, 2023 · 0 comments
Open

Data loss in AXI Slave VC #953

hcommin opened this issue Aug 15, 2023 · 0 comments

Comments

@hcommin
Copy link

hcommin commented Aug 15, 2023

Problem

The axi_write_slave VC has std_logic_vector ports, but internally stores data as integer.

Converting to two-level logic is understandable in terms of execution speed. However, the conversion from 9-level to 2-level logic uses to_integer, which presumes the data to be numeric:

record_input_data(input_data, aligned_address+j, to_integer(unsigned(wdata(8*j+7 downto 8*j))));

This means valid data is lost if it is (for example) padded with 'X':

Example: Write "X1010101" --> Read "00000000".

Expected Behavior

If the port types were signed or unsigned then I think we could possibly argue that the current behavior is valid (because the input is an undefined numeric value). However, for non-numeric std_logic_vector, there should be no dependency between the data bits.

Either of these behaviors could be considered valid (but the first is more conventional):

  • Write "X1010101" --> Read "01010101".
  • Write "X1010101" --> Read "11010101".

Possible Solution

VHDL-2008 infamously implemented to_01 in a "less desirable" way, so I think standard practice is to define a more desirable function like this:

function to01(x : std_logic_vector) return std_logic_vector is
begin
  return to_stdlogicvector(to_bitvector(x));
end;

which could be called like this:

record_input_data(input_data, aligned_address+j, to_integer(unsigned(to01(wdata(8*j+7 downto 8*j)))));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant