Paul Curtis wrote: > Peter, > > >> >>And CodeVision gets that right as you would expect but I am using >>unsigned quantities > > > ...but you're not, you've told the compiler that you're using signed > quantities, you said "long" not "unsigned long" in your code snippet. > If you has said "unsigned long" in the cast, the division by 65536 would > decay to a shift. > > Very true - how daft of me now I feel silly :) My apologies. I just went back and redid them as (unsigned long) casts and the compiler still performed the divide! Only the first timimg quoted changed - it reduced to 71 cycles. >>>(Actually, there *is* a way to implement a signed divide by >> >>a power of >> >>>two without using the clockwork method.) >> >>What is that? > > > x /= 2**n can be coded using shifts like this: > > if (x < 0) > x += (2**n)-1; > x >>= n; > Ah - handy. Pete
Message
Re: [AVR-Chat] Faster arithmetic
2005-06-15 by Peter Harrison
Attachments
- No local attachments were found for this message.