我试图将别人的项目从32位转换为64位.除了一个函数外,一切似乎都没问题,它使用了构建x64时Visual Studio不支持的汇编表达式:
// Returns the Read Time Stamp Counter of the cpu// The instruction returns in registers EDX:EAX the count of ticks from processor reset.// Added in Pentium. Opcode: 0F 31.int64_t CDiffIEHellman::GetRTSC( voID ){ int tmp1 = 0; int tmp2 = 0;#if defined(WIN32) __asm { RDTSC; // Clock cycles since cpu started mov tmp1,eax; mov tmp2,edx; }#else asm( "RDTSC;\n\t" "movl %%eax,%0;\n\t" "movl %%edx,%1;" :"=r"(tmp1),"=r"(tmp2) : : );#endif return ((int64_t)tmp1 * (int64_t)tmp2);}
最有趣的是,这被用于生成随机数. asm块在x64下都没有编译,所以使用ifdef也无济于事.我只需要找到C/C++替换以避免重写整个程序.
解决方法 对于windows分支,#include <intrin.h>
并调用__rdtsc()内在函数.
文件on MSDN
对于linux分支,内在函数可以使用相同的名称,但是您需要一个不同的头文件:
#include <x86intrin.h>总结
以上是内存溢出为你收集整理的如何将此装配时间戳功能转换为C?全部内容,希望文章能够帮你解决如何将此装配时间戳功能转换为C?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)