From 1d280d9f1e4d4c889d8123663a81b49256cf6fd6 Mon Sep 17 00:00:00 2001 From: Greg McGary Date: Tue, 6 Jun 2000 22:37:40 +0000 Subject: * sysdeps/powerpc/memset.S: Define & use symbolic register names. Use C comments throughout. Line up operands column with tabs. * sysdeps/powerpc/strchr.S: Likewise. * sysdeps/powerpc/strcmp.S: Likewise. * sysdeps/powerpc/strcpy.S: Likewise. * sysdeps/powerpc/strlen.S: Likewise. * sysdeps/powerpc/memset.S: Define & use symbolic register names. Use C comments throughout. Line up operands column with tabs. * sysdeps/powerpc/strchr.S: Likewise. * sysdeps/powerpc/strcmp.S: Likewise. * sysdeps/powerpc/strcpy.S: Likewise. * sysdeps/powerpc/strlen.S: Likewise. --- sysdeps/powerpc/strchr.S | 138 ++++++++++++++++++++++++----------------------- 1 file changed, 71 insertions(+), 67 deletions(-) (limited to 'sysdeps/powerpc/strchr.S') diff --git a/sysdeps/powerpc/strchr.S b/sysdeps/powerpc/strchr.S index 5367a5a4fe..4662447179 100644 --- a/sysdeps/powerpc/strchr.S +++ b/sysdeps/powerpc/strchr.S @@ -1,5 +1,5 @@ /* Optimized strchr implementation for PowerPC. - Copyright (C) 1997, 1999 Free Software Foundation, Inc. + Copyright (C) 1997, 1999, 2000 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -21,91 +21,95 @@ /* See strlen.s for comments on how this works. */ -/* char * [r3] strchr (const char *s [r3] , int c [r4] ) +/* char * [r3] strchr (const char *s [r3] , int c [r4] ) */ - r0: a temporary - r3: our return result. - r4: byte we're looking for, spread over the whole word - r5: the current word - r6: the constant 0xfefefeff (-0x01010101) - r7: the constant 0x7f7f7f7f - r8: pointer to the current word. - r9: a temporary - r10: the number of bits we should ignore in the first word - r11: a mask with the bits to ignore set to 0 - r12: a temporary */ -ENTRY(strchr) - rlwimi r4,r4,8,16,23 - li r11,-1 - rlwimi r4,r4,16,0,15 - lis r6,0xfeff - lis r7,0x7f7f - clrrwi r8,r3,2 - addi r7,r7,0x7f7f - addi r6,r6,0xfffffeff - rlwinm r10,r3,3,27,28 +ENTRY (strchr) + +#define rTMP1 r0 +#define rRTN r3 /* outgoing result */ +#define rSTRin r3 /* incoming string arg */ +#define rCHR r4 /* byte we're looking for, spread over the whole word */ +#define rCLZB rCHR /* leading zero byte count */ +#define rWORD r5 /* the current word */ +#define rFEFE r6 /* constant 0xfefefeff (-0x01010101) */ +#define r7F7F r7 /* constant 0x7f7f7f7f */ +#define rSTR r8 /* current word pointer */ +#define rTMP2 r9 +#define rIGN r10 /* number of bits we should ignore in the first word */ +#define rMASK r11 /* mask with the bits to ignore set to 0 */ +#define rTMP3 r12 + + rlwimi rCHR, rCHR, 8, 16, 23 + li rMASK, -1 + rlwimi rCHR, rCHR, 16, 0, 15 + lis rFEFE, -0x101 + lis r7F7F, 0x7f7f + clrrwi rSTR, rSTRin, 2 + addi r7F7F, r7F7F, 0x7f7f + addi rFEFE, rFEFE, -0x101 + rlwinm rIGN, rSTRin, 3, 27, 28 /* Test the first (partial?) word. */ - lwz r5,0(r8) - srw r11,r11,r10 - orc r5,r5,r11 - add r0,r6,r5 - nor r9,r7,r5 - and. r0,r0,r9 - xor r12,r4,r5 - orc r12,r12,r11 - b L(loopentry) + lwz rWORD, 0(rSTR) + srw rMASK, rMASK, rIGN + orc rWORD, rWORD, rMASK + add rTMP1, rFEFE, rWORD + nor rTMP2, r7F7F, rWORD + and. rTMP1, rTMP1, rTMP2 + xor rTMP3, rCHR, rWORD + orc rTMP3, rTMP3, rMASK + b L(loopentry) /* The loop. */ -L(loop):lwzu r5,4(r8) - and. r0,r0,r9 -/* Test for 0. */ - add r0,r6,r5 - nor r9,r7,r5 - bne L(foundit) - and. r0,r0,r9 +L(loop):lwzu rWORD, 4(rSTR) + and. rTMP1, rTMP1, rTMP2 +/* Test for 0. */ + add rTMP1, rFEFE, rWORD + nor rTMP2, r7F7F, rWORD + bne L(foundit) + and. rTMP1, rTMP1, rTMP2 /* Start test for the bytes we're looking for. */ - xor r12,r4,r5 + xor rTMP3, rCHR, rWORD L(loopentry): - add r0,r6,r12 - nor r9,r7,r12 - beq L(loop) + add rTMP1, rFEFE, rTMP3 + nor rTMP2, r7F7F, rTMP3 + beq L(loop) /* There is a zero byte in the word, but may also be a matching byte (either before or after the zero byte). In fact, we may be looking for a zero byte, in which case we return a match. We guess that this hasn't happened, though. */ L(missed): - and. r0,r0,r9 - li r3,0 + and. rTMP1, rTMP1, rTMP2 + li rRTN, 0 beqlr /* It did happen. Decide which one was first... I'm not sure if this is actually faster than a sequence of rotates, compares, and branches (we use it anyway because it's shorter). */ - and r6,r7,r5 - or r11,r7,r5 - and r0,r7,r12 - or r10,r7,r12 - add r6,r6,r7 - add r0,r0,r7 - nor r5,r11,r6 - nor r9,r10,r0 - cmplw r5,r9 + and rFEFE, r7F7F, rWORD + or rMASK, r7F7F, rWORD + and rTMP1, r7F7F, rTMP3 + or rIGN, r7F7F, rTMP3 + add rFEFE, rFEFE, r7F7F + add rTMP1, rTMP1, r7F7F + nor rWORD, rMASK, rFEFE + nor rTMP2, rIGN, rTMP1 + cmplw rWORD, rTMP2 bgtlr - cntlzw r4,r9 - srwi r4,r4,3 - add r3,r8,r4 + cntlzw rCLZB, rTMP2 + srwi rCLZB, rCLZB, 3 + add rRTN, rSTR, rCLZB blr L(foundit): - and r0,r7,r12 - or r10,r7,r12 - add r0,r0,r7 - nor r9,r10,r0 - cntlzw r4,r9 - subi r8,r8,4 - srwi r4,r4,3 - add r3,r8,r4 + and rTMP1, r7F7F, rTMP3 + or rIGN, r7F7F, rTMP3 + add rTMP1, rTMP1, r7F7F + nor rTMP2, rIGN, rTMP1 + cntlzw rCLZB, rTMP2 + subi rSTR, rSTR, 4 + srwi rCLZB, rCLZB, 3 + add rRTN, rSTR, rCLZB blr -END(strchr) +END (strchr) -weak_alias(strchr,index) +weak_alias(strchr, index) -- cgit 1.4.1