mips.pl 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265
  1. #! /usr/bin/env perl
  2. # Copyright 2010-2020 The OpenSSL Project Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License 2.0 (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
  8. #
  9. # ====================================================================
  10. # Written by Andy Polyakov <appro@openssl.org> for the OpenSSL
  11. # project.
  12. #
  13. # Rights for redistribution and usage in source and binary forms are
  14. # granted according to the License. Warranty of any kind is disclaimed.
  15. # ====================================================================
  16. # July 1999
  17. #
  18. # This is drop-in MIPS III/IV ISA replacement for crypto/bn/bn_asm.c.
  19. #
  20. # The module is designed to work with either of the "new" MIPS ABI(5),
  21. # namely N32 or N64, offered by IRIX 6.x. It's not meant to work under
  22. # IRIX 5.x not only because it doesn't support new ABIs but also
  23. # because 5.x kernels put R4x00 CPU into 32-bit mode and all those
  24. # 64-bit instructions (daddu, dmultu, etc.) found below gonna only
  25. # cause illegal instruction exception:-(
  26. #
  27. # In addition the code depends on preprocessor flags set up by MIPSpro
  28. # compiler driver (either as or cc) and therefore (probably?) can't be
  29. # compiled by the GNU assembler. GNU C driver manages fine though...
  30. # I mean as long as -mmips-as is specified or is the default option,
  31. # because then it simply invokes /usr/bin/as which in turn takes
  32. # perfect care of the preprocessor definitions. Another neat feature
  33. # offered by the MIPSpro assembler is an optimization pass. This gave
  34. # me the opportunity to have the code looking more regular as all those
  35. # architecture dependent instruction rescheduling details were left to
  36. # the assembler. Cool, huh?
  37. #
  38. # Performance improvement is astonishing! 'apps/openssl speed rsa dsa'
  39. # goes way over 3 times faster!
  40. #
  41. # <appro@openssl.org>
  42. # October 2010
  43. #
  44. # Adapt the module even for 32-bit ABIs and other OSes. The former was
  45. # achieved by mechanical replacement of 64-bit arithmetic instructions
  46. # such as dmultu, daddu, etc. with their 32-bit counterparts and
  47. # adjusting offsets denoting multiples of BN_ULONG. Above mentioned
  48. # >3x performance improvement naturally does not apply to 32-bit code
  49. # [because there is no instruction 32-bit compiler can't use], one
  50. # has to content with 40-85% improvement depending on benchmark and
  51. # key length, more for longer keys.
  52. # $output is the last argument if it looks like a file (it has an extension)
  53. # $flavour is the first argument if it doesn't look like a file
  54. $output = $#ARGV >= 0 && $ARGV[$#ARGV] =~ m|\.\w+$| ? pop : undef;
  55. $flavour = $#ARGV >= 0 && $ARGV[0] !~ m|\.| ? shift : "o32";
  56. if ($flavour =~ /64|n32/i) {
  57. $LD="ld";
  58. $ST="sd";
  59. $MULTU="dmultu";
  60. $DIVU="ddivu";
  61. $ADDU="daddu";
  62. $SUBU="dsubu";
  63. $SRL="dsrl";
  64. $SLL="dsll";
  65. $BNSZ=8;
  66. $PTR_ADD="daddu";
  67. $PTR_SUB="dsubu";
  68. $SZREG=8;
  69. $REG_S="sd";
  70. $REG_L="ld";
  71. } else {
  72. $LD="lw";
  73. $ST="sw";
  74. $MULTU="multu";
  75. $DIVU="divu";
  76. $ADDU="addu";
  77. $SUBU="subu";
  78. $SRL="srl";
  79. $SLL="sll";
  80. $BNSZ=4;
  81. $PTR_ADD="addu";
  82. $PTR_SUB="subu";
  83. $SZREG=4;
  84. $REG_S="sw";
  85. $REG_L="lw";
  86. $code="#if !(defined (__mips_isa_rev) && (__mips_isa_rev >= 6))\n.set mips2\n#endif\n";
  87. }
  88. $output and open STDOUT,">$output";
  89. # Below is N32/64 register layout used in the original module.
  90. #
  91. ($zero,$at,$v0,$v1)=map("\$$_",(0..3));
  92. ($a0,$a1,$a2,$a3,$a4,$a5,$a6,$a7)=map("\$$_",(4..11));
  93. ($t0,$t1,$t2,$t3,$t8,$t9)=map("\$$_",(12..15,24,25));
  94. ($s0,$s1,$s2,$s3,$s4,$s5,$s6,$s7)=map("\$$_",(16..23));
  95. ($gp,$sp,$fp,$ra)=map("\$$_",(28..31));
  96. ($ta0,$ta1,$ta2,$ta3)=($a4,$a5,$a6,$a7);
  97. #
  98. # No special adaptation is required for O32. NUBI on the other hand
  99. # is treated by saving/restoring ($v1,$t0..$t3).
  100. $gp=$v1 if ($flavour =~ /nubi/i);
  101. $minus4=$v1;
  102. $code.=<<___;
  103. #include "mips_arch.h"
  104. #if defined(_MIPS_ARCH_MIPS64R6)
  105. # define ddivu(rs,rt)
  106. # define mfqt(rd,rs,rt) ddivu rd,rs,rt
  107. # define mfrm(rd,rs,rt) dmodu rd,rs,rt
  108. #elif defined(_MIPS_ARCH_MIPS32R6)
  109. # define divu(rs,rt)
  110. # define mfqt(rd,rs,rt) divu rd,rs,rt
  111. # define mfrm(rd,rs,rt) modu rd,rs,rt
  112. #else
  113. # define $DIVU(rs,rt) $DIVU $zero,rs,rt
  114. # define mfqt(rd,rs,rt) mflo rd
  115. # define mfrm(rd,rs,rt) mfhi rd
  116. #endif
  117. .rdata
  118. .asciiz "mips3.s, Version 1.2"
  119. .asciiz "MIPS II/III/IV ISA artwork by Andy Polyakov <appro\@fy.chalmers.se>"
  120. .text
  121. .set noat
  122. .align 5
  123. .globl bn_mul_add_words
  124. .ent bn_mul_add_words
  125. bn_mul_add_words:
  126. .set noreorder
  127. bgtz $a2,bn_mul_add_words_internal
  128. move $v0,$zero
  129. jr $ra
  130. move $a0,$v0
  131. .end bn_mul_add_words
  132. .align 5
  133. .ent bn_mul_add_words_internal
  134. bn_mul_add_words_internal:
  135. ___
  136. $code.=<<___ if ($flavour =~ /nubi/i);
  137. .frame $sp,6*$SZREG,$ra
  138. .mask 0x8000f008,-$SZREG
  139. .set noreorder
  140. $PTR_SUB $sp,6*$SZREG
  141. $REG_S $ra,5*$SZREG($sp)
  142. $REG_S $t3,4*$SZREG($sp)
  143. $REG_S $t2,3*$SZREG($sp)
  144. $REG_S $t1,2*$SZREG($sp)
  145. $REG_S $t0,1*$SZREG($sp)
  146. $REG_S $gp,0*$SZREG($sp)
  147. ___
  148. $code.=<<___;
  149. .set reorder
  150. li $minus4,-4
  151. and $ta0,$a2,$minus4
  152. beqz $ta0,.L_bn_mul_add_words_tail
  153. .L_bn_mul_add_words_loop:
  154. $LD $t0,0($a1)
  155. $MULTU ($t0,$a3)
  156. $LD $t1,0($a0)
  157. $LD $t2,$BNSZ($a1)
  158. $LD $t3,$BNSZ($a0)
  159. $LD $ta0,2*$BNSZ($a1)
  160. $LD $ta1,2*$BNSZ($a0)
  161. $ADDU $t1,$v0
  162. sltu $v0,$t1,$v0 # All manuals say it "compares 32-bit
  163. # values", but it seems to work fine
  164. # even on 64-bit registers.
  165. mflo ($at,$t0,$a3)
  166. mfhi ($t0,$t0,$a3)
  167. $ADDU $t1,$at
  168. $ADDU $v0,$t0
  169. $MULTU ($t2,$a3)
  170. sltu $at,$t1,$at
  171. $ST $t1,0($a0)
  172. $ADDU $v0,$at
  173. $LD $ta2,3*$BNSZ($a1)
  174. $LD $ta3,3*$BNSZ($a0)
  175. $ADDU $t3,$v0
  176. sltu $v0,$t3,$v0
  177. mflo ($at,$t2,$a3)
  178. mfhi ($t2,$t2,$a3)
  179. $ADDU $t3,$at
  180. $ADDU $v0,$t2
  181. $MULTU ($ta0,$a3)
  182. sltu $at,$t3,$at
  183. $ST $t3,$BNSZ($a0)
  184. $ADDU $v0,$at
  185. subu $a2,4
  186. $PTR_ADD $a0,4*$BNSZ
  187. $PTR_ADD $a1,4*$BNSZ
  188. $ADDU $ta1,$v0
  189. sltu $v0,$ta1,$v0
  190. mflo ($at,$ta0,$a3)
  191. mfhi ($ta0,$ta0,$a3)
  192. $ADDU $ta1,$at
  193. $ADDU $v0,$ta0
  194. $MULTU ($ta2,$a3)
  195. sltu $at,$ta1,$at
  196. $ST $ta1,-2*$BNSZ($a0)
  197. $ADDU $v0,$at
  198. and $ta0,$a2,$minus4
  199. $ADDU $ta3,$v0
  200. sltu $v0,$ta3,$v0
  201. mflo ($at,$ta2,$a3)
  202. mfhi ($ta2,$ta2,$a3)
  203. $ADDU $ta3,$at
  204. $ADDU $v0,$ta2
  205. sltu $at,$ta3,$at
  206. $ST $ta3,-$BNSZ($a0)
  207. .set noreorder
  208. bgtz $ta0,.L_bn_mul_add_words_loop
  209. $ADDU $v0,$at
  210. beqz $a2,.L_bn_mul_add_words_return
  211. nop
  212. .L_bn_mul_add_words_tail:
  213. .set reorder
  214. $LD $t0,0($a1)
  215. $MULTU ($t0,$a3)
  216. $LD $t1,0($a0)
  217. subu $a2,1
  218. $ADDU $t1,$v0
  219. sltu $v0,$t1,$v0
  220. mflo ($at,$t0,$a3)
  221. mfhi ($t0,$t0,$a3)
  222. $ADDU $t1,$at
  223. $ADDU $v0,$t0
  224. sltu $at,$t1,$at
  225. $ST $t1,0($a0)
  226. $ADDU $v0,$at
  227. beqz $a2,.L_bn_mul_add_words_return
  228. $LD $t0,$BNSZ($a1)
  229. $MULTU ($t0,$a3)
  230. $LD $t1,$BNSZ($a0)
  231. subu $a2,1
  232. $ADDU $t1,$v0
  233. sltu $v0,$t1,$v0
  234. mflo ($at,$t0,$a3)
  235. mfhi ($t0,$t0,$a3)
  236. $ADDU $t1,$at
  237. $ADDU $v0,$t0
  238. sltu $at,$t1,$at
  239. $ST $t1,$BNSZ($a0)
  240. $ADDU $v0,$at
  241. beqz $a2,.L_bn_mul_add_words_return
  242. $LD $t0,2*$BNSZ($a1)
  243. $MULTU ($t0,$a3)
  244. $LD $t1,2*$BNSZ($a0)
  245. $ADDU $t1,$v0
  246. sltu $v0,$t1,$v0
  247. mflo ($at,$t0,$a3)
  248. mfhi ($t0,$t0,$a3)
  249. $ADDU $t1,$at
  250. $ADDU $v0,$t0
  251. sltu $at,$t1,$at
  252. $ST $t1,2*$BNSZ($a0)
  253. $ADDU $v0,$at
  254. .L_bn_mul_add_words_return:
  255. .set noreorder
  256. ___
  257. $code.=<<___ if ($flavour =~ /nubi/i);
  258. $REG_L $t3,4*$SZREG($sp)
  259. $REG_L $t2,3*$SZREG($sp)
  260. $REG_L $t1,2*$SZREG($sp)
  261. $REG_L $t0,1*$SZREG($sp)
  262. $REG_L $gp,0*$SZREG($sp)
  263. $PTR_ADD $sp,6*$SZREG
  264. ___
  265. $code.=<<___;
  266. jr $ra
  267. move $a0,$v0
  268. .end bn_mul_add_words_internal
  269. .align 5
  270. .globl bn_mul_words
  271. .ent bn_mul_words
  272. bn_mul_words:
  273. .set noreorder
  274. bgtz $a2,bn_mul_words_internal
  275. move $v0,$zero
  276. jr $ra
  277. move $a0,$v0
  278. .end bn_mul_words
  279. .align 5
  280. .ent bn_mul_words_internal
  281. bn_mul_words_internal:
  282. ___
  283. $code.=<<___ if ($flavour =~ /nubi/i);
  284. .frame $sp,6*$SZREG,$ra
  285. .mask 0x8000f008,-$SZREG
  286. .set noreorder
  287. $PTR_SUB $sp,6*$SZREG
  288. $REG_S $ra,5*$SZREG($sp)
  289. $REG_S $t3,4*$SZREG($sp)
  290. $REG_S $t2,3*$SZREG($sp)
  291. $REG_S $t1,2*$SZREG($sp)
  292. $REG_S $t0,1*$SZREG($sp)
  293. $REG_S $gp,0*$SZREG($sp)
  294. ___
  295. $code.=<<___;
  296. .set reorder
  297. li $minus4,-4
  298. and $ta0,$a2,$minus4
  299. beqz $ta0,.L_bn_mul_words_tail
  300. .L_bn_mul_words_loop:
  301. $LD $t0,0($a1)
  302. $MULTU ($t0,$a3)
  303. $LD $t2,$BNSZ($a1)
  304. $LD $ta0,2*$BNSZ($a1)
  305. $LD $ta2,3*$BNSZ($a1)
  306. mflo ($at,$t0,$a3)
  307. mfhi ($t0,$t0,$a3)
  308. $ADDU $v0,$at
  309. sltu $t1,$v0,$at
  310. $MULTU ($t2,$a3)
  311. $ST $v0,0($a0)
  312. $ADDU $v0,$t1,$t0
  313. subu $a2,4
  314. $PTR_ADD $a0,4*$BNSZ
  315. $PTR_ADD $a1,4*$BNSZ
  316. mflo ($at,$t2,$a3)
  317. mfhi ($t2,$t2,$a3)
  318. $ADDU $v0,$at
  319. sltu $t3,$v0,$at
  320. $MULTU ($ta0,$a3)
  321. $ST $v0,-3*$BNSZ($a0)
  322. $ADDU $v0,$t3,$t2
  323. mflo ($at,$ta0,$a3)
  324. mfhi ($ta0,$ta0,$a3)
  325. $ADDU $v0,$at
  326. sltu $ta1,$v0,$at
  327. $MULTU ($ta2,$a3)
  328. $ST $v0,-2*$BNSZ($a0)
  329. $ADDU $v0,$ta1,$ta0
  330. and $ta0,$a2,$minus4
  331. mflo ($at,$ta2,$a3)
  332. mfhi ($ta2,$ta2,$a3)
  333. $ADDU $v0,$at
  334. sltu $ta3,$v0,$at
  335. $ST $v0,-$BNSZ($a0)
  336. .set noreorder
  337. bgtz $ta0,.L_bn_mul_words_loop
  338. $ADDU $v0,$ta3,$ta2
  339. beqz $a2,.L_bn_mul_words_return
  340. nop
  341. .L_bn_mul_words_tail:
  342. .set reorder
  343. $LD $t0,0($a1)
  344. $MULTU ($t0,$a3)
  345. subu $a2,1
  346. mflo ($at,$t0,$a3)
  347. mfhi ($t0,$t0,$a3)
  348. $ADDU $v0,$at
  349. sltu $t1,$v0,$at
  350. $ST $v0,0($a0)
  351. $ADDU $v0,$t1,$t0
  352. beqz $a2,.L_bn_mul_words_return
  353. $LD $t0,$BNSZ($a1)
  354. $MULTU ($t0,$a3)
  355. subu $a2,1
  356. mflo ($at,$t0,$a3)
  357. mfhi ($t0,$t0,$a3)
  358. $ADDU $v0,$at
  359. sltu $t1,$v0,$at
  360. $ST $v0,$BNSZ($a0)
  361. $ADDU $v0,$t1,$t0
  362. beqz $a2,.L_bn_mul_words_return
  363. $LD $t0,2*$BNSZ($a1)
  364. $MULTU ($t0,$a3)
  365. mflo ($at,$t0,$a3)
  366. mfhi ($t0,$t0,$a3)
  367. $ADDU $v0,$at
  368. sltu $t1,$v0,$at
  369. $ST $v0,2*$BNSZ($a0)
  370. $ADDU $v0,$t1,$t0
  371. .L_bn_mul_words_return:
  372. .set noreorder
  373. ___
  374. $code.=<<___ if ($flavour =~ /nubi/i);
  375. $REG_L $t3,4*$SZREG($sp)
  376. $REG_L $t2,3*$SZREG($sp)
  377. $REG_L $t1,2*$SZREG($sp)
  378. $REG_L $t0,1*$SZREG($sp)
  379. $REG_L $gp,0*$SZREG($sp)
  380. $PTR_ADD $sp,6*$SZREG
  381. ___
  382. $code.=<<___;
  383. jr $ra
  384. move $a0,$v0
  385. .end bn_mul_words_internal
  386. .align 5
  387. .globl bn_sqr_words
  388. .ent bn_sqr_words
  389. bn_sqr_words:
  390. .set noreorder
  391. bgtz $a2,bn_sqr_words_internal
  392. move $v0,$zero
  393. jr $ra
  394. move $a0,$v0
  395. .end bn_sqr_words
  396. .align 5
  397. .ent bn_sqr_words_internal
  398. bn_sqr_words_internal:
  399. ___
  400. $code.=<<___ if ($flavour =~ /nubi/i);
  401. .frame $sp,6*$SZREG,$ra
  402. .mask 0x8000f008,-$SZREG
  403. .set noreorder
  404. $PTR_SUB $sp,6*$SZREG
  405. $REG_S $ra,5*$SZREG($sp)
  406. $REG_S $t3,4*$SZREG($sp)
  407. $REG_S $t2,3*$SZREG($sp)
  408. $REG_S $t1,2*$SZREG($sp)
  409. $REG_S $t0,1*$SZREG($sp)
  410. $REG_S $gp,0*$SZREG($sp)
  411. ___
  412. $code.=<<___;
  413. .set reorder
  414. li $minus4,-4
  415. and $ta0,$a2,$minus4
  416. beqz $ta0,.L_bn_sqr_words_tail
  417. .L_bn_sqr_words_loop:
  418. $LD $t0,0($a1)
  419. $MULTU ($t0,$t0)
  420. $LD $t2,$BNSZ($a1)
  421. $LD $ta0,2*$BNSZ($a1)
  422. $LD $ta2,3*$BNSZ($a1)
  423. mflo ($t1,$t0,$t0)
  424. mfhi ($t0,$t0,$t0)
  425. $ST $t1,0($a0)
  426. $ST $t0,$BNSZ($a0)
  427. $MULTU ($t2,$t2)
  428. subu $a2,4
  429. $PTR_ADD $a0,8*$BNSZ
  430. $PTR_ADD $a1,4*$BNSZ
  431. mflo ($t3,$t2,$t2)
  432. mfhi ($t2,$t2,$t2)
  433. $ST $t3,-6*$BNSZ($a0)
  434. $ST $t2,-5*$BNSZ($a0)
  435. $MULTU ($ta0,$ta0)
  436. mflo ($ta1,$ta0,$ta0)
  437. mfhi ($ta0,$ta0,$ta0)
  438. $ST $ta1,-4*$BNSZ($a0)
  439. $ST $ta0,-3*$BNSZ($a0)
  440. $MULTU ($ta2,$ta2)
  441. and $ta0,$a2,$minus4
  442. mflo ($ta3,$ta2,$ta2)
  443. mfhi ($ta2,$ta2,$ta2)
  444. $ST $ta3,-2*$BNSZ($a0)
  445. .set noreorder
  446. bgtz $ta0,.L_bn_sqr_words_loop
  447. $ST $ta2,-$BNSZ($a0)
  448. beqz $a2,.L_bn_sqr_words_return
  449. nop
  450. .L_bn_sqr_words_tail:
  451. .set reorder
  452. $LD $t0,0($a1)
  453. $MULTU ($t0,$t0)
  454. subu $a2,1
  455. mflo ($t1,$t0,$t0)
  456. mfhi ($t0,$t0,$t0)
  457. $ST $t1,0($a0)
  458. $ST $t0,$BNSZ($a0)
  459. beqz $a2,.L_bn_sqr_words_return
  460. $LD $t0,$BNSZ($a1)
  461. $MULTU ($t0,$t0)
  462. subu $a2,1
  463. mflo ($t1,$t0,$t0)
  464. mfhi ($t0,$t0,$t0)
  465. $ST $t1,2*$BNSZ($a0)
  466. $ST $t0,3*$BNSZ($a0)
  467. beqz $a2,.L_bn_sqr_words_return
  468. $LD $t0,2*$BNSZ($a1)
  469. $MULTU ($t0,$t0)
  470. mflo ($t1,$t0,$t0)
  471. mfhi ($t0,$t0,$t0)
  472. $ST $t1,4*$BNSZ($a0)
  473. $ST $t0,5*$BNSZ($a0)
  474. .L_bn_sqr_words_return:
  475. .set noreorder
  476. ___
  477. $code.=<<___ if ($flavour =~ /nubi/i);
  478. $REG_L $t3,4*$SZREG($sp)
  479. $REG_L $t2,3*$SZREG($sp)
  480. $REG_L $t1,2*$SZREG($sp)
  481. $REG_L $t0,1*$SZREG($sp)
  482. $REG_L $gp,0*$SZREG($sp)
  483. $PTR_ADD $sp,6*$SZREG
  484. ___
  485. $code.=<<___;
  486. jr $ra
  487. move $a0,$v0
  488. .end bn_sqr_words_internal
  489. .align 5
  490. .globl bn_add_words
  491. .ent bn_add_words
  492. bn_add_words:
  493. .set noreorder
  494. bgtz $a3,bn_add_words_internal
  495. move $v0,$zero
  496. jr $ra
  497. move $a0,$v0
  498. .end bn_add_words
  499. .align 5
  500. .ent bn_add_words_internal
  501. bn_add_words_internal:
  502. ___
  503. $code.=<<___ if ($flavour =~ /nubi/i);
  504. .frame $sp,6*$SZREG,$ra
  505. .mask 0x8000f008,-$SZREG
  506. .set noreorder
  507. $PTR_SUB $sp,6*$SZREG
  508. $REG_S $ra,5*$SZREG($sp)
  509. $REG_S $t3,4*$SZREG($sp)
  510. $REG_S $t2,3*$SZREG($sp)
  511. $REG_S $t1,2*$SZREG($sp)
  512. $REG_S $t0,1*$SZREG($sp)
  513. $REG_S $gp,0*$SZREG($sp)
  514. ___
  515. $code.=<<___;
  516. .set reorder
  517. li $minus4,-4
  518. and $at,$a3,$minus4
  519. beqz $at,.L_bn_add_words_tail
  520. .L_bn_add_words_loop:
  521. $LD $t0,0($a1)
  522. $LD $ta0,0($a2)
  523. subu $a3,4
  524. $LD $t1,$BNSZ($a1)
  525. and $at,$a3,$minus4
  526. $LD $t2,2*$BNSZ($a1)
  527. $PTR_ADD $a2,4*$BNSZ
  528. $LD $t3,3*$BNSZ($a1)
  529. $PTR_ADD $a0,4*$BNSZ
  530. $LD $ta1,-3*$BNSZ($a2)
  531. $PTR_ADD $a1,4*$BNSZ
  532. $LD $ta2,-2*$BNSZ($a2)
  533. $LD $ta3,-$BNSZ($a2)
  534. $ADDU $ta0,$t0
  535. sltu $t8,$ta0,$t0
  536. $ADDU $t0,$ta0,$v0
  537. sltu $v0,$t0,$ta0
  538. $ST $t0,-4*$BNSZ($a0)
  539. $ADDU $v0,$t8
  540. $ADDU $ta1,$t1
  541. sltu $t9,$ta1,$t1
  542. $ADDU $t1,$ta1,$v0
  543. sltu $v0,$t1,$ta1
  544. $ST $t1,-3*$BNSZ($a0)
  545. $ADDU $v0,$t9
  546. $ADDU $ta2,$t2
  547. sltu $t8,$ta2,$t2
  548. $ADDU $t2,$ta2,$v0
  549. sltu $v0,$t2,$ta2
  550. $ST $t2,-2*$BNSZ($a0)
  551. $ADDU $v0,$t8
  552. $ADDU $ta3,$t3
  553. sltu $t9,$ta3,$t3
  554. $ADDU $t3,$ta3,$v0
  555. sltu $v0,$t3,$ta3
  556. $ST $t3,-$BNSZ($a0)
  557. .set noreorder
  558. bgtz $at,.L_bn_add_words_loop
  559. $ADDU $v0,$t9
  560. beqz $a3,.L_bn_add_words_return
  561. nop
  562. .L_bn_add_words_tail:
  563. .set reorder
  564. $LD $t0,0($a1)
  565. $LD $ta0,0($a2)
  566. $ADDU $ta0,$t0
  567. subu $a3,1
  568. sltu $t8,$ta0,$t0
  569. $ADDU $t0,$ta0,$v0
  570. sltu $v0,$t0,$ta0
  571. $ST $t0,0($a0)
  572. $ADDU $v0,$t8
  573. beqz $a3,.L_bn_add_words_return
  574. $LD $t1,$BNSZ($a1)
  575. $LD $ta1,$BNSZ($a2)
  576. $ADDU $ta1,$t1
  577. subu $a3,1
  578. sltu $t9,$ta1,$t1
  579. $ADDU $t1,$ta1,$v0
  580. sltu $v0,$t1,$ta1
  581. $ST $t1,$BNSZ($a0)
  582. $ADDU $v0,$t9
  583. beqz $a3,.L_bn_add_words_return
  584. $LD $t2,2*$BNSZ($a1)
  585. $LD $ta2,2*$BNSZ($a2)
  586. $ADDU $ta2,$t2
  587. sltu $t8,$ta2,$t2
  588. $ADDU $t2,$ta2,$v0
  589. sltu $v0,$t2,$ta2
  590. $ST $t2,2*$BNSZ($a0)
  591. $ADDU $v0,$t8
  592. .L_bn_add_words_return:
  593. .set noreorder
  594. ___
  595. $code.=<<___ if ($flavour =~ /nubi/i);
  596. $REG_L $t3,4*$SZREG($sp)
  597. $REG_L $t2,3*$SZREG($sp)
  598. $REG_L $t1,2*$SZREG($sp)
  599. $REG_L $t0,1*$SZREG($sp)
  600. $REG_L $gp,0*$SZREG($sp)
  601. $PTR_ADD $sp,6*$SZREG
  602. ___
  603. $code.=<<___;
  604. jr $ra
  605. move $a0,$v0
  606. .end bn_add_words_internal
  607. .align 5
  608. .globl bn_sub_words
  609. .ent bn_sub_words
  610. bn_sub_words:
  611. .set noreorder
  612. bgtz $a3,bn_sub_words_internal
  613. move $v0,$zero
  614. jr $ra
  615. move $a0,$zero
  616. .end bn_sub_words
  617. .align 5
  618. .ent bn_sub_words_internal
  619. bn_sub_words_internal:
  620. ___
  621. $code.=<<___ if ($flavour =~ /nubi/i);
  622. .frame $sp,6*$SZREG,$ra
  623. .mask 0x8000f008,-$SZREG
  624. .set noreorder
  625. $PTR_SUB $sp,6*$SZREG
  626. $REG_S $ra,5*$SZREG($sp)
  627. $REG_S $t3,4*$SZREG($sp)
  628. $REG_S $t2,3*$SZREG($sp)
  629. $REG_S $t1,2*$SZREG($sp)
  630. $REG_S $t0,1*$SZREG($sp)
  631. $REG_S $gp,0*$SZREG($sp)
  632. ___
  633. $code.=<<___;
  634. .set reorder
  635. li $minus4,-4
  636. and $at,$a3,$minus4
  637. beqz $at,.L_bn_sub_words_tail
  638. .L_bn_sub_words_loop:
  639. $LD $t0,0($a1)
  640. $LD $ta0,0($a2)
  641. subu $a3,4
  642. $LD $t1,$BNSZ($a1)
  643. and $at,$a3,$minus4
  644. $LD $t2,2*$BNSZ($a1)
  645. $PTR_ADD $a2,4*$BNSZ
  646. $LD $t3,3*$BNSZ($a1)
  647. $PTR_ADD $a0,4*$BNSZ
  648. $LD $ta1,-3*$BNSZ($a2)
  649. $PTR_ADD $a1,4*$BNSZ
  650. $LD $ta2,-2*$BNSZ($a2)
  651. $LD $ta3,-$BNSZ($a2)
  652. sltu $t8,$t0,$ta0
  653. $SUBU $ta0,$t0,$ta0
  654. $SUBU $t0,$ta0,$v0
  655. sgtu $v0,$t0,$ta0
  656. $ST $t0,-4*$BNSZ($a0)
  657. $ADDU $v0,$t8
  658. sltu $t9,$t1,$ta1
  659. $SUBU $ta1,$t1,$ta1
  660. $SUBU $t1,$ta1,$v0
  661. sgtu $v0,$t1,$ta1
  662. $ST $t1,-3*$BNSZ($a0)
  663. $ADDU $v0,$t9
  664. sltu $t8,$t2,$ta2
  665. $SUBU $ta2,$t2,$ta2
  666. $SUBU $t2,$ta2,$v0
  667. sgtu $v0,$t2,$ta2
  668. $ST $t2,-2*$BNSZ($a0)
  669. $ADDU $v0,$t8
  670. sltu $t9,$t3,$ta3
  671. $SUBU $ta3,$t3,$ta3
  672. $SUBU $t3,$ta3,$v0
  673. sgtu $v0,$t3,$ta3
  674. $ST $t3,-$BNSZ($a0)
  675. .set noreorder
  676. bgtz $at,.L_bn_sub_words_loop
  677. $ADDU $v0,$t9
  678. beqz $a3,.L_bn_sub_words_return
  679. nop
  680. .L_bn_sub_words_tail:
  681. .set reorder
  682. $LD $t0,0($a1)
  683. $LD $ta0,0($a2)
  684. subu $a3,1
  685. sltu $t8,$t0,$ta0
  686. $SUBU $ta0,$t0,$ta0
  687. $SUBU $t0,$ta0,$v0
  688. sgtu $v0,$t0,$ta0
  689. $ST $t0,0($a0)
  690. $ADDU $v0,$t8
  691. beqz $a3,.L_bn_sub_words_return
  692. $LD $t1,$BNSZ($a1)
  693. subu $a3,1
  694. $LD $ta1,$BNSZ($a2)
  695. sltu $t9,$t1,$ta1
  696. $SUBU $ta1,$t1,$ta1
  697. $SUBU $t1,$ta1,$v0
  698. sgtu $v0,$t1,$ta1
  699. $ST $t1,$BNSZ($a0)
  700. $ADDU $v0,$t9
  701. beqz $a3,.L_bn_sub_words_return
  702. $LD $t2,2*$BNSZ($a1)
  703. $LD $ta2,2*$BNSZ($a2)
  704. sltu $t8,$t2,$ta2
  705. $SUBU $ta2,$t2,$ta2
  706. $SUBU $t2,$ta2,$v0
  707. sgtu $v0,$t2,$ta2
  708. $ST $t2,2*$BNSZ($a0)
  709. $ADDU $v0,$t8
  710. .L_bn_sub_words_return:
  711. .set noreorder
  712. ___
  713. $code.=<<___ if ($flavour =~ /nubi/i);
  714. $REG_L $t3,4*$SZREG($sp)
  715. $REG_L $t2,3*$SZREG($sp)
  716. $REG_L $t1,2*$SZREG($sp)
  717. $REG_L $t0,1*$SZREG($sp)
  718. $REG_L $gp,0*$SZREG($sp)
  719. $PTR_ADD $sp,6*$SZREG
  720. ___
  721. $code.=<<___;
  722. jr $ra
  723. move $a0,$v0
  724. .end bn_sub_words_internal
  725. #if 0
  726. /*
  727. * The bn_div_3_words entry point is re-used for constant-time interface.
  728. * Implementation is retained as historical reference.
  729. */
  730. .align 5
  731. .globl bn_div_3_words
  732. .ent bn_div_3_words
  733. bn_div_3_words:
  734. .set noreorder
  735. move $a3,$a0 # we know that bn_div_words does not
  736. # touch $a3, $ta2, $ta3 and preserves $a2
  737. # so that we can save two arguments
  738. # and return address in registers
  739. # instead of stack:-)
  740. $LD $a0,($a3)
  741. move $ta2,$a1
  742. bne $a0,$a2,bn_div_3_words_internal
  743. $LD $a1,-$BNSZ($a3)
  744. li $v0,-1
  745. jr $ra
  746. move $a0,$v0
  747. .end bn_div_3_words
  748. .align 5
  749. .ent bn_div_3_words_internal
  750. bn_div_3_words_internal:
  751. ___
  752. $code.=<<___ if ($flavour =~ /nubi/i);
  753. .frame $sp,6*$SZREG,$ra
  754. .mask 0x8000f008,-$SZREG
  755. .set noreorder
  756. $PTR_SUB $sp,6*$SZREG
  757. $REG_S $ra,5*$SZREG($sp)
  758. $REG_S $t3,4*$SZREG($sp)
  759. $REG_S $t2,3*$SZREG($sp)
  760. $REG_S $t1,2*$SZREG($sp)
  761. $REG_S $t0,1*$SZREG($sp)
  762. $REG_S $gp,0*$SZREG($sp)
  763. ___
  764. $code.=<<___;
  765. .set reorder
  766. move $ta3,$ra
  767. bal bn_div_words_internal
  768. move $ra,$ta3
  769. $MULTU ($ta2,$v0)
  770. $LD $t2,-2*$BNSZ($a3)
  771. move $ta0,$zero
  772. mfhi ($t1,$ta2,$v0)
  773. mflo ($t0,$ta2,$v0)
  774. sltu $t8,$t1,$a1
  775. .L_bn_div_3_words_inner_loop:
  776. bnez $t8,.L_bn_div_3_words_inner_loop_done
  777. sgeu $at,$t2,$t0
  778. seq $t9,$t1,$a1
  779. and $at,$t9
  780. sltu $t3,$t0,$ta2
  781. $ADDU $a1,$a2
  782. $SUBU $t1,$t3
  783. $SUBU $t0,$ta2
  784. sltu $t8,$t1,$a1
  785. sltu $ta0,$a1,$a2
  786. or $t8,$ta0
  787. .set noreorder
  788. beqz $at,.L_bn_div_3_words_inner_loop
  789. $SUBU $v0,1
  790. $ADDU $v0,1
  791. .set reorder
  792. .L_bn_div_3_words_inner_loop_done:
  793. .set noreorder
  794. ___
  795. $code.=<<___ if ($flavour =~ /nubi/i);
  796. $REG_L $t3,4*$SZREG($sp)
  797. $REG_L $t2,3*$SZREG($sp)
  798. $REG_L $t1,2*$SZREG($sp)
  799. $REG_L $t0,1*$SZREG($sp)
  800. $REG_L $gp,0*$SZREG($sp)
  801. $PTR_ADD $sp,6*$SZREG
  802. ___
  803. $code.=<<___;
  804. jr $ra
  805. move $a0,$v0
  806. .end bn_div_3_words_internal
  807. #endif
  808. .align 5
  809. .globl bn_div_words
  810. .ent bn_div_words
  811. bn_div_words:
  812. .set noreorder
  813. bnez $a2,bn_div_words_internal
  814. li $v0,-1 # I would rather signal div-by-zero
  815. # which can be done with 'break 7'
  816. jr $ra
  817. move $a0,$v0
  818. .end bn_div_words
  819. .align 5
  820. .ent bn_div_words_internal
  821. bn_div_words_internal:
  822. ___
  823. $code.=<<___ if ($flavour =~ /nubi/i);
  824. .frame $sp,6*$SZREG,$ra
  825. .mask 0x8000f008,-$SZREG
  826. .set noreorder
  827. $PTR_SUB $sp,6*$SZREG
  828. $REG_S $ra,5*$SZREG($sp)
  829. $REG_S $t3,4*$SZREG($sp)
  830. $REG_S $t2,3*$SZREG($sp)
  831. $REG_S $t1,2*$SZREG($sp)
  832. $REG_S $t0,1*$SZREG($sp)
  833. $REG_S $gp,0*$SZREG($sp)
  834. ___
  835. $code.=<<___;
  836. move $v1,$zero
  837. bltz $a2,.L_bn_div_words_body
  838. move $t9,$v1
  839. $SLL $a2,1
  840. bgtz $a2,.-4
  841. addu $t9,1
  842. .set reorder
  843. negu $t1,$t9
  844. li $t2,-1
  845. $SLL $t2,$t1
  846. and $t2,$a0
  847. $SRL $at,$a1,$t1
  848. .set noreorder
  849. beqz $t2,.+12
  850. nop
  851. break 6 # signal overflow
  852. .set reorder
  853. $SLL $a0,$t9
  854. $SLL $a1,$t9
  855. or $a0,$at
  856. ___
  857. $QT=$ta0;
  858. $HH=$ta1;
  859. $DH=$v1;
  860. $code.=<<___;
  861. .L_bn_div_words_body:
  862. $SRL $DH,$a2,4*$BNSZ # bits
  863. sgeu $at,$a0,$a2
  864. .set noreorder
  865. beqz $at,.+12
  866. nop
  867. $SUBU $a0,$a2
  868. .set reorder
  869. li $QT,-1
  870. $SRL $HH,$a0,4*$BNSZ # bits
  871. $SRL $QT,4*$BNSZ # q=0xffffffff
  872. beq $DH,$HH,.L_bn_div_words_skip_div1
  873. $DIVU ($a0,$DH)
  874. mfqt ($QT,$a0,$DH)
  875. .L_bn_div_words_skip_div1:
  876. $MULTU ($a2,$QT)
  877. $SLL $t3,$a0,4*$BNSZ # bits
  878. $SRL $at,$a1,4*$BNSZ # bits
  879. or $t3,$at
  880. mflo ($t0,$a2,$QT)
  881. mfhi ($t1,$a2,$QT)
  882. .L_bn_div_words_inner_loop1:
  883. sltu $t2,$t3,$t0
  884. seq $t8,$HH,$t1
  885. sltu $at,$HH,$t1
  886. and $t2,$t8
  887. sltu $v0,$t0,$a2
  888. or $at,$t2
  889. .set noreorder
  890. beqz $at,.L_bn_div_words_inner_loop1_done
  891. $SUBU $t1,$v0
  892. $SUBU $t0,$a2
  893. b .L_bn_div_words_inner_loop1
  894. $SUBU $QT,1
  895. .set reorder
  896. .L_bn_div_words_inner_loop1_done:
  897. $SLL $a1,4*$BNSZ # bits
  898. $SUBU $a0,$t3,$t0
  899. $SLL $v0,$QT,4*$BNSZ # bits
  900. li $QT,-1
  901. $SRL $HH,$a0,4*$BNSZ # bits
  902. $SRL $QT,4*$BNSZ # q=0xffffffff
  903. beq $DH,$HH,.L_bn_div_words_skip_div2
  904. $DIVU ($a0,$DH)
  905. mfqt ($QT,$a0,$DH)
  906. .L_bn_div_words_skip_div2:
  907. $MULTU ($a2,$QT)
  908. $SLL $t3,$a0,4*$BNSZ # bits
  909. $SRL $at,$a1,4*$BNSZ # bits
  910. or $t3,$at
  911. mflo ($t0,$a2,$QT)
  912. mfhi ($t1,$a2,$QT)
  913. .L_bn_div_words_inner_loop2:
  914. sltu $t2,$t3,$t0
  915. seq $t8,$HH,$t1
  916. sltu $at,$HH,$t1
  917. and $t2,$t8
  918. sltu $v1,$t0,$a2
  919. or $at,$t2
  920. .set noreorder
  921. beqz $at,.L_bn_div_words_inner_loop2_done
  922. $SUBU $t1,$v1
  923. $SUBU $t0,$a2
  924. b .L_bn_div_words_inner_loop2
  925. $SUBU $QT,1
  926. .set reorder
  927. .L_bn_div_words_inner_loop2_done:
  928. $SUBU $a0,$t3,$t0
  929. or $v0,$QT
  930. $SRL $v1,$a0,$t9 # $v1 contains remainder if anybody wants it
  931. $SRL $a2,$t9 # restore $a2
  932. .set noreorder
  933. move $a1,$v1
  934. ___
  935. $code.=<<___ if ($flavour =~ /nubi/i);
  936. $REG_L $t3,4*$SZREG($sp)
  937. $REG_L $t2,3*$SZREG($sp)
  938. $REG_L $t1,2*$SZREG($sp)
  939. $REG_L $t0,1*$SZREG($sp)
  940. $REG_L $gp,0*$SZREG($sp)
  941. $PTR_ADD $sp,6*$SZREG
  942. ___
  943. $code.=<<___;
  944. jr $ra
  945. move $a0,$v0
  946. .end bn_div_words_internal
  947. ___
  948. undef $HH; undef $QT; undef $DH;
  949. ($a_0,$a_1,$a_2,$a_3)=($t0,$t1,$t2,$t3);
  950. ($b_0,$b_1,$b_2,$b_3)=($ta0,$ta1,$ta2,$ta3);
  951. ($a_4,$a_5,$a_6,$a_7)=($s0,$s2,$s4,$a1); # once we load a[7], no use for $a1
  952. ($b_4,$b_5,$b_6,$b_7)=($s1,$s3,$s5,$a2); # once we load b[7], no use for $a2
  953. ($t_1,$t_2,$c_1,$c_2,$c_3)=($t8,$t9,$v0,$v1,$a3);
  954. $code.=<<___;
  955. .align 5
  956. .globl bn_mul_comba8
  957. .ent bn_mul_comba8
  958. bn_mul_comba8:
  959. .set noreorder
  960. ___
  961. $code.=<<___ if ($flavour =~ /nubi/i);
  962. .frame $sp,12*$SZREG,$ra
  963. .mask 0x803ff008,-$SZREG
  964. $PTR_SUB $sp,12*$SZREG
  965. $REG_S $ra,11*$SZREG($sp)
  966. $REG_S $s5,10*$SZREG($sp)
  967. $REG_S $s4,9*$SZREG($sp)
  968. $REG_S $s3,8*$SZREG($sp)
  969. $REG_S $s2,7*$SZREG($sp)
  970. $REG_S $s1,6*$SZREG($sp)
  971. $REG_S $s0,5*$SZREG($sp)
  972. $REG_S $t3,4*$SZREG($sp)
  973. $REG_S $t2,3*$SZREG($sp)
  974. $REG_S $t1,2*$SZREG($sp)
  975. $REG_S $t0,1*$SZREG($sp)
  976. $REG_S $gp,0*$SZREG($sp)
  977. ___
  978. $code.=<<___ if ($flavour !~ /nubi/i);
  979. .frame $sp,6*$SZREG,$ra
  980. .mask 0x003f0000,-$SZREG
  981. $PTR_SUB $sp,6*$SZREG
  982. $REG_S $s5,5*$SZREG($sp)
  983. $REG_S $s4,4*$SZREG($sp)
  984. $REG_S $s3,3*$SZREG($sp)
  985. $REG_S $s2,2*$SZREG($sp)
  986. $REG_S $s1,1*$SZREG($sp)
  987. $REG_S $s0,0*$SZREG($sp)
  988. ___
  989. $code.=<<___;
  990. .set reorder
  991. $LD $a_0,0($a1) # If compiled with -mips3 option on
  992. # R5000 box assembler barks on this
  993. # 1ine with "should not have mult/div
  994. # as last instruction in bb (R10K
  995. # bug)" warning. If anybody out there
  996. # has a clue about how to circumvent
  997. # this do send me a note.
  998. # <appro\@fy.chalmers.se>
  999. $LD $b_0,0($a2)
  1000. $LD $a_1,$BNSZ($a1)
  1001. $LD $a_2,2*$BNSZ($a1)
  1002. $MULTU ($a_0,$b_0) # mul_add_c(a[0],b[0],c1,c2,c3);
  1003. $LD $a_3,3*$BNSZ($a1)
  1004. $LD $b_1,$BNSZ($a2)
  1005. $LD $b_2,2*$BNSZ($a2)
  1006. $LD $b_3,3*$BNSZ($a2)
  1007. mflo ($c_1,$a_0,$b_0)
  1008. mfhi ($c_2,$a_0,$b_0)
  1009. $LD $a_4,4*$BNSZ($a1)
  1010. $LD $a_5,5*$BNSZ($a1)
  1011. $MULTU ($a_0,$b_1) # mul_add_c(a[0],b[1],c2,c3,c1);
  1012. $LD $a_6,6*$BNSZ($a1)
  1013. $LD $a_7,7*$BNSZ($a1)
  1014. $LD $b_4,4*$BNSZ($a2)
  1015. $LD $b_5,5*$BNSZ($a2)
  1016. mflo ($t_1,$a_0,$b_1)
  1017. mfhi ($t_2,$a_0,$b_1)
  1018. $ADDU $c_2,$t_1
  1019. sltu $at,$c_2,$t_1
  1020. $MULTU ($a_1,$b_0) # mul_add_c(a[1],b[0],c2,c3,c1);
  1021. $ADDU $c_3,$t_2,$at
  1022. $LD $b_6,6*$BNSZ($a2)
  1023. $LD $b_7,7*$BNSZ($a2)
  1024. $ST $c_1,0($a0) # r[0]=c1;
  1025. mflo ($t_1,$a_1,$b_0)
  1026. mfhi ($t_2,$a_1,$b_0)
  1027. $ADDU $c_2,$t_1
  1028. sltu $at,$c_2,$t_1
  1029. $MULTU ($a_2,$b_0) # mul_add_c(a[2],b[0],c3,c1,c2);
  1030. $ADDU $t_2,$at
  1031. $ADDU $c_3,$t_2
  1032. sltu $c_1,$c_3,$t_2
  1033. $ST $c_2,$BNSZ($a0) # r[1]=c2;
  1034. mflo ($t_1,$a_2,$b_0)
  1035. mfhi ($t_2,$a_2,$b_0)
  1036. $ADDU $c_3,$t_1
  1037. sltu $at,$c_3,$t_1
  1038. $MULTU ($a_1,$b_1) # mul_add_c(a[1],b[1],c3,c1,c2);
  1039. $ADDU $t_2,$at
  1040. $ADDU $c_1,$t_2
  1041. mflo ($t_1,$a_1,$b_1)
  1042. mfhi ($t_2,$a_1,$b_1)
  1043. $ADDU $c_3,$t_1
  1044. sltu $at,$c_3,$t_1
  1045. $MULTU ($a_0,$b_2) # mul_add_c(a[0],b[2],c3,c1,c2);
  1046. $ADDU $t_2,$at
  1047. $ADDU $c_1,$t_2
  1048. sltu $c_2,$c_1,$t_2
  1049. mflo ($t_1,$a_0,$b_2)
  1050. mfhi ($t_2,$a_0,$b_2)
  1051. $ADDU $c_3,$t_1
  1052. sltu $at,$c_3,$t_1
  1053. $MULTU ($a_0,$b_3) # mul_add_c(a[0],b[3],c1,c2,c3);
  1054. $ADDU $t_2,$at
  1055. $ADDU $c_1,$t_2
  1056. sltu $at,$c_1,$t_2
  1057. $ADDU $c_2,$at
  1058. $ST $c_3,2*$BNSZ($a0) # r[2]=c3;
  1059. mflo ($t_1,$a_0,$b_3)
  1060. mfhi ($t_2,$a_0,$b_3)
  1061. $ADDU $c_1,$t_1
  1062. sltu $at,$c_1,$t_1
  1063. $MULTU ($a_1,$b_2) # mul_add_c(a[1],b[2],c1,c2,c3);
  1064. $ADDU $t_2,$at
  1065. $ADDU $c_2,$t_2
  1066. sltu $c_3,$c_2,$t_2
  1067. mflo ($t_1,$a_1,$b_2)
  1068. mfhi ($t_2,$a_1,$b_2)
  1069. $ADDU $c_1,$t_1
  1070. sltu $at,$c_1,$t_1
  1071. $MULTU ($a_2,$b_1) # mul_add_c(a[2],b[1],c1,c2,c3);
  1072. $ADDU $t_2,$at
  1073. $ADDU $c_2,$t_2
  1074. sltu $at,$c_2,$t_2
  1075. $ADDU $c_3,$at
  1076. mflo ($t_1,$a_2,$b_1)
  1077. mfhi ($t_2,$a_2,$b_1)
  1078. $ADDU $c_1,$t_1
  1079. sltu $at,$c_1,$t_1
  1080. $MULTU ($a_3,$b_0) # mul_add_c(a[3],b[0],c1,c2,c3);
  1081. $ADDU $t_2,$at
  1082. $ADDU $c_2,$t_2
  1083. sltu $at,$c_2,$t_2
  1084. $ADDU $c_3,$at
  1085. mflo ($t_1,$a_3,$b_0)
  1086. mfhi ($t_2,$a_3,$b_0)
  1087. $ADDU $c_1,$t_1
  1088. sltu $at,$c_1,$t_1
  1089. $MULTU ($a_4,$b_0) # mul_add_c(a[4],b[0],c2,c3,c1);
  1090. $ADDU $t_2,$at
  1091. $ADDU $c_2,$t_2
  1092. sltu $at,$c_2,$t_2
  1093. $ADDU $c_3,$at
  1094. $ST $c_1,3*$BNSZ($a0) # r[3]=c1;
  1095. mflo ($t_1,$a_4,$b_0)
  1096. mfhi ($t_2,$a_4,$b_0)
  1097. $ADDU $c_2,$t_1
  1098. sltu $at,$c_2,$t_1
  1099. $MULTU ($a_3,$b_1) # mul_add_c(a[3],b[1],c2,c3,c1);
  1100. $ADDU $t_2,$at
  1101. $ADDU $c_3,$t_2
  1102. sltu $c_1,$c_3,$t_2
  1103. mflo ($t_1,$a_3,$b_1)
  1104. mfhi ($t_2,$a_3,$b_1)
  1105. $ADDU $c_2,$t_1
  1106. sltu $at,$c_2,$t_1
  1107. $MULTU ($a_2,$b_2) # mul_add_c(a[2],b[2],c2,c3,c1);
  1108. $ADDU $t_2,$at
  1109. $ADDU $c_3,$t_2
  1110. sltu $at,$c_3,$t_2
  1111. $ADDU $c_1,$at
  1112. mflo ($t_1,$a_2,$b_2)
  1113. mfhi ($t_2,$a_2,$b_2)
  1114. $ADDU $c_2,$t_1
  1115. sltu $at,$c_2,$t_1
  1116. $MULTU ($a_1,$b_3) # mul_add_c(a[1],b[3],c2,c3,c1);
  1117. $ADDU $t_2,$at
  1118. $ADDU $c_3,$t_2
  1119. sltu $at,$c_3,$t_2
  1120. $ADDU $c_1,$at
  1121. mflo ($t_1,$a_1,$b_3)
  1122. mfhi ($t_2,$a_1,$b_3)
  1123. $ADDU $c_2,$t_1
  1124. sltu $at,$c_2,$t_1
  1125. $MULTU ($a_0,$b_4) # mul_add_c(a[0],b[4],c2,c3,c1);
  1126. $ADDU $t_2,$at
  1127. $ADDU $c_3,$t_2
  1128. sltu $at,$c_3,$t_2
  1129. $ADDU $c_1,$at
  1130. mflo ($t_1,$a_0,$b_4)
  1131. mfhi ($t_2,$a_0,$b_4)
  1132. $ADDU $c_2,$t_1
  1133. sltu $at,$c_2,$t_1
  1134. $MULTU ($a_0,$b_5) # mul_add_c(a[0],b[5],c3,c1,c2);
  1135. $ADDU $t_2,$at
  1136. $ADDU $c_3,$t_2
  1137. sltu $at,$c_3,$t_2
  1138. $ADDU $c_1,$at
  1139. $ST $c_2,4*$BNSZ($a0) # r[4]=c2;
  1140. mflo ($t_1,$a_0,$b_5)
  1141. mfhi ($t_2,$a_0,$b_5)
  1142. $ADDU $c_3,$t_1
  1143. sltu $at,$c_3,$t_1
  1144. $MULTU ($a_1,$b_4) # mul_add_c(a[1],b[4],c3,c1,c2);
  1145. $ADDU $t_2,$at
  1146. $ADDU $c_1,$t_2
  1147. sltu $c_2,$c_1,$t_2
  1148. mflo ($t_1,$a_1,$b_4)
  1149. mfhi ($t_2,$a_1,$b_4)
  1150. $ADDU $c_3,$t_1
  1151. sltu $at,$c_3,$t_1
  1152. $MULTU ($a_2,$b_3) # mul_add_c(a[2],b[3],c3,c1,c2);
  1153. $ADDU $t_2,$at
  1154. $ADDU $c_1,$t_2
  1155. sltu $at,$c_1,$t_2
  1156. $ADDU $c_2,$at
  1157. mflo ($t_1,$a_2,$b_3)
  1158. mfhi ($t_2,$a_2,$b_3)
  1159. $ADDU $c_3,$t_1
  1160. sltu $at,$c_3,$t_1
  1161. $MULTU ($a_3,$b_2) # mul_add_c(a[3],b[2],c3,c1,c2);
  1162. $ADDU $t_2,$at
  1163. $ADDU $c_1,$t_2
  1164. sltu $at,$c_1,$t_2
  1165. $ADDU $c_2,$at
  1166. mflo ($t_1,$a_3,$b_2)
  1167. mfhi ($t_2,$a_3,$b_2)
  1168. $ADDU $c_3,$t_1
  1169. sltu $at,$c_3,$t_1
  1170. $MULTU ($a_4,$b_1) # mul_add_c(a[4],b[1],c3,c1,c2);
  1171. $ADDU $t_2,$at
  1172. $ADDU $c_1,$t_2
  1173. sltu $at,$c_1,$t_2
  1174. $ADDU $c_2,$at
  1175. mflo ($t_1,$a_4,$b_1)
  1176. mfhi ($t_2,$a_4,$b_1)
  1177. $ADDU $c_3,$t_1
  1178. sltu $at,$c_3,$t_1
  1179. $MULTU ($a_5,$b_0) # mul_add_c(a[5],b[0],c3,c1,c2);
  1180. $ADDU $t_2,$at
  1181. $ADDU $c_1,$t_2
  1182. sltu $at,$c_1,$t_2
  1183. $ADDU $c_2,$at
  1184. mflo ($t_1,$a_5,$b_0)
  1185. mfhi ($t_2,$a_5,$b_0)
  1186. $ADDU $c_3,$t_1
  1187. sltu $at,$c_3,$t_1
  1188. $MULTU ($a_6,$b_0) # mul_add_c(a[6],b[0],c1,c2,c3);
  1189. $ADDU $t_2,$at
  1190. $ADDU $c_1,$t_2
  1191. sltu $at,$c_1,$t_2
  1192. $ADDU $c_2,$at
  1193. $ST $c_3,5*$BNSZ($a0) # r[5]=c3;
  1194. mflo ($t_1,$a_6,$b_0)
  1195. mfhi ($t_2,$a_6,$b_0)
  1196. $ADDU $c_1,$t_1
  1197. sltu $at,$c_1,$t_1
  1198. $MULTU ($a_5,$b_1) # mul_add_c(a[5],b[1],c1,c2,c3);
  1199. $ADDU $t_2,$at
  1200. $ADDU $c_2,$t_2
  1201. sltu $c_3,$c_2,$t_2
  1202. mflo ($t_1,$a_5,$b_1)
  1203. mfhi ($t_2,$a_5,$b_1)
  1204. $ADDU $c_1,$t_1
  1205. sltu $at,$c_1,$t_1
  1206. $MULTU ($a_4,$b_2) # mul_add_c(a[4],b[2],c1,c2,c3);
  1207. $ADDU $t_2,$at
  1208. $ADDU $c_2,$t_2
  1209. sltu $at,$c_2,$t_2
  1210. $ADDU $c_3,$at
  1211. mflo ($t_1,$a_4,$b_2)
  1212. mfhi ($t_2,$a_4,$b_2)
  1213. $ADDU $c_1,$t_1
  1214. sltu $at,$c_1,$t_1
  1215. $MULTU ($a_3,$b_3) # mul_add_c(a[3],b[3],c1,c2,c3);
  1216. $ADDU $t_2,$at
  1217. $ADDU $c_2,$t_2
  1218. sltu $at,$c_2,$t_2
  1219. $ADDU $c_3,$at
  1220. mflo ($t_1,$a_3,$b_3)
  1221. mfhi ($t_2,$a_3,$b_3)
  1222. $ADDU $c_1,$t_1
  1223. sltu $at,$c_1,$t_1
  1224. $MULTU ($a_2,$b_4) # mul_add_c(a[2],b[4],c1,c2,c3);
  1225. $ADDU $t_2,$at
  1226. $ADDU $c_2,$t_2
  1227. sltu $at,$c_2,$t_2
  1228. $ADDU $c_3,$at
  1229. mflo ($t_1,$a_2,$b_4)
  1230. mfhi ($t_2,$a_2,$b_4)
  1231. $ADDU $c_1,$t_1
  1232. sltu $at,$c_1,$t_1
  1233. $MULTU ($a_1,$b_5) # mul_add_c(a[1],b[5],c1,c2,c3);
  1234. $ADDU $t_2,$at
  1235. $ADDU $c_2,$t_2
  1236. sltu $at,$c_2,$t_2
  1237. $ADDU $c_3,$at
  1238. mflo ($t_1,$a_1,$b_5)
  1239. mfhi ($t_2,$a_1,$b_5)
  1240. $ADDU $c_1,$t_1
  1241. sltu $at,$c_1,$t_1
  1242. $MULTU ($a_0,$b_6) # mul_add_c(a[0],b[6],c1,c2,c3);
  1243. $ADDU $t_2,$at
  1244. $ADDU $c_2,$t_2
  1245. sltu $at,$c_2,$t_2
  1246. $ADDU $c_3,$at
  1247. mflo ($t_1,$a_0,$b_6)
  1248. mfhi ($t_2,$a_0,$b_6)
  1249. $ADDU $c_1,$t_1
  1250. sltu $at,$c_1,$t_1
  1251. $MULTU ($a_0,$b_7) # mul_add_c(a[0],b[7],c2,c3,c1);
  1252. $ADDU $t_2,$at
  1253. $ADDU $c_2,$t_2
  1254. sltu $at,$c_2,$t_2
  1255. $ADDU $c_3,$at
  1256. $ST $c_1,6*$BNSZ($a0) # r[6]=c1;
  1257. mflo ($t_1,$a_0,$b_7)
  1258. mfhi ($t_2,$a_0,$b_7)
  1259. $ADDU $c_2,$t_1
  1260. sltu $at,$c_2,$t_1
  1261. $MULTU ($a_1,$b_6) # mul_add_c(a[1],b[6],c2,c3,c1);
  1262. $ADDU $t_2,$at
  1263. $ADDU $c_3,$t_2
  1264. sltu $c_1,$c_3,$t_2
  1265. mflo ($t_1,$a_1,$b_6)
  1266. mfhi ($t_2,$a_1,$b_6)
  1267. $ADDU $c_2,$t_1
  1268. sltu $at,$c_2,$t_1
  1269. $MULTU ($a_2,$b_5) # mul_add_c(a[2],b[5],c2,c3,c1);
  1270. $ADDU $t_2,$at
  1271. $ADDU $c_3,$t_2
  1272. sltu $at,$c_3,$t_2
  1273. $ADDU $c_1,$at
  1274. mflo ($t_1,$a_2,$b_5)
  1275. mfhi ($t_2,$a_2,$b_5)
  1276. $ADDU $c_2,$t_1
  1277. sltu $at,$c_2,$t_1
  1278. $MULTU ($a_3,$b_4) # mul_add_c(a[3],b[4],c2,c3,c1);
  1279. $ADDU $t_2,$at
  1280. $ADDU $c_3,$t_2
  1281. sltu $at,$c_3,$t_2
  1282. $ADDU $c_1,$at
  1283. mflo ($t_1,$a_3,$b_4)
  1284. mfhi ($t_2,$a_3,$b_4)
  1285. $ADDU $c_2,$t_1
  1286. sltu $at,$c_2,$t_1
  1287. $MULTU ($a_4,$b_3) # mul_add_c(a[4],b[3],c2,c3,c1);
  1288. $ADDU $t_2,$at
  1289. $ADDU $c_3,$t_2
  1290. sltu $at,$c_3,$t_2
  1291. $ADDU $c_1,$at
  1292. mflo ($t_1,$a_4,$b_3)
  1293. mfhi ($t_2,$a_4,$b_3)
  1294. $ADDU $c_2,$t_1
  1295. sltu $at,$c_2,$t_1
  1296. $MULTU ($a_5,$b_2) # mul_add_c(a[5],b[2],c2,c3,c1);
  1297. $ADDU $t_2,$at
  1298. $ADDU $c_3,$t_2
  1299. sltu $at,$c_3,$t_2
  1300. $ADDU $c_1,$at
  1301. mflo ($t_1,$a_5,$b_2)
  1302. mfhi ($t_2,$a_5,$b_2)
  1303. $ADDU $c_2,$t_1
  1304. sltu $at,$c_2,$t_1
  1305. $MULTU ($a_6,$b_1) # mul_add_c(a[6],b[1],c2,c3,c1);
  1306. $ADDU $t_2,$at
  1307. $ADDU $c_3,$t_2
  1308. sltu $at,$c_3,$t_2
  1309. $ADDU $c_1,$at
  1310. mflo ($t_1,$a_6,$b_1)
  1311. mfhi ($t_2,$a_6,$b_1)
  1312. $ADDU $c_2,$t_1
  1313. sltu $at,$c_2,$t_1
  1314. $MULTU ($a_7,$b_0) # mul_add_c(a[7],b[0],c2,c3,c1);
  1315. $ADDU $t_2,$at
  1316. $ADDU $c_3,$t_2
  1317. sltu $at,$c_3,$t_2
  1318. $ADDU $c_1,$at
  1319. mflo ($t_1,$a_7,$b_0)
  1320. mfhi ($t_2,$a_7,$b_0)
  1321. $ADDU $c_2,$t_1
  1322. sltu $at,$c_2,$t_1
  1323. $MULTU ($a_7,$b_1) # mul_add_c(a[7],b[1],c3,c1,c2);
  1324. $ADDU $t_2,$at
  1325. $ADDU $c_3,$t_2
  1326. sltu $at,$c_3,$t_2
  1327. $ADDU $c_1,$at
  1328. $ST $c_2,7*$BNSZ($a0) # r[7]=c2;
  1329. mflo ($t_1,$a_7,$b_1)
  1330. mfhi ($t_2,$a_7,$b_1)
  1331. $ADDU $c_3,$t_1
  1332. sltu $at,$c_3,$t_1
  1333. $MULTU ($a_6,$b_2) # mul_add_c(a[6],b[2],c3,c1,c2);
  1334. $ADDU $t_2,$at
  1335. $ADDU $c_1,$t_2
  1336. sltu $c_2,$c_1,$t_2
  1337. mflo ($t_1,$a_6,$b_2)
  1338. mfhi ($t_2,$a_6,$b_2)
  1339. $ADDU $c_3,$t_1
  1340. sltu $at,$c_3,$t_1
  1341. $MULTU ($a_5,$b_3) # mul_add_c(a[5],b[3],c3,c1,c2);
  1342. $ADDU $t_2,$at
  1343. $ADDU $c_1,$t_2
  1344. sltu $at,$c_1,$t_2
  1345. $ADDU $c_2,$at
  1346. mflo ($t_1,$a_5,$b_3)
  1347. mfhi ($t_2,$a_5,$b_3)
  1348. $ADDU $c_3,$t_1
  1349. sltu $at,$c_3,$t_1
  1350. $MULTU ($a_4,$b_4) # mul_add_c(a[4],b[4],c3,c1,c2);
  1351. $ADDU $t_2,$at
  1352. $ADDU $c_1,$t_2
  1353. sltu $at,$c_1,$t_2
  1354. $ADDU $c_2,$at
  1355. mflo ($t_1,$a_4,$b_4)
  1356. mfhi ($t_2,$a_4,$b_4)
  1357. $ADDU $c_3,$t_1
  1358. sltu $at,$c_3,$t_1
  1359. $MULTU ($a_3,$b_5) # mul_add_c(a[3],b[5],c3,c1,c2);
  1360. $ADDU $t_2,$at
  1361. $ADDU $c_1,$t_2
  1362. sltu $at,$c_1,$t_2
  1363. $ADDU $c_2,$at
  1364. mflo ($t_1,$a_3,$b_5)
  1365. mfhi ($t_2,$a_3,$b_5)
  1366. $ADDU $c_3,$t_1
  1367. sltu $at,$c_3,$t_1
  1368. $MULTU ($a_2,$b_6) # mul_add_c(a[2],b[6],c3,c1,c2);
  1369. $ADDU $t_2,$at
  1370. $ADDU $c_1,$t_2
  1371. sltu $at,$c_1,$t_2
  1372. $ADDU $c_2,$at
  1373. mflo ($t_1,$a_2,$b_6)
  1374. mfhi ($t_2,$a_2,$b_6)
  1375. $ADDU $c_3,$t_1
  1376. sltu $at,$c_3,$t_1
  1377. $MULTU ($a_1,$b_7) # mul_add_c(a[1],b[7],c3,c1,c2);
  1378. $ADDU $t_2,$at
  1379. $ADDU $c_1,$t_2
  1380. sltu $at,$c_1,$t_2
  1381. $ADDU $c_2,$at
  1382. mflo ($t_1,$a_1,$b_7)
  1383. mfhi ($t_2,$a_1,$b_7)
  1384. $ADDU $c_3,$t_1
  1385. sltu $at,$c_3,$t_1
  1386. $MULTU ($a_2,$b_7) # mul_add_c(a[2],b[7],c1,c2,c3);
  1387. $ADDU $t_2,$at
  1388. $ADDU $c_1,$t_2
  1389. sltu $at,$c_1,$t_2
  1390. $ADDU $c_2,$at
  1391. $ST $c_3,8*$BNSZ($a0) # r[8]=c3;
  1392. mflo ($t_1,$a_2,$b_7)
  1393. mfhi ($t_2,$a_2,$b_7)
  1394. $ADDU $c_1,$t_1
  1395. sltu $at,$c_1,$t_1
  1396. $MULTU ($a_3,$b_6) # mul_add_c(a[3],b[6],c1,c2,c3);
  1397. $ADDU $t_2,$at
  1398. $ADDU $c_2,$t_2
  1399. sltu $c_3,$c_2,$t_2
  1400. mflo ($t_1,$a_3,$b_6)
  1401. mfhi ($t_2,$a_3,$b_6)
  1402. $ADDU $c_1,$t_1
  1403. sltu $at,$c_1,$t_1
  1404. $MULTU ($a_4,$b_5) # mul_add_c(a[4],b[5],c1,c2,c3);
  1405. $ADDU $t_2,$at
  1406. $ADDU $c_2,$t_2
  1407. sltu $at,$c_2,$t_2
  1408. $ADDU $c_3,$at
  1409. mflo ($t_1,$a_4,$b_5)
  1410. mfhi ($t_2,$a_4,$b_5)
  1411. $ADDU $c_1,$t_1
  1412. sltu $at,$c_1,$t_1
  1413. $MULTU ($a_5,$b_4) # mul_add_c(a[5],b[4],c1,c2,c3);
  1414. $ADDU $t_2,$at
  1415. $ADDU $c_2,$t_2
  1416. sltu $at,$c_2,$t_2
  1417. $ADDU $c_3,$at
  1418. mflo ($t_1,$a_5,$b_4)
  1419. mfhi ($t_2,$a_5,$b_4)
  1420. $ADDU $c_1,$t_1
  1421. sltu $at,$c_1,$t_1
  1422. $MULTU ($a_6,$b_3) # mul_add_c(a[6],b[3],c1,c2,c3);
  1423. $ADDU $t_2,$at
  1424. $ADDU $c_2,$t_2
  1425. sltu $at,$c_2,$t_2
  1426. $ADDU $c_3,$at
  1427. mflo ($t_1,$a_6,$b_3)
  1428. mfhi ($t_2,$a_6,$b_3)
  1429. $ADDU $c_1,$t_1
  1430. sltu $at,$c_1,$t_1
  1431. $MULTU ($a_7,$b_2) # mul_add_c(a[7],b[2],c1,c2,c3);
  1432. $ADDU $t_2,$at
  1433. $ADDU $c_2,$t_2
  1434. sltu $at,$c_2,$t_2
  1435. $ADDU $c_3,$at
  1436. mflo ($t_1,$a_7,$b_2)
  1437. mfhi ($t_2,$a_7,$b_2)
  1438. $ADDU $c_1,$t_1
  1439. sltu $at,$c_1,$t_1
  1440. $MULTU ($a_7,$b_3) # mul_add_c(a[7],b[3],c2,c3,c1);
  1441. $ADDU $t_2,$at
  1442. $ADDU $c_2,$t_2
  1443. sltu $at,$c_2,$t_2
  1444. $ADDU $c_3,$at
  1445. $ST $c_1,9*$BNSZ($a0) # r[9]=c1;
  1446. mflo ($t_1,$a_7,$b_3)
  1447. mfhi ($t_2,$a_7,$b_3)
  1448. $ADDU $c_2,$t_1
  1449. sltu $at,$c_2,$t_1
  1450. $MULTU ($a_6,$b_4) # mul_add_c(a[6],b[4],c2,c3,c1);
  1451. $ADDU $t_2,$at
  1452. $ADDU $c_3,$t_2
  1453. sltu $c_1,$c_3,$t_2
  1454. mflo ($t_1,$a_6,$b_4)
  1455. mfhi ($t_2,$a_6,$b_4)
  1456. $ADDU $c_2,$t_1
  1457. sltu $at,$c_2,$t_1
  1458. $MULTU ($a_5,$b_5) # mul_add_c(a[5],b[5],c2,c3,c1);
  1459. $ADDU $t_2,$at
  1460. $ADDU $c_3,$t_2
  1461. sltu $at,$c_3,$t_2
  1462. $ADDU $c_1,$at
  1463. mflo ($t_1,$a_5,$b_5)
  1464. mfhi ($t_2,$a_5,$b_5)
  1465. $ADDU $c_2,$t_1
  1466. sltu $at,$c_2,$t_1
  1467. $MULTU ($a_4,$b_6) # mul_add_c(a[4],b[6],c2,c3,c1);
  1468. $ADDU $t_2,$at
  1469. $ADDU $c_3,$t_2
  1470. sltu $at,$c_3,$t_2
  1471. $ADDU $c_1,$at
  1472. mflo ($t_1,$a_4,$b_6)
  1473. mfhi ($t_2,$a_4,$b_6)
  1474. $ADDU $c_2,$t_1
  1475. sltu $at,$c_2,$t_1
  1476. $MULTU ($a_3,$b_7) # mul_add_c(a[3],b[7],c2,c3,c1);
  1477. $ADDU $t_2,$at
  1478. $ADDU $c_3,$t_2
  1479. sltu $at,$c_3,$t_2
  1480. $ADDU $c_1,$at
  1481. mflo ($t_1,$a_3,$b_7)
  1482. mfhi ($t_2,$a_3,$b_7)
  1483. $ADDU $c_2,$t_1
  1484. sltu $at,$c_2,$t_1
  1485. $MULTU ($a_4,$b_7) # mul_add_c(a[4],b[7],c3,c1,c2);
  1486. $ADDU $t_2,$at
  1487. $ADDU $c_3,$t_2
  1488. sltu $at,$c_3,$t_2
  1489. $ADDU $c_1,$at
  1490. $ST $c_2,10*$BNSZ($a0) # r[10]=c2;
  1491. mflo ($t_1,$a_4,$b_7)
  1492. mfhi ($t_2,$a_4,$b_7)
  1493. $ADDU $c_3,$t_1
  1494. sltu $at,$c_3,$t_1
  1495. $MULTU ($a_5,$b_6) # mul_add_c(a[5],b[6],c3,c1,c2);
  1496. $ADDU $t_2,$at
  1497. $ADDU $c_1,$t_2
  1498. sltu $c_2,$c_1,$t_2
  1499. mflo ($t_1,$a_5,$b_6)
  1500. mfhi ($t_2,$a_5,$b_6)
  1501. $ADDU $c_3,$t_1
  1502. sltu $at,$c_3,$t_1
  1503. $MULTU ($a_6,$b_5) # mul_add_c(a[6],b[5],c3,c1,c2);
  1504. $ADDU $t_2,$at
  1505. $ADDU $c_1,$t_2
  1506. sltu $at,$c_1,$t_2
  1507. $ADDU $c_2,$at
  1508. mflo ($t_1,$a_6,$b_5)
  1509. mfhi ($t_2,$a_6,$b_5)
  1510. $ADDU $c_3,$t_1
  1511. sltu $at,$c_3,$t_1
  1512. $MULTU ($a_7,$b_4) # mul_add_c(a[7],b[4],c3,c1,c2);
  1513. $ADDU $t_2,$at
  1514. $ADDU $c_1,$t_2
  1515. sltu $at,$c_1,$t_2
  1516. $ADDU $c_2,$at
  1517. mflo ($t_1,$a_7,$b_4)
  1518. mfhi ($t_2,$a_7,$b_4)
  1519. $ADDU $c_3,$t_1
  1520. sltu $at,$c_3,$t_1
  1521. $MULTU ($a_7,$b_5) # mul_add_c(a[7],b[5],c1,c2,c3);
  1522. $ADDU $t_2,$at
  1523. $ADDU $c_1,$t_2
  1524. sltu $at,$c_1,$t_2
  1525. $ADDU $c_2,$at
  1526. $ST $c_3,11*$BNSZ($a0) # r[11]=c3;
  1527. mflo ($t_1,$a_7,$b_5)
  1528. mfhi ($t_2,$a_7,$b_5)
  1529. $ADDU $c_1,$t_1
  1530. sltu $at,$c_1,$t_1
  1531. $MULTU ($a_6,$b_6) # mul_add_c(a[6],b[6],c1,c2,c3);
  1532. $ADDU $t_2,$at
  1533. $ADDU $c_2,$t_2
  1534. sltu $c_3,$c_2,$t_2
  1535. mflo ($t_1,$a_6,$b_6)
  1536. mfhi ($t_2,$a_6,$b_6)
  1537. $ADDU $c_1,$t_1
  1538. sltu $at,$c_1,$t_1
  1539. $MULTU ($a_5,$b_7) # mul_add_c(a[5],b[7],c1,c2,c3);
  1540. $ADDU $t_2,$at
  1541. $ADDU $c_2,$t_2
  1542. sltu $at,$c_2,$t_2
  1543. $ADDU $c_3,$at
  1544. mflo ($t_1,$a_5,$b_7)
  1545. mfhi ($t_2,$a_5,$b_7)
  1546. $ADDU $c_1,$t_1
  1547. sltu $at,$c_1,$t_1
  1548. $MULTU ($a_6,$b_7) # mul_add_c(a[6],b[7],c2,c3,c1);
  1549. $ADDU $t_2,$at
  1550. $ADDU $c_2,$t_2
  1551. sltu $at,$c_2,$t_2
  1552. $ADDU $c_3,$at
  1553. $ST $c_1,12*$BNSZ($a0) # r[12]=c1;
  1554. mflo ($t_1,$a_6,$b_7)
  1555. mfhi ($t_2,$a_6,$b_7)
  1556. $ADDU $c_2,$t_1
  1557. sltu $at,$c_2,$t_1
  1558. $MULTU ($a_7,$b_6) # mul_add_c(a[7],b[6],c2,c3,c1);
  1559. $ADDU $t_2,$at
  1560. $ADDU $c_3,$t_2
  1561. sltu $c_1,$c_3,$t_2
  1562. mflo ($t_1,$a_7,$b_6)
  1563. mfhi ($t_2,$a_7,$b_6)
  1564. $ADDU $c_2,$t_1
  1565. sltu $at,$c_2,$t_1
  1566. $MULTU ($a_7,$b_7) # mul_add_c(a[7],b[7],c3,c1,c2);
  1567. $ADDU $t_2,$at
  1568. $ADDU $c_3,$t_2
  1569. sltu $at,$c_3,$t_2
  1570. $ADDU $c_1,$at
  1571. $ST $c_2,13*$BNSZ($a0) # r[13]=c2;
  1572. mflo ($t_1,$a_7,$b_7)
  1573. mfhi ($t_2,$a_7,$b_7)
  1574. $ADDU $c_3,$t_1
  1575. sltu $at,$c_3,$t_1
  1576. $ADDU $t_2,$at
  1577. $ADDU $c_1,$t_2
  1578. $ST $c_3,14*$BNSZ($a0) # r[14]=c3;
  1579. $ST $c_1,15*$BNSZ($a0) # r[15]=c1;
  1580. .set noreorder
  1581. ___
  1582. $code.=<<___ if ($flavour =~ /nubi/i);
  1583. $REG_L $s5,10*$SZREG($sp)
  1584. $REG_L $s4,9*$SZREG($sp)
  1585. $REG_L $s3,8*$SZREG($sp)
  1586. $REG_L $s2,7*$SZREG($sp)
  1587. $REG_L $s1,6*$SZREG($sp)
  1588. $REG_L $s0,5*$SZREG($sp)
  1589. $REG_L $t3,4*$SZREG($sp)
  1590. $REG_L $t2,3*$SZREG($sp)
  1591. $REG_L $t1,2*$SZREG($sp)
  1592. $REG_L $t0,1*$SZREG($sp)
  1593. $REG_L $gp,0*$SZREG($sp)
  1594. jr $ra
  1595. $PTR_ADD $sp,12*$SZREG
  1596. ___
  1597. $code.=<<___ if ($flavour !~ /nubi/i);
  1598. $REG_L $s5,5*$SZREG($sp)
  1599. $REG_L $s4,4*$SZREG($sp)
  1600. $REG_L $s3,3*$SZREG($sp)
  1601. $REG_L $s2,2*$SZREG($sp)
  1602. $REG_L $s1,1*$SZREG($sp)
  1603. $REG_L $s0,0*$SZREG($sp)
  1604. jr $ra
  1605. $PTR_ADD $sp,6*$SZREG
  1606. ___
  1607. $code.=<<___;
  1608. .end bn_mul_comba8
  1609. .align 5
  1610. .globl bn_mul_comba4
  1611. .ent bn_mul_comba4
  1612. bn_mul_comba4:
  1613. ___
  1614. $code.=<<___ if ($flavour =~ /nubi/i);
  1615. .frame $sp,6*$SZREG,$ra
  1616. .mask 0x8000f008,-$SZREG
  1617. .set noreorder
  1618. $PTR_SUB $sp,6*$SZREG
  1619. $REG_S $ra,5*$SZREG($sp)
  1620. $REG_S $t3,4*$SZREG($sp)
  1621. $REG_S $t2,3*$SZREG($sp)
  1622. $REG_S $t1,2*$SZREG($sp)
  1623. $REG_S $t0,1*$SZREG($sp)
  1624. $REG_S $gp,0*$SZREG($sp)
  1625. ___
  1626. $code.=<<___;
  1627. .set reorder
  1628. $LD $a_0,0($a1)
  1629. $LD $b_0,0($a2)
  1630. $LD $a_1,$BNSZ($a1)
  1631. $LD $a_2,2*$BNSZ($a1)
  1632. $MULTU ($a_0,$b_0) # mul_add_c(a[0],b[0],c1,c2,c3);
  1633. $LD $a_3,3*$BNSZ($a1)
  1634. $LD $b_1,$BNSZ($a2)
  1635. $LD $b_2,2*$BNSZ($a2)
  1636. $LD $b_3,3*$BNSZ($a2)
  1637. mflo ($c_1,$a_0,$b_0)
  1638. mfhi ($c_2,$a_0,$b_0)
  1639. $ST $c_1,0($a0)
  1640. $MULTU ($a_0,$b_1) # mul_add_c(a[0],b[1],c2,c3,c1);
  1641. mflo ($t_1,$a_0,$b_1)
  1642. mfhi ($t_2,$a_0,$b_1)
  1643. $ADDU $c_2,$t_1
  1644. sltu $at,$c_2,$t_1
  1645. $MULTU ($a_1,$b_0) # mul_add_c(a[1],b[0],c2,c3,c1);
  1646. $ADDU $c_3,$t_2,$at
  1647. mflo ($t_1,$a_1,$b_0)
  1648. mfhi ($t_2,$a_1,$b_0)
  1649. $ADDU $c_2,$t_1
  1650. sltu $at,$c_2,$t_1
  1651. $MULTU ($a_2,$b_0) # mul_add_c(a[2],b[0],c3,c1,c2);
  1652. $ADDU $t_2,$at
  1653. $ADDU $c_3,$t_2
  1654. sltu $c_1,$c_3,$t_2
  1655. $ST $c_2,$BNSZ($a0)
  1656. mflo ($t_1,$a_2,$b_0)
  1657. mfhi ($t_2,$a_2,$b_0)
  1658. $ADDU $c_3,$t_1
  1659. sltu $at,$c_3,$t_1
  1660. $MULTU ($a_1,$b_1) # mul_add_c(a[1],b[1],c3,c1,c2);
  1661. $ADDU $t_2,$at
  1662. $ADDU $c_1,$t_2
  1663. mflo ($t_1,$a_1,$b_1)
  1664. mfhi ($t_2,$a_1,$b_1)
  1665. $ADDU $c_3,$t_1
  1666. sltu $at,$c_3,$t_1
  1667. $MULTU ($a_0,$b_2) # mul_add_c(a[0],b[2],c3,c1,c2);
  1668. $ADDU $t_2,$at
  1669. $ADDU $c_1,$t_2
  1670. sltu $c_2,$c_1,$t_2
  1671. mflo ($t_1,$a_0,$b_2)
  1672. mfhi ($t_2,$a_0,$b_2)
  1673. $ADDU $c_3,$t_1
  1674. sltu $at,$c_3,$t_1
  1675. $MULTU ($a_0,$b_3) # mul_add_c(a[0],b[3],c1,c2,c3);
  1676. $ADDU $t_2,$at
  1677. $ADDU $c_1,$t_2
  1678. sltu $at,$c_1,$t_2
  1679. $ADDU $c_2,$at
  1680. $ST $c_3,2*$BNSZ($a0)
  1681. mflo ($t_1,$a_0,$b_3)
  1682. mfhi ($t_2,$a_0,$b_3)
  1683. $ADDU $c_1,$t_1
  1684. sltu $at,$c_1,$t_1
  1685. $MULTU ($a_1,$b_2) # mul_add_c(a[1],b[2],c1,c2,c3);
  1686. $ADDU $t_2,$at
  1687. $ADDU $c_2,$t_2
  1688. sltu $c_3,$c_2,$t_2
  1689. mflo ($t_1,$a_1,$b_2)
  1690. mfhi ($t_2,$a_1,$b_2)
  1691. $ADDU $c_1,$t_1
  1692. sltu $at,$c_1,$t_1
  1693. $MULTU ($a_2,$b_1) # mul_add_c(a[2],b[1],c1,c2,c3);
  1694. $ADDU $t_2,$at
  1695. $ADDU $c_2,$t_2
  1696. sltu $at,$c_2,$t_2
  1697. $ADDU $c_3,$at
  1698. mflo ($t_1,$a_2,$b_1)
  1699. mfhi ($t_2,$a_2,$b_1)
  1700. $ADDU $c_1,$t_1
  1701. sltu $at,$c_1,$t_1
  1702. $MULTU ($a_3,$b_0) # mul_add_c(a[3],b[0],c1,c2,c3);
  1703. $ADDU $t_2,$at
  1704. $ADDU $c_2,$t_2
  1705. sltu $at,$c_2,$t_2
  1706. $ADDU $c_3,$at
  1707. mflo ($t_1,$a_3,$b_0)
  1708. mfhi ($t_2,$a_3,$b_0)
  1709. $ADDU $c_1,$t_1
  1710. sltu $at,$c_1,$t_1
  1711. $MULTU ($a_3,$b_1) # mul_add_c(a[3],b[1],c2,c3,c1);
  1712. $ADDU $t_2,$at
  1713. $ADDU $c_2,$t_2
  1714. sltu $at,$c_2,$t_2
  1715. $ADDU $c_3,$at
  1716. $ST $c_1,3*$BNSZ($a0)
  1717. mflo ($t_1,$a_3,$b_1)
  1718. mfhi ($t_2,$a_3,$b_1)
  1719. $ADDU $c_2,$t_1
  1720. sltu $at,$c_2,$t_1
  1721. $MULTU ($a_2,$b_2) # mul_add_c(a[2],b[2],c2,c3,c1);
  1722. $ADDU $t_2,$at
  1723. $ADDU $c_3,$t_2
  1724. sltu $c_1,$c_3,$t_2
  1725. mflo ($t_1,$a_2,$b_2)
  1726. mfhi ($t_2,$a_2,$b_2)
  1727. $ADDU $c_2,$t_1
  1728. sltu $at,$c_2,$t_1
  1729. $MULTU ($a_1,$b_3) # mul_add_c(a[1],b[3],c2,c3,c1);
  1730. $ADDU $t_2,$at
  1731. $ADDU $c_3,$t_2
  1732. sltu $at,$c_3,$t_2
  1733. $ADDU $c_1,$at
  1734. mflo ($t_1,$a_1,$b_3)
  1735. mfhi ($t_2,$a_1,$b_3)
  1736. $ADDU $c_2,$t_1
  1737. sltu $at,$c_2,$t_1
  1738. $MULTU ($a_2,$b_3) # mul_add_c(a[2],b[3],c3,c1,c2);
  1739. $ADDU $t_2,$at
  1740. $ADDU $c_3,$t_2
  1741. sltu $at,$c_3,$t_2
  1742. $ADDU $c_1,$at
  1743. $ST $c_2,4*$BNSZ($a0)
  1744. mflo ($t_1,$a_2,$b_3)
  1745. mfhi ($t_2,$a_2,$b_3)
  1746. $ADDU $c_3,$t_1
  1747. sltu $at,$c_3,$t_1
  1748. $MULTU ($a_3,$b_2) # mul_add_c(a[3],b[2],c3,c1,c2);
  1749. $ADDU $t_2,$at
  1750. $ADDU $c_1,$t_2
  1751. sltu $c_2,$c_1,$t_2
  1752. mflo ($t_1,$a_3,$b_2)
  1753. mfhi ($t_2,$a_3,$b_2)
  1754. $ADDU $c_3,$t_1
  1755. sltu $at,$c_3,$t_1
  1756. $MULTU ($a_3,$b_3) # mul_add_c(a[3],b[3],c1,c2,c3);
  1757. $ADDU $t_2,$at
  1758. $ADDU $c_1,$t_2
  1759. sltu $at,$c_1,$t_2
  1760. $ADDU $c_2,$at
  1761. $ST $c_3,5*$BNSZ($a0)
  1762. mflo ($t_1,$a_3,$b_3)
  1763. mfhi ($t_2,$a_3,$b_3)
  1764. $ADDU $c_1,$t_1
  1765. sltu $at,$c_1,$t_1
  1766. $ADDU $t_2,$at
  1767. $ADDU $c_2,$t_2
  1768. $ST $c_1,6*$BNSZ($a0)
  1769. $ST $c_2,7*$BNSZ($a0)
  1770. .set noreorder
  1771. ___
  1772. $code.=<<___ if ($flavour =~ /nubi/i);
  1773. $REG_L $t3,4*$SZREG($sp)
  1774. $REG_L $t2,3*$SZREG($sp)
  1775. $REG_L $t1,2*$SZREG($sp)
  1776. $REG_L $t0,1*$SZREG($sp)
  1777. $REG_L $gp,0*$SZREG($sp)
  1778. $PTR_ADD $sp,6*$SZREG
  1779. ___
  1780. $code.=<<___;
  1781. jr $ra
  1782. nop
  1783. .end bn_mul_comba4
  1784. ___
  1785. ($a_4,$a_5,$a_6,$a_7)=($b_0,$b_1,$b_2,$b_3);
  1786. sub add_c2 () {
  1787. my ($hi,$lo,$c0,$c1,$c2,
  1788. $warm, # !$warm denotes first call with specific sequence of
  1789. # $c_[XYZ] when there is no Z-carry to accumulate yet;
  1790. $an,$bn # these two are arguments for multiplication which
  1791. # result is used in *next* step [which is why it's
  1792. # commented as "forward multiplication" below];
  1793. )=@_;
  1794. $code.=<<___;
  1795. $ADDU $c0,$lo
  1796. sltu $at,$c0,$lo
  1797. $MULTU ($an,$bn) # forward multiplication
  1798. $ADDU $c0,$lo
  1799. $ADDU $at,$hi
  1800. sltu $lo,$c0,$lo
  1801. $ADDU $c1,$at
  1802. $ADDU $hi,$lo
  1803. ___
  1804. $code.=<<___ if (!$warm);
  1805. sltu $c2,$c1,$at
  1806. $ADDU $c1,$hi
  1807. ___
  1808. $code.=<<___ if ($warm);
  1809. sltu $at,$c1,$at
  1810. $ADDU $c1,$hi
  1811. $ADDU $c2,$at
  1812. ___
  1813. $code.=<<___;
  1814. sltu $hi,$c1,$hi
  1815. $ADDU $c2,$hi
  1816. mflo ($lo,$an,$bn)
  1817. mfhi ($hi,$an,$bn)
  1818. ___
  1819. }
  1820. $code.=<<___;
  1821. .align 5
  1822. .globl bn_sqr_comba8
  1823. .ent bn_sqr_comba8
  1824. bn_sqr_comba8:
  1825. ___
  1826. $code.=<<___ if ($flavour =~ /nubi/i);
  1827. .frame $sp,6*$SZREG,$ra
  1828. .mask 0x8000f008,-$SZREG
  1829. .set noreorder
  1830. $PTR_SUB $sp,6*$SZREG
  1831. $REG_S $ra,5*$SZREG($sp)
  1832. $REG_S $t3,4*$SZREG($sp)
  1833. $REG_S $t2,3*$SZREG($sp)
  1834. $REG_S $t1,2*$SZREG($sp)
  1835. $REG_S $t0,1*$SZREG($sp)
  1836. $REG_S $gp,0*$SZREG($sp)
  1837. ___
  1838. $code.=<<___;
  1839. .set reorder
  1840. $LD $a_0,0($a1)
  1841. $LD $a_1,$BNSZ($a1)
  1842. $LD $a_2,2*$BNSZ($a1)
  1843. $LD $a_3,3*$BNSZ($a1)
  1844. $MULTU ($a_0,$a_0) # mul_add_c(a[0],b[0],c1,c2,c3);
  1845. $LD $a_4,4*$BNSZ($a1)
  1846. $LD $a_5,5*$BNSZ($a1)
  1847. $LD $a_6,6*$BNSZ($a1)
  1848. $LD $a_7,7*$BNSZ($a1)
  1849. mflo ($c_1,$a_0,$a_0)
  1850. mfhi ($c_2,$a_0,$a_0)
  1851. $ST $c_1,0($a0)
  1852. $MULTU ($a_0,$a_1) # mul_add_c2(a[0],b[1],c2,c3,c1);
  1853. mflo ($t_1,$a_0,$a_1)
  1854. mfhi ($t_2,$a_0,$a_1)
  1855. slt $c_1,$t_2,$zero
  1856. $SLL $t_2,1
  1857. $MULTU ($a_2,$a_0) # mul_add_c2(a[2],b[0],c3,c1,c2);
  1858. slt $a2,$t_1,$zero
  1859. $ADDU $t_2,$a2
  1860. $SLL $t_1,1
  1861. $ADDU $c_2,$t_1
  1862. sltu $at,$c_2,$t_1
  1863. $ADDU $c_3,$t_2,$at
  1864. $ST $c_2,$BNSZ($a0)
  1865. mflo ($t_1,$a_2,$a_0)
  1866. mfhi ($t_2,$a_2,$a_0)
  1867. ___
  1868. &add_c2($t_2,$t_1,$c_3,$c_1,$c_2,0,
  1869. $a_1,$a_1); # mul_add_c(a[1],b[1],c3,c1,c2);
  1870. $code.=<<___;
  1871. $ADDU $c_3,$t_1
  1872. sltu $at,$c_3,$t_1
  1873. $MULTU ($a_0,$a_3) # mul_add_c2(a[0],b[3],c1,c2,c3);
  1874. $ADDU $t_2,$at
  1875. $ADDU $c_1,$t_2
  1876. sltu $at,$c_1,$t_2
  1877. $ADDU $c_2,$at
  1878. $ST $c_3,2*$BNSZ($a0)
  1879. mflo ($t_1,$a_0,$a_3)
  1880. mfhi ($t_2,$a_0,$a_3)
  1881. ___
  1882. &add_c2($t_2,$t_1,$c_1,$c_2,$c_3,0,
  1883. $a_1,$a_2); # mul_add_c2(a[1],b[2],c1,c2,c3);
  1884. &add_c2($t_2,$t_1,$c_1,$c_2,$c_3,1,
  1885. $a_4,$a_0); # mul_add_c2(a[4],b[0],c2,c3,c1);
  1886. $code.=<<___;
  1887. $ST $c_1,3*$BNSZ($a0)
  1888. ___
  1889. &add_c2($t_2,$t_1,$c_2,$c_3,$c_1,0,
  1890. $a_3,$a_1); # mul_add_c2(a[3],b[1],c2,c3,c1);
  1891. &add_c2($t_2,$t_1,$c_2,$c_3,$c_1,1,
  1892. $a_2,$a_2); # mul_add_c(a[2],b[2],c2,c3,c1);
  1893. $code.=<<___;
  1894. $ADDU $c_2,$t_1
  1895. sltu $at,$c_2,$t_1
  1896. $MULTU ($a_0,$a_5) # mul_add_c2(a[0],b[5],c3,c1,c2);
  1897. $ADDU $t_2,$at
  1898. $ADDU $c_3,$t_2
  1899. sltu $at,$c_3,$t_2
  1900. $ADDU $c_1,$at
  1901. $ST $c_2,4*$BNSZ($a0)
  1902. mflo ($t_1,$a_0,$a_5)
  1903. mfhi ($t_2,$a_0,$a_5)
  1904. ___
  1905. &add_c2($t_2,$t_1,$c_3,$c_1,$c_2,0,
  1906. $a_1,$a_4); # mul_add_c2(a[1],b[4],c3,c1,c2);
  1907. &add_c2($t_2,$t_1,$c_3,$c_1,$c_2,1,
  1908. $a_2,$a_3); # mul_add_c2(a[2],b[3],c3,c1,c2);
  1909. &add_c2($t_2,$t_1,$c_3,$c_1,$c_2,1,
  1910. $a_6,$a_0); # mul_add_c2(a[6],b[0],c1,c2,c3);
  1911. $code.=<<___;
  1912. $ST $c_3,5*$BNSZ($a0)
  1913. ___
  1914. &add_c2($t_2,$t_1,$c_1,$c_2,$c_3,0,
  1915. $a_5,$a_1); # mul_add_c2(a[5],b[1],c1,c2,c3);
  1916. &add_c2($t_2,$t_1,$c_1,$c_2,$c_3,1,
  1917. $a_4,$a_2); # mul_add_c2(a[4],b[2],c1,c2,c3);
  1918. &add_c2($t_2,$t_1,$c_1,$c_2,$c_3,1,
  1919. $a_3,$a_3); # mul_add_c(a[3],b[3],c1,c2,c3);
  1920. $code.=<<___;
  1921. $ADDU $c_1,$t_1
  1922. sltu $at,$c_1,$t_1
  1923. $MULTU ($a_0,$a_7) # mul_add_c2(a[0],b[7],c2,c3,c1);
  1924. $ADDU $t_2,$at
  1925. $ADDU $c_2,$t_2
  1926. sltu $at,$c_2,$t_2
  1927. $ADDU $c_3,$at
  1928. $ST $c_1,6*$BNSZ($a0)
  1929. mflo ($t_1,$a_0,$a_7)
  1930. mfhi ($t_2,$a_0,$a_7)
  1931. ___
  1932. &add_c2($t_2,$t_1,$c_2,$c_3,$c_1,0,
  1933. $a_1,$a_6); # mul_add_c2(a[1],b[6],c2,c3,c1);
  1934. &add_c2($t_2,$t_1,$c_2,$c_3,$c_1,1,
  1935. $a_2,$a_5); # mul_add_c2(a[2],b[5],c2,c3,c1);
  1936. &add_c2($t_2,$t_1,$c_2,$c_3,$c_1,1,
  1937. $a_3,$a_4); # mul_add_c2(a[3],b[4],c2,c3,c1);
  1938. &add_c2($t_2,$t_1,$c_2,$c_3,$c_1,1,
  1939. $a_7,$a_1); # mul_add_c2(a[7],b[1],c3,c1,c2);
  1940. $code.=<<___;
  1941. $ST $c_2,7*$BNSZ($a0)
  1942. ___
  1943. &add_c2($t_2,$t_1,$c_3,$c_1,$c_2,0,
  1944. $a_6,$a_2); # mul_add_c2(a[6],b[2],c3,c1,c2);
  1945. &add_c2($t_2,$t_1,$c_3,$c_1,$c_2,1,
  1946. $a_5,$a_3); # mul_add_c2(a[5],b[3],c3,c1,c2);
  1947. &add_c2($t_2,$t_1,$c_3,$c_1,$c_2,1,
  1948. $a_4,$a_4); # mul_add_c(a[4],b[4],c3,c1,c2);
  1949. $code.=<<___;
  1950. $ADDU $c_3,$t_1
  1951. sltu $at,$c_3,$t_1
  1952. $MULTU ($a_2,$a_7) # mul_add_c2(a[2],b[7],c1,c2,c3);
  1953. $ADDU $t_2,$at
  1954. $ADDU $c_1,$t_2
  1955. sltu $at,$c_1,$t_2
  1956. $ADDU $c_2,$at
  1957. $ST $c_3,8*$BNSZ($a0)
  1958. mflo ($t_1,$a_2,$a_7)
  1959. mfhi ($t_2,$a_2,$a_7)
  1960. ___
  1961. &add_c2($t_2,$t_1,$c_1,$c_2,$c_3,0,
  1962. $a_3,$a_6); # mul_add_c2(a[3],b[6],c1,c2,c3);
  1963. &add_c2($t_2,$t_1,$c_1,$c_2,$c_3,1,
  1964. $a_4,$a_5); # mul_add_c2(a[4],b[5],c1,c2,c3);
  1965. &add_c2($t_2,$t_1,$c_1,$c_2,$c_3,1,
  1966. $a_7,$a_3); # mul_add_c2(a[7],b[3],c2,c3,c1);
  1967. $code.=<<___;
  1968. $ST $c_1,9*$BNSZ($a0)
  1969. ___
  1970. &add_c2($t_2,$t_1,$c_2,$c_3,$c_1,0,
  1971. $a_6,$a_4); # mul_add_c2(a[6],b[4],c2,c3,c1);
  1972. &add_c2($t_2,$t_1,$c_2,$c_3,$c_1,1,
  1973. $a_5,$a_5); # mul_add_c(a[5],b[5],c2,c3,c1);
  1974. $code.=<<___;
  1975. $ADDU $c_2,$t_1
  1976. sltu $at,$c_2,$t_1
  1977. $MULTU ($a_4,$a_7) # mul_add_c2(a[4],b[7],c3,c1,c2);
  1978. $ADDU $t_2,$at
  1979. $ADDU $c_3,$t_2
  1980. sltu $at,$c_3,$t_2
  1981. $ADDU $c_1,$at
  1982. $ST $c_2,10*$BNSZ($a0)
  1983. mflo ($t_1,$a_4,$a_7)
  1984. mfhi ($t_2,$a_4,$a_7)
  1985. ___
  1986. &add_c2($t_2,$t_1,$c_3,$c_1,$c_2,0,
  1987. $a_5,$a_6); # mul_add_c2(a[5],b[6],c3,c1,c2);
  1988. &add_c2($t_2,$t_1,$c_3,$c_1,$c_2,1,
  1989. $a_7,$a_5); # mul_add_c2(a[7],b[5],c1,c2,c3);
  1990. $code.=<<___;
  1991. $ST $c_3,11*$BNSZ($a0)
  1992. ___
  1993. &add_c2($t_2,$t_1,$c_1,$c_2,$c_3,0,
  1994. $a_6,$a_6); # mul_add_c(a[6],b[6],c1,c2,c3);
  1995. $code.=<<___;
  1996. $ADDU $c_1,$t_1
  1997. sltu $at,$c_1,$t_1
  1998. $MULTU ($a_6,$a_7) # mul_add_c2(a[6],b[7],c2,c3,c1);
  1999. $ADDU $t_2,$at
  2000. $ADDU $c_2,$t_2
  2001. sltu $at,$c_2,$t_2
  2002. $ADDU $c_3,$at
  2003. $ST $c_1,12*$BNSZ($a0)
  2004. mflo ($t_1,$a_6,$a_7)
  2005. mfhi ($t_2,$a_6,$a_7)
  2006. ___
  2007. &add_c2($t_2,$t_1,$c_2,$c_3,$c_1,0,
  2008. $a_7,$a_7); # mul_add_c(a[7],b[7],c3,c1,c2);
  2009. $code.=<<___;
  2010. $ST $c_2,13*$BNSZ($a0)
  2011. $ADDU $c_3,$t_1
  2012. sltu $at,$c_3,$t_1
  2013. $ADDU $t_2,$at
  2014. $ADDU $c_1,$t_2
  2015. $ST $c_3,14*$BNSZ($a0)
  2016. $ST $c_1,15*$BNSZ($a0)
  2017. .set noreorder
  2018. ___
  2019. $code.=<<___ if ($flavour =~ /nubi/i);
  2020. $REG_L $t3,4*$SZREG($sp)
  2021. $REG_L $t2,3*$SZREG($sp)
  2022. $REG_L $t1,2*$SZREG($sp)
  2023. $REG_L $t0,1*$SZREG($sp)
  2024. $REG_L $gp,0*$SZREG($sp)
  2025. $PTR_ADD $sp,6*$SZREG
  2026. ___
  2027. $code.=<<___;
  2028. jr $ra
  2029. nop
  2030. .end bn_sqr_comba8
  2031. .align 5
  2032. .globl bn_sqr_comba4
  2033. .ent bn_sqr_comba4
  2034. bn_sqr_comba4:
  2035. ___
  2036. $code.=<<___ if ($flavour =~ /nubi/i);
  2037. .frame $sp,6*$SZREG,$ra
  2038. .mask 0x8000f008,-$SZREG
  2039. .set noreorder
  2040. $PTR_SUB $sp,6*$SZREG
  2041. $REG_S $ra,5*$SZREG($sp)
  2042. $REG_S $t3,4*$SZREG($sp)
  2043. $REG_S $t2,3*$SZREG($sp)
  2044. $REG_S $t1,2*$SZREG($sp)
  2045. $REG_S $t0,1*$SZREG($sp)
  2046. $REG_S $gp,0*$SZREG($sp)
  2047. ___
  2048. $code.=<<___;
  2049. .set reorder
  2050. $LD $a_0,0($a1)
  2051. $LD $a_1,$BNSZ($a1)
  2052. $MULTU ($a_0,$a_0) # mul_add_c(a[0],b[0],c1,c2,c3);
  2053. $LD $a_2,2*$BNSZ($a1)
  2054. $LD $a_3,3*$BNSZ($a1)
  2055. mflo ($c_1,$a_0,$a_0)
  2056. mfhi ($c_2,$a_0,$a_0)
  2057. $ST $c_1,0($a0)
  2058. $MULTU ($a_0,$a_1) # mul_add_c2(a[0],b[1],c2,c3,c1);
  2059. mflo ($t_1,$a_0,$a_1)
  2060. mfhi ($t_2,$a_0,$a_1)
  2061. slt $c_1,$t_2,$zero
  2062. $SLL $t_2,1
  2063. $MULTU ($a_2,$a_0) # mul_add_c2(a[2],b[0],c3,c1,c2);
  2064. slt $a2,$t_1,$zero
  2065. $ADDU $t_2,$a2
  2066. $SLL $t_1,1
  2067. $ADDU $c_2,$t_1
  2068. sltu $at,$c_2,$t_1
  2069. $ADDU $c_3,$t_2,$at
  2070. $ST $c_2,$BNSZ($a0)
  2071. mflo ($t_1,$a_2,$a_0)
  2072. mfhi ($t_2,$a_2,$a_0)
  2073. ___
  2074. &add_c2($t_2,$t_1,$c_3,$c_1,$c_2,0,
  2075. $a_1,$a_1); # mul_add_c(a[1],b[1],c3,c1,c2);
  2076. $code.=<<___;
  2077. $ADDU $c_3,$t_1
  2078. sltu $at,$c_3,$t_1
  2079. $MULTU ($a_0,$a_3) # mul_add_c2(a[0],b[3],c1,c2,c3);
  2080. $ADDU $t_2,$at
  2081. $ADDU $c_1,$t_2
  2082. sltu $at,$c_1,$t_2
  2083. $ADDU $c_2,$at
  2084. $ST $c_3,2*$BNSZ($a0)
  2085. mflo ($t_1,$a_0,$a_3)
  2086. mfhi ($t_2,$a_0,$a_3)
  2087. ___
  2088. &add_c2($t_2,$t_1,$c_1,$c_2,$c_3,0,
  2089. $a_1,$a_2); # mul_add_c2(a2[1],b[2],c1,c2,c3);
  2090. &add_c2($t_2,$t_1,$c_1,$c_2,$c_3,1,
  2091. $a_3,$a_1); # mul_add_c2(a[3],b[1],c2,c3,c1);
  2092. $code.=<<___;
  2093. $ST $c_1,3*$BNSZ($a0)
  2094. ___
  2095. &add_c2($t_2,$t_1,$c_2,$c_3,$c_1,0,
  2096. $a_2,$a_2); # mul_add_c(a[2],b[2],c2,c3,c1);
  2097. $code.=<<___;
  2098. $ADDU $c_2,$t_1
  2099. sltu $at,$c_2,$t_1
  2100. $MULTU ($a_2,$a_3) # mul_add_c2(a[2],b[3],c3,c1,c2);
  2101. $ADDU $t_2,$at
  2102. $ADDU $c_3,$t_2
  2103. sltu $at,$c_3,$t_2
  2104. $ADDU $c_1,$at
  2105. $ST $c_2,4*$BNSZ($a0)
  2106. mflo ($t_1,$a_2,$a_3)
  2107. mfhi ($t_2,$a_2,$a_3)
  2108. ___
  2109. &add_c2($t_2,$t_1,$c_3,$c_1,$c_2,0,
  2110. $a_3,$a_3); # mul_add_c(a[3],b[3],c1,c2,c3);
  2111. $code.=<<___;
  2112. $ST $c_3,5*$BNSZ($a0)
  2113. $ADDU $c_1,$t_1
  2114. sltu $at,$c_1,$t_1
  2115. $ADDU $t_2,$at
  2116. $ADDU $c_2,$t_2
  2117. $ST $c_1,6*$BNSZ($a0)
  2118. $ST $c_2,7*$BNSZ($a0)
  2119. .set noreorder
  2120. ___
  2121. $code.=<<___ if ($flavour =~ /nubi/i);
  2122. $REG_L $t3,4*$SZREG($sp)
  2123. $REG_L $t2,3*$SZREG($sp)
  2124. $REG_L $t1,2*$SZREG($sp)
  2125. $REG_L $t0,1*$SZREG($sp)
  2126. $REG_L $gp,0*$SZREG($sp)
  2127. $PTR_ADD $sp,6*$SZREG
  2128. ___
  2129. $code.=<<___;
  2130. jr $ra
  2131. nop
  2132. .end bn_sqr_comba4
  2133. ___
  2134. print $code;
  2135. close STDOUT or die "error closing STDOUT: $!";