Blame sysdeps/alpha/ffs.S

Packit 6c4009
/* Copyright (C) 1996-2018 Free Software Foundation, Inc.
Packit 6c4009
   Contributed by David Mosberger (davidm@cs.arizona.edu).
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library.  If not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
/* Finds the first bit set in an integer.  Optimized for the Alpha
Packit 6c4009
   architecture.  */
Packit 6c4009
Packit 6c4009
#include <sysdep.h>
Packit 6c4009
Packit 6c4009
	.set noreorder
Packit 6c4009
	.set noat
Packit 6c4009
Packit 6c4009
Packit 6c4009
ENTRY(__ffs)
Packit 6c4009
#ifdef PROF
Packit 6c4009
	ldgp	gp, 0(pv)
Packit 6c4009
	lda	AT, _mcount
Packit 6c4009
	jsr	AT, (AT), _mcount
Packit 6c4009
	.prologue 1
Packit 6c4009
	zap	$16, 0xF0, $16
Packit 6c4009
	br	$ffsl..ng
Packit 6c4009
#else
Packit 6c4009
	.prologue 0
Packit 6c4009
	zap	$16, 0xF0, $16
Packit 6c4009
	# FALLTHRU
Packit 6c4009
#endif
Packit 6c4009
END(__ffs)
Packit 6c4009
Packit 6c4009
	.align 4
Packit 6c4009
ENTRY(ffsl)
Packit 6c4009
#ifdef PROF
Packit 6c4009
	ldgp	gp, 0(pv)
Packit 6c4009
	lda	AT, _mcount
Packit 6c4009
	jsr	AT, (AT), _mcount
Packit 6c4009
	.prologue 1
Packit 6c4009
$ffsl..ng:
Packit 6c4009
#else
Packit 6c4009
	.prologue 0
Packit 6c4009
#endif
Packit 6c4009
	not	$16, $1		# e0    :
Packit 6c4009
	ldi	$2, -1		# .. e1 :
Packit 6c4009
	cmpbge	$1, $2, $3	# e0    : bit N == 1 for byte N == 0
Packit 6c4009
	clr	$0		# .. e1 :
Packit 6c4009
	addq	$3, 1, $4	# e0    :
Packit 6c4009
	bic	$4, $3, $3	# e1    : bit N == 1 for first byte N != 0
Packit 6c4009
	and	$3, 0xF0, $4	# e0    :
Packit 6c4009
	and	$3, 0xCC, $5	# .. e1 :
Packit 6c4009
	and	$3, 0xAA, $6	# e0    :
Packit 6c4009
	cmovne	$4, 4, $0	# .. e1 :
Packit 6c4009
	cmovne	$5, 2, $5	# e0    :
Packit 6c4009
	cmovne  $6, 1, $6	# .. e1 :
Packit 6c4009
	addl	$0, $5, $0	# e0    :
Packit 6c4009
	addl	$0, $6, $0	# e1    : $0 == N
Packit 6c4009
	extbl	$16, $0, $1	# e0    : $1 == byte N
Packit 6c4009
	ldi	$2, 1		# .. e1 :
Packit 6c4009
	negq	$1, $3		# e0    :
Packit 6c4009
	and	$3, $1, $3	# e1    : bit N == least bit set of byte N
Packit 6c4009
	and	$3, 0xF0, $4	# e0    :
Packit 6c4009
	and	$3, 0xCC, $5	# .. e1 :
Packit 6c4009
	and	$3, 0xAA, $6	# e0    :
Packit 6c4009
	cmovne	$4, 5, $2	# .. e1 :
Packit 6c4009
	cmovne	$5, 2, $5	# e0    :
Packit 6c4009
	cmovne	$6, 1, $6	# .. e1 :
Packit 6c4009
	s8addl	$0, $2, $0	# e0    : mult byte ofs by 8 and sum
Packit 6c4009
	addl	$5, $6, $5	# .. e1 :
Packit 6c4009
	addl	$0, $5, $0	# e0    :
Packit 6c4009
	nop			# .. e1 :
Packit 6c4009
	cmoveq	$16, 0, $0	# e0    : trap input == 0 case.
Packit 6c4009
	ret			# .. e1 : 18
Packit 6c4009
Packit 6c4009
END(ffsl)
Packit 6c4009
Packit 6c4009
weak_alias (__ffs, ffs)
Packit 6c4009
libc_hidden_def (__ffs)
Packit 6c4009
libc_hidden_builtin_def (ffs)
Packit 6c4009
weak_extern (ffsl)
Packit 6c4009
weak_alias (ffsl, ffsll)