Hi Tim,

> Generated code looks OK

Something I used to find gcc didn't cope too well with when targetting
ARM was the C idiom `!!x' to map 0 onto 0, and everything else onto 1.
IOW, `x ? 1 : 0'.

For

      signed int nnsi(         int x) { return !!x; }
    unsigned int nnui(unsigned int x) { return !!x; }
      signed int tosi(         int x) { return x ? 1 : 0; }
    unsigned int toui(unsigned int x) { return x ? 1 : 0; }

this gcc with -O3 produces the same x86 for all four,

    pushl %ebp
    xorl %eax, %eax
    movl %esp, %ebp
    cmpl $0, 8(%ebp)
    popl %ebp
    setne %al
    ret

I think ARM needs two instructions, ignoring function prologue and
epilogue,

    teq r0, #0     ; nflag, zflag = r0 xor 0
    movne r0, #1   ; if not zflag: r0 = 1
                   ; else: r0 already 0

Perhaps gcc on ARM does better these days.

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