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 Fix 64-bit atomic operations on 32-bit ...
details: https://anonhg.NetBSD.org/src/rev/112c718b711c
branches: trunk
changeset: 341096:112c718b711c
user: nakayama <nakayama%NetBSD.org@localhost>
date: Sun Oct 18 02:28:07 2015 +0000
description:
Fix 64-bit atomic operations on 32-bit kernel and userland, and add
support for missing __sync_*_8 builtins.
diffstat:
common/lib/libc/arch/sparc/atomic/Makefile.inc | 8 +++++-
common/lib/libc/arch/sparc64/atomic/atomic_add.S | 26 ++++++++++++++++++++-
common/lib/libc/arch/sparc64/atomic/atomic_and.S | 26 ++++++++++++++++++++-
common/lib/libc/arch/sparc64/atomic/atomic_cas.S | 14 ++++++++++-
common/lib/libc/arch/sparc64/atomic/atomic_dec.S | 7 ++++-
common/lib/libc/arch/sparc64/atomic/atomic_inc.S | 7 ++++-
common/lib/libc/arch/sparc64/atomic/atomic_op_asm.h | 6 ++++-
common/lib/libc/arch/sparc64/atomic/atomic_or.S | 26 ++++++++++++++++++++-
common/lib/libc/arch/sparc64/atomic/atomic_swap.S | 14 ++++++++++-
9 files changed, 125 insertions(+), 9 deletions(-)
diffs (truncated from 318 to 300 lines):
diff -r 88c2ae44fee4 -r 112c718b711c common/lib/libc/arch/sparc/atomic/Makefile.inc
--- a/common/lib/libc/arch/sparc/atomic/Makefile.inc Sun Oct 18 00:39:14 2015 +0000
+++ b/common/lib/libc/arch/sparc/atomic/Makefile.inc Sun Oct 18 02:28:07 2015 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.inc,v 1.18 2014/10/13 08:59:41 martin Exp $
+# $NetBSD: Makefile.inc,v 1.19 2015/10/18 02:28:07 nakayama Exp $
.include <bsd.own.mk>
@@ -12,6 +12,12 @@
.include "${SPARC64DIR}/Makefile.inc"
+.if defined(LIB) && (${LIB} == "kern" || ${LIB} == "c" || ${LIB} == "pthread" \
+ || ${LIB} == "rump")
+SRCS+= atomic_nand_64_cas.c atomic_xor_64_cas.c atomic_sub_64_cas.c \
+ atomic_cas_64_cas.c
+.endif
+
.else
. if defined(LIB)
diff -r 88c2ae44fee4 -r 112c718b711c common/lib/libc/arch/sparc64/atomic/atomic_add.S
--- a/common/lib/libc/arch/sparc64/atomic/atomic_add.S Sun Oct 18 00:39:14 2015 +0000
+++ b/common/lib/libc/arch/sparc64/atomic/atomic_add.S Sun Oct 18 02:28:07 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: atomic_add.S,v 1.6 2008/05/25 15:56:12 chs Exp $ */
+/* $NetBSD: atomic_add.S,v 1.7 2015/10/18 02:28:07 nakayama Exp $ */
/*-
* Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -52,14 +52,22 @@
STRONG_ALIAS(_atomic_add_int_nv,_atomic_add_32)
ENTRY(_atomic_add_64)
+#ifndef __arch64__
+ COMBINE(%o1, %o2, %o1)
+#endif
ldx [%o0], %o2
1: add %o1, %o2, %o3
casx [%o0], %o2, %o3
cmp %o2, %o3
bne,a,pn %xcc, 1b
mov %o3, %o2
+#ifdef __arch64__
retl
add %o1, %o2, %o0
+#else
+ add %o1, %o2, %o0
+ SPLIT_RETL(%o0, %o0, %o1)
+#endif
ATOMIC_OP_ALIAS(atomic_add_64,_atomic_add_64)
ATOMIC_OP_ALIAS(atomic_add_64_nv,_atomic_add_64)
@@ -74,3 +82,19 @@
STRONG_ALIAS_SIZE(_atomic_add_long_nv,_atomic_add)
ATOMIC_OP_ALIAS_SIZE(atomic_add_ptr_nv,_atomic_add)
STRONG_ALIAS_SIZE(_atomic_add_ptr_nv,_atomic_add)
+
+#if !defined(__arch64__) && defined(CRT_ALIAS)
+ENTRY(__sync_fetch_and_add_8)
+ COMBINE(%o1, %o2, %o1)
+ ldx [%o0], %o2
+1: add %o1, %o2, %o3
+ casx [%o0], %o2, %o3
+ cmp %o2, %o3
+ bne,a,pn %xcc, 1b
+ mov %o3, %o2
+ SPLIT_RETL(%o2, %o0, %o1)
+CRT_ALIAS(__sync_add_and_fetch_8,_atomic_add_64_nv)
+
+CRT_ALIAS(__atomic_fetch_add_8,__sync_fetch_and_add_8)
+CRT_ALIAS(__atomic_add_fetch_8,__sync_add_and_fetch_8)
+#endif
diff -r 88c2ae44fee4 -r 112c718b711c common/lib/libc/arch/sparc64/atomic/atomic_and.S
--- a/common/lib/libc/arch/sparc64/atomic/atomic_and.S Sun Oct 18 00:39:14 2015 +0000
+++ b/common/lib/libc/arch/sparc64/atomic/atomic_and.S Sun Oct 18 02:28:07 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: atomic_and.S,v 1.6 2008/05/25 15:56:12 chs Exp $ */
+/* $NetBSD: atomic_and.S,v 1.7 2015/10/18 02:28:07 nakayama Exp $ */
/*-
* Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -52,14 +52,22 @@
STRONG_ALIAS(_atomic_and_uint_nv,_atomic_and_32)
ENTRY(_atomic_and_64)
+#ifndef __arch64__
+ COMBINE(%o1, %o2, %o1)
+#endif
ldx [%o0], %o2
1: and %o1, %o2, %o3
casx [%o0], %o2, %o3
cmp %o2, %o3
bne,a,pn %xcc, 1b
mov %o3, %o2
+#ifdef __arch64__
retl
and %o1, %o2, %o0
+#else
+ and %o1, %o2, %o0
+ SPLIT_RETL(%o0, %o0, %o1)
+#endif
ATOMIC_OP_ALIAS(atomic_and_64,_atomic_and_64)
ATOMIC_OP_ALIAS(atomic_and_64_nv,_atomic_and_64)
@@ -70,3 +78,19 @@
ATOMIC_OP_ALIAS_SIZE(atomic_and_ulong_nv,_atomic_and)
STRONG_ALIAS_SIZE(_atomic_and_ulong_nv,_atomic_and)
+
+#if !defined(__arch64__) && defined(CRT_ALIAS)
+ENTRY(__sync_fetch_and_and_8)
+ COMBINE(%o1, %o2, %o1)
+ ldx [%o0], %o2
+1: and %o1, %o2, %o3
+ casx [%o0], %o2, %o3
+ cmp %o2, %o3
+ bne,a,pn %xcc, 1b
+ mov %o3, %o2
+ SPLIT_RETL(%o2, %o0, %o1)
+CRT_ALIAS(__sync_and_and_fetch_8,_atomic_and_64_nv)
+
+CRT_ALIAS(__atomic_fetch_and_8,__sync_fetch_and_and_8)
+CRT_ALIAS(__atomic_and_fetch_8,__sync_and_and_fetch_8)
+#endif
diff -r 88c2ae44fee4 -r 112c718b711c common/lib/libc/arch/sparc64/atomic/atomic_cas.S
--- a/common/lib/libc/arch/sparc64/atomic/atomic_cas.S Sun Oct 18 00:39:14 2015 +0000
+++ b/common/lib/libc/arch/sparc64/atomic/atomic_cas.S Sun Oct 18 02:28:07 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: atomic_cas.S,v 1.6 2008/05/25 15:56:12 chs Exp $ */
+/* $NetBSD: atomic_cas.S,v 1.7 2015/10/18 02:28:07 nakayama Exp $ */
/*-
* Copyright (c) 2007, 2008 The NetBSD Foundation, Inc.
@@ -48,9 +48,17 @@
STRONG_ALIAS(_atomic_cas_uint_ni,_atomic_cas_32)
ENTRY(_atomic_cas_64)
+#ifndef __arch64__
+ COMBINE(%o1, %o2, %o1)
+ COMBINE(%o3, %o4, %o2)
+#endif
casx [%o0], %o1, %o2
+#ifdef __arch64__
retl
mov %o2, %o0
+#else
+ SPLIT_RETL(%o2, %o0, %o1)
+#endif
ATOMIC_OP_ALIAS(atomic_cas_64,_atomic_cas_64)
ATOMIC_OP_ALIAS_SIZE(atomic_cas_ulong,_atomic_cas)
@@ -64,3 +72,7 @@
STRONG_ALIAS_SIZE(_atomic_cas_ulong_ni,_atomic_cas)
ATOMIC_OP_ALIAS_SIZE(atomic_cas_ptr_ni,_atomic_cas)
STRONG_ALIAS_SIZE(_atomic_cas_ptr_ni,_atomic_cas)
+
+#if !defined(__arch64__) && defined(CRT_ALIAS)
+CRT_ALIAS(__sync_val_compare_and_swap_8,_atomic_cas_64)
+#endif
diff -r 88c2ae44fee4 -r 112c718b711c common/lib/libc/arch/sparc64/atomic/atomic_dec.S
--- a/common/lib/libc/arch/sparc64/atomic/atomic_dec.S Sun Oct 18 00:39:14 2015 +0000
+++ b/common/lib/libc/arch/sparc64/atomic/atomic_dec.S Sun Oct 18 02:28:07 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: atomic_dec.S,v 1.7 2008/05/25 15:56:12 chs Exp $ */
+/* $NetBSD: atomic_dec.S,v 1.8 2015/10/18 02:28:07 nakayama Exp $ */
/*-
* Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -58,8 +58,13 @@
cmp %o2, %o3
bne,a,pn %xcc, 1b
mov %o3, %o2
+#ifdef __arch64__
retl
add %o2, -1, %o0
+#else
+ add %o2, -1, %o0
+ SPLIT_RETL(%o0, %o0, %o1)
+#endif
ATOMIC_OP_ALIAS(atomic_dec_64,_atomic_dec_64)
ATOMIC_OP_ALIAS(atomic_dec_64_nv,_atomic_dec_64)
diff -r 88c2ae44fee4 -r 112c718b711c common/lib/libc/arch/sparc64/atomic/atomic_inc.S
--- a/common/lib/libc/arch/sparc64/atomic/atomic_inc.S Sun Oct 18 00:39:14 2015 +0000
+++ b/common/lib/libc/arch/sparc64/atomic/atomic_inc.S Sun Oct 18 02:28:07 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: atomic_inc.S,v 1.6 2008/05/25 15:56:12 chs Exp $ */
+/* $NetBSD: atomic_inc.S,v 1.7 2015/10/18 02:28:07 nakayama Exp $ */
/*-
* Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -58,8 +58,13 @@
cmp %o2, %o3
bne,a,pn %xcc, 1b
mov %o3, %o2
+#ifdef __arch64__
retl
add %o2, 1, %o0
+#else
+ add %o2, 1, %o0
+ SPLIT_RETL(%o0, %o0, %o1)
+#endif
ATOMIC_OP_ALIAS(atomic_inc_64,_atomic_inc_64)
ATOMIC_OP_ALIAS(atomic_inc_64_nv,_atomic_inc_64)
diff -r 88c2ae44fee4 -r 112c718b711c common/lib/libc/arch/sparc64/atomic/atomic_op_asm.h
--- a/common/lib/libc/arch/sparc64/atomic/atomic_op_asm.h Sun Oct 18 00:39:14 2015 +0000
+++ b/common/lib/libc/arch/sparc64/atomic/atomic_op_asm.h Sun Oct 18 02:28:07 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: atomic_op_asm.h,v 1.6 2011/01/17 18:11:10 joerg Exp $ */
+/* $NetBSD: atomic_op_asm.h,v 1.7 2015/10/18 02:28:07 nakayama Exp $ */
/*-
* Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -54,6 +54,10 @@
#define ATOMIC_OP_ALIAS_SIZE(a,s) WEAK_ALIAS(a,s ## _32)
#endif
+#ifdef _LIBC
+#define CRT_ALIAS(a,s) STRONG_ALIAS(a,s)
+#endif
+
#endif /* _KERNEL */
#ifdef __arch64__
diff -r 88c2ae44fee4 -r 112c718b711c common/lib/libc/arch/sparc64/atomic/atomic_or.S
--- a/common/lib/libc/arch/sparc64/atomic/atomic_or.S Sun Oct 18 00:39:14 2015 +0000
+++ b/common/lib/libc/arch/sparc64/atomic/atomic_or.S Sun Oct 18 02:28:07 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: atomic_or.S,v 1.7 2008/05/25 15:56:12 chs Exp $ */
+/* $NetBSD: atomic_or.S,v 1.8 2015/10/18 02:28:07 nakayama Exp $ */
/*-
* Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -52,14 +52,22 @@
STRONG_ALIAS(_atomic_or_uint_nv,_atomic_or_32)
ENTRY(_atomic_or_64)
+#ifndef __arch64__
+ COMBINE(%o1, %o2, %o1)
+#endif
ldx [%o0], %o2
1: or %o1, %o2, %o3
casx [%o0], %o2, %o3
cmp %o2, %o3
bne,a,pn %xcc, 1b
mov %o3, %o2
+#ifdef __arch64__
retl
or %o1, %o2, %o0
+#else
+ or %o1, %o2, %o0
+ SPLIT_RETL(%o0, %o0, %o1)
+#endif
ATOMIC_OP_ALIAS(atomic_or_64,_atomic_or_64)
ATOMIC_OP_ALIAS(atomic_or_64_nv,_atomic_or_64)
@@ -70,3 +78,19 @@
ATOMIC_OP_ALIAS_SIZE(atomic_or_ulong_nv,_atomic_or)
STRONG_ALIAS_SIZE(_atomic_or_ulong_nv,_atomic_or)
+
+#if !defined(__arch64__) && defined(CRT_ALIAS)
+ENTRY(__sync_fetch_and_or_8)
+ COMBINE(%o1, %o2, %o1)
+ ldx [%o0], %o2
+1: or %o1, %o2, %o3
+ casx [%o0], %o2, %o3
+ cmp %o2, %o3
+ bne,a,pn %xcc, 1b
+ mov %o3, %o2
+ SPLIT_RETL(%o2, %o0, %o1)
+CRT_ALIAS(__sync_or_and_fetch_8,_atomic_or_64_nv)
+
+CRT_ALIAS(__atomic_fetch_or_8,__sync_fetch_and_or_8)
+CRT_ALIAS(__atomic_or_fetch_8,__sync_or_and_fetch_8)
+#endif
diff -r 88c2ae44fee4 -r 112c718b711c common/lib/libc/arch/sparc64/atomic/atomic_swap.S
--- a/common/lib/libc/arch/sparc64/atomic/atomic_swap.S Sun Oct 18 00:39:14 2015 +0000
+++ b/common/lib/libc/arch/sparc64/atomic/atomic_swap.S Sun Oct 18 02:28:07 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: atomic_swap.S,v 1.6 2008/05/25 15:56:12 chs Exp $ */
+/* $NetBSD: atomic_swap.S,v 1.7 2015/10/18 02:28:07 nakayama Exp $ */
/*-
* Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -47,17 +47,29 @@
STRONG_ALIAS(_atomic_swap_uint,_atomic_swap_32)
ENTRY(_atomic_swap_64)
+#ifndef __arch64__
+ COMBINE(%o1, %o2, %o1)
+#endif
ldx [%o0], %o2
1: mov %o1, %o3
casx [%o0], %o2, %o3
cmp %o2, %o3
bne,a,pn %xcc, 1b
Home |
Main Index |
Thread Index |
Old Index