Hello

The _divulong function use a bool variables, but this is not optimal:

- this force the use of the "T" reg as soon as a 32bit 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:


 ;x                         Allocated to stack - _bp +1
 ;reste                     Allocated to registers r2 r3 r6 r7 
 ;count                     Allocated to registers r5 
-;c                         Allocated to registers b0 
+;c                         Allocated to registers r4 
 ;------------------------------------------------------------
 ;      _divulong.c:335: _divulong (unsigned long x, unsigned long y)
 ;      -----------------------------------------
@@ -148,8 +134,6 @@
        rl      a
        anl     a,#0x01
        mov     r4,a
-       add     a,#0xff
-       mov     b0,c
 ;      _divulong.c:345: x <<= 1;
        mov     r0,_bp
        inc     r0
@@ -182,7 +166,8 @@
        rlc     a
        mov     r7,a
 ;      _divulong.c:347: if (c)
-       jnb     b0,00102$
+       mov     a,r4
+       jz      00102$
 ;      _divulong.c:348: reste |= 1L;
        orl     ar2,#0x01
 00102$:

On cc253x SoC this lead to a reduction of 4 byte in code size and 5 cycle per 
loop iteration, thus saving 160 cycle on a 32bits division.

Thanks,

Philippe

Index: device/lib/_divulong.c
===================================================================
--- device/lib/_divulong.c	(révision 7100)
+++ device/lib/_divulong.c	(copie de travail)
@@ -336,7 +336,7 @@
 {
   unsigned long reste = 0L;
   unsigned char count = 32;
-  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