1/* MIPS __mpn_mul_1 -- Multiply a limb vector with a single limb and
2store the product in a second limb vector.
3
4Copyright (C) 1995-2022 Free Software Foundation, Inc.
5
6This file is part of the GNU MP Library.
7
8The GNU MP Library is free software; you can redistribute it and/or modify
9it under the terms of the GNU Lesser General Public License as published by
10the Free Software Foundation; either version 2.1 of the License, or (at your
11option) any later version.
12
13The GNU MP Library is distributed in the hope that it will be useful, but
14WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
16License for more details.
17
18You should have received a copy of the GNU Lesser General Public License
19along with the GNU MP Library. If not, see
20<https://www.gnu.org/licenses/>. */
21
22#include <sysdep.h>
23
24/* INPUT PARAMETERS
25 res_ptr $4
26 s1_ptr $5
27 size $6
28 s2_limb $7
29*/
30#ifdef __PIC__
31 .option pic2
32#endif
33ENTRY (__mpn_mul_1)
34 .set noreorder
35#ifdef __PIC__
36 .cpload t9
37#endif
38 .set nomacro
39
40 /* warm up phase 0 */
41 lw $8,0($5)
42
43 /* warm up phase 1 */
44 addiu $5,$5,4
45#if __mips_isa_rev < 6
46 multu $8,$7
47#else
48 mulu $11,$8,$7
49 muhu $12,$8,$7
50#endif
51
52 addiu $6,$6,-1
53 beq $6,$0,L(LC0)
54 move $2,$0 /* zero cy2 */
55
56 addiu $6,$6,-1
57 beq $6,$0,L(LC1)
58 lw $8,0($5) /* load new s1 limb as early as possible */
59
60
61#if __mips_isa_rev < 6
62L(Loop): mflo $10
63 mfhi $9
64#else
65L(Loop): move $10,$11
66 move $9,$12
67#endif
68 addiu $5,$5,4
69 addu $10,$10,$2 /* add old carry limb to low product limb */
70#if __mips_isa_rev < 6
71 multu $8,$7
72#else
73 mulu $11,$8,$7
74 muhu $12,$8,$7
75#endif
76 lw $8,0($5) /* load new s1 limb as early as possible */
77 addiu $6,$6,-1 /* decrement loop counter */
78 sltu $2,$10,$2 /* carry from previous addition -> $2 */
79 sw $10,0($4)
80 addiu $4,$4,4
81 bne $6,$0,L(Loop) /* should be "bnel" */
82 addu $2,$9,$2 /* add high product limb and carry from addition */
83
84 /* cool down phase 1 */
85#if __mips_isa_rev < 6
86L(LC1): mflo $10
87 mfhi $9
88#else
89L(LC1): move $10,$11
90 move $9,$12
91#endif
92 addu $10,$10,$2
93 sltu $2,$10,$2
94#if __mips_isa_rev < 6
95 multu $8,$7
96#else
97 mulu $11,$8,$7
98 muhu $12,$8,$7
99#endif
100 sw $10,0($4)
101 addiu $4,$4,4
102 addu $2,$9,$2 /* add high product limb and carry from addition */
103
104 /* cool down phase 0 */
105#if __mips_isa_rev < 6
106L(LC0): mflo $10
107 mfhi $9
108#else
109L(LC0): move $10,$11
110 move $9,$12
111#endif
112 addu $10,$10,$2
113 sltu $2,$10,$2
114 sw $10,0($4)
115 j $31
116 addu $2,$9,$2 /* add high product limb and carry from addition */
117 END (__mpn_mul_1)
118

source code of glibc/sysdeps/mips/mul_1.S