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

« back to all changes in this revision

Viewing changes to gmp3/mpn/x86/pentium4/mmx/popham.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  Intel Pentium 4 mpn_popcount, mpn_hamdist -- population count and
 
2
dnl  hamming distance.
 
3
dnl 
 
4
dnl  P4: popcount 8.5 cycles/limb
 
5
dnl      hamdist  9.5 cycles/limb
 
6
 
 
7
dnl  Copyright 2000, 2001 Free Software Foundation, Inc.
 
8
dnl 
 
9
dnl  This file is part of the GNU MP Library.
 
10
dnl 
 
11
dnl  The GNU MP Library is free software; you can redistribute it and/or
 
12
dnl  modify it under the terms of the GNU Lesser General Public License as
 
13
dnl  published by the Free Software Foundation; either version 2.1 of the
 
14
dnl  License, or (at your option) any later version.
 
15
dnl 
 
16
dnl  The GNU MP Library is distributed in the hope that it will be useful,
 
17
dnl  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
18
dnl  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
19
dnl  Lesser General Public License for more details.
 
20
dnl 
 
21
dnl  You should have received a copy of the GNU Lesser General Public
 
22
dnl  License along with the GNU MP Library; see the file COPYING.LIB.  If
 
23
dnl  not, write to the Free Software Foundation, Inc., 59 Temple Place -
 
24
dnl  Suite 330, Boston, MA 02111-1307, USA.
 
25
 
 
26
include(`../config.m4')
 
27
 
 
28
 
 
29
C unsigned long mpn_popcount (mp_srcptr src, mp_size_t size);
 
30
C unsigned long mpn_hamdist (mp_srcptr src, mp_srcptr src2, mp_size_t size);
 
31
C
 
32
C Loading with unaligned movq's costs an extra 1 c/l and hence is avoided.
 
33
C Two movd's and a punpckldq seems to be the same speed as an aligned movq,
 
34
C and using them saves fiddling about with alignment testing on entry.
 
35
C
 
36
C For popcount there's 13 mmx instructions in the loop, so perhaps 6.5 c/l
 
37
C might be possible, but 8.5 c/l relying on out-of-order execution is
 
38
C already quite reasonable.
 
39
 
 
40
ifdef(`OPERATION_popcount',,
 
41
`ifdef(`OPERATION_hamdist',,
 
42
`m4_error(`Need OPERATION_popcount or OPERATION_hamdist defined
 
43
')')')
 
44
 
 
45
define(HAM,
 
46
m4_assert_numargs(1)
 
47
`ifdef(`OPERATION_hamdist',`$1')')
 
48
 
 
49
define(POP,
 
50
m4_assert_numargs(1)
 
51
`ifdef(`OPERATION_popcount',`$1')')
 
