1dnl  ARM mpn_add_n -- Add two limb vectors of the same length > 0 and store sum
2dnl  in a third limb vector.
3dnl  Contributed by Robert Harley.
4
5dnl  Copyright 1997, 2000, 2001 Free Software Foundation, Inc.
6
7dnl  This file is part of the GNU MP Library.
8
9dnl  The GNU MP Library is free software; you can redistribute it and/or modify
10dnl  it under the terms of the GNU Lesser General Public License as published
11dnl  by the Free Software Foundation; either version 3 of the License, or (at
12dnl  your option) any later version.
13
14dnl  The GNU MP Library is distributed in the hope that it will be useful, but
15dnl  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16dnl  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
17dnl  License for more details.
18
19dnl  You should have received a copy of the GNU Lesser General Public License
20dnl  along with the GNU MP Library.  If not, see http://www.gnu.org/licenses/.
21
22include(`../config.m4')
23
24C This code runs at 5 cycles/limb.
25
26define(`rp',`r0')
27define(`up',`r1')
28define(`vp',`r2')
29define(`n',`r3')
30
31
32ASM_START()
33PROLOGUE(mpn_add_n)
34	stmfd	sp!, { r8, r9, lr }
35	movs	n, n, lsr #1
36	bcc	L(skip1)
37	ldr	r12, [up], #4
38	ldr	lr, [vp], #4
39	adds	r12, r12, lr
40	str	r12, [rp], #4
41L(skip1):
42	tst	n, #1
43	beq	L(skip2)
44	ldmia	up!, { r8, r9 }
45	ldmia	vp!, { r12, lr }
46	adcs	r8, r8, r12
47	adcs	r9, r9, lr
48	stmia	rp!, { r8, r9 }
49L(skip2):
50	bics	n, n, #1
51	beq	L(return)
52	stmfd	sp!, { r4, r5, r6, r7 }
53L(add_n_loop):
54	ldmia	up!, { r4, r5, r6, r7 }
55	ldmia	vp!, { r8, r9, r12, lr }
56	adcs	r4, r4, r8
57	ldr	r8, [rp, #12]			C cache allocate
58	adcs	r5, r5, r9
59	adcs	r6, r6, r12
60	adcs	r7, r7, lr
61	stmia	rp!, { r4, r5, r6, r7 }
62	sub	n, n, #2
63	teq	n, #0
64	bne	L(add_n_loop)
65	ldmfd	sp!, { r4, r5, r6, r7 }
66L(return):
67	adc	r0, n, #0
68	ldmfd	sp!, { r8, r9, pc }
69EPILOGUE(mpn_add_n)
70