Module Name: src Committed By: martin Date: Tue Feb 18 10:16:55 UTC 2014
Modified Files: src/common/lib/libc/arch/i386/atomic: Makefile.inc atomic.S Added Files: src/common/lib/libc/atomic: atomic_cas_64_cas.c atomic_nand_64_cas.c atomic_sub_64_cas.c atomic_xor_64_cas.c Log Message: Provide most missing __sync_*64 primitives for i386 To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/common/lib/libc/arch/i386/atomic/Makefile.inc cvs rdiff -u -r1.19 -r1.20 src/common/lib/libc/arch/i386/atomic/atomic.S cvs rdiff -u -r0 -r1.1 src/common/lib/libc/atomic/atomic_cas_64_cas.c \ src/common/lib/libc/atomic/atomic_nand_64_cas.c \ src/common/lib/libc/atomic/atomic_sub_64_cas.c \ src/common/lib/libc/atomic/atomic_xor_64_cas.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/common/lib/libc/arch/i386/atomic/Makefile.inc diff -u src/common/lib/libc/arch/i386/atomic/Makefile.inc:1.7 src/common/lib/libc/arch/i386/atomic/Makefile.inc:1.8 --- src/common/lib/libc/arch/i386/atomic/Makefile.inc:1.7 Sun Jan 4 17:54:29 2009 +++ src/common/lib/libc/arch/i386/atomic/Makefile.inc Tue Feb 18 10:16:55 2014 @@ -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 Index: src/common/lib/libc/arch/i386/atomic/atomic.S diff -u src/common/lib/libc/arch/i386/atomic/atomic.S:1.19 src/common/lib/libc/arch/i386/atomic/atomic.S:1.20 --- src/common/lib/libc/arch/i386/atomic/atomic.S:1.19 Wed Jan 12 23:12:10 2011 +++ src/common/lib/libc/arch/i386/atomic/atomic.S Tue Feb 18 10:16:55 2014 @@ -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_ptr_ni,_atomic_cas_32_n 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) Added files: Index: src/common/lib/libc/atomic/atomic_cas_64_cas.c diff -u /dev/null src/common/lib/libc/atomic/atomic_cas_64_cas.c:1.1 --- /dev/null Tue Feb 18 10:16:55 2014 +++ src/common/lib/libc/atomic/atomic_cas_64_cas.c Tue Feb 18 10:16:55 2014 @@ -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 Index: src/common/lib/libc/atomic/atomic_nand_64_cas.c diff -u /dev/null src/common/lib/libc/atomic/atomic_nand_64_cas.c:1.1 --- /dev/null Tue Feb 18 10:16:55 2014 +++ src/common/lib/libc/atomic/atomic_nand_64_cas.c Tue Feb 18 10:16:55 2014 @@ -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 Index: src/common/lib/libc/atomic/atomic_sub_64_cas.c diff -u /dev/null src/common/lib/libc/atomic/atomic_sub_64_cas.c:1.1 --- /dev/null Tue Feb 18 10:16:55 2014 +++ src/common/lib/libc/atomic/atomic_sub_64_cas.c Tue Feb 18 10:16:55 2014 @@ -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 Index: src/common/lib/libc/atomic/atomic_xor_64_cas.c diff -u /dev/null src/common/lib/libc/atomic/atomic_xor_64_cas.c:1.1 --- /dev/null Tue Feb 18 10:16:55 2014 +++ src/common/lib/libc/atomic/atomic_xor_64_cas.c Tue Feb 18 10:16:55 2014 @@ -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