[xiph-commits] r11354 - branches/theora-mmx/lib

dlenski at svn.xiph.org dlenski at svn.xiph.org
Sat May 6 14:17:30 PDT 2006


Author: dlenski
Date: 2006-05-06 14:17:26 -0700 (Sat, 06 May 2006)
New Revision: 11354

Modified:
   branches/theora-mmx/lib/cpu.c
   branches/theora-mmx/lib/cpu.h
Log:
more complete x86_32 and x86_64 cpuid routines (should now detect 3dnowext, sse, sse2 on amd)

Modified: branches/theora-mmx/lib/cpu.c
===================================================================
--- branches/theora-mmx/lib/cpu.c	2006-05-06 19:41:12 UTC (rev 11353)
+++ branches/theora-mmx/lib/cpu.c	2006-05-06 21:17:26 UTC (rev 11354)
@@ -15,12 +15,13 @@
 
  ********************************************************************/
 
+#include <stdio.h>
 #include "cpu.h"
 
 ogg_uint32_t cpu_flags = 0;
 
 void
-cpuid(ogg_int32_t op, ogg_uint32_t *eax, ogg_uint32_t *ebx, ogg_uint32_t *ecx, ogg_uint32_t *edx) 
+cpuid(ogg_int32_t op, ogg_uint32_t *eax, ogg_uint32_t *ebx, ogg_uint32_t *ecx, ogg_uint32_t *edx)
 {
 #if defined(__x86_64__)
   asm volatile ("pushq %%rbx   \n\t"
@@ -47,12 +48,13 @@
 #endif
 }
 
+#if defined(__x86_64__) || defined(__i386__)
 static ogg_uint32_t cpu_get_flags (void)
 {
   ogg_uint32_t eax, ebx, ecx, edx;
   ogg_uint32_t flags = 0;
 
-/* check for cpuid support */
+  /* check for cpuid support */
 
 #if defined(__x86_64__)
 
@@ -80,45 +82,74 @@
 
   cpuid(0, &eax, &ebx, &ecx, &edx);
 
+#if 0
   if (ebx == 0x756e6547 &&
       edx == 0x49656e69 &&
       ecx == 0x6c65746e) {
     /* intel */
 
   inteltest:
+#endif
     cpuid(1, &eax, &ebx, &ecx, &edx);
     if ((edx & 0x00800000) == 0)
       return 0;
-    flags = CPU_X86_MMX;
+    flags |= CPU_X86_MMX;
     if (edx & 0x02000000)
       flags |= CPU_X86_MMXEXT | CPU_X86_SSE;
     if (edx & 0x04000000)
       flags |= CPU_X86_SSE2;
+#if 0
     return flags;
-  } else if (ebx == 0x68747541 &&
-             edx == 0x69746e65 &&
-             ecx == 0x444d4163) {
+  } else
+#endif
+
+  if (ebx == 0x68747541 &&
+      edx == 0x69746e65 &&
+      ecx == 0x444d4163) {
     /* AMD */
     cpuid(0x80000000, &eax, &ebx, &ecx, &edx);
-    if ((unsigned)eax < 0x80000001)
-      goto inteltest;
-    cpuid(0x80000001, &eax, &ebx, &ecx, &edx);
-    if ((edx & 0x00800000) == 0)
-      return 0;
-    flags = CPU_X86_MMX;
-    if (edx & 0x80000000)
-      flags |= CPU_X86_3DNOW;
-    if (edx & 0x00400000)
-      flags |= CPU_X86_MMXEXT;
-    return flags;
+    if (eax >= 0x80000001) {
+      cpuid(0x80000001, &eax, &ebx, &ecx, &edx);
+      if ((edx & 0x00800000) == 0)
+        return 0;
+      flags |= CPU_X86_MMX;
+      if (edx & 0x80000000)
+        flags |= CPU_X86_3DNOW;
+      if (edx & 0x40000000)
+        flags |= CPU_X86_3DNOWEXT;
+      if (edx & 0x00400000)
+        flags |= CPU_X86_MMXEXT;
+      /* return flags; */
+    }
   }
+#if 0
   else {
     /* implement me */
   }
+#endif
 
+  if (flags) {
+    fprintf(stderr, "vectorized instruction sets supported: ");
+    if (flags | CPU_X86_MMX)      fprintf(stderr, "mmx ");
+    if (flags | CPU_X86_MMXEXT)   fprintf(stderr, "mmxext ");
+    if (flags | CPU_X86_SSE)      fprintf(stderr, "sse ");
+    if (flags | CPU_X86_SSE2)     fprintf(stderr, "sse2 ");
+    if (flags | CPU_X86_3DNOW)    fprintf(stderr, "3dnow ");
+    if (flags | CPU_X86_3DNOWEXT) fprintf(stderr, "3dnowext ");
+    fprintf(stderr, "\n");
+  }
+
   return flags;
 }
 
+#else /* not an i386 or x86_64 */
+
+static ogg_uint32_t cpu_get_flags (void) {
+  return 0;
+}
+
+#endif
+
 void cpu_init () 
 {
   cpu_flags = cpu_get_flags();

Modified: branches/theora-mmx/lib/cpu.h
===================================================================
--- branches/theora-mmx/lib/cpu.h	2006-05-06 19:41:12 UTC (rev 11353)
+++ branches/theora-mmx/lib/cpu.h	2006-05-06 21:17:26 UTC (rev 11354)
@@ -24,5 +24,6 @@
 #define CPU_X86_MMXEXT	(1<<2)
 #define CPU_X86_SSE	(1<<3)
 #define CPU_X86_SSE2	(1<<4)
+#define CPU_X86_3DNOWEXT (1<<5)
 
 void cpu_init () ;



More information about the commits mailing list