From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/7697 Path: news.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: [PATCH] inline llsc atomics when compiling for sh4a Date: Mon, 18 May 2015 22:12:38 -0400 Message-ID: <20150519021238.GE17573@brightrain.aerifal.cx> References: <20150517185516.GA32020@duality.lan> <20150518023402.GS17573@brightrain.aerifal.cx> <20150518225617.GA1905@duality.lan> <20150519003045.GC17573@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1432001579 9539 80.91.229.3 (19 May 2015 02:12:59 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 19 May 2015 02:12:59 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-7709-gllmg-musl=m.gmane.org@lists.openwall.com Tue May 19 04:12:53 2015 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1YuX1Z-0004Z2-Hi for gllmg-musl@m.gmane.org; Tue, 19 May 2015 04:12:53 +0200 Original-Received: (qmail 6011 invoked by uid 550); 19 May 2015 02:12:52 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 5992 invoked from network); 19 May 2015 02:12:51 -0000 Content-Disposition: inline In-Reply-To: <20150519003045.GC17573@brightrain.aerifal.cx> User-Agent: Mutt/1.5.21 (2010-09-15) Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:7697 Archived-At: On Mon, May 18, 2015 at 08:30:45PM -0400, Rich Felker wrote: > [...] > static inline int __sh_cas_llsc(volatile int *p, int t, int s) > { > do old = llsc_start(p); > while (!llsc_end(p, old==t ? s : old)); > return old; > } > > This version is structurally analogous to the non-CAS atomics, but > perhaps more costly in the old!=t case. > > Anyway at this point I don't see an efficient way do to the > conditional, so it's mostly a theoretical topic at this point. I have a partial solution but it's utterly hideous: static inline int llsc_end(volatile int *p, int v) { __asm__ __volatile__ goto ( "mov.co %1, @%0 ; bf %l[fail]" : : "r"(p), "z"(v) : "memory" : fail ); return 1; fail: return 0; } This doesn't eliminate the branch in the asm, but it does allow gcc to eliminate the branch outside the asm. The resulting code is: a_cas: .align 2 .L2: #APP synco ; mov.li @r4, r0 #NO_APP cmp/eq r0,r5 bf .L4 mov r6,r0 #APP mov.co r0, @r4 ; bf .L2 #NO_APP .L6: rts mov r5,r0 .align 1 .L4: bra .L6 mov r0,r5 Of course asm goto is utterly hideous, so I don't propose actually using this. I doubt any of the non-GCC compilers we support would accept it. Rich