Add a few __sync_* and atomic functions.

This commit is contained in:
martin 2014-02-18 16:19:28 +00:00
parent 1a7bc9a039
commit 0ac513ac84
3 changed files with 123 additions and 3 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: atomic_add.S,v 1.6 2013/07/16 23:24:18 matt Exp $ */
/* $NetBSD: atomic_add.S,v 1.7 2014/02/18 16:19:28 martin Exp $ */
/*-
* Copyright (c) 2007 The NetBSD Foundation, Inc.
@ -66,3 +66,28 @@ ATOMIC_OP_ALIAS(atomic_add_long_nv,_atomic_add_32_nv)
STRONG_ALIAS(_atomic_add_long_nv,_atomic_add_32_nv)
ATOMIC_OP_ALIAS(atomic_add_ptr_nv,_atomic_add_32_nv)
STRONG_ALIAS(_atomic_add_ptr_nv,_atomic_add_32_nv)
STRONG_ALIAS(__sync_add_and_fetch_4,_atomic_add_32_nv)
ENTRY(_atomic_add_16_nv)
movl 4(%sp), %a0
1: movw (%a0), %d0
movw %d0, %d1
addw 8(%sp), %d0
casw %d1, %d0, (%a0)
bne 1b
rts
END(_atomic_add_16_nv)
STRONG_ALIAS(__sync_add_and_fetch_2,_atomic_add_16_nv)
ENTRY(_atomic_add_8_nv)
movl 4(%sp), %a0
1: movb (%a0), %d0
movb %d0, %d1
addb 8(%sp), %d0
casb %d1, %d0, (%a0)
bne 1b
rts
END(_atomic_add_8_nv)
STRONG_ALIAS(__sync_add_and_fetch_1,_atomic_add_8_nv)

View File

@ -1,4 +1,4 @@
/* $NetBSD: atomic_cas.S,v 1.7 2013/07/16 23:24:18 matt Exp $ */
/* $NetBSD: atomic_cas.S,v 1.8 2014/02/18 16:19:28 martin Exp $ */
/*-
* Copyright (c) 2007, 2008 The NetBSD Foundation, Inc.
@ -50,6 +50,7 @@ ATOMIC_OP_ALIAS(atomic_cas_ulong,_atomic_cas_32)
STRONG_ALIAS(_atomic_cas_ulong,_atomic_cas_32)
ATOMIC_OP_ALIAS(atomic_cas_ptr,_atomic_cas_32)
STRONG_ALIAS(_atomic_cas_ptr,_atomic_cas_32)
STRONG_ALIAS(__sync_val_compare_and_swap_4,_atomic_cas_32)
ATOMIC_OP_ALIAS(atomic_cas_32_ni,_atomic_cas_32)
STRONG_ALIAS(_atomic_cas_32_ni,_atomic_cas_32)
@ -59,3 +60,71 @@ ATOMIC_OP_ALIAS(atomic_cas_ulong_ni,_atomic_cas_32)
STRONG_ALIAS(_atomic_cas_ulong_ni,_atomic_cas_32)
ATOMIC_OP_ALIAS(atomic_cas_ptr_ni,_atomic_cas_32)
STRONG_ALIAS(_atomic_cas_ptr_ni,_atomic_cas_32)
ENTRY(__sync_bool_compare_and_swap_4)
movl 4(%sp), %a0
movl 8(%sp), %d3
movl %d3, %d2
movl 12(%sp), %d1
casl %d3, %d1, (%a0)
/* %d3 now contains the old value */
clrl %d0 /* assume it did not work */
cmpl %d3, %d2
bne 1f
movl #1, %d0 /* return success */
1: rts
END(__sync_bool_compare_and_swap_4)
ENTRY(_atomic_cas_16)
movl 4(%sp), %a0
movw 8(%sp), %d0
movw 10(%sp), %d1
casw %d0, %d1, (%a0)
/* %d0 now contains the old value */
rts
END(_atomic_cas_16)
ATOMIC_OP_ALIAS(atomic_cas_16,_atomic_cas_16)
STRONG_ALIAS(__sync_val_compare_and_swap_2,_atomic_cas_16)
ENTRY(__sync_bool_compare_and_swap_2)
movl 4(%sp), %a0
movw 8(%sp), %d3
movw %d3, %d2
movw 10(%sp), %d1
casw %d3, %d1, (%a0)
/* %d3 now contains the old value */
clrl %d0 /* assume it did not work */
cmpw %d3, %d2
bne 1f
movl #1, %d0 /* return success */
1: rts
END(__sync_bool_compare_and_swap_2)
ENTRY(_atomic_cas_8)
movl 4(%sp), %a0
movb 8(%sp), %d0
movb 9(%sp), %d1
casb %d0, %d1, (%a0)
/* %d0 now contains the old value */
rts
END(_atomic_cas_8)
ATOMIC_OP_ALIAS(atomic_cas_8,_atomic_cas_8)
STRONG_ALIAS(__sync_val_compare_and_swap_1,_atomic_cas_8)
ENTRY(__sync_bool_compare_and_swap_1)
movl 4(%sp), %a0
movb 8(%sp), %d3
movb %d3, %d2
movb 9(%sp), %d1
casb %d3, %d1, (%a0)
/* %d3 now contains the old value */
clrl %d0 /* assume it did not work */
cmpb %d3, %d2
bne 1f
movl #1, %d0 /* return success */
1: rts
END(__sync_bool_compare_and_swap_1)

View File

@ -1,4 +1,4 @@
/* $NetBSD: atomic_swap.S,v 1.6 2013/07/16 23:24:18 matt Exp $ */
/* $NetBSD: atomic_swap.S,v 1.7 2014/02/18 16:19:28 martin Exp $ */
/*-
* Copyright (c) 2007 The NetBSD Foundation, Inc.
@ -50,3 +50,29 @@ ATOMIC_OP_ALIAS(atomic_swap_ulong,_atomic_swap_32)
STRONG_ALIAS(_atomic_swap_ulong,_atomic_swap_32)
ATOMIC_OP_ALIAS(atomic_swap_ptr,_atomic_swap_32)
STRONG_ALIAS(_atomic_swap_ptr,_atomic_swap_32)
STRONG_ALIAS(__sync_lock_test_and_set_4,_atomic_swap_32)
ENTRY(_atomic_swap_16)
movl 4(%sp), %a0
1: movw (%a0), %d0
movw 8(%sp), %d1
casw %d0, %d1, (%a0)
bne 1b
/* %d0 now contains the old value */
rts
END(_atomic_swap_16)
ATOMIC_OP_ALIAS(atomic_swap_16,_atomic_swap_16)
STRONG_ALIAS(__sync_lock_test_and_set_2,_atomic_swap_16)
ENTRY(_atomic_swap_8)
movl 4(%sp), %a0
1: movb (%a0), %d0
movb 8(%sp), %d1
casb %d0, %d1, (%a0)
bne 1b
/* %d0 now contains the old value */
rts
END(_atomic_swap_8)
ATOMIC_OP_ALIAS(atomic_swap_8,_atomic_swap_8)
STRONG_ALIAS(__sync_lock_test_and_set_1,_atomic_swap_8)