[eigen] SEGFAULTs after changeset 537b5d33b440 (+patch)

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


Hi all,

I've been struggling this last week to find out why *several* parts of
my code suddenly stopped working with Eigen3, and I finally nailed
down the specific change that makes the code crashes, and it's about
the CPUID macros changed in 537b5d33b440.
It turned out that the logic of the #if's wasn't maintained in the
change, and it seems to me that the "xchgl ..." instruction was
invoked instead of the "cpuid...".

I attach a patch that fixes it (tested in gcc + amd64), but please,
someone with a good understanding of what is the __PIC__ supposed to
do here, take a careful look at the resulting code:

===============================
//---------- Cache sizes ----------

#if defined(__GNUC__) && ( defined(__i386__) || defined(__x86_64__) )
#  if defined(__PIC__) && defined(__i386__)
     // Case for x86 with PIC
#    define EIGEN_CPUID(abcd,func,id) \
       __asm__ __volatile__ ("xchgl %%ebx, %%esi;cpuid; xchgl
%%ebx,%%esi": "=a" (abcd[0]), "=S" (abcd[1]), "=c" (abcd[2]), "=d"
(abcd[3]) : "a" (func), "c" (id));
#  else
     // Case for x86_64 or x86 w/o PIC
#    define EIGEN_CPUID(abcd,func,id) \
       __asm__ __volatile__ ("cpuid": "=a" (abcd[0]), "=b" (abcd[1]),
"=c" (abcd[2]), "=d" (abcd[3]) : "a" (func), "c" (id) );
#  endif
#elif defined(_MSC_VER)
#  if (_MSC_VER > 1500) /* newer than MSVC++ 9.0 */ || (_MSC_VER ==
1500 && _MSC_FULL_VER >= 150030729) /* MSVC++ 9.0 with SP1*/
#    define EIGEN_CPUID(abcd,func,id) __cpuidex((int*)abcd,func,id)
#  endif
#endif

===============================

btw, if it helps, in all my builds __PIC__ seems to be predefined by GCC.

Thanks in advance!

JL
# HG changeset patch
# User Jose Luis Blanco <joseluisblancoc@xxxxxxxxx>
# Date 1294191823 -3600
# Node ID b010ba908e571b090315631881d76b43d218049b
# Parent  de9d6db42d0600f7300f57fee3627a2493632171
Update of CPUID macros to fix segfaults in amd64 code.

diff -r de9d6db42d06 -r b010ba908e57 Eigen/src/Core/util/Memory.h
--- a/Eigen/src/Core/util/Memory.h	Tue Jan 04 15:35:50 2011 +0100
+++ b/Eigen/src/Core/util/Memory.h	Wed Jan 05 02:43:43 2011 +0100
@@ -598,10 +598,12 @@
 //---------- Cache sizes ----------
 
 #if defined(__GNUC__) && ( defined(__i386__) || defined(__x86_64__) )
-#  if defined(__PIC__)
+#  if defined(__PIC__) && defined(__i386__)
+     // Case for x86 with PIC
 #    define EIGEN_CPUID(abcd,func,id) \
        __asm__ __volatile__ ("xchgl %%ebx, %%esi;cpuid; xchgl %%ebx,%%esi": "=a" (abcd[0]), "=S" (abcd[1]), "=c" (abcd[2]), "=d" (abcd[3]) : "a" (func), "c" (id));
 #  else
+     // Case for x86_64 or x86 w/o PIC
 #    define EIGEN_CPUID(abcd,func,id) \
        __asm__ __volatile__ ("cpuid": "=a" (abcd[0]), "=b" (abcd[1]), "=c" (abcd[2]), "=d" (abcd[3]) : "a" (func), "c" (id) );
 #  endif


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/