diff --git a/main.cpp b/main.cpp index bfc45af28..3dd512fe6 100644 --- a/main.cpp +++ b/main.cpp @@ -3151,71 +3151,6 @@ void ThreadBitcoinMiner(void* parg) printf("ThreadBitcoinMiner exiting, %d threads remaining\n", vnThreadsRunning[3]); } -#if defined(__GNUC__) && defined(CRYPTOPP_X86_ASM_AVAILABLE) -void CallCPUID(int in, int& aret, int& cret) -{ - int a, c; - asm ( - "mov %2, %%eax; " // in into eax - "cpuid;" - "mov %%eax, %0;" // eax into a - "mov %%ecx, %1;" // ecx into c - :"=r"(a),"=r"(c) /* output */ - :"r"(in) /* input */ - :"%eax","%ebx","%ecx","%edx" /* clobbered register */ - ); - aret = a; - cret = c; -} - -bool Detect128BitSSE2() -{ - int a, c, nBrand; - CallCPUID(0, a, nBrand); - bool fIntel = (nBrand == 0x6c65746e); // ntel - bool fAMD = (nBrand == 0x444d4163); // cAMD - - struct - { - unsigned int nStepping : 4; - unsigned int nModel : 4; - unsigned int nFamily : 4; - unsigned int nProcessorType : 2; - unsigned int nUnused : 2; - unsigned int nExtendedModel : 4; - unsigned int nExtendedFamily : 8; - } - cpu; - CallCPUID(1, a, c); - memcpy(&cpu, &a, sizeof(cpu)); - int nFamily = cpu.nExtendedFamily + cpu.nFamily; - int nModel = cpu.nExtendedModel*16 + cpu.nModel; - - // We need Intel Nehalem or AMD K10 or better for 128bit SSE2 - // Nehalem = i3/i5/i7 and some Xeon - // K10 = Opterons with 4 or more cores, Phenom, Phenom II, Athlon II - // Intel Core i5 family 6, model 26 or 30 - // Intel Core i7 family 6, model 26 or 30 - // Intel Core i3 family 6, model 37 - // AMD Phenom family 16, model 10 - bool fUseSSE2 = ((fIntel && nFamily * 10000 + nModel >= 60026) || - (fAMD && nFamily * 10000 + nModel >= 160010)); - - // AMD reports a lower model number in 64-bit mode - if (fAMD && sizeof(void*) > 4 && nFamily * 10000 + nModel >= 160000) - fUseSSE2 = true; - - static bool fPrinted; - if (!fPrinted) - { - fPrinted = true; - printf("CPUID %08x family %d, model %d, stepping %d, fUseSSE2=%d\n", nBrand, nFamily, nModel, cpu.nStepping, fUseSSE2); - } - return fUseSSE2; -} -#else -bool Detect128BitSSE2() { return false; } -#endif int FormatHashBlocks(void* pbuffer, unsigned int len) { @@ -3276,9 +3211,6 @@ unsigned int ScanHash_CryptoPP(char* pmidstate, char* pdata, char* phash1, char* } } -extern unsigned int ScanHash_4WaySSE2(char* pmidstate, char* pblock, char* phash1, char* phash, unsigned int& nHashesDone); - - class COrphan { @@ -3552,9 +3484,6 @@ void BitcoinMiner() { printf("BitcoinMiner started\n"); SetThreadPriority(THREAD_PRIORITY_LOWEST); - bool f4WaySSE2 = Detect128BitSSE2(); - if (mapArgs.count("-4way")) - f4WaySSE2 = GetBoolArg("-4way"); // Each thread has its own key and counter CReserveKey reservekey; @@ -3616,14 +3545,9 @@ void BitcoinMiner() unsigned int nHashesDone = 0; unsigned int nNonceFound; -#ifdef FOURWAYSSE2 - if (f4WaySSE2) - // tcatm's 4-way 128-bit SSE2 SHA-256 - nNonceFound = ScanHash_4WaySSE2(pmidstate, pdata + 64, phash1, (char*)&hash, nHashesDone); - else -#endif - // Crypto++ SHA-256 - nNonceFound = ScanHash_CryptoPP(pmidstate, pdata + 64, phash1, (char*)&hash, nHashesDone); + // Crypto++ SHA-256 + nNonceFound = ScanHash_CryptoPP(pmidstate, pdata + 64, phash1, + (char*)&hash, nHashesDone); // Check if something found if (nNonceFound != -1) diff --git a/makefile.unix b/makefile.unix index d306f746d..8beebdde2 100644 --- a/makefile.unix +++ b/makefile.unix @@ -23,7 +23,7 @@ LIBS= \ -l z \ -l dl -DEFS=-DNOPCH -DFOURWAYSSE2 -DUSE_SSL +DEFS=-DNOPCH -DUSE_SSL DEBUGFLAGS=-g -D__WXDEBUG__ CXXFLAGS=-O2 -Wno-invalid-offsetof -Wformat $(DEBUGFLAGS) $(DEFS) HEADERS=headers.h strlcpy.h serialize.h uint256.h util.h key.h bignum.h base58.h \ @@ -51,17 +51,14 @@ obj/%.o: %.cpp $(HEADERS) cryptopp/obj/%.o: cryptopp/%.cpp $(CXX) -c $(CXXFLAGS) -O3 -o $@ $< -obj/sha256.o: sha256.cpp - $(CXX) -c $(CXXFLAGS) -msse2 -O3 -march=amdfam10 -o $@ $< - -bitcoin: $(OBJS) obj/ui.o obj/uibase.o obj/sha256.o +bitcoin: $(OBJS) obj/ui.o obj/uibase.o $(CXX) $(CXXFLAGS) -o $@ $^ $(WXLIBS) $(LIBS) obj/nogui/%.o: %.cpp $(HEADERS) $(CXX) -c $(CXXFLAGS) -o $@ $< -bitcoind: $(OBJS:obj/%=obj/nogui/%) obj/sha256.o +bitcoind: $(OBJS:obj/%=obj/nogui/%) $(CXX) $(CXXFLAGS) -o $@ $^ $(LIBS) diff --git a/sha256.cpp b/sha256.cpp deleted file mode 100644 index ca116bdcd..000000000 --- a/sha256.cpp +++ /dev/null @@ -1,475 +0,0 @@ -// Copyright (c) 2010 Nils Schneider -// Distributed under the MIT/X11 software license, see the accompanying -// file license.txt or http://www.opensource.org/licenses/mit-license.php. - -// 4-way 128-bit SSE2 SHA-256 - -#ifdef FOURWAYSSE2 - -#include -#include - -#include -#include -#include - -#define NPAR 32 - -extern void DoubleBlockSHA256(const void* pin, void* pout, const void* pinit, unsigned int hash[8][NPAR], const void* init2); - -static const unsigned int sha256_consts[] = { - 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, /* 0 */ - 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, - 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, /* 8 */ - 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, - 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, /* 16 */ - 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, - 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, /* 24 */ - 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, - 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, /* 32 */ - 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, - 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, /* 40 */ - 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, - 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, /* 48 */ - 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, - 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, /* 56 */ - 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 -}; - - -static inline __m128i Ch(const __m128i b, const __m128i c, const __m128i d) { - return (b & c) ^ (~b & d); -} - -static inline __m128i Maj(const __m128i b, const __m128i c, const __m128i d) { - return (b & c) ^ (b & d) ^ (c & d); -} - -static inline __m128i ROTR(__m128i x, const int n) { - return _mm_srli_epi32(x, n) | _mm_slli_epi32(x, 32 - n); -} - -static inline __m128i SHR(__m128i x, const int n) { - return _mm_srli_epi32(x, n); -} - -/* SHA256 Functions */ -#define BIGSIGMA0_256(x) (ROTR((x), 2) ^ ROTR((x), 13) ^ ROTR((x), 22)) -#define BIGSIGMA1_256(x) (ROTR((x), 6) ^ ROTR((x), 11) ^ ROTR((x), 25)) -#define SIGMA0_256(x) (ROTR((x), 7) ^ ROTR((x), 18) ^ SHR((x), 3)) -#define SIGMA1_256(x) (ROTR((x), 17) ^ ROTR((x), 19) ^ SHR((x), 10)) - -static inline unsigned int store32(const __m128i x, int i) { - union { unsigned int ret[4]; __m128i x; } box; - box.x = x; - return box.ret[i]; -} - -static inline void store_epi32(const __m128i x, unsigned int *x0, unsigned int *x1, unsigned int *x2, unsigned int *x3) { - union { unsigned int ret[4]; __m128i x; } box; - box.x = x; - *x0 = box.ret[3]; *x1 = box.ret[2]; *x2 = box.ret[1]; *x3 = box.ret[0]; -} - -#define add4(x0, x1, x2, x3) _mm_add_epi32(_mm_add_epi32(_mm_add_epi32(x0, x1), x2), x3) -#define add5(x0, x1, x2, x3, x4) _mm_add_epi32(add4(x0, x1, x2, x3), x4) - -#define SHA256ROUND(a, b, c, d, e, f, g, h, i, w) \ - T1 = add5(h, BIGSIGMA1_256(e), Ch(e, f, g), _mm_set1_epi32(sha256_consts[i]), w); \ -d = _mm_add_epi32(d, T1); \ -h = _mm_add_epi32(T1, _mm_add_epi32(BIGSIGMA0_256(a), Maj(a, b, c))); - -static inline void dumpreg(__m128i x, char *msg) { - union { unsigned int ret[4]; __m128i x; } box; - box.x = x ; - printf("%s %08x %08x %08x %08x\n", msg, box.ret[0], box.ret[1], box.ret[2], box.ret[3]); -} - -#if 1 -#define dumpstate(i) printf("%s: %08x %08x %08x %08x %08x %08x %08x %08x %08x\n", \ - __func__, store32(w0, i), store32(a, i), store32(b, i), store32(c, i), store32(d, i), store32(e, i), store32(f, i), store32(g, i), store32(h, i)); -#else -#define dumpstate() -#endif - -// Align by increasing pointer, must have extra space at end of buffer -template -T* alignup(T* p) -{ - union - { - T* ptr; - size_t n; - } u; - u.ptr = p; - u.n = (u.n + (nBytes-1)) & ~(nBytes-1); - return u.ptr; -} - -static const unsigned int pSHA256InitState[8] = -{0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19}; - - -unsigned int ScanHash_4WaySSE2(char* pmidstate, char* pdata, char* phash1, char* phash, unsigned int& nHashesDone) -{ - unsigned int& nNonce = *(unsigned int*)(pdata + 12); - for (;;) - { - nNonce += NPAR; - unsigned int thashbuf[9][NPAR]; - unsigned int (&thash)[9][NPAR] = *alignup<16>(&thashbuf); - DoubleBlockSHA256(pdata, phash1, pmidstate, thash, pSHA256InitState); - - for (int j = 0; j < NPAR; j++) - { - if (thash[7][j] == 0) - { - for (int i = 0; i < 32/4; i++) - ((unsigned int*)phash)[i] = thash[i][j]; - return nNonce + j; - } - } - - if ((nNonce & 0xffff) == 0) - { - nHashesDone = 0xffff+1; - return -1; - } - } -} - - -void DoubleBlockSHA256(const void* pin, void* pad, const void *pre, unsigned int thash[9][NPAR], const void *init) -{ - unsigned int* In = (unsigned int*)pin; - unsigned int* Pad = (unsigned int*)pad; - unsigned int* hPre = (unsigned int*)pre; - unsigned int* hInit = (unsigned int*)init; - unsigned int i, j, k; - - /* vectors used in calculation */ - __m128i w0, w1, w2, w3, w4, w5, w6, w7; - __m128i w8, w9, w10, w11, w12, w13, w14, w15; - __m128i T1; - __m128i a, b, c, d, e, f, g, h; - __m128i nonce; - - /* nonce offset for vector */ - __m128i offset = _mm_set_epi32(0x00000003, 0x00000002, 0x00000001, 0x00000000); - - - for(k = 0; k