2
0

mips.pl 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257
  1. #! /usr/bin/env perl
  2. # Copyright 2010-2016 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=".set mips2\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. .align 5
  725. .globl bn_div_3_words
  726. .ent bn_div_3_words
  727. bn_div_3_words:
  728. .set noreorder
  729. move $a3,$a0 # we know that bn_div_words does not
  730. # touch $a3, $ta2, $ta3 and preserves $a2
  731. # so that we can save two arguments
  732. # and return address in registers
  733. # instead of stack:-)
  734. $LD $a0,($a3)
  735. move $ta2,$a1
  736. bne $a0,$a2,bn_div_3_words_internal
  737. $LD $a1,-$BNSZ($a3)
  738. li $v0,-1
  739. jr $ra
  740. move $a0,$v0
  741. .end bn_div_3_words
  742. .align 5
  743. .ent bn_div_3_words_internal
  744. bn_div_3_words_internal:
  745. ___
  746. $code.=<<___ if ($flavour =~ /nubi/i);
  747. .frame $sp,6*$SZREG,$ra
  748. .mask 0x8000f008,-$SZREG
  749. .set noreorder
  750. $PTR_SUB $sp,6*$SZREG
  751. $REG_S $ra,5*$SZREG($sp)
  752. $REG_S $t3,4*$SZREG($sp)
  753. $REG_S $t2,3*$SZREG($sp)
  754. $REG_S $t1,2*$SZREG($sp)
  755. $REG_S $t0,1*$SZREG($sp)
  756. $REG_S $gp,0*$SZREG($sp)
  757. ___
  758. $code.=<<___;
  759. .set reorder
  760. move $ta3,$ra
  761. bal bn_div_words_internal
  762. move $ra,$ta3
  763. $MULTU ($ta2,$v0)
  764. $LD $t2,-2*$BNSZ($a3)
  765. move $ta0,$zero
  766. mfhi ($t1,$ta2,$v0)
  767. mflo ($t0,$ta2,$v0)
  768. sltu $t8,$t1,$a1
  769. .L_bn_div_3_words_inner_loop:
  770. bnez $t8,.L_bn_div_3_words_inner_loop_done
  771. sgeu $at,$t2,$t0
  772. seq $t9,$t1,$a1
  773. and $at,$t9
  774. sltu $t3,$t0,$ta2
  775. $ADDU $a1,$a2
  776. $SUBU $t1,$t3
  777. $SUBU $t0,$ta2
  778. sltu $t8,$t1,$a1
  779. sltu $ta0,$a1,$a2
  780. or $t8,$ta0
  781. .set noreorder
  782. beqz $at,.L_bn_div_3_words_inner_loop
  783. $SUBU $v0,1
  784. $ADDU $v0,1
  785. .set reorder
  786. .L_bn_div_3_words_inner_loop_done:
  787. .set noreorder
  788. ___
  789. $code.=<<___ if ($flavour =~ /nubi/i);
  790. $REG_L $t3,4*$SZREG($sp)
  791. $REG_L $t2,3*$SZREG($sp)
  792. $REG_L $t1,2*$SZREG($sp)
  793. $REG_L $t0,1*$SZREG($sp)
  794. $REG_L $gp,0*$SZREG($sp)
  795. $PTR_ADD $sp,6*$SZREG
  796. ___
  797. $code.=<<___;
  798. jr $ra
  799. move $a0,$v0
  800. .end bn_div_3_words_internal
  801. .align 5
  802. .globl bn_div_words
  803. .ent bn_div_words
  804. bn_div_words:
  805. .set noreorder
  806. bnez $a2,bn_div_words_internal
  807. li $v0,-1 # I would rather signal div-by-zero
  808. # which can be done with 'break 7'
  809. jr $ra
  810. move $a0,$v0
  811. .end bn_div_words
  812. .align 5
  813. .ent bn_div_words_internal
  814. bn_div_words_internal:
  815. ___
  816. $code.=<<___ if ($flavour =~ /nubi/i);
  817. .frame $sp,6*$SZREG,$ra
  818. .mask 0x8000f008,-$SZREG
  819. .set noreorder
  820. $PTR_SUB $sp,6*$SZREG
  821. $REG_S $ra,5*$SZREG($sp)
  822. $REG_S $t3,4*$SZREG($sp)
  823. $REG_S $t2,3*$SZREG($sp)
  824. $REG_S $t1,2*$SZREG($sp)
  825. $REG_S $t0,1*$SZREG($sp)
  826. $REG_S $gp,0*$SZREG($sp)
  827. ___
  828. $code.=<<___;
  829. move $v1,$zero
  830. bltz $a2,.L_bn_div_words_body
  831. move $t9,$v1
  832. $SLL $a2,1
  833. bgtz $a2,.-4
  834. addu $t9,1
  835. .set reorder
  836. negu $t1,$t9
  837. li $t2,-1
  838. $SLL $t2,$t1
  839. and $t2,$a0
  840. $SRL $at,$a1,$t1
  841. .set noreorder
  842. beqz $t2,.+12
  843. nop
  844. break 6 # signal overflow
  845. .set reorder
  846. $SLL $a0,$t9
  847. $SLL $a1,$t9
  848. or $a0,$at
  849. ___
  850. $QT=$ta0;
  851. $HH=$ta1;
  852. $DH=$v1;
  853. $code.=<<___;
  854. .L_bn_div_words_body:
  855. $SRL $DH,$a2,4*$BNSZ # bits
  856. sgeu $at,$a0,$a2
  857. .set noreorder
  858. beqz $at,.+12
  859. nop
  860. $SUBU $a0,$a2
  861. .set reorder
  862. li $QT,-1
  863. $SRL $HH,$a0,4*$BNSZ # bits
  864. $SRL $QT,4*$BNSZ # q=0xffffffff
  865. beq $DH,$HH,.L_bn_div_words_skip_div1
  866. $DIVU ($a0,$DH)
  867. mfqt ($QT,$a0,$DH)
  868. .L_bn_div_words_skip_div1:
  869. $MULTU ($a2,$QT)
  870. $SLL $t3,$a0,4*$BNSZ # bits
  871. $SRL $at,$a1,4*$BNSZ # bits
  872. or $t3,$at
  873. mflo ($t0,$a2,$QT)
  874. mfhi ($t1,$a2,$QT)
  875. .L_bn_div_words_inner_loop1:
  876. sltu $t2,$t3,$t0
  877. seq $t8,$HH,$t1
  878. sltu $at,$HH,$t1
  879. and $t2,$t8
  880. sltu $v0,$t0,$a2
  881. or $at,$t2
  882. .set noreorder
  883. beqz $at,.L_bn_div_words_inner_loop1_done
  884. $SUBU $t1,$v0
  885. $SUBU $t0,$a2
  886. b .L_bn_div_words_inner_loop1
  887. $SUBU $QT,1
  888. .set reorder
  889. .L_bn_div_words_inner_loop1_done:
  890. $SLL $a1,4*$BNSZ # bits
  891. $SUBU $a0,$t3,$t0
  892. $SLL $v0,$QT,4*$BNSZ # bits
  893. li $QT,-1
  894. $SRL $HH,$a0,4*$BNSZ # bits
  895. $SRL $QT,4*$BNSZ # q=0xffffffff
  896. beq $DH,$HH,.L_bn_div_words_skip_div2
  897. $DIVU ($a0,$DH)
  898. mfqt ($QT,$a0,$DH)
  899. .L_bn_div_words_skip_div2:
  900. $MULTU ($a2,$QT)
  901. $SLL $t3,$a0,4*$BNSZ # bits
  902. $SRL $at,$a1,4*$BNSZ # bits
  903. or $t3,$at
  904. mflo ($t0,$a2,$QT)
  905. mfhi ($t1,$a2,$QT)
  906. .L_bn_div_words_inner_loop2:
  907. sltu $t2,$t3,$t0
  908. seq $t8,$HH,$t1
  909. sltu $at,$HH,$t1
  910. and $t2,$t8
  911. sltu $v1,$t0,$a2
  912. or $at,$t2
  913. .set noreorder
  914. beqz $at,.L_bn_div_words_inner_loop2_done
  915. $SUBU $t1,$v1
  916. $SUBU $t0,$a2
  917. b .L_bn_div_words_inner_loop2
  918. $SUBU $QT,1
  919. .set reorder
  920. .L_bn_div_words_inner_loop2_done:
  921. $SUBU $a0,$t3,$t0
  922. or $v0,$QT
  923. $SRL $v1,$a0,$t9 # $v1 contains remainder if anybody wants it
  924. $SRL $a2,$t9 # restore $a2
  925. .set noreorder
  926. move $a1,$v1
  927. ___
  928. $code.=<<___ if ($flavour =~ /nubi/i);
  929. $REG_L $t3,4*$SZREG($sp)
  930. $REG_L $t2,3*$SZREG($sp)
  931. $REG_L $t1,2*$SZREG($sp)
  932. $REG_L $t0,1*$SZREG($sp)
  933. $REG_L $gp,0*$SZREG($sp)
  934. $PTR_ADD $sp,6*$SZREG
  935. ___
  936. $code.=<<___;
  937. jr $ra
  938. move $a0,$v0
  939. .end bn_div_words_internal
  940. ___
  941. undef $HH; undef $QT; undef $DH;
  942. ($a_0,$a_1,$a_2,$a_3)=($t0,$t1,$t2,$t3);
  943. ($b_0,$b_1,$b_2,$b_3)=($ta0,$ta1,$ta2,$ta3);
  944. ($a_4,$a_5,$a_6,$a_7)=($s0,$s2,$s4,$a1); # once we load a[7], no use for $a1
  945. ($b_4,$b_5,$b_6,$b_7)=($s1,$s3,$s5,$a2); # once we load b[7], no use for $a2
  946. ($t_1,$t_2,$c_1,$c_2,$c_3)=($t8,$t9,$v0,$v1,$a3);
  947. $code.=<<___;
  948. .align 5
  949. .globl bn_mul_comba8
  950. .ent bn_mul_comba8
  951. bn_mul_comba8:
  952. .set noreorder
  953. ___
  954. $code.=<<___ if ($flavour =~ /nubi/i);
  955. .frame $sp,12*$SZREG,$ra
  956. .mask 0x803ff008,-$SZREG
  957. $PTR_SUB $sp,12*$SZREG
  958. $REG_S $ra,11*$SZREG($sp)
  959. $REG_S $s5,10*$SZREG($sp)
  960. $REG_S $s4,9*$SZREG($sp)
  961. $REG_S $s3,8*$SZREG($sp)
  962. $REG_S $s2,7*$SZREG($sp)
  963. $REG_S $s1,6*$SZREG($sp)
  964. $REG_S $s0,5*$SZREG($sp)
  965. $REG_S $t3,4*$SZREG($sp)
  966. $REG_S $t2,3*$SZREG($sp)
  967. $REG_S $t1,2*$SZREG($sp)
  968. $REG_S $t0,1*$SZREG($sp)
  969. $REG_S $gp,0*$SZREG($sp)
  970. ___
  971. $code.=<<___ if ($flavour !~ /nubi/i);
  972. .frame $sp,6*$SZREG,$ra
  973. .mask 0x003f0000,-$SZREG
  974. $PTR_SUB $sp,6*$SZREG
  975. $REG_S $s5,5*$SZREG($sp)
  976. $REG_S $s4,4*$SZREG($sp)
  977. $REG_S $s3,3*$SZREG($sp)
  978. $REG_S $s2,2*$SZREG($sp)
  979. $REG_S $s1,1*$SZREG($sp)
  980. $REG_S $s0,0*$SZREG($sp)
  981. ___
  982. $code.=<<___;
  983. .set reorder
  984. $LD $a_0,0($a1) # If compiled with -mips3 option on
  985. # R5000 box assembler barks on this
  986. # 1ine with "should not have mult/div
  987. # as last instruction in bb (R10K
  988. # bug)" warning. If anybody out there
  989. # has a clue about how to circumvent
  990. # this do send me a note.
  991. # <appro\@fy.chalmers.se>
  992. $LD $b_0,0($a2)
  993. $LD $a_1,$BNSZ($a1)
  994. $LD $a_2,2*$BNSZ($a1)
  995. $MULTU ($a_0,$b_0) # mul_add_c(a[0],b[0],c1,c2,c3);
  996. $LD $a_3,3*$BNSZ($a1)
  997. $LD $b_1,$BNSZ($a2)
  998. $LD $b_2,2*$BNSZ($a2)
  999. $LD $b_3,3*$BNSZ($a2)
  1000. mflo ($c_1,$a_0,$b_0)
  1001. mfhi ($c_2,$a_0,$b_0)
  1002. $LD $a_4,4*$BNSZ($a1)
  1003. $LD $a_5,5*$BNSZ($a1)
  1004. $MULTU ($a_0,$b_1) # mul_add_c(a[0],b[1],c2,c3,c1);
  1005. $LD $a_6,6*$BNSZ($a1)
  1006. $LD $a_7,7*$BNSZ($a1)
  1007. $LD $b_4,4*$BNSZ($a2)
  1008. $LD $b_5,5*$BNSZ($a2)
  1009. mflo ($t_1,$a_0,$b_1)
  1010. mfhi ($t_2,$a_0,$b_1)
  1011. $ADDU $c_2,$t_1
  1012. sltu $at,$c_2,$t_1
  1013. $MULTU ($a_1,$b_0) # mul_add_c(a[1],b[0],c2,c3,c1);
  1014. $ADDU $c_3,$t_2,$at
  1015. $LD $b_6,6*$BNSZ($a2)
  1016. $LD $b_7,7*$BNSZ($a2)
  1017. $ST $c_1,0($a0) # r[0]=c1;
  1018. mflo ($t_1,$a_1,$b_0)
  1019. mfhi ($t_2,$a_1,$b_0)
  1020. $ADDU $c_2,$t_1
  1021. sltu $at,$c_2,$t_1
  1022. $MULTU ($a_2,$b_0) # mul_add_c(a[2],b[0],c3,c1,c2);
  1023. $ADDU $t_2,$at
  1024. $ADDU $c_3,$t_2
  1025. sltu $c_1,$c_3,$t_2
  1026. $ST $c_2,$BNSZ($a0) # r[1]=c2;
  1027. mflo ($t_1,$a_2,$b_0)
  1028. mfhi ($t_2,$a_2,$b_0)
  1029. $ADDU $c_3,$t_1
  1030. sltu $at,$c_3,$t_1
  1031. $MULTU ($a_1,$b_1) # mul_add_c(a[1],b[1],c3,c1,c2);
  1032. $ADDU $t_2,$at
  1033. $ADDU $c_1,$t_2
  1034. mflo ($t_1,$a_1,$b_1)
  1035. mfhi ($t_2,$a_1,$b_1)
  1036. $ADDU $c_3,$t_1
  1037. sltu $at,$c_3,$t_1
  1038. $MULTU ($a_0,$b_2) # mul_add_c(a[0],b[2],c3,c1,c2);
  1039. $ADDU $t_2,$at
  1040. $ADDU $c_1,$t_2
  1041. sltu $c_2,$c_1,$t_2
  1042. mflo ($t_1,$a_0,$b_2)
  1043. mfhi ($t_2,$a_0,$b_2)
  1044. $ADDU $c_3,$t_1
  1045. sltu $at,$c_3,$t_1
  1046. $MULTU ($a_0,$b_3) # mul_add_c(a[0],b[3],c1,c2,c3);
  1047. $ADDU $t_2,$at
  1048. $ADDU $c_1,$t_2
  1049. sltu $at,$c_1,$t_2
  1050. $ADDU $c_2,$at
  1051. $ST $c_3,2*$BNSZ($a0) # r[2]=c3;
  1052. mflo ($t_1,$a_0,$b_3)
  1053. mfhi ($t_2,$a_0,$b_3)
  1054. $ADDU $c_1,$t_1
  1055. sltu $at,$c_1,$t_1
  1056. $MULTU ($a_1,$b_2) # mul_add_c(a[1],b[2],c1,c2,c3);
  1057. $ADDU $t_2,$at
  1058. $ADDU $c_2,$t_2
  1059. sltu $c_3,$c_2,$t_2
  1060. mflo ($t_1,$a_1,$b_2)
  1061. mfhi ($t_2,$a_1,$b_2)
  1062. $ADDU $c_1,$t_1
  1063. sltu $at,$c_1,$t_1
  1064. $MULTU ($a_2,$b_1) # mul_add_c(a[2],b[1],c1,c2,c3);
  1065. $ADDU $t_2,$at
  1066. $ADDU $c_2,$t_2
  1067. sltu $at,$c_2,$t_2
  1068. $ADDU $c_3,$at
  1069. mflo ($t_1,$a_2,$b_1)
  1070. mfhi ($t_2,$a_2,$b_1)
  1071. $ADDU $c_1,$t_1
  1072. sltu $at,$c_1,$t_1
  1073. $MULTU ($a_3,$b_0) # mul_add_c(a[3],b[0],c1,c2,c3);
  1074. $ADDU $t_2,$at
  1075. $ADDU $c_2,$t_2
  1076. sltu $at,$c_2,$t_2
  1077. $ADDU $c_3,$at
  1078. mflo ($t_1,$a_3,$b_0)
  1079. mfhi ($t_2,$a_3,$b_0)
  1080. $ADDU $c_1,$t_1
  1081. sltu $at,$c_1,$t_1
  1082. $MULTU ($a_4,$b_0) # mul_add_c(a[4],b[0],c2,c3,c1);
  1083. $ADDU $t_2,$at
  1084. $ADDU $c_2,$t_2
  1085. sltu $at,$c_2,$t_2
  1086. $ADDU $c_3,$at
  1087. $ST $c_1,3*$BNSZ($a0) # r[3]=c1;
  1088. mflo ($t_1,$a_4,$b_0)
  1089. mfhi ($t_2,$a_4,$b_0)
  1090. $ADDU $c_2,$t_1
  1091. sltu $at,$c_2,$t_1
  1092. $MULTU ($a_3,$b_1) # mul_add_c(a[3],b[1],c2,c3,c1);
  1093. $ADDU $t_2,$at
  1094. $ADDU $c_3,$t_2
  1095. sltu $c_1,$c_3,$t_2
  1096. mflo ($t_1,$a_3,$b_1)
  1097. mfhi ($t_2,$a_3,$b_1)
  1098. $ADDU $c_2,$t_1
  1099. sltu $at,$c_2,$t_1
  1100. $MULTU ($a_2,$b_2) # mul_add_c(a[2],b[2],c2,c3,c1);
  1101. $ADDU $t_2,$at
  1102. $ADDU $c_3,$t_2
  1103. sltu $at,$c_3,$t_2
  1104. $ADDU $c_1,$at
  1105. mflo ($t_1,$a_2,$b_2)
  1106. mfhi ($t_2,$a_2,$b_2)
  1107. $ADDU $c_2,$t_1
  1108. sltu $at,$c_2,$t_1
  1109. $MULTU ($a_1,$b_3) # mul_add_c(a[1],b[3],c2,c3,c1);
  1110. $ADDU $t_2,$at
  1111. $ADDU $c_3,$t_2
  1112. sltu $at,$c_3,$t_2
  1113. $ADDU $c_1,$at
  1114. mflo ($t_1,$a_1,$b_3)
  1115. mfhi ($t_2,$a_1,$b_3)
  1116. $ADDU $c_2,$t_1
  1117. sltu $at,$c_2,$t_1
  1118. $MULTU ($a_0,$b_4) # mul_add_c(a[0],b[4],c2,c3,c1);
  1119. $ADDU $t_2,$at
  1120. $ADDU $c_3,$t_2
  1121. sltu $at,$c_3,$t_2
  1122. $ADDU $c_1,$at
  1123. mflo ($t_1,$a_0,$b_4)
  1124. mfhi ($t_2,$a_0,$b_4)
  1125. $ADDU $c_2,$t_1
  1126. sltu $at,$c_2,$t_1
  1127. $MULTU ($a_0,$b_5) # mul_add_c(a[0],b[5],c3,c1,c2);
  1128. $ADDU $t_2,$at
  1129. $ADDU $c_3,$t_2
  1130. sltu $at,$c_3,$t_2
  1131. $ADDU $c_1,$at
  1132. $ST $c_2,4*$BNSZ($a0) # r[4]=c2;
  1133. mflo ($t_1,$a_0,$b_5)
  1134. mfhi ($t_2,$a_0,$b_5)
  1135. $ADDU $c_3,$t_1
  1136. sltu $at,$c_3,$t_1
  1137. $MULTU ($a_1,$b_4) # mul_add_c(a[1],b[4],c3,c1,c2);
  1138. $ADDU $t_2,$at
  1139. $ADDU $c_1,$t_2
  1140. sltu $c_2,$c_1,$t_2
  1141. mflo ($t_1,$a_1,$b_4)
  1142. mfhi ($t_2,$a_1,$b_4)
  1143. $ADDU $c_3,$t_1
  1144. sltu $at,$c_3,$t_1
  1145. $MULTU ($a_2,$b_3) # mul_add_c(a[2],b[3],c3,c1,c2);
  1146. $ADDU $t_2,$at
  1147. $ADDU $c_1,$t_2
  1148. sltu $at,$c_1,$t_2
  1149. $ADDU $c_2,$at
  1150. mflo ($t_1,$a_2,$b_3)
  1151. mfhi ($t_2,$a_2,$b_3)
  1152. $ADDU $c_3,$t_1
  1153. sltu $at,$c_3,$t_1
  1154. $MULTU ($a_3,$b_2) # mul_add_c(a[3],b[2],c3,c1,c2);
  1155. $ADDU $t_2,$at
  1156. $ADDU $c_1,$t_2
  1157. sltu $at,$c_1,$t_2
  1158. $ADDU $c_2,$at
  1159. mflo ($t_1,$a_3,$b_2)
  1160. mfhi ($t_2,$a_3,$b_2)
  1161. $ADDU $c_3,$t_1
  1162. sltu $at,$c_3,$t_1
  1163. $MULTU ($a_4,$b_1) # mul_add_c(a[4],b[1],c3,c1,c2);
  1164. $ADDU $t_2,$at
  1165. $ADDU $c_1,$t_2
  1166. sltu $at,$c_1,$t_2
  1167. $ADDU $c_2,$at
  1168. mflo ($t_1,$a_4,$b_1)
  1169. mfhi ($t_2,$a_4,$b_1)
  1170. $ADDU $c_3,$t_1
  1171. sltu $at,$c_3,$t_1
  1172. $MULTU ($a_5,$b_0) # mul_add_c(a[5],b[0],c3,c1,c2);
  1173. $ADDU $t_2,$at
  1174. $ADDU $c_1,$t_2
  1175. sltu $at,$c_1,$t_2
  1176. $ADDU $c_2,$at
  1177. mflo ($t_1,$a_5,$b_0)
  1178. mfhi ($t_2,$a_5,$b_0)
  1179. $ADDU $c_3,$t_1
  1180. sltu $at,$c_3,$t_1
  1181. $MULTU ($a_6,$b_0) # mul_add_c(a[6],b[0],c1,c2,c3);
  1182. $ADDU $t_2,$at
  1183. $ADDU $c_1,$t_2
  1184. sltu $at,$c_1,$t_2
  1185. $ADDU $c_2,$at
  1186. $ST $c_3,5*$BNSZ($a0) # r[5]=c3;
  1187. mflo ($t_1,$a_6,$b_0)
  1188. mfhi ($t_2,$a_6,$b_0)
  1189. $ADDU $c_1,$t_1
  1190. sltu $at,$c_1,$t_1
  1191. $MULTU ($a_5,$b_1) # mul_add_c(a[5],b[1],c1,c2,c3);
  1192. $ADDU $t_2,$at
  1193. $ADDU $c_2,$t_2
  1194. sltu $c_3,$c_2,$t_2
  1195. mflo ($t_1,$a_5,$b_1)
  1196. mfhi ($t_2,$a_5,$b_1)
  1197. $ADDU $c_1,$t_1
  1198. sltu $at,$c_1,$t_1
  1199. $MULTU ($a_4,$b_2) # mul_add_c(a[4],b[2],c1,c2,c3);
  1200. $ADDU $t_2,$at
  1201. $ADDU $c_2,$t_2
  1202. sltu $at,$c_2,$t_2
  1203. $ADDU $c_3,$at
  1204. mflo ($t_1,$a_4,$b_2)
  1205. mfhi ($t_2,$a_4,$b_2)
  1206. $ADDU $c_1,$t_1
  1207. sltu $at,$c_1,$t_1
  1208. $MULTU ($a_3,$b_3) # mul_add_c(a[3],b[3],c1,c2,c3);
  1209. $ADDU $t_2,$at
  1210. $ADDU $c_2,$t_2
  1211. sltu $at,$c_2,$t_2
  1212. $ADDU $c_3,$at
  1213. mflo ($t_1,$a_3,$b_3)
  1214. mfhi ($t_2,$a_3,$b_3)
  1215. $ADDU $c_1,$t_1
  1216. sltu $at,$c_1,$t_1
  1217. $MULTU ($a_2,$b_4) # mul_add_c(a[2],b[4],c1,c2,c3);
  1218. $ADDU $t_2,$at
  1219. $ADDU $c_2,$t_2
  1220. sltu $at,$c_2,$t_2
  1221. $ADDU $c_3,$at
  1222. mflo ($t_1,$a_2,$b_4)
  1223. mfhi ($t_2,$a_2,$b_4)
  1224. $ADDU $c_1,$t_1
  1225. sltu $at,$c_1,$t_1
  1226. $MULTU ($a_1,$b_5) # mul_add_c(a[1],b[5],c1,c2,c3);
  1227. $ADDU $t_2,$at
  1228. $ADDU $c_2,$t_2
  1229. sltu $at,$c_2,$t_2
  1230. $ADDU $c_3,$at
  1231. mflo ($t_1,$a_1,$b_5)
  1232. mfhi ($t_2,$a_1,$b_5)
  1233. $ADDU $c_1,$t_1
  1234. sltu $at,$c_1,$t_1
  1235. $MULTU ($a_0,$b_6) # mul_add_c(a[0],b[6],c1,c2,c3);
  1236. $ADDU $t_2,$at
  1237. $ADDU $c_2,$t_2
  1238. sltu $at,$c_2,$t_2
  1239. $ADDU $c_3,$at
  1240. mflo ($t_1,$a_0,$b_6)
  1241. mfhi ($t_2,$a_0,$b_6)
  1242. $ADDU $c_1,$t_1
  1243. sltu $at,$c_1,$t_1
  1244. $MULTU ($a_0,$b_7) # mul_add_c(a[0],b[7],c2,c3,c1);
  1245. $ADDU $t_2,$at
  1246. $ADDU $c_2,$t_2
  1247. sltu $at,$c_2,$t_2
  1248. $ADDU $c_3,$at
  1249. $ST $c_1,6*$BNSZ($a0) # r[6]=c1;
  1250. mflo ($t_1,$a_0,$b_7)
  1251. mfhi ($t_2,$a_0,$b_7)
  1252. $ADDU $c_2,$t_1
  1253. sltu $at,$c_2,$t_1
  1254. $MULTU ($a_1,$b_6) # mul_add_c(a[1],b[6],c2,c3,c1);
  1255. $ADDU $t_2,$at
  1256. $ADDU $c_3,$t_2
  1257. sltu $c_1,$c_3,$t_2
  1258. mflo ($t_1,$a_1,$b_6)
  1259. mfhi ($t_2,$a_1,$b_6)
  1260. $ADDU $c_2,$t_1
  1261. sltu $at,$c_2,$t_1
  1262. $MULTU ($a_2,$b_5) # mul_add_c(a[2],b[5],c2,c3,c1);
  1263. $ADDU $t_2,$at
  1264. $ADDU $c_3,$t_2
  1265. sltu $at,$c_3,$t_2
  1266. $ADDU $c_1,$at
  1267. mflo ($t_1,$a_2,$b_5)
  1268. mfhi ($t_2,$a_2,$b_5)
  1269. $ADDU $c_2,$t_1
  1270. sltu $at,$c_2,$t_1
  1271. $MULTU ($a_3,$b_4) # mul_add_c(a[3],b[4],c2,c3,c1);
  1272. $ADDU $t_2,$at
  1273. $ADDU $c_3,$t_2
  1274. sltu $at,$c_3,$t_2
  1275. $ADDU $c_1,$at
  1276. mflo ($t_1,$a_3,$b_4)
  1277. mfhi ($t_2,$a_3,$b_4)
  1278. $ADDU $c_2,$t_1
  1279. sltu $at,$c_2,$t_1
  1280. $MULTU ($a_4,$b_3) # mul_add_c(a[4],b[3],c2,c3,c1);
  1281. $ADDU $t_2,$at
  1282. $ADDU $c_3,$t_2
  1283. sltu $at,$c_3,$t_2
  1284. $ADDU $c_1,$at
  1285. mflo ($t_1,$a_4,$b_3)
  1286. mfhi ($t_2,$a_4,$b_3)
  1287. $ADDU $c_2,$t_1
  1288. sltu $at,$c_2,$t_1
  1289. $MULTU ($a_5,$b_2) # mul_add_c(a[5],b[2],c2,c3,c1);
  1290. $ADDU $t_2,$at
  1291. $ADDU $c_3,$t_2
  1292. sltu $at,$c_3,$t_2
  1293. $ADDU $c_1,$at
  1294. mflo ($t_1,$a_5,$b_2)
  1295. mfhi ($t_2,$a_5,$b_2)
  1296. $ADDU $c_2,$t_1
  1297. sltu $at,$c_2,$t_1
  1298. $MULTU ($a_6,$b_1) # mul_add_c(a[6],b[1],c2,c3,c1);
  1299. $ADDU $t_2,$at
  1300. $ADDU $c_3,$t_2
  1301. sltu $at,$c_3,$t_2
  1302. $ADDU $c_1,$at
  1303. mflo ($t_1,$a_6,$b_1)
  1304. mfhi ($t_2,$a_6,$b_1)
  1305. $ADDU $c_2,$t_1
  1306. sltu $at,$c_2,$t_1
  1307. $MULTU ($a_7,$b_0) # mul_add_c(a[7],b[0],c2,c3,c1);
  1308. $ADDU $t_2,$at
  1309. $ADDU $c_3,$t_2
  1310. sltu $at,$c_3,$t_2
  1311. $ADDU $c_1,$at
  1312. mflo ($t_1,$a_7,$b_0)
  1313. mfhi ($t_2,$a_7,$b_0)
  1314. $ADDU $c_2,$t_1
  1315. sltu $at,$c_2,$t_1
  1316. $MULTU ($a_7,$b_1) # mul_add_c(a[7],b[1],c3,c1,c2);
  1317. $ADDU $t_2,$at
  1318. $ADDU $c_3,$t_2
  1319. sltu $at,$c_3,$t_2
  1320. $ADDU $c_1,$at
  1321. $ST $c_2,7*$BNSZ($a0) # r[7]=c2;
  1322. mflo ($t_1,$a_7,$b_1)
  1323. mfhi ($t_2,$a_7,$b_1)
  1324. $ADDU $c_3,$t_1
  1325. sltu $at,$c_3,$t_1
  1326. $MULTU ($a_6,$b_2) # mul_add_c(a[6],b[2],c3,c1,c2);
  1327. $ADDU $t_2,$at
  1328. $ADDU $c_1,$t_2
  1329. sltu $c_2,$c_1,$t_2
  1330. mflo ($t_1,$a_6,$b_2)
  1331. mfhi ($t_2,$a_6,$b_2)
  1332. $ADDU $c_3,$t_1
  1333. sltu $at,$c_3,$t_1
  1334. $MULTU ($a_5,$b_3) # mul_add_c(a[5],b[3],c3,c1,c2);
  1335. $ADDU $t_2,$at
  1336. $ADDU $c_1,$t_2
  1337. sltu $at,$c_1,$t_2
  1338. $ADDU $c_2,$at
  1339. mflo ($t_1,$a_5,$b_3)
  1340. mfhi ($t_2,$a_5,$b_3)
  1341. $ADDU $c_3,$t_1
  1342. sltu $at,$c_3,$t_1
  1343. $MULTU ($a_4,$b_4) # mul_add_c(a[4],b[4],c3,c1,c2);
  1344. $ADDU $t_2,$at
  1345. $ADDU $c_1,$t_2
  1346. sltu $at,$c_1,$t_2
  1347. $ADDU $c_2,$at
  1348. mflo ($t_1,$a_4,$b_4)
  1349. mfhi ($t_2,$a_4,$b_4)
  1350. $ADDU $c_3,$t_1
  1351. sltu $at,$c_3,$t_1
  1352. $MULTU ($a_3,$b_5) # mul_add_c(a[3],b[5],c3,c1,c2);
  1353. $ADDU $t_2,$at
  1354. $ADDU $c_1,$t_2
  1355. sltu $at,$c_1,$t_2
  1356. $ADDU $c_2,$at
  1357. mflo ($t_1,$a_3,$b_5)
  1358. mfhi ($t_2,$a_3,$b_5)
  1359. $ADDU $c_3,$t_1
  1360. sltu $at,$c_3,$t_1
  1361. $MULTU ($a_2,$b_6) # mul_add_c(a[2],b[6],c3,c1,c2);
  1362. $ADDU $t_2,$at
  1363. $ADDU $c_1,$t_2
  1364. sltu $at,$c_1,$t_2
  1365. $ADDU $c_2,$at
  1366. mflo ($t_1,$a_2,$b_6)
  1367. mfhi ($t_2,$a_2,$b_6)
  1368. $ADDU $c_3,$t_1
  1369. sltu $at,$c_3,$t_1
  1370. $MULTU ($a_1,$b_7) # mul_add_c(a[1],b[7],c3,c1,c2);
  1371. $ADDU $t_2,$at
  1372. $ADDU $c_1,$t_2
  1373. sltu $at,$c_1,$t_2
  1374. $ADDU $c_2,$at
  1375. mflo ($t_1,$a_1,$b_7)
  1376. mfhi ($t_2,$a_1,$b_7)
  1377. $ADDU $c_3,$t_1
  1378. sltu $at,$c_3,$t_1
  1379. $MULTU ($a_2,$b_7) # mul_add_c(a[2],b[7],c1,c2,c3);
  1380. $ADDU $t_2,$at
  1381. $ADDU $c_1,$t_2
  1382. sltu $at,$c_1,$t_2
  1383. $ADDU $c_2,$at
  1384. $ST $c_3,8*$BNSZ($a0) # r[8]=c3;
  1385. mflo ($t_1,$a_2,$b_7)
  1386. mfhi ($t_2,$a_2,$b_7)
  1387. $ADDU $c_1,$t_1
  1388. sltu $at,$c_1,$t_1
  1389. $MULTU ($a_3,$b_6) # mul_add_c(a[3],b[6],c1,c2,c3);
  1390. $ADDU $t_2,$at
  1391. $ADDU $c_2,$t_2
  1392. sltu $c_3,$c_2,$t_2
  1393. mflo ($t_1,$a_3,$b_6)
  1394. mfhi ($t_2,$a_3,$b_6)
  1395. $ADDU $c_1,$t_1
  1396. sltu $at,$c_1,$t_1
  1397. $MULTU ($a_4,$b_5) # mul_add_c(a[4],b[5],c1,c2,c3);
  1398. $ADDU $t_2,$at
  1399. $ADDU $c_2,$t_2
  1400. sltu $at,$c_2,$t_2
  1401. $ADDU $c_3,$at
  1402. mflo ($t_1,$a_4,$b_5)
  1403. mfhi ($t_2,$a_4,$b_5)
  1404. $ADDU $c_1,$t_1
  1405. sltu $at,$c_1,$t_1
  1406. $MULTU ($a_5,$b_4) # mul_add_c(a[5],b[4],c1,c2,c3);
  1407. $ADDU $t_2,$at
  1408. $ADDU $c_2,$t_2
  1409. sltu $at,$c_2,$t_2
  1410. $ADDU $c_3,$at
  1411. mflo ($t_1,$a_5,$b_4)
  1412. mfhi ($t_2,$a_5,$b_4)
  1413. $ADDU $c_1,$t_1
  1414. sltu $at,$c_1,$t_1
  1415. $MULTU ($a_6,$b_3) # mul_add_c(a[6],b[3],c1,c2,c3);
  1416. $ADDU $t_2,$at
  1417. $ADDU $c_2,$t_2
  1418. sltu $at,$c_2,$t_2
  1419. $ADDU $c_3,$at
  1420. mflo ($t_1,$a_6,$b_3)
  1421. mfhi ($t_2,$a_6,$b_3)
  1422. $ADDU $c_1,$t_1
  1423. sltu $at,$c_1,$t_1
  1424. $MULTU ($a_7,$b_2) # mul_add_c(a[7],b[2],c1,c2,c3);
  1425. $ADDU $t_2,$at
  1426. $ADDU $c_2,$t_2
  1427. sltu $at,$c_2,$t_2
  1428. $ADDU $c_3,$at
  1429. mflo ($t_1,$a_7,$b_2)
  1430. mfhi ($t_2,$a_7,$b_2)
  1431. $ADDU $c_1,$t_1
  1432. sltu $at,$c_1,$t_1
  1433. $MULTU ($a_7,$b_3) # mul_add_c(a[7],b[3],c2,c3,c1);
  1434. $ADDU $t_2,$at
  1435. $ADDU $c_2,$t_2
  1436. sltu $at,$c_2,$t_2
  1437. $ADDU $c_3,$at
  1438. $ST $c_1,9*$BNSZ($a0) # r[9]=c1;
  1439. mflo ($t_1,$a_7,$b_3)
  1440. mfhi ($t_2,$a_7,$b_3)
  1441. $ADDU $c_2,$t_1
  1442. sltu $at,$c_2,$t_1
  1443. $MULTU ($a_6,$b_4) # mul_add_c(a[6],b[4],c2,c3,c1);
  1444. $ADDU $t_2,$at
  1445. $ADDU $c_3,$t_2
  1446. sltu $c_1,$c_3,$t_2
  1447. mflo ($t_1,$a_6,$b_4)
  1448. mfhi ($t_2,$a_6,$b_4)
  1449. $ADDU $c_2,$t_1
  1450. sltu $at,$c_2,$t_1
  1451. $MULTU ($a_5,$b_5) # mul_add_c(a[5],b[5],c2,c3,c1);
  1452. $ADDU $t_2,$at
  1453. $ADDU $c_3,$t_2
  1454. sltu $at,$c_3,$t_2
  1455. $ADDU $c_1,$at
  1456. mflo ($t_1,$a_5,$b_5)
  1457. mfhi ($t_2,$a_5,$b_5)
  1458. $ADDU $c_2,$t_1
  1459. sltu $at,$c_2,$t_1
  1460. $MULTU ($a_4,$b_6) # mul_add_c(a[4],b[6],c2,c3,c1);
  1461. $ADDU $t_2,$at
  1462. $ADDU $c_3,$t_2
  1463. sltu $at,$c_3,$t_2
  1464. $ADDU $c_1,$at
  1465. mflo ($t_1,$a_4,$b_6)
  1466. mfhi ($t_2,$a_4,$b_6)
  1467. $ADDU $c_2,$t_1
  1468. sltu $at,$c_2,$t_1
  1469. $MULTU ($a_3,$b_7) # mul_add_c(a[3],b[7],c2,c3,c1);
  1470. $ADDU $t_2,$at
  1471. $ADDU $c_3,$t_2
  1472. sltu $at,$c_3,$t_2
  1473. $ADDU $c_1,$at
  1474. mflo ($t_1,$a_3,$b_7)
  1475. mfhi ($t_2,$a_3,$b_7)
  1476. $ADDU $c_2,$t_1
  1477. sltu $at,$c_2,$t_1
  1478. $MULTU ($a_4,$b_7) # mul_add_c(a[4],b[7],c3,c1,c2);
  1479. $ADDU $t_2,$at
  1480. $ADDU $c_3,$t_2
  1481. sltu $at,$c_3,$t_2
  1482. $ADDU $c_1,$at
  1483. $ST $c_2,10*$BNSZ($a0) # r[10]=c2;
  1484. mflo ($t_1,$a_4,$b_7)
  1485. mfhi ($t_2,$a_4,$b_7)
  1486. $ADDU $c_3,$t_1
  1487. sltu $at,$c_3,$t_1
  1488. $MULTU ($a_5,$b_6) # mul_add_c(a[5],b[6],c3,c1,c2);
  1489. $ADDU $t_2,$at
  1490. $ADDU $c_1,$t_2
  1491. sltu $c_2,$c_1,$t_2
  1492. mflo ($t_1,$a_5,$b_6)
  1493. mfhi ($t_2,$a_5,$b_6)
  1494. $ADDU $c_3,$t_1
  1495. sltu $at,$c_3,$t_1
  1496. $MULTU ($a_6,$b_5) # mul_add_c(a[6],b[5],c3,c1,c2);
  1497. $ADDU $t_2,$at
  1498. $ADDU $c_1,$t_2
  1499. sltu $at,$c_1,$t_2
  1500. $ADDU $c_2,$at
  1501. mflo ($t_1,$a_6,$b_5)
  1502. mfhi ($t_2,$a_6,$b_5)
  1503. $ADDU $c_3,$t_1
  1504. sltu $at,$c_3,$t_1
  1505. $MULTU ($a_7,$b_4) # mul_add_c(a[7],b[4],c3,c1,c2);
  1506. $ADDU $t_2,$at
  1507. $ADDU $c_1,$t_2
  1508. sltu $at,$c_1,$t_2
  1509. $ADDU $c_2,$at
  1510. mflo ($t_1,$a_7,$b_4)
  1511. mfhi ($t_2,$a_7,$b_4)
  1512. $ADDU $c_3,$t_1
  1513. sltu $at,$c_3,$t_1
  1514. $MULTU ($a_7,$b_5) # mul_add_c(a[7],b[5],c1,c2,c3);
  1515. $ADDU $t_2,$at
  1516. $ADDU $c_1,$t_2
  1517. sltu $at,$c_1,$t_2
  1518. $ADDU $c_2,$at
  1519. $ST $c_3,11*$BNSZ($a0) # r[11]=c3;
  1520. mflo ($t_1,$a_7,$b_5)
  1521. mfhi ($t_2,$a_7,$b_5)
  1522. $ADDU $c_1,$t_1
  1523. sltu $at,$c_1,$t_1
  1524. $MULTU ($a_6,$b_6) # mul_add_c(a[6],b[6],c1,c2,c3);
  1525. $ADDU $t_2,$at
  1526. $ADDU $c_2,$t_2
  1527. sltu $c_3,$c_2,$t_2
  1528. mflo ($t_1,$a_6,$b_6)
  1529. mfhi ($t_2,$a_6,$b_6)
  1530. $ADDU $c_1,$t_1
  1531. sltu $at,$c_1,$t_1
  1532. $MULTU ($a_5,$b_7) # mul_add_c(a[5],b[7],c1,c2,c3);
  1533. $ADDU $t_2,$at
  1534. $ADDU $c_2,$t_2
  1535. sltu $at,$c_2,$t_2
  1536. $ADDU $c_3,$at
  1537. mflo ($t_1,$a_5,$b_7)
  1538. mfhi ($t_2,$a_5,$b_7)
  1539. $ADDU $c_1,$t_1
  1540. sltu $at,$c_1,$t_1
  1541. $MULTU ($a_6,$b_7) # mul_add_c(a[6],b[7],c2,c3,c1);
  1542. $ADDU $t_2,$at
  1543. $ADDU $c_2,$t_2
  1544. sltu $at,$c_2,$t_2
  1545. $ADDU $c_3,$at
  1546. $ST $c_1,12*$BNSZ($a0) # r[12]=c1;
  1547. mflo ($t_1,$a_6,$b_7)
  1548. mfhi ($t_2,$a_6,$b_7)
  1549. $ADDU $c_2,$t_1
  1550. sltu $at,$c_2,$t_1
  1551. $MULTU ($a_7,$b_6) # mul_add_c(a[7],b[6],c2,c3,c1);
  1552. $ADDU $t_2,$at
  1553. $ADDU $c_3,$t_2
  1554. sltu $c_1,$c_3,$t_2
  1555. mflo ($t_1,$a_7,$b_6)
  1556. mfhi ($t_2,$a_7,$b_6)
  1557. $ADDU $c_2,$t_1
  1558. sltu $at,$c_2,$t_1
  1559. $MULTU ($a_7,$b_7) # mul_add_c(a[7],b[7],c3,c1,c2);
  1560. $ADDU $t_2,$at
  1561. $ADDU $c_3,$t_2
  1562. sltu $at,$c_3,$t_2
  1563. $ADDU $c_1,$at
  1564. $ST $c_2,13*$BNSZ($a0) # r[13]=c2;
  1565. mflo ($t_1,$a_7,$b_7)
  1566. mfhi ($t_2,$a_7,$b_7)
  1567. $ADDU $c_3,$t_1
  1568. sltu $at,$c_3,$t_1
  1569. $ADDU $t_2,$at
  1570. $ADDU $c_1,$t_2
  1571. $ST $c_3,14*$BNSZ($a0) # r[14]=c3;
  1572. $ST $c_1,15*$BNSZ($a0) # r[15]=c1;
  1573. .set noreorder
  1574. ___
  1575. $code.=<<___ if ($flavour =~ /nubi/i);
  1576. $REG_L $s5,10*$SZREG($sp)
  1577. $REG_L $s4,9*$SZREG($sp)
  1578. $REG_L $s3,8*$SZREG($sp)
  1579. $REG_L $s2,7*$SZREG($sp)
  1580. $REG_L $s1,6*$SZREG($sp)
  1581. $REG_L $s0,5*$SZREG($sp)
  1582. $REG_L $t3,4*$SZREG($sp)
  1583. $REG_L $t2,3*$SZREG($sp)
  1584. $REG_L $t1,2*$SZREG($sp)
  1585. $REG_L $t0,1*$SZREG($sp)
  1586. $REG_L $gp,0*$SZREG($sp)
  1587. jr $ra
  1588. $PTR_ADD $sp,12*$SZREG
  1589. ___
  1590. $code.=<<___ if ($flavour !~ /nubi/i);
  1591. $REG_L $s5,5*$SZREG($sp)
  1592. $REG_L $s4,4*$SZREG($sp)
  1593. $REG_L $s3,3*$SZREG($sp)
  1594. $REG_L $s2,2*$SZREG($sp)
  1595. $REG_L $s1,1*$SZREG($sp)
  1596. $REG_L $s0,0*$SZREG($sp)
  1597. jr $ra
  1598. $PTR_ADD $sp,6*$SZREG
  1599. ___
  1600. $code.=<<___;
  1601. .end bn_mul_comba8
  1602. .align 5
  1603. .globl bn_mul_comba4
  1604. .ent bn_mul_comba4
  1605. bn_mul_comba4:
  1606. ___
  1607. $code.=<<___ if ($flavour =~ /nubi/i);
  1608. .frame $sp,6*$SZREG,$ra
  1609. .mask 0x8000f008,-$SZREG
  1610. .set noreorder
  1611. $PTR_SUB $sp,6*$SZREG
  1612. $REG_S $ra,5*$SZREG($sp)
  1613. $REG_S $t3,4*$SZREG($sp)
  1614. $REG_S $t2,3*$SZREG($sp)
  1615. $REG_S $t1,2*$SZREG($sp)
  1616. $REG_S $t0,1*$SZREG($sp)
  1617. $REG_S $gp,0*$SZREG($sp)
  1618. ___
  1619. $code.=<<___;
  1620. .set reorder
  1621. $LD $a_0,0($a1)
  1622. $LD $b_0,0($a2)
  1623. $LD $a_1,$BNSZ($a1)
  1624. $LD $a_2,2*$BNSZ($a1)
  1625. $MULTU ($a_0,$b_0) # mul_add_c(a[0],b[0],c1,c2,c3);
  1626. $LD $a_3,3*$BNSZ($a1)
  1627. $LD $b_1,$BNSZ($a2)
  1628. $LD $b_2,2*$BNSZ($a2)
  1629. $LD $b_3,3*$BNSZ($a2)
  1630. mflo ($c_1,$a_0,$b_0)
  1631. mfhi ($c_2,$a_0,$b_0)
  1632. $ST $c_1,0($a0)
  1633. $MULTU ($a_0,$b_1) # mul_add_c(a[0],b[1],c2,c3,c1);
  1634. mflo ($t_1,$a_0,$b_1)
  1635. mfhi ($t_2,$a_0,$b_1)
  1636. $ADDU $c_2,$t_1
  1637. sltu $at,$c_2,$t_1
  1638. $MULTU ($a_1,$b_0) # mul_add_c(a[1],b[0],c2,c3,c1);
  1639. $ADDU $c_3,$t_2,$at
  1640. mflo ($t_1,$a_1,$b_0)
  1641. mfhi ($t_2,$a_1,$b_0)
  1642. $ADDU $c_2,$t_1
  1643. sltu $at,$c_2,$t_1
  1644. $MULTU ($a_2,$b_0) # mul_add_c(a[2],b[0],c3,c1,c2);
  1645. $ADDU $t_2,$at
  1646. $ADDU $c_3,$t_2
  1647. sltu $c_1,$c_3,$t_2
  1648. $ST $c_2,$BNSZ($a0)
  1649. mflo ($t_1,$a_2,$b_0)
  1650. mfhi ($t_2,$a_2,$b_0)
  1651. $ADDU $c_3,$t_1
  1652. sltu $at,$c_3,$t_1
  1653. $MULTU ($a_1,$b_1) # mul_add_c(a[1],b[1],c3,c1,c2);
  1654. $ADDU $t_2,$at
  1655. $ADDU $c_1,$t_2
  1656. mflo ($t_1,$a_1,$b_1)
  1657. mfhi ($t_2,$a_1,$b_1)
  1658. $ADDU $c_3,$t_1
  1659. sltu $at,$c_3,$t_1
  1660. $MULTU ($a_0,$b_2) # mul_add_c(a[0],b[2],c3,c1,c2);
  1661. $ADDU $t_2,$at
  1662. $ADDU $c_1,$t_2
  1663. sltu $c_2,$c_1,$t_2
  1664. mflo ($t_1,$a_0,$b_2)
  1665. mfhi ($t_2,$a_0,$b_2)
  1666. $ADDU $c_3,$t_1
  1667. sltu $at,$c_3,$t_1
  1668. $MULTU ($a_0,$b_3) # mul_add_c(a[0],b[3],c1,c2,c3);
  1669. $ADDU $t_2,$at
  1670. $ADDU $c_1,$t_2
  1671. sltu $at,$c_1,$t_2
  1672. $ADDU $c_2,$at
  1673. $ST $c_3,2*$BNSZ($a0)
  1674. mflo ($t_1,$a_0,$b_3)
  1675. mfhi ($t_2,$a_0,$b_3)
  1676. $ADDU $c_1,$t_1
  1677. sltu $at,$c_1,$t_1
  1678. $MULTU ($a_1,$b_2) # mul_add_c(a[1],b[2],c1,c2,c3);
  1679. $ADDU $t_2,$at
  1680. $ADDU $c_2,$t_2
  1681. sltu $c_3,$c_2,$t_2
  1682. mflo ($t_1,$a_1,$b_2)
  1683. mfhi ($t_2,$a_1,$b_2)
  1684. $ADDU $c_1,$t_1
  1685. sltu $at,$c_1,$t_1
  1686. $MULTU ($a_2,$b_1) # mul_add_c(a[2],b[1],c1,c2,c3);
  1687. $ADDU $t_2,$at
  1688. $ADDU $c_2,$t_2
  1689. sltu $at,$c_2,$t_2
  1690. $ADDU $c_3,$at
  1691. mflo ($t_1,$a_2,$b_1)
  1692. mfhi ($t_2,$a_2,$b_1)
  1693. $ADDU $c_1,$t_1
  1694. sltu $at,$c_1,$t_1
  1695. $MULTU ($a_3,$b_0) # mul_add_c(a[3],b[0],c1,c2,c3);
  1696. $ADDU $t_2,$at
  1697. $ADDU $c_2,$t_2
  1698. sltu $at,$c_2,$t_2
  1699. $ADDU $c_3,$at
  1700. mflo ($t_1,$a_3,$b_0)
  1701. mfhi ($t_2,$a_3,$b_0)
  1702. $ADDU $c_1,$t_1
  1703. sltu $at,$c_1,$t_1
  1704. $MULTU ($a_3,$b_1) # mul_add_c(a[3],b[1],c2,c3,c1);
  1705. $ADDU $t_2,$at
  1706. $ADDU $c_2,$t_2
  1707. sltu $at,$c_2,$t_2
  1708. $ADDU $c_3,$at
  1709. $ST $c_1,3*$BNSZ($a0)
  1710. mflo ($t_1,$a_3,$b_1)
  1711. mfhi ($t_2,$a_3,$b_1)
  1712. $ADDU $c_2,$t_1
  1713. sltu $at,$c_2,$t_1
  1714. $MULTU ($a_2,$b_2) # mul_add_c(a[2],b[2],c2,c3,c1);
  1715. $ADDU $t_2,$at
  1716. $ADDU $c_3,$t_2
  1717. sltu $c_1,$c_3,$t_2
  1718. mflo ($t_1,$a_2,$b_2)
  1719. mfhi ($t_2,$a_2,$b_2)
  1720. $ADDU $c_2,$t_1
  1721. sltu $at,$c_2,$t_1
  1722. $MULTU ($a_1,$b_3) # mul_add_c(a[1],b[3],c2,c3,c1);
  1723. $ADDU $t_2,$at
  1724. $ADDU $c_3,$t_2
  1725. sltu $at,$c_3,$t_2
  1726. $ADDU $c_1,$at
  1727. mflo ($t_1,$a_1,$b_3)
  1728. mfhi ($t_2,$a_1,$b_3)
  1729. $ADDU $c_2,$t_1
  1730. sltu $at,$c_2,$t_1
  1731. $MULTU ($a_2,$b_3) # mul_add_c(a[2],b[3],c3,c1,c2);
  1732. $ADDU $t_2,$at
  1733. $ADDU $c_3,$t_2
  1734. sltu $at,$c_3,$t_2
  1735. $ADDU $c_1,$at
  1736. $ST $c_2,4*$BNSZ($a0)
  1737. mflo ($t_1,$a_2,$b_3)
  1738. mfhi ($t_2,$a_2,$b_3)
  1739. $ADDU $c_3,$t_1
  1740. sltu $at,$c_3,$t_1
  1741. $MULTU ($a_3,$b_2) # mul_add_c(a[3],b[2],c3,c1,c2);
  1742. $ADDU $t_2,$at
  1743. $ADDU $c_1,$t_2
  1744. sltu $c_2,$c_1,$t_2
  1745. mflo ($t_1,$a_3,$b_2)
  1746. mfhi ($t_2,$a_3,$b_2)
  1747. $ADDU $c_3,$t_1
  1748. sltu $at,$c_3,$t_1
  1749. $MULTU ($a_3,$b_3) # mul_add_c(a[3],b[3],c1,c2,c3);
  1750. $ADDU $t_2,$at
  1751. $ADDU $c_1,$t_2
  1752. sltu $at,$c_1,$t_2
  1753. $ADDU $c_2,$at
  1754. $ST $c_3,5*$BNSZ($a0)
  1755. mflo ($t_1,$a_3,$b_3)
  1756. mfhi ($t_2,$a_3,$b_3)
  1757. $ADDU $c_1,$t_1
  1758. sltu $at,$c_1,$t_1
  1759. $ADDU $t_2,$at
  1760. $ADDU $c_2,$t_2
  1761. $ST $c_1,6*$BNSZ($a0)
  1762. $ST $c_2,7*$BNSZ($a0)
  1763. .set noreorder
  1764. ___
  1765. $code.=<<___ if ($flavour =~ /nubi/i);
  1766. $REG_L $t3,4*$SZREG($sp)
  1767. $REG_L $t2,3*$SZREG($sp)
  1768. $REG_L $t1,2*$SZREG($sp)
  1769. $REG_L $t0,1*$SZREG($sp)
  1770. $REG_L $gp,0*$SZREG($sp)
  1771. $PTR_ADD $sp,6*$SZREG
  1772. ___
  1773. $code.=<<___;
  1774. jr $ra
  1775. nop
  1776. .end bn_mul_comba4
  1777. ___
  1778. ($a_4,$a_5,$a_6,$a_7)=($b_0,$b_1,$b_2,$b_3);
  1779. sub add_c2 () {
  1780. my ($hi,$lo,$c0,$c1,$c2,
  1781. $warm, # !$warm denotes first call with specific sequence of
  1782. # $c_[XYZ] when there is no Z-carry to accumulate yet;
  1783. $an,$bn # these two are arguments for multiplication which
  1784. # result is used in *next* step [which is why it's
  1785. # commented as "forward multiplication" below];
  1786. )=@_;
  1787. $code.=<<___;
  1788. $ADDU $c0,$lo
  1789. sltu $at,$c0,$lo
  1790. $MULTU ($an,$bn) # forward multiplication
  1791. $ADDU $c0,$lo
  1792. $ADDU $at,$hi
  1793. sltu $lo,$c0,$lo
  1794. $ADDU $c1,$at
  1795. $ADDU $hi,$lo
  1796. ___
  1797. $code.=<<___ if (!$warm);
  1798. sltu $c2,$c1,$at
  1799. $ADDU $c1,$hi
  1800. ___
  1801. $code.=<<___ if ($warm);
  1802. sltu $at,$c1,$at
  1803. $ADDU $c1,$hi
  1804. $ADDU $c2,$at
  1805. ___
  1806. $code.=<<___;
  1807. sltu $hi,$c1,$hi
  1808. $ADDU $c2,$hi
  1809. mflo ($lo,$an,$bn)
  1810. mfhi ($hi,$an,$bn)
  1811. ___
  1812. }
  1813. $code.=<<___;
  1814. .align 5
  1815. .globl bn_sqr_comba8
  1816. .ent bn_sqr_comba8
  1817. bn_sqr_comba8:
  1818. ___
  1819. $code.=<<___ if ($flavour =~ /nubi/i);
  1820. .frame $sp,6*$SZREG,$ra
  1821. .mask 0x8000f008,-$SZREG
  1822. .set noreorder
  1823. $PTR_SUB $sp,6*$SZREG
  1824. $REG_S $ra,5*$SZREG($sp)
  1825. $REG_S $t3,4*$SZREG($sp)
  1826. $REG_S $t2,3*$SZREG($sp)
  1827. $REG_S $t1,2*$SZREG($sp)
  1828. $REG_S $t0,1*$SZREG($sp)
  1829. $REG_S $gp,0*$SZREG($sp)
  1830. ___
  1831. $code.=<<___;
  1832. .set reorder
  1833. $LD $a_0,0($a1)
  1834. $LD $a_1,$BNSZ($a1)
  1835. $LD $a_2,2*$BNSZ($a1)
  1836. $LD $a_3,3*$BNSZ($a1)
  1837. $MULTU ($a_0,$a_0) # mul_add_c(a[0],b[0],c1,c2,c3);
  1838. $LD $a_4,4*$BNSZ($a1)
  1839. $LD $a_5,5*$BNSZ($a1)
  1840. $LD $a_6,6*$BNSZ($a1)
  1841. $LD $a_7,7*$BNSZ($a1)
  1842. mflo ($c_1,$a_0,$a_0)
  1843. mfhi ($c_2,$a_0,$a_0)
  1844. $ST $c_1,0($a0)
  1845. $MULTU ($a_0,$a_1) # mul_add_c2(a[0],b[1],c2,c3,c1);
  1846. mflo ($t_1,$a_0,$a_1)
  1847. mfhi ($t_2,$a_0,$a_1)
  1848. slt $c_1,$t_2,$zero
  1849. $SLL $t_2,1
  1850. $MULTU ($a_2,$a_0) # mul_add_c2(a[2],b[0],c3,c1,c2);
  1851. slt $a2,$t_1,$zero
  1852. $ADDU $t_2,$a2
  1853. $SLL $t_1,1
  1854. $ADDU $c_2,$t_1
  1855. sltu $at,$c_2,$t_1
  1856. $ADDU $c_3,$t_2,$at
  1857. $ST $c_2,$BNSZ($a0)
  1858. mflo ($t_1,$a_2,$a_0)
  1859. mfhi ($t_2,$a_2,$a_0)
  1860. ___
  1861. &add_c2($t_2,$t_1,$c_3,$c_1,$c_2,0,
  1862. $a_1,$a_1); # mul_add_c(a[1],b[1],c3,c1,c2);
  1863. $code.=<<___;
  1864. $ADDU $c_3,$t_1
  1865. sltu $at,$c_3,$t_1
  1866. $MULTU ($a_0,$a_3) # mul_add_c2(a[0],b[3],c1,c2,c3);
  1867. $ADDU $t_2,$at
  1868. $ADDU $c_1,$t_2
  1869. sltu $at,$c_1,$t_2
  1870. $ADDU $c_2,$at
  1871. $ST $c_3,2*$BNSZ($a0)
  1872. mflo ($t_1,$a_0,$a_3)
  1873. mfhi ($t_2,$a_0,$a_3)
  1874. ___
  1875. &add_c2($t_2,$t_1,$c_1,$c_2,$c_3,0,
  1876. $a_1,$a_2); # mul_add_c2(a[1],b[2],c1,c2,c3);
  1877. &add_c2($t_2,$t_1,$c_1,$c_2,$c_3,1,
  1878. $a_4,$a_0); # mul_add_c2(a[4],b[0],c2,c3,c1);
  1879. $code.=<<___;
  1880. $ST $c_1,3*$BNSZ($a0)
  1881. ___
  1882. &add_c2($t_2,$t_1,$c_2,$c_3,$c_1,0,
  1883. $a_3,$a_1); # mul_add_c2(a[3],b[1],c2,c3,c1);
  1884. &add_c2($t_2,$t_1,$c_2,$c_3,$c_1,1,
  1885. $a_2,$a_2); # mul_add_c(a[2],b[2],c2,c3,c1);
  1886. $code.=<<___;
  1887. $ADDU $c_2,$t_1
  1888. sltu $at,$c_2,$t_1
  1889. $MULTU ($a_0,$a_5) # mul_add_c2(a[0],b[5],c3,c1,c2);
  1890. $ADDU $t_2,$at
  1891. $ADDU $c_3,$t_2
  1892. sltu $at,$c_3,$t_2
  1893. $ADDU $c_1,$at
  1894. $ST $c_2,4*$BNSZ($a0)
  1895. mflo ($t_1,$a_0,$a_5)
  1896. mfhi ($t_2,$a_0,$a_5)
  1897. ___
  1898. &add_c2($t_2,$t_1,$c_3,$c_1,$c_2,0,
  1899. $a_1,$a_4); # mul_add_c2(a[1],b[4],c3,c1,c2);
  1900. &add_c2($t_2,$t_1,$c_3,$c_1,$c_2,1,
  1901. $a_2,$a_3); # mul_add_c2(a[2],b[3],c3,c1,c2);
  1902. &add_c2($t_2,$t_1,$c_3,$c_1,$c_2,1,
  1903. $a_6,$a_0); # mul_add_c2(a[6],b[0],c1,c2,c3);
  1904. $code.=<<___;
  1905. $ST $c_3,5*$BNSZ($a0)
  1906. ___
  1907. &add_c2($t_2,$t_1,$c_1,$c_2,$c_3,0,
  1908. $a_5,$a_1); # mul_add_c2(a[5],b[1],c1,c2,c3);
  1909. &add_c2($t_2,$t_1,$c_1,$c_2,$c_3,1,
  1910. $a_4,$a_2); # mul_add_c2(a[4],b[2],c1,c2,c3);
  1911. &add_c2($t_2,$t_1,$c_1,$c_2,$c_3,1,
  1912. $a_3,$a_3); # mul_add_c(a[3],b[3],c1,c2,c3);
  1913. $code.=<<___;
  1914. $ADDU $c_1,$t_1
  1915. sltu $at,$c_1,$t_1
  1916. $MULTU ($a_0,$a_7) # mul_add_c2(a[0],b[7],c2,c3,c1);
  1917. $ADDU $t_2,$at
  1918. $ADDU $c_2,$t_2
  1919. sltu $at,$c_2,$t_2
  1920. $ADDU $c_3,$at
  1921. $ST $c_1,6*$BNSZ($a0)
  1922. mflo ($t_1,$a_0,$a_7)
  1923. mfhi ($t_2,$a_0,$a_7)
  1924. ___
  1925. &add_c2($t_2,$t_1,$c_2,$c_3,$c_1,0,
  1926. $a_1,$a_6); # mul_add_c2(a[1],b[6],c2,c3,c1);
  1927. &add_c2($t_2,$t_1,$c_2,$c_3,$c_1,1,
  1928. $a_2,$a_5); # mul_add_c2(a[2],b[5],c2,c3,c1);
  1929. &add_c2($t_2,$t_1,$c_2,$c_3,$c_1,1,
  1930. $a_3,$a_4); # mul_add_c2(a[3],b[4],c2,c3,c1);
  1931. &add_c2($t_2,$t_1,$c_2,$c_3,$c_1,1,
  1932. $a_7,$a_1); # mul_add_c2(a[7],b[1],c3,c1,c2);
  1933. $code.=<<___;
  1934. $ST $c_2,7*$BNSZ($a0)
  1935. ___
  1936. &add_c2($t_2,$t_1,$c_3,$c_1,$c_2,0,
  1937. $a_6,$a_2); # mul_add_c2(a[6],b[2],c3,c1,c2);
  1938. &add_c2($t_2,$t_1,$c_3,$c_1,$c_2,1,
  1939. $a_5,$a_3); # mul_add_c2(a[5],b[3],c3,c1,c2);
  1940. &add_c2($t_2,$t_1,$c_3,$c_1,$c_2,1,
  1941. $a_4,$a_4); # mul_add_c(a[4],b[4],c3,c1,c2);
  1942. $code.=<<___;
  1943. $ADDU $c_3,$t_1
  1944. sltu $at,$c_3,$t_1
  1945. $MULTU ($a_2,$a_7) # mul_add_c2(a[2],b[7],c1,c2,c3);
  1946. $ADDU $t_2,$at
  1947. $ADDU $c_1,$t_2
  1948. sltu $at,$c_1,$t_2
  1949. $ADDU $c_2,$at
  1950. $ST $c_3,8*$BNSZ($a0)
  1951. mflo ($t_1,$a_2,$a_7)
  1952. mfhi ($t_2,$a_2,$a_7)
  1953. ___
  1954. &add_c2($t_2,$t_1,$c_1,$c_2,$c_3,0,
  1955. $a_3,$a_6); # mul_add_c2(a[3],b[6],c1,c2,c3);
  1956. &add_c2($t_2,$t_1,$c_1,$c_2,$c_3,1,
  1957. $a_4,$a_5); # mul_add_c2(a[4],b[5],c1,c2,c3);
  1958. &add_c2($t_2,$t_1,$c_1,$c_2,$c_3,1,
  1959. $a_7,$a_3); # mul_add_c2(a[7],b[3],c2,c3,c1);
  1960. $code.=<<___;
  1961. $ST $c_1,9*$BNSZ($a0)
  1962. ___
  1963. &add_c2($t_2,$t_1,$c_2,$c_3,$c_1,0,
  1964. $a_6,$a_4); # mul_add_c2(a[6],b[4],c2,c3,c1);
  1965. &add_c2($t_2,$t_1,$c_2,$c_3,$c_1,1,
  1966. $a_5,$a_5); # mul_add_c(a[5],b[5],c2,c3,c1);
  1967. $code.=<<___;
  1968. $ADDU $c_2,$t_1
  1969. sltu $at,$c_2,$t_1
  1970. $MULTU ($a_4,$a_7) # mul_add_c2(a[4],b[7],c3,c1,c2);
  1971. $ADDU $t_2,$at
  1972. $ADDU $c_3,$t_2
  1973. sltu $at,$c_3,$t_2
  1974. $ADDU $c_1,$at
  1975. $ST $c_2,10*$BNSZ($a0)
  1976. mflo ($t_1,$a_4,$a_7)
  1977. mfhi ($t_2,$a_4,$a_7)
  1978. ___
  1979. &add_c2($t_2,$t_1,$c_3,$c_1,$c_2,0,
  1980. $a_5,$a_6); # mul_add_c2(a[5],b[6],c3,c1,c2);
  1981. &add_c2($t_2,$t_1,$c_3,$c_1,$c_2,1,
  1982. $a_7,$a_5); # mul_add_c2(a[7],b[5],c1,c2,c3);
  1983. $code.=<<___;
  1984. $ST $c_3,11*$BNSZ($a0)
  1985. ___
  1986. &add_c2($t_2,$t_1,$c_1,$c_2,$c_3,0,
  1987. $a_6,$a_6); # mul_add_c(a[6],b[6],c1,c2,c3);
  1988. $code.=<<___;
  1989. $ADDU $c_1,$t_1
  1990. sltu $at,$c_1,$t_1
  1991. $MULTU ($a_6,$a_7) # mul_add_c2(a[6],b[7],c2,c3,c1);
  1992. $ADDU $t_2,$at
  1993. $ADDU $c_2,$t_2
  1994. sltu $at,$c_2,$t_2
  1995. $ADDU $c_3,$at
  1996. $ST $c_1,12*$BNSZ($a0)
  1997. mflo ($t_1,$a_6,$a_7)
  1998. mfhi ($t_2,$a_6,$a_7)
  1999. ___
  2000. &add_c2($t_2,$t_1,$c_2,$c_3,$c_1,0,
  2001. $a_7,$a_7); # mul_add_c(a[7],b[7],c3,c1,c2);
  2002. $code.=<<___;
  2003. $ST $c_2,13*$BNSZ($a0)
  2004. $ADDU $c_3,$t_1
  2005. sltu $at,$c_3,$t_1
  2006. $ADDU $t_2,$at
  2007. $ADDU $c_1,$t_2
  2008. $ST $c_3,14*$BNSZ($a0)
  2009. $ST $c_1,15*$BNSZ($a0)
  2010. .set noreorder
  2011. ___
  2012. $code.=<<___ if ($flavour =~ /nubi/i);
  2013. $REG_L $t3,4*$SZREG($sp)
  2014. $REG_L $t2,3*$SZREG($sp)
  2015. $REG_L $t1,2*$SZREG($sp)
  2016. $REG_L $t0,1*$SZREG($sp)
  2017. $REG_L $gp,0*$SZREG($sp)
  2018. $PTR_ADD $sp,6*$SZREG
  2019. ___
  2020. $code.=<<___;
  2021. jr $ra
  2022. nop
  2023. .end bn_sqr_comba8
  2024. .align 5
  2025. .globl bn_sqr_comba4
  2026. .ent bn_sqr_comba4
  2027. bn_sqr_comba4:
  2028. ___
  2029. $code.=<<___ if ($flavour =~ /nubi/i);
  2030. .frame $sp,6*$SZREG,$ra
  2031. .mask 0x8000f008,-$SZREG
  2032. .set noreorder
  2033. $PTR_SUB $sp,6*$SZREG
  2034. $REG_S $ra,5*$SZREG($sp)
  2035. $REG_S $t3,4*$SZREG($sp)
  2036. $REG_S $t2,3*$SZREG($sp)
  2037. $REG_S $t1,2*$SZREG($sp)
  2038. $REG_S $t0,1*$SZREG($sp)
  2039. $REG_S $gp,0*$SZREG($sp)
  2040. ___
  2041. $code.=<<___;
  2042. .set reorder
  2043. $LD $a_0,0($a1)
  2044. $LD $a_1,$BNSZ($a1)
  2045. $MULTU ($a_0,$a_0) # mul_add_c(a[0],b[0],c1,c2,c3);
  2046. $LD $a_2,2*$BNSZ($a1)
  2047. $LD $a_3,3*$BNSZ($a1)
  2048. mflo ($c_1,$a_0,$a_0)
  2049. mfhi ($c_2,$a_0,$a_0)
  2050. $ST $c_1,0($a0)
  2051. $MULTU ($a_0,$a_1) # mul_add_c2(a[0],b[1],c2,c3,c1);
  2052. mflo ($t_1,$a_0,$a_1)
  2053. mfhi ($t_2,$a_0,$a_1)
  2054. slt $c_1,$t_2,$zero
  2055. $SLL $t_2,1
  2056. $MULTU ($a_2,$a_0) # mul_add_c2(a[2],b[0],c3,c1,c2);
  2057. slt $a2,$t_1,$zero
  2058. $ADDU $t_2,$a2
  2059. $SLL $t_1,1
  2060. $ADDU $c_2,$t_1
  2061. sltu $at,$c_2,$t_1
  2062. $ADDU $c_3,$t_2,$at
  2063. $ST $c_2,$BNSZ($a0)
  2064. mflo ($t_1,$a_2,$a_0)
  2065. mfhi ($t_2,$a_2,$a_0)
  2066. ___
  2067. &add_c2($t_2,$t_1,$c_3,$c_1,$c_2,0,
  2068. $a_1,$a_1); # mul_add_c(a[1],b[1],c3,c1,c2);
  2069. $code.=<<___;
  2070. $ADDU $c_3,$t_1
  2071. sltu $at,$c_3,$t_1
  2072. $MULTU ($a_0,$a_3) # mul_add_c2(a[0],b[3],c1,c2,c3);
  2073. $ADDU $t_2,$at
  2074. $ADDU $c_1,$t_2
  2075. sltu $at,$c_1,$t_2
  2076. $ADDU $c_2,$at
  2077. $ST $c_3,2*$BNSZ($a0)
  2078. mflo ($t_1,$a_0,$a_3)
  2079. mfhi ($t_2,$a_0,$a_3)
  2080. ___
  2081. &add_c2($t_2,$t_1,$c_1,$c_2,$c_3,0,
  2082. $a_1,$a_2); # mul_add_c2(a2[1],b[2],c1,c2,c3);
  2083. &add_c2($t_2,$t_1,$c_1,$c_2,$c_3,1,
  2084. $a_3,$a_1); # mul_add_c2(a[3],b[1],c2,c3,c1);
  2085. $code.=<<___;
  2086. $ST $c_1,3*$BNSZ($a0)
  2087. ___
  2088. &add_c2($t_2,$t_1,$c_2,$c_3,$c_1,0,
  2089. $a_2,$a_2); # mul_add_c(a[2],b[2],c2,c3,c1);
  2090. $code.=<<___;
  2091. $ADDU $c_2,$t_1
  2092. sltu $at,$c_2,$t_1
  2093. $MULTU ($a_2,$a_3) # mul_add_c2(a[2],b[3],c3,c1,c2);
  2094. $ADDU $t_2,$at
  2095. $ADDU $c_3,$t_2
  2096. sltu $at,$c_3,$t_2
  2097. $ADDU $c_1,$at
  2098. $ST $c_2,4*$BNSZ($a0)
  2099. mflo ($t_1,$a_2,$a_3)
  2100. mfhi ($t_2,$a_2,$a_3)
  2101. ___
  2102. &add_c2($t_2,$t_1,$c_3,$c_1,$c_2,0,
  2103. $a_3,$a_3); # mul_add_c(a[3],b[3],c1,c2,c3);
  2104. $code.=<<___;
  2105. $ST $c_3,5*$BNSZ($a0)
  2106. $ADDU $c_1,$t_1
  2107. sltu $at,$c_1,$t_1
  2108. $ADDU $t_2,$at
  2109. $ADDU $c_2,$t_2
  2110. $ST $c_1,6*$BNSZ($a0)
  2111. $ST $c_2,7*$BNSZ($a0)
  2112. .set noreorder
  2113. ___
  2114. $code.=<<___ if ($flavour =~ /nubi/i);
  2115. $REG_L $t3,4*$SZREG($sp)
  2116. $REG_L $t2,3*$SZREG($sp)
  2117. $REG_L $t1,2*$SZREG($sp)
  2118. $REG_L $t0,1*$SZREG($sp)
  2119. $REG_L $gp,0*$SZREG($sp)
  2120. $PTR_ADD $sp,6*$SZREG
  2121. ___
  2122. $code.=<<___;
  2123. jr $ra
  2124. nop
  2125. .end bn_sqr_comba4
  2126. ___
  2127. print $code;
  2128. close STDOUT;