ppccpuid.pl 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. #! /usr/bin/env perl
  2. # Copyright 2007-2022 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. # $output is the last argument if it looks like a file (it has an extension)
  9. # $flavour is the first argument if it doesn't look like a file
  10. $output = $#ARGV >= 0 && $ARGV[$#ARGV] =~ m|\.\w+$| ? pop : undef;
  11. $flavour = $#ARGV >= 0 && $ARGV[0] !~ m|\.| ? shift : undef;
  12. $0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
  13. ( $xlate="${dir}ppc-xlate.pl" and -f $xlate ) or
  14. ( $xlate="${dir}perlasm/ppc-xlate.pl" and -f $xlate) or
  15. die "can't locate ppc-xlate.pl";
  16. open STDOUT,"| $^X $xlate $flavour \"$output\""
  17. or die "can't call $xlate: $!";
  18. if ($flavour=~/64/) {
  19. $CMPLI="cmpldi";
  20. $SHRLI="srdi";
  21. $SIGNX="extsw";
  22. } else {
  23. $CMPLI="cmplwi";
  24. $SHRLI="srwi";
  25. $SIGNX="mr";
  26. }
  27. $code=<<___;
  28. .machine "any"
  29. .text
  30. .globl .OPENSSL_fpu_probe
  31. .align 4
  32. .OPENSSL_fpu_probe:
  33. fmr f0,f0
  34. blr
  35. .long 0
  36. .byte 0,12,0x14,0,0,0,0,0
  37. .size .OPENSSL_fpu_probe,.-.OPENSSL_fpu_probe
  38. .globl .OPENSSL_ppc64_probe
  39. .align 4
  40. .OPENSSL_ppc64_probe:
  41. fcfid f1,f1
  42. extrdi r0,r0,32,0
  43. blr
  44. .long 0
  45. .byte 0,12,0x14,0,0,0,0,0
  46. .size .OPENSSL_ppc64_probe,.-.OPENSSL_ppc64_probe
  47. .globl .OPENSSL_altivec_probe
  48. .align 4
  49. .OPENSSL_altivec_probe:
  50. .long 0x10000484 # vor v0,v0,v0
  51. blr
  52. .long 0
  53. .byte 0,12,0x14,0,0,0,0,0
  54. .size .OPENSSL_altivec_probe,.-..OPENSSL_altivec_probe
  55. .globl .OPENSSL_crypto207_probe
  56. .align 4
  57. .OPENSSL_crypto207_probe:
  58. lvx_u v0,0,r1
  59. vcipher v0,v0,v0
  60. blr
  61. .long 0
  62. .byte 0,12,0x14,0,0,0,0,0
  63. .size .OPENSSL_crypto207_probe,.-.OPENSSL_crypto207_probe
  64. .globl .OPENSSL_madd300_probe
  65. .align 4
  66. .OPENSSL_madd300_probe:
  67. xor r0,r0,r0
  68. maddld r3,r0,r0,r0
  69. maddhdu r3,r0,r0,r0
  70. blr
  71. .long 0
  72. .byte 0,12,0x14,0,0,0,0,0
  73. .globl .OPENSSL_brd31_probe
  74. .align 4
  75. .OPENSSL_brd31_probe:
  76. xor r0,r0,r0
  77. brd r3,r0
  78. blr
  79. .long 0
  80. .byte 0,12,0x14,0,0,0,0,0
  81. .size .OPENSSL_brd31_probe,.-.OPENSSL_brd31_probe
  82. .globl .OPENSSL_wipe_cpu
  83. .align 4
  84. .OPENSSL_wipe_cpu:
  85. xor r0,r0,r0
  86. fmr f0,f31
  87. fmr f1,f31
  88. fmr f2,f31
  89. mr r3,r1
  90. fmr f3,f31
  91. xor r4,r4,r4
  92. fmr f4,f31
  93. xor r5,r5,r5
  94. fmr f5,f31
  95. xor r6,r6,r6
  96. fmr f6,f31
  97. xor r7,r7,r7
  98. fmr f7,f31
  99. xor r8,r8,r8
  100. fmr f8,f31
  101. xor r9,r9,r9
  102. fmr f9,f31
  103. xor r10,r10,r10
  104. fmr f10,f31
  105. xor r11,r11,r11
  106. fmr f11,f31
  107. xor r12,r12,r12
  108. fmr f12,f31
  109. fmr f13,f31
  110. blr
  111. .long 0
  112. .byte 0,12,0x14,0,0,0,0,0
  113. .size .OPENSSL_wipe_cpu,.-.OPENSSL_wipe_cpu
  114. .globl .OPENSSL_atomic_add
  115. .align 4
  116. .OPENSSL_atomic_add:
  117. Ladd: lwarx r5,0,r3
  118. add r0,r4,r5
  119. stwcx. r0,0,r3
  120. bne- Ladd
  121. $SIGNX r3,r0
  122. blr
  123. .long 0
  124. .byte 0,12,0x14,0,0,0,2,0
  125. .long 0
  126. .size .OPENSSL_atomic_add,.-.OPENSSL_atomic_add
  127. .globl .OPENSSL_rdtsc_mftb
  128. .align 4
  129. .OPENSSL_rdtsc_mftb:
  130. mftb r3
  131. blr
  132. .long 0
  133. .byte 0,12,0x14,0,0,0,0,0
  134. .size .OPENSSL_rdtsc_mftb,.-.OPENSSL_rdtsc_mftb
  135. .globl .OPENSSL_rdtsc_mfspr268
  136. .align 4
  137. .OPENSSL_rdtsc_mfspr268:
  138. mfspr r3,268
  139. blr
  140. .long 0
  141. .byte 0,12,0x14,0,0,0,0,0
  142. .size .OPENSSL_rdtsc_mfspr268,.-.OPENSSL_rdtsc_mfspr268
  143. .globl .OPENSSL_cleanse
  144. .align 4
  145. .OPENSSL_cleanse:
  146. $CMPLI r4,7
  147. li r0,0
  148. bge Lot
  149. $CMPLI r4,0
  150. beqlr-
  151. Little: mtctr r4
  152. stb r0,0(r3)
  153. addi r3,r3,1
  154. bdnz \$-8
  155. blr
  156. Lot: andi. r5,r3,3
  157. beq Laligned
  158. stb r0,0(r3)
  159. subi r4,r4,1
  160. addi r3,r3,1
  161. b Lot
  162. Laligned:
  163. $SHRLI r5,r4,2
  164. mtctr r5
  165. stw r0,0(r3)
  166. addi r3,r3,4
  167. bdnz \$-8
  168. andi. r4,r4,3
  169. bne Little
  170. blr
  171. .long 0
  172. .byte 0,12,0x14,0,0,0,2,0
  173. .long 0
  174. .size .OPENSSL_cleanse,.-.OPENSSL_cleanse
  175. globl .CRYPTO_memcmp
  176. .align 4
  177. .CRYPTO_memcmp:
  178. $CMPLI r5,0
  179. li r0,0
  180. beq Lno_data
  181. mtctr r5
  182. Loop_cmp:
  183. lbz r6,0(r3)
  184. addi r3,r3,1
  185. lbz r7,0(r4)
  186. addi r4,r4,1
  187. xor r6,r6,r7
  188. or r0,r0,r6
  189. bdnz Loop_cmp
  190. Lno_data:
  191. li r3,0
  192. sub r3,r3,r0
  193. extrwi r3,r3,1,0
  194. blr
  195. .long 0
  196. .byte 0,12,0x14,0,0,0,3,0
  197. .long 0
  198. .size .CRYPTO_memcmp,.-.CRYPTO_memcmp
  199. ___
  200. {
  201. my ($out,$cnt,$max)=("r3","r4","r5");
  202. my ($tick,$lasttick)=("r6","r7");
  203. my ($diff,$lastdiff)=("r8","r9");
  204. $code.=<<___;
  205. .globl .OPENSSL_instrument_bus_mftb
  206. .align 4
  207. .OPENSSL_instrument_bus_mftb:
  208. mtctr $cnt
  209. mftb $lasttick # collect 1st tick
  210. li $diff,0
  211. dcbf 0,$out # flush cache line
  212. lwarx $tick,0,$out # load and lock
  213. add $tick,$tick,$diff
  214. stwcx. $tick,0,$out
  215. stwx $tick,0,$out
  216. Loop: mftb $tick
  217. sub $diff,$tick,$lasttick
  218. mr $lasttick,$tick
  219. dcbf 0,$out # flush cache line
  220. lwarx $tick,0,$out # load and lock
  221. add $tick,$tick,$diff
  222. stwcx. $tick,0,$out
  223. stwx $tick,0,$out
  224. addi $out,$out,4 # ++$out
  225. bdnz Loop
  226. mr r3,$cnt
  227. blr
  228. .long 0
  229. .byte 0,12,0x14,0,0,0,2,0
  230. .long 0
  231. .size .OPENSSL_instrument_bus_mftb,.-.OPENSSL_instrument_bus_mftb
  232. .globl .OPENSSL_instrument_bus2_mftb
  233. .align 4
  234. .OPENSSL_instrument_bus2_mftb:
  235. mr r0,$cnt
  236. slwi $cnt,$cnt,2
  237. mftb $lasttick # collect 1st tick
  238. li $diff,0
  239. dcbf 0,$out # flush cache line
  240. lwarx $tick,0,$out # load and lock
  241. add $tick,$tick,$diff
  242. stwcx. $tick,0,$out
  243. stwx $tick,0,$out
  244. mftb $tick # collect 1st diff
  245. sub $diff,$tick,$lasttick
  246. mr $lasttick,$tick
  247. mr $lastdiff,$diff
  248. Loop2:
  249. dcbf 0,$out # flush cache line
  250. lwarx $tick,0,$out # load and lock
  251. add $tick,$tick,$diff
  252. stwcx. $tick,0,$out
  253. stwx $tick,0,$out
  254. addic. $max,$max,-1
  255. beq Ldone2
  256. mftb $tick
  257. sub $diff,$tick,$lasttick
  258. mr $lasttick,$tick
  259. cmplw 7,$diff,$lastdiff
  260. mr $lastdiff,$diff
  261. mfcr $tick # pull cr
  262. not $tick,$tick # flip bits
  263. rlwinm $tick,$tick,1,29,29 # isolate flipped eq bit and scale
  264. sub. $cnt,$cnt,$tick # conditional --$cnt
  265. add $out,$out,$tick # conditional ++$out
  266. bne Loop2
  267. Ldone2:
  268. srwi $cnt,$cnt,2
  269. sub r3,r0,$cnt
  270. blr
  271. .long 0
  272. .byte 0,12,0x14,0,0,0,3,0
  273. .long 0
  274. .size .OPENSSL_instrument_bus2_mftb,.-.OPENSSL_instrument_bus2_mftb
  275. .globl .OPENSSL_instrument_bus_mfspr268
  276. .align 4
  277. .OPENSSL_instrument_bus_mfspr268:
  278. mtctr $cnt
  279. mfspr $lasttick,268 # collect 1st tick
  280. li $diff,0
  281. dcbf 0,$out # flush cache line
  282. lwarx $tick,0,$out # load and lock
  283. add $tick,$tick,$diff
  284. stwcx. $tick,0,$out
  285. stwx $tick,0,$out
  286. Loop3: mfspr $tick,268
  287. sub $diff,$tick,$lasttick
  288. mr $lasttick,$tick
  289. dcbf 0,$out # flush cache line
  290. lwarx $tick,0,$out # load and lock
  291. add $tick,$tick,$diff
  292. stwcx. $tick,0,$out
  293. stwx $tick,0,$out
  294. addi $out,$out,4 # ++$out
  295. bdnz Loop3
  296. mr r3,$cnt
  297. blr
  298. .long 0
  299. .byte 0,12,0x14,0,0,0,2,0
  300. .long 0
  301. .size .OPENSSL_instrument_bus_mfspr268,.-.OPENSSL_instrument_bus_mfspr268
  302. .globl .OPENSSL_instrument_bus2_mfspr268
  303. .align 4
  304. .OPENSSL_instrument_bus2_mfspr268:
  305. mr r0,$cnt
  306. slwi $cnt,$cnt,2
  307. mfspr $lasttick,268 # collect 1st tick
  308. li $diff,0
  309. dcbf 0,$out # flush cache line
  310. lwarx $tick,0,$out # load and lock
  311. add $tick,$tick,$diff
  312. stwcx. $tick,0,$out
  313. stwx $tick,0,$out
  314. mfspr $tick,268 # collect 1st diff
  315. sub $diff,$tick,$lasttick
  316. mr $lasttick,$tick
  317. mr $lastdiff,$diff
  318. Loop4:
  319. dcbf 0,$out # flush cache line
  320. lwarx $tick,0,$out # load and lock
  321. add $tick,$tick,$diff
  322. stwcx. $tick,0,$out
  323. stwx $tick,0,$out
  324. addic. $max,$max,-1
  325. beq Ldone4
  326. mfspr $tick,268
  327. sub $diff,$tick,$lasttick
  328. mr $lasttick,$tick
  329. cmplw 7,$diff,$lastdiff
  330. mr $lastdiff,$diff
  331. mfcr $tick # pull cr
  332. not $tick,$tick # flip bits
  333. rlwinm $tick,$tick,1,29,29 # isolate flipped eq bit and scale
  334. sub. $cnt,$cnt,$tick # conditional --$cnt
  335. add $out,$out,$tick # conditional ++$out
  336. bne Loop4
  337. Ldone4:
  338. srwi $cnt,$cnt,2
  339. sub r3,r0,$cnt
  340. blr
  341. .long 0
  342. .byte 0,12,0x14,0,0,0,3,0
  343. .long 0
  344. .size .OPENSSL_instrument_bus2_mfspr268,.-.OPENSSL_instrument_bus2_mfspr268
  345. ___
  346. }
  347. $code =~ s/\`([^\`]*)\`/eval $1/gem;
  348. print $code;
  349. close STDOUT or die "error closing STDOUT: $!";