]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
In s_lock.h, use regular labels with %= instead of local labels.
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 2 Feb 2026 16:13:38 +0000 (11:13 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 2 Feb 2026 16:13:38 +0000 (11:13 -0500)
Up to now we've used GNU-style local labels for branch targets
in s_lock.h's assembly blocks.  But there's an alternative style,
which I for one didn't know about till recently: use regular
assembler labels, and insert a per-asm-block number in them
using %= to ensure they are distinct across multiple TAS calls
within one source file.  gcc has had %= since gcc 2.0, and
I've verified that clang knows it too.

While the immediate motivation for changing this is that AIX's
assembler doesn't do local labels, it seems to me that this is a
superior solution anyway.  There is nothing mnemonic about "1:",
while a regular label can convey something useful, and at least
to me it feels less error-prone.  Therefore let's standardize on
this approach, also converting the one other usage in s_lock.h.

Discussion: https://postgr.es/m/399291.1769998688@sss.pgh.pa.us

src/include/storage/s_lock.h

index 2522cae0c310e3b1ba14412787b465e8f089b4ae..3d9070e79d4696a25e7021116f9441400814c47e 100644 (file)
  * gcc from thinking it can cache the values of shared-memory fields
  * across the asm code.  Add "cc" if your asm code changes the condition
  * code register, and also list any temp registers the code uses.
+ *
+ * If you need branch target labels within the asm block, include "%="
+ * in the label names to make them distinct across multiple asm blocks
+ * within a source file.
  *----------
  */
 
@@ -147,11 +151,11 @@ tas(volatile slock_t *lock)
         * leave it alone.
         */
        __asm__ __volatile__(
-               "       cmpb    $0,%1   \n"
-               "       jne             1f              \n"
-               "       lock                    \n"
-               "       xchgb   %0,%1   \n"
-               "1: \n"
+               "       cmpb    $0,%1           \n"
+               "       jne             TAS%=_out       \n"
+               "       lock                            \n"
+               "       xchgb   %0,%1           \n"
+               "TAS%=_out: \n"
 :              "+q"(_res), "+m"(*lock)
 :              /* no inputs */
 :              "memory", "cc");
@@ -421,17 +425,17 @@ tas(volatile slock_t *lock)
        __asm__ __volatile__(
 "      lwarx   %0,0,%3,1       \n"
 "      cmpwi   %0,0            \n"
-"      bne     1f                      \n"
+"      bne     TAS%=_fail      \n"
 "      addi    %0,%0,1         \n"
 "      stwcx.  %0,0,%3         \n"
-"      beq     2f                      \n"
-"1: \n"
+"      beq     TAS%=_ok        \n"
+"TAS%=_fail: \n"
 "      li      %1,1            \n"
-"      b       3f                      \n"
-"2: \n"
+"      b       TAS%=_out       \n"
+"TAS%=_ok: \n"
 "      lwsync                          \n"
 "      li      %1,0            \n"
-"3: \n"
+"TAS%=_out: \n"
 :      "=&b"(_t), "=r"(_res), "+m"(*lock)
 :      "r"(lock)
 :      "memory", "cc");