1/* MIPS3 __mpn_addmul_1 -- Multiply a limb vector with a single limb and
2 * add the product to a second limb vector.
3 *
4 * Copyright (C) 1992-2024 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 <https://www.gnu.org/licenses/>.
20 */
21
22#include <sysdep.h>
23#include <sys/asm.h>
24
25/* INPUT PARAMETERS
26 * res_ptr $4
27 * s1_ptr $5
28 * size $6
29 * s2_limb $7
30 */
31
32#ifdef PIC
33 .option pic2
34#endif
35ENTRY (__mpn_addmul_1)
36#ifdef PIC
37 SETUP_GP /* ??? unused */
38#endif
39 .set noreorder
40 .set nomacro
41
42 # warm up phase 0
43 ld $8,0($5)
44
45 # warm up phase 1
46 daddiu $5,$5,8
47#if __mips_isa_rev < 6
48 dmultu $8,$7
49#else
50 dmulu $11,$8,$7
51 dmuhu $12,$8,$7
52#endif
53
54 daddiu $6,$6,-1
55 beq $6,$0,L(LC0)
56 move $2,$0 # zero cy2
57
58 daddiu $6,$6,-1
59 beq $6,$0,L(LC1)
60 ld $8,0($5) # load new s1 limb as early as possible
61
62L(Loop): ld $10,0($4)
63#if __mips_isa_rev < 6
64 mflo $3
65 mfhi $9
66#else
67 move $3,$11
68 move $9,$12
69#endif
70 daddiu $5,$5,8
71 daddu $3,$3,$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,$3,$2 # carry from previous addition -> $2
81 daddu $3,$10,$3
82 sltu $10,$3,$10
83 daddu $2,$2,$10
84 sd $3,0($4)
85 daddiu $4,$4,8
86 bne $6,$0,L(Loop)
87 daddu $2,$9,$2 # add high product limb and carry from addition
88
89 # cool down phase 1
90L(LC1): ld $10,0($4)
91#if __mips_isa_rev < 6
92 mflo $3
93 mfhi $9
94#else
95 move $3,$11
96 move $9,$12
97#endif
98 daddu $3,$3,$2
99 sltu $2,$3,$2
100#if __mips_isa_rev < 6
101 dmultu $8,$7
102#else
103 dmulu $11,$8,$7
104 dmuhu $12,$8,$7
105#endif
106 daddu $3,$10,$3
107 sltu $10,$3,$10
108 daddu $2,$2,$10
109 sd $3,0($4)
110 daddiu $4,$4,8
111 daddu $2,$9,$2 # add high product limb and carry from addition
112
113 # cool down phase 0
114L(LC0): ld $10,0($4)
115#if __mips_isa_rev < 6
116 mflo $3
117 mfhi $9
118#else
119 move $3,$11
120 move $9,$12
121#endif
122 daddu $3,$3,$2
123 sltu $2,$3,$2
124 daddu $3,$10,$3
125 sltu $10,$3,$10
126 daddu $2,$2,$10
127 sd $3,0($4)
128 j $31
129 daddu $2,$9,$2 # add high product limb and carry from addition
130
131END (__mpn_addmul_1)
132

source code of glibc/sysdeps/mips/mips64/addmul_1.S