glibc/sysdeps/alpha/ffs.S
Roland McGrath 56e70371a6 Wed May 29 00:57:37 1996 David Mosberger-Tang <davidm@azstarnet.com>
* sysdeps/alpha/_mcount.S, sysdeps/alpha/bb_init_func.S,
 	sysdeps/alpha/bsd-_setjmp.S, sysdeps/alpha/bsd-setjmp.S,
 	sysdeps/alpha/copysign.S, sysdeps/alpha/divrem.h,
 	sysdeps/alpha/fabs.S, sysdeps/alpha/ffs.S, sysdeps/alpha/htonl.S,
 	sysdeps/alpha/htons.S, sysdeps/alpha/memchr.S,
 	sysdeps/alpha/setjmp.S, sysdeps/alpha/strlen.S,
 	sysdeps/unix/sysv/linux/alpha/ieee_get_fp_control.S,
 	sysdeps/unix/sysv/linux/alpha/ieee_set_fp_control.S,
 	sysdeps/unix/sysv/linux/alpha/llseek.S,
 	sysdeps/unix/sysv/linux/alpha/pipe.S,
 	sysdeps/unix/sysv/linux/alpha/sigsuspend.S,
 	sysdeps/unix/sysv/linux/alpha/sysdep.S: Use END macro instead of
 	.end directive.
1996-06-02 18:49:21 +00:00

67 lines
1.7 KiB
ArmAsm

/* Copyright (C) 1996 Free Software Foundation, Inc.
Contributed by David Mosberger (davidm@cs.arizona.edu).
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
/* Finds the first bit set in an integer. Optimized for the Alpha
architecture. */
#include <sysdep.h>
.set noreorder
.set noat
ENTRY(ffs)
.prologue 0
ldq_u zero, 0(sp) # on the 21064, this helps dual-issuing
addl a0, zero, a0 # the last insn and reduces the stall
negq a0, t0 # due to the srl instruction
and a0, t0, t0
clr v0
beq a0, done
# now do binary search for first non-zero bit
zapnot t0, 0x03, t2
addq v0, 16, t3
cmoveq t2, t3, v0
zapnot t0, 0x05, t2
addq v0, 8, t3
cmoveq t2, t3, v0
srl t0, v0, t0
addq v0, 1, v0
and t0, 0x0f, t2
addq v0, 4, t3
cmoveq t2, t3, v0
and t0, 0x33, t2
addq v0, 2, t3
cmoveq t2, t3, v0
and t0, 0x55, t2
addq v0, 1, t3
cmoveq t2, t3, v0
done: ret
END(ffs)