aboutsummaryrefslogtreecommitdiff
path: root/vendor/gmp-6.3.0/mpn/x86/k7/mod_34lsub1.asm
blob: ee3ad04099d5d8808f951ab98e55fa7b15e7e042 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
dnl  AMD K7 mpn_mod_34lsub1 -- remainder modulo 2^24-1.

dnl  Copyright 2000-2002, 2004, 2005, 2008 Free Software Foundation, Inc.

dnl  This file is part of the GNU MP Library.
dnl
dnl  The GNU MP Library is free software; you can redistribute it and/or modify
dnl  it under the terms of either:
dnl
dnl    * the GNU Lesser General Public License as published by the Free
dnl      Software Foundation; either version 3 of the License, or (at your
dnl      option) any later version.
dnl
dnl  or
dnl
dnl    * the GNU General Public License as published by the Free Software
dnl      Foundation; either version 2 of the License, or (at your option) any
dnl      later version.
dnl
dnl  or both in parallel, as here.
dnl
dnl  The GNU MP Library is distributed in the hope that it will be useful, but
dnl  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
dnl  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
dnl  for more details.
dnl
dnl  You should have received copies of the GNU General Public License and the
dnl  GNU Lesser General Public License along with the GNU MP Library.  If not,
dnl  see https://www.gnu.org/licenses/.

include(`../config.m4')


C         cycles/limb
C Athlon:     1
C Hammer:     1


C mp_limb_t mpn_mod_34lsub1 (mp_srcptr src, mp_size_t size)
C
C The loop form below and the 64 byte code alignment seem necessary for the
C claimed speed.  This is a bit strange, since normally k7 isn't very
C sensitive to such things.  Perhaps there has to be 6 instructions in the
C first 16 bytes for the BTB entry or something.

defframe(PARAM_SIZE, 8)
defframe(PARAM_SRC,  4)

dnl  re-use parameter space
define(SAVE_EDI, `PARAM_SIZE')

	TEXT
	ALIGN(64)
PROLOGUE(mpn_mod_34lsub1)
deflit(`FRAME',0)

	movl	PARAM_SIZE, %ecx
	movl	PARAM_SRC, %edx

	subl	$2, %ecx
	ja	L(three_or_more)

	movl	(%edx), %eax
	jb	L(one)

	movl	4(%edx), %ecx
	movl	%eax, %edx
	shrl	$24, %eax		C src[0] low

	andl	$0xFFFFFF, %edx		C src[0] high
	addl	%edx, %eax
	movl	%ecx, %edx

	andl	$0xFFFF, %ecx
	shrl	$16, %edx		C src[1] high
	addl	%edx, %eax

	shll	$8, %ecx		C src[1] low
	addl	%ecx, %eax

L(one):
	ret


L(three_or_more):
	C eax
	C ebx
	C ecx	size-2
	C edx	src
	C esi
	C edi

	pushl	%ebx	FRAME_pushl()
	xorl	%eax, %eax
	xorl	%ebx, %ebx

	movl	%edi, SAVE_EDI
	pushl	%esi	FRAME_pushl()
	xorl	%esi, %esi		C and clear carry flag


	C code offset 0x40 at this point
L(top):
	C eax	acc 0mod3
	C ebx	acc 1mod3
	C ecx	counter, limbs
	C edx	src
	C esi	acc 2mod3
	C edi

	leal	24(%edx), %edx
	leal	-2(%ecx), %ecx
	adcl	-24(%edx), %eax
	adcl	-20(%edx), %ebx
	adcl	-16(%edx), %esi

	decl	%ecx
	jng	L(done_loop)

	leal	-2(%ecx), %ecx
	adcl	-12(%edx), %eax
	adcl	-8(%edx), %ebx
	adcl	-4(%edx), %esi

	decl	%ecx
	jg	L(top)


	leal	12(%edx), %edx


L(done_loop):
	C ecx is -2, -1 or 0 representing 0, 1 or 2 more limbs, respectively

	incl	%ecx
	movl	$0xFFFFFFFF, %edi
	js	L(combine)

	adcl	-12(%edx), %eax
	decl	%ecx
	movl	$0xFFFFFF00, %edi
	js	L(combine)

	adcl	-8(%edx), %ebx
	movl	$0xFFFF0000, %edi


L(combine):
	C eax	acc 0mod3
	C ebx	acc 1mod3
	C ecx
	C edx
	C esi	acc 2mod3
	C edi	mask

	sbbl	%ecx, %ecx		C carry
	movl	%eax, %edx		C 0mod3
	shrl	$24, %eax		C 0mod3 high

	andl	%edi, %ecx		C carry masked
	andl	$0x00FFFFFF, %edx	C 0mod3 low
	movl	%ebx, %edi		C 1mod3

	subl	%ecx, %eax		C apply carry
	shrl	$16, %ebx		C 1mod3 high
	andl	$0xFFFF, %edi

	addl	%edx, %eax		C apply 0mod3 low
	movl	%esi, %edx		C 2mod3
	shll	$8, %edi		C 1mod3 low

	addl	%ebx, %eax		C apply 1mod3 high
	shrl	$8, %esi		C 2mod3 high
	movzbl	%dl, %edx		C 2mod3 low

	addl	%edi, %eax		C apply 1mod3 low
	shll	$16, %edx		C 2mod3 low

	addl	%esi, %eax		C apply 2mod3 high
	popl	%esi	FRAME_popl()

	movl	SAVE_EDI, %edi
	addl	%edx, %eax		C apply 2mod3 low
	popl	%ebx	FRAME_popl()

	ret

EPILOGUE()