原始文献 / 论坛帖 / Re: 4 hashes parallel on SSE2 CPUs for 0.3.6

Re: 4 hashes parallel on SSE2 CPUs for 0.3.6

Bitcointalk · 2010-08-14 22:06:13 UTC

AuthorSatoshi Nakamoto
TitleRe: 4 hashes parallel on SSE2 CPUs for 0.3.6
Date2010-08-14 22:06:13 UTC
ForumBitcointalk · 原文

MinGW GCC 4.5.0:
Crypto++ 不工作,X86_SHA256_HashBlocks() 永不返回
我只在 test.cpp 里跑通了 4-way,但被 BitcoinMiner 调用时不行

MinGW GCC 4.4.1:
Crypto++ 工作
4-way 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.