Hi Tim,

>    86 0030 4AAE 0008          tst.l 8(%fp)
>    87 0034 56C0               sne %d0
>    88 0036 4E5E               unlk %fp
>    89                         .cfi_offset 14, -8
>    90 0038 7100               mvs.b %d0,%d0
>    91 003a 4480               neg.l %d0
>    92 003c 4E75               rts

I don't know 68000/Coldfire so I'm enjoying this.  :-)

    tst.l 8(%fp)     ; compare x to 0.
    sne %d0          ; if x != 0: d0 = 0xff.
    unlk %fp         ; prepare for return.
    mvs.b %d0,%d0    ; sign-extend the byte in d0 to be 32-bit.
    neg.l %d0        ; d0 = 0 - d0.  0 stays 0, -1 becomes 1.
    rts              ; return.

> At first glance not sure why the mvs.b is necessary.

I agree.  It could be (* marks change)

    tst.l 8(%fp)     ; compare x to 0.
    sne %d0          ; if x != 0: d0 = 0xff.
    unlk %fp         ; prepare for return.
  * neg.b %d0        ; d0 = 0 - d0.  0 stays 0, -1 becomes 1.
    rts              ; return.

if the neg.l became a neg.b.  I guess it's because it knows it's
returning a 32-bit int and doesn't see it can stick with 8-bit.

Cheers,
Ralph.


--
Next meeting:  Bournemouth? TBD, Wednesday 2010-10-06 20:00
Meets, Mailing list, IRC, LinkedIn, ...  http://dorset.lug.org.uk/
How to Report Bugs Effectively:  http://bit.ly/4sACa

Reply via email to