A
Art Stamness
Guest
And the answer is (the following is pseudo code in Verilog ) :
function [3:0] CountLeadingZeros ;
input [7:0] source ;
begin
// synopsys_full_case or something like that
casex ( source )
8'b1xxxxxx : CountLeadingZeros = 4'd0 ;
8'b01xxxxx : CountLeadingZeros = 4'd1 ;
8'b001xxxx : CountLeadingZeros = 4'd2 ;
... ( you can fill in the rest here )
8'b0000000 : CountLeadingZeros = 4'd8 ;
default : CountLeadingZeros = 4'dx ; // I always put in
defaults for simulation sake
endcasex
endfunction
This should do the trick. I have no clue what the other 21 people on
this thread are talking about, or why this wasn't the first answer. but
Here it is.
-Art
function [3:0] CountLeadingZeros ;
input [7:0] source ;
begin
// synopsys_full_case or something like that
casex ( source )
8'b1xxxxxx : CountLeadingZeros = 4'd0 ;
8'b01xxxxx : CountLeadingZeros = 4'd1 ;
8'b001xxxx : CountLeadingZeros = 4'd2 ;
... ( you can fill in the rest here )
8'b0000000 : CountLeadingZeros = 4'd8 ;
default : CountLeadingZeros = 4'dx ; // I always put in
defaults for simulation sake
endcasex
endfunction
This should do the trick. I have no clue what the other 21 people on
this thread are talking about, or why this wasn't the first answer. but
Here it is.
-Art