3 # ====================================================================
4 # Written by Andy Polyakov <appro@openssl.org> for the OpenSSL
5 # project. The module is, however, dual licensed under OpenSSL and
6 # CRYPTOGAMS licenses depending on where you obtain it. For further
7 # details see http://www.openssl.org/~appro/cryptogams/.
8 # ====================================================================
12 # The module implements "4-bit" GCM GHASH function and underlying
13 # single multiplication operation in GF(2^128). "4-bit" means that it
14 # uses 256 bytes per-key table [+128 bytes shared table]. Performance
15 # results are for streamed GHASH subroutine on UltraSPARC pre-Tx CPU
16 # and are expressed in cycles per processed byte, less is better:
18 # gcc 3.3.x cc 5.2 this assembler
20 # 32-bit build 81.0 48.6 11.8 (+586%/+311%)
21 # 64-bit build 27.5 20.3 11.8 (+133%/+72%)
23 # I don't quite understand why difference between 32-bit and 64-bit
24 # compiler-generated code is so big. Compilers *were* instructed to
25 # generate code for UltraSPARC and should have used 64-bit registers
26 # for Z vector (see C code) even in 32-bit build... Oh well, it only
27 # means more impressive improvement coefficients for this assembler
28 # module;-) Loops are aggressively modulo-scheduled in respect to
29 # references to input data and Z.hi updates to achieve 12 cycles
30 # timing. To anchor to something else, sha1-sparcv9.pl spends 11.6
31 # cycles to process one byte [on UltraSPARC pre-Tx CPU].
34 for (@ARGV) { $bits=64 if (/\-m64/ || /\-xarch\=v9/); }
35 if ($bits==64) { $bias=2047; $frame=192; }
36 else { $bias=0; $frame=112; }
39 open STDOUT,">$output";
41 $Zhi="%o0"; # 64-bit values
48 $nhi="%l0"; # small values and pointers
57 $Xi="%i0"; # input argument block
63 .section ".text",#alloc,#execinstr
67 .long `0x0000<<16`,0,`0x1C20<<16`,0,`0x3840<<16`,0,`0x2460<<16`,0
68 .long `0x7080<<16`,0,`0x6CA0<<16`,0,`0x48C0<<16`,0,`0x54E0<<16`,0
69 .long `0xE100<<16`,0,`0xFD20<<16`,0,`0xD940<<16`,0,`0xC560<<16`,0
70 .long `0x9180<<16`,0,`0x8DA0<<16`,0,`0xA9C0<<16`,0,`0xB5E0<<16`,0
71 .type rem_4bit,#object
72 .size rem_4bit,(.-rem_4bit)
85 add %o7,rem_4bit-1b,$rem_4bit
92 ldx [$Htblo+$nlo],$Zlo
97 ldx [$Htblo+$nhi],$Tlo
101 ldx [$rem_4bit+$remi],$rem
117 ldx [$Htblo+$nlo],$Tlo
120 ldx [$Htbl+$nlo],$Thi
123 ldx [$rem_4bit+$remi],$rem
126 ldub [$inp+$cnt],$nlo
133 ldx [$Htblo+$nhi],$Tlo
136 ldx [$Htbl+$nhi],$Thi
138 ldx [$rem_4bit+$remi],$rem
151 ldx [$Htblo+$nlo],$Tlo
154 ldx [$Htbl+$nlo],$Thi
157 ldx [$rem_4bit+$remi],$rem
166 be,pn `$bits==64?"%xcc":"%icc"`,.Ldone
169 ldx [$Htblo+$nhi],$Tlo
172 ldx [$Htbl+$nhi],$Thi
174 ldx [$rem_4bit+$remi],$rem
190 ldx [$Htblo+$nhi],$Tlo
193 ldx [$Htbl+$nhi],$Thi
195 ldx [$rem_4bit+$remi],$rem
207 .type gcm_ghash_4bit,#function
208 .size gcm_ghash_4bit,(.-gcm_ghash_4bit)
215 .globl gcm_gmult_4bit
223 add %o7,rem_4bit-1b,$rem_4bit
228 ldx [$Htblo+$nlo],$Zlo
229 ldx [$Htbl+$nlo],$Zhi
233 ldx [$Htblo+$nhi],$Tlo
235 ldx [$Htbl+$nhi],$Thi
237 ldx [$rem_4bit+$remi],$rem
252 ldx [$Htblo+$nlo],$Tlo
255 ldx [$Htbl+$nlo],$Thi
258 ldx [$rem_4bit+$remi],$rem
267 ldx [$Htblo+$nhi],$Tlo
270 ldx [$Htbl+$nhi],$Thi
272 ldx [$rem_4bit+$remi],$rem
284 ldx [$Htblo+$nlo],$Tlo
287 ldx [$Htbl+$nlo],$Thi
290 ldx [$rem_4bit+$remi],$rem
298 ldx [$Htblo+$nhi],$Tlo
301 ldx [$Htbl+$nhi],$Thi
303 ldx [$rem_4bit+$remi],$rem
315 .type gcm_gmult_4bit,#function
316 .size gcm_gmult_4bit,(.-gcm_gmult_4bit)
317 .asciz "GHASH for SPARCv9, CRYPTOGAMS by <appro\@openssl.org>"
320 $code =~ s/\`([^\`]*)\`/eval $1/gem;