xref: /netbsd-src/common/lib/libc/arch/i386/string/ffs.S (revision 2c56941e163201dcb781df7fdeec6bd093647c91)
137c9f0a6Schristos/*
237c9f0a6Schristos * Written by J.T. Conklin <jtc@NetBSD.org>.
337c9f0a6Schristos * Public domain.
437c9f0a6Schristos */
537c9f0a6Schristos
637c9f0a6Schristos#include <machine/asm.h>
737c9f0a6Schristos
837c9f0a6Schristos#if defined(LIBC_SCCS)
9*2c56941eSjakllsch	RCSID("$NetBSD: ffs.S,v 1.2 2014/03/22 19:38:46 jakllsch Exp $")
1037c9f0a6Schristos#endif
1137c9f0a6Schristos
1237c9f0a6SchristosENTRY(ffs)
1337c9f0a6Schristos	bsfl	4(%esp),%eax
1437c9f0a6Schristos	jz	L1	 		/* ZF is set if all bits are 0 */
1537c9f0a6Schristos	incl	%eax			/* bits numbered from 1, not 0 */
1637c9f0a6Schristos	ret
1737c9f0a6Schristos
1837c9f0a6Schristos	_ALIGN_TEXT
1937c9f0a6SchristosL1:	xorl	%eax,%eax		/* clear result */
2037c9f0a6Schristos	ret
21*2c56941eSjakllschEND(ffs)
22