xref: /openbsd/lib/libc/arch/amd64/string/ffs.S (revision 5af055cd)
1/*	$OpenBSD: ffs.S,v 1.4 2015/11/14 21:53:03 guenther Exp $	*/
2/*
3 * Written by J.T. Conklin <jtc@netbsd.org>.
4 * Public domain.
5 * Adapted for NetBSD/x86_64 by Frank van der Linden <fvdl@wasabisystems.com>
6 */
7
8#include "DEFS.h"
9
10ENTRY(ffs)
11	bsfl	%edi,%eax
12	jz	L1	 		/* ZF is set if all bits are 0 */
13	incl	%eax			/* bits numbered from 1, not 0 */
14	ret
15
16	_ALIGN_TEXT
17L1:	xorl	%eax,%eax		/* clear result */
18	ret
19END_WEAK(ffs)
20