Annotation of researchv10no/libc/gen/memccpy.s, revision 1.1.1.1

1.1       root        1:        .file   "memccpy.s"
                      2: #      @(#)memccpy.s   1.5
                      3: # Fast assembler language version of the following C-program
                      4: #                      memccpy
                      5: # which represents the `standard' for the C-library.
                      6: 
                      7: # Copy s2 to s1, stopping if character c is copied. Copy no more than n bytes.
                      8: # Return a pointer to the byte after character c in the copy,
                      9: # or NULL if c is not found in the first n bytes.
                     10: 
                     11: #      char *
                     12: #      memccpy(s1, s2, c, n)
                     13: #      register char *s1, *s2;
                     14: #      register int c, n;
                     15: #      {
                     16: #              while (--n >= 0)
                     17: #                      if ((*s1++ = *s2++) == c)
                     18: #                              return (s1);
                     19: #              return (0);
                     20: #      }
                     21:        .globl  _memccpy
                     22:        .text
                     23:        .align  2
                     24: _memccpy:
                     25:        .word   0x00c0          # uses regs. 0,1,2,3,4,5,6,7
                     26:        movq    12(ap),r6       # escape char in r6, len in r7
                     27:        tstl    r7              # source length (arg `n')
                     28:        bleq    L2              # n <= 0, so return now!
                     29:        movq    4(ap),r3        # dest ptr in r3, src ptr in r4
                     30:        movl    r4,r1           # src ptr in r1 also
                     31: L0:
                     32:        cmpl    $65535,r7       # is max len VERY large?
                     33:        bgeq    L1              # hop if not
                     34:        locc    r6,$65535,(r1)  # look for escape char in src.
                     35:        bneq    L3              # found it
                     36:        movc3   $65535,(r4),(r3)        # copy all the chars
                     37:        movl    r1,r4           # updated src ptr
                     38:        subl2   $65535,r7
                     39:        jbr     L0              # go look at some more chars
                     40: L1:
                     41:        locc    r6,r7,(r1)      # look for escape char in src.
                     42:        bneq    L4              # found it
                     43:        movc3   r7,(r4),(r3)    # copy all the chars
                     44:        ret                     # done (r0 is now 0)
                     45: L2:
                     46:        clrl    r0              # char not found, return zero
                     47:        ret
                     48: L3:
                     49:        movl    $65535,r7       # len of BLOCK when len VERY large
                     50: L4:
                     51:        subl2   r0,r7           # number of bytes to escape char
                     52:        incl    r7              # move the escape char also
                     53:        movc3   r7,(r4),(r3)    # copy the chars
                     54:        movl    r3,r0           # we're done - return ptr to next dest char
                     55:        ret

unix.superglobalmegacorp.com

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