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> |
Al Viro | d3867f04 | 2016-01-16 21:39:30 -0500 | [diff] [blame] | 10 | #include <asm/export.h> |
David S. Miller | ae984d7 | 2008-12-09 01:07:09 -0800 | [diff] [blame] | 11 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #define LO_MAGIC 0x01010101 |
| 13 | #define HI_MAGIC 0x80808080 |
| 14 | |
David S. Miller | ae984d7 | 2008-12-09 01:07:09 -0800 | [diff] [blame] | 15 | .text |
| 16 | ENTRY(strlen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | mov %o0, %o1 |
| 18 | andcc %o0, 3, %g0 |
David S. Miller | ae984d7 | 2008-12-09 01:07:09 -0800 | [diff] [blame] | 19 | BRANCH32(be, pt, 9f) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | sethi %hi(HI_MAGIC), %o4 |
| 21 | ldub [%o0], %o5 |
David S. Miller | ae984d7 | 2008-12-09 01:07:09 -0800 | [diff] [blame] | 22 | BRANCH_REG_ZERO(pn, %o5, 11f) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | add %o0, 1, %o0 |
| 24 | andcc %o0, 3, %g0 |
David S. Miller | ae984d7 | 2008-12-09 01:07:09 -0800 | [diff] [blame] | 25 | BRANCH32(be, pn, 4f) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | or %o4, %lo(HI_MAGIC), %o3 |
| 27 | ldub [%o0], %o5 |
David S. Miller | ae984d7 | 2008-12-09 01:07:09 -0800 | [diff] [blame] | 28 | BRANCH_REG_ZERO(pn, %o5, 12f) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | add %o0, 1, %o0 |
| 30 | andcc %o0, 3, %g0 |
David S. Miller | ae984d7 | 2008-12-09 01:07:09 -0800 | [diff] [blame] | 31 | BRANCH32(be, pt, 5f) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | sethi %hi(LO_MAGIC), %o4 |
| 33 | ldub [%o0], %o5 |
David S. Miller | ae984d7 | 2008-12-09 01:07:09 -0800 | [diff] [blame] | 34 | BRANCH_REG_ZERO(pn, %o5, 13f) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | add %o0, 1, %o0 |
David S. Miller | ae984d7 | 2008-12-09 01:07:09 -0800 | [diff] [blame] | 36 | BRANCH32(ba, pt, 8f) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | or %o4, %lo(LO_MAGIC), %o2 |
| 38 | 9: |
| 39 | or %o4, %lo(HI_MAGIC), %o3 |
| 40 | 4: |
| 41 | sethi %hi(LO_MAGIC), %o4 |
| 42 | 5: |
| 43 | or %o4, %lo(LO_MAGIC), %o2 |
| 44 | 8: |
| 45 | ld [%o0], %o5 |
| 46 | 2: |
| 47 | sub %o5, %o2, %o4 |
| 48 | andcc %o4, %o3, %g0 |
David S. Miller | ae984d7 | 2008-12-09 01:07:09 -0800 | [diff] [blame] | 49 | BRANCH32(be, pt, 8b) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | add %o0, 4, %o0 |
| 51 | |
| 52 | /* Check every byte. */ |
| 53 | srl %o5, 24, %g7 |
| 54 | andcc %g7, 0xff, %g0 |
David S. Miller | ae984d7 | 2008-12-09 01:07:09 -0800 | [diff] [blame] | 55 | BRANCH32(be, pn, 1f) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | add %o0, -4, %o4 |
| 57 | srl %o5, 16, %g7 |
| 58 | andcc %g7, 0xff, %g0 |
David S. Miller | ae984d7 | 2008-12-09 01:07:09 -0800 | [diff] [blame] | 59 | BRANCH32(be, pn, 1f) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | add %o4, 1, %o4 |
| 61 | srl %o5, 8, %g7 |
| 62 | andcc %g7, 0xff, %g0 |
David S. Miller | ae984d7 | 2008-12-09 01:07:09 -0800 | [diff] [blame] | 63 | BRANCH32(be, pn, 1f) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | add %o4, 1, %o4 |
| 65 | andcc %o5, 0xff, %g0 |
David S. Miller | ae984d7 | 2008-12-09 01:07:09 -0800 | [diff] [blame] | 66 | BRANCH32_ANNUL(bne, pt, 2b) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | ld [%o0], %o5 |
| 68 | add %o4, 1, %o4 |
| 69 | 1: |
| 70 | retl |
| 71 | sub %o4, %o1, %o0 |
| 72 | 11: |
| 73 | retl |
| 74 | mov 0, %o0 |
| 75 | 12: |
| 76 | retl |
| 77 | mov 1, %o0 |
| 78 | 13: |
| 79 | retl |
| 80 | mov 2, %o0 |
David S. Miller | ae984d7 | 2008-12-09 01:07:09 -0800 | [diff] [blame] | 81 | ENDPROC(strlen) |
Al Viro | d3867f04 | 2016-01-16 21:39:30 -0500 | [diff] [blame] | 82 | EXPORT_SYMBOL(strlen) |