Author: Walter Faxon
Date: 12:26:25 12/26/02
Go up one level in this thread
On December 25, 2002 at 22:23:28, Matt Taylor wrote: >On December 25, 2002 at 15:56:19, Dave Gomboc wrote: > >>On December 25, 2002 at 15:38:19, Matt Taylor wrote: >> >>>>Overloading costs nothing, it's a compile time construct and is resolved at >>>>compile/link time. >>>>Inheritance costs nothing, it too is a compile/link time issue. >>>>You know nothing about C++, do you? I didn't think so. >>> >>>Overloading costs an indirect function call. I'm not sure if you can apply const >>>to a class like you can apply final to one in Java, but unless the compiler >>>knows the class can't be inherited from, it has to make the operator an indirect >>>function call. >> >>Calling a class const in C++ means something else, but a C++ compiler can (and >>some do) figure out which classes are at the bottom of the inheritance hierarchy >>at compile-time. (Unlike with Java, this isn't mutable at run-time.) >> >>Dave > >Ah, sorry, I was somehow thinking of Java where everything can be overloaded >unless you say otherwise. Still, polymorphism still does not come for free. > >Another thing which C++ cannot do involves elimination of branches. If you have >a switch/case with a few cases and a small number of computations, the best >thing to do is compute them all and conditionally select the result (does not >require branching). > >-Matt Hi, Matt. You've said this last thing before but I still don't understand. Could you show an example of this in pseudo-asm, without using C conditionals? ("cond ? true : false" I understand to be simply disguised branches.) Maybe you could base it on this code fragment: int val, result; ... switch(val) { case 0: result = a + b + c; break; case 1: result = a + b - c; break; case 999: result = a - b + c; break; default: result = a - b - c; break; } foo(result); Even assuming that you can compute all the results simultaneously at a fixed cost, how do you "conditionally select the result" without branching? The only thing I can see to do is to stuff the results in an array of size at least 1000 and use the variable val as an index, which wouldn't seem too hot to me. I'm sure I'm missing something neat. -- Walter (I'll say more on our topic of bit flogging in a few days.)
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.