#194 Optimize _divuint on mcs51

closed-rejected
None
5
2012-10-14
2012-09-06
Anonymous
No

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.

Discussion

  • Comment has been marked as spam. 
    Undo

    You can see all pending comments posted by this user  here

    Anonymous - 2012-09-06
     
  • Maarten Brock

    Maarten Brock - 2012-09-17

    Revision 8110:

    Summary for 'mcs51-medium': 0 failures, 7027 tests, 1550 test cases, 2348951 bytes, 229970052 ticks
    Summary for 'mcs51-large': 0 failures, 7027 tests, 1550 test cases, 2690701 bytes, 338213556 ticks
    Summary for 'mcs51-xstack-auto': 0 failures, 7028 tests, 1550 test cases, 3310922 bytes, 360810840 ticks

    With your 'optimization':

    Summary for 'mcs51-medium': 0 failures, 7027 tests, 1550 test cases, 2350093 bytes, 231150528 ticks
    Summary for 'mcs51-large': 0 failures, 7027 tests, 1550 test cases, 2699837 bytes, 345666300 ticks
    Summary for 'mcs51-xstack-auto': 0 failures, 7028 tests, 1550 test cases, 3318916 bytes, 367254576 ticks

    Somehow this optimization doesn't really pay off.

    P.S. mcs51-small and mcs51-stack-auto show no changes as these have hand-written assembly for divuint.

    Maarten

     
  • Maarten Brock

    Maarten Brock - 2012-10-14
    • assigned_to: nobody --> maartenbrock
    • status: open --> closed-rejected
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks