x86_64cpuid.pl (160815) | x86_64cpuid.pl (194206) |
---|---|
1#!/usr/bin/env perl 2 3$output=shift; | 1#!/usr/bin/env perl 2 3$output=shift; |
4$win64a=1 if ($output =~ /win64a\.[s|asm]/); | 4$masm=1 if ($output =~ /\.asm/); |
5open STDOUT,">$output" || die "can't open $output: $!"; 6 | 5open STDOUT,">$output" || die "can't open $output: $!"; 6 |
7print<<___ if(defined($win64a)); | 7print<<___ if(defined($masm)); |
8_TEXT SEGMENT 9PUBLIC OPENSSL_rdtsc | 8_TEXT SEGMENT 9PUBLIC OPENSSL_rdtsc |
10ALIGN 16 11OPENSSL_rdtsc PROC 12 rdtsc 13 shl rdx,32 14 or rax,rdx 15 ret 16OPENSSL_rdtsc ENDP | |
17 18PUBLIC OPENSSL_atomic_add 19ALIGN 16 20OPENSSL_atomic_add PROC 21 mov eax,DWORD PTR[rcx] 22\$Lspin: lea r8,DWORD PTR[rdx+rax] 23lock cmpxchg DWORD PTR[rcx],r8d 24 jne \$Lspin --- 15 unchanged lines hidden (view full) --- 40 xor rdx,rdx 41 xor r8,r8 42 xor r9,r9 43 xor r10,r10 44 xor r11,r11 45 lea rax,QWORD PTR[rsp+8] 46 ret 47OPENSSL_wipe_cpu ENDP | 10 11PUBLIC OPENSSL_atomic_add 12ALIGN 16 13OPENSSL_atomic_add PROC 14 mov eax,DWORD PTR[rcx] 15\$Lspin: lea r8,DWORD PTR[rdx+rax] 16lock cmpxchg DWORD PTR[rcx],r8d 17 jne \$Lspin --- 15 unchanged lines hidden (view full) --- 33 xor rdx,rdx 34 xor r8,r8 35 xor r9,r9 36 xor r10,r10 37 xor r11,r11 38 lea rax,QWORD PTR[rsp+8] 39 ret 40OPENSSL_wipe_cpu ENDP |
48 49OPENSSL_ia32_cpuid PROC 50 mov r8,rbx 51 mov eax,1 52 cpuid 53 shl rcx,32 54 mov eax,edx 55 mov rbx,r8 56 or rax,rcx 57 ret 58OPENSSL_ia32_cpuid ENDP | |
59_TEXT ENDS 60 61CRT\$XIU SEGMENT 62EXTRN OPENSSL_cpuid_setup:PROC 63DQ OPENSSL_cpuid_setup 64CRT\$XIU ENDS | 41_TEXT ENDS 42 43CRT\$XIU SEGMENT 44EXTRN OPENSSL_cpuid_setup:PROC 45DQ OPENSSL_cpuid_setup 46CRT\$XIU ENDS |
65END | 47 |
66___ | 48___ |
67print<<___ if(!defined($win64a)); | 49print<<___ if(!defined($masm)); |
68.text | 50.text |
69.globl OPENSSL_rdtsc 70.align 16 71OPENSSL_rdtsc: 72 rdtsc 73 shlq \$32,%rdx 74 orq %rdx,%rax 75 ret 76.size OPENSSL_rdtsc,.-OPENSSL_rdtsc | |
77 78.globl OPENSSL_atomic_add 79.type OPENSSL_atomic_add,\@function 80.align 16 81OPENSSL_atomic_add: 82 movl (%rdi),%eax 83.Lspin: leaq (%rsi,%rax),%r8 84lock; cmpxchgl %r8d,(%rdi) --- 30 unchanged lines hidden (view full) --- 115 xorq %r8,%r8 116 xorq %r9,%r9 117 xorq %r10,%r10 118 xorq %r11,%r11 119 leaq 8(%rsp),%rax 120 ret 121.size OPENSSL_wipe_cpu,.-OPENSSL_wipe_cpu 122 | 51 52.globl OPENSSL_atomic_add 53.type OPENSSL_atomic_add,\@function 54.align 16 55OPENSSL_atomic_add: 56 movl (%rdi),%eax 57.Lspin: leaq (%rsi,%rax),%r8 58lock; cmpxchgl %r8d,(%rdi) --- 30 unchanged lines hidden (view full) --- 89 xorq %r8,%r8 90 xorq %r9,%r9 91 xorq %r10,%r10 92 xorq %r11,%r11 93 leaq 8(%rsp),%rax 94 ret 95.size OPENSSL_wipe_cpu,.-OPENSSL_wipe_cpu 96 |
97.section .init 98 call OPENSSL_cpuid_setup 99 100___ 101 102open STDOUT,"| $^X perlasm/x86_64-xlate.pl $output"; 103print<<___; 104.text 105 106.globl OPENSSL_rdtsc 107.type OPENSSL_rdtsc,\@abi-omnipotent 108.align 16 109OPENSSL_rdtsc: 110 rdtsc 111 shl \$32,%rdx 112 or %rdx,%rax 113 ret 114.size OPENSSL_rdtsc,.-OPENSSL_rdtsc 115 |
|
123.globl OPENSSL_ia32_cpuid | 116.globl OPENSSL_ia32_cpuid |
117.type OPENSSL_ia32_cpuid,\@abi-omnipotent |
|
124.align 16 125OPENSSL_ia32_cpuid: | 118.align 16 119OPENSSL_ia32_cpuid: |
126 movq %rbx,%r8 127 movl \$1,%eax | 120 mov %rbx,%r8 121 122 xor %eax,%eax |
128 cpuid | 123 cpuid |
129 shlq \$32,%rcx 130 movl %edx,%eax 131 movq %r8,%rbx 132 orq %rcx,%rax | 124 xor %eax,%eax 125 cmp \$0x756e6547,%ebx # "Genu" 126 setne %al 127 mov %eax,%r9d 128 cmp \$0x49656e69,%edx # "ineI" 129 setne %al 130 or %eax,%r9d 131 cmp \$0x6c65746e,%ecx # "ntel" 132 setne %al 133 or %eax,%r9d 134 135 mov \$1,%eax 136 cpuid 137 cmp \$0,%r9d 138 jne .Lnotintel 139 or \$0x00100000,%edx # use reserved 20th bit to engage RC4_CHAR 140 and \$15,%ah 141 cmp \$15,%ah # examine Family ID 142 je .Lnotintel 143 or \$0x40000000,%edx # use reserved bit to skip unrolled loop 144.Lnotintel: 145 bt \$28,%edx # test hyper-threading bit 146 jnc .Ldone 147 shr \$16,%ebx 148 cmp \$1,%bl # see if cache is shared 149 ja .Ldone 150 and \$0xefffffff,%edx # ~(1<<28) 151.Ldone: 152 shl \$32,%rcx 153 mov %edx,%eax 154 mov %r8,%rbx 155 or %rcx,%rax |
133 ret 134.size OPENSSL_ia32_cpuid,.-OPENSSL_ia32_cpuid | 156 ret 157.size OPENSSL_ia32_cpuid,.-OPENSSL_ia32_cpuid |
135 136.section .init 137 call OPENSSL_cpuid_setup | |
138___ | 158___ |
159close STDOUT; # flush |
|