Encoding:

POOL32A

000000

rt

rd

0

0000

BITSWAP

101100

POOL32Axf

111100

6

5

5

4

6

6

POOL32S

010110

rt

rd

0

0000

DBITSWAP

101100

POOL32Sxf

111100

6

5

5

4

6

6

Format:

BITSWAP DBITSWAP 

Swaps (reverses) bits in each byte

BITSWAP rd,rt

microMIPS32 Release 6

Swaps (reverses) bits in each byte

DBITSWAP rd,rt

microMIPS64 Release 6

Swaps (reverses) bits in each byte

Purpose:

Swaps (reverses) bits in each byte

Description:

GPR[rd].byte(i) =reverse_bits_in_byte(GPR[rt].byte(i)), for all bytes i

Each byte in input GPR rt is moved to the same byte position in output GPR rd, with bits in each byte reversed.

BITSWAP is a 32-bit instruction. BITSWAP operates on all 4 bytes of a 32-bit GPR on a 32-bit CPU. On a 64-bit

CPU, BITSWAP operates on the low 4 bytes, sign extending to 64-bits.

DBITSWAP operates on all 8 bytes of a 64-bit GPR on a 64-bit CPU.

Restrictions:

BITSWAP: None.

Availability and Compatibility:

The BITSWAP instruction is introduced by and required as of Release 6.

The DBITSWAP instruction is introduced by and required as of Release 6.

Operation:

BITSWAP:
   for i in 0 to 3 do  /* for all bytes in 32-bit GPR width */
      tmp.byte(i) = reverse_bits_in_byte( GPR[rt].byte(i) )
   endfor
   GPR[rd] = sign_extend.32( tmp )
DBITSWAP: 
   for i in 0 to 7 do  /* for all bytes in 64-bit GPR width */
      tmp.byte(i) = reverse_bits_in_byte( GPR[rt].byte(i) )
   endfor
   GPR[rd] = tmp
   where
      function reverse_bits_in_byte(inbyte)
         outbyte7 = inbyte0
         outbyte6 = inbyte1
         outbyte5 = inbyte2
         outbyte4 = inbyte3
         outbyte3 = inbyte4
         outbyte2 = inbyte5
         outbyte1 = inbyte6
         outbyte0 = inbyte7
         return outbyte
      end function

Exceptions:

BITSWAP: None

DBITSWAP: Reserved Instruction.

Programming Notes:

The Release 6 BITSWAP instruction corresponds to the DSP Module BITREV instruction, except that the latter bitreverses the least-significant 16-bit halfword of the input register, zero extending the rest, while BITSWAP operates on 32-bits.