Bug 1226627 - Use fmin[f]/fmax[f] when clamping floating point values (perf). r=roc
authorMats Palmgren <mats@mozilla.com>
Sun, 29 Nov 2015 17:58:36 +0100
changeset 308722 673461c0b772b7a63fc9eb4115ae682c3a9c32e1
parent 308721 fcda0da2ed2aaa642b10300833a1e21e52e7f5f9
child 308723 294b89a6fdae56d6eb3870081b5457238851e58c
push id5513
push userraliiev@mozilla.com
push dateMon, 25 Jan 2016 13:55:34 +0000
treeherdermozilla-beta@5ee97dd05b5c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs1226627
milestone45.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1226627 - Use fmin[f]/fmax[f] when clamping floating point values (perf). r=roc
gfx/src/nsCoord.h
--- a/gfx/src/nsCoord.h
+++ b/gfx/src/nsCoord.h
@@ -105,16 +105,18 @@ inline nscoord NSToCoordRoundWithClamp(f
 #ifndef NS_COORD_IS_FLOAT
   // Bounds-check before converting out of float, to avoid overflow
   if (aValue >= nscoord_MAX) {
     return nscoord_MAX;
   }
   if (aValue <= nscoord_MIN) {
     return nscoord_MIN;
   }
+  // NOTE: we can't replace the early returns above with fminf/fmaxf because
+  // NSToCoordRound(float(nscoord_MAX)) is negative on win32 (bug 1226627).
 #endif
   return NSToCoordRound(aValue);
 }
 
 /**
  * Returns aCoord * aScale, capping the product to nscoord_MAX or nscoord_MIN as
  * appropriate for the signs of aCoord and aScale.  If requireNotNegative is
  * true, this method will enforce that aScale is not negative; use that
@@ -254,22 +256,18 @@ inline nscoord NSToCoordFloor(double aVa
 {
   return nscoord(floor(aValue));
 }
 
 inline nscoord NSToCoordFloorClamped(float aValue)
 {
 #ifndef NS_COORD_IS_FLOAT
   // Bounds-check before converting out of float, to avoid overflow
-  if (aValue >= nscoord_MAX) {
-    return nscoord_MAX;
-  }
-  if (aValue <= nscoord_MIN) {
-    return nscoord_MIN;
-  }
+  aValue = fminf(aValue, nscoord_MAX);
+  aValue = fmaxf(aValue, nscoord_MIN);
 #endif
   return NSToCoordFloor(aValue);
 }
 
 inline nscoord NSToCoordCeil(float aValue)
 {
   return nscoord(ceilf(aValue));
 }
@@ -278,22 +276,18 @@ inline nscoord NSToCoordCeil(double aVal
 {
   return nscoord(ceil(aValue));
 }
 
 inline nscoord NSToCoordCeilClamped(double aValue)
 {
 #ifndef NS_COORD_IS_FLOAT
   // Bounds-check before converting out of double, to avoid overflow
-  if (aValue >= nscoord_MAX) {
-    return nscoord_MAX;
-  }
-  if (aValue <= nscoord_MIN) {
-    return nscoord_MIN;
-  }
+  aValue = fmin(aValue, nscoord_MAX);
+  aValue = fmax(aValue, nscoord_MIN);
 #endif
   return NSToCoordCeil(aValue);
 }
 
 // The NSToCoordTrunc* functions remove the fractional component of
 // aValue, and are thus equivalent to NSToCoordFloor* for positive
 // values and NSToCoordCeil* for negative values.
 
@@ -310,36 +304,28 @@ inline nscoord NSToCoordTrunc(double aVa
   // rules for float to integer conversion.
   return nscoord(aValue);
 }
 
 inline nscoord NSToCoordTruncClamped(float aValue)
 {
 #ifndef NS_COORD_IS_FLOAT
   // Bounds-check before converting out of float, to avoid overflow
-  if (aValue >= nscoord_MAX) {
-    return nscoord_MAX;
-  }
-  if (aValue <= nscoord_MIN) {
-    return nscoord_MIN;
-  }
+  aValue = fminf(aValue, nscoord_MAX);
+  aValue = fmaxf(aValue, nscoord_MIN);
 #endif
   return NSToCoordTrunc(aValue);
 }
 
 inline nscoord NSToCoordTruncClamped(double aValue)
 {
 #ifndef NS_COORD_IS_FLOAT
   // Bounds-check before converting out of double, to avoid overflow
-  if (aValue >= nscoord_MAX) {
-    return nscoord_MAX;
-  }
-  if (aValue <= nscoord_MIN) {
-    return nscoord_MIN;
-  }
+  aValue = fmin(aValue, nscoord_MAX);
+  aValue = fmax(aValue, nscoord_MIN);
 #endif
   return NSToCoordTrunc(aValue);
 }
 
 /*
  * Int Rounding Functions
  */
 inline int32_t NSToIntFloor(float aValue)