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

1.1       root        1: /*
                      2:  * Copyright (c) 1983 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 "@(#)rindex.s    5.5 (Berkeley) 6/27/88"
                     20: #endif /* LIBC_SCCS and not lint */
                     21: 
                     22: /*
                     23:  * Find the last occurence of c in the string cp.
                     24:  * Return pointer to match or null pointer.
                     25:  *
                     26:  * char *
                     27:  * rindex(cp, c)
                     28:  *     char *cp, c;
                     29:  */
                     30: #include "DEFS.h"
                     31: 
                     32: ENTRY(rindex, 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:        clrl    r4              # last found
                     47: 3:
                     48:        scanc   $65535,(r1),(r3),$1     # look for c or '\0'
                     49:        beql    3b              # keep looking
                     50:        tstb    (r1)            # if have found '\0'
                     51:        beql    4f              #    we are done
                     52:        movl    r1,r4           # save most recently found
                     53:        incl    r1              # skip over character
                     54:        jbr     3b              # keep looking
                     55: 4:
                     56:        movl    r4,r0           # return last found (if any)
                     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 rindex
                     67:  */
                     68: 5:
                     69:        movl    r1,r3
                     70:        clrl    r4              # r4 = pointer to last match
                     71: 6:
                     72:        locc    $0,$65535,(r3)  # look for '\0'
                     73:        bneq    8f
                     74:        decw    r0              # r0 = 65535
                     75: 1:
                     76:        locc    r2,r0,(r3)      # look for c
                     77:        bneq    7f
                     78:        movl    r1,r3           # reset pointer and ...
                     79:        jbr     6b              # ... try again
                     80: 7:
                     81:        movl    r1,r4           # stash pointer ...
                     82:        addl3   $1,r1,r3        # ... skip over match and ...
                     83:        decl    r0              # ... decrement count
                     84:        jbr     6b              # ... try again
                     85: 8:
                     86:        subl3   r3,r1,r0        # length of short block
                     87:        incl    r0              # +1 for '\0'
                     88: 9:
                     89:        locc    r2,r0,(r3)      # look for c
                     90:        beql    0f
                     91:        movl    r1,r4           # stash pointer ...
                     92:        addl3   $1,r1,r3        # ... skip over match ...
                     93:        decl    r0              # ... adjust count and ...
                     94:        jbr     9b              # ... try again
                     95: 0:
                     96:        movl    r4,r0           # return stashed pointer
                     97:        ret

unix.superglobalmegacorp.com

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