diff options
author | dmitry dulesov <dmitry.dulesov@gmail.com> | 2020-01-31 20:22:19 +0300 |
---|---|---|
committer | Dmitry Belyavskiy <beldmit@users.noreply.github.com> | 2020-02-02 21:05:29 +0300 |
commit | b3dd924c96575efc13392530295e0c30254780b1 (patch) | |
tree | bcfd9ad5229bdc3d92fb02403a293a199e18645d /gosthash2012.c | |
parent | 31138d02d9c3698c039154b3078c16f205e25902 (diff) | |
download | gost-engine-b3dd924c96575efc13392530295e0c30254780b1.zip gost-engine-b3dd924c96575efc13392530295e0c30254780b1.tar.gz gost-engine-b3dd924c96575efc13392530295e0c30254780b1.tar.bz2 |
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 <vt@altlinux.org>
Diffstat (limited to 'gosthash2012.c')
-rw-r--r-- | gosthash2012.c | 16 |
1 files 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 <immintrin.h> +# include <x86intrin.h> +#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, |