52
 
 
53
HAM(`
 
54
defframe(PARAM_SIZE, 12)
 
55
defframe(PARAM_SRC2,  8)
 
56
defframe(PARAM_SRC,   4)
 
57
define(M4_function,mpn_hamdist)
 
58
')
 
59
POP(`
 
60
defframe(PARAM_SIZE,  8)
 
61
defframe(PARAM_SRC,   4)
 
62
define(M4_function,mpn_popcount)
 
63
')
 
64
 
 
65
MULFUNC_PROLOGUE(mpn_popcount mpn_hamdist)
 
66
 
 
67
 
 
68
ifdef(`PIC',,`
 
69
        dnl  non-PIC
 
70
        RODATA
 
71
        ALIGN(8)
 
72
LF(M4_function,rodata_AAAAAAAAAAAAAAAA):
 
73
        .long   0xAAAAAAAA
 
74
        .long   0xAAAAAAAA
 
75
LF(M4_function,rodata_3333333333333333):
 
76
        .long   0x33333333
 
77
        .long   0x33333333
 
78
LF(M4_function,rodata_0F0F0F0F0F0F0F0F):
 
79
        .long   0x0F0F0F0F
 
80
        .long   0x0F0F0F0F
 
81
')
 
82
 
 
83
        TEXT
 
84
        ALIGN(16)
 
85
 
 
86
PROLOGUE(M4_function)
 
87
deflit(`FRAME',0)
 
88
 
 
89
        movl    PARAM_SIZE, %ecx
 
90
        movl    PARAM_SRC, %eax
 
91
 
 
92
ifdef(`PIC',`
 
93
        movl    $0xAAAAAAAA, %edx
 
94
        movd    %edx, %mm7
 
95
        punpckldq %mm7, %mm7
 
96
 
 
97
        movl    $0x33333333, %edx
 
98
        movd    %edx, %mm6
 
99
        punpckldq %mm6, %mm6
 
100
 
 
101
        movl    $0x0F0F0F0F, %edx
 
102
        movd    %edx, %mm5
 
103
        punpckldq %mm5, %mm5
 
104
 
 
105
HAM(`   movl    PARAM_SRC2, %edx')
 
106
 
 
107
',`
 
108
        dnl non-PIC
 
109
HAM(`   movl    PARAM_SRC2, %edx')
 
110
        movq    L(rodata_AAAAAAAAAAAAAAAA), %mm7
 
111
        movq    L(rodata_3333333333333333), %mm6
 
112
        movq    L(rodata_0F0F0F0F0F0F0F0F), %mm5
 
113
')
 
114
 
 
115
        pxor    %mm4, %mm4              C zero
 
116
        pxor    %mm0, %mm0              C total
 
117
 
 
118
        subl    $1, %ecx
 
119
        ja      L(top)
 
120
 
 
121
L(last):
 
122
        movd    (%eax,%ecx,4), %mm1             C src high limb
 
123
HAM(`   movd    (%edx,%ecx,4), %mm2
 
124
        pxor    %mm2, %mm1
 
125
')
 
126
        jmp     L(loaded)
 
127
 
 
128
 
 
129
L(top):
 
130
        C eax   src
 
131
        C ebx
 
132
        C ecx   counter, size-1 to 2 or 1, inclusive
 
133
        C edx   [hamdist] src2
 
134
        C
 
135
        C mm0   total (low dword)
 
136
        C mm1   (scratch)
 
137
        C mm2   (scratch)
 
138
        C mm3
 
139
        C mm4   0x0000000000000000
 
140
        C mm5   0x0F0F0F0F0F0F0F0F
 
141
        C mm6   0x3333333333333333
 
142
        C mm7   0xAAAAAAAAAAAAAAAA
 
143
 
 
144
        movd    (%eax), %mm1
 
145
        movd    4(%eax), %mm2
 
146
        punpckldq %mm2, %mm1
 
147
        addl    $8, %eax
 
148
 
 
149
HAM(`   movd    (%edx), %mm2
 
150
        movd    4(%edx), %mm3
 
151
        punpckldq %mm3, %mm2
 
152
        pxor    %mm2, %mm1
 
153
        addl    $8, %edx
 
154
')
 
155
 
 
156
L(loaded):
 
157
        movq    %mm7, %mm2
 
158
        pand    %mm1, %mm2
 
159
        psrlq   $1, %mm2
 
160
        psubd   %mm2, %mm1      C bit pairs
 
161
 
 
162
        movq    %mm6, %mm2
 
163
        pand    %mm1, %mm2
 
164
        psrlq   $2, %mm1
 
165
        pand    %mm6, %mm1
 
166
        paddd   %mm2, %mm1      C nibbles
 
167
 
 
168
        movq    %mm5, %mm2
 
169
        pand    %mm1, %mm2
 
170
        psrlq   $4, %mm1
 
171
        pand    %mm5, %mm1
 
172
        paddd   %mm2, %mm1      C bytes
 
173
 
 
174
        psadbw( %mm4, %mm1)
 
175
        paddd   %mm1, %mm0      C to total
 
176
 
 
177
        subl    $2, %ecx
 
178
        jg      L(top)
 
179
 
 
180
        C ecx is 0 or -1 representing respectively 1 or 0 further limbs
 
181
        jz      L(last)
 
182
 
 
183
 
 
184
        movd    %mm0, %eax
 
185
        emms
 
186
        ret
 
187
 
 
188
EPILOGUE()