1/* MIPS3 __mpn_add_n -- Add two limb vectors of the same length > 0 and
2 * store sum in a third limb vector.
3 *
4 * Copyright (C) 1995-2022 Free Software Foundation, Inc.
5 *
6 * This file is part of the GNU MP Library.
7 *
8 * The GNU MP Library is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation; either version 2.1 of the License, or (at your
11 * option) any later version.
12 *
13 * The GNU MP Library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
16 * License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with the GNU MP Library.  If not, see
20 * <https://www.gnu.org/licenses/>.
21 */
22
23#include <sysdep.h>
24#include <sys/asm.h>
25
26/*
27 * INPUT PARAMETERS
28 * res_ptr	$4
29 * s1_ptr	$5
30 * s2_ptr	$6
31 * size		$7
32 */
33#ifdef __PIC__
34	.option pic2
35#endif
36ENTRY (__mpn_add_n)
37#ifdef __PIC__
38	SETUP_GP /* ??? unused */
39#endif
40	.set	noreorder
41	.set	nomacro
42
43	ld	$10,0($5)
44	ld	$11,0($6)
45
46	daddiu	$7,$7,-1
47	and	$9,$7,4-1	# number of limbs in first loop
48	beq	$9,$0,L(L0)	# if multiple of 4 limbs, skip first loop
49	move	$2,$0
50
51	dsubu	$7,$7,$9
52
53L(Loop0):	daddiu	$9,$9,-1
54	ld	$12,8($5)
55	daddu	$11,$11,$2
56	ld	$13,8($6)
57	sltu	$8,$11,$2
58	daddu	$11,$10,$11
59	sltu	$2,$11,$10
60	sd	$11,0($4)
61	or	$2,$2,$8
62
63	daddiu	$5,$5,8
64	daddiu	$6,$6,8
65	move	$10,$12
66	move	$11,$13
67	bne	$9,$0,L(Loop0)
68	daddiu	$4,$4,8
69
70L(L0):	beq	$7,$0,L(Lend)
71	nop
72
73L(Loop):	daddiu	$7,$7,-4
74
75	ld	$12,8($5)
76	daddu	$11,$11,$2
77	ld	$13,8($6)
78	sltu	$8,$11,$2
79	daddu	$11,$10,$11
80	sltu	$2,$11,$10
81	sd	$11,0($4)
82	or	$2,$2,$8
83
84	ld	$10,16($5)
85	daddu	$13,$13,$2
86	ld	$11,16($6)
87	sltu	$8,$13,$2
88	daddu	$13,$12,$13
89	sltu	$2,$13,$12
90	sd	$13,8($4)
91	or	$2,$2,$8
92
93	ld	$12,24($5)
94	daddu	$11,$11,$2
95	ld	$13,24($6)
96	sltu	$8,$11,$2
97	daddu	$11,$10,$11
98	sltu	$2,$11,$10
99	sd	$11,16($4)
100	or	$2,$2,$8
101
102	ld	$10,32($5)
103	daddu	$13,$13,$2
104	ld	$11,32($6)
105	sltu	$8,$13,$2
106	daddu	$13,$12,$13
107	sltu	$2,$13,$12
108	sd	$13,24($4)
109	or	$2,$2,$8
110
111	daddiu	$5,$5,32
112	daddiu	$6,$6,32
113
114	bne	$7,$0,L(Loop)
115	daddiu	$4,$4,32
116
117L(Lend):	daddu	$11,$11,$2
118	sltu	$8,$11,$2
119	daddu	$11,$10,$11
120	sltu	$2,$11,$10
121	sd	$11,0($4)
122	j	$31
123	or	$2,$2,$8
124
125END (__mpn_add_n)
126