~ubuntu-branches/ubuntu/intrepid/ecl/intrepid

« back to all changes in this revision

Viewing changes to msvc/gmp/mpn/amd64i/aors_n.asm

  • Committer: Bazaar Package Importer
  • Author(s): Peter Van Eynde
  • Date: 2007-04-09 11:51:51 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20070409115151-ql8cr0kalzx1jmla
Tags: 0.9i-20070324-2
Upload to unstable. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
;
 
2
;  AMD64 mpn_add_n/mpn_sub_n -- mpn add or subtract.
 
3
;
 
4
;  Copyright 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
 
5
;   
 
6
;  This file is part of the GNU MP Library.
 
7
;   
 
8
;  The GNU MP Library is free software; you can redistribute it and/or
 
9
;  modify it under the terms of the GNU Lesser General Public License as
 
10
;  published by the Free Software Foundation; either version 2.1 of the
 
11
;  License, or (at your option) any later version.
 
12
;   
 
13
;  The GNU MP Library is distributed in the hope that it will be useful,
 
14
;  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
;  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
16
;  Lesser General Public License for more details.
 
17
;   
 
18
;  You should have received a copy of the GNU Lesser General Public
 
19
;  License along with the GNU MP Library; see the file COPYING.LIB.  If
 
20
;  not, write to the Free Software Foundation, Inc., 59 Temple Place -
 
21
;  Suite 330, Boston, MA 02111-1307, USA.
 
22
;
 
23
;  Adapted by Brian Gladman AMD64 using the Microsoft VC++ v8 64-bit 
 
24
;  compiler and the YASM assembler.
 
25
;
 
26
;  Calling interface:
 
27
;
 
28
;  mp_limb_t __gmpn_<op>_n(             <op> = add OR sub
 
29
;               mp_ptr dst,                             ecx
 
30
;               mp_srcptr src1,                 rdx
 
31
;               mp_srcptr src2,                  r8
 
32
;               mp_size_t  len                   r9
 
33
;  )
 
34
;
 
35
;  mp_limb_t __gmpn_<op>_nc(    <op> = add OR sub
 
36
;               mp_ptr dst,                             ecx
 
37
;               mp_srcptr src1,                 rdx
 
38
;               mp_srcptr src2,                  r8
 
39
;               mp_size_t len,                   r9
 
40
;               mp_limb_t carry  [rsp+0x28]
 
41
;  )
 
42
;
 
43
;  Calculate src1[size] plus(minus) src2[size] and store the result in
 
44
;  dst[size].  The return value is the carry bit from the top of the result 
 
45
;  (1 or 0).  The _nc version accepts 1 or 0 for an initial carry into the 
 
46
;  low limb of the calculation.  Note values other than 1 or 0 here will 
 
47
;  lead to garbage results.
 
48
 
 
49
%define dst                rcx  ; destination pointer
 
50
%define sr1                rdx  ; source 1 pointer
 
51
%define sr2                 r8  ; source 2 pointer
 
52
%define len                 r9  ; number of limbs
 
53
%define cry     [rsp+0x28]      ; carry value
 
54
 
 
55
%define r_jmp      r10  ; temporary for jump table entry
 
56
%define r_cnt      r11  ; temporary for loop count
 
57
 
 
58
%define UNROLL_LOG2                     4
 
59
%define UNROLL_COUNT            (1 << UNROLL_LOG2)
 
60
%define UNROLL_MASK                     (UNROLL_COUNT - 1)
 
61
%define UNROLL_BYTES            (8 * UNROLL_COUNT)
 
62
%define UNROLL_THRESHOLD        8
 
63
 
 
64
%if UNROLL_BYTES >= 256
 
65
%error unroll count is too large
 
66
%elif UNROLL_BYTES >= 128
 
67
%define off     128
 
68
%else
 
69
%define off     0
 
70
%endif
 
71
 
 
72
%macro  mac_sub 4
 
