From: Andrew Haley <aph@redhat.com>
To: "tom@womack.net" <tom@womack.net>
Cc: gcc-help@gcc.gnu.org
Subject: Re: Register constraint 'not RAX or RDX'
Date: Mon, 20 Nov 2006 15:31:00 -0000 [thread overview]
Message-ID: <17761.51794.41304.831893@zebedee.pink> (raw)
In-Reply-To: <12693659.1164035234728.JavaMail.?@fh1035.dia.cp.net>
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.
prev parent reply other threads:[~2006-11-20 15:31 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-11-20 15:07 tom
2006-11-20 15:31 ` Andrew Haley [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=17761.51794.41304.831893@zebedee.pink \
--to=aph@redhat.com \
--cc=gcc-help@gcc.gnu.org \
--cc=tom@womack.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).