SPARCv9 assembly pack: harmonize ABI handling (so that it's handled in one
[openssl.git] / crypto / md5 / asm / md5-sparcv9.pl
index 5875779101f49dc80bbdc88ecb5a6d1d765070e8..407da3c1b0df2417f405166510919d7948820557 100644 (file)
@@ -1,7 +1,7 @@
 #!/usr/bin/env perl
 
 # ====================================================================
-# Written by Andy Polyakov <appro@opensl.org> 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/.
 # MD5 for SPARCv9, 6.9 cycles per byte on UltraSPARC, >40% faster than
 # code generated by Sun C 5.2.
 
-# SPARC T4 MD5 hardware achieves 3.24 cycles per byte, which is 2.1x
+# SPARC T4 MD5 hardware achieves 3.20 cycles per byte, which is 2.1x
 # faster than software. Multi-process benchmark saturates at 12x
 # single-process result on 8-core processor, or ~11GBps per 2.85GHz
 # socket.
 
-$bits=32;
-for (@ARGV)    { $bits=64 if (/\-m64/ || /\-xarch\=v9/); }
-if ($bits==64) { $bias=2047; $frame=192; }
-else           { $bias=0;    $frame=112; }
-
 $output=shift;
 open STDOUT,">$output";
 
@@ -198,13 +193,14 @@ $code.=<<___;
 ___
 }
 
-$code.=<<___ if ($bits==64);
-.register      %g2,#scratch
-.register      %g3,#scratch
-___
 $code.=<<___;
 #include "sparc_arch.h"
 
+#ifdef __arch64__
+.register      %g2,#scratch
+.register      %g3,#scratch
+#endif
+
 .section       ".text",#alloc,#execinstr
 
 #ifdef __PIC__
@@ -221,15 +217,15 @@ md5_block_asm_data_order:
        be      .Lsoftware
        nop
 
-       rd      %asi, %g5
-       wr      %g0, 0x88, %asi         ! ASI_PRIMARY_LITTLE
-       lda     [%o0 + 0x00] %asi, %f0  ! load context
-       lda     [%o0 + 0x04] %asi, %f1
+       mov     4, %g1
        andcc   %o1, 0x7, %g0
-       lda     [%o0 + 0x08] %asi, %f2
+       lda     [%o0 + %g0]0x88, %f0            ! load context
+       lda     [%o0 + %g1]0x88, %f1
+       add     %o0, 8, %o0
+       lda     [%o0 + %g0]0x88, %f2
+       lda     [%o0 + %g1]0x88, %f3
        bne,pn  %icc, .Lhwunaligned
-        lda    [%o0 + 0x0c] %asi, %f3
+       sub     %o0, 8, %o0
 
 .Lhw_loop:
        ldd     [%o1 + 0x00], %f8
@@ -242,19 +238,21 @@ md5_block_asm_data_order:
        subcc   %o2, 1, %o2             ! done yet? 
        ldd     [%o1 + 0x38], %f22
        add     %o1, 0x40, %o1
+       prefetch [%o1 + 63], 20
 
        .word   0x81b02800              ! MD5
 
-       bne,pt  `$bits==64?"%xcc":"%icc"`, .Lhw_loop
+       bne,pt  SIZE_T_CC, .Lhw_loop
        nop
 
 .Lhwfinish:
-       sta     %f0, [%o0 + 0x00] %asi  ! store context
-       sta     %f1, [%o0 + 0x04] %asi
-       sta     %f2, [%o0 + 0x08] %asi
-       sta     %f3, [%o0 + 0x0c] %asi
+       sta     %f0, [%o0 + %g0]0x88    ! store context
+       sta     %f1, [%o0 + %g1]0x88
+       add     %o0, 8, %o0
+       sta     %f2, [%o0 + %g0]0x88
+       sta     %f3, [%o0 + %g1]0x88
        retl
-        wr     %g5, 0x0, %asi          ! restore %asi
+       nop
 
 .align 8
 .Lhwunaligned:
@@ -272,6 +270,7 @@ md5_block_asm_data_order:
        subcc   %o2, 1, %o2             ! done yet?
        ldd     [%o1 + 0x40], %f26
        add     %o1, 0x40, %o1
+       prefetch [%o1 + 63], 20
 
        faligndata %f10, %f12, %f8
        faligndata %f12, %f14, %f10
@@ -284,7 +283,7 @@ md5_block_asm_data_order:
 
        .word   0x81b02800              ! MD5
 
-       bne,pt  `$bits==64?"%xcc":"%icc"`, .Lhwunaligned_loop
+       bne,pt  SIZE_T_CC, .Lhwunaligned_loop
        for     %f26, %f26, %f10        ! %f10=%f26
 
        ba      .Lhwfinish
@@ -292,7 +291,7 @@ md5_block_asm_data_order:
 
 .align 16
 .Lsoftware:
-       save    %sp,-$frame,%sp
+       save    %sp,-STACK_FRAME,%sp
 
        rd      %asi,$saved_asi
        wr      %g0,0x88,%asi           ! ASI_PRIMARY_LITTLE
@@ -352,7 +351,7 @@ $code.=<<___;
        add     $t2,$C,$C
        add     $CD,$D,$D
        srl     $B,0,$B                 ! clruw $B
-       bne     `$bits==64?"%xcc":"%icc"`,.Loop
+       bne     SIZE_T_CC,.Loop
        srl     $D,0,$D                 ! clruw $D
 
        st      $A,[$ctx+0]             ! write out ctx