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
Index: device/lib/_divuint.c
===================================================================
--- device/lib/_divuint.c	(révision 7100)
+++ device/lib/_divuint.c	(copie de travail)
@@ -156,7 +156,7 @@
 {
   unsigned int reste = 0;
   unsigned char count = 16;
-  BOOL c;
+  unsigned char c;
 
   do
   {
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to