From: Vitaly Chikunov Date: Tue, 4 Feb 2020 02:41:53 +0000 (+0300) Subject: gosthash2012: Provide cmake test for _addcarry_u64 X-Git-Tag: v3.0.0~208 X-Git-Url: http://wagner.pp.ru/gitweb/?a=commitdiff_plain;h=ed0f8fbedf438e0ed1f6da9e829a932881695175;p=openssl-gost%2Fengine.git gosthash2012: Provide cmake test for _addcarry_u64 Also, simple check if `_addcarry_u64' works correctly. --- 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