From 04d86680bbabe06629dbf53a75ddd4076e6ec1ec Mon Sep 17 00:00:00 2001 From: Jakub Ptak Date: Mon, 15 Aug 2022 11:36:29 +0200 Subject: [PATCH 1/2] Add support for platforms without 128bit integers by using boost library --- CMakeLists.txt | 26 ++++++++++++++++++++++++++ src/starkware/algebra/big_int.h | 8 ++++++++ 2 files changed, 34 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index b442be6..50e09ad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,32 @@ include_directories(${GTEST_INCLUDE_DIRS}) enable_testing() include_directories("${CMAKE_SOURCE_DIR}/src") +# Include boost in case target platform doesn't support uint128 +INCLUDE(CheckCXXSourceCompiles) +check_cxx_source_compiles(" +int main() { + __uint128_t a = 0; + return 0; +}" HAVE_UINT128) + +if (NOT HAVE_UINT128) + FetchContent_Declare( + boostorg + URL https://boostorg.jfrog.io/artifactory/main/release/1.79.0/source/boost_1_79_0.tar.gz + ) + + FetchContent_GetProperties(boostorg) + if (NOT boostorg_POPULATED) + FetchContent_Populate(boostorg) + endif () + + include_directories(${boostorg_SOURCE_DIR}) + + # For Windows: Prevent overriding the parent project's compiler/linker settings + set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) + FetchContent_MakeAvailable(boostorg) +endif() + if (NOT DEFINED CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Debug) endif() diff --git a/src/starkware/algebra/big_int.h b/src/starkware/algebra/big_int.h index ec2ad62..5e47f6c 100644 --- a/src/starkware/algebra/big_int.h +++ b/src/starkware/algebra/big_int.h @@ -13,6 +13,14 @@ #include "starkware/utils/error_handling.h" #include "starkware/utils/prng.h" +/* + Support for 32-bit builds, where __uint128_t isn't defined. +*/ +#ifndef __SIZEOF_INT128__ + #include + typedef boost::multiprecision::uint128_t __uint128_t; +#endif + namespace starkware { static constexpr inline __uint128_t Umul128(uint64_t x, uint64_t y) { From 6d372d60b8a4ced760e1cdaa98c4a819f9809398 Mon Sep 17 00:00:00 2001 From: Jakub Ptak Date: Mon, 15 Aug 2022 11:52:34 +0200 Subject: [PATCH 2/2] Add hash of boost library --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 50e09ad..5f571e4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,7 @@ if (NOT HAVE_UINT128) FetchContent_Declare( boostorg URL https://boostorg.jfrog.io/artifactory/main/release/1.79.0/source/boost_1_79_0.tar.gz + URL_HASH SHA256=273f1be93238a068aba4f9735a4a2b003019af067b9c183ed227780b8f36062c ) FetchContent_GetProperties(boostorg)