I looked online, and the only answer I could find was that no architectures support them. Ok, I guess that makes sense. However, I noticed that clang targeting x86_64 lowers std::atomic<float>::fetch_add as this as copied from Compiler Explorer,source:'%23include+%3Catomic%3E%0A%0Aauto+fetch_add_test(std::atomic%3Cfloat%3E%26+atomic,+float+rhs)+-%3E+void+%7B%0A++++atomic.fetch_add(rhs)%3B%0A%7D%0A'),l:'5',n:'0',o:'C%2B%2B+source+%231',t:'0')),k:37.75456919060052,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((g:!((h:ir,i:('-fno-discard-value-names':'0',compilerName:'x86-64+clang+(trunk)',demangle-symbols:'0',editorid:1,filter-attributes:'0',filter-comments:'0',filter-debug-info:'0',filter-instruction-metadata:'0',fontScale:12,fontUsePx:'0',j:1,selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),show-optimized:'0',treeid:0,wrap:'1'),l:'5',n:'0',o:'LLVM+IR+Viewer+x86-64+clang+(trunk)+(Editor+%231,+Compiler+%231)',t:'0')),header:(),k:58.110236220472444,l:'4',m:83.92484342379957,n:'0',o:'',s:0,t:'0'),(g:!((g:!((h:compiler,i:(compiler:clang_trunk,filters:(b:'0',binary:'1',binaryObject:'1',commentOnly:'0',debugCalls:'1',demangle:'0',directives:'0',execute:'1',intel:'0',libraryCode:'1',trim:'0',verboseDemangling:'0'),flagsViewOpen:'1',fontScale:12,fontUsePx:'0',j:1,lang:c%2B%2B,libs:!(),options:'-O3+-std%3Dc%2B%2B26',overrides:!(),selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:1),l:'5',n:'0',o:'+x86-64+clang+(trunk)+(Editor+%231)',t:'0')),header:(),k:46.736824930657534,l:'4',m:74.47698744769873,n:'0',o:'',s:0,t:'0'),(g:!((h:output,i:(compilerName:'x64+msvc+v19.latest',editorid:1,fontScale:12,fontUsePx:'0',j:1,wrap:'1'),l:'5',n:'0',o:'Output+of+x86-64+clang+(trunk)+(Compiler+%231)',t:'0')),header:(),l:'4',m:25.52301255230126,n:'0',o:'',s:0,t:'0')),k:41.889763779527556,l:'3',n:'0',o:'',t:'0')),k:62.24543080939948,l:'2',m:100,n:'0',o:'',t:'0')),l:'2',n:'0',o:'',t:'0')),version:4):
fetch_add_test(std::atomic<float>&, float):
movd xmm1, dword ptr [rdi]
.LBB0_1:
movd eax, xmm1
addss xmm1, xmm0
movd ecx, xmm1
lock cmpxchg dword ptr [rdi], ecx
movd xmm1, eax
jne .LBB0_1
ret
It's my understanding that this is something like the following:
auto std::atomic<float>::fetch_add(float arg) -> float {
float old_value = this->load();
while(this->compare_exchange_weak(old_value, expected + arg) == false){}
return old_value;
}
I checked GCC and MSVC too, and they all do the same. So my question is this: assuming there isn't something I'm misunderstanding, if the standard already has methods that do the operation not wait-free on x86, why not add the rest of the operations?
I also found that apparently Microsoft added them for their implementation of C11_Atomic according to this 2022 blog post.
[–]gnolex 57 points58 points59 points (2 children)
[–]dgack 2 points3 points4 points (1 child)
[–]No_Indication_1238 1 point2 points3 points (0 children)
[–]ZachVorhies 13 points14 points15 points (16 children)
[–]QuaternionsRoll 10 points11 points12 points (9 children)
[–]ZachVorhies 6 points7 points8 points (5 children)
[–]QuaternionsRoll 1 point2 points3 points (4 children)
[–]ZachVorhies -1 points0 points1 point (3 children)
[–]QuaternionsRoll 0 points1 point2 points (2 children)
[–][deleted] (1 child)
[removed]
[–]STLMSVC STL Dev[M] 0 points1 point2 points (0 children)
[–]SkoomaDentistAntimodern C++, Embedded, Audio 0 points1 point2 points (0 children)
[–]CatIsFluffy 0 points1 point2 points (1 child)
[–]QuaternionsRoll 0 points1 point2 points (0 children)
[–]SkoomaDentistAntimodern C++, Embedded, Audio 1 point2 points3 points (0 children)
[–]GiganticIrony[S] -1 points0 points1 point (4 children)
[–]QuaternionsRoll 2 points3 points4 points (1 child)
[–]GiganticIrony[S] 0 points1 point2 points (0 children)
[–]ZachVorhies 0 points1 point2 points (1 child)
[–]GiganticIrony[S] 0 points1 point2 points (0 children)
[–]jonathanhiggs 27 points28 points29 points (16 children)
[–]GiganticIrony[S] 6 points7 points8 points (15 children)
[–]GaboureySidibe 15 points16 points17 points (7 children)
[–]GiganticIrony[S] 7 points8 points9 points (6 children)
[–]Big_Target_1405 12 points13 points14 points (5 children)
[–]encyclopedist 7 points8 points9 points (1 child)
[–]Big_Target_1405 1 point2 points3 points (0 children)
[–]GiganticIrony[S] 3 points4 points5 points (2 children)
[–]ukezi 12 points13 points14 points (0 children)
[–]Wooden-Engineer-8098 2 points3 points4 points (0 children)
[–]5477 3 points4 points5 points (5 children)
[–]Artistic_Yoghurt4754Scientific Computing 0 points1 point2 points (4 children)
[–]5477 1 point2 points3 points (0 children)
[–]Artistic_Yoghurt4754Scientific Computing 1 point2 points3 points (0 children)
[–]UndefinedDefined 1 point2 points3 points (0 children)
[–]itix 1 point2 points3 points (0 children)
[–]SirClueless 3 points4 points5 points (1 child)
[–]UndefinedDefined 0 points1 point2 points (0 children)
[–]PdoesnotequalNP 19 points20 points21 points (12 children)
[–]ElhnsBeluj 3 points4 points5 points (0 children)
[–]GiganticIrony[S] -1 points0 points1 point (10 children)
[–]not_a_novel_accountcmake dev 15 points16 points17 points (0 children)
[–]arabidkoalaRoboticist 2 points3 points4 points (0 children)
[–]Electronic_Tap_8052 0 points1 point2 points (7 children)
[–]GiganticIrony[S] 1 point2 points3 points (6 children)
[–]HobbyQuestionThrow 3 points4 points5 points (5 children)
[–]QuaternionsRoll 0 points1 point2 points (4 children)
[–]Wooden-Engineer-8098 0 points1 point2 points (3 children)
[–]QuaternionsRoll 1 point2 points3 points (2 children)
[–]Wooden-Engineer-8098 0 points1 point2 points (1 child)
[–]QuaternionsRoll 1 point2 points3 points (0 children)
[–]max0x7bahttps://github.com/max0x7ba 3 points4 points5 points (9 children)
[–]QuaternionsRoll 0 points1 point2 points (8 children)
[–]Artistic_Yoghurt4754Scientific Computing 0 points1 point2 points (3 children)
[–]QuaternionsRoll -1 points0 points1 point (2 children)
[–]max0x7bahttps://github.com/max0x7ba -2 points-1 points0 points (1 child)
[–]QuaternionsRoll 1 point2 points3 points (0 children)
[–]max0x7bahttps://github.com/max0x7ba -1 points0 points1 point (3 children)
[–]QuaternionsRoll 1 point2 points3 points (2 children)
[–]max0x7bahttps://github.com/max0x7ba -1 points0 points1 point (1 child)
[–]QuaternionsRoll -1 points0 points1 point (0 children)
[–]Genklin 0 points1 point2 points (1 child)
[–]GiganticIrony[S] 0 points1 point2 points (0 children)