#189 automatic char instead of int in loop reversal

open
nobody
None
5
2006-12-16
2006-12-16
No

/* it would be nice if loop reversal optimization
would also reduce the size of the loop control
variable if possible.
*/

bit mybit;

#if 1
# define BODY mybit = !mybit
#else
# define BODY *ptr++ = 0x00
#endif

void foo()
{
char xdata *ptr = (unsigned char xdata *) 0xf000;
int i;

/* automatic usage of unsigned char instead of int
would be give:
mov r2,#0x08
00103$:
cpl _mybit
djnz r2,00103$

Instead of:
mov r2,#0x08
mov r3,#0x00
00103$:
cpl _mybit
dec r2
cjne r2,#0xff,00121$
dec r3
00121$:
mov a,r2
orl a,r3
jnz 00103$
*/
for(i=0;i<8;i++)
BODY;

/* although 256 iterations are needed this could still be
achieved with the djnz instruction and only one register:)
mov r2,#0x00
00104$:
cpl _mybit
djnz r2,00104$
*/
for(i=0;i<0x100;i++)
BODY;
}

Discussion


Log in to post a comment.