Add Changelog ...
[glibc.git] / sysdeps / powerpc / powerpc32 / 405 / strcmp.S
blob9cd0e24f24604d4ad30a26e1c546454495c31768
1 /* Optimized strcmp implementation for PowerPC476.
2    Copyright (C) 2010 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
5    The GNU C Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
10    The GNU C Library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library.  If not, see
17    <http://www.gnu.org/licenses/>.  */
19 #include <sysdep.h>
20 #include <bp-sym.h>
21 #include <bp-asm.h>
23 /* strcmp
25        Register Use
26        r0:temp return equality
27        r3:source1 address, return equality
28        r4:source2 address
30        Implementation description
31        Check 2 words from src1 and src2. If unequal jump to end and
32        return src1 > src2 or src1 < src2.
33        If null check bytes before null and then jump to end and
34        return src1 > src2, src1 < src2 or src1 = src2.
35        If src1 = src2 and no null, repeat. */
37 EALIGN (BP_SYM(strcmp),5,0)
38        neg     r7,r3
39        clrlwi  r7,r7,20
40        neg     r8,r4
41        clrlwi  r8,r8,20
42        srwi.   r7,r7,5
43        beq     L(byte_loop)
44        srwi.   r8,r8,5
45        beq     L(byte_loop)
46        cmplw   r7,r8
47        mtctr   r7
48        ble     L(big_loop)
49        mtctr   r8
51 L(big_loop):
52        lwz     r5,0(r3)
53        lwz     r6,4(r3)
54        lwz     r8,0(r4)
55        lwz     r9,4(r4)
56        dlmzb.  r12,r5,r6
57        bne     L(end_check)
58        cmplw   r5,r8
59        bne     L(st1)
60        cmplw   r6,r9
61        bne     L(st1)
62        lwz     r5,8(r3)
63        lwz     r6,12(r3)
64        lwz     r8,8(r4)
65        lwz     r9,12(r4)
66        dlmzb.  r12,r5,r6
67        bne     L(end_check)
68        cmplw   r5,r8
69        bne     L(st1)
70        cmplw   r6,r9
71        bne     L(st1)
72        lwz     r5,16(r3)
73        lwz     r6,20(r3)
74        lwz     r8,16(r4)
75        lwz     r9,20(r4)
76        dlmzb.  r12,r5,r6
77        bne     L(end_check)
78        cmplw   r5,r8
79        bne     L(st1)
80        cmplw   r6,r9
81        bne     L(st1)
82        lwz     r5,24(r3)
83        lwz     r6,28(r3)
84        addi    r3,r3,0x20
85        lwz     r8,24(r4)
86        lwz     r9,28(r4)
87        addi    r4,r4,0x20
88        dlmzb.  r12,r5,r6
89        bne     L(end_check)
90        cmplw   r5,r8
91        bne     L(st1)
92        cmplw   r6,r9
93        bne     L(st1)
94        bdnz    L(big_loop)
95        b       L(byte_loop)
97 L(end_check):
98        subfic  r12,r12,4
99        blt     L(end_check2)
100        rlwinm  r12,r12,3,0,31
101        srw     r5,r5,r12
102        srw     r8,r8,r12
103        cmplw   r5,r8
104        bne     L(st1)
105        b       L(end_strcmp)
107 L(end_check2):
108        addi    r12,r12,4
109        cmplw   r5,r8
110        rlwinm  r12,r12,3,0,31
111        bne     L(st1)
112        srw     r6,r6,r12
113        srw     r9,r9,r12
114        cmplw   r6,r9
115        bne     L(st1)
117 L(end_strcmp):
118        addi    r3,r0,0
119        blr
121 L(st1):
122        mfcr    r3
123        blr
125 L(byte_loop):
126        lbz     r5,0(r3)
127        addi    r3,r3,1
128        lbz     r6,0(r4)
129        addi    r4,r4,1
130        cmplw   r5,r6
131        bne     L(st1)
132        cmpwi   r5,0
133        beq     L(end_strcmp)
134        b       L(byte_loop)
135 END (BP_SYM (strcmp))
136 libc_hidden_builtin_def (strcmp)