2
type matrixsignal is array (LEVELS downto 0) of std_logic_vector(NBIT-1 downto 0);
signal p_matrix, g_matrix: matrixsignal;
signal col_temp_g, col_temp_p : std_logic_vector(LEVELS downto 0);

...

col_temp_p<=p_matrix(LEVELS downto 0)(j-1);
col_temp_g<=g_matrix(LEVELS downto 0)(j-1);

Hello everyone! I want to select and copy the entire column (j-1) of the 2 arrays...but the compiler tells me that this way is not the correct one. How is it possible to do it?

P.S. LEVELS,NBIT,j are initialized parameters...I did not report their initialization.

1
  • You don't provide a minimal reproducible example nor identify the error. It's possible to construct an MCVe from your snippets but it doesn't do what you want, instead of taking a column, takes a level from an index name whose prefix is a slice name. A bounds error can occur when NBIT - 1 is not equal to LEVELS. (The slice names are perfect subsets of their prefixes). It's possible to column slice a single dimensional array's elements (std_logic_vector) and construct a std_logic_vector with a function if you get the length of target right. A 'corner turn' function doesn't imply any hardware just name organization. Commented Apr 8, 2018 at 21:29

1 Answer 1

2

You should define matrixsignal as a 2-dimensional array instead of a one-dimensional array that nests another 1-dimensional array.

type matrixsignal is array(LEVELS downto 0, NBIT - 1 downto 0) of std_logic;

The PoC-Library offers that type as T_SLM (std_logic_matrix) together lot's of manipulation functions and procedures in package PoC.vectors. E.g. PoC defines a get_col function like this:

function get_col(slm : T_SLM; ColIndex : natural) return std_logic_vector is
  variable slv      : std_logic_vector(slm'range(1));
begin
  for i in slm'range(1) loop
    slv(i)  := slm(i, ColIndex);
  end loop;
  return slv;
end function;

Usage:

subtype matrixsignal is T_SLM(LEVELS downto 0, NBIT - 1 downto 0);
signal p_matrix, g_matrix     : matrixsignal;
signal col_temp_g, col_temp_p : std_logic_vector(LEVELS downto 0);

...

col_temp_p <= get_col(p_matrix, j - 1);
col_temp_g <= get_col(g_matrix, j - 1);

The package PoC.vectors can be synthesized.

Further functions are provided like:

  • slicing a complete row
  • slicing sub matrixes
  • flattening / serialization
  • creating matrix from vector / deserialization
  • overloaded boolean operators
  • row / column assignment
  • matrix merging
  • conversion to/from 1-dimensional array types containing another 1-dimensional array type
  • ...
Sign up to request clarification or add additional context in comments.

2 Comments

Patrick and his PoC co-author(s) have done yeoman's work developing the entire library. It's not clear the entire work is applicable here and promoting it seems a bit like encouraging the camel's nose under the tent skirt without emphasizing the licensed right to create derivative works without some of the overhead.
@user1155120 I have presented the solution (function) that is required to answer his question. By correct attribution of the used package I a) honor the Apache 2.0 License of PoC; b) I protect that code from becoming CC-BY-SA licensed by StackOverflow; c) I don't pretend that we should reinvent the wheel every day.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.