]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Speed up copy4 and copy64 on little-endian systems
authorAndrew Stubbs <ams@codesourcery.com>
Tue, 1 Jan 2013 17:12:58 +0000 (18:12 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Tue, 1 Jan 2013 17:15:56 +0000 (18:15 +0100)
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.

configure.ac
mdfour.c

index 0ed10547c3d593f847fab51b1c3b1b879a50f4f6..2cf2939266f0a2c644d87e32282b3cc4e09f057f 100644 (file)
@@ -122,6 +122,8 @@ else
     extra_ldflags="-lz"
 fi
 
+AC_C_BIGENDIAN
+
 AC_C_INLINE
 
 dnl Check for "extern inline".
index 8d5b9a72f906871d49465e499e57dd5bbb25eccf..6e2f58425249a9519d7e00ea41ad7bcaecbf899b 100644 (file)
--- 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