]> asedeno.scripts.mit.edu Git - linux.git/blob - arch/powerpc/lib/string.S
5343a88e619e9d97f162d7cf8c6943d50fad38e9
[linux.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/ppc_asm.h>
12 #include <asm/export.h>
13 #include <asm/cache.h>
14
15         .text
16         
17 /* This clears out any unused part of the destination buffer,
18    just as the libc version does.  -- paulus */
19 _GLOBAL(strncpy)
20         PPC_LCMPI 0,r5,0
21         beqlr
22         mtctr   r5
23         addi    r6,r3,-1
24         addi    r4,r4,-1
25         .balign IFETCH_ALIGN_BYTES
26 1:      lbzu    r0,1(r4)
27         cmpwi   0,r0,0
28         stbu    r0,1(r6)
29         bdnzf   2,1b            /* dec ctr, branch if ctr != 0 && !cr0.eq */
30         bnelr                   /* if we didn't hit a null char, we're done */
31         mfctr   r5
32         PPC_LCMPI 0,r5,0        /* any space left in destination buffer? */
33         beqlr                   /* we know r0 == 0 here */
34 2:      stbu    r0,1(r6)        /* clear it out if so */
35         bdnz    2b
36         blr
37 EXPORT_SYMBOL(strncpy)
38
39 _GLOBAL(strncmp)
40         PPC_LCMPI 0,r5,0
41         beq-    2f
42         mtctr   r5
43         addi    r5,r3,-1
44         addi    r4,r4,-1
45         .balign IFETCH_ALIGN_BYTES
46 1:      lbzu    r3,1(r5)
47         cmpwi   1,r3,0
48         lbzu    r0,1(r4)
49         subf.   r3,r0,r3
50         beqlr   1
51         bdnzt   eq,1b
52         blr
53 2:      li      r3,0
54         blr
55 EXPORT_SYMBOL(strncmp)
56
57 #ifdef CONFIG_PPC32
58 _GLOBAL(memcmp)
59         PPC_LCMPI 0,r5,0
60         beq-    2f
61         mtctr   r5
62         addi    r6,r3,-1
63         addi    r4,r4,-1
64 1:      lbzu    r3,1(r6)
65         lbzu    r0,1(r4)
66         subf.   r3,r0,r3
67         bdnzt   2,1b
68         blr
69 2:      li      r3,0
70         blr
71 EXPORT_SYMBOL(memcmp)
72 #endif
73
74 _GLOBAL(memchr)
75         PPC_LCMPI 0,r5,0
76         beq-    2f
77         mtctr   r5
78         addi    r3,r3,-1
79         .balign IFETCH_ALIGN_BYTES
80 1:      lbzu    r0,1(r3)
81         cmpw    0,r0,r4
82         bdnzf   2,1b
83         beqlr
84 2:      li      r3,0
85         blr
86 EXPORT_SYMBOL(memchr)