1 ; mc88100 __gmpn_mul_1 -- Multiply a limb vector with a single limb and
2 ; store the product in a second limb vector.
4 ; Copyright 1992, 1994, 1995, 2000 Free Software Foundation, Inc.
6 ; This file is part of the GNU MP Library.
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 3 of the License, or (at your
11 ; option) any later version.
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.
18 ; You should have received a copy of the GNU Lesser General Public License
19 ; along with the GNU MP Library. If not, see http://www.gnu.org/licenses/.
28 ; Common overhead is about 11 cycles/invocation.
30 ; The speed for S2_LIMB >= 0x10000 is approximately 21 cycles/limb. (The
31 ; pipeline stalls 2 cycles due to WB contention.)
33 ; The speed for S2_LIMB < 0x10000 is approximately 16 cycles/limb. (The
34 ; pipeline stalls 2 cycles due to WB contention and 1 cycle due to latency.)
37 ; 1. Unroll main loop 4-8 times.
38 ; 2. Schedule code to avoid WB contention. It might be tempting to move the
39 ; ld instruction in the loops down to save 2 cycles (less WB contention),
40 ; but that looses because the ultimate value will be read from outside
41 ; the allocated space. But if we handle the ultimate multiplication in
42 ; the tail, we can do this.
43 ; 3. Make the multiplication with less instructions. I think the code for
44 ; (S2_LIMB >= 0x10000) is not minimal.
45 ; With these techniques the (S2_LIMB >= 0x10000) case would run in 17 or
46 ; less cycles/limb; the (S2_LIMB < 0x10000) case would run in 11
47 ; cycles/limb. (Assuming infinite unrolling.)
54 ; Make S1_PTR and RES_PTR point at the end of their blocks
57 lda r6,r2[r4] ; RES_PTR in r6 since r2 is retval
60 addu.co r2,r0,r0 ; r2 = cy = 0
62 mask r7,r5,0xffff ; r7 = lo(S2_LIMB)
63 extu r8,r5,16 ; r8 = hi(S2_LIMB)
64 bcnd.n eq0,r8,Lsmall ; jump if (hi(S2_LIMB) == 0)
67 ; General code for any value of S2_LIMB.
69 ; Make a stack frame and save r25 and r26
73 ; Enter the loop in the middle
79 ; bcnd ne0,r0,0 ; bubble
81 L1: mul r26,r9,r5 ; low word of product mul_1 WB ld
82 mask r12,r9,0xffff ; r12 = lo(s1_limb) mask_1
83 mul r11,r12,r7 ; r11 = prod_0 mul_2 WB mask_1
84 mul r10,r12,r8 ; r10 = prod_1a mul_3
85 extu r13,r9,16 ; r13 = hi(s1_limb) extu_1 WB mul_1
86 mul r12,r13,r7 ; r12 = prod_1b mul_4 WB extu_1
87 mul r25,r13,r8 ; r25 = prod_2 mul_5 WB mul_2
88 extu r11,r11,16 ; r11 = hi(prod_0) extu_2 WB mul_3
89 addu r10,r10,r11 ; addu_1 WB extu_2
90 ; bcnd ne0,r0,0 ; bubble WB addu_1
91 addu.co r10,r10,r12 ; WB mul_4
92 mask.u r10,r10,0xffff ; move the 16 most significant bits...
93 addu.ci r10,r10,r0 ; ...to the low half of the word...
94 rot r10,r10,16 ; ...and put carry in pos 16.
95 addu.co r26,r26,r2 ; add old carry limb
97 addu.ci r2,r25,r10 ; compute new carry limb
104 ; Fast code for S2_LIMB < 0x10000
106 ; Enter the loop in the middle
110 SLoop: ld r9,r3[r4] ;
113 SL1: mul r8,r9,r5 ; low word of product
114 mask r12,r9,0xffff ; r12 = lo(s1_limb)
115 extu r13,r9,16 ; r13 = hi(s1_limb)
116 mul r11,r12,r7 ; r11 = prod_0
117 mul r12,r13,r7 ; r12 = prod_1b
118 addu.cio r8,r8,r2 ; add old carry limb
119 extu r10,r11,16 ; r11 = hi(prod_0)
122 extu r2,r10,16 ; r2 = new carry limb