|
From: | Paulo Marques |
Subject: | Re: [avr-gcc-list] dev and mod may not be optimized |
Date: | Wed, 12 Dec 2007 16:48:52 +0000 |
User-agent: | Thunderbird 1.5.0.12 (X11/20070509) |
Gre7g Luterman wrote:
--- Paulo Marques <address@hidden> wrote:Actually after a few more digging, we can do thisall in plain C, by using a smaller reciprocal multiplier:<snipped>Wow, that's freakin' inspired!
Thanks :)It's not really a new idea, though. Using multiply by the reciprocal to do divisions by constants has been around for a while. For an in-depth analysis of the technique I suggest reading "Hacker's Delight".
The funny thing is that gcc for x86 does this optimization itself, replacing division by constants with multiplications when optimizing for speed. Unfortunately I don't know enough (or have time to get involved) to port the same optimization to the avr backend... :(
And you're right it does optimize nicely. Here's a 20 byte version that executes in 12 cycles: http://pastie.textmate.org/127541
Very nice :) -- Paulo Marques Software Development Department - Grupo PIE, S.A. Phone: +351 252 290600, Fax: +351 252 290601 Web: www.grupopie.com "All I ask is a chance to prove that money can't make me happy."
[Prev in Thread] | Current Thread | [Next in Thread] |