这是原始代码:
#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 \
}
感谢 Jester,我现在有了这个:
#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)); \
}
显然,gcc 不喜欢clflush 中的 volatile 。感谢大家。
我正在尝试使用 gcc 作为 dll 编译Slicing-By-8,以便可以在我的 VB6 应用程序中使用它。