Skip to content

Commit 7cc7eaa

Browse files
mrutland-armingomolnar
authored andcommitted
atomics/treewide: Clean up '*_andnot()' ifdeffery
The ifdeffery for atomic*_{fetch_,}andnot() is unlike that for all the other atomics. If atomic*_andnot() is not defined, the corresponding atomic*_fetch_andnot() is assumed to not be defined. Additionally, the fallbacks for the various ordering cases are written much later in atomic.h as static inlines. This isn't problematic today, but gets in the way of scripting the generation of atomics. To prepare for scripting, this patch: * Switches to separate ifdefs for atomic*_andnot() and atomic*_fetch_andnot(), updating implementations as appropriate. * Moves the fallbacks into the standards ifdefs, as macro expansions rather than static inlines. * Removes trivial andnot implementations from architectures, where these are superseded by core code. There should be no functional change as a result of this patch. Signed-off-by: Mark Rutland <mark.rutland@arm.com> Reviewed-by: Will Deacon <will.deacon@arm.com> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Boqun Feng <boqun.feng@gmail.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Thomas Gleixner <tglx@linutronix.de> Link: https://lore.kernel.org/lkml/20180621121321.4761-19-mark.rutland@arm.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent b3a2a05 commit 7cc7eaa

3 files changed

Lines changed: 36 additions & 70 deletions

File tree

‎arch/arc/include/asm/atomic.h‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,8 @@ static inline int atomic_fetch_##op(int i, atomic_t *v) \
187187
ATOMIC_OPS(add, +=, add)
188188
ATOMIC_OPS(sub, -=, sub)
189189

190-
#define atomic_andnot atomic_andnot
190+
#define atomic_andnot atomic_andnot
191+
#define atomic_fetch_andnot atomic_fetch_andnot
191192

192193
#undef ATOMIC_OPS
193194
#define ATOMIC_OPS(op, c_op, asm_op) \
@@ -296,8 +297,6 @@ ATOMIC_OPS(add, +=, CTOP_INST_AADD_DI_R2_R2_R3)
296297
ATOMIC_FETCH_OP(op, c_op, asm_op)
297298

298299
ATOMIC_OPS(and, &=, CTOP_INST_AAND_DI_R2_R2_R3)
299-
#define atomic_andnot(mask, v) atomic_and(~(mask), (v))
300-
#define atomic_fetch_andnot(mask, v) atomic_fetch_and(~(mask), (v))
301300
ATOMIC_OPS(or, |=, CTOP_INST_AOR_DI_R2_R2_R3)
302301
ATOMIC_OPS(xor, ^=, CTOP_INST_AXOR_DI_R2_R2_R3)
303302

@@ -430,7 +429,8 @@ static inline long long atomic64_fetch_##op(long long a, atomic64_t *v) \
430429
ATOMIC64_OP_RETURN(op, op1, op2) \
431430
ATOMIC64_FETCH_OP(op, op1, op2)
432431

433-
#define atomic64_andnot atomic64_andnot
432+
#define atomic64_andnot atomic64_andnot
433+
#define atomic64_fetch_andnot atomic64_fetch_andnot
434434

435435
ATOMIC64_OPS(add, add.f, adc)
436436
ATOMIC64_OPS(sub, sub.f, sbc)

‎arch/arm/include/asm/atomic.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
216216
return ret;
217217
}
218218

219+
#define atomic_fetch_andnot atomic_fetch_andnot
220+
219221
#endif /* __LINUX_ARM_ARCH__ */
220222

221223
#define ATOMIC_OPS(op, c_op, asm_op) \

‎include/linux/atomic.h‎

Lines changed: 30 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -354,12 +354,22 @@
354354
#endif
355355
#endif /* atomic_fetch_and_relaxed */
356356

357-
#ifdef atomic_andnot
358-
/* atomic_fetch_andnot_relaxed */
357+
#ifndef atomic_andnot
358+
#define atomic_andnot(i, v) atomic_and(~(int)(i), (v))
359+
#endif
360+
359361
#ifndef atomic_fetch_andnot_relaxed
360-
#define atomic_fetch_andnot_relaxed atomic_fetch_andnot
361-
#define atomic_fetch_andnot_acquire atomic_fetch_andnot
362-
#define atomic_fetch_andnot_release atomic_fetch_andnot
362+
363+
#ifndef atomic_fetch_andnot
364+
#define atomic_fetch_andnot(i, v) atomic_fetch_and(~(int)(i), (v))
365+
#define atomic_fetch_andnot_relaxed(i, v) atomic_fetch_and_relaxed(~(int)(i), (v))
366+
#define atomic_fetch_andnot_acquire(i, v) atomic_fetch_and_acquire(~(int)(i), (v))
367+
#define atomic_fetch_andnot_release(i, v) atomic_fetch_and_release(~(int)(i), (v))
368+
#else /* atomic_fetch_andnot */
369+
#define atomic_fetch_andnot_relaxed atomic_fetch_andnot
370+
#define atomic_fetch_andnot_acquire atomic_fetch_andnot
371+
#define atomic_fetch_andnot_release atomic_fetch_andnot
372+
#endif /* atomic_fetch_andnot */
363373

364374
#else /* atomic_fetch_andnot_relaxed */
365375

