Some minor changes for global motion.

Increases amortization blocks. Improves results a little.
Also adds aom_clear_system_state() calls correctly to avoid
some occasional crash issues.

Change-Id: Ib776ee5ec30c70c1cd4a1fae7e7f23c2acc58ef6
diff --git a/av1/encoder/rdopt.c b/av1/encoder/rdopt.c
index 3242f3d..f189bd8 100644
--- a/av1/encoder/rdopt.c
+++ b/av1/encoder/rdopt.c
@@ -4351,15 +4351,22 @@
     case IDENTITY: bits = 0; break;
     default: assert(0); return 0;
   }
+  assert(type < GLOBAL_TRANS_TYPES);
   return bits ? (bits << AV1_PROB_COST_SHIFT) + gmtype_cost[type] : 0;
 }
 
-#define GLOBAL_MOTION_RATE(ref)                            \
-  (cpi->global_motion_used[ref] >= 2                       \
-       ? 0                                                 \
-       : get_gmbitcost(&cm->global_motion[(ref)],          \
-                       cm->fc->global_motion_types_prob) / \
-             2);
+#define GLOBAL_MOTION_COST_AMORTIZATION_BLKS 8
+
+#if GLOBAL_MOTION_COST_AMORTIZATION_BLKS > 0
+#define GLOBAL_MOTION_RATE(ref)                                         \
+  (cpi->global_motion_used[ref] >= GLOBAL_MOTION_COST_AMORTIZATION_BLKS \
+       ? 0                                                              \
+       : get_gmbitcost(&cm->global_motion[(ref)],                       \
+                       cm->fc->global_motion_types_prob) /              \
+             GLOBAL_MOTION_COST_AMORTIZATION_BLKS);
+#else
+#define GLOBAL_MOTION_RATE(ref) 0
+#endif  // GLOBAL_MOTION_COST_AMORTIZATION_BLKS > 0
 #endif  // CONFIG_GLOBAL_MOTION
 
 static int set_and_cost_bmi_mvs(const AV1_COMP *const cpi, MACROBLOCK *x,