| 1 | #ifndef _URCU_ARCH_UATOMIC_SPARC64_H |
| 2 | #define _URCU_ARCH_UATOMIC_SPARC64_H |
| 3 | |
| 4 | /* |
| 5 | * Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved. |
| 6 | * Copyright (c) 1996-1999 by Silicon Graphics. All rights reserved. |
| 7 | * Copyright (c) 1999-2003 by Hewlett-Packard Company. All rights reserved. |
| 8 | * Copyright (c) 2009 Mathieu Desnoyers |
| 9 | * |
| 10 | * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED |
| 11 | * OR IMPLIED. ANY USE IS AT YOUR OWN RISK. |
| 12 | * |
| 13 | * Permission is hereby granted to use or copy this program |
| 14 | * for any purpose, provided the above notices are retained on all copies. |
| 15 | * Permission to modify the code and to distribute modified code is granted, |
| 16 | * provided the above notices are retained, and a notice that the code was |
| 17 | * modified is included with the above copyright notice. |
| 18 | * |
| 19 | * Code inspired from libuatomic_ops-1.2, inherited in part from the |
| 20 | * Boehm-Demers-Weiser conservative garbage collector. |
| 21 | */ |
| 22 | |
| 23 | #include <urcu/compiler.h> |
| 24 | #include <urcu/system.h> |
| 25 | |
| 26 | #ifdef __cplusplus |
| 27 | extern "C" { |
| 28 | #endif |
| 29 | |
| 30 | #ifndef __SIZEOF_LONG__ |
| 31 | #ifdef __LP64__ |
| 32 | #define __SIZEOF_LONG__ 8 |
| 33 | #else |
| 34 | #define __SIZEOF_LONG__ 4 |
| 35 | #endif |
| 36 | #endif |
| 37 | |
| 38 | #ifndef BITS_PER_LONG |
| 39 | #define BITS_PER_LONG (__SIZEOF_LONG__ * 8) |
| 40 | #endif |
| 41 | |
| 42 | /* cmpxchg */ |
| 43 | |
| 44 | static inline __attribute__((always_inline)) |
| 45 | unsigned long _uatomic_cmpxchg(void *addr, unsigned long old, |
| 46 | unsigned long _new, int len) |
| 47 | { |
| 48 | switch (len) { |
| 49 | case 4: |
| 50 | { |
| 51 | __asm__ __volatile__ ( |
| 52 | "membar #StoreLoad | #LoadLoad\n\t" |
| 53 | "cas [%1],%2,%0\n\t" |
| 54 | "membar #StoreLoad | #StoreStore\n\t" |
| 55 | : "+&r" (_new) |
| 56 | : "r" (addr), "r" (old) |
| 57 | : "memory"); |
| 58 | |
| 59 | return _new; |
| 60 | } |
| 61 | #if (BITS_PER_LONG == 64) |
| 62 | case 8: |
| 63 | { |
| 64 | __asm__ __volatile__ ( |
| 65 | "membar #StoreLoad | #LoadLoad\n\t" |
| 66 | "casx [%1],%2,%0\n\t" |
| 67 | "membar #StoreLoad | #StoreStore\n\t" |
| 68 | : "+&r" (_new) |
| 69 | : "r" (addr), "r" (old) |
| 70 | : "memory"); |
| 71 | |
| 72 | return _new; |
| 73 | } |
| 74 | #endif |
| 75 | } |
| 76 | __builtin_trap(); |
| 77 | return 0; |
| 78 | } |
| 79 | |
| 80 | |
| 81 | #define uatomic_cmpxchg(addr, old, _new) \ |
| 82 | ((__typeof__(*(addr))) _uatomic_cmpxchg((addr), (unsigned long)(old),\ |
| 83 | (unsigned long)(_new), \ |
| 84 | sizeof(*(addr)))) |
| 85 | |
| 86 | #ifdef __cplusplus |
| 87 | } |
| 88 | #endif |
| 89 | |
| 90 | #include <urcu/uatomic_generic.h> |
| 91 | |
| 92 | #endif /* _URCU_ARCH_UATOMIC_PPC_H */ |