From: CryptoManiac Date: Sun, 27 Mar 2016 13:15:22 +0000 (+0300) Subject: Merge pull request #293 from svost/patch X-Git-Tag: nvc-v0.5.8~28 X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=commitdiff_plain;h=b68dec11eea9e0b525bd26485c96425e7b1b6025;hp=b8185c9d52c544919cdf81958b0956abbc258662 Merge pull request #293 from svost/patch Minor fix --- diff --git a/src/crypto/scrypt/intrin/scrypt-sse2.cpp b/src/crypto/scrypt/intrin/scrypt-sse2.cpp index 63c0a7a..bc828e3 100644 --- a/src/crypto/scrypt/intrin/scrypt-sse2.cpp +++ b/src/crypto/scrypt/intrin/scrypt-sse2.cpp @@ -48,18 +48,14 @@ static inline void le32enc(void *pp, uint32_t x) static inline void xor_salsa8_sse2(__m128i B[4], const __m128i Bx[4]) { - __m128i X0, X1, X2, X3; - __m128i T; - int i; + __m128i X0 = B[0] = _mm_xor_si128(B[0], Bx[0]); + __m128i X1 = B[1] = _mm_xor_si128(B[1], Bx[1]); + __m128i X2 = B[2] = _mm_xor_si128(B[2], Bx[2]); + __m128i X3 = B[3] = _mm_xor_si128(B[3], Bx[3]); - X0 = B[0] = _mm_xor_si128(B[0], Bx[0]); - X1 = B[1] = _mm_xor_si128(B[1], Bx[1]); - X2 = B[2] = _mm_xor_si128(B[2], Bx[2]); - X3 = B[3] = _mm_xor_si128(B[3], Bx[3]); - - for (i = 0; i < 8; i += 2) { + for (uint32_t i = 0; i < 8; i += 2) { /* Operate on "columns". */ - T = _mm_add_epi32(X0, X3); + __m128i T = _mm_add_epi32(X0, X3); X1 = _mm_xor_si128(X1, _mm_slli_epi32(T, 7)); X1 = _mm_xor_si128(X1, _mm_srli_epi32(T, 25)); T = _mm_add_epi32(X1, X0); @@ -105,21 +101,18 @@ static inline void xor_salsa8_sse2(__m128i B[4], const __m128i Bx[4]) uint256 scrypt_blockhash(const uint8_t* input) { - uint256 result = 0; uint8_t scratchpad[SCRYPT_BUFFER_SIZE]; + __m128i *V = (__m128i *)(((uintptr_t)(scratchpad) + 63) & ~ (uintptr_t)(63)); + uint8_t B[128]; + void *const tmp = const_cast(input); + PKCS5_PBKDF2_HMAC(static_cast(tmp), 80, input, 80, 1, EVP_sha256(), 128, B); + union { __m128i i128[8]; uint32_t u32[32]; } X; - __m128i *V; - uint32_t i, j, k; - - V = (__m128i *)(((uintptr_t)(scratchpad) + 63) & ~ (uintptr_t)(63)); - - void *const tmp = const_cast(input); - PKCS5_PBKDF2_HMAC(static_cast(tmp), 80, input, 80, 1, EVP_sha256(), 128, B); - + uint32_t i, k; for (k = 0; k < 2; k++) { for (i = 0; i < 16; i++) { X.u32[k * 16 + i] = le32dec(&B[(k * 16 + (i * 5 % 16)) * 4]); @@ -133,7 +126,7 @@ uint256 scrypt_blockhash(const uint8_t* input) xor_salsa8_sse2(&X.i128[4], &X.i128[0]); } for (i = 0; i < 1024; i++) { - j = 8 * (X.u32[16] & 1023); + uint32_t j = 8 * (X.u32[16] & 1023); for (k = 0; k < 8; k++) X.i128[k] = _mm_xor_si128(X.i128[k], V[j + k]); xor_salsa8_sse2(&X.i128[0], &X.i128[4]); @@ -146,6 +139,7 @@ uint256 scrypt_blockhash(const uint8_t* input) } } + uint256 result = 0; PKCS5_PBKDF2_HMAC(static_cast(tmp), 80, B, 128, 1, EVP_sha256(), 32, (unsigned char*)&result); return result; diff --git a/src/init.cpp b/src/init.cpp index 55308ea..1e0daaa 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -376,7 +376,7 @@ bool AppInit2() // ********************************************************* Step 2: parameter interactions - nNodeLifespan = (unsigned int)(GetArg("-addrlifespan", 7)); + nNodeLifespan = GetArgUInt("-addrlifespan", 7); fUseFastIndex = GetBoolArg("-fastindex", true); fUseMemoryLog = GetBoolArg("-memorylog", true); diff --git a/src/main.cpp b/src/main.cpp index 38b3ac5..0a6fda1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2974,7 +2974,7 @@ bool LoadExternalBlockFile(FILE* fileIn) unsigned char pchData[65536]; do { fseek(blkdat, nPos, SEEK_SET); - int nRead = fread(pchData, 1, sizeof(pchData), blkdat); + size_t nRead = fread(pchData, 1, sizeof(pchData), blkdat); if (nRead <= 8) { nPos = std::numeric_limits::max(); @@ -3362,15 +3362,15 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) } // find last block in inv vector - unsigned int nLastBlock = std::numeric_limits::max(); - for (unsigned int nInv = 0; nInv < vInv.size(); nInv++) { + size_t nLastBlock = std::numeric_limits::max(); + for (size_t nInv = 0; nInv < vInv.size(); nInv++) { if (vInv[vInv.size() - 1 - nInv].type == MSG_BLOCK) { nLastBlock = vInv.size() - 1 - nInv; break; } } CTxDB txdb("r"); - for (unsigned int nInv = 0; nInv < vInv.size(); nInv++) + for (size_t nInv = 0; nInv < vInv.size(); nInv++) { const CInv &inv = vInv[nInv]; diff --git a/src/miner.cpp b/src/miner.cpp index 6057eec..5d01bb2 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -147,18 +147,18 @@ CBlock* CreateNewBlock(CWallet* pwallet, CTransaction *txCoinStake) } // Largest block you're willing to create: - unsigned int nBlockMaxSize = GetArg("-blockmaxsize", MAX_BLOCK_SIZE_GEN/2); + unsigned int nBlockMaxSize = GetArgUInt("-blockmaxsize", MAX_BLOCK_SIZE_GEN/2); // Limit to betweeen 1K and MAX_BLOCK_SIZE-1K for sanity: - nBlockMaxSize = std::max((unsigned int)1000, std::min((unsigned int)(MAX_BLOCK_SIZE-1000), nBlockMaxSize)); + nBlockMaxSize = std::max(1000u, std::min(MAX_BLOCK_SIZE-1000u, nBlockMaxSize)); // How much of the block should be dedicated to high-priority transactions, // included regardless of the fees they pay - unsigned int nBlockPrioritySize = GetArg("-blockprioritysize", 27000); + unsigned int nBlockPrioritySize = GetArgUInt("-blockprioritysize", 27000); nBlockPrioritySize = std::min(nBlockMaxSize, nBlockPrioritySize); // Minimum block size you want to create; block will be filled with free transactions // until there are no more or the block reaches this size: - unsigned int nBlockMinSize = GetArg("-blockminsize", 0); + unsigned int nBlockMinSize = GetArgUInt("-blockminsize", 0); nBlockMinSize = std::min(nBlockMaxSize, nBlockMinSize); // Fee-per-kilobyte amount considered the same as "free" diff --git a/src/net.cpp b/src/net.cpp index 9d3b998..c69e83c 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -570,10 +570,9 @@ void CNode::copyStats(CNodeStats &stats) } #undef X - - - - +void Release(CNode* node) { + node->Release(); +} @@ -925,8 +924,7 @@ void ThreadSocketHandler2(void* parg) } { LOCK(cs_vNodes); - BOOST_FOREACH(CNode* pnode, vNodesCopy) - pnode->Release(); + for_each(vNodesCopy.begin(), vNodesCopy.end(), Release); } Sleep(10); @@ -1507,8 +1505,7 @@ void ThreadMessageHandler2(void* parg) { LOCK(cs_vNodes); - BOOST_FOREACH(CNode* pnode, vNodesCopy) - pnode->Release(); + for_each(vNodesCopy.begin(), vNodesCopy.end(), Release); } // Wait and allow messages to bunch up.