http://d.puremagic.com/issues/show_bug.cgi?id=9920
Summary: [Optimizer] Use mul/imul for integer division by
constant
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P2
Component: DMD
AssignedTo: [email protected]
ReportedBy: [email protected]
--- Comment #0 from Dmitry Olshansky <[email protected]> 2013-04-11
08:44:06 PDT ---
Created an attachment (id=1208)
fast divison by constant for uint values
It's a common knowledge and is totally expected for any modern compiler to
re-write divisions by constant to double word width _multiplication_ by a
specific constant followed by shift.
DMD still DOESN'T DO it.
Attached is an example of this optimization done via meta-programming in D
along with test and a benchmark. On average (on my PC) the mul version is
around 3 times faster then compiler-generated div. On LDC and GDC results are
that compiler-generate version is a bit faster.
Compiler can easily do a better job especially with 64bit values (as 2x64
accumulator is completely unaccessible for the programmer).
For full description of one such technique see Agner Fog's manuals on assembly
optimizations: http://www.agner.org/optimize/optimizing_assembly.pdf
See the chapter 16. "Problematic instructions", section on DIV/IDIV is 16.9.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------