1/* IBM POWER add_n -- Add two limb vectors of equal, non-zero length.
2 *
3 *      Copyright (C) 1992, 1994, 1996, 1999,
4 *                    2002 Free Software Foundation, Inc.
5 *
6 * This file is part of Libgcrypt.
7 *
8 * Libgcrypt is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as
10 * published by the Free Software Foundation; either version 2.1 of
11 * the License, or (at your option) any later version.
12 *
13 * Libgcrypt is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 * GNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
21 */
22
23#include "sysdep.h"
24#include "asm-syntax.h"
25
26/*
27# INPUT PARAMETERS
28# res_ptr	r3
29# s1_ptr	r4
30# s2_ptr	r5
31# size		r6
32 */
33
34	.toc
35	.extern _gcry_mpih_add_n[DS]
36	.extern ._gcry_mpih_add_n
37.csect [PR]
38	.align 2
39	.globl _gcry_mpih_add_n
40	.globl ._gcry_mpih_add_n
41	.csect _gcry_mpih_add_n[DS]
42_gcry_mpih_add_n:
43	.long ._gcry_mpih_add_n, TOC[tc0], 0
44	.csect [PR]
45._gcry_mpih_add_n:
46	andil.	10,6,1		# odd or even number of limbs?
47	l	8,0(4)		# load least significant s1 limb
48	l	0,0(5)		# load least significant s2 limb
49	cal	3,-4(3) 	# offset res_ptr, it's updated before it's used
50	sri	10,6,1		# count for unrolled loop
51	a	7,0,8		# add least significant limbs, set cy
52	mtctr	10		# copy count into CTR
53	beq	0,Leven 	# branch if even # of limbs (# of limbs >= 2)
54
55# We have an odd # of limbs.  Add the first limbs separately.
56	cmpi	1,10,0		# is count for unrolled loop zero?
57	bne	1,L1		# branch if not
58	st	7,4(3)
59	aze	3,10		# use the fact that r10 is zero...
60	br			# return
61
62# We added least significant limbs.  Now reload the next limbs to enter loop.
63L1:	lu	8,4(4)		# load s1 limb and update s1_ptr
64	lu	0,4(5)		# load s2 limb and update s2_ptr
65	stu	7,4(3)
66	ae	7,0,8		# add limbs, set cy
67Leven:	lu	9,4(4)		# load s1 limb and update s1_ptr
68	lu	10,4(5) 	# load s2 limb and update s2_ptr
69	bdz	Lend		# If done, skip loop
70
71Loop:	lu	8,4(4)		# load s1 limb and update s1_ptr
72	lu	0,4(5)		# load s2 limb and update s2_ptr
73	ae	11,9,10 	# add previous limbs with cy, set cy
74	stu	7,4(3)		#
75	lu	9,4(4)		# load s1 limb and update s1_ptr
76	lu	10,4(5) 	# load s2 limb and update s2_ptr
77	ae	7,0,8		# add previous limbs with cy, set cy
78	stu	11,4(3) 	#
79	bdn	Loop		# decrement CTR and loop back
80
81Lend:	ae	11,9,10 	# add limbs with cy, set cy
82	st	7,4(3)		#
83	st	11,8(3) 	#
84	lil	3,0		# load cy into ...
85	aze	3,3		# ... return value register
86	br
87
88