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??
Here’s a possible approach (I’m ignoring the case of an input of 0, which is probably best treated as a special case):
In Verilog, it might look something like this: