I need to take the absolute value of a result and I am only interested in the most significant bits. This is what I have done:
data_ram_h <= std_logic_vector(abs(signed(resize(r4(calc_cnt - 2), data_ram_h'length) + r4(calc_cnt - 1) +
r4(calc_cnt) + r4(calc_cnt + 1) + r4(calc_cnt + 2) -
r2(calc_cnt - 2) - r2(calc_cnt - 1) - r2(calc_cnt) -
r2(calc_cnt + 1) - r2(calc_cnt + 2))))(11 downto 4);
I try to check the syntax and I get this error:
type conversion std_logic_vector is not allowed as a prefix for an slice name.
data_ram_h is a std_logic_vector of the right dimension, and the abs function returns a signed, to there shouldn't be problem in the conversion to std_logic_vector. The library I am using is use ieee.numeric_std.all.
Where am I wrong? Thanks in advance c:
A type conversion is a basic operation that happens to require parentheses around it's operand expression. And there's the rub, it's use is not a function call, so it can't be used as a prefix for a slice name.
A prefix for a slice name is either a function_call or a name. (IEEE Std 1076-2008, 5 Types, 5.1 General, explicit type conversion, 8 Names, 8.1 General, 8.5 Slice names).
If it was a function call you could slice the result.
On the other hand you can slice `"abs", so slice that and then do the type conversion:
Using
abs
as a function call requires you use it's declared name which is"abs"
.I'm just guessing at some declarations here, so I can't guarantee this works in your code. The above example does analyze, elaborate and run which says the subtype ranges are compatible.
Finally I solved my doubt. Even
std_logic_vector
is a function, so I need 3 variables to slice the result without errors. Here what I did:With the following definitions:
Thanks Paebbels for your comment :)
If someone has a better way to solve it, please post it!