Hi, I'm currently experimenting with just-in-time compilation using libfirm. While discussing issues with its developers, it was pointed out to me that our spinlock inline assembly is less than optimal. Attached is a patch that addresses this.
,---- | Remove the LOCK prefix from the XCHG instruction. Locking is implicit | with XCHG and the prefix wastes a byte. Also remove the "cc" register | from the clobber list as the XCHG instruction does not modify any flags. | | Reported by Christoph Mallon. `---- regards, Andreas
>From c836b4f3e0b60d070481d4061e6fe0ffbe488495 Mon Sep 17 00:00:00 2001 From: Andreas Seltenreich <seltenre...@gmx.de> Date: Sun, 17 Jan 2016 11:51:53 +0100 Subject: [PATCH] Improve spinlock inline assembly for x86. Remove the LOCK prefix from the XCHG instruction. Locking is implicit with XCHG and the prefix wastes a byte. Also remove the "cc" register from the clobber list as the xchg instruction does not modify any flags. Reported by Christoph Mallon. --- src/include/storage/s_lock.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/include/storage/s_lock.h b/src/include/storage/s_lock.h index 8b240cd..933bb76 100644 --- a/src/include/storage/s_lock.h +++ b/src/include/storage/s_lock.h @@ -158,7 +158,6 @@ tas(volatile slock_t *lock) __asm__ __volatile__( " cmpb $0,%1 \n" " jne 1f \n" - " lock \n" " xchgb %0,%1 \n" "1: \n" : "+q"(_res), "+m"(*lock) @@ -226,11 +225,10 @@ tas(volatile slock_t *lock) register slock_t _res = 1; __asm__ __volatile__( - " lock \n" " xchgb %0,%1 \n" : "+q"(_res), "+m"(*lock) : /* no inputs */ -: "memory", "cc"); +: "memory"); return (int) _res; } -- 2.1.4
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers