summaryrefslogtreecommitdiff
path: root/plugins/MirOTR/libgcrypt-1.4.6/mpi/pentium4/sse2/mpih-mul2.S
blob: f975adfca57395cb4c52a04252446737bf1cabaa (plain)
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
/* Intel Pentium-4 mpn_addmul_1 -- Multiply a limb vector with a limb and add
 * the result to a second limb vector.
 *
 * Copyright 2001, 2002, 2004, 2005 Free Software Foundation, Inc.
 *
 * This file is part of Libgcrypt.
 *
 * Libgcrypt is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * Libgcrypt is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 *
 * Note: This code is heavily based on the GNU MP Library.
 *	 Actually it's the same code with only minor changes in the
 *	 way the data is stored; this is to support the abstraction
 *	 of an optional secure memory allocation which may be used
 *	 to avoid revealing of sensitive data due to paging etc.
 */


#include "sysdep.h"
#include "asm-syntax.h"


/*******************
 * mpi_limb_t
 * _gcry_mpih_addmul_1( mpi_ptr_t res_ptr,      (sp + 4)
 *		     mpi_ptr_t s1_ptr,	     (sp + 8)
 *		     mpi_size_t s1_size,     (sp + 12)
 *		     mpi_limb_t s2_limb)     (sp + 16)
 *
 * P3 model 9  (Banias)          ?.?
 * P3 model 13 (Dothan)          5.8
 * P4 model 0  (Willamette)      5.5
 * P4 model 1  (?)               5.5
 * P4 model 2  (Northwood)       5.5
 * P4 model 3  (Prescott)        6.0
 * P4 model 4  (Nocona)
 *
 * Only the carry limb propagation is on the dependent chain, but some other
 * Pentium4 pipeline magic brings down performance to 6 cycles/l from the
 * ideal 4 cycles/l.
 */


	TEXT
	ALIGN (4)
	GLOBL	C_SYMBOL_NAME(_gcry_mpih_addmul_1)
C_SYMBOL_NAME(_gcry_mpih_addmul_1:)

	pxor	%mm4, %mm4
.Lstart_1c:
	movl	8(%esp), %eax
	movl	12(%esp), %ecx
	movl	4(%esp), %edx
	movd	16(%esp), %mm7

/*
	C eax	src, incrementing ; 5B
	C ecx	loop counter, decrementing
	C edx	dst, incrementing
	C
	C mm4	carry, low 32-bits
	C mm7	multiplier
*/

	movd		(%eax), %mm2	
	pmuludq		%mm7, %mm2

	shrl	$1, %ecx
	jnc	.Leven

	leal		4(%eax), %eax
	movd		(%edx), %mm1
	paddq		%mm2, %mm1
	paddq		%mm1, %mm4
	movd		%mm4, (%edx)
	psrlq		$32, %mm4

	testl	%ecx, %ecx
	jz	.Lrtn
	leal	4(%edx), %edx

	movd		(%eax), %mm2	
	pmuludq		%mm7, %mm2
.Leven:
	movd		4(%eax), %mm0	
	movd		(%edx), %mm1	
	pmuludq		%mm7, %mm0

	subl	$1, %ecx
	jz	.Lend
.Lloop:
	paddq		%mm2, %mm1	
	movd		8(%eax), %mm2	
	paddq		%mm1, %mm4	
	movd		4(%edx), %mm3	
	pmuludq		%mm7, %mm2
	movd		%mm4, (%edx)
	psrlq		$32, %mm4

	paddq		%mm0, %mm3	
	movd		12(%eax), %mm0	
	paddq		%mm3, %mm4	
	movd		8(%edx), %mm1	
	pmuludq		%mm7, %mm0
	movd		%mm4, 4(%edx)
	psrlq		$32, %mm4

	leal	8(%eax), %eax
	leal	8(%edx), %edx
	subl	$1, %ecx
	jnz	.Lloop
.Lend:
	paddq		%mm2, %mm1	
	paddq		%mm1, %mm4	
	movd		4(%edx), %mm3	
	movd		%mm4, (%edx)
	psrlq		$32, %mm4
	paddq		%mm0, %mm3	
	paddq		%mm3, %mm4	
	movd		%mm4, 4(%edx)
	psrlq		$32, %mm4
.Lrtn:
	movd	%mm4, %eax
	emms
	ret