From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 5177F3858C1F; Tue, 1 Nov 2022 08:41:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5177F3858C1F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667292091; bh=F+E32K15Mey5Dtw3uJPU2EOQv3CVDvscxZPl+i1hR8Q=; h=From:To:Subject:Date:In-Reply-To:References:From; b=sm0geCweHgswd1UggBw/Ar26x7kW7FwlPLZT48M+uKn2LtHIJGRh/qRr5xBZQtXAW 73wsUtPzLLuHrL8cPvlgfIQRt5f15TLAJPd/BH8QcHVDPlkahI1hL0KoeTDTHDzUx5 Q76UOofnHoZMCOepBLd1iQR3+xmISpcpDZ/6oQh8= From: "marko.makela at mariadb dot com" 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: Tue, 01 Nov 2022 08:41:23 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: enhancement X-Bugzilla-Who: marko.makela at mariadb dot com X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102566 --- Comment #33 from Marko M=C3=A4kel=C3=A4 --- When it comes to toggling the most significant bit, std::atomic::fetch_xor() could be translated to LOCK XADD which would be able to return all bits: #include uint32_t toggle_by_add(std::atomic& a) { return a.fetch_add(1U<<31); } uint32_t toggle_by_xor(std::atomic& a) { return a.fetch_xor(1U<<31); }=