making FreeCell redraw 20% faster...
John M McIntosh
johnmci at mac.com
Fri Jul 4 10:01:18 UTC 2003
When you run the FreeCell demo it seems on the powerpc that
BitBltSimulation>>alphaSourceBlendBits16
chews a lot of cycles, say 8.7% of the total time.
Well I noticed that in
BitBltSimulation>> dither32To16: threshold:
that it does something interesting, why it grabs the r g b bytes and
mangles them into a 16 bit word. But really at each step we have 8 bits
of data with 4 bits for threshold information to result in 4 bits of
output.
{Yes, well it's late maybe my math is wrong}
Gee can you say a lookup table (4096 elements of 4 bits (however 8 will
do)), yes you can.
{actually I'm not sure using a byte is wise, perhaps a word is faster,
silly risc machines}
New.
dither32To16: srcWord threshold: ditherValue
"Dither the given 32bit word to 16 bit. Ignore alpha."
| addThreshold |
self inline: true. "You bet"
addThreshold _ ditherValue bitShift: 8.
^((dither8Lookup at: (addThreshold+((srcWord bitShift: -16) bitAnd:
255))) bitShift: 10) +
((dither8Lookup at: (addThreshold+((srcWord bitShift: -8) bitAnd:
255))) bitShift: 5) +
(dither8Lookup at: (addThreshold+(srcWord bitAnd: 255))).
Populating the dither8Lookup (name to change) table is left as an
exercise for the reader.
This needless to say makes quite a difference and we shave about 20%
off our 16 bit alpha blended redraw times, which takes cpu cycle usage
to 4.8%.
I'll need to clean this up a bit, and of course if anyone wants to
test, please let me know.
Original.
dither32To16: srcWord threshold: ditherValue
"Dither the given 32bit word to 16 bit. Ignore alpha."
| pv threshold value out |
self inline: true. "You bet"
pv _ srcWord bitAnd: 255.
threshold _ ditherThresholds16 at: (pv bitAnd: 7).
value _ ditherValues16 at: (pv bitShift: -3).
ditherValue < threshold
ifTrue:[out _ value + 1]
ifFalse:[out _ value].
pv _ (srcWord bitShift: -8) bitAnd: 255.
threshold _ ditherThresholds16 at: (pv bitAnd: 7).
value _ ditherValues16 at: (pv bitShift: -3).
ditherValue < threshold
ifTrue:[out _ out bitOr: (value+1 bitShift:5)]
ifFalse:[out _ out bitOr: (value bitShift: 5)].
pv _ (srcWord bitShift: -16) bitAnd: 255.
threshold _ ditherThresholds16 at: (pv bitAnd: 7).
value _ ditherValues16 at: (pv bitShift: -3).
ditherValue < threshold
ifTrue:[out _ out bitOr: (value+1 bitShift:10)]
ifFalse:[out _ out bitOr: (value bitShift: 10)].
^out
--
========================================================================
===
John M. McIntosh <johnmci at smalltalkconsulting.com> 1-800-477-2659
Corporate Smalltalk Consulting Ltd. http://www.smalltalkconsulting.com
========================================================================
===
More information about the Squeak-dev
mailing list
|