hi it's first post here hi everyone.
i have problem predict cache line size in gnu as. wrote program in c calls function written in assembly.
here function
.section .text .section .data .global time time: pushl %ebp xor %edx, %edx xor %eax, %eax cpuid rdtsc popl %ebp ret
it measure cpu cycles
c code is:
#include <stdio.h> const int size = 256; void main(){ unsigned long long cykl, cykl1, cykl2; unsigned char matrix[size]; char bla; int i,j,k; for(i=0 ; i<size; i++) { cykl1 = time(); bla = matrix[i]; cykl2 = time(); cykl = cykl2 - cykl1; printf("i=%d: %lld \n",i, cykl); } }
i ran program, can't see time difference. know cache line lenght 64 bytes.
time should rise every time load next 64bytes of array, right?
i gratefull advice why can't work properly.
i think there 3 problems.
first, program call might not assembly routine, time(2) system call returns current time in seonds. assembly routine name should prefixed underscore, i.e., _time, in *.s file.
you can declare routine __asm__
keyword. see: http://gcc.gnu.org/onlinedocs/gcc-4.8.0/gcc/asm-labels.html
second, memory access might eliminated (or reordered) gcc optimizer. should check assembly code generated c code.
third, rdtsc
not serialized. in other words, cpu might reorder access memory , rdtsc
insturction, or executed in parallel. should insert instructions prevent reordering.
see description of rdtsc
in "intel® 64 , ia-32 architecture software developer's manual volume 2b: instruction set reference, m-z": http://www.intel.com/content/www/us/en/processors/architectures-software-developer-manuals.html
Comments
Post a Comment