1e1051a39Sopenharmony_ci#! /usr/bin/env perl
2e1051a39Sopenharmony_ci# Copyright 2011-2020 The OpenSSL Project Authors. All Rights Reserved.
3e1051a39Sopenharmony_ci#
4e1051a39Sopenharmony_ci# Licensed under the Apache License 2.0 (the "License").  You may not use
5e1051a39Sopenharmony_ci# this file except in compliance with the License.  You can obtain a copy
6e1051a39Sopenharmony_ci# in the file LICENSE in the source distribution or at
7e1051a39Sopenharmony_ci# https://www.openssl.org/source/license.html
8e1051a39Sopenharmony_ci
9e1051a39Sopenharmony_ci#
10e1051a39Sopenharmony_ci# ====================================================================
11e1051a39Sopenharmony_ci# Written by Andy Polyakov <appro@openssl.org> for the OpenSSL
12e1051a39Sopenharmony_ci# project. The module is, however, dual licensed under OpenSSL and
13e1051a39Sopenharmony_ci# CRYPTOGAMS licenses depending on where you obtain it. For further
14e1051a39Sopenharmony_ci# details see http://www.openssl.org/~appro/cryptogams/.
15e1051a39Sopenharmony_ci# ====================================================================
16e1051a39Sopenharmony_ci#
17e1051a39Sopenharmony_ci# May 2011
18e1051a39Sopenharmony_ci#
19e1051a39Sopenharmony_ci# The module implements bn_GF2m_mul_2x2 polynomial multiplication
20e1051a39Sopenharmony_ci# used in bn_gf2m.c. It's kind of low-hanging mechanical port from
21e1051a39Sopenharmony_ci# C for the time being... Except that it has two code paths: pure
22e1051a39Sopenharmony_ci# integer code suitable for any ARMv4 and later CPU and NEON code
23e1051a39Sopenharmony_ci# suitable for ARMv7. Pure integer 1x1 multiplication subroutine runs
24e1051a39Sopenharmony_ci# in ~45 cycles on dual-issue core such as Cortex A8, which is ~50%
25e1051a39Sopenharmony_ci# faster than compiler-generated code. For ECDH and ECDSA verify (but
26e1051a39Sopenharmony_ci# not for ECDSA sign) it means 25%-45% improvement depending on key
27e1051a39Sopenharmony_ci# length, more for longer keys. Even though NEON 1x1 multiplication
28e1051a39Sopenharmony_ci# runs in even less cycles, ~30, improvement is measurable only on
29e1051a39Sopenharmony_ci# longer keys. One has to optimize code elsewhere to get NEON glow...
30e1051a39Sopenharmony_ci#
31e1051a39Sopenharmony_ci# April 2014
32e1051a39Sopenharmony_ci#
33e1051a39Sopenharmony_ci# Double bn_GF2m_mul_2x2 performance by using algorithm from paper
34e1051a39Sopenharmony_ci# referred below, which improves ECDH and ECDSA verify benchmarks
35e1051a39Sopenharmony_ci# by 18-40%.
36e1051a39Sopenharmony_ci#
37e1051a39Sopenharmony_ci# Câmara, D.; Gouvêa, C. P. L.; López, J. & Dahab, R.: Fast Software
38e1051a39Sopenharmony_ci# Polynomial Multiplication on ARM Processors using the NEON Engine.
39e1051a39Sopenharmony_ci#
40e1051a39Sopenharmony_ci# http://conradoplg.cryptoland.net/files/2010/12/mocrysen13.pdf
41e1051a39Sopenharmony_ci
42e1051a39Sopenharmony_ci# $output is the last argument if it looks like a file (it has an extension)
43e1051a39Sopenharmony_ci# $flavour is the first argument if it doesn't look like a file
44e1051a39Sopenharmony_ci$output = $#ARGV >= 0 && $ARGV[$#ARGV] =~ m|\.\w+$| ? pop : undef;
45e1051a39Sopenharmony_ci$flavour = $#ARGV >= 0 && $ARGV[0] !~ m|\.| ? shift : undef;
46e1051a39Sopenharmony_ci
47e1051a39Sopenharmony_ciif ($flavour && $flavour ne "void") {
48e1051a39Sopenharmony_ci    $0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
49e1051a39Sopenharmony_ci    ( $xlate="${dir}arm-xlate.pl" and -f $xlate ) or
50e1051a39Sopenharmony_ci    ( $xlate="${dir}../../perlasm/arm-xlate.pl" and -f $xlate) or
51e1051a39Sopenharmony_ci    die "can't locate arm-xlate.pl";
52e1051a39Sopenharmony_ci
53e1051a39Sopenharmony_ci    open STDOUT,"| \"$^X\" $xlate $flavour \"$output\""
54e1051a39Sopenharmony_ci        or die "can't call $xlate: $1";
55e1051a39Sopenharmony_ci} else {
56e1051a39Sopenharmony_ci    $output and open STDOUT,">$output";
57e1051a39Sopenharmony_ci}
58e1051a39Sopenharmony_ci
59e1051a39Sopenharmony_ci$code=<<___;
60e1051a39Sopenharmony_ci#include "arm_arch.h"
61e1051a39Sopenharmony_ci
62e1051a39Sopenharmony_ci#if defined(__thumb2__)
63e1051a39Sopenharmony_ci.syntax	unified
64e1051a39Sopenharmony_ci.thumb
65e1051a39Sopenharmony_ci#else
66e1051a39Sopenharmony_ci.code	32
67e1051a39Sopenharmony_ci#endif
68e1051a39Sopenharmony_ci
69e1051a39Sopenharmony_ci.text
70e1051a39Sopenharmony_ci___
71e1051a39Sopenharmony_ci################
72e1051a39Sopenharmony_ci# private interface to mul_1x1_ialu
73e1051a39Sopenharmony_ci#
74e1051a39Sopenharmony_ci$a="r1";
75e1051a39Sopenharmony_ci$b="r0";
76e1051a39Sopenharmony_ci
77e1051a39Sopenharmony_ci($a0,$a1,$a2,$a12,$a4,$a14)=
78e1051a39Sopenharmony_ci($hi,$lo,$t0,$t1, $i0,$i1 )=map("r$_",(4..9),12);
79e1051a39Sopenharmony_ci
80e1051a39Sopenharmony_ci$mask="r12";
81e1051a39Sopenharmony_ci
82e1051a39Sopenharmony_ci$code.=<<___;
83e1051a39Sopenharmony_ci.type	mul_1x1_ialu,%function
84e1051a39Sopenharmony_ci.align	5
85e1051a39Sopenharmony_cimul_1x1_ialu:
86e1051a39Sopenharmony_ci	mov	$a0,#0
87e1051a39Sopenharmony_ci	bic	$a1,$a,#3<<30		@ a1=a&0x3fffffff
88e1051a39Sopenharmony_ci	str	$a0,[sp,#0]		@ tab[0]=0
89e1051a39Sopenharmony_ci	add	$a2,$a1,$a1		@ a2=a1<<1
90e1051a39Sopenharmony_ci	str	$a1,[sp,#4]		@ tab[1]=a1
91e1051a39Sopenharmony_ci	eor	$a12,$a1,$a2		@ a1^a2
92e1051a39Sopenharmony_ci	str	$a2,[sp,#8]		@ tab[2]=a2
93e1051a39Sopenharmony_ci	mov	$a4,$a1,lsl#2		@ a4=a1<<2
94e1051a39Sopenharmony_ci	str	$a12,[sp,#12]		@ tab[3]=a1^a2
95e1051a39Sopenharmony_ci	eor	$a14,$a1,$a4		@ a1^a4
96e1051a39Sopenharmony_ci	str	$a4,[sp,#16]		@ tab[4]=a4
97e1051a39Sopenharmony_ci	eor	$a0,$a2,$a4		@ a2^a4
98e1051a39Sopenharmony_ci	str	$a14,[sp,#20]		@ tab[5]=a1^a4
99e1051a39Sopenharmony_ci	eor	$a12,$a12,$a4		@ a1^a2^a4
100e1051a39Sopenharmony_ci	str	$a0,[sp,#24]		@ tab[6]=a2^a4
101e1051a39Sopenharmony_ci	and	$i0,$mask,$b,lsl#2
102e1051a39Sopenharmony_ci	str	$a12,[sp,#28]		@ tab[7]=a1^a2^a4
103e1051a39Sopenharmony_ci
104e1051a39Sopenharmony_ci	and	$i1,$mask,$b,lsr#1
105e1051a39Sopenharmony_ci	ldr	$lo,[sp,$i0]		@ tab[b       & 0x7]
106e1051a39Sopenharmony_ci	and	$i0,$mask,$b,lsr#4
107e1051a39Sopenharmony_ci	ldr	$t1,[sp,$i1]		@ tab[b >>  3 & 0x7]
108e1051a39Sopenharmony_ci	and	$i1,$mask,$b,lsr#7
109e1051a39Sopenharmony_ci	ldr	$t0,[sp,$i0]		@ tab[b >>  6 & 0x7]
110e1051a39Sopenharmony_ci	eor	$lo,$lo,$t1,lsl#3	@ stall
111e1051a39Sopenharmony_ci	mov	$hi,$t1,lsr#29
112e1051a39Sopenharmony_ci	ldr	$t1,[sp,$i1]		@ tab[b >>  9 & 0x7]
113e1051a39Sopenharmony_ci
114e1051a39Sopenharmony_ci	and	$i0,$mask,$b,lsr#10
115e1051a39Sopenharmony_ci	eor	$lo,$lo,$t0,lsl#6
116e1051a39Sopenharmony_ci	eor	$hi,$hi,$t0,lsr#26
117e1051a39Sopenharmony_ci	ldr	$t0,[sp,$i0]		@ tab[b >> 12 & 0x7]
118e1051a39Sopenharmony_ci
119e1051a39Sopenharmony_ci	and	$i1,$mask,$b,lsr#13
120e1051a39Sopenharmony_ci	eor	$lo,$lo,$t1,lsl#9
121e1051a39Sopenharmony_ci	eor	$hi,$hi,$t1,lsr#23
122e1051a39Sopenharmony_ci	ldr	$t1,[sp,$i1]		@ tab[b >> 15 & 0x7]
123e1051a39Sopenharmony_ci
124e1051a39Sopenharmony_ci	and	$i0,$mask,$b,lsr#16
125e1051a39Sopenharmony_ci	eor	$lo,$lo,$t0,lsl#12
126e1051a39Sopenharmony_ci	eor	$hi,$hi,$t0,lsr#20
127e1051a39Sopenharmony_ci	ldr	$t0,[sp,$i0]		@ tab[b >> 18 & 0x7]
128e1051a39Sopenharmony_ci
129e1051a39Sopenharmony_ci	and	$i1,$mask,$b,lsr#19
130e1051a39Sopenharmony_ci	eor	$lo,$lo,$t1,lsl#15
131e1051a39Sopenharmony_ci	eor	$hi,$hi,$t1,lsr#17
132e1051a39Sopenharmony_ci	ldr	$t1,[sp,$i1]		@ tab[b >> 21 & 0x7]
133e1051a39Sopenharmony_ci
134e1051a39Sopenharmony_ci	and	$i0,$mask,$b,lsr#22
135e1051a39Sopenharmony_ci	eor	$lo,$lo,$t0,lsl#18
136e1051a39Sopenharmony_ci	eor	$hi,$hi,$t0,lsr#14
137e1051a39Sopenharmony_ci	ldr	$t0,[sp,$i0]		@ tab[b >> 24 & 0x7]
138e1051a39Sopenharmony_ci
139e1051a39Sopenharmony_ci	and	$i1,$mask,$b,lsr#25
140e1051a39Sopenharmony_ci	eor	$lo,$lo,$t1,lsl#21
141e1051a39Sopenharmony_ci	eor	$hi,$hi,$t1,lsr#11
142e1051a39Sopenharmony_ci	ldr	$t1,[sp,$i1]		@ tab[b >> 27 & 0x7]
143e1051a39Sopenharmony_ci
144e1051a39Sopenharmony_ci	tst	$a,#1<<30
145e1051a39Sopenharmony_ci	and	$i0,$mask,$b,lsr#28
146e1051a39Sopenharmony_ci	eor	$lo,$lo,$t0,lsl#24
147e1051a39Sopenharmony_ci	eor	$hi,$hi,$t0,lsr#8
148e1051a39Sopenharmony_ci	ldr	$t0,[sp,$i0]		@ tab[b >> 30      ]
149e1051a39Sopenharmony_ci
150e1051a39Sopenharmony_ci#ifdef	__thumb2__
151e1051a39Sopenharmony_ci	itt	ne
152e1051a39Sopenharmony_ci#endif
153e1051a39Sopenharmony_ci	eorne	$lo,$lo,$b,lsl#30
154e1051a39Sopenharmony_ci	eorne	$hi,$hi,$b,lsr#2
155e1051a39Sopenharmony_ci	tst	$a,#1<<31
156e1051a39Sopenharmony_ci	eor	$lo,$lo,$t1,lsl#27
157e1051a39Sopenharmony_ci	eor	$hi,$hi,$t1,lsr#5
158e1051a39Sopenharmony_ci#ifdef	__thumb2__
159e1051a39Sopenharmony_ci	itt	ne
160e1051a39Sopenharmony_ci#endif
161e1051a39Sopenharmony_ci	eorne	$lo,$lo,$b,lsl#31
162e1051a39Sopenharmony_ci	eorne	$hi,$hi,$b,lsr#1
163e1051a39Sopenharmony_ci	eor	$lo,$lo,$t0,lsl#30
164e1051a39Sopenharmony_ci	eor	$hi,$hi,$t0,lsr#2
165e1051a39Sopenharmony_ci
166e1051a39Sopenharmony_ci	mov	pc,lr
167e1051a39Sopenharmony_ci.size	mul_1x1_ialu,.-mul_1x1_ialu
168e1051a39Sopenharmony_ci___
169e1051a39Sopenharmony_ci################
170e1051a39Sopenharmony_ci# void	bn_GF2m_mul_2x2(BN_ULONG *r,
171e1051a39Sopenharmony_ci#	BN_ULONG a1,BN_ULONG a0,
172e1051a39Sopenharmony_ci#	BN_ULONG b1,BN_ULONG b0);	# r[3..0]=a1a0·b1b0
173e1051a39Sopenharmony_ci{
174e1051a39Sopenharmony_ci$code.=<<___;
175e1051a39Sopenharmony_ci.global	bn_GF2m_mul_2x2
176e1051a39Sopenharmony_ci.type	bn_GF2m_mul_2x2,%function
177e1051a39Sopenharmony_ci.align	5
178e1051a39Sopenharmony_cibn_GF2m_mul_2x2:
179e1051a39Sopenharmony_ci#if __ARM_MAX_ARCH__>=7
180e1051a39Sopenharmony_ci	stmdb	sp!,{r10,lr}
181e1051a39Sopenharmony_ci	ldr	r12,.LOPENSSL_armcap
182e1051a39Sopenharmony_ci# if !defined(_WIN32)
183e1051a39Sopenharmony_ci	adr	r10,.LOPENSSL_armcap
184e1051a39Sopenharmony_ci	ldr	r12,[r12,r10]
185e1051a39Sopenharmony_ci# endif
186e1051a39Sopenharmony_ci# if defined(__APPLE__) || defined(_WIN32)
187e1051a39Sopenharmony_ci	ldr	r12,[r12]
188e1051a39Sopenharmony_ci# endif
189e1051a39Sopenharmony_ci	tst	r12,#ARMV7_NEON
190e1051a39Sopenharmony_ci	itt	ne
191e1051a39Sopenharmony_ci	ldrne	r10,[sp],#8
192e1051a39Sopenharmony_ci	bne	.LNEON
193e1051a39Sopenharmony_ci	stmdb	sp!,{r4-r9}
194e1051a39Sopenharmony_ci#else
195e1051a39Sopenharmony_ci	stmdb	sp!,{r4-r10,lr}
196e1051a39Sopenharmony_ci#endif
197e1051a39Sopenharmony_ci___
198e1051a39Sopenharmony_ci$ret="r10";	# reassigned 1st argument
199e1051a39Sopenharmony_ci$code.=<<___;
200e1051a39Sopenharmony_ci	mov	$ret,r0			@ reassign 1st argument
201e1051a39Sopenharmony_ci	mov	$b,r3			@ $b=b1
202e1051a39Sopenharmony_ci	sub	r7,sp,#36
203e1051a39Sopenharmony_ci	mov	r8,sp
204e1051a39Sopenharmony_ci	and	r7,r7,#-32
205e1051a39Sopenharmony_ci	ldr	r3,[sp,#32]		@ load b0
206e1051a39Sopenharmony_ci	mov	$mask,#7<<2
207e1051a39Sopenharmony_ci	mov	sp,r7			@ allocate tab[8]
208e1051a39Sopenharmony_ci	str	r8,[r7,#32]
209e1051a39Sopenharmony_ci
210e1051a39Sopenharmony_ci	bl	mul_1x1_ialu		@ a1·b1
211e1051a39Sopenharmony_ci	str	$lo,[$ret,#8]
212e1051a39Sopenharmony_ci	str	$hi,[$ret,#12]
213e1051a39Sopenharmony_ci
214e1051a39Sopenharmony_ci	eor	$b,$b,r3		@ flip b0 and b1
215e1051a39Sopenharmony_ci	 eor	$a,$a,r2		@ flip a0 and a1
216e1051a39Sopenharmony_ci	eor	r3,r3,$b
217e1051a39Sopenharmony_ci	 eor	r2,r2,$a
218e1051a39Sopenharmony_ci	eor	$b,$b,r3
219e1051a39Sopenharmony_ci	 eor	$a,$a,r2
220e1051a39Sopenharmony_ci	bl	mul_1x1_ialu		@ a0·b0
221e1051a39Sopenharmony_ci	str	$lo,[$ret]
222e1051a39Sopenharmony_ci	str	$hi,[$ret,#4]
223e1051a39Sopenharmony_ci
224e1051a39Sopenharmony_ci	eor	$a,$a,r2
225e1051a39Sopenharmony_ci	eor	$b,$b,r3
226e1051a39Sopenharmony_ci	bl	mul_1x1_ialu		@ (a1+a0)·(b1+b0)
227e1051a39Sopenharmony_ci___
228e1051a39Sopenharmony_ci@r=map("r$_",(6..9));
229e1051a39Sopenharmony_ci$code.=<<___;
230e1051a39Sopenharmony_ci	ldmia	$ret,{@r[0]-@r[3]}
231e1051a39Sopenharmony_ci	eor	$lo,$lo,$hi
232e1051a39Sopenharmony_ci	ldr	sp,[sp,#32]		@ destroy tab[8]
233e1051a39Sopenharmony_ci	eor	$hi,$hi,@r[1]
234e1051a39Sopenharmony_ci	eor	$lo,$lo,@r[0]
235e1051a39Sopenharmony_ci	eor	$hi,$hi,@r[2]
236e1051a39Sopenharmony_ci	eor	$lo,$lo,@r[3]
237e1051a39Sopenharmony_ci	eor	$hi,$hi,@r[3]
238e1051a39Sopenharmony_ci	str	$hi,[$ret,#8]
239e1051a39Sopenharmony_ci	eor	$lo,$lo,$hi
240e1051a39Sopenharmony_ci	str	$lo,[$ret,#4]
241e1051a39Sopenharmony_ci
242e1051a39Sopenharmony_ci#if __ARM_ARCH__>=5
243e1051a39Sopenharmony_ci	ldmia	sp!,{r4-r10,pc}
244e1051a39Sopenharmony_ci#else
245e1051a39Sopenharmony_ci	ldmia	sp!,{r4-r10,lr}
246e1051a39Sopenharmony_ci	tst	lr,#1
247e1051a39Sopenharmony_ci	moveq	pc,lr			@ be binary compatible with V4, yet
248e1051a39Sopenharmony_ci	bx	lr			@ interoperable with Thumb ISA:-)
249e1051a39Sopenharmony_ci#endif
250e1051a39Sopenharmony_ci___
251e1051a39Sopenharmony_ci}
252e1051a39Sopenharmony_ci{
253e1051a39Sopenharmony_cimy ($r,$t0,$t1,$t2,$t3)=map("q$_",(0..3,8..12));
254e1051a39Sopenharmony_cimy ($a,$b,$k48,$k32,$k16)=map("d$_",(26..31));
255e1051a39Sopenharmony_ci
256e1051a39Sopenharmony_ci$code.=<<___;
257e1051a39Sopenharmony_ci#if __ARM_MAX_ARCH__>=7
258e1051a39Sopenharmony_ci.arch	armv7-a
259e1051a39Sopenharmony_ci.fpu	neon
260e1051a39Sopenharmony_ci
261e1051a39Sopenharmony_ci.align	5
262e1051a39Sopenharmony_ci.LNEON:
263e1051a39Sopenharmony_ci	ldr		r12, [sp]		@ 5th argument
264e1051a39Sopenharmony_ci	vmov		$a, r2, r1
265e1051a39Sopenharmony_ci	vmov		$b, r12, r3
266e1051a39Sopenharmony_ci	vmov.i64	$k48, #0x0000ffffffffffff
267e1051a39Sopenharmony_ci	vmov.i64	$k32, #0x00000000ffffffff
268e1051a39Sopenharmony_ci	vmov.i64	$k16, #0x000000000000ffff
269e1051a39Sopenharmony_ci
270e1051a39Sopenharmony_ci	vext.8		$t0#lo, $a, $a, #1	@ A1
271e1051a39Sopenharmony_ci	vmull.p8	$t0, $t0#lo, $b		@ F = A1*B
272e1051a39Sopenharmony_ci	vext.8		$r#lo, $b, $b, #1	@ B1
273e1051a39Sopenharmony_ci	vmull.p8	$r, $a, $r#lo		@ E = A*B1
274e1051a39Sopenharmony_ci	vext.8		$t1#lo, $a, $a, #2	@ A2
275e1051a39Sopenharmony_ci	vmull.p8	$t1, $t1#lo, $b		@ H = A2*B
276e1051a39Sopenharmony_ci	vext.8		$t3#lo, $b, $b, #2	@ B2
277e1051a39Sopenharmony_ci	vmull.p8	$t3, $a, $t3#lo		@ G = A*B2
278e1051a39Sopenharmony_ci	vext.8		$t2#lo, $a, $a, #3	@ A3
279e1051a39Sopenharmony_ci	veor		$t0, $t0, $r		@ L = E + F
280e1051a39Sopenharmony_ci	vmull.p8	$t2, $t2#lo, $b		@ J = A3*B
281e1051a39Sopenharmony_ci	vext.8		$r#lo, $b, $b, #3	@ B3
282e1051a39Sopenharmony_ci	veor		$t1, $t1, $t3		@ M = G + H
283e1051a39Sopenharmony_ci	vmull.p8	$r, $a, $r#lo		@ I = A*B3
284e1051a39Sopenharmony_ci	veor		$t0#lo, $t0#lo, $t0#hi	@ t0 = (L) (P0 + P1) << 8
285e1051a39Sopenharmony_ci	vand		$t0#hi, $t0#hi, $k48
286e1051a39Sopenharmony_ci	vext.8		$t3#lo, $b, $b, #4	@ B4
287e1051a39Sopenharmony_ci	veor		$t1#lo, $t1#lo, $t1#hi	@ t1 = (M) (P2 + P3) << 16
288e1051a39Sopenharmony_ci	vand		$t1#hi, $t1#hi, $k32
289e1051a39Sopenharmony_ci	vmull.p8	$t3, $a, $t3#lo		@ K = A*B4
290e1051a39Sopenharmony_ci	veor		$t2, $t2, $r		@ N = I + J
291e1051a39Sopenharmony_ci	veor		$t0#lo, $t0#lo, $t0#hi
292e1051a39Sopenharmony_ci	veor		$t1#lo, $t1#lo, $t1#hi
293e1051a39Sopenharmony_ci	veor		$t2#lo, $t2#lo, $t2#hi	@ t2 = (N) (P4 + P5) << 24
294e1051a39Sopenharmony_ci	vand		$t2#hi, $t2#hi, $k16
295e1051a39Sopenharmony_ci	vext.8		$t0, $t0, $t0, #15
296e1051a39Sopenharmony_ci	veor		$t3#lo, $t3#lo, $t3#hi	@ t3 = (K) (P6 + P7) << 32
297e1051a39Sopenharmony_ci	vmov.i64	$t3#hi, #0
298e1051a39Sopenharmony_ci	vext.8		$t1, $t1, $t1, #14
299e1051a39Sopenharmony_ci	veor		$t2#lo, $t2#lo, $t2#hi
300e1051a39Sopenharmony_ci	vmull.p8	$r, $a, $b		@ D = A*B
301e1051a39Sopenharmony_ci	vext.8		$t3, $t3, $t3, #12
302e1051a39Sopenharmony_ci	vext.8		$t2, $t2, $t2, #13
303e1051a39Sopenharmony_ci	veor		$t0, $t0, $t1
304e1051a39Sopenharmony_ci	veor		$t2, $t2, $t3
305e1051a39Sopenharmony_ci	veor		$r, $r, $t0
306e1051a39Sopenharmony_ci	veor		$r, $r, $t2
307e1051a39Sopenharmony_ci
308e1051a39Sopenharmony_ci	vst1.32		{$r}, [r0]
309e1051a39Sopenharmony_ci	ret		@ bx lr
310e1051a39Sopenharmony_ci#endif
311e1051a39Sopenharmony_ci___
312e1051a39Sopenharmony_ci}
313e1051a39Sopenharmony_ci$code.=<<___;
314e1051a39Sopenharmony_ci.size	bn_GF2m_mul_2x2,.-bn_GF2m_mul_2x2
315e1051a39Sopenharmony_ci#if __ARM_MAX_ARCH__>=7
316e1051a39Sopenharmony_ci.align	5
317e1051a39Sopenharmony_ci.LOPENSSL_armcap:
318e1051a39Sopenharmony_ci# ifdef	_WIN32
319e1051a39Sopenharmony_ci.word	OPENSSL_armcap_P
320e1051a39Sopenharmony_ci# else
321e1051a39Sopenharmony_ci.word	OPENSSL_armcap_P-.
322e1051a39Sopenharmony_ci# endif
323e1051a39Sopenharmony_ci#endif
324e1051a39Sopenharmony_ci.asciz	"GF(2^m) Multiplication for ARMv4/NEON, CRYPTOGAMS by <appro\@openssl.org>"
325e1051a39Sopenharmony_ci.align	5
326e1051a39Sopenharmony_ci
327e1051a39Sopenharmony_ci#if __ARM_MAX_ARCH__>=7
328e1051a39Sopenharmony_ci.comm	OPENSSL_armcap_P,4,4
329e1051a39Sopenharmony_ci#endif
330e1051a39Sopenharmony_ci___
331e1051a39Sopenharmony_ci
332e1051a39Sopenharmony_ciforeach (split("\n",$code)) {
333e1051a39Sopenharmony_ci	s/\`([^\`]*)\`/eval $1/geo;
334e1051a39Sopenharmony_ci
335e1051a39Sopenharmony_ci	s/\bq([0-9]+)#(lo|hi)/sprintf "d%d",2*$1+($2 eq "hi")/geo	or
336e1051a39Sopenharmony_ci	s/\bret\b/bx	lr/go		or
337e1051a39Sopenharmony_ci	s/\bbx\s+lr\b/.word\t0xe12fff1e/go;    # make it possible to compile with -march=armv4
338e1051a39Sopenharmony_ci
339e1051a39Sopenharmony_ci	print $_,"\n";
340e1051a39Sopenharmony_ci}
341e1051a39Sopenharmony_ciclose STDOUT or die "error closing STDOUT: $!";   # enforce flush
342