blob: c2ca49d705af704da614ef7ff2dee9b4d253f975 [file] [log] [blame]
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001/*
2 * Copyright (C) 2004-2006 Atmel Corporation
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 */
8
9 /*
10 * void *memcpy(void *to, const void *from, unsigned long n)
11 *
12 * This implementation does word-aligned loads in the main loop,
13 * possibly sacrificing alignment of stores.
14 *
15 * Hopefully, in most cases, both "to" and "from" will be
16 * word-aligned to begin with.
17 */
18 .text
19 .global memcpy
20 .type memcpy, @function
21memcpy:
22 mov r9, r11
23 andl r9, 3, COH
24 brne 1f
25
26 /* At this point, "from" is word-aligned */
Sebastian Andrzej Siewior505d62d2009-07-26 14:57:54 +0200272: mov r9, r12
285: sub r10, 4
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070029 brlt 4f
30
313: ld.w r8, r11++
32 sub r10, 4
33 st.w r12++, r8
34 brge 3b
35
364: neg r10
37 reteq r9
38
39 /* Handle unaligned count */
40 lsl r10, 2
41 add pc, pc, r10
42 ld.ub r8, r11++
43 st.b r12++, r8
44 ld.ub r8, r11++
45 st.b r12++, r8
46 ld.ub r8, r11++
47 st.b r12++, r8
48 retal r9
49
50 /* Handle unaligned "from" pointer */
511: sub r10, 4
Sebastian Andrzej Siewior251ab1a2009-07-26 14:58:34 +020052 movlt r9, r12
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070053 brlt 4b
54 add r10, r9
55 lsl r9, 2
56 add pc, pc, r9
57 ld.ub r8, r11++
58 st.b r12++, r8
59 ld.ub r8, r11++
60 st.b r12++, r8
61 ld.ub r8, r11++
62 st.b r12++, r8
Sebastian Andrzej Siewior505d62d2009-07-26 14:57:54 +020063 mov r8, r12
64 add pc, pc, r9
65 sub r8, 1
66 nop
67 sub r8, 1
68 nop
69 sub r8, 1
70 nop
71 mov r9, r8
72 rjmp 5b