Atomic Floating Point Operations on x86_64
While C does not natively support atomic double operations, it does provide lock-free atomic
For atomic vector operations on x86_64, there is no direct hardware support. However, aligned 128-bit and 256-bit loads and stores are generally guaranteed to be atomic. For non-aligned vector operations, the atomicity guarantees are less clear.
Assembly-Level Support for Double and Vector Operations
x86_64 provides assembly-level support for atomic operations on doubles and vectors:
MSVC 2017 Implementation of Lock-Free atomic
MSVC 2017 implements lock-free atomic
CAS: movq QWORD PTR [dst_addr], rax // 64-bit CAS
The add operation uses:
CAS: lock cmpxchg16b QWORD PTR [dst_addr], rax // 128-bit CAS
Atomic RMW (Read-Modify-Write) Operations
Atomic read-modify-write (RMW) operations, such as fetch_add, require a CAS loop implementation. On x86_64, the CAS instruction supports 16-byte operations (cmpxchg16b).
CAS: lock cmpxchg16b QWORD PTR [dst_addr], rax
While CAS loops provide atomic RMW functionality, they are more expensive than atomic loads and stores.
Additional Notes
The above is the detailed content of How are Atomic Floating-Point and Vector Operations Handled on x86_64 Architectures?. For more information, please follow other related articles on the PHP Chinese website!