Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/common/lib/libc Provide most missing __sync_*64 primitives f...



details:   https://anonhg.NetBSD.org/src/rev/43c9d58fba2b
branches:  trunk
changeset: 326795:43c9d58fba2b
user:      martin <martin%NetBSD.org@localhost>
date:      Tue Feb 18 10:16:55 2014 +0000

description:
Provide most missing __sync_*64 primitives for i386

diffstat:

 common/lib/libc/arch/i386/atomic/Makefile.inc |   6 +-
 common/lib/libc/arch/i386/atomic/atomic.S     |   3 +-
 common/lib/libc/atomic/atomic_cas_64_cas.c    |  47 +++++++++++++++++++
 common/lib/libc/atomic/atomic_nand_64_cas.c   |  65 +++++++++++++++++++++++++++
 common/lib/libc/atomic/atomic_sub_64_cas.c    |  65 +++++++++++++++++++++++++++
 common/lib/libc/atomic/atomic_xor_64_cas.c    |  65 +++++++++++++++++++++++++++
 6 files changed, 248 insertions(+), 3 deletions(-)

diffs (295 lines):

diff -r 525b750057a0 -r 43c9d58fba2b common/lib/libc/arch/i386/atomic/Makefile.inc
--- a/common/lib/libc/arch/i386/atomic/Makefile.inc     Tue Feb 18 06:20:46 2014 +0000
+++ b/common/lib/libc/arch/i386/atomic/Makefile.inc     Tue Feb 18 10:16:55 2014 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile.inc,v 1.7 2009/01/04 17:54:29 pooka Exp $
+#      $NetBSD: Makefile.inc,v 1.8 2014/02/18 10:16:55 martin Exp $
 
 .if defined(LIB) && (${LIB} == "kern" || ${LIB} == "c" || ${LIB} == "pthread" \
        || ${LIB} == "rump")
@@ -6,7 +6,9 @@
 SRCS+= atomic_add_64_cas.c atomic_add_64_nv_cas.c atomic_and_64_cas.c \
        atomic_and_64_nv_cas.c atomic_dec_64_cas.c atomic_dec_64_nv_cas.c \
        atomic_inc_64_cas.c atomic_inc_64_nv_cas.c atomic_or_64_cas.c \
-       atomic_or_64_nv_cas.c atomic_swap_64_cas.c atomic.S
+       atomic_or_64_nv_cas.c atomic_swap_64_cas.c atomic.S     \
+       atomic_nand_64_cas.c atomic_xor_64_cas.c atomic_sub_64_cas.c \
+       atomic_cas_64_cas.c
 
 .endif
 
diff -r 525b750057a0 -r 43c9d58fba2b common/lib/libc/arch/i386/atomic/atomic.S
--- a/common/lib/libc/arch/i386/atomic/atomic.S Tue Feb 18 06:20:46 2014 +0000
+++ b/common/lib/libc/arch/i386/atomic/atomic.S Tue Feb 18 10:16:55 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: atomic.S,v 1.19 2011/01/12 23:12:10 joerg Exp $        */
+/*     $NetBSD: atomic.S,v 1.20 2014/02/18 10:16:55 martin Exp $       */
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -321,6 +321,7 @@
 
 ALIAS(atomic_cas_64,_atomic_cas_64)
 ALIAS(atomic_cas_64_ni,_atomic_cas_64)
+ALIAS(__sync_val_compare_and_swap_8,_atomic_cas_64)
 
 ALIAS(membar_consumer,_membar_consumer)
 ALIAS(membar_producer,_membar_producer)
