From 708673ac5d6c83b1fb87a146bfd0c1c82d94cb0b Mon Sep 17 00:00:00 2001 From: orignal Date: Fri, 7 Apr 2017 21:31:31 -0400 Subject: [PATCH] faster conversion to little endian --- i2pd | 2 +- src/hash.h | 8 ++++---- src/uint256.h | 3 +-- src/util.h | 9 +++++---- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/i2pd b/i2pd index 4448884..abf0f5a 160000 --- a/i2pd +++ b/i2pd @@ -1 +1 @@ -Subproject commit 4448884a3ebf822ecca7b39f2fe9777a79ae1863 +Subproject commit abf0f5ac8780c9cb0088e4ccefcd0d0274e63965 diff --git a/src/hash.h b/src/hash.h index 5d79a5f..d242870 100644 --- a/src/hash.h +++ b/src/hash.h @@ -22,12 +22,12 @@ inline uint256 Hash(const T1 pbegin, const T1 pend) static unsigned char pblank[1]; uint8_t hash1[64]; i2p::crypto::GOSTR3411_2012_512 ((pbegin == pend ? pblank : (unsigned char*)&pbegin[0]), (pend - pbegin) * sizeof(pbegin[0]), hash1); - uint8_t digest[32]; - i2p::crypto::GOSTR3411_2012_256 (hash1, 64, digest); + uint32_t digest[8]; + i2p::crypto::GOSTR3411_2012_256 (hash1, 64, (uint8_t *)digest); // to little endian uint256 hash2; - for (int i = 0; i < 32; i++) - hash2.begin ()[i] = digest[31-i]; + for (int i = 0; i < 8; i++) + hash2.pn[i] = ByteReverse (digest[7-i]); return hash2; } diff --git a/src/uint256.h b/src/uint256.h index 2a252c9..5b420cc 100644 --- a/src/uint256.h +++ b/src/uint256.h @@ -26,10 +26,9 @@ inline int Testuint256AdHoc(std::vector vArg); template class base_uint { -protected: +public: enum { WIDTH=BITS/32 }; uint32_t pn[WIDTH]; -public: bool operator!() const { diff --git a/src/util.h b/src/util.h index 7269dd7..3cf1c68 100644 --- a/src/util.h +++ b/src/util.h @@ -552,12 +552,13 @@ void RenameThread(const char* name); inline uint32_t ByteReverse(uint32_t value) { -#if 0 -// #if defined(__x86_64__) +#if defined(__x86_64__) || defined(__i386__) __asm__ ( - "bswap %%eax" - : "=a"(value) :: + "bswap %0" + : "=r"(value) + : "0"(value) + : ); return value; #else