1656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#!/usr/bin/env perl
2656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
3656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project# ====================================================================
4656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project# Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
5656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project# project. The module is, however, dual licensed under OpenSSL and
6656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project# CRYPTOGAMS licenses depending on where you obtain it. For further
7656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project# details see http://www.openssl.org/~appro/cryptogams/.
8656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project# ====================================================================
9656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
10656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project# January 2007.
11656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
12656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project# Montgomery multiplication for ARMv4.
13656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#
14656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project# Performance improvement naturally varies among CPU implementations
15656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project# and compilers. The code was observed to provide +65-35% improvement
16656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project# [depending on key length, less for longer keys] on ARM920T, and
17656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project# +115-80% on Intel IXP425. This is compared to pre-bn_mul_mont code
18656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project# base and compiler generated code with in-lined umull and even umlal
19656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project# instructions. The latter means that this code didn't really have an
20656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project# "advantage" of utilizing some "secret" instruction.
21656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#
22656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project# The code is interoperable with Thumb ISA and is rather compact, less
23656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project# than 1/2KB. Windows CE port would be trivial, as it's exclusively
24656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project# about decorations, ABI and instruction syntax are identical.
25656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
26392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstromwhile (($output=shift) && ($output!~/^\w[\w\-]*\.\w+$/)) {}
27392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstromopen STDOUT,">$output";
28392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom
29656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project$num="r0";	# starts as num argument, but holds &tp[num-1]
30656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project$ap="r1";
31656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project$bp="r2"; $bi="r2"; $rp="r2";
32656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project$np="r3";
33656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project$tp="r4";
34656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project$aj="r5";
35656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project$nj="r6";
36656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project$tj="r7";
37656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project$n0="r8";
38656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project###########	# r9 is reserved by ELF as platform specific, e.g. TLS pointer
39656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project$alo="r10";	# sl, gcc uses it to keep @GOT
40656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project$ahi="r11";	# fp
41656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project$nlo="r12";	# ip
42656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project###########	# r13 is stack pointer
43656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project$nhi="r14";	# lr
44656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project###########	# r15 is program counter
45656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
46656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#### argument block layout relative to &tp[num-1], a.k.a. $num
47656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project$_rp="$num,#12*4";
48656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project# ap permanently resides in r1
49656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project$_bp="$num,#13*4";
50656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project# np permanently resides in r3
51656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project$_n0="$num,#14*4";
52656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project$_num="$num,#15*4";	$_bpend=$_num;
53656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
54656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project$code=<<___;
55656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project.text
56656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
57656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project.global	bn_mul_mont
58656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project.type	bn_mul_mont,%function
59656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
60656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project.align	2
61656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectbn_mul_mont:
62656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	stmdb	sp!,{r0,r2}		@ sp points at argument block
63656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	ldr	$num,[sp,#3*4]		@ load num
64656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	cmp	$num,#2
65656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	movlt	r0,#0
66656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	addlt	sp,sp,#2*4
67656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	blt	.Labrt
68656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
69656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	stmdb	sp!,{r4-r12,lr}		@ save 10 registers
70656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
71656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	mov	$num,$num,lsl#2		@ rescale $num for byte count
72656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	sub	sp,sp,$num		@ alloca(4*num)
73656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	sub	sp,sp,#4		@ +extra dword
74656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	sub	$num,$num,#4		@ "num=num-1"
75656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	add	$tp,$bp,$num		@ &bp[num-1]
76656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
77656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	add	$num,sp,$num		@ $num to point at &tp[num-1]
78656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	ldr	$n0,[$_n0]		@ &n0
79656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	ldr	$bi,[$bp]		@ bp[0]
80656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	ldr	$aj,[$ap],#4		@ ap[0],ap++
81656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	ldr	$nj,[$np],#4		@ np[0],np++
82656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	ldr	$n0,[$n0]		@ *n0
83656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	str	$tp,[$_bpend]		@ save &bp[num]
84656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
85656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	umull	$alo,$ahi,$aj,$bi	@ ap[0]*bp[0]
86656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	str	$n0,[$_n0]		@ save n0 value
87656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	mul	$n0,$alo,$n0		@ "tp[0]"*n0
88656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	mov	$nlo,#0
89656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	umlal	$alo,$nlo,$nj,$n0	@ np[0]*n0+"t[0]"
90656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	mov	$tp,sp
91656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
92656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project.L1st:
93656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	ldr	$aj,[$ap],#4		@ ap[j],ap++
94656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	mov	$alo,$ahi
95392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom	ldr	$nj,[$np],#4		@ np[j],np++
96656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	mov	$ahi,#0
97656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	umlal	$alo,$ahi,$aj,$bi	@ ap[j]*bp[0]
98656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	mov	$nhi,#0
99656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	umlal	$nlo,$nhi,$nj,$n0	@ np[j]*n0
100656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	adds	$nlo,$nlo,$alo
101656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	str	$nlo,[$tp],#4		@ tp[j-1]=,tp++
102656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	adc	$nlo,$nhi,#0
103656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	cmp	$tp,$num
104656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	bne	.L1st
105656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
106656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	adds	$nlo,$nlo,$ahi
107392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom	ldr	$tp,[$_bp]		@ restore bp
108656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	mov	$nhi,#0
109392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom	ldr	$n0,[$_n0]		@ restore n0
110656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	adc	$nhi,$nhi,#0
111656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	str	$nlo,[$num]		@ tp[num-1]=
112656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	str	$nhi,[$num,#4]		@ tp[num]=
113656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
114656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project.Louter:
115656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	sub	$tj,$num,sp		@ "original" $num-1 value
116656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	sub	$ap,$ap,$tj		@ "rewind" ap to &ap[1]
117656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	ldr	$bi,[$tp,#4]!		@ *(++bp)
118392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom	sub	$np,$np,$tj		@ "rewind" np to &np[1]
119656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	ldr	$aj,[$ap,#-4]		@ ap[0]
120656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	ldr	$alo,[sp]		@ tp[0]
121392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom	ldr	$nj,[$np,#-4]		@ np[0]
122656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	ldr	$tj,[sp,#4]		@ tp[1]
123656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
124656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	mov	$ahi,#0
125656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	umlal	$alo,$ahi,$aj,$bi	@ ap[0]*bp[i]+tp[0]
126656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	str	$tp,[$_bp]		@ save bp
127656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	mul	$n0,$alo,$n0
128656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	mov	$nlo,#0
129656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	umlal	$alo,$nlo,$nj,$n0	@ np[0]*n0+"tp[0]"
130656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	mov	$tp,sp
131656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
132656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project.Linner:
133656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	ldr	$aj,[$ap],#4		@ ap[j],ap++
134656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	adds	$alo,$ahi,$tj		@ +=tp[j]
135392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom	ldr	$nj,[$np],#4		@ np[j],np++
136656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	mov	$ahi,#0
137656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	umlal	$alo,$ahi,$aj,$bi	@ ap[j]*bp[i]
138656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	mov	$nhi,#0
139656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	umlal	$nlo,$nhi,$nj,$n0	@ np[j]*n0
140656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	adc	$ahi,$ahi,#0
141392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom	ldr	$tj,[$tp,#8]		@ tp[j+1]
142656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	adds	$nlo,$nlo,$alo
143656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	str	$nlo,[$tp],#4		@ tp[j-1]=,tp++
144656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	adc	$nlo,$nhi,#0
145656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	cmp	$tp,$num
146656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	bne	.Linner
147656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
148656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	adds	$nlo,$nlo,$ahi
149656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	mov	$nhi,#0
150392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom	ldr	$tp,[$_bp]		@ restore bp
151656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	adc	$nhi,$nhi,#0
152392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom	ldr	$n0,[$_n0]		@ restore n0
153656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	adds	$nlo,$nlo,$tj
154656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	ldr	$tj,[$_bpend]		@ restore &bp[num]
155392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom	adc	$nhi,$nhi,#0
156656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	str	$nlo,[$num]		@ tp[num-1]=
157656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	str	$nhi,[$num,#4]		@ tp[num]=
158656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
159656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	cmp	$tp,$tj
160656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	bne	.Louter
161656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
162656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	ldr	$rp,[$_rp]		@ pull rp
163656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	add	$num,$num,#4		@ $num to point at &tp[num]
164656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	sub	$aj,$num,sp		@ "original" num value
165656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	mov	$tp,sp			@ "rewind" $tp
166656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	mov	$ap,$tp			@ "borrow" $ap
167656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	sub	$np,$np,$aj		@ "rewind" $np to &np[0]
168656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
169656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	subs	$tj,$tj,$tj		@ "clear" carry flag
170656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project.Lsub:	ldr	$tj,[$tp],#4
171656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	ldr	$nj,[$np],#4
172656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	sbcs	$tj,$tj,$nj		@ tp[j]-np[j]
173656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	str	$tj,[$rp],#4		@ rp[j]=
174656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	teq	$tp,$num		@ preserve carry
175656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	bne	.Lsub
176656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	sbcs	$nhi,$nhi,#0		@ upmost carry
177656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	mov	$tp,sp			@ "rewind" $tp
178656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	sub	$rp,$rp,$aj		@ "rewind" $rp
179656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
180656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	and	$ap,$tp,$nhi
181656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	bic	$np,$rp,$nhi
182656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	orr	$ap,$ap,$np		@ ap=borrow?tp:rp
183656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
184656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project.Lcopy:	ldr	$tj,[$ap],#4		@ copy or in-place refresh
185656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	str	sp,[$tp],#4		@ zap tp
186656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	str	$tj,[$rp],#4
187656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	cmp	$tp,$num
188656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	bne	.Lcopy
189656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
190656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	add	sp,$num,#4		@ skip over tp[num+1]
191656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	ldmia	sp!,{r4-r12,lr}		@ restore registers
192656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	add	sp,sp,#2*4		@ skip over {r0,r2}
193656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	mov	r0,#1
194656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project.Labrt:	tst	lr,#1
195656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	moveq	pc,lr			@ be binary compatible with V4, yet
196656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	bx	lr			@ interoperable with Thumb ISA:-)
197656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project.size	bn_mul_mont,.-bn_mul_mont
198656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project.asciz	"Montgomery multiplication for ARMv4, CRYPTOGAMS by <appro\@openssl.org>"
199221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom.align	2
200656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project___
201656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
202656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project$code =~ s/\bbx\s+lr\b/.word\t0xe12fff1e/gm;	# make it possible to compile with -march=armv4
203656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectprint $code;
204656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectclose STDOUT;
205