ppccpuid.pl 7.0 KB

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