Fixed_pkg: PRoblem using ABS operator

V

Ved

Hi,
I have just started using Fixed point package (fixed_pkg).
I have written a program where absolute values of elements of an array
are compared.
I get error (mentioned below) when I use "abs" operator.
When I remove abs operator, things work fine but ofcourse with
considering the signed value, which does not solve my purpose.

First I thought that it might be because of presence of ARITH and
SIGNED package and since they also have abs and > operator, so
ambiguity might be because of that. But removing those packages also
didn't help.


----Error message

** Error: : Subprogram '>' is ambiguous.
** Error: : Type error resolving infix expression ">".
--------------------------------------------------------------------------------

library WORK,IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_SIGNED.ALL;
use WORK.CONV.ALL;

use work.fixed_pkg.all; ---fixed package

type FiTYPE_IO is array(0 to N-2) of sfixed(4 downto -9);
.................
process(clock)

variable TEST: FiTYPE_IO ;

begin

if abs(TEST(j+1)) > abs(TEST(j)) then

-----Do something

else
----do something else
end if;
end process;
......................

Please give your valuable comments.
Thanks
Ved
 
D

David Bishop

Ved said:
Hi,
I have just started using Fixed point package (fixed_pkg).
I have written a program where absolute values of elements of an array
are compared.
I get error (mentioned below) when I use "abs" operator.
When I remove abs operator, things work fine but ofcourse with
considering the signed value, which does not solve my purpose.

I'm the guy who wrote these packages, let me take a look.
First I thought that it might be because of presence of ARITH and
SIGNED package and since they also have abs and > operator, so
ambiguity might be because of that. But removing those packages also
didn't help.


----Error message

** Error: : Subprogram '>' is ambiguous.
** Error: : Type error resolving infix expression ">".

The ">" operator used in the packages is the one from the "numeric_std"
package. The fixed_pkg was designed only to work with the IEEE packages.
--------------------------------------------------------------------------------

library WORK,IEEE;
use IEEE.STD_LOGIC_1164.ALL;
Good.

use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_SIGNED.ALL;
use WORK.CONV.ALL;

Replace these with the "ieee.numeric_std.all".
use work.fixed_pkg.all; ---fixed package

type FiTYPE_IO is array(0 to N-2) of sfixed(4 downto -9);
................
process(clock)

variable TEST: FiTYPE_IO ;

begin

if abs(TEST(j+1)) > abs(TEST(j)) then

I see the problem. There are two copies of the "abs" routine, one
returns a "sfixed", and the other returns a "ufixed". Giving the ">"
function two choices. Try this:

if sfixed (abs(TEST(j+1))) > abs(TEST(j)) then
 
V

Ved

Hi David,
I'm the guy who wrote these packages, let me take a look.
I am very well aware and thankfull to you for writting these packages
as they were desperately needed for people working in communications
field like me.


Thanks for the reply.
After making the suggested changes, my code now looks like the one
shown below.
But now new error message is coming
Thanks
Ved

---Error message

** Error: Ambiguous type in prefix expression; ufixed or sfixed.
** Error: Illegal type conversion to sfixed (operand type is not
known).


library WORK,IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.numeric_std.ALL;

use WORK.CONV.ALL; ---my package

use work.fixed_pkg.all; ---fixed package

type FiTYPE_IO is array(0 to N-2) of sfixed(4 downto -9);
.................
process(clock)

variable list : FiTYPE_IO ;

begin

if sfixed(abs(list(j+1))) > abs(list(j)) then

-----Do something
......................
 
R

rnbrady

Hi David, Ved and anyone else who can help

David said:
I see the problem. There are two copies of the "abs" routine, one
returns a "sfixed", and the other returns a "ufixed". Giving the ">"
function two choices. Try this:

if sfixed (abs(TEST(j+1))) > abs(TEST(j)) then

I tried this and it doesn't work. The typecast itself is ambiguous
becuase it doesn't know if your trying
to convert sifed to sfixed or ufixed to ufixed. Error message is same
as described by Ved.



Is it OK to have two function signatures differ only in their return
type? I see in numeric_std that there is only one "abs," and it's
signature is (signed) return signed. Why does fixed_pkg have two?

If it is OK for two functions with same name to differ only in return
type, what is the inline method for specifying which one to use in an
expression?

Regards,
Richard
 
V

Ved

Hi,
There is some casting problem and David is working on it.

David suggested me to do like this:

jtmp---> is type sfixed one bit more than list.

jtmp := abs(list(j+1));
if jtmp > (list(j)) then
 
A

amakyonin

Ved said:
Hi,
There is some casting problem and David is working on it.

David suggested me to do like this:

jtmp---> is type sfixed one bit more than list.

jtmp := abs(list(j+1));
if jtmp > (list(j)) then

VHDL provides a signature mechanism to disambiguate which version of an
overloaded function you want to use:

abs[sfixed return sfixed](...);

Note that you have to call the operator directly as a function rather
than as an operator.

You can also alias a function with a signature to make your expressions
cleaner:

alias sfabs is abs[sfixed return sfixed];

sfabs(...)

Unfortunately, Synplify still doesn't support signatures (at least as
of a few months ago). Other synthesizers may have better support for
VHDL-87.
 
R

rnbrady

VHDL provides a signature mechanism to disambiguate which version of an
overloaded function you want to use:

abs[sfixed return sfixed](...);

Note that you have to call the operator directly as a function rather
than as an operator.

Thanks for the answer amakyonin, that's exactly what I meant when I
asked:
 
R

rnbrady

Thanks for the answer amakyonin, that's exactly what I meant when I
asked:

OK, I spoke too soon there. This doesn't work with ModelSim. The alias
idea works, but the signature cannot be inlined.

I boiled it down to the essense of the problem. See attached. Tests 4,
5 and 6 will not compile.

Test 4 is expected to fail. David, this brings up the question again of
why their are two versions of "abs" in fixed_pkg as opposed to only one
version in numeric_std.

Tests 5 and 6 are not expected to fail, unless I'm missing something.

Richard

--problem.vhd
------------------------------------------------------------------------------------------------
library IEEE;
use work.fixed_pkg.all;

entity problem is
end entity;

architecture beh of problem is
subtype a is sfixed(1 downto -1);
subtype b is ufixed(1 downto -1);
constant c : a := to_sfixed(1.0, 1, -1);
constant d : a := to_sfixed(-0.5, 1, -1);
alias e is work.fixed_pkg."abs"[a return b];
begin

-- Test 1
assert abs(-4) < abs(-3)
report "Assert 1."
severity note;

-- Test 2
assert c < d
report "Assert 2."
severity note;

-- Test 3
assert abs(c) < d
report "Assert 3."
severity note;

-- Test 4
assert abs(c) < abs(d)
report "Assert 4."
severity note;

-- Test 5
assert work.fixed_pkg."abs"[a return b](c) < work.fixed_pkg."abs"[a
return b](d)
report "Assert 5."
severity note;

-- Test 6
assert abs[a return b](c)(c) < abs[a return b](c)(d)
report "Assert 6."
severity note;

-- Test 7
assert e(c) < e(d)
report "Assert 7."
severity note;

end beh;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top