[Bug target/71777] __builtin_cpu_supports() doesn't work on powerpc

2016-07-07 Thread bergner at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71777

Peter Bergner  changed:

   What|Removed |Added

 Status|RESOLVED|CLOSED

--- Comment #4 from Peter Bergner  ---
Closing per above.

[Bug target/71777] __builtin_cpu_supports() doesn't work on powerpc

2016-07-06 Thread mathieu.malaterre at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71777

Mathieu Malaterre  changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution|--- |INVALID

--- Comment #3 from Mathieu Malaterre  ---
Right. I totally missed that from your post. Sorry for the noise, this works
for me now (was using glibc 2.22).

For reference on POWER7, I get:

2
--
1
2
3
6
9
10
14
17
20
23
24
25
27
29
30
31
34
37

[Bug target/71777] __builtin_cpu_supports() doesn't work on powerpc

2016-07-06 Thread bergner at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71777

--- Comment #2 from Peter Bergner  ---
FYI, this is the output of your demo code on my POWER8 LE Ubuntu 16.04 system:

bergner@ampere:~$ gcc demo.c 
bergner@ampere:~$ ./a.out 
1
--
1
2
3
4
6
9
10
11
14
15
16
17
19
20
23
24
25
27
29
31
33
34
36
37

[Bug target/71777] __builtin_cpu_supports() doesn't work on powerpc

2016-07-06 Thread bergner at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71777

--- Comment #1 from Peter Bergner  ---
The documentation doesn't mention this (and I should probably add it), but the
__builtin_cpu_is() and __builtin_cpu_supports() builtins rely on support from
glibc (glibc 2.23 and later to be exact).  If you build against an oldish glibc
(2.22 and earlier), the builtins will always return 0.  You can verify whether
your gcc was built with a new enough glibc by looking at the assembly output of
a call to one of the builtins.  For example:

bergner@genoa:~/gcc/BUGS/CPU_IS$ cat cpu.c 
int
foo (void)
{
  return __builtin_cpu_is ("power8");
}
bergner@genoa:~/gcc/BUGS/CPU_IS$
/home/bergner/gcc/build/gcc-fsf-mainline-debug-2/gcc/xgcc
-B/home/bergner/gcc/build/gcc-fsf-mainline-debug-2/gcc -O2 -S cpu.c 
bergner@genoa:~/gcc/BUGS/CPU_IS$ cat cpu.s 
...
foo:
li 3,0   <- No support from glibc.
blr

If your gcc/glibc both support the builtins, then you'd see a load off of r13
and some logical instructions on the result, like so:

foo:
lwz 3,-28764(13)
xori 3,3,0x2d
cntlzw 3,3
srwi 3,3,5
blr


Another check is to see whether the libc.a and/or ld.so export the symbol
__parse_hwcap_and_convert_at_platform.  If it doesn't, then your glibc is too
old:

linux%: objdump -x /usr/lib/debug/lib/powerpc64le-linux-gnu/ld-2.23.so | grep
__parse_hwcap_and_convert_at_platform
 000289d0 g F .text  0348 0x60
__parse_hwcap_and_convert_at_platform@@GLIBC_2.23


My guess if this is your problem.  If not, I can help you diagnose further to
see what the problem is.

You can read my post here on why we need glibc for these builtins:

  https://gcc.gnu.org/ml/gcc-patches/2016-01/msg01012.html