~ubuntu-branches/ubuntu/quantal/gclcvs/quantal

« back to all changes in this revision

Viewing changes to gmp3/mpn/x86/k6/mode1o.asm

  • Committer: Bazaar Package Importer
  • Author(s): Camm Maguire
  • Date: 2004-06-24 15:13:46 UTC
  • Revision ID: james.westby@ubuntu.com-20040624151346-xh0xaaktyyp7aorc
Tags: 2.7.0-26
C_GC_OFFSET is 2 on m68k-linux

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
dnl  AMD K6 mpn_modexact_1_odd -- exact division style remainder.
 
2
dnl
 
3
dnl  K6: 10.0 cycles/limb
 
4
 
 
5
dnl  Copyright 2000, 2001 Free Software Foundation, Inc.
 
6
dnl 
 
7
dnl  This file is part of the GNU MP Library.
 
8
dnl 
 
9
dnl  The GNU MP Library is free software; you can redistribute it and/or
 
10
dnl  modify it under the terms of the GNU Lesser General Public License as
 
11
dnl  published by the Free Software Foundation; either version 2.1 of the
 
12
dnl  License, or (at your option) any later version.
 
13
dnl 
 
14
dnl  The GNU MP Library is distributed in the hope that it will be useful,
 
15
dnl  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
dnl  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
17
dnl  Lesser General Public License for more details.
 
18
dnl 
 
19
dnl  You should have received a copy of the GNU Lesser General Public
 
20
dnl  License along with the GNU MP Library; see the file COPYING.LIB.  If
 
21
dnl  not, write to the Free Software Foundation, Inc., 59 Temple Place -
 
22
dnl  Suite 330, Boston, MA 02111-1307, USA.
 
