From 79b2a0d634a9c8d51d00e2c4b9462b3b4529e108 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Sat, 8 Jun 2019 10:25:52 +0200 Subject: [PATCH] Add support for native 128bit types --- CMakeLists.txt | 7 ++++++- include/fc/uint128.hpp | 15 +++++++++++++++ src/crypto/city.cpp | 1 + src/variant.cpp | 4 ++-- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9769e66..fd83397 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,12 @@ CMAKE_MINIMUM_REQUIRED( VERSION 3.1 ) set( CMAKE_CXX_STANDARD 14 ) SET( CMAKE_CXX_STANDARD_REQUIRED ON ) -set( CMAKE_CXX_EXTENSIONS OFF ) + +if( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" ) + set( CMAKE_CXX_EXTENSIONS ON ) # for __int128 support +else( GNU ) + set( CMAKE_CXX_EXTENSIONS OFF ) +endif( GNU ) MESSAGE(STATUS "Configuring project fc located in: ${CMAKE_CURRENT_SOURCE_DIR}") SET( CMAKE_AUTOMOC OFF ) diff --git a/include/fc/uint128.hpp b/include/fc/uint128.hpp index fa9ae07..741676e 100644 --- a/include/fc/uint128.hpp +++ b/include/fc/uint128.hpp @@ -24,6 +24,19 @@ #pragma once +#ifdef __SIZEOF_INT128__ + +#include + +namespace fc { + +using int128_t = __int128_t; +using uint128_t = __uint128_t; + +} // namespace fc + +#else // __SIZEOF_INT128__ + #include namespace fc { @@ -32,3 +45,5 @@ using boost::multiprecision::int128_t; using boost::multiprecision::uint128_t; } // namespace fc + +#endif // __SIZEOF_INT128__ diff --git a/src/crypto/city.cpp b/src/crypto/city.cpp index 5649dd6..ef5469d 100644 --- a/src/crypto/city.cpp +++ b/src/crypto/city.cpp @@ -31,6 +31,7 @@ //#include #include +#include #include // for memcpy and memset #include #include diff --git a/src/variant.cpp b/src/variant.cpp index d823f32..a472ddf 100644 --- a/src/variant.cpp +++ b/src/variant.cpp @@ -675,12 +675,12 @@ void from_variant( const variant& var, std::vector& vo, uint32_t max_depth void to_variant( const uint128_t& var, variant& vo, uint32_t max_depth ) { - vo = var.str(); + vo = boost::lexical_cast( var ); } void from_variant( const variant& var, uint128_t& vo, uint32_t max_depth ) { - vo = uint128_t( var.as_string() ); + vo = boost::lexical_cast( var.as_string() ); } #ifdef __APPLE__