From ed0f8fbedf438e0ed1f6da9e829a932881695175 Mon Sep 17 00:00:00 2001 From: Vitaly Chikunov Date: Tue, 4 Feb 2020 05:41:53 +0300 Subject: [PATCH] gosthash2012: Provide cmake test for _addcarry_u64 Also, simple check if `_addcarry_u64' works correctly. --- CMakeLists.txt | 18 ++++++++++++++++++ gosthash2012.c | 9 ++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ea6920e..5d6da65 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,7 @@ project(gost-engine LANGUAGES C) include(GNUInstallDirs) include(CheckLibraryExists) include(CheckFunctionExists) +include(CheckCSourceRuns) enable_testing() @@ -47,6 +48,23 @@ else() add_definitions(-DL_ENDIAN) endif() +check_c_source_runs(" + #ifdef _MSC_VER + # include + #else + # include + #endif + int main(void) { + unsigned long long x = -1, y = 1, r; + unsigned char cf; + cf = _addcarry_u64(1, (unsigned long)x, y, &r); + return !(cf == 1 && r == 1); + } + " ADDCARRY_U64) +if (ADDCARRY_U64) + add_definitions(-DHAVE_ADDCARRY_U64) +endif() + set(BIN_DIRECTORY bin) # Same soversion as OpenSSL diff --git a/gosthash2012.c b/gosthash2012.c index 6399a9e..5a4c64e 100644 --- a/gosthash2012.c +++ b/gosthash2012.c @@ -10,8 +10,11 @@ #include "gosthash2012.h" #ifdef __x86_64__ -# include -# include +# ifdef _MSC_VER +# include +# else +# include +# endif #endif #if defined(_WIN32) || defined(_WINDOWS) @@ -64,7 +67,7 @@ static INLINE void add512(union uint512_u * RESTRICT x, unsigned int CF = 0; unsigned int i; -# ifdef __x86_64__ +# ifdef HAVE_ADDCARRY_U64 for (i = 0; i < 8; i++) CF = _addcarry_u64(CF, x->QWORD[i] , y->QWORD[i], &(x->QWORD[i])); # else -- 2.39.2