ghash-armv4.pl 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. #!/usr/bin/env perl
  2. #
  3. # ====================================================================
  4. # Written by Andy Polyakov <appro@openssl.org> for the OpenSSL
  5. # project. The module is, however, dual licensed under OpenSSL and
  6. # CRYPTOGAMS licenses depending on where you obtain it. For further
  7. # details see http://www.openssl.org/~appro/cryptogams/.
  8. # ====================================================================
  9. #
  10. # April 2010
  11. #
  12. # The module implements "4-bit" GCM GHASH function and underlying
  13. # single multiplication operation in GF(2^128). "4-bit" means that it
  14. # uses 256 bytes per-key table [+32 bytes shared table]. There is no
  15. # experimental performance data available yet. The only approximation
  16. # that can be made at this point is based on code size. Inner loop is
  17. # 32 instructions long and on single-issue core should execute in <40
  18. # cycles. Having verified that gcc 3.4 didn't unroll corresponding
  19. # loop, this assembler loop body was found to be ~3x smaller than
  20. # compiler-generated one...
  21. #
  22. # July 2010
  23. #
  24. # Rescheduling for dual-issue pipeline resulted in 8.5% improvement on
  25. # Cortex A8 core and ~25 cycles per processed byte (which was observed
  26. # to be ~3 times faster than gcc-generated code:-)
  27. #
  28. # February 2011
  29. #
  30. # Profiler-assisted and platform-specific optimization resulted in 7%
  31. # improvement on Cortex A8 core and ~23.5 cycles per byte.
  32. #
  33. # March 2011
  34. #
  35. # Add NEON implementation featuring polynomial multiplication, i.e. no
  36. # lookup tables involved. On Cortex A8 it was measured to process one
  37. # byte in 15 cycles or 55% faster than integer-only code.
  38. #
  39. # April 2014
  40. #
  41. # Switch to multiplication algorithm suggested in paper referred
  42. # below and combine it with reduction algorithm from x86 module.
  43. # Performance improvement over previous version varies from 65% on
  44. # Snapdragon S4 to 110% on Cortex A9. In absolute terms Cortex A8
  45. # processes one byte in 8.45 cycles, A9 - in 10.2, Snapdragon S4 -
  46. # in 9.33.
  47. #
  48. # Câmara, D.; Gouvêa, C. P. L.; López, J. & Dahab, R.: Fast Software
  49. # Polynomial Multiplication on ARM Processors using the NEON Engine.
  50. #
  51. # http://conradoplg.cryptoland.net/files/2010/12/mocrysen13.pdf
  52. # ====================================================================
  53. # Note about "528B" variant. In ARM case it makes lesser sense to
  54. # implement it for following reasons:
  55. #
  56. # - performance improvement won't be anywhere near 50%, because 128-
  57. # bit shift operation is neatly fused with 128-bit xor here, and
  58. # "538B" variant would eliminate only 4-5 instructions out of 32
  59. # in the inner loop (meaning that estimated improvement is ~15%);
  60. # - ARM-based systems are often embedded ones and extra memory
  61. # consumption might be unappreciated (for so little improvement);
  62. #
  63. # Byte order [in]dependence. =========================================
  64. #
  65. # Caller is expected to maintain specific *dword* order in Htable,
  66. # namely with *least* significant dword of 128-bit value at *lower*
  67. # address. This differs completely from C code and has everything to
  68. # do with ldm instruction and order in which dwords are "consumed" by
  69. # algorithm. *Byte* order within these dwords in turn is whatever
  70. # *native* byte order on current platform. See gcm128.c for working
  71. # example...
  72. while (($output=shift) && ($output!~/^\w[\w\-]*\.\w+$/)) {}
  73. open STDOUT,">$output";
  74. $Xi="r0"; # argument block
  75. $Htbl="r1";
  76. $inp="r2";
  77. $len="r3";
  78. $Zll="r4"; # variables
  79. $Zlh="r5";
  80. $Zhl="r6";
  81. $Zhh="r7";
  82. $Tll="r8";
  83. $Tlh="r9";
  84. $Thl="r10";
  85. $Thh="r11";
  86. $nlo="r12";
  87. ################# r13 is stack pointer
  88. $nhi="r14";
  89. ################# r15 is program counter
  90. $rem_4bit=$inp; # used in gcm_gmult_4bit
  91. $cnt=$len;
  92. sub Zsmash() {
  93. my $i=12;
  94. my @args=@_;
  95. for ($Zll,$Zlh,$Zhl,$Zhh) {
  96. $code.=<<___;
  97. #if __ARM_ARCH__>=7 && defined(__ARMEL__)
  98. rev $_,$_
  99. str $_,[$Xi,#$i]
  100. #elif defined(__ARMEB__)
  101. str $_,[$Xi,#$i]
  102. #else
  103. mov $Tlh,$_,lsr#8
  104. strb $_,[$Xi,#$i+3]
  105. mov $Thl,$_,lsr#16
  106. strb $Tlh,[$Xi,#$i+2]
  107. mov $Thh,$_,lsr#24
  108. strb $Thl,[$Xi,#$i+1]
  109. strb $Thh,[$Xi,#$i]
  110. #endif
  111. ___
  112. $code.="\t".shift(@args)."\n";
  113. $i-=4;
  114. }
  115. }
  116. $code=<<___;
  117. #include "arm_arch.h"
  118. .text
  119. .code 32
  120. #ifdef __clang__
  121. #define ldrplb ldrbpl
  122. #define ldrneb ldrbne
  123. #endif
  124. .type rem_4bit,%object
  125. .align 5
  126. rem_4bit:
  127. .short 0x0000,0x1C20,0x3840,0x2460
  128. .short 0x7080,0x6CA0,0x48C0,0x54E0
  129. .short 0xE100,0xFD20,0xD940,0xC560
  130. .short 0x9180,0x8DA0,0xA9C0,0xB5E0
  131. .size rem_4bit,.-rem_4bit
  132. .type rem_4bit_get,%function
  133. rem_4bit_get:
  134. sub $rem_4bit,pc,#8
  135. sub $rem_4bit,$rem_4bit,#32 @ &rem_4bit
  136. b .Lrem_4bit_got
  137. nop
  138. .size rem_4bit_get,.-rem_4bit_get
  139. .global gcm_ghash_4bit
  140. .type gcm_ghash_4bit,%function
  141. gcm_ghash_4bit:
  142. sub r12,pc,#8
  143. add $len,$inp,$len @ $len to point at the end
  144. stmdb sp!,{r3-r11,lr} @ save $len/end too
  145. sub r12,r12,#48 @ &rem_4bit
  146. ldmia r12,{r4-r11} @ copy rem_4bit ...
  147. stmdb sp!,{r4-r11} @ ... to stack
  148. ldrb $nlo,[$inp,#15]
  149. ldrb $nhi,[$Xi,#15]
  150. .Louter:
  151. eor $nlo,$nlo,$nhi
  152. and $nhi,$nlo,#0xf0
  153. and $nlo,$nlo,#0x0f
  154. mov $cnt,#14
  155. add $Zhh,$Htbl,$nlo,lsl#4
  156. ldmia $Zhh,{$Zll-$Zhh} @ load Htbl[nlo]
  157. add $Thh,$Htbl,$nhi
  158. ldrb $nlo,[$inp,#14]
  159. and $nhi,$Zll,#0xf @ rem
  160. ldmia $Thh,{$Tll-$Thh} @ load Htbl[nhi]
  161. add $nhi,$nhi,$nhi
  162. eor $Zll,$Tll,$Zll,lsr#4
  163. ldrh $Tll,[sp,$nhi] @ rem_4bit[rem]
  164. eor $Zll,$Zll,$Zlh,lsl#28
  165. ldrb $nhi,[$Xi,#14]
  166. eor $Zlh,$Tlh,$Zlh,lsr#4
  167. eor $Zlh,$Zlh,$Zhl,lsl#28
  168. eor $Zhl,$Thl,$Zhl,lsr#4
  169. eor $Zhl,$Zhl,$Zhh,lsl#28
  170. eor $Zhh,$Thh,$Zhh,lsr#4
  171. eor $nlo,$nlo,$nhi
  172. and $nhi,$nlo,#0xf0
  173. and $nlo,$nlo,#0x0f
  174. eor $Zhh,$Zhh,$Tll,lsl#16
  175. .Linner:
  176. add $Thh,$Htbl,$nlo,lsl#4
  177. and $nlo,$Zll,#0xf @ rem
  178. subs $cnt,$cnt,#1
  179. add $nlo,$nlo,$nlo
  180. ldmia $Thh,{$Tll-$Thh} @ load Htbl[nlo]
  181. eor $Zll,$Tll,$Zll,lsr#4
  182. eor $Zll,$Zll,$Zlh,lsl#28
  183. eor $Zlh,$Tlh,$Zlh,lsr#4
  184. eor $Zlh,$Zlh,$Zhl,lsl#28
  185. ldrh $Tll,[sp,$nlo] @ rem_4bit[rem]
  186. eor $Zhl,$Thl,$Zhl,lsr#4
  187. ldrplb $nlo,[$inp,$cnt]
  188. eor $Zhl,$Zhl,$Zhh,lsl#28
  189. eor $Zhh,$Thh,$Zhh,lsr#4
  190. add $Thh,$Htbl,$nhi
  191. and $nhi,$Zll,#0xf @ rem
  192. eor $Zhh,$Zhh,$Tll,lsl#16 @ ^= rem_4bit[rem]
  193. add $nhi,$nhi,$nhi
  194. ldmia $Thh,{$Tll-$Thh} @ load Htbl[nhi]
  195. eor $Zll,$Tll,$Zll,lsr#4
  196. ldrplb $Tll,[$Xi,$cnt]
  197. eor $Zll,$Zll,$Zlh,lsl#28
  198. eor $Zlh,$Tlh,$Zlh,lsr#4
  199. ldrh $Tlh,[sp,$nhi]
  200. eor $Zlh,$Zlh,$Zhl,lsl#28
  201. eor $Zhl,$Thl,$Zhl,lsr#4
  202. eor $Zhl,$Zhl,$Zhh,lsl#28
  203. eorpl $nlo,$nlo,$Tll
  204. eor $Zhh,$Thh,$Zhh,lsr#4
  205. andpl $nhi,$nlo,#0xf0
  206. andpl $nlo,$nlo,#0x0f
  207. eor $Zhh,$Zhh,$Tlh,lsl#16 @ ^= rem_4bit[rem]
  208. bpl .Linner
  209. ldr $len,[sp,#32] @ re-load $len/end
  210. add $inp,$inp,#16
  211. mov $nhi,$Zll
  212. ___
  213. &Zsmash("cmp\t$inp,$len","ldrneb\t$nlo,[$inp,#15]");
  214. $code.=<<___;
  215. bne .Louter
  216. add sp,sp,#36
  217. #if __ARM_ARCH__>=5
  218. ldmia sp!,{r4-r11,pc}
  219. #else
  220. ldmia sp!,{r4-r11,lr}
  221. tst lr,#1
  222. moveq pc,lr @ be binary compatible with V4, yet
  223. bx lr @ interoperable with Thumb ISA:-)
  224. #endif
  225. .size gcm_ghash_4bit,.-gcm_ghash_4bit
  226. .global gcm_gmult_4bit
  227. .type gcm_gmult_4bit,%function
  228. gcm_gmult_4bit:
  229. stmdb sp!,{r4-r11,lr}
  230. ldrb $nlo,[$Xi,#15]
  231. b rem_4bit_get
  232. .Lrem_4bit_got:
  233. and $nhi,$nlo,#0xf0
  234. and $nlo,$nlo,#0x0f
  235. mov $cnt,#14
  236. add $Zhh,$Htbl,$nlo,lsl#4
  237. ldmia $Zhh,{$Zll-$Zhh} @ load Htbl[nlo]
  238. ldrb $nlo,[$Xi,#14]
  239. add $Thh,$Htbl,$nhi
  240. and $nhi,$Zll,#0xf @ rem
  241. ldmia $Thh,{$Tll-$Thh} @ load Htbl[nhi]
  242. add $nhi,$nhi,$nhi
  243. eor $Zll,$Tll,$Zll,lsr#4
  244. ldrh $Tll,[$rem_4bit,$nhi] @ rem_4bit[rem]
  245. eor $Zll,$Zll,$Zlh,lsl#28
  246. eor $Zlh,$Tlh,$Zlh,lsr#4
  247. eor $Zlh,$Zlh,$Zhl,lsl#28
  248. eor $Zhl,$Thl,$Zhl,lsr#4
  249. eor $Zhl,$Zhl,$Zhh,lsl#28
  250. eor $Zhh,$Thh,$Zhh,lsr#4
  251. and $nhi,$nlo,#0xf0
  252. eor $Zhh,$Zhh,$Tll,lsl#16
  253. and $nlo,$nlo,#0x0f
  254. .Loop:
  255. add $Thh,$Htbl,$nlo,lsl#4
  256. and $nlo,$Zll,#0xf @ rem
  257. subs $cnt,$cnt,#1
  258. add $nlo,$nlo,$nlo
  259. ldmia $Thh,{$Tll-$Thh} @ load Htbl[nlo]
  260. eor $Zll,$Tll,$Zll,lsr#4
  261. eor $Zll,$Zll,$Zlh,lsl#28
  262. eor $Zlh,$Tlh,$Zlh,lsr#4
  263. eor $Zlh,$Zlh,$Zhl,lsl#28
  264. ldrh $Tll,[$rem_4bit,$nlo] @ rem_4bit[rem]
  265. eor $Zhl,$Thl,$Zhl,lsr#4
  266. ldrplb $nlo,[$Xi,$cnt]
  267. eor $Zhl,$Zhl,$Zhh,lsl#28
  268. eor $Zhh,$Thh,$Zhh,lsr#4
  269. add $Thh,$Htbl,$nhi
  270. and $nhi,$Zll,#0xf @ rem
  271. eor $Zhh,$Zhh,$Tll,lsl#16 @ ^= rem_4bit[rem]
  272. add $nhi,$nhi,$nhi
  273. ldmia $Thh,{$Tll-$Thh} @ load Htbl[nhi]
  274. eor $Zll,$Tll,$Zll,lsr#4
  275. eor $Zll,$Zll,$Zlh,lsl#28
  276. eor $Zlh,$Tlh,$Zlh,lsr#4
  277. ldrh $Tll,[$rem_4bit,$nhi] @ rem_4bit[rem]
  278. eor $Zlh,$Zlh,$Zhl,lsl#28
  279. eor $Zhl,$Thl,$Zhl,lsr#4
  280. eor $Zhl,$Zhl,$Zhh,lsl#28
  281. eor $Zhh,$Thh,$Zhh,lsr#4
  282. andpl $nhi,$nlo,#0xf0
  283. andpl $nlo,$nlo,#0x0f
  284. eor $Zhh,$Zhh,$Tll,lsl#16 @ ^= rem_4bit[rem]
  285. bpl .Loop
  286. ___
  287. &Zsmash();
  288. $code.=<<___;
  289. #if __ARM_ARCH__>=5
  290. ldmia sp!,{r4-r11,pc}
  291. #else
  292. ldmia sp!,{r4-r11,lr}
  293. tst lr,#1
  294. moveq pc,lr @ be binary compatible with V4, yet
  295. bx lr @ interoperable with Thumb ISA:-)
  296. #endif
  297. .size gcm_gmult_4bit,.-gcm_gmult_4bit
  298. ___
  299. {
  300. my ($Xl,$Xm,$Xh,$IN)=map("q$_",(0..3));
  301. my ($t0,$t1,$t2,$t3)=map("q$_",(8..12));
  302. my ($Hlo,$Hhi,$Hhl,$k48,$k32,$k16)=map("d$_",(26..31));
  303. sub clmul64x64 {
  304. my ($r,$a,$b)=@_;
  305. $code.=<<___;
  306. vext.8 $t0#lo, $a, $a, #1 @ A1
  307. vmull.p8 $t0, $t0#lo, $b @ F = A1*B
  308. vext.8 $r#lo, $b, $b, #1 @ B1
  309. vmull.p8 $r, $a, $r#lo @ E = A*B1
  310. vext.8 $t1#lo, $a, $a, #2 @ A2
  311. vmull.p8 $t1, $t1#lo, $b @ H = A2*B
  312. vext.8 $t3#lo, $b, $b, #2 @ B2
  313. vmull.p8 $t3, $a, $t3#lo @ G = A*B2
  314. vext.8 $t2#lo, $a, $a, #3 @ A3
  315. veor $t0, $t0, $r @ L = E + F
  316. vmull.p8 $t2, $t2#lo, $b @ J = A3*B
  317. vext.8 $r#lo, $b, $b, #3 @ B3
  318. veor $t1, $t1, $t3 @ M = G + H
  319. vmull.p8 $r, $a, $r#lo @ I = A*B3
  320. veor $t0#lo, $t0#lo, $t0#hi @ t0 = (L) (P0 + P1) << 8
  321. vand $t0#hi, $t0#hi, $k48
  322. vext.8 $t3#lo, $b, $b, #4 @ B4
  323. veor $t1#lo, $t1#lo, $t1#hi @ t1 = (M) (P2 + P3) << 16
  324. vand $t1#hi, $t1#hi, $k32
  325. vmull.p8 $t3, $a, $t3#lo @ K = A*B4
  326. veor $t2, $t2, $r @ N = I + J
  327. veor $t0#lo, $t0#lo, $t0#hi
  328. veor $t1#lo, $t1#lo, $t1#hi
  329. veor $t2#lo, $t2#lo, $t2#hi @ t2 = (N) (P4 + P5) << 24
  330. vand $t2#hi, $t2#hi, $k16
  331. vext.8 $t0, $t0, $t0, #15
  332. veor $t3#lo, $t3#lo, $t3#hi @ t3 = (K) (P6 + P7) << 32
  333. vmov.i64 $t3#hi, #0
  334. vext.8 $t1, $t1, $t1, #14
  335. veor $t2#lo, $t2#lo, $t2#hi
  336. vmull.p8 $r, $a, $b @ D = A*B
  337. vext.8 $t3, $t3, $t3, #12
  338. vext.8 $t2, $t2, $t2, #13
  339. veor $t0, $t0, $t1
  340. veor $t2, $t2, $t3
  341. veor $r, $r, $t0
  342. veor $r, $r, $t2
  343. ___
  344. }
  345. $code.=<<___;
  346. #if __ARM_MAX_ARCH__>=7
  347. .arch armv7-a
  348. .fpu neon
  349. .global gcm_init_neon
  350. .type gcm_init_neon,%function
  351. .align 4
  352. gcm_init_neon:
  353. vld1.64 $IN#hi,[r1,:64]! @ load H
  354. vmov.i8 $t0,#0xe1
  355. vld1.64 $IN#lo,[r1,:64]
  356. vshl.i64 $t0#hi,#57
  357. vshr.u64 $t0#lo,#63 @ t0=0xc2....01
  358. vdup.8 $t1,$IN#hi[7]
  359. vshr.u64 $Hlo,$IN#lo,#63
  360. vshr.s8 $t1,#7 @ broadcast carry bit
  361. vshl.i64 $IN,$IN,#1
  362. vand $t0,$t0,$t1
  363. vorr $IN#hi,$Hlo @ H<<<=1
  364. veor $IN,$IN,$t0 @ twisted H
  365. vstmia r0,{$IN}
  366. ret @ bx lr
  367. .size gcm_init_neon,.-gcm_init_neon
  368. .global gcm_gmult_neon
  369. .type gcm_gmult_neon,%function
  370. .align 4
  371. gcm_gmult_neon:
  372. vld1.64 $IN#hi,[$Xi,:64]! @ load Xi
  373. vld1.64 $IN#lo,[$Xi,:64]!
  374. vmov.i64 $k48,#0x0000ffffffffffff
  375. vldmia $Htbl,{$Hlo-$Hhi} @ load twisted H
  376. vmov.i64 $k32,#0x00000000ffffffff
  377. #ifdef __ARMEL__
  378. vrev64.8 $IN,$IN
  379. #endif
  380. vmov.i64 $k16,#0x000000000000ffff
  381. veor $Hhl,$Hlo,$Hhi @ Karatsuba pre-processing
  382. mov $len,#16
  383. b .Lgmult_neon
  384. .size gcm_gmult_neon,.-gcm_gmult_neon
  385. .global gcm_ghash_neon
  386. .type gcm_ghash_neon,%function
  387. .align 4
  388. gcm_ghash_neon:
  389. vld1.64 $Xl#hi,[$Xi,:64]! @ load Xi
  390. vld1.64 $Xl#lo,[$Xi,:64]!
  391. vmov.i64 $k48,#0x0000ffffffffffff
  392. vldmia $Htbl,{$Hlo-$Hhi} @ load twisted H
  393. vmov.i64 $k32,#0x00000000ffffffff
  394. #ifdef __ARMEL__
  395. vrev64.8 $Xl,$Xl
  396. #endif
  397. vmov.i64 $k16,#0x000000000000ffff
  398. veor $Hhl,$Hlo,$Hhi @ Karatsuba pre-processing
  399. .Loop_neon:
  400. vld1.64 $IN#hi,[$inp]! @ load inp
  401. vld1.64 $IN#lo,[$inp]!
  402. #ifdef __ARMEL__
  403. vrev64.8 $IN,$IN
  404. #endif
  405. veor $IN,$Xl @ inp^=Xi
  406. .Lgmult_neon:
  407. ___
  408. &clmul64x64 ($Xl,$Hlo,"$IN#lo"); # H.lo·Xi.lo
  409. $code.=<<___;
  410. veor $IN#lo,$IN#lo,$IN#hi @ Karatsuba pre-processing
  411. ___
  412. &clmul64x64 ($Xm,$Hhl,"$IN#lo"); # (H.lo+H.hi)·(Xi.lo+Xi.hi)
  413. &clmul64x64 ($Xh,$Hhi,"$IN#hi"); # H.hi·Xi.hi
  414. $code.=<<___;
  415. veor $Xm,$Xm,$Xl @ Karatsuba post-processing
  416. veor $Xm,$Xm,$Xh
  417. veor $Xl#hi,$Xl#hi,$Xm#lo
  418. veor $Xh#lo,$Xh#lo,$Xm#hi @ Xh|Xl - 256-bit result
  419. @ equivalent of reduction_avx from ghash-x86_64.pl
  420. vshl.i64 $t1,$Xl,#57 @ 1st phase
  421. vshl.i64 $t2,$Xl,#62
  422. veor $t2,$t2,$t1 @
  423. vshl.i64 $t1,$Xl,#63
  424. veor $t2, $t2, $t1 @
  425. veor $Xl#hi,$Xl#hi,$t2#lo @
  426. veor $Xh#lo,$Xh#lo,$t2#hi
  427. vshr.u64 $t2,$Xl,#1 @ 2nd phase
  428. veor $Xh,$Xh,$Xl
  429. veor $Xl,$Xl,$t2 @
  430. vshr.u64 $t2,$t2,#6
  431. vshr.u64 $Xl,$Xl,#1 @
  432. veor $Xl,$Xl,$Xh @
  433. veor $Xl,$Xl,$t2 @
  434. subs $len,#16
  435. bne .Loop_neon
  436. #ifdef __ARMEL__
  437. vrev64.8 $Xl,$Xl
  438. #endif
  439. sub $Xi,#16
  440. vst1.64 $Xl#hi,[$Xi,:64]! @ write out Xi
  441. vst1.64 $Xl#lo,[$Xi,:64]
  442. ret @ bx lr
  443. .size gcm_ghash_neon,.-gcm_ghash_neon
  444. #endif
  445. ___
  446. }
  447. $code.=<<___;
  448. .asciz "GHASH for ARMv4/NEON, CRYPTOGAMS by <appro\@openssl.org>"
  449. .align 2
  450. ___
  451. foreach (split("\n",$code)) {
  452. s/\`([^\`]*)\`/eval $1/geo;
  453. s/\bq([0-9]+)#(lo|hi)/sprintf "d%d",2*$1+($2 eq "hi")/geo or
  454. s/\bret\b/bx lr/go or
  455. s/\bbx\s+lr\b/.word\t0xe12fff1e/go; # make it possible to compile with -march=armv4
  456. print $_,"\n";
  457. }
  458. close STDOUT; # enforce flush