Split bignum code out of the sparcv9cap.c
[openssl.git] / crypto / bn / asm / sparcv9-mont.pl
index 2697965b3f28050f64f1f5b713038a0d5896bd35..ac93ef9ee64205a8e5b11a07f2f90bc5ec722fd4 100644 (file)
@@ -1,14 +1,14 @@
 #! /usr/bin/env perl
-# Copyright 2005-2016 The OpenSSL Project Authors. All Rights Reserved.
+# Copyright 2005-2020 The OpenSSL Project Authors. All Rights Reserved.
 #
-# Licensed under the OpenSSL license (the "License").  You may not use
+# Licensed under the Apache License 2.0 (the "License").  You may not use
 # this file except in compliance with the License.  You can obtain a copy
 # in the file LICENSE in the source distribution or at
 # https://www.openssl.org/source/license.html
 
 
 # ====================================================================
-# Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
+# Written by Andy Polyakov <appro@openssl.org> for the OpenSSL
 # project. The module is, however, dual licensed under OpenSSL and
 # CRYPTOGAMS licenses depending on where you obtain it. For further
 # details see http://www.openssl.org/~appro/cryptogams/.
@@ -30,7 +30,7 @@
 # instructions...
 
 # (*)  Engine accessing the driver in question is on my TODO list.
-#      For reference, acceleator is estimated to give 6 to 10 times
+#      For reference, accelerator is estimated to give 6 to 10 times
 #      improvement on single-threaded RSA sign. It should be noted
 #      that 6-10x improvement coefficient does not actually mean
 #      something extraordinary in terms of absolute [single-threaded]
@@ -49,8 +49,7 @@
 # module still have hidden potential [see TODO list there], which is
 # estimated to be larger than 20%...
 
-$output = pop;
-open STDOUT,">$output";
+$output = pop and open STDOUT,">$output";
 
 # int bn_mul_mont(
 $rp="%i0";     # BN_ULONG *rp,
@@ -84,7 +83,10 @@ $tpj="%l7";
 $fname="bn_mul_mont_int";
 
 $code=<<___;
-#include "sparc_arch.h"
+#ifndef __ASSEMBLER__
+# define __ASSEMBLER__ 1
+#endif
+#include "crypto/sparc_arch.h"
 
 .section       ".text",#alloc,#execinstr
 
@@ -265,7 +267,6 @@ $fname:
 .Ltail:
        add     $np,$num,$np
        add     $rp,$num,$rp
-       mov     $tp,$ap
        sub     %g0,$num,%o7            ! k=-num
        ba      .Lsub
        subcc   %g0,%g0,%g0             ! clear %icc.c
@@ -278,15 +279,14 @@ $fname:
        add     %o7,4,%o7
        brnz    %o7,.Lsub
        st      %o1,[$i]
-       subc    $car2,0,$car2           ! handle upmost overflow bit
-       and     $tp,$car2,$ap
-       andn    $rp,$car2,$np
-       or      $ap,$np,$ap
+       subccc  $car2,0,$car2           ! handle upmost overflow bit
        sub     %g0,$num,%o7
 
 .Lcopy:
-       ld      [$ap+%o7],%o0           ! copy or in-place refresh
+       ld      [$tp+%o7],%o1           ! conditional copy
+       ld      [$rp+%o7],%o0
        st      %g0,[$tp+%o7]           ! zap tp
+       movcs   %icc,%o1,%o0
        st      %o0,[$rp+%o7]
        add     %o7,4,%o7
        brnz    %o7,.Lcopy
@@ -495,6 +495,9 @@ $code.=<<___;
        mulx    $npj,$mul1,$acc1
        add     $tpj,$car1,$car1
        ld      [$np+$j],$npj                   ! np[j]
+       srlx    $car1,32,$tmp0
+       and     $car1,$mask,$car1
+       add     $tmp0,$sbit,$sbit
        add     $acc0,$car1,$car1
        ld      [$tp+8],$tpj                    ! tp[j]
        add     $acc1,$car1,$car1
@@ -611,9 +614,9 @@ $code.=<<___;
        add     $tp,8,$tp
 .type  $fname,#function
 .size  $fname,(.-$fname)
-.asciz "Montgomery Multipltication for SPARCv9, CRYPTOGAMS by <appro\@openssl.org>"
+.asciz "Montgomery Multiplication for SPARCv9, CRYPTOGAMS by <appro\@openssl.org>"
 .align 32
 ___
 $code =~ s/\`([^\`]*)\`/eval($1)/gem;
 print $code;
-close STDOUT;
+close STDOUT or die "error closing STDOUT: $!";