Bug 43215 - x86-64: Nonstandard instruction "movd %xmm0, %rax"
Summary: x86-64: Nonstandard instruction "movd %xmm0, %rax"
Status: RESOLVED WONTFIX
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.4.3
: P3 minor
Target Milestone: 4.3.5
Assignee: Uroš Bizjak
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-03-01 02:22 UTC by Richard Li
Modified: 2010-05-03 09:01 UTC (History)
1 user (show)

See Also:
Host: i686-linux-gnu
Target: x86_64-linux-gnu
Build: x86_64-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2010-03-01 09:56:03


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Li 2010-03-01 02:22:16 UTC
#include <stdint.h>
uint64_t extract_double (double x)
{
    union {
        double dbl;
        uint64_t u;
    } t;
    t.dbl = x;
    return t.u;
}

Compile this function with "x86_64-pc-linux-gnu-gcc -O2 -march=core2 -S a.c", and we get the following assembly codes:

extract_double:
.LFB0:
    .cfi_startproc
    movd    %xmm0, %rax
    ret

The instruction "movd %xmm0, %rax" is nonstandard. Movd should be replaced by movq.

(GNU assembler silently accepts it as if it were "movq %xmm0, %rax", so it probably has caused no practical problems.)
Comment 1 Uroš Bizjak 2010-03-01 09:56:03 UTC
Indeed.

Following patch fixes the problem:

Index: i386.md
===================================================================
--- i386.md	(revision 157132)
+++ i386.md	(working copy)
@@ -3245,7 +3245,7 @@
 
     case 9:
     case 10:
-    return "%vmovd\t{%1, %0|%0, %1}";
+    return "%vmovq\t{%1, %0|%0, %1}";
 
     default:
       gcc_unreachable();
Comment 2 H.J. Lu 2010-03-01 13:31:29 UTC
This is done on purpose to provide backward compatibility
since vmovq isn't in original x86-64 spec and older assemblers
don't support it. From i386-opc.tbl in binutils:

// These really shouldn't allow for Reg64 (movq is the right mnemonic for
// copying between Reg64/Mem64 and RegXMM/RegMMX, as is mandated by Intel's
// spec). AMD's spec, having been in existence for much longer, failed to
// recognize that and specified movd for 32- and 64-bit operations.

// vmovd really shouldn't allow for 64bit operand (vmovq is the right
// mnemonic for copying between Reg64/Mem64 and RegXMM, as is mandated
// by Intel AVX spec).  To avoid extra template in gcc x86 backend and
// support assembler for AMD64, we accept 64bit operand on vmovd so
// that we can use one template for both SSE and AVX instructions.
Comment 3 Richard Biener 2010-03-01 14:55:45 UTC
I fail to see why binutils accepting both version should be a reason to
not fix gcc.
Comment 4 H.J. Lu 2010-03-01 15:42:00 UTC
(In reply to comment #3)
> I fail to see why binutils accepting both version should be a reason to
> not fix gcc.
> 

What is the minimum binutils required by gcc? Does it support movq?
Comment 5 Uroš Bizjak 2010-03-01 20:30:05 UTC
(In reply to comment #4)

> What is the minimum binutils required by gcc? Does it support movq?

install.texi says that i?86-linux-gnu requires 2.13.1.

Since you are listed as x86 binutils maintainer, I would expect that you can provide the information if it includes correct movq support.
Comment 6 Uroš Bizjak 2010-03-01 20:36:11 UTC
(In reply to comment #5)

> install.texi says that i?86-linux-gnu requires 2.13.1.

binutils-2.13.1.tar.bz2           07-Nov-2002 23:45  9.5M  
binutils-2.13.1.tar.gz            07-Nov-2002 23:45   12M  

IMNSHO, I really can't see the reason why we should support *eight* years old toolchain part with a new compiler.  Does it even build with gcc-4.5?

Comment 7 H.J. Lu 2010-03-01 23:16:05 UTC
(In reply to comment #5)
> (In reply to comment #4)
> 
> > What is the minimum binutils required by gcc? Does it support movq?
> 
> install.texi says that i?86-linux-gnu requires 2.13.1.
> 
> Since you are listed as x86 binutils maintainer, I would expect that you can
> provide the information if it includes correct movq support.

"movq" was added by

http://sourceware.org/ml/binutils/2005-07/msg00134.html

in binutils-2.17.
Comment 8 H.J. Lu 2010-03-01 23:18:03 UTC
(In reply to comment #6)
> (In reply to comment #5)
> 
> > install.texi says that i?86-linux-gnu requires 2.13.1.
> 
> binutils-2.13.1.tar.bz2           07-Nov-2002 23:45  9.5M  
> binutils-2.13.1.tar.gz            07-Nov-2002 23:45   12M  
> 
> IMNSHO, I really can't see the reason why we should support *eight* years old
> toolchain part with a new compiler.  Does it even build with gcc-4.5?
> 

It may be a good idea by itself. However, since AMD64 uses movd instead
of movq, some non-GNU assemblers may not support movq. Why change it
when nothing is broken?
Comment 9 Uroš Bizjak 2010-05-03 09:01:19 UTC
(In reply to comment #8)

> It may be a good idea by itself. However, since AMD64 uses movd instead
> of movq, some non-GNU assemblers may not support movq. Why change it
> when nothing is broken?

Indeed.