Merge "New experiment: Perceptual Vector Quantization from Daala" into nextgenv2
diff --git a/av1/common/mv.h b/av1/common/mv.h
index d49fc3f..e5400d9 100644
--- a/av1/common/mv.h
+++ b/av1/common/mv.h
@@ -36,7 +36,7 @@
 
 #if CONFIG_GLOBAL_MOTION || CONFIG_WARPED_MOTION
 // Bits of precision used for the model
-#define WARPEDMODEL_PREC_BITS 8
+#define WARPEDMODEL_PREC_BITS 12
 #define WARPEDMODEL_ROW3HOMO_PREC_BITS 12
 
 // Bits of subpel precision for warped interpolation
@@ -65,7 +65,7 @@
 
 typedef struct {
   TransformationType wmtype;
-  int_mv wmmat[4];  // For homography wmmat[9] is assumed to be 1
+  int32_t wmmat[8];  // For homography wmmat[9] is assumed to be 1
 } WarpedMotionParams;
 #endif  // CONFIG_GLOBAL_MOTION || CONFIG_WARPED_MOTION
 
@@ -94,16 +94,16 @@
 //
 // XX_MIN, XX_MAX are also computed to avoid repeated computation
 
-#define GM_TRANS_PREC_BITS 8
+#define GM_TRANS_PREC_BITS 3
 #define GM_TRANS_PREC_DIFF (WARPEDMODEL_PREC_BITS - GM_TRANS_PREC_BITS)
 #define GM_TRANS_DECODE_FACTOR (1 << GM_TRANS_PREC_DIFF)
 
-#define GM_ALPHA_PREC_BITS 8
+#define GM_ALPHA_PREC_BITS 12
 #define GM_ALPHA_PREC_DIFF (WARPEDMODEL_PREC_BITS - GM_ALPHA_PREC_BITS)
 #define GM_ALPHA_DECODE_FACTOR (1 << GM_ALPHA_PREC_DIFF)
 
-#define GM_ABS_ALPHA_BITS 8
-#define GM_ABS_TRANS_BITS 8
+#define GM_ABS_ALPHA_BITS 9
+#define GM_ABS_TRANS_BITS 9
 
 #define GM_TRANS_MAX (1 << GM_ABS_TRANS_BITS)
 #define GM_ALPHA_MAX (1 << GM_ABS_ALPHA_BITS)
@@ -123,6 +123,17 @@
   WarpedMotionParams motion_params;
 } Global_Motion_Params;
 
