From: Hirokazu Takata Upgrade include/asm-m32r/atomic.h. * include/asm-m32r/atomic.h - Change atomic_add(), atomic_sub(), atomic_inc() and atomic_dec() from function to macro. - Change not to use fixed woking register in atomic_clear_mask() and atomic_set_mask(). - Update comments: "return" to "return it", and so on. Signed-off-by: Hirokazu Takata Signed-off-by: Andrew Morton --- 25-akpm/include/asm-m32r/atomic.h | 180 +++++++++++--------------------------- 1 files changed, 53 insertions(+), 127 deletions(-) diff -puN include/asm-m32r/atomic.h~m32r-upgrade-include-asm-m32r-atomich include/asm-m32r/atomic.h --- 25/include/asm-m32r/atomic.h~m32r-upgrade-include-asm-m32r-atomich 2004-09-15 20:26:43.104046368 -0700 +++ 25-akpm/include/asm-m32r/atomic.h 2004-09-15 20:26:43.108045760 -0700 @@ -54,63 +54,7 @@ typedef struct { volatile int counter; } #define atomic_set(v,i) (((v)->counter) = (i)) /** - * atomic_add - add integer to atomic variable - * @i: integer value to add - * @v: pointer of type atomic_t - * - * Atomically adds @i to @v. - */ -static inline void atomic_add(int i, atomic_t *v) -{ - unsigned long flags; - - local_irq_save(flags); - __asm__ __volatile__ ( - "# atomic_add \n\t" - DCACHE_CLEAR("r4", "r5", "%0") - LOAD" r4, @%0; \n\t" - "add r4, %1; \n\t" - STORE" r4, @%0; \n\t" - : /* no outputs */ - : "r" (&v->counter), "r" (i) - : "memory", "r4" -#ifdef CONFIG_CHIP_M32700_TS1 - , "r5" -#endif /* CONFIG_CHIP_M32700_TS1 */ - ); - local_irq_restore(flags); -} - -/** - * atomic_sub - subtract the atomic variable - * @i: integer value to subtract - * @v: pointer of type atomic_t - * - * Atomically subtracts @i from @v. - */ -static inline void atomic_sub(int i, atomic_t *v) -{ - unsigned long flags; - - local_irq_save(flags); - __asm__ __volatile__ ( - "# atomic_sub \n\t" - DCACHE_CLEAR("r4", "r5", "%0") - LOAD" r4, @%0; \n\t" - "sub r4, %1; \n\t" - STORE" r4, @%0; \n\t" - : /* no outputs */ - : "r" (&v->counter), "r" (i) - : "memory", "r4" -#ifdef CONFIG_CHIP_M32700_TS1 - , "r5" -#endif /* CONFIG_CHIP_M32700_TS1 */ - ); - local_irq_restore(flags); -} - -/** - * atomic_add_return - add integer to atomic variable and return + * atomic_add_return - add integer to atomic variable and return it * @i: integer value to add * @v: pointer of type atomic_t * @@ -123,7 +67,7 @@ static inline int atomic_add_return(int local_irq_save(flags); __asm__ __volatile__ ( - "# atomic_add \n\t" + "# atomic_add_return \n\t" DCACHE_CLEAR("%0", "r4", "%1") LOAD" %0, @%1; \n\t" "add %0, %2; \n\t" @@ -141,7 +85,7 @@ static inline int atomic_add_return(int } /** - * atomic_sub_return - subtract the atomic variable and return + * atomic_sub_return - subtract integer from atomic variable and return it * @i: integer value to subtract * @v: pointer of type atomic_t * @@ -154,7 +98,7 @@ static inline int atomic_sub_return(int local_irq_save(flags); __asm__ __volatile__ ( - "# atomic_sub \n\t" + "# atomic_sub_return \n\t" DCACHE_CLEAR("%0", "r4", "%1") LOAD" %0, @%1; \n\t" "sub %0, %2; \n\t" @@ -172,72 +116,36 @@ static inline int atomic_sub_return(int } /** - * atomic_sub_and_test - subtract value from variable and test result - * @i: integer value to subtract + * atomic_add - add integer to atomic variable + * @i: integer value to add * @v: pointer of type atomic_t * - * Atomically subtracts @i from @v and returns - * true if the result is zero, or false for all - * other cases. + * Atomically adds @i to @v. */ -#define atomic_sub_and_test(i,v) (atomic_sub_return((i), (v)) == 0) +#define atomic_add(i,v) ((void) atomic_add_return((i), (v))) /** - * atomic_inc - increment atomic variable + * atomic_sub - subtract the atomic variable + * @i: integer value to subtract * @v: pointer of type atomic_t * - * Atomically increments @v by 1. + * Atomically subtracts @i from @v. */ -static inline void atomic_inc(atomic_t *v) -{ - unsigned long flags; - - local_irq_save(flags); - __asm__ __volatile__ ( - "# atomic_inc \n\t" - DCACHE_CLEAR("r4", "r5", "%0") - LOAD" r4, @%0; \n\t" - "addi r4, #1; \n\t" - STORE" r4, @%0; \n\t" - : /* no outputs */ - : "r" (&v->counter) - : "memory", "r4" -#ifdef CONFIG_CHIP_M32700_TS1 - , "r5" -#endif /* CONFIG_CHIP_M32700_TS1 */ - ); - local_irq_restore(flags); -} +#define atomic_sub(i,v) ((void) atomic_sub_return((i), (v))) /** - * atomic_dec - decrement atomic variable + * atomic_sub_and_test - subtract value from variable and test result + * @i: integer value to subtract * @v: pointer of type atomic_t * - * Atomically decrements @v by 1. + * Atomically subtracts @i from @v and returns + * true if the result is zero, or false for all + * other cases. */ -static inline void atomic_dec(atomic_t *v) -{ - unsigned long flags; - - local_irq_save(flags); - __asm__ __volatile__ ( - "# atomic_dec \n\t" - DCACHE_CLEAR("r4", "r5", "%0") - LOAD" r4, @%0; \n\t" - "addi r4, #-1; \n\t" - STORE" r4, @%0; \n\t" - : /* no outputs */ - : "r" (&v->counter) - : "memory", "r4" -#ifdef CONFIG_CHIP_M32700_TS1 - , "r5" -#endif /* CONFIG_CHIP_M32700_TS1 */ - ); - local_irq_restore(flags); -} +#define atomic_sub_and_test(i,v) (atomic_sub_return((i), (v)) == 0) /** - * atomic_inc_return - increment atomic variable and return + * atomic_inc_return - increment atomic variable and return it * @v: pointer of type atomic_t * * Atomically increments @v by 1 and returns the result. @@ -249,7 +157,7 @@ static inline int atomic_inc_return(atom local_irq_save(flags); __asm__ __volatile__ ( - "# atomic_dec_and_test \n\t" + "# atomic_inc_return \n\t" DCACHE_CLEAR("%0", "r4", "%1") LOAD" %0, @%1; \n\t" "addi %0, #1; \n\t" @@ -267,7 +175,7 @@ static inline int atomic_inc_return(atom } /** - * atomic_dec_return - decrement atomic variable and return + * atomic_dec_return - decrement atomic variable and return it * @v: pointer of type atomic_t * * Atomically decrements @v by 1 and returns the result. @@ -279,7 +187,7 @@ static inline int atomic_dec_return(atom local_irq_save(flags); __asm__ __volatile__ ( - "# atomic_dec_and_test \n\t" + "# atomic_dec_return \n\t" DCACHE_CLEAR("%0", "r4", "%1") LOAD" %0, @%1; \n\t" "addi %0, #-1; \n\t" @@ -297,6 +205,22 @@ static inline int atomic_dec_return(atom } /** + * atomic_inc - increment atomic variable + * @v: pointer of type atomic_t + * + * Atomically increments @v by 1. + */ +#define atomic_inc(v) ((void)atomic_inc_return(v)) + +/** + * atomic_dec - decrement atomic variable + * @v: pointer of type atomic_t + * + * Atomically decrements @v by 1. + */ +#define atomic_dec(v) ((void)atomic_dec_return(v)) + +/** * atomic_inc_and_test - increment and test * @v: pointer of type atomic_t * @@ -330,17 +254,18 @@ static inline int atomic_dec_return(atom static inline void atomic_clear_mask(unsigned long mask, atomic_t *addr) { unsigned long flags; + unsigned long tmp; local_irq_save(flags); __asm__ __volatile__ ( - "# atomic_set_mask \n\t" - DCACHE_CLEAR("r4", "r5", "%0") - LOAD" r4, @%0; \n\t" - "and r4, %1; \n\t" - STORE" r4, @%0; \n\t" - : /* no outputs */ + "# atomic_clear_mask \n\t" + DCACHE_CLEAR("%0", "r5", "%1") + LOAD" %0, @%1; \n\t" + "and %0, %2; \n\t" + STORE" %0, @%1; \n\t" + : "=&r" (tmp) : "r" (addr), "r" (~mask) - : "memory", "r4" + : "memory" #ifdef CONFIG_CHIP_M32700_TS1 , "r5" #endif /* CONFIG_CHIP_M32700_TS1 */ @@ -351,17 +276,18 @@ static inline void atomic_clear_mask(uns static inline void atomic_set_mask(unsigned long mask, atomic_t *addr) { unsigned long flags; + unsigned long tmp; local_irq_save(flags); __asm__ __volatile__ ( "# atomic_set_mask \n\t" - DCACHE_CLEAR("r4", "r5", "%0") - LOAD" r4, @%0; \n\t" - "or r4, %1; \n\t" - STORE" r4, @%0; \n\t" - : /* no outputs */ + DCACHE_CLEAR("%0", "r5", "%1") + LOAD" %0, @%1; \n\t" + "or %0, %2; \n\t" + STORE" %0, @%1; \n\t" + : "=&r" (tmp) : "r" (addr), "r" (mask) - : "memory", "r4" + : "memory" #ifdef CONFIG_CHIP_M32700_TS1 , "r5" #endif /* CONFIG_CHIP_M32700_TS1 */ _