Fix 64-bit atomic operations on 32-bit kernel and userland, and add

support for missing __sync_*_8 builtins.
This commit is contained in:
nakayama 2015-10-18 02:28:07 +00:00
parent 91e54f1e4a
commit 2c01e1e121
9 changed files with 125 additions and 9 deletions

View File

@ -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 @@ SPARC64DIR= ${.PARSEDIR}/../../sparc64/atomic
.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)

View File

@ -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 @@ ATOMIC_OP_ALIAS(atomic_add_int_nv,_atomic_add_32)
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 @@ ATOMIC_OP_ALIAS_SIZE(atomic_add_long_nv,_atomic_add)
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

View File

@ -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 @@ ATOMIC_OP_ALIAS(atomic_and_uint_nv,_atomic_and_32)
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 @@ STRONG_ALIAS_SIZE(_atomic_and_ulong,_atomic_and)
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

View File

@ -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 @@ ATOMIC_OP_ALIAS(atomic_cas_uint_ni,_atomic_cas_32)
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 @@ ATOMIC_OP_ALIAS_SIZE(atomic_cas_ulong_ni,_atomic_cas)
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

View File

@ -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 @@ ENTRY(_atomic_dec_64)
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)

View File

@ -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 @@ ENTRY(_atomic_inc_64)
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)

View File

@ -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__

View File

@ -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 @@ ATOMIC_OP_ALIAS(atomic_or_uint_nv,_atomic_or_32)
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 @@ STRONG_ALIAS_SIZE(_atomic_or_ulong,_atomic_or)
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

View File

@ -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 @@ ATOMIC_OP_ALIAS(atomic_swap_uint,_atomic_swap_32)
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
mov %o3, %o2
#ifdef __arch64__
retl
mov %o3, %o0
#else
SPLIT_RETL(%o3, %o0, %o1)
#endif
ATOMIC_OP_ALIAS(atomic_swap_64,_atomic_swap_64)
ATOMIC_OP_ALIAS_SIZE(atomic_swap_ulong,_atomic_swap)
STRONG_ALIAS_SIZE(_atomic_swap_ulong,_atomic_swap)
ATOMIC_OP_ALIAS_SIZE(atomic_swap_ptr,_atomic_swap)
STRONG_ALIAS_SIZE(_atomic_swap_ptr,_atomic_swap)
#if !defined(__arch64__) && defined(CRT_ALIAS)
CRT_ALIAS(__sync_lock_test_and_set_8,_atomic_swap_64)
CRT_ALIAS(__atomic_exchange_8,_atomic_swap_64)
#endif