determine parity of a bit representation of a number in MIPS

Posted by Hristo on Stack Overflow See other posts from Stack Overflow or by Hristo
Published on 2010-04-11T15:17:18Z Indexed on 2010/04/11 17:13 UTC
Read the original article Hit count: 750

Filed under:
|

Is there some instruction in MIPS that will determine the parity of a certain bit representation? I know to determine whether a "number" has an even parity or an odd parity is to XOR the individual bits of the binary representation together, but that seems computationally-intensive for a set of MIPS instructions... and I need to do this as quick as possible.

Also, the number I'm working in is represented in Grey Code... just to throw that in there. So is there some pseudo-instruction in MIPS to determine the parity of a "number" or do I have to do it by hand?

If there is no MIPS instruction, which it seems very unlikely to be, any advice on how to do it by hand?

Thanks, Hristo

follow-up: I found a optimization, but my implementation isn't working.

unsigned int v; // 32-bit word
v ^= v >> 1;
v ^= v >> 2;
v = (v & 0x11111111U) * 0x11111111U;
return (v >> 28) & 1;

© Stack Overflow or respective owner

Related posts about mips

Related posts about parity