public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] hppa: Optimize atomic_compare_and_exchange_val_acq
@ 2016-09-22 14:14 John David Anglin
  2016-09-22 20:37 ` Carlos O'Donell
  0 siblings, 1 reply; 14+ messages in thread
From: John David Anglin @ 2016-09-22 14:14 UTC (permalink / raw)
  To: GNU C Library; +Cc: deller, Carlos O'Donell, Mike Frysinger, Aurelien Jarno

[-- Attachment #1: Type: text/plain, Size: 470 bytes --]

The attached patch replaces the conditional branch tests in atomic_compare_and_exchange_val_acq with
conditional instruction nullification.  This avoids the stalls associated with conditional branches and the resulting
code is shorter.  There are no branches in the fast path when the operation is successful.

The change was intended as an optimization but tst-stack4 now passes.

Please install.

Thanks,
Dave
--
John David Anglin	dave.anglin@bell.net



[-- Attachment #2: submitted-atomic-machine.diff.txt --]
[-- Type: text/plain, Size: 2132 bytes --]

2016-09-22  John David Anglin  

	* sysdeps/unix/sysv/linux/hppa/atomic-machine.h: Don't include
	abort-instr.h.
	(EFAULT): Remove conditional define.
	(ENOSYS): Likewise.
	(atomic_compare_and_exchange_val_acq): Use instruction nullification
	instead of conditional branch instructions.

Index: glibc-2.23/sysdeps/unix/sysv/linux/hppa/atomic-machine.h
===================================================================
--- glibc-2.23.orig/sysdeps/unix/sysv/linux/hppa/atomic-machine.h
+++ glibc-2.23/sysdeps/unix/sysv/linux/hppa/atomic-machine.h
@@ -17,13 +17,6 @@
    <http://www.gnu.org/licenses/>.  */
 
 #include <stdint.h> /*  Required for type definitions e.g. uint8_t.  */
-#include <abort-instr.h> /*  Required for ABORT_INSTRUCTIUON.  */
-
-/* We need EFAULT, ENONSYS */
-#if !defined EFAULT && !defined ENOSYS
-#define EFAULT	14
-#define ENOSYS	251
-#endif
 
 #ifndef _ATOMIC_MACHINE_H
 #define _ATOMIC_MACHINE_H	1
@@ -62,7 +55,7 @@ typedef uintmax_t uatomic_max_t;
 #define _ASM_EDEADLOCK "-45"
 
 /* The only basic operation needed is compare and exchange.  The mem
-   pointer must be word aligned.  */
+   pointer must be word aligned.  We no longer loop on deadlock.  */
 #define atomic_compare_and_exchange_val_acq(mem, newval, oldval)	\
   ({									\
      register long lws_errno asm("r21");				\
@@ -74,20 +67,15 @@ typedef uintmax_t uatomic_max_t;
 	"0:					\n\t"			\
 	"ble	" _LWS "(%%sr2, %%r0)		\n\t"			\
 	"ldi	" _LWS_CAS ", %%r20		\n\t"			\
-	"ldi	" _ASM_EAGAIN ", %%r20		\n\t"			\
-	"cmpb,=,n %%r20, %%r21, 0b		\n\t"			\
-	"nop					\n\t"			\
-	"ldi	" _ASM_EDEADLOCK ", %%r20	\n\t"			\
-	"cmpb,=,n %%r20, %%r21, 0b		\n\t"			\
-	"nop					\n\t"			\
+	"cmpiclr,<> " _ASM_EAGAIN ", %%r21, %%r0\n\t"			\
+	"b,n 0b					\n\t"			\
+	"cmpclr,= %%r0, %%r21, %%r0		\n\t"			\
+	"iitlbp %%r0,(%%sr0, %%r0)		\n\t"			\
 	: "=r" (lws_ret), "=r" (lws_errno)				\
 	: "r" (lws_mem), "r" (lws_old), "r" (lws_new)			\
 	: _LWS_CLOBBER							\
      );									\
 									\
-     if (lws_errno == -EFAULT || lws_errno == -ENOSYS)			\
-	ABORT_INSTRUCTION;						\
-									\
      (__typeof (oldval)) lws_ret;					\
    })
 

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2016-10-12  5:24 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-22 14:14 [PATCH] hppa: Optimize atomic_compare_and_exchange_val_acq John David Anglin
2016-09-22 20:37 ` Carlos O'Donell
2016-09-22 21:38   ` Helge Deller
2016-09-27 17:15     ` Carlos O'Donell
2016-09-22 21:49   ` John David Anglin
2016-09-23  7:13     ` Florian Weimer
2016-09-27 17:17       ` Carlos O'Donell
2016-09-27 22:26         ` John David Anglin
2016-09-27 22:50           ` Florian Weimer
2016-09-27 23:04             ` John David Anglin
2016-09-28 20:29           ` Carlos O'Donell
2016-09-28 21:00           ` Florian Weimer
2016-10-02 16:47             ` John David Anglin
2016-10-12  5:24               ` Carlos O'Donell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).