xref: /netbsd-src/common/lib/libc/arch/x86_64/string/ffs.S (revision c8da0e5fefd3800856b306200a18b2315c7fbb9f)
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.1 2005/12/20 19:28:51 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