improve performince of fc::uin128 divide

This commit is contained in:
Daniel Larimer 2016-06-27 16:22:14 -04:00
parent 8cfc246316
commit c109dbecf3
3 changed files with 31 additions and 7 deletions

View file

@ -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 {

View file

@ -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");
}

View file

@ -1,15 +1,18 @@
#include <fc/uint128.hpp>
#include <fc/variant.hpp>
#include <fc/crypto/bigint.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <stdexcept>
#include "byteswap.hpp"
namespace fc
{
typedef boost::multiprecision::uint128_t m128;
template <typename T>
static void divide(const T &numerator, const T &denominator, T &quotient, 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<uint64_t>(self >> 64);
lo = static_cast<uint64_t>((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<const m128&>(b);
auto& this128 = std::reinterpret_cast<m128&>(*this);
this128 /= b128;
*/
return *this;
}