From 004e15d6a27248383965a270534db07a47fde1ae Mon Sep 17 00:00:00 2001 From: kettenis Date: Sat, 4 Apr 2020 22:11:36 +0000 Subject: [PATCH] Implement __atomic_is_lock_free for powerpc. Needed because the architecture doesn't implement 64-bit atomic operations. This implementation is pessimistic and only flags naturally aligned operations up to and including 32-bit as lock free. tested by cwen@ ok gkoehler@ --- lib/libcompiler_rt/Makefile | 5 +++-- lib/libcompiler_rt/ppc/atomic_lock_free.c | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 lib/libcompiler_rt/ppc/atomic_lock_free.c diff --git a/lib/libcompiler_rt/Makefile b/lib/libcompiler_rt/Makefile index 812bef29aea..6c92a870f20 100644 --- a/lib/libcompiler_rt/Makefile +++ b/lib/libcompiler_rt/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.14 2018/12/25 09:20:49 claudio Exp $ +# $OpenBSD: Makefile,v 1.15 2020/04/04 22:11:36 kettenis Exp $ .include @@ -275,7 +275,8 @@ SRCS+= comparetf2.c \ .endif .if ${RTARCH} == "ppc" -SRCS+= divtc3.c \ +SRCS+= atomic_lock_free.c \ + divtc3.c \ fixtfdi.c \ fixunstfdi.c \ floatditf.c \ diff --git a/lib/libcompiler_rt/ppc/atomic_lock_free.c b/lib/libcompiler_rt/ppc/atomic_lock_free.c new file mode 100644 index 00000000000..6a781a3069b --- /dev/null +++ b/lib/libcompiler_rt/ppc/atomic_lock_free.c @@ -0,0 +1,22 @@ +/* Public domain. */ + +#include +#include +#include + +#pragma redefine_extname __atomic_is_lock_free_c __atomic_is_lock_free + +bool +__atomic_is_lock_free_c(size_t size, void *ptr) +{ + switch (size) { + case 1: + return true; + case 2: + return (((uintptr_t)ptr & 1) == 0); + case 4: + return (((uintptr_t)ptr & 3) == 0); + } + + return false; +}