🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

3 total messages Started by Chris M. Thomasson Fri, 09 Oct 2026 00:13
Re: Consequential RCU
#48
Author: Chris M. Thomasson
Date: Fri, 09 Oct 2026 00:13
66 lines
5103 bytes
On 10/4/2026 2:34 AM, David Brown wrote:
> On 03/10/2026 23:12, Chris M. Thomasson wrote:
>> On 10/3/2026 8:50 AM, boltar@caprica.universe wrote:
>>> On Sat, 3 Oct 2026 14:19:56 +0200
>>> David Brown <david.brown@hesbynett.no> gabbled:
>>>> On 02/10/2026 20:13, Chris M. Thomasson wrote:
>>>>> It should be something akin to, why do I feel the need to code this 
>>>>> is ASM when the C/C++11 should already do it for me. That type of 
>>>>> angle?
>>>>
>>>> Something along these lines should be fine.  There may be some 
>>>> underlying reason why this is implemented as a library call in gcc's 
>>>> C++ standard library, rather than a direct lock-free opcode.  I 
>>>> don't know the details of any of this - maybe there are flaws in 
>>>> some chips, maybe the single op-code actually takes longer than a 
>>>> lock- based implementation.  Maybe it's just that no one has got 
>>>> round to implementing it yet.
>>>
>>> I would guess the reason is consistent behaviour across different 
>>> architectures.
>>>
>>
>> Well, if the library call goes to LOCK CMPXCHG16B for what we need it 
>> for then that would be okay. We need to step into the library call to 
>> find out.
> 
>  From what I have looked at, including the bugzilla link Joseph posted, 
> there seem to be a number of complications involved.  A particular 
> sticking point is that you can't have lock-free C++ standard atomic 
> types without also having atomic load and store operations of the same 
> size.  And while the 16-byte CAS can be used for loads and stores, it 
> can't be used for 16-byte atomic loads on read-only memory.  This means 
> that on older 64-bit x86 processors, 16-byte atomic types cannot be 
> lock-free even if they support 16-byte CAS.

Shit... Well, damn that kind of ruins things. Well, because I do not 
even need atomic loads/stores of the DWCAS (aka, two contiguous words)!

Sigh. I just want C++ to have a always lock-free DWCAS on systems that 
support it. The loads and stores do not even need to be there. But, see, 
that is for my personal use. Sigh. Not good enough for the std?


> 
> It seems that the libatomic implementation does, in some cases, use the 
> CMPXCHG16B instruction rather than a mutex.  
Thank GOD! Then they can make their C++ impl report that this is always 
lock-free?

> The exact code run in the 
> library depends on the cpuid of the processor, as well as compiler 
> flags.  (The default "lowest common denominator" x86-64 instruction set 
> does not support CMPXCHG16B.)
> 
> So the C++ standard library atomics do not lead directly to the use of 
> the lock-free instruction.  But if you have the "-mxc16" compiler flag 
> (or use a -march flag for a cpu family that supports it), then you can 
> use the low-level builtin __sync_bool_compare_and_swap to generate it.
> 
> Better still, in gcc 17 (in development) you can use the "-m128bit- 
> atomic" flag to get full 16-byte atomics on processors for which the GCC 
> folks have assurances from Intel or AMD that the 128-bit SSE2 vector 
> loads and stores are atomic.  You can try this on godbolt.org.
> 
> 
Re: Consequential RCU
#61
Author: David Brown
Date: Fri, 09 Oct 2026 06:33
86 lines
6100 bytes
On 09/10/2026 02:13, Chris M. Thomasson wrote:
> On 10/4/2026 2:34 AM, David Brown wrote:
>> On 03/10/2026 23:12, Chris M. Thomasson wrote:
>>> On 10/3/2026 8:50 AM, boltar@caprica.universe wrote:
>>>> On Sat, 3 Oct 2026 14:19:56 +0200
>>>> David Brown <david.brown@hesbynett.no> gabbled:
>>>>> On 02/10/2026 20:13, Chris M. Thomasson wrote:
>>>>>> It should be something akin to, why do I feel the need to code 
>>>>>> this is ASM when the C/C++11 should already do it for me. That 
>>>>>> type of angle?
>>>>>
>>>>> Something along these lines should be fine.  There may be some 
>>>>> underlying reason why this is implemented as a library call in 
>>>>> gcc's C++ standard library, rather than a direct lock-free opcode.  
>>>>> I don't know the details of any of this - maybe there are flaws in 
>>>>> some chips, maybe the single op-code actually takes longer than a 
>>>>> lock- based implementation.  Maybe it's just that no one has got 
>>>>> round to implementing it yet.
>>>>
>>>> I would guess the reason is consistent behaviour across different 
>>>> architectures.
>>>>
>>>
>>> Well, if the library call goes to LOCK CMPXCHG16B for what we need it 
>>> for then that would be okay. We need to step into the library call to 
>>> find out.
>>
>>  From what I have looked at, including the bugzilla link Joseph 
>> posted, there seem to be a number of complications involved.  A 
>> particular sticking point is that you can't have lock-free C++ 
>> standard atomic types without also having atomic load and store 
>> operations of the same size.  And while the 16-byte CAS can be used 
>> for loads and stores, it can't be used for 16-byte atomic loads on 
>> read-only memory.  This means that on older 64-bit x86 processors, 16- 
>> byte atomic types cannot be lock-free even if they support 16-byte CAS.
> 
> Shit... Well, damn that kind of ruins things. Well, because I do not 
> even need atomic loads/stores of the DWCAS (aka, two contiguous words)!
> 
> Sigh. I just want C++ to have a always lock-free DWCAS on systems that 
> support it. The loads and stores do not even need to be there. But, see, 
> that is for my personal use. Sigh. Not good enough for the std?
> 

