Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* strlen_user.S: Sparc64 optimized strlen_user code |
| 2 | * |
| 3 | * Return length of string in userspace including terminating 0 |
| 4 | * or 0 for error |
| 5 | * |
| 6 | * Copyright (C) 1991,1996 Free Software Foundation |
| 7 | * Copyright (C) 1996,1999 David S. Miller (davem@redhat.com) |
| 8 | * Copyright (C) 1996,1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz) |
| 9 | */ |
| 10 | |
| 11 | #include <asm/asi.h> |
| 12 | |
| 13 | #define LO_MAGIC 0x01010101 |
| 14 | #define HI_MAGIC 0x80808080 |
| 15 | |
| 16 | .align 4 |
| 17 | .global __strlen_user, __strnlen_user |
| 18 | __strlen_user: |
| 19 | sethi %hi(32768), %o1 |
| 20 | __strnlen_user: |
| 21 | mov %o1, %g1 |
| 22 | mov %o0, %o1 |
| 23 | andcc %o0, 3, %g0 |
| 24 | be,pt %icc, 9f |
| 25 | sethi %hi(HI_MAGIC), %o4 |
| 26 | 10: lduba [%o0] %asi, %o5 |
| 27 | brz,pn %o5, 21f |
| 28 | add %o0, 1, %o0 |
| 29 | andcc %o0, 3, %g0 |
| 30 | be,pn %icc, 4f |
| 31 | or %o4, %lo(HI_MAGIC), %o3 |
| 32 | 11: lduba [%o0] %asi, %o5 |
| 33 | brz,pn %o5, 22f |
| 34 | add %o0, 1, %o0 |
| 35 | andcc %o0, 3, %g0 |
| 36 | be,pt %icc, 13f |
| 37 | srl %o3, 7, %o2 |
| 38 | 12: lduba [%o0] %asi, %o5 |
| 39 | brz,pn %o5, 23f |
| 40 | add %o0, 1, %o0 |
| 41 | ba,pt %icc, 2f |
| 42 | 15: lda [%o0] %asi, %o5 |
| 43 | 9: or %o4, %lo(HI_MAGIC), %o3 |
| 44 | 4: srl %o3, 7, %o2 |
| 45 | 13: lda [%o0] %asi, %o5 |
| 46 | 2: sub %o5, %o2, %o4 |
| 47 | andcc %o4, %o3, %g0 |
| 48 | bne,pn %icc, 82f |
| 49 | add %o0, 4, %o0 |
| 50 | sub %o0, %o1, %g2 |
| 51 | 81: cmp %g2, %g1 |
| 52 | blu,pt %icc, 13b |
| 53 | mov %o0, %o4 |
| 54 | ba,a,pt %xcc, 1f |
| 55 | |
| 56 | /* Check every byte. */ |
| 57 | 82: srl %o5, 24, %g7 |
| 58 | andcc %g7, 0xff, %g0 |
| 59 | be,pn %icc, 1f |
| 60 | add %o0, -3, %o4 |
| 61 | srl %o5, 16, %g7 |
| 62 | andcc %g7, 0xff, %g0 |
| 63 | be,pn %icc, 1f |
| 64 | add %o4, 1, %o4 |
| 65 | srl %o5, 8, %g7 |
| 66 | andcc %g7, 0xff, %g0 |
| 67 | be,pn %icc, 1f |
| 68 | add %o4, 1, %o4 |
| 69 | andcc %o5, 0xff, %g0 |
| 70 | bne,pt %icc, 81b |
| 71 | sub %o0, %o1, %g2 |
| 72 | add %o4, 1, %o4 |
| 73 | 1: retl |
| 74 | sub %o4, %o1, %o0 |
| 75 | 21: retl |
| 76 | mov 1, %o0 |
| 77 | 22: retl |
| 78 | mov 2, %o0 |
| 79 | 23: retl |
| 80 | mov 3, %o0 |
| 81 | |
| 82 | .section .fixup,#alloc,#execinstr |
| 83 | .align 4 |
| 84 | 30: |
| 85 | retl |
| 86 | clr %o0 |
| 87 | |
David S. Miller | 4d000d5 | 2006-03-04 23:23:56 -0800 | [diff] [blame] | 88 | .section __ex_table,"a" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | .align 4 |
| 90 | |
| 91 | .word 10b, 30b |
| 92 | .word 11b, 30b |
| 93 | .word 12b, 30b |
| 94 | .word 15b, 30b |
| 95 | .word 13b, 30b |