co-alpha.pl 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #!/usr/local/bin/perl
  2. # I have this in perl so I can use more usefull register names and then convert
  3. # them into alpha registers.
  4. #
  5. push(@INC,"perlasm","../../perlasm");
  6. require "alpha.pl";
  7. &asm_init($ARGV[0],$0);
  8. print &bn_sub_words("bn_sub_words");
  9. &asm_finish();
  10. sub bn_sub_words
  11. {
  12. local($name)=@_;
  13. local($cc,$a,$b,$r);
  14. $cc="r0";
  15. $a0="r1"; $b0="r5"; $r0="r9"; $tmp="r13";
  16. $a1="r2"; $b1="r6"; $r1="r10"; $t1="r14";
  17. $a2="r3"; $b2="r7"; $r2="r11";
  18. $a3="r4"; $b3="r8"; $r3="r12"; $t3="r15";
  19. $rp=&wparam(0);
  20. $ap=&wparam(1);
  21. $bp=&wparam(2);
  22. $count=&wparam(3);
  23. &function_begin($name,"");
  24. &comment("");
  25. &sub($count,4,$count);
  26. &mov("zero",$cc);
  27. &blt($count,&label("finish"));
  28. &ld($a0,&QWPw(0,$ap));
  29. &ld($b0,&QWPw(0,$bp));
  30. ##########################################################
  31. &set_label("loop");
  32. &ld($a1,&QWPw(1,$ap));
  33. &cmpult($a0,$b0,$tmp); # will we borrow?
  34. &ld($b1,&QWPw(1,$bp));
  35. &sub($a0,$b0,$a0); # do the subtract
  36. &ld($a2,&QWPw(2,$ap));
  37. &cmpult($a0,$cc,$b0); # will we borrow?
  38. &ld($b2,&QWPw(2,$bp));
  39. &sub($a0,$cc,$a0); # will we borrow?
  40. &ld($a3,&QWPw(3,$ap));
  41. &add($b0,$tmp,$cc); # add the borrows
  42. &cmpult($a1,$b1,$t1); # will we borrow?
  43. &sub($a1,$b1,$a1); # do the subtract
  44. &ld($b3,&QWPw(3,$bp));
  45. &cmpult($a1,$cc,$b1); # will we borrow?
  46. &sub($a1,$cc,$a1); # will we borrow?
  47. &add($b1,$t1,$cc); # add the borrows
  48. &cmpult($a2,$b2,$tmp); # will we borrow?
  49. &sub($a2,$b2,$a2); # do the subtract
  50. &st($a0,&QWPw(0,$rp)); # save
  51. &cmpult($a2,$cc,$b2); # will we borrow?
  52. &sub($a2,$cc,$a2); # will we borrow?
  53. &add($b2,$tmp,$cc); # add the borrows
  54. &cmpult($a3,$b3,$t3); # will we borrow?
  55. &sub($a3,$b3,$a3); # do the subtract
  56. &st($a1,&QWPw(1,$rp)); # save
  57. &cmpult($a3,$cc,$b3); # will we borrow?
  58. &sub($a3,$cc,$a3); # will we borrow?
  59. &add($b3,$t3,$cc); # add the borrows
  60. &st($a2,&QWPw(2,$rp)); # save
  61. &sub($count,4,$count); # count-=4
  62. &st($a3,&QWPw(3,$rp)); # save
  63. &add($ap,4*$QWS,$ap); # count+=4
  64. &add($bp,4*$QWS,$bp); # count+=4
  65. &add($rp,4*$QWS,$rp); # count+=4
  66. &blt($count,&label("finish"));
  67. &ld($a0,&QWPw(0,$ap));
  68. &ld($b0,&QWPw(0,$bp));
  69. &br(&label("loop"));
  70. ##################################################
  71. # Do the last 0..3 words
  72. &set_label("last_loop");
  73. &ld($a0,&QWPw(0,$ap)); # get a
  74. &ld($b0,&QWPw(0,$bp)); # get b
  75. &cmpult($a0,$b0,$tmp); # will we borrow?
  76. &sub($a0,$b0,$a0); # do the subtract
  77. &cmpult($a0,$cc,$b0); # will we borrow?
  78. &sub($a0,$cc,$a0); # will we borrow?
  79. &st($a0,&QWPw(0,$rp)); # save
  80. &add($b0,$tmp,$cc); # add the borrows
  81. &add($ap,$QWS,$ap);
  82. &add($bp,$QWS,$bp);
  83. &add($rp,$QWS,$rp);
  84. &sub($count,1,$count);
  85. &bgt($count,&label("last_loop"));
  86. &function_end_A($name);
  87. ######################################################
  88. &set_label("finish");
  89. &add($count,4,$count);
  90. &bgt($count,&label("last_loop"));
  91. &set_label("end");
  92. &function_end($name);
  93. }