Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9266879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:25:10+00:00 2026-06-18T14:25:10+00:00

I want to implement the K&R algorithm for hamming weight calculation of 256 bit

  • 0

I want to implement the K&R algorithm for hamming weight calculation of 256 bit vector. I have written my code in vhdl as:

entity counter_loop is
    Port ( dataIn : in  STD_LOGIC_VECTOR (255 downto 0);
              dataOut : out STD_LOGIC_VECTOR (8 downto 0);
           threshold : in  STD_LOGIC_VECTOR (8 downto 0);
           clk : in  STD_LOGIC;
           flag : out  STD_LOGIC);
end counter_loop;

architecture Behavioral of counter_loop is
    signal val : STD_LOGIC_VECTOR (255 downto 0) := X"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF";
begin
    process (clk)
        variable count : STD_LOGIC_VECTOR (8 downto 0):= "000000000";       
    begin
        flag <= '0';
        val <= dataIn;
        --if(clk'event and clk = '1') then 
            while (val > 0) loop
                count := count+1;
                val <= (val and (val-1));
                if (count > threshold) then
                    flag <= '1';
                end if;
            end loop;
                dataOut <= count;
        --end if;
    end process;
end Behavioral;

But, while synthesizing it using Xilinx, the error comes up as

Line 53: Non-static loop limit exceeded

Any clues please?

P.S: Line 53 is – while (val > 0) loop

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T14:25:12+00:00Added an answer on June 18, 2026 at 2:25 pm

    So, I’m going to ignore issues of things actually meeting timing (val - 1 is expensive) and actually talk about your logic.

    Here’s a piece of your code:

    signal val : std_logic_vector(255 downto 0) := (others => '1');
    
    process (clk)
    begin
        while (val > 0) loop
            val <= (val and (val-1));
        end loop;
    end process;
    

    val is a signal, not a variable. That means it will be updated when you finish the delta cycle. Which in this case, will be never. So you have an infinite loop.


    If you’re just trying to calculate the popcount of a number, then why don’t you just do this. Although I doubt this will meet timing as well (Probably need to break it up over multiple clock cycles).

    process (clk)
        variable count : std_logic_vector(8 downto 0) := "0" & x"00";
    begin
        if rising_edge(clk) then
            for i in dataIn'range loop
                if dataIn(i) = '1' then
                    count := count + 1;
                end if;
            end loop;
    
            dataOut <= count_i;
        end if;
    end process;
    

    And finally, most people would argue that algorithms designed for C code often perform poorly in hardware, because hardware has different capabilities than a fixed processor.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to implement drag&drop possibilities in my application. Here is my source code:
for a datastructures & algorithms class in college we have to implement an algorithm
I have a Category List & I want to implement History.Java in my project.
i have calculated maximum flow using ford fulkerson algorithm,now i want to implement project
i have developed website & i want to implement ssl in that but My
I started my project in Asp.net MVC(c#) & SQL Server 2005.I want to implement
i starter in jqgrid, i want implement inline edit in jqgrid i have this
I want to implement the Binary Quicksort algorithm from [Robert Sedgewick's book][1]. It looks
I read Introduction to Algorithms by Cormen&Co and implement algorithm on java. I wonder
I'm trying to implement a Quicksort algorithm, I have read how to do it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.