diff -r 525b750057a0 -r 43c9d58fba2b common/lib/libc/atomic/atomic_cas_64_cas.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/common/lib/libc/atomic/atomic_cas_64_cas.c        Tue Feb 18 10:16:55 2014 +0000
@@ -0,0 +1,47 @@
+/*     $NetBSD: atomic_cas_64_cas.c,v 1.1 2014/02/18 10:16:55 martin Exp $     */
+
+/*-
+ * Copyright (c) 2014 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jason R. Thorpe.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdbool.h>
+#include <sys/atomic.h>
+
+#ifdef __HAVE_ATOMIC64_OPS
+
+bool bool_compare_and_swap_8(volatile uint64_t *, uint64_t, uint64_t, ...)
+    asm("__sync_bool_compare_and_swap_8");
+
+bool
+bool_compare_and_swap_8(volatile uint64_t *addr, uint64_t oldval,
+       uint64_t newval, ...)
+{
+       return atomic_cas_64(addr, oldval, newval) == oldval;
+}
+
+#endif
diff -r 525b750057a0 -r 43c9d58fba2b common/lib/libc/atomic/atomic_nand_64_cas.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/common/lib/libc/atomic/atomic_nand_64_cas.c       Tue Feb 18 10:16:55 2014 +0000
@@ -0,0 +1,65 @@
+/*     $NetBSD: atomic_nand_64_cas.c,v 1.1 2014/02/18 10:16:55 martin Exp $    */
+
+/*-
+ * Copyright (c) 2014 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jason R. Thorpe.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/atomic.h>
+
+#ifdef __HAVE_ATOMIC64_OPS
+
+uint64_t fetch_and_nand_8(volatile uint64_t *, uint64_t, ...)
+    asm("__sync_fetch_and_nand_8");
+uint64_t nand_and_fetch_8(volatile uint64_t *, uint64_t, ...)
+    asm("__sync_nand_and_fetch_8");
+
+uint64_t
+fetch_and_nand_8(volatile uint64_t *addr, uint64_t val, ...)
+{
+       uint64_t old, new;
+
+       do {
+               old = *addr;
+               new = ~(old & val);
+       } while (atomic_cas_64(addr, old, new) != old);
+       return old;
+}
+
+uint64_t
+nand_and_fetch_8(volatile uint64_t *addr, uint64_t val, ...)
+{
+       uint64_t old, new;
+
+       do {
+               old = *addr;
+               new = ~(old & val);
+       } while (atomic_cas_64(addr, old, new) != old);
+       return *addr;
+}
+
+#endif
diff -r 525b750057a0 -r 43c9d58fba2b common/lib/libc/atomic/atomic_sub_64_cas.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/common/lib/libc/atomic/atomic_sub_64_cas.c        Tue Feb 18 10:16:55 2014 +0000
@@ -0,0 +1,65 @@
+/*     $NetBSD: atomic_sub_64_cas.c,v 1.1 2014/02/18 10:16:55 martin Exp $     */
+
+/*-
+ * Copyright (c) 2014 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jason R. Thorpe.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/atomic.h>
+
+#ifdef __HAVE_ATOMIC64_OPS
+
+uint64_t fetch_and_sub_8(volatile uint64_t *, uint64_t, ...)
+    asm("__sync_fetch_and_sub_8");
+uint64_t sub_and_fetch_8(volatile uint64_t *, uint64_t, ...)
+    asm("__sync_sub_and_fetch_8");
+
+uint64_t
+fetch_and_sub_8(volatile uint64_t *addr, uint64_t val, ...)
+{
+       uint64_t old, new;
+
+       do {
+               old = *addr;
+               new = old - val;
+       } while (atomic_cas_64(addr, old, new) != old);
+       return old;
+}
+
+uint64_t
+sub_and_fetch_8(volatile uint64_t *addr, uint64_t val, ...)
+{
+       uint64_t old, new;
+
+       do {
+               old = *addr;
+               new = old - val;
+       } while (atomic_cas_64(addr, old, new) != old);
+       return *addr;
+}
+
+#endif
diff -r 525b750057a0 -r 43c9d58fba2b common/lib/libc/atomic/atomic_xor_64_cas.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/common/lib/libc/atomic/atomic_xor_64_cas.c        Tue Feb 18 10:16:55 2014 +0000
@@ -0,0 +1,65 @@
+/*     $NetBSD: atomic_xor_64_cas.c,v 1.1 2014/02/18 10:16:55 martin Exp $     */
+
+/*-
+ * Copyright (c) 2014 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jason R. Thorpe.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/atomic.h>
+
+#ifdef __HAVE_ATOMIC64_OPS
+
+uint64_t fetch_and_xor_8(volatile uint64_t *, uint64_t, ...)
+    asm("__sync_fetch_and_xor_8");
+uint64_t xor_and_fetch_8(volatile uint64_t *, uint64_t, ...)
+    asm("__sync_xor_and_fetch_8");
+
+uint64_t
+fetch_and_xor_8(volatile uint64_t *addr, uint64_t val, ...)
+{
+       uint64_t old, new;
+
+       do {
+               old = *addr;
+               new = old ^ val;
+       } while (atomic_cas_64(addr, old, new) != old);
+       return old;
+}
+
+uint64_t
+xor_and_fetch_8(volatile uint64_t *addr, uint64_t val, ...)
+{
+       uint64_t old, new;
+
+       do {
+               old = *addr;
+               new = old ^ val;
+       } while (atomic_cas_64(addr, old, new) != old);
+       return *addr;
+}
+
+#endif



Home | Main Index | Thread Index | Old Index