Pergunta

This is the original code:

#define CPU_PREFETCH(cache_line)            \
{ int* address = (int*) (cache_line);       \
    _asm mov edx, address                   \
    _asm prefetcht0[edx]                    \
}

#define CPU_GET_CYCLES(low)                 \
{                                           \
    _asm    rdtsc                           \
    _asm    mov dword ptr [low], eax        \
}

#define CPU_SYNC                            \
{                                           \
    _asm    mov eax, 0                      \
    _asm    cpuid                           \
}

#define CPU_CACHE_FLUSH(cache_line)         \
{ int* address = (int*) (cache_line);       \
    _asm mov edx, address                   \
    _asm clflush[edx]                       \
    _asm mfence                             \
}

Thanks to Jester, I now have this:

#define CPU_PREFETCH(cache_line) \
{ \
    __asm__ __volatile__ ("prefetcht0 %0" : : "m" (*(int*)cache_line)); \
}

#define CPU_GET_CYCLES(low) \
{ \
    __asm__ __volatile__ ("rdtsc" : "=a" (low) : : "%edx"); \
}

#define CPU_SYNC \
{ \
    __asm__ __volatile__ ("cpuid" : : : "%eax", "%ebx", "%ecx", "%edx"); \
}

#define CPU_CACHE_FLUSH(cache_line) \
{ \
    __asm__ ("clflush %0; mfence" : : "m" (*(int*)cache_line)); \
}

Evidently, gcc doesn't like volatile with clflush. Thanks everyone.

I am trying to compile Slicing-By-8 with gcc as a dll so I can use it in my VB6 app.

Foi útil?

Solução

Would be nice to use proper inline functions. Anyway, here is your macro version:

#define CPU_PREFETCH(cache_line) \
{ \
    __asm__ __volatile__ ("prefetcht0 %0" : : "m" (*(int*)cache_line)); \
}

#define CPU_GET_CYCLES(low) \
{ \
    __asm__ __volatile__ ("rdtsc" : "=a" (low) : : "%edx"); \
}

#define CPU_SYNC \
{ \
    __asm__ __volatile__ ("cpuid" : : : "%eax", "%ebx", "%ecx", "%edx"); \
}

#define CPU_CACHE_FLUSH(cache_line) \
{ \
    __asm__ __volatile__ ("clflush %0; mfence" : : "m" (*(int*)cache_line)); \
}

Outras dicas

Instead of converting your Intel syntax to AT&T, why don't you tell GCC that you just want to compile Intel syntax?

You can do it like this:

add this line before any other assembly lines:

asm(".intel_syntax noprefix\n");

Then run GCC like this:

gcc -o my_output_file -masm=intel my_src_file.c

Thanks to stingduk at BiW Reversing.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top