Skip to content

Commit f633abd

Browse files
committed
Atomic<T>: Use pre-op assembler primitives
Use the pre-op assembler primitives that use one fewer register where possible. Note that this means that `++atomic;` or `atomic += 1;` will be more efficient than `atomic++;` or `atomic->fetch_add(1);`. The inline assembler can't detect that the return value of `atomic++;` is not used and avoid the extra register.
1 parent e7c13d4 commit f633abd

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

platform/Atomic.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ struct AtomicWithAdd : public AtomicBaseInt<T, A> {
530530
T operator++() volatile
531531
{
532532
A d = static_cast<A>(sizeof(StrideT));
533-
return T(core_util_atomic_fetch_add(&this->u, d) + d);
533+
return T(core_util_atomic_incr(&this->u, d));
534534
}
535535
T operator++(int) volatile
536536
{
@@ -540,7 +540,7 @@ struct AtomicWithAdd : public AtomicBaseInt<T, A> {
540540
T operator--() volatile
541541
{
542542
A d = static_cast<A>(sizeof(StrideT));
543-
return T(core_util_atomic_fetch_sub(&this->u, d) - d);
543+
return T(core_util_atomic_decr(&this->u, d));
544544
}
545545
T operator--(int) volatile
546546
{
@@ -560,7 +560,7 @@ struct AtomicWithAdd : public AtomicBaseInt<T, A> {
560560
T operator+=(DiffT arg) volatile
561561
{
562562
A d = static_cast<A>(arg * sizeof(StrideT));
563-
return T(core_util_atomic_fetch_add(&this->u, d) + d);
563+
return T(core_util_atomic_incr(&this->u, d));
564564
}
565565
T fetch_sub(DiffT arg) volatile
566566
{
@@ -575,7 +575,7 @@ struct AtomicWithAdd : public AtomicBaseInt<T, A> {
575575
T operator-=(DiffT arg) volatile
576576
{
577577
A d = static_cast<A>(arg * sizeof(StrideT));
578-
return T(core_util_atomic_fetch_sub(&this->u, d) - d);
578+
return T(core_util_atomic_decr(&this->u, d));
579579
}
580580
};
581581

@@ -602,7 +602,7 @@ struct AtomicWithBitwise : public AtomicWithAdd<T, A> {
602602
T operator&=(T arg) volatile
603603
{
604604
A d = static_cast<A>(arg);
605-
return static_cast<T>(core_util_atomic_fetch_and(&this->u, d) & d);
605+
return static_cast<T>(core_util_atomic_and_fetch(&this->u, d));
606606
}
607607
T fetch_or(T arg) volatile
608608
{
@@ -617,7 +617,7 @@ struct AtomicWithBitwise : public AtomicWithAdd<T, A> {
617617
T operator|=(T arg) volatile
618618
{
619619
A d = static_cast<A>(arg);
620-
return static_cast<T>(core_util_atomic_fetch_or(&this->u, d) | d);
620+
return static_cast<T>(core_util_atomic_or_fetch(&this->u, d));
621621
}
622622
T fetch_xor(T arg) volatile
623623
{
@@ -632,7 +632,7 @@ struct AtomicWithBitwise : public AtomicWithAdd<T, A> {
632632
T operator^=(T arg) volatile
633633
{
634634
A d = static_cast<A>(arg);
635-
return static_cast<T>(core_util_atomic_fetch_xor(&this->u, d) ^ d);
635+
return static_cast<T>(core_util_atomic_xor_fetch(&this->u, d));
636636
}
637637
};
638638

0 commit comments

Comments
 (0)