[Bug c/43782] Erroneous expansion of __asm__() directive

2010-04-29 Thread beebe at math dot utah dot edu


--- 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. BeebeTel: +1 801 581 5254  -
- University of UtahFAX: +1 801 581 4148  -
- Department of Mathematics, 110 LCBInternet e-mail: be...@math.utah.edu  -
- 155 S 1400 E RM 233   be...@acm.org  be...@computer.org -
- Salt Lake City, UT 84112-0090, USAURL: http://www.math.utah.edu/~beebe/ -
---


-- 


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



[Bug c/43782] Erroneous expansion of __asm__() directive

2010-04-19 Thread pinskia at gmail dot com


--- Comment #6 from pinskia at gmail dot com  2010-04-19 15:07 ---
Subject: Re:  Erroneous expansion of __asm__() directive



Sent from my iPhone

On Apr 19, 2010, at 7:35 AM, "Nelson H. F. Beebe"  
 wrote:

>>> That is wrong because with AT&T style x86 asm, the src is first  
>>> and the dest is
>>> second.
>
> That cannot be the case: you cannot change the operand order after  
> three
> years of it working one way!

It did not change. Just what happened was gcc is now inlining the  
function. Before it was not inlining the function which allowed the  
inline-asm's two operands to be the same (the argument to the function  
and the return value are done in the same register). Which means you  
were just getting lucky that it worked. In fact AT&T asm has always  
been that way; while intel style asm is the opposite. Gcc outputs AT&T  
by default, though you can change it via an option.


>
> --- 
> --- 
> --- 
> --
> - Nelson H. F. BeebeTel: +1 801 581  
> 5254  -
> - University of UtahFAX: +1 801 581  
> 4148  -
> - Department of Mathematics, 110 LCBInternet e-mail: be...@math.utah.edu 
>   -
> - 155 S 1400 E RM 233   be...@acm.org  be...@computer.org 
>  -
> - Salt Lake City, UT 84112-0090, USAURL: http://www.math.utah.edu/~beebe/ 
>  -
> --- 
> --- 
> --- 
> --


-- 


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



[Bug c/43782] Erroneous expansion of __asm__() directive

2010-04-19 Thread jakub at gcc dot gnu dot org


--- Comment #5 from jakub at gcc dot gnu dot org  2010-04-19 14:56 ---
Nobody changed the order of arguments, in AT&T syntax always the result is the
last, in Intel syntax (not the default on Linux unless -masm=intel) the result
is the first.
Perhaps you were lucky and both the input and output got the same register and
so it didn't matter (say sqrtsd %xmm0, %xmm0).
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.


-- 


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



[Bug c/43782] Erroneous expansion of __asm__() directive

2010-04-19 Thread beebe at math dot utah dot edu


--- Comment #4 from beebe at math dot utah dot edu  2010-04-19 14:35 ---
Subject: Re:  Erroneous expansion of __asm__() directive

>> That is wrong because with AT&T style x86 asm, the src is first and the dest 
>> is
>> second.

That cannot be the case: you cannot change the operand order after three 
years of it working one way!

---
- Nelson H. F. BeebeTel: +1 801 581 5254  -
- University of UtahFAX: +1 801 581 4148  -
- Department of Mathematics, 110 LCBInternet e-mail: be...@math.utah.edu  -
- 155 S 1400 E RM 233   be...@acm.org  be...@computer.org -
- Salt Lake City, UT 84112-0090, USAURL: http://www.math.utah.edu/~beebe/ -
---


-- 


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



[Bug c/43782] Erroneous expansion of __asm__() directive

2010-04-19 Thread beebe at math dot utah dot edu


--- Comment #3 from beebe at math dot utah dot edu  2010-04-19 14:34 ---
Subject: Re:  Erroneous expansion of __asm__() directive

>> Oh I forgot to mention, sqrt will use sqrtsd and will be inlined so you don't
>> need to use inline-asm yourself.

The test code that I sent is an extract of a larger system; its use of
__asm__() is intentional.

---
- Nelson H. F. BeebeTel: +1 801 581 5254  -
- University of UtahFAX: +1 801 581 4148  -
- Department of Mathematics, 110 LCBInternet e-mail: be...@math.utah.edu  -
- 155 S 1400 E RM 233   be...@acm.org  be...@computer.org -
- Salt Lake City, UT 84112-0090, USAURL: http://www.math.utah.edu/~beebe/ -
---


-- 


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



[Bug c/43782] Erroneous expansion of __asm__() directive

2010-04-17 Thread pinskia at gcc dot gnu dot org


--- Comment #2 from pinskia at gcc dot gnu dot org  2010-04-18 06:45 ---
Oh I forgot to mention, sqrt will use sqrtsd and will be inlined so you don't
need to use inline-asm yourself.


-- 


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



[Bug c/43782] Erroneous expansion of __asm__() directive

2010-04-17 Thread pinskia at gcc dot gnu dot org


--- Comment #1 from pinskia at gcc dot gnu dot org  2010-04-18 06:44 ---
You have the wrong inline-asm:
 sqrtsd %0, %1

That is wrong because with AT&T style x86 asm, the src is first and the dest is
second.


-- 

pinskia at gcc dot gnu dot org changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution||INVALID


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