+// Convert a global motion translation vector (which may have more bits than a
+// regular motion vector) into a motion vector
+static INLINE int_mv gm_get_motion_vector(const Global_Motion_Params *gm) {
+  int_mv res;
+  res.as_mv.row = (int16_t)ROUND_POWER_OF_TWO_SIGNED(gm->motion_params.wmmat[0],
+                                                     WARPEDMODEL_PREC_BITS - 3);
+  res.as_mv.col = (int16_t)ROUND_POWER_OF_TWO_SIGNED(gm->motion_params.wmmat[1],
+                                                     WARPEDMODEL_PREC_BITS - 3);
+  return res;
+}
+
 static INLINE TransformationType gm_to_trans_type(GLOBAL_MOTION_TYPE gmtype) {
   switch (gmtype) {
     case GLOBAL_ZERO: return UNKNOWN_TRANSFORM; break;
@@ -135,10 +146,11 @@
 }
 
 static INLINE GLOBAL_MOTION_TYPE get_gmtype(const Global_Motion_Params *gm) {
-  if (!gm->motion_params.wmmat[2].as_int) {
-    if (!gm->motion_params.wmmat[1].as_int) {
-      return (gm->motion_params.wmmat[0].as_int ? GLOBAL_TRANSLATION
-                                                : GLOBAL_ZERO);
+  if (!gm->motion_params.wmmat[5] && !gm->motion_params.wmmat[4]) {
+    if (!gm->motion_params.wmmat[3] && !gm->motion_params.wmmat[2]) {
+      return ((!gm->motion_params.wmmat[1] && !gm->motion_params.wmmat[0])
+                  ? GLOBAL_ZERO
+                  : GLOBAL_TRANSLATION);
     } else {
       return GLOBAL_ROTZOOM;
     }
diff --git a/av1/common/warped_motion.c b/av1/common/warped_motion.c
index ad92150..2534345 100644
--- a/av1/common/warped_motion.c
+++ b/av1/common/warped_motion.c
@@ -26,7 +26,7 @@
   }
 }
 
-void project_points_translation(int16_t *mat, int *points, int *proj,
+void project_points_translation(int32_t *mat, int *points, int *proj,
                                 const int n, const int stride_points,
                                 const int stride_proj, const int subsampling_x,
                                 const int subsampling_y) {
@@ -52,7 +52,7 @@
   }
 }
 
-void project_points_rotzoom(int16_t *mat, int *points, int *proj, const int n,
+void project_points_rotzoom(int32_t *mat, int *points, int *proj, const int n,
                             const int stride_points, const int stride_proj,
                             const int subsampling_x, const int subsampling_y) {
   int i;
@@ -79,7 +79,7 @@
   }
 }
 
-void project_points_affine(int16_t *mat, int *points, int *proj, const int n,
+void project_points_affine(int32_t *mat, int *points, int *proj, const int n,
                            const int stride_points, const int stride_proj,
                            const int subsampling_x, const int subsampling_y) {
   int i;
@@ -106,7 +106,7 @@
   }
 }
 
-void project_points_homography(int16_t *mat, int *points, int *proj,
+void project_points_homography(int32_t *mat, int *points, int *proj,
                                const int n, const int stride_points,
                                const int stride_proj, const int subsampling_x,
                                const int subsampling_y) {
@@ -443,8 +443,7 @@
       int in[2], out[2];
       in[0] = j;
       in[1] = i;
-      projectpoints((int16_t *)wm->wmmat, in, out, 1, 2, 2, subsampling_x,
-                    subsampling_y);
+      projectpoints(wm->wmmat, in, out, 1, 2, 2, subsampling_x, subsampling_y);
       out[0] = ROUND_POWER_OF_TWO_SIGNED(out[0] * x_scale, 4);
       out[1] = ROUND_POWER_OF_TWO_SIGNED(out[1] * y_scale, 4);
       gm_err = dst[(j - p_col) + (i - p_row) * p_stride] -
@@ -475,8 +474,7 @@
       int in[2], out[2];
       in[0] = j;
       in[1] = i;
-      projectpoints((int16_t *)wm->wmmat, in, out, 1, 2, 2, subsampling_x,
-                    subsampling_y);
+      projectpoints(wm->wmmat, in, out, 1, 2, 2, subsampling_x, subsampling_y);
       out[0] = ROUND_POWER_OF_TWO_SIGNED(out[0] * x_scale, 4);
       out[1] = ROUND_POWER_OF_TWO_SIGNED(out[1] * y_scale, 4);
       if (ref_frm)
@@ -507,8 +505,7 @@
       int in[2], out[2];
       in[0] = j;
       in[1] = i;
-      projectpoints((int16_t *)wm->wmmat, in, out, 1, 2, 2, subsampling_x,
-                    subsampling_y);
+      projectpoints(wm->wmmat, in, out, 1, 2, 2, subsampling_x, subsampling_y);
       out[0] = ROUND_POWER_OF_TWO_SIGNED(out[0] * x_scale, 4);
       out[1] = ROUND_POWER_OF_TWO_SIGNED(out[1] * y_scale, 4);
       gm_err = dst[(j - p_col) + (i - p_row) * p_stride] -
@@ -535,8 +532,7 @@
       int in[2], out[2];
       in[0] = j;
       in[1] = i;
-      projectpoints((int16_t *)wm->wmmat, in, out, 1, 2, 2, subsampling_x,
-                    subsampling_y);
+      projectpoints(wm->wmmat, in, out, 1, 2, 2, subsampling_x, subsampling_y);
       out[0] = ROUND_POWER_OF_TWO_SIGNED(out[0] * x_scale, 4);
       out[1] = ROUND_POWER_OF_TWO_SIGNED(out[1] * y_scale, 4);
       if (ref_frm)
@@ -596,28 +592,22 @@
   switch (wmtype) {
     case HOMOGRAPHY:
       assert(fabs(model[8] - 1.0) < 1e-12);
-      wm->wmmat[3].as_mv.row =
-          (int16_t)lrint(model[6] * (1 << WARPEDMODEL_ROW3HOMO_PREC_BITS));
-      wm->wmmat[3].as_mv.col =
-          (int16_t)lrint(model[7] * (1 << WARPEDMODEL_ROW3HOMO_PREC_BITS));
+      wm->wmmat[6] =
+          (int32_t)lrint(model[6] * (1 << WARPEDMODEL_ROW3HOMO_PREC_BITS));
+      wm->wmmat[7] =
+          (int32_t)lrint(model[7] * (1 << WARPEDMODEL_ROW3HOMO_PREC_BITS));
     /* fallthrough intended */
     case AFFINE:
-      wm->wmmat[2].as_mv.row =
-          (int16_t)lrint(model[4] * (1 << WARPEDMODEL_PREC_BITS));
-      wm->wmmat[2].as_mv.col =
-          (int16_t)lrint(model[5] * (1 << WARPEDMODEL_PREC_BITS));
+      wm->wmmat[4] = (int32_t)lrint(model[4] * (1 << WARPEDMODEL_PREC_BITS));
+      wm->wmmat[5] = (int32_t)lrint(model[5] * (1 << WARPEDMODEL_PREC_BITS));
     /* fallthrough intended */
     case ROTZOOM:
-      wm->wmmat[1].as_mv.row =
-          (int16_t)lrint(model[2] * (1 << WARPEDMODEL_PREC_BITS));
-      wm->wmmat[1].as_mv.col =
-          (int16_t)lrint(model[3] * (1 << WARPEDMODEL_PREC_BITS));
+      wm->wmmat[2] = (int32_t)lrint(model[2] * (1 << WARPEDMODEL_PREC_BITS));
+      wm->wmmat[3] = (int32_t)lrint(model[3] * (1 << WARPEDMODEL_PREC_BITS));
     /* fallthrough intended */
     case TRANSLATION:
-      wm->wmmat[0].as_mv.row =
-          (int16_t)lrint(model[0] * (1 << WARPEDMODEL_PREC_BITS));
-      wm->wmmat[0].as_mv.col =
-          (int16_t)lrint(model[1] * (1 << WARPEDMODEL_PREC_BITS));
+      wm->wmmat[0] = (int32_t)lrint(model[0] * (1 << WARPEDMODEL_PREC_BITS));
+      wm->wmmat[1] = (int32_t)lrint(model[1] * (1 << WARPEDMODEL_PREC_BITS));
       break;
     default: assert(0 && "Invalid TransformationType");
   }
diff --git a/av1/common/warped_motion.h b/av1/common/warped_motion.h
index e7b9038..7c9919f 100644
--- a/av1/common/warped_motion.h
+++ b/av1/common/warped_motion.h
@@ -24,26 +24,26 @@
 
 #define MAX_PARAMDIM 9
 
-typedef void (*ProjectPointsFunc)(int16_t *mat, int *points, int *proj,
+typedef void (*ProjectPointsFunc)(int32_t *mat, int *points, int *proj,
                                   const int n, const int stride_points,
                                   const int stride_proj,
                                   const int subsampling_x,
                                   const int subsampling_y);
 
-void project_points_translation(int16_t *mat, int *points, int *proj,
+void project_points_translation(int32_t *mat, int *points, int *proj,
                                 const int n, const int stride_points,
                                 const int stride_proj, const int subsampling_x,
                                 const int subsampling_y);
 
-void project_points_rotzoom(int16_t *mat, int *points, int *proj, const int n,
+void project_points_rotzoom(int32_t *mat, int *points, int *proj, const int n,
                             const int stride_points, const int stride_proj,
                             const int subsampling_x, const int subsampling_y);
 
-void project_points_affine(int16_t *mat, int *points, int *proj, const int n,
+void project_points_affine(int32_t *mat, int *points, int *proj, const int n,
                            const int stride_points, const int stride_proj,
                            const int subsampling_x, const int subsampling_y);
 
-void project_points_homography(int16_t *mat, int *points, int *proj,
+void project_points_homography(int32_t *mat, int *points, int *proj,
                                const int n, const int stride_points,
                                const int stride_proj, const int subsampling_x,
                                const int subsampling_y);
diff --git a/av1/decoder/decodeframe.c b/av1/decoder/decodeframe.c
index ee067f7..d0907ec 100644
--- a/av1/decoder/decodeframe.c
+++ b/av1/decoder/decodeframe.c
@@ -3856,28 +3856,28 @@
   switch (gmtype) {
     case GLOBAL_ZERO: break;
     case GLOBAL_AFFINE:
-      params->motion_params.wmmat[2].as_mv.row =
+      params->motion_params.wmmat[4] =
           (aom_read_primitive_symmetric(r, GM_ABS_ALPHA_BITS) *
            GM_ALPHA_DECODE_FACTOR);
-      params->motion_params.wmmat[2].as_mv.col =
+      params->motion_params.wmmat[5] =
           aom_read_primitive_symmetric(r, GM_ABS_ALPHA_BITS) *
               GM_ALPHA_DECODE_FACTOR +
           (1 << WARPEDMODEL_PREC_BITS);
     // fallthrough intended
     case GLOBAL_ROTZOOM:
-      params->motion_params.wmmat[1].as_mv.row =
+      params->motion_params.wmmat[2] =
           aom_read_primitive_symmetric(r, GM_ABS_ALPHA_BITS) *
           GM_ALPHA_DECODE_FACTOR;
-      params->motion_params.wmmat[1].as_mv.col =
+      params->motion_params.wmmat[3] =
           (aom_read_primitive_symmetric(r, GM_ABS_ALPHA_BITS) *
            GM_ALPHA_DECODE_FACTOR) +
           (1 << WARPEDMODEL_PREC_BITS);
     // fallthrough intended
     case GLOBAL_TRANSLATION:
-      params->motion_params.wmmat[0].as_mv.row =
+      params->motion_params.wmmat[0] =
           aom_read_primitive_symmetric(r, GM_ABS_TRANS_BITS) *
           GM_TRANS_DECODE_FACTOR;
-      params->motion_params.wmmat[0].as_mv.col =
+      params->motion_params.wmmat[1] =
           aom_read_primitive_symmetric(r, GM_ABS_TRANS_BITS) *
           GM_TRANS_DECODE_FACTOR;
       break;
diff --git a/av1/decoder/decodemv.c b/av1/decoder/decodemv.c
index 50583f5..088167e 100644
--- a/av1/decoder/decodemv.c
+++ b/av1/decoder/decodemv.c
@@ -1184,10 +1184,10 @@
     case ZEROMV: {
 #if CONFIG_GLOBAL_MOTION
       mv[0].as_int =
-          cm->global_motion[ref_frame[0]].motion_params.wmmat[0].as_int;
+          gm_get_motion_vector(&cm->global_motion[ref_frame[0]]).as_int;
       if (is_compound)
         mv[1].as_int =
-            cm->global_motion[ref_frame[1]].motion_params.wmmat[0].as_int;
+            gm_get_motion_vector(&cm->global_motion[ref_frame[1]]).as_int;
 #else
       mv[0].as_int = 0;
       if (is_compound) mv[1].as_int = 0;
diff --git a/av1/encoder/bitstream.c b/av1/encoder/bitstream.c
index 75dc124..d94f863 100644
--- a/av1/encoder/bitstream.c
+++ b/av1/encoder/bitstream.c
@@ -3809,28 +3809,28 @@
     case GLOBAL_ZERO: break;
     case GLOBAL_AFFINE:
       aom_write_primitive_symmetric(
-          w, (params->motion_params.wmmat[2].as_mv.row >> GM_ALPHA_PREC_DIFF),
+          w, (params->motion_params.wmmat[4] >> GM_ALPHA_PREC_DIFF),
           GM_ABS_ALPHA_BITS);
       aom_write_primitive_symmetric(
-          w, (params->motion_params.wmmat[2].as_mv.col >> GM_ALPHA_PREC_DIFF) -
+          w, (params->motion_params.wmmat[5] >> GM_ALPHA_PREC_DIFF) -
                  (1 << GM_ALPHA_PREC_BITS),
           GM_ABS_ALPHA_BITS);
     // fallthrough intended
     case GLOBAL_ROTZOOM:
       aom_write_primitive_symmetric(
-          w, (params->motion_params.wmmat[1].as_mv.row >> GM_ALPHA_PREC_DIFF),
+          w, (params->motion_params.wmmat[2] >> GM_ALPHA_PREC_DIFF),
           GM_ABS_ALPHA_BITS);
       aom_write_primitive_symmetric(
-          w, (params->motion_params.wmmat[1].as_mv.col >> GM_ALPHA_PREC_DIFF) -
+          w, (params->motion_params.wmmat[3] >> GM_ALPHA_PREC_DIFF) -
                  (1 << GM_ALPHA_PREC_BITS),
           GM_ABS_ALPHA_BITS);
     // fallthrough intended
     case GLOBAL_TRANSLATION:
       aom_write_primitive_symmetric(
-          w, (params->motion_params.wmmat[0].as_mv.row >> GM_TRANS_PREC_DIFF),
+          w, (params->motion_params.wmmat[0] >> GM_TRANS_PREC_DIFF),
           GM_ABS_TRANS_BITS);
       aom_write_primitive_symmetric(
-          w, (params->motion_params.wmmat[0].as_mv.col >> GM_TRANS_PREC_DIFF),
+          w, (params->motion_params.wmmat[1] >> GM_TRANS_PREC_DIFF),
           GM_ABS_TRANS_BITS);
       break;
     default: assert(0);
diff --git a/av1/encoder/encodeframe.c b/av1/encoder/encodeframe.c
index 9adc8e0..bb1c151 100644
--- a/av1/encoder/encodeframe.c
+++ b/av1/encoder/encodeframe.c
@@ -4624,8 +4624,8 @@
 // Adds some offset to a global motion parameter and handles
 // all of the necessary precision shifts, clamping, and
 // zero-centering.
-static int16_t add_param_offset(int param_index, int16_t param_value,
-                                int16_t offset) {
+static int32_t add_param_offset(int param_index, int32_t param_value,
+                                int32_t offset) {
   const int scale_vals[2] = { GM_ALPHA_PREC_DIFF, GM_TRANS_PREC_DIFF };
   const int clamp_vals[2] = { GM_ALPHA_MAX, GM_TRANS_MAX };
   const int is_trans_param = param_index < 2;
@@ -4639,7 +4639,7 @@
   param_value += offset;
   // Clamp the parameter so it does not overflow the number of bits allotted
   // to it in the bitstream
-  param_value = (int16_t)clamp(param_value, -clamp_vals[is_trans_param],
+  param_value = (int32_t)clamp(param_value, -clamp_vals[is_trans_param],
                                clamp_vals[is_trans_param]);
   // Rescale the parameter to WARPEDMODEL_PRECISION_BITS so it is compatible
   // with the warped motion library
@@ -4659,12 +4659,12 @@
                                      int n_refinements) {
   int i = 0, p;
   int n_params = n_trans_model_params[wm->wmtype];
-  int16_t *param_mat = (int16_t *)wm->wmmat;
+  int32_t *param_mat = wm->wmmat;
   double step_error;
-  int16_t step;
-  int16_t *param;
-  int16_t curr_param;
-  int16_t best_param;
+  int32_t step;
+  int32_t *param;
+  int32_t curr_param;
+  int32_t best_param;
 
   double best_error =
       av1_warp_erroradv(wm,
@@ -4723,22 +4723,22 @@
 }
 
 static void convert_to_params(const double *params, TransformationType type,
-                              int16_t *model) {
+                              int32_t *model) {
   int i, diag_value;
   int alpha_present = 0;
   int n_params = n_trans_model_params[type];
-  model[0] = (int16_t)floor(params[0] * (1 << GM_TRANS_PREC_BITS) + 0.5);
-  model[1] = (int16_t)floor(params[1] * (1 << GM_TRANS_PREC_BITS) + 0.5);
-  model[0] = (int16_t)clamp(model[0], GM_TRANS_MIN, GM_TRANS_MAX) *
+  model[0] = (int32_t)floor(params[0] * (1 << GM_TRANS_PREC_BITS) + 0.5);
+  model[1] = (int32_t)floor(params[1] * (1 << GM_TRANS_PREC_BITS) + 0.5);
+  model[0] = (int32_t)clamp(model[0], GM_TRANS_MIN, GM_TRANS_MAX) *
              GM_TRANS_DECODE_FACTOR;
-  model[1] = (int16_t)clamp(model[1], GM_TRANS_MIN, GM_TRANS_MAX) *
+  model[1] = (int32_t)clamp(model[1], GM_TRANS_MIN, GM_TRANS_MAX) *
              GM_TRANS_DECODE_FACTOR;
 
   for (i = 2; i < n_params; ++i) {
     diag_value = ((i & 1) ? (1 << GM_ALPHA_PREC_BITS) : 0);
-    model[i] = (int16_t)floor(params[i] * (1 << GM_ALPHA_PREC_BITS) + 0.5);
+    model[i] = (int32_t)floor(params[i] * (1 << GM_ALPHA_PREC_BITS) + 0.5);
     model[i] =
-        (int16_t)(clamp(model[i] - diag_value, GM_ALPHA_MIN, GM_ALPHA_MAX) +
+        (int32_t)(clamp(model[i] - diag_value, GM_ALPHA_MIN, GM_ALPHA_MAX) +
                   diag_value) *
         GM_ALPHA_DECODE_FACTOR;
     alpha_present |= (model[i] != 0);
@@ -4757,7 +4757,7 @@
                                     Global_Motion_Params *model) {
   // TODO(sarahparker) implement for homography
   if (type > HOMOGRAPHY)
-    convert_to_params(params, type, (int16_t *)model->motion_params.wmmat);
+    convert_to_params(params, type, model->motion_params.wmmat);
   model->gmtype = get_gmtype(model);
   model->motion_params.wmtype = gm_to_trans_type(model->gmtype);
 }
diff --git a/av1/encoder/rdopt.c b/av1/encoder/rdopt.c
index dfd7163..c0abb68 100644
--- a/av1/encoder/rdopt.c
+++ b/av1/encoder/rdopt.c
@@ -4306,13 +4306,14 @@
   int gmtype_cost[GLOBAL_MOTION_TYPES];
   int bits;
   av1_cost_tokens(gmtype_cost, probs, av1_global_motion_types_tree);
-  if (gm->motion_params.wmmat[2].as_int) {
+  if (gm->motion_params.wmmat[5] || gm->motion_params.wmmat[4]) {
     bits = (GM_ABS_TRANS_BITS + 1) * 2 + 4 * GM_ABS_ALPHA_BITS + 4;
-  } else if (gm->motion_params.wmmat[1].as_int) {
+  } else if (gm->motion_params.wmmat[3] || gm->motion_params.wmmat[2]) {
     bits = (GM_ABS_TRANS_BITS + 1) * 2 + 2 * GM_ABS_ALPHA_BITS + 2;
   } else {
-    bits =
-        (gm->motion_params.wmmat[0].as_int ? ((GM_ABS_TRANS_BITS + 1) * 2) : 0);
+    bits = ((gm->motion_params.wmmat[1] || gm->motion_params.wmmat[0])
+                ? ((GM_ABS_TRANS_BITS + 1) * 2)
+                : 0);
   }
   return bits ? (bits << AV1_PROB_COST_SHIFT) + gmtype_cost[gm->gmtype] : 0;
 }
@@ -4390,14 +4391,14 @@
       break;
     case ZEROMV:
 #if CONFIG_GLOBAL_MOTION
-      this_mv[0].as_int = cpi->common.global_motion[mbmi->ref_frame[0]]
-                              .motion_params.wmmat[0]
-                              .as_int;
+      this_mv[0].as_int =
+          gm_get_motion_vector(&cpi->common.global_motion[mbmi->ref_frame[0]])
+              .as_int;
       thismvcost += GLOBAL_MOTION_RATE(mbmi->ref_frame[0]);
       if (is_compound) {
-        this_mv[1].as_int = cpi->common.global_motion[mbmi->ref_frame[1]]
-                                .motion_params.wmmat[0]
-                                .as_int;
+        this_mv[1].as_int =
+            gm_get_motion_vector(&cpi->common.global_motion[mbmi->ref_frame[1]])
+                .as_int;
         thismvcost += GLOBAL_MOTION_RATE(mbmi->ref_frame[1]);
       }
 #else   // CONFIG_GLOBAL_MOTION
@@ -5173,7 +5174,7 @@
 #endif  // CONFIG_EXT_INTER
 #if CONFIG_GLOBAL_MOTION
         frame_mv[ZEROMV][frame].as_int =
-            cm->global_motion[frame].motion_params.wmmat[0].as_int;
+            gm_get_motion_vector(&cm->global_motion[frame]).as_int;
 #else   // CONFIG_GLOBAL_MOTION
         frame_mv[ZEROMV][frame].as_int = 0;
 #endif  // CONFIG_GLOBAL_MOTION
@@ -8534,7 +8535,7 @@
     frame_mv[NEWMV][ref_frame].as_int = INVALID_MV;
 #if CONFIG_GLOBAL_MOTION
     frame_mv[ZEROMV][ref_frame].as_int =
-        cm->global_motion[ref_frame].motion_params.wmmat[0].as_int;
+        gm_get_motion_vector(&cm->global_motion[ref_frame]).as_int;
 #else   // CONFIG_GLOBAL_MOTION
     frame_mv[ZEROMV][ref_frame].as_int = 0;
 #endif  // CONFIG_GLOBAL_MOTION
@@ -8628,7 +8629,7 @@
       mode_skip_mask[ALTREF_FRAME] = ~INTER_NEAREST_NEAR_ZERO;
 #if CONFIG_GLOBAL_MOTION
       zeromv.as_int =
-          cm->global_motion[ALTREF_FRAME].motion_params.wmmat[0].as_int;
+          gm_get_motion_vector(&cm->global_motion[ALTREF_FRAME]).as_int;
 #else
       zeromv.as_int = 0;
 #endif  // CONFIG_GLOBAL_MOTION
@@ -9728,10 +9729,10 @@
     const uint8_t rf_type = av1_ref_frame_type(best_mbmode.ref_frame);
 #endif  // CONFIG_REF_MV
 #if CONFIG_GLOBAL_MOTION
-    zeromv[0].as_int = cm->global_motion[refs[0]].motion_params.wmmat[0].as_int;
+    zeromv[0].as_int = gm_get_motion_vector(&cm->global_motion[refs[0]]).as_int;
     zeromv[1].as_int =
         comp_pred_mode
-            ? cm->global_motion[refs[1]].motion_params.wmmat[0].as_int
+            ? gm_get_motion_vector(&cm->global_motion[refs[1]]).as_int
             : 0;
 #else
     zeromv[0].as_int = 0;
@@ -9992,7 +9993,7 @@
   mbmi->ref_frame[1] = NONE;
 #if CONFIG_GLOBAL_MOTION
   mbmi->mv[0].as_int =
-      cm->global_motion[mbmi->ref_frame[0]].motion_params.wmmat[0].as_int;
+      gm_get_motion_vector(&cm->global_motion[mbmi->ref_frame[0]]).as_int;
 #else   // CONFIG_GLOBAL_MOTION
   mbmi->mv[0].as_int = 0;
 #endif  // CONFIG_GLOBAL_MOTION