3

他の人のプロジェクトを 32 ビットから 64 ビットに変換しようとしています。x64 のビルド時に Visual Studio でサポートされていないアセンブリ式を使用する 1 つの関数を除いて、すべて問題ないようです。

// 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++ の代替を見つける必要があります。

4

1 に答える 1