I think one can trust the compiler to handle a/3.14 as a multiplication. If it doesn't it'd probably be worse to write a*(1/3.14), for this would be a division AND a multiplication.

-----Original Message----- From: Nigel Redmon
Sent: Saturday, March 09, 2013 5:15 PM
To: A discussion list for music-related DSP
Subject: Re: [music-dsp] Efficiency of clear/copy/offset buffers

On Mar 8, 2013, at 2:53 PM, ChordWizard Software <corpor...@chordwizard.com> wrote:
But some are quite new - I never realised that multiplication ops were more efficient than divisions.

Worthy of some background...

When multiplying, you can do all the necessary multiplications in parallel (think of performing a long multiply by hand—1234 x 5678 for instance. It's easy to imagine how you could speed this up by having a few friends help you, where you manage the first digit, 4 x 5678, another handles 3(0) x 5678, etc., at the same time.) but when you divide, you need to finish one digit before you know what the remainder is and you can move to the next digit. There's no way to look ahead—you need the result of the first step before doing the second. So, processors optimize multiplication and addition with parallel circuits, but division is iterated in a microcode loop (or done entirely in software). The 56K DSPs, for instance have a single-cycle multiply, but for division, "DIV" is a single division iteration—you need to do it for every digit you need to generate. It's just the nature of the operation.

Compilers may help you optimize constants, but it's always best to keep track of things yourself so you know what you're getting. So, yes, multiply by the sample period instead of dividing by the sample rate, etc.

--
dupswapdrop -- the music-dsp mailing list and website:
subscription info, FAQ, source code archive, list archive, book reviews, dsp links
http://music.columbia.edu/cmc/music-dsp
http://music.columbia.edu/mailman/listinfo/music-dsp
--
dupswapdrop -- the music-dsp mailing list and website:
subscription info, FAQ, source code archive, list archive, book reviews, dsp 
links
http://music.columbia.edu/cmc/music-dsp
http://music.columbia.edu/mailman/listinfo/music-dsp

Reply via email to