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:         <@(#)bzero.s	1.2 (Berkeley) 8/21/87\0>
   9:         .even
  10: #endif LIBC_SCCS
  11: 
  12: #include "DEFS.h"
  13: 
  14: /*
  15:  * bzero(b, length)
  16:  *	caddr_t	b;
  17:  *	u_int	length;
  18:  *
  19:  * Zero length bytes starting at b.  Bzero uses a cost analysis heuristic to
  20:  * determine if it's worth while to try zeroing memory by words.  If length >
  21:  * N, then try for a word zero.  This routine will fail if N < 8.
  22:  * 8 is a good value for N:
  23:  *
  24:  *	Algorithm			Cost (in instructions)
  25:  *	byte loop			2 * length
  26:  *	word loop overhead [worst case]	11
  27:  *	word loop			0.625 * length
  28:  *
  29:  *	N * 2 > 11 + N * 0.625
  30:  *	N > 8
  31:  */
  32: #undef  N
  33: #define N       8.
  34: 
  35: ENTRY(bzero)
  36:         mov     4(sp),r0        / if ((r0 = length) == 0)
  37:         beq     2f              /	return
  38:         mov     2(sp),r1        / r1 = b
  39:         cmp     r0,$N           / if (length > N)
  40:         bhi     3f              /	do words
  41: 1:
  42:         clrb    (r1)+           / do  *b++ = 0
  43:         sob     r0,1b           / while (--length)
  44: 2:
  45:         rts     pc              / and return
  46: 
  47: /*
  48:  * The length of the zero justifies using a word loop, handling any leading
  49:  * and trailing odd bytes separately.
  50:  */
  51: 3:
  52:         bit     $1,r1           / if (odd leading byte)
  53:         beq     4f              / {	zero it
  54:         clrb    (r1)+           /	length--
  55:         dec     r0              / }
  56: 4:
  57:         mov     r0,-(sp)        / save trailing byte indicator
  58:         asr     r0              / length >>= 1 (unsigned)
  59:         bic     $0100000,r0     / (length is now in remaining words to zero)
  60:         asr     r0              / if (length >>= 1, wasodd(length))
  61:         bcc     5f              /	handle leading non multiple of four
  62:         clr     (r1)+
  63: 5:
  64:         asr     r0              / if (length >>= 1, wasodd(length))
  65:         bcc     6f              /	handle leading non multiple of eight
  66:         clr     (r1)+
  67:         clr     (r1)+
  68: 6:
  69:         clr     (r1)+           / do
  70:         clr     (r1)+           /	clear eight bytes
  71:         clr     (r1)+
  72:         clr     (r1)+
  73:         sob     r0,6b           / while (--length)
  74:         bit     $1,(sp)+        / if (odd trailing byte)
  75:         beq     7f
  76:         clrb    (r1)+           /	zero it
  77: 7:
  78:         rts     pc              / and return

Defined functions

_bzero defined in line 35; used 251 times

Defined macros

N defined in line 33; used 1 times
  • in line 39
Last modified: 1987-08-22
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 4143
Valid CSS Valid XHTML 1.0 Strict