I was browsing the Allegro 4.2.0 source to see how complex the blender functions are so I could determine how to effectively integrate them into the game engine I'm working on, and I noticed that there are numerous divisions by constant powers of 2 on unsigned long integers littered throughout "colblend.c". For example:
Wouldn't it be faster and more efficient, especially considering the nature of these procedures, to change all the divisions by 8, 32, and 256 to right bit-shifts of 3, 5 and 8? I'd do the change myself if I understood how changes to the Allegro source were actually proposed and made.
--- Kris Asick (Gemini)
--- http://www.pixelships.com
I'd do the change myself if I understood how changes to the Allegro source were actually proposed and made.
I imagine this hasn't been done because it's trivial for the compiler to optimize constant, power-of-2 division itself.
Profile it and see what happens.
Well, I decided to perform a test on my system. I compiled Allegro 4.2.0 the way it always was, made the change from division to bit-shifting, then compiled another copy of the DLL. I quickly wrote up a pixel plotting program and tested it with both DLLs...
...There was no discernable difference in speed.
Then again, when I compile Allegro, the ALLEG42.DLL file ends up almost twice as big as the one that comes with the pre-compiled binaries, so I have to wonder if something's going on with that which would be affecting my tests. shrugs
In either case, I guess it isn't the biggest of deals considering my results.
...though my pixel plotter managed to hit 4,000,000 additive-blended pixels a second, with 5 modulo, 5 rand(), one addition and one IF operation additionally being performed for each of those 4,000,000 pixels... that's a lot of processing going on...
When I took the blender functionality out, it only got up to 6,500,000 pixels a second. I guess the blender functions must work faster than I thought...
--- Kris Asick (Gemini)
--- http://www.pixelships.com
Wouldn't it be faster and more efficient, especially considering the nature of these procedures, to change all the divisions by 8, 32, and 256 to right bit-shifts of 3, 5 and 8?
Not really; it's one of those trivial optimizations that the compiler can do automatically.
I was browsing the Allegro 4.2.0 source to see how complex the blender functions are so I could determine how to effectively integrate them into the game engine I'm working on
If you didn't want to use AllegroGL / OpenLayer, I'd look at the source for FBlend and that use parts of that (without the functions calls if possible).