3 dnl Based on the K7 gcd_1.asm
, by Kevin Ryde. Rehacked for SPARC by Torbjörn
6 dnl Copyright
2000-2002, 2005, 2009, 2011-2013 Free Software Foundation
, Inc.
8 dnl
This file is part of the GNU MP Library.
10 dnl The GNU MP Library is free software
; you can redistribute it and/or modify
11 dnl it under the terms of
either:
13 dnl
* the GNU Lesser General
Public License as published by the Free
14 dnl Software Foundation
; either version 3 of the License, or (at your
15 dnl option
) any later version.
19 dnl
* the GNU General
Public License as published by the Free Software
20 dnl Foundation
; either version 2 of the License, or (at your option) any
23 dnl
or both
in parallel
, as here.
25 dnl The GNU MP Library is distributed
in the hope that it will be useful
, but
26 dnl WITHOUT ANY WARRANTY
; without even the implied warranty of MERCHANTABILITY
27 dnl
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
Public License
30 dnl You should have received copies of the GNU General
Public License
and the
31 dnl GNU Lesser General
Public License along with the GNU MP Library. If
not,
32 dnl see
https://www.gnu.
org/licenses
/.
34 include(`..
/config.m4
')
43 C Numbers measured with: speed -CD -s32-64 -t32 mpn_gcd_1
45 C ctz_table[n] is the number of trailing zeros on n, or MAXSHIFT if n==0.
48 deflit(MASK, eval((m4_lshift(1,MAXSHIFT))-1))
51 TYPE(ctz_table,object)
55 ` .byte m4_count_trailing_zeros(i)
57 SIZE(ctz_table
,.
-ctz_table
)
59 C Threshold of when to
call bmod when U is one limb. Should be about
60 C
(time_in_cycles
(bmod_1
,1) + call_overhead
) / (cycles
/bit
).
61 define
(`BMOD_THRES_LOG2
', 14)
70 REGISTER(%g2,#scratch)
71 REGISTER(%g3,#scratch)
74 ldx [up+0], %g1 C U low limb
76 or v0, %g1, %g2 C x | y
86 bz,a %xcc, L(divide_strip_y)
89 cmp n, 1 C if n > 1 we need
90 bnz %xcc, L(bmod) C to call bmod_1
93 C Both U and V are single limbs, reduce with bmod if u0 >> v0.
94 srlx %g1, BMOD_THRES_LOG2, %g2
96 bleu %xcc, L(noreduce)
103 call mpn_modexact_1c_odd
108 LEA64(ctz_table, i5, g4)
115 sllx %o2, %o4, %o0 C CAUTION: v0 alias for o2
118 L(top): movcc %xcc, %l4, v0 C v = min(u,v)
119 movcc %xcc, %l2, %o0 C u = |v - u]
120 L(mid): ldub [%i5+%g3], %g5 C
121 brz,a,pn %g3, L(shift_alot) C
122 srlx %o0, MAXSHIFT, %o0
123 srlx %o0, %g5, %l4 C new u, odd
124 subcc v0, %l4, %l2 C v - u, set flags for branch and movcc
125 sub %l4, v0, %o0 C u - v
126 bnz,pt %xcc, L(top) C
127 and %l2, MASK, %g3 C extract low MAXSHIFT bits from (v-u)
130 sllx %o2, %o4, %o0 C CAUTION: v0 alias for o2