ppccpuid.pl 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. #!/usr/bin/env perl
  2. $flavour = shift;
  3. $0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
  4. ( $xlate="${dir}ppc-xlate.pl" and -f $xlate ) or
  5. ( $xlate="${dir}perlasm/ppc-xlate.pl" and -f $xlate) or
  6. die "can't locate ppc-xlate.pl";
  7. open STDOUT,"| $^X $xlate $flavour ".shift || die "can't call $xlate: $!";
  8. if ($flavour=~/64/) {
  9. $CMPLI="cmpldi";
  10. $SHRLI="srdi";
  11. $SIGNX="extsw";
  12. } else {
  13. $CMPLI="cmplwi";
  14. $SHRLI="srwi";
  15. $SIGNX="mr";
  16. }
  17. $code=<<___;
  18. .machine "any"
  19. .text
  20. .globl .OPENSSL_fpu_probe
  21. .align 4
  22. .OPENSSL_fpu_probe:
  23. fmr f0,f0
  24. blr
  25. .long 0
  26. .byte 0,12,0x14,0,0,0,0,0
  27. .size .OPENSSL_fpu_probe,.-.OPENSSL_fpu_probe
  28. .globl .OPENSSL_ppc64_probe
  29. .align 4
  30. .OPENSSL_ppc64_probe:
  31. fcfid f1,f1
  32. extrdi r0,r0,32,0
  33. blr
  34. .long 0
  35. .byte 0,12,0x14,0,0,0,0,0
  36. .size .OPENSSL_ppc64_probe,.-.OPENSSL_ppc64_probe
  37. .globl .OPENSSL_altivec_probe
  38. .align 4
  39. .OPENSSL_altivec_probe:
  40. .long 0x10000484 # vor v0,v0,v0
  41. blr
  42. .long 0
  43. .byte 0,12,0x14,0,0,0,0,0
  44. .size .OPENSSL_altivec_probe,.-..OPENSSL_altivec_probe
  45. .globl .OPENSSL_crypto207_probe
  46. .align 4
  47. .OPENSSL_crypto207_probe:
  48. lvx_u v0,0,r1
  49. vcipher v0,v0,v0
  50. blr
  51. .long 0
  52. .byte 0,12,0x14,0,0,0,0,0
  53. .size .OPENSSL_crypto207_probe,.-.OPENSSL_crypto207_probe
  54. .globl .OPENSSL_wipe_cpu
  55. .align 4
  56. .OPENSSL_wipe_cpu:
  57. xor r0,r0,r0
  58. fmr f0,f31
  59. fmr f1,f31
  60. fmr f2,f31
  61. mr r3,r1
  62. fmr f3,f31
  63. xor r4,r4,r4
  64. fmr f4,f31
  65. xor r5,r5,r5
  66. fmr f5,f31
  67. xor r6,r6,r6
  68. fmr f6,f31
  69. xor r7,r7,r7
  70. fmr f7,f31
  71. xor r8,r8,r8
  72. fmr f8,f31
  73. xor r9,r9,r9
  74. fmr f9,f31
  75. xor r10,r10,r10
  76. fmr f10,f31
  77. xor r11,r11,r11
  78. fmr f11,f31
  79. xor r12,r12,r12
  80. fmr f12,f31
  81. fmr f13,f31
  82. blr
  83. .long 0
  84. .byte 0,12,0x14,0,0,0,0,0
  85. .size .OPENSSL_wipe_cpu,.-.OPENSSL_wipe_cpu
  86. .globl .OPENSSL_atomic_add
  87. .align 4
  88. .OPENSSL_atomic_add:
  89. Ladd: lwarx r5,0,r3
  90. add r0,r4,r5
  91. stwcx. r0,0,r3
  92. bne- Ladd
  93. $SIGNX r3,r0
  94. blr
  95. .long 0
  96. .byte 0,12,0x14,0,0,0,2,0
  97. .long 0
  98. .size .OPENSSL_atomic_add,.-.OPENSSL_atomic_add
  99. .globl .OPENSSL_rdtsc
  100. .align 4
  101. .OPENSSL_rdtsc:
  102. ___
  103. $code.=<<___ if ($flavour =~ /64/);
  104. mftb r3
  105. ___
  106. $code.=<<___ if ($flavour !~ /64/);
  107. Loop_rdtsc:
  108. mftbu r5
  109. mftb r3
  110. mftbu r4
  111. cmplw r4,r5
  112. bne Loop_rdtsc
  113. ___
  114. $code.=<<___;
  115. blr
  116. .long 0
  117. .byte 0,12,0x14,0,0,0,0,0
  118. .size .OPENSSL_rdtsc,.-.OPENSSL_rdtsc
  119. .globl .OPENSSL_cleanse
  120. .align 4
  121. .OPENSSL_cleanse:
  122. $CMPLI r4,7
  123. li r0,0
  124. bge Lot
  125. $CMPLI r4,0
  126. beqlr-
  127. Little: mtctr r4
  128. stb r0,0(r3)
  129. addi r3,r3,1
  130. bdnz \$-8
  131. blr
  132. Lot: andi. r5,r3,3
  133. beq Laligned
  134. stb r0,0(r3)
  135. subi r4,r4,1
  136. addi r3,r3,1
  137. b Lot
  138. Laligned:
  139. $SHRLI r5,r4,2
  140. mtctr r5
  141. stw r0,0(r3)
  142. addi r3,r3,4
  143. bdnz \$-8
  144. andi. r4,r4,3
  145. bne Little
  146. blr
  147. .long 0
  148. .byte 0,12,0x14,0,0,0,2,0
  149. .long 0
  150. .size .OPENSSL_cleanse,.-.OPENSSL_cleanse
  151. ___
  152. {
  153. my ($out,$cnt,$max)=("r3","r4","r5");
  154. my ($tick,$lasttick)=("r6","r7");
  155. my ($diff,$lastdiff)=("r8","r9");
  156. $code.=<<___;
  157. .globl .OPENSSL_instrument_bus
  158. .align 4
  159. .OPENSSL_instrument_bus:
  160. mtctr $cnt
  161. mftb $lasttick # collect 1st tick
  162. li $diff,0
  163. dcbf 0,$out # flush cache line
  164. lwarx $tick,0,$out # load and lock
  165. add $tick,$tick,$diff
  166. stwcx. $tick,0,$out
  167. stwx $tick,0,$out
  168. Loop: mftb $tick
  169. sub $diff,$tick,$lasttick
  170. mr $lasttick,$tick
  171. dcbf 0,$out # flush cache line
  172. lwarx $tick,0,$out # load and lock
  173. add $tick,$tick,$diff
  174. stwcx. $tick,0,$out
  175. stwx $tick,0,$out
  176. addi $out,$out,4 # ++$out
  177. bdnz Loop
  178. mr r3,$cnt
  179. blr
  180. .long 0
  181. .byte 0,12,0x14,0,0,0,2,0
  182. .long 0
  183. .size .OPENSSL_instrument_bus,.-.OPENSSL_instrument_bus
  184. .globl .OPENSSL_instrument_bus2
  185. .align 4
  186. .OPENSSL_instrument_bus2:
  187. mr r0,$cnt
  188. slwi $cnt,$cnt,2
  189. mftb $lasttick # collect 1st tick
  190. li $diff,0
  191. dcbf 0,$out # flush cache line
  192. lwarx $tick,0,$out # load and lock
  193. add $tick,$tick,$diff
  194. stwcx. $tick,0,$out
  195. stwx $tick,0,$out
  196. mftb $tick # collect 1st diff
  197. sub $diff,$tick,$lasttick
  198. mr $lasttick,$tick
  199. mr $lastdiff,$diff
  200. Loop2:
  201. dcbf 0,$out # flush cache line
  202. lwarx $tick,0,$out # load and lock
  203. add $tick,$tick,$diff
  204. stwcx. $tick,0,$out
  205. stwx $tick,0,$out
  206. addic. $max,$max,-1
  207. beq Ldone2
  208. mftb $tick
  209. sub $diff,$tick,$lasttick
  210. mr $lasttick,$tick
  211. cmplw 7,$diff,$lastdiff
  212. mr $lastdiff,$diff
  213. mfcr $tick # pull cr
  214. not $tick,$tick # flip bits
  215. rlwinm $tick,$tick,1,29,29 # isolate flipped eq bit and scale
  216. sub. $cnt,$cnt,$tick # conditional --$cnt
  217. add $out,$out,$tick # conditional ++$out
  218. bne Loop2
  219. Ldone2:
  220. srwi $cnt,$cnt,2
  221. sub r3,r0,$cnt
  222. blr
  223. .long 0
  224. .byte 0,12,0x14,0,0,0,3,0
  225. .long 0
  226. .size .OPENSSL_instrument_bus2,.-.OPENSSL_instrument_bus2
  227. ___
  228. }
  229. $code =~ s/\`([^\`]*)\`/eval $1/gem;
  230. print $code;
  231. close STDOUT;