Re: Test atomic operations on SPARC 32-bit
2017-12-08 22:32 GMT+01:00 Petr Vorel <firstname.lastname@example.org>:
> I'm trying to implement __sync_add_and_fetch(), as according to buildroot investigation
>  it's not available on SPARC 32-bit
As mentioned by someone else, v7 and v8 do not have them as hardware
instruction. They were introduced in v9 and its 32 bits sibling, v8+.
You can emulate them in many ways, including with a trivial global
lock using the existing test-and-set instruction.
I did that a while ago for some recompilation in S7 and S8:
Beware that it's not a universal solution.
1) The lock variable is defined in the library, so it's not shared
between processes. Atomic won't work between processes in shared
memory such as SysV shmem, only for threads. Going multi-process
transparently (w/o changing the function signature) is non-trivial.
2) The lock variable is one big contention point that will slow things
down, by forcing mutual exclusion for all atomic accesses including
those to different variables. In theory it could be replaced by an
array of variables (in different cache lines) using some sort of hash
function based on the address of the protected variable. If that
matters... use v8+ hardware instead would be my advice :-) v7 and v8
are not suitable for modern parallelism.