 # Sw_64  __mpn_rshift --

 # Copyright (C) 1994-2023 Free Software Foundation, Inc.

 # This file is part of the GNU MP Library.

 # The GNU MP Library is free software; you can redistribute it and/or modify
 # it under the terms of the GNU Lesser General Public License as published by
 # the Free Software Foundation; either version 2.1 of the License, or (at your
 # option) any later version.

 # The GNU MP 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 Lesser General Public
 # License for more details.

 # You should have received a copy of the GNU Lesser General Public License
 # along with the GNU MP Library.  If not, see <http://www.gnu.org/licenses/>.


 # INPUT PARAMETERS
 # res_ptr	r16
 # s1_ptr	r17
 # size		r18
 # cnt		r19

 # This code runs at 3.25 cycles/limb on the sw_64.

	.set	noreorder
	.set	noat
.text
	.align	3
	.globl	__mpn_rshift
	.ent	__mpn_rshift
__mpn_rshift:
	.frame	$30,0,$26,0

	ldl	$4,0($17)	# load first limb
	subl	$31,$19,$20
	subl	$18,1,$18
	and	$18,4-1,$28	# number of limbs in first loop
	sll	$4,$20,$0	# compute function result

	beq	$28,.L0
	subl	$18,$28,$18

	.align	3
.Loop0:	ldl	$3,8($17)
	addl	$16,8,$16
	srl	$4,$19,$5
	addl	$17,8,$17
	subl	$28,1,$28
	sll	$3,$20,$6
	or	$3,$3,$4
	or	$5,$6,$8
	stl	$8,-8($16)
	bne	$28,.Loop0

.L0:	srl	$4,$19,$24
	beq	$18,.Lend
 # warm up phase 1
	ldl	$1,8($17)
	subl	$18,4,$18
	ldl	$2,16($17)
	ldl	$3,24($17)
	ldl	$4,32($17)
	beq	$18,.Lend1
 # warm up phase 2
	sll	$1,$20,$7
	srl	$1,$19,$21
	sll	$2,$20,$8
	ldl	$1,40($17)
	srl	$2,$19,$22
	ldl	$2,48($17)
	sll	$3,$20,$5
	or	$7,$24,$7
	srl	$3,$19,$23
	or	$8,$21,$8
	sll	$4,$20,$6
	ldl	$3,56($17)
	srl	$4,$19,$24
	ldl	$4,64($17)
	subl	$18,4,$18
	beq	$18,.Lend2
	.align  4
 # main loop
.Loop:	stl	$7,0($16)
	or	$5,$22,$5
	stl	$8,8($16)
	or	$6,$23,$6

	sll	$1,$20,$7
	subl	$18,4,$18
	srl	$1,$19,$21
	unop	# ldl	$31,-96($17)

	sll	$2,$20,$8
	ldl	$1,72($17)
	srl	$2,$19,$22
	ldl	$2,80($17)

	stl	$5,16($16)
	or	$7,$24,$7
	stl	$6,24($16)
	or	$8,$21,$8

	sll	$3,$20,$5
	unop	# ldl	$31,-96($17)
	srl	$3,$19,$23
	addl	$16,32,$16

	sll	$4,$20,$6
	ldl	$3,88($17)
	srl	$4,$19,$24
	ldl	$4,96($17)

	addl	$17,32,$17
	bne	$18,.Loop
 # cool down phase 2/1
.Lend2:	stl	$7,0($16)
	or	$5,$22,$5
	stl	$8,8($16)
	or	$6,$23,$6
	sll	$1,$20,$7
	srl	$1,$19,$21
	sll	$2,$20,$8
	srl	$2,$19,$22
	stl	$5,16($16)
	or	$7,$24,$7
	stl	$6,24($16)
	or	$8,$21,$8
	sll	$3,$20,$5
	srl	$3,$19,$23
	sll	$4,$20,$6
	srl	$4,$19,$24
 # cool down phase 2/2
	stl	$7,32($16)
	or	$5,$22,$5
	stl	$8,40($16)
	or	$6,$23,$6
	stl	$5,48($16)
	stl	$6,56($16)
 # cool down phase 2/3
	stl	$24,64($16)
	ret	$31,($26),1

 # cool down phase 1/1
.Lend1:	sll	$1,$20,$7
	srl	$1,$19,$21
	sll	$2,$20,$8
	srl	$2,$19,$22
	sll	$3,$20,$5
	or	$7,$24,$7
	srl	$3,$19,$23
	or	$8,$21,$8
	sll	$4,$20,$6
	srl	$4,$19,$24
 # cool down phase 1/2
	stl	$7,0($16)
	or	$5,$22,$5
	stl	$8,8($16)
	or	$6,$23,$6
	stl	$5,16($16)
	stl	$6,24($16)
	stl	$24,32($16)
	ret	$31,($26),1

.Lend:	stl	$24,0($16)
	ret	$31,($26),1
	.end	__mpn_rshift
