1dnl  PowerPC-64/mode32 mpn_add_n -- Add two limb vectors of the same length > 0
2dnl  and store sum in a third limb vector.
3
4dnl  Copyright 1999-2001, 2003, 2005 Free Software Foundation, Inc.
5
6dnl  This file is part of the GNU MP Library.
7dnl
8dnl  The GNU MP Library is free software; you can redistribute it and/or modify
9dnl  it under the terms of either:
10dnl
11dnl    * the GNU Lesser General Public License as published by the Free
12dnl      Software Foundation; either version 3 of the License, or (at your
13dnl      option) any later version.
14dnl
15dnl  or
16dnl
17dnl    * the GNU General Public License as published by the Free Software
18dnl      Foundation; either version 2 of the License, or (at your option) any
19dnl      later version.
20dnl
21dnl  or both in parallel, as here.
22dnl
23dnl  The GNU MP Library is distributed in the hope that it will be useful, but
24dnl  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
25dnl  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
26dnl  for more details.
27dnl
28dnl  You should have received copies of the GNU General Public License and the
29dnl  GNU Lesser General Public License along with the GNU MP Library.  If not,
30dnl  see https://www.gnu.org/licenses/.
31
32include(`../config.m4')
33
34C                   cycles/limb
35C POWER3/PPC630:     ?
36C POWER4/PPC970:     4.25
37
38C INPUT PARAMETERS
39C rp      r3
40C up      r4
41C vp      r5
42C n       r6
43
44ASM_START()
45PROLOGUE(mpn_add_n)
46          mtctr     r6                  C copy size into CTR
47          addic     r0, r0, 0 C clear cy
48          ld        r8, 0(r4) C load least significant s1 limb
49          ld        r0, 0(r5) C load least significant s2 limb
50          addi      r3, r3, -8          C offset res_ptr, it's updated before it's used
51          bdz       L(end)              C If done, skip loop
52
53L(oop):   ld        r9, 8(r4) C load s1 limb
54          ld        r10, 8(r5)          C load s2 limb
55          adde      r7, r0, r8          C add limbs with cy, set cy
56          srdi      r6, r0, 32
57          srdi      r11, r8, 32
58          adde      r6, r6, r11         C add high limb parts, set cy
59          std       r7, 8(r3) C store result limb
60          bdz       L(exit)             C decrement CTR and exit if done
61          ldu       r8, 16(r4)          C load s1 limb and update s1_ptr
62          ldu       r0, 16(r5)          C load s2 limb and update s2_ptr
63          adde      r7, r10, r9         C add limbs with cy, set cy
64          srdi      r6, r10, 32
65          srdi      r11, r9, 32
66          adde      r6, r6, r11         C add high limb parts, set cy
67          stdu      r7, 16(r3)          C store result limb and update res_ptr
68          bdnz      L(oop)              C decrement CTR and loop back
69
70L(end):   adde      r7, r0, r8
71          srdi      r6, r0, 32
72          srdi      r11, r8, 32
73          adde      r6, r6, r11         C add limbs with cy, set cy
74          std       r7, 8(r3) C store ultimate result limb
75          li        r3, 0               C load cy into ...
76          addze     r4, r3              C ... return value register
77          blr
78L(exit):  adde      r7, r10, r9
79          srdi      r6, r10, 32
80          srdi      r11, r9, 32
81          adde      r6, r6, r11         C add limbs with cy, set cy
82          std       r7, 16(r3)
83          li        r3, 0               C load cy into ...
84          addze     r4, r3              C ... return value register
85          blr
86EPILOGUE()
87