]> wagner.pp.ru Git - openssl-gost/engine.git/commitdiff
gosthash2012: Provide cmake test for _addcarry_u64
authorVitaly Chikunov <vt@altlinux.org>
Tue, 4 Feb 2020 02:41:53 +0000 (05:41 +0300)
committerDmitry Belyavskiy <beldmit@users.noreply.github.com>
Tue, 4 Feb 2020 06:56:31 +0000 (09:56 +0300)
Also, simple check if `_addcarry_u64' works correctly.

CMakeLists.txt
gosthash2012.c

index ea6920e7af2528ae0fa115f7b974c5761cebe158..5d6da65729cab1fa0d0dd5a81c5be0d8c4cdd85c 100644 (file)
@@ -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 <intrin.h>
+  #else
+  # include <x86intrin.h>
+  #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
index 6399a9edd2d5dca686c78434de4ecabe0dc9ef33..5a4c64e488d0830beefa34c36c7192114d8ba99f 100644 (file)
 
 #include "gosthash2012.h"
 #ifdef __x86_64__
-# include <immintrin.h>
-# include <x86intrin.h>
+# ifdef _MSC_VER
+#  include <intrin.h>
+# else
+#  include <x86intrin.h>
+# 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