73
 
 
74
        global  %1%4
 
75
        global  %1%3
 
76
        
 
77
%ifdef DLL
 
78
        export  %1%4
 
79
        export  %1%3
 
80
%define         PIC
 
81
%endif
 
82
 
 
83
%1%4:
 
84
        mov             rax,[rsp+0x28]
 
85
        jmp             %%0
 
86
%1%3:
 
87
        xor             rax,rax 
 
88
%%0:
 
89
        movsxd  len,r9d
 
90
        cmp             len,UNROLL_THRESHOLD
 
91
        jae             %%2
 
92
        lea             sr1,[sr1+len*8]
 
93
        lea             sr2,[sr2+len*8]
 
94
        lea             dst,[dst+len*8]
 
95
        neg             len
 
96
        shr             rax,1
 
97
%%1:
 
98
        mov             rax,[sr1+len*8]
 
99
        mov             r10,[sr2+len*8]
 
100
        %2              rax,r10
 
101
        mov             [dst+len*8],rax
 
102
        inc             len
 
103
        jnz             %%1
 
104
        mov             rax,dword 0
 
105
        setc    al
 
106
        ret
 
107
%%2:
 
108
        mov             r_cnt,1
 
109
        and             r_cnt,len
 
110
        push    r_cnt
 
111
        and             len,-2
 
112
        mov             r_cnt,len
 
113
        dec             r_cnt
 
114
        shr             r_cnt,UNROLL_LOG2
 
115
        neg             len
 
116
        and             len,UNROLL_MASK
 
117
        lea             r_jmp,[len*4]
 
118
        neg             len
 
119
        lea             sr1,[sr1+len*8+off]
 
120
        lea             sr2,[sr2+len*8+off]
 
121
        lea             dst,[dst+len*8+off]
 
122
        shr             rax,1
 
123
%ifdef PIC
 
124
        lea             r_jmp,[r_jmp+r_jmp*2]
 
125
        lea             rax,[%%3 wrt rip]
 
126
        lea             r_jmp,[r_jmp+rax]
 
127
%else
 
128
        lea             r_jmp,[r_jmp+r_jmp*2+%%3]
 
129
%endif
 
130
        jmp             r_jmp
 
131
%%3:
 
132
 
 
133
%define CHUNK_COUNT     2
 
134
%assign i 0
 
135
 
 
136
%rep    UNROLL_COUNT / CHUNK_COUNT
 
137
%assign disp0   8 * i * CHUNK_COUNT - off
 
138
 
 
139
                mov             r_jmp,[byte sr1+disp0]          ; len and r_jmp registers
 
140
                mov             len,[byte sr1+disp0+8]          ; now not needed
 
141
                %2              r_jmp,[byte sr2+disp0]
 
142
                mov             [byte dst+disp0],r_jmp
 
143
                %2              len,[byte sr2+disp0+8]
 
144
                mov             [byte dst+disp0+8],len
 
145
 
 
146
%assign i i + 1
 
147
%endrep
 
148
 
 
149
        dec             r_cnt
 
150
        lea             sr1,[sr1+UNROLL_BYTES]
 
151
        lea             sr2,[sr2+UNROLL_BYTES]
 
152
        lea             dst,[dst+UNROLL_BYTES]
 
153
        jns             %%3
 
154
 
 
155
        pop             rax
 
156
        dec             rax
 
157
        js              %%5
 
158
        mov             len,[sr1-off]
 
159
        %2              len,[sr2-off]
 
160
        mov             [dst-off],len
 
161
%%5:mov         rax,dword 0
 
162
        setc    al
 
163
        ret
 
164
 
 
165
%endmacro
 
166
 
 
167
        bits 64
 
168
        text
 
169
        
 
170
        mac_sub __g,adc,mpn_add_n,mpn_add_nc    
 
171
        mac_sub __g,sbb,mpn_sub_n,mpn_sub_nc
 
172
 
 
173
        end