 # Sw_64 __mpn_sub_n -- Subtract two limb vectors of the same length > 0 and
 # store difference in a third limb vector.

 # Copyright (C) 1995-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	$16
 # s1_ptr	$17
 # s2_ptr	$18
 # size		$19

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

	or	$31,$31,$25		# clear cy
	subl	$19,4,$19		# decr loop cnt
	blt	$19,.Lend2		# if less than 4 limbs, goto 2nd loop
 # Start software pipeline for 1st loop
	ldl	$0,0($18)
	ldl	$1,8($18)
	ldl	$4,0($17)
	ldl	$5,8($17)
	addl	$17,32,$17		# update s1_ptr
	ldl	$2,16($18)
	subl	$4,$0,$20		# 1st main sub
	ldl	$3,24($18)
	subl	$19,4,$19		# decr loop cnt
	ldl	$6,-16($17)
	cmpult	$4,$20,$25		# compute cy from last sub
	ldl	$7,-8($17)
	addl	$1,$25,$28		# cy add
	addl	$18,32,$18		# update s2_ptr
	subl	$5,$28,$21		# 2nd main sub
	cmpult	$28,$25,$8		# compute cy from last add
	blt	$19,.Lend1		# if less than 4 limbs remain, jump
 # 1st loop handles groups of 4 limbs in a software pipeline
	.align	4
.Loop:	cmpult	$5,$21,$25		# compute cy from last add
	ldl	$0,0($18)
	or	$8,$25,$25		# combine cy from the two fadds
	ldl	$1,8($18)
	addl	$2,$25,$28		# cy add
	ldl	$4,0($17)
	subl	$6,$28,$22		# 3rd main sub
	ldl	$5,8($17)
	cmpult	$28,$25,$8		# compute cy from last add
	cmpult	$6,$22,$25		# compute cy from last add
	stl	$20,0($16)
	or	$8,$25,$25		# combine cy from the two fadds
	stl	$21,8($16)
	addl	$3,$25,$28		# cy add
	subl	$7,$28,$23		# 4th main sub
	cmpult	$28,$25,$8		# compute cy from last add
	cmpult	$7,$23,$25		# compute cy from last add
	addl	$17,32,$17		# update s1_ptr
	or	$8,$25,$25		# combine cy from the two fadds
	addl	$16,32,$16		# update res_ptr
	addl	$0,$25,$28		# cy add
	ldl	$2,16($18)
	subl	$4,$28,$20		# 1st main sub
	ldl	$3,24($18)
	cmpult	$28,$25,$8		# compute cy from last add
	ldl	$6,-16($17)
	cmpult	$4,$20,$25		# compute cy from last add
	ldl	$7,-8($17)
	or	$8,$25,$25		# combine cy from the two fadds
	subl	$19,4,$19		# decr loop cnt
	stl	$22,-16($16)
	addl	$1,$25,$28		# cy add
	stl	$23,-8($16)
	subl	$5,$28,$21		# 2nd main sub
	addl	$18,32,$18		# update s2_ptr
	cmpult	$28,$25,$8		# compute cy from last add
	bge	$19,.Loop
 # Finish software pipeline for 1st loop
.Lend1:	cmpult	$5,$21,$25		# compute cy from last add
	or	$8,$25,$25		# combine cy from the two fadds
	addl	$2,$25,$28		# cy add
	subl	$6,$28,$22		# 3rd main sub
	cmpult	$28,$25,$8		# compute cy from last add
	cmpult	$6,$22,$25		# compute cy from last add
	stl	$20,0($16)
	or	$8,$25,$25		# combine cy from the two fadds
	stl	$21,8($16)
	addl	$3,$25,$28		# cy add
	subl	$7,$28,$23		# 4th main sub
	cmpult	$28,$25,$8		# compute cy from last add
	cmpult	$7,$23,$25		# compute cy from last add
	or	$8,$25,$25		# combine cy from the two fadds
	addl	$16,32,$16		# update res_ptr
	stl	$22,-16($16)
	stl	$23,-8($16)
.Lend2:	addl	$19,4,$19		# restore loop cnt
	beq	$19,.Lret
 # Start software pipeline for 2nd loop
	ldl	$0,0($18)
	ldl	$4,0($17)
	subl	$19,1,$19
	beq	$19,.Lend0
 # 2nd loop handles remaining 1-3 limbs
	.align	4
.Loop0:	addl	$0,$25,$28		# cy add
	ldl	$0,8($18)
	subl	$4,$28,$20		# main sub
	ldl	$1,8($17)
	addl	$18,8,$18
	cmpult	$28,$25,$8		# compute cy from last add
	addl	$17,8,$17
	stl	$20,0($16)
	cmpult	$4,$20,$25		# compute cy from last add
	subl	$19,1,$19		# decr loop cnt
	or	$8,$25,$25		# combine cy from the two fadds
	addl	$16,8,$16
	or	$1,$31,$4
	bne	$19,.Loop0
.Lend0:	addl	$0,$25,$28		# cy add
	subl	$4,$28,$20		# main sub
	cmpult	$28,$25,$8		# compute cy from last add
	cmpult	$4,$20,$25		# compute cy from last add
	stl	$20,0($16)
	or	$8,$25,$25		# combine cy from the two fadds

.Lret:	or	$25,$31,$0		# return cy
	ret	$31,($26),1
	.end	__mpn_sub_n
