Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

521 lignes
13 KiB

  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, A15 - in 7.63,
  46. # Snapdragon S4 - 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. $flavour = shift;
  73. if ($flavour=~/^\w[\w\-]*\.\w+$/) { $output=$flavour; undef $flavour; }
  74. else { while (($output=shift) && ($output!~/^\w[\w\-]*\.\w+$/)) {} }
  75. if ($flavour && $flavour ne "void") {
  76. $0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
  77. ( $xlate="${dir}arm-xlate.pl" and -f $xlate ) or
  78. ( $xlate="${dir}../../perlasm/arm-xlate.pl" and -f $xlate) or
  79. die "can't locate arm-xlate.pl";
  80. open STDOUT,"| \"$^X\" $xlate $flavour $output";
  81. } else {
  82. open STDOUT,">$output";
  83. }
  84. $Xi="r0"; # argument block
  85. $Htbl="r1";
  86. $inp="r2";
  87. $len="r3";
  88. $Zll="r4"; # variables
  89. $Zlh="r5";
  90. $Zhl="r6";
  91. $Zhh="r7";
  92. $Tll="r8";
  93. $Tlh="r9";
  94. $Thl="r10";
  95. $Thh="r11";
  96. $nlo="r12";
  97. ################# r13 is stack pointer
  98. $nhi="r14";
  99. ################# r15 is program counter
  100. $rem_4bit=$inp; # used in gcm_gmult_4bit
  101. $cnt=$len;
  102. sub Zsmash() {
  103. my $i=12;
  104. my @args=@_;
  105. for ($Zll,$Zlh,$Zhl,$Zhh) {
  106. $code.=<<___;
  107. #if __ARM_ARCH__>=7 && defined(__ARMEL__)
  108. rev $_,$_
  109. str $_,[$Xi,#$i]
  110. #elif defined(__ARMEB__)
  111. str $_,[$Xi,#$i]
  112. #else
  113. mov $Tlh,$_,lsr#8
  114. strb $_,[$Xi,#$i+3]
  115. mov $Thl,$_,lsr#16
  116. strb $Tlh,[$Xi,#$i+2]
  117. mov $Thh,$_,lsr#24
  118. strb $Thl,[$Xi,#$i+1]
  119. strb $Thh,[$Xi,#$i]
  120. #endif
  121. ___
  122. $code.="\t".shift(@args)."\n";
  123. $i-=4;
  124. }
  125. }
  126. $code=<<___;
  127. #if defined(__arm__)
  128. #include "arm_arch.h"
  129. .syntax unified
  130. .text
  131. .code 32
  132. #ifdef __APPLE__
  133. #define ldrplb ldrbpl
  134. #define ldrneb ldrbne
  135. #endif
  136. .type rem_4bit,%object
  137. .align 5
  138. rem_4bit:
  139. .short 0x0000,0x1C20,0x3840,0x2460
  140. .short 0x7080,0x6CA0,0x48C0,0x54E0
  141. .short 0xE100,0xFD20,0xD940,0xC560
  142. .short 0x9180,0x8DA0,0xA9C0,0xB5E0
  143. .size rem_4bit,.-rem_4bit
  144. .type rem_4bit_get,%function
  145. rem_4bit_get:
  146. sub $rem_4bit,pc,#8
  147. sub $rem_4bit,$rem_4bit,#32 @ &rem_4bit
  148. b .Lrem_4bit_got
  149. nop
  150. .size rem_4bit_get,.-rem_4bit_get
  151. .global gcm_ghash_4bit
  152. .hidden gcm_ghash_4bit
  153. .type gcm_ghash_4bit,%function
  154. gcm_ghash_4bit:
  155. sub r12,pc,#8
  156. add $len,$inp,$len @ $len to point at the end
  157. stmdb sp!,{r3-r11,lr} @ save $len/end too
  158. sub r12,r12,#48 @ &rem_4bit
  159. ldmia r12,{r4-r11} @ copy rem_4bit ...
  160. stmdb sp!,{r4-r11} @ ... to stack
  161. ldrb $nlo,[$inp,#15]
  162. ldrb $nhi,[$Xi,#15]
  163. .Louter:
  164. eor $nlo,$nlo,$nhi
  165. and $nhi,$nlo,#0xf0
  166. and $nlo,$nlo,#0x0f
  167. mov $cnt,#14
  168. add $Zhh,$Htbl,$nlo,lsl#4
  169. ldmia $Zhh,{$Zll-$Zhh} @ load Htbl[nlo]
  170. add $Thh,$Htbl,$nhi
  171. ldrb $nlo,[$inp,#14]
  172. and $nhi,$Zll,#0xf @ rem
  173. ldmia $Thh,{$Tll-$Thh} @ load Htbl[nhi]
  174. add $nhi,$nhi,$nhi
  175. eor $Zll,$Tll,$Zll,lsr#4
  176. ldrh $Tll,[sp,$nhi] @ rem_4bit[rem]
  177. eor $Zll,$Zll,$Zlh,lsl#28
  178. ldrb $nhi,[$Xi,#14]
  179. eor $Zlh,$Tlh,$Zlh,lsr#4
  180. eor $Zlh,$Zlh,$Zhl,lsl#28
  181. eor $Zhl,$Thl,$Zhl,lsr#4
  182. eor $Zhl,$Zhl,$Zhh,lsl#28
  183. eor $Zhh,$Thh,$Zhh,lsr#4
  184. eor $nlo,$nlo,$nhi
  185. and $nhi,$nlo,#0xf0
  186. and $nlo,$nlo,#0x0f
  187. eor $Zhh,$Zhh,$Tll,lsl#16
  188. .Linner:
  189. add $Thh,$Htbl,$nlo,lsl#4
  190. and $nlo,$Zll,#0xf @ rem
  191. subs $cnt,$cnt,#1
  192. add $nlo,$nlo,$nlo
  193. ldmia $Thh,{$Tll-$Thh} @ load Htbl[nlo]
  194. eor $Zll,$Tll,$Zll,lsr#4
  195. eor $Zll,$Zll,$Zlh,lsl#28
  196. eor $Zlh,$Tlh,$Zlh,lsr#4
  197. eor $Zlh,$Zlh,$Zhl,lsl#28
  198. ldrh $Tll,[sp,$nlo] @ rem_4bit[rem]
  199. eor $Zhl,$Thl,$Zhl,lsr#4
  200. ldrbpl $nlo,[$inp,$cnt]
  201. eor $Zhl,$Zhl,$Zhh,lsl#28
  202. eor $Zhh,$Thh,$Zhh,lsr#4
  203. add $Thh,$Htbl,$nhi
  204. and $nhi,$Zll,#0xf @ rem
  205. eor $Zhh,$Zhh,$Tll,lsl#16 @ ^= rem_4bit[rem]
  206. add $nhi,$nhi,$nhi
  207. ldmia $Thh,{$Tll-$Thh} @ load Htbl[nhi]
  208. eor $Zll,$Tll,$Zll,lsr#4
  209. ldrbpl $Tll,[$Xi,$cnt]
  210. eor $Zll,$Zll,$Zlh,lsl#28
  211. eor $Zlh,$Tlh,$Zlh,lsr#4
  212. ldrh $Tlh,[sp,$nhi]
  213. eor $Zlh,$Zlh,$Zhl,lsl#28
  214. eor $Zhl,$Thl,$Zhl,lsr#4
  215. eor $Zhl,$Zhl,$Zhh,lsl#28
  216. eorpl $nlo,$nlo,$Tll
  217. eor $Zhh,$Thh,$Zhh,lsr#4
  218. andpl $nhi,$nlo,#0xf0
  219. andpl $nlo,$nlo,#0x0f
  220. eor $Zhh,$Zhh,$Tlh,lsl#16 @ ^= rem_4bit[rem]
  221. bpl .Linner
  222. ldr $len,[sp,#32] @ re-load $len/end
  223. add $inp,$inp,#16
  224. mov $nhi,$Zll
  225. ___
  226. &Zsmash("cmp\t$inp,$len","ldrbne\t$nlo,[$inp,#15]");
  227. $code.=<<___;
  228. bne .Louter
  229. add sp,sp,#36
  230. #if __ARM_ARCH__>=5
  231. ldmia sp!,{r4-r11,pc}
  232. #else
  233. ldmia sp!,{r4-r11,lr}
  234. tst lr,#1
  235. moveq pc,lr @ be binary compatible with V4, yet
  236. bx lr @ interoperable with Thumb ISA:-)
  237. #endif
  238. .size gcm_ghash_4bit,.-gcm_ghash_4bit
  239. .global gcm_gmult_4bit
  240. .hidden gcm_gmult_4bit
  241. .type gcm_gmult_4bit,%function
  242. gcm_gmult_4bit:
  243. stmdb sp!,{r4-r11,lr}
  244. ldrb $nlo,[$Xi,#15]
  245. b rem_4bit_get
  246. .Lrem_4bit_got:
  247. and $nhi,$nlo,#0xf0
  248. and $nlo,$nlo,#0x0f
  249. mov $cnt,#14
  250. add $Zhh,$Htbl,$nlo,lsl#4
  251. ldmia $Zhh,{$Zll-$Zhh} @ load Htbl[nlo]
  252. ldrb $nlo,[$Xi,#14]
  253. add $Thh,$Htbl,$nhi
  254. and $nhi,$Zll,#0xf @ rem
  255. ldmia $Thh,{$Tll-$Thh} @ load Htbl[nhi]
  256. add $nhi,$nhi,$nhi
  257. eor $Zll,$Tll,$Zll,lsr#4
  258. ldrh $Tll,[$rem_4bit,$nhi] @ rem_4bit[rem]
  259. eor $Zll,$Zll,$Zlh,lsl#28
  260. eor $Zlh,$Tlh,$Zlh,lsr#4
  261. eor $Zlh,$Zlh,$Zhl,lsl#28
  262. eor $Zhl,$Thl,$Zhl,lsr#4
  263. eor $Zhl,$Zhl,$Zhh,lsl#28
  264. eor $Zhh,$Thh,$Zhh,lsr#4
  265. and $nhi,$nlo,#0xf0
  266. eor $Zhh,$Zhh,$Tll,lsl#16
  267. and $nlo,$nlo,#0x0f
  268. .Loop:
  269. add $Thh,$Htbl,$nlo,lsl#4
  270. and $nlo,$Zll,#0xf @ rem
  271. subs $cnt,$cnt,#1
  272. add $nlo,$nlo,$nlo
  273. ldmia $Thh,{$Tll-$Thh} @ load Htbl[nlo]
  274. eor $Zll,$Tll,$Zll,lsr#4
  275. eor $Zll,$Zll,$Zlh,lsl#28
  276. eor $Zlh,$Tlh,$Zlh,lsr#4
  277. eor $Zlh,$Zlh,$Zhl,lsl#28
  278. ldrh $Tll,[$rem_4bit,$nlo] @ rem_4bit[rem]
  279. eor $Zhl,$Thl,$Zhl,lsr#4
  280. ldrbpl $nlo,[$Xi,$cnt]
  281. eor $Zhl,$Zhl,$Zhh,lsl#28
  282. eor $Zhh,$Thh,$Zhh,lsr#4
  283. add $Thh,$Htbl,$nhi
  284. and $nhi,$Zll,#0xf @ rem
  285. eor $Zhh,$Zhh,$Tll,lsl#16 @ ^= rem_4bit[rem]
  286. add $nhi,$nhi,$nhi
  287. ldmia $Thh,{$Tll-$Thh} @ load Htbl[nhi]
  288. eor $Zll,$Tll,$Zll,lsr#4
  289. eor $Zll,$Zll,$Zlh,lsl#28
  290. eor $Zlh,$Tlh,$Zlh,lsr#4
  291. ldrh $Tll,[$rem_4bit,$nhi] @ rem_4bit[rem]
  292. eor $Zlh,$Zlh,$Zhl,lsl#28
  293. eor $Zhl,$Thl,$Zhl,lsr#4
  294. eor $Zhl,$Zhl,$Zhh,lsl#28
  295. eor $Zhh,$Thh,$Zhh,lsr#4
  296. andpl $nhi,$nlo,#0xf0
  297. andpl $nlo,$nlo,#0x0f
  298. eor $Zhh,$Zhh,$Tll,lsl#16 @ ^= rem_4bit[rem]
  299. bpl .Loop
  300. ___
  301. &Zsmash();
  302. $code.=<<___;
  303. #if __ARM_ARCH__>=5
  304. ldmia sp!,{r4-r11,pc}
  305. #else
  306. ldmia sp!,{r4-r11,lr}
  307. tst lr,#1
  308. moveq pc,lr @ be binary compatible with V4, yet
  309. bx lr @ interoperable with Thumb ISA:-)
  310. #endif
  311. .size gcm_gmult_4bit,.-gcm_gmult_4bit
  312. ___
  313. {
  314. my ($Xl,$Xm,$Xh,$IN)=map("q$_",(0..3));
  315. my ($t0,$t1,$t2,$t3)=map("q$_",(8..12));
  316. my ($Hlo,$Hhi,$Hhl,$k48,$k32,$k16)=map("d$_",(26..31));
  317. sub clmul64x64 {
  318. my ($r,$a,$b)=@_;
  319. $code.=<<___;
  320. vext.8 $t0#lo, $a, $a, #1 @ A1
  321. vmull.p8 $t0, $t0#lo, $b @ F = A1*B
  322. vext.8 $r#lo, $b, $b, #1 @ B1
  323. vmull.p8 $r, $a, $r#lo @ E = A*B1
  324. vext.8 $t1#lo, $a, $a, #2 @ A2
  325. vmull.p8 $t1, $t1#lo, $b @ H = A2*B
  326. vext.8 $t3#lo, $b, $b, #2 @ B2
  327. vmull.p8 $t3, $a, $t3#lo @ G = A*B2
  328. vext.8 $t2#lo, $a, $a, #3 @ A3
  329. veor $t0, $t0, $r @ L = E + F
  330. vmull.p8 $t2, $t2#lo, $b @ J = A3*B
  331. vext.8 $r#lo, $b, $b, #3 @ B3
  332. veor $t1, $t1, $t3 @ M = G + H
  333. vmull.p8 $r, $a, $r#lo @ I = A*B3
  334. veor $t0#lo, $t0#lo, $t0#hi @ t0 = (L) (P0 + P1) << 8
  335. vand $t0#hi, $t0#hi, $k48
  336. vext.8 $t3#lo, $b, $b, #4 @ B4
  337. veor $t1#lo, $t1#lo, $t1#hi @ t1 = (M) (P2 + P3) << 16
  338. vand $t1#hi, $t1#hi, $k32
  339. vmull.p8 $t3, $a, $t3#lo @ K = A*B4
  340. veor $t2, $t2, $r @ N = I + J
  341. veor $t0#lo, $t0#lo, $t0#hi
  342. veor $t1#lo, $t1#lo, $t1#hi
  343. veor $t2#lo, $t2#lo, $t2#hi @ t2 = (N) (P4 + P5) << 24
  344. vand $t2#hi, $t2#hi, $k16
  345. vext.8 $t0, $t0, $t0, #15
  346. veor $t3#lo, $t3#lo, $t3#hi @ t3 = (K) (P6 + P7) << 32
  347. vmov.i64 $t3#hi, #0
  348. vext.8 $t1, $t1, $t1, #14
  349. veor $t2#lo, $t2#lo, $t2#hi
  350. vmull.p8 $r, $a, $b @ D = A*B
  351. vext.8 $t3, $t3, $t3, #12
  352. vext.8 $t2, $t2, $t2, #13
  353. veor $t0, $t0, $t1
  354. veor $t2, $t2, $t3
  355. veor $r, $r, $t0
  356. veor $r, $r, $t2
  357. ___
  358. }
  359. $code.=<<___;
  360. #if __ARM_MAX_ARCH__>=7
  361. .arch armv7-a
  362. .fpu neon
  363. .global gcm_init_neon
  364. .hidden gcm_init_neon
  365. .type gcm_init_neon,%function
  366. .align 4
  367. gcm_init_neon:
  368. vld1.64 $IN#hi,[r1]! @ load H
  369. vmov.i8 $t0,#0xe1
  370. vld1.64 $IN#lo,[r1]
  371. vshl.i64 $t0#hi,#57
  372. vshr.u64 $t0#lo,#63 @ t0=0xc2....01
  373. vdup.8 $t1,$IN#hi[7]
  374. vshr.u64 $Hlo,$IN#lo,#63
  375. vshr.s8 $t1,#7 @ broadcast carry bit
  376. vshl.i64 $IN,$IN,#1
  377. vand $t0,$t0,$t1
  378. vorr $IN#hi,$Hlo @ H<<<=1
  379. veor $IN,$IN,$t0 @ twisted H
  380. vstmia r0,{$IN}
  381. ret @ bx lr
  382. .size gcm_init_neon,.-gcm_init_neon
  383. .global gcm_gmult_neon
  384. .hidden gcm_gmult_neon
  385. .type gcm_gmult_neon,%function
  386. .align 4
  387. gcm_gmult_neon:
  388. vld1.64 $IN#hi,[$Xi]! @ load Xi
  389. vld1.64 $IN#lo,[$Xi]!
  390. vmov.i64 $k48,#0x0000ffffffffffff
  391. vldmia $Htbl,{$Hlo-$Hhi} @ load twisted H
  392. vmov.i64 $k32,#0x00000000ffffffff
  393. #ifdef __ARMEL__
  394. vrev64.8 $IN,$IN
  395. #endif
  396. vmov.i64 $k16,#0x000000000000ffff
  397. veor $Hhl,$Hlo,$Hhi @ Karatsuba pre-processing
  398. mov $len,#16
  399. b .Lgmult_neon
  400. .size gcm_gmult_neon,.-gcm_gmult_neon
  401. .global gcm_ghash_neon
  402. .hidden gcm_ghash_neon
  403. .type gcm_ghash_neon,%function
  404. .align 4
  405. gcm_ghash_neon:
  406. vld1.64 $Xl#hi,[$Xi]! @ load Xi
  407. vld1.64 $Xl#lo,[$Xi]!
  408. vmov.i64 $k48,#0x0000ffffffffffff
  409. vldmia $Htbl,{$Hlo-$Hhi} @ load twisted H
  410. vmov.i64 $k32,#0x00000000ffffffff
  411. #ifdef __ARMEL__
  412. vrev64.8 $Xl,$Xl
  413. #endif
  414. vmov.i64 $k16,#0x000000000000ffff
  415. veor $Hhl,$Hlo,$Hhi @ Karatsuba pre-processing
  416. .Loop_neon:
  417. vld1.64 $IN#hi,[$inp]! @ load inp
  418. vld1.64 $IN#lo,[$inp]!
  419. #ifdef __ARMEL__
  420. vrev64.8 $IN,$IN
  421. #endif
  422. veor $IN,$Xl @ inp^=Xi
  423. .Lgmult_neon:
  424. ___
  425. &clmul64x64 ($Xl,$Hlo,"$IN#lo"); # H.lo·Xi.lo
  426. $code.=<<___;
  427. veor $IN#lo,$IN#lo,$IN#hi @ Karatsuba pre-processing
  428. ___
  429. &clmul64x64 ($Xm,$Hhl,"$IN#lo"); # (H.lo+H.hi)·(Xi.lo+Xi.hi)
  430. &clmul64x64 ($Xh,$Hhi,"$IN#hi"); # H.hi·Xi.hi
  431. $code.=<<___;
  432. veor $Xm,$Xm,$Xl @ Karatsuba post-processing
  433. veor $Xm,$Xm,$Xh
  434. veor $Xl#hi,$Xl#hi,$Xm#lo
  435. veor $Xh#lo,$Xh#lo,$Xm#hi @ Xh|Xl - 256-bit result
  436. @ equivalent of reduction_avx from ghash-x86_64.pl
  437. vshl.i64 $t1,$Xl,#57 @ 1st phase
  438. vshl.i64 $t2,$Xl,#62
  439. veor $t2,$t2,$t1 @
  440. vshl.i64 $t1,$Xl,#63
  441. veor $t2, $t2, $t1 @
  442. veor $Xl#hi,$Xl#hi,$t2#lo @
  443. veor $Xh#lo,$Xh#lo,$t2#hi
  444. vshr.u64 $t2,$Xl,#1 @ 2nd phase
  445. veor $Xh,$Xh,$Xl
  446. veor $Xl,$Xl,$t2 @
  447. vshr.u64 $t2,$t2,#6
  448. vshr.u64 $Xl,$Xl,#1 @
  449. veor $Xl,$Xl,$Xh @
  450. veor $Xl,$Xl,$t2 @
  451. subs $len,#16
  452. bne .Loop_neon
  453. #ifdef __ARMEL__
  454. vrev64.8 $Xl,$Xl
  455. #endif
  456. sub $Xi,#16
  457. vst1.64 $Xl#hi,[$Xi]! @ write out Xi
  458. vst1.64 $Xl#lo,[$Xi]
  459. ret @ bx lr
  460. .size gcm_ghash_neon,.-gcm_ghash_neon
  461. #endif
  462. ___
  463. }
  464. $code.=<<___;
  465. .asciz "GHASH for ARMv4/NEON, CRYPTOGAMS by <appro\@openssl.org>"
  466. .align 2
  467. #endif
  468. ___
  469. foreach (split("\n",$code)) {
  470. s/\`([^\`]*)\`/eval $1/geo;
  471. s/\bq([0-9]+)#(lo|hi)/sprintf "d%d",2*$1+($2 eq "hi")/geo or
  472. s/\bret\b/bx lr/go or
  473. s/\bbx\s+lr\b/.word\t0xe12fff1e/go; # make it possible to compile with -march=armv4
  474. print $_,"\n";
  475. }
  476. close STDOUT; # enforce flush