ffs.S revision 1.3
1/*
2 * Written by J.T. Conklin <jtc@NetBSD.org>.
3 * Public domain.
4 * Adapted for NetBSD/x86_64 by Frank van der Linden <fvdl@wasabisystems.com>
5 */
6
7#include <machine/asm.h>
8
9#if defined(LIBC_SCCS)
10	RCSID("$NetBSD: ffs.S,v 1.3 2009/07/19 23:45:29 christos Exp $")
11#endif
12
13ENTRY(ffs)
14	bsfl	%edi,%eax
15	jz	L1	 		/* ZF is set if all bits are 0 */
16	incl	%eax			/* bits numbered from 1, not 0 */
17	ret
18
19	_ALIGN_TEXT
20L1:	xorl	%eax,%eax		/* clear result */
21	ret
22