ghash-sparcv9.pl 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  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. # Written by Andy Polyakov <appro@openssl.org> for the OpenSSL
  10. # project. The module is, however, dual licensed under OpenSSL and
  11. # CRYPTOGAMS licenses depending on where you obtain it. For further
  12. # details see http://www.openssl.org/~appro/cryptogams/.
  13. # ====================================================================
  14. # March 2010
  15. #
  16. # The module implements "4-bit" GCM GHASH function and underlying
  17. # single multiplication operation in GF(2^128). "4-bit" means that it
  18. # uses 256 bytes per-key table [+128 bytes shared table]. Performance
  19. # results are for streamed GHASH subroutine on UltraSPARC pre-Tx CPU
  20. # and are expressed in cycles per processed byte, less is better:
  21. #
  22. # gcc 3.3.x cc 5.2 this assembler
  23. #
  24. # 32-bit build 81.4 43.3 12.6 (+546%/+244%)
  25. # 64-bit build 20.2 21.2 12.6 (+60%/+68%)
  26. #
  27. # Here is data collected on UltraSPARC T1 system running Linux:
  28. #
  29. # gcc 4.4.1 this assembler
  30. #
  31. # 32-bit build 566 50 (+1000%)
  32. # 64-bit build 56 50 (+12%)
  33. #
  34. # I don't quite understand why difference between 32-bit and 64-bit
  35. # compiler-generated code is so big. Compilers *were* instructed to
  36. # generate code for UltraSPARC and should have used 64-bit registers
  37. # for Z vector (see C code) even in 32-bit build... Oh well, it only
  38. # means more impressive improvement coefficients for this assembler
  39. # module;-) Loops are aggressively modulo-scheduled in respect to
  40. # references to input data and Z.hi updates to achieve 12 cycles
  41. # timing. To anchor to something else, sha1-sparcv9.pl spends 11.6
  42. # cycles to process one byte on UltraSPARC pre-Tx CPU and ~24 on T1.
  43. #
  44. # October 2012
  45. #
  46. # Add VIS3 lookup-table-free implementation using polynomial
  47. # multiplication xmulx[hi] and extended addition addxc[cc]
  48. # instructions. 4.52/7.63x improvement on T3/T4 or in absolute
  49. # terms 7.90/2.14 cycles per byte. On T4 multi-process benchmark
  50. # saturates at ~15.5x single-process result on 8-core processor,
  51. # or ~20.5GBps per 2.85GHz socket.
  52. $output=pop and open STDOUT,">$output";
  53. $frame="STACK_FRAME";
  54. $bias="STACK_BIAS";
  55. $Zhi="%o0"; # 64-bit values
  56. $Zlo="%o1";
  57. $Thi="%o2";
  58. $Tlo="%o3";
  59. $rem="%o4";
  60. $tmp="%o5";
  61. $nhi="%l0"; # small values and pointers
  62. $nlo="%l1";
  63. $xi0="%l2";
  64. $xi1="%l3";
  65. $rem_4bit="%l4";
  66. $remi="%l5";
  67. $Htblo="%l6";
  68. $cnt="%l7";
  69. $Xi="%i0"; # input argument block
  70. $Htbl="%i1";
  71. $inp="%i2";
  72. $len="%i3";
  73. $code.=<<___;
  74. #include "sparc_arch.h"
  75. #ifdef __arch64__
  76. .register %g2,#scratch
  77. .register %g3,#scratch
  78. #endif
  79. .section ".text",#alloc,#execinstr
  80. .align 64
  81. rem_4bit:
  82. .long `0x0000<<16`,0,`0x1C20<<16`,0,`0x3840<<16`,0,`0x2460<<16`,0
  83. .long `0x7080<<16`,0,`0x6CA0<<16`,0,`0x48C0<<16`,0,`0x54E0<<16`,0
  84. .long `0xE100<<16`,0,`0xFD20<<16`,0,`0xD940<<16`,0,`0xC560<<16`,0
  85. .long `0x9180<<16`,0,`0x8DA0<<16`,0,`0xA9C0<<16`,0,`0xB5E0<<16`,0
  86. .type rem_4bit,#object
  87. .size rem_4bit,(.-rem_4bit)
  88. .globl gcm_ghash_4bit
  89. .align 32
  90. gcm_ghash_4bit:
  91. save %sp,-$frame,%sp
  92. ldub [$inp+15],$nlo
  93. ldub [$Xi+15],$xi0
  94. ldub [$Xi+14],$xi1
  95. add $len,$inp,$len
  96. add $Htbl,8,$Htblo
  97. 1: call .+8
  98. add %o7,rem_4bit-1b,$rem_4bit
  99. .Louter:
  100. xor $xi0,$nlo,$nlo
  101. and $nlo,0xf0,$nhi
  102. and $nlo,0x0f,$nlo
  103. sll $nlo,4,$nlo
  104. ldx [$Htblo+$nlo],$Zlo
  105. ldx [$Htbl+$nlo],$Zhi
  106. ldub [$inp+14],$nlo
  107. ldx [$Htblo+$nhi],$Tlo
  108. and $Zlo,0xf,$remi
  109. ldx [$Htbl+$nhi],$Thi
  110. sll $remi,3,$remi
  111. ldx [$rem_4bit+$remi],$rem
  112. srlx $Zlo,4,$Zlo
  113. mov 13,$cnt
  114. sllx $Zhi,60,$tmp
  115. xor $Tlo,$Zlo,$Zlo
  116. srlx $Zhi,4,$Zhi
  117. xor $Zlo,$tmp,$Zlo
  118. xor $xi1,$nlo,$nlo
  119. and $Zlo,0xf,$remi
  120. and $nlo,0xf0,$nhi
  121. and $nlo,0x0f,$nlo
  122. ba .Lghash_inner
  123. sll $nlo,4,$nlo
  124. .align 32
  125. .Lghash_inner:
  126. ldx [$Htblo+$nlo],$Tlo
  127. sll $remi,3,$remi
  128. xor $Thi,$Zhi,$Zhi
  129. ldx [$Htbl+$nlo],$Thi
  130. srlx $Zlo,4,$Zlo
  131. xor $rem,$Zhi,$Zhi
  132. ldx [$rem_4bit+$remi],$rem
  133. sllx $Zhi,60,$tmp
  134. xor $Tlo,$Zlo,$Zlo
  135. ldub [$inp+$cnt],$nlo
  136. srlx $Zhi,4,$Zhi
  137. xor $Zlo,$tmp,$Zlo
  138. ldub [$Xi+$cnt],$xi1
  139. xor $Thi,$Zhi,$Zhi
  140. and $Zlo,0xf,$remi
  141. ldx [$Htblo+$nhi],$Tlo
  142. sll $remi,3,$remi
  143. xor $rem,$Zhi,$Zhi
  144. ldx [$Htbl+$nhi],$Thi
  145. srlx $Zlo,4,$Zlo
  146. ldx [$rem_4bit+$remi],$rem
  147. sllx $Zhi,60,$tmp
  148. xor $xi1,$nlo,$nlo
  149. srlx $Zhi,4,$Zhi
  150. and $nlo,0xf0,$nhi
  151. addcc $cnt,-1,$cnt
  152. xor $Zlo,$tmp,$Zlo
  153. and $nlo,0x0f,$nlo
  154. xor $Tlo,$Zlo,$Zlo
  155. sll $nlo,4,$nlo
  156. blu .Lghash_inner
  157. and $Zlo,0xf,$remi
  158. ldx [$Htblo+$nlo],$Tlo
  159. sll $remi,3,$remi
  160. xor $Thi,$Zhi,$Zhi
  161. ldx [$Htbl+$nlo],$Thi
  162. srlx $Zlo,4,$Zlo
  163. xor $rem,$Zhi,$Zhi
  164. ldx [$rem_4bit+$remi],$rem
  165. sllx $Zhi,60,$tmp
  166. xor $Tlo,$Zlo,$Zlo
  167. srlx $Zhi,4,$Zhi
  168. xor $Zlo,$tmp,$Zlo
  169. xor $Thi,$Zhi,$Zhi
  170. add $inp,16,$inp
  171. cmp $inp,$len
  172. be,pn SIZE_T_CC,.Ldone
  173. and $Zlo,0xf,$remi
  174. ldx [$Htblo+$nhi],$Tlo
  175. sll $remi,3,$remi
  176. xor $rem,$Zhi,$Zhi
  177. ldx [$Htbl+$nhi],$Thi
  178. srlx $Zlo,4,$Zlo
  179. ldx [$rem_4bit+$remi],$rem
  180. sllx $Zhi,60,$tmp
  181. xor $Tlo,$Zlo,$Zlo
  182. ldub [$inp+15],$nlo
  183. srlx $Zhi,4,$Zhi
  184. xor $Zlo,$tmp,$Zlo
  185. xor $Thi,$Zhi,$Zhi
  186. stx $Zlo,[$Xi+8]
  187. xor $rem,$Zhi,$Zhi
  188. stx $Zhi,[$Xi]
  189. srl $Zlo,8,$xi1
  190. and $Zlo,0xff,$xi0
  191. ba .Louter
  192. and $xi1,0xff,$xi1
  193. .align 32
  194. .Ldone:
  195. ldx [$Htblo+$nhi],$Tlo
  196. sll $remi,3,$remi
  197. xor $rem,$Zhi,$Zhi
  198. ldx [$Htbl+$nhi],$Thi
  199. srlx $Zlo,4,$Zlo
  200. ldx [$rem_4bit+$remi],$rem
  201. sllx $Zhi,60,$tmp
  202. xor $Tlo,$Zlo,$Zlo
  203. srlx $Zhi,4,$Zhi
  204. xor $Zlo,$tmp,$Zlo
  205. xor $Thi,$Zhi,$Zhi
  206. stx $Zlo,[$Xi+8]
  207. xor $rem,$Zhi,$Zhi
  208. stx $Zhi,[$Xi]
  209. ret
  210. restore
  211. .type gcm_ghash_4bit,#function
  212. .size gcm_ghash_4bit,(.-gcm_ghash_4bit)
  213. ___
  214. undef $inp;
  215. undef $len;
  216. $code.=<<___;
  217. .globl gcm_gmult_4bit
  218. .align 32
  219. gcm_gmult_4bit:
  220. save %sp,-$frame,%sp
  221. ldub [$Xi+15],$nlo
  222. add $Htbl,8,$Htblo
  223. 1: call .+8
  224. add %o7,rem_4bit-1b,$rem_4bit
  225. and $nlo,0xf0,$nhi
  226. and $nlo,0x0f,$nlo
  227. sll $nlo,4,$nlo
  228. ldx [$Htblo+$nlo],$Zlo
  229. ldx [$Htbl+$nlo],$Zhi
  230. ldub [$Xi+14],$nlo
  231. ldx [$Htblo+$nhi],$Tlo
  232. and $Zlo,0xf,$remi
  233. ldx [$Htbl+$nhi],$Thi
  234. sll $remi,3,$remi
  235. ldx [$rem_4bit+$remi],$rem
  236. srlx $Zlo,4,$Zlo
  237. mov 13,$cnt
  238. sllx $Zhi,60,$tmp
  239. xor $Tlo,$Zlo,$Zlo
  240. srlx $Zhi,4,$Zhi
  241. xor $Zlo,$tmp,$Zlo
  242. and $Zlo,0xf,$remi
  243. and $nlo,0xf0,$nhi
  244. and $nlo,0x0f,$nlo
  245. ba .Lgmult_inner
  246. sll $nlo,4,$nlo
  247. .align 32
  248. .Lgmult_inner:
  249. ldx [$Htblo+$nlo],$Tlo
  250. sll $remi,3,$remi
  251. xor $Thi,$Zhi,$Zhi
  252. ldx [$Htbl+$nlo],$Thi
  253. srlx $Zlo,4,$Zlo
  254. xor $rem,$Zhi,$Zhi
  255. ldx [$rem_4bit+$remi],$rem
  256. sllx $Zhi,60,$tmp
  257. xor $Tlo,$Zlo,$Zlo
  258. ldub [$Xi+$cnt],$nlo
  259. srlx $Zhi,4,$Zhi
  260. xor $Zlo,$tmp,$Zlo
  261. xor $Thi,$Zhi,$Zhi
  262. and $Zlo,0xf,$remi
  263. ldx [$Htblo+$nhi],$Tlo
  264. sll $remi,3,$remi
  265. xor $rem,$Zhi,$Zhi
  266. ldx [$Htbl+$nhi],$Thi
  267. srlx $Zlo,4,$Zlo
  268. ldx [$rem_4bit+$remi],$rem
  269. sllx $Zhi,60,$tmp
  270. srlx $Zhi,4,$Zhi
  271. and $nlo,0xf0,$nhi
  272. addcc $cnt,-1,$cnt
  273. xor $Zlo,$tmp,$Zlo
  274. and $nlo,0x0f,$nlo
  275. xor $Tlo,$Zlo,$Zlo
  276. sll $nlo,4,$nlo
  277. blu .Lgmult_inner
  278. and $Zlo,0xf,$remi
  279. ldx [$Htblo+$nlo],$Tlo
  280. sll $remi,3,$remi
  281. xor $Thi,$Zhi,$Zhi
  282. ldx [$Htbl+$nlo],$Thi
  283. srlx $Zlo,4,$Zlo
  284. xor $rem,$Zhi,$Zhi
  285. ldx [$rem_4bit+$remi],$rem
  286. sllx $Zhi,60,$tmp
  287. xor $Tlo,$Zlo,$Zlo
  288. srlx $Zhi,4,$Zhi
  289. xor $Zlo,$tmp,$Zlo
  290. xor $Thi,$Zhi,$Zhi
  291. and $Zlo,0xf,$remi
  292. ldx [$Htblo+$nhi],$Tlo
  293. sll $remi,3,$remi
  294. xor $rem,$Zhi,$Zhi
  295. ldx [$Htbl+$nhi],$Thi
  296. srlx $Zlo,4,$Zlo
  297. ldx [$rem_4bit+$remi],$rem
  298. sllx $Zhi,60,$tmp
  299. xor $Tlo,$Zlo,$Zlo
  300. srlx $Zhi,4,$Zhi
  301. xor $Zlo,$tmp,$Zlo
  302. xor $Thi,$Zhi,$Zhi
  303. stx $Zlo,[$Xi+8]
  304. xor $rem,$Zhi,$Zhi
  305. stx $Zhi,[$Xi]
  306. ret
  307. restore
  308. .type gcm_gmult_4bit,#function
  309. .size gcm_gmult_4bit,(.-gcm_gmult_4bit)
  310. ___
  311. {{{
  312. # Straightforward 128x128-bit multiplication using Karatsuba algorithm
  313. # followed by pair of 64-bit reductions [with a shortcut in first one,
  314. # which allowed to break dependency between reductions and remove one
  315. # multiplication from critical path]. While it might be suboptimal
  316. # with regard to sheer number of multiplications, other methods [such
  317. # as aggregate reduction] would require more 64-bit registers, which
  318. # we don't have in 32-bit application context.
  319. ($Xip,$Htable,$inp,$len)=map("%i$_",(0..3));
  320. ($Hhl,$Hlo,$Hhi,$Xlo,$Xhi,$xE1,$sqr, $C0,$C1,$C2,$C3,$V)=
  321. (map("%o$_",(0..5,7)),map("%g$_",(1..5)));
  322. ($shl,$shr)=map("%l$_",(0..7));
  323. # For details regarding "twisted H" see ghash-x86.pl.
  324. $code.=<<___;
  325. .globl gcm_init_vis3
  326. .align 32
  327. gcm_init_vis3:
  328. save %sp,-$frame,%sp
  329. ldx [%i1+0],$Hhi
  330. ldx [%i1+8],$Hlo
  331. mov 0xE1,$Xhi
  332. mov 1,$Xlo
  333. sllx $Xhi,57,$Xhi
  334. srax $Hhi,63,$C0 ! broadcast carry
  335. addcc $Hlo,$Hlo,$Hlo ! H<<=1
  336. addxc $Hhi,$Hhi,$Hhi
  337. and $C0,$Xlo,$Xlo
  338. and $C0,$Xhi,$Xhi
  339. xor $Xlo,$Hlo,$Hlo
  340. xor $Xhi,$Hhi,$Hhi
  341. stx $Hlo,[%i0+8] ! save twisted H
  342. stx $Hhi,[%i0+0]
  343. sethi %hi(0xA0406080),$V
  344. sethi %hi(0x20C0E000),%l0
  345. or $V,%lo(0xA0406080),$V
  346. or %l0,%lo(0x20C0E000),%l0
  347. sllx $V,32,$V
  348. or %l0,$V,$V ! (0xE0·i)&0xff=0xA040608020C0E000
  349. stx $V,[%i0+16]
  350. ret
  351. restore
  352. .type gcm_init_vis3,#function
  353. .size gcm_init_vis3,.-gcm_init_vis3
  354. .globl gcm_gmult_vis3
  355. .align 32
  356. gcm_gmult_vis3:
  357. save %sp,-$frame,%sp
  358. ldx [$Xip+8],$Xlo ! load Xi
  359. ldx [$Xip+0],$Xhi
  360. ldx [$Htable+8],$Hlo ! load twisted H
  361. ldx [$Htable+0],$Hhi
  362. mov 0xE1,%l7
  363. sllx %l7,57,$xE1 ! 57 is not a typo
  364. ldx [$Htable+16],$V ! (0xE0·i)&0xff=0xA040608020C0E000
  365. xor $Hhi,$Hlo,$Hhl ! Karatsuba pre-processing
  366. xmulx $Xlo,$Hlo,$C0
  367. xor $Xlo,$Xhi,$C2 ! Karatsuba pre-processing
  368. xmulx $C2,$Hhl,$C1
  369. xmulxhi $Xlo,$Hlo,$Xlo
  370. xmulxhi $C2,$Hhl,$C2
  371. xmulxhi $Xhi,$Hhi,$C3
  372. xmulx $Xhi,$Hhi,$Xhi
  373. sll $C0,3,$sqr
  374. srlx $V,$sqr,$sqr ! ·0xE0 [implicit &(7<<3)]
  375. xor $C0,$sqr,$sqr
  376. sllx $sqr,57,$sqr ! ($C0·0xE1)<<1<<56 [implicit &0x7f]
  377. xor $C0,$C1,$C1 ! Karatsuba post-processing
  378. xor $Xlo,$C2,$C2
  379. xor $sqr,$Xlo,$Xlo ! real destination is $C1
  380. xor $C3,$C2,$C2
  381. xor $Xlo,$C1,$C1
  382. xor $Xhi,$C2,$C2
  383. xor $Xhi,$C1,$C1
  384. xmulxhi $C0,$xE1,$Xlo ! ·0xE1<<1<<56
  385. xor $C0,$C2,$C2
  386. xmulx $C1,$xE1,$C0
  387. xor $C1,$C3,$C3
  388. xmulxhi $C1,$xE1,$C1
  389. xor $Xlo,$C2,$C2
  390. xor $C0,$C2,$C2
  391. xor $C1,$C3,$C3
  392. stx $C2,[$Xip+8] ! save Xi
  393. stx $C3,[$Xip+0]
  394. ret
  395. restore
  396. .type gcm_gmult_vis3,#function
  397. .size gcm_gmult_vis3,.-gcm_gmult_vis3
  398. .globl gcm_ghash_vis3
  399. .align 32
  400. gcm_ghash_vis3:
  401. save %sp,-$frame,%sp
  402. nop
  403. srln $len,0,$len ! needed on v8+, "nop" on v9
  404. ldx [$Xip+8],$C2 ! load Xi
  405. ldx [$Xip+0],$C3
  406. ldx [$Htable+8],$Hlo ! load twisted H
  407. ldx [$Htable+0],$Hhi
  408. mov 0xE1,%l7
  409. sllx %l7,57,$xE1 ! 57 is not a typo
  410. ldx [$Htable+16],$V ! (0xE0·i)&0xff=0xA040608020C0E000
  411. and $inp,7,$shl
  412. andn $inp,7,$inp
  413. sll $shl,3,$shl
  414. prefetch [$inp+63], 20
  415. sub %g0,$shl,$shr
  416. xor $Hhi,$Hlo,$Hhl ! Karatsuba pre-processing
  417. .Loop:
  418. ldx [$inp+8],$Xlo
  419. brz,pt $shl,1f
  420. ldx [$inp+0],$Xhi
  421. ldx [$inp+16],$C1 ! align data
  422. srlx $Xlo,$shr,$C0
  423. sllx $Xlo,$shl,$Xlo
  424. sllx $Xhi,$shl,$Xhi
  425. srlx $C1,$shr,$C1
  426. or $C0,$Xhi,$Xhi
  427. or $C1,$Xlo,$Xlo
  428. 1:
  429. add $inp,16,$inp
  430. sub $len,16,$len
  431. xor $C2,$Xlo,$Xlo
  432. xor $C3,$Xhi,$Xhi
  433. prefetch [$inp+63], 20
  434. xmulx $Xlo,$Hlo,$C0
  435. xor $Xlo,$Xhi,$C2 ! Karatsuba pre-processing
  436. xmulx $C2,$Hhl,$C1
  437. xmulxhi $Xlo,$Hlo,$Xlo
  438. xmulxhi $C2,$Hhl,$C2
  439. xmulxhi $Xhi,$Hhi,$C3
  440. xmulx $Xhi,$Hhi,$Xhi
  441. sll $C0,3,$sqr
  442. srlx $V,$sqr,$sqr ! ·0xE0 [implicit &(7<<3)]
  443. xor $C0,$sqr,$sqr
  444. sllx $sqr,57,$sqr ! ($C0·0xE1)<<1<<56 [implicit &0x7f]
  445. xor $C0,$C1,$C1 ! Karatsuba post-processing
  446. xor $Xlo,$C2,$C2
  447. xor $sqr,$Xlo,$Xlo ! real destination is $C1
  448. xor $C3,$C2,$C2
  449. xor $Xlo,$C1,$C1
  450. xor $Xhi,$C2,$C2
  451. xor $Xhi,$C1,$C1
  452. xmulxhi $C0,$xE1,$Xlo ! ·0xE1<<1<<56
  453. xor $C0,$C2,$C2
  454. xmulx $C1,$xE1,$C0
  455. xor $C1,$C3,$C3
  456. xmulxhi $C1,$xE1,$C1
  457. xor $Xlo,$C2,$C2
  458. xor $C0,$C2,$C2
  459. brnz,pt $len,.Loop
  460. xor $C1,$C3,$C3
  461. stx $C2,[$Xip+8] ! save Xi
  462. stx $C3,[$Xip+0]
  463. ret
  464. restore
  465. .type gcm_ghash_vis3,#function
  466. .size gcm_ghash_vis3,.-gcm_ghash_vis3
  467. ___
  468. }}}
  469. $code.=<<___;
  470. .asciz "GHASH for SPARCv9/VIS3, CRYPTOGAMS by <appro\@openssl.org>"
  471. .align 4
  472. ___
  473. # Purpose of these subroutines is to explicitly encode VIS instructions,
  474. # so that one can compile the module without having to specify VIS
  475. # extensions on compiler command line, e.g. -xarch=v9 vs. -xarch=v9a.
  476. # Idea is to reserve for option to produce "universal" binary and let
  477. # programmer detect if current CPU is VIS capable at run-time.
  478. sub unvis3 {
  479. my ($mnemonic,$rs1,$rs2,$rd)=@_;
  480. my %bias = ( "g" => 0, "o" => 8, "l" => 16, "i" => 24 );
  481. my ($ref,$opf);
  482. my %visopf = ( "addxc" => 0x011,
  483. "addxccc" => 0x013,
  484. "xmulx" => 0x115,
  485. "xmulxhi" => 0x116 );
  486. $ref = "$mnemonic\t$rs1,$rs2,$rd";
  487. if ($opf=$visopf{$mnemonic}) {
  488. foreach ($rs1,$rs2,$rd) {
  489. return $ref if (!/%([goli])([0-9])/);
  490. $_=$bias{$1}+$2;
  491. }
  492. return sprintf ".word\t0x%08x !%s",
  493. 0x81b00000|$rd<<25|$rs1<<14|$opf<<5|$rs2,
  494. $ref;
  495. } else {
  496. return $ref;
  497. }
  498. }
  499. foreach (split("\n",$code)) {
  500. s/\`([^\`]*)\`/eval $1/ge;
  501. s/\b(xmulx[hi]*|addxc[c]{0,2})\s+(%[goli][0-7]),\s*(%[goli][0-7]),\s*(%[goli][0-7])/
  502. &unvis3($1,$2,$3,$4)
  503. /ge;
  504. print $_,"\n";
  505. }
  506. close STDOUT or die "error closing STDOUT: $!";