From 9580d67514ec138e65496aa1170c63b53f657207 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Thu, 30 Jul 2015 13:35:20 +0200 Subject: [PATCH] Do some IEEE trickery to help the shader optimizer remove a sub or two in some YCbCr cases. --- ycbcr.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ycbcr.cpp b/ycbcr.cpp index 08c8cd2..6dbcd9d 100644 --- 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 , compute the values needed to turn Y'CbCr into R'G'B'; -- 2.39.2