ppccpuid.pl 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. #! /usr/bin/env perl
  2. # Copyright 2007-2016 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_wipe_cpu
  74. .align 4
  75. .OPENSSL_wipe_cpu:
  76. xor r0,r0,r0
  77. fmr f0,f31
  78. fmr f1,f31
  79. fmr f2,f31
  80. mr r3,r1
  81. fmr f3,f31
  82. xor r4,r4,r4
  83. fmr f4,f31
  84. xor r5,r5,r5
  85. fmr f5,f31
  86. xor r6,r6,r6
  87. fmr f6,f31
  88. xor r7,r7,r7
  89. fmr f7,f31
  90. xor r8,r8,r8
  91. fmr f8,f31
  92. xor r9,r9,r9
  93. fmr f9,f31
  94. xor r10,r10,r10
  95. fmr f10,f31
  96. xor r11,r11,r11
  97. fmr f11,f31
  98. xor r12,r12,r12
  99. fmr f12,f31
  100. fmr f13,f31
  101. blr
  102. .long 0
  103. .byte 0,12,0x14,0,0,0,0,0
  104. .size .OPENSSL_wipe_cpu,.-.OPENSSL_wipe_cpu
  105. .globl .OPENSSL_atomic_add
  106. .align 4
  107. .OPENSSL_atomic_add:
  108. Ladd: lwarx r5,0,r3
  109. add r0,r4,r5
  110. stwcx. r0,0,r3
  111. bne- Ladd
  112. $SIGNX r3,r0
  113. blr
  114. .long 0
  115. .byte 0,12,0x14,0,0,0,2,0
  116. .long 0
  117. .size .OPENSSL_atomic_add,.-.OPENSSL_atomic_add
  118. .globl .OPENSSL_rdtsc_mftb
  119. .align 4
  120. .OPENSSL_rdtsc_mftb:
  121. mftb r3
  122. blr
  123. .long 0
  124. .byte 0,12,0x14,0,0,0,0,0
  125. .size .OPENSSL_rdtsc_mftb,.-.OPENSSL_rdtsc_mftb
  126. .globl .OPENSSL_rdtsc_mfspr268
  127. .align 4
  128. .OPENSSL_rdtsc_mfspr268:
  129. mfspr r3,268
  130. blr
  131. .long 0
  132. .byte 0,12,0x14,0,0,0,0,0
  133. .size .OPENSSL_rdtsc_mfspr268,.-.OPENSSL_rdtsc_mfspr268
  134. .globl .OPENSSL_cleanse
  135. .align 4
  136. .OPENSSL_cleanse:
  137. $CMPLI r4,7
  138. li r0,0
  139. bge Lot
  140. $CMPLI r4,0
  141. beqlr-
  142. Little: mtctr r4
  143. stb r0,0(r3)
  144. addi r3,r3,1
  145. bdnz \$-8
  146. blr
  147. Lot: andi. r5,r3,3
  148. beq Laligned
  149. stb r0,0(r3)
  150. subi r4,r4,1
  151. addi r3,r3,1
  152. b Lot
  153. Laligned:
  154. $SHRLI r5,r4,2
  155. mtctr r5
  156. stw r0,0(r3)
  157. addi r3,r3,4
  158. bdnz \$-8
  159. andi. r4,r4,3
  160. bne Little
  161. blr
  162. .long 0
  163. .byte 0,12,0x14,0,0,0,2,0
  164. .long 0
  165. .size .OPENSSL_cleanse,.-.OPENSSL_cleanse
  166. globl .CRYPTO_memcmp
  167. .align 4
  168. .CRYPTO_memcmp:
  169. $CMPLI r5,0
  170. li r0,0
  171. beq Lno_data
  172. mtctr r5
  173. Loop_cmp:
  174. lbz r6,0(r3)
  175. addi r3,r3,1
  176. lbz r7,0(r4)
  177. addi r4,r4,1
  178. xor r6,r6,r7
  179. or r0,r0,r6
  180. bdnz Loop_cmp
  181. Lno_data:
  182. li r3,0
  183. sub r3,r3,r0
  184. extrwi r3,r3,1,0
  185. blr
  186. .long 0
  187. .byte 0,12,0x14,0,0,0,3,0
  188. .long 0
  189. .size .CRYPTO_memcmp,.-.CRYPTO_memcmp
  190. ___
  191. {
  192. my ($out,$cnt,$max)=("r3","r4","r5");
  193. my ($tick,$lasttick)=("r6","r7");
  194. my ($diff,$lastdiff)=("r8","r9");
  195. $code.=<<___;
  196. .globl .OPENSSL_instrument_bus_mftb
  197. .align 4
  198. .OPENSSL_instrument_bus_mftb:
  199. mtctr $cnt
  200. mftb $lasttick # collect 1st tick
  201. li $diff,0
  202. dcbf 0,$out # flush cache line
  203. lwarx $tick,0,$out # load and lock
  204. add $tick,$tick,$diff
  205. stwcx. $tick,0,$out
  206. stwx $tick,0,$out
  207. Loop: mftb $tick
  208. sub $diff,$tick,$lasttick
  209. mr $lasttick,$tick
  210. dcbf 0,$out # flush cache line
  211. lwarx $tick,0,$out # load and lock
  212. add $tick,$tick,$diff
  213. stwcx. $tick,0,$out
  214. stwx $tick,0,$out
  215. addi $out,$out,4 # ++$out
  216. bdnz Loop
  217. mr r3,$cnt
  218. blr
  219. .long 0
  220. .byte 0,12,0x14,0,0,0,2,0
  221. .long 0
  222. .size .OPENSSL_instrument_bus_mftb,.-.OPENSSL_instrument_bus_mftb
  223. .globl .OPENSSL_instrument_bus2_mftb
  224. .align 4
  225. .OPENSSL_instrument_bus2_mftb:
  226. mr r0,$cnt
  227. slwi $cnt,$cnt,2
  228. mftb $lasttick # collect 1st tick
  229. li $diff,0
  230. dcbf 0,$out # flush cache line
  231. lwarx $tick,0,$out # load and lock
  232. add $tick,$tick,$diff
  233. stwcx. $tick,0,$out
  234. stwx $tick,0,$out
  235. mftb $tick # collect 1st diff
  236. sub $diff,$tick,$lasttick
  237. mr $lasttick,$tick
  238. mr $lastdiff,$diff
  239. Loop2:
  240. dcbf 0,$out # flush cache line
  241. lwarx $tick,0,$out # load and lock
  242. add $tick,$tick,$diff
  243. stwcx. $tick,0,$out
  244. stwx $tick,0,$out
  245. addic. $max,$max,-1
  246. beq Ldone2
  247. mftb $tick
  248. sub $diff,$tick,$lasttick
  249. mr $lasttick,$tick
  250. cmplw 7,$diff,$lastdiff
  251. mr $lastdiff,$diff
  252. mfcr $tick # pull cr
  253. not $tick,$tick # flip bits
  254. rlwinm $tick,$tick,1,29,29 # isolate flipped eq bit and scale
  255. sub. $cnt,$cnt,$tick # conditional --$cnt
  256. add $out,$out,$tick # conditional ++$out
  257. bne Loop2
  258. Ldone2:
  259. srwi $cnt,$cnt,2
  260. sub r3,r0,$cnt
  261. blr
  262. .long 0
  263. .byte 0,12,0x14,0,0,0,3,0
  264. .long 0
  265. .size .OPENSSL_instrument_bus2_mftb,.-.OPENSSL_instrument_bus2_mftb
  266. .globl .OPENSSL_instrument_bus_mfspr268
  267. .align 4
  268. .OPENSSL_instrument_bus_mfspr268:
  269. mtctr $cnt
  270. mfspr $lasttick,268 # collect 1st tick
  271. li $diff,0
  272. dcbf 0,$out # flush cache line
  273. lwarx $tick,0,$out # load and lock
  274. add $tick,$tick,$diff
  275. stwcx. $tick,0,$out
  276. stwx $tick,0,$out
  277. Loop3: mfspr $tick,268
  278. sub $diff,$tick,$lasttick
  279. mr $lasttick,$tick
  280. dcbf 0,$out # flush cache line
  281. lwarx $tick,0,$out # load and lock
  282. add $tick,$tick,$diff
  283. stwcx. $tick,0,$out
  284. stwx $tick,0,$out
  285. addi $out,$out,4 # ++$out
  286. bdnz Loop3
  287. mr r3,$cnt
  288. blr
  289. .long 0
  290. .byte 0,12,0x14,0,0,0,2,0
  291. .long 0
  292. .size .OPENSSL_instrument_bus_mfspr268,.-.OPENSSL_instrument_bus_mfspr268
  293. .globl .OPENSSL_instrument_bus2_mfspr268
  294. .align 4
  295. .OPENSSL_instrument_bus2_mfspr268:
  296. mr r0,$cnt
  297. slwi $cnt,$cnt,2
  298. mfspr $lasttick,268 # collect 1st tick
  299. li $diff,0
  300. dcbf 0,$out # flush cache line
  301. lwarx $tick,0,$out # load and lock
  302. add $tick,$tick,$diff
  303. stwcx. $tick,0,$out
  304. stwx $tick,0,$out
  305. mfspr $tick,268 # collect 1st diff
  306. sub $diff,$tick,$lasttick
  307. mr $lasttick,$tick
  308. mr $lastdiff,$diff
  309. Loop4:
  310. dcbf 0,$out # flush cache line
  311. lwarx $tick,0,$out # load and lock
  312. add $tick,$tick,$diff
  313. stwcx. $tick,0,$out
  314. stwx $tick,0,$out
  315. addic. $max,$max,-1
  316. beq Ldone4
  317. mfspr $tick,268
  318. sub $diff,$tick,$lasttick
  319. mr $lasttick,$tick
  320. cmplw 7,$diff,$lastdiff
  321. mr $lastdiff,$diff
  322. mfcr $tick # pull cr
  323. not $tick,$tick # flip bits
  324. rlwinm $tick,$tick,1,29,29 # isolate flipped eq bit and scale
  325. sub. $cnt,$cnt,$tick # conditional --$cnt
  326. add $out,$out,$tick # conditional ++$out
  327. bne Loop4
  328. Ldone4:
  329. srwi $cnt,$cnt,2
  330. sub r3,r0,$cnt
  331. blr
  332. .long 0
  333. .byte 0,12,0x14,0,0,0,3,0
  334. .long 0
  335. .size .OPENSSL_instrument_bus2_mfspr268,.-.OPENSSL_instrument_bus2_mfspr268
  336. ___
  337. }
  338. $code =~ s/\`([^\`]*)\`/eval $1/gem;
  339. print $code;
  340. close STDOUT;