public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: David Brown <david.brown@hesbynett.no>
To: LIU Hao <lh_mouse@126.com>, gcc@gcc.gnu.org
Subject: Re: Please, really, make `-masm=intel` the default for x86
Date: Fri, 25 Nov 2022 14:31:55 +0100	[thread overview]
Message-ID: <72aad43c-cd02-24a9-9bdf-fd75fe76ce5a@hesbynett.no> (raw)
In-Reply-To: <4b31677c-255c-2796-67c4-2d67f0c9fa60@126.com>

On 25/11/2022 07:39, LIU Hao via Gcc wrote:
> I am a Windows developer and I have been writing x86 and amd64 assembly 
> for more than ten years. One annoying thing about GCC is that, for x86 
> if I need to write I piece of inline assembly then I have to do it 
> twice: one in AT&T syntax and one in Intel syntax.
> 
> 
> The AT&T syntax is an awkward foreign dialect, designed originally for 
> PDP-11 and spoken by bumpkins that knew little about x86 or ARM. No 
> official Intel or AMD documentation ever adopts it. The syntax is 
> terrible. Consider:
> 
>     movl $1, %eax  ; k; moves $1 into EAX
>                    ; but in high-level languages we expect '%eax = $1',
>                    ; so it goes awkwardly backwards.
> 
> If this looks fine to you, please re-consider:
> 
>    cmpl $1, %eax
>    jg .L1          ; does this mean 'jump if $1 is greater than %eax'
>                    ; or something stupidly reversed?
> 
> If CMP still looks fine to you, please consider how to write VFMADD231PD 
> in AT&T syntax, really.
> 
> 
> I have been tired of such inconsistency. For God's sake, please 
> deprecate it.
> 
> 

You can have all the personal preferences or prejudices you want, but 
that won't change the fact that AT&T syntax was the standard x86 
assembly from long before Intel thought of making their own syntax, and 
it is here to stay.  No one is going to deprecate it, remove it, or 
change any defaults.


#include <stdio.h>

int main(void)
{
     int temp=0;

     asm
     (   ".intel_syntax noprefix"
         "mov %0, 1"
         ".att_syntax"
         : "=r"(temp)
         :                   /* no input*/
     );
     printf("temp=%d\n", temp);
}


A use feature that could be added to gcc, perhaps, would be a way to let 
the user specify the assembler dialect as part of the "asm" statement:

	asm __attribute__((masm = "intel")) ( ... )

The idea with this is that it would issue the requested ".intel_syntax 
noprefix" or ".att_syntax" at the start of the assembly, and the 
appropriate directive to return to normal syntax at the end - adjusting 
according to the "-masm" setting for the compilation.  This would, I 
think, let people write the assembly once in the syntax they choose, and 
have it work smoothly regardless of which syntax is chosen for compilation.


  parent reply	other threads:[~2022-11-25 13:32 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-25  6:39 LIU Hao
2022-11-25  7:37 ` Hi-Angel
2022-11-25  7:56   ` LIU Hao
2022-11-25  8:50 ` Marc Glisse
2022-11-25  9:11   ` LIU Hao
2022-11-25  9:30     ` Jonathan Wakely
2022-11-25  9:56     ` Iain Sandoe
2022-11-25  9:32 ` Jakub Jelinek
2022-11-25 12:01   ` LIU Hao
2022-11-25 13:00     ` Richard Biener
2022-11-25 13:31 ` David Brown [this message]
2022-11-25  7:48 Dave Blanchard
2022-11-25  8:03 ` LIU Hao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=72aad43c-cd02-24a9-9bdf-fd75fe76ce5a@hesbynett.no \
    --to=david.brown@hesbynett.no \
    --cc=gcc@gcc.gnu.org \
    --cc=lh_mouse@126.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).