static int count_leading_zeros(int input, LeadingZeros lz) { int output = 0; int curbyte = 0; curbyte = input >> 24; if (curbyte != 0) { count_leading_zeros_extra(curbyte, output, lz); output = lz.output; curbyte = lz.curbyte; return(output); } output += 8; curbyte = input >> 16; if ((curbyte & 0xFF) != 0) { count_leading_zeros_extra(curbyte, output, lz); output = lz.output; curbyte = lz.curbyte; return(output); } output += 8; curbyte = input >> 8; if ((curbyte & 0xFF) != 0) { count_leading_zeros_extra(curbyte, output, lz); output = lz.output; curbyte = lz.curbyte; return(output); } output += 8; curbyte = input; if ((curbyte & 0xFF) != 0) { count_leading_zeros_extra(curbyte, output, lz); output = lz.output; curbyte = lz.curbyte; return(output); } output += 8; return(output); }
static LeadingZeros count_leading_zeros_extra(int curbyte, int output, LeadingZeros lz) { if ((curbyte & 0xf0) == 0) { output += 4; } else { curbyte = curbyte >> 4; } if ((curbyte & 0x8) != 0) { lz.output = output; lz.curbyte = curbyte; return(lz); } if ((curbyte & 0x4) != 0) { lz.output = output + 1; lz.curbyte = curbyte; return(lz); } if ((curbyte & 0x2) != 0) { lz.output = output + 2; lz.curbyte = curbyte; return(lz); } if ((curbyte & 0x1) != 0) { lz.output = output + 3; lz.curbyte = curbyte; return(lz); } /* shouldn't get here: */ lz.output = output + 4; lz.curbyte = curbyte; return(lz); }