Fixed_pkg: PRoblem using ABS operator

Discussion in 'VHDL' started by Ved, Jul 28, 2006.

  1. Ved

    Ved Guest

    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
     
    Ved, Jul 28, 2006
    #1
    1. Advertising

  2. Ved

    David Bishop Guest

    Ved wrote:
    > 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

    > -----Do something
    >
    > else
    > ----do something else
    > end if;
    > end process;
    > .....................
    >
    > Please give your valuable comments.
    > Thanks
    > Ved
    >
     
    David Bishop, Jul 30, 2006
    #2
    1. Advertising

  3. Ved

    Ved Guest

    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
    ......................
     
    Ved, Jul 31, 2006
    #3
  4. Ved

    Guest

    Hi David, Ved and anyone else who can help

    David Bishop wrote:
    > 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
     
    , Aug 3, 2006
    #4
  5. Ved

    Ved Guest

    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
     
    Ved, Aug 4, 2006
    #5
  6. Ved

    amakyonin Guest

    Ved wrote:
    > 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.
     
    amakyonin, Aug 7, 2006
    #6
  7. Ved

    Guest

    > 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:

    > 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?
     
    , Aug 8, 2006
    #7
  8. Ved

    Guest

    wrote:
    > Thanks for the answer amakyonin, that's exactly what I meant when I
    > asked:
    >
    > > 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?


    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;
     
    , Aug 8, 2006
    #8
  9. Ved

    David Bishop Guest

    wrote:
    > wrote:
    >> Thanks for the answer amakyonin, that's exactly what I meant when I
    >> asked:
    >>
    >>> 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?

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


    You proved it. I'm rewriting it.

    I'm changing the "abs (sfixed) return ufixed" to a "to_ufixed(sfixed)
    function. That should fix the problem.

    I should have something up on:
    http://www.vhdl.org/vhdl-200x/vhdl-200x-ft/packages/files.html
    Monday or Tuesday.
     
    David Bishop, Aug 12, 2006
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    6
    Views:
    1,943
    Divyang M
    Dec 14, 2004
  2. Divyang M
    Replies:
    3
    Views:
    599
    David Bishop
    Feb 4, 2005
  3. Replies:
    2
    Views:
    545
  4. Jamin
    Replies:
    7
    Views:
    874
    Jamin
    Jan 29, 2007
  5. Klaas Vantournhout

    f2c's abs conflicts with <complex> abs

    Klaas Vantournhout, Oct 31, 2006, in forum: C++
    Replies:
    3
    Views:
    388
    Victor Bazarov
    Oct 31, 2006
Loading...

Share This Page