xref: /netbsd-src/external/lgpl3/gmp/dist/mpn/alpha/sqr_diag_addlsh1.asm (revision f3cfa6f6ce31685c6c4a758bc430e69eb99f50a4)
1dnl  Alpha mpn_sqr_diag_addlsh1.
2
3dnl  Copyright 2013 Free Software Foundation, Inc.
4
5dnl  This file is part of the GNU MP Library.
6dnl
7dnl  The GNU MP Library is free software; you can redistribute it and/or modify
8dnl  it under the terms of either:
9dnl
10dnl    * the GNU Lesser General Public License as published by the Free
11dnl      Software Foundation; either version 3 of the License, or (at your
12dnl      option) any later version.
13dnl
14dnl  or
15dnl
16dnl    * the GNU General Public License as published by the Free Software
17dnl      Foundation; either version 2 of the License, or (at your option) any
18dnl      later version.
19dnl
20dnl  or both in parallel, as here.
21dnl
22dnl  The GNU MP Library is distributed in the hope that it will be useful, but
23dnl  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
24dnl  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
25dnl  for more details.
26dnl
27dnl  You should have received copies of the GNU General Public License and the
28dnl  GNU Lesser General Public License along with the GNU MP Library.  If not,
29dnl  see https://www.gnu.org/licenses/.
30
31include(`../config.m4')
32
33C      cycles/limb
34C EV4:      ?
35C EV5:     10.2
36C EV6:      4.5
37
38C Ideally, one-way code could run at 9 c/l (limited by mulq+umulh) on ev5 and
39C about 3.75 c/l on ev6.  Two-way code could run at about 3.25 c/l on ev6.
40
41C Algorithm: We allow ourselves to propagate carry to a product high word
42C without worrying for carry out, since (B-1)^2 = B^2-2B+1 has a high word of
43C B-2, i.e, will not spill.  We propagate carry similarly to a product low word
44C since the problem value B-1 is a quadratic non-residue mod B, but our
45C products are squares.
46
47define(`rp',	`r16')
48define(`tp',	`r17')
49define(`up',	`r18')
50define(`n',	`r19')
51
52ASM_START()
53PROLOGUE(mpn_sqr_diag_addlsh1)
54	ldq	r0, 0(up)
55	bis	r31, r31, r21
56	bis	r31, r31, r3
57	mulq	r0, r0, r7
58	stq	r7, 0(rp)
59	umulh	r0, r0, r6
60	lda	n, -1(n)
61
62	ALIGN(16)
63L(top):	ldq	r0, 8(up)
64	lda	up, 8(up)
65	ldq	r8, 0(tp)
66	ldq	r20, 8(tp)
67	mulq	r0, r0, r7
68	lda	tp, 16(tp)
69	sll	r8, 1, r23
70	srl	r8, 63, r22
71	or	r21, r23, r23
72	sll	r20, 1, r24
73	addq	r3, r6, r6		C cannot carry per comment above
74	or	r22, r24, r24
75	addq	r23, r6, r21
76	umulh	r0, r0, r6
77	cmpult	r21, r23, r1
78	addq	r1, r7, r7		C cannot carry per comment above
79	stq	r21, 8(rp)
80	addq	r24, r7, r22
81	stq	r22, 16(rp)
82	lda	n, -1(n)
83	cmpult	r22, r7, r3
84	srl	r20, 63, r21
85	lda	rp, 16(rp)
86	bne	n, L(top)
87
88	addq	r3, r6, r6		C cannot carry per comment above
89	addq	r21, r6, r21
90	stq	r21, 8(rp)
91	ret	r31, (r26), 1
92EPILOGUE()
93ASM_END()
94