Here is my test case:
unsigned char Keep4_3Ratio;
unsigned long SMode=0, DSMode=0;
bool CheckTVRatioReq()
{
return(Keep4_3Ratio && (DSMode == 1 || SMode == 1));
}
Compiling on an x86-32 compiler with the following:
g++ -march=athlon64 -masm=intel -O3 -fomit-frame-pointer -o test.o -c test.cpp
Causes the compile to fail with:
Assembler messages: Error: expecting string instruction after `rep'
The assembly being:
_Z15CheckTVRatioReqv:
.LFB2:
xor %eax, %eax
cmp BYTE PTR Keep4_3Ratio, 0
je .L4
cmp DWORD PTR DSMode, 1
mov %al, 1
je .L4
xor %eax, %eax
cmp DWORD PTR SMode, 1
sete %al
.L4:
rep ret
"rep ret" is an invalid instruction.
I've tested with the following 32 bit compilers:
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v
--enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--program-suffix=-4.1 --enable-__cxa_atexit --enable-clocale=gnu
--enable-libstdcxx-debug --enable-mpfr --with-tune=i686
--enable-checking=release i486-linux-gnu
Thread model: posix
gcc version 4.1.2 20060928 (prerelease) (Debian 4.1.1-15)
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v
--enable-languages=c,c++,java,fortran,objc,obj-c++,treelang --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--program-suffix=-4.2 --enable-__cxa_atexit --enable-clocale=gnu
--enable-libstdcxx-debug --enable-java-awt=gtk-default,qt-default
--enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-4.2-1.4.2.0/jre
--enable-objc-gc --enable-mpfr --with-tune=generic --enable-checking=release
i486-linux-gnu
Thread model: posix
gcc version 4.2.0 20060709 (experimental) (Debian 4.2-20060709-1)
Using built-in specs.
Target: i586-msdosdjgpp
Configured with: ./configure --target=i586-msdosdjgpp --prefix=/usr
--disable-nls --enable-languages=c,c++
--with-headers=/usr/i586-msdosdjgpp/sys-include
Thread model: single
gcc version 4.1.0
Reading specs from /usr/i586-mingw32/lib/gcc/i586-mingw32/3.4.5/specs
Configured with: ../configure --prefix=/usr/i586-mingw32 --with-gcc
--with-gnu-ld --with-gnu-as --target=i586-mingw32 --enable-threads
--disable-nls --enable-languages=c,c++,f77,ada,objc,java
--disable-win32-registry --disable-shared --enable-sjlj-exceptions
--enable-libgcj --disable-java-awt --without-x --enable-java-gc=boehm
--disable-libgcj-debug --enable-interpreter --enable-hash-synchronization
--disable-libstdcxx-debug
Thread model: win32
gcc version 3.4.5 (mingw special)
Reading specs from ../lib/gcc/mingw32/3.4.5/specs
Configured with: ../gcc-3.4.5/configure --with-gcc --with-gnu-ld --with-gnu-as
--host=mingw32 --target=mingw32 --prefix=/mingw --enable-threads --disable-nls
--enable-languages=c,c++,f77,ada,objc,java --disable-win32-registry
--disable-shared --enable-sjlj-exceptions --enable-libgcj --disable-java-awt
--without-x --enable-java-gc=boehm --disable-libgcj-debug --enable-interpreter
--enable-hash-synchronization --enable-libstdcxx-debug
Thread model: win32
gcc version 3.4.5 (mingw special)
Using built-in specs.
Target: djgpp
Configured with: /gnu/gcc-4.10/configure djgpp --prefix=/dev/env/DJDIR
--disable-nls --disable-werror
--enable-languages=c,c++,fortran,objc,obj-c++,ada
Thread model: single
gcc version 4.1.0
Interestingly enough, it did not fail when using this version of GCC:
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --enable-languages=c,c++,java
--prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--program-suffix=-4.0 --enable-__cxa_atexit --enable-clocale=gnu
--enable-libstdcxx-debug --enable-java-awt=gtk-default --enable-gtk-cairo
--with-java-home=/usr/lib/jvm/java-1.4.2-gcj-4.0-1.4.2.0/jre --with-tune=i686
--enable-checking=release i486-linux-gnu
Thread model: posix
gcc version 4.0.4 20060904 (prerelease) (Debian 4.0.3-7)
Although I suspect if I played with the options more I can get it to fail with
that GCC too.
Now when using the same case with an x86-64 compile and the following options:
g++ -march=athlon64 -masm=intel -o test.o -c test.cpp
I get the following errors:
Assembler messages:
Error: invalid operand for 'movzx' ('(' unexpected)
Error: invalid operand for 'mov' ('(' unexpected)
Error: invalid operand for 'mov' ('(' unexpected)
Assembly being:
_Z15CheckTVRatioReqv:
.LFB2:
push %rbp
.LCFI0:
mov %rbp, %rsp
.LCFI1:
movzx %eax, BYTE PTR Keep4_3Ratio(%rip)
test %al, %al
je .L2
mov %rax, QWORD PTR DSMode(%rip)
cmp %rax, 1
je .L4
mov %rax, QWORD PTR SMode(%rip)
cmp %rax, 1
jne .L2
.L4:
mov BYTE PTR [%rbp-1], 1
jmp .L6
.L2:
mov BYTE PTR [%rbp-1], 0
.L6:
movzx %eax, BYTE PTR [%rbp-1]
leave
ret
I don't know AMD64 assembly well but "Keep4_3Ratio(%rip)" and the like doesn't
look right to me.
If I add -O3 so the line becomes:
g++ -O3 -march=athlon64 -masm=intel -o test.o -c test.cpp
I get "cmp" bugs instead of "mov" and I also get the "rep ret" bug from above
when using GCC 4.1 (but not 4.0).
My 64 bit compilers:
Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --enable-languages=c,c++,java
--prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--program-suffix=-4.0 --enable-__cxa_atexit --enable-clocale=gnu
--enable-libstdcxx-debug --enable-java-awt=gtk --enable-gtk-cairo
--with-java-home=/usr/lib/jvm/java-1.4.2-gcj-4.0-1.4.2.0/jre
--enable-checking=release x86_64-linux-gnu
Thread model: posix
gcc version 4.0.4 20060904 (prerelease) (Debian 4.0.3-7)
Target: x86_64-linux-gnu
Configured with: ../src/configure -v
--enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--program-suffix=-4.1 --enable-__cxa_atexit --enable-clocale=gnu
--enable-libstdcxx-debug --enable-mpfr --enable-checking=release
x86_64-linux-gnu
Thread model: posix
gcc version 4.1.2 20060928 (prerelease) (Debian 4.1.1-15)
I've conducted this test on two different PCs, one running WinXP SP2, and the
other Debian Unstable.
--
Summary: -masm=intel combined with -march=athlon64 has some
issues.
Product: gcc
Version: 4.1.2
Status: UNCONFIRMED
Severity: major
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: nachms+gcc at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29473