<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Nov 17, 2014 at 12:20 PM, Axel Davy <span dir="ltr"><<a href="mailto:axel.davy@ens.fr" target="_blank">axel.davy@ens.fr</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">From: Christoph Bumiller <<a href="mailto:christoph.bumiller@speed.at">christoph.bumiller@speed.at</a>><br>
<br>
At this moment we use only zero or positive values.<br>
<br>
v2: Implement it for also for Solaris, MSVC assembly<br>
and enable for other combinations.<br>
<br>
v3: Replace MSVC assembly by assert + warning during compilation<br>
<br>
Signed-off-by: David Heidelberg <<a href="mailto:david@ixit.cz">david@ixit.cz</a>><br>
---<br>
src/gallium/auxiliary/util/u_atomic.h | 72 +++++++++++++++++++++++++++++++++++<br>
1 file changed, 72 insertions(+)<br>
<br>
diff --git a/src/gallium/auxiliary/util/u_atomic.h b/src/gallium/auxiliary/util/u_atomic.h<br>
index 2f2b42b..9279073 100644<br>
--- a/src/gallium/auxiliary/util/u_atomic.h<br>
+++ b/src/gallium/auxiliary/util/u_atomic.h<br>
@@ -69,6 +69,18 @@ p_atomic_dec(int32_t *v)<br>
}<br>
<br>
static INLINE int32_t<br>
+p_atomic_inc_return(int32_t *v)<br>
+{<br>
+ return __sync_add_and_fetch(v, 1);<br>
+}<br>
+<br>
+static INLINE int32_t<br>
+p_atomic_dec_return(int32_t *v)<br>
+{<br>
+ return __sync_sub_and_fetch(v, 1);<br>
+}<br>
+<br>
+static INLINE int32_t<br>
p_atomic_cmpxchg(int32_t *v, int32_t old, int32_t _new)<br>
{<br>
return __sync_val_compare_and_swap(v, old, _new);<br>
@@ -116,6 +128,18 @@ p_atomic_dec(int32_t *v)<br>
}<br>
<br>
static INLINE int32_t<br>
+p_atomic_inc_return(int32_t *v)<br>
+{<br>
+ return __sync_add_and_fetch(v, 1);<br>
+}<br>
+<br>
+static INLINE int32_t<br>
+p_atomic_dec_return(int32_t *v)<br>
+{<br>
+ return __sync_sub_and_fetch(v, 1);<br>
+}<br>
+<br>
+static INLINE int32_t<br>
p_atomic_cmpxchg(int32_t *v, int32_t old, int32_t _new)<br>
{<br>
return __sync_val_compare_and_swap(v, old, _new);<br>
@@ -161,6 +185,18 @@ p_atomic_dec(int32_t *v)<br>
}<br>
<br>
static INLINE int32_t<br>
+p_atomic_inc_return(int32_t *v)<br>
+{<br>
+ return __sync_add_and_fetch(v, 1);<br>
+}<br>
+<br>
+static INLINE int32_t<br>
+p_atomic_dec_return(int32_t *v)<br>
+{<br>
+ return __sync_sub_and_fetch(v, 1);<br>
+}<br>
+<br>
+static INLINE int32_t<br>
p_atomic_cmpxchg(int32_t *v, int32_t old, int32_t _new)<br>
{<br>
return __sync_val_compare_and_swap(v, old, _new);<br>
@@ -186,6 +222,8 @@ p_atomic_cmpxchg(int32_t *v, int32_t old, int32_t _new)<br>
#define p_atomic_dec_zero(_v) ((boolean) --(*(_v)))<br>
#define p_atomic_inc(_v) ((void) (*(_v))++)<br>
#define p_atomic_dec(_v) ((void) (*(_v))--)<br>
+#define p_atomic_inc_return(_v) ((*(_v))++)<br>
+#define p_atomic_dec_return(_v) ((*(_v))--)<br>
#define p_atomic_cmpxchg(_v, old, _new) (*(_v) == old ? *(_v) = (_new) : *(_v))<br>
<br>
#endif<br>
@@ -197,6 +235,8 @@ p_atomic_cmpxchg(int32_t *v, int32_t old, int32_t _new)<br>
<br>
#define PIPE_ATOMIC "MSVC x86 assembly"<br>
<br>
+#include <assert.h><br>
+<br>
#ifdef __cplusplus<br>
extern "C" {<br>
#endif<br>
@@ -236,6 +276,24 @@ p_atomic_dec(int32_t *v)<br>
}<br>
}<br>
<br>
+#pragma message ( "Warning: p_atomic_dec_return and p_atomic_inc_return unimplemented for PIPE_ATOMIC_ASM_MSVC_X86" )<br>
+<br>
+static INLINE int32_t<br>
+p_atomic_inc_return(int32_t *v)<br>
+{<br>
+ (void) v;<br>
+ assert(0);<br>
+ return 0;<br>
+}<br></blockquote><div><br></div><div>Why isn't _InterlockedIncrement() used here? It is used for the void functions. If you read the definition of _InterlockedIncrement() it returns the new value -- isn't that what is needed?</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
+static INLINE int32_t<br>
+p_atomic_dec_return(int32_t *v)<br>
+{<br>
+ (void) v;<br>
+ assert(0);<br>
+ return 0;<br>
+}<br></blockquote><div><br></div><div>Similarly here.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
static INLINE int32_t<br>
p_atomic_cmpxchg(int32_t *v, int32_t old, int32_t _new)<br>
{<br>
@@ -288,6 +346,12 @@ p_atomic_inc(int32_t *v)<br>
_InterlockedIncrement((long *)v);<br>
}<br>
<br>
+static INLINE int32_t<br>
+p_atomic_inc_return(int32_t *v)<br>
+{<br>
+ return _InterlockedIncrement((long *)v);<br>
+}<br>
+<br>
static INLINE void<br>
p_atomic_dec(int32_t *v)<br>
{<br>
@@ -295,6 +359,12 @@ p_atomic_dec(int32_t *v)<br>
}<br>
<br>
static INLINE int32_t<br>
+p_atomic_dec_return(int32_t *v)<br>
+{<br>
+ return _InterlockedDecrement((long *)v);<br>
+}<br>
+<br>
+static INLINE int32_t<br>
p_atomic_cmpxchg(int32_t *v, int32_t old, int32_t _new)<br>
{<br>
return _InterlockedCompareExchange((long *)v, _new, old);<br>
@@ -329,6 +399,8 @@ p_atomic_dec_zero(int32_t *v)<br>
<br>
#define p_atomic_inc(_v) atomic_inc_32((uint32_t *) _v)<br>
#define p_atomic_dec(_v) atomic_dec_32((uint32_t *) _v)<br>
+#define p_atomic_inc_return(_v) atomic_inc_32_nv((uint32_t *) _v)<br>
+#define p_atomic_dec_return(_v) atomic_dec_32_nv((uint32_t *) _v)<br>
<br>
#define p_atomic_cmpxchg(_v, _old, _new) \<br>
atomic_cas_32( (uint32_t *) _v, (uint32_t) _old, (uint32_t) _new)<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.1.0<br>
<br>
_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev" target="_blank">http://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div></div>