Split bignum code out of the sparcv9cap.c
[openssl.git] / crypto / md5 / asm / md5-sparcv9.pl
index ef16666cc34276f9b2030cbdef0a8b72d67c0dc9..a17d0b6bf58126241fa6f46b4b8ec76dfcda0194 100644 (file)
@@ -1,4 +1,11 @@
-#!/usr/bin/env perl
+#! /usr/bin/env perl
+# Copyright 2012-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@openssl.org> for the OpenSSL
@@ -6,7 +13,7 @@
 # CRYPTOGAMS licenses depending on where you obtain it. For further
 # details see http://www.openssl.org/~appro/cryptogams/.
 #
-# Hardware SPARC T4 support by David S. Miller <davem@davemloft.net>.
+# Hardware SPARC T4 support by David S. Miller.
 # ====================================================================
 
 # MD5 for SPARCv9, 6.9 cycles per byte on UltraSPARC, >40% faster than
 # 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 is the last argument if it looks like a file (it has an extension)
+$output = $#ARGV >= 0 && $ARGV[$#ARGV] =~ m|\.\w+$| ? pop : undef;
 
-$output=shift;
-open STDOUT,">$output";
+$output and open STDOUT,">$output";
 
 use integer;
 
@@ -198,12 +202,16 @@ $code.=<<___;
 ___
 }
 
-$code.=<<___ if ($bits==64);
+$code.=<<___;
+#ifndef __ASSEMBLER__
+# define __ASSEMBLER__ 1
+#endif
+#include "crypto/sparc_arch.h"
+
+#ifdef __arch64__
 .register      %g2,#scratch
 .register      %g3,#scratch
-___
-$code.=<<___;
-#include "sparc_arch.h"
+#endif
 
 .section       ".text",#alloc,#execinstr
 
@@ -211,9 +219,9 @@ $code.=<<___;
 SPARC_PIC_THUNK(%g1)
 #endif
 
-.globl md5_block_asm_data_order
+.globl ossl_md5_block_asm_data_order
 .align 32
-md5_block_asm_data_order:
+ossl_md5_block_asm_data_order:
        SPARC_LOAD_ADDRESS_LEAF(OPENSSL_sparcv9cap_P,%g1,%g5)
        ld      [%g1+4],%g1             ! OPENSSL_sparcv9cap_P[1]
 
@@ -239,14 +247,14 @@ md5_block_asm_data_order:
        ldd     [%o1 + 0x20], %f16
        ldd     [%o1 + 0x28], %f18
        ldd     [%o1 + 0x30], %f20
-       subcc   %o2, 1, %o2             ! done yet? 
+       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:
@@ -287,7 +295,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
@@ -295,7 +303,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
@@ -355,7 +363,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
@@ -366,8 +374,8 @@ $code.=<<___;
        wr      %g0,$saved_asi,%asi
        ret
        restore
-.type  md5_block_asm_data_order,#function
-.size  md5_block_asm_data_order,(.-md5_block_asm_data_order)
+.type  ossl_md5_block_asm_data_order,#function
+.size  ossl_md5_block_asm_data_order,(.-ossl_md5_block_asm_data_order)
 
 .asciz "MD5 block transform for SPARCv9, CRYPTOGAMS by <appro\@openssl.org>"
 .align 4
@@ -375,7 +383,7 @@ ___
 
 # Purpose of these subroutines is to explicitly encode VIS instructions,
 # so that one can compile the module without having to specify VIS
-# extentions on compiler command line, e.g. -xarch=v9 vs. -xarch=v9a.
+# extensions on compiler command line, e.g. -xarch=v9 vs. -xarch=v9a.
 # Idea is to reserve for option to produce "universal" binary and let
 # programmer detect if current CPU is VIS capable at run-time.
 sub unvis {
@@ -431,4 +439,4 @@ foreach (split("\n",$code)) {
        print $_,"\n";
 }
 
-close STDOUT;
+close STDOUT or die "error closing STDOUT: $!";