xref: /netbsd-src/external/lgpl3/gmp/dist/mpn/arm/rsh1aors_n.asm (revision 87d689fb734c654d2486f87f7be32f1b53ecdbec)
1dnl  ARM mpn_rsh1add_n and mpn_rsh1sub_n.
2
3dnl  Contributed to the GNU project by Torbjörn Granlund.
4
5dnl  Copyright 2012 Free Software Foundation, Inc.
6
7dnl  This file is part of the GNU MP Library.
8dnl
9dnl  The GNU MP Library is free software; you can redistribute it and/or modify
10dnl  it under the terms of either:
11dnl
12dnl    * the GNU Lesser General Public License as published by the Free
13dnl      Software Foundation; either version 3 of the License, or (at your
14dnl      option) any later version.
15dnl
16dnl  or
17dnl
18dnl    * the GNU General Public License as published by the Free Software
19dnl      Foundation; either version 2 of the License, or (at your option) any
20dnl      later version.
21dnl
22dnl  or both in parallel, as here.
23dnl
24dnl  The GNU MP Library is distributed in the hope that it will be useful, but
25dnl  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
26dnl  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
27dnl  for more details.
28dnl
29dnl  You should have received copies of the GNU General Public License and the
30dnl  GNU Lesser General Public License along with the GNU MP Library.  If not,
31dnl  see https://www.gnu.org/licenses/.
32
33include(`../config.m4')
34
35C	     cycles/limb
36C StrongARM	 ?
37C XScale	 ?
38C Cortex-A7	 ?
39C Cortex-A8	 ?
40C Cortex-A9	3.64-3.7
41C Cortex-A15	 2.5
42
43C TODO
44C  * Not optimised.
45
46define(`rp', `r0')
47define(`up', `r1')
48define(`vp', `r2')
49define(`n',  `r3')
50
51ifdef(`OPERATION_rsh1add_n', `
52  define(`ADDSUB',	adds)
53  define(`ADDSUBC',	adcs)
54  define(`RSTCY',	`cmn	$1, $1')
55  define(`func',	mpn_rsh1add_n)
56  define(`func_nc',	mpn_rsh1add_nc)')
57ifdef(`OPERATION_rsh1sub_n', `
58  define(`ADDSUB',	subs)
59  define(`ADDSUBC',	sbcs)
60  define(`RSTCY',
61	`mvn	$2, #0x80000000
62	cmp	$2, $1')
63  define(`func',	mpn_rsh1sub_n)
64  define(`func_nc',	mpn_rsh1sub_nc)')
65
66MULFUNC_PROLOGUE(mpn_rsh1add_n mpn_rsh1sub_n)
67
68ASM_START()
69PROLOGUE(func)
70	push	{r4-r11}
71	ldr	r4, [up], #4
72	ldr	r8, [vp], #4
73	ADDSUB	r4, r4, r8
74	movs	r12, r7, rrx
75	and	r11, r4, #1	C return value
76	subs	n, n, #4
77	blo	L(end)
78
79L(top):	ldmia	up!, {r5,r6,r7}
80	ldmia	vp!, {r8,r9,r10}
81	cmn	r12, r12
82	ADDSUBC	r5, r5, r8
83	ADDSUBC	r6, r6, r9
84	ADDSUBC	r7, r7, r10
85	movs	r12, r7, rrx
86	movs	r6, r6, rrx
87	movs	r5, r5, rrx
88	movs	r4, r4, rrx
89	subs	n, n, #3
90	stmia	rp!, {r4,r5,r6}
91	mov	r4, r7
92	bhs	L(top)
93
94L(end):	cmn	n, #2
95	bls	L(e2)
96	ldm	up, {r5,r6}
97	ldm	vp, {r8,r9}
98	cmn	r12, r12
99	ADDSUBC	r5, r5, r8
100	ADDSUBC	r6, r6, r9
101	movs	r12, r6, rrx
102	movs	r5, r5, rrx
103	movs	r4, r4, rrx
104	stmia	rp!, {r4,r5}
105	mov	r4, r6
106	b	L(e1)
107
108L(e2):	bne	L(e1)
109	ldr	r5, [up, #0]
110	ldr	r8, [vp, #0]
111	cmn	r12, r12
112	ADDSUBC	r5, r5, r8
113	movs	r12, r5, rrx
114	movs	r4, r4, rrx
115	str	r4, [rp], #4
116	mov	r4, r5
117
118L(e1):	RSTCY(	r12, r1)
119	mov	r4, r4, rrx
120	str	r4, [rp, #0]
121	mov	r0, r11
122	pop	{r4-r11}
123	ret	r14
124EPILOGUE()
125