------- Comment #7 from beebe at math dot utah dot edu  2010-04-30 00:23 -------
Subject: Re:  Erroneous expansion of __asm__() directive

I accept the explanation of the problem with my sample __asm__()
directive, and I think that we can close my bug report at

        http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43782

Since I corrected the test code to put the destination register last,
I have written an extensive test suite to check all of the other uses
of __asm__() directives in my code, and satisfied myself that there
was only one problem instance.

I also verified that after the change, the 49 gcc compiler versions
that I tested now produce the correct answer, as do icc, nvcc, opencc,
pathcc, pgcc, suncc, and upc; they all recognize the __asm__()
directive on x86_64.

However, I strongly recommend some updates in the gcc manual and
possibly also the gas manual.

I went through both in detail, and found that the gcc documentation,
which is where any programmer would expect gcc's __asm__() directive
to be documented, makes NO MENTION WHATSOEVER of the operand order
in ``5.37 Assembler Instructions with C Expression Operands''.

Elsewhere in the gcc manual, there is only this brief description

`-masm=DIALECT'
     Output asm instructions using selected DIALECT.  Supported choices
     are `intel' or `att' (the default one).  Darwin does not support
     `intel'.

but nothing more.

In the gas manual, there is an explanation in the section

* i386-Syntax::                 AT&T Syntax versus Intel Syntax

that gcc uses the AT&T src,dst order on all platforms.  For any
programmer used to reading or writing assembly code (outside of gcc)
for the Intel and AMD processor families over the last 30 years, that
is the opposite of expectation and instruction-set reference manuals.

The gas manual also has a critical section

* i386-Bugs::                   AT&T Syntax bugs

that affects the coding of subtraction instructions.

I believe that the gcc manual's description of the __asm__() directive
should carry a prominent cross reference to those two sections, and a
clear statement that the default operand order is consistent across
platforms, but may differ from vendor instruction-set manuals.

One respondent suggested:

    You can also write the asm using
    "sqrtsd {%1, %0|%0, %1}"
    and then it will work with both the default AT&T syntax and -masm=intel.

However, the vertical-bar syntax is not documented at all in the
__asm__() directive description in the gcc manual.  That too needs
improvement.

-------------------------------------------------------------------------------
- Nelson H. F. Beebe                    Tel: +1 801 581 5254                  -
- University of Utah                    FAX: +1 801 581 4148                  -
- Department of Mathematics, 110 LCB    Internet e-mail: be...@math.utah.edu  -
- 155 S 1400 E RM 233                       be...@acm.org  be...@computer.org -
- Salt Lake City, UT 84112-0090, USA    URL: http://www.math.utah.edu/~beebe/ -
-------------------------------------------------------------------------------


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43782

Reply via email to