xref: /netbsd-src/external/lgpl3/gmp/dist/mpn/arm/cnd_aors_n.asm (revision eceb233b9bd0dfebb902ed73b531ae6964fa3f9b)
1dnl  ARM mpn_cnd_add_n, mpn_cnd_sub_n
2
3dnl  Copyright 2012, 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 StrongARM	 ?
35C XScale	 ?
36C Cortex-A7	 ?
37C Cortex-A8	 ?
38C Cortex-A9	 3
39C Cortex-A15	 2.5
40
41define(`cnd',	`r0')
42define(`rp',	`r1')
43define(`up',	`r2')
44define(`vp',	`r3')
45
46define(`n',	`r12')
47
48
49ifdef(`OPERATION_cnd_add_n', `
50	define(`ADDSUB',      adds)
51	define(`ADDSUBC',      adcs)
52	define(`INITCY',      `cmn	r0, #0')
53	define(`RETVAL',      `adc	r0, n, #0')
54	define(func,	      mpn_cnd_add_n)')
55ifdef(`OPERATION_cnd_sub_n', `
56	define(`ADDSUB',      subs)
57	define(`ADDSUBC',      sbcs)
58	define(`INITCY',      `cmp	r0, #0')
59	define(`RETVAL',      `adc	r0, n, #0
60			      rsb	r0, r0, #1')
61	define(func,	      mpn_cnd_sub_n)')
62
63MULFUNC_PROLOGUE(mpn_cnd_add_n mpn_cnd_sub_n)
64
65ASM_START()
66PROLOGUE(func)
67	push	{r4-r11}
68	ldr	n, [sp, #32]
69
70	cmp	cnd, #1
71	sbc	cnd, cnd, cnd		C conditionally set to 0xffffffff
72
73	INITCY				C really only needed for n = 0 (mod 4)
74
75	ands	r4, n, #3
76	beq	L(top)
77	cmp	r4, #2
78	bcc	L(b1)
79	beq	L(b2)
80
81L(b3):	ldm	vp!, {r4,r5,r6}
82	ldm	up!, {r8,r9,r10}
83	bic	r4, r4, cnd
84	bic	r5, r5, cnd
85	bic	r6, r6, cnd
86	ADDSUB	r8, r8, r4
87	ADDSUBC	r9, r9, r5
88	ADDSUBC	r10, r10, r6
89	stm	rp!, {r8,r9,r10}
90	sub	n, n, #3
91	teq	n, #0
92	bne	L(top)
93	b	L(end)
94
95L(b2):	ldm	vp!, {r4,r5}
96	ldm	up!, {r8,r9}
97	bic	r4, r4, cnd
98	bic	r5, r5, cnd
99	ADDSUB	r8, r8, r4
100	ADDSUBC	r9, r9, r5
101	stm	rp!, {r8,r9}
102	sub	n, n, #2
103	teq	n, #0
104	bne	L(top)
105	b	L(end)
106
107L(b1):	ldr	r4, [vp], #4
108	ldr	r8, [up], #4
109	bic	r4, r4, cnd
110	ADDSUB	r8, r8, r4
111	str	r8, [rp], #4
112	sub	n, n, #1
113	teq	n, #0
114	beq	L(end)
115
116L(top):	ldm	vp!, {r4,r5,r6,r7}
117	ldm	up!, {r8,r9,r10,r11}
118	bic	r4, r4, cnd
119	bic	r5, r5, cnd
120	bic	r6, r6, cnd
121	bic	r7, r7, cnd
122	ADDSUBC	r8, r8, r4
123	ADDSUBC	r9, r9, r5
124	ADDSUBC	r10, r10, r6
125	ADDSUBC	r11, r11, r7
126	sub	n, n, #4
127	stm	rp!, {r8,r9,r10,r11}
128	teq	n, #0
129	bne	L(top)
130
131L(end):	RETVAL
132	pop	{r4-r11}
133	ret	r14
134EPILOGUE()
135