Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/common/lib/libc/atomic Add _atomic_cas_16 and _atomic_cas_8 ...



details:   https://anonhg.NetBSD.org/src/rev/de4e86a24a57
branches:  trunk
changeset: 326367:de4e86a24a57
user:      matt <matt%NetBSD.org@localhost>
date:      Mon Jan 27 18:03:44 2014 +0000

description:
Add _atomic_cas_16 and _atomic_cas_8 and their aliases
__sync_val_compare_and_swap_2 & __sync_val_compare_and_swap_1

diffstat:

 common/lib/libc/atomic/atomic_init_testset.c |  96 ++++++++++++++++++++++++++-
 1 files changed, 91 insertions(+), 5 deletions(-)

diffs (147 lines):

diff -r f1f11a762959 -r de4e86a24a57 common/lib/libc/atomic/atomic_init_testset.c
--- a/common/lib/libc/atomic/atomic_init_testset.c      Mon Jan 27 13:23:33 2014 +0000
+++ b/common/lib/libc/atomic/atomic_init_testset.c      Mon Jan 27 18:03:44 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: atomic_init_testset.c,v 1.9 2013/08/21 03:00:56 matt Exp $     */
+/*     $NetBSD: atomic_init_testset.c,v 1.10 2014/01/27 18:03:44 matt Exp $    */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: atomic_init_testset.c,v 1.9 2013/08/21 03:00:56 matt Exp $");
+__RCSID("$NetBSD: atomic_init_testset.c,v 1.10 2014/01/27 18:03:44 matt Exp $");
 
 #include "atomic_op_namespace.h"
 
@@ -59,14 +59,30 @@
 #else
 static uint32_t _atomic_cas_up(volatile uint32_t *, uint32_t, uint32_t);
 #endif
-
 static uint32_t (*_atomic_cas_fn)(volatile uint32_t *, uint32_t, uint32_t) =
     _atomic_cas_up;
+RAS_DECL(_atomic_cas);
+
+#ifdef __HAVE_ASM_ATOMIC_CAS_16_UP
+extern uint16_t _atomic_cas_16_up(volatile uint16_t *, uint16_t, uint16_t);
+#else
+static uint16_t _atomic_cas_16_up(volatile uint16_t *, uint16_t, uint16_t);
+#endif
+static uint16_t (*_atomic_cas_16_fn)(volatile uint16_t *, uint16_t, uint16_t) =
+    _atomic_cas_16_up;
+RAS_DECL(_atomic_cas_16);
+
+#ifdef __HAVE_ASM_ATOMIC_CAS_8_UP
+extern uint8_t _atomic_cas_8_up(volatile uint8_t *, uint8_t, uint8_t);
+#else
+static uint8_t _atomic_cas_8_up(volatile uint8_t *, uint8_t, uint8_t);
+#endif
+static uint8_t (*_atomic_cas_8_fn)(volatile uint8_t *, uint8_t, uint8_t) =
+    _atomic_cas_8_up;
+RAS_DECL(_atomic_cas_8);
 
 void   __libc_atomic_init(void) __attribute__ ((visibility("hidden")));
 
-RAS_DECL(_atomic_cas);
-
 #ifndef        __HAVE_ASM_ATOMIC_CAS_UP
 static uint32_t
 _atomic_cas_up(volatile uint32_t *ptr, uint32_t old, uint32_t new)
@@ -85,6 +101,42 @@
 }
 #endif
 
+#ifndef        __HAVE_ASM_ATOMIC_CAS_16_UP
+static uint16_t
+_atomic_cas_up_16(volatile uint16_t *ptr, uint16_t old, uint16_t new)
+{
+       uint16_t ret;
+
+       RAS_START(_atomic_cas_16);
+       ret = *ptr;
+       if (__predict_false(ret != old)) {
+               return ret;
+       }
+       *ptr = new;
+       RAS_END(_atomic_cas_16);
+
+       return ret;
+}
+#endif
+
+#ifndef        __HAVE_ASM_ATOMIC_CAS_UP
+static uint8_t
+_atomic_cas_up(volatile uint8_t *ptr, uint8_t old, uint8_t new)
+{
+       uint8_t ret;
+
+       RAS_START(_atomic_cas_8);
+       ret = *ptr;
+       if (__predict_false(ret != old)) {
+               return ret;
+       }
+       *ptr = new;
+       RAS_END(_atomic_cas_16);
+
+       return ret;
+}
+#endif
+
 static uint32_t
 _atomic_cas_mp(volatile uint32_t *ptr, uint32_t old, uint32_t new)
 {
@@ -109,6 +161,24 @@
        return (*_atomic_cas_fn)(ptr, old, new);
 }
 
+uint16_t _atomic_cas_16(volatile uint16_t *, uint16_t, uint16_t);
+
+uint16_t
+_atomic_cas_16(volatile uint16_t *ptr, uint16_t old, uint16_t new)
+{
+
+       return (*_atomic_cas_16_fn)(ptr, old, new);
+}
+
+uint8_t _atomic_cas_8(volatile uint8_t *, uint8_t, uint8_t);
+
+uint8_t
+_atomic_cas_8(volatile uint8_t *ptr, uint8_t old, uint8_t new)
+{
+
+       return (*_atomic_cas_8_fn)(ptr, old, new);
+}
+
 void __section(".text.startup")
 __libc_atomic_init(void)
 {
@@ -129,6 +199,18 @@
                _atomic_cas_fn = _atomic_cas_up;
                return;
        }
+
+       if (rasctl(RAS_ADDR(_atomic_cas_16), RAS_SIZE(_atomic_cas_16),
+           RAS_INSTALL) == 0) {
+               _atomic_cas_16_fn = _atomic_cas_16_up;
+               return;
+       }
+
+       if (rasctl(RAS_ADDR(_atomic_cas_8), RAS_SIZE(_atomic_cas_8),
+           RAS_INSTALL) == 0) {
+               _atomic_cas_8_fn = _atomic_cas_8_up;
+               return;
+       }
 }
 
 #undef atomic_cas_32
@@ -156,3 +238,7 @@
 __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)
+
+__strong_alias(__sync_val_compare_and_swap_4,_atomic_cas_32)
+__strong_alias(__sync_val_compare_and_swap_2,_atomic_cas_16)
+__strong_alias(__sync_val_compare_and_swap_1,_atomic_cas_8)



Home | Main Index | Thread Index | Old Index