summaryrefslogtreecommitdiffstats
path: root/crypto/x86_64cpuid.pl
diff options
context:
space:
mode:
authorAndy Polyakov <appro@openssl.org>2008-11-12 08:15:52 +0000
committerAndy Polyakov <appro@openssl.org>2008-11-12 08:15:52 +0000
commitaa8f38e49b2430a1939d7e9a8d2ecaa77edbb1a9 (patch)
tree46a196ea0c26f62de5890e05f25888ae3b54dede /crypto/x86_64cpuid.pl
parent852537726574b0b568a3bd8d12e5c797c5e56c63 (diff)
x86_64 assembler pack to comply with updated styling x86_64-xlate.pl rules.
Diffstat (limited to 'crypto/x86_64cpuid.pl')
-rw-r--r--crypto/x86_64cpuid.pl193
1 files changed, 88 insertions, 105 deletions
diff --git a/crypto/x86_64cpuid.pl b/crypto/x86_64cpuid.pl
index e19ecdbbfc..c54b9e3681 100644
--- a/crypto/x86_64cpuid.pl
+++ b/crypto/x86_64cpuid.pl
@@ -1,110 +1,37 @@
#!/usr/bin/env perl
-$output=shift;
-$masm=1 if ($output =~ /\.asm/);
-open STDOUT,">$output" || die "can't open $output: $!";
+$flavour = shift;
+$output = shift;
+if ($flavour =~ /\./) { $output = $flavour; undef $flavour; }
-print<<___ if(defined($masm));
-_TEXT SEGMENT
-PUBLIC OPENSSL_rdtsc
+$win64=0; $win64=1 if ($flavour =~ /[nm]asm|mingw64/ || $output =~ /\.asm$/);
-PUBLIC OPENSSL_atomic_add
-ALIGN 16
-OPENSSL_atomic_add PROC
- mov eax,DWORD PTR[rcx]
-\$Lspin: lea r8,DWORD PTR[rdx+rax]
-lock cmpxchg DWORD PTR[rcx],r8d
- jne \$Lspin
- mov eax,r8d
- cdqe
- ret
-OPENSSL_atomic_add ENDP
-
-PUBLIC OPENSSL_wipe_cpu
-ALIGN 16
-OPENSSL_wipe_cpu PROC
- pxor xmm0,xmm0
- pxor xmm1,xmm1
- pxor xmm2,xmm2
- pxor xmm3,xmm3
- pxor xmm4,xmm4
- pxor xmm5,xmm5
- xor rcx,rcx
- xor rdx,rdx
- xor r8,r8
- xor r9,r9
- xor r10,r10
- xor r11,r11
- lea rax,QWORD PTR[rsp+8]
- ret
-OPENSSL_wipe_cpu ENDP
-_TEXT ENDS
+$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
+open STDOUT,"| $^X ${dir}perlasm/x86_64-xlate.pl $flavour $output";
-CRT\$XIU SEGMENT
-EXTRN OPENSSL_cpuid_setup:PROC
-DQ OPENSSL_cpuid_setup
-CRT\$XIU ENDS
+if ($win64) { $arg1="%rcx"; $arg2="%rdx"; }
+else { $arg1="%rdi"; $arg2="%rsi"; }
+print<<___;
+.extern OPENSSL_cpuid_setup
+.section .init
+ call OPENSSL_cpuid_setup
-___
-print<<___ if(!defined($masm));
.text
.globl OPENSSL_atomic_add
-.type OPENSSL_atomic_add,\@function
+.type OPENSSL_atomic_add,\@abi-omnipotent
.align 16
OPENSSL_atomic_add:
- movl (%rdi),%eax
-.Lspin: leaq (%rsi,%rax),%r8
-lock; cmpxchgl %r8d,(%rdi)
+ movl ($arg1),%eax
+.Lspin: leaq ($arg2,%rax),%r8
+ .byte 0xf0 # lock
+ cmpxchgl %r8d,($arg1)
jne .Lspin
movl %r8d,%eax
- .byte 0x48,0x98
+ .byte 0x48,0x98 # cltq/cdqe
ret
.size OPENSSL_atomic_add,.-OPENSSL_atomic_add
-.globl OPENSSL_wipe_cpu
-.type OPENSSL_wipe_cpu,\@function
-.align 16
-OPENSSL_wipe_cpu:
- pxor %xmm0,%xmm0
- pxor %xmm1,%xmm1
- pxor %xmm2,%xmm2
- pxor %xmm3,%xmm3
- pxor %xmm4,%xmm4
- pxor %xmm5,%xmm5
- pxor %xmm6,%xmm6
- pxor %xmm7,%xmm7
- pxor %xmm8,%xmm8
- pxor %xmm9,%xmm9
- pxor %xmm10,%xmm10
- pxor %xmm11,%xmm11
- pxor %xmm12,%xmm12
- pxor %xmm13,%xmm13
- pxor %xmm14,%xmm14
- pxor %xmm15,%xmm15
- xorq %rcx,%rcx
- xorq %rdx,%rdx
- xorq %rsi,%rsi
- xorq %rdi,%rdi
- xorq %r8,%r8
- xorq %r9,%r9
- xorq %r10,%r10
- xorq %r11,%r11
- leaq 8(%rsp),%rax
- ret
-.size OPENSSL_wipe_cpu,.-OPENSSL_wipe_cpu
-
-.section .init
- call OPENSSL_cpuid_setup
-
-___
-
-$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
-open STDOUT,"| $^X ${dir}perlasm/x86_64-xlate.pl $output";
-
-print<<___;
-.text
-
.globl OPENSSL_rdtsc
.type OPENSSL_rdtsc,\@abi-omnipotent
.align 16
@@ -159,35 +86,91 @@ OPENSSL_ia32_cpuid:
.size OPENSSL_ia32_cpuid,.-OPENSSL_ia32_cpuid
.globl OPENSSL_cleanse
-.type OPENSSL_cleanse,\@function,2
+.type OPENSSL_cleanse,\@abi-omnipotent
.align 16
OPENSSL_cleanse:
xor %rax,%rax
- cmp \$15,%rsi
+ cmp \$15,$arg2
jae .Lot
.Little:
- mov %al,(%rdi)
- sub \$1,%rsi
- lea 1(%rdi),%rdi
+ mov %al,($arg1)
+ sub \$1,$arg2
+ lea 1($arg1),$arg1
jnz .Little
ret
.align 16
.Lot:
- test \$7,%rdi
+ test \$7,$arg1
jz .Laligned
- mov %al,(%rdi)
- lea -1(%rsi),%rsi
- lea 1(%rdi),%rdi
+ mov %al,($arg1)
+ lea -1($arg2),$arg2
+ lea 1($arg1),$arg1
jmp .Lot
.Laligned:
- mov %rax,(%rdi)
- lea -8(%rsi),%rsi
- test \$-8,%rsi
- lea 8(%rdi),%rdi
+ mov %rax,($arg1)
+ lea -8($arg2),$arg2
+ test \$-8,$arg2
+ lea 8($arg1),$arg1
jnz .Laligned
- cmp \$0,%rsi
+ cmp \$0,$arg2
jne .Little
ret
.size OPENSSL_cleanse,.-OPENSSL_cleanse
___
+
+print<<___ if (!$win64);
+.globl OPENSSL_wipe_cpu
+.type OPENSSL_wipe_cpu,\@abi-omnipotent
+.align 16
+OPENSSL_wipe_cpu:
+ pxor %xmm0,%xmm0
+ pxor %xmm1,%xmm1
+ pxor %xmm2,%xmm2
+ pxor %xmm3,%xmm3
+ pxor %xmm4,%xmm4
+ pxor %xmm5,%xmm5
+ pxor %xmm6,%xmm6
+ pxor %xmm7,%xmm7
+ pxor %xmm8,%xmm8
+ pxor %xmm9,%xmm9
+ pxor %xmm10,%xmm10
+ pxor %xmm11,%xmm11
+ pxor %xmm12,%xmm12
+ pxor %xmm13,%xmm13
+ pxor %xmm14,%xmm14
+ pxor %xmm15,%xmm15
+ xorq %rcx,%rcx
+ xorq %rdx,%rdx
+ xorq %rsi,%rsi
+ xorq %rdi,%rdi
+ xorq %r8,%r8
+ xorq %r9,%r9
+ xorq %r10,%r10
+ xorq %r11,%r11
+ leaq 8(%rsp),%rax
+ ret
+.size OPENSSL_wipe_cpu,.-OPENSSL_wipe_cpu
+___
+print<<___ if ($win64);
+.globl OPENSSL_wipe_cpu
+.type OPENSSL_wipe_cpu,\@abi-omnipotent
+.align 16
+OPENSSL_wipe_cpu:
+ pxor %xmm0,%xmm0
+ pxor %xmm1,%xmm1
+ pxor %xmm2,%xmm2
+ pxor %xmm3,%xmm3
+ pxor %xmm4,%xmm4
+ pxor %xmm5,%xmm5
+ xorq %rcx,%rcx
+ xorq %rdx,%rdx
+ xorq %r8,%r8
+ xorq %r9,%r9
+ xorq %r10,%r10
+ xorq %r11,%r11
+ leaq 8(%rsp),%rax
+ ret
+.size OPENSSL_wipe_cpu,.-OPENSSL_wipe_cpu
+___
+
close STDOUT; # flush
="o">->tm_yday))) { /* This code is optimized to negative timezones (West of Greenwich) */ if (yday == -1 || /* UTC passed midnight before localtime */ yday > 1) /* UTC passed new year before localtime */ t -= 24 * 60 * 60; else t += 24 * 60 * 60; } return t; } /* Returns the local timezone in seconds east of UTC for the time t, * or for the current time if t is zero. */ time_t mutt_local_tz (time_t t) { struct tm *ptm; struct tm utc; if (!t) t = time (NULL); ptm = gmtime (&t); /* need to make a copy because gmtime/localtime return a pointer to static memory (grr!) */ memcpy (&utc, ptm, sizeof (utc)); return (compute_tz (t, &utc)); } /* converts struct tm to time_t, but does not take the local timezone into account unless ``local'' is nonzero */ time_t mutt_mktime (struct tm *t, int local) { time_t g; static int AccumDaysPerMonth[12] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 }; /* Compute the number of days since January 1 in the same year */ g = AccumDaysPerMonth [t->tm_mon % 12]; /* The leap years are 1972 and every 4. year until 2096, * but this algoritm will fail after year 2099 */ g += t->tm_mday; if ((t->tm_year % 4) || t->tm_mon < 2) g--; t->tm_yday = g; /* Compute the number of days since January 1, 1970 */ g += (t->tm_year - 70) * 365; g += (t->tm_year - 69) / 4; /* Compute the number of hours */ g *= 24; g += t->tm_hour; /* Compute the number of minutes */ g *= 60; g += t->tm_min; /* Compute the number of seconds */ g *= 60; g += t->tm_sec; if (local) g -= compute_tz (g, t); return (g); } /* Return 1 if month is February of leap year, else 0 */ static int isLeapYearFeb (struct tm *tm) { if (tm->tm_mon == 1) { int y = tm->tm_year + 1900; return (((y & 3) == 0) && (((y % 100) != 0) || ((y % 400) == 0))); } return (0); } void mutt_normalize_time (struct tm *tm) { static char DaysPerMonth[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; int nLeap; while (tm->tm_sec < 0) { tm->tm_sec += 60; tm->tm_min--; } while (tm->tm_sec >= 60) { tm->tm_sec -= 60; tm->tm_min++; } while (tm->tm_min < 0) { tm->tm_min += 60; tm->tm_hour--; } while (tm->tm_min >= 60) { tm->tm_min -= 60; tm->tm_hour++; } while (tm->tm_hour < 0) { tm->tm_hour += 24; tm->tm_mday--; } while (tm->tm_hour >= 24) { tm->tm_hour -= 24; tm->tm_mday++; } /* use loops on NNNdwmy user input values? */ while (tm->tm_mon < 0) { tm->tm_mon += 12; tm->tm_year--; } while (tm->tm_mon >= 12) { tm->tm_mon -= 12; tm->tm_year++; } while (tm->tm_mday <= 0) { if (tm->tm_mon) tm->tm_mon--; else { tm->tm_mon = 11; tm->tm_year--; } tm->tm_mday += DaysPerMonth[tm->tm_mon] + isLeapYearFeb (tm); } while (tm->tm_mday > (DaysPerMonth[tm->tm_mon] + (nLeap = isLeapYearFeb (tm)))) { tm->tm_mday -= DaysPerMonth[tm->tm_mon] + nLeap; if (tm->tm_mon < 11) tm->tm_mon++; else { tm->tm_mon = 0; tm->tm_year++; } } }