Count Leading Zero (CLZ) possible by MicroBlaze??

Hi all,

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?

Thanks,

Armando

Reply to
armandolou
Loading thread data ...

Unless you really only want to count the leading zeroes, which only needs a priority encoder...

Reply to
Gabor

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.

-- glen

Reply to
glen herrmannsfeldt

Hi,

thanks for the answers. I know it should not be difficult to implement the module in Hardware (or SW). But i would like to calculate the operation as quick as possible.

In the case of Hardware, i should attach the module to the processor of my system using a bus, and thus with a few more extra cycles.

I just would like to be sure that the Microblaze Prozessor does not have such an instruction and know if some of you have already had experiences with CLZ in a EDK system.

Thx again

Reply to
armandolou

=_NextPart_000_0DE2_01C804E8.098CDF10 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable

Hi,

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'.

G=C3=B6ran Bilski

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

Reply to
Göran Bilski

Hi,

thank you for your tip.

But i don't know how tu use the instruction set. I suppose i should write some assemble Code, but how and what are the commands?? Is there a datasheet or example on internet?

I am working with EDK 9 and SDK.

Thanks for the help

f instruction.

nd you will get the number of bytes that matches from left to right.

pcmbf against register 0 which always is 0.

r that do 8 bit search inside that byte.

n do a 32-bit search for the first '1'.

ister rB.

ing with MSB as position 1, and comparing until LSB as position 4

@50g2000hsm.googlegroups.com...

Reply to
Anacrom

Hi,

Here is the link to the MicroBlaze reference guide.

formatting link
If you have EDK, you will find the documentations under /doc in your install.

For how to program MicroBlaze, you will need to read about the software tools. But I would suggest doing a tutorial first to get a feeling on how things are done.

Göran Bilski

thank you for your tip.

But i don't know how tu use the instruction set. I suppose i should write some assemble Code, but how and what are the commands?? Is there a datasheet or example on internet?

I am working with EDK 9 and SDK.

Thanks for the help

Reply to
Göran Bilski

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.