public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/108539] New: Wrong register usage for -m16 -masm=intel -march=i386 on asm volatile
@ 2023-01-25 13:33 arheik at dnainternet dot net
  2023-01-25 13:37 ` [Bug c++/108539] " arheik at dnainternet dot net
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: arheik at dnainternet dot net @ 2023-01-25 13:33 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108539

            Bug ID: 108539
           Summary: Wrong register usage for -m16 -masm=intel -march=i386
                    on asm volatile
           Product: gcc
           Version: 12.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: arheik at dnainternet dot net
  Target Milestone: ---

Consider the following code (test.cpp):

void test(unsigned char& a, unsigned char& b)
{
        unsigned char _a, _b;
        asm volatile(
                "mov dx, 0\n"
                "mov bx, 0\n"
        : "=dl" (_a), "=dh" (_b)
        :
        : "bx"
        );
        a = _a;
        b = _b;
}

void main(void)
{
        unsigned char a, b;
        test(a, b);
}

Compiled with:
g++ -m16 -masm=intel -march=i386 -ffreestanding -fno-inline -mregparm=3
-fno-dwarf2-cfi-asm -fno-asynchronous-unwind-tables -fno-ident -O2 test.cpp -o
- -S

This generates for test():

_Z4testRhS_:
.LFB0:
        push    esi
.LCFI0:
        push    ebx
.LCFI1:
        mov     ecx, edx
#APP
# 4 "test.cpp" 1
        mov dx, 0
mov bx, 0

# 0 "" 2
#NO_APP
        mov     ebx, esi
        mov     BYTE PTR [eax], bl
        mov     BYTE PTR [ecx], dl
        pop     ebx
.LCFI2:
        pop     esi
.LCFI3:
        ret

In which bl usage is clearly wrong (dh is missing) and ebx/eax/esi usage looks
suspect.

Compling with -mregparm=0 produces for test():

_Z4testRhS_:
.LFB0:
        push    ebx
.LCFI0:
#APP
# 4 "test.cpp" 1
        mov dx, 0
mov bx, 0

# 0 "" 2
#NO_APP
        mov     eax, DWORD PTR 8[esp]
        mov     BYTE PTR [eax], cl
        mov     eax, DWORD PTR 12[esp]
        mov     BYTE PTR [eax], dl
        pop     ebx
.LCFI1:
        ret

Which should use dh instead of cl.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/108539] Wrong register usage for -m16 -masm=intel -march=i386 on asm volatile
  2023-01-25 13:33 [Bug c++/108539] New: Wrong register usage for -m16 -masm=intel -march=i386 on asm volatile arheik at dnainternet dot net
@ 2023-01-25 13:37 ` arheik at dnainternet dot net
  2023-01-25 13:40 ` jakub at gcc dot gnu.org
  2023-01-26 12:50 ` arheik at dnainternet dot net
  2 siblings, 0 replies; 4+ messages in thread
From: arheik at dnainternet dot net @ 2023-01-25 13:37 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108539

--- Comment #1 from arheik at dnainternet dot net ---
Reproduced with these:

Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/11/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu
11.3.0-1ubuntu1~22.04' --with-bugurl=file:///usr/share/doc/gcc-11/README.Bugs
--enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix=/usr
--with-gcc-major-version-only --program-suffix=-11
--program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes
--with-default-libstdcxx-abi=new --enable-gnu-unique-object
--disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib
--enable-libphobos-checking=release --with-target-system-zlib=auto
--enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet
--with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32
--enable-multilib --with-tune=generic
--enable-offload-targets=nvptx-none=/build/gcc-11-xKiWfi/gcc-11-11.3.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-11-xKiWfi/gcc-11-11.3.0/debian/tmp-gcn/usr
--without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu
--host=x86_64-linux-gnu --target=x86_64-linux-gnu
--with-build-config=bootstrap-lto-lean --enable-link-serialization=2
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.3.0 (Ubuntu 11.3.0-1ubuntu1~22.04)

and

Using built-in specs.
COLLECT_GCC=g++-12
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/12/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu
12.1.0-2ubuntu1~22.04' --with-bugurl=file:///usr/share/doc/gcc-12/README.Bugs
--enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=/usr
--with-gcc-major-version-only --program-suffix=-12
--program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug
--enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new
--enable-gnu-unique-object --disable-vtable-verify --enable-plugin
--enable-default-pie --with-system-zlib --enable-libphobos-checking=release
--with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch
--disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64
--with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic
--enable-offload-targets=nvptx-none=/build/gcc-12-sZcx2y/gcc-12-12.1.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-12-sZcx2y/gcc-12-12.1.0/debian/tmp-gcn/usr
--enable-offload-defaulted --without-cuda-driver --enable-checking=release
--build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 12.1.0 (Ubuntu 12.1.0-2ubuntu1~22.04)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/108539] Wrong register usage for -m16 -masm=intel -march=i386 on asm volatile
  2023-01-25 13:33 [Bug c++/108539] New: Wrong register usage for -m16 -masm=intel -march=i386 on asm volatile arheik at dnainternet dot net
  2023-01-25 13:37 ` [Bug c++/108539] " arheik at dnainternet dot net
@ 2023-01-25 13:40 ` jakub at gcc dot gnu.org
  2023-01-26 12:50 ` arheik at dnainternet dot net
  2 siblings, 0 replies; 4+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-01-25 13:40 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108539

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
                 CC|                            |jakub at gcc dot gnu.org
         Resolution|---                         |INVALID

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
That is just misunderstanding of the inline asm syntax, please read the
documentation.
"=dl" doesn't mean that _a output is in %dl register, but either in %edx
register or
in any of the index registers (%eax %ebx %ecx %edx %esi %edi %ebp).
"=dh" means either in %edx register or in nowhere (h isn't a valid constraint).
So, when doing RA _b needs to be put into %edx (the low 8 bits of that aka %dl)
and _a into some index register other than %edx.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/108539] Wrong register usage for -m16 -masm=intel -march=i386 on asm volatile
  2023-01-25 13:33 [Bug c++/108539] New: Wrong register usage for -m16 -masm=intel -march=i386 on asm volatile arheik at dnainternet dot net
  2023-01-25 13:37 ` [Bug c++/108539] " arheik at dnainternet dot net
  2023-01-25 13:40 ` jakub at gcc dot gnu.org
@ 2023-01-26 12:50 ` arheik at dnainternet dot net
  2 siblings, 0 replies; 4+ messages in thread
From: arheik at dnainternet dot net @ 2023-01-26 12:50 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108539

arheik at dnainternet dot net changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |CLOSED

--- Comment #3 from arheik at dnainternet dot net ---
Thanks for the info, wasn't obvious when searching for the syntax, maybe add
warning if using invalid constraint or al, ax, etc. on x86 or note to
documentation for the next guy?

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-01-26 12:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-25 13:33 [Bug c++/108539] New: Wrong register usage for -m16 -masm=intel -march=i386 on asm volatile arheik at dnainternet dot net
2023-01-25 13:37 ` [Bug c++/108539] " arheik at dnainternet dot net
2023-01-25 13:40 ` jakub at gcc dot gnu.org
2023-01-26 12:50 ` arheik at dnainternet dot net

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).