Richard Quirk
unread,Dec 7, 2010, 10:42:53 AM12/7/10Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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