blob: 2666bc49e9d578e8f540ca760b2f6c90fe05dfca [file] [log] [blame]
Elliott Hughes8ca530e2013-10-17 17:03:22 -07001/* $OpenBSD: ffs.S,v 1.1 2004/01/28 01:44:45 mickey 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 <machine/asm.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