]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/uclibc/lib/contrib/uclibc/libc/string/frv/memcpy.S
update
[l4.git] / l4 / pkg / uclibc / lib / contrib / uclibc / libc / string / frv / memcpy.S
1 /* memcpy.S: optimised assembly memcpy
2  *
3  * Copyright (C) 2003, 2004 Red Hat, Inc. All Rights Reserved.
4  * Written by David Howells (dhowells@redhat.com)
5  *
6  *  This library is free software; you can redistribute it and/or
7  *  modify it under the terms of the GNU Library General Public
8  *  License as published by the Free Software Foundation; either
9  *  version 2 of the License, or (at your option) any later version.
10  *
11  *  This library is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  *  Library General Public License for more details.
15  *
16  *  You should have received a copy of the GNU Library General Public
17  *  License along with this library; if not, see
18  *  <http://www.gnu.org/licenses/>.
19  */
20
21 #include <features.h>
22
23         .text
24         .p2align        4
25
26 ###############################################################################
27 #
28 # void *memcpy(void *to, const char *from, size_t count)
29 #
30 # - NOTE: must not use any stack. exception detection performs function return
31 #         to caller's fixup routine, aborting the remainder of the copy
32 #
33 ###############################################################################
34         .globl          memcpy
35         .type           memcpy,@function
36 memcpy:
37         or.p            gr8,gr9,gr4
38         orcc            gr10,gr0,gr0,icc3
39         or.p            gr10,gr4,gr4
40         beqlr           icc3,#0
41
42         # optimise based on best common alignment for to, from & count
43         andicc.p        gr4,#0x1f,gr0,icc0
44         setlos          #8,gr11
45         andicc.p        gr4,#0x0f,gr0,icc1
46         beq             icc0,#0,memcpy_32
47         andicc.p        gr4,#0x07,gr0,icc0
48         beq             icc1,#0,memcpy_16
49         andicc.p        gr4,#0x03,gr0,icc1
50         beq             icc0,#0,memcpy_8
51         andicc.p        gr4,#0x01,gr0,icc0
52         beq             icc1,#0,memcpy_4
53         setlos.p        #1,gr11
54         beq             icc0,#0,memcpy_2
55
56         # do byte by byte copy
57         sub.p           gr8,gr11,gr3
58         sub             gr9,gr11,gr9
59 0:      ldubu.p         @(gr9,gr11),gr4
60         subicc          gr10,#1,gr10,icc0
61         stbu.p          gr4,@(gr3,gr11)
62         bne             icc0,#2,0b
63         bralr
64
65         # do halfword by halfword copy
66 memcpy_2:
67         setlos          #2,gr11
68         sub.p           gr8,gr11,gr3
69         sub             gr9,gr11,gr9
70 0:      lduhu.p         @(gr9,gr11),gr4
71         subicc          gr10,#2,gr10,icc0
72         sthu.p          gr4,@(gr3,gr11)
73         bne             icc0,#2,0b
74         bralr
75
76         # do word by word copy
77 memcpy_4:
78         setlos          #4,gr11
79         sub.p           gr8,gr11,gr3
80         sub             gr9,gr11,gr9
81 0:      ldu.p           @(gr9,gr11),gr4
82         subicc          gr10,#4,gr10,icc0
83         stu.p           gr4,@(gr3,gr11)
84         bne             icc0,#2,0b
85         bralr
86
87         # do double-word by double-word copy
88 memcpy_8:
89         sub.p           gr8,gr11,gr3
90         sub             gr9,gr11,gr9
91 0:      lddu.p          @(gr9,gr11),gr4
92         subicc          gr10,#8,gr10,icc0
93         stdu.p          gr4,@(gr3,gr11)
94         bne             icc0,#2,0b
95         bralr
96
97         # do quad-word by quad-word copy
98 memcpy_16:
99         sub.p           gr8,gr11,gr3
100         sub             gr9,gr11,gr9
101 0:      lddu            @(gr9,gr11),gr4
102         lddu.p          @(gr9,gr11),gr6
103         subicc          gr10,#16,gr10,icc0
104         stdu            gr4,@(gr3,gr11)
105         stdu.p          gr6,@(gr3,gr11)
106         bne             icc0,#2,0b
107         bralr
108
109         # do eight-word by eight-word copy
110 memcpy_32:
111         sub.p           gr8,gr11,gr3
112         sub             gr9,gr11,gr9
113 0:      lddu            @(gr9,gr11),gr4
114         lddu            @(gr9,gr11),gr6
115         lddu            @(gr9,gr11),gr12
116         lddu.p          @(gr9,gr11),gr14
117         subicc          gr10,#32,gr10,icc0
118         stdu            gr4,@(gr3,gr11)
119         stdu            gr6,@(gr3,gr11)
120         stdu            gr12,@(gr3,gr11)
121         stdu.p          gr14,@(gr3,gr11)
122         bne             icc0,#2,0b
123         bralr
124
125         .size           memcpy, .-memcpy
126
127 libc_hidden_def(memcpy)