64-bit atomic ops on 32-bit CPU (again)

Justin Hibbits jrh29 at alumni.cwru.edu
Thu Sep 10 16:22:35 UTC 2015


On Sun, Sep 6, 2015 at 12:20 AM, Alexey Dokuchaev <danfe at freebsd.org> wrote:
> On Wed, Aug 05, 2015 at 03:16:58PM -0700, Justin Hibbits wrote:
>> I *think* all that's needed is atomic64 emulation.  I had written a
>> patch implementing them, [...]
>
> Hmm, perhaps you can help me here for a slightly different problem?  I
> need to do __sync_fetch_and_add() on int64_t argument (in userspace),
> but linking fails due to undefined reference to `__sync_fetch_and_add_8'
> (this is on 32-bit G4).
>
> I've googled a bit on how to implement a lock-free atomic 64-bit addition
> on a 32-bit ppc (e.g. [1], [2]), it looks certainly doable (albeit would
> require good understanding of CPU and cache details, and a manual ;-).
>
> What's my best bet here: implement local __sync_fetch_and_add_64() with
> inline asm(), or teach gcc how to avoid __sync_fetch_and_add_8() linking
> problem somehow?
>
> ./danfe
>
> [1] http://lists.apple.com/archives/perfoptimization-dev/2008/Nov/msg00012.html
> [2] https://lists.freebsd.org/pipermail/freebsd-ppc/2008-September/003129.html

Hmm, looking at it again, you could feasibly just augment
sys/dev/drm2/drm_atomic.h to use different atomic64 primitives, rather
than adding 64-bit atomic(9) support.

As for the user space, I would add __sync_*_8() methods into
contrib/compiler-rt/lib/builtins/ppc, a'la .../arm/sync*.S .

- Justin


More information about the freebsd-ppc mailing list