From: Benedikt Meurer <benedikt.meurer@googlemail.com>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Re: optimize div to right shift (NOT!)
Date: Mon, 13 Dec 2010 14:03:24 +0100 [thread overview]
Message-ID: <C629C2F0-1847-41AC-ABC9-0BD5429703CE@googlemail.com> (raw)
In-Reply-To: <20101213145806.7a6f9ac0@deb0>
On Dec 13, 2010, at 13:58 , Török Edwin wrote:
> It is still possible to avoid the division, gcc generates this:
> movq %rdi, %rax
> shrq $63, %rax
> addq %rdi, %rax
> sarq %rax
>
> Or a better example with division by 8:
> leaq 7(%rdi), %rax
> testq %rdi, %rdi
> cmovns %rdi, %rax
> sarq $3, %rax
ocamlopt does exactly this, atleast for x86-64.
> And division by non-power of two integers can optimized by replacing it
> with multiplication with its inverse (which gcc and llvm don't do for
> signed divisions, only for unsigned ones):
> http://www.hackersdelight.org/HDcode/magic.c.txt
> http://www.hackersdelight.org/HDcode/magicu.c.txt
The AMD64 optimization guide gives additional pointers here, i.e. it also lists replacement sequences for multiplication by constant.
> Best regards,
> --Edwin
greets,
Benedikt
next prev parent reply other threads:[~2010-12-13 13:03 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20101212172643.3EF80BC5D@yquem.inria.fr>
2010-12-13 12:33 ` Jonathan Kimmitt
2010-12-13 12:58 ` [Caml-list] " Török Edwin
2010-12-13 13:03 ` Benedikt Meurer [this message]
2010-12-13 20:13 ` Jon Harrop
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=C629C2F0-1847-41AC-ABC9-0BD5429703CE@googlemail.com \
--to=benedikt.meurer@googlemail.com \
--cc=caml-list@yquem.inria.fr \
/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 NNTP newsgroup(s).