Merge pull request #221

3ece158 make fallback compatible with newer slow-hash (Riccardo Spagni)
709bbc5 replaced 64-bit multiplication in difficulty.cpp with a portable version (Riccardo Spagni)
497a514 replaced 64-bit multiplication in difficulty.cpp with a portable version (Riccardo Spagni)
This commit is contained in:
Riccardo Spagni 2015-02-03 20:15:02 +02:00
commit 6e5797dc11
No known key found for this signature in database
GPG Key ID: 55432DF31CCD4FCD
2 changed files with 46 additions and 4 deletions

View File

@ -627,6 +627,18 @@ void cn_slow_hash(const void *data, size_t length, char *hash)
#else #else
// Portable implementation as a fallback // Portable implementation as a fallback
void slow_hash_allocate_state(void)
{
// Do nothing, this is just to maintain compatibility with the upgraded slow-hash.c
return;
}
void slow_hash_free_state(void)
{
// As above
return;
}
static void (*const extra_hashes[4])(const void *, size_t, char *) = { static void (*const extra_hashes[4])(const void *, size_t, char *) = {
hash_extra_blake, hash_extra_groestl, hash_extra_jh, hash_extra_skein hash_extra_blake, hash_extra_groestl, hash_extra_jh, hash_extra_skein
}; };

View File

@ -56,10 +56,40 @@ namespace cryptonote {
#else #else
static inline void mul(uint64_t a, uint64_t b, uint64_t &low, uint64_t &high) { static inline void mul(uint64_t a, uint64_t b, uint64_t &low, uint64_t &high) {
typedef unsigned __int128 uint128_t; // __int128 isn't part of the standard, so the previous function wasn't portable. mul128() in Windows is fine,
uint128_t res = (uint128_t) a * (uint128_t) b; // but this portable function should be used elsewhere. Credit for this function goes to latexi95.
low = (uint64_t) res;
high = (uint64_t) (res >> 64); uint64_t aLow = a & 0xFFFFFFFF;
uint64_t aHigh = a >> 32;
uint64_t bLow = b & 0xFFFFFFFF;
uint64_t bHigh = b >> 32;
uint64_t res = aLow * bLow;
uint64_t lowRes1 = res & 0xFFFFFFFF;
uint64_t carry = res >> 32;
res = aHigh * bLow + carry;
uint64_t highResHigh1 = res >> 32;
uint64_t highResLow1 = res & 0xFFFFFFFF;
res = aLow * bHigh;
uint64_t lowRes2 = res & 0xFFFFFFFF;
carry = res >> 32;
res = aHigh * bHigh + carry;
uint64_t highResHigh2 = res >> 32;
uint64_t highResLow2 = res & 0xFFFFFFFF;
//Addition
uint64_t r = highResLow1 + lowRes2;
carry = r >> 32;
low = (r << 32) | lowRes1;
r = highResHigh1 + highResLow2 + carry;
uint64_t d3 = r & 0xFFFFFFFF;
carry = r >> 32;
r = highResHigh2 + carry;
high = d3 | (r << 32);
} }
#endif #endif