@@ -378,7 +388,6 @@
378388
__atomic_op_fence(atomic_fetch_andnot, __VA_ARGS__)
379389
#endif
380390
#endif /* atomic_fetch_andnot_relaxed */
381-
#endif /* atomic_andnot */
382391

383392
/* atomic_fetch_xor_relaxed */
384393
#ifndef atomic_fetch_xor_relaxed
@@ -655,33 +664,6 @@ static inline bool atomic_add_negative(int i, atomic_t *v)
655664
}
656665
#endif
657666

658-
#ifndef atomic_andnot
659-
static inline void atomic_andnot(int i, atomic_t *v)
660-
{
661-
atomic_and(~i, v);
662-
}
663-
664-
static inline int atomic_fetch_andnot(int i, atomic_t *v)
665-
{
666-
return atomic_fetch_and(~i, v);
667-
}
668-
669-
static inline int atomic_fetch_andnot_relaxed(int i, atomic_t *v)
670-
{
671-
return atomic_fetch_and_relaxed(~i, v);
672-
}
673-
674-
static inline int atomic_fetch_andnot_acquire(int i, atomic_t *v)
675-
{
676-
return atomic_fetch_and_acquire(~i, v);
677-
}
678-
679-
static inline int atomic_fetch_andnot_release(int i, atomic_t *v)
680-
{
681-
return atomic_fetch_and_release(~i, v);
682-
}
683-
#endif
684-
685667
#ifndef atomic_inc_unless_negative
686668
static inline bool atomic_inc_unless_negative(atomic_t *v)
687669
{
@@ -1029,12 +1011,22 @@ static inline int atomic_dec_if_positive(atomic_t *v)
10291011
#endif
10301012
#endif /* atomic64_fetch_and_relaxed */
10311013

1032-
#ifdef atomic64_andnot
1033-
/* atomic64_fetch_andnot_relaxed */
1014+
#ifndef atomic64_andnot
1015+
#define atomic64_andnot(i, v) atomic64_and(~(long long)(i), (v))
1016+
#endif
1017+
10341018
#ifndef atomic64_fetch_andnot_relaxed
1035-
#define atomic64_fetch_andnot_relaxed atomic64_fetch_andnot
1036-
#define atomic64_fetch_andnot_acquire atomic64_fetch_andnot
1037-
#define atomic64_fetch_andnot_release atomic64_fetch_andnot
1019+
1020+
#ifndef atomic64_fetch_andnot
1021+
#define atomic64_fetch_andnot(i, v) atomic64_fetch_and(~(long long)(i), (v))
1022+
#define atomic64_fetch_andnot_relaxed(i, v) atomic64_fetch_and_relaxed(~(long long)(i), (v))
1023+
#define atomic64_fetch_andnot_acquire(i, v) atomic64_fetch_and_acquire(~(long long)(i), (v))
1024+
#define atomic64_fetch_andnot_release(i, v) atomic64_fetch_and_release(~(long long)(i), (v))
1025+
#else /* atomic64_fetch_andnot */
1026+
#define atomic64_fetch_andnot_relaxed atomic64_fetch_andnot
1027+
#define atomic64_fetch_andnot_acquire atomic64_fetch_andnot
1028+
#define atomic64_fetch_andnot_release atomic64_fetch_andnot
1029+
#endif /* atomic64_fetch_andnot */
10381030

10391031
#else /* atomic64_fetch_andnot_relaxed */
10401032

@@ -1053,7 +1045,6 @@ static inline int atomic_dec_if_positive(atomic_t *v)
10531045
__atomic_op_fence(atomic64_fetch_andnot, __VA_ARGS__)
10541046
#endif
10551047
#endif /* atomic64_fetch_andnot_relaxed */
1056-
#endif /* atomic64_andnot */
10571048

10581049
/* atomic64_fetch_xor_relaxed */
10591050
#ifndef atomic64_fetch_xor_relaxed
@@ -1262,33 +1253,6 @@ static inline bool atomic64_add_negative(long long i, atomic64_t *v)
12621253
}
12631254
#endif
12641255

1265-
#ifndef atomic64_andnot
1266-
static inline void atomic64_andnot(long long i, atomic64_t *v)
1267-
{
1268-
atomic64_and(~i, v);
1269-
}
1270-
1271-
static inline long long atomic64_fetch_andnot(long long i, atomic64_t *v)
1272-
{
1273-
return atomic64_fetch_and(~i, v);
1274-
}
1275-
1276-
static inline long long atomic64_fetch_andnot_relaxed(long long i, atomic64_t *v)
1277-
{
1278-
return atomic64_fetch_and_relaxed(~i, v);
1279-
}
1280-
1281-
static inline long long atomic64_fetch_andnot_acquire(long long i, atomic64_t *v)
1282-
{
1283-
return atomic64_fetch_and_acquire(~i, v);
1284-
}
1285-
1286-
static inline long long atomic64_fetch_andnot_release(long long i, atomic64_t *v)
1287-
{
1288-
return atomic64_fetch_and_release(~i, v);
1289-
}
1290-
#endif
1291-
12921256
#ifndef atomic64_inc_unless_negative
12931257
static inline bool atomic64_inc_unless_negative(atomic64_t *v)
12941258
{

0 commit comments

Comments
 (0)