Jump to content

  • Log In with Google      Sign In   
  • Create Account

code -> .data & data -> .code


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
22 replies to this topic

#21 fir   Members   -  Reputation: -456

Like
0Likes
Like

Posted 28 February 2014 - 03:29 PM

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



Sponsor:

#22 richardurich   Members   -  Reputation: 1187

Like
0Likes
Like

Posted 28 February 2014 - 03:42 PM

If you're going to put code in the data section, at least pad to a new cache line (often 64 bytes). Ideally, you'd give the code its own page.



#23 fir   Members   -  Reputation: -456

Like
0Likes
Like

Posted 28 February 2014 - 03:57 PM

If you're going to put code in the data section, at least pad to a new cache line (often 64 bytes). Ideally, you'd give the code its own page.

was not aligned even to 4

 

SECTION .data   align=4 noexecute                       ; section number 2, data
 
_rtdsc_bin:                                             ; byte
        db 0FH, 31H, 0C3H                               ; 0000 _ .1.
 
_f_bin:                                                 ; byte
        db 55H, 89H, 0E5H, 8BH, 45H, 08H, 0C7H, 00H     ; 0003 _ U...E...
        db 0AH, 00H, 00H, 00H, 8BH, 45H, 08H, 83H       ; 000B _ .....E..
        db 0C0H, 04H, 0C7H, 00H, 14H, 00H, 00H, 00H     ; 0013 _ ........
        db 5DH, 0FH, 31H, 0C3H, 00H                     ; 001B _ ].1..





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS