Skip to content

回复:在 SSE2 CPU 上为 0.3.6 并行计算 4 个哈希 ​

原始发布页

打开来源页面
查看 1 个交叉存档

MinGW GCC 4.5.0: Crypto++ 无法工作,X86_SHA256_HashBlocks() 一直不返回 我只在 test.cpp 中让四路并行运行成功了,但由 BitcoinMiner 调用时不行

MinGW GCC 4.4.1: Crypto++ 可以工作 四路并行发生 SIGSEGV

GCC 肯定没有对齐 __m128i。

即使我们对齐了自己的 __m128i 变量,编译器也可能决定在幕后使用一个 __m128i 作为临时变量。

通过对齐我们的 __m128i 变量,并把这些内联函数改成宏定义,我让它在 4.4.1 上运行成功了,但仅限使用 -O0: #define Ch(b, c, d) ((b & c) ^ (~b & d)) #define Maj(b, c, d) ((b & c) ^ (b & d) ^ (c & d)) #define ROTR(x, n) (_mm_srli_epi32(x, n) | _mm_slli_epi32(x, 32 - n)) #define SHR(x, n) _mm_srli_epi32(x, n)

但那是使用 -O0 的情况。

英文原文 ​

展开英文原文

MinGW GCC 4.5.0: Crypto++ doesn't work, X86_SHA256_HashBlocks() never returns I only got 4-way working with test.cpp but not when called by BitcoinMiner

MinGW GCC 4.4.1: Crypto++ works 4-way SIGSEGV

GCC is definitely not aligning __m128i.

Even if we align our own __m128i variables, the compiler may decide to use a __m128i behind the scenes as a temporary variable.

By making our __m128i variables aligned and changing these inlines to defines, I was able to get it to work on 4.4.1 with -O0 only: #define Ch(b, c, d) ((b & c) ^ (~b & d)) #define Maj(b, c, d) ((b & c) ^ (b & d) ^ (c & d)) #define ROTR(x, n) (_mm_srli_epi32(x, n) | _mm_slli_epi32(x, 32 - n)) #define SHR(x, n) _mm_srli_epi32(x, n)

But that's with -O0.

为历史保存,为中文读者整理。每篇档案均附来源与英文原文。