I did some test (it is a somewhat 'casual' test but i got no energy to
rewrite it
#include <stdio.h>
char rtdsc_bin[] =
{
0x0f, 0x31,
0xc3
};
int f(int* x)
{
x[0] = 10;
x[1] = 20;
}
char f_bin[] = //f() body + rdtsc commnd
{
0x55,
0x89, 0xE5,
0x8B, 0x45, 0x08,
0xC7, 0x00, 0x0A, 0x00, 0x00, 0x00,
0x8B, 0x45, 0x08,
0x83, 0xC0, 0x04,
0xC7, 0x00, 0x14, 0x00, 0x00, 0x00,
0x5D,
0x0f, 0x31, //rdtsc here
0xC3,
};
void main()
{
int (*foo)() ;
int (*food)(int*) ;
foo = rtdsc_bin;
int a = foo();
int b = foo();
printf(" %d ",b-a);
static int i[2];
/////////////////////////////
food = f_bin;
int c = food(i);
int d = food(i);
printf(" %d ",d-c);
printf("\n %d ",i[0]);
printf("\n %d ",i[1]);
}
and im at least happy with that , seem to be no slowdown
probably here in mingw
results are like
112 119
10
20
112 126
10
20
112 is probably rtdsc cost itself (?) the rest of the function f
takes only few cycles probably - no applied slowdown noticable
(as far as i can be sure) so this machine code trick (one of my favourites) still work