3

多倍精度モジュールを実装していますが、現時点では乗算で立ち往生しています。

私のアルゴリズムを実行するには、Haswell マイクロアーキテクチャを使用して 64 ビットの 2 つの符号なしオペランドを乗算し、結果をメモリ ブロックに格納する必要があります。「g++」を使用した実装と、「icpc」を使用した別のより効率的な実装を行っています。

int main(){

    //Operands
    size_t a = 10000000000000000000 //Fit in 8 bytes
           b = 7;

    //To store the result;
    size_t dst[2];

    //Multiplication here... (Note that the multiplication result don't fit in 64bits. So, I need to save the result in two memory positions)

    dst[0] = //Store the less significative half..
    dst[1] = //Store the more significative half..


    //My function
    print_To_Screen(dst);
}

結果の各半分にアクセスして、必要なメモリ ブロックに格納する方法がわかりません。乗算にアセンブリ命令を使用し、結果を格納する義務がありますか、または簡単な方法がありますか?

4

2 に答える 2

4

提案どおりに使用するだけ__int128で、ほとんどのコンパイラがサポートしています:

__uint128_t mul64x64( uint64_t a, uint64_t b ) {
    return ((__uint128_t)a) * ((__uint128_t)a);
}

これは、x64 アーキテクチャでは単一命令の乗算に変換されます。

于 2016-02-04T13:55:15.863 に答える