Incorrect thumb output in NDK r5 using signed char

145 views
Skip to first unread message

Richard Quirk

unread,
Dec 7, 2010, 10:42:53 AM12/7/10
to android-ndk
I think I've discovered a bug in the output from NDK r5 using signed
chars. Here is a minimum snippet that produces bogus output:

int test(signed char anim_col)
{
if (anim_col >= 31) {
return 1;
} else if (anim_col <= -15) {
return -2;
}
return 0;
}

With r4b the thumb code produced is:

test:
mov r3, #1
cmp r0, #30
bgt .L3
mov r3, #0
add r0, r0, #14
bge .L3
mov r3, #2
neg r3, r3
.L3:
mov r0, r3
@ sp needed for prologue
bx lr

But r5 produces:

test:
mov r3, #1
cmp r0, #30
bgt .L3
lsl r0, r0, #24
lsr r0, r0, #24
mov r3, #0
cmp r0, #127
bls .L3
mov r3, #2
neg r3, r3
.L3:
mov r0, r3
@ sp needed for prologue
bx lr

That is equivalent to "else if (anim_col < 0)". For example passing in
-7 should return 0, but it will actually return -2. The command lines
I've used are as follows:

NDK5=~/tools/android-ndk-r5/toolchains/arm-linux-androideabi-4.4.3/
prebuilt/linux-x86/bin/arm-linux-androideabi-gcc
NDK4B=~/tools/android-ndk-r4b/build/prebuilt/linux-x86/arm-eabi-4.4.0/
bin/arm-eabi-gcc

$NDK5 -c -o test.o -Os test.c --save-temps -mthumb
mv test.s test-5.s
$NDK4B -c -o test.o -Os test.c --save-temps -mthumb
mv test.s test-4.s

I spotted the problem after recompiling my Android game using r5 and
noting that it had a strange new bug. Any comments on this? Apart from
"yeah, avoid using signed char data types" I mean :-)

regards,
Richard

Carrot

unread,
Dec 7, 2010, 7:23:10 PM12/7/10
to android-ndk
It has been confirmed as a GCC 4.4.3 bug, thank you for reporting
this.

Carrot

David Turner

unread,
Dec 14, 2010, 5:35:56 AM12/14/10
to andro...@googlegroups.com
By the way, this was fixed by the following change: https://review.source.android.com/#change,19474
Which will be in the upcoming NDK update.

Thanks for reporting, and thanks to the compiler team for the quick fix.

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.


Reply all
Reply to author
Forward
0 new messages