]> Cypherpunks repositories - gostls13.git/commit
image/color: optimize YCbCrToRGB
authorMartin Möhrmann <martisch@uos.de>
Tue, 12 Apr 2016 19:16:27 +0000 (21:16 +0200)
committerMartin Möhrmann <martisch@uos.de>
Tue, 12 Apr 2016 23:04:26 +0000 (23:04 +0000)
commitf0c5b8b9c9c7900033ddb11b584da6198d599454
treeef04682c55b152a5a9700a4a002bc3fc681b0933
parent1650ced98f4f6c5f0783f78cb9d0ffd3a6d1768f
image/color: optimize YCbCrToRGB

Use one comparison to detect underflow and overflow simultaneously.
Use a shift, bitwise complement and uint8 type conversion to handle
clamping to upper and lower bound without additional branching.

Overall the new code is faster for a mix of
common case, underflow and overflow.

name     old time/op  new time/op  delta
YCbCr-2  1.12ms ± 0%  0.64ms ± 0%  -43.01%  (p=0.000 n=48+47)

name              old time/op  new time/op  delta
YCbCrToRGB/0-2    5.52ns ± 0%  5.77ns ± 0%  +4.48%  (p=0.000 n=50+49)
YCbCrToRGB/128-2  6.05ns ± 0%  5.52ns ± 0%  -8.69%  (p=0.000 n=39+50)
YCbCrToRGB/255-2  5.80ns ± 0%  5.77ns ± 0%  -0.58%  (p=0.000 n=50+49)

Found in collaboration with Josh Bleecher Snyder and Ralph Corderoy.

Change-Id: Ic5020320f704966f545fdc1ae6bc24ddb5d3d09a
Reviewed-on: https://go-review.googlesource.com/21910
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
src/image/color/ycbcr.go
src/image/internal/imageutil/gen.go
src/image/internal/imageutil/impl.go