#64 Pretty unoptimized asm code

closed
None
5
2006-12-30
2004-02-17
No

Very shortened example of my problem: "code char
*text" -pointer converted to an "unsigned long" and
passed as a parameter to an another function:

;text Allocated to registers r2 r3
;k Allocated to registers r5
;Interf.c:251: BYTE printT(code char *text)
... (here's some unincluded code)
00104$:
;Interf.c:257: k=lueFlaCode((LONG) text);
; genIpush
push ar4
; genCast
mov ar5,r2
mov ar6,r3
mov r7,#0x00
mov r4,#0x00
; genCall
mov dpl,r5
mov dph,r6
mov b,r7
mov a,r4
lcall _lueFlaCode
mov r4,dpl
; genAssign
mov ar5,r4

A lot of unnecessary movs that could be easily avoided
if the optimizer would keep a track of where unchanged
register values finally end up to. Please improve this part
a bit.

Discussion

  • Maarten Brock

    Maarten Brock - 2004-02-18

    Logged In: YES
    user_id=888171

    Hello,

    I've been looking at something similar this week. Especially
    casts generate too much mov's. My example:

    unsigned char foo(unsigned long i)
    {
    unsigned char a;
    a = i >> 24;
    return a;
    }

    The generated code first generates a temporary unsigned
    long with the shifted data, then casts this temp to unsigned
    char, throwing away the "data" it just created. Couldn't this
    be done a little smarter, for it could save a lot of SLOC's I
    think.

    Greets,
    Maarten

     
  • Bernhard Held

    Bernhard Held - 2006-12-30

    Logged In: YES
    user_id=203539
    Originator: NO

    void foo (long l);

    void f (code char *text)
    {
    foo ((long) text);
    }

    is compiled by sdcc rev. 4541 to:

    _foo: mov r4,#0x00
    mov r5,#0x00
    mov b,r4
    mov a,r5
    ljmp _foo1

    Still not perfect but good enough. Isn't it?

    Maarten's example is compiled to:
    _foo: mov dpl,a
    ret

    no comment ;-)))))

     
  • Bernhard Held

    Bernhard Held - 2006-12-30
    • assigned_to: nobody --> bernhardheld
    • status: open --> closed
     

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

Sign up for the SourceForge newsletter:





No, thanks