Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/common/lib/libc/arch/arm/atomic Add 64bit atomic ops for ARM...
details: https://anonhg.NetBSD.org/src/rev/7a0223280fb7
branches: trunk
changeset: 781510:7a0223280fb7
user: matt <matt%NetBSD.org@localhost>
date: Tue Sep 11 20:51:25 2012 +0000
description:
Add 64bit atomic ops for ARMv6+ (using ldrexd/strexd).
diffstat:
common/lib/libc/arch/arm/atomic/Makefile.inc | 11 ++-
common/lib/libc/arch/arm/atomic/atomic_add_64.S | 82 ++++++++++++++++++++++++
common/lib/libc/arch/arm/atomic/atomic_and_64.S | 82 ++++++++++++++++++++++++
common/lib/libc/arch/arm/atomic/atomic_cas_64.S | 69 ++++++++++++++++++++
common/lib/libc/arch/arm/atomic/atomic_dec_64.S | 73 +++++++++++++++++++++
common/lib/libc/arch/arm/atomic/atomic_inc_64.S | 72 +++++++++++++++++++++
common/lib/libc/arch/arm/atomic/atomic_op_asm.h | 14 +++-
common/lib/libc/arch/arm/atomic/atomic_or_64.S | 81 +++++++++++++++++++++++
common/lib/libc/arch/arm/atomic/atomic_swap_64.S | 67 +++++++++++++++++++
9 files changed, 546 insertions(+), 5 deletions(-)
diffs (truncated from 605 to 300 lines):
diff -r a5a4ed31cad8 -r 7a0223280fb7 common/lib/libc/arch/arm/atomic/Makefile.inc
--- a/common/lib/libc/arch/arm/atomic/Makefile.inc Tue Sep 11 20:29:58 2012 +0000
+++ b/common/lib/libc/arch/arm/atomic/Makefile.inc Tue Sep 11 20:51:25 2012 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.inc,v 1.9 2012/08/16 16:49:10 matt Exp $
+# $NetBSD: Makefile.inc,v 1.10 2012/09/11 20:51:25 matt Exp $
ARMV6= ${CPUFLAGS:M-march=armv7*} ${CPUFLAGS:M-mcpu=cortex*}
ARMV6+= ${CPUFLAGS:M-march=armv6*} ${CPUFLAGS:M-mcpu=arm11*}
@@ -18,9 +18,12 @@
atomic_or_32_cas.c atomic_or_32_nv_cas.c \
atomic_swap_32_cas.c membar_ops_nop.c
.else
-SRCS.atomic+= atomic_add_32.S atomic_and_32.S atomic_cas_32.S \
- atomic_dec_32.S atomic_inc_32.S atomic_or_32.S \
- atomic_swap.S membar_ops.S
+SRCS.atomic+= atomic_add_32.S atomic_and_32.S atomic_cas_32.S
+SRCS.atomic+= atomic_dec_32.S atomic_inc_32.S atomic_or_32.S
+SRCS.atomic+= atomic_swap.S membar_ops.S
+SRCS.atomic+= atomic_add_64.S atomic_and_64.S atomic_cas_64.S
+SRCS.atomic+= atomic_dec_64.S atomic_inc_64.S atomic_or_64.S
+SRCS.atomic+= atomic_swap_64.S
.endif
.endif
diff -r a5a4ed31cad8 -r 7a0223280fb7 common/lib/libc/arch/arm/atomic/atomic_add_64.S
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/common/lib/libc/arch/arm/atomic/atomic_add_64.S Tue Sep 11 20:51:25 2012 +0000
@@ -0,0 +1,82 @@
+/* $NetBSD: atomic_add_64.S,v 1.1 2012/09/11 20:51:25 matt Exp $ */
+
+/*-
+ * Copyright (c) 2008 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Matt Thomas <matt%3am-software.com@localhost>
+ *
+ * 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 "atomic_op_asm.h"
+
+#ifdef _ARM_ARCH_6
+
+ENTRY_NP(_atomic_add_64)
+ str r4, [sp, #-4]! /* save temporary */
+ mov r4, r0 /* need r0 for return value */
+#ifndef __ARM_EABI__
+ mov r3, r2
+ mov r2, r1
+#endif
+1: ldrexd r0, [r4] /* load old value (to be returned) */
+ adds NLO, LO, NLO /* calculate new value */
+ adc NHI, HI, NHI /* calculate new value */
+ strexd ip, r2, [r4] /* try to store */
+ cmp ip, #0 /* succeed? */
+ bne 1b /* no, try again */
+#ifdef _ARM_ARCH_7
+ dmb
+#else
+ mcr p15, 0, ip, c7, c10, 5 /* data memory barrier */
+#endif
+ ldmfd sp!, {r4, r5}
+ RET /* return old value */
+ END(_atomic_add_64)
+ATOMIC_OP_ALIAS(atomic_add_64,_atomic_add_64)
+
+ENTRY_NP(_atomic_add_64_nv)
+ str r4, [sp, #-4]! /* save temporary */
+ mov r4, r0 /* need r0 for return value */
+#ifndef __ARM_EABI__
+ mov r3, r2
+ mov r2, r1
+#endif
+1: ldrexd r0, [r4] /* load old value */
+ adds LO, LO, NLO /* calculate new value lo */
+ adc HI, HI, NHI /* calculate new value hi */
+ strexd ip, r0, [r4] /* try to store */
+ cmp ip, #0 /* succeed? */
+ bne 1b /* no, try again? */
+#ifdef _ARM_ARCH_7
+ dmb
+#else
+ mcr p15, 0, ip, c7, c10, 5 /* data memory barrier */
+#endif
+ ldmfd sp!, {r4, r5}
+ RET /* return new value */
+ END(_atomic_add_64_nv)
+ATOMIC_OP_ALIAS(atomic_add_64_nv,_atomic_add_64_nv)
+
+#endif /* _ARM_ARCH_6 */
diff -r a5a4ed31cad8 -r 7a0223280fb7 common/lib/libc/arch/arm/atomic/atomic_and_64.S
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/common/lib/libc/arch/arm/atomic/atomic_and_64.S Tue Sep 11 20:51:25 2012 +0000
@@ -0,0 +1,82 @@
+/* $NetBSD: atomic_and_64.S,v 1.1 2012/09/11 20:51:25 matt Exp $ */
+
+/*-
+ * Copyright (c) 2008 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Matt Thomas <matt%3am-software.com@localhost>
+ *
+ * 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 "atomic_op_asm.h"
+
+#ifdef _ARM_ARCH_6
+
+ENTRY_NP(_atomic_and_64)
+ str r4, [sp, #-4]! /* save temporary */
+#ifndef __ARM_EABI__
+ mov r3, r2
+ mov r2, r1
+#endif
+ mov r4, r0 /* need r0 for return value */
+1: ldrexd r0, [r4] /* load old value (to be returned) */
+ and r2, r0, r2 /* calculate new value */
+ and r3, r1, r3 /* calculate new value */
+ strexd ip, r2, [r4] /* try to store */
+ cmp ip, #0 /* succeed? */
+ bne 1b /* no, try again */
+#ifdef _ARM_ARCH_7
+ dmb
+#else
+ mcr p15, 0, ip, c7, c10, 5 /* data memory barrier */
+#endif
+ ldr r4, [sp], #4 /* restore temporary */
+ RET /* return old value */
+ END(_atomic_and_64)
+ATOMIC_OP_ALIAS(atomic_and_64,_atomic_and_64)
+
+ENTRY_NP(_atomic_and_64_nv)
+ str r4, [sp, #-4]! /* save temporary */
+#ifndef __ARM_EABI__
+ mov r3, r2
+ mov r2, r1
+#endif
+ mov r4, r0 /* need r0 for return value */
+1: ldrexd r0, [r4] /* load old value */
+ and r0, r0, r2 /* calculate new value */
+ and r1, r1, r3 /* calculate new value */
+ strexd ip, r0, [r4] /* try to store */
+ cmp ip, #0 /* succeed? */
+ bne 1b /* no, try again? */
+#ifdef _ARM_ARCH_7
+ dmb
+#else
+ mcr p15, 0, ip, c7, c10, 5 /* data memory barrier */
+#endif
+ ldr r4, [sp], #4 /* restore temporary */
+ RET /* return new value */
+ END(_atomic_and_64_nv)
+ATOMIC_OP_ALIAS(atomic_and_64_nv,_atomic_and_64_nv)
+
+#endif /* _ARM_ARCH_6 */
diff -r a5a4ed31cad8 -r 7a0223280fb7 common/lib/libc/arch/arm/atomic/atomic_cas_64.S
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/common/lib/libc/arch/arm/atomic/atomic_cas_64.S Tue Sep 11 20:51:25 2012 +0000
@@ -0,0 +1,69 @@
+/* $NetBSD: atomic_cas_64.S,v 1.1 2012/09/11 20:51:25 matt Exp $ */
+/*-
+ * Copyright (c) 2012 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Matt Thomas <matt%3am-software.com@localhost>
+ *
+ * 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 "atomic_op_asm.h"
+
+#if defined(_ARM_ARCH_6)
+/*
+ * ARMv6 has load-exclusive/store-exclusive which works for both user
+ * and kernel.
+ */
+ENTRY_NP(_atomic_cas_64)
+ stmfd sp!, {r4, r5, r6} /* save temporaries */
+ mov r6, r0 /* we need r0 for return value */
+#ifdef __ARM_EABI__
+ ldrd r4, [sp] /* fetch new value */
+#else
+ ldr r5, [sp, #4] /* fetch new value */
+ ldr r4, [sp, #0] /* fetch new value */
+ mov r3, r2 /* r2 will be overwritten by r1 which ... */
+ mov r2, r1 /* r1 will be overwritten by ldrexd */
+#endif
+1:
+ ldrexd r0, [r6] /* load current value */
+ teq r0, r2 /* compare to old? 1st half */
+ teqeq r1, r3 /* compare to old? 2nd half */
+ bne 2f /* jump to return if different */
+ strexd ip, r4, [r6] /* store new value */
+ cmp ip, #0 /* succeed? */
+ bne 1b /* nope, try again. */
+#ifdef _ARM_ARCH_7
+ dsb
+#else
+ mcr p15, 0, ip, c7, c10, 4 /* data synchronization barrier */
+#endif
+2:
+ ldmfd sp!, {r4, r5, r6} /* restore temporaries */
+ RET /* return. */
+ END(_atomic_cas_64)
+
+ATOMIC_OP_ALIAS(atomic_cas_64,_atomic_cas_64)
+
+#endif /* _ARCH_ARM_6 */
diff -r a5a4ed31cad8 -r 7a0223280fb7 common/lib/libc/arch/arm/atomic/atomic_dec_64.S
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/common/lib/libc/arch/arm/atomic/atomic_dec_64.S Tue Sep 11 20:51:25 2012 +0000
@@ -0,0 +1,73 @@
+/* $NetBSD: atomic_dec_64.S,v 1.1 2012/09/11 20:51:25 matt Exp $ */
+/*-
+ * Copyright (c) 2008 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Matt Thomas <matt%3am-software.com@localhost>
+ *
+ * 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)
Home |
Main Index |
Thread Index |
Old Index