xref: /freebsd/crypto/openssl/crypto/sha/asm/sha1-parisc.pl (revision b077aed33b7b6aefca7b17ddb250cf521f938613)
11f13597dSJung-uk Kim#! /usr/bin/env perl
217f01e99SJung-uk Kim# Copyright 2009-2020 The OpenSSL Project Authors. All Rights Reserved.
3e71b7053SJung-uk Kim#
4*b077aed3SPierre Pronchery# Licensed under the Apache License 2.0 (the "License").  You may not use
5e71b7053SJung-uk Kim# this file except in compliance with the License.  You can obtain a copy
6e71b7053SJung-uk Kim# in the file LICENSE in the source distribution or at
7e71b7053SJung-uk Kim# https://www.openssl.org/source/license.html
8e71b7053SJung-uk Kim
91f13597dSJung-uk Kim
101f13597dSJung-uk Kim# ====================================================================
11e71b7053SJung-uk Kim# Written by Andy Polyakov <appro@openssl.org> for the OpenSSL
121f13597dSJung-uk Kim# project. The module is, however, dual licensed under OpenSSL and
131f13597dSJung-uk Kim# CRYPTOGAMS licenses depending on where you obtain it. For further
141f13597dSJung-uk Kim# details see http://www.openssl.org/~appro/cryptogams/.
151f13597dSJung-uk Kim# ====================================================================
161f13597dSJung-uk Kim
171f13597dSJung-uk Kim# SHA1 block procedure for PA-RISC.
181f13597dSJung-uk Kim
191f13597dSJung-uk Kim# June 2009.
201f13597dSJung-uk Kim#
211f13597dSJung-uk Kim# On PA-7100LC performance is >30% better than gcc 3.2 generated code
221f13597dSJung-uk Kim# for aligned input and >50% better for unaligned. Compared to vendor
231f13597dSJung-uk Kim# compiler on PA-8600 it's almost 60% faster in 64-bit build and just
241f13597dSJung-uk Kim# few percent faster in 32-bit one (this for aligned input, data for
251f13597dSJung-uk Kim# unaligned input is not available).
261f13597dSJung-uk Kim#
271f13597dSJung-uk Kim# Special thanks to polarhome.com for providing HP-UX account.
281f13597dSJung-uk Kim
29*b077aed3SPierre Pronchery# $output is the last argument if it looks like a file (it has an extension)
30*b077aed3SPierre Pronchery# $flavour is the first argument if it doesn't look like a file
31*b077aed3SPierre Pronchery$output = $#ARGV >= 0 && $ARGV[$#ARGV] =~ m|\.\w+$| ? pop : undef;
32*b077aed3SPierre Pronchery$flavour = $#ARGV >= 0 && $ARGV[0] !~ m|\.| ? shift : undef;
33*b077aed3SPierre Pronchery
34*b077aed3SPierre Pronchery$output and open STDOUT,">$output";
351f13597dSJung-uk Kim
361f13597dSJung-uk Kimif ($flavour =~ /64/) {
371f13597dSJung-uk Kim	$LEVEL		="2.0W";
381f13597dSJung-uk Kim	$SIZE_T		=8;
391f13597dSJung-uk Kim	$FRAME_MARKER	=80;
401f13597dSJung-uk Kim	$SAVED_RP	=16;
411f13597dSJung-uk Kim	$PUSH		="std";
421f13597dSJung-uk Kim	$PUSHMA		="std,ma";
431f13597dSJung-uk Kim	$POP		="ldd";
441f13597dSJung-uk Kim	$POPMB		="ldd,mb";
451f13597dSJung-uk Kim} else {
461f13597dSJung-uk Kim	$LEVEL		="1.0";
471f13597dSJung-uk Kim	$SIZE_T		=4;
481f13597dSJung-uk Kim	$FRAME_MARKER	=48;
491f13597dSJung-uk Kim	$SAVED_RP	=20;
501f13597dSJung-uk Kim	$PUSH		="stw";
511f13597dSJung-uk Kim	$PUSHMA		="stwm";
521f13597dSJung-uk Kim	$POP		="ldw";
531f13597dSJung-uk Kim	$POPMB		="ldwm";
541f13597dSJung-uk Kim}
551f13597dSJung-uk Kim
561f13597dSJung-uk Kim$FRAME=14*$SIZE_T+$FRAME_MARKER;# 14 saved regs + frame marker
571f13597dSJung-uk Kim				#                 [+ argument transfer]
581f13597dSJung-uk Kim$ctx="%r26";		# arg0
591f13597dSJung-uk Kim$inp="%r25";		# arg1
601f13597dSJung-uk Kim$num="%r24";		# arg2
611f13597dSJung-uk Kim
621f13597dSJung-uk Kim$t0="%r28";
631f13597dSJung-uk Kim$t1="%r29";
641f13597dSJung-uk Kim$K="%r31";
651f13597dSJung-uk Kim
661f13597dSJung-uk Kim@X=("%r1", "%r2", "%r3", "%r4", "%r5", "%r6", "%r7", "%r8",
671f13597dSJung-uk Kim    "%r9", "%r10","%r11","%r12","%r13","%r14","%r15","%r16",$t0);
681f13597dSJung-uk Kim
691f13597dSJung-uk Kim@V=($A,$B,$C,$D,$E)=("%r19","%r20","%r21","%r22","%r23");
701f13597dSJung-uk Kim
711f13597dSJung-uk Kimsub BODY_00_19 {
721f13597dSJung-uk Kimmy ($i,$a,$b,$c,$d,$e)=@_;
731f13597dSJung-uk Kimmy $j=$i+1;
741f13597dSJung-uk Kim$code.=<<___ if ($i<15);
751f13597dSJung-uk Kim	addl	$K,$e,$e	; $i
761f13597dSJung-uk Kim	shd	$a,$a,27,$t1
771f13597dSJung-uk Kim	addl	@X[$i],$e,$e
781f13597dSJung-uk Kim	and	$c,$b,$t0
791f13597dSJung-uk Kim	addl	$t1,$e,$e
801f13597dSJung-uk Kim	andcm	$d,$b,$t1
811f13597dSJung-uk Kim	shd	$b,$b,2,$b
821f13597dSJung-uk Kim	or	$t1,$t0,$t0
831f13597dSJung-uk Kim	addl	$t0,$e,$e
841f13597dSJung-uk Kim___
851f13597dSJung-uk Kim$code.=<<___ if ($i>=15);	# with forward Xupdate
861f13597dSJung-uk Kim	addl	$K,$e,$e	; $i
871f13597dSJung-uk Kim	shd	$a,$a,27,$t1
881f13597dSJung-uk Kim	xor	@X[($j+2)%16],@X[$j%16],@X[$j%16]
891f13597dSJung-uk Kim	addl	@X[$i%16],$e,$e
901f13597dSJung-uk Kim	and	$c,$b,$t0
911f13597dSJung-uk Kim	xor	@X[($j+8)%16],@X[$j%16],@X[$j%16]
921f13597dSJung-uk Kim	addl	$t1,$e,$e
931f13597dSJung-uk Kim	andcm	$d,$b,$t1
941f13597dSJung-uk Kim	shd	$b,$b,2,$b
951f13597dSJung-uk Kim	or	$t1,$t0,$t0
961f13597dSJung-uk Kim	xor	@X[($j+13)%16],@X[$j%16],@X[$j%16]
971f13597dSJung-uk Kim	add	$t0,$e,$e
981f13597dSJung-uk Kim	shd	@X[$j%16],@X[$j%16],31,@X[$j%16]
991f13597dSJung-uk Kim___
1001f13597dSJung-uk Kim}
1011f13597dSJung-uk Kim
1021f13597dSJung-uk Kimsub BODY_20_39 {
1031f13597dSJung-uk Kimmy ($i,$a,$b,$c,$d,$e)=@_;
1041f13597dSJung-uk Kimmy $j=$i+1;
1051f13597dSJung-uk Kim$code.=<<___ if ($i<79);
1061f13597dSJung-uk Kim	xor	@X[($j+2)%16],@X[$j%16],@X[$j%16]	; $i
1071f13597dSJung-uk Kim	addl	$K,$e,$e
1081f13597dSJung-uk Kim	shd	$a,$a,27,$t1
1091f13597dSJung-uk Kim	xor	@X[($j+8)%16],@X[$j%16],@X[$j%16]
1101f13597dSJung-uk Kim	addl	@X[$i%16],$e,$e
1111f13597dSJung-uk Kim	xor	$b,$c,$t0
1121f13597dSJung-uk Kim	xor	@X[($j+13)%16],@X[$j%16],@X[$j%16]
1131f13597dSJung-uk Kim	addl	$t1,$e,$e
1141f13597dSJung-uk Kim	shd	$b,$b,2,$b
1151f13597dSJung-uk Kim	xor	$d,$t0,$t0
1161f13597dSJung-uk Kim	shd	@X[$j%16],@X[$j%16],31,@X[$j%16]
1171f13597dSJung-uk Kim	addl	$t0,$e,$e
1181f13597dSJung-uk Kim___
1191f13597dSJung-uk Kim$code.=<<___ if ($i==79);	# with context load
1201f13597dSJung-uk Kim	ldw	0($ctx),@X[0]	; $i
1211f13597dSJung-uk Kim	addl	$K,$e,$e
1221f13597dSJung-uk Kim	shd	$a,$a,27,$t1
1231f13597dSJung-uk Kim	ldw	4($ctx),@X[1]
1241f13597dSJung-uk Kim	addl	@X[$i%16],$e,$e
1251f13597dSJung-uk Kim	xor	$b,$c,$t0
1261f13597dSJung-uk Kim	ldw	8($ctx),@X[2]
1271f13597dSJung-uk Kim	addl	$t1,$e,$e
1281f13597dSJung-uk Kim	shd	$b,$b,2,$b
1291f13597dSJung-uk Kim	xor	$d,$t0,$t0
1301f13597dSJung-uk Kim	ldw	12($ctx),@X[3]
1311f13597dSJung-uk Kim	addl	$t0,$e,$e
1321f13597dSJung-uk Kim	ldw	16($ctx),@X[4]
1331f13597dSJung-uk Kim___
1341f13597dSJung-uk Kim}
1351f13597dSJung-uk Kim
1361f13597dSJung-uk Kimsub BODY_40_59 {
1371f13597dSJung-uk Kimmy ($i,$a,$b,$c,$d,$e)=@_;
1381f13597dSJung-uk Kimmy $j=$i+1;
1391f13597dSJung-uk Kim$code.=<<___;
1401f13597dSJung-uk Kim	shd	$a,$a,27,$t1	; $i
1411f13597dSJung-uk Kim	addl	$K,$e,$e
1421f13597dSJung-uk Kim	xor	@X[($j+2)%16],@X[$j%16],@X[$j%16]
1431f13597dSJung-uk Kim	xor	$d,$c,$t0
1441f13597dSJung-uk Kim	addl	@X[$i%16],$e,$e
1451f13597dSJung-uk Kim	xor	@X[($j+8)%16],@X[$j%16],@X[$j%16]
1461f13597dSJung-uk Kim	and	$b,$t0,$t0
1471f13597dSJung-uk Kim	addl	$t1,$e,$e
1481f13597dSJung-uk Kim	shd	$b,$b,2,$b
1491f13597dSJung-uk Kim	xor	@X[($j+13)%16],@X[$j%16],@X[$j%16]
1501f13597dSJung-uk Kim	addl	$t0,$e,$e
1511f13597dSJung-uk Kim	and	$d,$c,$t1
1521f13597dSJung-uk Kim	shd	@X[$j%16],@X[$j%16],31,@X[$j%16]
1531f13597dSJung-uk Kim	addl	$t1,$e,$e
1541f13597dSJung-uk Kim___
1551f13597dSJung-uk Kim}
1561f13597dSJung-uk Kim
1571f13597dSJung-uk Kim$code=<<___;
1581f13597dSJung-uk Kim	.LEVEL	$LEVEL
1591f13597dSJung-uk Kim	.SPACE	\$TEXT\$
1601f13597dSJung-uk Kim	.SUBSPA	\$CODE\$,QUAD=0,ALIGN=8,ACCESS=0x2C,CODE_ONLY
1611f13597dSJung-uk Kim
1621f13597dSJung-uk Kim	.EXPORT	sha1_block_data_order,ENTRY,ARGW0=GR,ARGW1=GR,ARGW2=GR
1631f13597dSJung-uk Kimsha1_block_data_order
1641f13597dSJung-uk Kim	.PROC
1651f13597dSJung-uk Kim	.CALLINFO	FRAME=`$FRAME-14*$SIZE_T`,NO_CALLS,SAVE_RP,ENTRY_GR=16
1661f13597dSJung-uk Kim	.ENTRY
1671f13597dSJung-uk Kim	$PUSH	%r2,-$SAVED_RP(%sp)	; standard prologue
1681f13597dSJung-uk Kim	$PUSHMA	%r3,$FRAME(%sp)
1691f13597dSJung-uk Kim	$PUSH	%r4,`-$FRAME+1*$SIZE_T`(%sp)
1701f13597dSJung-uk Kim	$PUSH	%r5,`-$FRAME+2*$SIZE_T`(%sp)
1711f13597dSJung-uk Kim	$PUSH	%r6,`-$FRAME+3*$SIZE_T`(%sp)
1721f13597dSJung-uk Kim	$PUSH	%r7,`-$FRAME+4*$SIZE_T`(%sp)
1731f13597dSJung-uk Kim	$PUSH	%r8,`-$FRAME+5*$SIZE_T`(%sp)
1741f13597dSJung-uk Kim	$PUSH	%r9,`-$FRAME+6*$SIZE_T`(%sp)
1751f13597dSJung-uk Kim	$PUSH	%r10,`-$FRAME+7*$SIZE_T`(%sp)
1761f13597dSJung-uk Kim	$PUSH	%r11,`-$FRAME+8*$SIZE_T`(%sp)
1771f13597dSJung-uk Kim	$PUSH	%r12,`-$FRAME+9*$SIZE_T`(%sp)
1781f13597dSJung-uk Kim	$PUSH	%r13,`-$FRAME+10*$SIZE_T`(%sp)
1791f13597dSJung-uk Kim	$PUSH	%r14,`-$FRAME+11*$SIZE_T`(%sp)
1801f13597dSJung-uk Kim	$PUSH	%r15,`-$FRAME+12*$SIZE_T`(%sp)
1811f13597dSJung-uk Kim	$PUSH	%r16,`-$FRAME+13*$SIZE_T`(%sp)
1821f13597dSJung-uk Kim
1831f13597dSJung-uk Kim	ldw	0($ctx),$A
1841f13597dSJung-uk Kim	ldw	4($ctx),$B
1851f13597dSJung-uk Kim	ldw	8($ctx),$C
1861f13597dSJung-uk Kim	ldw	12($ctx),$D
1871f13597dSJung-uk Kim	ldw	16($ctx),$E
1881f13597dSJung-uk Kim
1891f13597dSJung-uk Kim	extru	$inp,31,2,$t0		; t0=inp&3;
1901f13597dSJung-uk Kim	sh3addl	$t0,%r0,$t0		; t0*=8;
1911f13597dSJung-uk Kim	subi	32,$t0,$t0		; t0=32-t0;
1921f13597dSJung-uk Kim	mtctl	$t0,%cr11		; %sar=t0;
1931f13597dSJung-uk Kim
1941f13597dSJung-uk KimL\$oop
1951f13597dSJung-uk Kim	ldi	3,$t0
1961f13597dSJung-uk Kim	andcm	$inp,$t0,$t0		; 64-bit neutral
1971f13597dSJung-uk Kim___
1981f13597dSJung-uk Kim	for ($i=0;$i<15;$i++) {		# load input block
1991f13597dSJung-uk Kim	$code.="\tldw	`4*$i`($t0),@X[$i]\n";		}
2001f13597dSJung-uk Kim$code.=<<___;
2011f13597dSJung-uk Kim	cmpb,*=	$inp,$t0,L\$aligned
2021f13597dSJung-uk Kim	ldw	60($t0),@X[15]
2031f13597dSJung-uk Kim	ldw	64($t0),@X[16]
2041f13597dSJung-uk Kim___
2051f13597dSJung-uk Kim	for ($i=0;$i<16;$i++) {		# align input
2061f13597dSJung-uk Kim	$code.="\tvshd	@X[$i],@X[$i+1],@X[$i]\n";	}
2071f13597dSJung-uk Kim$code.=<<___;
2081f13597dSJung-uk KimL\$aligned
2091f13597dSJung-uk Kim	ldil	L'0x5a827000,$K		; K_00_19
2101f13597dSJung-uk Kim	ldo	0x999($K),$K
2111f13597dSJung-uk Kim___
2121f13597dSJung-uk Kimfor ($i=0;$i<20;$i++)   { &BODY_00_19($i,@V); unshift(@V,pop(@V)); }
2131f13597dSJung-uk Kim$code.=<<___;
2141f13597dSJung-uk Kim	ldil	L'0x6ed9e000,$K		; K_20_39
2151f13597dSJung-uk Kim	ldo	0xba1($K),$K
2161f13597dSJung-uk Kim___
2171f13597dSJung-uk Kim
2181f13597dSJung-uk Kimfor (;$i<40;$i++)       { &BODY_20_39($i,@V); unshift(@V,pop(@V)); }
2191f13597dSJung-uk Kim$code.=<<___;
2201f13597dSJung-uk Kim	ldil	L'0x8f1bb000,$K		; K_40_59
2211f13597dSJung-uk Kim	ldo	0xcdc($K),$K
2221f13597dSJung-uk Kim___
2231f13597dSJung-uk Kim
2241f13597dSJung-uk Kimfor (;$i<60;$i++)       { &BODY_40_59($i,@V); unshift(@V,pop(@V)); }
2251f13597dSJung-uk Kim$code.=<<___;
2261f13597dSJung-uk Kim	ldil	L'0xca62c000,$K		; K_60_79
2271f13597dSJung-uk Kim	ldo	0x1d6($K),$K
2281f13597dSJung-uk Kim___
2291f13597dSJung-uk Kimfor (;$i<80;$i++)       { &BODY_20_39($i,@V); unshift(@V,pop(@V)); }
2301f13597dSJung-uk Kim
2311f13597dSJung-uk Kim$code.=<<___;
2321f13597dSJung-uk Kim	addl	@X[0],$A,$A
2331f13597dSJung-uk Kim	addl	@X[1],$B,$B
2341f13597dSJung-uk Kim	addl	@X[2],$C,$C
2351f13597dSJung-uk Kim	addl	@X[3],$D,$D
2361f13597dSJung-uk Kim	addl	@X[4],$E,$E
2371f13597dSJung-uk Kim	stw	$A,0($ctx)
2381f13597dSJung-uk Kim	stw	$B,4($ctx)
2391f13597dSJung-uk Kim	stw	$C,8($ctx)
2401f13597dSJung-uk Kim	stw	$D,12($ctx)
2411f13597dSJung-uk Kim	stw	$E,16($ctx)
2421f13597dSJung-uk Kim	addib,*<> -1,$num,L\$oop
2431f13597dSJung-uk Kim	ldo	64($inp),$inp
2441f13597dSJung-uk Kim
2451f13597dSJung-uk Kim	$POP	`-$FRAME-$SAVED_RP`(%sp),%r2	; standard epilogue
2461f13597dSJung-uk Kim	$POP	`-$FRAME+1*$SIZE_T`(%sp),%r4
2471f13597dSJung-uk Kim	$POP	`-$FRAME+2*$SIZE_T`(%sp),%r5
2481f13597dSJung-uk Kim	$POP	`-$FRAME+3*$SIZE_T`(%sp),%r6
2491f13597dSJung-uk Kim	$POP	`-$FRAME+4*$SIZE_T`(%sp),%r7
2501f13597dSJung-uk Kim	$POP	`-$FRAME+5*$SIZE_T`(%sp),%r8
2511f13597dSJung-uk Kim	$POP	`-$FRAME+6*$SIZE_T`(%sp),%r9
2521f13597dSJung-uk Kim	$POP	`-$FRAME+7*$SIZE_T`(%sp),%r10
2531f13597dSJung-uk Kim	$POP	`-$FRAME+8*$SIZE_T`(%sp),%r11
2541f13597dSJung-uk Kim	$POP	`-$FRAME+9*$SIZE_T`(%sp),%r12
2551f13597dSJung-uk Kim	$POP	`-$FRAME+10*$SIZE_T`(%sp),%r13
2561f13597dSJung-uk Kim	$POP	`-$FRAME+11*$SIZE_T`(%sp),%r14
2571f13597dSJung-uk Kim	$POP	`-$FRAME+12*$SIZE_T`(%sp),%r15
2581f13597dSJung-uk Kim	$POP	`-$FRAME+13*$SIZE_T`(%sp),%r16
2591f13597dSJung-uk Kim	bv	(%r2)
2601f13597dSJung-uk Kim	.EXIT
2611f13597dSJung-uk Kim	$POPMB	-$FRAME(%sp),%r3
2621f13597dSJung-uk Kim	.PROCEND
2631f13597dSJung-uk Kim	.STRINGZ "SHA1 block transform for PA-RISC, CRYPTOGAMS by <appro\@openssl.org>"
2641f13597dSJung-uk Kim___
2651f13597dSJung-uk Kim
266e71b7053SJung-uk Kimif (`$ENV{CC} -Wa,-v -c -o /dev/null -x assembler /dev/null 2>&1`
267e71b7053SJung-uk Kim	=~ /GNU assembler/) {
268e71b7053SJung-uk Kim    $gnuas = 1;
269e71b7053SJung-uk Kim}
270e71b7053SJung-uk Kim
271e71b7053SJung-uk Kimforeach(split("\n",$code)) {
272e71b7053SJung-uk Kim	s/\`([^\`]*)\`/eval $1/ge;
273e71b7053SJung-uk Kim
274e71b7053SJung-uk Kim	s/(\.LEVEL\s+2\.0)W/$1w/	if ($gnuas && $SIZE_T==8);
275e71b7053SJung-uk Kim	s/\.SPACE\s+\$TEXT\$/.text/	if ($gnuas && $SIZE_T==8);
276e71b7053SJung-uk Kim	s/\.SUBSPA.*//			if ($gnuas && $SIZE_T==8);
277e71b7053SJung-uk Kim	s/,\*/,/			if ($SIZE_T==4);
278e71b7053SJung-uk Kim	s/\bbv\b/bve/			if ($SIZE_T==8);
279e71b7053SJung-uk Kim
280e71b7053SJung-uk Kim	print $_,"\n";
281e71b7053SJung-uk Kim}
28217f01e99SJung-uk Kimclose STDOUT or die "error closing STDOUT: $!";
283