1/* MIPS3 __mpn_mul_1 -- Multiply a limb vector with a single limb and
2 * store the product in a second limb vector.
3 *
4 * Copyright (C) 1992-2021 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/* INPUT PARAMETERS
27 * res_ptr	$4
28 * s1_ptr	$5
29 * size		$6
30 * s2_limb	$7
31 */
32
33#ifdef __PIC__
34	.option pic2
35#endif
36ENTRY (__mpn_mul_1)
37#ifdef __PIC__
38	SETUP_GP /* ??? unused */
39#endif
40	.set    noreorder
41	.set    nomacro
42
43 # warm up phase 0
44	ld	$8,0($5)
45
46 # warm up phase 1
47	daddiu	$5,$5,8
48#if __mips_isa_rev < 6
49	dmultu	$8,$7
50#else
51	dmulu	$11,$8,$7
52	dmuhu	$12,$8,$7
53#endif
54
55	daddiu	$6,$6,-1
56	beq	$6,$0,L(LC0)
57	move	$2,$0		# zero cy2
58
59	daddiu	$6,$6,-1
60	beq	$6,$0,L(LC1)
61	ld	$8,0($5)	# load new s1 limb as early as possible
62
63#if __mips_isa_rev < 6
64L(Loop):	mflo	$10
65	mfhi	$9
66#else
67L(Loop):	move	$10,$11
68		move	$9,$12
69#endif
70	daddiu	$5,$5,8
71	daddu	$10,$10,$2	# add old carry limb to low product limb
72#if __mips_isa_rev < 6
73	dmultu	$8,$7
74#else
75	dmulu	$11,$8,$7
76	dmuhu	$12,$8,$7
77#endif
78	ld	$8,0($5)	# load new s1 limb as early as possible
79	daddiu	$6,$6,-1	# decrement loop counter
80	sltu	$2,$10,$2	# carry from previous addition -> $2
81	sd	$10,0($4)
82	daddiu	$4,$4,8
83	bne	$6,$0,L(Loop)
84	daddu	$2,$9,$2	# add high product limb and carry from addition
85
86 # cool down phase 1
87#if __mips_isa_rev < 6
88L(LC1):	mflo	$10
89	mfhi	$9
90#else
91L(LC1):	move	$10,$11
92	move	$9,$12
93#endif
94	daddu	$10,$10,$2
95	sltu	$2,$10,$2
96#if __mips_isa_rev < 6
97	dmultu	$8,$7
98#else
99	dmulu	$11,$8,$7
100	dmuhu	$12,$8,$7
101#endif
102	sd	$10,0($4)
103	daddiu	$4,$4,8
104	daddu	$2,$9,$2	# add high product limb and carry from addition
105
106 # cool down phase 0
107#if  __mips_isa_rev < 6
108L(LC0):	mflo	$10
109	mfhi	$9
110#else
111L(LC0):	move	$10,$11
112	move	$9,$12
113#endif
114	daddu	$10,$10,$2
115	sltu	$2,$10,$2
116	sd	$10,0($4)
117	j	$31
118	daddu	$2,$9,$2	# add high product limb and carry from addition
119
120END (__mpn_mul_1)
121