1
\$\begingroup\$

Have a an array of type std_logic_vector which holds some status flags which I have to combine(OR) into one single flag of type std_logic.

Is there a more elegant and effective way than doing it by hand

flag <= x(0)(1) OR x(1)(1) OR x(2)(1) OR x(3)(1) OR x(4)(1) OR x(5)(1) OR 
        x(6)(1) OR x(7)(1) OR x(8)(1) OR x(9)(1) OR x(10)(1) OR x(11)(1) OR
        x(12)(1) OR x(13)(1) OR x(14)(1);

Can this be achieved using some kind of generate statement?

\$\endgroup\$
2
\$\begingroup\$

Use a loop.

flag := false;
for i in 0 to x'high loop
  flag := flag or x(i)(1);
end loop;

If you insist on having flag be a signal, use a function which uses a loop. In fact, always use this function, but also turn flag into a variable.

function or_reduce_index(array : t_flag_array_type,
                         flag_index : natural) return std_logic is
  variable result : std_logic;
begin
  result := false;
  for i in 0 to array'high loop
    result := result or array(i)(flag_index);
  end loop;
  return result;
end;

flag := or_reduce_index(x, 1); -- somewhere else

Flag should probably also be a boolean.

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.