Update copyright year
[openssl.git] / crypto / bn / asm / sparcv9a-mont.pl
index 5583b41193d5a95eea847d5a103441ae7e02f75a..2a4255ed695286f76a02b803e6d99839b48c747e 100755 (executable)
@@ -1,7 +1,14 @@
-#!/usr/bin/env perl
+#! /usr/bin/env perl
+# Copyright 2005-2020 The OpenSSL Project Authors. All Rights Reserved.
+#
+# 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/.
 #
 # Modulo-scheduled inner loops allow to interleave floating point and
 # integer instructions and minimize Read-After-Write penalties. This
-# results in *further* 20-50% perfromance improvement [depending on
+# results in *further* 20-50% performance improvement [depending on
 # key length, more for longer keys] on USI&II cores and 30-80% - on
 # USIII&IV.
 
+# $output is the last argument if it looks like a file (it has an extension)
+$output = $#ARGV >= 0 && $ARGV[$#ARGV] =~ m|\.\w+$| ? pop : undef;
+
+$output and open STDOUT,">$output";
+
 $fname="bn_mul_mont_fpu";
-$bits=32;
-for (@ARGV) { $bits=64 if (/\-m64/ || /\-xarch\=v9/); }
-
-if ($bits==64) {
-       $bias=2047;
-       $frame=192;
-} else {
-       $bias=0;
-       $frame=128;     # 96 rounded up to largest known cache-line
-}
+
+$frame="STACK_FRAME";
+$bias="STACK_BIAS";
 $locals=64;
 
 # In order to provide for 32-/64-bit ABI duality, I keep integers wider
@@ -121,15 +126,14 @@ $nhia="%f56"; $nhib="%f58"; $nhic="%f60"; $nhid="%f62";
 $ASI_FL16_P=0xD2;      # magic ASI value to engage 16-bit FP load
 
 $code=<<___;
-.ident         "UltraSPARC Montgomery multiply by <appro\@fy.chalmers.se>"
+#include "sparc_arch.h"
+
 .section       ".text",#alloc,#execinstr
 
 .global $fname
 .align  32
 $fname:
        save    %sp,-$frame-$locals,%sp
-       sethi   %hi(0xffff),$mask
-       or      $mask,%lo(0xffff),$mask
 
        cmp     $num,4
        bl,a,pn %icc,.Lret
@@ -137,14 +141,11 @@ $fname:
        andcc   $num,1,%g0              ! $num has to be even...
        bnz,a,pn %icc,.Lret
        clr     %i0                     ! signal "unsupported input value"
-       or      $bp,$ap,%l0
+
        srl     $num,1,$num
-       or      $rp,$np,%l1
-       or      %l0,%l1,%l0
-       andcc   %l0,7,%g0               ! ...and pointers has to be 8-byte aligned
-       bnz,a,pn %icc,.Lret
-       clr     %i0                     ! signal "unsupported input value"
+       sethi   %hi(0xffff),$mask
        ld      [%i4+0],$n0             ! $n0 reassigned, remember?
+       or      $mask,%lo(0xffff),$mask
        ld      [%i4+4],%o0
        sllx    %o0,32,%o0
        or      %o0,$n0,$n0             ! $n0=n0[1].n0[0]
@@ -359,7 +360,7 @@ $fname:
        bz,pn   %icc,.L1stskip
        std     $nlod,[%sp+$bias+$frame+24]
 \f
-.align 32,0x1000000
+.align 32                      ! incidentally already aligned !
 .L1st:
        add     $ap,$j,%o4
        add     $np,$j,%o5
@@ -804,18 +805,13 @@ $fname:
        bnz     %icc,.Louter
        nop
 \f
-       sub     %g0,$num,%o7            ! n=-num
-       cmp     $carry,0                ! clears %icc.c
-       bne,pn  %icc,.Lsub
        add     $tp,8,$tp               ! adjust tp to point at the end
+       orn     %g0,%g0,%g4
+       sub     %g0,$num,%o7            ! n=-num
+       ba      .Lsub
+       subcc   %g0,%g0,%g0             ! clear %icc.c
 
-       ld      [$tp-8],%o0
-       ld      [$np-4],%o1
-       cmp     %o0,%o1                 ! compare topmost words
-       bcs,pt  %icc,.Lcopy             ! %icc.c is clean if not taken
-       nop
-
-.align 32,0x1000000
+.align 32
 .Lsub:
        ldx     [$tp+%o7],%o0
        add     $np,%o7,%g1
@@ -829,25 +825,31 @@ $fname:
        add     %o7,8,%o7
        brnz,pt %o7,.Lsub
        st      %o3,[%g1+4]
-       subccc  $carry,0,$carry
-       bcc,pt  %icc,.Lzap
+       subc    $carry,0,%g4
        sub     %g0,$num,%o7            ! n=-num
+       ba      .Lcopy
+       nop
 
-.align 16,0x1000000
+.align 32
 .Lcopy:
        ldx     [$tp+%o7],%o0
-       srlx    %o0,32,%o1
        add     $rp,%o7,%g1
+       ld      [%g1+0],%o2
+       ld      [%g1+4],%o3
+       stx     %g0,[$tp+%o7]
+       and     %o0,%g4,%o0
+       srlx    %o0,32,%o1
+       andn    %o2,%g4,%o2
+       andn    %o3,%g4,%o3
+       or      %o2,%o0,%o0
+       or      %o3,%o1,%o1
        st      %o0,[%g1+0]
        add     %o7,8,%o7
        brnz,pt %o7,.Lcopy
        st      %o1,[%g1+4]
-       ba      .Lzap
        sub     %g0,$num,%o7            ! n=-num
 
-.align 32
 .Lzap:
-       stx     %g0,[$tp+%o7]
        stx     %g0,[$ap_l+%o7]
        stx     %g0,[$ap_h+%o7]
        stx     %g0,[$np_l+%o7]
@@ -865,13 +867,14 @@ $fname:
        restore
 .type   $fname,#function
 .size  $fname,(.-$fname)
-.asciz "Montgomery Multipltication for UltraSPARC, CRYPTOGAMS by <appro\@openssl.org>"
+.asciz "Montgomery Multiplication for UltraSPARC, CRYPTOGAMS by <appro\@openssl.org>"
+.align 32
 ___
 
 $code =~ s/\`([^\`]*)\`/eval($1)/gem;
 
 # Below substitution makes it possible to compile without demanding
-# VIS extentions on command line, e.g. -xarch=v9 vs. -xarch=v9a. I
+# VIS extensions on command line, e.g. -xarch=v9 vs. -xarch=v9a. I
 # dare to do this, because VIS capability is detected at run-time now
 # and this routine is not called on CPU not capable to execute it. Do
 # note that fzeros is not the only VIS dependency! Another dependency
@@ -883,4 +886,4 @@ $code =~ s/fzeros\s+%f([0-9]+)/
 
 print $code;
 # flush
-close STDOUT;
+close STDOUT or die "error closing STDOUT: $!";