|
Packit |
6c4009 |
/* Optimized strcmp implementation for PowerPC.
|
|
Packit |
6c4009 |
Copyright (C) 1997-2018 Free Software Foundation, Inc.
|
|
Packit |
6c4009 |
This file is part of the GNU C Library.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit |
6c4009 |
modify it under the terms of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License as published by the Free Software Foundation; either
|
|
Packit |
6c4009 |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit |
6c4009 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6c4009 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6c4009 |
Lesser General Public License for more details.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License along with the GNU C Library; if not, see
|
|
Packit |
6c4009 |
<http://www.gnu.org/licenses/>. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <sysdep.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* See strlen.s for comments on how the end-of-string testing works. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* int [r3] strcmp (const char *s1 [r3], const char *s2 [r4]) */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
EALIGN (strcmp, 4, 0)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#define rTMP2 r0
|
|
Packit |
6c4009 |
#define rRTN r3
|
|
Packit |
6c4009 |
#define rSTR1 r3 /* first string arg */
|
|
Packit |
6c4009 |
#define rSTR2 r4 /* second string arg */
|
|
Packit |
6c4009 |
#define rWORD1 r5 /* current word in s1 */
|
|
Packit |
6c4009 |
#define rWORD2 r6 /* current word in s2 */
|
|
Packit |
6c4009 |
#define rFEFE r7 /* constant 0xfefefeff (-0x01010101) */
|
|
Packit |
6c4009 |
#define r7F7F r8 /* constant 0x7f7f7f7f */
|
|
Packit |
6c4009 |
#define rNEG r9 /* ~(word in s1 | 0x7f7f7f7f) */
|
|
Packit |
6c4009 |
#define rBITDIF r10 /* bits that differ in s1 & s2 words */
|
|
Packit |
6c4009 |
#define rTMP r11
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
or rTMP, rSTR2, rSTR1
|
|
Packit |
6c4009 |
clrlwi. rTMP, rTMP, 30
|
|
Packit |
6c4009 |
lis rFEFE, -0x101
|
|
Packit |
6c4009 |
bne L(unaligned)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
lwz rWORD1, 0(rSTR1)
|
|
Packit |
6c4009 |
lwz rWORD2, 0(rSTR2)
|
|
Packit |
6c4009 |
lis r7F7F, 0x7f7f
|
|
Packit |
6c4009 |
addi rFEFE, rFEFE, -0x101
|
|
Packit |
6c4009 |
addi r7F7F, r7F7F, 0x7f7f
|
|
Packit |
6c4009 |
b L(g1)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
L(g0): lwzu rWORD1, 4(rSTR1)
|
|
Packit |
6c4009 |
bne cr1, L(different)
|
|
Packit |
6c4009 |
lwzu rWORD2, 4(rSTR2)
|
|
Packit |
6c4009 |
L(g1): add rTMP, rFEFE, rWORD1
|
|
Packit |
6c4009 |
nor rNEG, r7F7F, rWORD1
|
|
Packit |
6c4009 |
and. rTMP, rTMP, rNEG
|
|
Packit |
6c4009 |
cmpw cr1, rWORD1, rWORD2
|
|
Packit |
6c4009 |
beq+ L(g0)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* OK. We've hit the end of the string. We need to be careful that
|
|
Packit |
6c4009 |
we don't compare two strings as different because of gunk beyond
|
|
Packit |
6c4009 |
the end of the strings... */
|
|
Packit |
6c4009 |
#ifdef __LITTLE_ENDIAN__
|
|
Packit |
6c4009 |
L(endstring):
|
|
Packit |
6c4009 |
addi rTMP2, rTMP, -1
|
|
Packit |
6c4009 |
andc rTMP2, rTMP2, rTMP
|
|
Packit |
6c4009 |
rlwimi rTMP2, rTMP2, 1, 0, 30
|
|
Packit |
6c4009 |
and rWORD2, rWORD2, rTMP2 /* Mask off gunk. */
|
|
Packit |
6c4009 |
and rWORD1, rWORD1, rTMP2
|
|
Packit |
6c4009 |
rlwinm rTMP2, rWORD2, 8, 0xffffffff /* Byte reverse word. */
|
|
Packit |
6c4009 |
rlwinm rTMP, rWORD1, 8, 0xffffffff
|
|
Packit |
6c4009 |
rlwimi rTMP2, rWORD2, 24, 0, 7
|
|
Packit |
6c4009 |
rlwimi rTMP, rWORD1, 24, 0, 7
|
|
Packit |
6c4009 |
rlwimi rTMP2, rWORD2, 24, 16, 23
|
|
Packit |
6c4009 |
rlwimi rTMP, rWORD1, 24, 16, 23
|
|
Packit |
6c4009 |
xor. rBITDIF, rTMP, rTMP2
|
|
Packit |
6c4009 |
sub rRTN, rTMP, rTMP2
|
|
Packit |
6c4009 |
bgelr+
|
|
Packit |
6c4009 |
ori rRTN, rTMP2, 1
|
|
Packit |
6c4009 |
blr
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
L(different):
|
|
Packit |
6c4009 |
lwz rWORD1, -4(rSTR1)
|
|
Packit |
6c4009 |
rlwinm rTMP2, rWORD2, 8, 0xffffffff /* Byte reverse word. */
|
|
Packit |
6c4009 |
rlwinm rTMP, rWORD1, 8, 0xffffffff
|
|
Packit |
6c4009 |
rlwimi rTMP2, rWORD2, 24, 0, 7
|
|
Packit |
6c4009 |
rlwimi rTMP, rWORD1, 24, 0, 7
|
|
Packit |
6c4009 |
rlwimi rTMP2, rWORD2, 24, 16, 23
|
|
Packit |
6c4009 |
rlwimi rTMP, rWORD1, 24, 16, 23
|
|
Packit |
6c4009 |
xor. rBITDIF, rTMP, rTMP2
|
|
Packit |
6c4009 |
sub rRTN, rTMP, rTMP2
|
|
Packit |
6c4009 |
bgelr+
|
|
Packit |
6c4009 |
ori rRTN, rTMP2, 1
|
|
Packit |
6c4009 |
blr
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#else
|
|
Packit |
6c4009 |
L(endstring):
|
|
Packit |
6c4009 |
and rTMP, r7F7F, rWORD1
|
|
Packit |
6c4009 |
beq cr1, L(equal)
|
|
Packit |
6c4009 |
add rTMP, rTMP, r7F7F
|
|
Packit |
6c4009 |
xor. rBITDIF, rWORD1, rWORD2
|
|
Packit |
6c4009 |
andc rNEG, rNEG, rTMP
|
|
Packit |
6c4009 |
blt- L(highbit)
|
|
Packit |
6c4009 |
cntlzw rBITDIF, rBITDIF
|
|
Packit |
6c4009 |
cntlzw rNEG, rNEG
|
|
Packit |
6c4009 |
addi rNEG, rNEG, 7
|
|
Packit |
6c4009 |
cmpw cr1, rNEG, rBITDIF
|
|
Packit |
6c4009 |
sub rRTN, rWORD1, rWORD2
|
|
Packit |
6c4009 |
bgelr+ cr1
|
|
Packit |
6c4009 |
L(equal):
|
|
Packit |
6c4009 |
li rRTN, 0
|
|
Packit |
6c4009 |
blr
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
L(different):
|
|
Packit |
6c4009 |
lwz rWORD1, -4(rSTR1)
|
|
Packit |
6c4009 |
xor. rBITDIF, rWORD1, rWORD2
|
|
Packit |
6c4009 |
sub rRTN, rWORD1, rWORD2
|
|
Packit |
6c4009 |
bgelr+
|
|
Packit |
6c4009 |
L(highbit):
|
|
Packit |
6c4009 |
ori rRTN, rWORD2, 1
|
|
Packit |
6c4009 |
blr
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Oh well. In this case, we just do a byte-by-byte comparison. */
|
|
Packit |
6c4009 |
.align 4
|
|
Packit |
6c4009 |
L(unaligned):
|
|
Packit |
6c4009 |
lbz rWORD1, 0(rSTR1)
|
|
Packit |
6c4009 |
lbz rWORD2, 0(rSTR2)
|
|
Packit |
6c4009 |
b L(u1)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
L(u0): lbzu rWORD1, 1(rSTR1)
|
|
Packit |
6c4009 |
bne- L(u4)
|
|
Packit |
6c4009 |
lbzu rWORD2, 1(rSTR2)
|
|
Packit |
6c4009 |
L(u1): cmpwi cr1, rWORD1, 0
|
|
Packit |
6c4009 |
beq- cr1, L(u3)
|
|
Packit |
6c4009 |
cmpw rWORD1, rWORD2
|
|
Packit |
6c4009 |
bne- L(u3)
|
|
Packit |
6c4009 |
lbzu rWORD1, 1(rSTR1)
|
|
Packit |
6c4009 |
lbzu rWORD2, 1(rSTR2)
|
|
Packit |
6c4009 |
cmpwi cr1, rWORD1, 0
|
|
Packit |
6c4009 |
cmpw rWORD1, rWORD2
|
|
Packit |
6c4009 |
bne+ cr1, L(u0)
|
|
Packit |
6c4009 |
L(u3): sub rRTN, rWORD1, rWORD2
|
|
Packit |
6c4009 |
blr
|
|
Packit |
6c4009 |
L(u4): lbz rWORD1, -1(rSTR1)
|
|
Packit |
6c4009 |
sub rRTN, rWORD1, rWORD2
|
|
Packit |
6c4009 |
blr
|
|
Packit |
6c4009 |
END (strcmp)
|
|
Packit |
6c4009 |
libc_hidden_builtin_def (strcmp)
|