|
From: | Erik Søe Sørensen |
Subject: | [glob2-devel] Optimizing calculations |
Date: | Tue, 11 Sep 2007 01:40:15 +0200 |
User-agent: | Mozilla/5.0 (X11; U; Linux i686; da; rv:1.7.13) Gecko/20060717 Debian/1.7.12-1.1ubuntu2 StumbleUpon/1.9995 |
Kai Antweiler skrev:
Looks like you use a small Taylor polynomials for cos and calculate it using the Horner scheme. I don't think this can be made faster. Or could we use some discrete calculation for approximation? 2. Instead of: float val, amp = 1.0, sum = 0.0; for ( int i = 0;i < oct;i++, amp *= 0.5, tp *= 2.0 ) { val = Noise3d( f_tp ); if ( hard ) val = fabs( val ); sum += amp * val; } return 0.5 + 0.5*( sum * ( ( float ) ( 1 << oct ) / ( float ) ( ( 1 << ( oct + 1 ) ) - 1 ) ) ); We could try: float val, sum = 0.0; for ( int i = 0;i < oct;i++, tp *= 2.0 ) { val = Noise3d( f_tp ); if ( hard ) val = fabs( val ); sum += val / (float) (1<<i); } return 0.5 + 0.5*( sum * ( ( float ) ( 1 << oct ) / ( float ) ( ( 1 << ( oct + 1 ) ) - 1 ) ) ); But that is probably worse.
It probably is - float->int and int->float conversions are expensive. Keeping calculations in integers is usually way faster.
Well, there is such an instruction (FSCALE for x86); it doesn't seem like gcc uses it though... OoHey why isn't there a thing like float-shift? After all this would only require to add/subtract 1 from the exponent!
The compiler ought to figure this out for itself - at least for unsigned values (for signed it makes two shifts instead).3. DynamicClouds.cpp: vpX += (viewPortX-vpX%64+96)%64-32; This might be faster using a mask: vpX += (viewPortX-vpX&63+96)&63-32;
/Erik
[Prev in Thread] | Current Thread | [Next in Thread] |