diff options
| author | Mike Klein <mtklein@chromium.org> | 2016-12-02 14:22:57 -0500 |
|---|---|---|
| committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2016-12-02 19:54:39 +0000 |
| commit | 3e05671ace65faf4b849275f2eefb534e336e92f (patch) | |
| tree | 4eadc1310adc600e344ea3db64e47d6fe83d09d9 /samplecode/SampleCode.cpp | |
| parent | c2881e9b404d757cb26a1c68ed9c8a51ddd36f6b (diff) | |
Tricky float -> byte conversion in store_8888.
In IEEE, for each byte BB, the float 0x470000BB equals 32768.0f + BB*(1/256.0f).
So to turn a [0,1] float into a byte, we can
- multiply by (255/256.0f) to get into [0,255/256.0f] range,
- add 32768.0f to get into [32768.0f, 32768.0f + 255/256.0f] range,
- look at the low byte.
Those first two of course are an FMA.
Using this trick here makes store_8888 measurably faster. Instead of a FMA then float->int trunc, we do an FMA then a bitwise AND. Overall the math goes from 4 FMA + 4 trunc + 3 shift to 4 FMA + 3 AND + 3 shift (we can skip the shift for red and the AND for alpha). As you might guess, AND is cheaper than trunc, so this is a net win.
I should be able to follow up with the same trick in reverse in from_8888().
CQ_INCLUDE_TRYBOTS=skia.primary:Test-Ubuntu-GCC-GCE-CPU-AVX2-x86_64-Release-SKNX_NO_SIMD
Change-Id: I42c8f4a6ea0b6c22160517cf5f9c048f01c9a330
Reviewed-on: https://skia-review.googlesource.com/5540
Reviewed-by: Matt Sarett <msarett@google.com>
Commit-Queue: Mike Klein <mtklein@chromium.org>
Diffstat (limited to 'samplecode/SampleCode.cpp')
0 files changed, 0 insertions, 0 deletions
