xref: /openbsd-src/lib/libc/arch/i386/string/ffs.S (revision b2ea75c1b17e1a9a339660e7ed45cd24946b230e)
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	.text
10	.asciz "$OpenBSD: ffs.S,v 1.2 1996/08/19 08:12:58 tholo Exp $"
11#endif
12
13ENTRY(ffs)
14	bsfl	4(%esp),%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 2
20L1:	xorl	%eax,%eax		/* clear result */
21	ret
22