For my project I must use inline assembly instructions such as rdtsc to calculate the execution time of an Android 4.3 C++ instruction in the stack. I found similar problem in stackoverflow such as 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 but non of them solve the problem that I have.
I used the following code:
{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)/2-20;
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.