https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103065
Bug ID: 103065 Summary: [meta] atomic operations aren't optimized Product: gcc Version: 12.0 Status: UNCONFIRMED Keywords: meta-bug Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: hjl.tools at gmail dot com CC: crazylht at gmail dot com, wwwhhhyyy333 at gmail dot com Target Milestone: --- Target: i386,x86-64 >From the CPU's point of view, getting a cache line for writing is more expensive than reading. See Appendix A.2 Spinlock in: https://www.intel.com/content/dam/www/public/us/en/documents/white-papers/xeon-lock-scaling-analysis-paper.pdf The full compare and swap will grab the cache line exclusive and causes excessive cache line bouncing.