xref: /netbsd-src/external/lgpl3/gmp/dist/mpn/arm/aors_n.asm (revision 16dce51364ebe8aeafbae46bc5aa167b8115bc45)
1dnl  ARM mpn_add_n and mpn_sub_n
2
3dnl  Contributed to the GNU project by Robert Harley.
4
5dnl  Copyright 1997, 2000, 2001, 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	 2.5	slightly fluctuating
41C Cortex-A15	 2.25
42
43define(`rp', `r0')
44define(`up', `r1')
45define(`vp', `r2')
46define(`n',  `r3')
47
48ifdef(`OPERATION_add_n', `
49  define(`ADDSUB',	adds)
50  define(`ADDSUBC',	adcs)
51  define(`CLRCY',	`cmn	r0, #0')
52  define(`SETCY',	`cmp	$1, #1')
53  define(`RETVAL',	`adc	r0, n, #0')
54  define(`func',	mpn_add_n)
55  define(`func_nc',	mpn_add_nc)')
56ifdef(`OPERATION_sub_n', `
57  define(`ADDSUB',	subs)
58  define(`ADDSUBC',	sbcs)
59  define(`CLRCY',	`cmp	r0, r0')
60  define(`SETCY',	`rsbs	$1, $1, #0')
61  define(`RETVAL',	`sbc	r0, r0, r0
62			and	r0, r0, #1')
63  define(`func',	mpn_sub_n)
64  define(`func_nc',	mpn_sub_nc)')
65
66MULFUNC_PROLOGUE(mpn_add_n mpn_add_nc mpn_sub_n mpn_sub_nc)
67
68ASM_START()
69PROLOGUE(func_nc)
70	ldr	r12, [sp, #0]
71	stmfd	sp!, { r8, r9, lr }
72	SETCY(	r12)
73	b	L(ent)
74EPILOGUE()
75PROLOGUE(func)
76	stmfd	sp!, { r8, r9, lr }
77	CLRCY(	r12)
78L(ent):	tst	n, #1
79	beq	L(skip1)
80	ldr	r12, [up], #4
81	ldr	lr, [vp], #4
82	ADDSUBC	r12, r12, lr
83	str	r12, [rp], #4
84L(skip1):
85	tst	n, #2
86	beq	L(skip2)
87	ldmia	up!, { r8, r9 }
88	ldmia	vp!, { r12, lr }
89	ADDSUBC	r8, r8, r12
90	ADDSUBC	r9, r9, lr
91	stmia	rp!, { r8, r9 }
92L(skip2):
93	bics	n, n, #3
94	beq	L(rtn)
95	stmfd	sp!, { r4, r5, r6, r7 }
96
97L(top):	ldmia	up!, { r4, r5, r6, r7 }
98	ldmia	vp!, { r8, r9, r12, lr }
99	ADDSUBC	r4, r4, r8
100	sub	n, n, #4
101	ADDSUBC	r5, r5, r9
102	ADDSUBC	r6, r6, r12
103	ADDSUBC	r7, r7, lr
104	stmia	rp!, { r4, r5, r6, r7 }
105	teq	n, #0
106	bne	L(top)
107
108	ldmfd	sp!, { r4, r5, r6, r7 }
109
110L(rtn):	RETVAL
111	ldmfd	sp!, { r8, r9, pc }
112EPILOGUE()
113