23
 
 
24
include(`../config.m4')
 
25
 
 
26
 
 
27
C mp_limb_t mpn_modexact_1_odd (mp_srcptr src, mp_size_t size,
 
28
C                               mp_limb_t divisor);
 
29
C mp_limb_t mpn_modexact_1c_odd (mp_srcptr src, mp_size_t size,
 
30
C                                mp_limb_t divisor, mp_limb_t carry);
 
31
C
 
32
C A special case for high<divisor at the end measured only about 4 cycles
 
33
C faster, and so isn't used.
 
34
C
 
35
C A special case for size==1 using a divl rather than the inverse measured
 
36
C only about 5 cycles faster, and so isn't used.  When size==1 and
 
37
C high<divisor it can skip a division and be a full 24 cycles faster, but
 
38
C this isn't an important case.
 
39
 
 
40
defframe(PARAM_CARRY,  16)
 
41
defframe(PARAM_DIVISOR,12)
 
42
defframe(PARAM_SIZE,   8)
 
43
defframe(PARAM_SRC,    4)
 
44
 
 
45
        TEXT
 
46
 
 
47
        ALIGN(32)
 
48
PROLOGUE(mpn_modexact_1c_odd)
 
49
deflit(`FRAME',0)
 
50
 
 
51
        movl    PARAM_DIVISOR, %ecx
 
52
        pushl   %esi            FRAME_pushl()
 
53
 
 
54
        movl    PARAM_CARRY, %edx
 
55
        jmp     LF(mpn_modexact_1_odd,start_1c)
 
56
 
 
57
ifdef(`PIC',`
 
58
L(movl_eip_edi):
 
59
        movl    (%esp), %edi
 
60
        ret
 
61
')
 
62
 
 
63
EPILOGUE()
 
64
 
 
65
 
 
66
        ALIGN(16)
 
67
PROLOGUE(mpn_modexact_1_odd)
 
68
deflit(`FRAME',0)
 
69
 
 
70
        movl    PARAM_DIVISOR, %ecx
 
71
        pushl   %esi            FRAME_pushl()
 
72
 
 
73
        xorl    %edx, %edx
 
74
L(start_1c):
 
75
        pushl   %edi            FRAME_pushl()
 
76
 
 
77
        shrl    %ecx                    C d/2
 
78
        movl    PARAM_DIVISOR, %esi
 
79
 
 
80
        andl    $127, %ecx              C d/2, 7 bits
 
81
        pushl   %ebp            FRAME_pushl()
 
82
 
 
83
ifdef(`PIC',`
 
84
        call    LF(mpn_modexact_1c_odd,movl_eip_edi)
 
85
 
 
86
        addl    $_GLOBAL_OFFSET_TABLE_, %edi
 
87
        C
 
88
        movl    modlimb_invert_table@GOT(%edi), %edi
 
89
        C
 
90
Zdisp(  movzbl, 0,(%ecx,%edi), %edi)                    C inv 8 bits
 
91
',`
 
92
 
 
93
dnl non-PIC
 
94
        movzbl  modlimb_invert_table(%ecx), %edi        C inv 8 bits
 
95
')
 
96
        leal    (%edi,%edi), %ecx       C 2*inv
 
97
 
 
98
        imull   %edi, %edi              C inv*inv
 
99
 
 
100
        movl    PARAM_SRC, %eax
 
101
        movl    PARAM_SIZE, %ebp
 
102
 
 
103
        imull   %esi, %edi              C inv*inv*d
 
104
 
 
105
        pushl   %ebx            FRAME_pushl()
 
106
        leal    (%eax,%ebp,4), %ebx     C src end
 
107
 
 
108
        subl    %edi, %ecx              C inv = 2*inv - inv*inv*d
 
109
        leal    (%ecx,%ecx), %edi       C 2*inv
 
110
 
 
111
        imull   %ecx, %ecx              C inv*inv
 
112
 
 
113
        movl    (%eax), %eax            C src low limb
 
114
        negl    %ebp                    C -size
 
115
 
 
116
        imull   %esi, %ecx              C inv*inv*d
 
117
 
 
118
        subl    %ecx, %edi              C inv = 2*inv - inv*inv*d
 
119
 
 
120
        ASSERT(e,`      C d*inv == 1 mod 2^BITS_PER_MP_LIMB
 
121
        pushl   %eax
 
122
        movl    %esi, %eax
 
123
        imull   %edi, %eax
 
124
        cmpl    $1, %eax
 
125
        popl    %eax')
 
126
 
 
127
        jmp     L(entry)
 
128
 
 
129
 
 
130
C Rotating the mul to the top of the loop saves 1 cycle, presumably by
 
131
C hiding the loop control under the imul latency.
 
132
C
 
133
C The run time is 10 cycles, but decoding is only 9 (and the dependent chain
 
134
C only 8).  It's not clear how to get down to 9 cycles.
 
135
C
 
136
C The xor and rcl to handle the carry bit could be an sbb instead, with the
 
137
C the carry bit add becoming a sub, but that doesn't save anything.
 
138
 
 
139
L(top):
 
140
        C eax   (low product)
 
141
        C ebx   src end
 
142
        C ecx   carry bit, 0 or 1
 
143
        C edx   (high product, being carry limb)
 
144
        C esi   divisor
 
145
        C edi   inverse
 
146
        C ebp   counter, limbs, negative
 
147
 
 
148
        mull    %esi
 
149
 
 
150
        movl    (%ebx,%ebp,4), %eax
 
151
        addl    %ecx, %edx              C apply carry bit to carry limb
 
152
        ASSERT(a, `cmpl %edx, %esi')
 
153
 
 
154
L(entry):
 
155
        xorl    %ecx, %ecx
 
156
        subl    %edx, %eax              C apply carry limb
 
157
 
 
158
        rcll    %ecx
 
159
 
 
160
        imull   %edi, %eax
 
161
 
 
162
        incl    %ebp
 
163
        jnz     L(top)
 
164
 
 
165
 
 
166
 
 
167
        popl    %ebx
 
168
        popl    %ebp
 
169
 
 
170
        mull    %esi
 
171
 
 
172
        popl    %edi
 
173
        popl    %esi
 
174
 
 
175
        leal    (%ecx,%edx), %eax
 
176
 
 
177
        ret
 
178
 
 
179
EPILOGUE()