From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30963 invoked by alias); 20 Nov 2006 15:31:48 -0000 Received: (qmail 30954 invoked by uid 22791); 20 Nov 2006 15:31:47 -0000 X-Spam-Check-By: sourceware.org Received: from mx2.redhat.com (HELO mx2.redhat.com) (66.187.237.31) by sourceware.org (qpsmtpd/0.31) with ESMTP; Mon, 20 Nov 2006 15:31:39 +0000 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.12.11.20060308/8.12.11) with ESMTP id kAKFVbCQ023221 for ; Mon, 20 Nov 2006 10:31:37 -0500 Received: from zebedee.littlepinkcloud.COM (vpn-14-158.rdu.redhat.com [10.11.14.158]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id kAKFVWUi009528; Mon, 20 Nov 2006 10:31:33 -0500 Received: from littlepinkcloud.COM (localhost.localdomain [127.0.0.1]) by zebedee.littlepinkcloud.COM (8.13.6/8.13.5) with ESMTP id kAKFVUtW010821; Mon, 20 Nov 2006 15:31:31 GMT Received: (from aph@localhost) by littlepinkcloud.COM (8.13.6/8.13.5/Submit) id kAKFVU9t010816; Mon, 20 Nov 2006 15:31:30 GMT MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <17761.51794.41304.831893@zebedee.pink> Date: Mon, 20 Nov 2006 15:31:00 -0000 From: Andrew Haley To: "tom@womack.net" Cc: gcc-help@gcc.gnu.org Subject: Re: Register constraint 'not RAX or RDX' In-Reply-To: <12693659.1164035234728.JavaMail.?@fh1035.dia.cp.net> References: <12693659.1164035234728.JavaMail.?@fh1035.dia.cp.net> X-Mailer: VM 7.19 under Emacs 21.4.1 X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2006-11/txt/msg00249.txt.bz2 tom@womack.net writes: > What's the right way of writing the 'compute a*b%c' intrinsic? > > I can do > > #define mulmod(a,b,c,d,e) { asm ("mul %%rbx; div %%rsi;" : "=d" (d), > "=a" (e) : "a" (a), "b" (b), "S" (c));} > > but that causes quite a lot of ugly register-shuffling > > If I do > > #define mulmod(a,b,c,d,e) { asm ("mul %0; div %1;" : "=d" (d), "=a" > (e) : "a" (a), "r" (b), "r" (c));} > > then the program doesn't work; disassembling > > u64 zul(u64 a, u64 b, u64 p) > { > u64 x,y; > mulmod(a,b,p,x,y); > return x; > } > > gives > > 00000000004005b0 <_Z3zulyyy>: > 4005b0: 48 89 f8 mov %rdi,%rax > 4005b3: 48 f7 e2 mul %rdx > 4005b6: 48 f7 f0 div %rax > 4005b9: 48 89 d0 mov %rdx,%rax > 4005bc: c3 retq > > which is clearly crazy since %rax from 4005b0 will have been > overwritten by the mul command before it's used. #define mulmod(a,b,c,d,e) \ { \ asm ("mul %3\n\tdiv %4\n" \ : "=&d" (d), "=a" (e) \ : "1" (a), "g" (b), "g" (c)); \ } Andrew.