From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 0F28F3858D33; Sun, 10 Dec 2023 09:54:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0F28F3858D33 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1702202055; bh=ao8TTnrQYcADF/w//9UGyU+6e7BY/I5o9tCMsT8FjKo=; h=From:To:Subject:Date:In-Reply-To:References:From; b=yFaKLTJkH3s3zMFdDIfXaXsWVxT2zwtNs5LWdKF49c5ElQrUd23xhZXOcgYKy7Rnq NT74aNLJiRb3T+qpS/b67iKT7fXXTFdebAhY6rw8cyuv9Y2fu+ZRcoQPzhu8+2kYaT R0zVomrrFSJF+43ZEDrePWCGI/9crK2uqsPu0eM4= From: "lh_mouse at 126 dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/80878] -mcx16 (enable 128 bit CAS) on x86_64 seems not to work on 7.1.0 Date: Sun, 10 Dec 2023 09:54:10 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 7.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: lh_mouse at 126 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=3D80878 --- Comment #42 from LIU Hao --- (In reply to Yongwei Wu from comment #27) > Anyone can show a valid use case for a non-lock-free version of 128-bit > atomic_compare_exchange? >=20 > I am trying to use it in a data structure intended to be lock-free. I am > surprised to find that the C++ std::atomic::compare_exchange_weak does not > result in lock-free code for a 128-bit struct intended for ABA-free CAS. = As > a result, the GCC-generated code is MUCH slower than the mutex-based vers= ion > in my 8-thread contention test, defeating all its valid purposes. I am > talking about a 10x difference. And the Clang-generated code is more than > 200x faster in the same test. [I think this is off topic though.] I tested CMPXCHG16B with inline assembly on an i7-1165G7 (Dell XPS 13 9305)= and it turned out to be much slower than CMPXCHG, even slower than a pair of ca= lls to `pthread_mutex_lock()` and unlock. Similar results were observed on a desktop i7 11700 and a server Xeon Cascadelake. The performance degeneration might be caused by more =CE=BCops, more locking work for the extra width of operands, and more cache synchronization, which makes some sense if we assu= me the CPU should be optimized mostly for 8-byte access. The conclusion is probably that 16-byte compare-and-swap isn't recommended.=