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 # ====================================================================
10 # This module implements Poly1305 hash for SPARCv9, vanilla, as well
11 # as VIS3 and FMA extensions.
15 # Numbers are cycles per processed byte with poly1305_blocks alone.
19 # UltraSPARC III 11.9(**)
21 # SPARC T4 1.67(***) 6.55
24 # (*) Comparison to compiler-generated code is really problematic,
25 # because latter's performance varies too much depending on too
26 # many variables. For example, one can measure from 5x to 15x
27 # improvement on T4 for gcc-4.6. Well, in T4 case it's a bit
28 # unfair comparison, because compiler doesn't use VIS3, but
29 # given same initial conditions coefficient varies from 3x to 9x.
30 # (**) Pre-III performance should be even worse; floating-point
31 # performance for UltraSPARC I-IV on the other hand is reported
32 # to be 4.25 for hand-coded assembly, but they are just too old
34 # (***) Multi-process benchmark saturates at ~12.5x single-process
35 # result on 8-core processor, or ~21GBps per 2.85GHz socket.
38 open STDOUT,">$output";
40 my ($ctx,$inp,$len,$padbit,$shl,$shr) = map("%i$_",(0..5));
41 my ($r0,$r1,$r2,$r3,$s1,$s2,$s3,$h4) = map("%l$_",(0..7));
42 my ($h0,$h1,$h2,$h3, $t0,$t1,$t2) = map("%o$_",(0..5,7));
43 my ($d0,$d1,$d2,$d3) = map("%g$_",(1..4));
46 open STDOUT,">$stdout";
49 #include "sparc_arch.h"
52 .register %g2,#scratch
53 .register %g3,#scratch
60 #define LOCALS (STACK_BIAS+STACK_FRAME)
62 .section ".text",#alloc,#execinstr
71 save %sp,-STACK_FRAME-16,%sp
74 SPARC_LOAD_ADDRESS(OPENSSL_sparcv9cap_P,%g1)
77 and %g1,SPARCV9_FMADD|SPARCV9_PREFER_FPU|SPARCV9_VIS3,%g1
78 cmp %g1,SPARCV9_FMADD|SPARCV9_PREFER_FPU
79 be .Lpoly1305_init_fma
83 stx %g0,[$ctx+8] ! zero hash value
87 and $inp,7,$shr ! alignment factor
92 sethi %hi(0x0ffffffc),$t0
94 or $t0,%lo(0x0ffffffc),$t0
97 or $t0,$t1,$t1 ! 0x0ffffffc0ffffffc
98 or $t1,3,$t0 ! 0x0ffffffc0fffffff
100 ldxa [$inp+%g0]0x88,$h0 ! load little-endian key
101 brz,pt $shr,.Lkey_aligned
102 ldxa [$inp+$h1]0x88,$h1
104 ldxa [$inp+$h2]0x88,$h2
115 stx $h0,[$ctx+32+0] ! store key
118 andcc %g1,SPARCV9_VIS3,%g0
123 add %o7,poly1305_blocks_vis3-1b,%o7
125 add %o7,poly1305_emit-poly1305_blocks_vis3,%o5
127 STPTR %o5,[%i2+SIZE_T]
130 restore %g0,1,%o0 ! return 1
134 restore %g0,%g0,%o0 ! return 0
135 .size poly1305_init,.-poly1305_init
137 .globl poly1305_blocks
140 save %sp,-STACK_FRAME,%sp
143 brz,pn $len,.Lno_data
146 ld [$ctx+32+0],$r1 ! load key
151 ld [$ctx+0],$h1 ! load hash value
157 and $inp,7,$shr ! alignment factor
172 ldxa [$inp+%g0]0x88,$d0 ! load little-endian input
173 brz,pt $shr,.Linp_aligned
174 ldxa [$inp+$d1]0x88,$d1
176 ldxa [$inp+$d2]0x88,$d2
186 addcc $d0,$h0,$h0 ! accumulate input
246 srl $h4,2,$t0 ! final reduction step
257 st $h1,[$ctx+0] ! store hash value
266 .size poly1305_blocks,.-poly1305_blocks
268 ########################################################################
269 # VIS3 has umulxhi and addxc...
271 my ($H0,$H1,$H2,$R0,$R1,$S1,$T1) = map("%o$_",(0..5,7));
272 my ($D0,$D1,$D2,$T0) = map("%g$_",(1..4));
276 poly1305_blocks_vis3:
277 save %sp,-STACK_FRAME,%sp
280 brz,pn $len,.Lno_data
283 ldx [$ctx+32+0],$R0 ! load key
286 ldx [$ctx+0],$H0 ! load hash value
290 and $inp,7,$shr ! alignment factor
301 ldxa [$inp+%g0]0x88,$D0 ! load little-endian input
302 brz,pt $shr,.Linp_aligned_vis3
303 ldxa [$inp+$r1]0x88,$D1
305 ldxa [$inp+$r2]0x88,$D2
314 addcc $D0,$H0,$H0 ! accumulate input
319 mulx $R0,$H0,$D0 ! r0*h0
320 addxc $padbit,$H2,$H2
322 mulx $S1,$H1,$T0 ! s1*h1
325 mulx $R1,$H0,$T0 ! r1*h0
329 mulx $R0,$H1,$T0 ! r0*h1
333 mulx $S1,$H2,$T0 ! s1*h2
335 mulx $R0,$H2,$T1 ! r0*h2
339 srlx $D2,2,$T0 ! final reduction step
345 brnz,pt $len,.Loop_vis3
348 stx $H0,[$ctx+0] ! store hash value
354 .size poly1305_blocks_vis3,.-poly1305_blocks_vis3
357 my ($mac,$nonce) = ($inp,$len);
363 save %sp,-STACK_FRAME,%sp
365 ld [$ctx+0],$h1 ! load hash value
371 addcc $h0,5,$r0 ! compare to modulus
376 andcc $h4,4,%g0 ! did it carry/borrow?
379 ld [$nonce+0],$r0 ! load nonce
387 addcc $r0,$h0,$h0 ! accumulate nonce
393 stb $h0,[$mac+0] ! store little-endian result
426 .size poly1305_emit,.-poly1305_emit
430 my ($ctx,$inp,$len,$padbit) = map("%i$_",(0..3));
431 my ($in0,$in1,$in2,$in3,$in4) = map("%o$_",(0..4));
432 my ($i1,$step,$shr,$shl) = map("%l$_",(0..7));
435 my ($h0lo,$h0hi,$h1lo,$h1hi,$h2lo,$h2hi,$h3lo,$h3hi,
436 $two0,$two32,$two64,$two96,$two130,$five_two130,
437 $r0lo,$r0hi,$r1lo,$r1hi,$r2lo,$r2hi,
438 $s2lo,$s2hi,$s3lo,$s3hi,
439 $c0lo,$c0hi,$c1lo,$c1hi,$c2lo,$c2hi,$c3lo,$c3hi) = map("%f".2*$_,(0..31));
441 my ($r3lo,$r3hi,$s1lo,$s1hi) = ($c0lo,$c0hi,$c1lo,$c1hi);
442 my ($x0,$x1,$x2,$x3) = ($c2lo,$c2hi,$c3lo,$c3hi);
443 my ($y0,$y1,$y2,$y3) = ($c1lo,$c1hi,$c3hi,$c3lo);
448 save %sp,-STACK_FRAME-16,%sp
453 add %o7,.Lconsts_fma-1b,%o7
455 ldd [%o7+8*0],$two0 ! load constants
459 ldd [%o7+8*5],$five_two130
461 std $two0,[$ctx+8*0] ! initial hash value, biased 0
462 std $two32,[$ctx+8*1]
463 std $two64,[$ctx+8*2]
464 std $two96,[$ctx+8*3]
466 brz,pn $inp,.Lno_key_fma
469 stx %fsr,[%sp+LOCALS] ! save original %fsr
470 ldx [%o7+8*6],%fsr ! load new %fsr
472 std $two0,[$ctx+8*4] ! key "template"
473 std $two32,[$ctx+8*5]
474 std $two64,[$ctx+8*6]
475 std $two96,[$ctx+8*7]
478 andn $inp,7,$inp ! align pointer
484 ldxa [$inp+%g0]0x88,$in0 ! load little-endian key
485 ldxa [$inp+$i1]0x88,$in2
487 brz $shr,.Lkey_aligned_fma
488 sethi %hi(0xf0000000),$i1 ! 0xf0000000
490 ldxa [$inp+$i2]0x88,$in4
492 srlx $in0,$shr,$in0 ! align data
500 or $i1,3,$i2 ! 0xf0000003
502 andn $in0,$i1,$in0 ! &=0x0fffffff
503 andn $in1,$i2,$in1 ! &=0x0ffffffc
508 st $in0,[$ctx+`8*4+4`] ! fill "template"
509 st $in1,[$ctx+`8*5+4`]
510 st $in2,[$ctx+`8*6+4`]
511 st $in3,[$ctx+`8*7+4`]
513 ldd [$ctx+8*4],$h0lo ! load [biased] key
518 fsubd $h0lo,$two0, $h0lo ! r0
519 ldd [%o7+8*7],$two0 ! more constants
520 fsubd $h1lo,$two32,$h1lo ! r1
522 fsubd $h2lo,$two64,$h2lo ! r2
524 fsubd $h3lo,$two96,$h3lo ! r3
525 ldd [%o7+8*10],$two96
527 fmuld $five_two130,$h1lo,$s1lo ! s1
528 fmuld $five_two130,$h2lo,$s2lo ! s2
529 fmuld $five_two130,$h3lo,$s3lo ! s3
531 faddd $h0lo,$two0, $h0hi
532 faddd $h1lo,$two32,$h1hi
533 faddd $h2lo,$two64,$h2hi
534 faddd $h3lo,$two96,$h3hi
536 fsubd $h0hi,$two0, $h0hi
537 ldd [%o7+8*11],$two0 ! more constants
538 fsubd $h1hi,$two32,$h1hi
539 ldd [%o7+8*12],$two32
540 fsubd $h2hi,$two64,$h2hi
541 ldd [%o7+8*13],$two64
542 fsubd $h3hi,$two96,$h3hi
544 fsubd $h0lo,$h0hi,$h0lo
545 std $h0hi,[$ctx+8*5] ! r0hi
546 fsubd $h1lo,$h1hi,$h1lo
547 std $h1hi,[$ctx+8*7] ! r1hi
548 fsubd $h2lo,$h2hi,$h2lo
549 std $h2hi,[$ctx+8*9] ! r2hi
550 fsubd $h3lo,$h3hi,$h3lo
551 std $h3hi,[$ctx+8*11] ! r3hi
553 faddd $s1lo,$two0, $s1hi
554 faddd $s2lo,$two32,$s2hi
555 faddd $s3lo,$two64,$s3hi
557 fsubd $s1hi,$two0, $s1hi
558 fsubd $s2hi,$two32,$s2hi
559 fsubd $s3hi,$two64,$s3hi
561 fsubd $s1lo,$s1hi,$s1lo
562 fsubd $s2lo,$s2hi,$s2lo
563 fsubd $s3lo,$s3hi,$s3lo
565 ldx [%sp+LOCALS],%fsr ! restore %fsr
567 std $h0lo,[$ctx+8*4] ! r0lo
568 std $h1lo,[$ctx+8*6] ! r1lo
569 std $h2lo,[$ctx+8*8] ! r2lo
570 std $h3lo,[$ctx+8*10] ! r3lo
572 std $s1hi,[$ctx+8*13]
573 std $s2hi,[$ctx+8*15]
574 std $s3hi,[$ctx+8*17]
576 std $s1lo,[$ctx+8*12]
577 std $s2lo,[$ctx+8*14]
578 std $s3lo,[$ctx+8*16]
580 add %o7,poly1305_blocks_fma-.Lconsts_fma,%o0
581 add %o7,poly1305_emit_fma-.Lconsts_fma,%o1
583 STPTR %o1,[%i2+SIZE_T]
586 restore %g0,1,%o0 ! return 1
590 restore %g0,%g0,%o0 ! return 0
591 .size poly1305_init_fma,.-poly1305_init_fma
595 save %sp,-STACK_FRAME-48,%sp
602 add %o7,.Lconsts_fma-1b,%o7
604 ldd [%o7+8*0],$two0 ! load constants
608 ldd [%o7+8*4],$two130
609 ldd [%o7+8*5],$five_two130
611 ldd [$ctx+8*0],$h0lo ! load [biased] hash value
616 std $two0,[%sp+LOCALS+8*0] ! input "template"
617 sethi %hi((1023+52+96)<<20),$in3
618 std $two32,[%sp+LOCALS+8*1]
620 std $two64,[%sp+LOCALS+8*2]
621 st $in3,[%sp+LOCALS+8*3]
624 andn $inp,7,$inp ! align pointer
630 ldxa [$inp+%g0]0x88,$in0 ! load little-endian input
631 brz $shr,.Linp_aligned_fma
632 ldxa [$inp+$i1]0x88,$in2
634 ldxa [$inp+$step]0x88,$in4
637 srlx $in0,$shr,$in0 ! align data
642 srlx $in4,$shr,$in4 ! pre-shift
649 add $step,$inp,$inp ! conditional advance
651 st $in0,[%sp+LOCALS+8*0+4] ! fill "template"
652 st $in1,[%sp+LOCALS+8*1+4]
653 st $in2,[%sp+LOCALS+8*2+4]
654 st $in3,[%sp+LOCALS+8*3+4]
656 ldd [$ctx+8*4],$r0lo ! load key
662 ldd [$ctx+8*10],$r3lo
663 ldd [$ctx+8*11],$r3hi
664 ldd [$ctx+8*12],$s1lo
665 ldd [$ctx+8*13],$s1hi
666 ldd [$ctx+8*14],$s2lo
667 ldd [$ctx+8*15],$s2hi
668 ldd [$ctx+8*16],$s3lo
669 ldd [$ctx+8*17],$s3hi
671 stx %fsr,[%sp+LOCALS+8*4] ! save original %fsr
672 ldx [%o7+8*6],%fsr ! load new %fsr
677 ldd [%sp+LOCALS+8*0],$x0 ! load biased input
678 ldd [%sp+LOCALS+8*1],$x1
679 ldd [%sp+LOCALS+8*2],$x2
680 ldd [%sp+LOCALS+8*3],$x3
682 fsubd $h0lo,$two0, $h0lo ! de-bias hash value
683 fsubd $h1lo,$two32,$h1lo
684 ldxa [$inp+%g0]0x88,$in0 ! modulo-scheduled input load
685 fsubd $h2lo,$two64,$h2lo
686 fsubd $h3lo,$two96,$h3lo
687 ldxa [$inp+$i1]0x88,$in2
689 fsubd $x0,$two0, $x0 ! de-bias input
694 brz $shr,.Linp_aligned_fma2
695 add $step,$inp,$inp ! conditional advance
697 sllx $in0,$shl,$in1 ! align data
701 srlx $in2,$shr,$in4 ! pre-shift
707 faddd $h0lo,$x0,$x0 ! accumulate input
708 stw $in0,[%sp+LOCALS+8*0+4]
710 stw $in1,[%sp+LOCALS+8*1+4]
712 stw $in2,[%sp+LOCALS+8*2+4]
714 stw $in3,[%sp+LOCALS+8*3+4]
721 ldxa [$inp+%g0]0x88,$in0 ! modulo-scheduled input load
722 ldxa [$inp+$i1]0x88,$in2
725 faddd $y0,$h0lo,$h0lo ! accumulate input
726 faddd $y1,$h0hi,$h0hi
727 faddd $y2,$h2lo,$h2lo
728 faddd $y3,$h2hi,$h2hi
730 brz,pn $shr,.Linp_aligned_fma3
731 add $step,$inp,$inp ! conditional advance
733 sllx $in0,$shl,$in1 ! align data
737 srlx $in2,$shr,$in4 ! pre-shift
741 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! base 2^48 -> base 2^32
742 faddd $two64,$h1lo,$c1lo
744 faddd $two64,$h1hi,$c1hi
746 faddd $two130,$h3lo,$c3lo
747 st $in0,[%sp+LOCALS+8*0+4] ! fill "template"
748 faddd $two130,$h3hi,$c3hi
749 st $in1,[%sp+LOCALS+8*1+4]
750 faddd $two32,$h0lo,$c0lo
751 st $in2,[%sp+LOCALS+8*2+4]
752 faddd $two32,$h0hi,$c0hi
753 st $in3,[%sp+LOCALS+8*3+4]
754 faddd $two96,$h2lo,$c2lo
755 faddd $two96,$h2hi,$c2hi
757 fsubd $c1lo,$two64,$c1lo
758 fsubd $c1hi,$two64,$c1hi
759 fsubd $c3lo,$two130,$c3lo
760 fsubd $c3hi,$two130,$c3hi
761 fsubd $c0lo,$two32,$c0lo
762 fsubd $c0hi,$two32,$c0hi
763 fsubd $c2lo,$two96,$c2lo
764 fsubd $c2hi,$two96,$c2hi
766 fsubd $h1lo,$c1lo,$h1lo
767 fsubd $h1hi,$c1hi,$h1hi
768 fsubd $h3lo,$c3lo,$h3lo
769 fsubd $h3hi,$c3hi,$h3hi
770 fsubd $h2lo,$c2lo,$h2lo
771 fsubd $h2hi,$c2hi,$h2hi
772 fsubd $h0lo,$c0lo,$h0lo
773 fsubd $h0hi,$c0hi,$h0hi
775 faddd $h1lo,$c0lo,$h1lo
776 faddd $h1hi,$c0hi,$h1hi
777 faddd $h3lo,$c2lo,$h3lo
778 faddd $h3hi,$c2hi,$h3hi
779 faddd $h2lo,$c1lo,$h2lo
780 faddd $h2hi,$c1hi,$h2hi
781 fmaddd $five_two130,$c3lo,$h0lo,$h0lo
782 fmaddd $five_two130,$c3hi,$h0hi,$h0hi
784 faddd $h1lo,$h1hi,$x1
785 ldd [$ctx+8*12],$s1lo ! reload constants
786 faddd $h3lo,$h3hi,$x3
787 ldd [$ctx+8*13],$s1hi
788 faddd $h2lo,$h2hi,$x2
789 ldd [$ctx+8*10],$r3lo
790 faddd $h0lo,$h0hi,$x0
791 ldd [$ctx+8*11],$r3hi
794 fmuld $x1,$s3lo,$h0lo
795 fmuld $x1,$s3hi,$h0hi
796 fmuld $x1,$r1lo,$h2lo
797 fmuld $x1,$r1hi,$h2hi
798 fmuld $x1,$r0lo,$h1lo
799 fmuld $x1,$r0hi,$h1hi
800 fmuld $x1,$r2lo,$h3lo
801 fmuld $x1,$r2hi,$h3hi
803 fmaddd $x3,$s1lo,$h0lo,$h0lo
804 fmaddd $x3,$s1hi,$h0hi,$h0hi
805 fmaddd $x3,$s3lo,$h2lo,$h2lo
806 fmaddd $x3,$s3hi,$h2hi,$h2hi
807 fmaddd $x3,$s2lo,$h1lo,$h1lo
808 fmaddd $x3,$s2hi,$h1hi,$h1hi
809 fmaddd $x3,$r0lo,$h3lo,$h3lo
810 fmaddd $x3,$r0hi,$h3hi,$h3hi
812 fmaddd $x2,$s2lo,$h0lo,$h0lo
813 fmaddd $x2,$s2hi,$h0hi,$h0hi
814 fmaddd $x2,$r0lo,$h2lo,$h2lo
815 fmaddd $x2,$r0hi,$h2hi,$h2hi
816 fmaddd $x2,$s3lo,$h1lo,$h1lo
817 ldd [%sp+LOCALS+8*0],$y0 ! load [biased] input
818 fmaddd $x2,$s3hi,$h1hi,$h1hi
819 ldd [%sp+LOCALS+8*1],$y1
820 fmaddd $x2,$r1lo,$h3lo,$h3lo
821 ldd [%sp+LOCALS+8*2],$y2
822 fmaddd $x2,$r1hi,$h3hi,$h3hi
823 ldd [%sp+LOCALS+8*3],$y3
825 fmaddd $x0,$r0lo,$h0lo,$h0lo
826 fsubd $y0,$two0, $y0 ! de-bias input
827 fmaddd $x0,$r0hi,$h0hi,$h0hi
829 fmaddd $x0,$r2lo,$h2lo,$h2lo
831 fmaddd $x0,$r2hi,$h2hi,$h2hi
833 fmaddd $x0,$r1lo,$h1lo,$h1lo
834 fmaddd $x0,$r1hi,$h1hi,$h1hi
835 fmaddd $x0,$r3lo,$h3lo,$h3lo
836 fmaddd $x0,$r3hi,$h3hi,$h3hi
838 bcc SIZE_T_CC,.Loop_fma
841 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! base 2^48 -> base 2^32
842 faddd $h0lo,$two32,$c0lo
843 faddd $h0hi,$two32,$c0hi
844 faddd $h2lo,$two96,$c2lo
845 faddd $h2hi,$two96,$c2hi
846 faddd $h1lo,$two64,$c1lo
847 faddd $h1hi,$two64,$c1hi
848 faddd $h3lo,$two130,$c3lo
849 faddd $h3hi,$two130,$c3hi
851 fsubd $c0lo,$two32,$c0lo
852 fsubd $c0hi,$two32,$c0hi
853 fsubd $c2lo,$two96,$c2lo
854 fsubd $c2hi,$two96,$c2hi
855 fsubd $c1lo,$two64,$c1lo
856 fsubd $c1hi,$two64,$c1hi
857 fsubd $c3lo,$two130,$c3lo
858 fsubd $c3hi,$two130,$c3hi
860 fsubd $h1lo,$c1lo,$h1lo
861 fsubd $h1hi,$c1hi,$h1hi
862 fsubd $h3lo,$c3lo,$h3lo
863 fsubd $h3hi,$c3hi,$h3hi
864 fsubd $h2lo,$c2lo,$h2lo
865 fsubd $h2hi,$c2hi,$h2hi
866 fsubd $h0lo,$c0lo,$h0lo
867 fsubd $h0hi,$c0hi,$h0hi
869 faddd $h1lo,$c0lo,$h1lo
870 faddd $h1hi,$c0hi,$h1hi
871 faddd $h3lo,$c2lo,$h3lo
872 faddd $h3hi,$c2hi,$h3hi
873 faddd $h2lo,$c1lo,$h2lo
874 faddd $h2hi,$c1hi,$h2hi
875 fmaddd $five_two130,$c3lo,$h0lo,$h0lo
876 fmaddd $five_two130,$c3hi,$h0hi,$h0hi
878 faddd $h1lo,$h1hi,$x1
879 faddd $h3lo,$h3hi,$x3
880 faddd $h2lo,$h2hi,$x2
881 faddd $h0lo,$h0hi,$x0
883 faddd $x1,$two32,$x1 ! bias
888 ldx [%sp+LOCALS+8*4],%fsr ! restore saved %fsr
890 std $x1,[$ctx+8*1] ! store [biased] hash value
898 .size poly1305_blocks_fma,.-poly1305_blocks_fma
901 my ($mac,$nonce)=($inp,$len);
903 my ($h0,$h1,$h2,$h3,$h4, $d0,$d1,$d2,$d3, $mask
904 ) = (map("%l$_",(0..5)),map("%o$_",(0..4)));
909 save %sp,-STACK_FRAME,%sp
911 ld [$ctx+8*0+0],$d0 ! load hash
920 sethi %hi(0xfff00000),$mask
921 andn $d0,$mask,$d0 ! mask exponent
924 andn $d3,$mask,$d3 ! can be partially reduced...
927 srl $d3,2,$padbit ! ... so reduce
938 addcc $h0,5,$d0 ! compare to modulus
944 srl $mask,2,$mask ! did it carry/borrow?
946 sra $mask,31,$mask ! mask
953 ld [$nonce+0],$d0 ! load nonce
965 addcc $d0,$h0,$h0 ! accumulate nonce
970 stb $h0,[$mac+0] ! write little-endian result
1004 .size poly1305_emit_fma,.-poly1305_emit_fma
1011 .word 0x43300000,0x00000000 ! 2^(52+0)
1012 .word 0x45300000,0x00000000 ! 2^(52+32)
1013 .word 0x47300000,0x00000000 ! 2^(52+64)
1014 .word 0x49300000,0x00000000 ! 2^(52+96)
1015 .word 0x4b500000,0x00000000 ! 2^(52+130)
1017 .word 0x37f40000,0x00000000 ! 5/2^130
1018 .word 0,1<<30 ! fsr: truncate, no exceptions
1020 .word 0x44300000,0x00000000 ! 2^(52+16+0)
1021 .word 0x46300000,0x00000000 ! 2^(52+16+32)
1022 .word 0x48300000,0x00000000 ! 2^(52+16+64)
1023 .word 0x4a300000,0x00000000 ! 2^(52+16+96)
1024 .word 0x3e300000,0x00000000 ! 2^(52+16+0-96)
1025 .word 0x40300000,0x00000000 ! 2^(52+16+32-96)
1026 .word 0x42300000,0x00000000 ! 2^(52+16+64-96)
1027 .asciz "Poly1305 for SPARCv9/VIS3/FMA, CRYPTOGAMS by <appro\@openssl.org>"
1032 # Purpose of these subroutines is to explicitly encode VIS instructions,
1033 # so that one can compile the module without having to specify VIS
1034 # extensions on compiler command line, e.g. -xarch=v9 vs. -xarch=v9a.
1035 # Idea is to reserve for option to produce "universal" binary and let
1036 # programmer detect if current CPU is VIS capable at run-time.
1038 my ($mnemonic,$rs1,$rs2,$rd)=@_;
1039 my %bias = ( "g" => 0, "o" => 8, "l" => 16, "i" => 24 );
1041 my %visopf = ( "addxc" => 0x011,
1043 "umulxhi" => 0x016 );
1045 $ref = "$mnemonic\t$rs1,$rs2,$rd";
1047 if ($opf=$visopf{$mnemonic}) {
1048 foreach ($rs1,$rs2,$rd) {
1049 return $ref if (!/%([goli])([0-9])/);
1053 return sprintf ".word\t0x%08x !%s",
1054 0x81b00000|$rd<<25|$rs1<<14|$opf<<5|$rs2,
1062 my ($mnemonic,$rs1,$rs2,$rs3,$rd)=@_;
1064 my %fmaopf = ( "fmadds" => 0x1,
1069 $ref = "$mnemonic\t$rs1,$rs2,$rs3,$rd";
1071 if ($opf=$fmaopf{$mnemonic}) {
1072 foreach ($rs1,$rs2,$rs3,$rd) {
1073 return $ref if (!/%f([0-9]{1,2})/);
1076 return $ref if ($1&1);
1077 # re-encode for upper double register addressing
1082 return sprintf ".word\t0x%08x !%s",
1083 0x81b80000|$rd<<25|$rs1<<14|$rs3<<9|$opf<<5|$rs2,
1090 foreach (split("\n",$code)) {
1091 s/\`([^\`]*)\`/eval $1/ge;
1093 s/\b(umulxhi|addxc[c]{0,2})\s+(%[goli][0-7]),\s*(%[goli][0-7]),\s*(%[goli][0-7])/
1094 &unvis3($1,$2,$3,$4)
1096 s/\b(fmadd[sd])\s+(%f[0-9]+),\s*(%f[0-9]+),\s*(%f[0-9]+),\s*(%f[0-9]+)/
1097 &unfma($1,$2,$3,$4,$5)