Standard libraries are not about individuals.

"Always lock-free" means /always/ lock-free.  If the target does not 
support lock-free versions of all the operations on the atomic type, the 
atomic type is not "always lock-free".  (As far as I can tell, this is a 
limitation of the x86 processors, perhaps also partly a failure of AMD 
and Intel to document guarantees about atomic loads and stores.  It is 
not a failure of the gcc C++ standard library.)

> 
>>
>> It seems that the libatomic implementation does, in some cases, use 
>> the CMPXCHG16B instruction rather than a mutex. 
> Thank GOD! Then they can make their C++ impl report that this is always 
> lock-free?

Or perhaps thank the libatomic authors and the GCC C++ standard library 
implementers for making a correct implementation?

No, their library cannot say that 128-bit types are "always lock-free" 
unless they /are/ always lock-free.  You can always test gcc 17 with the 
"-m128bit-atomic" flag, assuming you have an appropriate target 
processor (or just look at it on godbolt.org).

> 
>> The exact code run in the library depends on the cpuid of the 
>> processor, as well as compiler flags.  (The default "lowest common 
>> denominator" x86-64 instruction set does not support CMPXCHG16B.)
>>
>> So the C++ standard library atomics do not lead directly to the use of 
>> the lock-free instruction.  But if you have the "-mxc16" compiler flag 
>> (or use a -march flag for a cpu family that supports it), then you can 
>> use the low-level builtin __sync_bool_compare_and_swap to generate it.
>>
>> Better still, in gcc 17 (in development) you can use the "-m128bit- 
>> atomic" flag to get full 16-byte atomics on processors for which the 
>> GCC folks have assurances from Intel or AMD that the 128-bit SSE2 
>> vector loads and stores are atomic.  You can try this on godbolt.org.
>>
>>
> 
Re: Consequential RCU
#306
Author: Chris M. Thomasson
Date: Mon, 12 Oct 2026 19:58
101 lines
6998 bytes
On 10/8/2026 11:33 PM, David Brown wrote:
> On 09/10/2026 02:13, Chris M. Thomasson wrote:
>> On 10/4/2026 2:34 AM, David Brown wrote:
>>> On 03/10/2026 23:12, Chris M. Thomasson wrote:
>>>> On 10/3/2026 8:50 AM, boltar@caprica.universe wrote:
>>>>> On Sat, 3 Oct 2026 14:19:56 +0200
>>>>> David Brown <david.brown@hesbynett.no> gabbled:
>>>>>> On 02/10/2026 20:13, Chris M. Thomasson wrote:
>>>>>>> It should be something akin to, why do I feel the need to code 
>>>>>>> this is ASM when the C/C++11 should already do it for me. That 
>>>>>>> type of angle?
>>>>>>
>>>>>> Something along these lines should be fine.  There may be some 
>>>>>> underlying reason why this is implemented as a library call in 
>>>>>> gcc's C++ standard library, rather than a direct lock-free opcode. 
>>>>>> I don't know the details of any of this - maybe there are flaws in 
>>>>>> some chips, maybe the single op-code actually takes longer than a 
>>>>>> lock- based implementation.  Maybe it's just that no one has got 
>>>>>> round to implementing it yet.
>>>>>
>>>>> I would guess the reason is consistent behaviour across different 
>>>>> architectures.
>>>>>
>>>>
>>>> Well, if the library call goes to LOCK CMPXCHG16B for what we need 
>>>> it for then that would be okay. We need to step into the library 
>>>> call to find out.
>>>
>>>  From what I have looked at, including the bugzilla link Joseph 
>>> posted, there seem to be a number of complications involved.  A 
>>> particular sticking point is that you can't have lock-free C++ 
>>> standard atomic types without also having atomic load and store 
>>> operations of the same size.  And while the 16-byte CAS can be used 
>>> for loads and stores, it can't be used for 16-byte atomic loads on 
>>> read-only memory.  This means that on older 64-bit x86 processors, 
>>> 16- byte atomic types cannot be lock-free even if they support 16- 
>>> byte CAS.
>>
>> Shit... Well, damn that kind of ruins things. Well, because I do not 
>> even need atomic loads/stores of the DWCAS (aka, two contiguous words)!
>>
>> Sigh. I just want C++ to have a always lock-free DWCAS on systems that 
>> support it. The loads and stores do not even need to be there. But, 
>> see, that is for my personal use. Sigh. Not good enough for the std?
>>
> 
> Standard libraries are not about individuals.
> 
> "Always lock-free" means /always/ lock-free.  If the target does not 
> support lock-free versions of all the operations on the atomic type, the 
> atomic type is not "always lock-free".  (As far as I can tell, this is a 
> limitation of the x86 processors, perhaps also partly a failure of AMD 
> and Intel to document guarantees about atomic loads and stores.  It is 
> not a failure of the gcc C++ standard library.)

I understand. I am only interested in if a fallback to a library, or 
whatever, uses the LOCK CMPXCHG16B on x64. Or any other arch if they 
support a native double-width CAS (DWCAS) instruction. LL/SC aside for a 
moment... It might be interesting if I can infer if say DWCAS was always 
lock-free but DW atomic loads/stores are not. That is fine with me.


>>> It seems that the libatomic implementation does, in some cases, use 
>>> the CMPXCHG16B instruction rather than a mutex. 
>> Thank GOD! Then they can make their C++ impl report that this is 
>> always lock-free?
> 
> Or perhaps thank the libatomic authors and the GCC C++ standard library 
> implementers for making a correct implementation?

Ponder on those implementers as akin to a "god"... lol. ;^)

