# 2.11BSD#431 - /usr/src/lib/libc/pdp/gen/bcmp.s

##### Functions

    _bcmp             X

##### Macros

    N                 X

       1: /*
       2:  * Copyright (c) 1987 Regents of the University of California.
       3:  * All rights reserved.  The Berkeley software License Agreement
       4:  * specifies the terms and conditions for redistribution.
       5:  */
       6:
       7: #ifdef LIBC_SCCS
       8:         <@(#)bcmp.s	1.2 (Berkeley) 1/8/87\0>
       9:         .even
      10: #endif LIBC_SCCS
      11:
      12: #include "DEFS.h"
      13:
      14: /*
      15:  * bcmp(b1, b2, length)
      16:  *
      17:  * Compare length bytes starting at b1 and b2 - return 0 if equal, non zero
      18:  * otherwise.  Bcmp uses a cost analysis heuristic to determine if it's worth
      19:  * while to try for a word comparison.  If length > N, then try for a word
      20:  * comparison.  Bcmp will fail if N < 3.  8 is a good value for N:
      21:  *
      22:  *	Algorithm			Cost (in instructions)
      23:  *	byte loop			3 * length
      24:  *	word loop overhead [worst case]	12
      25:  *	word loop			1.5 * length
      26:  *
      27:  *	N * 3 > 12 + N * 1.5
      28:  *	N > 8
      29:  */
      30: #define N       8.
      31:
      32: ENTRY(bcmp)
      33:         mov     6(sp),r0        / if ((r0 = length) == 0)
      34:         beq     3f              /	return(length:r0)
      35:         mov     r2,-(sp)        / reserve a register for our use
      36:         mov     6(sp),r2        / r2 = b2
      37:         mov     4(sp),r1        / r1 = b1
      38:         cmp     r0,$N           / if (length > N)
      39:         bhi     4f              /	try words
      40:
      41: 1:      cmpb    (r1)+,(r2)+     / do  if (*b1++ != *b2++)
      42:         bne     2f              /	return(length:r0) {length != 0}
      43:         sob     r0,1b           / while (--length)
      44: 2:
      45:         mov     (sp)+,r2        / return(length:r0)
      46: 3:
      47:         rts     pc
      48:
      49: /*
      50:  * The length of the comparison justifies trying a word by word comparison.
      51:  * If b1 and b2 are of the same parity, we can do a word comparison by
      52:  * handling any leading and trailing odd bytes separately.
      53:  */
      54: 4:
      55:         bit     $1,r1           / if (b1&1 != b2&1)
      56:         beq     5f              /	do bytes
      57:         bit     $1,r2
      58:         beq     1b              / (b1 odd, b2 even - do bytes)
      59:         cmpb    (r1)+,(r2)+     / if (leading odd bytes equal)
      60:         bne     2b              /	return(non_zero::r0)
      61:         dec     r0              / else	onto word loop
      62:         br      6f
      63: 5:
      64:         bit     $1,r2
      65:         bne     1b              / (b1 even, b2 odd - do bytes)
      66: 6:
      67:         mov     r0,-(sp)        / save trailing byte indicator
      68:         asr     r0              / length >>= 1 (unsigned)
      69:         bic     $0100000,r0     / (length is now in remaining words to compare)
      70: 7:
      71:         cmp     (r1)+,(r2)+     / do  if (*(short *)b1++ != *(short *)b2++)
      72:         bne     9f              /       return(length:r0) {length != 0}
      73:         sob     r0,7b           / while (--length)
      74: 8:
      75:         mov     (sp)+,r0        / if (no odd trailing byte)
      76:         bic     $!1,r0
      77:         beq     2b              /	return(0)
      78:         cmpb    (r1)+,(r2)+     / if (trailing odd bytes different)
      79:         bne     2b              /	return(non-zero)
      80:         clr     r0              / else	return(0)
      81:         br      2b
      82: 9:
      83:         mov     (sp)+,r0        / bad compare in word loop,
      84:         br      2b              / return(non-zero)

#### Defined functions

_bcmp defined in line 32; used 73 times

- in /usr/src/bin/ar/archive.c line 101, 165
- in /usr/src/bin/cmp.c line 147
- in /usr/src/bin/ld/ld.c line 2082
- in /usr/src/bin/make/files.c line 534
- in /usr/src/bin/nm/nm.c line 346
- in /usr/src/bin/od.c line 324
- in /usr/src/bin/ping/ping.c line 594
- in /usr/src/bin/sh/name.c line 86
- in /usr/src/lib/libc/gen/ndbm.c line 373
- in /usr/src/lib/libc/net/hosttable/gethnamadr.c line 137
- in /usr/src/lib/libc/net/named/gethnamadr.c line 397
- in /usr/src/libexec/acctd/acctd.c line 330, 340, 350, 364
- in /usr/src/libexec/popper/pop_init.c line 148
- in /usr/src/libexec/rlogind/rlogind.c line 183, 189
- in /usr/src/libexec/rshd/rshd.c line 252, 266
- in /usr/src/new/PORT/hexdump/display.c line 221, 244
- in /usr/src/new/crash/route.c line 354-356(2)
- in /usr/src/sbin/fsck/dir.c line 273
- in /usr/src/sbin/fsck/pass1.c line 42, 76
- in /usr/src/sbin/route/route.c line 551-553(2)
- in /usr/src/sbin/routed/defs.h line 39
- in /usr/src/sbin/routed/if.c line 28
- in /usr/src/sbin/routed/tools/query.c line 190
- in /usr/src/sys/net/if.c line 91, 243
- in /usr/src/sys/net/raw_usrreq.c line 114
- in /usr/src/sys/net/route.c line 64, 134
- in /usr/src/sys/netinet/if_ether.c line 310-313(2)
- in /usr/src/sys/pdpif/if_de.c line 595, 1135, 1141-1145(2)
- in /usr/src/sys/pdpif/if_ec.c line 498, 522-525(2)
- in /usr/src/sys/pdpif/if_il.c line 288
- in /usr/src/sys/pdpif/if_qe.c line 598, 608
- in /usr/src/sys/pdpif/if_qt.c line 627, 637
- in /usr/src/sys/sys/ingreslock.c line 41
- in /usr/src/sys/sys/tty.c line 559
- in /usr/src/sys/sys/ufs_namei.c line 260, 479
- in /usr/src/sys/sys/ufs_syscalls.c line 828
- in /usr/src/ucb/indent/indent.c line 1025
- in /usr/src/ucb/netstat/route.c line 320-322(2)
- in /usr/src/ucb/rlogin.c line 358, 370
- in /usr/src/ucb/tset/tset.c line 963
- in /usr/src/usr.sbin/mkhosts/mkhosts.c line 238
- in /usr/src/usr.sbin/named/named/db_update.c line 320, 354
- in /usr/src/usr.sbin/named/named/ns_forw.c line 72-76(3), 231
- in /usr/src/usr.sbin/named/named/ns_req.c line 443
- in /usr/src/usr.sbin/named/named/ns_resp.c line 144, 1170

#### Defined macros

N defined in line 30; used 1 times

- in line 38

Last modified: 1987-02-11 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 1110 |