开发者

I need help converting Intel inline asm to AT&T so I can compile it with gcc

开发者 https://www.devze.com 2023-01-31 02:45 出处:网络
T开发者_JS百科his is the original code: #define CPU_PREFETCH(cache_line)\\ { int* address = (int*) (cache_line);\\

T开发者_JS百科his 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.


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)); \
}


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消