From: Nicolas Pitre <nico@cam.org>
To: Andrew Morton <akpm@osdl.org>, Herbert Xu <herbert@gondor.apana.org.au>
Cc: lkml <linux-kernel@vger.kernel.org>
Subject: [PATCH 1/5] crypto/sha1.c: avoid useless memcpy()
Date: Mon, 24 Oct 2005 13:56:06 -0400 (EDT) [thread overview]
Message-ID: <Pine.LNX.4.64.0510241355030.5288@localhost.localdomain> (raw)
In-Reply-To: <Pine.LNX.4.64.0510241347081.5288@localhost.localdomain>
The current code unconditionally copy the first block for every call to
sha1_update(). This can be avoided if there is no pending partial block.
This is always the case on the first call to sha1_update() (if the length
is >= 64 of course0.
In the case where sha1_update() is called successively with len=64,
a 8.5% performance increase can be observed on i386, and 8.2% on ARm.
Signed-off-by: Nicolas Pitre <nico@cam.org>
Index: linux-2.6/crypto/sha1.c
===================================================================
--- linux-2.6.orig/crypto/sha1.c
+++ linux-2.6/crypto/sha1.c
@@ -48,23 +48,26 @@
static void sha1_update(void *ctx, const u8 *data, unsigned int len)
{
struct sha1_ctx *sctx = ctx;
- unsigned int i, j;
+ unsigned int partial, done;
u32 temp[SHA_WORKSPACE_WORDS];
- j = (sctx->count >> 3) & 0x3f;
+ partial = (sctx->count >> 3) & 0x3f;
sctx->count += len << 3;
+ done = 0;
- if ((j + len) > 63) {
- memcpy(&sctx->buffer[j], data, (i = 64-j));
- sha_transform(sctx->state, sctx->buffer, temp);
- for ( ; i + 63 < len; i += 64) {
- sha_transform(sctx->state, &data[i], temp);
+ if ((partial + len) > 63) {
+ if (partial) {
+ done = 64 - partial;
+ memcpy(sctx->buffer + partial, data, done);
+ sha_transform(sctx->state, sctx->buffer, temp);
+ partial = 0;
}
- j = 0;
+ for ( ; done + 63 < len; done += 64)
+ sha_transform(sctx->state, data + done, temp);
}
- else i = 0;
+ if (len - done)
+ memcpy(sctx->buffer + partial, data + done, len - done);
memset(temp, 0, sizeof(temp));
- memcpy(&sctx->buffer[j], &data[i], len - i);
}
next prev parent reply other threads:[~2005-10-24 17:56 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-10-24 17:54 [PATCH 0/5] crypto/sha1.c: code cleanup Nicolas Pitre
2005-10-24 17:56 ` Nicolas Pitre [this message]
2005-10-24 17:57 ` [PATCH 2/5] crypto/sha1.c: avoid shifting count left and right Nicolas Pitre
2005-11-13 0:29 ` Herbert Xu
2005-10-24 17:57 ` [PATCH 3/5] crypto/sha1.c: move related code together Nicolas Pitre
2005-10-24 18:03 ` Nicolas Pitre
2005-10-24 18:03 ` [PATCH 5/5] crypto/sha1.c: final cleanup Nicolas Pitre
2005-10-24 18:05 ` [PATCH 4/5] crypto/sha1.c: avoid successively shifting a long long Nicolas Pitre
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Pine.LNX.4.64.0510241355030.5288@localhost.localdomain \
--to=nico@cam.org \
--cc=akpm@osdl.org \
--cc=herbert@gondor.apana.org.au \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®