mips.pl 48 KB

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