|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1980 Regents of the University of California. ! 3: * All rights reserved. ! 4: * ! 5: * Redistribution and use in source and binary forms are permitted ! 6: * provided that: (1) source distributions retain this entire copyright ! 7: * notice and comment, and (2) distributions including binaries display ! 8: * the following acknowledgement: ``This product includes software ! 9: * developed by the University of California, Berkeley and its contributors'' ! 10: * in the documentation or other materials provided with the distribution ! 11: * and in all advertising materials mentioning features or use of this ! 12: * software. Neither the name of the University nor the names of its ! 13: * contributors may be used to endorse or promote products derived ! 14: * from this software without specific prior written permission. ! 15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR ! 16: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED ! 17: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ! 18: */ ! 19: ! 20: #if defined(LIBC_SCCS) && !defined(lint) ! 21: .asciz "@(#)index.s 5.6 (Berkeley) 6/1/90" ! 22: #endif /* LIBC_SCCS and not lint */ ! 23: ! 24: /* ! 25: * Find the first occurence of c in the string cp. ! 26: * Return pointer to match or null pointer. ! 27: * ! 28: * char * ! 29: * index(cp, c) ! 30: * char *cp, c; ! 31: */ ! 32: #include "DEFS.h" ! 33: ! 34: ENTRY(index, 0) ! 35: movq 4(ap),r1 # r1 = cp; r2 = c ! 36: tstl r2 # check for special case c == '\0' ! 37: bneq 2f ! 38: 1: ! 39: locc $0,$65535,(r1) # just find end of string ! 40: beql 1b # still looking ! 41: movl r1,r0 # found it ! 42: ret ! 43: 2: ! 44: moval tbl,r3 # r3 = address of table ! 45: bbss $0,(r3),5f # insure not reentering ! 46: movab (r3)[r2],r5 # table entry for c ! 47: incb (r5) ! 48: movzwl $65535,r4 # fast access ! 49: 3: ! 50: scanc r4,(r1),(r3),$1 # look for c or '\0' ! 51: beql 3b # still looking ! 52: movl r1,r0 # return pointer to char ! 53: tstb (r0) # if have found '\0' ! 54: bneq 4f ! 55: clrl r0 # else return 0 ! 56: 4: ! 57: clrb (r5) # clean up table ! 58: clrb (r3) ! 59: ret ! 60: ! 61: .data ! 62: tbl: .space 256 ! 63: .text ! 64: ! 65: /* ! 66: * Reentrant, but slower version of index ! 67: */ ! 68: 5: ! 69: movl r1,r3 ! 70: 6: ! 71: locc $0,$65535,(r3) # look for '\0' ! 72: bneq 7f ! 73: locc r2,$65535,(r3) # look for c ! 74: bneq 8f ! 75: movl r1,r3 # reset pointer and ... ! 76: jbr 6b # ... try again ! 77: 7: ! 78: subl3 r3,r1,r4 # length of short block ! 79: incl r4 # +1 for '\0' ! 80: locc r2,r4,(r3) # look for c ! 81: bneq 8f ! 82: ret ! 83: 8: ! 84: movl r1,r0 # return pointer to char ! 85: ret
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.