public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "hjl.tools at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/102566] [i386] GCC should emit LOCK BTS for simple bit-test-and-set operations with std::atomic
Date: Wed, 18 Jan 2023 18:49:40 +0000	[thread overview]
Message-ID: <bug-102566-4-LW24tZdFbE@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-102566-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #36 from H.J. Lu <hjl.tools at gmail dot com> ---
(1 << (x)) works, but (((unsigned int) 1) << (x)) doesn't work:

[hjl@gnu-skx-1 gcc]$ cat bar.c
void bar (void);

#define MASK1(x) (1 << (x))

void
f1 (unsigned int *a, unsigned int bit)
{
  if ((__atomic_fetch_xor (a, MASK1 (bit), __ATOMIC_RELAXED) & MASK1 (bit)))
    bar ();
}

#define MASK2(x) (((unsigned int) 1) << (x))

void
f2 (unsigned int *a, unsigned int bit)
{
  if ((__atomic_fetch_xor (a, MASK2 (bit), __ATOMIC_RELAXED) & MASK2 (bit)))
    bar ();
}
[hjl@gnu-skx-1 gcc]$ ./xgcc -B./ -S -O2 bar.c
[hjl@gnu-skx-1 gcc]$ cat bar.s
        .file   "bar.c"
        .text
        .p2align 4
        .globl  f1
        .type   f1, @function
f1:
.LFB0:
        .cfi_startproc
        lock btcl       %esi, (%rdi)
        jc      .L4
        ret
        .p2align 4,,10
        .p2align 3
.L4:
        jmp     bar
        .cfi_endproc
.LFE0:
        .size   f1, .-f1
        .p2align 4
        .globl  f2
        .type   f2, @function
f2:
.LFB1:
        .cfi_startproc
        movl    %esi, %ecx
        movl    $1, %edx
        movl    (%rdi), %eax
        sall    %cl, %edx
.L6:
        movl    %eax, %r8d
        movl    %eax, %esi
        xorl    %edx, %r8d
        lock cmpxchgl   %r8d, (%rdi)
        jne     .L6
        btl     %ecx, %esi
        jc      .L10
        ret
        .p2align 4,,10
        .p2align 3
.L10:
        jmp     bar
        .cfi_endproc
.LFE1:
        .size   f2, .-f2
        .ident  "GCC: (GNU) 13.0.1 20230118 (experimental)"
        .section        .note.GNU-stack,"",@progbits
[hjl@gnu-skx-1 gcc]$

  parent reply	other threads:[~2023-01-18 18:49 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-02 16:08 [Bug target/102566] New: " thiago at kde dot org
2021-10-02 20:30 ` [Bug target/102566] " pinskia at gcc dot gnu.org
2021-10-03 12:56 ` hjl.tools at gmail dot com
2021-10-03 13:06 ` hjl.tools at gmail dot com
2021-10-03 13:19 ` [Bug tree-optimization/102566] " hjl.tools at gmail dot com
2021-10-03 15:10 ` hjl.tools at gmail dot com
2021-10-03 16:45 ` [Bug middle-end/102566] " hjl.tools at gmail dot com
2021-10-03 22:36 ` hjl.tools at gmail dot com
2021-10-04 15:58 ` thiago at kde dot org
2021-10-04 16:10 ` thiago at kde dot org
2021-10-04 16:13 ` thiago at kde dot org
2021-10-04 21:46 ` hjl.tools at gmail dot com
2021-10-04 23:25 ` thiago at kde dot org
2021-10-04 23:26 ` thiago at kde dot org
2021-10-05  4:40 ` hjl.tools at gmail dot com
2021-10-05 15:23 ` hjl.tools at gmail dot com
2021-10-05 15:57 ` thiago at kde dot org
2021-10-05 16:02 ` pinskia at gcc dot gnu.org
2021-10-05 19:26 ` hjl.tools at gmail dot com
2021-10-05 19:30 ` hjl.tools at gmail dot com
2021-10-05 19:36 ` thiago at kde dot org
2021-10-06  8:00 ` jakub at gcc dot gnu.org
2021-10-06 15:40 ` thiago at kde dot org
2021-10-06 15:47 ` hjl.tools at gmail dot com
2021-10-06 15:54 ` thiago at kde dot org
2021-10-06 16:05 ` hjl.tools at gmail dot com
2021-10-07 15:18 ` thiago at kde dot org
2021-10-07 15:19 ` hjl.tools at gmail dot com
2021-10-07 15:35 ` thiago at kde dot org
2021-10-10 13:51 ` hjl.tools at gmail dot com
2021-10-22  3:31 ` crazylht at gmail dot com
2021-11-04 21:24 ` thiago at kde dot org
2021-11-10  9:17 ` cvs-commit at gcc dot gnu.org
2022-10-29 10:53 ` marko.makela at mariadb dot com
2022-10-31  2:42 ` crazylht at gmail dot com
2022-11-01  8:41 ` marko.makela at mariadb dot com
2022-11-01 16:46 ` hjl.tools at gmail dot com
2022-11-07 19:20 ` cvs-commit at gcc dot gnu.org
2023-01-18 18:49 ` hjl.tools at gmail dot com [this message]
2023-01-18 22:30 ` hjl.tools at gmail dot com

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=bug-102566-4-LW24tZdFbE@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /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).