+ Post New Thread
Results 1 to 9 of 9
  1. #1
    Newbie level 5
    Points: 49, Level: 1

    Join Date
    Apr 2019
    Posts
    8
    Helped
    0 / 0
    Points
    49
    Level
    1

    Design to state position of first one from lsb every clock for parallel data coming

    Can you please provide a design whose output will state the location of the first '1' from the LSB for an incoming parallel bit stream every clock?

  2. #2
    Advanced Member level 5
    Points: 7,802, Level: 21

    Join Date
    Apr 2016
    Posts
    1,642
    Helped
    289 / 289
    Points
    7,802
    Level
    21

    Re: Design to state position of first one from lsb every clock for parallel data comi

    Is this a homework?
    Really, I am not Sam.



    •   AltAdvertisment

        
       

  3. #3
    Newbie level 5
    Points: 49, Level: 1

    Join Date
    Apr 2019
    Posts
    8
    Helped
    0 / 0
    Points
    49
    Level
    1

    Re: Design to state position of first one from lsb every clock for parallel data comi

    Quote Originally Posted by ThisIsNotSam View Post
    Is this a homework?
    No it is not. Please reply.



    •   AltAdvertisment

        
       

  4. #4
    Super Moderator
    Points: 30,234, Level: 42
    ads-ee's Avatar
    Join Date
    Sep 2013
    Location
    USA
    Posts
    6,967
    Helped
    1659 / 1659
    Points
    30,234
    Level
    42

    Re: Design to state position of first one from lsb every clock for parallel data comi

    Quote Originally Posted by fragnen View Post
    No it is not. Please reply.
    You seem to have a misconception of what this forum is about. Members will help you with answering questions you may have on a variety of electronics related topics. They will assist you in resolving problems you may have in code or concepts. What members are unlikely to help with is: Doing your work for you.

    You have an assignment or a need to have this circuit then do one or more of the following:
    a) design it yourself
    b) hire someone to design it, if you are not capable of designing such a circuit
    c) try to design it and ask questions on the forum (showing what you have done) about any problems with your circuit that you can't figure out how to fix.
    d) search the internet for your answer

    Of the various options you will learn the most by doing either a or c.



    •   AltAdvertisment

        
       

  5. #5
    Advanced Member level 3
    Points: 6,767, Level: 19
    Achievements:
    7 years registered

    Join Date
    Jul 2010
    Location
    Sweden
    Posts
    877
    Helped
    352 / 352
    Points
    6,767
    Level
    19

    Re: Design to state position of first one from lsb every clock for parallel data comi

    Quote Originally Posted by fragnen View Post
    Can you please provide a design whose output will state the location of the first '1' from the LSB for an incoming parallel bit stream every clock?
    What you want is identical to a "priority encoder."



  6. #6
    Advanced Member level 3
    Points: 5,911, Level: 18

    Join Date
    Feb 2015
    Posts
    969
    Helped
    278 / 278
    Points
    5,911
    Level
    18

    Re: Design to state position of first one from lsb every clock for parallel data comi

    There are 2-3 ways to code this. The obvious is a for loop from msb to lsb. This actually works when the synthesis tool understands and implements this in a good way. The fancy way uses "bitscan" with (x) & (-x). This expression returns a one-hot vector with the lowest 1 being the only bit set. The third method is manually generating the logic for a priority encoder.

    There is also a priority encoder implementation that takes a 1-hot vector and does the and-or map-reduce with 10101010, 11001100, 11110000, etc...



  7. #7
    Newbie level 5
    Points: 49, Level: 1

    Join Date
    Apr 2019
    Posts
    8
    Helped
    0 / 0
    Points
    49
    Level
    1

    Re: Design to state position of first one from lsb every clock for parallel data comi

    Quote Originally Posted by vGoodtimes View Post
    There are 2-3 ways to code this. The obvious is a for loop from msb to lsb. This actually works when the synthesis tool understands and implements this in a good way. The fancy way uses "bitscan" with (x) & (-x). This expression returns a one-hot vector with the lowest 1 being the only bit set. The third method is manually generating the logic for a priority encoder.

    There is also a priority encoder implementation that takes a 1-hot vector and does the and-or map-reduce with 10101010, 11001100, 11110000, etc...
    Will the rtl with for loop be synthesizable ? But for loop reduces the work. If it is a priority encoder it is a big code when the width of the input data is parametrized.

    What is the bitscan mathod. What is x and what is -x?

    Thank you.



    •   AltAdvertisment

        
       

  8. #8
    Super Moderator
    Points: 253,760, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    44,217
    Helped
    13458 / 13458
    Points
    253,760
    Level
    100

    Re: Design to state position of first one from lsb every clock for parallel data comi

    What is x and what is -x?
    Review this previous thread for an explanation. https://www.edaboard.com/showthread....d_logic_vector

    In my view, a behavioral description of the intended logic, typically using a for loop is a straightforward approach to synthesize it, as long as you don't have additional requirements, e.g. implementing pipelining or enforcing a specific hardware implementation like using carry chains to speed up the design.

    Some synthesis tools have difficulties to implement non-arithmetic problems like priority encoder optimally following a behavioral description, but they are always able to implement it correctly.



  9. #9
    Full Member level 1
    Points: 1,369, Level: 8

    Join Date
    Feb 2014
    Posts
    98
    Helped
    3 / 3
    Points
    1,369
    Level
    8

    Re: Design to state position of first one from lsb every clock for parallel data comi

    Code:
    for (i=0; i<WIDTH, i=i+1) begin
      if (input[i]) begin
        position = i;
        break;
      end
    end


    1 members found this post helpful.

--[[ ]]--