ghash-sparcv9.pl 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  1. #! /usr/bin/env perl
  2. # Copyright 2010-2021 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. #ifndef __ASSEMBLER__
  75. # define __ASSEMBLER__ 1
  76. #endif
  77. #include "crypto/sparc_arch.h"
  78. #ifdef __arch64__
  79. .register %g2,#scratch
  80. .register %g3,#scratch
  81. #endif
  82. .section ".text",#alloc,#execinstr
  83. .align 64
  84. rem_4bit:
  85. .long `0x0000<<16`,0,`0x1C20<<16`,0,`0x3840<<16`,0,`0x2460<<16`,0
  86. .long `0x7080<<16`,0,`0x6CA0<<16`,0,`0x48C0<<16`,0,`0x54E0<<16`,0
  87. .long `0xE100<<16`,0,`0xFD20<<16`,0,`0xD940<<16`,0,`0xC560<<16`,0
  88. .long `0x9180<<16`,0,`0x8DA0<<16`,0,`0xA9C0<<16`,0,`0xB5E0<<16`,0
  89. .type rem_4bit,#object
  90. .size rem_4bit,(.-rem_4bit)
  91. .globl gcm_ghash_4bit
  92. .align 32
  93. gcm_ghash_4bit:
  94. save %sp,-$frame,%sp
  95. ldub [$inp+15],$nlo
  96. ldub [$Xi+15],$xi0
  97. ldub [$Xi+14],$xi1
  98. add $len,$inp,$len
  99. add $Htbl,8,$Htblo
  100. 1: call .+8
  101. add %o7,rem_4bit-1b,$rem_4bit
  102. .Louter:
  103. xor $xi0,$nlo,$nlo
  104. and $nlo,0xf0,$nhi
  105. and $nlo,0x0f,$nlo
  106. sll $nlo,4,$nlo
  107. ldx [$Htblo+$nlo],$Zlo
  108. ldx [$Htbl+$nlo],$Zhi
  109. ldub [$inp+14],$nlo
  110. ldx [$Htblo+$nhi],$Tlo
  111. and $Zlo,0xf,$remi
  112. ldx [$Htbl+$nhi],$Thi
  113. sll $remi,3,$remi
  114. ldx [$rem_4bit+$remi],$rem
  115. srlx $Zlo,4,$Zlo
  116. mov 13,$cnt
  117. sllx $Zhi,60,$tmp
  118. xor $Tlo,$Zlo,$Zlo
  119. srlx $Zhi,4,$Zhi
  120. xor $Zlo,$tmp,$Zlo
  121. xor $xi1,$nlo,$nlo
  122. and $Zlo,0xf,$remi
  123. and $nlo,0xf0,$nhi
  124. and $nlo,0x0f,$nlo
  125. ba .Lghash_inner
  126. sll $nlo,4,$nlo
  127. .align 32
  128. .Lghash_inner:
  129. ldx [$Htblo+$nlo],$Tlo
  130. sll $remi,3,$remi
  131. xor $Thi,$Zhi,$Zhi
  132. ldx [$Htbl+$nlo],$Thi
  133. srlx $Zlo,4,$Zlo
  134. xor $rem,$Zhi,$Zhi
  135. ldx [$rem_4bit+$remi],$rem
  136. sllx $Zhi,60,$tmp
  137. xor $Tlo,$Zlo,$Zlo
  138. ldub [$inp+$cnt],$nlo
  139. srlx $Zhi,4,$Zhi
  140. xor $Zlo,$tmp,$Zlo
  141. ldub [$Xi+$cnt],$xi1
  142. xor $Thi,$Zhi,$Zhi
  143. and $Zlo,0xf,$remi
  144. ldx [$Htblo+$nhi],$Tlo
  145. sll $remi,3,$remi
  146. xor $rem,$Zhi,$Zhi
  147. ldx [$Htbl+$nhi],$Thi
  148. srlx $Zlo,4,$Zlo
  149. ldx [$rem_4bit+$remi],$rem
  150. sllx $Zhi,60,$tmp
  151. xor $xi1,$nlo,$nlo
  152. srlx $Zhi,4,$Zhi
  153. and $nlo,0xf0,$nhi
  154. addcc $cnt,-1,$cnt
  155. xor $Zlo,$tmp,$Zlo
  156. and $nlo,0x0f,$nlo
  157. xor $Tlo,$Zlo,$Zlo
  158. sll $nlo,4,$nlo
  159. blu .Lghash_inner
  160. and $Zlo,0xf,$remi
  161. ldx [$Htblo+$nlo],$Tlo
  162. sll $remi,3,$remi
  163. xor $Thi,$Zhi,$Zhi
  164. ldx [$Htbl+$nlo],$Thi
  165. srlx $Zlo,4,$Zlo
  166. xor $rem,$Zhi,$Zhi
  167. ldx [$rem_4bit+$remi],$rem
  168. sllx $Zhi,60,$tmp
  169. xor $Tlo,$Zlo,$Zlo
  170. srlx $Zhi,4,$Zhi
  171. xor $Zlo,$tmp,$Zlo
  172. xor $Thi,$Zhi,$Zhi
  173. add $inp,16,$inp
  174. cmp $inp,$len
  175. be,pn SIZE_T_CC,.Ldone
  176. and $Zlo,0xf,$remi
  177. ldx [$Htblo+$nhi],$Tlo
  178. sll $remi,3,$remi
  179. xor $rem,$Zhi,$Zhi
  180. ldx [$Htbl+$nhi],$Thi
  181. srlx $Zlo,4,$Zlo
  182. ldx [$rem_4bit+$remi],$rem
  183. sllx $Zhi,60,$tmp
  184. xor $Tlo,$Zlo,$Zlo
  185. ldub [$inp+15],$nlo
  186. srlx $Zhi,4,$Zhi
  187. xor $Zlo,$tmp,$Zlo
  188. xor $Thi,$Zhi,$Zhi
  189. stx $Zlo,[$Xi+8]
  190. xor $rem,$Zhi,$Zhi
  191. stx $Zhi,[$Xi]
  192. srl $Zlo,8,$xi1
  193. and $Zlo,0xff,$xi0
  194. ba .Louter
  195. and $xi1,0xff,$xi1
  196. .align 32
  197. .Ldone:
  198. ldx [$Htblo+$nhi],$Tlo
  199. sll $remi,3,$remi
  200. xor $rem,$Zhi,$Zhi
  201. ldx [$Htbl+$nhi],$Thi
  202. srlx $Zlo,4,$Zlo
  203. ldx [$rem_4bit+$remi],$rem
  204. sllx $Zhi,60,$tmp
  205. xor $Tlo,$Zlo,$Zlo
  206. srlx $Zhi,4,$Zhi
  207. xor $Zlo,$tmp,$Zlo
  208. xor $Thi,$Zhi,$Zhi
  209. stx $Zlo,[$Xi+8]
  210. xor $rem,$Zhi,$Zhi
  211. stx $Zhi,[$Xi]
  212. ret
  213. restore
  214. .type gcm_ghash_4bit,#function
  215. .size gcm_ghash_4bit,(.-gcm_ghash_4bit)
  216. ___
  217. undef $inp;
  218. undef $len;
  219. $code.=<<___;
  220. .globl gcm_gmult_4bit
  221. .align 32
  222. gcm_gmult_4bit:
  223. save %sp,-$frame,%sp
  224. ldub [$Xi+15],$nlo
  225. add $Htbl,8,$Htblo
  226. 1: call .+8
  227. add %o7,rem_4bit-1b,$rem_4bit
  228. and $nlo,0xf0,$nhi
  229. and $nlo,0x0f,$nlo
  230. sll $nlo,4,$nlo
  231. ldx [$Htblo+$nlo],$Zlo
  232. ldx [$Htbl+$nlo],$Zhi
  233. ldub [$Xi+14],$nlo
  234. ldx [$Htblo+$nhi],$Tlo
  235. and $Zlo,0xf,$remi
  236. ldx [$Htbl+$nhi],$Thi
  237. sll $remi,3,$remi
  238. ldx [$rem_4bit+$remi],$rem
  239. srlx $Zlo,4,$Zlo
  240. mov 13,$cnt
  241. sllx $Zhi,60,$tmp
  242. xor $Tlo,$Zlo,$Zlo
  243. srlx $Zhi,4,$Zhi
  244. xor $Zlo,$tmp,$Zlo
  245. and $Zlo,0xf,$remi
  246. and $nlo,0xf0,$nhi
  247. and $nlo,0x0f,$nlo
  248. ba .Lgmult_inner
  249. sll $nlo,4,$nlo
  250. .align 32
  251. .Lgmult_inner:
  252. ldx [$Htblo+$nlo],$Tlo
  253. sll $remi,3,$remi
  254. xor $Thi,$Zhi,$Zhi
  255. ldx [$Htbl+$nlo],$Thi
  256. srlx $Zlo,4,$Zlo
  257. xor $rem,$Zhi,$Zhi
  258. ldx [$rem_4bit+$remi],$rem
  259. sllx $Zhi,60,$tmp
  260. xor $Tlo,$Zlo,$Zlo
  261. ldub [$Xi+$cnt],$nlo
  262. srlx $Zhi,4,$Zhi
  263. xor $Zlo,$tmp,$Zlo
  264. xor $Thi,$Zhi,$Zhi
  265. and $Zlo,0xf,$remi
  266. ldx [$Htblo+$nhi],$Tlo
  267. sll $remi,3,$remi
  268. xor $rem,$Zhi,$Zhi
  269. ldx [$Htbl+$nhi],$Thi
  270. srlx $Zlo,4,$Zlo
  271. ldx [$rem_4bit+$remi],$rem
  272. sllx $Zhi,60,$tmp
  273. srlx $Zhi,4,$Zhi
  274. and $nlo,0xf0,$nhi
  275. addcc $cnt,-1,$cnt
  276. xor $Zlo,$tmp,$Zlo
  277. and $nlo,0x0f,$nlo
  278. xor $Tlo,$Zlo,$Zlo
  279. sll $nlo,4,$nlo
  280. blu .Lgmult_inner
  281. and $Zlo,0xf,$remi
  282. ldx [$Htblo+$nlo],$Tlo
  283. sll $remi,3,$remi
  284. xor $Thi,$Zhi,$Zhi
  285. ldx [$Htbl+$nlo],$Thi
  286. srlx $Zlo,4,$Zlo
  287. xor $rem,$Zhi,$Zhi
  288. ldx [$rem_4bit+$remi],$rem
  289. sllx $Zhi,60,$tmp
  290. xor $Tlo,$Zlo,$Zlo
  291. srlx $Zhi,4,$Zhi
  292. xor $Zlo,$tmp,$Zlo
  293. xor $Thi,$Zhi,$Zhi
  294. and $Zlo,0xf,$remi
  295. ldx [$Htblo+$nhi],$Tlo
  296. sll $remi,3,$remi
  297. xor $rem,$Zhi,$Zhi
  298. ldx [$Htbl+$nhi],$Thi
  299. srlx $Zlo,4,$Zlo
  300. ldx [$rem_4bit+$remi],$rem
  301. sllx $Zhi,60,$tmp
  302. xor $Tlo,$Zlo,$Zlo
  303. srlx $Zhi,4,$Zhi
  304. xor $Zlo,$tmp,$Zlo
  305. xor $Thi,$Zhi,$Zhi
  306. stx $Zlo,[$Xi+8]
  307. xor $rem,$Zhi,$Zhi
  308. stx $Zhi,[$Xi]
  309. ret
  310. restore
  311. .type gcm_gmult_4bit,#function
  312. .size gcm_gmult_4bit,(.-gcm_gmult_4bit)
  313. ___
  314. {{{
  315. # Straightforward 128x128-bit multiplication using Karatsuba algorithm
  316. # followed by pair of 64-bit reductions [with a shortcut in first one,
  317. # which allowed to break dependency between reductions and remove one
  318. # multiplication from critical path]. While it might be suboptimal
  319. # with regard to sheer number of multiplications, other methods [such
  320. # as aggregate reduction] would require more 64-bit registers, which
  321. # we don't have in 32-bit application context.
  322. ($Xip,$Htable,$inp,$len)=map("%i$_",(0..3));
  323. ($Hhl,$Hlo,$Hhi,$Xlo,$Xhi,$xE1,$sqr, $C0,$C1,$C2,$C3,$V)=
  324. (map("%o$_",(0..5,7)),map("%g$_",(1..5)));
  325. ($shl,$shr)=map("%l$_",(0..7));
  326. # For details regarding "twisted H" see ghash-x86.pl.
  327. $code.=<<___;
  328. .globl gcm_init_vis3
  329. .align 32
  330. gcm_init_vis3:
  331. save %sp,-$frame,%sp
  332. ldx [%i1+0],$Hhi
  333. ldx [%i1+8],$Hlo
  334. mov 0xE1,$Xhi
  335. mov 1,$Xlo
  336. sllx $Xhi,57,$Xhi
  337. srax $Hhi,63,$C0 ! broadcast carry
  338. addcc $Hlo,$Hlo,$Hlo ! H<<=1
  339. addxc $Hhi,$Hhi,$Hhi
  340. and $C0,$Xlo,$Xlo
  341. and $C0,$Xhi,$Xhi
  342. xor $Xlo,$Hlo,$Hlo
  343. xor $Xhi,$Hhi,$Hhi
  344. stx $Hlo,[%i0+8] ! save twisted H
  345. stx $Hhi,[%i0+0]
  346. sethi %hi(0xA0406080),$V
  347. sethi %hi(0x20C0E000),%l0
  348. or $V,%lo(0xA0406080),$V
  349. or %l0,%lo(0x20C0E000),%l0
  350. sllx $V,32,$V
  351. or %l0,$V,$V ! (0xE0·i)&0xff=0xA040608020C0E000
  352. stx $V,[%i0+16]
  353. ret
  354. restore
  355. .type gcm_init_vis3,#function
  356. .size gcm_init_vis3,.-gcm_init_vis3
  357. .globl gcm_gmult_vis3
  358. .align 32
  359. gcm_gmult_vis3:
  360. save %sp,-$frame,%sp
  361. ldx [$Xip+8],$Xlo ! load Xi
  362. ldx [$Xip+0],$Xhi
  363. ldx [$Htable+8],$Hlo ! load twisted H
  364. ldx [$Htable+0],$Hhi
  365. mov 0xE1,%l7
  366. sllx %l7,57,$xE1 ! 57 is not a typo
  367. ldx [$Htable+16],$V ! (0xE0·i)&0xff=0xA040608020C0E000
  368. xor $Hhi,$Hlo,$Hhl ! Karatsuba pre-processing
  369. xmulx $Xlo,$Hlo,$C0
  370. xor $Xlo,$Xhi,$C2 ! Karatsuba pre-processing
  371. xmulx $C2,$Hhl,$C1
  372. xmulxhi $Xlo,$Hlo,$Xlo
  373. xmulxhi $C2,$Hhl,$C2
  374. xmulxhi $Xhi,$Hhi,$C3
  375. xmulx $Xhi,$Hhi,$Xhi
  376. sll $C0,3,$sqr
  377. srlx $V,$sqr,$sqr ! ·0xE0 [implicit &(7<<3)]
  378. xor $C0,$sqr,$sqr
  379. sllx $sqr,57,$sqr ! ($C0·0xE1)<<1<<56 [implicit &0x7f]
  380. xor $C0,$C1,$C1 ! Karatsuba post-processing
  381. xor $Xlo,$C2,$C2
  382. xor $sqr,$Xlo,$Xlo ! real destination is $C1
  383. xor $C3,$C2,$C2
  384. xor $Xlo,$C1,$C1
  385. xor $Xhi,$C2,$C2
  386. xor $Xhi,$C1,$C1
  387. xmulxhi $C0,$xE1,$Xlo ! ·0xE1<<1<<56
  388. xor $C0,$C2,$C2
  389. xmulx $C1,$xE1,$C0
  390. xor $C1,$C3,$C3
  391. xmulxhi $C1,$xE1,$C1
  392. xor $Xlo,$C2,$C2
  393. xor $C0,$C2,$C2
  394. xor $C1,$C3,$C3
  395. stx $C2,[$Xip+8] ! save Xi
  396. stx $C3,[$Xip+0]
  397. ret
  398. restore
  399. .type gcm_gmult_vis3,#function
  400. .size gcm_gmult_vis3,.-gcm_gmult_vis3
  401. .globl gcm_ghash_vis3
  402. .align 32
  403. gcm_ghash_vis3:
  404. save %sp,-$frame,%sp
  405. nop
  406. srln $len,0,$len ! needed on v8+, "nop" on v9
  407. ldx [$Xip+8],$C2 ! load Xi
  408. ldx [$Xip+0],$C3
  409. ldx [$Htable+8],$Hlo ! load twisted H
  410. ldx [$Htable+0],$Hhi
  411. mov 0xE1,%l7
  412. sllx %l7,57,$xE1 ! 57 is not a typo
  413. ldx [$Htable+16],$V ! (0xE0·i)&0xff=0xA040608020C0E000
  414. and $inp,7,$shl
  415. andn $inp,7,$inp
  416. sll $shl,3,$shl
  417. prefetch [$inp+63], 20
  418. sub %g0,$shl,$shr
  419. xor $Hhi,$Hlo,$Hhl ! Karatsuba pre-processing
  420. .Loop:
  421. ldx [$inp+8],$Xlo
  422. brz,pt $shl,1f
  423. ldx [$inp+0],$Xhi
  424. ldx [$inp+16],$C1 ! align data
  425. srlx $Xlo,$shr,$C0
  426. sllx $Xlo,$shl,$Xlo
  427. sllx $Xhi,$shl,$Xhi
  428. srlx $C1,$shr,$C1
  429. or $C0,$Xhi,$Xhi
  430. or $C1,$Xlo,$Xlo
  431. 1:
  432. add $inp,16,$inp
  433. sub $len,16,$len
  434. xor $C2,$Xlo,$Xlo
  435. xor $C3,$Xhi,$Xhi
  436. prefetch [$inp+63], 20
  437. xmulx $Xlo,$Hlo,$C0
  438. xor $Xlo,$Xhi,$C2 ! Karatsuba pre-processing
  439. xmulx $C2,$Hhl,$C1
  440. xmulxhi $Xlo,$Hlo,$Xlo
  441. xmulxhi $C2,$Hhl,$C2
  442. xmulxhi $Xhi,$Hhi,$C3
  443. xmulx $Xhi,$Hhi,$Xhi
  444. sll $C0,3,$sqr
  445. srlx $V,$sqr,$sqr ! ·0xE0 [implicit &(7<<3)]
  446. xor $C0,$sqr,$sqr
  447. sllx $sqr,57,$sqr ! ($C0·0xE1)<<1<<56 [implicit &0x7f]
  448. xor $C0,$C1,$C1 ! Karatsuba post-processing
  449. xor $Xlo,$C2,$C2
  450. xor $sqr,$Xlo,$Xlo ! real destination is $C1
  451. xor $C3,$C2,$C2
  452. xor $Xlo,$C1,$C1
  453. xor $Xhi,$C2,$C2
  454. xor $Xhi,$C1,$C1
  455. xmulxhi $C0,$xE1,$Xlo ! ·0xE1<<1<<56
  456. xor $C0,$C2,$C2
  457. xmulx $C1,$xE1,$C0
  458. xor $C1,$C3,$C3
  459. xmulxhi $C1,$xE1,$C1
  460. xor $Xlo,$C2,$C2
  461. xor $C0,$C2,$C2
  462. brnz,pt $len,.Loop
  463. xor $C1,$C3,$C3
  464. stx $C2,[$Xip+8] ! save Xi
  465. stx $C3,[$Xip+0]
  466. ret
  467. restore
  468. .type gcm_ghash_vis3,#function
  469. .size gcm_ghash_vis3,.-gcm_ghash_vis3
  470. ___
  471. }}}
  472. $code.=<<___;
  473. .asciz "GHASH for SPARCv9/VIS3, CRYPTOGAMS by <appro\@openssl.org>"
  474. .align 4
  475. ___
  476. # Purpose of these subroutines is to explicitly encode VIS instructions,
  477. # so that one can compile the module without having to specify VIS
  478. # extensions on compiler command line, e.g. -xarch=v9 vs. -xarch=v9a.
  479. # Idea is to reserve for option to produce "universal" binary and let
  480. # programmer detect if current CPU is VIS capable at run-time.
  481. sub unvis3 {
  482. my ($mnemonic,$rs1,$rs2,$rd)=@_;
  483. my %bias = ( "g" => 0, "o" => 8, "l" => 16, "i" => 24 );
  484. my ($ref,$opf);
  485. my %visopf = ( "addxc" => 0x011,
  486. "addxccc" => 0x013,
  487. "xmulx" => 0x115,
  488. "xmulxhi" => 0x116 );
  489. $ref = "$mnemonic\t$rs1,$rs2,$rd";
  490. if ($opf=$visopf{$mnemonic}) {
  491. foreach ($rs1,$rs2,$rd) {
  492. return $ref if (!/%([goli])([0-9])/);
  493. $_=$bias{$1}+$2;
  494. }
  495. return sprintf ".word\t0x%08x !%s",
  496. 0x81b00000|$rd<<25|$rs1<<14|$opf<<5|$rs2,
  497. $ref;
  498. } else {
  499. return $ref;
  500. }
  501. }
  502. foreach (split("\n",$code)) {
  503. s/\`([^\`]*)\`/eval $1/ge;
  504. s/\b(xmulx[hi]*|addxc[c]{0,2})\s+(%[goli][0-7]),\s*(%[goli][0-7]),\s*(%[goli][0-7])/
  505. &unvis3($1,$2,$3,$4)
  506. /ge;
  507. print $_,"\n";
  508. }
  509. close STDOUT or die "error closing STDOUT: $!";