From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27470 invoked by alias); 1 Mar 2014 22:41:40 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 27154 invoked by uid 48); 1 Mar 2014 22:41:37 -0000 From: "glisse at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/58897] Improve 128/64 division Date: Sat, 01 Mar 2014 22:41:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 4.9.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: enhancement X-Bugzilla-Who: glisse at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-03/txt/msg00058.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58897 --- Comment #1 from Marc Glisse --- Untested, but this shows what the 128/64 division could look like (with obvious variants for mod and divmod). I don't really know how to get gcc to generate anything like that though. I have seen udivmodtidi3 in s390 but that seems to return (ql,r) packed in an __int128, not what I want. And gcc doesn't show ul->ux as a zero_extend and forgets extremely fast the REG_EQUAL note on the call to __udivti3, so I can't rely on combine. typedef unsigned __int128 ux; typedef unsigned long ul; #define udiv_qrnnd(q, r, n1, n0, dx) \ __asm__ ("divq %4" : "=a" (q), "=d" (r) \ : "0" ((ul)(n0)), "1" ((ul)(n1)), "rm" ((ul)(dx))) ux div128by64(ux a, ul b){ ul ah = a >> 64; ul al = a; ul qh, ql, r1, r; qh=ah/b; r1=ah%b; udiv_qrnnd(ql,r,r1,al,b); return (ux)qh << 64 | ql; } /* a=ah*2^64+al ah=qh*b+r1 a=qh*2^64*b+r1*2^64+al r1*2^64+al<2^64*b r1*2^64+al=ql*b+r a=(qh*2^64+ql)*b+r */