From b3dd924c96575efc13392530295e0c30254780b1 Mon Sep 17 00:00:00 2001 From: dmitry dulesov Date: Fri, 31 Jan 2020 20:22:19 +0300 Subject: [PATCH] gosthash2012: Optimize `add512` on x86_64 using Intel intrinsics `_addcarry_u64' is using `ADC' and does not require ADX extensions (`-madx'). Committed-by: Vitaly Chikunov --- gosthash2012.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/gosthash2012.c b/gosthash2012.c index ddd35fa..d6cde21 100644 --- a/gosthash2012.c +++ b/gosthash2012.c @@ -9,6 +9,10 @@ */ #include "gosthash2012.h" +#ifdef __x86_64__ +# include +# include +#endif #if defined(_WIN32) || defined(_WINDOWS) # define INLINE __inline @@ -57,10 +61,13 @@ static INLINE void add512(union uint512_u * RESTRICT x, const union uint512_u * RESTRICT y) { #ifndef __GOST3411_BIG_ENDIAN__ - unsigned int CF; + unsigned int CF = 0; unsigned int i; - CF = 0; +# ifdef __x86_64__ + for (i = 0; i < 8; i++) + CF = _addcarry_u64(CF, x->QWORD[i] , y->QWORD[i], &(x->QWORD[i])); +# else for (i = 0; i < 8; i++) { const unsigned long long left = x->QWORD[i]; unsigned long long sum; @@ -82,7 +89,8 @@ static INLINE void add512(union uint512_u * RESTRICT x, CF = (sum < left); x->QWORD[i] = sum; } -#else +# endif /* !__x86_64__ */ +#else /* __GOST3411_BIG_ENDIAN__ */ const unsigned char *yp; unsigned char *xp; unsigned int i; @@ -96,7 +104,7 @@ static INLINE void add512(union uint512_u * RESTRICT x, buf = xp[i] + yp[i] + (buf >> 8); xp[i] = (unsigned char)buf & 0xFF; } -#endif +#endif /* __GOST3411_BIG_ENDIAN__ */ } static void g(union uint512_u *h, const union uint512_u * RESTRICT N, -- 2.39.5