Correcting myself, sorry.

On 11/27/21 11:44 AM, Mario Bezzi wrote:
the code between #APP and #NO_APP is the same for the two runs.

The code between #APP and #NO_APP is *not* the same, still the call is there. I.e. gcc attempted an optimization of the passed asm code.

Thank you,
mario

On 11/27/21 11:44 AM, Mario Bezzi wrote:
Tested under linux x86_64. _asm call sample blindly taken from https://www.ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html

gcc --version
gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0


int asmFunct() {

 int from, to;

 asm (" movl %0,%%eax; \n"
      " movl %1,%%ecx; \n"
      " call _foo      \n"
      : /* no outputs */
      : "g" (from), "g" (to)
      : "eax", "ecx");

 return 0;
}

gcc -c -S asmFunct.c produces the following code:

    .cfi_startproc
    endbr64
    pushq    %rbp
    .cfi_def_cfa_offset 16
    .cfi_offset 6, -16
    movq    %rsp, %rbp
    .cfi_def_cfa_register 6
#APP
# 35 "asmFunct.c" 1
     movl -8(%rbp),%eax;
     movl -4(%rbp),%ecx;
     call _foo

# 0 "" 2
#NO_APP
    movl    $0, %eax
    popq    %rbp
    .cfi_def_cfa 7, 8
    ret
    .cfi_endproc



gcc -O3 -c -S asmFunct.c produces the following code:

    .cfi_startproc
    endbr64
#APP
# 35 "asmFunct.c" 1
     movl $0,%eax;
     movl $0,%ecx;
     call _foo

# 0 "" 2
#NO_APP
    xorl    %eax, %eax
    ret
    .cfi_endproc


From the little I understand, the _asm statement is not optimized away by gcc. I.e. the code between #APP and #NO_APP is the same for the two runs.

I hope this helps.

On 11/27/21 1:45 AM, Peter Relson wrote:
Dave Rivers wrote about the "clobber list".
I'd say that IBM's C does have a "clobber list" for __ASM.

My question would be whether GCC would have the same result for the
example that was posed, where the function return was unconditional and
there were no outputs identified in the "clobber list" so that, at least
as far as the "clobber list" is concerned, the __asm had no identified
effect.

What would GCC ask their users to identify as "clobbered" if they (for
example) just wanted the __ASM to issue linkage instructions to a routine
that did some sort of "print"? It could indicate that regs 0,1,14,15 are
clobbered (which this did), but that would not be relevant to the function
return.

And does GCC, as IBM C, feel free to remove the __ASM (or whatever the GCC
analog is) in the specific case being discussed? If not, why not?

Peter Relson
z/OS Core Technology Design

Reply via email to