On Tue, Jul 28, 2015 at 3:05 PM, Samuel Thibault <samuel.thiba...@inria.fr>
wrote:

> Paul Hargrove, le Tue 28 Jul 2015 15:00:36 -0700, a écrit :
> > Well, for the compiler that accepted the "=r" form and then generated
> code that
> > SEGV'd I would say "buggy".
>
> I would like to see the generated code before saying anything, since
> it's so easy to write bogus inline assembly and being completely unable
> to see the issue before seeing the bogus generated code :)
>

The compiler I have characterized as "buggy" is Solaris Studio 12.2 for
Linux ("Sun C 5.11 Linux_i386 2010/08/13"):

Previously I only had a bunch of SEGVs from "make check" to support that.
However, now I have the generated code that Samuel requested to support
that conclusion.

The inline asm I had originally tested that lead to that characterization
was:

  __asm__(
  "xchg %%ebx,%1\n\t"
  "cpuid\n\t"
  "xchg %%ebx,%1\n\t"
  : "=a" (*eax), "=r" (*ebx), "=c" (*ecx), "=d" (*edx)
  : "0" (*eax), "2" (*ecx));


And retesting that asm today, I find the following generated code:

$ objdump -d src/.libs/libhwloc.so | grep -C1 -w cpuid
   5f5c5:       87 d3                   xchg   %edx,%ebx
   5f5c7:       0f a2                   cpuid
   5f5c9:       87 d3                   xchg   %edx,%ebx



So the compiler chose %edx for the 2nd output, even though is is explicitly
used for the 4th output.
I don't see how that could ever be correct.

I tried adding the early-clobbers ("=&" vs "="):

  : "=a" (*eax), "=r&" (*ebx), "=c" (*ecx), "=&d" (*edx)


But the same bogus code is generated.


We already know the following "final" asm works on this system (on all the
systems I tested):

  __asm__(
  "mov %%ebx,%1\n\t"
  "cpuid\n\t"
  "xchg %%ebx,%1\n\t"
  : "+a" (*eax), "=&SD" (*ebx), "+c" (*ecx), "=&d" (*edx));

But I tried changing "SD" to "r":

  : "+a" (*eax), "=&r" (*ebx), "+c" (*ecx), "=&d" (*edx));


And we again see %edx being chosen for two outputs:

$ objdump -d src/.libs/libhwloc.so | grep -C1 -w cpuid
   5f5b3:       8b d3                   mov    %ebx,%edx
   5f5b5:       0f a2                   cpuid
   5f5b7:       87 d3                   xchg   %edx,%ebx




It is also worth pointing out that the first asm in this email was never a
real candidate because it also resulted in build failures on a couple gcc
versions:

With "gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-11)" on Scientific Linux 6.6
(RHEL clone like CentOS):

libtool: compile:  gcc -DHAVE_CONFIG_H -I.
-I/home/phargrov/OMPI/hwloc-1.11.0-linux-x86-sl6x/hwloc-1.11.0/src
-I../include/private/autogen -I../include/hwloc/autogen
-I/home/phargrov/OMPI/hwloc-1.11.0-linux-x86-sl6x/BLD/
include
-I/home/phargrov/OMPI/hwloc-1.11.0-linux-x86-sl6x/hwloc-1.11.0/include
-DHWLOC_INSIDE_LIBHWLOC -DHWLOC
_PLUGINS_PATH=\"/home/phargrov/OMPI/hwloc-1.11.0-linux-x86-sl6x/INST/lib/hwloc\"
-fvisibility=hidden -g -O2 -M
T topology-x86.lo -MD -MP -MF .deps/topology-x86.Tpo -c
/home/phargrov/OMPI/hwloc-1.11.0-linux-x86-sl6x/hwloc-
1.11.0/src/topology-x86.c  -fPIC -DPIC -o .libs/topology-x86.o
/home/phargrov/OMPI/hwloc-1.11.0-linux-x86-sl6x/hwloc-1.11.0/src/topology-x86.c:
In function ?look_proc?:
/home/phargrov/OMPI/hwloc-1.11.0-linux-x86-sl6x/hwloc-1.11.0/include/private/cpuid-x86.h:75:
error: can't find a register in class ?CLOBBERED_REGS? while reloading ?asm?
/home/phargrov/OMPI/hwloc-1.11.0-linux-x86-sl6x/hwloc-1.11.0/include/private/cpuid-x86.h:75:
error: ?asm? operand has impossible constraints
/home/phargrov/OMPI/hwloc-1.11.0-linux-x86-sl6x/hwloc-1.11.0/include/private/cpuid-x86.h:75:
error: ?asm? operand has impossible constraints
/home/phargrov/OMPI/hwloc-1.11.0-linux-x86-sl6x/hwloc-1.11.0/include/private/cpuid-x86.h:75:
error: ?asm? operand has impossible constraints
/home/phargrov/OMPI/hwloc-1.11.0-linux-x86-sl6x/hwloc-1.11.0/include/private/cpuid-x86.h:75:
error: ?asm? operand has impossible constraints
/home/phargrov/OMPI/hwloc-1.11.0-linux-x86-sl6x/hwloc-1.11.0/include/private/cpuid-x86.h:75:
error: ?asm? operand has impossible constraints
/home/phargrov/OMPI/hwloc-1.11.0-linux-x86-sl6x/hwloc-1.11.0/include/private/cpuid-x86.h:75:
error: ?asm? operand has impossible constraints
/home/phargrov/OMPI/hwloc-1.11.0-linux-x86-sl6x/hwloc-1.11.0/include/private/cpuid-x86.h:75:
error: ?asm? operand has impossible constraints
/home/phargrov/OMPI/hwloc-1.11.0-linux-x86-sl6x/hwloc-1.11.0/include/private/cpuid-x86.h:75:
error: ?asm? operand has impossible constraints
/home/phargrov/OMPI/hwloc-1.11.0-linux-x86-sl6x/hwloc-1.11.0/include/private/cpuid-x86.h:75:
error: ?asm? operand has impossible constraints
/home/phargrov/OMPI/hwloc-1.11.0-linux-x86-sl6x/hwloc-1.11.0/include/private/cpuid-x86.h:75:
error: ?asm? operand has impossible constraints
/home/phargrov/OMPI/hwloc-1.11.0-linux-x86-sl6x/hwloc-1.11.0/include/private/cpuid-x86.h:75:
error: ?asm? operand has impossible constraints
/home/phargrov/OMPI/hwloc-1.11.0-linux-x86-sl6x/hwloc-1.11.0/include/private/cpuid-x86.h:75:
error: ?asm? operand has impossible constraints
/home/phargrov/OMPI/hwloc-1.11.0-linux-x86-sl6x/hwloc-1.11.0/include/private/cpuid-x86.h:75:
error: ?asm? operand has impossible constraints
/home/phargrov/OMPI/hwloc-1.11.0-linux-x86-sl6x/hwloc-1.11.0/include/private/cpuid-x86.h:75:
error: ?asm? operand has impossible constraints
make[1]: *** [topology-x86.lo] Error 1

