mips.pl 48 KB

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