Annotation of 43BSDTahoe/lib/libc/gen/gen.vax/index.s, revision 1.1.1.1

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 the above copyright notice and this paragraph are
                      7:  * duplicated in all such forms and that any documentation,
                      8:  * advertising materials, and other materials related to such
                      9:  * distribution and use acknowledge that the software was developed
                     10:  * by the University of California, Berkeley.  The name of the
                     11:  * University may not be used to endorse or promote products derived
                     12:  * from this software without specific prior written permission.
                     13:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
                     14:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
                     15:  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
                     16:  */
                     17: 
                     18: #if defined(LIBC_SCCS) && !defined(lint)
                     19:        .asciz "@(#)index.s     5.5 (Berkeley) 6/27/88"
                     20: #endif /* LIBC_SCCS and not lint */
                     21: 
                     22: /*
                     23:  * Find the first occurence of c in the string cp.
                     24:  * Return pointer to match or null pointer.
                     25:  *
                     26:  * char *
                     27:  * index(cp, c)
                     28:  *     char *cp, c;
                     29:  */
                     30: #include "DEFS.h"
                     31: 
                     32: ENTRY(index, 0)
                     33:        movq    4(ap),r1        # r1 = cp; r2 = c
                     34:        tstl    r2              # check for special case c == '\0'
                     35:        bneq    2f
                     36: 1:
                     37:        locc    $0,$65535,(r1)  # just find end of string
                     38:        beql    1b              # still looking
                     39:        movl    r1,r0           # found it
                     40:        ret
                     41: 2:
                     42:        moval   tbl,r3          # r3 = address of table
                     43:        bbss    $0,(r3),5f      # insure not reentering
                     44:        movab   (r3)[r2],r5     # table entry for c
                     45:        incb    (r5)
                     46:        movzwl  $65535,r4       # fast access
                     47: 3:
                     48:        scanc   r4,(r1),(r3),$1 # look for c or '\0'
                     49:        beql    3b              # still looking
                     50:        movl    r1,r0           # return pointer to char
                     51:        tstb    (r0)            #    if have found '\0'
                     52:        bneq    4f
                     53:        clrl    r0              # else return 0
                     54: 4:
                     55:        clrb    (r5)            # clean up table
                     56:        clrb    (r3)
                     57:        ret
                     58: 
                     59:        .data
                     60: tbl:   .space  256
                     61:        .text
                     62: 
                     63: /*
                     64:  * Reentrant, but slower version of index
                     65:  */
                     66: 5:
                     67:        movl    r1,r3
                     68: 6:
                     69:        locc    $0,$65535,(r3)  # look for '\0'
                     70:        bneq    7f
                     71:        locc    r2,$65535,(r3)  # look for c
                     72:        bneq    8f
                     73:        movl    r1,r3           # reset pointer and ...
                     74:        jbr     6b              # ... try again
                     75: 7:
                     76:        subl3   r3,r1,r4        # length of short block
                     77:        incl    r4              # +1 for '\0'
                     78:        locc    r2,r4,(r3)      # look for c
                     79:        bneq    8f
                     80:        ret
                     81: 8:
                     82:        movl    r1,r0           # return pointer to char
                     83:        ret

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.