[PATCH] Speed up "copy4", "copy64" on little-endian systems.
Andrew Stubbs <[email protected]>
| Newsgroups | gmane.comp.compilers.ccache |
|---|---|
| Message-ID | <[email protected]> |
The copy64 function implements an endian-safe copy routine for an array of 16 32-bit integers, but this is sub-optimal on machines where the byte-order is already correct. Likewise for copy4. This patch replaces the implementation with a simple memcpy when appropriate, and retains the old implementation otherwise. Note that the compiler will always inline calls to memcpy for small byte-counts, so this is a big win. Signed-off-by: Andrew Stubbs <[email protected]> --- configure.ac | 2 ++ mdfour.c | 8 ++++++++ 2 files changed, 10 insertions(+) _______________________________________________ ccache mailing list [email protected] https://lists.samba.org/mailman/listinfo/ccache
0001-Speed-up-copy4-copy64-on-little-endian-systems.patch
(text/x-patch, 836 B)
diff --git a/configure.ac b/configure.ac
index 0ed1054..2cf2939 100644
--- a/configure.ac
+++ b/configure.ac
@@ -122,6 +122,8 @@ else
extra_ldflags="-lz"
fi
+AC_C_BIGENDIAN
+
AC_C_INLINE
dnl Check for "extern inline".
diff --git a/mdfour.c b/mdfour.c
index 8d5b9a7..6e2f584 100644
--- a/mdfour.c
+++ b/mdfour.c
@@ -83,20 +83,28 @@ mdfour64(uint32_t *M)
static void
copy64(uint32_t *M, const unsigned char *in)
{
+#ifdef WORDS_BIGENDIAN
int i;
for (i = 0; i < 16; i++)
M[i] = (in[i*4+3]<<24) | (in[i*4+2]<<16) |
(in[i*4+1]<<8) | (in[i*4+0]<<0);
+#else
+ memcpy(M, in, 16*4);
+#endif
}
static void
copy4(unsigned char *out, uint32_t x)
{
+#ifdef WORDS_BIGENDIAN
out[0] = x&0xFF;
out[1] = (x>>8)&0xFF;
out[2] = (x>>16)&0xFF;
out[3] = (x>>24)&0xFF;
+#else
+ memcpy(out, &x, 4);
+#endif
}
void