Ones Counter

Discussion in 'VHDL' started by Paulo Valentim, Oct 20, 2004.

  1. Hello!

    David Bishop wrote in this newsgroup a function which implemented a
    recursive xor function. Please check out
    http://groups.google.com/groups?hl=pt&lr=&safe=off&selm=ey27d.27264$

    This worked beautifully in Synplify Pro 7.7. I tried extending the
    idea to do a "Ones counter" using a generic binary adder structure.
    The synthesis tool implements the function as if it was done in a FOR
    loop and not recursively. I'm just curious as if somebody can
    successfully use this function (get a binary adder tree) in another
    synthesis tool or if there is a better way of doing this.
    Thanks a lot. BTW, here is the code I adapted from Bishop's code.

    function ones_count (arg : std_logic_vector )
    return integer is
    variable Upper, Lower : integer range 0 to VEC_SIZE;
    variable Half : integer range 0 to VEC_SIZE;
    variable BUS_int : std_logic_vector ( arg'length - 1 downto 0 );
    variable Result : integer range 0 to VEC_SIZE;

    begin
    if (arg'LENGTH < 1) then -- In the case of a NULL
    range
    Result := 0;
    else
    BUS_int := to_ux01 (arg);
    if ( BUS_int'length = 1 ) then
    Result := conv_integer(BUS_int ( BUS_int'left ));
    elsif ( BUS_int'length = 2 ) then
    Result := conv_integer(BUS_int ( BUS_int'right )) +
    conv_integer(BUS_int ( BUS_int'left));
    else
    Half := ( BUS_int'length + 1 ) / 2 + BUS_int'right;
    Upper := ones_count ( BUS_int ( BUS_int'left downto Half ));
    Lower := ones_count ( BUS_int ( Half - 1 downto
    BUS_int'right));
    Result := Upper + Lower;
    end if;
    end if;
    return Result;
    end;

    Any ideas to make this work better? Thanks!

    - Paulo Valentim
    Paulo Valentim, Oct 20, 2004
    #1
    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:
    0
    Views:
    670
  2. The Eeediot
    Replies:
    3
    Views:
    2,225
    =?Utf-8?B?UnVsaW4gSG9uZw==?=
    Dec 22, 2004
  3. =?Utf-8?B?Um9iS2FyYXR6YXM=?=

    application keys in web config (no taking new ones?)

    =?Utf-8?B?Um9iS2FyYXR6YXM=?=, Dec 12, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    718
    Karl Seguin
    Dec 12, 2005
  4. =?Utf-8?B?Sm9u?=

    Debug DLL Performance over runtime ones

    =?Utf-8?B?Sm9u?=, Mar 31, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    419
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Mar 31, 2006
  5. George2
    Replies:
    1
    Views:
    792
    Alf P. Steinbach
    Jan 31, 2008
Loading...

Share This Page