beta-0.89.2
[luatex.git] / source / libs / gmp / gmp-src / mpn / x86 / k6 / mode1o.asm
blob4a338bd7bada42aa9052c14f406da8966fb7617f
1 dnl AMD K6 mpn_modexact_1_odd -- exact division style remainder.
3 dnl Copyright 2000-2003, 2007 Free Software Foundation, Inc.
5 dnl This file is part of the GNU MP Library.
6 dnl
7 dnl The GNU MP Library is free software; you can redistribute it and/or modify
8 dnl it under the terms of either:
9 dnl
10 dnl * the GNU Lesser General Public License as published by the Free
11 dnl Software Foundation; either version 3 of the License, or (at your
12 dnl option) any later version.
13 dnl
14 dnl or
15 dnl
16 dnl * the GNU General Public License as published by the Free Software
17 dnl Foundation; either version 2 of the License, or (at your option) any
18 dnl later version.
19 dnl
20 dnl or both in parallel, as here.
21 dnl
22 dnl The GNU MP Library is distributed in the hope that it will be useful, but
23 dnl WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
24 dnl or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25 dnl for more details.
26 dnl
27 dnl You should have received copies of the GNU General Public License and the
28 dnl GNU Lesser General Public License along with the GNU MP Library. If not,
29 dnl see https://www.gnu.org/licenses/.
31 include(`../config.m4')
34 C K6: 10.0 cycles/limb
37 C mp_limb_t mpn_modexact_1_odd (mp_srcptr src, mp_size_t size,
38 C mp_limb_t divisor);
39 C mp_limb_t mpn_modexact_1c_odd (mp_srcptr src, mp_size_t size,
40 C mp_limb_t divisor, mp_limb_t carry);
42 C A special case for high<divisor at the end measured only about 4 cycles
43 C faster, and so isn't used.
45 C A special case for size==1 using a divl rather than the inverse measured
46 C only about 5 cycles faster, and so isn't used. When size==1 and
47 C high<divisor it can skip a division and be a full 24 cycles faster, but
48 C this isn't an important case.
50 defframe(PARAM_CARRY, 16)
51 defframe(PARAM_DIVISOR,12)
52 defframe(PARAM_SIZE, 8)
53 defframe(PARAM_SRC, 4)
55 TEXT
57 ALIGN(32)
58 PROLOGUE(mpn_modexact_1c_odd)
59 deflit(`FRAME',0)
61 movl PARAM_DIVISOR, %ecx
62 pushl %esi FRAME_pushl()
64 movl PARAM_CARRY, %edx
65 jmp L(start_1c)
67 EPILOGUE()
70 ALIGN(16)
71 PROLOGUE(mpn_modexact_1_odd)
72 deflit(`FRAME',0)
74 movl PARAM_DIVISOR, %ecx
75 pushl %esi FRAME_pushl()
77 xorl %edx, %edx
78 L(start_1c):
79 pushl %edi FRAME_pushl()
81 shrl %ecx C d/2
82 movl PARAM_DIVISOR, %esi
84 andl $127, %ecx C d/2, 7 bits
85 pushl %ebp FRAME_pushl()
87 ifdef(`PIC',`
88 LEA( binvert_limb_table, %edi)
89 Zdisp( movzbl, 0,(%ecx,%edi), %edi) C inv 8 bits
90 ',`
91 movzbl binvert_limb_table(%ecx), %edi C inv 8 bits
93 leal (%edi,%edi), %ecx C 2*inv
95 imull %edi, %edi C inv*inv
97 movl PARAM_SRC, %eax
98 movl PARAM_SIZE, %ebp
100 imull %esi, %edi C inv*inv*d
102 pushl %ebx FRAME_pushl()
103 leal (%eax,%ebp,4), %ebx C src end
105 subl %edi, %ecx C inv = 2*inv - inv*inv*d
106 leal (%ecx,%ecx), %edi C 2*inv
108 imull %ecx, %ecx C inv*inv
110 movl (%eax), %eax C src low limb
111 negl %ebp C -size
113 imull %esi, %ecx C inv*inv*d
115 subl %ecx, %edi C inv = 2*inv - inv*inv*d
117 ASSERT(e,` C d*inv == 1 mod 2^GMP_LIMB_BITS
118 pushl %eax
119 movl %esi, %eax
120 imull %edi, %eax
121 cmpl $1, %eax
122 popl %eax')
124 jmp L(entry)
127 C Rotating the mul to the top of the loop saves 1 cycle, presumably by
128 C hiding the loop control under the imul latency.
130 C The run time is 10 cycles, but decoding is only 9 (and the dependent chain
131 C only 8). It's not clear how to get down to 9 cycles.
133 C The xor and rcl to handle the carry bit could be an sbb instead, with the
134 C the carry bit add becoming a sub, but that doesn't save anything.
136 L(top):
137 C eax (low product)
138 C ebx src end
139 C ecx carry bit, 0 or 1
140 C edx (high product, being carry limb)
141 C esi divisor
142 C edi inverse
143 C ebp counter, limbs, negative
145 mull %esi
147 movl (%ebx,%ebp,4), %eax
148 addl %ecx, %edx C apply carry bit to carry limb
150 L(entry):
151 xorl %ecx, %ecx
152 subl %edx, %eax C apply carry limb
154 rcll %ecx
156 imull %edi, %eax
158 incl %ebp
159 jnz L(top)
163 popl %ebx
164 popl %ebp
166 mull %esi
168 popl %edi
169 popl %esi
171 leal (%ecx,%edx), %eax
175 EPILOGUE()
176 ASM_END()