Way before C++11, implementing these things in per-arch ASM was my gold 
std. LTO aside for a moment... Uggg. I was scared/paranoid of a compiler 
trying to do some funny business with my results (.o) files, from GAS/MASM.


> No, their library cannot say that 128-bit types are "always lock-free" 
> unless they /are/ always lock-free.  You can always test gcc 17 with the 
> "-m128bit-atomic" flag, assuming you have an appropriate target 
> processor (or just look at it on godbolt.org).

Indeed.


>>> The exact code run in the library depends on the cpuid of the 
>>> processor, as well as compiler flags.  (The default "lowest common 
>>> denominator" x86-64 instruction set does not support CMPXCHG16B.)
>>>
>>> So the C++ standard library atomics do not lead directly to the use 
>>> of the lock-free instruction.  But if you have the "-mxc16" compiler 
>>> flag (or use a -march flag for a cpu family that supports it), then 
>>> you can use the low-level builtin __sync_bool_compare_and_swap to 
>>> generate it.
>>>
>>> Better still, in gcc 17 (in development) you can use the "-m128bit- 
>>> atomic" flag to get full 16-byte atomics on processors for which the 
>>> GCC folks have assurances from Intel or AMD that the 128-bit SSE2 
>>> vector loads and stores are atomic.  You can try this on godbolt.org.

Shit happens. This is a rather niche area anyway.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads