[PATCH 1/4] gostr3411-94: small speedup
dbaryshkov at gmail.com
dbaryshkov at gmail.com
Tue Nov 12 14:50:02 CET 2019
From: Dmitry Eremin-Solenikov <dbaryshkov at gmail.com>
* cipher/gostr3411-94.c (do_p): unroll loop for a small spedup
--
Before:
GOSTR3411_94 | 25.12 ns/B 37.96 MiB/s - c/B
GOSTR3411_CP | 25.14 ns/B 37.93 MiB/s - c/B
After:
GOSTR3411_94 | 24.57 ns/B 38.81 MiB/s - c/B
GOSTR3411_CP | 24.59 ns/B 38.79 MiB/s - c/B
Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov at gmail.com>
---
cipher/gostr3411-94.c | 50 +++++++++++++++++++++++++++++++++----------
1 file changed, 39 insertions(+), 11 deletions(-)
diff --git a/cipher/gostr3411-94.c b/cipher/gostr3411-94.c
index ebf9e0a242f3..c5a0aef63de3 100644
--- a/cipher/gostr3411-94.c
+++ b/cipher/gostr3411-94.c
@@ -83,17 +83,45 @@ do_p (u32 *p, u32 *u, u32 *v)
for (k = 0; k < 8; k++)
t[k] = u[k] ^ v[k];
- for (k = 0; k < 4; k++)
- {
- p[k+0] = ((t[0] >> (8*k)) & 0xff) << 0 |
- ((t[2] >> (8*k)) & 0xff) << 8 |
- ((t[4] >> (8*k)) & 0xff) << 16 |
- ((t[6] >> (8*k)) & 0xff) << 24;
- p[k+4] = ((t[1] >> (8*k)) & 0xff) << 0 |
- ((t[3] >> (8*k)) & 0xff) << 8 |
- ((t[5] >> (8*k)) & 0xff) << 16 |
- ((t[7] >> (8*k)) & 0xff) << 24;
- }
+ k = 0;
+ p[k+0] = ((t[0] >> (8*k)) & 0xff) << 0 |
+ ((t[2] >> (8*k)) & 0xff) << 8 |
+ ((t[4] >> (8*k)) & 0xff) << 16 |
+ ((t[6] >> (8*k)) & 0xff) << 24;
+ p[k+4] = ((t[1] >> (8*k)) & 0xff) << 0 |
+ ((t[3] >> (8*k)) & 0xff) << 8 |
+ ((t[5] >> (8*k)) & 0xff) << 16 |
+ ((t[7] >> (8*k)) & 0xff) << 24;
+
+ k = 1;
+ p[k+0] = ((t[0] >> (8*k)) & 0xff) << 0 |
+ ((t[2] >> (8*k)) & 0xff) << 8 |
+ ((t[4] >> (8*k)) & 0xff) << 16 |
+ ((t[6] >> (8*k)) & 0xff) << 24;
+ p[k+4] = ((t[1] >> (8*k)) & 0xff) << 0 |
+ ((t[3] >> (8*k)) & 0xff) << 8 |
+ ((t[5] >> (8*k)) & 0xff) << 16 |
+ ((t[7] >> (8*k)) & 0xff) << 24;
+
+ k = 2;
+ p[k+0] = ((t[0] >> (8*k)) & 0xff) << 0 |
+ ((t[2] >> (8*k)) & 0xff) << 8 |
+ ((t[4] >> (8*k)) & 0xff) << 16 |
+ ((t[6] >> (8*k)) & 0xff) << 24;
+ p[k+4] = ((t[1] >> (8*k)) & 0xff) << 0 |
+ ((t[3] >> (8*k)) & 0xff) << 8 |
+ ((t[5] >> (8*k)) & 0xff) << 16 |
+ ((t[7] >> (8*k)) & 0xff) << 24;
+
+ k = 3;
+ p[k+0] = ((t[0] >> (8*k)) & 0xff) << 0 |
+ ((t[2] >> (8*k)) & 0xff) << 8 |
+ ((t[4] >> (8*k)) & 0xff) << 16 |
+ ((t[6] >> (8*k)) & 0xff) << 24;
+ p[k+4] = ((t[1] >> (8*k)) & 0xff) << 0 |
+ ((t[3] >> (8*k)) & 0xff) << 8 |
+ ((t[5] >> (8*k)) & 0xff) << 16 |
+ ((t[7] >> (8*k)) & 0xff) << 24;
}
static void
--
2.24.0
More information about the Gcrypt-devel
mailing list