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:         <@(#)ffs.s	1.2 (Berkeley) 1/8/87\0>
   9:         .even
  10: #endif LIBC_SCCS
  11: 
  12: #include "DEFS.h"
  13: 
  14: /*
  15:  * ffs(mask)
  16:  *	long	mask;
  17:  *
  18:  * Return index of lowest order bit set in mask (counting from the right
  19:  * starting at 1), or zero if mask is zero.  Ffs(m) is essentiallty
  20:  * log2(m)+1 with a 0 error return.
  21:  */
  22: ENTRY(ffs)
  23:         clr     r0              / cnt:r0 = 0
  24:         mov     4(sp),r1        / if ((imask = loint(mask)) != 0)
  25:         bne     1f
  26:         mov     2(sp),r1        / if ((imask = hiint(mask)) == 0)
  27:         beq     2f
  28:         mov     $16.,r0         / else  cnt = 16
  29: 1:
  30:         inc     r0              / do { cnt++
  31:         asr     r1              / 	imask >>= 1
  32:         bcc     1b              / } while (!wasodd(imask))
  33: 2:
  34:         rts     pc              / return(cnt:r0)
Last modified: 1987-02-05
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 619
Valid CSS Valid XHTML 1.0 Strict