tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Tinycc-devel] Floating point problems on Android ARM 32 bit


From: Alexander Muth
Subject: [Tinycc-devel] Floating point problems on Android ARM 32 bit
Date: Mon, 18 May 2020 00:22:32 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0

Hello,
I  use cmake to build libtcc [1] under android which works fine with x86, x86_64 and aarch64. But when I compile for 32 bit arm, there are problems when doubles and floats are passed as parameter to or from libtcc compiled code. I don't think that I have missed some Macros in my cmake because on Linux 32bit arm it is working just fine.

e.g. the code:

#include <stdlib.h>
#include <math.h>
double internalTestFunction(double x) {
     return x+1;
}
int test1() {       /* OK on all architectures, returns 5 */
     return (int) internalTestFunction(4);
}
float test2() {      /* UNEXPECTED RESULT on arm 32 bit: expected 5.0 but returns different value (Maybe the value of the integer registers misinterpreted because the return is not in integer registers?)*/
    return (float) internalTestFunction(4);
}
float* test2Ptr() {       /* OK on all architectures, returns 5: passing float/double in libtcc compiled code and return pointer to float is working just fine */
     float *resultPtr = malloc(sizeof(float));
    *resultPtr = (float) internalTestFunction(4);
    return resultPtr;
}
double test3() {         /* UNEXPECTED RESULT on arm 32 bit: expected 5.0 but returns different value (Maybe the value of the integer registers misinterpreted because the return is not in integer registers?) */
    return internalTestFunction(4);
}
double* test3Ptr() {         /* OK on all architectures, returns 5: passing float/double in libtcc compiled code and return pointer to double is working just fine */
  double *resultPtr = malloc(sizeof(double));
  *resultPtr = internalTestFunction(4);
    return resultPtr;
}
[2]

It compiles without any errors on all tested architectures (x86, x86_64, aarch64 and arm (32bit)) and is working as intended on all platforms except 32 bit arm. test1(), test2Ptr() and test3Ptr() is working just fine on all of these platforms (even 32 bit arm) but test2() and test3() doesn't return the intended result.

I tried both "arm" and "thumb" for ANDROID_ARM_MODE (according to https://developer.android.com/ndk/guides/cmake#android_arm_mode).

I thought it might be related to the fact that "-mfloat-abi=softfp" is used as flag under android, so that double and float values are passed to functions in integer registers (according to https://developer.android.com/ndk/guides/abis#v7a) because if I return pointers to the double and float values the pointed to values are correct.
Unfortunately I lack the know-how to debug or even fix this.

best regards,
Alexander

[1] repository with CMake project to build libtcc: https://github.com/Alex2804/libtcc-cmake [2] The code is in a repository with an Android Studio project: https://github.com/Alex2804/libtcc-cmake-android/blob/master/app/src/main/cpp/native-lib.cpp



reply via email to

[Prev in Thread] Current Thread [Next in Thread]