ppc.pl 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011
  1. #! /usr/bin/env perl
  2. # Copyright 2004-2018 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. # Implemented as a Perl wrapper as we want to support several different
  9. # architectures with single file. We pick up the target based on the
  10. # file name we are asked to generate.
  11. #
  12. # It should be noted though that this perl code is nothing like
  13. # <openssl>/crypto/perlasm/x86*. In this case perl is used pretty much
  14. # as pre-processor to cover for platform differences in name decoration,
  15. # linker tables, 32-/64-bit instruction sets...
  16. #
  17. # As you might know there're several PowerPC ABI in use. Most notably
  18. # Linux and AIX use different 32-bit ABIs. Good news are that these ABIs
  19. # are similar enough to implement leaf(!) functions, which would be ABI
  20. # neutral. And that's what you find here: ABI neutral leaf functions.
  21. # In case you wonder what that is...
  22. #
  23. # AIX performance
  24. #
  25. # MEASUREMENTS WITH cc ON a 200 MhZ PowerPC 604e.
  26. #
  27. # The following is the performance of 32-bit compiler
  28. # generated code:
  29. #
  30. # OpenSSL 0.9.6c 21 dec 2001
  31. # built on: Tue Jun 11 11:06:51 EDT 2002
  32. # options:bn(64,32) ...
  33. #compiler: cc -DTHREADS -DAIX -DB_ENDIAN -DBN_LLONG -O3
  34. # sign verify sign/s verify/s
  35. #rsa 512 bits 0.0098s 0.0009s 102.0 1170.6
  36. #rsa 1024 bits 0.0507s 0.0026s 19.7 387.5
  37. #rsa 2048 bits 0.3036s 0.0085s 3.3 117.1
  38. #rsa 4096 bits 2.0040s 0.0299s 0.5 33.4
  39. #dsa 512 bits 0.0087s 0.0106s 114.3 94.5
  40. #dsa 1024 bits 0.0256s 0.0313s 39.0 32.0
  41. #
  42. # Same benchmark with this assembler code:
  43. #
  44. #rsa 512 bits 0.0056s 0.0005s 178.6 2049.2
  45. #rsa 1024 bits 0.0283s 0.0015s 35.3 674.1
  46. #rsa 2048 bits 0.1744s 0.0050s 5.7 201.2
  47. #rsa 4096 bits 1.1644s 0.0179s 0.9 55.7
  48. #dsa 512 bits 0.0052s 0.0062s 191.6 162.0
  49. #dsa 1024 bits 0.0149s 0.0180s 67.0 55.5
  50. #
  51. # Number of operations increases by at almost 75%
  52. #
  53. # Here are performance numbers for 64-bit compiler
  54. # generated code:
  55. #
  56. # OpenSSL 0.9.6g [engine] 9 Aug 2002
  57. # built on: Fri Apr 18 16:59:20 EDT 2003
  58. # options:bn(64,64) ...
  59. # compiler: cc -DTHREADS -D_REENTRANT -q64 -DB_ENDIAN -O3
  60. # sign verify sign/s verify/s
  61. #rsa 512 bits 0.0028s 0.0003s 357.1 3844.4
  62. #rsa 1024 bits 0.0148s 0.0008s 67.5 1239.7
  63. #rsa 2048 bits 0.0963s 0.0028s 10.4 353.0
  64. #rsa 4096 bits 0.6538s 0.0102s 1.5 98.1
  65. #dsa 512 bits 0.0026s 0.0032s 382.5 313.7
  66. #dsa 1024 bits 0.0081s 0.0099s 122.8 100.6
  67. #
  68. # Same benchmark with this assembler code:
  69. #
  70. #rsa 512 bits 0.0020s 0.0002s 510.4 6273.7
  71. #rsa 1024 bits 0.0088s 0.0005s 114.1 2128.3
  72. #rsa 2048 bits 0.0540s 0.0016s 18.5 622.5
  73. #rsa 4096 bits 0.3700s 0.0058s 2.7 171.0
  74. #dsa 512 bits 0.0016s 0.0020s 610.7 507.1
  75. #dsa 1024 bits 0.0047s 0.0058s 212.5 173.2
  76. #
  77. # Again, performance increases by at about 75%
  78. #
  79. # Mac OS X, Apple G5 1.8GHz (Note this is 32 bit code)
  80. # OpenSSL 0.9.7c 30 Sep 2003
  81. #
  82. # Original code.
  83. #
  84. #rsa 512 bits 0.0011s 0.0001s 906.1 11012.5
  85. #rsa 1024 bits 0.0060s 0.0003s 166.6 3363.1
  86. #rsa 2048 bits 0.0370s 0.0010s 27.1 982.4
  87. #rsa 4096 bits 0.2426s 0.0036s 4.1 280.4
  88. #dsa 512 bits 0.0010s 0.0012s 1038.1 841.5
  89. #dsa 1024 bits 0.0030s 0.0037s 329.6 269.7
  90. #dsa 2048 bits 0.0101s 0.0127s 98.9 78.6
  91. #
  92. # Same benchmark with this assembler code:
  93. #
  94. #rsa 512 bits 0.0007s 0.0001s 1416.2 16645.9
  95. #rsa 1024 bits 0.0036s 0.0002s 274.4 5380.6
  96. #rsa 2048 bits 0.0222s 0.0006s 45.1 1589.5
  97. #rsa 4096 bits 0.1469s 0.0022s 6.8 449.6
  98. #dsa 512 bits 0.0006s 0.0007s 1664.2 1376.2
  99. #dsa 1024 bits 0.0018s 0.0023s 545.0 442.2
  100. #dsa 2048 bits 0.0061s 0.0075s 163.5 132.8
  101. #
  102. # Performance increase of ~60%
  103. # Based on submission from Suresh N. Chari of IBM
  104. $flavour = shift;
  105. if ($flavour =~ /32/) {
  106. $BITS= 32;
  107. $BNSZ= $BITS/8;
  108. $ISA= "\"ppc\"";
  109. $LD= "lwz"; # load
  110. $LDU= "lwzu"; # load and update
  111. $ST= "stw"; # store
  112. $STU= "stwu"; # store and update
  113. $UMULL= "mullw"; # unsigned multiply low
  114. $UMULH= "mulhwu"; # unsigned multiply high
  115. $UDIV= "divwu"; # unsigned divide
  116. $UCMPI= "cmplwi"; # unsigned compare with immediate
  117. $UCMP= "cmplw"; # unsigned compare
  118. $CNTLZ= "cntlzw"; # count leading zeros
  119. $SHL= "slw"; # shift left
  120. $SHR= "srw"; # unsigned shift right
  121. $SHRI= "srwi"; # unsigned shift right by immediate
  122. $SHLI= "slwi"; # shift left by immediate
  123. $CLRU= "clrlwi"; # clear upper bits
  124. $INSR= "insrwi"; # insert right
  125. $ROTL= "rotlwi"; # rotate left by immediate
  126. $TR= "tw"; # conditional trap
  127. } elsif ($flavour =~ /64/) {
  128. $BITS= 64;
  129. $BNSZ= $BITS/8;
  130. $ISA= "\"ppc64\"";
  131. # same as above, but 64-bit mnemonics...
  132. $LD= "ld"; # load
  133. $LDU= "ldu"; # load and update
  134. $ST= "std"; # store
  135. $STU= "stdu"; # store and update
  136. $UMULL= "mulld"; # unsigned multiply low
  137. $UMULH= "mulhdu"; # unsigned multiply high
  138. $UDIV= "divdu"; # unsigned divide
  139. $UCMPI= "cmpldi"; # unsigned compare with immediate
  140. $UCMP= "cmpld"; # unsigned compare
  141. $CNTLZ= "cntlzd"; # count leading zeros
  142. $SHL= "sld"; # shift left
  143. $SHR= "srd"; # unsigned shift right
  144. $SHRI= "srdi"; # unsigned shift right by immediate
  145. $SHLI= "sldi"; # shift left by immediate
  146. $CLRU= "clrldi"; # clear upper bits
  147. $INSR= "insrdi"; # insert right
  148. $ROTL= "rotldi"; # rotate left by immediate
  149. $TR= "td"; # conditional trap
  150. } else { die "nonsense $flavour"; }
  151. $0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
  152. ( $xlate="${dir}ppc-xlate.pl" and -f $xlate ) or
  153. ( $xlate="${dir}../../perlasm/ppc-xlate.pl" and -f $xlate) or
  154. die "can't locate ppc-xlate.pl";
  155. open STDOUT,"| $^X $xlate $flavour ".shift || die "can't call $xlate: $!";
  156. $data=<<EOF;
  157. #--------------------------------------------------------------------
  158. #
  159. #
  160. #
  161. #
  162. # File: ppc32.s
  163. #
  164. # Created by: Suresh Chari
  165. # IBM Thomas J. Watson Research Library
  166. # Hawthorne, NY
  167. #
  168. #
  169. # Description: Optimized assembly routines for OpenSSL crypto
  170. # on the 32 bitPowerPC platform.
  171. #
  172. #
  173. # Version History
  174. #
  175. # 2. Fixed bn_add,bn_sub and bn_div_words, added comments,
  176. # cleaned up code. Also made a single version which can
  177. # be used for both the AIX and Linux compilers. See NOTE
  178. # below.
  179. # 12/05/03 Suresh Chari
  180. # (with lots of help from) Andy Polyakov
  181. ##
  182. # 1. Initial version 10/20/02 Suresh Chari
  183. #
  184. #
  185. # The following file works for the xlc,cc
  186. # and gcc compilers.
  187. #
  188. # NOTE: To get the file to link correctly with the gcc compiler
  189. # you have to change the names of the routines and remove
  190. # the first .(dot) character. This should automatically
  191. # be done in the build process.
  192. #
  193. # Hand optimized assembly code for the following routines
  194. #
  195. # bn_sqr_comba4
  196. # bn_sqr_comba8
  197. # bn_mul_comba4
  198. # bn_mul_comba8
  199. # bn_sub_words
  200. # bn_add_words
  201. # bn_div_words
  202. # bn_sqr_words
  203. # bn_mul_words
  204. # bn_mul_add_words
  205. #
  206. # NOTE: It is possible to optimize this code more for
  207. # specific PowerPC or Power architectures. On the Northstar
  208. # architecture the optimizations in this file do
  209. # NOT provide much improvement.
  210. #
  211. # If you have comments or suggestions to improve code send
  212. # me a note at schari\@us.ibm.com
  213. #
  214. #--------------------------------------------------------------------------
  215. #
  216. # Defines to be used in the assembly code.
  217. #
  218. #.set r0,0 # we use it as storage for value of 0
  219. #.set SP,1 # preserved
  220. #.set RTOC,2 # preserved
  221. #.set r3,3 # 1st argument/return value
  222. #.set r4,4 # 2nd argument/volatile register
  223. #.set r5,5 # 3rd argument/volatile register
  224. #.set r6,6 # ...
  225. #.set r7,7
  226. #.set r8,8
  227. #.set r9,9
  228. #.set r10,10
  229. #.set r11,11
  230. #.set r12,12
  231. #.set r13,13 # not used, nor any other "below" it...
  232. # Declare function names to be global
  233. # NOTE: For gcc these names MUST be changed to remove
  234. # the first . i.e. for example change ".bn_sqr_comba4"
  235. # to "bn_sqr_comba4". This should be automatically done
  236. # in the build.
  237. .globl .bn_sqr_comba4
  238. .globl .bn_sqr_comba8
  239. .globl .bn_mul_comba4
  240. .globl .bn_mul_comba8
  241. .globl .bn_sub_words
  242. .globl .bn_add_words
  243. .globl .bn_div_words
  244. .globl .bn_sqr_words
  245. .globl .bn_mul_words
  246. .globl .bn_mul_add_words
  247. # .text section
  248. .machine "any"
  249. #
  250. # NOTE: The following label name should be changed to
  251. # "bn_sqr_comba4" i.e. remove the first dot
  252. # for the gcc compiler. This should be automatically
  253. # done in the build
  254. #
  255. .align 4
  256. .bn_sqr_comba4:
  257. #
  258. # Optimized version of bn_sqr_comba4.
  259. #
  260. # void bn_sqr_comba4(BN_ULONG *r, BN_ULONG *a)
  261. # r3 contains r
  262. # r4 contains a
  263. #
  264. # Freely use registers r5,r6,r7,r8,r9,r10,r11 as follows:
  265. #
  266. # r5,r6 are the two BN_ULONGs being multiplied.
  267. # r7,r8 are the results of the 32x32 giving 64 bit multiply.
  268. # r9,r10, r11 are the equivalents of c1,c2, c3.
  269. # Here's the assembly
  270. #
  271. #
  272. xor r0,r0,r0 # set r0 = 0. Used in the addze
  273. # instructions below
  274. #sqr_add_c(a,0,c1,c2,c3)
  275. $LD r5,`0*$BNSZ`(r4)
  276. $UMULL r9,r5,r5
  277. $UMULH r10,r5,r5 #in first iteration. No need
  278. #to add since c1=c2=c3=0.
  279. # Note c3(r11) is NOT set to 0
  280. # but will be.
  281. $ST r9,`0*$BNSZ`(r3) # r[0]=c1;
  282. # sqr_add_c2(a,1,0,c2,c3,c1);
  283. $LD r6,`1*$BNSZ`(r4)
  284. $UMULL r7,r5,r6
  285. $UMULH r8,r5,r6
  286. addc r7,r7,r7 # compute (r7,r8)=2*(r7,r8)
  287. adde r8,r8,r8
  288. addze r9,r0 # catch carry if any.
  289. # r9= r0(=0) and carry
  290. addc r10,r7,r10 # now add to temp result.
  291. addze r11,r8 # r8 added to r11 which is 0
  292. addze r9,r9
  293. $ST r10,`1*$BNSZ`(r3) #r[1]=c2;
  294. #sqr_add_c(a,1,c3,c1,c2)
  295. $UMULL r7,r6,r6
  296. $UMULH r8,r6,r6
  297. addc r11,r7,r11
  298. adde r9,r8,r9
  299. addze r10,r0
  300. #sqr_add_c2(a,2,0,c3,c1,c2)
  301. $LD r6,`2*$BNSZ`(r4)
  302. $UMULL r7,r5,r6
  303. $UMULH r8,r5,r6
  304. addc r7,r7,r7
  305. adde r8,r8,r8
  306. addze r10,r10
  307. addc r11,r7,r11
  308. adde r9,r8,r9
  309. addze r10,r10
  310. $ST r11,`2*$BNSZ`(r3) #r[2]=c3
  311. #sqr_add_c2(a,3,0,c1,c2,c3);
  312. $LD r6,`3*$BNSZ`(r4)
  313. $UMULL r7,r5,r6
  314. $UMULH r8,r5,r6
  315. addc r7,r7,r7
  316. adde r8,r8,r8
  317. addze r11,r0
  318. addc r9,r7,r9
  319. adde r10,r8,r10
  320. addze r11,r11
  321. #sqr_add_c2(a,2,1,c1,c2,c3);
  322. $LD r5,`1*$BNSZ`(r4)
  323. $LD r6,`2*$BNSZ`(r4)
  324. $UMULL r7,r5,r6
  325. $UMULH r8,r5,r6
  326. addc r7,r7,r7
  327. adde r8,r8,r8
  328. addze r11,r11
  329. addc r9,r7,r9
  330. adde r10,r8,r10
  331. addze r11,r11
  332. $ST r9,`3*$BNSZ`(r3) #r[3]=c1
  333. #sqr_add_c(a,2,c2,c3,c1);
  334. $UMULL r7,r6,r6
  335. $UMULH r8,r6,r6
  336. addc r10,r7,r10
  337. adde r11,r8,r11
  338. addze r9,r0
  339. #sqr_add_c2(a,3,1,c2,c3,c1);
  340. $LD r6,`3*$BNSZ`(r4)
  341. $UMULL r7,r5,r6
  342. $UMULH r8,r5,r6
  343. addc r7,r7,r7
  344. adde r8,r8,r8
  345. addze r9,r9
  346. addc r10,r7,r10
  347. adde r11,r8,r11
  348. addze r9,r9
  349. $ST r10,`4*$BNSZ`(r3) #r[4]=c2
  350. #sqr_add_c2(a,3,2,c3,c1,c2);
  351. $LD r5,`2*$BNSZ`(r4)
  352. $UMULL r7,r5,r6
  353. $UMULH r8,r5,r6
  354. addc r7,r7,r7
  355. adde r8,r8,r8
  356. addze r10,r0
  357. addc r11,r7,r11
  358. adde r9,r8,r9
  359. addze r10,r10
  360. $ST r11,`5*$BNSZ`(r3) #r[5] = c3
  361. #sqr_add_c(a,3,c1,c2,c3);
  362. $UMULL r7,r6,r6
  363. $UMULH r8,r6,r6
  364. addc r9,r7,r9
  365. adde r10,r8,r10
  366. $ST r9,`6*$BNSZ`(r3) #r[6]=c1
  367. $ST r10,`7*$BNSZ`(r3) #r[7]=c2
  368. blr
  369. .long 0
  370. .byte 0,12,0x14,0,0,0,2,0
  371. .long 0
  372. .size .bn_sqr_comba4,.-.bn_sqr_comba4
  373. #
  374. # NOTE: The following label name should be changed to
  375. # "bn_sqr_comba8" i.e. remove the first dot
  376. # for the gcc compiler. This should be automatically
  377. # done in the build
  378. #
  379. .align 4
  380. .bn_sqr_comba8:
  381. #
  382. # This is an optimized version of the bn_sqr_comba8 routine.
  383. # Tightly uses the adde instruction
  384. #
  385. #
  386. # void bn_sqr_comba8(BN_ULONG *r, BN_ULONG *a)
  387. # r3 contains r
  388. # r4 contains a
  389. #
  390. # Freely use registers r5,r6,r7,r8,r9,r10,r11 as follows:
  391. #
  392. # r5,r6 are the two BN_ULONGs being multiplied.
  393. # r7,r8 are the results of the 32x32 giving 64 bit multiply.
  394. # r9,r10, r11 are the equivalents of c1,c2, c3.
  395. #
  396. # Possible optimization of loading all 8 longs of a into registers
  397. # doesn't provide any speedup
  398. #
  399. xor r0,r0,r0 #set r0 = 0.Used in addze
  400. #instructions below.
  401. #sqr_add_c(a,0,c1,c2,c3);
  402. $LD r5,`0*$BNSZ`(r4)
  403. $UMULL r9,r5,r5 #1st iteration: no carries.
  404. $UMULH r10,r5,r5
  405. $ST r9,`0*$BNSZ`(r3) # r[0]=c1;
  406. #sqr_add_c2(a,1,0,c2,c3,c1);
  407. $LD r6,`1*$BNSZ`(r4)
  408. $UMULL r7,r5,r6
  409. $UMULH r8,r5,r6
  410. addc r10,r7,r10 #add the two register number
  411. adde r11,r8,r0 # (r8,r7) to the three register
  412. addze r9,r0 # number (r9,r11,r10).NOTE:r0=0
  413. addc r10,r7,r10 #add the two register number
  414. adde r11,r8,r11 # (r8,r7) to the three register
  415. addze r9,r9 # number (r9,r11,r10).
  416. $ST r10,`1*$BNSZ`(r3) # r[1]=c2
  417. #sqr_add_c(a,1,c3,c1,c2);
  418. $UMULL r7,r6,r6
  419. $UMULH r8,r6,r6
  420. addc r11,r7,r11
  421. adde r9,r8,r9
  422. addze r10,r0
  423. #sqr_add_c2(a,2,0,c3,c1,c2);
  424. $LD r6,`2*$BNSZ`(r4)
  425. $UMULL r7,r5,r6
  426. $UMULH r8,r5,r6
  427. addc r11,r7,r11
  428. adde r9,r8,r9
  429. addze r10,r10
  430. addc r11,r7,r11
  431. adde r9,r8,r9
  432. addze r10,r10
  433. $ST r11,`2*$BNSZ`(r3) #r[2]=c3
  434. #sqr_add_c2(a,3,0,c1,c2,c3);
  435. $LD r6,`3*$BNSZ`(r4) #r6 = a[3]. r5 is already a[0].
  436. $UMULL r7,r5,r6
  437. $UMULH r8,r5,r6
  438. addc r9,r7,r9
  439. adde r10,r8,r10
  440. addze r11,r0
  441. addc r9,r7,r9
  442. adde r10,r8,r10
  443. addze r11,r11
  444. #sqr_add_c2(a,2,1,c1,c2,c3);
  445. $LD r5,`1*$BNSZ`(r4)
  446. $LD r6,`2*$BNSZ`(r4)
  447. $UMULL r7,r5,r6
  448. $UMULH r8,r5,r6
  449. addc r9,r7,r9
  450. adde r10,r8,r10
  451. addze r11,r11
  452. addc r9,r7,r9
  453. adde r10,r8,r10
  454. addze r11,r11
  455. $ST r9,`3*$BNSZ`(r3) #r[3]=c1;
  456. #sqr_add_c(a,2,c2,c3,c1);
  457. $UMULL r7,r6,r6
  458. $UMULH r8,r6,r6
  459. addc r10,r7,r10
  460. adde r11,r8,r11
  461. addze r9,r0
  462. #sqr_add_c2(a,3,1,c2,c3,c1);
  463. $LD r6,`3*$BNSZ`(r4)
  464. $UMULL r7,r5,r6
  465. $UMULH r8,r5,r6
  466. addc r10,r7,r10
  467. adde r11,r8,r11
  468. addze r9,r9
  469. addc r10,r7,r10
  470. adde r11,r8,r11
  471. addze r9,r9
  472. #sqr_add_c2(a,4,0,c2,c3,c1);
  473. $LD r5,`0*$BNSZ`(r4)
  474. $LD r6,`4*$BNSZ`(r4)
  475. $UMULL r7,r5,r6
  476. $UMULH r8,r5,r6
  477. addc r10,r7,r10
  478. adde r11,r8,r11
  479. addze r9,r9
  480. addc r10,r7,r10
  481. adde r11,r8,r11
  482. addze r9,r9
  483. $ST r10,`4*$BNSZ`(r3) #r[4]=c2;
  484. #sqr_add_c2(a,5,0,c3,c1,c2);
  485. $LD r6,`5*$BNSZ`(r4)
  486. $UMULL r7,r5,r6
  487. $UMULH r8,r5,r6
  488. addc r11,r7,r11
  489. adde r9,r8,r9
  490. addze r10,r0
  491. addc r11,r7,r11
  492. adde r9,r8,r9
  493. addze r10,r10
  494. #sqr_add_c2(a,4,1,c3,c1,c2);
  495. $LD r5,`1*$BNSZ`(r4)
  496. $LD r6,`4*$BNSZ`(r4)
  497. $UMULL r7,r5,r6
  498. $UMULH r8,r5,r6
  499. addc r11,r7,r11
  500. adde r9,r8,r9
  501. addze r10,r10
  502. addc r11,r7,r11
  503. adde r9,r8,r9
  504. addze r10,r10
  505. #sqr_add_c2(a,3,2,c3,c1,c2);
  506. $LD r5,`2*$BNSZ`(r4)
  507. $LD r6,`3*$BNSZ`(r4)
  508. $UMULL r7,r5,r6
  509. $UMULH r8,r5,r6
  510. addc r11,r7,r11
  511. adde r9,r8,r9
  512. addze r10,r10
  513. addc r11,r7,r11
  514. adde r9,r8,r9
  515. addze r10,r10
  516. $ST r11,`5*$BNSZ`(r3) #r[5]=c3;
  517. #sqr_add_c(a,3,c1,c2,c3);
  518. $UMULL r7,r6,r6
  519. $UMULH r8,r6,r6
  520. addc r9,r7,r9
  521. adde r10,r8,r10
  522. addze r11,r0
  523. #sqr_add_c2(a,4,2,c1,c2,c3);
  524. $LD r6,`4*$BNSZ`(r4)
  525. $UMULL r7,r5,r6
  526. $UMULH r8,r5,r6
  527. addc r9,r7,r9
  528. adde r10,r8,r10
  529. addze r11,r11
  530. addc r9,r7,r9
  531. adde r10,r8,r10
  532. addze r11,r11
  533. #sqr_add_c2(a,5,1,c1,c2,c3);
  534. $LD r5,`1*$BNSZ`(r4)
  535. $LD r6,`5*$BNSZ`(r4)
  536. $UMULL r7,r5,r6
  537. $UMULH r8,r5,r6
  538. addc r9,r7,r9
  539. adde r10,r8,r10
  540. addze r11,r11
  541. addc r9,r7,r9
  542. adde r10,r8,r10
  543. addze r11,r11
  544. #sqr_add_c2(a,6,0,c1,c2,c3);
  545. $LD r5,`0*$BNSZ`(r4)
  546. $LD r6,`6*$BNSZ`(r4)
  547. $UMULL r7,r5,r6
  548. $UMULH r8,r5,r6
  549. addc r9,r7,r9
  550. adde r10,r8,r10
  551. addze r11,r11
  552. addc r9,r7,r9
  553. adde r10,r8,r10
  554. addze r11,r11
  555. $ST r9,`6*$BNSZ`(r3) #r[6]=c1;
  556. #sqr_add_c2(a,7,0,c2,c3,c1);
  557. $LD r6,`7*$BNSZ`(r4)
  558. $UMULL r7,r5,r6
  559. $UMULH r8,r5,r6
  560. addc r10,r7,r10
  561. adde r11,r8,r11
  562. addze r9,r0
  563. addc r10,r7,r10
  564. adde r11,r8,r11
  565. addze r9,r9
  566. #sqr_add_c2(a,6,1,c2,c3,c1);
  567. $LD r5,`1*$BNSZ`(r4)
  568. $LD r6,`6*$BNSZ`(r4)
  569. $UMULL r7,r5,r6
  570. $UMULH r8,r5,r6
  571. addc r10,r7,r10
  572. adde r11,r8,r11
  573. addze r9,r9
  574. addc r10,r7,r10
  575. adde r11,r8,r11
  576. addze r9,r9
  577. #sqr_add_c2(a,5,2,c2,c3,c1);
  578. $LD r5,`2*$BNSZ`(r4)
  579. $LD r6,`5*$BNSZ`(r4)
  580. $UMULL r7,r5,r6
  581. $UMULH r8,r5,r6
  582. addc r10,r7,r10
  583. adde r11,r8,r11
  584. addze r9,r9
  585. addc r10,r7,r10
  586. adde r11,r8,r11
  587. addze r9,r9
  588. #sqr_add_c2(a,4,3,c2,c3,c1);
  589. $LD r5,`3*$BNSZ`(r4)
  590. $LD r6,`4*$BNSZ`(r4)
  591. $UMULL r7,r5,r6
  592. $UMULH r8,r5,r6
  593. addc r10,r7,r10
  594. adde r11,r8,r11
  595. addze r9,r9
  596. addc r10,r7,r10
  597. adde r11,r8,r11
  598. addze r9,r9
  599. $ST r10,`7*$BNSZ`(r3) #r[7]=c2;
  600. #sqr_add_c(a,4,c3,c1,c2);
  601. $UMULL r7,r6,r6
  602. $UMULH r8,r6,r6
  603. addc r11,r7,r11
  604. adde r9,r8,r9
  605. addze r10,r0
  606. #sqr_add_c2(a,5,3,c3,c1,c2);
  607. $LD r6,`5*$BNSZ`(r4)
  608. $UMULL r7,r5,r6
  609. $UMULH r8,r5,r6
  610. addc r11,r7,r11
  611. adde r9,r8,r9
  612. addze r10,r10
  613. addc r11,r7,r11
  614. adde r9,r8,r9
  615. addze r10,r10
  616. #sqr_add_c2(a,6,2,c3,c1,c2);
  617. $LD r5,`2*$BNSZ`(r4)
  618. $LD r6,`6*$BNSZ`(r4)
  619. $UMULL r7,r5,r6
  620. $UMULH r8,r5,r6
  621. addc r11,r7,r11
  622. adde r9,r8,r9
  623. addze r10,r10
  624. addc r11,r7,r11
  625. adde r9,r8,r9
  626. addze r10,r10
  627. #sqr_add_c2(a,7,1,c3,c1,c2);
  628. $LD r5,`1*$BNSZ`(r4)
  629. $LD r6,`7*$BNSZ`(r4)
  630. $UMULL r7,r5,r6
  631. $UMULH r8,r5,r6
  632. addc r11,r7,r11
  633. adde r9,r8,r9
  634. addze r10,r10
  635. addc r11,r7,r11
  636. adde r9,r8,r9
  637. addze r10,r10
  638. $ST r11,`8*$BNSZ`(r3) #r[8]=c3;
  639. #sqr_add_c2(a,7,2,c1,c2,c3);
  640. $LD r5,`2*$BNSZ`(r4)
  641. $UMULL r7,r5,r6
  642. $UMULH r8,r5,r6
  643. addc r9,r7,r9
  644. adde r10,r8,r10
  645. addze r11,r0
  646. addc r9,r7,r9
  647. adde r10,r8,r10
  648. addze r11,r11
  649. #sqr_add_c2(a,6,3,c1,c2,c3);
  650. $LD r5,`3*$BNSZ`(r4)
  651. $LD r6,`6*$BNSZ`(r4)
  652. $UMULL r7,r5,r6
  653. $UMULH r8,r5,r6
  654. addc r9,r7,r9
  655. adde r10,r8,r10
  656. addze r11,r11
  657. addc r9,r7,r9
  658. adde r10,r8,r10
  659. addze r11,r11
  660. #sqr_add_c2(a,5,4,c1,c2,c3);
  661. $LD r5,`4*$BNSZ`(r4)
  662. $LD r6,`5*$BNSZ`(r4)
  663. $UMULL r7,r5,r6
  664. $UMULH r8,r5,r6
  665. addc r9,r7,r9
  666. adde r10,r8,r10
  667. addze r11,r11
  668. addc r9,r7,r9
  669. adde r10,r8,r10
  670. addze r11,r11
  671. $ST r9,`9*$BNSZ`(r3) #r[9]=c1;
  672. #sqr_add_c(a,5,c2,c3,c1);
  673. $UMULL r7,r6,r6
  674. $UMULH r8,r6,r6
  675. addc r10,r7,r10
  676. adde r11,r8,r11
  677. addze r9,r0
  678. #sqr_add_c2(a,6,4,c2,c3,c1);
  679. $LD r6,`6*$BNSZ`(r4)
  680. $UMULL r7,r5,r6
  681. $UMULH r8,r5,r6
  682. addc r10,r7,r10
  683. adde r11,r8,r11
  684. addze r9,r9
  685. addc r10,r7,r10
  686. adde r11,r8,r11
  687. addze r9,r9
  688. #sqr_add_c2(a,7,3,c2,c3,c1);
  689. $LD r5,`3*$BNSZ`(r4)
  690. $LD r6,`7*$BNSZ`(r4)
  691. $UMULL r7,r5,r6
  692. $UMULH r8,r5,r6
  693. addc r10,r7,r10
  694. adde r11,r8,r11
  695. addze r9,r9
  696. addc r10,r7,r10
  697. adde r11,r8,r11
  698. addze r9,r9
  699. $ST r10,`10*$BNSZ`(r3) #r[10]=c2;
  700. #sqr_add_c2(a,7,4,c3,c1,c2);
  701. $LD r5,`4*$BNSZ`(r4)
  702. $UMULL r7,r5,r6
  703. $UMULH r8,r5,r6
  704. addc r11,r7,r11
  705. adde r9,r8,r9
  706. addze r10,r0
  707. addc r11,r7,r11
  708. adde r9,r8,r9
  709. addze r10,r10
  710. #sqr_add_c2(a,6,5,c3,c1,c2);
  711. $LD r5,`5*$BNSZ`(r4)
  712. $LD r6,`6*$BNSZ`(r4)
  713. $UMULL r7,r5,r6
  714. $UMULH r8,r5,r6
  715. addc r11,r7,r11
  716. adde r9,r8,r9
  717. addze r10,r10
  718. addc r11,r7,r11
  719. adde r9,r8,r9
  720. addze r10,r10
  721. $ST r11,`11*$BNSZ`(r3) #r[11]=c3;
  722. #sqr_add_c(a,6,c1,c2,c3);
  723. $UMULL r7,r6,r6
  724. $UMULH r8,r6,r6
  725. addc r9,r7,r9
  726. adde r10,r8,r10
  727. addze r11,r0
  728. #sqr_add_c2(a,7,5,c1,c2,c3)
  729. $LD r6,`7*$BNSZ`(r4)
  730. $UMULL r7,r5,r6
  731. $UMULH r8,r5,r6
  732. addc r9,r7,r9
  733. adde r10,r8,r10
  734. addze r11,r11
  735. addc r9,r7,r9
  736. adde r10,r8,r10
  737. addze r11,r11
  738. $ST r9,`12*$BNSZ`(r3) #r[12]=c1;
  739. #sqr_add_c2(a,7,6,c2,c3,c1)
  740. $LD r5,`6*$BNSZ`(r4)
  741. $UMULL r7,r5,r6
  742. $UMULH r8,r5,r6
  743. addc r10,r7,r10
  744. adde r11,r8,r11
  745. addze r9,r0
  746. addc r10,r7,r10
  747. adde r11,r8,r11
  748. addze r9,r9
  749. $ST r10,`13*$BNSZ`(r3) #r[13]=c2;
  750. #sqr_add_c(a,7,c3,c1,c2);
  751. $UMULL r7,r6,r6
  752. $UMULH r8,r6,r6
  753. addc r11,r7,r11
  754. adde r9,r8,r9
  755. $ST r11,`14*$BNSZ`(r3) #r[14]=c3;
  756. $ST r9, `15*$BNSZ`(r3) #r[15]=c1;
  757. blr
  758. .long 0
  759. .byte 0,12,0x14,0,0,0,2,0
  760. .long 0
  761. .size .bn_sqr_comba8,.-.bn_sqr_comba8
  762. #
  763. # NOTE: The following label name should be changed to
  764. # "bn_mul_comba4" i.e. remove the first dot
  765. # for the gcc compiler. This should be automatically
  766. # done in the build
  767. #
  768. .align 4
  769. .bn_mul_comba4:
  770. #
  771. # This is an optimized version of the bn_mul_comba4 routine.
  772. #
  773. # void bn_mul_comba4(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
  774. # r3 contains r
  775. # r4 contains a
  776. # r5 contains b
  777. # r6, r7 are the 2 BN_ULONGs being multiplied.
  778. # r8, r9 are the results of the 32x32 giving 64 multiply.
  779. # r10, r11, r12 are the equivalents of c1, c2, and c3.
  780. #
  781. xor r0,r0,r0 #r0=0. Used in addze below.
  782. #mul_add_c(a[0],b[0],c1,c2,c3);
  783. $LD r6,`0*$BNSZ`(r4)
  784. $LD r7,`0*$BNSZ`(r5)
  785. $UMULL r10,r6,r7
  786. $UMULH r11,r6,r7
  787. $ST r10,`0*$BNSZ`(r3) #r[0]=c1
  788. #mul_add_c(a[0],b[1],c2,c3,c1);
  789. $LD r7,`1*$BNSZ`(r5)
  790. $UMULL r8,r6,r7
  791. $UMULH r9,r6,r7
  792. addc r11,r8,r11
  793. adde r12,r9,r0
  794. addze r10,r0
  795. #mul_add_c(a[1],b[0],c2,c3,c1);
  796. $LD r6, `1*$BNSZ`(r4)
  797. $LD r7, `0*$BNSZ`(r5)
  798. $UMULL r8,r6,r7
  799. $UMULH r9,r6,r7
  800. addc r11,r8,r11
  801. adde r12,r9,r12
  802. addze r10,r10
  803. $ST r11,`1*$BNSZ`(r3) #r[1]=c2
  804. #mul_add_c(a[2],b[0],c3,c1,c2);
  805. $LD r6,`2*$BNSZ`(r4)
  806. $UMULL r8,r6,r7
  807. $UMULH r9,r6,r7
  808. addc r12,r8,r12
  809. adde r10,r9,r10
  810. addze r11,r0
  811. #mul_add_c(a[1],b[1],c3,c1,c2);
  812. $LD r6,`1*$BNSZ`(r4)
  813. $LD r7,`1*$BNSZ`(r5)
  814. $UMULL r8,r6,r7
  815. $UMULH r9,r6,r7
  816. addc r12,r8,r12
  817. adde r10,r9,r10
  818. addze r11,r11
  819. #mul_add_c(a[0],b[2],c3,c1,c2);
  820. $LD r6,`0*$BNSZ`(r4)
  821. $LD r7,`2*$BNSZ`(r5)
  822. $UMULL r8,r6,r7
  823. $UMULH r9,r6,r7
  824. addc r12,r8,r12
  825. adde r10,r9,r10
  826. addze r11,r11
  827. $ST r12,`2*$BNSZ`(r3) #r[2]=c3
  828. #mul_add_c(a[0],b[3],c1,c2,c3);
  829. $LD r7,`3*$BNSZ`(r5)
  830. $UMULL r8,r6,r7
  831. $UMULH r9,r6,r7
  832. addc r10,r8,r10
  833. adde r11,r9,r11
  834. addze r12,r0
  835. #mul_add_c(a[1],b[2],c1,c2,c3);
  836. $LD r6,`1*$BNSZ`(r4)
  837. $LD r7,`2*$BNSZ`(r5)
  838. $UMULL r8,r6,r7
  839. $UMULH r9,r6,r7
  840. addc r10,r8,r10
  841. adde r11,r9,r11
  842. addze r12,r12
  843. #mul_add_c(a[2],b[1],c1,c2,c3);
  844. $LD r6,`2*$BNSZ`(r4)
  845. $LD r7,`1*$BNSZ`(r5)
  846. $UMULL r8,r6,r7
  847. $UMULH r9,r6,r7
  848. addc r10,r8,r10
  849. adde r11,r9,r11
  850. addze r12,r12
  851. #mul_add_c(a[3],b[0],c1,c2,c3);
  852. $LD r6,`3*$BNSZ`(r4)
  853. $LD r7,`0*$BNSZ`(r5)
  854. $UMULL r8,r6,r7
  855. $UMULH r9,r6,r7
  856. addc r10,r8,r10
  857. adde r11,r9,r11
  858. addze r12,r12
  859. $ST r10,`3*$BNSZ`(r3) #r[3]=c1
  860. #mul_add_c(a[3],b[1],c2,c3,c1);
  861. $LD r7,`1*$BNSZ`(r5)
  862. $UMULL r8,r6,r7
  863. $UMULH r9,r6,r7
  864. addc r11,r8,r11
  865. adde r12,r9,r12
  866. addze r10,r0
  867. #mul_add_c(a[2],b[2],c2,c3,c1);
  868. $LD r6,`2*$BNSZ`(r4)
  869. $LD r7,`2*$BNSZ`(r5)
  870. $UMULL r8,r6,r7
  871. $UMULH r9,r6,r7
  872. addc r11,r8,r11
  873. adde r12,r9,r12
  874. addze r10,r10
  875. #mul_add_c(a[1],b[3],c2,c3,c1);
  876. $LD r6,`1*$BNSZ`(r4)
  877. $LD r7,`3*$BNSZ`(r5)
  878. $UMULL r8,r6,r7
  879. $UMULH r9,r6,r7
  880. addc r11,r8,r11
  881. adde r12,r9,r12
  882. addze r10,r10
  883. $ST r11,`4*$BNSZ`(r3) #r[4]=c2
  884. #mul_add_c(a[2],b[3],c3,c1,c2);
  885. $LD r6,`2*$BNSZ`(r4)
  886. $UMULL r8,r6,r7
  887. $UMULH r9,r6,r7
  888. addc r12,r8,r12
  889. adde r10,r9,r10
  890. addze r11,r0
  891. #mul_add_c(a[3],b[2],c3,c1,c2);
  892. $LD r6,`3*$BNSZ`(r4)
  893. $LD r7,`2*$BNSZ`(r5)
  894. $UMULL r8,r6,r7
  895. $UMULH r9,r6,r7
  896. addc r12,r8,r12
  897. adde r10,r9,r10
  898. addze r11,r11
  899. $ST r12,`5*$BNSZ`(r3) #r[5]=c3
  900. #mul_add_c(a[3],b[3],c1,c2,c3);
  901. $LD r7,`3*$BNSZ`(r5)
  902. $UMULL r8,r6,r7
  903. $UMULH r9,r6,r7
  904. addc r10,r8,r10
  905. adde r11,r9,r11
  906. $ST r10,`6*$BNSZ`(r3) #r[6]=c1
  907. $ST r11,`7*$BNSZ`(r3) #r[7]=c2
  908. blr
  909. .long 0
  910. .byte 0,12,0x14,0,0,0,3,0
  911. .long 0
  912. .size .bn_mul_comba4,.-.bn_mul_comba4
  913. #
  914. # NOTE: The following label name should be changed to
  915. # "bn_mul_comba8" i.e. remove the first dot
  916. # for the gcc compiler. This should be automatically
  917. # done in the build
  918. #
  919. .align 4
  920. .bn_mul_comba8:
  921. #
  922. # Optimized version of the bn_mul_comba8 routine.
  923. #
  924. # void bn_mul_comba8(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
  925. # r3 contains r
  926. # r4 contains a
  927. # r5 contains b
  928. # r6, r7 are the 2 BN_ULONGs being multiplied.
  929. # r8, r9 are the results of the 32x32 giving 64 multiply.
  930. # r10, r11, r12 are the equivalents of c1, c2, and c3.
  931. #
  932. xor r0,r0,r0 #r0=0. Used in addze below.
  933. #mul_add_c(a[0],b[0],c1,c2,c3);
  934. $LD r6,`0*$BNSZ`(r4) #a[0]
  935. $LD r7,`0*$BNSZ`(r5) #b[0]
  936. $UMULL r10,r6,r7
  937. $UMULH r11,r6,r7
  938. $ST r10,`0*$BNSZ`(r3) #r[0]=c1;
  939. #mul_add_c(a[0],b[1],c2,c3,c1);
  940. $LD r7,`1*$BNSZ`(r5)
  941. $UMULL r8,r6,r7
  942. $UMULH r9,r6,r7
  943. addc r11,r11,r8
  944. addze r12,r9 # since we didn't set r12 to zero before.
  945. addze r10,r0
  946. #mul_add_c(a[1],b[0],c2,c3,c1);
  947. $LD r6,`1*$BNSZ`(r4)
  948. $LD r7,`0*$BNSZ`(r5)
  949. $UMULL r8,r6,r7
  950. $UMULH r9,r6,r7
  951. addc r11,r11,r8
  952. adde r12,r12,r9
  953. addze r10,r10
  954. $ST r11,`1*$BNSZ`(r3) #r[1]=c2;
  955. #mul_add_c(a[2],b[0],c3,c1,c2);
  956. $LD r6,`2*$BNSZ`(r4)
  957. $UMULL r8,r6,r7
  958. $UMULH r9,r6,r7
  959. addc r12,r12,r8
  960. adde r10,r10,r9
  961. addze r11,r0
  962. #mul_add_c(a[1],b[1],c3,c1,c2);
  963. $LD r6,`1*$BNSZ`(r4)
  964. $LD r7,`1*$BNSZ`(r5)
  965. $UMULL r8,r6,r7
  966. $UMULH r9,r6,r7
  967. addc r12,r12,r8
  968. adde r10,r10,r9
  969. addze r11,r11
  970. #mul_add_c(a[0],b[2],c3,c1,c2);
  971. $LD r6,`0*$BNSZ`(r4)
  972. $LD r7,`2*$BNSZ`(r5)
  973. $UMULL r8,r6,r7
  974. $UMULH r9,r6,r7
  975. addc r12,r12,r8
  976. adde r10,r10,r9
  977. addze r11,r11
  978. $ST r12,`2*$BNSZ`(r3) #r[2]=c3;
  979. #mul_add_c(a[0],b[3],c1,c2,c3);
  980. $LD r7,`3*$BNSZ`(r5)
  981. $UMULL r8,r6,r7
  982. $UMULH r9,r6,r7
  983. addc r10,r10,r8
  984. adde r11,r11,r9
  985. addze r12,r0
  986. #mul_add_c(a[1],b[2],c1,c2,c3);
  987. $LD r6,`1*$BNSZ`(r4)
  988. $LD r7,`2*$BNSZ`(r5)
  989. $UMULL r8,r6,r7
  990. $UMULH r9,r6,r7
  991. addc r10,r10,r8
  992. adde r11,r11,r9
  993. addze r12,r12
  994. #mul_add_c(a[2],b[1],c1,c2,c3);
  995. $LD r6,`2*$BNSZ`(r4)
  996. $LD r7,`1*$BNSZ`(r5)
  997. $UMULL r8,r6,r7
  998. $UMULH r9,r6,r7
  999. addc r10,r10,r8
  1000. adde r11,r11,r9
  1001. addze r12,r12
  1002. #mul_add_c(a[3],b[0],c1,c2,c3);
  1003. $LD r6,`3*$BNSZ`(r4)
  1004. $LD r7,`0*$BNSZ`(r5)
  1005. $UMULL r8,r6,r7
  1006. $UMULH r9,r6,r7
  1007. addc r10,r10,r8
  1008. adde r11,r11,r9
  1009. addze r12,r12
  1010. $ST r10,`3*$BNSZ`(r3) #r[3]=c1;
  1011. #mul_add_c(a[4],b[0],c2,c3,c1);
  1012. $LD r6,`4*$BNSZ`(r4)
  1013. $UMULL r8,r6,r7
  1014. $UMULH r9,r6,r7
  1015. addc r11,r11,r8
  1016. adde r12,r12,r9
  1017. addze r10,r0
  1018. #mul_add_c(a[3],b[1],c2,c3,c1);
  1019. $LD r6,`3*$BNSZ`(r4)
  1020. $LD r7,`1*$BNSZ`(r5)
  1021. $UMULL r8,r6,r7
  1022. $UMULH r9,r6,r7
  1023. addc r11,r11,r8
  1024. adde r12,r12,r9
  1025. addze r10,r10
  1026. #mul_add_c(a[2],b[2],c2,c3,c1);
  1027. $LD r6,`2*$BNSZ`(r4)
  1028. $LD r7,`2*$BNSZ`(r5)
  1029. $UMULL r8,r6,r7
  1030. $UMULH r9,r6,r7
  1031. addc r11,r11,r8
  1032. adde r12,r12,r9
  1033. addze r10,r10
  1034. #mul_add_c(a[1],b[3],c2,c3,c1);
  1035. $LD r6,`1*$BNSZ`(r4)
  1036. $LD r7,`3*$BNSZ`(r5)
  1037. $UMULL r8,r6,r7
  1038. $UMULH r9,r6,r7
  1039. addc r11,r11,r8
  1040. adde r12,r12,r9
  1041. addze r10,r10
  1042. #mul_add_c(a[0],b[4],c2,c3,c1);
  1043. $LD r6,`0*$BNSZ`(r4)
  1044. $LD r7,`4*$BNSZ`(r5)
  1045. $UMULL r8,r6,r7
  1046. $UMULH r9,r6,r7
  1047. addc r11,r11,r8
  1048. adde r12,r12,r9
  1049. addze r10,r10
  1050. $ST r11,`4*$BNSZ`(r3) #r[4]=c2;
  1051. #mul_add_c(a[0],b[5],c3,c1,c2);
  1052. $LD r7,`5*$BNSZ`(r5)
  1053. $UMULL r8,r6,r7
  1054. $UMULH r9,r6,r7
  1055. addc r12,r12,r8
  1056. adde r10,r10,r9
  1057. addze r11,r0
  1058. #mul_add_c(a[1],b[4],c3,c1,c2);
  1059. $LD r6,`1*$BNSZ`(r4)
  1060. $LD r7,`4*$BNSZ`(r5)
  1061. $UMULL r8,r6,r7
  1062. $UMULH r9,r6,r7
  1063. addc r12,r12,r8
  1064. adde r10,r10,r9
  1065. addze r11,r11
  1066. #mul_add_c(a[2],b[3],c3,c1,c2);
  1067. $LD r6,`2*$BNSZ`(r4)
  1068. $LD r7,`3*$BNSZ`(r5)
  1069. $UMULL r8,r6,r7
  1070. $UMULH r9,r6,r7
  1071. addc r12,r12,r8
  1072. adde r10,r10,r9
  1073. addze r11,r11
  1074. #mul_add_c(a[3],b[2],c3,c1,c2);
  1075. $LD r6,`3*$BNSZ`(r4)
  1076. $LD r7,`2*$BNSZ`(r5)
  1077. $UMULL r8,r6,r7
  1078. $UMULH r9,r6,r7
  1079. addc r12,r12,r8
  1080. adde r10,r10,r9
  1081. addze r11,r11
  1082. #mul_add_c(a[4],b[1],c3,c1,c2);
  1083. $LD r6,`4*$BNSZ`(r4)
  1084. $LD r7,`1*$BNSZ`(r5)
  1085. $UMULL r8,r6,r7
  1086. $UMULH r9,r6,r7
  1087. addc r12,r12,r8
  1088. adde r10,r10,r9
  1089. addze r11,r11
  1090. #mul_add_c(a[5],b[0],c3,c1,c2);
  1091. $LD r6,`5*$BNSZ`(r4)
  1092. $LD r7,`0*$BNSZ`(r5)
  1093. $UMULL r8,r6,r7
  1094. $UMULH r9,r6,r7
  1095. addc r12,r12,r8
  1096. adde r10,r10,r9
  1097. addze r11,r11
  1098. $ST r12,`5*$BNSZ`(r3) #r[5]=c3;
  1099. #mul_add_c(a[6],b[0],c1,c2,c3);
  1100. $LD r6,`6*$BNSZ`(r4)
  1101. $UMULL r8,r6,r7
  1102. $UMULH r9,r6,r7
  1103. addc r10,r10,r8
  1104. adde r11,r11,r9
  1105. addze r12,r0
  1106. #mul_add_c(a[5],b[1],c1,c2,c3);
  1107. $LD r6,`5*$BNSZ`(r4)
  1108. $LD r7,`1*$BNSZ`(r5)
  1109. $UMULL r8,r6,r7
  1110. $UMULH r9,r6,r7
  1111. addc r10,r10,r8
  1112. adde r11,r11,r9
  1113. addze r12,r12
  1114. #mul_add_c(a[4],b[2],c1,c2,c3);
  1115. $LD r6,`4*$BNSZ`(r4)
  1116. $LD r7,`2*$BNSZ`(r5)
  1117. $UMULL r8,r6,r7
  1118. $UMULH r9,r6,r7
  1119. addc r10,r10,r8
  1120. adde r11,r11,r9
  1121. addze r12,r12
  1122. #mul_add_c(a[3],b[3],c1,c2,c3);
  1123. $LD r6,`3*$BNSZ`(r4)
  1124. $LD r7,`3*$BNSZ`(r5)
  1125. $UMULL r8,r6,r7
  1126. $UMULH r9,r6,r7
  1127. addc r10,r10,r8
  1128. adde r11,r11,r9
  1129. addze r12,r12
  1130. #mul_add_c(a[2],b[4],c1,c2,c3);
  1131. $LD r6,`2*$BNSZ`(r4)
  1132. $LD r7,`4*$BNSZ`(r5)
  1133. $UMULL r8,r6,r7
  1134. $UMULH r9,r6,r7
  1135. addc r10,r10,r8
  1136. adde r11,r11,r9
  1137. addze r12,r12
  1138. #mul_add_c(a[1],b[5],c1,c2,c3);
  1139. $LD r6,`1*$BNSZ`(r4)
  1140. $LD r7,`5*$BNSZ`(r5)
  1141. $UMULL r8,r6,r7
  1142. $UMULH r9,r6,r7
  1143. addc r10,r10,r8
  1144. adde r11,r11,r9
  1145. addze r12,r12
  1146. #mul_add_c(a[0],b[6],c1,c2,c3);
  1147. $LD r6,`0*$BNSZ`(r4)
  1148. $LD r7,`6*$BNSZ`(r5)
  1149. $UMULL r8,r6,r7
  1150. $UMULH r9,r6,r7
  1151. addc r10,r10,r8
  1152. adde r11,r11,r9
  1153. addze r12,r12
  1154. $ST r10,`6*$BNSZ`(r3) #r[6]=c1;
  1155. #mul_add_c(a[0],b[7],c2,c3,c1);
  1156. $LD r7,`7*$BNSZ`(r5)
  1157. $UMULL r8,r6,r7
  1158. $UMULH r9,r6,r7
  1159. addc r11,r11,r8
  1160. adde r12,r12,r9
  1161. addze r10,r0
  1162. #mul_add_c(a[1],b[6],c2,c3,c1);
  1163. $LD r6,`1*$BNSZ`(r4)
  1164. $LD r7,`6*$BNSZ`(r5)
  1165. $UMULL r8,r6,r7
  1166. $UMULH r9,r6,r7
  1167. addc r11,r11,r8
  1168. adde r12,r12,r9
  1169. addze r10,r10
  1170. #mul_add_c(a[2],b[5],c2,c3,c1);
  1171. $LD r6,`2*$BNSZ`(r4)
  1172. $LD r7,`5*$BNSZ`(r5)
  1173. $UMULL r8,r6,r7
  1174. $UMULH r9,r6,r7
  1175. addc r11,r11,r8
  1176. adde r12,r12,r9
  1177. addze r10,r10
  1178. #mul_add_c(a[3],b[4],c2,c3,c1);
  1179. $LD r6,`3*$BNSZ`(r4)
  1180. $LD r7,`4*$BNSZ`(r5)
  1181. $UMULL r8,r6,r7
  1182. $UMULH r9,r6,r7
  1183. addc r11,r11,r8
  1184. adde r12,r12,r9
  1185. addze r10,r10
  1186. #mul_add_c(a[4],b[3],c2,c3,c1);
  1187. $LD r6,`4*$BNSZ`(r4)
  1188. $LD r7,`3*$BNSZ`(r5)
  1189. $UMULL r8,r6,r7
  1190. $UMULH r9,r6,r7
  1191. addc r11,r11,r8
  1192. adde r12,r12,r9
  1193. addze r10,r10
  1194. #mul_add_c(a[5],b[2],c2,c3,c1);
  1195. $LD r6,`5*$BNSZ`(r4)
  1196. $LD r7,`2*$BNSZ`(r5)
  1197. $UMULL r8,r6,r7
  1198. $UMULH r9,r6,r7
  1199. addc r11,r11,r8
  1200. adde r12,r12,r9
  1201. addze r10,r10
  1202. #mul_add_c(a[6],b[1],c2,c3,c1);
  1203. $LD r6,`6*$BNSZ`(r4)
  1204. $LD r7,`1*$BNSZ`(r5)
  1205. $UMULL r8,r6,r7
  1206. $UMULH r9,r6,r7
  1207. addc r11,r11,r8
  1208. adde r12,r12,r9
  1209. addze r10,r10
  1210. #mul_add_c(a[7],b[0],c2,c3,c1);
  1211. $LD r6,`7*$BNSZ`(r4)
  1212. $LD r7,`0*$BNSZ`(r5)
  1213. $UMULL r8,r6,r7
  1214. $UMULH r9,r6,r7
  1215. addc r11,r11,r8
  1216. adde r12,r12,r9
  1217. addze r10,r10
  1218. $ST r11,`7*$BNSZ`(r3) #r[7]=c2;
  1219. #mul_add_c(a[7],b[1],c3,c1,c2);
  1220. $LD r7,`1*$BNSZ`(r5)
  1221. $UMULL r8,r6,r7
  1222. $UMULH r9,r6,r7
  1223. addc r12,r12,r8
  1224. adde r10,r10,r9
  1225. addze r11,r0
  1226. #mul_add_c(a[6],b[2],c3,c1,c2);
  1227. $LD r6,`6*$BNSZ`(r4)
  1228. $LD r7,`2*$BNSZ`(r5)
  1229. $UMULL r8,r6,r7
  1230. $UMULH r9,r6,r7
  1231. addc r12,r12,r8
  1232. adde r10,r10,r9
  1233. addze r11,r11
  1234. #mul_add_c(a[5],b[3],c3,c1,c2);
  1235. $LD r6,`5*$BNSZ`(r4)
  1236. $LD r7,`3*$BNSZ`(r5)
  1237. $UMULL r8,r6,r7
  1238. $UMULH r9,r6,r7
  1239. addc r12,r12,r8
  1240. adde r10,r10,r9
  1241. addze r11,r11
  1242. #mul_add_c(a[4],b[4],c3,c1,c2);
  1243. $LD r6,`4*$BNSZ`(r4)
  1244. $LD r7,`4*$BNSZ`(r5)
  1245. $UMULL r8,r6,r7
  1246. $UMULH r9,r6,r7
  1247. addc r12,r12,r8
  1248. adde r10,r10,r9
  1249. addze r11,r11
  1250. #mul_add_c(a[3],b[5],c3,c1,c2);
  1251. $LD r6,`3*$BNSZ`(r4)
  1252. $LD r7,`5*$BNSZ`(r5)
  1253. $UMULL r8,r6,r7
  1254. $UMULH r9,r6,r7
  1255. addc r12,r12,r8
  1256. adde r10,r10,r9
  1257. addze r11,r11
  1258. #mul_add_c(a[2],b[6],c3,c1,c2);
  1259. $LD r6,`2*$BNSZ`(r4)
  1260. $LD r7,`6*$BNSZ`(r5)
  1261. $UMULL r8,r6,r7
  1262. $UMULH r9,r6,r7
  1263. addc r12,r12,r8
  1264. adde r10,r10,r9
  1265. addze r11,r11
  1266. #mul_add_c(a[1],b[7],c3,c1,c2);
  1267. $LD r6,`1*$BNSZ`(r4)
  1268. $LD r7,`7*$BNSZ`(r5)
  1269. $UMULL r8,r6,r7
  1270. $UMULH r9,r6,r7
  1271. addc r12,r12,r8
  1272. adde r10,r10,r9
  1273. addze r11,r11
  1274. $ST r12,`8*$BNSZ`(r3) #r[8]=c3;
  1275. #mul_add_c(a[2],b[7],c1,c2,c3);
  1276. $LD r6,`2*$BNSZ`(r4)
  1277. $UMULL r8,r6,r7
  1278. $UMULH r9,r6,r7
  1279. addc r10,r10,r8
  1280. adde r11,r11,r9
  1281. addze r12,r0
  1282. #mul_add_c(a[3],b[6],c1,c2,c3);
  1283. $LD r6,`3*$BNSZ`(r4)
  1284. $LD r7,`6*$BNSZ`(r5)
  1285. $UMULL r8,r6,r7
  1286. $UMULH r9,r6,r7
  1287. addc r10,r10,r8
  1288. adde r11,r11,r9
  1289. addze r12,r12
  1290. #mul_add_c(a[4],b[5],c1,c2,c3);
  1291. $LD r6,`4*$BNSZ`(r4)
  1292. $LD r7,`5*$BNSZ`(r5)
  1293. $UMULL r8,r6,r7
  1294. $UMULH r9,r6,r7
  1295. addc r10,r10,r8
  1296. adde r11,r11,r9
  1297. addze r12,r12
  1298. #mul_add_c(a[5],b[4],c1,c2,c3);
  1299. $LD r6,`5*$BNSZ`(r4)
  1300. $LD r7,`4*$BNSZ`(r5)
  1301. $UMULL r8,r6,r7
  1302. $UMULH r9,r6,r7
  1303. addc r10,r10,r8
  1304. adde r11,r11,r9
  1305. addze r12,r12
  1306. #mul_add_c(a[6],b[3],c1,c2,c3);
  1307. $LD r6,`6*$BNSZ`(r4)
  1308. $LD r7,`3*$BNSZ`(r5)
  1309. $UMULL r8,r6,r7
  1310. $UMULH r9,r6,r7
  1311. addc r10,r10,r8
  1312. adde r11,r11,r9
  1313. addze r12,r12
  1314. #mul_add_c(a[7],b[2],c1,c2,c3);
  1315. $LD r6,`7*$BNSZ`(r4)
  1316. $LD r7,`2*$BNSZ`(r5)
  1317. $UMULL r8,r6,r7
  1318. $UMULH r9,r6,r7
  1319. addc r10,r10,r8
  1320. adde r11,r11,r9
  1321. addze r12,r12
  1322. $ST r10,`9*$BNSZ`(r3) #r[9]=c1;
  1323. #mul_add_c(a[7],b[3],c2,c3,c1);
  1324. $LD r7,`3*$BNSZ`(r5)
  1325. $UMULL r8,r6,r7
  1326. $UMULH r9,r6,r7
  1327. addc r11,r11,r8
  1328. adde r12,r12,r9
  1329. addze r10,r0
  1330. #mul_add_c(a[6],b[4],c2,c3,c1);
  1331. $LD r6,`6*$BNSZ`(r4)
  1332. $LD r7,`4*$BNSZ`(r5)
  1333. $UMULL r8,r6,r7
  1334. $UMULH r9,r6,r7
  1335. addc r11,r11,r8
  1336. adde r12,r12,r9
  1337. addze r10,r10
  1338. #mul_add_c(a[5],b[5],c2,c3,c1);
  1339. $LD r6,`5*$BNSZ`(r4)
  1340. $LD r7,`5*$BNSZ`(r5)
  1341. $UMULL r8,r6,r7
  1342. $UMULH r9,r6,r7
  1343. addc r11,r11,r8
  1344. adde r12,r12,r9
  1345. addze r10,r10
  1346. #mul_add_c(a[4],b[6],c2,c3,c1);
  1347. $LD r6,`4*$BNSZ`(r4)
  1348. $LD r7,`6*$BNSZ`(r5)
  1349. $UMULL r8,r6,r7
  1350. $UMULH r9,r6,r7
  1351. addc r11,r11,r8
  1352. adde r12,r12,r9
  1353. addze r10,r10
  1354. #mul_add_c(a[3],b[7],c2,c3,c1);
  1355. $LD r6,`3*$BNSZ`(r4)
  1356. $LD r7,`7*$BNSZ`(r5)
  1357. $UMULL r8,r6,r7
  1358. $UMULH r9,r6,r7
  1359. addc r11,r11,r8
  1360. adde r12,r12,r9
  1361. addze r10,r10
  1362. $ST r11,`10*$BNSZ`(r3) #r[10]=c2;
  1363. #mul_add_c(a[4],b[7],c3,c1,c2);
  1364. $LD r6,`4*$BNSZ`(r4)
  1365. $UMULL r8,r6,r7
  1366. $UMULH r9,r6,r7
  1367. addc r12,r12,r8
  1368. adde r10,r10,r9
  1369. addze r11,r0
  1370. #mul_add_c(a[5],b[6],c3,c1,c2);
  1371. $LD r6,`5*$BNSZ`(r4)
  1372. $LD r7,`6*$BNSZ`(r5)
  1373. $UMULL r8,r6,r7
  1374. $UMULH r9,r6,r7
  1375. addc r12,r12,r8
  1376. adde r10,r10,r9
  1377. addze r11,r11
  1378. #mul_add_c(a[6],b[5],c3,c1,c2);
  1379. $LD r6,`6*$BNSZ`(r4)
  1380. $LD r7,`5*$BNSZ`(r5)
  1381. $UMULL r8,r6,r7
  1382. $UMULH r9,r6,r7
  1383. addc r12,r12,r8
  1384. adde r10,r10,r9
  1385. addze r11,r11
  1386. #mul_add_c(a[7],b[4],c3,c1,c2);
  1387. $LD r6,`7*$BNSZ`(r4)
  1388. $LD r7,`4*$BNSZ`(r5)
  1389. $UMULL r8,r6,r7
  1390. $UMULH r9,r6,r7
  1391. addc r12,r12,r8
  1392. adde r10,r10,r9
  1393. addze r11,r11
  1394. $ST r12,`11*$BNSZ`(r3) #r[11]=c3;
  1395. #mul_add_c(a[7],b[5],c1,c2,c3);
  1396. $LD r7,`5*$BNSZ`(r5)
  1397. $UMULL r8,r6,r7
  1398. $UMULH r9,r6,r7
  1399. addc r10,r10,r8
  1400. adde r11,r11,r9
  1401. addze r12,r0
  1402. #mul_add_c(a[6],b[6],c1,c2,c3);
  1403. $LD r6,`6*$BNSZ`(r4)
  1404. $LD r7,`6*$BNSZ`(r5)
  1405. $UMULL r8,r6,r7
  1406. $UMULH r9,r6,r7
  1407. addc r10,r10,r8
  1408. adde r11,r11,r9
  1409. addze r12,r12
  1410. #mul_add_c(a[5],b[7],c1,c2,c3);
  1411. $LD r6,`5*$BNSZ`(r4)
  1412. $LD r7,`7*$BNSZ`(r5)
  1413. $UMULL r8,r6,r7
  1414. $UMULH r9,r6,r7
  1415. addc r10,r10,r8
  1416. adde r11,r11,r9
  1417. addze r12,r12
  1418. $ST r10,`12*$BNSZ`(r3) #r[12]=c1;
  1419. #mul_add_c(a[6],b[7],c2,c3,c1);
  1420. $LD r6,`6*$BNSZ`(r4)
  1421. $UMULL r8,r6,r7
  1422. $UMULH r9,r6,r7
  1423. addc r11,r11,r8
  1424. adde r12,r12,r9
  1425. addze r10,r0
  1426. #mul_add_c(a[7],b[6],c2,c3,c1);
  1427. $LD r6,`7*$BNSZ`(r4)
  1428. $LD r7,`6*$BNSZ`(r5)
  1429. $UMULL r8,r6,r7
  1430. $UMULH r9,r6,r7
  1431. addc r11,r11,r8
  1432. adde r12,r12,r9
  1433. addze r10,r10
  1434. $ST r11,`13*$BNSZ`(r3) #r[13]=c2;
  1435. #mul_add_c(a[7],b[7],c3,c1,c2);
  1436. $LD r7,`7*$BNSZ`(r5)
  1437. $UMULL r8,r6,r7
  1438. $UMULH r9,r6,r7
  1439. addc r12,r12,r8
  1440. adde r10,r10,r9
  1441. $ST r12,`14*$BNSZ`(r3) #r[14]=c3;
  1442. $ST r10,`15*$BNSZ`(r3) #r[15]=c1;
  1443. blr
  1444. .long 0
  1445. .byte 0,12,0x14,0,0,0,3,0
  1446. .long 0
  1447. .size .bn_mul_comba8,.-.bn_mul_comba8
  1448. #
  1449. # NOTE: The following label name should be changed to
  1450. # "bn_sub_words" i.e. remove the first dot
  1451. # for the gcc compiler. This should be automatically
  1452. # done in the build
  1453. #
  1454. #
  1455. .align 4
  1456. .bn_sub_words:
  1457. #
  1458. # Handcoded version of bn_sub_words
  1459. #
  1460. #BN_ULONG bn_sub_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
  1461. #
  1462. # r3 = r
  1463. # r4 = a
  1464. # r5 = b
  1465. # r6 = n
  1466. #
  1467. # Note: No loop unrolling done since this is not a performance
  1468. # critical loop.
  1469. xor r0,r0,r0 #set r0 = 0
  1470. #
  1471. # check for r6 = 0 AND set carry bit.
  1472. #
  1473. subfc. r7,r0,r6 # If r6 is 0 then result is 0.
  1474. # if r6 > 0 then result !=0
  1475. # In either case carry bit is set.
  1476. beq Lppcasm_sub_adios
  1477. addi r4,r4,-$BNSZ
  1478. addi r3,r3,-$BNSZ
  1479. addi r5,r5,-$BNSZ
  1480. mtctr r6
  1481. Lppcasm_sub_mainloop:
  1482. $LDU r7,$BNSZ(r4)
  1483. $LDU r8,$BNSZ(r5)
  1484. subfe r6,r8,r7 # r6 = r7+carry bit + onescomplement(r8)
  1485. # if carry = 1 this is r7-r8. Else it
  1486. # is r7-r8 -1 as we need.
  1487. $STU r6,$BNSZ(r3)
  1488. bdnz Lppcasm_sub_mainloop
  1489. Lppcasm_sub_adios:
  1490. subfze r3,r0 # if carry bit is set then r3 = 0 else -1
  1491. andi. r3,r3,1 # keep only last bit.
  1492. blr
  1493. .long 0
  1494. .byte 0,12,0x14,0,0,0,4,0
  1495. .long 0
  1496. .size .bn_sub_words,.-.bn_sub_words
  1497. #
  1498. # NOTE: The following label name should be changed to
  1499. # "bn_add_words" i.e. remove the first dot
  1500. # for the gcc compiler. This should be automatically
  1501. # done in the build
  1502. #
  1503. .align 4
  1504. .bn_add_words:
  1505. #
  1506. # Handcoded version of bn_add_words
  1507. #
  1508. #BN_ULONG bn_add_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
  1509. #
  1510. # r3 = r
  1511. # r4 = a
  1512. # r5 = b
  1513. # r6 = n
  1514. #
  1515. # Note: No loop unrolling done since this is not a performance
  1516. # critical loop.
  1517. xor r0,r0,r0
  1518. #
  1519. # check for r6 = 0. Is this needed?
  1520. #
  1521. addic. r6,r6,0 #test r6 and clear carry bit.
  1522. beq Lppcasm_add_adios
  1523. addi r4,r4,-$BNSZ
  1524. addi r3,r3,-$BNSZ
  1525. addi r5,r5,-$BNSZ
  1526. mtctr r6
  1527. Lppcasm_add_mainloop:
  1528. $LDU r7,$BNSZ(r4)
  1529. $LDU r8,$BNSZ(r5)
  1530. adde r8,r7,r8
  1531. $STU r8,$BNSZ(r3)
  1532. bdnz Lppcasm_add_mainloop
  1533. Lppcasm_add_adios:
  1534. addze r3,r0 #return carry bit.
  1535. blr
  1536. .long 0
  1537. .byte 0,12,0x14,0,0,0,4,0
  1538. .long 0
  1539. .size .bn_add_words,.-.bn_add_words
  1540. #
  1541. # NOTE: The following label name should be changed to
  1542. # "bn_div_words" i.e. remove the first dot
  1543. # for the gcc compiler. This should be automatically
  1544. # done in the build
  1545. #
  1546. .align 4
  1547. .bn_div_words:
  1548. #
  1549. # This is a cleaned up version of code generated by
  1550. # the AIX compiler. The only optimization is to use
  1551. # the PPC instruction to count leading zeros instead
  1552. # of call to num_bits_word. Since this was compiled
  1553. # only at level -O2 we can possibly squeeze it more?
  1554. #
  1555. # r3 = h
  1556. # r4 = l
  1557. # r5 = d
  1558. $UCMPI 0,r5,0 # compare r5 and 0
  1559. bne Lppcasm_div1 # proceed if d!=0
  1560. li r3,-1 # d=0 return -1
  1561. blr
  1562. Lppcasm_div1:
  1563. xor r0,r0,r0 #r0=0
  1564. li r8,$BITS
  1565. $CNTLZ. r7,r5 #r7 = num leading 0s in d.
  1566. beq Lppcasm_div2 #proceed if no leading zeros
  1567. subf r8,r7,r8 #r8 = BN_num_bits_word(d)
  1568. $SHR. r9,r3,r8 #are there any bits above r8'th?
  1569. $TR 16,r9,r0 #if there're, signal to dump core...
  1570. Lppcasm_div2:
  1571. $UCMP 0,r3,r5 #h>=d?
  1572. blt Lppcasm_div3 #goto Lppcasm_div3 if not
  1573. subf r3,r5,r3 #h-=d ;
  1574. Lppcasm_div3: #r7 = BN_BITS2-i. so r7=i
  1575. cmpi 0,0,r7,0 # is (i == 0)?
  1576. beq Lppcasm_div4
  1577. $SHL r3,r3,r7 # h = (h<< i)
  1578. $SHR r8,r4,r8 # r8 = (l >> BN_BITS2 -i)
  1579. $SHL r5,r5,r7 # d<<=i
  1580. or r3,r3,r8 # h = (h<<i)|(l>>(BN_BITS2-i))
  1581. $SHL r4,r4,r7 # l <<=i
  1582. Lppcasm_div4:
  1583. $SHRI r9,r5,`$BITS/2` # r9 = dh
  1584. # dl will be computed when needed
  1585. # as it saves registers.
  1586. li r6,2 #r6=2
  1587. mtctr r6 #counter will be in count.
  1588. Lppcasm_divouterloop:
  1589. $SHRI r8,r3,`$BITS/2` #r8 = (h>>BN_BITS4)
  1590. $SHRI r11,r4,`$BITS/2` #r11= (l&BN_MASK2h)>>BN_BITS4
  1591. # compute here for innerloop.
  1592. $UCMP 0,r8,r9 # is (h>>BN_BITS4)==dh
  1593. bne Lppcasm_div5 # goto Lppcasm_div5 if not
  1594. li r8,-1
  1595. $CLRU r8,r8,`$BITS/2` #q = BN_MASK2l
  1596. b Lppcasm_div6
  1597. Lppcasm_div5:
  1598. $UDIV r8,r3,r9 #q = h/dh
  1599. Lppcasm_div6:
  1600. $UMULL r12,r9,r8 #th = q*dh
  1601. $CLRU r10,r5,`$BITS/2` #r10=dl
  1602. $UMULL r6,r8,r10 #tl = q*dl
  1603. Lppcasm_divinnerloop:
  1604. subf r10,r12,r3 #t = h -th
  1605. $SHRI r7,r10,`$BITS/2` #r7= (t &BN_MASK2H), sort of...
  1606. addic. r7,r7,0 #test if r7 == 0. used below.
  1607. # now want to compute
  1608. # r7 = (t<<BN_BITS4)|((l&BN_MASK2h)>>BN_BITS4)
  1609. # the following 2 instructions do that
  1610. $SHLI r7,r10,`$BITS/2` # r7 = (t<<BN_BITS4)
  1611. or r7,r7,r11 # r7|=((l&BN_MASK2h)>>BN_BITS4)
  1612. $UCMP cr1,r6,r7 # compare (tl <= r7)
  1613. bne Lppcasm_divinnerexit
  1614. ble cr1,Lppcasm_divinnerexit
  1615. addi r8,r8,-1 #q--
  1616. subf r12,r9,r12 #th -=dh
  1617. $CLRU r10,r5,`$BITS/2` #r10=dl. t is no longer needed in loop.
  1618. subf r6,r10,r6 #tl -=dl
  1619. b Lppcasm_divinnerloop
  1620. Lppcasm_divinnerexit:
  1621. $SHRI r10,r6,`$BITS/2` #t=(tl>>BN_BITS4)
  1622. $SHLI r11,r6,`$BITS/2` #tl=(tl<<BN_BITS4)&BN_MASK2h;
  1623. $UCMP cr1,r4,r11 # compare l and tl
  1624. add r12,r12,r10 # th+=t
  1625. bge cr1,Lppcasm_div7 # if (l>=tl) goto Lppcasm_div7
  1626. addi r12,r12,1 # th++
  1627. Lppcasm_div7:
  1628. subf r11,r11,r4 #r11=l-tl
  1629. $UCMP cr1,r3,r12 #compare h and th
  1630. bge cr1,Lppcasm_div8 #if (h>=th) goto Lppcasm_div8
  1631. addi r8,r8,-1 # q--
  1632. add r3,r5,r3 # h+=d
  1633. Lppcasm_div8:
  1634. subf r12,r12,r3 #r12 = h-th
  1635. $SHLI r4,r11,`$BITS/2` #l=(l&BN_MASK2l)<<BN_BITS4
  1636. # want to compute
  1637. # h = ((h<<BN_BITS4)|(l>>BN_BITS4))&BN_MASK2
  1638. # the following 2 instructions will do this.
  1639. $INSR r11,r12,`$BITS/2`,`$BITS/2` # r11 is the value we want rotated $BITS/2.
  1640. $ROTL r3,r11,`$BITS/2` # rotate by $BITS/2 and store in r3
  1641. bdz Lppcasm_div9 #if (count==0) break ;
  1642. $SHLI r0,r8,`$BITS/2` #ret =q<<BN_BITS4
  1643. b Lppcasm_divouterloop
  1644. Lppcasm_div9:
  1645. or r3,r8,r0
  1646. blr
  1647. .long 0
  1648. .byte 0,12,0x14,0,0,0,3,0
  1649. .long 0
  1650. .size .bn_div_words,.-.bn_div_words
  1651. #
  1652. # NOTE: The following label name should be changed to
  1653. # "bn_sqr_words" i.e. remove the first dot
  1654. # for the gcc compiler. This should be automatically
  1655. # done in the build
  1656. #
  1657. .align 4
  1658. .bn_sqr_words:
  1659. #
  1660. # Optimized version of bn_sqr_words
  1661. #
  1662. # void bn_sqr_words(BN_ULONG *r, BN_ULONG *a, int n)
  1663. #
  1664. # r3 = r
  1665. # r4 = a
  1666. # r5 = n
  1667. #
  1668. # r6 = a[i].
  1669. # r7,r8 = product.
  1670. #
  1671. # No unrolling done here. Not performance critical.
  1672. addic. r5,r5,0 #test r5.
  1673. beq Lppcasm_sqr_adios
  1674. addi r4,r4,-$BNSZ
  1675. addi r3,r3,-$BNSZ
  1676. mtctr r5
  1677. Lppcasm_sqr_mainloop:
  1678. #sqr(r[0],r[1],a[0]);
  1679. $LDU r6,$BNSZ(r4)
  1680. $UMULL r7,r6,r6
  1681. $UMULH r8,r6,r6
  1682. $STU r7,$BNSZ(r3)
  1683. $STU r8,$BNSZ(r3)
  1684. bdnz Lppcasm_sqr_mainloop
  1685. Lppcasm_sqr_adios:
  1686. blr
  1687. .long 0
  1688. .byte 0,12,0x14,0,0,0,3,0
  1689. .long 0
  1690. .size .bn_sqr_words,.-.bn_sqr_words
  1691. #
  1692. # NOTE: The following label name should be changed to
  1693. # "bn_mul_words" i.e. remove the first dot
  1694. # for the gcc compiler. This should be automatically
  1695. # done in the build
  1696. #
  1697. .align 4
  1698. .bn_mul_words:
  1699. #
  1700. # BN_ULONG bn_mul_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w)
  1701. #
  1702. # r3 = rp
  1703. # r4 = ap
  1704. # r5 = num
  1705. # r6 = w
  1706. xor r0,r0,r0
  1707. xor r12,r12,r12 # used for carry
  1708. rlwinm. r7,r5,30,2,31 # num >> 2
  1709. beq Lppcasm_mw_REM
  1710. mtctr r7
  1711. Lppcasm_mw_LOOP:
  1712. #mul(rp[0],ap[0],w,c1);
  1713. $LD r8,`0*$BNSZ`(r4)
  1714. $UMULL r9,r6,r8
  1715. $UMULH r10,r6,r8
  1716. addc r9,r9,r12
  1717. #addze r10,r10 #carry is NOT ignored.
  1718. #will be taken care of
  1719. #in second spin below
  1720. #using adde.
  1721. $ST r9,`0*$BNSZ`(r3)
  1722. #mul(rp[1],ap[1],w,c1);
  1723. $LD r8,`1*$BNSZ`(r4)
  1724. $UMULL r11,r6,r8
  1725. $UMULH r12,r6,r8
  1726. adde r11,r11,r10
  1727. #addze r12,r12
  1728. $ST r11,`1*$BNSZ`(r3)
  1729. #mul(rp[2],ap[2],w,c1);
  1730. $LD r8,`2*$BNSZ`(r4)
  1731. $UMULL r9,r6,r8
  1732. $UMULH r10,r6,r8
  1733. adde r9,r9,r12
  1734. #addze r10,r10
  1735. $ST r9,`2*$BNSZ`(r3)
  1736. #mul_add(rp[3],ap[3],w,c1);
  1737. $LD r8,`3*$BNSZ`(r4)
  1738. $UMULL r11,r6,r8
  1739. $UMULH r12,r6,r8
  1740. adde r11,r11,r10
  1741. addze r12,r12 #this spin we collect carry into
  1742. #r12
  1743. $ST r11,`3*$BNSZ`(r3)
  1744. addi r3,r3,`4*$BNSZ`
  1745. addi r4,r4,`4*$BNSZ`
  1746. bdnz Lppcasm_mw_LOOP
  1747. Lppcasm_mw_REM:
  1748. andi. r5,r5,0x3
  1749. beq Lppcasm_mw_OVER
  1750. #mul(rp[0],ap[0],w,c1);
  1751. $LD r8,`0*$BNSZ`(r4)
  1752. $UMULL r9,r6,r8
  1753. $UMULH r10,r6,r8
  1754. addc r9,r9,r12
  1755. addze r10,r10
  1756. $ST r9,`0*$BNSZ`(r3)
  1757. addi r12,r10,0
  1758. addi r5,r5,-1
  1759. cmpli 0,0,r5,0
  1760. beq Lppcasm_mw_OVER
  1761. #mul(rp[1],ap[1],w,c1);
  1762. $LD r8,`1*$BNSZ`(r4)
  1763. $UMULL r9,r6,r8
  1764. $UMULH r10,r6,r8
  1765. addc r9,r9,r12
  1766. addze r10,r10
  1767. $ST r9,`1*$BNSZ`(r3)
  1768. addi r12,r10,0
  1769. addi r5,r5,-1
  1770. cmpli 0,0,r5,0
  1771. beq Lppcasm_mw_OVER
  1772. #mul_add(rp[2],ap[2],w,c1);
  1773. $LD r8,`2*$BNSZ`(r4)
  1774. $UMULL r9,r6,r8
  1775. $UMULH r10,r6,r8
  1776. addc r9,r9,r12
  1777. addze r10,r10
  1778. $ST r9,`2*$BNSZ`(r3)
  1779. addi r12,r10,0
  1780. Lppcasm_mw_OVER:
  1781. addi r3,r12,0
  1782. blr
  1783. .long 0
  1784. .byte 0,12,0x14,0,0,0,4,0
  1785. .long 0
  1786. .size .bn_mul_words,.-.bn_mul_words
  1787. #
  1788. # NOTE: The following label name should be changed to
  1789. # "bn_mul_add_words" i.e. remove the first dot
  1790. # for the gcc compiler. This should be automatically
  1791. # done in the build
  1792. #
  1793. .align 4
  1794. .bn_mul_add_words:
  1795. #
  1796. # BN_ULONG bn_mul_add_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w)
  1797. #
  1798. # r3 = rp
  1799. # r4 = ap
  1800. # r5 = num
  1801. # r6 = w
  1802. #
  1803. # empirical evidence suggests that unrolled version performs best!!
  1804. #
  1805. xor r0,r0,r0 #r0 = 0
  1806. xor r12,r12,r12 #r12 = 0 . used for carry
  1807. rlwinm. r7,r5,30,2,31 # num >> 2
  1808. beq Lppcasm_maw_leftover # if (num < 4) go LPPCASM_maw_leftover
  1809. mtctr r7
  1810. Lppcasm_maw_mainloop:
  1811. #mul_add(rp[0],ap[0],w,c1);
  1812. $LD r8,`0*$BNSZ`(r4)
  1813. $LD r11,`0*$BNSZ`(r3)
  1814. $UMULL r9,r6,r8
  1815. $UMULH r10,r6,r8
  1816. addc r9,r9,r12 #r12 is carry.
  1817. addze r10,r10
  1818. addc r9,r9,r11
  1819. #addze r10,r10
  1820. #the above instruction addze
  1821. #is NOT needed. Carry will NOT
  1822. #be ignored. It's not affected
  1823. #by multiply and will be collected
  1824. #in the next spin
  1825. $ST r9,`0*$BNSZ`(r3)
  1826. #mul_add(rp[1],ap[1],w,c1);
  1827. $LD r8,`1*$BNSZ`(r4)
  1828. $LD r9,`1*$BNSZ`(r3)
  1829. $UMULL r11,r6,r8
  1830. $UMULH r12,r6,r8
  1831. adde r11,r11,r10 #r10 is carry.
  1832. addze r12,r12
  1833. addc r11,r11,r9
  1834. #addze r12,r12
  1835. $ST r11,`1*$BNSZ`(r3)
  1836. #mul_add(rp[2],ap[2],w,c1);
  1837. $LD r8,`2*$BNSZ`(r4)
  1838. $UMULL r9,r6,r8
  1839. $LD r11,`2*$BNSZ`(r3)
  1840. $UMULH r10,r6,r8
  1841. adde r9,r9,r12
  1842. addze r10,r10
  1843. addc r9,r9,r11
  1844. #addze r10,r10
  1845. $ST r9,`2*$BNSZ`(r3)
  1846. #mul_add(rp[3],ap[3],w,c1);
  1847. $LD r8,`3*$BNSZ`(r4)
  1848. $UMULL r11,r6,r8
  1849. $LD r9,`3*$BNSZ`(r3)
  1850. $UMULH r12,r6,r8
  1851. adde r11,r11,r10
  1852. addze r12,r12
  1853. addc r11,r11,r9
  1854. addze r12,r12
  1855. $ST r11,`3*$BNSZ`(r3)
  1856. addi r3,r3,`4*$BNSZ`
  1857. addi r4,r4,`4*$BNSZ`
  1858. bdnz Lppcasm_maw_mainloop
  1859. Lppcasm_maw_leftover:
  1860. andi. r5,r5,0x3
  1861. beq Lppcasm_maw_adios
  1862. addi r3,r3,-$BNSZ
  1863. addi r4,r4,-$BNSZ
  1864. #mul_add(rp[0],ap[0],w,c1);
  1865. mtctr r5
  1866. $LDU r8,$BNSZ(r4)
  1867. $UMULL r9,r6,r8
  1868. $UMULH r10,r6,r8
  1869. $LDU r11,$BNSZ(r3)
  1870. addc r9,r9,r11
  1871. addze r10,r10
  1872. addc r9,r9,r12
  1873. addze r12,r10
  1874. $ST r9,0(r3)
  1875. bdz Lppcasm_maw_adios
  1876. #mul_add(rp[1],ap[1],w,c1);
  1877. $LDU r8,$BNSZ(r4)
  1878. $UMULL r9,r6,r8
  1879. $UMULH r10,r6,r8
  1880. $LDU r11,$BNSZ(r3)
  1881. addc r9,r9,r11
  1882. addze r10,r10
  1883. addc r9,r9,r12
  1884. addze r12,r10
  1885. $ST r9,0(r3)
  1886. bdz Lppcasm_maw_adios
  1887. #mul_add(rp[2],ap[2],w,c1);
  1888. $LDU r8,$BNSZ(r4)
  1889. $UMULL r9,r6,r8
  1890. $UMULH r10,r6,r8
  1891. $LDU r11,$BNSZ(r3)
  1892. addc r9,r9,r11
  1893. addze r10,r10
  1894. addc r9,r9,r12
  1895. addze r12,r10
  1896. $ST r9,0(r3)
  1897. Lppcasm_maw_adios:
  1898. addi r3,r12,0
  1899. blr
  1900. .long 0
  1901. .byte 0,12,0x14,0,0,0,4,0
  1902. .long 0
  1903. .size .bn_mul_add_words,.-.bn_mul_add_words
  1904. .align 4
  1905. EOF
  1906. $data =~ s/\`([^\`]*)\`/eval $1/gem;
  1907. print $data;
  1908. close STDOUT;