Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

168 linhas
3.8 KiB

  1. #!/usr/bin/env perl
  2. $flavour = shift;
  3. $output = shift;
  4. if ($flavour =~ /\./) { $output = $flavour; undef $flavour; }
  5. $win64=0; $win64=1 if ($flavour =~ /[nm]asm|mingw64/ || $output =~ /\.asm$/);
  6. $0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
  7. ( $xlate="${dir}x86_64-xlate.pl" and -f $xlate ) or
  8. ( $xlate="${dir}perlasm/x86_64-xlate.pl" and -f $xlate) or
  9. die "can't locate x86_64-xlate.pl";
  10. open OUT,"| \"$^X\" $xlate $flavour $output";
  11. *STDOUT=*OUT;
  12. ($arg1,$arg2,$arg3,$arg4)=$win64?("%rcx","%rdx","%r8", "%r9") : # Win64 order
  13. ("%rdi","%rsi","%rdx","%rcx"); # Unix order
  14. print<<___;
  15. .text
  16. .globl OPENSSL_ia32_cpuid
  17. .type OPENSSL_ia32_cpuid,\@function,1
  18. .align 16
  19. OPENSSL_ia32_cpuid:
  20. # On Windows, $arg1 is rcx, but that will be clobbered. So make Windows
  21. # use the same register as Unix.
  22. mov $arg1,%rdi
  23. mov %rbx,%r8 # save %rbx
  24. xor %eax,%eax
  25. mov %eax,8(%rdi) # clear 3rd word
  26. cpuid
  27. mov %eax,%r11d # max value for standard query level
  28. xor %eax,%eax
  29. cmp \$0x756e6547,%ebx # "Genu"
  30. setne %al
  31. mov %eax,%r9d
  32. cmp \$0x49656e69,%edx # "ineI"
  33. setne %al
  34. or %eax,%r9d
  35. cmp \$0x6c65746e,%ecx # "ntel"
  36. setne %al
  37. or %eax,%r9d # 0 indicates Intel CPU
  38. jz .Lintel
  39. cmp \$0x68747541,%ebx # "Auth"
  40. setne %al
  41. mov %eax,%r10d
  42. cmp \$0x69746E65,%edx # "enti"
  43. setne %al
  44. or %eax,%r10d
  45. cmp \$0x444D4163,%ecx # "cAMD"
  46. setne %al
  47. or %eax,%r10d # 0 indicates AMD CPU
  48. jnz .Lintel
  49. # AMD specific
  50. # See http://developer.amd.com/wordpress/media/2012/10/254811.pdf (1)
  51. mov \$0x80000000,%eax
  52. cpuid
  53. # Returns "The largest CPUID extended function input value supported by
  54. # the processor implementation." in EAX.
  55. cmp \$0x80000001,%eax
  56. jb .Lintel
  57. mov %eax,%r10d
  58. mov \$0x80000001,%eax
  59. cpuid
  60. # Returns feature bits in ECX. See page 20 of [1].
  61. # TODO(fork): I think this should be a MOV.
  62. or %ecx,%r9d
  63. and \$0x00000801,%r9d # isolate AMD XOP bit, 1<<11
  64. cmp \$0x80000008,%r10d
  65. jb .Lintel
  66. mov \$0x80000008,%eax
  67. cpuid
  68. # Returns APIC ID and number of cores in ECX. See page 27 of [1].
  69. movzb %cl,%r10 # number of cores - 1
  70. inc %r10 # number of cores
  71. mov \$1,%eax
  72. cpuid
  73. # See page 13 of [1].
  74. bt \$28,%edx # test hyper-threading bit
  75. jnc .Lgeneric
  76. shr \$16,%ebx # number of logical processors
  77. cmp %r10b,%bl
  78. ja .Lgeneric
  79. and \$0xefffffff,%edx # Clear hyper-threading bit.
  80. jmp .Lgeneric
  81. .Lintel:
  82. cmp \$4,%r11d
  83. mov \$-1,%r10d
  84. jb .Lnocacheinfo
  85. mov \$4,%eax
  86. mov \$0,%ecx # query L1D
  87. cpuid
  88. mov %eax,%r10d
  89. shr \$14,%r10d
  90. and \$0xfff,%r10d # number of cores -1 per L1D
  91. cmp \$7,%r11d
  92. jb .Lnocacheinfo
  93. mov \$7,%eax
  94. xor %ecx,%ecx
  95. cpuid
  96. mov %ebx,8(%rdi)
  97. .Lnocacheinfo:
  98. mov \$1,%eax
  99. cpuid
  100. # Gets feature information. See table 3-21 in the Intel manual.
  101. and \$0xbfefffff,%edx # force reserved bits to 0
  102. cmp \$0,%r9d
  103. jne .Lnotintel
  104. or \$0x40000000,%edx # set reserved bit#30 on Intel CPUs
  105. and \$15,%ah
  106. cmp \$15,%ah # examine Family ID
  107. jne .Lnotintel
  108. or \$0x00100000,%edx # set reserved bit#20 to engage RC4_CHAR
  109. .Lnotintel:
  110. bt \$28,%edx # test hyper-threading bit
  111. jnc .Lgeneric
  112. and \$0xefffffff,%edx # ~(1<<28) - clear hyper-threading.
  113. cmp \$0,%r10d
  114. je .Lgeneric
  115. or \$0x10000000,%edx # 1<<28
  116. shr \$16,%ebx
  117. cmp \$1,%bl # see if cache is shared
  118. ja .Lgeneric
  119. and \$0xefffffff,%edx # ~(1<<28)
  120. .Lgeneric:
  121. and \$0x00000800,%r9d # isolate AMD XOP flag
  122. and \$0xfffff7ff,%ecx
  123. or %ecx,%r9d # merge AMD XOP flag
  124. mov %edx,%r10d # %r9d:%r10d is copy of %ecx:%edx
  125. bt \$27,%r9d # check OSXSAVE bit
  126. jnc .Lclear_avx
  127. xor %ecx,%ecx # XCR0
  128. .byte 0x0f,0x01,0xd0 # xgetbv
  129. and \$6,%eax # isolate XMM and YMM state support
  130. cmp \$6,%eax
  131. je .Ldone
  132. .Lclear_avx:
  133. mov \$0xefffe7ff,%eax # ~(1<<28|1<<12|1<<11)
  134. and %eax,%r9d # clear AVX, FMA and AMD XOP bits
  135. andl \$0xffffffdf,8(%rdi) # cleax AVX2, ~(1<<5)
  136. .Ldone:
  137. movl %r9d,4(%rdi)
  138. movl %r10d,0(%rdi)
  139. mov %r8,%rbx # restore %rbx
  140. ret
  141. .size OPENSSL_ia32_cpuid,.-OPENSSL_ia32_cpuid
  142. ___
  143. close STDOUT; # flush