From: Philippe R. <phi...@ep...> - 2012-08-30 09:46:29
Attachments:
divuint-optim.patch
|
Hello The _divuint function use a bool variables, but this is not optimal: - this force the use of the "T" reg as soon as a 16bit division is used on mcs51, thus potentially reducing the stack size up to 24 bytes. - This force the compiler to use a bit, which produce suboptimal code - This does not reduce stack useage as the compiler can allocate the bool variable to a register The following patch use a unsigned char for the boolean variable the generated code is changed as following for the large stack auto code model: @@ -109,7 +95,7 @@ ;x Allocated to registers r6 r7 ;reste Allocated to registers r4 r5 ;count Allocated to registers r3 -;c Allocated to registers b0 +;c Allocated to registers r2 ;------------------------------------------------------------ ; _divuint.c:155: _divuint (unsigned int x, unsigned int y) ; ----------------------------------------- @@ -139,8 +125,6 @@ rl a anl a,#0x01 mov r2,a - add a,#0xff - mov b0,c ; _divuint.c:165: x <<= 1; mov a,r7 xch a,r6 @@ -156,7 +140,8 @@ rlc a mov r5,a ; _divuint.c:167: if (c) - jnb b0,00102$ + mov a,r2 + jz 00102$ ; _divuint.c:168: reste |= 1; orl ar4,#0x01 00102$: On cc253x SoC this lead to a reduction of 4 byte in code size and 5 cycle per loop iteration. Thanks, Philippe |