2 # Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
4 # Licensed under the OpenSSL license (the "License"). You may not use
5 # this file except in compliance with the License. You can obtain a copy
6 # in the file LICENSE in the source distribution or at
7 # https://www.openssl.org/source/license.html
10 # ====================================================================
11 # Written by Andy Polyakov <appro@openssl.org> for the OpenSSL
12 # project. The module is, however, dual licensed under OpenSSL and
13 # CRYPTOGAMS licenses depending on where you obtain it. For further
14 # details see http://www.openssl.org/~appro/cryptogams/.
15 # ====================================================================
17 # This module implements Poly1305 hash for SPARCv9, vanilla, as well
18 # as VIS3 and FMA extensions.
22 # Numbers are cycles per processed byte with poly1305_blocks alone.
26 # UltraSPARC III 12.3(**)
28 # SPARC T4 1.70(***) 6.55
31 # (*) Comparison to compiler-generated code is really problematic,
32 # because latter's performance varies too much depending on too
33 # many variables. For example, one can measure from 5x to 15x
34 # improvement on T4 for gcc-4.6. Well, in T4 case it's a bit
35 # unfair comparison, because compiler doesn't use VIS3, but
36 # given same initial conditions coefficient varies from 3x to 9x.
37 # (**) Pre-III performance should be even worse; floating-point
38 # performance for UltraSPARC I-IV on the other hand is reported
39 # to be 4.25 for hand-coded assembly, but they are just too old
41 # (***) Multi-process benchmark saturates at ~12.5x single-process
42 # result on 8-core processor, or ~21GBps per 2.85GHz socket.
45 open STDOUT,">$output";
47 my ($ctx,$inp,$len,$padbit,$shl,$shr) = map("%i$_",(0..5));
48 my ($r0,$r1,$r2,$r3,$s1,$s2,$s3,$h4) = map("%l$_",(0..7));
49 my ($h0,$h1,$h2,$h3, $t0,$t1,$t2) = map("%o$_",(0..5,7));
50 my ($d0,$d1,$d2,$d3) = map("%g$_",(1..4));
53 open STDOUT,">$stdout";
56 #include "sparc_arch.h"
59 .register %g2,#scratch
60 .register %g3,#scratch
67 #define LOCALS (STACK_BIAS+STACK_FRAME)
69 .section ".text",#alloc,#execinstr
78 save %sp,-STACK_FRAME-16,%sp
81 SPARC_LOAD_ADDRESS(OPENSSL_sparcv9cap_P,%g1)
84 and %g1,SPARCV9_FMADD|SPARCV9_VIS3,%g1
86 be .Lpoly1305_init_fma
90 stx %g0,[$ctx+8] ! zero hash value
94 and $inp,7,$shr ! alignment factor
99 sethi %hi(0x0ffffffc),$t0
101 or $t0,%lo(0x0ffffffc),$t0
104 or $t0,$t1,$t1 ! 0x0ffffffc0ffffffc
105 or $t1,3,$t0 ! 0x0ffffffc0fffffff
107 ldxa [$inp+%g0]0x88,$h0 ! load little-endian key
108 brz,pt $shr,.Lkey_aligned
109 ldxa [$inp+$h1]0x88,$h1
111 ldxa [$inp+$h2]0x88,$h2
122 stx $h0,[$ctx+32+0] ! store key
125 andcc %g1,SPARCV9_VIS3,%g0
130 add %o7,poly1305_blocks_vis3-1b,%o7
132 add %o7,poly1305_emit-poly1305_blocks_vis3,%o5
134 STPTR %o5,[%i2+SIZE_T]
137 restore %g0,1,%o0 ! return 1
141 restore %g0,%g0,%o0 ! return 0
142 .size poly1305_init,.-poly1305_init
144 .globl poly1305_blocks
147 save %sp,-STACK_FRAME,%sp
150 brz,pn $len,.Lno_data
153 ld [$ctx+32+0],$r1 ! load key
158 ld [$ctx+0],$h1 ! load hash value
164 and $inp,7,$shr ! alignment factor
179 ldxa [$inp+%g0]0x88,$d0 ! load little-endian input
180 brz,pt $shr,.Linp_aligned
181 ldxa [$inp+$d1]0x88,$d1
183 ldxa [$inp+$d2]0x88,$d2
193 addcc $d0,$h0,$h0 ! accumulate input
253 srl $h4,2,$t0 ! final reduction step
265 st $h1,[$ctx+0] ! store hash value
274 .size poly1305_blocks,.-poly1305_blocks
276 ########################################################################
277 # VIS3 has umulxhi and addxc...
279 my ($H0,$H1,$H2,$R0,$R1,$S1,$T1) = map("%o$_",(0..5,7));
280 my ($D0,$D1,$D2,$T0) = map("%g$_",(1..4));
284 poly1305_blocks_vis3:
285 save %sp,-STACK_FRAME,%sp
288 brz,pn $len,.Lno_data
291 ldx [$ctx+32+0],$R0 ! load key
294 ldx [$ctx+0],$H0 ! load hash value
298 and $inp,7,$shr ! alignment factor
310 ldxa [$inp+%g0]0x88,$D0 ! load little-endian input
311 brz,pt $shr,.Linp_aligned_vis3
312 ldxa [$inp+$r1]0x88,$D1
314 ldxa [$inp+$r2]0x88,$D2
323 addcc $D0,$H0,$H0 ! accumulate input
328 mulx $R0,$H0,$D0 ! r0*h0
329 addxc $padbit,$H2,$H2
331 mulx $S1,$H1,$T0 ! s1*h1
334 mulx $R1,$H0,$T0 ! r1*h0
338 mulx $R0,$H1,$T0 ! r0*h1
342 mulx $S1,$H2,$T0 ! s1*h2
344 mulx $R0,$H2,$T1 ! r0*h2
348 srlx $D2,2,$T0 ! final reduction step
355 brnz,pt $len,.Loop_vis3
358 stx $H0,[$ctx+0] ! store hash value
364 .size poly1305_blocks_vis3,.-poly1305_blocks_vis3
367 my ($mac,$nonce) = ($inp,$len);
373 save %sp,-STACK_FRAME,%sp
375 ld [$ctx+0],$h1 ! load hash value
381 addcc $h0,5,$r0 ! compare to modulus
386 andcc $h4,4,%g0 ! did it carry/borrow?
389 ld [$nonce+0],$r0 ! load nonce
397 addcc $r0,$h0,$h0 ! accumulate nonce
403 stb $h0,[$mac+0] ! store little-endian result
436 .size poly1305_emit,.-poly1305_emit
440 my ($ctx,$inp,$len,$padbit) = map("%i$_",(0..3));
441 my ($in0,$in1,$in2,$in3,$in4) = map("%o$_",(0..4));
442 my ($i1,$step,$shr,$shl) = map("%l$_",(0..7));
445 my ($h0lo,$h0hi,$h1lo,$h1hi,$h2lo,$h2hi,$h3lo,$h3hi,
446 $two0,$two32,$two64,$two96,$two130,$five_two130,
447 $r0lo,$r0hi,$r1lo,$r1hi,$r2lo,$r2hi,
448 $s2lo,$s2hi,$s3lo,$s3hi,
449 $c0lo,$c0hi,$c1lo,$c1hi,$c2lo,$c2hi,$c3lo,$c3hi) = map("%f".2*$_,(0..31));
451 my ($r3lo,$r3hi,$s1lo,$s1hi) = ($c0lo,$c0hi,$c1lo,$c1hi);
452 my ($x0,$x1,$x2,$x3) = ($c2lo,$c2hi,$c3lo,$c3hi);
453 my ($y0,$y1,$y2,$y3) = ($c1lo,$c1hi,$c3hi,$c3lo);
458 save %sp,-STACK_FRAME-16,%sp
463 add %o7,.Lconsts_fma-1b,%o7
465 ldd [%o7+8*0],$two0 ! load constants
469 ldd [%o7+8*5],$five_two130
471 std $two0,[$ctx+8*0] ! initial hash value, biased 0
472 std $two32,[$ctx+8*1]
473 std $two64,[$ctx+8*2]
474 std $two96,[$ctx+8*3]
476 brz,pn $inp,.Lno_key_fma
479 stx %fsr,[%sp+LOCALS] ! save original %fsr
480 ldx [%o7+8*6],%fsr ! load new %fsr
482 std $two0,[$ctx+8*4] ! key "template"
483 std $two32,[$ctx+8*5]
484 std $two64,[$ctx+8*6]
485 std $two96,[$ctx+8*7]
488 andn $inp,7,$inp ! align pointer
494 ldxa [$inp+%g0]0x88,$in0 ! load little-endian key
495 ldxa [$inp+$i1]0x88,$in2
497 brz $shr,.Lkey_aligned_fma
498 sethi %hi(0xf0000000),$i1 ! 0xf0000000
500 ldxa [$inp+$i2]0x88,$in4
502 srlx $in0,$shr,$in0 ! align data
510 or $i1,3,$i2 ! 0xf0000003
512 andn $in0,$i1,$in0 ! &=0x0fffffff
513 andn $in1,$i2,$in1 ! &=0x0ffffffc
518 st $in0,[$ctx+`8*4+4`] ! fill "template"
519 st $in1,[$ctx+`8*5+4`]
520 st $in2,[$ctx+`8*6+4`]
521 st $in3,[$ctx+`8*7+4`]
523 ldd [$ctx+8*4],$h0lo ! load [biased] key
528 fsubd $h0lo,$two0, $h0lo ! r0
529 ldd [%o7+8*7],$two0 ! more constants
530 fsubd $h1lo,$two32,$h1lo ! r1
532 fsubd $h2lo,$two64,$h2lo ! r2
534 fsubd $h3lo,$two96,$h3lo ! r3
535 ldd [%o7+8*10],$two96
537 fmuld $five_two130,$h1lo,$s1lo ! s1
538 fmuld $five_two130,$h2lo,$s2lo ! s2
539 fmuld $five_two130,$h3lo,$s3lo ! s3
541 faddd $h0lo,$two0, $h0hi
542 faddd $h1lo,$two32,$h1hi
543 faddd $h2lo,$two64,$h2hi
544 faddd $h3lo,$two96,$h3hi
546 fsubd $h0hi,$two0, $h0hi
547 ldd [%o7+8*11],$two0 ! more constants
548 fsubd $h1hi,$two32,$h1hi
549 ldd [%o7+8*12],$two32
550 fsubd $h2hi,$two64,$h2hi
551 ldd [%o7+8*13],$two64
552 fsubd $h3hi,$two96,$h3hi
554 fsubd $h0lo,$h0hi,$h0lo
555 std $h0hi,[$ctx+8*5] ! r0hi
556 fsubd $h1lo,$h1hi,$h1lo
557 std $h1hi,[$ctx+8*7] ! r1hi
558 fsubd $h2lo,$h2hi,$h2lo
559 std $h2hi,[$ctx+8*9] ! r2hi
560 fsubd $h3lo,$h3hi,$h3lo
561 std $h3hi,[$ctx+8*11] ! r3hi
563 faddd $s1lo,$two0, $s1hi
564 faddd $s2lo,$two32,$s2hi
565 faddd $s3lo,$two64,$s3hi
567 fsubd $s1hi,$two0, $s1hi
568 fsubd $s2hi,$two32,$s2hi
569 fsubd $s3hi,$two64,$s3hi
571 fsubd $s1lo,$s1hi,$s1lo
572 fsubd $s2lo,$s2hi,$s2lo
573 fsubd $s3lo,$s3hi,$s3lo
575 ldx [%sp+LOCALS],%fsr ! restore %fsr
577 std $h0lo,[$ctx+8*4] ! r0lo
578 std $h1lo,[$ctx+8*6] ! r1lo
579 std $h2lo,[$ctx+8*8] ! r2lo
580 std $h3lo,[$ctx+8*10] ! r3lo
582 std $s1hi,[$ctx+8*13]
583 std $s2hi,[$ctx+8*15]
584 std $s3hi,[$ctx+8*17]
586 std $s1lo,[$ctx+8*12]
587 std $s2lo,[$ctx+8*14]
588 std $s3lo,[$ctx+8*16]
590 add %o7,poly1305_blocks_fma-.Lconsts_fma,%o0
591 add %o7,poly1305_emit_fma-.Lconsts_fma,%o1
593 STPTR %o1,[%i2+SIZE_T]
596 restore %g0,1,%o0 ! return 1
600 restore %g0,%g0,%o0 ! return 0
601 .size poly1305_init_fma,.-poly1305_init_fma
605 save %sp,-STACK_FRAME-48,%sp
612 add %o7,.Lconsts_fma-1b,%o7
614 ldd [%o7+8*0],$two0 ! load constants
618 ldd [%o7+8*4],$two130
619 ldd [%o7+8*5],$five_two130
621 ldd [$ctx+8*0],$h0lo ! load [biased] hash value
626 std $two0,[%sp+LOCALS+8*0] ! input "template"
627 sethi %hi((1023+52+96)<<20),$in3
628 std $two32,[%sp+LOCALS+8*1]
630 std $two64,[%sp+LOCALS+8*2]
631 st $in3,[%sp+LOCALS+8*3]
634 andn $inp,7,$inp ! align pointer
640 ldxa [$inp+%g0]0x88,$in0 ! load little-endian input
641 brz $shr,.Linp_aligned_fma
642 ldxa [$inp+$i1]0x88,$in2
644 ldxa [$inp+$step]0x88,$in4
647 srlx $in0,$shr,$in0 ! align data
652 srlx $in4,$shr,$in4 ! pre-shift
659 add $step,$inp,$inp ! conditional advance
661 st $in0,[%sp+LOCALS+8*0+4] ! fill "template"
662 st $in1,[%sp+LOCALS+8*1+4]
663 st $in2,[%sp+LOCALS+8*2+4]
664 st $in3,[%sp+LOCALS+8*3+4]
666 ldd [$ctx+8*4],$r0lo ! load key
672 ldd [$ctx+8*10],$r3lo
673 ldd [$ctx+8*11],$r3hi
674 ldd [$ctx+8*12],$s1lo
675 ldd [$ctx+8*13],$s1hi
676 ldd [$ctx+8*14],$s2lo
677 ldd [$ctx+8*15],$s2hi
678 ldd [$ctx+8*16],$s3lo
679 ldd [$ctx+8*17],$s3hi
681 stx %fsr,[%sp+LOCALS+8*4] ! save original %fsr
682 ldx [%o7+8*6],%fsr ! load new %fsr
687 ldd [%sp+LOCALS+8*0],$x0 ! load biased input
688 ldd [%sp+LOCALS+8*1],$x1
689 ldd [%sp+LOCALS+8*2],$x2
690 ldd [%sp+LOCALS+8*3],$x3
692 fsubd $h0lo,$two0, $h0lo ! de-bias hash value
693 fsubd $h1lo,$two32,$h1lo
694 ldxa [$inp+%g0]0x88,$in0 ! modulo-scheduled input load
695 fsubd $h2lo,$two64,$h2lo
696 fsubd $h3lo,$two96,$h3lo
697 ldxa [$inp+$i1]0x88,$in2
699 fsubd $x0,$two0, $x0 ! de-bias input
704 brz $shr,.Linp_aligned_fma2
705 add $step,$inp,$inp ! conditional advance
707 sllx $in0,$shl,$in1 ! align data
711 srlx $in2,$shr,$in4 ! pre-shift
717 faddd $h0lo,$x0,$x0 ! accumulate input
718 stw $in0,[%sp+LOCALS+8*0+4]
720 stw $in1,[%sp+LOCALS+8*1+4]
722 stw $in2,[%sp+LOCALS+8*2+4]
724 stw $in3,[%sp+LOCALS+8*3+4]
731 ldxa [$inp+%g0]0x88,$in0 ! modulo-scheduled input load
732 ldxa [$inp+$i1]0x88,$in2
735 faddd $y0,$h0lo,$h0lo ! accumulate input
736 faddd $y1,$h0hi,$h0hi
737 faddd $y2,$h2lo,$h2lo
738 faddd $y3,$h2hi,$h2hi
740 brz,pn $shr,.Linp_aligned_fma3
741 add $step,$inp,$inp ! conditional advance
743 sllx $in0,$shl,$in1 ! align data
747 srlx $in2,$shr,$in4 ! pre-shift
751 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! base 2^48 -> base 2^32
752 faddd $two64,$h1lo,$c1lo
754 faddd $two64,$h1hi,$c1hi
756 faddd $two130,$h3lo,$c3lo
757 st $in0,[%sp+LOCALS+8*0+4] ! fill "template"
758 faddd $two130,$h3hi,$c3hi
759 st $in1,[%sp+LOCALS+8*1+4]
760 faddd $two32,$h0lo,$c0lo
761 st $in2,[%sp+LOCALS+8*2+4]
762 faddd $two32,$h0hi,$c0hi
763 st $in3,[%sp+LOCALS+8*3+4]
764 faddd $two96,$h2lo,$c2lo
765 faddd $two96,$h2hi,$c2hi
767 fsubd $c1lo,$two64,$c1lo
768 fsubd $c1hi,$two64,$c1hi
769 fsubd $c3lo,$two130,$c3lo
770 fsubd $c3hi,$two130,$c3hi
771 fsubd $c0lo,$two32,$c0lo
772 fsubd $c0hi,$two32,$c0hi
773 fsubd $c2lo,$two96,$c2lo
774 fsubd $c2hi,$two96,$c2hi
776 fsubd $h1lo,$c1lo,$h1lo
777 fsubd $h1hi,$c1hi,$h1hi
778 fsubd $h3lo,$c3lo,$h3lo
779 fsubd $h3hi,$c3hi,$h3hi
780 fsubd $h2lo,$c2lo,$h2lo
781 fsubd $h2hi,$c2hi,$h2hi
782 fsubd $h0lo,$c0lo,$h0lo
783 fsubd $h0hi,$c0hi,$h0hi
785 faddd $h1lo,$c0lo,$h1lo
786 faddd $h1hi,$c0hi,$h1hi
787 faddd $h3lo,$c2lo,$h3lo
788 faddd $h3hi,$c2hi,$h3hi
789 faddd $h2lo,$c1lo,$h2lo
790 faddd $h2hi,$c1hi,$h2hi
791 fmaddd $five_two130,$c3lo,$h0lo,$h0lo
792 fmaddd $five_two130,$c3hi,$h0hi,$h0hi
794 faddd $h1lo,$h1hi,$x1
795 ldd [$ctx+8*12],$s1lo ! reload constants
796 faddd $h3lo,$h3hi,$x3
797 ldd [$ctx+8*13],$s1hi
798 faddd $h2lo,$h2hi,$x2
799 ldd [$ctx+8*10],$r3lo
800 faddd $h0lo,$h0hi,$x0
801 ldd [$ctx+8*11],$r3hi
804 fmuld $x1,$s3lo,$h0lo
805 fmuld $x1,$s3hi,$h0hi
806 fmuld $x1,$r1lo,$h2lo
807 fmuld $x1,$r1hi,$h2hi
808 fmuld $x1,$r0lo,$h1lo
809 fmuld $x1,$r0hi,$h1hi
810 fmuld $x1,$r2lo,$h3lo
811 fmuld $x1,$r2hi,$h3hi
813 fmaddd $x3,$s1lo,$h0lo,$h0lo
814 fmaddd $x3,$s1hi,$h0hi,$h0hi
815 fmaddd $x3,$s3lo,$h2lo,$h2lo
816 fmaddd $x3,$s3hi,$h2hi,$h2hi
817 fmaddd $x3,$s2lo,$h1lo,$h1lo
818 fmaddd $x3,$s2hi,$h1hi,$h1hi
819 fmaddd $x3,$r0lo,$h3lo,$h3lo
820 fmaddd $x3,$r0hi,$h3hi,$h3hi
822 fmaddd $x2,$s2lo,$h0lo,$h0lo
823 fmaddd $x2,$s2hi,$h0hi,$h0hi
824 fmaddd $x2,$r0lo,$h2lo,$h2lo
825 fmaddd $x2,$r0hi,$h2hi,$h2hi
826 fmaddd $x2,$s3lo,$h1lo,$h1lo
827 ldd [%sp+LOCALS+8*0],$y0 ! load [biased] input
828 fmaddd $x2,$s3hi,$h1hi,$h1hi
829 ldd [%sp+LOCALS+8*1],$y1
830 fmaddd $x2,$r1lo,$h3lo,$h3lo
831 ldd [%sp+LOCALS+8*2],$y2
832 fmaddd $x2,$r1hi,$h3hi,$h3hi
833 ldd [%sp+LOCALS+8*3],$y3
835 fmaddd $x0,$r0lo,$h0lo,$h0lo
836 fsubd $y0,$two0, $y0 ! de-bias input
837 fmaddd $x0,$r0hi,$h0hi,$h0hi
839 fmaddd $x0,$r2lo,$h2lo,$h2lo
841 fmaddd $x0,$r2hi,$h2hi,$h2hi
843 fmaddd $x0,$r1lo,$h1lo,$h1lo
844 fmaddd $x0,$r1hi,$h1hi,$h1hi
845 fmaddd $x0,$r3lo,$h3lo,$h3lo
846 fmaddd $x0,$r3hi,$h3hi,$h3hi
848 bcc SIZE_T_CC,.Loop_fma
851 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! base 2^48 -> base 2^32
852 faddd $h0lo,$two32,$c0lo
853 faddd $h0hi,$two32,$c0hi
854 faddd $h2lo,$two96,$c2lo
855 faddd $h2hi,$two96,$c2hi
856 faddd $h1lo,$two64,$c1lo
857 faddd $h1hi,$two64,$c1hi
858 faddd $h3lo,$two130,$c3lo
859 faddd $h3hi,$two130,$c3hi
861 fsubd $c0lo,$two32,$c0lo
862 fsubd $c0hi,$two32,$c0hi
863 fsubd $c2lo,$two96,$c2lo
864 fsubd $c2hi,$two96,$c2hi
865 fsubd $c1lo,$two64,$c1lo
866 fsubd $c1hi,$two64,$c1hi
867 fsubd $c3lo,$two130,$c3lo
868 fsubd $c3hi,$two130,$c3hi
870 fsubd $h1lo,$c1lo,$h1lo
871 fsubd $h1hi,$c1hi,$h1hi
872 fsubd $h3lo,$c3lo,$h3lo
873 fsubd $h3hi,$c3hi,$h3hi
874 fsubd $h2lo,$c2lo,$h2lo
875 fsubd $h2hi,$c2hi,$h2hi
876 fsubd $h0lo,$c0lo,$h0lo
877 fsubd $h0hi,$c0hi,$h0hi
879 faddd $h1lo,$c0lo,$h1lo
880 faddd $h1hi,$c0hi,$h1hi
881 faddd $h3lo,$c2lo,$h3lo
882 faddd $h3hi,$c2hi,$h3hi
883 faddd $h2lo,$c1lo,$h2lo
884 faddd $h2hi,$c1hi,$h2hi
885 fmaddd $five_two130,$c3lo,$h0lo,$h0lo
886 fmaddd $five_two130,$c3hi,$h0hi,$h0hi
888 faddd $h1lo,$h1hi,$x1
889 faddd $h3lo,$h3hi,$x3
890 faddd $h2lo,$h2hi,$x2
891 faddd $h0lo,$h0hi,$x0
893 faddd $x1,$two32,$x1 ! bias
898 ldx [%sp+LOCALS+8*4],%fsr ! restore saved %fsr
900 std $x1,[$ctx+8*1] ! store [biased] hash value
908 .size poly1305_blocks_fma,.-poly1305_blocks_fma
911 my ($mac,$nonce)=($inp,$len);
913 my ($h0,$h1,$h2,$h3,$h4, $d0,$d1,$d2,$d3, $mask
914 ) = (map("%l$_",(0..5)),map("%o$_",(0..4)));
919 save %sp,-STACK_FRAME,%sp
921 ld [$ctx+8*0+0],$d0 ! load hash
930 sethi %hi(0xfff00000),$mask
931 andn $d0,$mask,$d0 ! mask exponent
934 andn $d3,$mask,$d3 ! can be partially reduced...
937 srl $d3,2,$padbit ! ... so reduce
948 addcc $h0,5,$d0 ! compare to modulus
954 srl $mask,2,$mask ! did it carry/borrow?
956 sra $mask,31,$mask ! mask
963 ld [$nonce+0],$d0 ! load nonce
975 addcc $d0,$h0,$h0 ! accumulate nonce
980 stb $h0,[$mac+0] ! write little-endian result
1014 .size poly1305_emit_fma,.-poly1305_emit_fma
1021 .word 0x43300000,0x00000000 ! 2^(52+0)
1022 .word 0x45300000,0x00000000 ! 2^(52+32)
1023 .word 0x47300000,0x00000000 ! 2^(52+64)
1024 .word 0x49300000,0x00000000 ! 2^(52+96)
1025 .word 0x4b500000,0x00000000 ! 2^(52+130)
1027 .word 0x37f40000,0x00000000 ! 5/2^130
1028 .word 0,1<<30 ! fsr: truncate, no exceptions
1030 .word 0x44300000,0x00000000 ! 2^(52+16+0)
1031 .word 0x46300000,0x00000000 ! 2^(52+16+32)
1032 .word 0x48300000,0x00000000 ! 2^(52+16+64)
1033 .word 0x4a300000,0x00000000 ! 2^(52+16+96)
1034 .word 0x3e300000,0x00000000 ! 2^(52+16+0-96)
1035 .word 0x40300000,0x00000000 ! 2^(52+16+32-96)
1036 .word 0x42300000,0x00000000 ! 2^(52+16+64-96)
1037 .asciz "Poly1305 for SPARCv9/VIS3/FMA, CRYPTOGAMS by <appro\@openssl.org>"
1042 # Purpose of these subroutines is to explicitly encode VIS instructions,
1043 # so that one can compile the module without having to specify VIS
1044 # extensions on compiler command line, e.g. -xarch=v9 vs. -xarch=v9a.
1045 # Idea is to reserve for option to produce "universal" binary and let
1046 # programmer detect if current CPU is VIS capable at run-time.
1048 my ($mnemonic,$rs1,$rs2,$rd)=@_;
1049 my %bias = ( "g" => 0, "o" => 8, "l" => 16, "i" => 24 );
1051 my %visopf = ( "addxc" => 0x011,
1053 "umulxhi" => 0x016 );
1055 $ref = "$mnemonic\t$rs1,$rs2,$rd";
1057 if ($opf=$visopf{$mnemonic}) {
1058 foreach ($rs1,$rs2,$rd) {
1059 return $ref if (!/%([goli])([0-9])/);
1063 return sprintf ".word\t0x%08x !%s",
1064 0x81b00000|$rd<<25|$rs1<<14|$opf<<5|$rs2,
1072 my ($mnemonic,$rs1,$rs2,$rs3,$rd)=@_;
1074 my %fmaopf = ( "fmadds" => 0x1,
1079 $ref = "$mnemonic\t$rs1,$rs2,$rs3,$rd";
1081 if ($opf=$fmaopf{$mnemonic}) {
1082 foreach ($rs1,$rs2,$rs3,$rd) {
1083 return $ref if (!/%f([0-9]{1,2})/);
1086 return $ref if ($1&1);
1087 # re-encode for upper double register addressing
1092 return sprintf ".word\t0x%08x !%s",
1093 0x81b80000|$rd<<25|$rs1<<14|$rs3<<9|$opf<<5|$rs2,
1100 foreach (split("\n",$code)) {
1101 s/\`([^\`]*)\`/eval $1/ge;
1103 s/\b(umulxhi|addxc[c]{0,2})\s+(%[goli][0-7]),\s*(%[goli][0-7]),\s*(%[goli][0-7])/
1104 &unvis3($1,$2,$3,$4)
1106 s/\b(fmadd[sd])\s+(%f[0-9]+),\s*(%f[0-9]+),\s*(%f[0-9]+),\s*(%f[0-9]+)/
1107 &unfma($1,$2,$3,$4,$5)