From c109dbecf3bf72b464f994e1870d93af34095e9c Mon Sep 17 00:00:00 2001 From: Daniel Larimer Date: Mon, 27 Jun 2016 16:22:14 -0400 Subject: [PATCH] improve performince of fc::uin128 divide --- src/asio.cpp | 10 ++++++---- src/network/tcp_socket.cpp | 2 +- src/uint128.cpp | 26 ++++++++++++++++++++++++-- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/asio.cpp b/src/asio.cpp index 0319eaa..4a512f1 100644 --- a/src/asio.cpp +++ b/src/asio.cpp @@ -140,10 +140,12 @@ namespace fc { /// If cleanup is true, do not use the return value; it is a null reference boost::asio::io_service& default_io_service(bool cleanup) { - static default_io_service_scope fc_asio_service; - if (cleanup) - fc_asio_service.cleanup(); - return *fc_asio_service.io; + static default_io_service_scope fc_asio_service[4]; + if (cleanup) { + for( int i = 0; i < 4; ++i ) + fc_asio_service[i].cleanup(); + } + return *fc_asio_service[0].io; } namespace tcp { diff --git a/src/network/tcp_socket.cpp b/src/network/tcp_socket.cpp index 499a0ed..7eee2ab 100644 --- a/src/network/tcp_socket.cpp +++ b/src/network/tcp_socket.cpp @@ -309,7 +309,7 @@ namespace fc { try { my->_accept.bind(boost::asio::ip::tcp::endpoint(boost::asio::ip::address_v4(), port)); - my->_accept.listen(); + my->_accept.listen(256); } FC_RETHROW_EXCEPTIONS(warn, "error listening on socket"); } diff --git a/src/uint128.cpp b/src/uint128.cpp index dae2aef..66128ce 100644 --- a/src/uint128.cpp +++ b/src/uint128.cpp @@ -1,15 +1,18 @@ #include #include #include +#include + #include #include "byteswap.hpp" namespace fc { + typedef boost::multiprecision::uint128_t m128; + template static void divide(const T &numerator, const T &denominator, T "ient, T &remainder) { - static const int bits = sizeof(T) * 8;//CHAR_BIT; if(denominator == 0) { @@ -220,8 +223,27 @@ namespace fc uint128& uint128::operator/=(const uint128 &b) { + auto self = (m128(hi) << 64) + m128(lo); + auto other = (m128(b.hi) << 64) + m128(b.lo); + self /= other; + hi = static_cast(self >> 64); + lo = static_cast((self << 64 ) >> 64); + + /* uint128 remainder; - divide(*this, b, *this, remainder); + divide(*this, b, *this, remainder ); //, *this); + if( tmp.hi != hi || tmp.lo != lo ) { + std::cerr << tmp.hi << " " << hi <<"\n"; + std::cerr << tmp.lo << " " << lo << "\n"; + exit(1); + } + */ + + /* + const auto& b128 = std::reinterpret_cast(b); + auto& this128 = std::reinterpret_cast(*this); + this128 /= b128; + */ return *this; }