And with "gcc (GCC) 3.2 20020903 (Red Hat Linux 8.0 3.2-7)" on Red Hat
Linux 8.0:

libtool: compile:  gcc -DHAVE_CONFIG_H -I.
-I/home/pcp1/phargrov/OMPI/hwloc-1.11.0-linux-x86-RH8/hwloc-1.11.0/src
-I../include/private/autogen -I../include/hwloc/autogen
-I/home/pcp1/phargrov/OMPI/hwloc-1.11.0-linux-x86-RH8/BLD/include
-I/home/pcp1/phargrov/OMPI/hwloc-1.11.0-linux-x86-RH8/hwloc-1.11.0/include
-DHWLOC_INSIDE_LIBHWLOC
-DHWLOC_PLUGINS_PATH=\"/home/pcp1/phargrov/OMPI/hwloc-1.11.0-linux-x86-RH8/INST/lib/hwloc\"
-g -O2 -MT topology-x86.lo -MD -MP -MF .deps/topology-x86.Tpo -c
/home/pcp1/phargrov/OMPI/hwloc-1.11.0-linux-x86-RH8/hwloc-1.11.0/src/topology-x86.c
 -fPIC -DPIC -o .libs/topology-x86.o
/home/pcp1/phargrov/OMPI/hwloc-1.11.0-linux-x86-RH8/hwloc-1.11.0/src/topology-x86.c:
In function `look_proc':
/home/pcp1/phargrov/OMPI/hwloc-1.11.0-linux-x86-RH8/hwloc-1.11.0/include/private/cpuid-x86.h:75:
can't find a register in class `Q_REGS' while reloading `asm'
/home/pcp1/phargrov/OMPI/hwloc-1.11.0-linux-x86-RH8/hwloc-1.11.0/include/private/cpuid-x86.h:75:
can't find a register in class `Q_REGS' while reloading `asm'
/home/pcp1/phargrov/OMPI/hwloc-1.11.0-linux-x86-RH8/hwloc-1.11.0/include/private/cpuid-x86.h:75:
can't find a register in class `Q_REGS' while reloading `asm'
/home/pcp1/phargrov/OMPI/hwloc-1.11.0-linux-x86-RH8/hwloc-1.11.0/include/private/cpuid-x86.h:75:
can't find a register in class `Q_REGS' while reloading `asm'
/home/pcp1/phargrov/OMPI/hwloc-1.11.0-linux-x86-RH8/hwloc-1.11.0/include/private/cpuid-x86.h:75:
can't find a register in class `Q_REGS' while reloading `asm'
make[1]: *** [topology-x86.lo] Error 1


These two are examples of "poorly performing" register allocators, as
opposed to the *incorrect* one seen in Solaris Studio 12.2.

-Paul

-- 
Paul H. Hargrove                          phhargr...@lbl.gov
Computer Languages & Systems Software (CLaSS) Group
Computer Science Department               Tel: +1-510-495-2352
Lawrence Berkeley National Laboratory     Fax: +1-510-486-6900

Reply via email to