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