1/* strlen.S: Sparc 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 Jakub Jelinek (jj@sunsite.mff.cuni.cz) 6 */ 7 8#define LO_MAGIC 0x01010101 9#define HI_MAGIC 0x80808080 10 110: 12 ldub [%o0], %o5 13 cmp %o5, 0 14 be 1f 15 add %o0, 1, %o0 16 andcc %o0, 3, %g0 17 be 4f 18 or %o4, %lo(HI_MAGIC), %o3 19 ldub [%o0], %o5 20 cmp %o5, 0 21 be 2f 22 add %o0, 1, %o0 23 andcc %o0, 3, %g0 24 be 5f 25 sethi %hi(LO_MAGIC), %o4 26 ldub [%o0], %o5 27 cmp %o5, 0 28 be 3f 29 add %o0, 1, %o0 30 b 8f 31 or %o4, %lo(LO_MAGIC), %o2 321: 33 retl 34 mov 0, %o0 352: 36 retl 37 mov 1, %o0 383: 39 retl 40 mov 2, %o0 41 42 .align 4 43 .global strlen 44strlen: 45 mov %o0, %o1 46 andcc %o0, 3, %g0 47 bne 0b 48 sethi %hi(HI_MAGIC), %o4 49 or %o4, %lo(HI_MAGIC), %o3 504: 51 sethi %hi(LO_MAGIC), %o4 525: 53 or %o4, %lo(LO_MAGIC), %o2 548: 55 ld [%o0], %o5 562: 57 sub %o5, %o2, %o4 58 andcc %o4, %o3, %g0 59 be 8b 60 add %o0, 4, %o0 61 62 /* Check every byte. */ 63 srl %o5, 24, %g5 64 andcc %g5, 0xff, %g0 65 be 1f 66 add %o0, -4, %o4 67 srl %o5, 16, %g5 68 andcc %g5, 0xff, %g0 69 be 1f 70 add %o4, 1, %o4 71 srl %o5, 8, %g5 72 andcc %g5, 0xff, %g0 73 be 1f 74 add %o4, 1, %o4 75 andcc %o5, 0xff, %g0 76 bne,a 2b 77 ld [%o0], %o5 78 add %o4, 1, %o4 791: 80 retl 81 sub %o4, %o1, %o0 82