Debian Codegraph @

mpi/powerpc32/mpih-sub1.S

raw
1 /* PowerPC-32 sub_n -- Subtract two limb vectors of the same length > 0
2 * and store difference in a third limb vector.
3 *
4 * Copyright (C) 1992, 1994, 1995, 1998,
5 * 2002 Free Software Foundation, Inc.
6 *
7 * This file is part of Libgcrypt.
8 *
9 * Libgcrypt is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser General Public License as
11 * published by the Free Software Foundation; either version 2.1 of
12 * the License, or (at your option) any later version.
13 *
14 * Libgcrypt is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this program; if not, see <https://www.gnu.org/licenses/>.
21 * SPDX-License-Identifier: LGPL-2.1-or-later
22 */
23
24 #include "sysdep.h"
25 #include "asm-syntax.h"
26
27
28 #ifndef USE_PPC_PATCHES
29
30 /*******************
31 * mpi_limb_t
32 * _gcry_mpih_sub_n( mpi_ptr_t res_ptr, (r3)
33 * mpi_ptr_t s1_ptr, (r4)
34 * mpi_ptr_t s2_ptr, (r5)
35 * mpi_size_t size) (r6)
36 */
37
38 .toc
39 .extern _gcry_mpih_sub_n[DS]
40 .extern ._gcry_mpih_sub_n
41 .csect [PR]
42 .align 2
43 .globl _gcry_mpih_sub_n
44 .globl ._gcry_mpih_sub_n
45 .csect _gcry_mpih_sub_n[DS]
46 _gcry_mpih_sub_n:
47 .long ._gcry_mpih_sub_n, TOC[tc0], 0
48 .csect [PR]
49 ._gcry_mpih_sub_n:
50 mtctr 6 # copy size into CTR
51 lwz 8,0(4) # load least significant s1 limb
52 lwz 0,0(5) # load least significant s2 limb
53 addi 3,3,-4 # offset res_ptr, it is updated before used
54 subfc 7,0,8 # add least significant limbs, set cy
55 bdz Lend # If done, skip loop
56 Loop: lwzu 8,4(4) # load s1 limb and update s1_ptr
57 lwzu 0,4(5) # load s2 limb and update s2_ptr
58 stwu 7,4(3) # store previous limb in load latency slot
59 subfe 7,0,8 # add new limbs with cy, set cy
60 bdnz Loop # decrement CTR and loop back
61 Lend: stw 7,4(3) # store ultimate result limb
62 subfe 3,0,0 # load !cy into ...
63 subfic 3,3,0 # ... return value register
64 blr
65
66 #else
67 /* Subtract two limb vectors of equal, non-zero length for PowerPC.
68 Copyright (C) 1997 Free Software Foundation, Inc.
69 This file is part of the GNU C Library.
70
71 The GNU C Library is free software; you can redistribute it and/or
72 modify it under the terms of the GNU Library General Public License as
73 published by the Free Software Foundation; either version 2 of the
74 License, or (at your option) any later version.
75
76 The GNU C Library is distributed in the hope that it will be useful,
77 but WITHOUT ANY WARRANTY; without even the implied warranty of
78 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
79 Library General Public License for more details.
80
81 You should have received a copy of the GNU Library General Public
82 License along with the GNU C Library; see the file COPYING.LIB. If not,
83 see <https://www.gnu.org/licenses/>.
84 SPDX-License-Identifier: LGPL-2.1-or-later
85 */
86
87 /* mp_limb_t mpn_sub_n (mp_ptr res_ptr, mp_srcptr s1_ptr, mp_srcptr s2_ptr,
88 mp_size_t size)
89 Calculate s1-s2 and put result in res_ptr; return borrow, 0 or 1. */
90
91 /* Note on optimisation: This code is optimal for the 601. Almost every other
92 possible 2-unrolled inner loop will not be. Also, watch out for the
93 alignment... */
94
95 EALIGN(_gcry_mpih_sub_n,3,1)
96 /* Set up for loop below. */
97 mtcrf 0x01,%r6
98 srwi. %r7,%r6,1
99 mtctr %r7
100 bt 31,2f
101
102 /* Set the carry (clear the borrow). */
103 subfc %r0,%r0,%r0
104 /* Adjust pointers for loop. */
105 addi %r3,%r3,-4
106 addi %r4,%r4,-4
107 addi %r5,%r5,-4
108 b 0f
109
110 2: lwz %r7,0(%r5)
111 lwz %r6,0(%r4)
112 subfc %r6,%r7,%r6
113 stw %r6,0(%r3)
114 beq 1f
115
116 /* Align start of loop to an odd word boundary to guarantee that the
117 last two words can be fetched in one access (for 601). This turns
118 out to be important. */
119 0:
120 lwz %r9,4(%r4)
121 lwz %r8,4(%r5)
122 lwzu %r6,8(%r4)
123 lwzu %r7,8(%r5)
124 subfe %r8,%r8,%r9
125 stw %r8,4(%r3)
126 subfe %r6,%r7,%r6
127 stwu %r6,8(%r3)
128 bdnz 0b
129 /* Return the borrow. */
130 1: subfe %r3,%r3,%r3
131 neg %r3,%r3
132 blr
133 END(_gcry_mpih_sub_n)
134 #endif