Revision: 45555
http://brlcad.svn.sourceforge.net/brlcad/?rev=45555&view=rev
Author: erikgreenwald
Date: 2011-07-20 20:20:07 +0000 (Wed, 20 Jul 2011)
Log Message:
-----------
add support for SSE3, SSE4_1 and SSE4_2. Add a bu_simd_supported function.
Minor cleanup and clobberage fixes
Modified Paths:
--------------
brlcad/trunk/include/bu.h
brlcad/trunk/src/libbu/simd.c
Modified: brlcad/trunk/include/bu.h
===================================================================
--- brlcad/trunk/include/bu.h 2011-07-20 18:56:38 UTC (rev 45554)
+++ brlcad/trunk/include/bu.h 2011-07-20 20:20:07 UTC (rev 45555)
@@ -6113,13 +6113,25 @@
* Detect SIMD type at runtime.
*/
+#define BU_SIMD_SSE4_2 7
+#define BU_SIMD_SSE4_1 6
+#define BU_SIMD_SSE3 5
#define BU_SIMD_ALTIVEC 4
#define BU_SIMD_SSE2 3
#define BU_SIMD_SSE 2
#define BU_SIMD_MMX 1
#define BU_SIMD_NONE 0
+/**
+ * Detect SIMD capabilities at runtime.
+ */
BU_EXPORT extern int bu_simd_level();
+/**
+ * Detect if requested SIMD capabilities are available at runtime.
+ * Returns 1 if they are, 0 if they are not.
+ */
+BU_EXPORT extern int bu_simd_supported(int level);
+
/** @} */
/** @addtogroup file */
Modified: brlcad/trunk/src/libbu/simd.c
===================================================================
--- brlcad/trunk/src/libbu/simd.c 2011-07-20 18:56:38 UTC (rev 45554)
+++ brlcad/trunk/src/libbu/simd.c 2011-07-20 20:20:07 UTC (rev 45555)
@@ -25,13 +25,25 @@
bu_simd_level()
{
#if defined(__GNUC__) && defined(__SSE__)
- int d;
+ int b=0, c=0, d=0;
+ asm volatile(
/* since we're PIC, we need to stash EBX on ia32 */
-#ifdef __i386__
- asm ("pushl %%ebx;cpuid;popl %%ebx;movl $0,%%eax": "=d" (d): "a" (0x1));
-#else
- asm ("cpuid;movl $0,%%eax": "=d"(d): "a"(0x1));
-#endif
+# ifdef __i386__
+ "pushl %%ebx;"
+# endif
+ "cpuid;"
+# ifdef __i386__
+ "popl %%ebx;"
+# endif
+ : "=b"(b), "=c"(c), "=d" (d)
+ : "a" (0x1));
+
+ if(c & 0x100000)
+ return BU_SIMD_SSE4_2;
+ if(c & 0x080000)
+ return BU_SIMD_SSE4_1;
+ if(c & 0x1)
+ return BU_SIMD_SSE3;
if(d & 0x1<<26)
return BU_SIMD_SSE2;
if(d & 0x1<<25)
@@ -42,7 +54,20 @@
return BU_SIMD_NONE;
}
+int
+bu_simd_supported(int level)
+{
+ int l;
+ if(level == 4)
+ return 0;
+
+ l = bu_simd_level();
+
+ return l >= level;
+}
+
+
/*
* Local Variables:
* mode: C
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
10 Tips for Better Web Security
Learn 10 ways to better secure your business today. Topics covered include:
Web security, SSL, hacker attacks & Denial of Service (DoS), private keys,
security Microsoft Exchange, secure Instant Messaging, and much more.
http://www.accelacomm.com/jaw/sfnl/114/51426210/
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits