![]() |
|
Suggestion for Speed Improvement to Blender Functions |
Kris Asick
Member #1,424
July 2001
|
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) --- Kris Asick (Gemini) |
CGamesPlay
Member #2,559
July 2002
![]() |
Quote: 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. -- Ryan Patterson - <http://cgamesplay.com/> |
gnolam
Member #2,030
March 2002
![]() |
Profile it and see what happens. -- |
Kris Asick
Member #1,424
July 2001
|
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) --- Kris Asick (Gemini) |
Evert
Member #794
November 2000
![]() |
Quote: 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. |
Richard Phipps
Member #1,632
November 2001
![]() |
Quote: 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). |
|