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 669365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:08:36+00:00 2026-05-14T00:08:36+00:00

As you all might know that the MIPS instruction set supports clz (count leading

  • 0

As you all might know that the MIPS instruction set supports clz (count leading zero) as follows:

clz $t0,$t1 count leading zeros t0 = # of leading zeros in t1

I am writing a single cycle datapath in verilog and was just wondering what the ALU needs to support in order for me to do this… any ideas??

  • 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-05-14T00:08:37+00:00Added an answer on May 14, 2026 at 12:08 am

    Here’s a possible approach (I’m ignoring the case of an input of 0, which is probably best treated as a special case):

    • The number of leading zeros in a 32-bit number is either:
      • the number of leading zeros in the top 16 bits, if any of the top 16 bits are non-zero; or
      • 16, plus the number of leading zeros in the bottom 16 bits, if the top 16 bits are all zero
    • That gives the top bit of the 5-bit result (ignoring the special case of an input of 0…).
    • Now you need to find the number of leading zeros in a 16-bit number, so apply the same principle again.
    • etc.

    In Verilog, it might look something like this:

    result[4] = (value[31:16] == 16'b0);
    val16     = result[4] ? value[15:0] : value[31:16];
    result[3] = (val16[15:8] == 8'b0);
    val8      = result[3] ? val16[7:0] : val16[15:8];
    result[2] = (val8[7:4] == 4'b0);
    val4      = result[2] ? val8[3:0] : val8[7:4];
    result[1] = (val4[3:2] == 2'b0);
    result[0] = result[1] ? ~val4[1] : ~val4[3];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

You all might know that iOS takes a screen shot of your application before
I know this might sound really ridiculas but all of a sudden when I
I have a (big) problem that all of you that work with Webforms might
We all know that Debug.Assert will not be compiled into the dlls when compiled
I know that this question might have been asked like 100 times, but, believe
I know that a consequence of using the prototype is that all added properties
As you might know, all threads in the application die in a forked process,
We all know that we should rather reuse a JDBC PreparedStatement than creating a
Just curious: sure, we all know that the general case of type inference for
We all know that we should only be publishing our ASP.NET Web Applications with

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.