xref: /netbsd-src/common/lib/libc/arch/i386/string/ffs.S (revision 2c56941e163201dcb781df7fdeec6bd093647c91)
1/*
2 * Written by J.T. Conklin <jtc@NetBSD.org>.
3 * Public domain.
4 */
5
6#include <machine/asm.h>
7
8#if defined(LIBC_SCCS)
9	RCSID("$NetBSD: ffs.S,v 1.2 2014/03/22 19:38:46 jakllsch Exp $")
10#endif
11
12ENTRY(ffs)
13	bsfl	4(%esp),%eax
14	jz	L1	 		/* ZF is set if all bits are 0 */
15	incl	%eax			/* bits numbered from 1, not 0 */
16	ret
17
18	_ALIGN_TEXT
19L1:	xorl	%eax,%eax		/* clear result */
20	ret
21END(ffs)
22