2 # Copyright 2006-2018 The OpenSSL Project Authors. All Rights Reserved.
4 # Licensed under the Apache License 2.0 (the "License"). You may not use
5 # this file except in compliance with the License. You can obtain a copy
6 # in the file LICENSE in the source distribution or at
7 # https://www.openssl.org/source/license.html
10 # ====================================================================
11 # Written by Andy Polyakov <appro@openssl.org> for the OpenSSL
12 # project. The module is, however, dual licensed under OpenSSL and
13 # CRYPTOGAMS licenses depending on where you obtain it. For further
14 # details see http://www.openssl.org/~appro/cryptogams/.
15 # ====================================================================
17 # On 21264 RSA sign performance improves by 70/35/20/15 percent for
18 # 512/1024/2048/4096 bit key lengths. This is against vendor compiler
19 # instructed to '-tune host' code with in-line assembler. Other
20 # benchmarks improve by 15-20%. To anchor it to something else, the
21 # code provides approximately the same performance per GHz as AMD64.
22 # I.e. if you compare 1GHz 21264 and 2GHz Opteron, you'll observe ~2x
25 $output=pop and open STDOUT,">$output";
28 $rp="a0"; # BN_ULONG *rp,
29 $ap="a1"; # const BN_ULONG *ap,
30 $bp="a2"; # const BN_ULONG *bp,
31 $np="a3"; # const BN_ULONG *np,
32 $n0="a4"; # const BN_ULONG *n0,
33 $num="a5"; # int num);
54 #include <asm/regdef.h>
87 ldq $hi0,0($ap) # ap[0]
91 ldq $bi,0($bp) # bp[0]
92 lda AT,-4096(zero) # mov -4096,AT
97 ldq $hi1,0($np) # np[0]
212 s8addq $j,$np,$nj #U0
216 addq $alo,$hi0,$lo0 #L1
219 mulq $aj,$bi,$alo #U1
220 cmpult $lo0,$hi0,AT #L0
221 addq $nlo,$hi1,$lo1 #L1
224 mulq $nj,$m1,$nlo #U1
225 addq $ahi,AT,$hi0 #L0
226 addq $lo0,$tj,$lo0 #L1
227 cmpult $lo1,$hi1,v0 #U0
229 umulh $aj,$bi,$ahi #U1
230 cmpult $lo0,$tj,AT #L0
231 addq $lo1,$lo0,$lo1 #L1
232 addq $nhi,v0,$hi1 #U0
234 umulh $nj,$m1,$nhi #U1
235 s8addq $j,$ap,$aj #L0
236 cmpult $lo1,$lo0,v0 #L1
237 cmplt $j,$num,$tj #U0 # borrow $tj
239 addq $hi0,AT,$hi0 #L0
240 addq $hi1,v0,$hi1 #U1
264 cmpult $lo1,$hi0,$hi1
270 cmplt $i,$num,$tj # borrow $tj
274 s8addq $num,sp,$tj # &tp[num]
275 mov $rp,$bp # put rp aside
278 mov 0,$hi0 # clear borrow bit
281 .Lsub: ldq $lo0,0($tp)
285 subq $lo0,$lo1,$lo1 # tp[i]-np[i]
288 cmpult $lo1,$lo0,$hi0
295 subq $hi1,$hi0,$hi0 # handle upmost overflow bit
297 mov $bp,$rp # restore rp
300 .Lcopy: ldq $aj,0($tp) # conditional copy
305 stq zero,-8($tp) # zap tp
322 .ascii "Montgomery Multiplication for Alpha, CRYPTOGAMS by <appro\@openssl.org>"
327 close STDOUT or die "error closing STDOUT";