diff options
author | Keir Fraser <keir.fraser@citrix.com> | 2009-10-07 07:45:39 +0100 |
---|---|---|
committer | Keir Fraser <keir.fraser@citrix.com> | 2009-10-07 07:45:39 +0100 |
commit | 62d705d4a2764cf7d36300bcb4a26a806d0c6db1 (patch) | |
tree | 51bebc4f85dfd4adaa439739542281a151ba158e /xen/include/asm-x86/string.h | |
parent | f00b33008950c400711c9ab1cd11337be04a4eb5 (diff) | |
download | xen-62d705d4a2764cf7d36300bcb4a26a806d0c6db1.tar.gz xen-62d705d4a2764cf7d36300bcb4a26a806d0c6db1.tar.bz2 xen-62d705d4a2764cf7d36300bcb4a26a806d0c6db1.zip |
Optimize memcpy for x86 arch. If source buffers does not start at a 64
bit boundary, copy a few bytes at the beginnig up to next 64-bit
boundary and then does an aligned copy for the remaining data. This
can reduce the copy cost by up to 50%.
Signed-off-by: Jose Renato Santos <jsantos@hpl.hp.com>
Diffstat (limited to 'xen/include/asm-x86/string.h')
-rw-r--r-- | xen/include/asm-x86/string.h | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/xen/include/asm-x86/string.h b/xen/include/asm-x86/string.h index 496b22754f..c3481216ee 100644 --- a/xen/include/asm-x86/string.h +++ b/xen/include/asm-x86/string.h @@ -96,13 +96,29 @@ static always_inline void * __constant_memcpy( } #define __HAVE_ARCH_MEMCPY +/* align source to a 64-bit boundary */ +static always_inline +void *__var_memcpy(void *t, const void *f, size_t n) +{ + int off = (unsigned long)f & 0x7; + /* just do alignment if needed and if size is worth */ + if ( (n > 32) && off ) { + size_t n1 = 8 - off; + __variable_memcpy(t, f, n1); + __variable_memcpy(t + n1, f + n1, n - n1); + return t; + } else { + return (__variable_memcpy(t, f, n)); + } +} + #define memcpy(t,f,n) (__memcpy((t),(f),(n))) static always_inline void *__memcpy(void *t, const void *f, size_t n) { return (__builtin_constant_p(n) ? __constant_memcpy((t),(f),(n)) : - __variable_memcpy((t),(f),(n))); + __var_memcpy((t),(f),(n))); } /* Some version of gcc don't have this builtin. It's non-critical anyway. */ |