From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16337 invoked by alias); 31 May 2011 19:25:24 -0000 Received: (qmail 16323 invoked by uid 22791); 31 May 2011 19:25:23 -0000 X-SWARE-Spam-Status: No, hits=-2.7 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 31 May 2011 19:25:08 +0000 From: "desrt at desrt dot ca" To: gcc-bugs@gcc.gnu.org Subject: [Bug other/49244] New: no intrinsics to emit 'lock bts' and 'lock btc' X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: other X-Bugzilla-Keywords: X-Bugzilla-Severity: enhancement X-Bugzilla-Who: desrt at desrt dot ca X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Date: Tue, 31 May 2011 19:38:00 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2011-05/txt/msg03122.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49244 Summary: no intrinsics to emit 'lock bts' and 'lock btc' Product: gcc Version: unknown Status: UNCONFIRMED Severity: enhancement Priority: P3 Component: other AssignedTo: unassigned@gcc.gnu.org ReportedBy: desrt@desrt.ca I want to be able to code this function: bool set_and_test (int *a, int bit) { uint mask = (1u << bit); return (__sync_fetch_and_or (a, mask) & mask) != 0; } and have GCC not emit a loop on amd64 and x86. GCC presently emits a loop for __sync_fetch_and_or() in this case. That's because asm "lock or" discards the previous value, so it can only be used in cases that the result is ignored. Since we do a comparison with the value, GCC has to do the loop. This special case (set and test a single bit) corresponds quite directly to the 'lock bts' assembly instruction, though. GCC could emit that instead. It would be nice if GCC could detect (by magic?) that I am only interested in this single bit or (probably much easier) expose an intrinsic that lets me access this functionality on platforms that it exists and falls back to using __sync_fetch_and_or() otherwise.