Subj : Re: faster approach to division To : comp.programming From : Willem Date : Mon Jul 11 2005 08:27 pm Mark wrote: ) I'm working on a problem which involves a fair amount of integer ) division but in essentially all cases the divisor is +/- 1 or +/- 2. ) I'm using C++ and trying to figure out whether I should code this as ) just ordinary division or whether it makes sense to create a special ) class (basically a wrapped enumeration) to hold my possible divisor ) values. Then I would overload operator/() to recast division as a null ) operation or a sign flip and/or right shift. ) ) Anyone have any intuition on this? I've tried a few very simple tests ) comparing division and shifting and it's hard to discern a difference, ) but I'm not sure my tests are very effective. (Are modern machines ) optimized to divide by 1 and 2 quickly?) Are these values hardcoded as constants ? (i.e. is there a literal 'x = y/2' in the code ?) If so, the compiler will help you. In any case, division isn't that slow anymore, and some 'if' statements to check special cases may very well be slower than a straight div. You may be able to find instructiuon timing sheets on intel processors on the intel site. They're big ass pdf files that you have to wade through but they do contain detailed info on all the instructions. SaSW, Willem -- Disclaimer: I am in no way responsible for any of the statements made in the above text. For all I know I might be drugged or something.. No I'm not paranoid. You all think I'm paranoid, don't you ! #EOT .