Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 28 Jun 2022 13:43:58 +0000
From:      bugzilla-noreply@freebsd.org
To:        bugs@FreeBSD.org
Subject:   [Bug 264941] gcc9 and optimize options and inline-assembler and pointer assignment
Message-ID:  <bug-264941-227@https.bugs.freebsd.org/bugzilla/>

next in thread | raw e-mail | index | archive | help
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D264941

            Bug ID: 264941
           Summary: gcc9 and optimize options and inline-assembler and
                    pointer assignment
           Product: Base System
           Version: 11.4-RELEASE
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Some People
          Priority: ---
         Component: gnu
          Assignee: bugs@FreeBSD.org
          Reporter: var@schellong.biz

C-Source with extended inline-assembler:
---------------------------------------------------------------------------=
--
STaTIc long double ctop87l(long double x, long double y,
                           long double *rad, long double *deg)
{
   long double r, ld;
   if (!rad)  rad=3D &ld;
   if (!deg)  deg=3D &ld;
   __asm__ ("\n\t"
            "fldt  %[y] \n\t"
            "fldt  %[x] \n\t"
            "fld  %%st(1) \n\t"
            "fmul  %%st(0), %%st(0) \n\t"
            "fld  %%st(1) \n\t"
            "fmul  %%st(0), %%st(0) \n\t"
            "faddp \n\t"
            "fsqrt \n\t"
            "fstpt  %[r] \n\t"
            "fpatan \n\t"
            "fldz \n\t"
            "fcomip  %%st(1), %%st(0) \n\t"
            "jbe  CTPp \n\t"
            "fldpi \n\t"
            "fldpi \n\t"
            "faddp \n\t"
            "faddp \n\t"
            "CTPp:\n\t"
            "fld  %%st(0) \n\t"
            "fstpt  %[rad] \n\t"
            "fldt  %[rtd] \n\t"
            "fmulp \n\t"
            "fstpt  %[deg] \n\t"
            "fwait \n\t"
            : [r]"=3Dm"(r), [rad]"=3Dm"(*rad), [deg]"=3Dm"(*deg)
            : [x]"m"(x), [y]"m"(y), [rtd]"m"(radtodeg)
            :
           );
   return r;
}
---------------------------------------------------------------------------=
--


Output of gcc9 (with -O1):  Gcc -S asm87c.c
---------------------------------------------------------------------------=
--
        .globl  ctop87l
        .type   ctop87l, @function
ctop87l:
.LFB18:
        .cfi_startproc
# asm87c.c:428:    if (!rad)  rad=3D &ld;
        testq   %rdi, %rdi      # rad
        je      .L28    #,
# asm87c.c:429:    if (!deg)  deg=3D &ld;
        testq   %rsi, %rsi      # deg
        je      .L30    #,
# asm87c.c:430:    __asm__ ("\n\t"
#APP
# 430 "asm87c.c" 1

        fldt  24(%rsp)  # y
        fldt  8(%rsp)   # x
        fld  %st(1)=20
        fmul  %st(0), %st(0)=20
        fld  %st(1)=20
        fmul  %st(0), %st(0)=20
        faddp=20
        fsqrt=20
        fstpt  -24(%rsp)        # r
        fpatan=20
        fldz=20
        fcomip  %st(1), %st(0)=20
        jbe  CTPp=20
        fldpi=20
        fldpi=20
        faddp=20
        faddp=20
        CTPp:
        fld  %st(0)=20
        fstpt  (%rdi)   # *rad_3(D)
        fldt  radtodeg(%rip)    # radtodeg
        fmulp=20
        fstpt  (%rsi)   # *deg_4(D)
        fwait=20

# 0 "" 2
# asm87c.c:459:    return r;
#NO_APP
        fldt    -24(%rsp)       # r
        ret=20=20=20=20=20
        .p2align 2
.L28:
# asm87c.c:428:    if (!rad)  rad=3D &ld;
        leaq    -40(%rsp), %rdi #, rad
# asm87c.c:429:    if (!deg)  deg=3D &ld;
        testq   %rsi, %rsi      # deg
        je      .L32    #,
.L29:
# asm87c.c:430:    __asm__ ("\n\t"
#APP
# 430 "asm87c.c" 1

        fldt  24(%rsp)  # y
        fldt  8(%rsp)   # x
        fld  %st(1)=20
        fmul  %st(0), %st(0)=20
        fld  %st(1)=20
        fmul  %st(0), %st(0)=20
        faddp=20
        fsqrt=20
        fstpt  -24(%rsp)        # r
        fpatan=20
        fldz=20
        fcomip  %st(1), %st(0)=20
        jbe  CTPp=20
        fldpi=20
        fldpi=20
        faddp=20
        faddp=20
        CTPp:
        fld  %st(0)=20
        fstpt  (%rdi)   # *rad_16
        fldt  radtodeg(%rip)    # radtodeg
        fmulp=20
        fstpt  (%rsi)   # *deg_2
        fwait=20

# 0 "" 2
# asm87c.c:459:    return r;
#NO_APP
        fldt    -24(%rsp)       # r
# asm87c.c:460: }
        ret=20=20=20=20=20
        .p2align 2
.L32:
# asm87c.c:429:    if (!deg)  deg=3D &ld;
        movq    %rdi, %rsi      # rad, deg
        jmp     .L29    #
        .p2align 2
.L30:
        leaq    -40(%rsp), %rsi #, deg
        jmp     .L29    #
        .cfi_endproc
.LFE18:
        .size   ctop87l, .-ctop87l
---------------------------------------------------------------------------=
--

The code  '__asm__ (...);'  is doubled!
Therefore 'CTPp:' is doubled, and this is an error.
The reason for this doubling are each of the two lines with '=3D &ld' above
__asm__.
Without these two lines there is no doubling.
IMO a curiosity.


A doubling too, but without jump-label (no error):
---------------------------------------------------------------------------=
--
STaTIc long double ptoc87l(int dor, long double degrad, long double r, long
double *x)
{
   if (dor!=3D'r' && dor!=3D'R')  degrad*=3D degtorad;
   long double y, ld;
   if (!x)  x=3D &ld;
   __asm__ ("\n\t"
   // .......
---------------------------------------------------------------------------=
--


With options -O0 and -Os there is no doubling.
Clang doubles not.
I mean  __asm__(...);  should never be doubled --> assembler.

--=20
You are receiving this mail because:
You are the assignee for the bug.=



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-264941-227>