GNU Linux-libre 4.14.266-gnu1
[releases.git] / arch / powerpc / lib / mem_64.S
1 /*
2  * String handling functions for PowerPC.
3  *
4  * Copyright (C) 1996 Paul Mackerras.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version
9  * 2 of the License, or (at your option) any later version.
10  */
11 #include <asm/processor.h>
12 #include <asm/errno.h>
13 #include <asm/ppc_asm.h>
14 #include <asm/export.h>
15
16 _GLOBAL(__memset16)
17         rlwimi  r4,r4,16,0,15
18         /* fall through */
19
20 _GLOBAL(__memset32)
21         rldimi  r4,r4,32,0
22         /* fall through */
23
24 _GLOBAL(__memset64)
25         neg     r0,r3
26         andi.   r0,r0,7
27         cmplw   cr1,r5,r0
28         b       .Lms
29 EXPORT_SYMBOL(__memset16)
30 EXPORT_SYMBOL(__memset32)
31 EXPORT_SYMBOL(__memset64)
32
33 _GLOBAL(memset)
34         neg     r0,r3
35         rlwimi  r4,r4,8,16,23
36         andi.   r0,r0,7                 /* # bytes to be 8-byte aligned */
37         rlwimi  r4,r4,16,0,15
38         cmplw   cr1,r5,r0               /* do we get that far? */
39         rldimi  r4,r4,32,0
40 .Lms:   PPC_MTOCRF(1,r0)
41         mr      r6,r3
42         blt     cr1,8f
43         beq+    3f                      /* if already 8-byte aligned */
44         subf    r5,r0,r5
45         bf      31,1f
46         stb     r4,0(r6)
47         addi    r6,r6,1
48 1:      bf      30,2f
49         sth     r4,0(r6)
50         addi    r6,r6,2
51 2:      bf      29,3f
52         stw     r4,0(r6)
53         addi    r6,r6,4
54 3:      srdi.   r0,r5,6
55         clrldi  r5,r5,58
56         mtctr   r0
57         beq     5f
58         .balign 16
59 4:      std     r4,0(r6)
60         std     r4,8(r6)
61         std     r4,16(r6)
62         std     r4,24(r6)
63         std     r4,32(r6)
64         std     r4,40(r6)
65         std     r4,48(r6)
66         std     r4,56(r6)
67         addi    r6,r6,64
68         bdnz    4b
69 5:      srwi.   r0,r5,3
70         clrlwi  r5,r5,29
71         PPC_MTOCRF(1,r0)
72         beq     8f
73         bf      29,6f
74         std     r4,0(r6)
75         std     r4,8(r6)
76         std     r4,16(r6)
77         std     r4,24(r6)
78         addi    r6,r6,32
79 6:      bf      30,7f
80         std     r4,0(r6)
81         std     r4,8(r6)
82         addi    r6,r6,16
83 7:      bf      31,8f
84         std     r4,0(r6)
85         addi    r6,r6,8
86 8:      cmpwi   r5,0
87         PPC_MTOCRF(1,r5)
88         beqlr+
89         bf      29,9f
90         stw     r4,0(r6)
91         addi    r6,r6,4
92 9:      bf      30,10f
93         sth     r4,0(r6)
94         addi    r6,r6,2
95 10:     bflr    31
96         stb     r4,0(r6)
97         blr
98 EXPORT_SYMBOL(memset)
99
100 _GLOBAL_TOC(memmove)
101         cmplw   0,r3,r4
102         bgt     backwards_memcpy
103         b       memcpy
104
105 _GLOBAL(backwards_memcpy)
106         rlwinm. r7,r5,32-3,3,31         /* r0 = r5 >> 3 */
107         add     r6,r3,r5
108         add     r4,r4,r5
109         beq     2f
110         andi.   r0,r6,3
111         mtctr   r7
112         bne     5f
113         .balign 16
114 1:      lwz     r7,-4(r4)
115         lwzu    r8,-8(r4)
116         stw     r7,-4(r6)
117         stwu    r8,-8(r6)
118         bdnz    1b
119         andi.   r5,r5,7
120 2:      cmplwi  0,r5,4
121         blt     3f
122         lwzu    r0,-4(r4)
123         subi    r5,r5,4
124         stwu    r0,-4(r6)
125 3:      cmpwi   0,r5,0
126         beqlr
127         mtctr   r5
128 4:      lbzu    r0,-1(r4)
129         stbu    r0,-1(r6)
130         bdnz    4b
131         blr
132 5:      mtctr   r0
133 6:      lbzu    r7,-1(r4)
134         stbu    r7,-1(r6)
135         bdnz    6b
136         subf    r5,r0,r5
137         rlwinm. r7,r5,32-3,3,31
138         beq     2b
139         mtctr   r7
140         b       1b
141 EXPORT_SYMBOL(memmove)