does anyone know if the MicroBlaze Processor of Xilinx has the CLZ Instruction? I took a look in the datasheet, but didn't find anything about it. I would like to count the number of zeros in a 32-bit Register in one cycle.
If this processor does not support this function, could you maybe suggest me how to calculate this operation as fast as possible?
It is more common to have an instruction to count ones. If so, complement and then count the ones.
There are well known ways to do this in C, though maybe not as fast as you would like. One uses a 256 byte lookup table and sums over the four bytes of a 32 bit value. Another uses the bitwise AND operator and addition to add pairs of bits, sums the pairs, quads, octets, etc.
It is not hard to do in FPGA logic as a carry save adder tree. If it can't be done in a single cycle at your clock rate it is easily pipelined.
It's better to add the HW module to FSL instead to the bus.
There is currently no CLZ instruction for MicroBlaze. You can however do an optimized software implementation by using the = pcmbf instruction. The instruction will compare a register with another register byte-wise = and you will get the number of bytes that matches from left to right. So if you have the value you want to do a CLZ in a register, you can do = a pcmbf against register 0 which always is 0. You will know in which byte the first leading '1' is located and can = after that do 8 bit search inside that byte.
It will not be done in one clock cycle but is most likely much faster = than do a 32-bit search for the first '1'.
From MicroBlaze reference guide:
pcmpbf Pattern Compare Byte Find=20 Description=20 The contents of register rA is bytewise compared with the contents in = register rB.=20 =E2=80=A2 rD is loaded with the position of the first matching byte = pair, starting with MSB as position 1, and comparing until LSB as = position 4=20 =E2=80=A2 If none of the byte pairs match, rD is set to 0=20 Pseudocode=20 if rB[0:7] =3D rA[0:7] then (rD) =E2=86=90 1 else=20 if rB[8:15] =3D rA[8:15] then (rD) =E2=86=90 2=20 else=20 if rB[16:23] =3D rA[16:23] then (rD) =E2=86=90 3 else=20 if rB[24:31] =3D rA[24:31] then (rD) =E2=86=90 4=20 else=20 (rD) =E2=86=90 0=20