Skip to content

Commit 89b4d77

Browse files
committed
For PowerPC instruction "addi", use constraint "b".
Without "b", a variant of the tas() code miscompiles on macOS 10.4. This may also fix a compilation failure involving macOS 10.1. Today's compilers have been allocating acceptable registers with or without this change, but this future-proofs the code by precisely conveying the acceptable registers. Back-patch to 9.4 (all supported versions). Reviewed by Tom Lane. Discussion: https://postgr.es/m/20191009063900.GA4066266@rfd.leadboat.com
1 parent f25968c commit 89b4d77

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/include/storage/s_lock.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,11 @@ typedef unsigned int slock_t;
452452
#define TAS_SPIN(lock) (*(lock) ? 1 : TAS(lock))
453453

454454
/*
455+
* The second operand of addi can hold a constant zero or a register number,
456+
* hence constraint "=&b" to avoid allocating r0. "b" stands for "address
457+
* base register"; most operands having this register-or-zero property are
458+
* address bases, e.g. the second operand of lwax.
459+
*
455460
* NOTE: per the Enhanced PowerPC Architecture manual, v1.0 dated 7-May-2002,
456461
* an isync is a sufficient synchronization barrier after a lwarx/stwcx loop.
457462
* On newer machines, we can use lwsync instead for better performance.
@@ -488,7 +493,7 @@ tas(volatile slock_t *lock)
488493
#endif
489494
" li %1,0 \n"
490495

491-
: "=&r"(_t), "=r"(_res), "+m"(*lock)
496+
: "=&b"(_t), "=r"(_res), "+m"(*lock)
492497
: "r"(lock)
493498
: "memory", "cc");
494499
return _res;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy