1 // SPDX-License-Identifier: GPL-2.0
3 * arch/openrisc/lib/memcpy.c
5 * Optimized memory copy routines for openrisc. These are mostly copied
6 * from ohter sources but slightly entended based on ideas discuassed in
9 * The word unroll implementation is an extension to the arm byte
10 * unrolled implementation, but using word copies (if things are
13 * The great arm loop unroll algorithm can be found at:
14 * arch/arm/boot/compressed/string.c
17 #include <linux/export.h>
19 #include <linux/string.h>
21 #ifdef CONFIG_OR1K_1200
23 * Do memcpy with word copies and loop unrolling. This gives the
24 * best performance on the OR1200 and MOR1KX archirectures
26 void *memcpy(void *dest, __const void *src, __kernel_size_t n)
30 uint32_t *dest_w = (uint32_t *)dest, *src_w = (uint32_t *)src;
32 /* If both source and dest are word aligned copy words */
33 if (!((unsigned int)dest_w & 3) && !((unsigned int)src_w & 3)) {
34 /* Copy 32 bytes per loop */
35 for (i = n >> 5; i > 0; i--) {
61 d = (unsigned char *)dest_w;
62 s = (unsigned char *)src_w;
65 d = (unsigned char *)dest_w;
66 s = (unsigned char *)src_w;
68 for (i = n >> 3; i > 0; i--) {
99 * Use word copies but no loop unrolling as we cannot assume there
100 * will be benefits on the archirecture
102 void *memcpy(void *dest, __const void *src, __kernel_size_t n)
104 unsigned char *d = (unsigned char *)dest, *s = (unsigned char *)src;
105 uint32_t *dest_w = (uint32_t *)dest, *src_w = (uint32_t *)src;
107 /* If both source and dest are word aligned copy words */
108 if (!((unsigned int)dest_w & 3) && !((unsigned int)src_w & 3)) {
109 for (; n >= 4; n -= 4)
110 *dest_w++ = *src_w++;
113 d = (unsigned char *)dest_w;
114 s = (unsigned char *)src_w;
116 /* For remaining or if not aligned, copy bytes */
117 for (; n >= 1; n -= 1)
125 EXPORT_SYMBOL(memcpy);