[Bug c/58928] New: Different results from gcc when -mlzcnt is used
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58928 Bug ID: 58928 Summary: Different results from gcc when -mlzcnt is used Product: gcc Version: 4.8.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: mikeb01 at gmail dot com Created attachment 31113 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=31113&action=edit Preprossed test.c code I have the following code: #include #include #include long long lzcnt(long long l) { return __lzcnt64(l); } int main(int argc, char** argv) { printf("%lld\n", lzcnt(atoll(argv[1]))); return 0; } If I compile and run with and without the -mlzcnt flag I get different results: $ gcc src/test.c -D__LZCNT__ -mlzcnt && ./a.out 2047 10 $ gcc src/test.c -D__LZCNT__ && ./a.out 2047 53 $ gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.2/lto-wrapper Target: x86_64-redhat-linux Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-isl=/builddir/build/BUILD/gcc-4.8.2-20131017/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.2-20131017/obj-x86_64-redhat-linux/cloog-install --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux Thread model: posix gcc version 4.8.2 20131017 (Red Hat 4.8.2-1) (GCC) File test.i attached. It was the same for both compilations, so only one file attached.
[Bug target/58928] Different results from gcc when -mlzcnt is used
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58928 --- Comment #2 from Michael Barker --- > Hope helps What hardware platform are you testing on? I'm running on Ivy Bridge: Intel(R) Xeon(R) CPU E5620 @2.40GHz Could you put the assembler that you see on the ticket: With -mlzcnt: 00400580 : 400580:55 push %rbp 400581:48 89 e5 mov%rsp,%rbp 400584:48 89 7d e8 mov%rdi,-0x18(%rbp) 400588:48 8b 45 e8 mov-0x18(%rbp),%rax 40058c:48 89 45 f8 mov%rax,-0x8(%rbp) 400590:f3 48 0f bd 45 f8lzcnt -0x8(%rbp),%rax 400596:48 98cltq 400598:5d pop%rbp 400599:c3 retq Without -mlzcnt: 00400580 : 400580:55 push %rbp 400581:48 89 e5 mov%rsp,%rbp 400584:48 89 7d e8 mov%rdi,-0x18(%rbp) 400588:48 8b 45 e8 mov-0x18(%rbp),%rax 40058c:48 89 45 f8 mov%rax,-0x8(%rbp) 400590:48 0f bd 45 f8 bsr-0x8(%rbp),%rax 400595:48 83 f0 3f xor$0x3f,%rax 400599:48 98cltq 40059b:5d pop%rbp 40059c:c3 retq
[Bug target/58928] Different results from gcc when -mlzcnt is used
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58928 --- Comment #5 from Michael Barker --- (In reply to Jakub Jelinek from comment #4) > Intel(R) Xeon(R) CPU E5620 @2.40GHz > is not IvyBridge, plus even IvyBridge doesn't support lzcnt insn, only > Haswell or some recent AMD CPUs. So, this looks like user error, you > shouldn't compile code you intend to run on non-lzcnt CPUs with -mlzcnt. Sorry, shelled into the wrong machine when running the command. Actual model number is (i7-3770). Happy with the explanation, please close. There is a further issue that the bug.c code won't compile under g++, due to a missing builtin. /.../lzcntintrin.h:38:29: error: ‘__builtin_clzs’ was not declared in this scope return __builtin_clzs (__X); However I will raise a separate bug for that.
[Bug c++/59874] New: Missing builtin (__builtin_clzs) when compiling with g++
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59874 Bug ID: 59874 Summary: Missing builtin (__builtin_clzs) when compiling with g++ Product: gcc Version: 4.8.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: mikeb01 at gmail dot com Created attachment 31888 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=31888&action=edit Preprocessed version of bug.cc The following code: #include int main(int argc, char** argv) { return __lzcnt32(2047); } Fails to compile using g++ (works fine with gcc). It will compile if the -mlzcnt switch is used, but on some platforms that will generate incorrect code. The __builtin_clzs does not appear to be defined when using the c++ compiler. If I hand modify the lzcntintrin.h file and comment out the whole definition of the __lzcnt16 intrinsic it works okay and generates the expected code. $ g++ -v -save-temps -D__LZCNT__ bug.cc Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.2/lto-wrapper Target: x86_64-redhat-linux Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-isl=/builddir/build/BUILD/gcc-4.8.2-20131212/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.2-20131212/obj-x86_64-redhat-linux/cloog-install --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux Thread model: posix gcc version 4.8.2 20131212 (Red Hat 4.8.2-7) (GCC) COLLECT_GCC_OPTIONS='-v' '-save-temps' '-D' '__LZCNT__' '-shared-libgcc' '-mtune=generic' '-march=x86-64' /usr/libexec/gcc/x86_64-redhat-linux/4.8.2/cc1plus -E -quiet -v -D_GNU_SOURCE -D __LZCNT__ bug.cc -mtune=generic -march=x86-64 -fpch-preprocess -o bug.ii ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/4.8.2/include-fixed" ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/4.8.2/../../../../x86_64-redhat-linux/include" #include "..." search starts here: #include <...> search starts here: /usr/lib/gcc/x86_64-redhat-linux/4.8.2/../../../../include/c++/4.8.2 /usr/lib/gcc/x86_64-redhat-linux/4.8.2/../../../../include/c++/4.8.2/x86_64-redhat-linux /usr/lib/gcc/x86_64-redhat-linux/4.8.2/../../../../include/c++/4.8.2/backward /usr/lib/gcc/x86_64-redhat-linux/4.8.2/include /usr/local/include /usr/include End of search list. COLLECT_GCC_OPTIONS='-v' '-save-temps' '-D' '__LZCNT__' '-shared-libgcc' '-mtune=generic' '-march=x86-64' /usr/libexec/gcc/x86_64-redhat-linux/4.8.2/cc1plus -fpreprocessed bug.ii -quiet -dumpbase bug.cc -mtune=generic -march=x86-64 -auxbase bug -version -o bug.s GNU C++ (GCC) version 4.8.2 20131212 (Red Hat 4.8.2-7) (x86_64-redhat-linux) compiled by GNU C version 4.8.2 20131212 (Red Hat 4.8.2-7), GMP version 5.1.1, MPFR version 3.1.1, MPC version 1.0.1 GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 GNU C++ (GCC) version 4.8.2 20131212 (Red Hat 4.8.2-7) (x86_64-redhat-linux) compiled by GNU C version 4.8.2 20131212 (Red Hat 4.8.2-7), GMP version 5.1.1, MPFR version 3.1.1, MPC version 1.0.1 GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: 489f772b6d0264e1e4c03fca513f7a0d In file included from /usr/lib/gcc/x86_64-redhat-linux/4.8.2/include/immintrin.h:64:0, from /usr/lib/gcc/x86_64-redhat-linux/4.8.2/include/x86intrin.h:62, from bug.cc:1: /usr/lib/gcc/x86_64-redhat-linux/4.8.2/include/lzcntintrin.h: In function ‘short unsigned int __lzcnt16(short unsigned int)’: /usr/lib/gcc/x86_64-redhat-linux/4.8.2/include/lzcntintrin.h:38:29: error: ‘__builtin_clzs’ was not declared in this scope return __builtin_clzs (__X);
[Bug target/58928] Different results from gcc when -mlzcnt is used
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58928 Michael Barker changed: What|Removed |Added Status|UNCONFIRMED |RESOLVED Resolution|--- |FIXED --- Comment #6 from Michael Barker --- Not a bug, closed by reporter.
[Bug target/58928] Different results from gcc when -mlzcnt is used
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58928 Michael Barker changed: What|Removed |Added Resolution|FIXED |INVALID