X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;ds=sidebyside;f=crypto%2Fbn%2Fasm%2Fsparcv9a-mont.pl;h=369913b85b44f0862478aefacf9ea086d6fb5942;hb=a21314dbbc56cd30580123d74b3106a628540965;hp=8bc64ad5f5628b00196b7c825ffa51cd940e39ba;hpb=ebae8092cb5a71b80ad325cb38815efb51fe0cd3;p=oweals%2Fopenssl.git diff --git a/crypto/bn/asm/sparcv9a-mont.pl b/crypto/bn/asm/sparcv9a-mont.pl index 8bc64ad5f5..369913b85b 100755 --- a/crypto/bn/asm/sparcv9a-mont.pl +++ b/crypto/bn/asm/sparcv9a-mont.pl @@ -1,7 +1,14 @@ -#!/usr/bin/env perl +#! /usr/bin/env perl +# Copyright 2005-2016 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 for the OpenSSL +# Written by Andy Polyakov 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/. @@ -18,8 +25,8 @@ # implementations from compatibility matrix. But the rest, whole Sun # UltraSPARC family and brand new Fujitsu's SPARC64 V, all support # VIS extension instructions used in this module. This is considered -# good enough to recommend HAL SPARC64 users [if any] to simply fall -# down to no-asm configuration. +# good enough to not care about HAL SPARC64 users [if any] who have +# integer-only pure SPARCv9 module to "fall down" to. # USI&II cores currently exhibit uniform 2x improvement [over pre- # bn_mul_mont codebase] for all key lengths and benchmarks. On USIII @@ -31,14 +38,12 @@ # is pipelined, which in turn *might* be impossible to match... On # additional note, SPARC64 V implements FP Multiply-Add instruction, # which is perfectly usable in this context... In other words, as far -# as HAL/Fujitsu SPARC64 family goes, talk to the author:-) +# as Fujitsu SPARC64 V goes, talk to the author:-) # The implementation implies following "non-natural" limitations on # input arguments: # - num may not be less than 4; # - num has to be even; -# - ap, bp, rp, np has to be 64-bit aligned [which is not a problem -# as long as BIGNUM.d are malloc-ated]; # Failure to meet either condition has no fatal effects, simply # doesn't give any performance gain. @@ -53,21 +58,19 @@ # # 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 @@ -123,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 " +#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 @@ -139,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] @@ -183,12 +182,12 @@ $fname: add $ap,$j,%o3 add $bp,$i,%o4 - ldx [$bp+$i],%o0 ! bp[0] - ldx [$ap+$j],%o1 ! ap[0] - sllx %o0,32,%g1 - sllx %o1,32,%g5 - srlx %o0,32,%o0 - srlx %o1,32,%o1 + ld [%o3+4],%g1 ! bp[0] + ld [%o3+0],%o0 + ld [%o4+4],%g5 ! ap[0] + sllx %g1,32,%g1 + ld [%o4+0],%o1 + sllx %g5,32,%g5 or %g1,%o0,%o0 or %g5,%o1,%o1 @@ -361,7 +360,7 @@ $fname: bz,pn %icc,.L1stskip std $nlod,[%sp+$bias+$frame+24] -.align 32,0x1000000 +.align 32 ! incidentally already aligned ! .L1st: add $ap,$j,%o4 add $np,$j,%o5 @@ -510,14 +509,15 @@ $fname: sub %g0,$num,$j ! j=-num add %sp,$bias+$frame+$locals,$tp + add $ap,$j,%o3 add $bp,$i,%o4 - ldx [$bp+$i],%o0 ! bp[i] - ldx [$ap+$j],%o1 ! ap[0] - sllx %o0,32,%g1 - sllx %o1,32,%g5 - srlx %o0,32,%o0 - srlx %o1,32,%o1 + ld [%o3+4],%g1 ! bp[i] + ld [%o3+0],%o0 + ld [%o4+4],%g5 ! ap[0] + sllx %g1,32,%g1 + ld [%o4+0],%o1 + sllx %g5,32,%g5 or %g1,%o0,%o0 or %g5,%o1,%o1 @@ -805,45 +805,51 @@ $fname: bnz %icc,.Louter nop - 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: - ldd [$tp+%o7],%o0 - ldd [$np+%o7],%o2 - subccc %o1,%o2,%o2 - subccc %o0,%o3,%o3 - std %o2,[$rp+%o7] + ldx [$tp+%o7],%o0 + add $np,%o7,%g1 + ld [%g1+0],%o2 + ld [%g1+4],%o3 + srlx %o0,32,%o1 + subccc %o0,%o2,%o2 + add $rp,%o7,%g1 + subccc %o1,%o3,%o3 + st %o2,[%g1+0] add %o7,8,%o7 brnz,pt %o7,.Lsub - nop - subccc $carry,0,$carry - bcc,pt %icc,.Lzap + st %o3,[%g1+4] + subc $carry,0,%g4 sub %g0,$num,%o7 ! n=-num + ba .Lcopy + nop -.align 16,0x1000000 +.align 32 .Lcopy: ldx [$tp+%o7],%o0 + add $rp,%o7,%g1 + ld [%g1+0],%o2 + ld [%g1+4],%o3 + stx %g0,[$tp+%o7] + and %o0,%g4,%o0 srlx %o0,32,%o1 - std %o0,[$rp+%o7] + 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 - nop - ba .Lzap + st %o1,[%g1+4] 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] @@ -861,12 +867,14 @@ $fname: restore .type $fname,#function .size $fname,(.-$fname) +.asciz "Montgomery Multiplication for UltraSPARC, CRYPTOGAMS by " +.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 @@ -878,4 +886,4 @@ $code =~ s/fzeros\s+%f([0-9]+)/ print $code; # flush -close STDOUT; +close STDOUT or die "error closing STDOUT: $!";