]> git.sesse.net Git - movit/commitdiff
Do some IEEE trickery to help the shader optimizer remove a sub or two in some YCbCr...
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 30 Jul 2015 11:35:20 +0000 (13:35 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 30 Jul 2015 11:35:20 +0000 (13:35 +0200)
ycbcr.cpp

index 08c8cd25d4603c43b092abe078b6d98815a466e9..6dbcd9d94691e1a1190d1fcabf36c1ff373e1919 100644 (file)
--- a/ycbcr.cpp
+++ b/ycbcr.cpp
@@ -48,7 +48,12 @@ namespace movit {
 float compute_chroma_offset(float pos, unsigned subsampling_factor, unsigned resolution)
 {
        float local_chroma_pos = (0.5 + pos * (subsampling_factor - 1)) / subsampling_factor;
-       return (0.5 - local_chroma_pos) / resolution;
+       if (fabs(local_chroma_pos - 0.5) < 1e-10) {
+               // x + (-0) can be optimized away freely, as opposed to x + 0.
+               return -0.0;
+       } else {
+               return (local_chroma_pos - 0.5) / resolution;
+       }
 }
 
 // Given <ycbcr_format>, compute the values needed to turn Y'CbCr into R'G'B';