IlmImf/ImfSystemSpecific.cpp and cpuid

Richard PALO <[email protected]>
Newsgroups gmane.comp.video.openexr.devel
Message-ID <[email protected]>
Hi, came across build issues and the above file..
In particular, it fails when building PIC as the asm code doesn't deal 
with all the possible cases...

Fortunately the code was already strobed with __GNUC__, so I updated to 
use the gcc builtin __get_cpuid which does all the work.

I took advantage of the occasion to rectify the ints to be unsigned as 
we're dealing with registers here.

Patch proposal is attached.

Wanting to test this, I came across an issue here as well for SunOS, so 
I add as well a second patch to correctly include unistd.h for this 
platform in IlmImfTest/main.cpp.

Unfortunately the test fails anyway as there is a file not found named 
'comp_dwaa_v1.exr'.  Can't seem to find it anywhere.  Any hints?

cheers

_______________________________________________
Openexr-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/openexr-devel
patch-IlmImf_ImfSystemSpecific.cpp (text/plain, 1.8 KB)
$NetBSD$

--- IlmImf/ImfSystemSpecific.cpp.orig	2014-08-10 04:23:57.000000000 +0000
+++ IlmImf/ImfSystemSpecific.cpp
@@ -40,21 +40,19 @@ OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_EN
 
 namespace {
 #if defined(IMF_HAVE_SSE2) &&  defined(__GNUC__)
-
+#include <cpuid.h>
     // Helper functions for gcc + SSE enabled
-    void cpuid(int n, int &eax, int &ebx, int &ecx, int &edx)
+    void cpuid(unsigned int n, unsigned int &eax, unsigned int &ebx,
+					unsigned int &ecx, unsigned int &edx)
     {
-        __asm__ __volatile__ (
-            "cpuid"
-            : /* Output  */ "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx) 
-            : /* Input   */ "a"(n)
-            : /* Clobber */);
+		__get_cpuid(n, &eax, &ebx, &ecx, &edx);
     }
 
 #else // IMF_HAVE_SSE2 && __GNUC__
 
     // Helper functions for generic compiler - all disabled
-    void cpuid(int n, int &eax, int &ebx, int &ecx, int &edx)
+    void cpuid(unsigned int n, unsigned int &eax, unsigned int &ebx,
+					unsigned int &ecx, unsigned int &edx)
     {
         eax = ebx = ecx = edx = 0;
     }
@@ -64,7 +62,7 @@ namespace {
 
 #ifdef OPENEXR_IMF_HAVE_GCC_INLINE_ASM_AVX
 
-    void xgetbv(int n, int &eax, int &edx)
+    void xgetbv(unsigned int n, unsigned int &eax, unsigned int &edx)
     {
         __asm__ __volatile__ (
             "xgetbv"
@@ -75,7 +73,7 @@ namespace {
 
 #else //  OPENEXR_IMF_HAVE_GCC_INLINE_ASM_AVX
 
-    void xgetbv(int n, int &eax, int &edx)
+    void xgetbv(unsigned int n, unsigned int &eax, unsigned int &edx)
     {
         eax = edx = 0;
     }
@@ -94,8 +92,8 @@ CpuId::CpuId():
     f16c(false)
 {
     bool osxsave = false;
-    int  max     = 0;
-    int  eax, ebx, ecx, edx;
+    unsigned int  max     = 0;
+    unsigned int  eax, ebx, ecx, edx;
 
     cpuid(0, max, ebx, ecx, edx);
     if (max > 0)
patch-IlmImfTest_main.cpp (text/plain, 324 B)
$NetBSD$

--- IlmImfTest/main.cpp.orig	2014-08-10 04:23:59.000000000 +0000
+++ IlmImfTest/main.cpp
@@ -103,6 +103,8 @@
 #if defined(OPENEXR_IMF_HAVE_LINUX_PROCFS) || defined(OPENEXR_IMF_HAVE_DARWIN)
     #include <unistd.h>
     #include <sstream>
+#elif defined(__sun)
+	#include <unistd.h>
 #endif
 
 using namespace std;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.