Linux 4.13.16
[linux/fpc-iii.git] / arch / powerpc / lib / mem_64.S
blob85fa9869aec5848d1c22c7b24e297cb51f1d4a9d
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>
16 _GLOBAL(memset)
17         neg     r0,r3
18         rlwimi  r4,r4,8,16,23
19         andi.   r0,r0,7                 /* # bytes to be 8-byte aligned */
20         rlwimi  r4,r4,16,0,15
21         cmplw   cr1,r5,r0               /* do we get that far? */
22         rldimi  r4,r4,32,0
23         PPC_MTOCRF(1,r0)
24         mr      r6,r3
25         blt     cr1,8f
26         beq+    3f                      /* if already 8-byte aligned */
27         subf    r5,r0,r5
28         bf      31,1f
29         stb     r4,0(r6)
30         addi    r6,r6,1
31 1:      bf      30,2f
32         sth     r4,0(r6)
33         addi    r6,r6,2
34 2:      bf      29,3f
35         stw     r4,0(r6)
36         addi    r6,r6,4
37 3:      srdi.   r0,r5,6
38         clrldi  r5,r5,58
39         mtctr   r0
40         beq     5f
41         .balign 16
42 4:      std     r4,0(r6)
43         std     r4,8(r6)
44         std     r4,16(r6)
45         std     r4,24(r6)
46         std     r4,32(r6)
47         std     r4,40(r6)
48         std     r4,48(r6)
49         std     r4,56(r6)
50         addi    r6,r6,64
51         bdnz    4b
52 5:      srwi.   r0,r5,3
53         clrlwi  r5,r5,29
54         PPC_MTOCRF(1,r0)
55         beq     8f
56         bf      29,6f
57         std     r4,0(r6)
58         std     r4,8(r6)
59         std     r4,16(r6)
60         std     r4,24(r6)
61         addi    r6,r6,32
62 6:      bf      30,7f
63         std     r4,0(r6)
64         std     r4,8(r6)
65         addi    r6,r6,16
66 7:      bf      31,8f
67         std     r4,0(r6)
68         addi    r6,r6,8
69 8:      cmpwi   r5,0
70         PPC_MTOCRF(1,r5)
71         beqlr+
72         bf      29,9f
73         stw     r4,0(r6)
74         addi    r6,r6,4
75 9:      bf      30,10f
76         sth     r4,0(r6)
77         addi    r6,r6,2
78 10:     bflr    31
79         stb     r4,0(r6)
80         blr
81 EXPORT_SYMBOL(memset)
83 _GLOBAL_TOC(memmove)
84         cmplw   0,r3,r4
85         bgt     backwards_memcpy
86         b       memcpy
88 _GLOBAL(backwards_memcpy)
89         rlwinm. r7,r5,32-3,3,31         /* r0 = r5 >> 3 */
90         add     r6,r3,r5
91         add     r4,r4,r5
92         beq     2f
93         andi.   r0,r6,3
94         mtctr   r7
95         bne     5f
96         .balign 16
97 1:      lwz     r7,-4(r4)
98         lwzu    r8,-8(r4)
99         stw     r7,-4(r6)
100         stwu    r8,-8(r6)
101         bdnz    1b
102         andi.   r5,r5,7
103 2:      cmplwi  0,r5,4
104         blt     3f
105         lwzu    r0,-4(r4)
106         subi    r5,r5,4
107         stwu    r0,-4(r6)
108 3:      cmpwi   0,r5,0
109         beqlr
110         mtctr   r5
111 4:      lbzu    r0,-1(r4)
112         stbu    r0,-1(r6)
113         bdnz    4b
114         blr
115 5:      mtctr   r0
116 6:      lbzu    r7,-1(r4)
117         stbu    r7,-1(r6)
118         bdnz    6b
119         subf    r5,r0,r5
120         rlwinm. r7,r5,32-3,3,31
121         beq     2b
122         mtctr   r7
123         b       1b
124 EXPORT_SYMBOL(memmove)