2 * arch/openrisc/lib/memcpy.c
4 * Optimized memory copy routines for openrisc. These are mostly copied
5 * from ohter sources but slightly entended based on ideas discuassed in
8 * The word unroll implementation is an extension to the arm byte
9 * unrolled implementation, but using word copies (if things are
12 * The great arm loop unroll algorithm can be found at:
13 * arch/arm/boot/compressed/string.c
16 #include <linux/export.h>
18 #include <linux/string.h>
20 #ifdef CONFIG_OR1K_1200
22 * Do memcpy with word copies and loop unrolling. This gives the
23 * best performance on the OR1200 and MOR1KX archirectures
25 void *memcpy(void *dest, __const void *src, __kernel_size_t n)
29 uint32_t *dest_w = (uint32_t *)dest, *src_w = (uint32_t *)src;
31 /* If both source and dest are word aligned copy words */
32 if (!((unsigned int)dest_w & 3) && !((unsigned int)src_w & 3)) {
33 /* Copy 32 bytes per loop */
34 for (i = n >> 5; i > 0; i--) {
60 d = (unsigned char *)dest_w;
61 s = (unsigned char *)src_w;
64 d = (unsigned char *)dest_w;
65 s = (unsigned char *)src_w;
67 for (i = n >> 3; i > 0; i--) {
98 * Use word copies but no loop unrolling as we cannot assume there
99 * will be benefits on the archirecture
101 void *memcpy(void *dest, __const void *src, __kernel_size_t n)
103 unsigned char *d = (unsigned char *)dest, *s = (unsigned char *)src;
104 uint32_t *dest_w = (uint32_t *)dest, *src_w = (uint32_t *)src;
106 /* If both source and dest are word aligned copy words */
107 if (!((unsigned int)dest_w & 3) && !((unsigned int)src_w & 3)) {
108 for (; n >= 4; n -= 4)
109 *dest_w++ = *src_w++;
112 d = (unsigned char *)dest_w;
113 s = (unsigned char *)src_w;
115 /* For remaining or if not aligned, copy bytes */
116 for (; n >= 1; n -= 1)
124 EXPORT_SYMBOL(memcpy);