For my project I must use inline assembly instructions such as rdtsc to calculate the execution time of a
single Android 4.3 source code C++ instruction.
I added the following code around the
single Android 4.3 source code C++ instruction that I need to measure:
{unsigned a, d;asm volatile("rdtsc" : "=a" (a), "=d" (d)); t0 = ((unsigned long)a) | (((unsigned long)d) << 32);}
//The C++ statement to measure its execution time
{unsigned a, d;asm volatile("rdtsc" : "=a" (a), "=d" (d)); t1 = ((unsigned long)a) | (((unsigned long)d) << 32);}
time = (t1-t0);
But I'm getting the error message: error: impossible constraint in 'asm'
My build environment are:
- Ubuntu 14.04.5 LTS
- Android 4.3
- GCC 4.8.5
- G++ 4.8.5
- Target: x86_64-linux-gnu
I have tried the above code in a standalone C program (in the same environment) and it is working fine with no problem but once I embed the above code in the Android source code, I get the error message.
My target: I'm building an image for Android emulator qemu on x86_64-linux-gnu platform.
More details:
I’m building/compiling the Android source code (with some added inline assembly code) itself (not an app) for x86_64 and ARM Android ROM images. I must build/compile these ROM images on my Ubuntu PC (my build environment) first before I can test the images on an emulator or a real phone, however,I’m getting error messages as explained above during the compiling process and I could not pass the compilation phase yet.
I cannot use clock_gettime (or similar functions) because they are very slow and did not give me the correct result when measuring the execution time of a single Android source code C++ statement but RDTSC did. Also in my project I cannot use for-loops or any type of iteration.
I’m not clocking something in the emulator but I’m clocking something in the Android source code itself. However, I need to test the build on the QEMU emulator to make sure these ROM images are working before I flash them to the real phones (Intel and ARM).
I'm using the standard Android source code build process outlined
here in the Android Open Source Project web site. As I said before I tested the inline assembly code in a standalone C/C++ in the same build environment and it's working fine with no problems.
I added the following code before the
single Android 4.3 source code C++ instruction that I want to measure and I got the message "
Not Intel and Not ARM arch!
"
#if defined(__x86_64__)
ALOGD("__x86_64__");
#elif defined(__aarch64__)
ALOGD("__aarch64__");
#elif defined(__ARM_ARCH)
ALOGD("__ARM_ARCH");
#else
ALOGD("Not Intel and Not ARM arch!");
#endif
Which I think it means that the compiler is not allowing me to use Intel or ARM inline assembly code inside the Android 4.3 source code.
My question is:How can I add Intel or ARM inline assembly code inside the Android 4.3 source code and compile it without any error?