• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /netgear-WNDR4500-V1.0.1.40_1.0.68/ap/gpl/timemachine/libgcrypt-1.5.0/mpi/powerpc32/
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, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
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
56Loop:	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
61Lend:	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   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
84   Boston, MA 02111-1307, USA.	*/
85
86/* mp_limb_t mpn_sub_n (mp_ptr res_ptr, mp_srcptr s1_ptr, mp_srcptr s2_ptr,
87			mp_size_t size)
88   Calculate s1-s2 and put result in res_ptr; return borrow, 0 or 1.  */
89
90/* Note on optimisation: This code is optimal for the 601.  Almost every other
91   possible 2-unrolled inner loop will not be.	Also, watch out for the
92   alignment...  */
93
94EALIGN(_gcry_mpih_sub_n,3,1)
95/* Set up for loop below.  */
96       mtcrf 0x01,%r6
97       srwi. %r7,%r6,1
98       mtctr %r7
99       bt    31,2f
100
101/* Set the carry (clear the borrow).  */
102       subfc %r0,%r0,%r0
103/* Adjust pointers for loop.  */
104       addi  %r3,%r3,-4
105       addi  %r4,%r4,-4
106       addi  %r5,%r5,-4
107       b     0f
108
1092:     lwz   %r7,0(%r5)
110       lwz   %r6,0(%r4)
111       subfc %r6,%r7,%r6
112       stw   %r6,0(%r3)
113	beq   1f
114
115/* Align start of loop to an odd word boundary to guarantee that the
116   last two words can be fetched in one access (for 601).  This turns
117   out to be important.  */
1180:
119       lwz   %r9,4(%r4)
120       lwz   %r8,4(%r5)
121       lwzu  %r6,8(%r4)
122       lwzu  %r7,8(%r5)
123       subfe %r8,%r8,%r9
124       stw   %r8,4(%r3)
125       subfe %r6,%r7,%r6
126       stwu  %r6,8(%r3)
127       bdnz  0b
128/* Return the borrow. */
1291:     subfe %r3,%r3,%r3
130       neg   %r3,%r3
131       blr
132END(_gcry_mpih_sub_n)
133#endif
134