]> git.karo-electronics.de Git - mv-sheeva.git/commitdiff
sh: consolidate atomic_cmpxchg()/atomic_add_unless() definitions.
authorPaul Mundt <lethal@linux-sh.org>
Fri, 8 Jan 2010 08:02:17 +0000 (17:02 +0900)
committerPaul Mundt <lethal@linux-sh.org>
Fri, 8 Jan 2010 08:02:17 +0000 (17:02 +0900)
The LL/SC and IRQ versions were using generic stubs while the GRB version
was just reimplementing what it already had for the standard cmpxchg()
code. As we have optimized cmpxchg() implementations that are decoupled
from the atomic code, simply falling back on the generic wrapper does the
right thing. With this in place the GRB case is unaffected while the
LL/SC case gets to use its optimized cmpxchg().

Signed-off-by: Paul Mundt <lethal@linux-sh.org>
arch/sh/include/asm/atomic-grb.h
arch/sh/include/asm/atomic-llsc.h
arch/sh/include/asm/atomic.h

index 4c5b7dbfcedb1deb80a759799cd2d5de1e3402ee..a273c88578fc99d81cc4a2879d628372349b8fbd 100644 (file)
@@ -120,50 +120,4 @@ static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
                : "memory" , "r0", "r1");
 }
 
-static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
-{
-       int ret;
-
-       __asm__ __volatile__ (
-               "   .align 2            \n\t"
-               "   mova     1f,  r0    \n\t"
-               "   nop                 \n\t"
-               "   mov     r15,  r1    \n\t"
-               "   mov    #-8,  r15    \n\t"
-               "   mov.l   @%1,  %0    \n\t"
-               "   cmp/eq   %2,  %0    \n\t"
-               "   bf       1f         \n\t"
-               "   mov.l    %3, @%1    \n\t"
-               "1: mov      r1,  r15   \n\t"
-               : "=&r" (ret)
-               : "r" (v), "r" (old), "r" (new)
-               : "memory" , "r0", "r1" , "t");
-
-       return ret;
-}
-
-static inline int atomic_add_unless(atomic_t *v, int a, int u)
-{
-       int ret;
-       unsigned long tmp;
-
-       __asm__ __volatile__ (
-               "   .align 2            \n\t"
-               "   mova    1f,   r0    \n\t"
-               "   nop                 \n\t"
-               "   mov    r15,   r1    \n\t"
-               "   mov    #-12,  r15   \n\t"
-               "   mov.l  @%2,   %1    \n\t"
-               "   mov     %1,   %0    \n\t"
-               "   cmp/eq  %4,   %0    \n\t"
-               "   bt/s    1f          \n\t"
-               "    add    %3,   %1    \n\t"
-               "   mov.l   %1,  @%2    \n\t"
-               "1: mov     r1,   r15   \n\t"
-               : "=&r" (ret), "=&r" (tmp)
-               : "r" (v), "r" (a), "r" (u)
-               : "memory" , "r0", "r1" , "t");
-
-       return ret != u;
-}
 #endif /* __ASM_SH_ATOMIC_GRB_H */
index b040e1e086108c606c6da8ecbd712b0dca2b1734..4b00b78e3f4f3a6a5be4a70a924123c84f32c895 100644 (file)
@@ -104,31 +104,4 @@ static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
        : "t");
 }
 
-#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
-
-/**
- * atomic_add_unless - add unless the number is a given value
- * @v: pointer of type atomic_t
- * @a: the amount to add to v...
- * @u: ...unless v is equal to u.
- *
- * Atomically adds @a to @v, so long as it was not @u.
- * Returns non-zero if @v was not @u, and zero otherwise.
- */
-static inline int atomic_add_unless(atomic_t *v, int a, int u)
-{
-       int c, old;
-       c = atomic_read(v);
-       for (;;) {
-               if (unlikely(c == (u)))
-                       break;
-               old = atomic_cmpxchg((v), c, c + (a));
-               if (likely(old == c))
-                       break;
-               c = old;
-       }
-
-       return c != (u);
-}
-
 #endif /* __ASM_SH_ATOMIC_LLSC_H */
index b16388d719546a3c2cdb70e2b1a94eec897a180e..275a448ae8c27bd38bb6cd19fbe7280d8b54198a 100644 (file)
 #endif
 
 #define atomic_add_negative(a, v)      (atomic_add_return((a), (v)) < 0)
+#define atomic_dec_return(v)           atomic_sub_return(1, (v))
+#define atomic_inc_return(v)           atomic_add_return(1, (v))
+#define atomic_inc_and_test(v)         (atomic_inc_return(v) == 0)
+#define atomic_sub_and_test(i,v)       (atomic_sub_return((i), (v)) == 0)
+#define atomic_dec_and_test(v)         (atomic_sub_return(1, (v)) == 0)
+#define atomic_inc_not_zero(v)         atomic_add_unless((v), 1, 0)
 
-#define atomic_dec_return(v) atomic_sub_return(1,(v))
-#define atomic_inc_return(v) atomic_add_return(1,(v))
+#define atomic_inc(v)                  atomic_add(1, (v))
+#define atomic_dec(v)                  atomic_sub(1, (v))
 
-/*
- * atomic_inc_and_test - increment and test
+#define atomic_xchg(v, new)            (xchg(&((v)->counter), new))
+#define atomic_cmpxchg(v, o, n)                (cmpxchg(&((v)->counter), (o), (n)))
+
+/**
+ * atomic_add_unless - add unless the number is a given value
  * @v: pointer of type atomic_t
+ * @a: the amount to add to v...
+ * @u: ...unless v is equal to u.
  *
- * Atomically increments @v by 1
- * and returns true if the result is zero, or false for all
- * other cases.
+ * Atomically adds @a to @v, so long as it was not @u.
+ * Returns non-zero if @v was not @u, and zero otherwise.
  */
-#define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
-
-#define atomic_sub_and_test(i,v) (atomic_sub_return((i), (v)) == 0)
-#define atomic_dec_and_test(v) (atomic_sub_return(1, (v)) == 0)
-
-#define atomic_inc(v) atomic_add(1,(v))
-#define atomic_dec(v) atomic_sub(1,(v))
-
-#if !defined(CONFIG_GUSA_RB) && !defined(CONFIG_CPU_SH4A)
-static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
-{
-       int ret;
-       unsigned long flags;
-
-       local_irq_save(flags);
-       ret = v->counter;
-       if (likely(ret == old))
-               v->counter = new;
-       local_irq_restore(flags);
-
-       return ret;
-}
-
 static inline int atomic_add_unless(atomic_t *v, int a, int u)
 {
-       int ret;
-       unsigned long flags;
-
-       local_irq_save(flags);
-       ret = v->counter;
-       if (ret != u)
-               v->counter += a;
-       local_irq_restore(flags);
-
-       return ret != u;
+       int c, old;
+       c = atomic_read(v);
+       for (;;) {
+               if (unlikely(c == (u)))
+                       break;
+               old = atomic_cmpxchg((v), c, c + (a));
+               if (likely(old == c))
+                       break;
+               c = old;
+       }
+
+       return c != (u);
 }
-#endif /* !CONFIG_GUSA_RB && !CONFIG_CPU_SH4A */
-
-#define atomic_xchg(v, new) (xchg(&((v)->counter), new))
-#define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
 
 #define smp_mb__before_atomic_dec()    smp_mb()
 #define smp_mb__after_atomic_dec()     smp_mb()