Merge branch 'topic/hdac-hdmi' of git://git.kernel.org/pub/scm/linux/kernel/git/broon...
[linux-2.6-microblaze.git] / arch / powerpc / lib / string.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         .text
17         
18 /* This clears out any unused part of the destination buffer,
19    just as the libc version does.  -- paulus */
20 _GLOBAL(strncpy)
21         PPC_LCMPI 0,r5,0
22         beqlr
23         mtctr   r5
24         addi    r6,r3,-1
25         addi    r4,r4,-1
26         .balign 16
27 1:      lbzu    r0,1(r4)
28         cmpwi   0,r0,0
29         stbu    r0,1(r6)
30         bdnzf   2,1b            /* dec ctr, branch if ctr != 0 && !cr0.eq */
31         bnelr                   /* if we didn't hit a null char, we're done */
32         mfctr   r5
33         PPC_LCMPI 0,r5,0        /* any space left in destination buffer? */
34         beqlr                   /* we know r0 == 0 here */
35 2:      stbu    r0,1(r6)        /* clear it out if so */
36         bdnz    2b
37         blr
38 EXPORT_SYMBOL(strncpy)
39
40 _GLOBAL(strncmp)
41         PPC_LCMPI 0,r5,0
42         beq-    2f
43         mtctr   r5
44         addi    r5,r3,-1
45         addi    r4,r4,-1
46         .balign 16
47 1:      lbzu    r3,1(r5)
48         cmpwi   1,r3,0
49         lbzu    r0,1(r4)
50         subf.   r3,r0,r3
51         beqlr   1
52         bdnzt   eq,1b
53         blr
54 2:      li      r3,0
55         blr
56 EXPORT_SYMBOL(strncmp)
57
58 #ifdef CONFIG_PPC32
59 _GLOBAL(memcmp)
60         PPC_LCMPI 0,r5,0
61         beq-    2f
62         mtctr   r5
63         addi    r6,r3,-1
64         addi    r4,r4,-1
65 1:      lbzu    r3,1(r6)
66         lbzu    r0,1(r4)
67         subf.   r3,r0,r3
68         bdnzt   2,1b
69         blr
70 2:      li      r3,0
71         blr
72 EXPORT_SYMBOL(memcmp)
73 #endif
74
75 _GLOBAL(memchr)
76         PPC_LCMPI 0,r5,0
77         beq-    2f
78         mtctr   r5
79         addi    r3,r3,-1
80         .balign 16
81 1:      lbzu    r0,1(r3)
82         cmpw    0,r0,r4
83         bdnzf   2,1b
84         beqlr
85 2:      li      r3,0
86         blr
87 EXPORT_SYMBOL(memchr)
88
89 #ifdef CONFIG_PPC32
90 _GLOBAL(__clear_user)
91         addi    r6,r3,-4
92         li      r3,0
93         li      r5,0
94         cmplwi  0,r4,4
95         blt     7f
96         /* clear a single word */
97 11:     stwu    r5,4(r6)
98         beqlr
99         /* clear word sized chunks */
100         andi.   r0,r6,3
101         add     r4,r0,r4
102         subf    r6,r0,r6
103         srwi    r0,r4,2
104         andi.   r4,r4,3
105         mtctr   r0
106         bdz     7f
107 1:      stwu    r5,4(r6)
108         bdnz    1b
109         /* clear byte sized chunks */
110 7:      cmpwi   0,r4,0
111         beqlr
112         mtctr   r4
113         addi    r6,r6,3
114 8:      stbu    r5,1(r6)
115         bdnz    8b
116         blr
117 90:     mr      r3,r4
118         blr
119 91:     mfctr   r3
120         slwi    r3,r3,2
121         add     r3,r3,r4
122         blr
123 92:     mfctr   r3
124         blr
125
126         EX_TABLE(11b, 90b)
127         EX_TABLE(1b, 91b)
128         EX_TABLE(8b, 92b)
129
130 EXPORT_SYMBOL(__clear_user)
131 #endif