]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
eliminated inline assembly.
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Sat, 17 Sep 2011 09:44:08 +0000 (11:44 +0200)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Sat, 17 Sep 2011 09:44:58 +0000 (11:44 +0200)
lib/accelerated/accelerated.c
lib/accelerated/intel/Makefile.am
lib/accelerated/intel/aes-padlock.c
lib/accelerated/intel/aes-x86.c
lib/accelerated/intel/asm/cpuid-x86-64.s [new file with mode: 0644]
lib/accelerated/intel/asm/cpuid-x86.s [new file with mode: 0644]
lib/accelerated/x86.h

index e2da12f6c3abb471ef9ffea412761c39bad9fffe..8a89e3dc96b721df2740f80ac75c5c73348daafd 100644 (file)
@@ -30,7 +30,7 @@ void _gnutls_register_accel_crypto(void)
 {
 
 #if defined(ASM_X86_32) || defined(ASM_X86_64)
-  if (have_cpuid() != 0)
+  if (_gnutls_have_cpuid() != 0)
     {
       register_x86_crypto ();
       register_padlock_crypto ();
index a0ea3338d35a2fc922eacdba378d852e95e3812a..996c0d586229e91d663c2193c33bb9cf90cbd58a 100644 (file)
@@ -38,8 +38,8 @@ libintel_la_SOURCES = aes-x86.c aes-padlock.c aes-gcm-padlock.c
 
 if ASM_X86_64
 AM_CPPFLAGS += -DASM_X86_64
-libintel_la_SOURCES += asm/appro-aes-x86-64.s asm/appro-aes-gcm-x86-64.s aes-gcm-x86.c asm/padlock-x86-64.s
+libintel_la_SOURCES += asm/appro-aes-x86-64.s asm/appro-aes-gcm-x86-64.s aes-gcm-x86.c asm/padlock-x86-64.s asm/cpuid-x86-64.s
 else
-libintel_la_SOURCES += asm/appro-aes-x86.s asm/padlock-x86.s
+libintel_la_SOURCES += asm/appro-aes-x86.s asm/padlock-x86.s asm/cpuid-x86.s
 endif
 
index e0e79c1656608bd55917ee1b3edffd932b0e5ce4..59f33bc55eeb6bfa53289d3d485338133ccb40e9 100644 (file)
@@ -170,7 +170,7 @@ static int check_padlock(void)
 static unsigned check_via(void)
 {
     unsigned int a, b, c, d;
-    cpuid(0, a, b, c, d);
+    _gnutls_cpuid(0, &a, &b, &c, &d);
 
     if ((memcmp(&b, "VIA ", 4) == 0 &&
          memcmp(&d, "VIA ", 4) == 0 && memcmp(&c, "VIA ", 4) == 0)) {
index 9f4c4cbed725dd6c99079472a7e1053f5eddf901..5f465a529018ffd1a1a37cf7b6f8f54a9bf4e0f4 100644 (file)
@@ -126,7 +126,7 @@ static unsigned
 check_optimized_aes (void)
 {
   unsigned int a, b, c, d;
-  cpuid (1, a, b, c, d);
+  _gnutls_cpuid (1, &a, &b, &c, &d);
 
   return (c & 0x2000000);
 }
@@ -136,7 +136,7 @@ static unsigned
 check_pclmul (void)
 {
   unsigned int a, b, c, d;
-  cpuid (1, a, b, c, d);
+  _gnutls_cpuid (1, &a, &b, &c, &d);
 
   return (c & 0x2);
 }
@@ -146,7 +146,7 @@ static unsigned
 check_intel_or_amd (void)
 {
   unsigned int a, b, c, d;
-  cpuid (0, a, b, c, d);
+  _gnutls_cpuid (0, &a, &b, &c, &d);
 
   if ((memcmp (&b, "Genu", 4) == 0 &&
        memcmp (&d, "ineI", 4) == 0 &&
diff --git a/lib/accelerated/intel/asm/cpuid-x86-64.s b/lib/accelerated/intel/asm/cpuid-x86-64.s
new file mode 100644 (file)
index 0000000..48b2cc4
--- /dev/null
@@ -0,0 +1,39 @@
+       .file "cpuid.asm"
+        
+       .text
+       .align 16
+.globl _gnutls_cpuid
+.type _gnutls_cpuid,%function
+_gnutls_cpuid:
+       pushq   %rbp
+       movq    %rsp, %rbp
+       pushq   %rbx
+       movl    %edi, -12(%rbp)
+       movq    %rsi, -24(%rbp)
+       movq    %rdx, -32(%rbp)
+       movq    %rcx, -40(%rbp)
+       movq    %r8, -48(%rbp)
+       movl    -12(%rbp), %eax
+       movl    %eax, -60(%rbp)
+       movl    -60(%rbp), %eax
+       cpuid
+       movl    %edx, -56(%rbp)
+       movl    %ecx, %esi
+       movl    %eax, -52(%rbp)
+       movq    -24(%rbp), %rax
+       movl    -52(%rbp), %edx
+       movl    %edx, (%rax)
+       movq    -32(%rbp), %rax
+       movl    %ebx, (%rax)
+       movq    -40(%rbp), %rax
+       movl    %esi, (%rax)
+       movq    -48(%rbp), %rax
+       movl    -56(%rbp), %ecx
+       movl    %ecx, (%rax)
+       popq    %rbx
+       leave
+       ret
+.size _gnutls_cpuid, . - _gnutls_cpuid
+
+
+.section .note.GNU-stack,"",@progbits
diff --git a/lib/accelerated/intel/asm/cpuid-x86.s b/lib/accelerated/intel/asm/cpuid-x86.s
new file mode 100644 (file)
index 0000000..b286225
--- /dev/null
@@ -0,0 +1,54 @@
+       .file "cpuid.asm"
+        
+       .text
+       .align 16
+.globl _gnutls_cpuid
+.type _gnutls_cpuid,%function
+_gnutls_cpuid:
+       pushl   %ebp
+       movl    %esp, %ebp
+       subl    $12, %esp
+       movl    %ebx, (%esp)
+       movl    8(%ebp), %eax
+       movl    %esi, 4(%esp)
+       movl    %edi, 8(%esp)
+       pushl %ebx
+       cpuid
+       movl %ebx, %edi
+       popl %ebx
+       movl    %edx, %esi
+       movl    12(%ebp), %edx
+       movl    %eax, (%edx)
+       movl    16(%ebp), %eax
+       movl    %edi, (%eax)
+       movl    20(%ebp), %eax
+       movl    %ecx, (%eax)
+       movl    24(%ebp), %eax
+       movl    %esi, (%eax)
+       movl    (%esp), %ebx
+       movl    4(%esp), %esi
+       movl    8(%esp), %edi
+       movl    %ebp, %esp
+       popl    %ebp
+       ret
+.size _gnutls_cpuid, . - _gnutls_cpuid
+
+       .globl  _gnutls_have_cpuid
+       .type   _gnutls_have_cpuid, @function
+_gnutls_have_cpuid:
+.LFB0:
+       .cfi_startproc
+       pushfl  
+       pop %eax        
+       orl $0x200000, %eax     
+       push %eax       
+       popfl   
+       pushfl  
+       pop %eax        
+       andl $0x200000, %eax    
+       ret
+       .cfi_endproc
+.LFE0:
+       .size   _gnutls_have_cpuid, .-_gnutls_have_cpuid
+
+.section .note.GNU-stack,"",@progbits
index 0b61272cda9f0129d1cd539a69f309edab157698..4a5d5c77011328fccb10b4bb17fef5ccd0e453be 100644 (file)
 
 #include <config.h>
 
-#ifdef ASM_X86_64
+#if defined(ASM_X86_32) || defined(ASM_X86_64)
 
-# ifdef HAVE_CPUID_H
-#  include <cpuid.h>
-#  define cpuid __cpuid
-# else
-
-#define cpuid(func,ax,bx,cx,dx)\
-  __asm__ __volatile__ ("cpuid":\
-  "=a" (ax), "=b" (bx), "=c" (cx), "=d" (dx) : "a" (func));
-
-# endif
-
-# define have_cpuid() 1
+void _gnutls_cpuid(unsigned int func, unsigned int *ax, unsigned int *bx, unsigned int *cx, unsigned int* dx);
 
-#endif /* ASM_X86_64 */
-
-
-#ifdef ASM_X86_32
-/* some GCC versions complain on the version above */
-#  define cpuid(func, a, b, c, d) g_cpuid(func, &a, &b, &c, &d)
+# ifdef ASM_X86_32
+unsigned int _gnutls_have_cpuid(void);
+# else
+#  define _gnutls_have_cpuid() 1
+# endif /* ASM_X86_32 */
 
-inline static void g_cpuid(uint32_t func, unsigned int *ax, unsigned int *bx, unsigned int *cx, unsigned int* dx)
-{
-    asm volatile ("pushl %%ebx\n"
-                  "cpuid\n" 
-                  "movl %%ebx, %1\n"
-                  "popl %%ebx\n"
-                  :"=a" (*ax), "=r"(*bx), "=c"(*cx), "=d"(*dx)
-                  :"a"(func)
-                  :"cc");
-}
+#endif
 
-inline static unsigned int have_cpuid(void)
-{
-  unsigned int have_id;
-  asm volatile(
-    "pushfl\t\n"
-    "pop %0\t\n"
-    "orl $0x200000, %0\t\n"
-    "push %0\t\n"
-    "popfl\t\n"
-    "pushfl\t\n"
-    "pop %0\t\n"
-    "andl $0x200000, %0\t\n"
-    :"=r" (have_id)
-    ::
-  );
-  
-  return have_id;
-}
-#endif /* ASM_X86_32 */