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

« back to all changes in this revision

Viewing changes to src/gmp/mpn/x86/pentium4/sse2/diveby3.asm

  • Committer: Bazaar Package Importer
  • Author(s): Peter Van Eynde
  • Date: 2006-05-17 02:46:26 UTC
  • Revision ID: james.westby@ubuntu.com-20060517024626-lljr08ftv9g9vefl
Tags: upstream-0.9h-20060510
ImportĀ upstreamĀ versionĀ 0.9h-20060510

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
dnl  Intel Pentium-4 mpn_divexact_by3 -- mpn exact division by 3.
 
2
 
 
3
dnl  Copyright 2001, 2002, 2003 Free Software Foundation, Inc.
 
4
dnl 
 
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
 
8
dnl  modify it under the terms of the GNU Library General Public License as
 
9
dnl  published by the Free Software Foundation; either version 2 of the
 
10
dnl  License, or (at your option) any later version.
 
11
dnl 
 
12
dnl  The GNU MP Library is distributed in the hope that it will be useful,
 
13
dnl  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
dnl  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
15
dnl  Library General Public License for more details.
 
16
dnl 
 
17
dnl  You should have received a copy of the GNU Library General Public
 
18
dnl  License along with the GNU MP Library; see the file COPYING.LIB.  If
 
19
dnl  not, write to the Free Software Foundation, Inc., 59 Temple Place -
 
20
dnl  Suite 330, Boston, MA 02111-1307, USA.
 
21
 
 
22
include(`../config.m4')
 
23
 
 
24
 
 
25
C P4: 18.0 cycles/limb
 
26
 
 
27
 
 
28
C mp_limb_t mpn_divexact_by3c (mp_ptr dst, mp_srcptr src, mp_size_t size,
 
29
C                              mp_limb_t carry);
 
30
C
 
31
C The dependent chain in the loop is as follows, and this is what the code
 
32
C measures.
 
33
C
 
34
C       psubq     (src-cbit) - climb    2
 
35
C       pmuludq   s*inverse             8
 
36
C       pand      mask q                2
 
37
C       psllq     2*q                   2
 
38
C       paddq     q+2*q                 2
 
39
C       psrlq     high(3*q)             2
 
40
C                                      --
 
41
C                                      18
 
42
C
 
43
C Perhaps the s*inverse can be taken off the dependent chain as described in
 
44
C mpn/generic/diveby3.c, with a modified 3*q calculation that can give
 
45
C high(3*q)*inv too.
 
46
 
 
47
 
 
48
defframe(PARAM_CARRY,16)
 
49
defframe(PARAM_SIZE, 12)
 
50
defframe(PARAM_SRC,   8)
 
51
defframe(PARAM_DST,   4)
 
52
 
 
53
        RODATA
 
54
C multiplicative inverse of 3, modulo 2^32
 
55
        ALIGN(4)
 
56
L(inverse):
 
57
        .long   0xAAAAAAAB
 
58
 
 
59
        TEXT
 
60
        ALIGN(16)
 
61
 
 
62
PROLOGUE(mpn_divexact_by3c)
 
63
deflit(`FRAME',0)
 
64
 
 
65
        movl    PARAM_SRC, %eax
 
66
        pxor    %mm0, %mm0
 
67
 
 
68
        movd    PARAM_CARRY, %mm1
 
69
        pcmpeqd %mm6, %mm6
 
70
 
 
71
        movl    $0xAAAAAAAB, %edx
 
72
        movd    %edx, %mm7
 
73
 
 
74
        movl    PARAM_DST, %edx
 
75
        psrlq   $32, %mm6               C 0x00000000FFFFFFFF
 
76
 
 
77
        movl    PARAM_SIZE, %ecx
 
78
 
 
79
L(top):
 
80
        C eax   src, incrementing
 
81
        C ebx
 
82
        C ecx   counter, limbs, decrementing
 
83
        C edx   dst, incrementing
 
84
        C
 
85
        C mm0   carry bit
 
86
        C mm1   carry limb
 
87
        C mm6   0x00000000FFFFFFFF
 
88
        C mm7   inverse
 
89
 
 
90
        movd    (%eax), %mm2
 
91
        addl    $4, %eax
 
92
 
 
93
        psubq   %mm0, %mm2              C src - cbit
 
94
 
 
95
        psubq   %mm1, %mm2              C src - cbit - climb
 
96
        movq    %mm2, %mm0
 
97
        psrlq   $63, %mm0               C new cbit
 
98
 
 
99
        pmuludq %mm7, %mm2              C s*inverse
 
100
        movd    %mm2, (%edx)            C q
 
101
        addl    $4, %edx
 
102
 
 
103
        movq    %mm6, %mm1
 
104
 
 
105
        pand    %mm2, %mm1
 
106
 
 
107
        pand    %mm6, %mm2
 
108
 
 
109
        psllq   $1, %mm1
 
110
 
 
111
        C
 
112
 
 
113
        paddq   %mm2, %mm1
 
114
 
 
115
        C
 
116
 
 
117
        psrlq   $32, %mm1
 
118
 
 
119
        subl    $1, %ecx
 
120
        jnz     L(top)
 
121
 
 
122
 
 
123
        paddd   %mm1, %mm0
 
124
        movd    %mm0, %eax
 
125
        emms
 
126
        ret
 
127
 
 
128
EPILOGUE()