xref: /netbsd-src/external/lgpl3/gmp/dist/mpn/power/add_n.asm (revision fdd524d4ccd2bb0c6f67401e938dabf773eb0372)
1dnl  IBM POWER mpn_add_n -- Add two limb vectors of equal, non-zero length.
2
3dnl  Copyright 1992, 1994, 1995, 1996, 1999, 2000, 2001, 2005 Free Software
4dnl  Foundation, Inc.
5
6dnl  This file is part of the GNU MP Library.
7
8dnl  The GNU MP Library is free software; you can redistribute it and/or modify
9dnl  it under the terms of the GNU Lesser General Public License as published
10dnl  by the Free Software Foundation; either version 3 of the License, or (at
11dnl  your option) any later version.
12
13dnl  The GNU MP Library is distributed in the hope that it will be useful, but
14dnl  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15dnl  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
16dnl  License for more details.
17
18dnl  You should have received a copy of the GNU Lesser General Public License
19dnl  along with the GNU MP Library.  If not, see http://www.gnu.org/licenses/.
20
21
22dnl  INPUT PARAMETERS
23dnl  res_ptr	r3
24dnl  s1_ptr	r4
25dnl  s2_ptr	r5
26dnl  size	r6
27
28include(`../config.m4')
29
30ASM_START()
31PROLOGUE(mpn_add_n)
32	andil.	10,6,1		C odd or even number of limbs?
33	l	8,0(4)		C load least significant s1 limb
34	l	0,0(5)		C load least significant s2 limb
35	cal	3,-4(3)		C offset res_ptr, it's updated before it's used
36	sri	10,6,1		C count for unrolled loop
37	a	7,0,8		C add least significant limbs, set cy
38	mtctr	10		C copy count into CTR
39	beq	0,Leven		C branch if even # of limbs (# of limbs >= 2)
40
41C We have an odd # of limbs.  Add the first limbs separately.
42	cmpi	1,10,0		C is count for unrolled loop zero?
43	bc	4,6,L1		C bne cr1,L1 (misassembled by gas)
44	st	7,4(3)
45	aze	3,10		C use the fact that r10 is zero...
46	br			C return
47
48C We added least significant limbs.  Now reload the next limbs to enter loop.
49L1:	lu	8,4(4)		C load s1 limb and update s1_ptr
50	lu	0,4(5)		C load s2 limb and update s2_ptr
51	stu	7,4(3)
52	ae	7,0,8		C add limbs, set cy
53Leven:	lu	9,4(4)		C load s1 limb and update s1_ptr
54	lu	10,4(5)		C load s2 limb and update s2_ptr
55	bdz	Lend		C If done, skip loop
56
57Loop:	lu	8,4(4)		C load s1 limb and update s1_ptr
58	lu	0,4(5)		C load s2 limb and update s2_ptr
59	ae	11,10,9		C add previous limbs with cy, set cy
60	stu	7,4(3)		C
61	lu	9,4(4)		C load s1 limb and update s1_ptr
62	lu	10,4(5)		C load s2 limb and update s2_ptr
63	ae	7,0,8		C add previous limbs with cy, set cy
64	stu	11,4(3)		C
65	bdn	Loop		C decrement CTR and loop back
66
67Lend:	ae	11,10,9		C add limbs with cy, set cy
68	st	7,4(3)		C
69	st	11,8(3)		C
70	lil	3,0		C load cy into ...
71	aze	3,3		C ... return value register
72	br
73EPILOGUE(mpn_add_n)
74