On Fri, Dec 17, 2021 at 12:00:47PM -0800, Jim Wilson via Gcc-help wrote: > RISC-V is the only major target that does not support subword atomics. > Some ports have hardware support for subword atomics. Some ports like PPC > lack hardware support for subword atomics but have gcc patterns to > implement them using full word atomic instructions. That was true until ISA 2.06 (POWER7, eleven years ago). > Unfortunately, there are many package maintainers that refuse to add > -latomic to their packages because x86/arm doesn't need it. So we modified > the compiler to add the necessary -latomic option. However, in the FSF > tree, we only add -latomic when -pthread is used, because pthread > definitely needs subword atomic support. The libatomic implementation requires pthread, I think? > Though convincing people to use > the -pthread option is another issue, some package maintainers refuse to > use it even though the gcc docs say it is required. It looks like you have > a modified source tree that is adding the -latomic always which is one way > to fix that problem. > > Adding gcc patterns to expand subword atomics into sequences of code using > full word atomic instructions would be a better fix, but it is a > complicated one. This might well generate worse code on average. That is very target- dependent of course. > There are issues with the libstdc++ ABI changing, and > issues of how exactly we test the patch, and issues with writing it and > proving it is correct as the RISC-V memory consistency spec is > complicated. This has been a known problem for over 4 years, and no one > has volunteered to fix it yet. Good luck with it! It is pretty hard work, and thankless. For one thing it isn't very visible. For another a much better performance gain will result from implementing it in hardware, and that will catch up, if it takes another >4y to implement in software ;-) Segher