aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoah Misch <noah@leadboat.com>2019-10-18 20:20:28 -0700
committerNoah Misch <noah@leadboat.com>2019-10-18 20:20:31 -0700
commitef13f914e6c2a66f186f73ec1bba682e56dc621b (patch)
tree3f8a3704b071255fee499c588480660a7b278ac9
parent9dfbf9a04398f8b9332d95e49037c530c4dda827 (diff)
downloadpostgresql-ef13f914e6c2a66f186f73ec1bba682e56dc621b.tar.gz
postgresql-ef13f914e6c2a66f186f73ec1bba682e56dc621b.zip
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
-rw-r--r--src/include/storage/s_lock.h7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/include/storage/s_lock.h b/src/include/storage/s_lock.h
index d0ab247623c..e0984efcd6a 100644
--- a/src/include/storage/s_lock.h
+++ b/src/include/storage/s_lock.h
@@ -452,6 +452,11 @@ typedef unsigned int slock_t;
#define TAS_SPIN(lock) (*(lock) ? 1 : TAS(lock))
/*
+ * The second operand of addi can hold a constant zero or a register number,
+ * hence constraint "=&b" to avoid allocating r0. "b" stands for "address
+ * base register"; most operands having this register-or-zero property are
+ * address bases, e.g. the second operand of lwax.
+ *
* NOTE: per the Enhanced PowerPC Architecture manual, v1.0 dated 7-May-2002,
* an isync is a sufficient synchronization barrier after a lwarx/stwcx loop.
* On newer machines, we can use lwsync instead for better performance.
@@ -488,7 +493,7 @@ tas(volatile slock_t *lock)
#endif
" li %1,0 \n"
-: "=&r"(_t), "=r"(_res), "+m"(*lock)
+: "=&b"(_t), "=r"(_res), "+m"(*lock)
: "r"(lock)
: "memory", "cc");
return _res;