1 dnl Intel Pentium mpn_mul_2 -- mpn by 2-limb multiplication.
3 dnl Copyright 2001, 2002 Free Software Foundation, Inc.
5 dnl This file is part of the GNU MP Library.
7 dnl The GNU MP Library is free software; you can redistribute it and/or
8 dnl modify it under the terms of the GNU Lesser General Public License as
9 dnl published by the Free Software Foundation; either version 3 of the
10 dnl License, or (at your option) any later version.
12 dnl The GNU MP Library is distributed in the hope that it will be useful,
13 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
14 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 dnl Lesser General Public License for more details.
17 dnl You should have received a copy of the GNU Lesser General Public License
18 dnl along with the GNU MP Library. If not, see http://www.gnu.org/licenses/.
20 include(`../config.m4')
23 C P5: 24.0 cycles/limb
26 C mp_limb_t mpn_mul_2 (mp_ptr dst, mp_srcptr src, mp_size_t size,
29 C At 24 c/l this is only 2 cycles faster than a separate mul_1 and addmul_1,
30 C but has the advantage of making just one pass over the operands.
32 C There's not enough registers to use PARAM_MULT directly, so the multiplier
33 C limbs are transferred to local variables on the stack.
35 defframe(PARAM_MULT, 16)
36 defframe(PARAM_SIZE, 12)
37 defframe(PARAM_SRC, 8)
38 defframe(PARAM_DST, 4)
40 dnl re-use parameter space
41 define(VAR_MULT_LOW, `PARAM_SRC')
42 define(VAR_MULT_HIGH,`PARAM_DST')
49 pushl %esi FRAME_pushl()
50 pushl %edi FRAME_pushl()
58 movl 4(%eax), %edx C mult high
59 movl (%eax), %eax C mult low
61 movl %eax, VAR_MULT_LOW
62 movl %edx, VAR_MULT_HIGH
64 pushl %ebx FRAME_pushl()
65 pushl %ebp FRAME_pushl()
67 mull (%esi) C src[0] * mult[0]
69 movl %eax, %ebp C in case src==dst
70 movl (%esi), %eax C src[0]
72 movl %ebp, (%edi) C dst[0]
73 movl %edx, %ebx C initial low carry
75 xorl %ebp, %ebp C initial high carry
76 leal (%edi,%ecx,4), %edi C dst end
78 mull VAR_MULT_HIGH C src[0] * mult[1]
80 subl $2, %ecx C size-2
83 leal 8(%esi,%ecx,4), %esi C &src[size]
84 xorl $-1, %ecx C -(size-1)
91 C ecx counter, negative
95 C ebp high carry (0 or -1)
97 andl $1, %ebp C 1 or 0
102 movl (%esi,%ecx,4), %eax
106 addl %eax, %ebx C low carry
107 movl (%esi,%ecx,4), %eax
109 adcl %ebp, %edx C high carry
110 movl %ebx, (%edi,%ecx,4)
112 sbbl %ebp, %ebp C new high carry, -1 or 0
113 movl %edx, %ebx C new low carry
122 andl $1, %ebp C 1 or 0
127 movl %eax, (%edi) C store carry low
129 movl %edx, %eax C return carry high