Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame^] | 1 | /* strlen.S: Sparc64 optimized strlen code |
| 2 | * Hand optimized from GNU libc's strlen |
| 3 | * Copyright (C) 1991,1996 Free Software Foundation |
| 4 | * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu) |
| 5 | * Copyright (C) 1996, 1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz) |
| 6 | */ |
| 7 | |
| 8 | #define LO_MAGIC 0x01010101 |
| 9 | #define HI_MAGIC 0x80808080 |
| 10 | |
| 11 | .align 32 |
| 12 | .globl strlen |
| 13 | .type strlen,#function |
| 14 | strlen: |
| 15 | mov %o0, %o1 |
| 16 | andcc %o0, 3, %g0 |
| 17 | be,pt %icc, 9f |
| 18 | sethi %hi(HI_MAGIC), %o4 |
| 19 | ldub [%o0], %o5 |
| 20 | brz,pn %o5, 11f |
| 21 | add %o0, 1, %o0 |
| 22 | andcc %o0, 3, %g0 |
| 23 | be,pn %icc, 4f |
| 24 | or %o4, %lo(HI_MAGIC), %o3 |
| 25 | ldub [%o0], %o5 |
| 26 | brz,pn %o5, 12f |
| 27 | add %o0, 1, %o0 |
| 28 | andcc %o0, 3, %g0 |
| 29 | be,pt %icc, 5f |
| 30 | sethi %hi(LO_MAGIC), %o4 |
| 31 | ldub [%o0], %o5 |
| 32 | brz,pn %o5, 13f |
| 33 | add %o0, 1, %o0 |
| 34 | ba,pt %icc, 8f |
| 35 | or %o4, %lo(LO_MAGIC), %o2 |
| 36 | 9: |
| 37 | or %o4, %lo(HI_MAGIC), %o3 |
| 38 | 4: |
| 39 | sethi %hi(LO_MAGIC), %o4 |
| 40 | 5: |
| 41 | or %o4, %lo(LO_MAGIC), %o2 |
| 42 | 8: |
| 43 | ld [%o0], %o5 |
| 44 | 2: |
| 45 | sub %o5, %o2, %o4 |
| 46 | andcc %o4, %o3, %g0 |
| 47 | be,pt %icc, 8b |
| 48 | add %o0, 4, %o0 |
| 49 | |
| 50 | /* Check every byte. */ |
| 51 | srl %o5, 24, %g7 |
| 52 | andcc %g7, 0xff, %g0 |
| 53 | be,pn %icc, 1f |
| 54 | add %o0, -4, %o4 |
| 55 | srl %o5, 16, %g7 |
| 56 | andcc %g7, 0xff, %g0 |
| 57 | be,pn %icc, 1f |
| 58 | add %o4, 1, %o4 |
| 59 | srl %o5, 8, %g7 |
| 60 | andcc %g7, 0xff, %g0 |
| 61 | be,pn %icc, 1f |
| 62 | add %o4, 1, %o4 |
| 63 | andcc %o5, 0xff, %g0 |
| 64 | bne,a,pt %icc, 2b |
| 65 | ld [%o0], %o5 |
| 66 | add %o4, 1, %o4 |
| 67 | 1: |
| 68 | retl |
| 69 | sub %o4, %o1, %o0 |
| 70 | 11: |
| 71 | retl |
| 72 | mov 0, %o0 |
| 73 | 12: |
| 74 | retl |
| 75 | mov 1, %o0 |
| 76 | 13: |
| 77 | retl |
| 78 | mov 2, %o0 |
| 79 | |
| 80 | .size strlen, .-strlen |