Microchip C30 Bitwise Operation

Thread Starter

Art

Joined Sep 10, 2007
806
Hi Guys,
I’m used to assembler, or a BASIC compiler with access to inline assembler,
so porting my reusable code to C30 has been a bit hit & miss where speed with
bitwise operations are concerned.

The most prohibitive thing at the moment, porting an LCD graphics routine,
I was using this to bitwise rotate an array to the right for speed
(well I'm actually rotating a 50 byte array to the left, but this is an example)
Code:
RotateRight ;bitwise rotate array
rrf HMK+0 ,F ;a faster way
rrf HMK+1 ,F ;
rrf HMK+2 ,F ;
rrf HMK+3 ,F ;
rrf HMK+4 ,F ;
rrf HMK+5 ,F ;
rrf HMK+6 ,F ;
rrf HMK+7 ,F ;
rrf HMK+8 ,F ;
rrf HMK+9 ,F ;
bcf HMK+0 ,7 ;preclear MSB
btfsc status ,C ;check carry bit
bsf HMK+0 ,7 ;set MSB
return ;or return
Now it seems the best option for the same with C30 is this:
Code:
void rotateRight() {
temp = (HMK[9] << 7); // rotate HMK right once
HMK[9] = (HMK[8] << 7) | (HMK[9] >> 1);
HMK[8] = (HMK[7] << 7) | (HMK[8] >> 1);
HMK[7] = (HMK[6] << 7) | (HMK[7] >> 1);
HMK[6] = (HMK[5] << 7) | (HMK[6] >> 1);
HMK[5] = (HMK[4] << 7) | (HMK[5] >> 1);
HMK[4] = (HMK[3] << 7) | (HMK[4] >> 1);
HMK[3] = (HMK[2] << 7) | (HMK[3] >> 1);
HMK[2] = (HMK[1] << 7) | (HMK[2] >> 1);
HMK[1] = (HMK[0] << 7) | (HMK[1] >> 1);
HMK[0] = temp | (HMK[0] >> 1);
}
It occurs to me this is a lot slower, even on a much faster micro.
It could be that I need to check delays in other routines (such as the LCD delays),
but is there a better way?
Cheers, Art.
 
Top