On Wed, 2009-04-29 at 09:21 -0700, Greg Wright wrote: > > > > I checked "if( NBITS_PER_AUDIOSAMPLE==32 )" in the cvt32 before this > > changed and no, the compiler doesn't optimized it away. > > Was NBITS_PER_AUDIOSAMPLE still a #define at this point?
Still a #define with sizeof in it. > > > It's not 'broken'. C/C++ never says how compiler should optimize or how > > much it should do. We can only second guess what a compiler will do. > > It's better to not rely on compiler optimization if we know better what > > we want. > > const unsigned int NBITS_PER_AUDIOSAMPLE = sizeof(tAudioSample)<<3; > > changing the #define to a 'const int'(or even static) should not give the > compiler a choice, it should evaluate the sizeof() and assign > the result to NBITS_PER_AUDIOSAMPLE. That leaves us with: > > if( 16==16 ) > > Now, whether or not the compiler optimizes that out or > not, as you say, is up to the compiler. Again we are relying on compiler optimization here. 'const' only means that compiler won't let anybody change that variable. It doesn't mean that compiler MUST not allocate a memory location for that variable. > > But, is 'if(16==16)' comparison a big hit for you, assuming > the compiler does not optimize it out? If so, then we really > don't have much choice and I don't see a problem with the > change. I still don't know if you are just trying to get the > memcpy instead of the for-loop or you want to get rid of both > the 'if' and the 'for-loop'. Not just speed hit. If compiler choose to not optimize away the 'if' statement, the code for the other for loop branch will be there always -- a constant memory usage hit. I want to get rid of both for loop and the 'if'. That's the best we can do and should do imho, no matter what compiler or debug/release config it is. > > --greg. > _______________________________________________ Audio-dev mailing list [email protected] http://lists.helixcommunity.org/mailman/listinfo/audio-dev
