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