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

1.1       root        1:        .file   "memchr.s"
                      2: #      @(#)memchr.s    1.5
                      3: # Fast assembler language version of the following C-program
                      4: #                      memchr
                      5: # which represents the `standard' for the C-library.
                      6: 
                      7: # Return the ptr in sp at which the character c appears;
                      8: #   NULL if not found in n chars; don't stop at \0.
                      9: #      
                     10: #      char *
                     11: #      memchr(sp, c, n)
                     12: #      register char *sp, c;
                     13: #      register int n;
                     14: #      {
                     15: #              while (--n >= 0)
                     16: #                      if (*sp++ == c)
                     17: #                              return (--sp);
                     18: #              return (0);
                     19: #      }
                     20:        .globl  _memchr
                     21:        .text
                     22:        .align  2
                     23: _memchr:
                     24:        .word   0x0000          # pgm uses regs 0,1,2,3
                     25:        movl    12(ap),r3       # n in r3
                     26:        bleq    L4              #       should be > 0
                     27:        movq    4(ap),r1        # s1 in r1; `c' in r2
                     28: L0:
                     29:        cmpl    $65535,r3       # is len VERY large?
                     30:        bgeq    L1              # hop if not
                     31:        locc    r2,$65535,(r1)  # look for `c' in this BLOCK
                     32:        bneq    L2              # hop if found (r1 points to it)
                     33:        subl2   $65535,r3
                     34:        jbr     L0
                     35: L1:
                     36:        locc    r2,r3,(r1)      # look for `c' in this BLOCK
                     37:        beql    L3              # fall through if found (r1 points to it)
                     38: L2:
                     39:        movl    r1,r0           # found one, return pointer to user
                     40: L3:
                     41:        ret                     # return 0 if not found (r0 is 0 already)
                     42: L4:
                     43:        clrl    r0              # n <= 0, return 0 (not found)
                     44:        ret

unix.superglobalmegacorp.com

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