CDEF: Add damping to dering

high-latency, cpu-used=0:
   PSNR | PSNR Cb | PSNR Cr | PSNR HVS |    SSIM | MS SSIM | CIEDE 2000
-0.1650 |  0.2545 |  0.2977 |  -0.0423 | -0.0947 | -0.0725 |    -0.0365

low-latency, cpu-used=0:
   PSNR | PSNR Cb | PSNR Cr | PSNR HVS |    SSIM | MS SSIM | CIEDE 2000
-0.4006 |  0.0501 | -0.0108 |  -0.1790 | -0.1660 | -0.1992 |    -0.2135

low latency, cpu-used=4:
   PSNR | PSNR Cb | PSNR Cr | PSNR HVS |    SSIM | MS SSIM | CIEDE 2000
-0.5508 | -0.2445 | -0.2762 |  -0.1981 | -0.2878 | -0.2228 |    -0.3733

Change-Id: Ia20df28c8bbb6182215b02016053af33bd498145
diff --git a/av1/common/cdef.h b/av1/common/cdef.h
index 5f48ca0..c0e7dfc 100644
--- a/av1/common/cdef.h
+++ b/av1/common/cdef.h
@@ -23,6 +23,18 @@
 #include "av1/common/onyxc_int.h"
 #include "./od_dering.h"
 
+static INLINE int sign(int i) { return i < 0 ? -1 : 1; }
+
+static INLINE int constrain(int diff, int threshold, unsigned int damping) {
+  return threshold
+             ? sign(diff) *
+                   AOMMIN(
+                       abs(diff),
+                       AOMMAX(0, threshold - (abs(diff) >>
+                                              (damping - get_msb(threshold)))))
+             : 0;
+}
+
 #ifdef __cplusplus
 extern "C" {
 #endif