gallium/rtasm: properly detect SSE and SSE2
authorMarek Olšák <maraeo@gmail.com>
Fri, 24 Feb 2012 18:29:48 +0000 (19:29 +0100)
committerMarek Olšák <maraeo@gmail.com>
Mon, 27 Feb 2012 01:03:23 +0000 (02:03 +0100)
This should fix crashes on ancient processors.

src/gallium/auxiliary/rtasm/rtasm_cpu.c

index 0461c815504800f183c9bb7f5ac919e7be9cc6d1..7afcf1452b1f144e69db3203d17aa72a2a53d71c 100644 (file)
  *
  **************************************************************************/
 
+#include "pipe/p_config.h"
+#include "rtasm_cpu.h"
+
+#if defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64)
 
 #include "util/u_debug.h"
-#include "rtasm_cpu.h"
+#include "util/u_cpu_detect.h"
 
+DEBUG_GET_ONCE_BOOL_OPTION(nosse, "GALLIUM_NOSSE", FALSE);
 
-#if defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64)
-static boolean rtasm_sse_enabled(void)
+static struct util_cpu_caps *get_cpu_caps(void)
 {
-   static boolean firsttime = 1;
-   static boolean enabled;
-   
-   /* This gets called quite often at the moment:
-    */
-   if (firsttime) {
-      enabled =  !debug_get_bool_option("GALLIUM_NOSSE", FALSE);
-      firsttime = FALSE;
-   }
-   return enabled;
+   util_cpu_detect();
+   return &util_cpu_caps;
 }
-#endif
 
 int rtasm_cpu_has_sse(void)
 {
-   /* FIXME: actually detect this at run-time */
-#if defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64)
-   return rtasm_sse_enabled();
-#else
-   return 0;
-#endif
+   return !debug_get_option_nosse() && get_cpu_caps()->has_sse;
 }
 
 int rtasm_cpu_has_sse2(void) 
 {
-   /* FIXME: actually detect this at run-time */
-#if defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64)
-   return rtasm_sse_enabled();
+   return !debug_get_option_nosse() && get_cpu_caps()->has_sse2;
+}
+
+
 #else
+
+int rtasm_cpu_has_sse(void)
+{
    return 0;
-#endif
 }
+
+int rtasm_cpu_has_sse2(void)
+{
+   return 0;
+}
+
+#endif