New reference signaling

This is a new experiment, which removes all the named references and uses ranked
references instead. The last 4 commits are main changes for this experiment, while 
the other 9 commits are cleanups on the baseline.
diff --git a/.clang-format b/.clang-format
index a378820..70fe9f2 100644
--- a/.clang-format
+++ b/.clang-format
@@ -1,7 +1,7 @@
 ---
 Language:        Cpp
 # BasedOnStyle:  Google
-# Generated with clang-format 7.0.1
+# Generated with clang-format 11.1.0
 AccessModifierOffset: -1
 AlignAfterOpenBracket: Align
 AlignConsecutiveAssignments: false
diff --git a/.cmake-format.py b/.cmake-format.py
index 7b0e4f0..56bea40 100644
--- a/.cmake-format.py
+++ b/.cmake-format.py
@@ -1,102 +1,241 @@
-# Generated with cmake-format 0.5.1
-# How wide to allow formatted cmake files
-line_width = 80
+# Generated with cmake-format 0.6.13
 
-# How many spaces to tab for indent
-tab_size = 2
+# ----------------------------------
+# Options affecting listfile parsing
+# ----------------------------------
+with section("parse"):
 
-# If arglists are longer than this, break them always
-max_subargs_per_line = 10
+  # Specify structure for custom cmake functions
+  additional_commands = {}
 
-# If true, separate flow control names from their parentheses with a space
-separate_ctrl_name_with_space = False
+  # Override configurations per-command where available
+  override_spec = {}
 
-# If true, separate function names from parentheses with a space
-separate_fn_name_with_space = False
+  # Specify variable tags.
+  vartags = []
 
-# If a statement is wrapped to more than one line, than dangle the closing
-# parenthesis on it's own line
-dangle_parens = False
+  # Specify property tags.
+  proptags = []
 
-# What character to use for bulleted lists
-bullet_char = '*'
+# -----------------------------
+# Options affecting formatting.
+# -----------------------------
+with section("format"):
 
-# What character to use as punctuation after numerals in an enumerated list
-enum_char = '.'
+  # Disable formatting entirely, making cmake-format a no-op
+  disable = False
 
-# What style line endings to use in the output.
-line_ending = u'unix'
+  # How wide to allow formatted cmake files
+  line_width = 80
 
-# Format command names consistently as 'lower' or 'upper' case
-command_case = u'lower'
+  # How many spaces to tab for indent
+  tab_size = 2
 
-# Format keywords consistently as 'lower' or 'upper' case
-keyword_case = u'unchanged'
+  # If true, lines are indented using tab characters (utf-8 0x09) instead of
+  # <tab_size> space characters (utf-8 0x20). In cases where the layout would
+  # require a fractional tab character, the behavior of the  fractional
+  # indentation is governed by <fractional_tab_policy>
+  use_tabchars = False
 
-# Specify structure for custom cmake functions
-additional_commands = {
-  "foo": {
-    "flags": [
-      "BAR",
-      "BAZ"
-    ],
-    "kwargs": {
-      "HEADERS": "*",
-      "DEPENDS": "*",
-      "SOURCES": "*"
-    }
-  }
-}
+  # If <use_tabchars> is True, then the value of this variable indicates how
+  # fractional indentions are handled during whitespace replacement. If set to
+  # 'use-space', fractional indentation is left as spaces (utf-8 0x20). If set
+  # to `round-up` fractional indentation is replaced with a single tab character
+  # (utf-8 0x09) effectively shifting the column to the next tabstop
+  fractional_tab_policy = 'use-space'
 
-# A list of command names which should always be wrapped
-always_wrap = []
+  # If an argument group contains more than this many sub-groups (parg or kwarg
+  # groups) then force it to a vertical layout.
+  max_subgroups_hwrap = 2
 
-# Specify the order of wrapping algorithms during successive reflow attempts
-algorithm_order = [0, 1, 2, 3, 4]
+  # If a positional argument group contains more than this many arguments, then
+  # force it to a vertical layout.
+  max_pargs_hwrap = 6
 
-# If true, the argument lists which are known to be sortable will be sorted
-# lexicographicall
-autosort = False
+  # If a cmdline positional group consumes more than this many lines without
+  # nesting, then invalidate the layout (and nest)
+  max_rows_cmdline = 2
 
-# enable comment markup parsing and reflow
-enable_markup = True
+  # If true, separate flow control names from their parentheses with a space
+  separate_ctrl_name_with_space = False
 
-# If comment markup is enabled, don't reflow the first comment block in
-# eachlistfile. Use this to preserve formatting of your
-# copyright/licensestatements.
-first_comment_is_literal = False
+  # If true, separate function names from parentheses with a space
+  separate_fn_name_with_space = False
 
-# If comment markup is enabled, don't reflow any comment block which matchesthis
-# (regex) pattern. Default is `None` (disabled).
-literal_comment_pattern = None
+  # If a statement is wrapped to more than one line, than dangle the closing
+  # parenthesis on its own line.
+  dangle_parens = False
 
-# Regular expression to match preformat fences in comments
-# default=r'^\s*([`~]{3}[`~]*)(.*)$'
-fence_pattern = u'^\\s*([`~]{3}[`~]*)(.*)$'
+  # If the trailing parenthesis must be 'dangled' on its on line, then align it
+  # to this reference: `prefix`: the start of the statement,  `prefix-indent`:
+  # the start of the statement, plus one indentation  level, `child`: align to
+  # the column of the arguments
+  dangle_align = 'prefix'
 
-# Regular expression to match rulers in comments
-# default=r'^\s*[^\w\s]{3}.*[^\w\s]{3}$'
-ruler_pattern = u'^\\s*[^\\w\\s]{3}.*[^\\w\\s]{3}$'
+  # If the statement spelling length (including space and parenthesis) is
+  # smaller than this amount, then force reject nested layouts.
+  min_prefix_chars = 4
 
-# If true, emit the unicode byte-order mark (BOM) at the start of the file
-emit_byteorder_mark = False
+  # If the statement spelling length (including space and parenthesis) is larger
+  # than the tab width by more than this amount, then force reject un-nested
+  # layouts.
+  max_prefix_chars = 10
 
-# If a comment line starts with at least this many consecutive hash characters,
-# then don't lstrip() them off. This allows for lazy hash rulers where the first
-# hash char is not separated by space
-hashruler_min_length = 10
+  # If a candidate layout is wrapped horizontally but it exceeds this many
+  # lines, then reject the layout.
+  max_lines_hwrap = 2
 
-# If true, then insert a space between the first hash char and remaining hash
-# chars in a hash ruler, and normalize it's length to fill the column
-canonicalize_hashrulers = True
+  # What style line endings to use in the output.
+  line_ending = 'unix'
 
-# Specify the encoding of the input file. Defaults to utf-8.
-input_encoding = u'utf-8'
+  # Format command names consistently as 'lower' or 'upper' case
+  command_case = 'lower'
 
-# Specify the encoding of the output file. Defaults to utf-8. Note that cmake
-# only claims to support utf-8 so be careful when using anything else
-output_encoding = u'utf-8'
+  # Format keywords consistently as 'lower' or 'upper' case
+  keyword_case = 'unchanged'
 
-# A dictionary containing any per-command configuration overrides. Currently
-# only `command_case` is supported.
-per_command = {}
+  # A list of command names which should always be wrapped
+  always_wrap = []
+
+  # If true, the argument lists which are known to be sortable will be sorted
+  # lexicographicall
+  enable_sort = True
+
+  # If true, the parsers may infer whether or not an argument list is sortable
+  # (without annotation).
+  autosort = False
+
+  # By default, if cmake-format cannot successfully fit everything into the
+  # desired linewidth it will apply the last, most agressive attempt that it
+  # made. If this flag is True, however, cmake-format will print error, exit
+  # with non-zero status code, and write-out nothing
+  require_valid_layout = False
+
+  # A dictionary mapping layout nodes to a list of wrap decisions. See the
+  # documentation for more information.
+  layout_passes = {}
+
+# ------------------------------------------------
+# Options affecting comment reflow and formatting.
+# ------------------------------------------------
+with section("markup"):
+
+  # What character to use for bulleted lists
+  bullet_char = '*'
+
+  # What character to use as punctuation after numerals in an enumerated list
+  enum_char = '.'
+
+  # If comment markup is enabled, don't reflow the first comment block in each
+  # listfile. Use this to preserve formatting of your copyright/license
+  # statements.
+  first_comment_is_literal = False
+
+  # If comment markup is enabled, don't reflow any comment block which matches
+  # this (regex) pattern. Default is `None` (disabled).
+  literal_comment_pattern = None
+
+  # Regular expression to match preformat fences in comments default=
+  # ``r'^\s*([`~]{3}[`~]*)(.*)$'``
+  fence_pattern = '^\\s*([`~]{3}[`~]*)(.*)$'
+
+  # Regular expression to match rulers in comments default=
+  # ``r'^\s*[^\w\s]{3}.*[^\w\s]{3}$'``
+  ruler_pattern = '^\\s*[^\\w\\s]{3}.*[^\\w\\s]{3}$'
+
+  # If a comment line matches starts with this pattern then it is explicitly a
+  # trailing comment for the preceeding argument. Default is '#<'
+  explicit_trailing_pattern = '#<'
+
+  # If a comment line starts with at least this many consecutive hash
+  # characters, then don't lstrip() them off. This allows for lazy hash rulers
+  # where the first hash char is not separated by space
+  hashruler_min_length = 10
+
+  # If true, then insert a space between the first hash char and remaining hash
+  # chars in a hash ruler, and normalize its length to fill the column
+  canonicalize_hashrulers = True
+
+  # enable comment markup parsing and reflow
+  enable_markup = True
+
+# ----------------------------
+# Options affecting the linter
+# ----------------------------
+with section("lint"):
+
+  # a list of lint codes to disable
+  disabled_codes = []
+
+  # regular expression pattern describing valid function names
+  function_pattern = '[0-9a-z_]+'
+
+  # regular expression pattern describing valid macro names
+  macro_pattern = '[0-9A-Z_]+'
+
+  # regular expression pattern describing valid names for variables with global
+  # (cache) scope
+  global_var_pattern = '[A-Z][0-9A-Z_]+'
+
+  # regular expression pattern describing valid names for variables with global
+  # scope (but internal semantic)
+  internal_var_pattern = '_[A-Z][0-9A-Z_]+'
+
+  # regular expression pattern describing valid names for variables with local
+  # scope
+  local_var_pattern = '[a-z][a-z0-9_]+'
+
+  # regular expression pattern describing valid names for privatedirectory
+  # variables
+  private_var_pattern = '_[0-9a-z_]+'
+
+  # regular expression pattern describing valid names for public directory
+  # variables
+  public_var_pattern = '[A-Z][0-9A-Z_]+'
+
+  # regular expression pattern describing valid names for function/macro
+  # arguments and loop variables.
+  argument_var_pattern = '[a-z][a-z0-9_]+'
+
+  # regular expression pattern describing valid names for keywords used in
+  # functions or macros
+  keyword_pattern = '[A-Z][0-9A-Z_]+'
+
+  # In the heuristic for C0201, how many conditionals to match within a loop in
+  # before considering the loop a parser.
+  max_conditionals_custom_parser = 2
+
+  # Require at least this many newlines between statements
+  min_statement_spacing = 1
+
+  # Require no more than this many newlines between statements
+  max_statement_spacing = 2
+  max_returns = 6
+  max_branches = 12
+  max_arguments = 5
+  max_localvars = 15
+  max_statements = 50
+
+# -------------------------------
+# Options affecting file encoding
+# -------------------------------
+with section("encode"):
+
+  # If true, emit the unicode byte-order mark (BOM) at the start of the file
+  emit_byteorder_mark = False
+
+  # Specify the encoding of the input file. Defaults to utf-8
+  input_encoding = 'utf-8'
+
+  # Specify the encoding of the output file. Defaults to utf-8. Note that cmake
+  # only claims to support utf-8 so be careful when using anything else
+  output_encoding = 'utf-8'
+
+# -------------------------------------
+# Miscellaneous configurations options.
+# -------------------------------------
+with section("misc"):
+
+  # A dictionary containing any per-command configuration overrides. Currently
+  # only `command_case` is supported.
+  per_command = {}
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 1b79f52..f42bfe6 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -4,7 +4,7 @@
   - test
   - report
 
-image: registry.gitlab.com/epirat/images/ubuntu2004:20210225223748
+image: registry.gitlab.com/aomediacodec/aom-testing/ubuntu2004:20211125032922
 
 default:
   tags:
@@ -21,18 +21,24 @@
 Style Check:
   stage: check
   interruptible: true
-  image: registry.gitlab.com/aomediacodec/aom-testing/alpine3
-  before_script:
-    - apk add --no-cache git clang
+  image: registry.gitlab.com/aomediacodec/aom-testing/alpine3:20210901124702
+  variables:
+    DIFF_REF: $CI_MERGE_REQUEST_DIFF_BASE_SHA
   script:
+    - 'echo "Diff ref is: $DIFF_REF"'
+    - git fetch --unshallow
     - |
-      # Run clang-format
-      for f in $(git ls-files '*.[hc]pp' '*.cc' '*.[ch]' | grep -v third_party); do
-        clang-format -i --style=file $f
+      # Run clang-format check.
+      for f in $(git diff --diff-filter=ACMR --name-only $DIFF_REF '*.[hc]pp' '*.cc' '*.[ch]' \
+        | grep -v third_party); do
+        clang-format -i --style=file $f -n -Werror
       done
     - |
-      # Run cmake-format
-      git ls-files '*.cmake' 'CMakeLists.txt' | grep -v third_party | xargs cmake-format -i
+      # Run cmake-format check.
+      for f in $(git diff --diff-filter=ACMR --name-only $DIFF_REF '*.cmake' 'CMakeLists.txt' \
+        | grep -v third_party); do
+        cmake-format --check $f
+      done
   rules:
     - if: '$CI_PIPELINE_SOURCE == "schedule"'
       when: never
@@ -41,7 +47,7 @@
 .commit-checks-common:
   stage: check
   interruptible: true
-  image: registry.gitlab.com/aomediacodec/aom-testing/alpine3
+  image: registry.gitlab.com/aomediacodec/aom-testing/alpine3:20210901124702
   script:
     - 'echo "Diff ref is: $DIFF_REF"'
     - git fetch --unshallow
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e6f489f..1f97624 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,12 +1,12 @@
 #
-# Copyright (c) 2016, Alliance for Open Media. All rights reserved
+# Copyright (c) 2021, Alliance for Open Media. All rights reserved
 #
-# This source code is subject to the terms of the BSD 2 Clause License and the
-# Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License was
-# not distributed with this source code in the LICENSE file, you can obtain it
-# at www.aomedia.org/license/software. If the Alliance for Open Media Patent
-# License 1.0 was not distributed with this source code in the PATENTS file, you
-# can obtain it at www.aomedia.org/license/patent.
+# This source code is subject to the terms of the BSD 3-Clause Clear License and
+# the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+# License was not distributed with this source code in the LICENSE file, you can
+# obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance
+# for Open Media Patent License 1.0 was not distributed with this source code in
+# the PATENTS file, you can obtain it at aomedia.org/license/patent-license/.
 #
 cmake_minimum_required(VERSION 3.5)
 
@@ -14,14 +14,16 @@
 set(AOM_CONFIG_DIR "${CMAKE_CURRENT_BINARY_DIR}")
 if("${AOM_ROOT}" STREQUAL "${AOM_CONFIG_DIR}")
   message(
-    FATAL_ERROR "Building from within the aom source tree is not supported.\n"
-                "Hint: Run these commands\n"
-                "$ rm -rf CMakeCache.txt CMakeFiles\n"
-                "$ mkdir -p ../aom_build\n" "$ cd ../aom_build\n"
-                "And re-run CMake from the aom_build directory.")
+    FATAL_ERROR
+      "Building from within the aom source tree is not supported.\n"
+      "Hint: Run these commands\n"
+      "$ rm -rf CMakeCache.txt CMakeFiles\n"
+      "$ mkdir -p ../aom_build\n"
+      "$ cd ../aom_build\n"
+      "And re-run CMake from the aom_build directory.")
 endif()
 
-project(AOM C CXX)
+project(AVM C CXX)
 
 if(NOT EMSCRIPTEN)
   if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
@@ -50,130 +52,147 @@
 include("${AOM_ROOT}/build/cmake/util.cmake")
 include("${AOM_ROOT}/test/test.cmake")
 
-list(APPEND AOM_RTCD_SOURCES
-            "${AOM_CONFIG_DIR}/config/aom_dsp_rtcd.h"
-            "${AOM_CONFIG_DIR}/config/aom_scale_rtcd.h"
-            "${AOM_CONFIG_DIR}/config/av1_rtcd.h"
-            "${AOM_ROOT}/aom_dsp/aom_dsp_rtcd_defs.pl"
-            "${AOM_ROOT}/aom_dsp/aom_dsp_rtcd.c"
-            "${AOM_ROOT}/aom_scale/aom_scale_rtcd.pl"
-            "${AOM_ROOT}/aom_scale/aom_scale_rtcd.c"
-            "${AOM_ROOT}/av1/common/av1_rtcd_defs.pl"
-            "${AOM_ROOT}/av1/common/av1_rtcd.c"
-            "${AOM_ROOT}/build/cmake/rtcd.pl")
+list(
+  APPEND
+  AOM_RTCD_SOURCES
+  "${AOM_CONFIG_DIR}/config/aom_dsp_rtcd.h"
+  "${AOM_CONFIG_DIR}/config/aom_scale_rtcd.h"
+  "${AOM_CONFIG_DIR}/config/av1_rtcd.h"
+  "${AOM_ROOT}/aom_dsp/aom_dsp_rtcd_defs.pl"
+  "${AOM_ROOT}/aom_dsp/aom_dsp_rtcd.c"
+  "${AOM_ROOT}/aom_scale/aom_scale_rtcd.pl"
+  "${AOM_ROOT}/aom_scale/aom_scale_rtcd.c"
+  "${AOM_ROOT}/av1/common/av1_rtcd_defs.pl"
+  "${AOM_ROOT}/av1/common/av1_rtcd.c"
+  "${AOM_ROOT}/build/cmake/rtcd.pl")
 
-list(APPEND AOM_LIBWEBM_SOURCES
-            "${AOM_ROOT}/third_party/libwebm/common/hdr_util.cc"
-            "${AOM_ROOT}/third_party/libwebm/common/hdr_util.h"
-            "${AOM_ROOT}/third_party/libwebm/common/webmids.h"
-            "${AOM_ROOT}/third_party/libwebm/mkvmuxer/mkvmuxer.cc"
-            "${AOM_ROOT}/third_party/libwebm/mkvmuxer/mkvmuxer.h"
-            "${AOM_ROOT}/third_party/libwebm/mkvmuxer/mkvmuxertypes.h"
-            "${AOM_ROOT}/third_party/libwebm/mkvmuxer/mkvmuxerutil.cc"
-            "${AOM_ROOT}/third_party/libwebm/mkvmuxer/mkvmuxerutil.h"
-            "${AOM_ROOT}/third_party/libwebm/mkvmuxer/mkvwriter.cc"
-            "${AOM_ROOT}/third_party/libwebm/mkvmuxer/mkvwriter.h"
-            "${AOM_ROOT}/third_party/libwebm/mkvparser/mkvparser.cc"
-            "${AOM_ROOT}/third_party/libwebm/mkvparser/mkvparser.h"
-            "${AOM_ROOT}/third_party/libwebm/mkvparser/mkvreader.cc"
-            "${AOM_ROOT}/third_party/libwebm/mkvparser/mkvreader.h")
+list(
+  APPEND
+  AOM_LIBWEBM_SOURCES
+  "${AOM_ROOT}/third_party/libwebm/common/hdr_util.cc"
+  "${AOM_ROOT}/third_party/libwebm/common/hdr_util.h"
+  "${AOM_ROOT}/third_party/libwebm/common/webmids.h"
+  "${AOM_ROOT}/third_party/libwebm/mkvmuxer/mkvmuxer.cc"
+  "${AOM_ROOT}/third_party/libwebm/mkvmuxer/mkvmuxer.h"
+  "${AOM_ROOT}/third_party/libwebm/mkvmuxer/mkvmuxertypes.h"
+  "${AOM_ROOT}/third_party/libwebm/mkvmuxer/mkvmuxerutil.cc"
+  "${AOM_ROOT}/third_party/libwebm/mkvmuxer/mkvmuxerutil.h"
+  "${AOM_ROOT}/third_party/libwebm/mkvmuxer/mkvwriter.cc"
+  "${AOM_ROOT}/third_party/libwebm/mkvmuxer/mkvwriter.h"
+  "${AOM_ROOT}/third_party/libwebm/mkvparser/mkvparser.cc"
+  "${AOM_ROOT}/third_party/libwebm/mkvparser/mkvparser.h"
+  "${AOM_ROOT}/third_party/libwebm/mkvparser/mkvreader.cc"
+  "${AOM_ROOT}/third_party/libwebm/mkvparser/mkvreader.h")
 
-list(APPEND AOM_LIBYUV_SOURCES
-            "${AOM_ROOT}/third_party/libyuv/include/libyuv/basic_types.h"
-            "${AOM_ROOT}/third_party/libyuv/include/libyuv/convert.h"
-            "${AOM_ROOT}/third_party/libyuv/include/libyuv/convert_argb.h"
-            "${AOM_ROOT}/third_party/libyuv/include/libyuv/convert_from.h"
-            "${AOM_ROOT}/third_party/libyuv/include/libyuv/cpu_id.h"
-            "${AOM_ROOT}/third_party/libyuv/include/libyuv/planar_functions.h"
-            "${AOM_ROOT}/third_party/libyuv/include/libyuv/rotate.h"
-            "${AOM_ROOT}/third_party/libyuv/include/libyuv/row.h"
-            "${AOM_ROOT}/third_party/libyuv/include/libyuv/scale.h"
-            "${AOM_ROOT}/third_party/libyuv/include/libyuv/scale_row.h"
-            "${AOM_ROOT}/third_party/libyuv/source/cpu_id.cc"
-            "${AOM_ROOT}/third_party/libyuv/source/planar_functions.cc"
-            "${AOM_ROOT}/third_party/libyuv/source/row_any.cc"
-            "${AOM_ROOT}/third_party/libyuv/source/row_common.cc"
-            "${AOM_ROOT}/third_party/libyuv/source/row_gcc.cc"
-            "${AOM_ROOT}/third_party/libyuv/source/row_mips.cc"
-            "${AOM_ROOT}/third_party/libyuv/source/row_neon.cc"
-            "${AOM_ROOT}/third_party/libyuv/source/row_neon64.cc"
-            "${AOM_ROOT}/third_party/libyuv/source/row_win.cc"
-            "${AOM_ROOT}/third_party/libyuv/source/scale.cc"
-            "${AOM_ROOT}/third_party/libyuv/source/scale_any.cc"
-            "${AOM_ROOT}/third_party/libyuv/source/scale_common.cc"
-            "${AOM_ROOT}/third_party/libyuv/source/scale_gcc.cc"
-            "${AOM_ROOT}/third_party/libyuv/source/scale_mips.cc"
-            "${AOM_ROOT}/third_party/libyuv/source/scale_neon.cc"
-            "${AOM_ROOT}/third_party/libyuv/source/scale_neon64.cc"
-            "${AOM_ROOT}/third_party/libyuv/source/scale_win.cc")
+list(
+  APPEND
+  AOM_LIBYUV_SOURCES
+  "${AOM_ROOT}/third_party/libyuv/include/libyuv/basic_types.h"
+  "${AOM_ROOT}/third_party/libyuv/include/libyuv/convert.h"
+  "${AOM_ROOT}/third_party/libyuv/include/libyuv/convert_argb.h"
+  "${AOM_ROOT}/third_party/libyuv/include/libyuv/convert_from.h"
+  "${AOM_ROOT}/third_party/libyuv/include/libyuv/cpu_id.h"
+  "${AOM_ROOT}/third_party/libyuv/include/libyuv/planar_functions.h"
+  "${AOM_ROOT}/third_party/libyuv/include/libyuv/rotate.h"
+  "${AOM_ROOT}/third_party/libyuv/include/libyuv/row.h"
+  "${AOM_ROOT}/third_party/libyuv/include/libyuv/scale.h"
+  "${AOM_ROOT}/third_party/libyuv/include/libyuv/scale_row.h"
+  "${AOM_ROOT}/third_party/libyuv/source/cpu_id.cc"
+  "${AOM_ROOT}/third_party/libyuv/source/planar_functions.cc"
+  "${AOM_ROOT}/third_party/libyuv/source/row_any.cc"
+  "${AOM_ROOT}/third_party/libyuv/source/row_common.cc"
+  "${AOM_ROOT}/third_party/libyuv/source/row_gcc.cc"
+  "${AOM_ROOT}/third_party/libyuv/source/row_mips.cc"
+  "${AOM_ROOT}/third_party/libyuv/source/row_neon.cc"
+  "${AOM_ROOT}/third_party/libyuv/source/row_neon64.cc"
+  "${AOM_ROOT}/third_party/libyuv/source/row_win.cc"
+  "${AOM_ROOT}/third_party/libyuv/source/scale.cc"
+  "${AOM_ROOT}/third_party/libyuv/source/scale_any.cc"
+  "${AOM_ROOT}/third_party/libyuv/source/scale_common.cc"
+  "${AOM_ROOT}/third_party/libyuv/source/scale_gcc.cc"
+  "${AOM_ROOT}/third_party/libyuv/source/scale_mips.cc"
+  "${AOM_ROOT}/third_party/libyuv/source/scale_neon.cc"
+  "${AOM_ROOT}/third_party/libyuv/source/scale_neon64.cc"
+  "${AOM_ROOT}/third_party/libyuv/source/scale_win.cc")
 
-list(APPEND AOM_SOURCES
-            "${AOM_CONFIG_DIR}/config/aom_config.c"
-            "${AOM_CONFIG_DIR}/config/aom_config.h"
-            "${AOM_ROOT}/aom/aom.h"
-            "${AOM_ROOT}/aom/aom_codec.h"
-            "${AOM_ROOT}/aom/aom_decoder.h"
-            "${AOM_ROOT}/aom/aom_encoder.h"
-            "${AOM_ROOT}/aom/aom_frame_buffer.h"
-            "${AOM_ROOT}/aom/aom_image.h"
-            "${AOM_ROOT}/aom/aom_integer.h"
-            "${AOM_ROOT}/aom/aomcx.h"
-            "${AOM_ROOT}/aom/aomdx.h"
-            "${AOM_ROOT}/aom/internal/aom_codec_internal.h"
-            "${AOM_ROOT}/aom/internal/aom_image_internal.h"
-            "${AOM_ROOT}/aom/src/aom_codec.c"
-            "${AOM_ROOT}/aom/src/aom_decoder.c"
-            "${AOM_ROOT}/aom/src/aom_encoder.c"
-            "${AOM_ROOT}/aom/src/aom_image.c"
-            "${AOM_ROOT}/aom/src/aom_integer.c")
+list(
+  APPEND
+  AOM_SOURCES
+  "${AOM_CONFIG_DIR}/config/aom_config.c"
+  "${AOM_CONFIG_DIR}/config/aom_config.h"
+  "${AOM_ROOT}/aom/aom.h"
+  "${AOM_ROOT}/aom/aom_codec.h"
+  "${AOM_ROOT}/aom/aom_decoder.h"
+  "${AOM_ROOT}/aom/aom_encoder.h"
+  "${AOM_ROOT}/aom/aom_frame_buffer.h"
+  "${AOM_ROOT}/aom/aom_image.h"
+  "${AOM_ROOT}/aom/aom_integer.h"
+  "${AOM_ROOT}/aom/aomcx.h"
+  "${AOM_ROOT}/aom/aomdx.h"
+  "${AOM_ROOT}/aom/internal/aom_codec_internal.h"
+  "${AOM_ROOT}/aom/internal/aom_image_internal.h"
+  "${AOM_ROOT}/aom/src/aom_codec.c"
+  "${AOM_ROOT}/aom/src/aom_decoder.c"
+  "${AOM_ROOT}/aom/src/aom_encoder.c"
+  "${AOM_ROOT}/aom/src/aom_image.c"
+  "${AOM_ROOT}/aom/src/aom_integer.c")
 
-list(APPEND AOM_COMMON_APP_UTIL_SOURCES
-            "${AOM_ROOT}/av1/arg_defs.h"
-            "${AOM_ROOT}/av1/arg_defs.c"
-            "${AOM_ROOT}/common/args_helper.c"
-            "${AOM_ROOT}/common/args_helper.h"
-            "${AOM_ROOT}/common/args.c"
-            "${AOM_ROOT}/common/args.h"
-            "${AOM_ROOT}/common/av1_config.c"
-            "${AOM_ROOT}/common/av1_config.h"
-            "${AOM_ROOT}/common/md5_utils.c"
-            "${AOM_ROOT}/common/md5_utils.h"
-            "${AOM_ROOT}/common/tools_common.c"
-            "${AOM_ROOT}/common/tools_common.h"
-            "${AOM_ROOT}/common/video_common.h"
-            "${AOM_ROOT}/common/rawenc.c"
-            "${AOM_ROOT}/common/rawenc.h"
-            "${AOM_ROOT}/common/y4menc.c"
-            "${AOM_ROOT}/common/y4menc.h")
+list(
+  APPEND
+  AOM_COMMON_APP_UTIL_SOURCES
+  "${AOM_ROOT}/av1/arg_defs.h"
+  "${AOM_ROOT}/av1/arg_defs.c"
+  "${AOM_ROOT}/common/args_helper.c"
+  "${AOM_ROOT}/common/args_helper.h"
+  "${AOM_ROOT}/common/args.c"
+  "${AOM_ROOT}/common/args.h"
+  "${AOM_ROOT}/common/av1_config.c"
+  "${AOM_ROOT}/common/av1_config.h"
+  "${AOM_ROOT}/common/md5_utils.c"
+  "${AOM_ROOT}/common/md5_utils.h"
+  "${AOM_ROOT}/common/tools_common.c"
+  "${AOM_ROOT}/common/tools_common.h"
+  "${AOM_ROOT}/common/video_common.h"
+  "${AOM_ROOT}/common/rawenc.c"
+  "${AOM_ROOT}/common/rawenc.h"
+  "${AOM_ROOT}/common/y4menc.c"
+  "${AOM_ROOT}/common/y4menc.h")
 
-list(APPEND AOM_DECODER_APP_UTIL_SOURCES "${AOM_ROOT}/common/ivfdec.c"
-            "${AOM_ROOT}/common/ivfdec.h" "${AOM_ROOT}/common/obudec.c"
-            "${AOM_ROOT}/common/obudec.h" "${AOM_ROOT}/common/video_reader.c"
-            "${AOM_ROOT}/common/video_reader.h")
+list(
+  APPEND
+  AOM_DECODER_APP_UTIL_SOURCES
+  "${AOM_ROOT}/common/ivfdec.c"
+  "${AOM_ROOT}/common/ivfdec.h"
+  "${AOM_ROOT}/common/obudec.c"
+  "${AOM_ROOT}/common/obudec.h"
+  "${AOM_ROOT}/common/video_reader.c"
+  "${AOM_ROOT}/common/video_reader.h")
 
-list(APPEND AOM_ENCODER_APP_UTIL_SOURCES
-            "${AOM_ROOT}/common/ivfenc.c"
-            "${AOM_ROOT}/common/ivfenc.h"
-            "${AOM_ROOT}/common/video_writer.c"
-            "${AOM_ROOT}/common/video_writer.h"
-            "${AOM_ROOT}/common/warnings.c"
-            "${AOM_ROOT}/common/warnings.h"
-            "${AOM_ROOT}/common/y4minput.c"
-            "${AOM_ROOT}/common/y4minput.h"
-            "${AOM_ROOT}/common/stream_iter.c"
-            "${AOM_ROOT}/examples/encoder_util.h"
-            "${AOM_ROOT}/examples/encoder_util.c")
+list(
+  APPEND
+  AOM_ENCODER_APP_UTIL_SOURCES
+  "${AOM_ROOT}/common/ivfenc.c"
+  "${AOM_ROOT}/common/ivfenc.h"
+  "${AOM_ROOT}/common/video_writer.c"
+  "${AOM_ROOT}/common/video_writer.h"
+  "${AOM_ROOT}/common/warnings.c"
+  "${AOM_ROOT}/common/warnings.h"
+  "${AOM_ROOT}/common/y4minput.c"
+  "${AOM_ROOT}/common/y4minput.h"
+  "${AOM_ROOT}/common/stream_iter.c"
+  "${AOM_ROOT}/examples/encoder_util.h"
+  "${AOM_ROOT}/examples/encoder_util.c")
 
 list(APPEND AOM_ENCODER_STATS_SOURCES "${AOM_ROOT}/stats/rate_hist.c"
-            "${AOM_ROOT}/stats/rate_hist.h")
+     "${AOM_ROOT}/stats/rate_hist.h")
 
 list(APPEND AOM_VERSION_SOURCES "${AOM_CONFIG_DIR}/config/aom_version.h")
 
 list(APPEND AOM_WEBM_DECODER_SOURCES "${AOM_ROOT}/common/webmdec.cc"
-            "${AOM_ROOT}/common/webmdec.h")
+     "${AOM_ROOT}/common/webmdec.h")
 
 list(APPEND AOM_WEBM_ENCODER_SOURCES "${AOM_ROOT}/common/webmenc.cc"
-            "${AOM_ROOT}/common/webmenc.h")
+     "${AOM_ROOT}/common/webmenc.h")
 
 include_directories(${AOM_ROOT} ${AOM_CONFIG_DIR} ${AOM_ROOT}/apps
                     ${AOM_ROOT}/common ${AOM_ROOT}/examples ${AOM_ROOT}/stats)
@@ -181,50 +200,52 @@
 # Targets
 add_library(aom_version ${AOM_VERSION_SOURCES})
 add_dummy_source_file_to_target(aom_version c)
-add_custom_command(OUTPUT "${AOM_CONFIG_DIR}/config/aom_version.h"
-                   COMMAND ${CMAKE_COMMAND} ARGS
-                           -DAOM_CONFIG_DIR=${AOM_CONFIG_DIR}
-                           -DAOM_ROOT=${AOM_ROOT}
-                           -DGIT_EXECUTABLE=${GIT_EXECUTABLE}
-                           -DPERL_EXECUTABLE=${PERL_EXECUTABLE} -P
-                           "${AOM_ROOT}/build/cmake/version.cmake"
-                   COMMENT "Writing aom_version.h"
-                   VERBATIM)
+add_custom_command(
+  OUTPUT "${AOM_CONFIG_DIR}/config/aom_version.h"
+  COMMAND
+    ${CMAKE_COMMAND} ARGS -DAOM_CONFIG_DIR=${AOM_CONFIG_DIR}
+    -DAOM_ROOT=${AOM_ROOT} -DGIT_EXECUTABLE=${GIT_EXECUTABLE}
+    -DPERL_EXECUTABLE=${PERL_EXECUTABLE} -P
+    "${AOM_ROOT}/build/cmake/version.cmake"
+  COMMENT "Writing aom_version.h"
+  VERBATIM)
 
-add_custom_target(aom_version_check
-                  COMMAND ${CMAKE_COMMAND}
-                          -DAOM_CONFIG_DIR=${AOM_CONFIG_DIR}
-                          -DAOM_ROOT=${AOM_ROOT}
-                          -DGIT_EXECUTABLE=${GIT_EXECUTABLE}
-                          -DPERL_EXECUTABLE=${PERL_EXECUTABLE} -P
-                          "${AOM_ROOT}/build/cmake/version.cmake"
-                  COMMENT "Updating version info if necessary."
-                  VERBATIM)
+add_custom_target(
+  aom_version_check
+  COMMAND
+    ${CMAKE_COMMAND} -DAOM_CONFIG_DIR=${AOM_CONFIG_DIR} -DAOM_ROOT=${AOM_ROOT}
+    -DGIT_EXECUTABLE=${GIT_EXECUTABLE} -DPERL_EXECUTABLE=${PERL_EXECUTABLE} -P
+    "${AOM_ROOT}/build/cmake/version.cmake"
+  COMMENT "Updating version info if necessary."
+  VERBATIM)
 
 if(BUILD_SHARED_LIBS AND NOT MSVC)
   # Generate version file immediately for non-MSVC shared builds: The version
   # string is needed for the aom target.
-  execute_process(COMMAND ${CMAKE_COMMAND}
-                          -DAOM_CONFIG_DIR=${AOM_CONFIG_DIR}
-                          -DAOM_ROOT=${AOM_ROOT}
-                          -DGIT_EXECUTABLE=${GIT_EXECUTABLE}
-                          -DPERL_EXECUTABLE=${PERL_EXECUTABLE} -P
-                          "${AOM_ROOT}/build/cmake/version.cmake")
+  execute_process(
+    COMMAND
+      ${CMAKE_COMMAND} -DAOM_CONFIG_DIR=${AOM_CONFIG_DIR}
+      -DAOM_ROOT=${AOM_ROOT} -DGIT_EXECUTABLE=${GIT_EXECUTABLE}
+      -DPERL_EXECUTABLE=${PERL_EXECUTABLE} -P
+      "${AOM_ROOT}/build/cmake/version.cmake")
 endif()
 
 add_dependencies(aom_version aom_version_check)
 
 # TODO(tomfinegan): Move rtcd target setup where it belongs for each rtcd
 # source.
-add_rtcd_build_step("${AOM_ROOT}/aom_dsp/aom_dsp_rtcd_defs.pl"
-                    "${AOM_CONFIG_DIR}/config/aom_dsp_rtcd.h"
-                    "${AOM_ROOT}/aom_dsp/aom_dsp_rtcd.c" "aom_dsp_rtcd")
-add_rtcd_build_step("${AOM_ROOT}/aom_scale/aom_scale_rtcd.pl"
-                    "${AOM_CONFIG_DIR}/config/aom_scale_rtcd.h"
-                    "${AOM_ROOT}/aom_scale/aom_scale_rtcd.c" "aom_scale_rtcd")
-add_rtcd_build_step("${AOM_ROOT}/av1/common/av1_rtcd_defs.pl"
-                    "${AOM_CONFIG_DIR}/config/av1_rtcd.h"
-                    "${AOM_ROOT}/av1/common/av1_rtcd.c" "av1_rtcd")
+add_rtcd_build_step(
+  "${AOM_ROOT}/aom_dsp/aom_dsp_rtcd_defs.pl"
+  "${AOM_CONFIG_DIR}/config/aom_dsp_rtcd.h"
+  "${AOM_ROOT}/aom_dsp/aom_dsp_rtcd.c" "aom_dsp_rtcd")
+add_rtcd_build_step(
+  "${AOM_ROOT}/aom_scale/aom_scale_rtcd.pl"
+  "${AOM_CONFIG_DIR}/config/aom_scale_rtcd.h"
+  "${AOM_ROOT}/aom_scale/aom_scale_rtcd.c" "aom_scale_rtcd")
+add_rtcd_build_step(
+  "${AOM_ROOT}/av1/common/av1_rtcd_defs.pl"
+  "${AOM_CONFIG_DIR}/config/av1_rtcd.h" "${AOM_ROOT}/av1/common/av1_rtcd.c"
+  "av1_rtcd")
 
 add_library(aom_rtcd OBJECT ${AOM_RTCD_SOURCES})
 add_dependencies(aom_rtcd aom_version)
@@ -300,7 +321,9 @@
 #
 # Application and application support targets.
 #
-if(ENABLE_EXAMPLES OR ENABLE_TESTS OR ENABLE_TOOLS)
+if(ENABLE_EXAMPLES
+   OR ENABLE_TESTS
+   OR ENABLE_TOOLS)
   add_library(aom_common_app_util OBJECT ${AOM_COMMON_APP_UTIL_SOURCES})
   if(CONFIG_AV1_DECODER)
     add_library(aom_decoder_app_util OBJECT ${AOM_DECODER_APP_UTIL_SOURCES})
@@ -316,52 +339,65 @@
   add_executable(resize_util "${AOM_ROOT}/examples/resize_util.c"
                              $<TARGET_OBJECTS:aom_common_app_util>)
   list(APPEND AOM_APP_TARGETS resize_util)
-  add_executable(lanczos_resample_y4m
-                 "${AOM_ROOT}/tools/lanczos/lanczos_resample.c"
-                 "${AOM_ROOT}/tools/lanczos/lanczos_resample.h"
-                 "${AOM_ROOT}/tools/lanczos/lanczos_resample_y4m.c")
-  add_executable(lanczos_resample_yuv
-                 "${AOM_ROOT}/tools/lanczos/lanczos_resample.c"
-                 "${AOM_ROOT}/tools/lanczos/lanczos_resample.h"
-                 "${AOM_ROOT}/tools/lanczos/lanczos_resample_yuv.c")
+  add_executable(
+    lanczos_resample_y4m
+    "${AOM_ROOT}/tools/lanczos/lanczos_resample.c"
+    "${AOM_ROOT}/tools/lanczos/lanczos_resample.h"
+    "${AOM_ROOT}/tools/lanczos/lanczos_resample_y4m.c")
+  add_executable(
+    lanczos_resample_yuv
+    "${AOM_ROOT}/tools/lanczos/lanczos_resample.c"
+    "${AOM_ROOT}/tools/lanczos/lanczos_resample.h"
+    "${AOM_ROOT}/tools/lanczos/lanczos_resample_yuv.c")
   list(APPEND AOM_APP_TARGETS lanczos_resample_y4m lanczos_resample_yuv)
-  add_executable(lanczos_resample_filter
-                 "${AOM_ROOT}/tools/lanczos/lanczos_resample.c"
-                 "${AOM_ROOT}/tools/lanczos/lanczos_resample.h"
-                 "${AOM_ROOT}/tools/lanczos/lanczos_resample_filter.c")
+  add_executable(
+    lanczos_resample_filter
+    "${AOM_ROOT}/tools/lanczos/lanczos_resample.c"
+    "${AOM_ROOT}/tools/lanczos/lanczos_resample.h"
+    "${AOM_ROOT}/tools/lanczos/lanczos_resample_filter.c")
   list(APPEND AOM_APP_TARGETS lanczos_resample_filter)
 endif()
 
 if(CONFIG_AV1_DECODER AND ENABLE_EXAMPLES)
-  add_executable(aomdec "${AOM_ROOT}/apps/aomdec.c"
-                        $<TARGET_OBJECTS:aom_common_app_util>
-                        $<TARGET_OBJECTS:aom_decoder_app_util>)
-  add_executable(decode_to_md5 "${AOM_ROOT}/examples/decode_to_md5.c"
-                               $<TARGET_OBJECTS:aom_common_app_util>
-                               $<TARGET_OBJECTS:aom_decoder_app_util>)
-  add_executable(decode_with_drops "${AOM_ROOT}/examples/decode_with_drops.c"
-                                   $<TARGET_OBJECTS:aom_common_app_util>
-                                   $<TARGET_OBJECTS:aom_decoder_app_util>)
-  add_executable(simple_decoder "${AOM_ROOT}/examples/simple_decoder.c"
-                                $<TARGET_OBJECTS:aom_common_app_util>
-                                $<TARGET_OBJECTS:aom_decoder_app_util>)
-  add_executable(scalable_decoder "${AOM_ROOT}/examples/scalable_decoder.c"
-                                  $<TARGET_OBJECTS:aom_common_app_util>
-                                  $<TARGET_OBJECTS:aom_decoder_app_util>)
+  add_executable(
+    aomdec "${AOM_ROOT}/apps/aomdec.c" $<TARGET_OBJECTS:aom_common_app_util>
+           $<TARGET_OBJECTS:aom_decoder_app_util>)
+  add_executable(
+    decode_to_md5
+    "${AOM_ROOT}/examples/decode_to_md5.c"
+    $<TARGET_OBJECTS:aom_common_app_util>
+    $<TARGET_OBJECTS:aom_decoder_app_util>)
+  add_executable(
+    decode_with_drops
+    "${AOM_ROOT}/examples/decode_with_drops.c"
+    $<TARGET_OBJECTS:aom_common_app_util>
+    $<TARGET_OBJECTS:aom_decoder_app_util>)
+  add_executable(
+    simple_decoder
+    "${AOM_ROOT}/examples/simple_decoder.c"
+    $<TARGET_OBJECTS:aom_common_app_util>
+    $<TARGET_OBJECTS:aom_decoder_app_util>)
+  add_executable(
+    scalable_decoder
+    "${AOM_ROOT}/examples/scalable_decoder.c"
+    $<TARGET_OBJECTS:aom_common_app_util>
+    $<TARGET_OBJECTS:aom_decoder_app_util>)
 
   if(CONFIG_ANALYZER)
-    add_executable(analyzer "${AOM_ROOT}/examples/analyzer.cc"
-                            $<TARGET_OBJECTS:aom_common_app_util>
-                            $<TARGET_OBJECTS:aom_decoder_app_util>)
+    add_executable(
+      analyzer
+      "${AOM_ROOT}/examples/analyzer.cc" $<TARGET_OBJECTS:aom_common_app_util>
+      $<TARGET_OBJECTS:aom_decoder_app_util>)
     target_link_libraries(analyzer ${AOM_LIB_LINK_TYPE} ${wxWidgets_LIBRARIES})
     list(APPEND AOM_APP_TARGETS analyzer)
     list(APPEND AOM_DECODER_EXAMPLE_TARGETS analyzer)
   endif()
 
   if(CONFIG_INSPECTION)
-    add_executable(inspect "${AOM_ROOT}/examples/inspect.c"
-                           $<TARGET_OBJECTS:aom_common_app_util>
-                           $<TARGET_OBJECTS:aom_decoder_app_util>)
+    add_executable(
+      inspect
+      "${AOM_ROOT}/examples/inspect.c" $<TARGET_OBJECTS:aom_common_app_util>
+      $<TARGET_OBJECTS:aom_decoder_app_util>)
     list(APPEND AOM_DECODER_EXAMPLE_TARGETS inspect)
 
     if(EMSCRIPTEN)
@@ -388,8 +424,14 @@
   endif()
 
   # Maintain a list of decoder example targets.
-  list(APPEND AOM_DECODER_EXAMPLE_TARGETS aomdec decode_to_md5 decode_with_drops
-              scalable_decoder simple_decoder)
+  list(
+    APPEND
+    AOM_DECODER_EXAMPLE_TARGETS
+    aomdec
+    decode_to_md5
+    decode_with_drops
+    scalable_decoder
+    simple_decoder)
 
   # Add decoder examples to the app targets list.
   list(APPEND AOM_APP_TARGETS ${AOM_DECODER_EXAMPLE_TARGETS})
@@ -397,32 +439,52 @@
 
 if(CONFIG_AV1_ENCODER)
   if(ENABLE_EXAMPLES)
-    add_executable(aomenc "${AOM_ROOT}/apps/aomenc.c"
-                          $<TARGET_OBJECTS:aom_common_app_util>
-                          $<TARGET_OBJECTS:aom_encoder_app_util>
-                          $<TARGET_OBJECTS:aom_encoder_stats>)
-    add_executable(lossless_encoder "${AOM_ROOT}/examples/lossless_encoder.c"
-                                    $<TARGET_OBJECTS:aom_common_app_util>
-                                    $<TARGET_OBJECTS:aom_encoder_app_util>)
-    add_executable(set_maps "${AOM_ROOT}/examples/set_maps.c"
-                            $<TARGET_OBJECTS:aom_common_app_util>
-                            $<TARGET_OBJECTS:aom_encoder_app_util>)
-    add_executable(simple_encoder "${AOM_ROOT}/examples/simple_encoder.c"
-                                  $<TARGET_OBJECTS:aom_common_app_util>
-                                  $<TARGET_OBJECTS:aom_encoder_app_util>)
-    add_executable(twopass_encoder "${AOM_ROOT}/examples/twopass_encoder.c"
-                                   $<TARGET_OBJECTS:aom_common_app_util>
-                                   $<TARGET_OBJECTS:aom_encoder_app_util>)
-    add_executable(noise_model "${AOM_ROOT}/examples/noise_model.c"
-                               $<TARGET_OBJECTS:aom_common_app_util>
-                               $<TARGET_OBJECTS:aom_encoder_app_util>)
-    add_executable(scalable_encoder "${AOM_ROOT}/examples/scalable_encoder.c"
-                                    $<TARGET_OBJECTS:aom_common_app_util>
-                                    $<TARGET_OBJECTS:aom_encoder_app_util>)
+    add_executable(
+      aomenc
+      "${AOM_ROOT}/apps/aomenc.c" $<TARGET_OBJECTS:aom_common_app_util>
+      $<TARGET_OBJECTS:aom_encoder_app_util>
+      $<TARGET_OBJECTS:aom_encoder_stats>)
+    add_executable(
+      lossless_encoder
+      "${AOM_ROOT}/examples/lossless_encoder.c"
+      $<TARGET_OBJECTS:aom_common_app_util>
+      $<TARGET_OBJECTS:aom_encoder_app_util>)
+    add_executable(
+      set_maps
+      "${AOM_ROOT}/examples/set_maps.c" $<TARGET_OBJECTS:aom_common_app_util>
+      $<TARGET_OBJECTS:aom_encoder_app_util>)
+    add_executable(
+      simple_encoder
+      "${AOM_ROOT}/examples/simple_encoder.c"
+      $<TARGET_OBJECTS:aom_common_app_util>
+      $<TARGET_OBJECTS:aom_encoder_app_util>)
+    add_executable(
+      twopass_encoder
+      "${AOM_ROOT}/examples/twopass_encoder.c"
+      $<TARGET_OBJECTS:aom_common_app_util>
+      $<TARGET_OBJECTS:aom_encoder_app_util>)
+    add_executable(
+      noise_model
+      "${AOM_ROOT}/examples/noise_model.c"
+      $<TARGET_OBJECTS:aom_common_app_util>
+      $<TARGET_OBJECTS:aom_encoder_app_util>)
+    add_executable(
+      scalable_encoder
+      "${AOM_ROOT}/examples/scalable_encoder.c"
+      $<TARGET_OBJECTS:aom_common_app_util>
+      $<TARGET_OBJECTS:aom_encoder_app_util>)
 
     # Maintain a list of encoder example targets.
-    list(APPEND AOM_ENCODER_EXAMPLE_TARGETS aomenc lossless_encoder noise_model
-                set_maps simple_encoder scalable_encoder twopass_encoder)
+    list(
+      APPEND
+      AOM_ENCODER_EXAMPLE_TARGETS
+      aomenc
+      lossless_encoder
+      noise_model
+      set_maps
+      simple_encoder
+      scalable_encoder
+      twopass_encoder)
   endif()
 
   if(ENABLE_TOOLS)
@@ -431,11 +493,12 @@
       # TODO(tomfinegan): Sort out why a simple link command with
       # aom_entropy_optimizer.c won't work on macos, but dragging in all the
       # helper machinery allows the link to succeed.
-      add_executable(aom_entropy_optimizer
-                     "${AOM_GEN_SRC_DIR}/usage_exit.c"
-                     "${AOM_ROOT}/tools/aom_entropy_optimizer.c"
-                     $<TARGET_OBJECTS:aom_common_app_util>
-                     $<TARGET_OBJECTS:aom_encoder_app_util>)
+      add_executable(
+        aom_entropy_optimizer
+        "${AOM_GEN_SRC_DIR}/usage_exit.c"
+        "${AOM_ROOT}/tools/aom_entropy_optimizer.c"
+        $<TARGET_OBJECTS:aom_common_app_util>
+        $<TARGET_OBJECTS:aom_encoder_app_util>)
 
       # Maintain a list of encoder tool targets.
       list(APPEND AOM_ENCODER_TOOL_TARGETS aom_entropy_optimizer)
@@ -444,7 +507,7 @@
 
   # Add encoder examples and tools to the targets list.
   list(APPEND AOM_APP_TARGETS ${AOM_ENCODER_EXAMPLE_TARGETS}
-              ${AOM_ENCODER_TOOL_TARGETS})
+       ${AOM_ENCODER_TOOL_TARGETS})
 
   if(CONFIG_USE_VMAF_RC AND NOT CONFIG_TUNE_VMAF)
     message(FATAL_ERROR "Turn on CONFIG_TUNE_VMAF to use CONFIG_USE_VMAF_RC.")
@@ -455,8 +518,8 @@
     if(CONFIG_USE_VMAF_RC)
       if(PKG_CONFIG_FOUND)
         pkg_check_modules(VMAF_RC REQUIRED libvmaf_rc)
-        target_link_libraries(aom
-                              PRIVATE ${VMAF_RC_LDFLAGS} ${VMAF_RC_LIBRARIES})
+        target_link_libraries(aom PRIVATE ${VMAF_RC_LDFLAGS}
+                                          ${VMAF_RC_LIBRARIES})
         target_include_directories(aom PRIVATE ${VMAF_RC_INCLUDE_DIRS})
         if(VMAF_RC_CFLAGS)
           append_compiler_flag("${VMAF_RC_CFLAGS}")
@@ -496,17 +559,19 @@
   # installation of example programs into an examples sub directory of
   # $AOM_DIST_DIR/bin when building the dist target.
   list(APPEND AOM_EXAMPLE_TARGETS ${AOM_DECODER_EXAMPLE_TARGETS}
-              ${AOM_ENCODER_EXAMPLE_TARGETS})
+       ${AOM_ENCODER_EXAMPLE_TARGETS})
 endif()
 
 if(ENABLE_TOOLS)
   if(CONFIG_AV1_DECODER)
-    add_executable(dump_obu "${AOM_GEN_SRC_DIR}/usage_exit.cc"
-                            "${AOM_ROOT}/tools/dump_obu.cc"
-                            "${AOM_ROOT}/tools/obu_parser.cc"
-                            "${AOM_ROOT}/tools/obu_parser.h"
-                            $<TARGET_OBJECTS:aom_common_app_util>
-                            $<TARGET_OBJECTS:aom_decoder_app_util>)
+    add_executable(
+      dump_obu
+      "${AOM_GEN_SRC_DIR}/usage_exit.cc"
+      "${AOM_ROOT}/tools/dump_obu.cc"
+      "${AOM_ROOT}/tools/obu_parser.cc"
+      "${AOM_ROOT}/tools/obu_parser.h"
+      $<TARGET_OBJECTS:aom_common_app_util>
+      $<TARGET_OBJECTS:aom_decoder_app_util>)
 
     list(APPEND AOM_TOOL_TARGETS dump_obu)
     list(APPEND AOM_APP_TARGETS dump_obu)
@@ -515,49 +580,61 @@
     # installation of example programs into an tools sub directory of
     # $AOM_DIST_DIR/bin when building the dist target.
     list(APPEND AOM_TOOL_TARGETS ${AOM_DECODER_TOOL_TARGETS}
-                ${AOM_ENCODER_TOOL_TARGETS})
+         ${AOM_ENCODER_TOOL_TARGETS})
   endif()
 endif()
 
-if(ENABLE_EXAMPLES AND CONFIG_AV1_DECODER AND CONFIG_AV1_ENCODER)
-  add_executable(aom_cx_set_ref "${AOM_ROOT}/examples/aom_cx_set_ref.c"
-                                $<TARGET_OBJECTS:aom_common_app_util>
-                                $<TARGET_OBJECTS:aom_encoder_app_util>)
+if(ENABLE_EXAMPLES
+   AND CONFIG_AV1_DECODER
+   AND CONFIG_AV1_ENCODER)
+  add_executable(
+    aom_cx_set_ref
+    "${AOM_ROOT}/examples/aom_cx_set_ref.c"
+    $<TARGET_OBJECTS:aom_common_app_util>
+    $<TARGET_OBJECTS:aom_encoder_app_util>)
   list(APPEND AOM_EXAMPLE_TARGETS aom_cx_set_ref)
   list(APPEND AOM_APP_TARGETS aom_cx_set_ref)
 endif()
 
 if(ENABLE_EXAMPLES AND CONFIG_AV1_ENCODER)
-  add_executable(lightfield_encoder "${AOM_ROOT}/examples/lightfield_encoder.c"
-                                    $<TARGET_OBJECTS:aom_common_app_util>
-                                    $<TARGET_OBJECTS:aom_encoder_app_util>)
+  add_executable(
+    lightfield_encoder
+    "${AOM_ROOT}/examples/lightfield_encoder.c"
+    $<TARGET_OBJECTS:aom_common_app_util>
+    $<TARGET_OBJECTS:aom_encoder_app_util>)
   list(APPEND AOM_EXAMPLE_TARGETS lightfield_encoder)
   list(APPEND AOM_APP_TARGETS lightfield_encoder)
 endif()
 
 if(ENABLE_EXAMPLES AND CONFIG_AV1_DECODER)
-  add_executable(lightfield_tile_list_decoder
-                 "${AOM_ROOT}/examples/lightfield_tile_list_decoder.c"
-                 $<TARGET_OBJECTS:aom_common_app_util>
-                 $<TARGET_OBJECTS:aom_decoder_app_util>)
+  add_executable(
+    lightfield_tile_list_decoder
+    "${AOM_ROOT}/examples/lightfield_tile_list_decoder.c"
+    $<TARGET_OBJECTS:aom_common_app_util>
+    $<TARGET_OBJECTS:aom_decoder_app_util>)
   list(APPEND AOM_EXAMPLE_TARGETS lightfield_tile_list_decoder)
   list(APPEND AOM_APP_TARGETS lightfield_tile_list_decoder)
 endif()
 
 if(ENABLE_EXAMPLES AND CONFIG_AV1_DECODER)
-  add_executable(lightfield_decoder "${AOM_ROOT}/examples/lightfield_decoder.c"
-                                    $<TARGET_OBJECTS:aom_common_app_util>
-                                    $<TARGET_OBJECTS:aom_decoder_app_util>)
+  add_executable(
+    lightfield_decoder
+    "${AOM_ROOT}/examples/lightfield_decoder.c"
+    $<TARGET_OBJECTS:aom_common_app_util>
+    $<TARGET_OBJECTS:aom_decoder_app_util>)
   list(APPEND AOM_EXAMPLE_TARGETS lightfield_decoder)
   list(APPEND AOM_APP_TARGETS lightfield_decoder)
 endif()
 
-if(ENABLE_EXAMPLES AND CONFIG_AV1_ENCODER AND CONFIG_AV1_DECODER)
-  add_executable(lightfield_bitstream_parsing
-                 "${AOM_ROOT}/examples/lightfield_bitstream_parsing.c"
-                 $<TARGET_OBJECTS:aom_common_app_util>
-                 $<TARGET_OBJECTS:aom_encoder_app_util>
-                 $<TARGET_OBJECTS:aom_decoder_app_util>)
+if(ENABLE_EXAMPLES
+   AND CONFIG_AV1_ENCODER
+   AND CONFIG_AV1_DECODER)
+  add_executable(
+    lightfield_bitstream_parsing
+    "${AOM_ROOT}/examples/lightfield_bitstream_parsing.c"
+    $<TARGET_OBJECTS:aom_common_app_util>
+    $<TARGET_OBJECTS:aom_encoder_app_util>
+    $<TARGET_OBJECTS:aom_decoder_app_util>)
   list(APPEND AOM_EXAMPLE_TARGETS lightfield_bitstream_parsing)
   list(APPEND AOM_APP_TARGETS lightfield_bitstream_parsing)
 endif()
@@ -566,7 +643,9 @@
   target_link_libraries(${aom_app} ${AOM_LIB_LINK_TYPE} aom)
 endforeach()
 
-if(ENABLE_EXAMPLES OR ENABLE_TESTS OR ENABLE_TOOLS)
+if(ENABLE_EXAMPLES
+   OR ENABLE_TESTS
+   OR ENABLE_TOOLS)
   if(CONFIG_LIBYUV)
     add_library(yuv OBJECT ${AOM_LIBYUV_SOURCES})
     if(NOT MSVC)
@@ -671,9 +750,8 @@
 
   foreach(target ${AOM_EXAMPLE_TARGETS})
     if(NOT "${target}" MATCHES "aomdec\|aomenc")
-      set_target_properties(${target}
-                            PROPERTIES RUNTIME_OUTPUT_DIRECTORY
-                                       "${AOM_CONFIG_DIR}/examples")
+      set_target_properties(${target} PROPERTIES RUNTIME_OUTPUT_DIRECTORY
+                                                 "${AOM_CONFIG_DIR}/examples")
     endif()
   endforeach()
 
@@ -681,8 +759,8 @@
 
     # The same expectation is true for tool targets.
     file(MAKE_DIRECTORY "${AOM_CONFIG_DIR}/tools")
-    set_target_properties(${AOM_TOOL_TARGETS}
-                          PROPERTIES RUNTIME_OUTPUT_DIRECTORY
+    set_target_properties(
+      ${AOM_TOOL_TARGETS} PROPERTIES RUNTIME_OUTPUT_DIRECTORY
                                      "${AOM_CONFIG_DIR}/tools")
   endif()
 endif()
@@ -727,7 +805,7 @@
   else()
     message(
       "--- Cannot find doxygen(version 1.8.10 or newer), ENABLE_DOCS turned off."
-      )
+    )
     set(ENABLE_DOCS OFF)
   endif()
 endif()
@@ -756,21 +834,17 @@
   set(AOM_DIST_DIR "${AOM_CONFIG_DIR}/dist")
 endif()
 
-add_custom_target(dist
-                  COMMAND ${CMAKE_COMMAND}
-                          -DAOM_ROOT=${AOM_ROOT}
-                          -DAOM_CONFIG_DIR=${AOM_CONFIG_DIR}
-                          -DAOM_DIST_DIR=${AOM_DIST_DIR}
-                          -DAOM_DIST_APPS="${AOM_DIST_APPS}"
-                          -DAOM_DIST_EXAMPLES="${AOM_DIST_EXAMPLES}"
-                          -DAOM_DIST_TOOLS="${AOM_DIST_TOOLS}"
-                          -DAOM_DIST_INCLUDES="${AOM_INSTALL_INCS}"
-                          -DAOM_DIST_LIBS=$<TARGET_FILE:aom>
-                          -DENABLE_DOCS=${ENABLE_DOCS} -P
-                          "${AOM_ROOT}/build/cmake/dist.cmake"
-                  DEPENDS ${AOM_INSTALL_BINS} ${AOM_INSTALL_LIBS}
-                          ${AOM_INSTALL_INCS} ${AOM_EXAMPLE_TARGETS}
-                          ${AOM_TOOL_TARGETS})
+add_custom_target(
+  dist
+  COMMAND
+    ${CMAKE_COMMAND} -DAOM_ROOT=${AOM_ROOT} -DAOM_CONFIG_DIR=${AOM_CONFIG_DIR}
+    -DAOM_DIST_DIR=${AOM_DIST_DIR} -DAOM_DIST_APPS="${AOM_DIST_APPS}"
+    -DAOM_DIST_EXAMPLES="${AOM_DIST_EXAMPLES}"
+    -DAOM_DIST_TOOLS="${AOM_DIST_TOOLS}"
+    -DAOM_DIST_INCLUDES="${AOM_INSTALL_INCS}" -DAOM_DIST_LIBS=$<TARGET_FILE:aom>
+    -DENABLE_DOCS=${ENABLE_DOCS} -P "${AOM_ROOT}/build/cmake/dist.cmake"
+  DEPENDS ${AOM_INSTALL_BINS} ${AOM_INSTALL_LIBS} ${AOM_INSTALL_INCS}
+          ${AOM_EXAMPLE_TARGETS} ${AOM_TOOL_TARGETS})
 
 if(ENABLE_DOCS)
   add_dependencies(dist docs)
diff --git a/LICENSE b/LICENSE
index fc340c3..81a76cc 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,27 +1,30 @@
-Copyright (c) 2016, Alliance for Open Media. All rights reserved.
+BSD 3-Clause Clear License The Clear BSD License
 
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions
-are met:
+Copyright (c) 2021, Alliance for Open Media
+
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification, are permitted (subject to the limitations in the disclaimer below) provided that the following conditions are met:
 
 1. Redistributions of source code must retain the above copyright
-   notice, this list of conditions and the following disclaimer.
+notice, this list of conditions and the following disclaimer.
 
 2. Redistributions in binary form must reproduce the above copyright
-   notice, this list of conditions and the following disclaimer in
-   the documentation and/or other materials provided with the
-   distribution.
+notice, this list of conditions and the following disclaimer in
+the documentation and/or other materials provided with the distribution.
 
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
-FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
-INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
-BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
-ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGE.
+3. Neither the name of the Alliance for Open Media nor the names of its
+contributors may be used to endorse or promote products derived from
+this software without specific prior written permission.
 
+
+NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
+OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/README.md b/README.md
index 7e068c3..72093b4 100644
--- a/README.md
+++ b/README.md
@@ -263,40 +263,46 @@
 We are using the Google C Coding Style defined by the
 [Google C++ Style Guide](https://google.github.io/styleguide/cppguide.html).
 
-The coding style used by this project is enforced with clang-format using the
-configuration contained in the
-[.clang-format](https://gitlab.com/AOMediaCodec/avm/-/blob/main/.clang-format)
-file in the root of the repository.
+The coding style used by this project is enforced with `clang-format` and
+`cmake-format`.
 
-You can download clang-format using your system's package manager, or directly
-from [llvm.org](http://llvm.org/releases/download.html). You can also view the
-[documentation](https://clang.llvm.org/docs/ClangFormat.html) on llvm.org.
-Output from clang-format varies by clang-format version,
-for best results your version should match the one used by Gitlab CI. You can find the clang-format
-version by reading the comment in the `.clang-format` file linked above.
+- `clang-format` can be installed with your system's package manager, or directly
+from [llvm.org](http://llvm.org/releases/download.html). For best results, your
+version should match the one used by Gitlab CI, noted as a comment in
+[.clang-format](https://gitlab.com/AOMediaCodec/avm/-/blob/main/.clang-format).
 
-Before pushing changes for review you can format your code with:
+- `cmake-format` can be obtained by installing
+[cmakelang](https://pypi.org/project/cmakelang/). Again, for best results, your
+version should match the one used by Gitlab CI, noted as a comment in
+[.cmake-format.py](https://gitlab.com/AOMediaCodec/avm/-/blob/main/.cmake-format.py)
+
+
+Before pushing changes for review, format your code using the tools above.
+
+We recommend automating the formatting by adding a
+[pre-commit hook](https://git-scm.com/docs/githooks#_pre_commit) at
+`.git/hooks/pre-commit`. An example pre-commit hook is provided below:
 
 ~~~
-    # Apply clang-format to modified .c, .h and .cc files
-    $ clang-format -i --style=file \
-      $(git diff --name-only --diff-filter=ACMR '*.[hc]' '*.cc')
-~~~
+#!/bin/bash
+CLANG_FORMAT_PATH=/usr/bin/
+CMAKE_FORMAT_PATH=${HOME}/.local/bin/
 
-Check the .clang-format file for the version used to generate it if there is any
-difference between your local formatting and the review system.
+echo "Applying clang-format ..."
+for file in $(git diff-index --cached --name-only HEAD -- "*.[hc]pp" "*.cc" "*.[ch]") ; do
+  ${CLANG_FORMAT_PATH}/clang-format -i --style=file ${file}
+  git add ${file}
+  echo "Formatted file: $file"
+done
+echo "Done."
 
-Some Git installations have clang-format integration. Here are some examples:
-
-~~~
-    # Apply clang-format to all staged changes:
-    $ git clang-format
-
-    # Clang format all staged and unstaged changes:
-    $ git clang-format -f
-
-    # Clang format all staged and unstaged changes interactively:
-    $ git clang-format -f -p
+echo "Applying cmake-format ..."
+for file in $(git diff-index --cached --name-only HEAD -- '*.cmake' CMakeLists.txt) ; do
+  ${CMAKE_FORMAT_PATH}/cmake-format -i ${file}
+  git add ${file}
+  echo "Formatted file: $file"
+done
+echo "Done."
 ~~~
 
 ## Submitting patches
diff --git a/aom/aom.h b/aom/aom.h
index c591dc9..d312f82 100644
--- a/aom/aom.h
+++ b/aom/aom.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 /*!\defgroup aom AOM
diff --git a/aom/aom_codec.h b/aom/aom_codec.h
index f58272e..66b3cb6 100644
--- a/aom/aom_codec.h
+++ b/aom/aom_codec.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 ///////////////////////////////////////////////////////////////////////////////
diff --git a/aom/aom_decoder.h b/aom/aom_decoder.h
index 5ce7c7b..60da50f 100644
--- a/aom/aom_decoder.h
+++ b/aom/aom_decoder.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #ifndef AOM_AOM_AOM_DECODER_H_
 #define AOM_AOM_AOM_DECODER_H_
diff --git a/aom/aom_encoder.h b/aom/aom_encoder.h
index 5ec26e4..024fb1c 100644
--- a/aom/aom_encoder.h
+++ b/aom/aom_encoder.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #ifndef AOM_AOM_AOM_ENCODER_H_
 #define AOM_AOM_AOM_ENCODER_H_
@@ -200,6 +201,22 @@
   AOM_SUPERRES_AUTO,
 } aom_superres_mode;
 
+#if CONFIG_OPTFLOW_REFINEMENT
+/*!\brief Frame super-resolution mode. */
+typedef enum {
+  /**< MV refinement is disabled for all frames. */
+  AOM_OPFL_REFINE_NONE,
+  /**< MV refinement is switchable per block and signaled by the encoder for all
+   * frames. */
+  AOM_OPFL_REFINE_SWITCHABLE,
+  /**< MV refinement is done for all compound average blocks for all frames. */
+  AOM_OPFL_REFINE_ALL,
+  /**< One among the three above types is automatically selected by the encoder
+   * for each frame. */
+  AOM_OPFL_REFINE_AUTO,
+} aom_opfl_refine_type;
+#endif  // CONFIG_OPTFLOW_REFINEMENT
+
 /*!\brief Encoder Config Options
  *
  * This type allows to enumerate and control flags defined for encoder control
@@ -266,6 +283,12 @@
    */
   unsigned int enable_ist;
 #endif  // CONFIG_IST
+#if CONFIG_IBP_DC || CONFIG_IBP_DIR
+  /*!\brief enable Intra Bi-Prediction (IBP)
+   *
+   */
+  unsigned int enable_ibp;
+#endif  // CONFIG_IBP_DC || CONFIG_IBP_DIR
   /*!\brief enable flip and identity transform type
    *
    */
@@ -300,12 +323,6 @@
    *
    */
   unsigned int enable_global_motion;
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-  /*!\brief enable dist weighted compound
-   *
-   */
-  unsigned int enable_dist_wtd_comp;
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
   /*!\brief enable diff weighted compound
    *
    */
@@ -352,6 +369,12 @@
    *
    */
   unsigned int enable_angle_delta;
+#if CONFIG_OPTFLOW_REFINEMENT
+  /*!\brief enable optical flow refinement
+   *
+   */
+  aom_opfl_refine_type enable_opfl_refine;
+#endif  // CONFIG_OPTFLOW_REFINEMENT
   /*!\brief enable intra edge filter
    *
    */
@@ -388,6 +411,12 @@
    *
    */
   unsigned int enable_reduced_reference_set;
+#if CONFIG_NEW_REF_SIGNALING
+  /*!\brief explicitly signal reference frame mapping
+   *
+   */
+  unsigned int explicit_ref_frame_map;
+#endif  // CONFIG_NEW_REF_SIGNALING
   /*!\brief use reduced transform type set
    *
    */
@@ -398,6 +427,12 @@
    */
   unsigned int max_drl_refmvs;
 #endif  // CONFIG_NEW_INTER_MODES
+#if CONFIG_REF_MV_BANK
+  /*!\brief enable reference MV Bank
+   *
+   */
+  unsigned int enable_refmvbank;
+#endif
 } cfg_options_t;
 
 /*!\brief Encoded Frame Flags
diff --git a/aom/aom_frame_buffer.h b/aom/aom_frame_buffer.h
index d40b18e..7f5b6b9 100644
--- a/aom/aom_frame_buffer.h
+++ b/aom/aom_frame_buffer.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_AOM_FRAME_BUFFER_H_
diff --git a/aom/aom_image.h b/aom/aom_image.h
index 03bc73e..5347aa2 100644
--- a/aom/aom_image.h
+++ b/aom/aom_image.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 /*!\file
diff --git a/aom/aom_integer.h b/aom/aom_integer.h
index d9bba09..e5025bb 100644
--- a/aom/aom_integer.h
+++ b/aom/aom_integer.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #ifndef AOM_AOM_AOM_INTEGER_H_
 #define AOM_AOM_AOM_INTEGER_H_
diff --git a/aom/aomcx.h b/aom/aomcx.h
index db2a744..396463f 100644
--- a/aom/aomcx.h
+++ b/aom/aomcx.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #ifndef AOM_AOM_AOMCX_H_
 #define AOM_AOM_AOMCX_H_
@@ -847,23 +848,9 @@
    */
   AV1E_SET_ENABLE_FLIP_IDTX = 81,
 
-/* Note: enum value 82 unused */
+  /* Note: enum value 82 unused */
 
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-  /*!\brief Codec control function to turn on / off dist-wtd compound mode
-   * at sequence level, int parameter
-   *
-   * This will enable or disable distance-weighted compound mode.
-   * \attention If AV1E_SET_ENABLE_ORDER_HINT is 0, then this flag is forced
-   * to 0.
-   *
-   * - 0 = disable
-   * - 1 = enable (default)
-   */
-  AV1E_SET_ENABLE_DIST_WTD_COMP = 83,
-#else
-/* Note: enum value 83 unused */
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
+  /* Note: enum value 83 unused */
 
   /*!\brief Codec control function to turn on / off ref frame mvs (mfmv) usage
    * at sequence level, int parameter
@@ -1214,8 +1201,9 @@
    */
   AV1E_SET_MIN_CR = 144,
 
-  /* NOTE: enums 145-149 unused */
+/* NOTE: enums 145-149 unused */
 
+#if CONFIG_SVC_ENCODER
   /*!\brief Codec control function to set the layer id, aom_svc_layer_id_t*
    * parameter
    */
@@ -1231,6 +1219,7 @@
    * aom_svc_ref_frame_config_t* parameter
    */
   AV1E_SET_SVC_REF_FRAME_CONFIG = 152,
+#endif  // CONFIG_SVC_ENCODER
 
   /*!\brief Codec control function to set the path to the VMAF model used when
    * tuning the encoder for VMAF, const char* parameter
@@ -1402,6 +1391,7 @@
   AOM_TUNE_VMAF_NEG_MAX_GAIN = 7,
 } aom_tune_metric;
 
+#if CONFIG_SVC_ENCODER
 #define AOM_MAX_LAYERS 32   /**< Max number of layers */
 #define AOM_MAX_SS_LAYERS 4 /**< Max number of spatial layers */
 #define AOM_MAX_TS_LAYERS 8 /**< Max number of temporal layers */
@@ -1435,6 +1425,7 @@
   int ref_idx[7];
   int refresh[8]; /**< Refresh flag for each of the 8 slots. */
 } aom_svc_ref_frame_config_t;
+#endif  // CONFIG_SVC_ENCODER
 
 /*!\cond */
 /*!\brief Encoder control function parameter type
@@ -1598,11 +1589,6 @@
 AOM_CTRL_USE_TYPE(AV1E_SET_ENABLE_FLIP_IDTX, int)
 #define AOM_CTRL_AV1E_SET_ENABLE_FLIP_IDTX
 
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-AOM_CTRL_USE_TYPE(AV1E_SET_ENABLE_DIST_WTD_COMP, int)
-#define AOM_CTRL_AV1E_SET_ENABLE_DIST_WTD_COMP
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
-
 AOM_CTRL_USE_TYPE(AV1E_SET_ENABLE_REF_FRAME_MVS, int)
 #define AOM_CTRL_AV1E_SET_ENABLE_REF_FRAME_MVS
 
@@ -1827,6 +1813,7 @@
 AOM_CTRL_USE_TYPE(AV1E_SET_MIN_CR, unsigned int)
 #define AOM_CTRL_AV1E_SET_MIN_CR
 
+#if CONFIG_SVC_ENCODER
 AOM_CTRL_USE_TYPE(AV1E_SET_SVC_LAYER_ID, aom_svc_layer_id_t *)
 #define AOME_CTRL_AV1E_SET_SVC_LAYER_ID
 
@@ -1835,6 +1822,7 @@
 
 AOM_CTRL_USE_TYPE(AV1E_SET_SVC_REF_FRAME_CONFIG, aom_svc_ref_frame_config_t *)
 #define AOME_CTRL_AV1E_SET_SVC_REF_FRAME_CONFIG
+#endif  // CONFIG_SVC_ENCODER
 
 AOM_CTRL_USE_TYPE(AV1E_ENABLE_SB_MULTIPASS_UNIT_TEST, unsigned int)
 #define AOM_CTRL_AV1E_ENABLE_SB_MULTIPASS_UNIT_TEST
diff --git a/aom/aomdx.h b/aom/aomdx.h
index 810709e..d8f3579 100644
--- a/aom/aomdx.h
+++ b/aom/aomdx.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 /*!\defgroup aom_decoder AOMedia AOM/AV1 Decoder
diff --git a/aom/internal/aom_codec_internal.h b/aom/internal/aom_codec_internal.h
index 0ad33bd..0afc7b7 100644
--- a/aom/internal/aom_codec_internal.h
+++ b/aom/internal/aom_codec_internal.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 /*!\file
@@ -48,6 +49,9 @@
 #include "../aom_decoder.h"
 #include "../aom_encoder.h"
 #include "common/args_helper.h"
+#if CONFIG_IBP_DIR
+#include "av1/common/enums.h"
+#endif
 #include <stdarg.h>
 
 #ifdef __cplusplus
@@ -324,6 +328,9 @@
 struct aom_codec_priv {
   const char *err_detail;
   aom_codec_flags_t init_flags;
+#if CONFIG_IBP_DIR
+  uint8_t *ibp_directional_weights[TX_SIZES_ALL][DIR_MODES_0_90];
+#endif
   struct {
     aom_fixed_buf_t cx_data_dst_buf;
     unsigned int cx_data_pad_before;
diff --git a/aom/internal/aom_image_internal.h b/aom/internal/aom_image_internal.h
index 1b04c9e..5e23757 100644
--- a/aom/internal/aom_image_internal.h
+++ b/aom/internal/aom_image_internal.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2019, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 /*!\file
diff --git a/aom/src/aom_codec.c b/aom/src/aom_codec.c
index 4778781..23749b6 100644
--- a/aom/src/aom_codec.c
+++ b/aom/src/aom_codec.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 /*!\file
diff --git a/aom/src/aom_decoder.c b/aom/src/aom_decoder.c
index 49fff26..5c9ec2b 100644
--- a/aom/src/aom_decoder.c
+++ b/aom/src/aom_decoder.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 /*!\file
diff --git a/aom/src/aom_encoder.c b/aom/src/aom_encoder.c
index f3c7c08..ef6e472 100644
--- a/aom/src/aom_encoder.c
+++ b/aom/src/aom_encoder.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 /*!\file
diff --git a/aom/src/aom_image.c b/aom/src/aom_image.c
index dfdee87..18bfd22 100644
--- a/aom/src/aom_image.c
+++ b/aom/src/aom_image.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <stdlib.h>
diff --git a/aom/src/aom_integer.c b/aom/src/aom_integer.c
index 7edfd0d..0a9cf77 100644
--- a/aom/src/aom_integer.c
+++ b/aom/src/aom_integer.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #include <assert.h>
 
diff --git a/aom_dsp/aom_convolve.c b/aom_dsp/aom_convolve.c
index 863b5a5..85455ec 100644
--- a/aom_dsp/aom_convolve.c
+++ b/aom_dsp/aom_convolve.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/aom_dsp/aom_dsp.cmake b/aom_dsp/aom_dsp.cmake
index 0a27cdf..4cc8f57 100644
--- a/aom_dsp/aom_dsp.cmake
+++ b/aom_dsp/aom_dsp.cmake
@@ -1,274 +1,313 @@
 #
-# Copyright (c) 2017, Alliance for Open Media. All rights reserved
+# Copyright (c) 2021, Alliance for Open Media. All rights reserved
 #
-# This source code is subject to the terms of the BSD 2 Clause License and the
-# Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License was
-# not distributed with this source code in the LICENSE file, you can obtain it
-# at www.aomedia.org/license/software. If the Alliance for Open Media Patent
-# License 1.0 was not distributed with this source code in the PATENTS file, you
-# can obtain it at www.aomedia.org/license/patent.
+# This source code is subject to the terms of the BSD 3-Clause Clear License and
+# the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+# License was not distributed with this source code in the LICENSE file, you can
+# obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance
+# for Open Media Patent License 1.0 was not distributed with this source code in
+# the PATENTS file, you can obtain it at aomedia.org/license/patent-license/.
 #
 if(AOM_AOM_DSP_AOM_DSP_CMAKE_)
   return()
 endif() # AOM_AOM_DSP_AOM_DSP_CMAKE_
 set(AOM_AOM_DSP_AOM_DSP_CMAKE_ 1)
 
-list(APPEND AOM_DSP_COMMON_SOURCES
-            "${AOM_ROOT}/aom_dsp/aom_convolve.c"
-            "${AOM_ROOT}/aom_dsp/aom_dsp_common.h"
-            "${AOM_ROOT}/aom_dsp/aom_filter.h"
-            "${AOM_ROOT}/aom_dsp/aom_simd.h"
-            "${AOM_ROOT}/aom_dsp/aom_simd_inline.h"
-            "${AOM_ROOT}/aom_dsp/bitreader_buffer.c"
-            "${AOM_ROOT}/aom_dsp/bitreader_buffer.h"
-            "${AOM_ROOT}/aom_dsp/bitwriter_buffer.c"
-            "${AOM_ROOT}/aom_dsp/bitwriter_buffer.h"
-            "${AOM_ROOT}/aom_dsp/blend.h"
-            "${AOM_ROOT}/aom_dsp/blend_a64_hmask.c"
-            "${AOM_ROOT}/aom_dsp/blend_a64_mask.c"
-            "${AOM_ROOT}/aom_dsp/blend_a64_vmask.c"
-            "${AOM_ROOT}/aom_dsp/entcode.c"
-            "${AOM_ROOT}/aom_dsp/entcode.h"
-            "${AOM_ROOT}/aom_dsp/fft.c"
-            "${AOM_ROOT}/aom_dsp/fft_common.h"
-            "${AOM_ROOT}/aom_dsp/intrapred.c"
-            "${AOM_ROOT}/aom_dsp/intrapred_common.h"
-            "${AOM_ROOT}/aom_dsp/loopfilter.c"
-            "${AOM_ROOT}/aom_dsp/prob.h"
-            "${AOM_ROOT}/aom_dsp/recenter.h"
-            "${AOM_ROOT}/aom_dsp/simd/v128_intrinsics.h"
-            "${AOM_ROOT}/aom_dsp/simd/v128_intrinsics_c.h"
-            "${AOM_ROOT}/aom_dsp/simd/v256_intrinsics.h"
-            "${AOM_ROOT}/aom_dsp/simd/v256_intrinsics_c.h"
-            "${AOM_ROOT}/aom_dsp/simd/v64_intrinsics.h"
-            "${AOM_ROOT}/aom_dsp/simd/v64_intrinsics_c.h"
-            "${AOM_ROOT}/aom_dsp/subtract.c"
-            "${AOM_ROOT}/aom_dsp/txfm_common.h"
-            "${AOM_ROOT}/aom_dsp/x86/convolve_common_intrin.h"
-            "${AOM_ROOT}/aom_dsp/avg.c")
+list(
+  APPEND
+  AOM_DSP_COMMON_SOURCES
+  "${AOM_ROOT}/aom_dsp/aom_convolve.c"
+  "${AOM_ROOT}/aom_dsp/aom_dsp_common.h"
+  "${AOM_ROOT}/aom_dsp/aom_filter.h"
+  "${AOM_ROOT}/aom_dsp/aom_simd.h"
+  "${AOM_ROOT}/aom_dsp/aom_simd_inline.h"
+  "${AOM_ROOT}/aom_dsp/bitreader_buffer.c"
+  "${AOM_ROOT}/aom_dsp/bitreader_buffer.h"
+  "${AOM_ROOT}/aom_dsp/bitwriter_buffer.c"
+  "${AOM_ROOT}/aom_dsp/bitwriter_buffer.h"
+  "${AOM_ROOT}/aom_dsp/blend.h"
+  "${AOM_ROOT}/aom_dsp/blend_a64_hmask.c"
+  "${AOM_ROOT}/aom_dsp/blend_a64_mask.c"
+  "${AOM_ROOT}/aom_dsp/blend_a64_vmask.c"
+  "${AOM_ROOT}/aom_dsp/entcode.c"
+  "${AOM_ROOT}/aom_dsp/entcode.h"
+  "${AOM_ROOT}/aom_dsp/fft.c"
+  "${AOM_ROOT}/aom_dsp/fft_common.h"
+  "${AOM_ROOT}/aom_dsp/intrapred.c"
+  "${AOM_ROOT}/aom_dsp/intrapred_common.h"
+  "${AOM_ROOT}/aom_dsp/loopfilter.c"
+  "${AOM_ROOT}/aom_dsp/prob.h"
+  "${AOM_ROOT}/aom_dsp/recenter.h"
+  "${AOM_ROOT}/aom_dsp/simd/v128_intrinsics.h"
+  "${AOM_ROOT}/aom_dsp/simd/v128_intrinsics_c.h"
+  "${AOM_ROOT}/aom_dsp/simd/v256_intrinsics.h"
+  "${AOM_ROOT}/aom_dsp/simd/v256_intrinsics_c.h"
+  "${AOM_ROOT}/aom_dsp/simd/v64_intrinsics.h"
+  "${AOM_ROOT}/aom_dsp/simd/v64_intrinsics_c.h"
+  "${AOM_ROOT}/aom_dsp/subtract.c"
+  "${AOM_ROOT}/aom_dsp/txfm_common.h"
+  "${AOM_ROOT}/aom_dsp/x86/convolve_common_intrin.h"
+  "${AOM_ROOT}/aom_dsp/avg.c")
 
-list(APPEND AOM_DSP_COMMON_ASM_SSE2
-            "${AOM_ROOT}/aom_dsp/x86/aom_high_subpixel_8t_sse2.asm"
-            "${AOM_ROOT}/aom_dsp/x86/aom_high_subpixel_bilinear_sse2.asm"
-            "${AOM_ROOT}/aom_dsp/x86/aom_subpixel_8t_sse2.asm"
-            "${AOM_ROOT}/aom_dsp/x86/aom_subpixel_bilinear_sse2.asm"
-            "${AOM_ROOT}/aom_dsp/x86/highbd_intrapred_asm_sse2.asm"
-            "${AOM_ROOT}/aom_dsp/x86/intrapred_asm_sse2.asm"
-            "${AOM_ROOT}/aom_dsp/x86/inv_wht_sse2.asm")
+list(
+  APPEND
+  AOM_DSP_COMMON_ASM_SSE2
+  "${AOM_ROOT}/aom_dsp/x86/aom_high_subpixel_8t_sse2.asm"
+  "${AOM_ROOT}/aom_dsp/x86/aom_high_subpixel_bilinear_sse2.asm"
+  "${AOM_ROOT}/aom_dsp/x86/aom_subpixel_8t_sse2.asm"
+  "${AOM_ROOT}/aom_dsp/x86/aom_subpixel_bilinear_sse2.asm"
+  "${AOM_ROOT}/aom_dsp/x86/highbd_intrapred_asm_sse2.asm"
+  "${AOM_ROOT}/aom_dsp/x86/intrapred_asm_sse2.asm"
+  "${AOM_ROOT}/aom_dsp/x86/inv_wht_sse2.asm")
 
-list(APPEND AOM_DSP_COMMON_INTRIN_SSE2
-            "${AOM_ROOT}/aom_dsp/x86/aom_convolve_copy_sse2.c"
-            "${AOM_ROOT}/aom_dsp/x86/aom_subpixel_8t_intrin_sse2.c"
-            "${AOM_ROOT}/aom_dsp/x86/aom_asm_stubs.c"
-            "${AOM_ROOT}/aom_dsp/x86/convolve.h"
-            "${AOM_ROOT}/aom_dsp/x86/convolve_sse2.h"
-            "${AOM_ROOT}/aom_dsp/x86/fft_sse2.c"
-            "${AOM_ROOT}/aom_dsp/x86/highbd_convolve_sse2.c"
-            "${AOM_ROOT}/aom_dsp/x86/highbd_intrapred_sse2.c"
-            "${AOM_ROOT}/aom_dsp/x86/highbd_loopfilter_sse2.c"
-            "${AOM_ROOT}/aom_dsp/x86/intrapred_sse2.c"
-            "${AOM_ROOT}/aom_dsp/x86/intrapred_x86.h"
-            "${AOM_ROOT}/aom_dsp/x86/loopfilter_sse2.c"
-            "${AOM_ROOT}/aom_dsp/x86/lpf_common_sse2.h"
-            "${AOM_ROOT}/aom_dsp/x86/mem_sse2.h"
-            "${AOM_ROOT}/aom_dsp/x86/transpose_sse2.h"
-            "${AOM_ROOT}/aom_dsp/x86/txfm_common_sse2.h"
-            "${AOM_ROOT}/aom_dsp/x86/sum_squares_sse2.h"
-            "${AOM_ROOT}/aom_dsp/x86/avg_intrin_sse2.c"
-            "${AOM_ROOT}/aom_dsp/x86/bitdepth_conversion_sse2.h")
+list(
+  APPEND
+  AOM_DSP_COMMON_INTRIN_SSE2
+  "${AOM_ROOT}/aom_dsp/x86/aom_convolve_copy_sse2.c"
+  "${AOM_ROOT}/aom_dsp/x86/aom_subpixel_8t_intrin_sse2.c"
+  "${AOM_ROOT}/aom_dsp/x86/aom_asm_stubs.c"
+  "${AOM_ROOT}/aom_dsp/x86/convolve.h"
+  "${AOM_ROOT}/aom_dsp/x86/convolve_sse2.h"
+  "${AOM_ROOT}/aom_dsp/x86/fft_sse2.c"
+  "${AOM_ROOT}/aom_dsp/x86/highbd_convolve_sse2.c"
+  "${AOM_ROOT}/aom_dsp/x86/highbd_intrapred_sse2.c"
+  "${AOM_ROOT}/aom_dsp/x86/highbd_loopfilter_sse2.c"
+  "${AOM_ROOT}/aom_dsp/x86/highbd_subtract_sse2.c"
+  "${AOM_ROOT}/aom_dsp/x86/intrapred_sse2.c"
+  "${AOM_ROOT}/aom_dsp/x86/intrapred_x86.h"
+  "${AOM_ROOT}/aom_dsp/x86/loopfilter_sse2.c"
+  "${AOM_ROOT}/aom_dsp/x86/lpf_common_sse2.h"
+  "${AOM_ROOT}/aom_dsp/x86/mem_sse2.h"
+  "${AOM_ROOT}/aom_dsp/x86/transpose_sse2.h"
+  "${AOM_ROOT}/aom_dsp/x86/txfm_common_sse2.h"
+  "${AOM_ROOT}/aom_dsp/x86/sum_squares_sse2.h"
+  "${AOM_ROOT}/aom_dsp/x86/avg_intrin_sse2.c"
+  "${AOM_ROOT}/aom_dsp/x86/bitdepth_conversion_sse2.h")
 
 list(APPEND AOM_DSP_COMMON_ASM_SSSE3
-            "${AOM_ROOT}/aom_dsp/x86/aom_subpixel_8t_ssse3.asm"
-            "${AOM_ROOT}/aom_dsp/x86/aom_subpixel_bilinear_ssse3.asm")
+     "${AOM_ROOT}/aom_dsp/x86/aom_subpixel_8t_ssse3.asm"
+     "${AOM_ROOT}/aom_dsp/x86/aom_subpixel_bilinear_ssse3.asm")
 
-list(APPEND AOM_DSP_COMMON_INTRIN_SSSE3
-            "${AOM_ROOT}/aom_dsp/x86/aom_subpixel_8t_intrin_ssse3.c"
-            "${AOM_ROOT}/aom_dsp/x86/highbd_convolve_ssse3.c"
-            "${AOM_ROOT}/aom_dsp/x86/intrapred_ssse3.c")
+list(
+  APPEND
+  AOM_DSP_COMMON_INTRIN_SSSE3
+  "${AOM_ROOT}/aom_dsp/x86/aom_subpixel_8t_intrin_ssse3.c"
+  "${AOM_ROOT}/aom_dsp/x86/highbd_convolve_ssse3.c"
+  "${AOM_ROOT}/aom_dsp/x86/intrapred_ssse3.c")
 
-list(APPEND AOM_DSP_COMMON_INTRIN_SSE4_1
-            "${AOM_ROOT}/aom_dsp/x86/blend_mask_sse4.h"
-            "${AOM_ROOT}/aom_dsp/x86/blend_a64_hmask_sse4.c"
-            "${AOM_ROOT}/aom_dsp/x86/blend_a64_mask_sse4.c"
-            "${AOM_ROOT}/aom_dsp/x86/blend_a64_vmask_sse4.c")
+list(
+  APPEND
+  AOM_DSP_COMMON_INTRIN_SSE4_1
+  "${AOM_ROOT}/aom_dsp/x86/blend_mask_sse4.h"
+  "${AOM_ROOT}/aom_dsp/x86/blend_a64_hmask_sse4.c"
+  "${AOM_ROOT}/aom_dsp/x86/blend_a64_mask_sse4.c"
+  "${AOM_ROOT}/aom_dsp/x86/blend_a64_vmask_sse4.c")
 
-list(APPEND AOM_DSP_COMMON_INTRIN_AVX2
-            "${AOM_ROOT}/aom_dsp/x86/aom_convolve_copy_avx2.c"
-            "${AOM_ROOT}/aom_dsp/x86/aom_subpixel_8t_intrin_avx2.c"
-            "${AOM_ROOT}/aom_dsp/x86/common_avx2.h"
-            "${AOM_ROOT}/aom_dsp/x86/txfm_common_avx2.h"
-            "${AOM_ROOT}/aom_dsp/x86/convolve_avx2.h"
-            "${AOM_ROOT}/aom_dsp/x86/fft_avx2.c"
-            "${AOM_ROOT}/aom_dsp/x86/highbd_convolve_avx2.c"
-            "${AOM_ROOT}/aom_dsp/x86/highbd_loopfilter_avx2.c"
-            "${AOM_ROOT}/aom_dsp/x86/intrapred_avx2.c"
-            "${AOM_ROOT}/aom_dsp/x86/blend_a64_mask_avx2.c"
-            "${AOM_ROOT}/aom_dsp/x86/avg_intrin_avx2.c"
-            "${AOM_ROOT}/aom_dsp/x86/bitdepth_conversion_avx2.h")
+list(
+  APPEND
+  AOM_DSP_COMMON_INTRIN_AVX2
+  "${AOM_ROOT}/aom_dsp/x86/aom_convolve_copy_avx2.c"
+  "${AOM_ROOT}/aom_dsp/x86/aom_subpixel_8t_intrin_avx2.c"
+  "${AOM_ROOT}/aom_dsp/x86/common_avx2.h"
+  "${AOM_ROOT}/aom_dsp/x86/subtract_avx2.c"
+  "${AOM_ROOT}/aom_dsp/x86/txfm_common_avx2.h"
+  "${AOM_ROOT}/aom_dsp/x86/convolve_avx2.h"
+  "${AOM_ROOT}/aom_dsp/x86/fft_avx2.c"
+  "${AOM_ROOT}/aom_dsp/x86/highbd_convolve_avx2.c"
+  "${AOM_ROOT}/aom_dsp/x86/highbd_loopfilter_avx2.c"
+  "${AOM_ROOT}/aom_dsp/x86/intrapred_avx2.c"
+  "${AOM_ROOT}/aom_dsp/x86/blend_a64_mask_avx2.c"
+  "${AOM_ROOT}/aom_dsp/x86/avg_intrin_avx2.c"
+  "${AOM_ROOT}/aom_dsp/x86/bitdepth_conversion_avx2.h")
 
-list(APPEND AOM_DSP_COMMON_INTRIN_NEON
-            "${AOM_ROOT}/aom_dsp/arm/aom_convolve_copy_neon.c"
-            "${AOM_ROOT}/aom_dsp/arm/fwd_txfm_neon.c"
-            "${AOM_ROOT}/aom_dsp/arm/loopfilter_neon.c"
-            "${AOM_ROOT}/aom_dsp/arm/intrapred_neon.c"
-            "${AOM_ROOT}/aom_dsp/arm/subtract_neon.c"
-            "${AOM_ROOT}/aom_dsp/arm/blend_a64_mask_neon.c")
+list(
+  APPEND
+  AOM_DSP_COMMON_INTRIN_NEON
+  "${AOM_ROOT}/aom_dsp/arm/aom_convolve_copy_neon.c"
+  "${AOM_ROOT}/aom_dsp/arm/fwd_txfm_neon.c"
+  "${AOM_ROOT}/aom_dsp/arm/loopfilter_neon.c"
+  "${AOM_ROOT}/aom_dsp/arm/intrapred_neon.c"
+  "${AOM_ROOT}/aom_dsp/arm/subtract_neon.c"
+  "${AOM_ROOT}/aom_dsp/arm/blend_a64_mask_neon.c")
 
-list(APPEND AOM_DSP_COMMON_INTRIN_DSPR2
-            "${AOM_ROOT}/aom_dsp/mips/aom_convolve_copy_dspr2.c"
-            "${AOM_ROOT}/aom_dsp/mips/common_dspr2.c"
-            "${AOM_ROOT}/aom_dsp/mips/common_dspr2.h"
-            "${AOM_ROOT}/aom_dsp/mips/convolve2_dspr2.c"
-            "${AOM_ROOT}/aom_dsp/mips/convolve2_horiz_dspr2.c"
-            "${AOM_ROOT}/aom_dsp/mips/convolve2_vert_dspr2.c"
-            "${AOM_ROOT}/aom_dsp/mips/convolve8_horiz_dspr2.c"
-            "${AOM_ROOT}/aom_dsp/mips/convolve8_vert_dspr2.c"
-            "${AOM_ROOT}/aom_dsp/mips/convolve_common_dspr2.h"
-            "${AOM_ROOT}/aom_dsp/mips/intrapred16_dspr2.c"
-            "${AOM_ROOT}/aom_dsp/mips/intrapred4_dspr2.c"
-            "${AOM_ROOT}/aom_dsp/mips/intrapred8_dspr2.c"
-            "${AOM_ROOT}/aom_dsp/mips/inv_txfm_dspr2.h")
+list(
+  APPEND
+  AOM_DSP_COMMON_INTRIN_DSPR2
+  "${AOM_ROOT}/aom_dsp/mips/aom_convolve_copy_dspr2.c"
+  "${AOM_ROOT}/aom_dsp/mips/common_dspr2.c"
+  "${AOM_ROOT}/aom_dsp/mips/common_dspr2.h"
+  "${AOM_ROOT}/aom_dsp/mips/convolve2_dspr2.c"
+  "${AOM_ROOT}/aom_dsp/mips/convolve2_horiz_dspr2.c"
+  "${AOM_ROOT}/aom_dsp/mips/convolve2_vert_dspr2.c"
+  "${AOM_ROOT}/aom_dsp/mips/convolve8_horiz_dspr2.c"
+  "${AOM_ROOT}/aom_dsp/mips/convolve8_vert_dspr2.c"
+  "${AOM_ROOT}/aom_dsp/mips/convolve_common_dspr2.h"
+  "${AOM_ROOT}/aom_dsp/mips/intrapred16_dspr2.c"
+  "${AOM_ROOT}/aom_dsp/mips/intrapred4_dspr2.c"
+  "${AOM_ROOT}/aom_dsp/mips/intrapred8_dspr2.c"
+  "${AOM_ROOT}/aom_dsp/mips/inv_txfm_dspr2.h")
 
-list(APPEND AOM_DSP_COMMON_INTRIN_MSA
-            "${AOM_ROOT}/aom_dsp/mips/aom_convolve8_horiz_msa.c"
-            "${AOM_ROOT}/aom_dsp/mips/aom_convolve8_vert_msa.c"
-            "${AOM_ROOT}/aom_dsp/mips/aom_convolve_copy_msa.c"
-            "${AOM_ROOT}/aom_dsp/mips/aom_convolve_msa.h"
-            "${AOM_ROOT}/aom_dsp/mips/intrapred_msa.c"
-            "${AOM_ROOT}/aom_dsp/mips/macros_msa.h")
+list(
+  APPEND
+  AOM_DSP_COMMON_INTRIN_MSA
+  "${AOM_ROOT}/aom_dsp/mips/aom_convolve8_horiz_msa.c"
+  "${AOM_ROOT}/aom_dsp/mips/aom_convolve8_vert_msa.c"
+  "${AOM_ROOT}/aom_dsp/mips/aom_convolve_copy_msa.c"
+  "${AOM_ROOT}/aom_dsp/mips/aom_convolve_msa.h"
+  "${AOM_ROOT}/aom_dsp/mips/intrapred_msa.c"
+  "${AOM_ROOT}/aom_dsp/mips/macros_msa.h")
 
 if(CONFIG_AV1_DECODER)
-  list(APPEND AOM_DSP_DECODER_SOURCES
-              "${AOM_ROOT}/aom_dsp/binary_codes_reader.c"
-              "${AOM_ROOT}/aom_dsp/binary_codes_reader.h"
-              "${AOM_ROOT}/aom_dsp/bitreader.c"
-              "${AOM_ROOT}/aom_dsp/bitreader.h" "${AOM_ROOT}/aom_dsp/entdec.c"
-              "${AOM_ROOT}/aom_dsp/entdec.h"
-              "${AOM_ROOT}/aom_dsp/grain_synthesis.c"
-              "${AOM_ROOT}/aom_dsp/grain_synthesis.h")
+  list(
+    APPEND
+    AOM_DSP_DECODER_SOURCES
+    "${AOM_ROOT}/aom_dsp/binary_codes_reader.c"
+    "${AOM_ROOT}/aom_dsp/binary_codes_reader.h"
+    "${AOM_ROOT}/aom_dsp/bitreader.c"
+    "${AOM_ROOT}/aom_dsp/bitreader.h"
+    "${AOM_ROOT}/aom_dsp/entdec.c"
+    "${AOM_ROOT}/aom_dsp/entdec.h"
+    "${AOM_ROOT}/aom_dsp/grain_synthesis.c"
+    "${AOM_ROOT}/aom_dsp/grain_synthesis.h")
 endif()
 
 if(CONFIG_AV1_ENCODER)
-  list(APPEND AOM_DSP_ENCODER_SOURCES
-              "${AOM_ROOT}/aom_dsp/binary_codes_writer.c"
-              "${AOM_ROOT}/aom_dsp/binary_codes_writer.h"
-              "${AOM_ROOT}/aom_dsp/bitwriter.c"
-              "${AOM_ROOT}/aom_dsp/bitwriter.h"
-              "${AOM_ROOT}/aom_dsp/blk_sse_sum.c"
-              "${AOM_ROOT}/aom_dsp/entenc.c"
-              "${AOM_ROOT}/aom_dsp/entenc.h"
-              "${AOM_ROOT}/aom_dsp/fwd_txfm.c"
-              "${AOM_ROOT}/aom_dsp/grain_table.c"
-              "${AOM_ROOT}/aom_dsp/grain_table.h"
-              "${AOM_ROOT}/aom_dsp/noise_model.c"
-              "${AOM_ROOT}/aom_dsp/noise_model.h"
-              "${AOM_ROOT}/aom_dsp/noise_util.c"
-              "${AOM_ROOT}/aom_dsp/noise_util.h"
-              "${AOM_ROOT}/aom_dsp/psnr.c"
-              "${AOM_ROOT}/aom_dsp/psnr.h"
-              "${AOM_ROOT}/aom_dsp/quantize.c"
-              "${AOM_ROOT}/aom_dsp/quantize.h"
-              "${AOM_ROOT}/aom_dsp/sad.c"
-              "${AOM_ROOT}/aom_dsp/sse.c"
-              "${AOM_ROOT}/aom_dsp/sad_av1.c"
-              "${AOM_ROOT}/aom_dsp/sum_squares.c"
-              "${AOM_ROOT}/aom_dsp/variance.c"
-              "${AOM_ROOT}/aom_dsp/variance.h")
+  list(
+    APPEND
+    AOM_DSP_ENCODER_SOURCES
+    "${AOM_ROOT}/aom_dsp/binary_codes_writer.c"
+    "${AOM_ROOT}/aom_dsp/binary_codes_writer.h"
+    "${AOM_ROOT}/aom_dsp/bitwriter.c"
+    "${AOM_ROOT}/aom_dsp/bitwriter.h"
+    "${AOM_ROOT}/aom_dsp/blk_sse_sum.c"
+    "${AOM_ROOT}/aom_dsp/entenc.c"
+    "${AOM_ROOT}/aom_dsp/entenc.h"
+    "${AOM_ROOT}/aom_dsp/fwd_txfm.c"
+    "${AOM_ROOT}/aom_dsp/grain_table.c"
+    "${AOM_ROOT}/aom_dsp/grain_table.h"
+    "${AOM_ROOT}/aom_dsp/noise_model.c"
+    "${AOM_ROOT}/aom_dsp/noise_model.h"
+    "${AOM_ROOT}/aom_dsp/noise_util.c"
+    "${AOM_ROOT}/aom_dsp/noise_util.h"
+    "${AOM_ROOT}/aom_dsp/psnr.c"
+    "${AOM_ROOT}/aom_dsp/psnr.h"
+    "${AOM_ROOT}/aom_dsp/quantize.c"
+    "${AOM_ROOT}/aom_dsp/quantize.h"
+    "${AOM_ROOT}/aom_dsp/sad.c"
+    "${AOM_ROOT}/aom_dsp/sse.c"
+    "${AOM_ROOT}/aom_dsp/sad_av1.c"
+    "${AOM_ROOT}/aom_dsp/sum_squares.c"
+    "${AOM_ROOT}/aom_dsp/variance.c"
+    "${AOM_ROOT}/aom_dsp/variance.h")
 
-  list(APPEND AOM_DSP_ENCODER_ASM_SSE2
-              "${AOM_ROOT}/aom_dsp/x86/highbd_sad4d_sse2.asm"
-              "${AOM_ROOT}/aom_dsp/x86/highbd_sad_sse2.asm"
-              "${AOM_ROOT}/aom_dsp/x86/highbd_subpel_variance_impl_sse2.asm"
-              "${AOM_ROOT}/aom_dsp/x86/highbd_variance_impl_sse2.asm"
-              "${AOM_ROOT}/aom_dsp/x86/sad4d_sse2.asm"
-              "${AOM_ROOT}/aom_dsp/x86/sad_sse2.asm"
-              "${AOM_ROOT}/aom_dsp/x86/subpel_variance_sse2.asm"
-              "${AOM_ROOT}/aom_dsp/x86/subtract_sse2.asm")
+  list(
+    APPEND
+    AOM_DSP_ENCODER_ASM_SSE2
+    "${AOM_ROOT}/aom_dsp/x86/highbd_sad4d_sse2.asm"
+    "${AOM_ROOT}/aom_dsp/x86/highbd_sad_sse2.asm"
+    "${AOM_ROOT}/aom_dsp/x86/highbd_subpel_variance_impl_sse2.asm"
+    "${AOM_ROOT}/aom_dsp/x86/highbd_variance_impl_sse2.asm"
+    "${AOM_ROOT}/aom_dsp/x86/sad4d_sse2.asm"
+    "${AOM_ROOT}/aom_dsp/x86/sad_sse2.asm"
+    "${AOM_ROOT}/aom_dsp/x86/subpel_variance_sse2.asm"
+    "${AOM_ROOT}/aom_dsp/x86/subtract_sse2.asm")
 
   list(APPEND AOM_DSP_ENCODER_ASM_SSE2_X86_64
-              "${AOM_ROOT}/aom_dsp/x86/ssim_sse2_x86_64.asm")
+       "${AOM_ROOT}/aom_dsp/x86/ssim_sse2_x86_64.asm")
 
-  list(APPEND AOM_DSP_ENCODER_INTRIN_SSE2
-              "${AOM_ROOT}/aom_dsp/x86/fwd_txfm_impl_sse2.h"
-              "${AOM_ROOT}/aom_dsp/x86/fwd_txfm_sse2.c"
-              "${AOM_ROOT}/aom_dsp/x86/fwd_txfm_sse2.h"
-              "${AOM_ROOT}/aom_dsp/x86/highbd_quantize_intrin_sse2.c"
-              "${AOM_ROOT}/aom_dsp/x86/highbd_subtract_sse2.c"
-              "${AOM_ROOT}/aom_dsp/x86/highbd_variance_sse2.c"
-              "${AOM_ROOT}/aom_dsp/x86/quantize_sse2.c"
-              "${AOM_ROOT}/aom_dsp/x86/adaptive_quantize_sse2.c"
-              "${AOM_ROOT}/aom_dsp/x86/highbd_adaptive_quantize_sse2.c"
-              "${AOM_ROOT}/aom_dsp/x86/quantize_x86.h"
-              "${AOM_ROOT}/aom_dsp/x86/blk_sse_sum_sse2.c"
-              "${AOM_ROOT}/aom_dsp/x86/sum_squares_sse2.c"
-              "${AOM_ROOT}/aom_dsp/x86/variance_sse2.c")
+  list(
+    APPEND
+    AOM_DSP_ENCODER_INTRIN_SSE2
+    "${AOM_ROOT}/aom_dsp/x86/fwd_txfm_impl_sse2.h"
+    "${AOM_ROOT}/aom_dsp/x86/fwd_txfm_sse2.c"
+    "${AOM_ROOT}/aom_dsp/x86/fwd_txfm_sse2.h"
+    "${AOM_ROOT}/aom_dsp/x86/highbd_quantize_intrin_sse2.c"
+    "${AOM_ROOT}/aom_dsp/x86/highbd_variance_sse2.c"
+    "${AOM_ROOT}/aom_dsp/x86/quantize_sse2.c"
+    "${AOM_ROOT}/aom_dsp/x86/adaptive_quantize_sse2.c"
+    "${AOM_ROOT}/aom_dsp/x86/highbd_adaptive_quantize_sse2.c"
+    "${AOM_ROOT}/aom_dsp/x86/quantize_x86.h"
+    "${AOM_ROOT}/aom_dsp/x86/blk_sse_sum_sse2.c"
+    "${AOM_ROOT}/aom_dsp/x86/sum_squares_sse2.c"
+    "${AOM_ROOT}/aom_dsp/x86/variance_sse2.c")
 
   list(APPEND AOM_DSP_ENCODER_ASM_SSSE3_X86_64
-              "${AOM_ROOT}/aom_dsp/x86/fwd_txfm_ssse3_x86_64.asm"
-              "${AOM_ROOT}/aom_dsp/x86/quantize_ssse3_x86_64.asm")
+       "${AOM_ROOT}/aom_dsp/x86/fwd_txfm_ssse3_x86_64.asm"
+       "${AOM_ROOT}/aom_dsp/x86/quantize_ssse3_x86_64.asm")
 
-  list(APPEND AOM_DSP_ENCODER_INTRIN_AVX2
-              "${AOM_ROOT}/aom_dsp/x86/masked_sad_intrin_avx2.c"
-              "${AOM_ROOT}/aom_dsp/x86/subtract_avx2.c"
-              "${AOM_ROOT}/aom_dsp/x86/highbd_quantize_intrin_avx2.c"
-              "${AOM_ROOT}/aom_dsp/x86/adaptive_quantize_avx2.c"
-              "${AOM_ROOT}/aom_dsp/x86/highbd_adaptive_quantize_avx2.c"
-              "${AOM_ROOT}/aom_dsp/x86/sad4d_avx2.c"
-              "${AOM_ROOT}/aom_dsp/x86/sad_avx2.c"
-              "${AOM_ROOT}/aom_dsp/x86/sad_highbd_avx2.c"
-              "${AOM_ROOT}/aom_dsp/x86/sad_impl_avx2.c"
-              "${AOM_ROOT}/aom_dsp/x86/variance_avx2.c"
-              "${AOM_ROOT}/aom_dsp/x86/highbd_variance_avx2.c"
-              "${AOM_ROOT}/aom_dsp/x86/sse_avx2.c"
-              "${AOM_ROOT}/aom_dsp/x86/variance_impl_avx2.c"
-              "${AOM_ROOT}/aom_dsp/x86/obmc_sad_avx2.c"
-              "${AOM_ROOT}/aom_dsp/x86/obmc_variance_avx2.c"
-              "${AOM_ROOT}/aom_dsp/x86/blk_sse_sum_avx2.c"
-              "${AOM_ROOT}/aom_dsp/x86/sum_squares_avx2.c")
+  list(
+    APPEND
+    AOM_DSP_ENCODER_INTRIN_AVX2
+    "${AOM_ROOT}/aom_dsp/x86/masked_sad_intrin_avx2.c"
+    "${AOM_ROOT}/aom_dsp/x86/highbd_quantize_intrin_avx2.c"
+    "${AOM_ROOT}/aom_dsp/x86/adaptive_quantize_avx2.c"
+    "${AOM_ROOT}/aom_dsp/x86/highbd_adaptive_quantize_avx2.c"
+    "${AOM_ROOT}/aom_dsp/x86/sad4d_avx2.c"
+    "${AOM_ROOT}/aom_dsp/x86/sad_avx2.c"
+    "${AOM_ROOT}/aom_dsp/x86/sad_highbd_avx2.c"
+    "${AOM_ROOT}/aom_dsp/x86/sad_impl_avx2.c"
+    "${AOM_ROOT}/aom_dsp/x86/variance_avx2.c"
+    "${AOM_ROOT}/aom_dsp/x86/highbd_variance_avx2.c"
+    "${AOM_ROOT}/aom_dsp/x86/sse_avx2.c"
+    "${AOM_ROOT}/aom_dsp/x86/variance_impl_avx2.c"
+    "${AOM_ROOT}/aom_dsp/x86/obmc_sad_avx2.c"
+    "${AOM_ROOT}/aom_dsp/x86/obmc_variance_avx2.c"
+    "${AOM_ROOT}/aom_dsp/x86/blk_sse_sum_avx2.c"
+    "${AOM_ROOT}/aom_dsp/x86/sum_squares_avx2.c")
 
   list(APPEND AOM_DSP_ENCODER_INTRIN_AVX
-              "${AOM_ROOT}/aom_dsp/x86/aom_quantize_avx.c")
+       "${AOM_ROOT}/aom_dsp/x86/aom_quantize_avx.c")
 
-  list(APPEND AOM_DSP_ENCODER_INTRIN_SSSE3
-              "${AOM_ROOT}/aom_dsp/x86/masked_sad_intrin_ssse3.h"
-              "${AOM_ROOT}/aom_dsp/x86/masked_sad_intrin_ssse3.c"
-              "${AOM_ROOT}/aom_dsp/x86/masked_sad4d_ssse3.c"
-              "${AOM_ROOT}/aom_dsp/x86/masked_variance_intrin_ssse3.h"
-              "${AOM_ROOT}/aom_dsp/x86/masked_variance_intrin_ssse3.c"
-              "${AOM_ROOT}/aom_dsp/x86/quantize_ssse3.c"
-              "${AOM_ROOT}/aom_dsp/x86/variance_impl_ssse3.c"
-              "${AOM_ROOT}/aom_dsp/x86/jnt_variance_ssse3.c"
-              "${AOM_ROOT}/aom_dsp/x86/jnt_sad_ssse3.c")
+  list(
+    APPEND
+    AOM_DSP_ENCODER_INTRIN_SSSE3
+    "${AOM_ROOT}/aom_dsp/x86/masked_sad_intrin_ssse3.h"
+    "${AOM_ROOT}/aom_dsp/x86/masked_sad_intrin_ssse3.c"
+    "${AOM_ROOT}/aom_dsp/x86/masked_sad4d_ssse3.c"
+    "${AOM_ROOT}/aom_dsp/x86/masked_variance_intrin_ssse3.h"
+    "${AOM_ROOT}/aom_dsp/x86/masked_variance_intrin_ssse3.c"
+    "${AOM_ROOT}/aom_dsp/x86/quantize_ssse3.c"
+    "${AOM_ROOT}/aom_dsp/x86/variance_impl_ssse3.c"
+    "${AOM_ROOT}/aom_dsp/x86/jnt_variance_ssse3.c"
+    "${AOM_ROOT}/aom_dsp/x86/jnt_sad_ssse3.c")
 
-  list(APPEND AOM_DSP_ENCODER_INTRIN_SSE4_1
-              "${AOM_ROOT}/aom_dsp/x86/highbd_variance_sse4.c"
-              "${AOM_ROOT}/aom_dsp/x86/sse_sse4.c"
-              "${AOM_ROOT}/aom_dsp/x86/obmc_sad_sse4.c"
-              "${AOM_ROOT}/aom_dsp/x86/obmc_variance_sse4.c")
+  list(
+    APPEND
+    AOM_DSP_ENCODER_INTRIN_SSE4_1
+    "${AOM_ROOT}/aom_dsp/x86/highbd_variance_sse4.c"
+    "${AOM_ROOT}/aom_dsp/x86/sse_sse4.c"
+    "${AOM_ROOT}/aom_dsp/x86/obmc_sad_sse4.c"
+    "${AOM_ROOT}/aom_dsp/x86/obmc_variance_sse4.c")
 
-  list(APPEND AOM_DSP_ENCODER_INTRIN_NEON "${AOM_ROOT}/aom_dsp/arm/sad4d_neon.c"
-              "${AOM_ROOT}/aom_dsp/arm/sad_neon.c"
-              "${AOM_ROOT}/aom_dsp/arm/subpel_variance_neon.c"
-              "${AOM_ROOT}/aom_dsp/arm/variance_neon.c"
-              "${AOM_ROOT}/aom_dsp/arm/hadamard_neon.c"
-              "${AOM_ROOT}/aom_dsp/arm/avg_neon.c"
-              "${AOM_ROOT}/aom_dsp/arm/sse_neon.c"
-              "${AOM_ROOT}/aom_dsp/arm/sum_squares_neon.c")
+  list(
+    APPEND
+    AOM_DSP_ENCODER_INTRIN_NEON
+    "${AOM_ROOT}/aom_dsp/arm/sad4d_neon.c"
+    "${AOM_ROOT}/aom_dsp/arm/sad_neon.c"
+    "${AOM_ROOT}/aom_dsp/arm/subpel_variance_neon.c"
+    "${AOM_ROOT}/aom_dsp/arm/variance_neon.c"
+    "${AOM_ROOT}/aom_dsp/arm/hadamard_neon.c"
+    "${AOM_ROOT}/aom_dsp/arm/avg_neon.c"
+    "${AOM_ROOT}/aom_dsp/arm/sse_neon.c"
+    "${AOM_ROOT}/aom_dsp/arm/sum_squares_neon.c")
 
-  list(APPEND AOM_DSP_ENCODER_INTRIN_MSA "${AOM_ROOT}/aom_dsp/mips/sad_msa.c"
-              "${AOM_ROOT}/aom_dsp/mips/subtract_msa.c"
-              "${AOM_ROOT}/aom_dsp/mips/variance_msa.c"
-              "${AOM_ROOT}/aom_dsp/mips/sub_pixel_variance_msa.c")
+  list(
+    APPEND
+    AOM_DSP_ENCODER_INTRIN_MSA
+    "${AOM_ROOT}/aom_dsp/mips/sad_msa.c"
+    "${AOM_ROOT}/aom_dsp/mips/subtract_msa.c"
+    "${AOM_ROOT}/aom_dsp/mips/variance_msa.c"
+    "${AOM_ROOT}/aom_dsp/mips/sub_pixel_variance_msa.c")
 
   if(CONFIG_INTERNAL_STATS)
     list(APPEND AOM_DSP_ENCODER_SOURCES "${AOM_ROOT}/aom_dsp/fastssim.c"
-                "${AOM_ROOT}/aom_dsp/psnrhvs.c" "${AOM_ROOT}/aom_dsp/ssim.c"
-                "${AOM_ROOT}/aom_dsp/ssim.h")
+         "${AOM_ROOT}/aom_dsp/psnrhvs.c" "${AOM_ROOT}/aom_dsp/ssim.c"
+         "${AOM_ROOT}/aom_dsp/ssim.h")
   endif()
 
   if(CONFIG_TUNE_VMAF)
     list(APPEND AOM_DSP_ENCODER_SOURCES "${AOM_ROOT}/aom_dsp/vmaf.c"
-                "${AOM_ROOT}/aom_dsp/vmaf.h")
+         "${AOM_ROOT}/aom_dsp/vmaf.h")
   endif()
 endif()
 
@@ -330,7 +369,7 @@
     if(CONFIG_AV1_ENCODER)
       if("${AOM_TARGET_CPU}" STREQUAL "x86_64")
         list(APPEND AOM_DSP_ENCODER_ASM_SSSE3
-                    ${AOM_DSP_ENCODER_ASM_SSSE3_X86_64})
+             ${AOM_DSP_ENCODER_ASM_SSSE3_X86_64})
       endif()
       add_asm_library("aom_dsp_encoder_ssse3" "AOM_DSP_ENCODER_ASM_SSSE3")
       add_intrinsics_object_library("-mssse3" "ssse3" "aom_dsp_encoder"
@@ -367,9 +406,9 @@
     add_intrinsics_object_library("${AOM_NEON_INTRIN_FLAG}" "neon"
                                   "aom_dsp_common" "AOM_DSP_COMMON_INTRIN_NEON")
     if(CONFIG_AV1_ENCODER)
-      add_intrinsics_object_library("${AOM_NEON_INTRIN_FLAG}" "neon"
-                                    "aom_dsp_encoder"
-                                    "AOM_DSP_ENCODER_INTRIN_NEON")
+      add_intrinsics_object_library(
+        "${AOM_NEON_INTRIN_FLAG}" "neon" "aom_dsp_encoder"
+        "AOM_DSP_ENCODER_INTRIN_NEON")
     endif()
   endif()
 
@@ -394,5 +433,7 @@
 
   # Pass the new lib targets up to the parent scope instance of
   # $AOM_LIB_TARGETS.
-  set(AOM_LIB_TARGETS ${AOM_LIB_TARGETS} PARENT_SCOPE)
+  set(AOM_LIB_TARGETS
+      ${AOM_LIB_TARGETS}
+      PARENT_SCOPE)
 endfunction()
diff --git a/aom_dsp/aom_dsp_common.h b/aom_dsp/aom_dsp_common.h
index ee385b7..0f7384a 100644
--- a/aom_dsp/aom_dsp_common.h
+++ b/aom_dsp/aom_dsp_common.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_AOM_DSP_COMMON_H_
diff --git a/aom_dsp/aom_dsp_rtcd.c b/aom_dsp/aom_dsp_rtcd.c
index 1514bd6..a56d615 100644
--- a/aom_dsp/aom_dsp_rtcd.c
+++ b/aom_dsp/aom_dsp_rtcd.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #include "config/aom_config.h"
 
diff --git a/aom_dsp/aom_dsp_rtcd_defs.pl b/aom_dsp/aom_dsp_rtcd_defs.pl
index 9e6b5b1..7672dfb 100755
--- a/aom_dsp/aom_dsp_rtcd_defs.pl
+++ b/aom_dsp/aom_dsp_rtcd_defs.pl
@@ -1,12 +1,12 @@
 ##
-## Copyright (c) 2017, Alliance for Open Media. All rights reserved
+## Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ##
-## This source code is subject to the terms of the BSD 2 Clause License and
-## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-## was not distributed with this source code in the LICENSE file, you can
-## obtain it at www.aomedia.org/license/software. If the Alliance for Open
-## Media Patent License 1.0 was not distributed with this source code in the
-## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+## This source code is subject to the terms of the BSD 3-Clause Clear License and the
+## Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+## not distributed with this source code in the LICENSE file, you can obtain it
+## at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+## License 1.0 was not distributed with this source code in the PATENTS file, you
+## can obtain it at aomedia.org/license/patent-license/.
 ##
 sub aom_dsp_forward_decls() {
 print <<EOF
@@ -64,7 +64,10 @@
   }
 }
 
-@pred_names = qw/dc dc_top dc_left dc_128 v h paeth smooth smooth_v smooth_h/;
+@pred_names = qw /
+              dc dc_top dc_left dc_128 v h paeth smooth smooth_v smooth_h ibp_dc
+              ibp_dc_top ibp_dc_left /
+    ;
 
 #
 # Intra prediction
@@ -606,22 +609,22 @@
 specialize "aom_highbd_blend_a64_vmask", qw/sse4_1/;
 specialize "aom_highbd_blend_a64_d16_mask", qw/sse4_1 avx2/;
 
-if (aom_config("CONFIG_AV1_ENCODER") eq "yes") {
-  #
-  # Block subtraction
-  #
-  add_proto qw/void aom_subtract_block/, "int rows, int cols, int16_t *diff_ptr, ptrdiff_t diff_stride, const uint8_t *src_ptr, ptrdiff_t src_stride, const uint8_t *pred_ptr, ptrdiff_t pred_stride";
-  specialize qw/aom_subtract_block neon msa sse2 avx2/;
+#
+# Block subtraction
+#
+add_proto qw/void aom_subtract_block/, "int rows, int cols, int16_t *diff_ptr, ptrdiff_t diff_stride, const uint8_t *src_ptr, ptrdiff_t src_stride, const uint8_t *pred_ptr, ptrdiff_t pred_stride";
+specialize qw/aom_subtract_block neon msa avx2/;
 
+add_proto qw/void aom_highbd_subtract_block/, "int rows, int cols, int16_t *diff_ptr, ptrdiff_t diff_stride, const uint8_t *src_ptr, ptrdiff_t src_stride, const uint8_t *pred_ptr, ptrdiff_t pred_stride, int bd";
+specialize qw/aom_highbd_subtract_block sse2/;
+
+if (aom_config("CONFIG_AV1_ENCODER") eq "yes") {
   add_proto qw/int64_t/, "aom_sse", "const uint8_t *a, int a_stride, const uint8_t *b,int b_stride, int width, int height";
   specialize qw/aom_sse  sse4_1 avx2 neon/;
 
   add_proto qw/void/, "aom_get_blk_sse_sum", "const int16_t *data, int stride, int bw, int bh, int *x_sum, int64_t *x2_sum";
   specialize qw/aom_get_blk_sse_sum sse2 avx2/;
 
-  add_proto qw/void aom_highbd_subtract_block/, "int rows, int cols, int16_t *diff_ptr, ptrdiff_t diff_stride, const uint8_t *src_ptr, ptrdiff_t src_stride, const uint8_t *pred_ptr, ptrdiff_t pred_stride, int bd";
-  specialize qw/aom_highbd_subtract_block sse2/;
-
   add_proto qw/int64_t/, "aom_highbd_sse", "const uint8_t *a8, int a_stride, const uint8_t *b8,int b_stride, int width, int height";
   specialize qw/aom_highbd_sse  sse4_1 avx2 neon/;
 
diff --git a/aom_dsp/aom_filter.h b/aom_dsp/aom_filter.h
index 00686ac..247062c 100644
--- a/aom_dsp/aom_filter.h
+++ b/aom_dsp/aom_filter.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_AOM_FILTER_H_
diff --git a/aom_dsp/aom_simd.h b/aom_dsp/aom_simd.h
index ab950ca..1a55e6b 100644
--- a/aom_dsp/aom_simd.h
+++ b/aom_dsp/aom_simd.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_AOM_SIMD_H_
diff --git a/aom_dsp/aom_simd_inline.h b/aom_dsp/aom_simd_inline.h
index eb333f6..bbf1efe 100644
--- a/aom_dsp/aom_simd_inline.h
+++ b/aom_dsp/aom_simd_inline.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_AOM_SIMD_INLINE_H_
diff --git a/aom_dsp/arm/blend_a64_mask_neon.c b/aom_dsp/arm/blend_a64_mask_neon.c
index e7f08a5..cf692e6 100644
--- a/aom_dsp/arm/blend_a64_mask_neon.c
+++ b/aom_dsp/arm/blend_a64_mask_neon.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <arm_neon.h>
diff --git a/aom_dsp/arm/fwd_txfm_neon.c b/aom_dsp/arm/fwd_txfm_neon.c
index ce93523..4e67438 100644
--- a/aom_dsp/arm/fwd_txfm_neon.c
+++ b/aom_dsp/arm/fwd_txfm_neon.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <arm_neon.h>
diff --git a/aom_dsp/arm/intrapred_neon.c b/aom_dsp/arm/intrapred_neon.c
index 6d41708..5d3c152 100644
--- a/aom_dsp/arm/intrapred_neon.c
+++ b/aom_dsp/arm/intrapred_neon.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <arm_neon.h>
diff --git a/aom_dsp/arm/loopfilter_neon.c b/aom_dsp/arm/loopfilter_neon.c
index aafac89..37022cc 100644
--- a/aom_dsp/arm/loopfilter_neon.c
+++ b/aom_dsp/arm/loopfilter_neon.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <arm_neon.h>
diff --git a/aom_dsp/arm/sad4d_neon.c b/aom_dsp/arm/sad4d_neon.c
index 0e633b5..8e60939 100644
--- a/aom_dsp/arm/sad4d_neon.c
+++ b/aom_dsp/arm/sad4d_neon.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <arm_neon.h>
diff --git a/aom_dsp/arm/sad_neon.c b/aom_dsp/arm/sad_neon.c
index 32b9e9d..c3740a7 100644
--- a/aom_dsp/arm/sad_neon.c
+++ b/aom_dsp/arm/sad_neon.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <arm_neon.h>
diff --git a/aom_dsp/arm/subpel_variance_neon.c b/aom_dsp/arm/subpel_variance_neon.c
index 7c861d4..d75387e 100644
--- a/aom_dsp/arm/subpel_variance_neon.c
+++ b/aom_dsp/arm/subpel_variance_neon.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <arm_neon.h>
diff --git a/aom_dsp/arm/subtract_neon.c b/aom_dsp/arm/subtract_neon.c
index 28f5ace..923fcc7 100644
--- a/aom_dsp/arm/subtract_neon.c
+++ b/aom_dsp/arm/subtract_neon.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <arm_neon.h>
diff --git a/aom_dsp/arm/sum_squares_neon.c b/aom_dsp/arm/sum_squares_neon.c
index 1ce12ec..ee54967 100644
--- a/aom_dsp/arm/sum_squares_neon.c
+++ b/aom_dsp/arm/sum_squares_neon.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <arm_neon.h>
diff --git a/aom_dsp/arm/variance_neon.c b/aom_dsp/arm/variance_neon.c
index 3a95ba2..d455238 100644
--- a/aom_dsp/arm/variance_neon.c
+++ b/aom_dsp/arm/variance_neon.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <arm_neon.h>
diff --git a/aom_dsp/avg.c b/aom_dsp/avg.c
index 5363736..a638b02 100644
--- a/aom_dsp/avg.c
+++ b/aom_dsp/avg.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <stdlib.h>
diff --git a/aom_dsp/binary_codes_reader.c b/aom_dsp/binary_codes_reader.c
index 7cd903d..b9172b0 100644
--- a/aom_dsp/binary_codes_reader.c
+++ b/aom_dsp/binary_codes_reader.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "aom_dsp/binary_codes_reader.h"
diff --git a/aom_dsp/binary_codes_reader.h b/aom_dsp/binary_codes_reader.h
index d218f06..4559ff2 100644
--- a/aom_dsp/binary_codes_reader.h
+++ b/aom_dsp/binary_codes_reader.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_BINARY_CODES_READER_H_
diff --git a/aom_dsp/binary_codes_writer.c b/aom_dsp/binary_codes_writer.c
index adf1c13..9d8b4c6 100644
--- a/aom_dsp/binary_codes_writer.c
+++ b/aom_dsp/binary_codes_writer.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "aom_dsp/bitwriter.h"
diff --git a/aom_dsp/binary_codes_writer.h b/aom_dsp/binary_codes_writer.h
index 5ec8662..8d37574 100644
--- a/aom_dsp/binary_codes_writer.h
+++ b/aom_dsp/binary_codes_writer.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_BINARY_CODES_WRITER_H_
diff --git a/aom_dsp/bitreader.c b/aom_dsp/bitreader.c
index 4c70a91..96fc999 100644
--- a/aom_dsp/bitreader.c
+++ b/aom_dsp/bitreader.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "aom_dsp/bitreader.h"
diff --git a/aom_dsp/bitreader.h b/aom_dsp/bitreader.h
index 255d98c..8f938f3 100644
--- a/aom_dsp/bitreader.h
+++ b/aom_dsp/bitreader.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_BITREADER_H_
@@ -93,10 +94,22 @@
   }
 }
 
+#if CONFIG_THROUGHPUT_ANALYSIS
+static INLINE void aom_update_symb_counts(const aom_reader *r, int is_binary,
+                                          int is_context_coded) {
+#else
 static INLINE void aom_update_symb_counts(const aom_reader *r, int is_binary) {
+#endif  // CONFIG_THROUGHPUT_ANALYSIS
   if (r->accounting != NULL) {
     r->accounting->syms.num_multi_syms += !is_binary;
     r->accounting->syms.num_binary_syms += !!is_binary;
+#if CONFIG_THROUGHPUT_ANALYSIS
+    if (is_context_coded) {
+      r->accounting->syms.num_ctx_coded += 1;
+    } else {
+      r->accounting->syms.num_bypass_coded += 1;
+    }
+#endif  // CONFIG_THROUGHPUT_ANALYSIS
   }
 }
 #endif
@@ -141,7 +154,11 @@
 
 #if CONFIG_ACCOUNTING
   if (ACCT_STR_NAME) aom_process_accounting(r, ACCT_STR_NAME);
+#if CONFIG_THROUGHPUT_ANALYSIS
+  aom_update_symb_counts(r, 1, 0);
+#else
   aom_update_symb_counts(r, 1);
+#endif  // CONFIG_THROUGHPUT_ANALYSIS
 #endif
   return bit;
 }
@@ -212,7 +229,11 @@
 
 #if CONFIG_ACCOUNTING
   if (ACCT_STR_NAME) aom_process_accounting(r, ACCT_STR_NAME);
+#if CONFIG_THROUGHPUT_ANALYSIS
+  aom_update_symb_counts(r, (nsymbs == 2), 1);
+#else
   aom_update_symb_counts(r, (nsymbs == 2));
+#endif  // CONFIG_THROUGHPUT_ANALYSIS
 #endif
   return symb;
 }
diff --git a/aom_dsp/bitreader_buffer.c b/aom_dsp/bitreader_buffer.c
index 0b48c5d..6a89a59 100644
--- a/aom_dsp/bitreader_buffer.c
+++ b/aom_dsp/bitreader_buffer.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/aom_dsp/bitreader_buffer.h b/aom_dsp/bitreader_buffer.h
index 42a69d8..42be446 100644
--- a/aom_dsp/bitreader_buffer.h
+++ b/aom_dsp/bitreader_buffer.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_BITREADER_BUFFER_H_
diff --git a/aom_dsp/bitwriter.c b/aom_dsp/bitwriter.c
index 41fcc51..675918a 100644
--- a/aom_dsp/bitwriter.c
+++ b/aom_dsp/bitwriter.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <string.h>
diff --git a/aom_dsp/bitwriter.h b/aom_dsp/bitwriter.h
index 4a750c0..1490b41 100644
--- a/aom_dsp/bitwriter.h
+++ b/aom_dsp/bitwriter.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_BITWRITER_H_
diff --git a/aom_dsp/bitwriter_buffer.c b/aom_dsp/bitwriter_buffer.c
index c617a44..2a85365 100644
--- a/aom_dsp/bitwriter_buffer.c
+++ b/aom_dsp/bitwriter_buffer.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/aom_dsp/bitwriter_buffer.h b/aom_dsp/bitwriter_buffer.h
index 09ebeff..30199f3 100644
--- a/aom_dsp/bitwriter_buffer.h
+++ b/aom_dsp/bitwriter_buffer.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_BITWRITER_BUFFER_H_
diff --git a/aom_dsp/blend.h b/aom_dsp/blend.h
index fd87dc1..f40d2db 100644
--- a/aom_dsp/blend.h
+++ b/aom_dsp/blend.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_BLEND_H_
diff --git a/aom_dsp/blend_a64_hmask.c b/aom_dsp/blend_a64_hmask.c
index 0554b43..d41f749 100644
--- a/aom_dsp/blend_a64_hmask.c
+++ b/aom_dsp/blend_a64_hmask.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/aom_dsp/blend_a64_mask.c b/aom_dsp/blend_a64_mask.c
index 79956c3..718c68e 100644
--- a/aom_dsp/blend_a64_mask.c
+++ b/aom_dsp/blend_a64_mask.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/aom_dsp/blend_a64_vmask.c b/aom_dsp/blend_a64_vmask.c
index 4f222e1..413b773 100644
--- a/aom_dsp/blend_a64_vmask.c
+++ b/aom_dsp/blend_a64_vmask.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/aom_dsp/blk_sse_sum.c b/aom_dsp/blk_sse_sum.c
index d76c3f8..8da5559 100644
--- a/aom_dsp/blk_sse_sum.c
+++ b/aom_dsp/blk_sse_sum.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2019, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "config/aom_dsp_rtcd.h"
diff --git a/aom_dsp/entcode.c b/aom_dsp/entcode.c
index aad96c6..c794edb 100644
--- a/aom_dsp/entcode.c
+++ b/aom_dsp/entcode.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2001-2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "aom_dsp/entcode.h"
diff --git a/aom_dsp/entcode.h b/aom_dsp/entcode.h
index 7518879..bd29d58 100644
--- a/aom_dsp/entcode.h
+++ b/aom_dsp/entcode.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2001-2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_ENTCODE_H_
diff --git a/aom_dsp/entdec.c b/aom_dsp/entdec.c
index da43e8a..aaae871 100644
--- a/aom_dsp/entdec.c
+++ b/aom_dsp/entdec.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2001-2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/aom_dsp/entdec.h b/aom_dsp/entdec.h
index c746167..bd4f4a3 100644
--- a/aom_dsp/entdec.h
+++ b/aom_dsp/entdec.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2001-2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_ENTDEC_H_
diff --git a/aom_dsp/entenc.c b/aom_dsp/entenc.c
index 2fd4493..7c0e8fb 100644
--- a/aom_dsp/entenc.c
+++ b/aom_dsp/entenc.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2001-2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <stdlib.h>
diff --git a/aom_dsp/entenc.h b/aom_dsp/entenc.h
index 3551d42..d342e4a 100644
--- a/aom_dsp/entenc.h
+++ b/aom_dsp/entenc.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2001-2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_ENTENC_H_
diff --git a/aom_dsp/fastssim.c b/aom_dsp/fastssim.c
index 3804519..37e4849 100644
--- a/aom_dsp/fastssim.c
+++ b/aom_dsp/fastssim.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  *
  *  This code was originally written by: Nathan E. Egge, at the Daala
  *  project.
diff --git a/aom_dsp/fft.c b/aom_dsp/fft.c
index 0ba71cf..407067b 100644
--- a/aom_dsp/fft.c
+++ b/aom_dsp/fft.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "aom_dsp/aom_dsp_common.h"
diff --git a/aom_dsp/fft_common.h b/aom_dsp/fft_common.h
index 5137331..e620de1 100644
--- a/aom_dsp/fft_common.h
+++ b/aom_dsp/fft_common.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_FFT_COMMON_H_
diff --git a/aom_dsp/fwd_txfm.c b/aom_dsp/fwd_txfm.c
index 359e9ac..a592f6e 100644
--- a/aom_dsp/fwd_txfm.c
+++ b/aom_dsp/fwd_txfm.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/aom_dsp/grain_synthesis.c b/aom_dsp/grain_synthesis.c
index 626eb76..c035441 100644
--- a/aom_dsp/grain_synthesis.c
+++ b/aom_dsp/grain_synthesis.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 /*!\file
diff --git a/aom_dsp/grain_synthesis.h b/aom_dsp/grain_synthesis.h
index 9155b39..0e07571 100644
--- a/aom_dsp/grain_synthesis.h
+++ b/aom_dsp/grain_synthesis.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 /*!\file
diff --git a/aom_dsp/grain_table.c b/aom_dsp/grain_table.c
index e03f04d..7614d32 100644
--- a/aom_dsp/grain_table.c
+++ b/aom_dsp/grain_table.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 /*!\file
diff --git a/aom_dsp/grain_table.h b/aom_dsp/grain_table.h
index a8ac507..37f527e 100644
--- a/aom_dsp/grain_table.h
+++ b/aom_dsp/grain_table.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 /*!\file
diff --git a/aom_dsp/intrapred.c b/aom_dsp/intrapred.c
index 72ccfd8..c9e545f 100644
--- a/aom_dsp/intrapred.c
+++ b/aom_dsp/intrapred.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
@@ -52,9 +53,9 @@
   const int p_top_left = abs_diff(base, top_left);
 
   // Return nearest to base of left, top and top_left.
-  return (p_left <= p_top && p_left <= p_top_left)
-             ? left
-             : (p_top <= p_top_left) ? top : top_left;
+  return (p_left <= p_top && p_left <= p_top_left) ? left
+         : (p_top <= p_top_left)                   ? top
+                                                   : top_left;
 }
 
 static INLINE void paeth_predictor(uint8_t *dst, ptrdiff_t stride, int bw,
@@ -562,7 +563,163 @@
     dst += stride;
   }
 }
+#if CONFIG_IBP_DC
+const uint8_t ibp_weights[5][16] = {
+  { 192, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+  { 171, 213, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+  { 154, 179, 205, 230, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+  { 142, 156, 171, 185, 199, 213, 228, 242, 0, 0, 0, 0, 0, 0, 0, 0 },
+  { 136, 143, 151, 158, 166, 173, 181, 188, 196, 203, 211, 218, 226, 233, 241,
+    248 }
+};
+const uint8_t size_to_weights_index[9] = { 0, 1, 2, 0, 3, 0, 0, 0, 4 };
+static INLINE void highbd_ibp_dc_left_predictor(uint16_t *dst, ptrdiff_t stride,
+                                                int bw, int bh,
+                                                const uint16_t *above,
+                                                const uint16_t *left, int bd) {
+  int r, c;
+  (void)above;
+  (void)bd;
 
+  int len = bw >> 2;
+  const uint8_t weights_index = size_to_weights_index[bw >> 3];
+  const uint8_t *weights = ibp_weights[weights_index];
+  for (r = 0; r < bh; r++) {
+    for (c = 0; c < len; c++) {
+      int val = ROUND_POWER_OF_TWO(
+          left[r] * (256 - weights[c]) + dst[c] * weights[c], IBP_WEIGHT_SHIFT);
+      dst[c] = val;
+    }
+    dst += stride;
+  }
+}
+
+static INLINE void highbd_ibp_dc_top_predictor(uint16_t *dst, ptrdiff_t stride,
+                                               int bw, int bh,
+                                               const uint16_t *above,
+                                               const uint16_t *left, int bd) {
+  int r, c;
+  (void)left;
+  (void)bd;
+
+  int len = bh >> 2;
+  const uint8_t weights_index = size_to_weights_index[bh >> 3];
+  const uint8_t *weights = ibp_weights[weights_index];
+  for (r = 0; r < len; r++) {
+    for (c = 0; c < bw; c++) {
+      int val = ROUND_POWER_OF_TWO(
+          above[c] * (256 - weights[r]) + dst[c] * weights[r],
+          IBP_WEIGHT_SHIFT);
+      dst[c] = val;
+    }
+    dst += stride;
+  }
+}
+
+static INLINE void highbd_ibp_dc_predictor(uint16_t *dst, ptrdiff_t stride,
+                                           int bw, int bh,
+                                           const uint16_t *above,
+                                           const uint16_t *left, int bd) {
+  int r, c;
+  (void)bd;
+
+  uint16_t *orig_dst = dst;
+  int len_h = bh >> 2;
+  int len_w = bw >> 2;
+  uint8_t weights_index = size_to_weights_index[bh >> 3];
+  const uint8_t *weights = ibp_weights[weights_index];
+  for (r = 0; r < len_h; r++) {
+    for (c = 0; c < bw; c++) {
+      int val = ROUND_POWER_OF_TWO(
+          above[c] * (256 - weights[r]) + dst[c] * weights[r],
+          IBP_WEIGHT_SHIFT);
+      dst[c] = val;
+    }
+    dst += stride;
+  }
+  dst = orig_dst;
+  weights_index = size_to_weights_index[bw >> 3];
+  weights = ibp_weights[weights_index];
+  for (r = 0; r < bh; r++) {
+    for (c = 0; c < len_w; c++) {
+      int val = ROUND_POWER_OF_TWO(
+          left[r] * (256 - weights[c]) + dst[c] * weights[c], IBP_WEIGHT_SHIFT);
+      dst[c] = val;
+    }
+    dst += stride;
+  }
+}
+
+static INLINE void ibp_dc_left_predictor(uint8_t *dst, ptrdiff_t stride, int bw,
+                                         int bh, const uint8_t *above,
+                                         const uint8_t *left) {
+  int r, c;
+  (void)above;
+
+  const uint8_t weights_index = size_to_weights_index[bw >> 3];
+  const uint8_t *weights = ibp_weights[weights_index];
+  int len = bw >> 2;
+  for (r = 0; r < bh; r++) {
+    for (c = 0; c < len; c++) {
+      int val = ROUND_POWER_OF_TWO(
+          left[r] * (256 - weights[c]) + dst[c] * weights[c], IBP_WEIGHT_SHIFT);
+      dst[c] = val;
+    }
+    dst += stride;
+  }
+}
+
+static INLINE void ibp_dc_top_predictor(uint8_t *dst, ptrdiff_t stride, int bw,
+                                        int bh, const uint8_t *above,
+                                        const uint8_t *left) {
+  int r, c;
+  (void)left;
+
+  const uint8_t weights_index = size_to_weights_index[bh >> 3];
+  const uint8_t *weights = ibp_weights[weights_index];
+  int len = bh >> 2;
+  for (r = 0; r < len; r++) {
+    for (c = 0; c < bw; c++) {
+      int val = ROUND_POWER_OF_TWO(
+          above[c] * (256 - weights[r]) + dst[c] * weights[r],
+          IBP_WEIGHT_SHIFT);
+      dst[c] = val;
+    }
+    dst += stride;
+  }
+}
+
+static INLINE void ibp_dc_predictor(uint8_t *dst, ptrdiff_t stride, int bw,
+                                    int bh, const uint8_t *above,
+                                    const uint8_t *left) {
+  int r, c;
+  uint8_t *orig_dst = dst;
+  uint8_t weights_index = size_to_weights_index[bh >> 3];
+  const uint8_t *weights = ibp_weights[weights_index];
+  int len_w = bw >> 2;
+  int len_h = bh >> 2;
+  for (r = 0; r < len_h; r++) {
+    for (c = 0; c < bw; c++) {
+      int val = ROUND_POWER_OF_TWO(
+          above[c] * (256 - weights[r]) + dst[c] * weights[r],
+          IBP_WEIGHT_SHIFT);
+      dst[c] = val;
+    }
+    dst += stride;
+  }
+  dst = orig_dst;
+  weights_index = size_to_weights_index[bw >> 3];
+  weights = ibp_weights[weights_index];
+  for (r = 0; r < bh; r++) {
+    for (c = 0; c < len_w; c++) {
+      int val = ROUND_POWER_OF_TWO(
+          left[r] * (256 - weights[c]) + dst[c] * weights[c], IBP_WEIGHT_SHIFT);
+      dst[c] = val;
+    }
+    dst += stride;
+  }
+}
+#endif
 // Obtained similarly as DC_MULTIPLIER_1X2 and DC_MULTIPLIER_1X4 above, but
 // assume 2nd shift of 17 bits instead of 16.
 // Note: Strictly speaking, 2nd shift needs to be 17 only when:
@@ -788,5 +945,11 @@
 intra_pred_allsizes(dc_left)
 intra_pred_allsizes(dc_top)
 intra_pred_square(dc)
+#if CONFIG_IBP_DC
+intra_pred_allsizes(ibp_dc_left)
+intra_pred_allsizes(ibp_dc_top)
+intra_pred_allsizes(ibp_dc)
+#endif
+
 /* clang-format on */
 #undef intra_pred_allsizes
diff --git a/aom_dsp/intrapred_common.h b/aom_dsp/intrapred_common.h
index 3ec62a8..d8bbef4 100644
--- a/aom_dsp/intrapred_common.h
+++ b/aom_dsp/intrapred_common.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_INTRAPRED_COMMON_H_
diff --git a/aom_dsp/loopfilter.c b/aom_dsp/loopfilter.c
index 9647e18..ee9a5cb 100644
--- a/aom_dsp/loopfilter.c
+++ b/aom_dsp/loopfilter.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <stdlib.h>
diff --git a/aom_dsp/mips/aom_convolve8_horiz_msa.c b/aom_dsp/mips/aom_convolve8_horiz_msa.c
index c8ab612..e06eed4 100644
--- a/aom_dsp/mips/aom_convolve8_horiz_msa.c
+++ b/aom_dsp/mips/aom_convolve8_horiz_msa.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/aom_dsp/mips/aom_convolve8_vert_msa.c b/aom_dsp/mips/aom_convolve8_vert_msa.c
index 2c3bc08..e49fea7 100644
--- a/aom_dsp/mips/aom_convolve8_vert_msa.c
+++ b/aom_dsp/mips/aom_convolve8_vert_msa.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/aom_dsp/mips/aom_convolve_copy_dspr2.c b/aom_dsp/mips/aom_convolve_copy_dspr2.c
index 12a213e..3f0d2d8 100644
--- a/aom_dsp/mips/aom_convolve_copy_dspr2.c
+++ b/aom_dsp/mips/aom_convolve_copy_dspr2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/aom_dsp/mips/aom_convolve_copy_msa.c b/aom_dsp/mips/aom_convolve_copy_msa.c
index 12e7d95..a92696c 100644
--- a/aom_dsp/mips/aom_convolve_copy_msa.c
+++ b/aom_dsp/mips/aom_convolve_copy_msa.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <string.h>
diff --git a/aom_dsp/mips/aom_convolve_msa.h b/aom_dsp/mips/aom_convolve_msa.h
index 852415c..39e183c 100644
--- a/aom_dsp/mips/aom_convolve_msa.h
+++ b/aom_dsp/mips/aom_convolve_msa.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_MIPS_AOM_CONVOLVE_MSA_H_
diff --git a/aom_dsp/mips/common_dspr2.c b/aom_dsp/mips/common_dspr2.c
index 00ab75d..5196319 100644
--- a/aom_dsp/mips/common_dspr2.c
+++ b/aom_dsp/mips/common_dspr2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "aom_dsp/mips/common_dspr2.h"
diff --git a/aom_dsp/mips/common_dspr2.h b/aom_dsp/mips/common_dspr2.h
index c42188d..8f94fa7 100644
--- a/aom_dsp/mips/common_dspr2.h
+++ b/aom_dsp/mips/common_dspr2.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_MIPS_COMMON_DSPR2_H_
diff --git a/aom_dsp/mips/convolve2_dspr2.c b/aom_dsp/mips/convolve2_dspr2.c
index 08bf1ab..b037333 100644
--- a/aom_dsp/mips/convolve2_dspr2.c
+++ b/aom_dsp/mips/convolve2_dspr2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/aom_dsp/mips/convolve2_horiz_dspr2.c b/aom_dsp/mips/convolve2_horiz_dspr2.c
index 097da73..c448470 100644
--- a/aom_dsp/mips/convolve2_horiz_dspr2.c
+++ b/aom_dsp/mips/convolve2_horiz_dspr2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/aom_dsp/mips/convolve2_vert_dspr2.c b/aom_dsp/mips/convolve2_vert_dspr2.c
index 40abfd8..2f7b162 100644
--- a/aom_dsp/mips/convolve2_vert_dspr2.c
+++ b/aom_dsp/mips/convolve2_vert_dspr2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/aom_dsp/mips/convolve8_horiz_dspr2.c b/aom_dsp/mips/convolve8_horiz_dspr2.c
index f9c6879..73d05e4 100644
--- a/aom_dsp/mips/convolve8_horiz_dspr2.c
+++ b/aom_dsp/mips/convolve8_horiz_dspr2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/aom_dsp/mips/convolve8_vert_dspr2.c b/aom_dsp/mips/convolve8_vert_dspr2.c
index 201e664..7f1a150 100644
--- a/aom_dsp/mips/convolve8_vert_dspr2.c
+++ b/aom_dsp/mips/convolve8_vert_dspr2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/aom_dsp/mips/convolve_common_dspr2.h b/aom_dsp/mips/convolve_common_dspr2.h
index e5d48a8..431ea8c 100644
--- a/aom_dsp/mips/convolve_common_dspr2.h
+++ b/aom_dsp/mips/convolve_common_dspr2.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_MIPS_CONVOLVE_COMMON_DSPR2_H_
diff --git a/aom_dsp/mips/intrapred16_dspr2.c b/aom_dsp/mips/intrapred16_dspr2.c
index 7c221ae..632752d 100644
--- a/aom_dsp/mips/intrapred16_dspr2.c
+++ b/aom_dsp/mips/intrapred16_dspr2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "aom_dsp/mips/common_dspr2.h"
diff --git a/aom_dsp/mips/intrapred4_dspr2.c b/aom_dsp/mips/intrapred4_dspr2.c
index 0a21979..4cb5c04 100644
--- a/aom_dsp/mips/intrapred4_dspr2.c
+++ b/aom_dsp/mips/intrapred4_dspr2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "aom_dsp/mips/common_dspr2.h"
diff --git a/aom_dsp/mips/intrapred8_dspr2.c b/aom_dsp/mips/intrapred8_dspr2.c
index d42a77c..41cb92c 100644
--- a/aom_dsp/mips/intrapred8_dspr2.c
+++ b/aom_dsp/mips/intrapred8_dspr2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "aom_dsp/mips/common_dspr2.h"
diff --git a/aom_dsp/mips/intrapred_msa.c b/aom_dsp/mips/intrapred_msa.c
index 9f25cc1..262a531 100644
--- a/aom_dsp/mips/intrapred_msa.c
+++ b/aom_dsp/mips/intrapred_msa.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "config/aom_dsp_rtcd.h"
diff --git a/aom_dsp/mips/loopfilter_16_msa.c b/aom_dsp/mips/loopfilter_16_msa.c
index 38a10e9..e11e110 100644
--- a/aom_dsp/mips/loopfilter_16_msa.c
+++ b/aom_dsp/mips/loopfilter_16_msa.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "aom_ports/mem.h"
diff --git a/aom_dsp/mips/loopfilter_4_msa.c b/aom_dsp/mips/loopfilter_4_msa.c
index dc0a977..f8da0fd 100644
--- a/aom_dsp/mips/loopfilter_4_msa.c
+++ b/aom_dsp/mips/loopfilter_4_msa.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "aom_dsp/mips/loopfilter_msa.h"
diff --git a/aom_dsp/mips/loopfilter_8_msa.c b/aom_dsp/mips/loopfilter_8_msa.c
index dc203e7..73c66e8 100644
--- a/aom_dsp/mips/loopfilter_8_msa.c
+++ b/aom_dsp/mips/loopfilter_8_msa.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "aom_dsp/mips/loopfilter_msa.h"
diff --git a/aom_dsp/mips/loopfilter_filters_dspr2.c b/aom_dsp/mips/loopfilter_filters_dspr2.c
index 8c41278..1d5f5c4 100644
--- a/aom_dsp/mips/loopfilter_filters_dspr2.c
+++ b/aom_dsp/mips/loopfilter_filters_dspr2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <stdlib.h>
diff --git a/aom_dsp/mips/loopfilter_filters_dspr2.h b/aom_dsp/mips/loopfilter_filters_dspr2.h
index 28f0dc3..0346007 100644
--- a/aom_dsp/mips/loopfilter_filters_dspr2.h
+++ b/aom_dsp/mips/loopfilter_filters_dspr2.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_MIPS_LOOPFILTER_FILTERS_DSPR2_H_
diff --git a/aom_dsp/mips/loopfilter_macros_dspr2.h b/aom_dsp/mips/loopfilter_macros_dspr2.h
index 62295d6..647c091 100644
--- a/aom_dsp/mips/loopfilter_macros_dspr2.h
+++ b/aom_dsp/mips/loopfilter_macros_dspr2.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_MIPS_LOOPFILTER_MACROS_DSPR2_H_
diff --git a/aom_dsp/mips/loopfilter_masks_dspr2.h b/aom_dsp/mips/loopfilter_masks_dspr2.h
index a0f57f3..e774dc1 100644
--- a/aom_dsp/mips/loopfilter_masks_dspr2.h
+++ b/aom_dsp/mips/loopfilter_masks_dspr2.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_MIPS_LOOPFILTER_MASKS_DSPR2_H_
diff --git a/aom_dsp/mips/loopfilter_mb_dspr2.c b/aom_dsp/mips/loopfilter_mb_dspr2.c
index b67ccfe..b99baf3 100644
--- a/aom_dsp/mips/loopfilter_mb_dspr2.c
+++ b/aom_dsp/mips/loopfilter_mb_dspr2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <stdlib.h>
diff --git a/aom_dsp/mips/loopfilter_mb_horiz_dspr2.c b/aom_dsp/mips/loopfilter_mb_horiz_dspr2.c
index 34733e4..8024ef7 100644
--- a/aom_dsp/mips/loopfilter_mb_horiz_dspr2.c
+++ b/aom_dsp/mips/loopfilter_mb_horiz_dspr2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <stdlib.h>
diff --git a/aom_dsp/mips/loopfilter_mb_vert_dspr2.c b/aom_dsp/mips/loopfilter_mb_vert_dspr2.c
index 3d3f1ec..aa40d38 100644
--- a/aom_dsp/mips/loopfilter_mb_vert_dspr2.c
+++ b/aom_dsp/mips/loopfilter_mb_vert_dspr2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <stdlib.h>
diff --git a/aom_dsp/mips/loopfilter_msa.h b/aom_dsp/mips/loopfilter_msa.h
index 54b0bb4..7c08526 100644
--- a/aom_dsp/mips/loopfilter_msa.h
+++ b/aom_dsp/mips/loopfilter_msa.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_MIPS_LOOPFILTER_MSA_H_
diff --git a/aom_dsp/mips/macros_msa.h b/aom_dsp/mips/macros_msa.h
index 9bfc271..d3c317c 100644
--- a/aom_dsp/mips/macros_msa.h
+++ b/aom_dsp/mips/macros_msa.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_MIPS_MACROS_MSA_H_
diff --git a/aom_dsp/mips/sad_msa.c b/aom_dsp/mips/sad_msa.c
index 58cdd80..b305d16 100644
--- a/aom_dsp/mips/sad_msa.c
+++ b/aom_dsp/mips/sad_msa.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "config/aom_dsp_rtcd.h"
diff --git a/aom_dsp/mips/sub_pixel_variance_msa.c b/aom_dsp/mips/sub_pixel_variance_msa.c
index 810b6ef..9713cb4 100644
--- a/aom_dsp/mips/sub_pixel_variance_msa.c
+++ b/aom_dsp/mips/sub_pixel_variance_msa.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "config/aom_dsp_rtcd.h"
diff --git a/aom_dsp/mips/subtract_msa.c b/aom_dsp/mips/subtract_msa.c
index bfed773..7871e7a 100644
--- a/aom_dsp/mips/subtract_msa.c
+++ b/aom_dsp/mips/subtract_msa.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "config/aom_dsp_rtcd.h"
diff --git a/aom_dsp/mips/variance_msa.c b/aom_dsp/mips/variance_msa.c
index 065c09a..5efbbef 100644
--- a/aom_dsp/mips/variance_msa.c
+++ b/aom_dsp/mips/variance_msa.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "config/aom_dsp_rtcd.h"
diff --git a/aom_dsp/noise_model.c b/aom_dsp/noise_model.c
index c7a0003..cc47019 100644
--- a/aom_dsp/noise_model.c
+++ b/aom_dsp/noise_model.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <math.h>
diff --git a/aom_dsp/noise_model.h b/aom_dsp/noise_model.h
index 5e7de9b..fcf9cb9 100644
--- a/aom_dsp/noise_model.h
+++ b/aom_dsp/noise_model.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_NOISE_MODEL_H_
diff --git a/aom_dsp/noise_util.c b/aom_dsp/noise_util.c
index 7e7e380..ab17893 100644
--- a/aom_dsp/noise_util.c
+++ b/aom_dsp/noise_util.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <math.h>
diff --git a/aom_dsp/noise_util.h b/aom_dsp/noise_util.h
index 2284a17..20a0970 100644
--- a/aom_dsp/noise_util.h
+++ b/aom_dsp/noise_util.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_NOISE_UTIL_H_
diff --git a/aom_dsp/prob.h b/aom_dsp/prob.h
index ea5e4cb..724fb22 100644
--- a/aom_dsp/prob.h
+++ b/aom_dsp/prob.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_PROB_H_
diff --git a/aom_dsp/psnr.c b/aom_dsp/psnr.c
index 2379e5c..04d4bd4 100644
--- a/aom_dsp/psnr.c
+++ b/aom_dsp/psnr.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/aom_dsp/psnr.h b/aom_dsp/psnr.h
index 16a2fef..b3e0ec3 100644
--- a/aom_dsp/psnr.h
+++ b/aom_dsp/psnr.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_PSNR_H_
diff --git a/aom_dsp/psnrhvs.c b/aom_dsp/psnrhvs.c
index 69a1d99..421a6dc 100644
--- a/aom_dsp/psnrhvs.c
+++ b/aom_dsp/psnrhvs.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  *
  *  This code was originally written by: Gregory Maxwell, at the Daala
  *  project.
diff --git a/aom_dsp/quantize.c b/aom_dsp/quantize.c
index 1806b11..5b0086c 100644
--- a/aom_dsp/quantize.c
+++ b/aom_dsp/quantize.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "aom_dsp/quantize.h"
diff --git a/aom_dsp/quantize.h b/aom_dsp/quantize.h
index 089155a..3ef43c9 100644
--- a/aom_dsp/quantize.h
+++ b/aom_dsp/quantize.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_QUANTIZE_H_
diff --git a/aom_dsp/recenter.h b/aom_dsp/recenter.h
index b3fd412..14c9d0f 100644
--- a/aom_dsp/recenter.h
+++ b/aom_dsp/recenter.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_RECENTER_H_
diff --git a/aom_dsp/sad.c b/aom_dsp/sad.c
index ed2d7dc..46f92b6 100644
--- a/aom_dsp/sad.c
+++ b/aom_dsp/sad.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <stdlib.h>
diff --git a/aom_dsp/sad_av1.c b/aom_dsp/sad_av1.c
index f6426a6..808d9b3 100644
--- a/aom_dsp/sad_av1.c
+++ b/aom_dsp/sad_av1.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <stdlib.h>
diff --git a/aom_dsp/simd/v128_intrinsics.h b/aom_dsp/simd/v128_intrinsics.h
index 218a7a6..ffa2b60 100644
--- a/aom_dsp/simd/v128_intrinsics.h
+++ b/aom_dsp/simd/v128_intrinsics.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_SIMD_V128_INTRINSICS_H_
diff --git a/aom_dsp/simd/v128_intrinsics_arm.h b/aom_dsp/simd/v128_intrinsics_arm.h
index 2d497f4..6a6b8ca 100644
--- a/aom_dsp/simd/v128_intrinsics_arm.h
+++ b/aom_dsp/simd/v128_intrinsics_arm.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_SIMD_V128_INTRINSICS_ARM_H_
diff --git a/aom_dsp/simd/v128_intrinsics_c.h b/aom_dsp/simd/v128_intrinsics_c.h
index 466a41e..13e626f 100644
--- a/aom_dsp/simd/v128_intrinsics_c.h
+++ b/aom_dsp/simd/v128_intrinsics_c.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_SIMD_V128_INTRINSICS_C_H_
diff --git a/aom_dsp/simd/v128_intrinsics_x86.h b/aom_dsp/simd/v128_intrinsics_x86.h
index c404015..8c07c02 100644
--- a/aom_dsp/simd/v128_intrinsics_x86.h
+++ b/aom_dsp/simd/v128_intrinsics_x86.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_SIMD_V128_INTRINSICS_X86_H_
diff --git a/aom_dsp/simd/v256_intrinsics.h b/aom_dsp/simd/v256_intrinsics.h
index 17e36ee..538282d 100644
--- a/aom_dsp/simd/v256_intrinsics.h
+++ b/aom_dsp/simd/v256_intrinsics.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_SIMD_V256_INTRINSICS_H_
diff --git a/aom_dsp/simd/v256_intrinsics_arm.h b/aom_dsp/simd/v256_intrinsics_arm.h
index bd86ea1..a3f8e66 100644
--- a/aom_dsp/simd/v256_intrinsics_arm.h
+++ b/aom_dsp/simd/v256_intrinsics_arm.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_SIMD_V256_INTRINSICS_ARM_H_
diff --git a/aom_dsp/simd/v256_intrinsics_c.h b/aom_dsp/simd/v256_intrinsics_c.h
index 8127ee3..b17f092 100644
--- a/aom_dsp/simd/v256_intrinsics_c.h
+++ b/aom_dsp/simd/v256_intrinsics_c.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_SIMD_V256_INTRINSICS_C_H_
diff --git a/aom_dsp/simd/v256_intrinsics_v128.h b/aom_dsp/simd/v256_intrinsics_v128.h
index 0d22667..e2989dc 100644
--- a/aom_dsp/simd/v256_intrinsics_v128.h
+++ b/aom_dsp/simd/v256_intrinsics_v128.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_SIMD_V256_INTRINSICS_V128_H_
diff --git a/aom_dsp/simd/v256_intrinsics_x86.h b/aom_dsp/simd/v256_intrinsics_x86.h
index 5983cb8..d64d015 100644
--- a/aom_dsp/simd/v256_intrinsics_x86.h
+++ b/aom_dsp/simd/v256_intrinsics_x86.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_SIMD_V256_INTRINSICS_X86_H_
diff --git a/aom_dsp/simd/v64_intrinsics.h b/aom_dsp/simd/v64_intrinsics.h
index 7079949..3296fbe 100644
--- a/aom_dsp/simd/v64_intrinsics.h
+++ b/aom_dsp/simd/v64_intrinsics.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_SIMD_V64_INTRINSICS_H_
diff --git a/aom_dsp/simd/v64_intrinsics_arm.h b/aom_dsp/simd/v64_intrinsics_arm.h
index a4ecdf4..53b815a 100644
--- a/aom_dsp/simd/v64_intrinsics_arm.h
+++ b/aom_dsp/simd/v64_intrinsics_arm.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_SIMD_V64_INTRINSICS_ARM_H_
diff --git a/aom_dsp/simd/v64_intrinsics_c.h b/aom_dsp/simd/v64_intrinsics_c.h
index b84f243..b04e05a 100644
--- a/aom_dsp/simd/v64_intrinsics_c.h
+++ b/aom_dsp/simd/v64_intrinsics_c.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_SIMD_V64_INTRINSICS_C_H_
@@ -186,11 +187,10 @@
   c_v64 t;
   int c;
   for (c = 0; c < 8; c++)
-    t.u8[c] = (int16_t)a.u8[c] + (int16_t)b.u8[c] > 255
-                  ? 255
-                  : (int16_t)a.u8[c] + (int16_t)b.u8[c] < 0
-                        ? 0
-                        : (int16_t)a.u8[c] + (int16_t)b.u8[c];
+    t.u8[c] = (int16_t)a.u8[c] + (int16_t)b.u8[c] > 255 ? 255
+              : (int16_t)a.u8[c] + (int16_t)b.u8[c] < 0
+                  ? 0
+                  : (int16_t)a.u8[c] + (int16_t)b.u8[c];
   return t;
 }
 
@@ -198,11 +198,10 @@
   c_v64 t;
   int c;
   for (c = 0; c < 8; c++)
-    t.s8[c] = (int16_t)a.s8[c] + (int16_t)b.s8[c] > 127
-                  ? 127
-                  : (int16_t)a.s8[c] + (int16_t)b.s8[c] < -128
-                        ? -128
-                        : (int16_t)a.s8[c] + (int16_t)b.s8[c];
+    t.s8[c] = (int16_t)a.s8[c] + (int16_t)b.s8[c] > 127 ? 127
+              : (int16_t)a.s8[c] + (int16_t)b.s8[c] < -128
+                  ? -128
+                  : (int16_t)a.s8[c] + (int16_t)b.s8[c];
   return t;
 }
 
@@ -210,11 +209,10 @@
   c_v64 t;
   int c;
   for (c = 0; c < 4; c++)
-    t.s16[c] = (int32_t)a.s16[c] + (int32_t)b.s16[c] > 32767
-                   ? 32767
-                   : (int32_t)a.s16[c] + (int32_t)b.s16[c] < -32768
-                         ? -32768
-                         : (int32_t)a.s16[c] + (int32_t)b.s16[c];
+    t.s16[c] = (int32_t)a.s16[c] + (int32_t)b.s16[c] > 32767 ? 32767
+               : (int32_t)a.s16[c] + (int32_t)b.s16[c] < -32768
+                   ? -32768
+                   : (int32_t)a.s16[c] + (int32_t)b.s16[c];
   return t;
 }
 
@@ -260,11 +258,10 @@
   c_v64 t;
   int c;
   for (c = 0; c < 4; c++)
-    t.s16[c] = (int32_t)a.s16[c] - (int32_t)b.s16[c] < -32768
-                   ? -32768
-                   : (int32_t)a.s16[c] - (int32_t)b.s16[c] > 32767
-                         ? 32767
-                         : (int32_t)a.s16[c] - (int32_t)b.s16[c];
+    t.s16[c] = (int32_t)a.s16[c] - (int32_t)b.s16[c] < -32768 ? -32768
+               : (int32_t)a.s16[c] - (int32_t)b.s16[c] > 32767
+                   ? 32767
+                   : (int32_t)a.s16[c] - (int32_t)b.s16[c];
   return t;
 }
 
diff --git a/aom_dsp/simd/v64_intrinsics_x86.h b/aom_dsp/simd/v64_intrinsics_x86.h
index 1f273fe..ce9a642 100644
--- a/aom_dsp/simd/v64_intrinsics_x86.h
+++ b/aom_dsp/simd/v64_intrinsics_x86.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_SIMD_V64_INTRINSICS_X86_H_
@@ -182,10 +183,18 @@
   int32_t al = v64_low_u32(a);
   int32_t bh = v64_high_u32(b);
   int32_t bl = v64_low_u32(b);
-  return v64_from_16(ah > 65535 ? 65535 : ah < 0 ? 0 : ah,
-                     al > 65535 ? 65535 : al < 0 ? 0 : al,
-                     bh > 65535 ? 65535 : bh < 0 ? 0 : bh,
-                     bl > 65535 ? 65535 : bl < 0 ? 0 : bl);
+  return v64_from_16(ah > 65535 ? 65535
+                     : ah < 0   ? 0
+                                : ah,
+                     al > 65535 ? 65535
+                     : al < 0   ? 0
+                                : al,
+                     bh > 65535 ? 65535
+                     : bh < 0   ? 0
+                                : bh,
+                     bl > 65535 ? 65535
+                     : bl < 0   ? 0
+                                : bl);
 #endif
 }
 
diff --git a/aom_dsp/sse.c b/aom_dsp/sse.c
index 2493948..c71ebe6 100644
--- a/aom_dsp/sse.c
+++ b/aom_dsp/sse.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 /* Sum the difference between every corresponding element of the buffers. */
diff --git a/aom_dsp/ssim.c b/aom_dsp/ssim.c
index f1deff2..5510ea3 100644
--- a/aom_dsp/ssim.c
+++ b/aom_dsp/ssim.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/aom_dsp/ssim.h b/aom_dsp/ssim.h
index 55038f4..627ef6a 100644
--- a/aom_dsp/ssim.h
+++ b/aom_dsp/ssim.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_SSIM_H_
diff --git a/aom_dsp/subtract.c b/aom_dsp/subtract.c
index 2f6da96..1f66d5a 100644
--- a/aom_dsp/subtract.c
+++ b/aom_dsp/subtract.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <stdlib.h>
diff --git a/aom_dsp/sum_squares.c b/aom_dsp/sum_squares.c
index f58defa..8662b3d 100644
--- a/aom_dsp/sum_squares.c
+++ b/aom_dsp/sum_squares.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/aom_dsp/txfm_common.h b/aom_dsp/txfm_common.h
index c777da3..92381ab 100644
--- a/aom_dsp/txfm_common.h
+++ b/aom_dsp/txfm_common.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_TXFM_COMMON_H_
diff --git a/aom_dsp/variance.c b/aom_dsp/variance.c
index f75c540..0d54c40 100644
--- a/aom_dsp/variance.c
+++ b/aom_dsp/variance.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #include <assert.h>
 #include <stdlib.h>
diff --git a/aom_dsp/variance.h b/aom_dsp/variance.h
index 428afd0..3f577fa 100644
--- a/aom_dsp/variance.h
+++ b/aom_dsp/variance.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_VARIANCE_H_
diff --git a/aom_dsp/vmaf.c b/aom_dsp/vmaf.c
index 531baf5..83acc60 100644
--- a/aom_dsp/vmaf.c
+++ b/aom_dsp/vmaf.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2019, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "aom_dsp/vmaf.h"
diff --git a/aom_dsp/vmaf.h b/aom_dsp/vmaf.h
index d9da223..9e95ae6 100644
--- a/aom_dsp/vmaf.h
+++ b/aom_dsp/vmaf.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2019, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_VMAF_H_
diff --git a/aom_dsp/x86/adaptive_quantize_avx2.c b/aom_dsp/x86/adaptive_quantize_avx2.c
index 7277ec6..f3d11b0 100644
--- a/aom_dsp/x86/adaptive_quantize_avx2.c
+++ b/aom_dsp/x86/adaptive_quantize_avx2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2019, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <immintrin.h>
diff --git a/aom_dsp/x86/adaptive_quantize_sse2.c b/aom_dsp/x86/adaptive_quantize_sse2.c
index aede0d2..8308f5b 100644
--- a/aom_dsp/x86/adaptive_quantize_sse2.c
+++ b/aom_dsp/x86/adaptive_quantize_sse2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2019, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/aom_dsp/x86/aom_asm_stubs.c b/aom_dsp/x86/aom_asm_stubs.c
index db22c24..f0c8653 100644
--- a/aom_dsp/x86/aom_asm_stubs.c
+++ b/aom_dsp/x86/aom_asm_stubs.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "config/aom_config.h"
diff --git a/aom_dsp/x86/aom_high_subpixel_8t_sse2.asm b/aom_dsp/x86/aom_high_subpixel_8t_sse2.asm
index d392225..5fc4770 100644
--- a/aom_dsp/x86/aom_high_subpixel_8t_sse2.asm
+++ b/aom_dsp/x86/aom_high_subpixel_8t_sse2.asm
@@ -1,12 +1,12 @@
 ;
-; Copyright (c) 2016, Alliance for Open Media. All rights reserved
+; Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ;
-; This source code is subject to the terms of the BSD 2 Clause License and
-; the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-; was not distributed with this source code in the LICENSE file, you can
-; obtain it at www.aomedia.org/license/software. If the Alliance for Open
-; Media Patent License 1.0 was not distributed with this source code in the
-; PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+; This source code is subject to the terms of the BSD 3-Clause Clear License and the
+; Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+; not distributed with this source code in the LICENSE file, you can obtain it
+; at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+; License 1.0 was not distributed with this source code in the PATENTS file, you
+; can obtain it at aomedia.org/license/patent-license/.
 ;
 
 ;
diff --git a/aom_dsp/x86/aom_high_subpixel_bilinear_sse2.asm b/aom_dsp/x86/aom_high_subpixel_bilinear_sse2.asm
index db4cad9..7a60fa3 100644
--- a/aom_dsp/x86/aom_high_subpixel_bilinear_sse2.asm
+++ b/aom_dsp/x86/aom_high_subpixel_bilinear_sse2.asm
@@ -1,12 +1,12 @@
 ;
-; Copyright (c) 2016, Alliance for Open Media. All rights reserved
+; Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ;
-; This source code is subject to the terms of the BSD 2 Clause License and
-; the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-; was not distributed with this source code in the LICENSE file, you can
-; obtain it at www.aomedia.org/license/software. If the Alliance for Open
-; Media Patent License 1.0 was not distributed with this source code in the
-; PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+; This source code is subject to the terms of the BSD 3-Clause Clear License and the
+; Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+; not distributed with this source code in the LICENSE file, you can obtain it
+; at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+; License 1.0 was not distributed with this source code in the PATENTS file, you
+; can obtain it at aomedia.org/license/patent-license/.
 ;
 
 ;
diff --git a/aom_dsp/x86/aom_quantize_avx.c b/aom_dsp/x86/aom_quantize_avx.c
index 8205cf6..7f832c7 100644
--- a/aom_dsp/x86/aom_quantize_avx.c
+++ b/aom_dsp/x86/aom_quantize_avx.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <immintrin.h>
diff --git a/aom_dsp/x86/aom_subpixel_8t_intrin_avx2.c b/aom_dsp/x86/aom_subpixel_8t_intrin_avx2.c
index 94b5da1..a3fea93 100644
--- a/aom_dsp/x86/aom_subpixel_8t_intrin_avx2.c
+++ b/aom_dsp/x86/aom_subpixel_8t_intrin_avx2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <immintrin.h>
diff --git a/aom_dsp/x86/aom_subpixel_8t_intrin_sse2.c b/aom_dsp/x86/aom_subpixel_8t_intrin_sse2.c
index cff7f43..a870451 100644
--- a/aom_dsp/x86/aom_subpixel_8t_intrin_sse2.c
+++ b/aom_dsp/x86/aom_subpixel_8t_intrin_sse2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <emmintrin.h>  // SSE2
diff --git a/aom_dsp/x86/aom_subpixel_8t_intrin_ssse3.c b/aom_dsp/x86/aom_subpixel_8t_intrin_ssse3.c
index f64b821..7425373 100644
--- a/aom_dsp/x86/aom_subpixel_8t_intrin_ssse3.c
+++ b/aom_dsp/x86/aom_subpixel_8t_intrin_ssse3.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <tmmintrin.h>
diff --git a/aom_dsp/x86/aom_subpixel_8t_sse2.asm b/aom_dsp/x86/aom_subpixel_8t_sse2.asm
index 640c5b2..1b5c7bb 100644
--- a/aom_dsp/x86/aom_subpixel_8t_sse2.asm
+++ b/aom_dsp/x86/aom_subpixel_8t_sse2.asm
@@ -1,12 +1,12 @@
 ;
-; Copyright (c) 2016, Alliance for Open Media. All rights reserved
+; Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ;
-; This source code is subject to the terms of the BSD 2 Clause License and
-; the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-; was not distributed with this source code in the LICENSE file, you can
-; obtain it at www.aomedia.org/license/software. If the Alliance for Open
-; Media Patent License 1.0 was not distributed with this source code in the
-; PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+; This source code is subject to the terms of the BSD 3-Clause Clear License and the
+; Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+; not distributed with this source code in the LICENSE file, you can obtain it
+; at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+; License 1.0 was not distributed with this source code in the PATENTS file, you
+; can obtain it at aomedia.org/license/patent-license/.
 ;
 
 ;
diff --git a/aom_dsp/x86/aom_subpixel_8t_ssse3.asm b/aom_dsp/x86/aom_subpixel_8t_ssse3.asm
index 3ca7921..c8d276e 100644
--- a/aom_dsp/x86/aom_subpixel_8t_ssse3.asm
+++ b/aom_dsp/x86/aom_subpixel_8t_ssse3.asm
@@ -1,12 +1,12 @@
 ;
-; Copyright (c) 2016, Alliance for Open Media. All rights reserved
+; Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ;
-; This source code is subject to the terms of the BSD 2 Clause License and
-; the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-; was not distributed with this source code in the LICENSE file, you can
-; obtain it at www.aomedia.org/license/software. If the Alliance for Open
-; Media Patent License 1.0 was not distributed with this source code in the
-; PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+; This source code is subject to the terms of the BSD 3-Clause Clear License and the
+; Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+; not distributed with this source code in the LICENSE file, you can obtain it
+; at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+; License 1.0 was not distributed with this source code in the PATENTS file, you
+; can obtain it at aomedia.org/license/patent-license/.
 ;
 
 ;
diff --git a/aom_dsp/x86/aom_subpixel_bilinear_sse2.asm b/aom_dsp/x86/aom_subpixel_bilinear_sse2.asm
index 90dd55a..2c6f68f 100644
--- a/aom_dsp/x86/aom_subpixel_bilinear_sse2.asm
+++ b/aom_dsp/x86/aom_subpixel_bilinear_sse2.asm
@@ -1,12 +1,12 @@
 ;
-; Copyright (c) 2016, Alliance for Open Media. All rights reserved
+; Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ;
-; This source code is subject to the terms of the BSD 2 Clause License and
-; the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-; was not distributed with this source code in the LICENSE file, you can
-; obtain it at www.aomedia.org/license/software. If the Alliance for Open
-; Media Patent License 1.0 was not distributed with this source code in the
-; PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+; This source code is subject to the terms of the BSD 3-Clause Clear License and the
+; Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+; not distributed with this source code in the LICENSE file, you can obtain it
+; at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+; License 1.0 was not distributed with this source code in the PATENTS file, you
+; can obtain it at aomedia.org/license/patent-license/.
 ;
 
 ;
diff --git a/aom_dsp/x86/aom_subpixel_bilinear_ssse3.asm b/aom_dsp/x86/aom_subpixel_bilinear_ssse3.asm
index 253bc26..acedd37 100644
--- a/aom_dsp/x86/aom_subpixel_bilinear_ssse3.asm
+++ b/aom_dsp/x86/aom_subpixel_bilinear_ssse3.asm
@@ -1,12 +1,12 @@
 ;
-; Copyright (c) 2016, Alliance for Open Media. All rights reserved
+; Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ;
-; This source code is subject to the terms of the BSD 2 Clause License and
-; the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-; was not distributed with this source code in the LICENSE file, you can
-; obtain it at www.aomedia.org/license/software. If the Alliance for Open
-; Media Patent License 1.0 was not distributed with this source code in the
-; PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+; This source code is subject to the terms of the BSD 3-Clause Clear License and the
+; Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+; not distributed with this source code in the LICENSE file, you can obtain it
+; at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+; License 1.0 was not distributed with this source code in the PATENTS file, you
+; can obtain it at aomedia.org/license/patent-license/.
 ;
 
 ;
diff --git a/aom_dsp/x86/avg_intrin_avx2.c b/aom_dsp/x86/avg_intrin_avx2.c
index 4ed06de..f5b5d27 100644
--- a/aom_dsp/x86/avg_intrin_avx2.c
+++ b/aom_dsp/x86/avg_intrin_avx2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <immintrin.h>
diff --git a/aom_dsp/x86/avg_intrin_sse2.c b/aom_dsp/x86/avg_intrin_sse2.c
index b9d38ec..ad401b0 100644
--- a/aom_dsp/x86/avg_intrin_sse2.c
+++ b/aom_dsp/x86/avg_intrin_sse2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <immintrin.h>
diff --git a/aom_dsp/x86/bitdepth_conversion_avx2.h b/aom_dsp/x86/bitdepth_conversion_avx2.h
index 85896e2..dab7f41 100644
--- a/aom_dsp/x86/bitdepth_conversion_avx2.h
+++ b/aom_dsp/x86/bitdepth_conversion_avx2.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <immintrin.h>
diff --git a/aom_dsp/x86/bitdepth_conversion_sse2.h b/aom_dsp/x86/bitdepth_conversion_sse2.h
index 42bb2d1..7d13b17 100644
--- a/aom_dsp/x86/bitdepth_conversion_sse2.h
+++ b/aom_dsp/x86/bitdepth_conversion_sse2.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <xmmintrin.h>
diff --git a/aom_dsp/x86/blend_a64_hmask_sse4.c b/aom_dsp/x86/blend_a64_hmask_sse4.c
index 4f5e3f8..57a4026 100644
--- a/aom_dsp/x86/blend_a64_hmask_sse4.c
+++ b/aom_dsp/x86/blend_a64_hmask_sse4.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "aom/aom_integer.h"
diff --git a/aom_dsp/x86/blend_a64_mask_avx2.c b/aom_dsp/x86/blend_a64_mask_avx2.c
index f38c43f..0942010 100644
--- a/aom_dsp/x86/blend_a64_mask_avx2.c
+++ b/aom_dsp/x86/blend_a64_mask_avx2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <smmintrin.h>  // SSE4.1
diff --git a/aom_dsp/x86/blend_a64_mask_sse4.c b/aom_dsp/x86/blend_a64_mask_sse4.c
index cab2742..342470c 100644
--- a/aom_dsp/x86/blend_a64_mask_sse4.c
+++ b/aom_dsp/x86/blend_a64_mask_sse4.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <smmintrin.h>  // SSE4.1
diff --git a/aom_dsp/x86/blend_a64_vmask_sse4.c b/aom_dsp/x86/blend_a64_vmask_sse4.c
index 0649102..3ae6e85 100644
--- a/aom_dsp/x86/blend_a64_vmask_sse4.c
+++ b/aom_dsp/x86/blend_a64_vmask_sse4.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <smmintrin.h>  // SSE4.1
diff --git a/aom_dsp/x86/blend_mask_sse4.h b/aom_dsp/x86/blend_mask_sse4.h
index c071fdc..1c2261f 100644
--- a/aom_dsp/x86/blend_mask_sse4.h
+++ b/aom_dsp/x86/blend_mask_sse4.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_X86_BLEND_MASK_SSE4_H_
diff --git a/aom_dsp/x86/blend_sse4.h b/aom_dsp/x86/blend_sse4.h
index 8d9b325..9360348 100644
--- a/aom_dsp/x86/blend_sse4.h
+++ b/aom_dsp/x86/blend_sse4.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_X86_BLEND_SSE4_H_
diff --git a/aom_dsp/x86/blk_sse_sum_avx2.c b/aom_dsp/x86/blk_sse_sum_avx2.c
index f7c0eb0..fc22e0b 100644
--- a/aom_dsp/x86/blk_sse_sum_avx2.c
+++ b/aom_dsp/x86/blk_sse_sum_avx2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2019, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <immintrin.h>
diff --git a/aom_dsp/x86/blk_sse_sum_sse2.c b/aom_dsp/x86/blk_sse_sum_sse2.c
index ef0a024..8cb78ab 100644
--- a/aom_dsp/x86/blk_sse_sum_sse2.c
+++ b/aom_dsp/x86/blk_sse_sum_sse2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2019, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <emmintrin.h>
diff --git a/aom_dsp/x86/common_avx2.h b/aom_dsp/x86/common_avx2.h
index 96fe4eb..28545ff 100644
--- a/aom_dsp/x86/common_avx2.h
+++ b/aom_dsp/x86/common_avx2.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_X86_COMMON_AVX2_H_
diff --git a/aom_dsp/x86/convolve.h b/aom_dsp/x86/convolve.h
index ff3224e..d551689 100644
--- a/aom_dsp/x86/convolve.h
+++ b/aom_dsp/x86/convolve.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #ifndef AOM_AOM_DSP_X86_CONVOLVE_H_
 #define AOM_AOM_DSP_X86_CONVOLVE_H_
diff --git a/aom_dsp/x86/convolve_avx2.h b/aom_dsp/x86/convolve_avx2.h
index 1523539..e06efe5 100644
--- a/aom_dsp/x86/convolve_avx2.h
+++ b/aom_dsp/x86/convolve_avx2.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_X86_CONVOLVE_AVX2_H_
@@ -326,6 +327,111 @@
     _mm256_store_si256((__m256i *)&im_block[i * im_stride], res);              \
   }
 
+#if CONFIG_OPTFLOW_REFINEMENT
+// In optical flow MV refinement, unaligned store (_mm_storeu_si128) is used
+// in this function to avoid a subblock boundary error.
+#define DIST_WTD_CONVOLVE_VERTICAL_FILTER_8TAP                                 \
+  __m256i s[8];                                                                \
+  __m256i s0 = _mm256_loadu_si256((__m256i *)(im_block + 0 * im_stride));      \
+  __m256i s1 = _mm256_loadu_si256((__m256i *)(im_block + 1 * im_stride));      \
+  __m256i s2 = _mm256_loadu_si256((__m256i *)(im_block + 2 * im_stride));      \
+  __m256i s3 = _mm256_loadu_si256((__m256i *)(im_block + 3 * im_stride));      \
+  __m256i s4 = _mm256_loadu_si256((__m256i *)(im_block + 4 * im_stride));      \
+  __m256i s5 = _mm256_loadu_si256((__m256i *)(im_block + 5 * im_stride));      \
+                                                                               \
+  s[0] = _mm256_unpacklo_epi16(s0, s1);                                        \
+  s[1] = _mm256_unpacklo_epi16(s2, s3);                                        \
+  s[2] = _mm256_unpacklo_epi16(s4, s5);                                        \
+                                                                               \
+  s[4] = _mm256_unpackhi_epi16(s0, s1);                                        \
+  s[5] = _mm256_unpackhi_epi16(s2, s3);                                        \
+  s[6] = _mm256_unpackhi_epi16(s4, s5);                                        \
+                                                                               \
+  for (i = 0; i < h; i += 2) {                                                 \
+    const int16_t *data = &im_block[i * im_stride];                            \
+                                                                               \
+    const __m256i s6 = _mm256_loadu_si256((__m256i *)(data + 6 * im_stride));  \
+    const __m256i s7 = _mm256_loadu_si256((__m256i *)(data + 7 * im_stride));  \
+                                                                               \
+    s[3] = _mm256_unpacklo_epi16(s6, s7);                                      \
+    s[7] = _mm256_unpackhi_epi16(s6, s7);                                      \
+                                                                               \
+    const __m256i res_a = convolve(s, coeffs_y);                               \
+    const __m256i res_a_round = _mm256_sra_epi32(                              \
+        _mm256_add_epi32(res_a, round_const_v), round_shift_v);                \
+                                                                               \
+    if (w - j > 4) {                                                           \
+      const __m256i res_b = convolve(s + 4, coeffs_y);                         \
+      const __m256i res_b_round = _mm256_sra_epi32(                            \
+          _mm256_add_epi32(res_b, round_const_v), round_shift_v);              \
+      const __m256i res_16b = _mm256_packs_epi32(res_a_round, res_b_round);    \
+      const __m256i res_unsigned = _mm256_add_epi16(res_16b, offset_const);    \
+                                                                               \
+      if (do_average) {                                                        \
+        const __m256i data_ref_0 = load_line2_avx2(                            \
+            &dst[i * dst_stride + j], &dst[i * dst_stride + j + dst_stride]);  \
+        const __m256i comp_avg_res =                                           \
+            comp_avg(&data_ref_0, &res_unsigned, &wt, use_wtd_comp_avg);       \
+                                                                               \
+        const __m256i round_result = convolve_rounding(                        \
+            &comp_avg_res, &offset_const, &rounding_const, rounding_shift);    \
+                                                                               \
+        const __m256i res_8 = _mm256_packus_epi16(round_result, round_result); \
+        const __m128i res_0 = _mm256_castsi256_si128(res_8);                   \
+        const __m128i res_1 = _mm256_extracti128_si256(res_8, 1);              \
+                                                                               \
+        _mm_storel_epi64((__m128i *)(&dst0[i * dst_stride0 + j]), res_0);      \
+        _mm_storel_epi64(                                                      \
+            (__m128i *)((&dst0[i * dst_stride0 + j + dst_stride0])), res_1);   \
+      } else {                                                                 \
+        const __m128i res_0 = _mm256_castsi256_si128(res_unsigned);            \
+        _mm_storeu_si128((__m128i *)(&dst[i * dst_stride + j]), res_0);        \
+                                                                               \
+        const __m128i res_1 = _mm256_extracti128_si256(res_unsigned, 1);       \
+        _mm_storeu_si128((__m128i *)(&dst[i * dst_stride + j + dst_stride]),   \
+                         res_1);                                               \
+      }                                                                        \
+    } else {                                                                   \
+      const __m256i res_16b = _mm256_packs_epi32(res_a_round, res_a_round);    \
+      const __m256i res_unsigned = _mm256_add_epi16(res_16b, offset_const);    \
+                                                                               \
+      if (do_average) {                                                        \
+        const __m256i data_ref_0 = load_line2_avx2(                            \
+            &dst[i * dst_stride + j], &dst[i * dst_stride + j + dst_stride]);  \
+                                                                               \
+        const __m256i comp_avg_res =                                           \
+            comp_avg(&data_ref_0, &res_unsigned, &wt, use_wtd_comp_avg);       \
+                                                                               \
+        const __m256i round_result = convolve_rounding(                        \
+            &comp_avg_res, &offset_const, &rounding_const, rounding_shift);    \
+                                                                               \
+        const __m256i res_8 = _mm256_packus_epi16(round_result, round_result); \
+        const __m128i res_0 = _mm256_castsi256_si128(res_8);                   \
+        const __m128i res_1 = _mm256_extracti128_si256(res_8, 1);              \
+                                                                               \
+        *(uint32_t *)(&dst0[i * dst_stride0 + j]) = _mm_cvtsi128_si32(res_0);  \
+        *(uint32_t *)(&dst0[i * dst_stride0 + j + dst_stride0]) =              \
+            _mm_cvtsi128_si32(res_1);                                          \
+                                                                               \
+      } else {                                                                 \
+        const __m128i res_0 = _mm256_castsi256_si128(res_unsigned);            \
+        _mm_storeu_si128((__m128i *)(&dst[i * dst_stride + j]), res_0);        \
+                                                                               \
+        const __m128i res_1 = _mm256_extracti128_si256(res_unsigned, 1);       \
+        _mm_storeu_si128((__m128i *)(&dst[i * dst_stride + j + dst_stride]),   \
+                         res_1);                                               \
+      }                                                                        \
+    }                                                                          \
+                                                                               \
+    s[0] = s[1];                                                               \
+    s[1] = s[2];                                                               \
+    s[2] = s[3];                                                               \
+                                                                               \
+    s[4] = s[5];                                                               \
+    s[5] = s[6];                                                               \
+    s[6] = s[7];                                                               \
+  }
+#else
 #define DIST_WTD_CONVOLVE_VERTICAL_FILTER_8TAP                                 \
   __m256i s[8];                                                                \
   __m256i s0 = _mm256_loadu_si256((__m256i *)(im_block + 0 * im_stride));      \
@@ -427,6 +533,8 @@
     s[5] = s[6];                                                               \
     s[6] = s[7];                                                               \
   }
+#endif  // CONFIG_OPTFLOW_REFINEMENT
+
 static INLINE void prepare_coeffs_lowbd(
     const InterpFilterParams *const filter_params, const int subpel_q4,
     __m256i *const coeffs /* [4] */) {
diff --git a/aom_dsp/x86/convolve_common_intrin.h b/aom_dsp/x86/convolve_common_intrin.h
index 707bd2d..27bb15c 100644
--- a/aom_dsp/x86/convolve_common_intrin.h
+++ b/aom_dsp/x86/convolve_common_intrin.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_X86_CONVOLVE_COMMON_INTRIN_H_
diff --git a/aom_dsp/x86/convolve_sse2.h b/aom_dsp/x86/convolve_sse2.h
index 385c7c7..7a3a39f 100644
--- a/aom_dsp/x86/convolve_sse2.h
+++ b/aom_dsp/x86/convolve_sse2.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_X86_CONVOLVE_SSE2_H_
diff --git a/aom_dsp/x86/convolve_sse4_1.h b/aom_dsp/x86/convolve_sse4_1.h
index b1a3bb4..c6fea79 100644
--- a/aom_dsp/x86/convolve_sse4_1.h
+++ b/aom_dsp/x86/convolve_sse4_1.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_X86_CONVOLVE_SSE4_1_H_
diff --git a/aom_dsp/x86/fft_avx2.c b/aom_dsp/x86/fft_avx2.c
index 4cccc5f..46f2b8c 100644
--- a/aom_dsp/x86/fft_avx2.c
+++ b/aom_dsp/x86/fft_avx2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <immintrin.h>
diff --git a/aom_dsp/x86/fft_sse2.c b/aom_dsp/x86/fft_sse2.c
index 6f20a3c..b8d3536 100644
--- a/aom_dsp/x86/fft_sse2.c
+++ b/aom_dsp/x86/fft_sse2.c
@@ -1,12 +1,15 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
-s * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+and the
+ * Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License
+was
+ * not distributed with this source code in the LICENSE file, you can obtain it
+ * at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open
+Media Patent
+ * License 1.0 was not distributed with this source code in the PATENTS file,
+you s * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
  */
 
 #include <xmmintrin.h>
diff --git a/aom_dsp/x86/fwd_txfm_impl_sse2.h b/aom_dsp/x86/fwd_txfm_impl_sse2.h
index 89fe189..2c470cd 100644
--- a/aom_dsp/x86/fwd_txfm_impl_sse2.h
+++ b/aom_dsp/x86/fwd_txfm_impl_sse2.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <emmintrin.h>  // SSE2
diff --git a/aom_dsp/x86/fwd_txfm_sse2.c b/aom_dsp/x86/fwd_txfm_sse2.c
index 964f28d..a645bdb 100644
--- a/aom_dsp/x86/fwd_txfm_sse2.c
+++ b/aom_dsp/x86/fwd_txfm_sse2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <emmintrin.h>  // SSE2
diff --git a/aom_dsp/x86/fwd_txfm_sse2.h b/aom_dsp/x86/fwd_txfm_sse2.h
index ab3cd91..a4686ea 100644
--- a/aom_dsp/x86/fwd_txfm_sse2.h
+++ b/aom_dsp/x86/fwd_txfm_sse2.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_X86_FWD_TXFM_SSE2_H_
diff --git a/aom_dsp/x86/fwd_txfm_ssse3_x86_64.asm b/aom_dsp/x86/fwd_txfm_ssse3_x86_64.asm
index c1fb259..723df21 100644
--- a/aom_dsp/x86/fwd_txfm_ssse3_x86_64.asm
+++ b/aom_dsp/x86/fwd_txfm_ssse3_x86_64.asm
@@ -1,12 +1,12 @@
 ;
-; Copyright (c) 2016, Alliance for Open Media. All rights reserved
+; Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ;
-; This source code is subject to the terms of the BSD 2 Clause License and
-; the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-; was not distributed with this source code in the LICENSE file, you can
-; obtain it at www.aomedia.org/license/software. If the Alliance for Open
-; Media Patent License 1.0 was not distributed with this source code in the
-; PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+; This source code is subject to the terms of the BSD 3-Clause Clear License and the
+; Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+; not distributed with this source code in the LICENSE file, you can obtain it
+; at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+; License 1.0 was not distributed with this source code in the PATENTS file, you
+; can obtain it at aomedia.org/license/patent-license/.
 ;
 
 ;
diff --git a/aom_dsp/x86/highbd_adaptive_quantize_avx2.c b/aom_dsp/x86/highbd_adaptive_quantize_avx2.c
index 4d52c47..572ae05 100644
--- a/aom_dsp/x86/highbd_adaptive_quantize_avx2.c
+++ b/aom_dsp/x86/highbd_adaptive_quantize_avx2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2019, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <immintrin.h>
diff --git a/aom_dsp/x86/highbd_adaptive_quantize_sse2.c b/aom_dsp/x86/highbd_adaptive_quantize_sse2.c
index ce6c7ee..0f5cfa3 100644
--- a/aom_dsp/x86/highbd_adaptive_quantize_sse2.c
+++ b/aom_dsp/x86/highbd_adaptive_quantize_sse2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2019, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <emmintrin.h>
diff --git a/aom_dsp/x86/highbd_convolve_avx2.c b/aom_dsp/x86/highbd_convolve_avx2.c
index 0af7d87..c65ff57 100644
--- a/aom_dsp/x86/highbd_convolve_avx2.c
+++ b/aom_dsp/x86/highbd_convolve_avx2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #include <immintrin.h>
 #include <string.h>
diff --git a/aom_dsp/x86/highbd_convolve_sse2.c b/aom_dsp/x86/highbd_convolve_sse2.c
index a2bb283..3a66cf3 100644
--- a/aom_dsp/x86/highbd_convolve_sse2.c
+++ b/aom_dsp/x86/highbd_convolve_sse2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #include <emmintrin.h>
 
diff --git a/aom_dsp/x86/highbd_convolve_ssse3.c b/aom_dsp/x86/highbd_convolve_ssse3.c
index 491c647..6467141 100644
--- a/aom_dsp/x86/highbd_convolve_ssse3.c
+++ b/aom_dsp/x86/highbd_convolve_ssse3.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <tmmintrin.h>
diff --git a/aom_dsp/x86/highbd_intrapred_asm_sse2.asm b/aom_dsp/x86/highbd_intrapred_asm_sse2.asm
index 91b3d12..0b54d91 100644
--- a/aom_dsp/x86/highbd_intrapred_asm_sse2.asm
+++ b/aom_dsp/x86/highbd_intrapred_asm_sse2.asm
@@ -1,12 +1,12 @@
 ;
-; Copyright (c) 2016, Alliance for Open Media. All rights reserved
+; Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ;
-; This source code is subject to the terms of the BSD 2 Clause License and
-; the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-; was not distributed with this source code in the LICENSE file, you can
-; obtain it at www.aomedia.org/license/software. If the Alliance for Open
-; Media Patent License 1.0 was not distributed with this source code in the
-; PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+; This source code is subject to the terms of the BSD 3-Clause Clear License and the
+; Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+; not distributed with this source code in the LICENSE file, you can obtain it
+; at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+; License 1.0 was not distributed with this source code in the PATENTS file, you
+; can obtain it at aomedia.org/license/patent-license/.
 ;
 
 ;
diff --git a/aom_dsp/x86/highbd_intrapred_sse2.c b/aom_dsp/x86/highbd_intrapred_sse2.c
index 5a55736..8184ad3 100644
--- a/aom_dsp/x86/highbd_intrapred_sse2.c
+++ b/aom_dsp/x86/highbd_intrapred_sse2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <emmintrin.h>
diff --git a/aom_dsp/x86/highbd_loopfilter_avx2.c b/aom_dsp/x86/highbd_loopfilter_avx2.c
index c954da9..e0c2bfd 100644
--- a/aom_dsp/x86/highbd_loopfilter_avx2.c
+++ b/aom_dsp/x86/highbd_loopfilter_avx2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <immintrin.h>
diff --git a/aom_dsp/x86/highbd_loopfilter_sse2.c b/aom_dsp/x86/highbd_loopfilter_sse2.c
index ea7dc6a..6146020 100644
--- a/aom_dsp/x86/highbd_loopfilter_sse2.c
+++ b/aom_dsp/x86/highbd_loopfilter_sse2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <emmintrin.h>  // SSE2
diff --git a/aom_dsp/x86/highbd_quantize_intrin_avx2.c b/aom_dsp/x86/highbd_quantize_intrin_avx2.c
index c816b5f..1e262c6 100644
--- a/aom_dsp/x86/highbd_quantize_intrin_avx2.c
+++ b/aom_dsp/x86/highbd_quantize_intrin_avx2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <immintrin.h>
diff --git a/aom_dsp/x86/highbd_quantize_intrin_sse2.c b/aom_dsp/x86/highbd_quantize_intrin_sse2.c
index 13d6530..e883e12 100644
--- a/aom_dsp/x86/highbd_quantize_intrin_sse2.c
+++ b/aom_dsp/x86/highbd_quantize_intrin_sse2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <emmintrin.h>
diff --git a/aom_dsp/x86/highbd_sad4d_sse2.asm b/aom_dsp/x86/highbd_sad4d_sse2.asm
index 7ae1ca1..15f6f26 100644
--- a/aom_dsp/x86/highbd_sad4d_sse2.asm
+++ b/aom_dsp/x86/highbd_sad4d_sse2.asm
@@ -1,12 +1,12 @@
 ;
-; Copyright (c) 2016, Alliance for Open Media. All rights reserved
+; Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ;
-; This source code is subject to the terms of the BSD 2 Clause License and
-; the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-; was not distributed with this source code in the LICENSE file, you can
-; obtain it at www.aomedia.org/license/software. If the Alliance for Open
-; Media Patent License 1.0 was not distributed with this source code in the
-; PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+; This source code is subject to the terms of the BSD 3-Clause Clear License and the
+; Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+; not distributed with this source code in the LICENSE file, you can obtain it
+; at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+; License 1.0 was not distributed with this source code in the PATENTS file, you
+; can obtain it at aomedia.org/license/patent-license/.
 ;
 
 ;
diff --git a/aom_dsp/x86/highbd_sad_sse2.asm b/aom_dsp/x86/highbd_sad_sse2.asm
index 58f1ac9..883e9d1 100644
--- a/aom_dsp/x86/highbd_sad_sse2.asm
+++ b/aom_dsp/x86/highbd_sad_sse2.asm
@@ -1,12 +1,12 @@
 ;
-; Copyright (c) 2016, Alliance for Open Media. All rights reserved
+; Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ;
-; This source code is subject to the terms of the BSD 2 Clause License and
-; the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-; was not distributed with this source code in the LICENSE file, you can
-; obtain it at www.aomedia.org/license/software. If the Alliance for Open
-; Media Patent License 1.0 was not distributed with this source code in the
-; PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+; This source code is subject to the terms of the BSD 3-Clause Clear License and the
+; Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+; not distributed with this source code in the LICENSE file, you can obtain it
+; at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+; License 1.0 was not distributed with this source code in the PATENTS file, you
+; can obtain it at aomedia.org/license/patent-license/.
 ;
 
 ;
diff --git a/aom_dsp/x86/highbd_subpel_variance_impl_sse2.asm b/aom_dsp/x86/highbd_subpel_variance_impl_sse2.asm
index 5c78933..22ad232 100644
--- a/aom_dsp/x86/highbd_subpel_variance_impl_sse2.asm
+++ b/aom_dsp/x86/highbd_subpel_variance_impl_sse2.asm
@@ -1,12 +1,12 @@
 ;
-; Copyright (c) 2016, Alliance for Open Media. All rights reserved
+; Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ;
-; This source code is subject to the terms of the BSD 2 Clause License and
-; the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-; was not distributed with this source code in the LICENSE file, you can
-; obtain it at www.aomedia.org/license/software. If the Alliance for Open
-; Media Patent License 1.0 was not distributed with this source code in the
-; PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+; This source code is subject to the terms of the BSD 3-Clause Clear License and the
+; Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+; not distributed with this source code in the LICENSE file, you can obtain it
+; at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+; License 1.0 was not distributed with this source code in the PATENTS file, you
+; can obtain it at aomedia.org/license/patent-license/.
 ;
 
 ;
diff --git a/aom_dsp/x86/highbd_subtract_sse2.c b/aom_dsp/x86/highbd_subtract_sse2.c
index b72d1cf..6d7d4be 100644
--- a/aom_dsp/x86/highbd_subtract_sse2.c
+++ b/aom_dsp/x86/highbd_subtract_sse2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/aom_dsp/x86/highbd_variance_avx2.c b/aom_dsp/x86/highbd_variance_avx2.c
index 3d76c78..0e5502f 100644
--- a/aom_dsp/x86/highbd_variance_avx2.c
+++ b/aom_dsp/x86/highbd_variance_avx2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/aom_dsp/x86/highbd_variance_impl_sse2.asm b/aom_dsp/x86/highbd_variance_impl_sse2.asm
index ec6c7e9..d8372c1 100644
--- a/aom_dsp/x86/highbd_variance_impl_sse2.asm
+++ b/aom_dsp/x86/highbd_variance_impl_sse2.asm
@@ -1,12 +1,12 @@
 ;
-; Copyright (c) 2016, Alliance for Open Media. All rights reserved
+; Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ;
-; This source code is subject to the terms of the BSD 2 Clause License and
-; the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-; was not distributed with this source code in the LICENSE file, you can
-; obtain it at www.aomedia.org/license/software. If the Alliance for Open
-; Media Patent License 1.0 was not distributed with this source code in the
-; PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+; This source code is subject to the terms of the BSD 3-Clause Clear License and the
+; Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+; not distributed with this source code in the LICENSE file, you can obtain it
+; at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+; License 1.0 was not distributed with this source code in the PATENTS file, you
+; can obtain it at aomedia.org/license/patent-license/.
 ;
 
 ;
diff --git a/aom_dsp/x86/highbd_variance_sse2.c b/aom_dsp/x86/highbd_variance_sse2.c
index cbdeba2..21b4c7b 100644
--- a/aom_dsp/x86/highbd_variance_sse2.c
+++ b/aom_dsp/x86/highbd_variance_sse2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/aom_dsp/x86/highbd_variance_sse4.c b/aom_dsp/x86/highbd_variance_sse4.c
index df5449a..67d5839 100644
--- a/aom_dsp/x86/highbd_variance_sse4.c
+++ b/aom_dsp/x86/highbd_variance_sse4.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <smmintrin.h> /* SSE4.1 */
diff --git a/aom_dsp/x86/intrapred_asm_sse2.asm b/aom_dsp/x86/intrapred_asm_sse2.asm
index 0eb6323..a2570d3 100644
--- a/aom_dsp/x86/intrapred_asm_sse2.asm
+++ b/aom_dsp/x86/intrapred_asm_sse2.asm
@@ -1,12 +1,12 @@
 ;
-; Copyright (c) 2016, Alliance for Open Media. All rights reserved
+; Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ;
-; This source code is subject to the terms of the BSD 2 Clause License and
-; the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-; was not distributed with this source code in the LICENSE file, you can
-; obtain it at www.aomedia.org/license/software. If the Alliance for Open
-; Media Patent License 1.0 was not distributed with this source code in the
-; PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+; This source code is subject to the terms of the BSD 3-Clause Clear License and the
+; Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+; not distributed with this source code in the LICENSE file, you can obtain it
+; at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+; License 1.0 was not distributed with this source code in the PATENTS file, you
+; can obtain it at aomedia.org/license/patent-license/.
 ;
 
 ;
diff --git a/aom_dsp/x86/intrapred_avx2.c b/aom_dsp/x86/intrapred_avx2.c
index 23c5b2b..80a8b31 100644
--- a/aom_dsp/x86/intrapred_avx2.c
+++ b/aom_dsp/x86/intrapred_avx2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <immintrin.h>
diff --git a/aom_dsp/x86/intrapred_sse2.c b/aom_dsp/x86/intrapred_sse2.c
index 5afef68..6902dd9 100644
--- a/aom_dsp/x86/intrapred_sse2.c
+++ b/aom_dsp/x86/intrapred_sse2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <emmintrin.h>
diff --git a/aom_dsp/x86/intrapred_ssse3.c b/aom_dsp/x86/intrapred_ssse3.c
index 5a34ea0..468d036 100644
--- a/aom_dsp/x86/intrapred_ssse3.c
+++ b/aom_dsp/x86/intrapred_ssse3.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <tmmintrin.h>
diff --git a/aom_dsp/x86/intrapred_x86.h b/aom_dsp/x86/intrapred_x86.h
index b13f575..ff32b23 100644
--- a/aom_dsp/x86/intrapred_x86.h
+++ b/aom_dsp/x86/intrapred_x86.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_X86_INTRAPRED_X86_H_
diff --git a/aom_dsp/x86/inv_wht_sse2.asm b/aom_dsp/x86/inv_wht_sse2.asm
index 0bc841a..5fbd0eb 100644
--- a/aom_dsp/x86/inv_wht_sse2.asm
+++ b/aom_dsp/x86/inv_wht_sse2.asm
@@ -1,12 +1,12 @@
 ;
-; Copyright (c) 2016, Alliance for Open Media. All rights reserved
+; Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ;
-; This source code is subject to the terms of the BSD 2 Clause License and
-; the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-; was not distributed with this source code in the LICENSE file, you can
-; obtain it at www.aomedia.org/license/software. If the Alliance for Open
-; Media Patent License 1.0 was not distributed with this source code in the
-; PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+; This source code is subject to the terms of the BSD 3-Clause Clear License and the
+; Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+; not distributed with this source code in the LICENSE file, you can obtain it
+; at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+; License 1.0 was not distributed with this source code in the PATENTS file, you
+; can obtain it at aomedia.org/license/patent-license/.
 ;
 
 ;
diff --git a/aom_dsp/x86/jnt_sad_ssse3.c b/aom_dsp/x86/jnt_sad_ssse3.c
index 2e3e2be..6d7b3f6 100644
--- a/aom_dsp/x86/jnt_sad_ssse3.c
+++ b/aom_dsp/x86/jnt_sad_ssse3.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/aom_dsp/x86/jnt_variance_ssse3.c b/aom_dsp/x86/jnt_variance_ssse3.c
index c8b02f5..fa7e145 100644
--- a/aom_dsp/x86/jnt_variance_ssse3.c
+++ b/aom_dsp/x86/jnt_variance_ssse3.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/aom_dsp/x86/loopfilter_sse2.c b/aom_dsp/x86/loopfilter_sse2.c
index d534683..12c8d19 100644
--- a/aom_dsp/x86/loopfilter_sse2.c
+++ b/aom_dsp/x86/loopfilter_sse2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <emmintrin.h>  // SSE2
diff --git a/aom_dsp/x86/lpf_common_sse2.h b/aom_dsp/x86/lpf_common_sse2.h
index 6ed2cbf..a0ad69f 100644
--- a/aom_dsp/x86/lpf_common_sse2.h
+++ b/aom_dsp/x86/lpf_common_sse2.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_X86_LPF_COMMON_SSE2_H_
diff --git a/aom_dsp/x86/masked_sad4d_ssse3.c b/aom_dsp/x86/masked_sad4d_ssse3.c
index 8ef7ee0..963fc30 100644
--- a/aom_dsp/x86/masked_sad4d_ssse3.c
+++ b/aom_dsp/x86/masked_sad4d_ssse3.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <stdio.h>
diff --git a/aom_dsp/x86/masked_sad_intrin_avx2.c b/aom_dsp/x86/masked_sad_intrin_avx2.c
index 60f0ab3..10b9688 100644
--- a/aom_dsp/x86/masked_sad_intrin_avx2.c
+++ b/aom_dsp/x86/masked_sad_intrin_avx2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <tmmintrin.h>
diff --git a/aom_dsp/x86/masked_sad_intrin_ssse3.c b/aom_dsp/x86/masked_sad_intrin_ssse3.c
index 7168277..1d62714 100644
--- a/aom_dsp/x86/masked_sad_intrin_ssse3.c
+++ b/aom_dsp/x86/masked_sad_intrin_ssse3.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <stdio.h>
diff --git a/aom_dsp/x86/masked_sad_intrin_ssse3.h b/aom_dsp/x86/masked_sad_intrin_ssse3.h
index cffbd96..f09e585 100644
--- a/aom_dsp/x86/masked_sad_intrin_ssse3.h
+++ b/aom_dsp/x86/masked_sad_intrin_ssse3.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_X86_MASKED_SAD_INTRIN_SSSE3_H_
diff --git a/aom_dsp/x86/masked_variance_intrin_ssse3.c b/aom_dsp/x86/masked_variance_intrin_ssse3.c
index 8811829..fc36829 100644
--- a/aom_dsp/x86/masked_variance_intrin_ssse3.c
+++ b/aom_dsp/x86/masked_variance_intrin_ssse3.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <stdlib.h>
diff --git a/aom_dsp/x86/masked_variance_intrin_ssse3.h b/aom_dsp/x86/masked_variance_intrin_ssse3.h
index 4faa098..a008713 100644
--- a/aom_dsp/x86/masked_variance_intrin_ssse3.h
+++ b/aom_dsp/x86/masked_variance_intrin_ssse3.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_X86_MASKED_VARIANCE_INTRIN_SSSE3_H_
diff --git a/aom_dsp/x86/mem_sse2.h b/aom_dsp/x86/mem_sse2.h
index 59d704e..f89eaa8 100644
--- a/aom_dsp/x86/mem_sse2.h
+++ b/aom_dsp/x86/mem_sse2.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_X86_MEM_SSE2_H_
diff --git a/aom_dsp/x86/obmc_intrinsic_sse4.h b/aom_dsp/x86/obmc_intrinsic_sse4.h
index 5181e44..c2365ee 100644
--- a/aom_dsp/x86/obmc_intrinsic_sse4.h
+++ b/aom_dsp/x86/obmc_intrinsic_sse4.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_X86_OBMC_INTRINSIC_SSE4_H_
diff --git a/aom_dsp/x86/obmc_intrinsic_ssse3.h b/aom_dsp/x86/obmc_intrinsic_ssse3.h
index 48486c6..202dad6 100644
--- a/aom_dsp/x86/obmc_intrinsic_ssse3.h
+++ b/aom_dsp/x86/obmc_intrinsic_ssse3.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_X86_OBMC_INTRINSIC_SSSE3_H_
diff --git a/aom_dsp/x86/obmc_sad_avx2.c b/aom_dsp/x86/obmc_sad_avx2.c
index 2aa2a05..582b05d 100644
--- a/aom_dsp/x86/obmc_sad_avx2.c
+++ b/aom_dsp/x86/obmc_sad_avx2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/aom_dsp/x86/obmc_sad_sse4.c b/aom_dsp/x86/obmc_sad_sse4.c
index 0338a8c..6fdf354 100644
--- a/aom_dsp/x86/obmc_sad_sse4.c
+++ b/aom_dsp/x86/obmc_sad_sse4.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/aom_dsp/x86/obmc_variance_avx2.c b/aom_dsp/x86/obmc_variance_avx2.c
index bfec0e8..5214f67 100644
--- a/aom_dsp/x86/obmc_variance_avx2.c
+++ b/aom_dsp/x86/obmc_variance_avx2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/aom_dsp/x86/obmc_variance_sse4.c b/aom_dsp/x86/obmc_variance_sse4.c
index b676a5b..12ee91f 100644
--- a/aom_dsp/x86/obmc_variance_sse4.c
+++ b/aom_dsp/x86/obmc_variance_sse4.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/aom_dsp/x86/quantize_sse2.c b/aom_dsp/x86/quantize_sse2.c
index 67823c7..1595499 100644
--- a/aom_dsp/x86/quantize_sse2.c
+++ b/aom_dsp/x86/quantize_sse2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/aom_dsp/x86/quantize_ssse3.c b/aom_dsp/x86/quantize_ssse3.c
index 16dd18f..15ad9f1 100644
--- a/aom_dsp/x86/quantize_ssse3.c
+++ b/aom_dsp/x86/quantize_ssse3.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2019, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/aom_dsp/x86/quantize_ssse3_x86_64.asm b/aom_dsp/x86/quantize_ssse3_x86_64.asm
index fa616a6..6eefa39 100644
--- a/aom_dsp/x86/quantize_ssse3_x86_64.asm
+++ b/aom_dsp/x86/quantize_ssse3_x86_64.asm
@@ -1,12 +1,12 @@
 ;
-; Copyright (c) 2016, Alliance for Open Media. All rights reserved
+; Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ;
-; This source code is subject to the terms of the BSD 2 Clause License and
-; the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-; was not distributed with this source code in the LICENSE file, you can
-; obtain it at www.aomedia.org/license/software. If the Alliance for Open
-; Media Patent License 1.0 was not distributed with this source code in the
-; PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+; This source code is subject to the terms of the BSD 3-Clause Clear License and the
+; Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+; not distributed with this source code in the LICENSE file, you can obtain it
+; at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+; License 1.0 was not distributed with this source code in the PATENTS file, you
+; can obtain it at aomedia.org/license/patent-license/.
 ;
 
 ;
diff --git a/aom_dsp/x86/quantize_x86.h b/aom_dsp/x86/quantize_x86.h
index d74eb77..f794c8e 100644
--- a/aom_dsp/x86/quantize_x86.h
+++ b/aom_dsp/x86/quantize_x86.h
@@ -1,12 +1,13 @@
 /*
- *  Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <emmintrin.h>
diff --git a/aom_dsp/x86/sad4d_avx2.c b/aom_dsp/x86/sad4d_avx2.c
index 0e0b904..a718035 100644
--- a/aom_dsp/x86/sad4d_avx2.c
+++ b/aom_dsp/x86/sad4d_avx2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #include <immintrin.h>  // AVX2
 
diff --git a/aom_dsp/x86/sad4d_sse2.asm b/aom_dsp/x86/sad4d_sse2.asm
index b5a17c5..b720f9c 100644
--- a/aom_dsp/x86/sad4d_sse2.asm
+++ b/aom_dsp/x86/sad4d_sse2.asm
@@ -1,12 +1,12 @@
 ;
-; Copyright (c) 2016, Alliance for Open Media. All rights reserved
+; Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ;
-; This source code is subject to the terms of the BSD 2 Clause License and
-; the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-; was not distributed with this source code in the LICENSE file, you can
-; obtain it at www.aomedia.org/license/software. If the Alliance for Open
-; Media Patent License 1.0 was not distributed with this source code in the
-; PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+; This source code is subject to the terms of the BSD 3-Clause Clear License and the
+; Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+; not distributed with this source code in the LICENSE file, you can obtain it
+; at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+; License 1.0 was not distributed with this source code in the PATENTS file, you
+; can obtain it at aomedia.org/license/patent-license/.
 ;
 
 ;
diff --git a/aom_dsp/x86/sad_avx2.c b/aom_dsp/x86/sad_avx2.c
index 9ab9812..991d63d 100644
--- a/aom_dsp/x86/sad_avx2.c
+++ b/aom_dsp/x86/sad_avx2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #include <immintrin.h>
 
diff --git a/aom_dsp/x86/sad_highbd_avx2.c b/aom_dsp/x86/sad_highbd_avx2.c
index 7d0626a..e143d00 100644
--- a/aom_dsp/x86/sad_highbd_avx2.c
+++ b/aom_dsp/x86/sad_highbd_avx2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <immintrin.h>
diff --git a/aom_dsp/x86/sad_impl_avx2.c b/aom_dsp/x86/sad_impl_avx2.c
index 2afae4b..25378b4 100644
--- a/aom_dsp/x86/sad_impl_avx2.c
+++ b/aom_dsp/x86/sad_impl_avx2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <immintrin.h>
diff --git a/aom_dsp/x86/sad_sse2.asm b/aom_dsp/x86/sad_sse2.asm
index de9845a..bd8ef45 100644
--- a/aom_dsp/x86/sad_sse2.asm
+++ b/aom_dsp/x86/sad_sse2.asm
@@ -1,12 +1,12 @@
 ;
-; Copyright (c) 2016, Alliance for Open Media. All rights reserved
+; Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ;
-; This source code is subject to the terms of the BSD 2 Clause License and
-; the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-; was not distributed with this source code in the LICENSE file, you can
-; obtain it at www.aomedia.org/license/software. If the Alliance for Open
-; Media Patent License 1.0 was not distributed with this source code in the
-; PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+; This source code is subject to the terms of the BSD 3-Clause Clear License and the
+; Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+; not distributed with this source code in the LICENSE file, you can obtain it
+; at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+; License 1.0 was not distributed with this source code in the PATENTS file, you
+; can obtain it at aomedia.org/license/patent-license/.
 ;
 
 ;
diff --git a/aom_dsp/x86/sse_avx2.c b/aom_dsp/x86/sse_avx2.c
index 42df981..817cb63 100644
--- a/aom_dsp/x86/sse_avx2.c
+++ b/aom_dsp/x86/sse_avx2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #include <smmintrin.h>
 #include <immintrin.h>
diff --git a/aom_dsp/x86/sse_sse4.c b/aom_dsp/x86/sse_sse4.c
index 59ed857..8ab6cf0 100644
--- a/aom_dsp/x86/sse_sse4.c
+++ b/aom_dsp/x86/sse_sse4.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/aom_dsp/x86/ssim_sse2_x86_64.asm b/aom_dsp/x86/ssim_sse2_x86_64.asm
index 49bc655..0eb7ff5 100644
--- a/aom_dsp/x86/ssim_sse2_x86_64.asm
+++ b/aom_dsp/x86/ssim_sse2_x86_64.asm
@@ -1,12 +1,12 @@
 ;
-; Copyright (c) 2016, Alliance for Open Media. All rights reserved
+; Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ;
-; This source code is subject to the terms of the BSD 2 Clause License and
-; the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-; was not distributed with this source code in the LICENSE file, you can
-; obtain it at www.aomedia.org/license/software. If the Alliance for Open
-; Media Patent License 1.0 was not distributed with this source code in the
-; PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+; This source code is subject to the terms of the BSD 3-Clause Clear License and the
+; Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+; not distributed with this source code in the LICENSE file, you can obtain it
+; at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+; License 1.0 was not distributed with this source code in the PATENTS file, you
+; can obtain it at aomedia.org/license/patent-license/.
 ;
 
 ;
diff --git a/aom_dsp/x86/subpel_variance_sse2.asm b/aom_dsp/x86/subpel_variance_sse2.asm
index cbf2890..431f966 100644
--- a/aom_dsp/x86/subpel_variance_sse2.asm
+++ b/aom_dsp/x86/subpel_variance_sse2.asm
@@ -1,12 +1,12 @@
 ;
-; Copyright (c) 2016, Alliance for Open Media. All rights reserved
+; Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ;
-; This source code is subject to the terms of the BSD 2 Clause License and
-; the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-; was not distributed with this source code in the LICENSE file, you can
-; obtain it at www.aomedia.org/license/software. If the Alliance for Open
-; Media Patent License 1.0 was not distributed with this source code in the
-; PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+; This source code is subject to the terms of the BSD 3-Clause Clear License and the
+; Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+; not distributed with this source code in the LICENSE file, you can obtain it
+; at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+; License 1.0 was not distributed with this source code in the PATENTS file, you
+; can obtain it at aomedia.org/license/patent-license/.
 ;
 
 ;
diff --git a/aom_dsp/x86/subtract_avx2.c b/aom_dsp/x86/subtract_avx2.c
index 4083160..8326451 100644
--- a/aom_dsp/x86/subtract_avx2.c
+++ b/aom_dsp/x86/subtract_avx2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #include <immintrin.h>
 
@@ -101,8 +102,8 @@
                                 src_stride, pred_ptr, pred_stride);
       break;
     default:
-      aom_subtract_block_sse2(rows, cols, diff_ptr, diff_stride, src_ptr,
-                              src_stride, pred_ptr, pred_stride);
+      aom_subtract_block_c(rows, cols, diff_ptr, diff_stride, src_ptr,
+                           src_stride, pred_ptr, pred_stride);
       break;
   }
 }
diff --git a/aom_dsp/x86/subtract_sse2.asm b/aom_dsp/x86/subtract_sse2.asm
index af38022..f4e9406 100644
--- a/aom_dsp/x86/subtract_sse2.asm
+++ b/aom_dsp/x86/subtract_sse2.asm
@@ -1,12 +1,12 @@
 ;
-; Copyright (c) 2016, Alliance for Open Media. All rights reserved
+; Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ;
-; This source code is subject to the terms of the BSD 2 Clause License and
-; the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-; was not distributed with this source code in the LICENSE file, you can
-; obtain it at www.aomedia.org/license/software. If the Alliance for Open
-; Media Patent License 1.0 was not distributed with this source code in the
-; PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+; This source code is subject to the terms of the BSD 3-Clause Clear License and the
+; Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+; not distributed with this source code in the LICENSE file, you can obtain it
+; at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+; License 1.0 was not distributed with this source code in the PATENTS file, you
+; can obtain it at aomedia.org/license/patent-license/.
 ;
 
 ;
diff --git a/aom_dsp/x86/sum_squares_avx2.c b/aom_dsp/x86/sum_squares_avx2.c
index 0d63db2..30f94e2 100644
--- a/aom_dsp/x86/sum_squares_avx2.c
+++ b/aom_dsp/x86/sum_squares_avx2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <immintrin.h>
diff --git a/aom_dsp/x86/sum_squares_sse2.c b/aom_dsp/x86/sum_squares_sse2.c
index 0bdeee9..bbbd4a4 100644
--- a/aom_dsp/x86/sum_squares_sse2.c
+++ b/aom_dsp/x86/sum_squares_sse2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/aom_dsp/x86/sum_squares_sse2.h b/aom_dsp/x86/sum_squares_sse2.h
index 5ed3f2c..0bfa4ad 100644
--- a/aom_dsp/x86/sum_squares_sse2.h
+++ b/aom_dsp/x86/sum_squares_sse2.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_DSP_X86_SUM_SQUARES_SSE2_H_
diff --git a/aom_dsp/x86/synonyms.h b/aom_dsp/x86/synonyms.h
index 2e99bee..0eaa50e 100644
--- a/aom_dsp/x86/synonyms.h
+++ b/aom_dsp/x86/synonyms.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_X86_SYNONYMS_H_
diff --git a/aom_dsp/x86/synonyms_avx2.h b/aom_dsp/x86/synonyms_avx2.h
index 4d6ee6a..b58e001 100644
--- a/aom_dsp/x86/synonyms_avx2.h
+++ b/aom_dsp/x86/synonyms_avx2.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_X86_SYNONYMS_AVX2_H_
diff --git a/aom_dsp/x86/transpose_sse2.h b/aom_dsp/x86/transpose_sse2.h
index 7ac692c..78daf91 100644
--- a/aom_dsp/x86/transpose_sse2.h
+++ b/aom_dsp/x86/transpose_sse2.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_X86_TRANSPOSE_SSE2_H_
diff --git a/aom_dsp/x86/txfm_common_avx2.h b/aom_dsp/x86/txfm_common_avx2.h
index ea57c9f..57059d7 100644
--- a/aom_dsp/x86/txfm_common_avx2.h
+++ b/aom_dsp/x86/txfm_common_avx2.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_X86_TXFM_COMMON_AVX2_H_
diff --git a/aom_dsp/x86/txfm_common_sse2.h b/aom_dsp/x86/txfm_common_sse2.h
index 9c99eb9..bcc600d 100644
--- a/aom_dsp/x86/txfm_common_sse2.h
+++ b/aom_dsp/x86/txfm_common_sse2.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_DSP_X86_TXFM_COMMON_SSE2_H_
diff --git a/aom_dsp/x86/variance_avx2.c b/aom_dsp/x86/variance_avx2.c
index 3558070..39d301d 100644
--- a/aom_dsp/x86/variance_avx2.c
+++ b/aom_dsp/x86/variance_avx2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <immintrin.h>
diff --git a/aom_dsp/x86/variance_impl_avx2.c b/aom_dsp/x86/variance_impl_avx2.c
index f779270..d3d7aab 100644
--- a/aom_dsp/x86/variance_impl_avx2.c
+++ b/aom_dsp/x86/variance_impl_avx2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <immintrin.h>  // AVX2
diff --git a/aom_dsp/x86/variance_impl_ssse3.c b/aom_dsp/x86/variance_impl_ssse3.c
index 66b0d7d..48b575a 100644
--- a/aom_dsp/x86/variance_impl_ssse3.c
+++ b/aom_dsp/x86/variance_impl_ssse3.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <tmmintrin.h>
diff --git a/aom_dsp/x86/variance_sse2.c b/aom_dsp/x86/variance_sse2.c
index 217d9de..7c4511f 100644
--- a/aom_dsp/x86/variance_sse2.c
+++ b/aom_dsp/x86/variance_sse2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/aom_mem/aom_mem.c b/aom_mem/aom_mem.c
index e977b01..ce3c6c6 100644
--- a/aom_mem/aom_mem.c
+++ b/aom_mem/aom_mem.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "aom_mem.h"
diff --git a/aom_mem/aom_mem.cmake b/aom_mem/aom_mem.cmake
index 346588d..b0d661f 100644
--- a/aom_mem/aom_mem.cmake
+++ b/aom_mem/aom_mem.cmake
@@ -1,12 +1,12 @@
 #
-# Copyright (c) 2017, Alliance for Open Media. All rights reserved
+# Copyright (c) 2021, Alliance for Open Media. All rights reserved
 #
-# This source code is subject to the terms of the BSD 2 Clause License and the
-# Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License was
-# not distributed with this source code in the LICENSE file, you can obtain it
-# at www.aomedia.org/license/software. If the Alliance for Open Media Patent
-# License 1.0 was not distributed with this source code in the PATENTS file, you
-# can obtain it at www.aomedia.org/license/patent.
+# This source code is subject to the terms of the BSD 3-Clause Clear License and
+# the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+# License was not distributed with this source code in the LICENSE file, you can
+# obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance
+# for Open Media Patent License 1.0 was not distributed with this source code in
+# the PATENTS file, you can obtain it at aomedia.org/license/patent-license/.
 #
 if(AOM_AOM_MEM_AOM_MEM_CMAKE_)
   return()
@@ -14,14 +14,16 @@
 set(AOM_AOM_MEM_AOM_MEM_CMAKE_ 1)
 
 list(APPEND AOM_MEM_SOURCES "${AOM_ROOT}/aom_mem/aom_mem.c"
-            "${AOM_ROOT}/aom_mem/aom_mem.h"
-            "${AOM_ROOT}/aom_mem/include/aom_mem_intrnl.h")
+     "${AOM_ROOT}/aom_mem/aom_mem.h"
+     "${AOM_ROOT}/aom_mem/include/aom_mem_intrnl.h")
 
 # Creates the aom_mem build target and makes libaom depend on it. The libaom
 # target must exist before this function is called.
 function(setup_aom_mem_targets)
   add_library(aom_mem OBJECT ${AOM_MEM_SOURCES})
-  set(AOM_LIB_TARGETS ${AOM_LIB_TARGETS} aom_mem PARENT_SCOPE)
+  set(AOM_LIB_TARGETS
+      ${AOM_LIB_TARGETS} aom_mem
+      PARENT_SCOPE)
   target_sources(aom PRIVATE $<TARGET_OBJECTS:aom_mem>)
   if(BUILD_SHARED_LIBS)
     target_sources(aom_static PRIVATE $<TARGET_OBJECTS:aom_mem>)
diff --git a/aom_mem/aom_mem.h b/aom_mem/aom_mem.h
index bc5d8bc..da0fa66 100644
--- a/aom_mem/aom_mem.h
+++ b/aom_mem/aom_mem.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_MEM_AOM_MEM_H_
diff --git a/aom_mem/include/aom_mem_intrnl.h b/aom_mem/include/aom_mem_intrnl.h
index 2c9819d..03e17c6 100644
--- a/aom_mem/include/aom_mem_intrnl.h
+++ b/aom_mem/include/aom_mem_intrnl.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_MEM_INCLUDE_AOM_MEM_INTRNL_H_
diff --git a/aom_ports/aom_once.h b/aom_ports/aom_once.h
index d1a031b..5dc9a18 100644
--- a/aom_ports/aom_once.h
+++ b/aom_ports/aom_once.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_PORTS_AOM_ONCE_H_
diff --git a/aom_ports/aom_ports.cmake b/aom_ports/aom_ports.cmake
index d579896..2e4b5bf 100644
--- a/aom_ports/aom_ports.cmake
+++ b/aom_ports/aom_ports.cmake
@@ -1,39 +1,41 @@
 #
-# Copyright (c) 2017, Alliance for Open Media. All rights reserved
+# Copyright (c) 2021, Alliance for Open Media. All rights reserved
 #
-# This source code is subject to the terms of the BSD 2 Clause License and the
-# Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License was
-# not distributed with this source code in the LICENSE file, you can obtain it
-# at www.aomedia.org/license/software. If the Alliance for Open Media Patent
-# License 1.0 was not distributed with this source code in the PATENTS file, you
-# can obtain it at www.aomedia.org/license/patent.
+# This source code is subject to the terms of the BSD 3-Clause Clear License and
+# the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+# License was not distributed with this source code in the LICENSE file, you can
+# obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance
+# for Open Media Patent License 1.0 was not distributed with this source code in
+# the PATENTS file, you can obtain it at aomedia.org/license/patent-license/.
 #
 if(AOM_AOM_PORTS_AOM_PORTS_CMAKE_)
   return()
 endif() # AOM_AOM_PORTS_AOM_PORTS_CMAKE_
 set(AOM_AOM_PORTS_AOM_PORTS_CMAKE_ 1)
 
-list(APPEND AOM_PORTS_INCLUDES
-            "${AOM_ROOT}/aom_ports/aom_once.h"
-            "${AOM_ROOT}/aom_ports/aom_timer.h"
-            "${AOM_ROOT}/aom_ports/bitops.h"
-            "${AOM_ROOT}/aom_ports/emmintrin_compat.h"
-            "${AOM_ROOT}/aom_ports/mem.h"
-            "${AOM_ROOT}/aom_ports/mem_ops.h"
-            "${AOM_ROOT}/aom_ports/mem_ops_aligned.h"
-            "${AOM_ROOT}/aom_ports/msvc.h"
-            "${AOM_ROOT}/aom_ports/sanitizer.h"
-            "${AOM_ROOT}/aom_ports/system_state.h")
+list(
+  APPEND
+  AOM_PORTS_INCLUDES
+  "${AOM_ROOT}/aom_ports/aom_once.h"
+  "${AOM_ROOT}/aom_ports/aom_timer.h"
+  "${AOM_ROOT}/aom_ports/bitops.h"
+  "${AOM_ROOT}/aom_ports/emmintrin_compat.h"
+  "${AOM_ROOT}/aom_ports/mem.h"
+  "${AOM_ROOT}/aom_ports/mem_ops.h"
+  "${AOM_ROOT}/aom_ports/mem_ops_aligned.h"
+  "${AOM_ROOT}/aom_ports/msvc.h"
+  "${AOM_ROOT}/aom_ports/sanitizer.h"
+  "${AOM_ROOT}/aom_ports/system_state.h")
 
 list(APPEND AOM_PORTS_ASM_X86 "${AOM_ROOT}/aom_ports/emms.asm")
 
 list(APPEND AOM_PORTS_INCLUDES_X86 "${AOM_ROOT}/aom_ports/x86_abi_support.asm")
 
 list(APPEND AOM_PORTS_SOURCES_ARM "${AOM_ROOT}/aom_ports/arm.h"
-            "${AOM_ROOT}/aom_ports/arm_cpudetect.c")
+     "${AOM_ROOT}/aom_ports/arm_cpudetect.c")
 
 list(APPEND AOM_PORTS_SOURCES_PPC "${AOM_ROOT}/aom_ports/ppc.h"
-            "${AOM_ROOT}/aom_ports/ppc_cpudetect.c")
+     "${AOM_ROOT}/aom_ports/ppc_cpudetect.c")
 
 # For arm and x86 targets:
 #
@@ -69,20 +71,22 @@
   if(aom_ports_has_symbols)
     target_sources(aom_ports PRIVATE ${AOM_PORTS_INCLUDES})
 
-    if("${AOM_TARGET_CPU}" STREQUAL "x86"
-       OR "${AOM_TARGET_CPU}" STREQUAL "x86_64")
+    if("${AOM_TARGET_CPU}" STREQUAL "x86" OR "${AOM_TARGET_CPU}" STREQUAL
+                                             "x86_64")
       target_sources(aom_ports PRIVATE ${AOM_PORTS_INCLUDES_X86})
     endif()
 
-    set(AOM_LIB_TARGETS ${AOM_LIB_TARGETS} PARENT_SCOPE)
+    set(AOM_LIB_TARGETS
+        ${AOM_LIB_TARGETS}
+        PARENT_SCOPE)
   else()
     target_sources(aom PRIVATE ${AOM_PORTS_INCLUDES})
     if(BUILD_SHARED_LIBS)
       target_sources(aom_static PRIVATE ${AOM_PORTS_INCLUDES})
     endif()
 
-    if("${AOM_TARGET_CPU}" STREQUAL "x86"
-       OR "${AOM_TARGET_CPU}" STREQUAL "x86_64")
+    if("${AOM_TARGET_CPU}" STREQUAL "x86" OR "${AOM_TARGET_CPU}" STREQUAL
+                                             "x86_64")
       target_sources(aom PRIVATE ${AOM_PORTS_INCLUDES_X86})
       if(BUILD_SHARED_LIBS)
         target_sources(aom_static PRIVATE ${AOM_PORTS_INCLUDES_X86})
diff --git a/aom_ports/aom_timer.h b/aom_ports/aom_timer.h
index 9b17b89..e8bd10d 100644
--- a/aom_ports/aom_timer.h
+++ b/aom_ports/aom_timer.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_PORTS_AOM_TIMER_H_
diff --git a/aom_ports/arm.h b/aom_ports/arm.h
index cb1fb9b..95cd456 100644
--- a/aom_ports/arm.h
+++ b/aom_ports/arm.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_PORTS_ARM_H_
diff --git a/aom_ports/arm_cpudetect.c b/aom_ports/arm_cpudetect.c
index 5a75bb3..c32a730 100644
--- a/aom_ports/arm_cpudetect.c
+++ b/aom_ports/arm_cpudetect.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <stdlib.h>
diff --git a/aom_ports/bitops.h b/aom_ports/bitops.h
index 44df173..2169ceb 100644
--- a/aom_ports/bitops.h
+++ b/aom_ports/bitops.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_PORTS_BITOPS_H_
diff --git a/aom_ports/emmintrin_compat.h b/aom_ports/emmintrin_compat.h
index 85d218a..daf548a 100644
--- a/aom_ports/emmintrin_compat.h
+++ b/aom_ports/emmintrin_compat.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_PORTS_EMMINTRIN_COMPAT_H_
diff --git a/aom_ports/emms.asm b/aom_ports/emms.asm
index 038635d..18493ff 100644
--- a/aom_ports/emms.asm
+++ b/aom_ports/emms.asm
@@ -1,12 +1,12 @@
 ;
-; Copyright (c) 2016, Alliance for Open Media. All rights reserved
+; Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ;
-; This source code is subject to the terms of the BSD 2 Clause License and
-; the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-; was not distributed with this source code in the LICENSE file, you can
-; obtain it at www.aomedia.org/license/software. If the Alliance for Open
-; Media Patent License 1.0 was not distributed with this source code in the
-; PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+; This source code is subject to the terms of the BSD 3-Clause Clear License and the
+; Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+; not distributed with this source code in the LICENSE file, you can obtain it
+; at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+; License 1.0 was not distributed with this source code in the PATENTS file, you
+; can obtain it at aomedia.org/license/patent-license/.
 ;
 
 ;
diff --git a/aom_ports/mem.h b/aom_ports/mem.h
index 9e3d424..9bbd6dc 100644
--- a/aom_ports/mem.h
+++ b/aom_ports/mem.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_PORTS_MEM_H_
@@ -62,6 +63,8 @@
   (((value) + ((1 << (n)) - 1)) & ~((1 << (n)) - 1))
 
 #define DIVIDE_AND_ROUND(x, y) (((x) + ((y) >> 1)) / (y))
+#define DIVIDE_AND_ROUND_SIGNED(n, d) \
+  ((((n) < 0) ^ ((d) < 0)) ? (((n) - (d) / 2) / (d)) : (((n) + (d) / 2) / (d)))
 
 #define CONVERT_TO_SHORTPTR(x) ((uint16_t *)(((uintptr_t)(x)) << 1))
 #define CONVERT_TO_BYTEPTR(x) ((uint8_t *)(((uintptr_t)(x)) >> 1))
diff --git a/aom_ports/mem_ops.h b/aom_ports/mem_ops.h
index 2b5bc0f..3299999 100644
--- a/aom_ports/mem_ops.h
+++ b/aom_ports/mem_ops.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_PORTS_MEM_OPS_H_
diff --git a/aom_ports/mem_ops_aligned.h b/aom_ports/mem_ops_aligned.h
index 37c3675..d1b361d 100644
--- a/aom_ports/mem_ops_aligned.h
+++ b/aom_ports/mem_ops_aligned.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_PORTS_MEM_OPS_ALIGNED_H_
diff --git a/aom_ports/msvc.h b/aom_ports/msvc.h
index e78e605..49c1a12 100644
--- a/aom_ports/msvc.h
+++ b/aom_ports/msvc.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_PORTS_MSVC_H_
diff --git a/aom_ports/ppc.h b/aom_ports/ppc.h
index 3159bda..6500216 100644
--- a/aom_ports/ppc.h
+++ b/aom_ports/ppc.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_PORTS_PPC_H_
diff --git a/aom_ports/ppc_cpudetect.c b/aom_ports/ppc_cpudetect.c
index ce4d5ae..2bf687b 100644
--- a/aom_ports/ppc_cpudetect.c
+++ b/aom_ports/ppc_cpudetect.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <fcntl.h>
diff --git a/aom_ports/sanitizer.h b/aom_ports/sanitizer.h
index 1dd8eb4..8f2b23f 100644
--- a/aom_ports/sanitizer.h
+++ b/aom_ports/sanitizer.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_PORTS_SANITIZER_H_
diff --git a/aom_ports/system_state.h b/aom_ports/system_state.h
index 6640839..2841ad7 100644
--- a/aom_ports/system_state.h
+++ b/aom_ports/system_state.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_PORTS_SYSTEM_STATE_H_
diff --git a/aom_ports/x86.h b/aom_ports/x86.h
index 8c18448..51917a9 100644
--- a/aom_ports/x86.h
+++ b/aom_ports/x86.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_PORTS_X86_H_
diff --git a/aom_ports/x86_abi_support.asm b/aom_ports/x86_abi_support.asm
index f1a65f5..bef8e5b 100644
--- a/aom_ports/x86_abi_support.asm
+++ b/aom_ports/x86_abi_support.asm
@@ -1,12 +1,12 @@
 ;
-; Copyright (c) 2016, Alliance for Open Media. All rights reserved
+; Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ;
-; This source code is subject to the terms of the BSD 2 Clause License and
-; the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-; was not distributed with this source code in the LICENSE file, you can
-; obtain it at www.aomedia.org/license/software. If the Alliance for Open
-; Media Patent License 1.0 was not distributed with this source code in the
-; PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+; This source code is subject to the terms of the BSD 3-Clause Clear License and the
+; Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+; not distributed with this source code in the LICENSE file, you can obtain it
+; at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+; License 1.0 was not distributed with this source code in the PATENTS file, you
+; can obtain it at aomedia.org/license/patent-license/.
 ;
 
 ;
diff --git a/aom_scale/aom_scale.cmake b/aom_scale/aom_scale.cmake
index e832993..d37db18 100644
--- a/aom_scale/aom_scale.cmake
+++ b/aom_scale/aom_scale.cmake
@@ -1,27 +1,30 @@
 #
-# Copyright (c) 2017, Alliance for Open Media. All rights reserved
+# Copyright (c) 2021, Alliance for Open Media. All rights reserved
 #
-# This source code is subject to the terms of the BSD 2 Clause License and the
-# Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License was
-# not distributed with this source code in the LICENSE file, you can obtain it
-# at www.aomedia.org/license/software. If the Alliance for Open Media Patent
-# License 1.0 was not distributed with this source code in the PATENTS file, you
-# can obtain it at www.aomedia.org/license/patent.
+# This source code is subject to the terms of the BSD 3-Clause Clear License and
+# the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+# License was not distributed with this source code in the LICENSE file, you can
+# obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance
+# for Open Media Patent License 1.0 was not distributed with this source code in
+# the PATENTS file, you can obtain it at aomedia.org/license/patent-license/.
 #
 if(AOM_AOM_SCALE_AOM_SCALE_CMAKE_)
   return()
 endif() # AOM_AOM_SCALE_AOM_SCALE_CMAKE_
 set(AOM_AOM_SCALE_AOM_SCALE_CMAKE_ 1)
 
-list(APPEND AOM_SCALE_SOURCES "${AOM_ROOT}/aom_scale/aom_scale.h"
-            "${AOM_ROOT}/aom_scale/generic/aom_scale.c"
-            "${AOM_ROOT}/aom_scale/generic/gen_scalers.c"
-            "${AOM_ROOT}/aom_scale/generic/yv12config.c"
-            "${AOM_ROOT}/aom_scale/generic/yv12extend.c"
-            "${AOM_ROOT}/aom_scale/yv12config.h")
+list(
+  APPEND
+  AOM_SCALE_SOURCES
+  "${AOM_ROOT}/aom_scale/aom_scale.h"
+  "${AOM_ROOT}/aom_scale/generic/aom_scale.c"
+  "${AOM_ROOT}/aom_scale/generic/gen_scalers.c"
+  "${AOM_ROOT}/aom_scale/generic/yv12config.c"
+  "${AOM_ROOT}/aom_scale/generic/yv12extend.c"
+  "${AOM_ROOT}/aom_scale/yv12config.h")
 
 list(APPEND AOM_SCALE_INTRIN_DSPR2
-            "${AOM_ROOT}/aom_scale/mips/dspr2/yv12extend_dspr2.c")
+     "${AOM_ROOT}/aom_scale/mips/dspr2/yv12extend_dspr2.c")
 
 # Creates the aom_scale build target and makes libaom depend on it. The libaom
 # target must exist before this function is called.
@@ -41,5 +44,7 @@
 
   # Pass the new lib targets up to the parent scope instance of
   # $AOM_LIB_TARGETS.
-  set(AOM_LIB_TARGETS ${AOM_LIB_TARGETS} aom_scale PARENT_SCOPE)
+  set(AOM_LIB_TARGETS
+      ${AOM_LIB_TARGETS} aom_scale
+      PARENT_SCOPE)
 endfunction()
diff --git a/aom_scale/aom_scale.h b/aom_scale/aom_scale.h
index 11812a1..0c0a20d 100644
--- a/aom_scale/aom_scale.h
+++ b/aom_scale/aom_scale.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_SCALE_AOM_SCALE_H_
diff --git a/aom_scale/aom_scale_rtcd.c b/aom_scale/aom_scale_rtcd.c
index a04e053..6c1325a 100644
--- a/aom_scale/aom_scale_rtcd.c
+++ b/aom_scale/aom_scale_rtcd.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #include "config/aom_config.h"
 
diff --git a/aom_scale/aom_scale_rtcd.pl b/aom_scale/aom_scale_rtcd.pl
index eef6f16..1399127 100644
--- a/aom_scale/aom_scale_rtcd.pl
+++ b/aom_scale/aom_scale_rtcd.pl
@@ -1,12 +1,12 @@
 ##
-## Copyright (c) 2017, Alliance for Open Media. All rights reserved
+## Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ##
-## This source code is subject to the terms of the BSD 2 Clause License and
-## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-## was not distributed with this source code in the LICENSE file, you can
-## obtain it at www.aomedia.org/license/software. If the Alliance for Open
-## Media Patent License 1.0 was not distributed with this source code in the
-## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+## This source code is subject to the terms of the BSD 3-Clause Clear License and the
+## Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+## not distributed with this source code in the LICENSE file, you can obtain it
+## at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+## License 1.0 was not distributed with this source code in the PATENTS file, you
+## can obtain it at aomedia.org/license/patent-license/.
 ##
 sub aom_scale_forward_decls() {
 print <<EOF
diff --git a/aom_scale/generic/aom_scale.c b/aom_scale/generic/aom_scale.c
index 206c42c..09960a3 100644
--- a/aom_scale/generic/aom_scale.c
+++ b/aom_scale/generic/aom_scale.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 /****************************************************************************
diff --git a/aom_scale/generic/gen_scalers.c b/aom_scale/generic/gen_scalers.c
index 549e2aa..180e8fa 100644
--- a/aom_scale/generic/gen_scalers.c
+++ b/aom_scale/generic/gen_scalers.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "config/aom_scale_rtcd.h"
diff --git a/aom_scale/generic/yv12config.c b/aom_scale/generic/yv12config.c
index d3bc151..dc3668f 100644
--- a/aom_scale/generic/yv12config.c
+++ b/aom_scale/generic/yv12config.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/aom_scale/generic/yv12extend.c b/aom_scale/generic/yv12extend.c
index a0f2788..53937fc 100644
--- a/aom_scale/generic/yv12extend.c
+++ b/aom_scale/generic/yv12extend.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/aom_scale/mips/dspr2/yv12extend_dspr2.c b/aom_scale/mips/dspr2/yv12extend_dspr2.c
index 869e594..d74a49e 100644
--- a/aom_scale/mips/dspr2/yv12extend_dspr2.c
+++ b/aom_scale/mips/dspr2/yv12extend_dspr2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/aom_scale/yv12config.h b/aom_scale/yv12config.h
index ea92c92..6172c77 100644
--- a/aom_scale/yv12config.h
+++ b/aom_scale/yv12config.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_SCALE_YV12CONFIG_H_
diff --git a/aom_util/aom_thread.c b/aom_util/aom_thread.c
index a749a22..5d70b17 100644
--- a/aom_util/aom_thread.c
+++ b/aom_util/aom_thread.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 //
 // Multi-threaded worker
diff --git a/aom_util/aom_thread.h b/aom_util/aom_thread.h
index 8d04312..d942120 100644
--- a/aom_util/aom_thread.h
+++ b/aom_util/aom_thread.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 //
 // Multi-threaded worker
diff --git a/aom_util/aom_util.cmake b/aom_util/aom_util.cmake
index 1a1bfe1..031ae0e 100644
--- a/aom_util/aom_util.cmake
+++ b/aom_util/aom_util.cmake
@@ -1,29 +1,34 @@
 #
-# Copyright (c) 2017, Alliance for Open Media. All rights reserved
+# Copyright (c) 2021, Alliance for Open Media. All rights reserved
 #
-# This source code is subject to the terms of the BSD 2 Clause License and the
-# Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License was
-# not distributed with this source code in the LICENSE file, you can obtain it
-# at www.aomedia.org/license/software. If the Alliance for Open Media Patent
-# License 1.0 was not distributed with this source code in the PATENTS file, you
-# can obtain it at www.aomedia.org/license/patent.
+# This source code is subject to the terms of the BSD 3-Clause Clear License and
+# the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+# License was not distributed with this source code in the LICENSE file, you can
+# obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance
+# for Open Media Patent License 1.0 was not distributed with this source code in
+# the PATENTS file, you can obtain it at aomedia.org/license/patent-license/.
 #
 if(AOM_AOM_UTIL_AOM_UTIL_CMAKE_)
   return()
 endif() # AOM_AOM_UTIL_AOM_UTIL_CMAKE_
 set(AOM_AOM_UTIL_AOM_UTIL_CMAKE_ 1)
 
-list(APPEND AOM_UTIL_SOURCES "${AOM_ROOT}/aom_util/aom_thread.c"
-            "${AOM_ROOT}/aom_util/aom_thread.h"
-            "${AOM_ROOT}/aom_util/endian_inl.h"
-            "${AOM_ROOT}/aom_util/debug_util.c"
-            "${AOM_ROOT}/aom_util/debug_util.h")
+list(
+  APPEND
+  AOM_UTIL_SOURCES
+  "${AOM_ROOT}/aom_util/aom_thread.c"
+  "${AOM_ROOT}/aom_util/aom_thread.h"
+  "${AOM_ROOT}/aom_util/endian_inl.h"
+  "${AOM_ROOT}/aom_util/debug_util.c"
+  "${AOM_ROOT}/aom_util/debug_util.h")
 
 # Creates the aom_util build target and makes libaom depend on it. The libaom
 # target must exist before this function is called.
 function(setup_aom_util_targets)
   add_library(aom_util OBJECT ${AOM_UTIL_SOURCES})
-  set(AOM_LIB_TARGETS ${AOM_LIB_TARGETS} aom_util PARENT_SCOPE)
+  set(AOM_LIB_TARGETS
+      ${AOM_LIB_TARGETS} aom_util
+      PARENT_SCOPE)
   target_sources(aom PRIVATE $<TARGET_OBJECTS:aom_util>)
   if(BUILD_SHARED_LIBS)
     target_sources(aom_static PRIVATE $<TARGET_OBJECTS:aom_util>)
diff --git a/aom_util/debug_util.c b/aom_util/debug_util.c
index a9654fa..462da45 100644
--- a/aom_util/debug_util.c
+++ b/aom_util/debug_util.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/aom_util/debug_util.h b/aom_util/debug_util.h
index 23cad2a..82efde8 100644
--- a/aom_util/debug_util.h
+++ b/aom_util/debug_util.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AOM_UTIL_DEBUG_UTIL_H_
diff --git a/aom_util/endian_inl.h b/aom_util/endian_inl.h
index f536ec5..f94e68b 100644
--- a/aom_util/endian_inl.h
+++ b/aom_util/endian_inl.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 //
 // Endian related functions.
diff --git a/apps/aomdec.c b/apps/aomdec.c
index e42e2f7..3b6a31b 100644
--- a/apps/aomdec.c
+++ b/apps/aomdec.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/apps/aomenc.c b/apps/aomenc.c
index 88ba906..1896301 100644
--- a/apps/aomenc.c
+++ b/apps/aomenc.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "apps/aomenc.h"
@@ -151,9 +152,6 @@
                                         AV1E_SET_ENABLE_ORDER_HINT,
                                         AV1E_SET_ENABLE_TX64,
                                         AV1E_SET_ENABLE_FLIP_IDTX,
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-                                        AV1E_SET_ENABLE_DIST_WTD_COMP,
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
                                         AV1E_SET_ENABLE_MASKED_COMP,
                                         AV1E_SET_ENABLE_ONESIDED_COMP,
                                         AV1E_SET_ENABLE_INTERINTRA_COMP,
@@ -351,9 +349,6 @@
   &g_av1_codec_arg_defs.enable_order_hint,
   &g_av1_codec_arg_defs.enable_tx64,
   &g_av1_codec_arg_defs.enable_flip_idtx,
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-  &g_av1_codec_arg_defs.enable_dist_wtd_comp,
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
   &g_av1_codec_arg_defs.enable_masked_comp,
   &g_av1_codec_arg_defs.enable_onesided_comp,
   &g_av1_codec_arg_defs.enable_interintra_comp,
@@ -444,9 +439,21 @@
 #if CONFIG_IST
   &g_av1_codec_arg_defs.enable_ist,
 #endif
+#if CONFIG_IBP_DC || CONFIG_IBP_DIR
+  &g_av1_codec_arg_defs.enable_ibp,
+#endif
+#if CONFIG_NEW_REF_SIGNALING
+  &g_av1_codec_arg_defs.explicit_ref_frame_map,
+#endif  // CONFIG_NEW_REF_SIGNALING
 #if CONFIG_NEW_INTER_MODES
   &g_av1_codec_arg_defs.max_drl_refmvs,
 #endif  // CONFIG_NEW_INTER_MODES
+#if CONFIG_REF_MV_BANK
+  &g_av1_codec_arg_defs.enable_refmvbank,
+#endif  // CONFIG_REF_MV_BANK
+#if CONFIG_OPTFLOW_REFINEMENT
+  &g_av1_codec_arg_defs.enable_opfl_refine,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 #if CONFIG_CCSO
   &g_av1_codec_arg_defs.enable_ccso,
 #endif
@@ -594,6 +601,9 @@
 #if CONFIG_IST
   config->enable_ist = 1;
 #endif
+#if CONFIG_IBP_DC || CONFIG_IBP_DIR
+  config->enable_ibp = 1;
+#endif
   config->enable_flip_idtx = 1;
   config->enable_deblocking = 1;
   config->enable_cdef = 1;
@@ -604,9 +614,6 @@
   config->enable_obmc = 1;
   config->enable_warped_motion = 1;
   config->enable_global_motion = 1;
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-  config->enable_dist_wtd_comp = 1;
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
   config->enable_diff_wtd_comp = 1;
   config->enable_interintra_comp = 1;
   config->enable_masked_comp = 1;
@@ -620,6 +627,12 @@
   config->enable_dual_filter = 1;
 #endif  // !CONFIG_REMOVE_DUAL_FILTER
   config->enable_angle_delta = 1;
+#if CONFIG_OPTFLOW_REFINEMENT
+  config->enable_opfl_refine = 1;
+#endif  // CONFIG_OPTFLOW_REFINEMENT
+#if CONFIG_NEW_REF_SIGNALING
+  config->explicit_ref_frame_map = 0;
+#endif  // CONFIG_NEW_REF_SIGNALING
   config->enable_intra_edge_filter = 1;
   config->enable_tx64 = 1;
   config->enable_smooth_interintra = 1;
@@ -630,6 +643,9 @@
   config->enable_ref_frame_mvs = 1;
   config->enable_reduced_reference_set = 0;
   config->reduced_tx_type_set = 0;
+#if CONFIG_REF_MV_BANK
+  config->enable_refmvbank = 1;
+#endif
 }
 
 /* Parses global config arguments into the AvxEncoderConfig. Note that
@@ -1374,15 +1390,25 @@
           encoder_cfg->enable_reduced_reference_set);
   fprintf(stdout, "Reduced transform set          : %d\n",
           encoder_cfg->reduced_tx_type_set);
+
+#if CONFIG_NEW_INTER_MODES || CONFIG_REF_MV_BANK
+  fprintf(stdout, "Tool setting (Ref MVs)         :");
 #if CONFIG_NEW_INTER_MODES
-  fprintf(stdout, "Tool setting (Ref MVs)         : max-drl-refmvs (%d)\n",
-          encoder_cfg->max_drl_refmvs);
+  fprintf(stdout, " max-drl-refmvs (%d)", encoder_cfg->max_drl_refmvs);
 #endif  // CONFIG_NEW_INTER_MODES
+#if CONFIG_NEW_INTER_MODES && CONFIG_REF_MV_BANK
+  fprintf(stdout, " ,");
+#endif  // CONFIG_NEW_INTER_MODES && CONFIG_REF_MV_BANK
+#if CONFIG_REF_MV_BANK
+  fprintf(stdout, " Refmv Bank (%d)", encoder_cfg->enable_refmvbank);
+#endif  // CONFIG_REF_MV_BANK
+  fprintf(stdout, "\n");
+#endif  // CONFIG_NEW_INTER_MODES || CONFIG_REF_MV_BANK
 
   fprintf(
       stdout, "Tool setting (Partition)       : T-Type (%d), 4:1/1:4 (%d)\n",
       encoder_cfg->enable_ab_partitions, encoder_cfg->enable_1to4_partitions);
-  fprintf(stdout, "Disable ml transform speed features          : %d\n",
+  fprintf(stdout, "Disable ml tx speed features   : %d\n",
           encoder_cfg->disable_ml_transform_speed_features);
 #if CONFIG_SDP
   fprintf(stdout, "                               : SDP (%d)\n",
@@ -1416,42 +1442,56 @@
 #if CONFIG_ORIP
           ", ORIP(%d)"
 #endif
+#if CONFIG_IBP_DC || CONFIG_IBP_DIR
+          ", IBP(%d)"
+#endif
           "\n",
           encoder_cfg->enable_intra_edge_filter,
 
 #if CONFIG_MRLS
 #if CONFIG_ORIP
+#if CONFIG_IBP_DC || CONFIG_IBP_DIR
+          encoder_cfg->enable_paeth_intra, encoder_cfg->enable_mrls,
+          encoder_cfg->enable_orip, encoder_cfg->enable_ibp);
+#else
           encoder_cfg->enable_paeth_intra, encoder_cfg->enable_mrls,
           encoder_cfg->enable_orip);
+#endif
+#else
+#if CONFIG_IBP_DC || CONFIG_IBP_DIR
+          encoder_cfg->enable_paeth_intra, encoder_cfg->enable_mrls,
+          encoder_cfg->enable_ibp);
 #else
           encoder_cfg->enable_paeth_intra, encoder_cfg->enable_mrls);
 #endif
+#endif
 #else
 #if CONFIG_ORIP
+#if CONFIG_IBP_DC || CONFIG_IBP_DIR
+          encoder_cfg->enable_paeth_intra, encoder_cfg->enable_orip,
+          encoder_cfg->enable_ibp);
+#else
           encoder_cfg->enable_paeth_intra, encoder_cfg->enable_orip);
+#endif
+#else
+#if CONFIG_IBP_DC || CONFIG_IBP_DIR
+          encoder_cfg->enable_paeth_intra, encoder_cfg->enable_ibp);
 #else
           encoder_cfg->enable_paeth_intra);
 #endif
 #endif
+#endif
   fprintf(stdout,
           "Tool setting (Inter)           : OBMC (%d), WarpMotion (%d), "
           "GlobalMotion (%d)\n",
           encoder_cfg->enable_obmc, encoder_cfg->enable_warped_motion,
           encoder_cfg->enable_global_motion);
 
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-  fprintf(stdout,
-          "                               : DistCompound (%d), DiffCompound "
-          "(%d), InterIntra (%d)\n",
-          encoder_cfg->enable_dist_wtd_comp, encoder_cfg->enable_diff_wtd_comp,
-          encoder_cfg->enable_interintra_comp);
-#else
   fprintf(stdout,
           "                               : DiffCompound "
           "(%d), InterIntra (%d)\n",
           encoder_cfg->enable_diff_wtd_comp,
           encoder_cfg->enable_interintra_comp);
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
 
   fprintf(stdout,
           "                               : MaskCompound: (%d), "
@@ -1466,6 +1506,11 @@
           encoder_cfg->enable_interintra_wedge,
           encoder_cfg->enable_ref_frame_mvs);
 
+#if CONFIG_OPTFLOW_REFINEMENT
+  fprintf(stdout, "                               : OptflowRefinement (%d)\n",
+          encoder_cfg->enable_opfl_refine);
+#endif  // CONFIG_OPTFLOW_REFINEMENT
+
   fprintf(stdout,
           "Tool setting (Transform)       : Flip & IDT (%d), TX_64 (%d)\n",
           encoder_cfg->enable_flip_idtx, encoder_cfg->enable_tx64);
diff --git a/apps/aomenc.h b/apps/aomenc.h
index 253867c..f243891 100644
--- a/apps/aomenc.h
+++ b/apps/aomenc.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #ifndef AOM_APPS_AOMENC_H_
 #define AOM_APPS_AOMENC_H_
diff --git a/av1/arg_defs.c b/av1/arg_defs.c
index ebb2469..991c8d0 100644
--- a/av1/arg_defs.c
+++ b/av1/arg_defs.c
@@ -1,12 +1,13 @@
 /*
  * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "av1/arg_defs.h"
@@ -371,6 +372,11 @@
                         "Enable intra secondary transform"
                         "(0: false, 1: true (default))"),
 #endif
+#if CONFIG_IBP_DC || CONFIG_IBP_DIR
+  .enable_ibp = ARG_DEF(NULL, "enable-ibp", 1,
+                        "Enable intra bi-prediction"
+                        "(0: false, 1: true (default))"),
+#endif
   .min_partition_size =
       ARG_DEF(NULL, "min-partition-size", 1,
               "Set min partition size "
@@ -407,12 +413,6 @@
               "ADST_FLIPADST, FLIPADST_ADST, IDTX, V_DCT, H_DCT, V_ADST, "
               "H_ADST, V_FLIPADST, H_FLIPADST"),
 
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-  .enable_dist_wtd_comp = ARG_DEF(NULL, "enable-dist-wtd-comp", 1,
-                                  "Enable distance-weighted compound "
-                                  "(0: false, 1: true (default))"),
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
-
   .enable_masked_comp = ARG_DEF(NULL, "enable-masked-comp", 1,
                                 "Enable masked (wedge/diff-wtd) compound "
                                 "(0: false, 1: true (default))"),
@@ -468,6 +468,13 @@
   .enable_angle_delta =
       ARG_DEF(NULL, "enable-angle-delta", 1,
               "Enable intra angle delta (0: false, 1: true (default))"),
+#if CONFIG_OPTFLOW_REFINEMENT
+  .enable_opfl_refine =
+      ARG_DEF(NULL, "enable-opfl-refine", 1,
+              "Enable optical flow MV refinement (0: off , 1: switchable per "
+              "block (default), 2: used in all blocks with simple compound "
+              "average, 3: auto (swtichable per frame by the encoder))"),
+#endif  // CONFIG_OPTFLOW_REFINEMENT
   .enable_trellis_quant =
       ARG_DEF(NULL, "enable-trellis-quant", 1,
               "Enable trellis optimization of quantized coefficients "
@@ -575,6 +582,12 @@
       ARG_DEF(NULL, "reduced-reference-set", 1,
               "Use reduced set of single and compound references (0: off "
               "(default), 1: on)"),
+#if CONFIG_NEW_REF_SIGNALING
+  .explicit_ref_frame_map =
+      ARG_DEF(NULL, "explicit-ref-frame-map", 1,
+              "Explicitly signal the reference frame mapping (0: off "
+              "(default), 1: on)"),
+#endif  // CONFIG_NEW_REF_SIGNALING
   .target_seq_level_idx = ARG_DEF(
       NULL, "target-seq-level-idx", 1,
       "Target sequence level index. "
@@ -669,6 +682,10 @@
               "maximum number of drl reference MVs per reference. "
               "(0 (auto), 2-8 (fixed)) default is 0 (auto)."),
 #endif  // CONFIG_NEW_INTER_MODES
-
+#if CONFIG_REF_MV_BANK
+  .enable_refmvbank = ARG_DEF(NULL, "enable-refmvbank", 1,
+                              "Enable reference MV bank (0: false "
+                              "1: true)"),
+#endif  // CONFIG_REF_MV_BANK
 #endif  // CONFIG_AV1_ENCODER
 };
diff --git a/av1/arg_defs.h b/av1/arg_defs.h
index 6653b49..f2815eb 100644
--- a/av1/arg_defs.h
+++ b/av1/arg_defs.h
@@ -1,12 +1,13 @@
 /*
  * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #ifndef AOM_AV1_ARG_DEFS_H_
 #define AOM_AV1_ARG_DEFS_H_
@@ -151,6 +152,9 @@
 #if CONFIG_IST
   arg_def_t enable_ist;
 #endif
+#if CONFIG_IBP_DC || CONFIG_IBP_DIR
+  arg_def_t enable_ibp;
+#endif
   arg_def_t min_partition_size;
   arg_def_t max_partition_size;
 #if !CONFIG_REMOVE_DUAL_FILTER
@@ -161,9 +165,6 @@
   arg_def_t enable_order_hint;
   arg_def_t enable_tx64;
   arg_def_t enable_flip_idtx;
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-  arg_def_t enable_dist_wtd_comp;
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
   arg_def_t enable_masked_comp;
   arg_def_t enable_onesided_comp;
   arg_def_t enable_interintra_comp;
@@ -183,6 +184,9 @@
   arg_def_t enable_palette;
   arg_def_t enable_intrabc;
   arg_def_t enable_angle_delta;
+#if CONFIG_OPTFLOW_REFINEMENT
+  arg_def_t enable_opfl_refine;
+#endif  // CONFIG_OPTFLOW_REFINEMENT
   arg_def_t enable_trellis_quant;
   arg_def_t enable_qm;
   arg_def_t qm_min;
@@ -222,6 +226,9 @@
   arg_def_t gf_max_pyr_height;
   arg_def_t max_reference_frames;
   arg_def_t reduced_reference_set;
+#if CONFIG_NEW_REF_SIGNALING
+  arg_def_t explicit_ref_frame_map;
+#endif  // CONFIG_NEW_REF_SIGNALING
   arg_def_t target_seq_level_idx;
   arg_def_t set_min_cr;
   arg_def_t input_color_primaries;
@@ -240,6 +247,9 @@
 #if CONFIG_NEW_INTER_MODES
   arg_def_t max_drl_refmvs;
 #endif  // CONFIG_NEW_INTER_MODES
+#if CONFIG_REF_MV_BANK
+  arg_def_t enable_refmvbank;
+#endif  // CONFIG_REF_MV_BANK
 #endif  // CONFIG_AV1_ENCODER
 } av1_codec_arg_definitions_t;
 
diff --git a/av1/av1.cmake b/av1/av1.cmake
index 6925b68..87ea535 100644
--- a/av1/av1.cmake
+++ b/av1/av1.cmake
@@ -1,96 +1,98 @@
 #
-# Copyright (c) 2017, Alliance for Open Media. All rights reserved
+# Copyright (c) 2021, Alliance for Open Media. All rights reserved
 #
-# This source code is subject to the terms of the BSD 2 Clause License and the
-# Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License was
-# not distributed with this source code in the LICENSE file, you can obtain it
-# at www.aomedia.org/license/software. If the Alliance for Open Media Patent
-# License 1.0 was not distributed with this source code in the PATENTS file, you
-# can obtain it at www.aomedia.org/license/patent.
+# This source code is subject to the terms of the BSD 3-Clause Clear License and
+# the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+# License was not distributed with this source code in the LICENSE file, you can
+# obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance
+# for Open Media Patent License 1.0 was not distributed with this source code in
+# the PATENTS file, you can obtain it at aomedia.org/license/patent-license/.
 #
 if(AOM_AV1_AV1_CMAKE_)
   return()
 endif() # AOM_AV1_AV1_CMAKE_
 set(AOM_AV1_AV1_CMAKE_ 1)
 
-list(APPEND AOM_AV1_COMMON_SOURCES
-            "${AOM_ROOT}/common/args_helper.h"
-            "${AOM_ROOT}/common/args_helper.c"
-            "${AOM_ROOT}/av1/arg_defs.h"
-            "${AOM_ROOT}/av1/arg_defs.c"
-            "${AOM_ROOT}/av1/av1_iface_common.h"
-            "${AOM_ROOT}/av1/common/alloccommon.c"
-            "${AOM_ROOT}/av1/common/alloccommon.h"
-            "${AOM_ROOT}/av1/common/av1_common_int.h"
-            "${AOM_ROOT}/av1/common/av1_inv_txfm1d.c"
-            "${AOM_ROOT}/av1/common/av1_inv_txfm1d.h"
-            "${AOM_ROOT}/av1/common/av1_inv_txfm1d_cfg.h"
-            "${AOM_ROOT}/av1/common/av1_inv_txfm2d.c"
-            "${AOM_ROOT}/av1/common/av1_loopfilter.c"
-            "${AOM_ROOT}/av1/common/av1_loopfilter.h"
-            "${AOM_ROOT}/av1/common/av1_txfm.c"
-            "${AOM_ROOT}/av1/common/av1_txfm.h"
-            "${AOM_ROOT}/av1/common/blockd.c"
-            "${AOM_ROOT}/av1/common/blockd.h"
-            "${AOM_ROOT}/av1/common/cdef.c"
-            "${AOM_ROOT}/av1/common/cdef.h"
-            "${AOM_ROOT}/av1/common/cdef_block.c"
-            "${AOM_ROOT}/av1/common/cdef_block.h"
-            "${AOM_ROOT}/av1/common/cfl.c"
-            "${AOM_ROOT}/av1/common/cfl.h"
-            "${AOM_ROOT}/av1/common/common.h"
-            "${AOM_ROOT}/av1/common/common_data.h"
-            "${AOM_ROOT}/av1/common/convolve.c"
-            "${AOM_ROOT}/av1/common/convolve.h"
-            "${AOM_ROOT}/av1/common/debugmodes.c"
-            "${AOM_ROOT}/av1/common/entropy.c"
-            "${AOM_ROOT}/av1/common/entropy.h"
-            "${AOM_ROOT}/av1/common/entropymode.c"
-            "${AOM_ROOT}/av1/common/entropymode.h"
-            "${AOM_ROOT}/av1/common/entropymv.c"
-            "${AOM_ROOT}/av1/common/entropymv.h"
-            "${AOM_ROOT}/av1/common/enums.h"
-            "${AOM_ROOT}/av1/common/filter.h"
-            "${AOM_ROOT}/av1/common/frame_buffers.c"
-            "${AOM_ROOT}/av1/common/frame_buffers.h"
-            "${AOM_ROOT}/av1/common/idct.c"
-            "${AOM_ROOT}/av1/common/idct.h"
-            "${AOM_ROOT}/av1/common/mv.h"
-            "${AOM_ROOT}/av1/common/mvref_common.c"
-            "${AOM_ROOT}/av1/common/mvref_common.h"
-            "${AOM_ROOT}/av1/common/obu_util.c"
-            "${AOM_ROOT}/av1/common/obu_util.h"
-            "${AOM_ROOT}/av1/common/odintrin.c"
-            "${AOM_ROOT}/av1/common/odintrin.h"
-            "${AOM_ROOT}/av1/common/pred_common.c"
-            "${AOM_ROOT}/av1/common/pred_common.h"
-            "${AOM_ROOT}/av1/common/quant_common.c"
-            "${AOM_ROOT}/av1/common/quant_common.h"
-            "${AOM_ROOT}/av1/common/reconinter.c"
-            "${AOM_ROOT}/av1/common/reconinter.h"
-            "${AOM_ROOT}/av1/common/reconintra.c"
-            "${AOM_ROOT}/av1/common/reconintra.h"
-            "${AOM_ROOT}/av1/common/resize.c"
-            "${AOM_ROOT}/av1/common/resize.h"
-            "${AOM_ROOT}/av1/common/restoration.c"
-            "${AOM_ROOT}/av1/common/restoration.h"
-            "${AOM_ROOT}/av1/common/scale.c"
-            "${AOM_ROOT}/av1/common/scale.h"
-            "${AOM_ROOT}/av1/common/scan.c"
-            "${AOM_ROOT}/av1/common/scan.h"
-            "${AOM_ROOT}/av1/common/seg_common.c"
-            "${AOM_ROOT}/av1/common/seg_common.h"
-            "${AOM_ROOT}/av1/common/thread_common.c"
-            "${AOM_ROOT}/av1/common/thread_common.h"
-            "${AOM_ROOT}/av1/common/tile_common.c"
-            "${AOM_ROOT}/av1/common/tile_common.h"
-            "${AOM_ROOT}/av1/common/timing.c"
-            "${AOM_ROOT}/av1/common/timing.h"
-            "${AOM_ROOT}/av1/common/token_cdfs.h"
-            "${AOM_ROOT}/av1/common/txb_common.c"
-            "${AOM_ROOT}/av1/common/txb_common.h"
-            "${AOM_ROOT}/av1/common/warped_motion.c"
-            "${AOM_ROOT}/av1/common/warped_motion.h")
+list(
+  APPEND
+  AOM_AV1_COMMON_SOURCES
+  "${AOM_ROOT}/common/args_helper.h"
+  "${AOM_ROOT}/common/args_helper.c"
+  "${AOM_ROOT}/av1/arg_defs.h"
+  "${AOM_ROOT}/av1/arg_defs.c"
+  "${AOM_ROOT}/av1/av1_iface_common.h"
+  "${AOM_ROOT}/av1/common/alloccommon.c"
+  "${AOM_ROOT}/av1/common/alloccommon.h"
+  "${AOM_ROOT}/av1/common/av1_common_int.h"
+  "${AOM_ROOT}/av1/common/av1_inv_txfm1d.c"
+  "${AOM_ROOT}/av1/common/av1_inv_txfm1d.h"
+  "${AOM_ROOT}/av1/common/av1_inv_txfm1d_cfg.h"
+  "${AOM_ROOT}/av1/common/av1_inv_txfm2d.c"
+  "${AOM_ROOT}/av1/common/av1_loopfilter.c"
+  "${AOM_ROOT}/av1/common/av1_loopfilter.h"
+  "${AOM_ROOT}/av1/common/av1_txfm.c"
+  "${AOM_ROOT}/av1/common/av1_txfm.h"
+  "${AOM_ROOT}/av1/common/blockd.c"
+  "${AOM_ROOT}/av1/common/blockd.h"
+  "${AOM_ROOT}/av1/common/cdef.c"
+  "${AOM_ROOT}/av1/common/cdef.h"
+  "${AOM_ROOT}/av1/common/cdef_block.c"
+  "${AOM_ROOT}/av1/common/cdef_block.h"
+  "${AOM_ROOT}/av1/common/cfl.c"
+  "${AOM_ROOT}/av1/common/cfl.h"
+  "${AOM_ROOT}/av1/common/common.h"
+  "${AOM_ROOT}/av1/common/common_data.h"
+  "${AOM_ROOT}/av1/common/convolve.c"
+  "${AOM_ROOT}/av1/common/convolve.h"
+  "${AOM_ROOT}/av1/common/debugmodes.c"
+  "${AOM_ROOT}/av1/common/entropy.c"
+  "${AOM_ROOT}/av1/common/entropy.h"
+  "${AOM_ROOT}/av1/common/entropymode.c"
+  "${AOM_ROOT}/av1/common/entropymode.h"
+  "${AOM_ROOT}/av1/common/entropymv.c"
+  "${AOM_ROOT}/av1/common/entropymv.h"
+  "${AOM_ROOT}/av1/common/enums.h"
+  "${AOM_ROOT}/av1/common/filter.h"
+  "${AOM_ROOT}/av1/common/frame_buffers.c"
+  "${AOM_ROOT}/av1/common/frame_buffers.h"
+  "${AOM_ROOT}/av1/common/idct.c"
+  "${AOM_ROOT}/av1/common/idct.h"
+  "${AOM_ROOT}/av1/common/mv.h"
+  "${AOM_ROOT}/av1/common/mvref_common.c"
+  "${AOM_ROOT}/av1/common/mvref_common.h"
+  "${AOM_ROOT}/av1/common/obu_util.c"
+  "${AOM_ROOT}/av1/common/obu_util.h"
+  "${AOM_ROOT}/av1/common/odintrin.c"
+  "${AOM_ROOT}/av1/common/odintrin.h"
+  "${AOM_ROOT}/av1/common/pred_common.c"
+  "${AOM_ROOT}/av1/common/pred_common.h"
+  "${AOM_ROOT}/av1/common/quant_common.c"
+  "${AOM_ROOT}/av1/common/quant_common.h"
+  "${AOM_ROOT}/av1/common/reconinter.c"
+  "${AOM_ROOT}/av1/common/reconinter.h"
+  "${AOM_ROOT}/av1/common/reconintra.c"
+  "${AOM_ROOT}/av1/common/reconintra.h"
+  "${AOM_ROOT}/av1/common/resize.c"
+  "${AOM_ROOT}/av1/common/resize.h"
+  "${AOM_ROOT}/av1/common/restoration.c"
+  "${AOM_ROOT}/av1/common/restoration.h"
+  "${AOM_ROOT}/av1/common/scale.c"
+  "${AOM_ROOT}/av1/common/scale.h"
+  "${AOM_ROOT}/av1/common/scan.c"
+  "${AOM_ROOT}/av1/common/scan.h"
+  "${AOM_ROOT}/av1/common/seg_common.c"
+  "${AOM_ROOT}/av1/common/seg_common.h"
+  "${AOM_ROOT}/av1/common/thread_common.c"
+  "${AOM_ROOT}/av1/common/thread_common.h"
+  "${AOM_ROOT}/av1/common/tile_common.c"
+  "${AOM_ROOT}/av1/common/tile_common.h"
+  "${AOM_ROOT}/av1/common/timing.c"
+  "${AOM_ROOT}/av1/common/timing.h"
+  "${AOM_ROOT}/av1/common/token_cdfs.h"
+  "${AOM_ROOT}/av1/common/txb_common.c"
+  "${AOM_ROOT}/av1/common/txb_common.h"
+  "${AOM_ROOT}/av1/common/warped_motion.c"
+  "${AOM_ROOT}/av1/common/warped_motion.h")
 
 if(CONFIG_LPF_MASK)
   list(APPEND AOM_AV1_COMMON_SOURCES "${AOM_ROOT}/av1/common/loopfiltermask.c")
@@ -98,326 +100,355 @@
 
 if(CONFIG_CCSO)
   list(APPEND AOM_AV1_COMMON_SOURCES "${AOM_ROOT}/av1/common/ccso.c"
-              "${AOM_ROOT}/av1/common/ccso.h")
+       "${AOM_ROOT}/av1/common/ccso.h")
   list(APPEND AOM_AV1_ENCODER_SOURCES "${AOM_ROOT}/av1/encoder/pickccso.c"
-              "${AOM_ROOT}/av1/encoder/pickccso.h")
+       "${AOM_ROOT}/av1/encoder/pickccso.h")
 endif()
 
-list(APPEND AOM_AV1_DECODER_SOURCES
-            "${AOM_ROOT}/av1/av1_dx_iface.c"
-            "${AOM_ROOT}/av1/decoder/decodeframe.c"
-            "${AOM_ROOT}/av1/decoder/decodeframe.h"
-            "${AOM_ROOT}/av1/decoder/decodemv.c"
-            "${AOM_ROOT}/av1/decoder/decodemv.h"
-            "${AOM_ROOT}/av1/decoder/decoder.c"
-            "${AOM_ROOT}/av1/decoder/decoder.h"
-            "${AOM_ROOT}/av1/decoder/decodetxb.c"
-            "${AOM_ROOT}/av1/decoder/decodetxb.h"
-            "${AOM_ROOT}/av1/decoder/detokenize.c"
-            "${AOM_ROOT}/av1/decoder/detokenize.h"
-            "${AOM_ROOT}/av1/decoder/dthread.h"
-            "${AOM_ROOT}/av1/decoder/obu.h"
-            "${AOM_ROOT}/av1/decoder/obu.c")
+list(
+  APPEND
+  AOM_AV1_DECODER_SOURCES
+  "${AOM_ROOT}/av1/av1_dx_iface.c"
+  "${AOM_ROOT}/av1/decoder/decodeframe.c"
+  "${AOM_ROOT}/av1/decoder/decodeframe.h"
+  "${AOM_ROOT}/av1/decoder/decodemv.c"
+  "${AOM_ROOT}/av1/decoder/decodemv.h"
+  "${AOM_ROOT}/av1/decoder/decoder.c"
+  "${AOM_ROOT}/av1/decoder/decoder.h"
+  "${AOM_ROOT}/av1/decoder/decodetxb.c"
+  "${AOM_ROOT}/av1/decoder/decodetxb.h"
+  "${AOM_ROOT}/av1/decoder/detokenize.c"
+  "${AOM_ROOT}/av1/decoder/detokenize.h"
+  "${AOM_ROOT}/av1/decoder/dthread.h"
+  "${AOM_ROOT}/av1/decoder/obu.h"
+  "${AOM_ROOT}/av1/decoder/obu.c")
 
-list(APPEND AOM_AV1_ENCODER_SOURCES
-            "${AOM_ROOT}/av1/av1_cx_iface.c"
-            "${AOM_ROOT}/av1/encoder/aq_complexity.c"
-            "${AOM_ROOT}/av1/encoder/aq_complexity.h"
-            "${AOM_ROOT}/av1/encoder/aq_cyclicrefresh.c"
-            "${AOM_ROOT}/av1/encoder/aq_cyclicrefresh.h"
-            "${AOM_ROOT}/av1/encoder/aq_variance.c"
-            "${AOM_ROOT}/av1/encoder/aq_variance.h"
-            "${AOM_ROOT}/av1/encoder/enc_enums.h"
-            "${AOM_ROOT}/av1/encoder/av1_fwd_txfm1d.c"
-            "${AOM_ROOT}/av1/encoder/av1_fwd_txfm1d.h"
-            "${AOM_ROOT}/av1/encoder/av1_fwd_txfm1d_cfg.h"
-            "${AOM_ROOT}/av1/encoder/av1_fwd_txfm2d.c"
-            "${AOM_ROOT}/av1/encoder/av1_quantize.c"
-            "${AOM_ROOT}/av1/encoder/av1_quantize.h"
-            "${AOM_ROOT}/av1/encoder/bitstream.c"
-            "${AOM_ROOT}/av1/encoder/bitstream.h"
-            "${AOM_ROOT}/av1/encoder/block.h"
-            "${AOM_ROOT}/av1/encoder/cnn.c"
-            "${AOM_ROOT}/av1/encoder/cnn.h"
-            "${AOM_ROOT}/av1/encoder/compound_type.c"
-            "${AOM_ROOT}/av1/encoder/compound_type.h"
-            "${AOM_ROOT}/av1/encoder/context_tree.c"
-            "${AOM_ROOT}/av1/encoder/context_tree.h"
-            "${AOM_ROOT}/av1/encoder/corner_detect.c"
-            "${AOM_ROOT}/av1/encoder/corner_detect.h"
-            "${AOM_ROOT}/av1/encoder/corner_match.c"
-            "${AOM_ROOT}/av1/encoder/corner_match.h"
-            "${AOM_ROOT}/av1/encoder/cost.c"
-            "${AOM_ROOT}/av1/encoder/cost.h"
-            "${AOM_ROOT}/av1/encoder/encodeframe.c"
-            "${AOM_ROOT}/av1/encoder/encodeframe.h"
-            "${AOM_ROOT}/av1/encoder/encodeframe_utils.c"
-            "${AOM_ROOT}/av1/encoder/encodeframe_utils.h"
-            "${AOM_ROOT}/av1/encoder/encodemb.c"
-            "${AOM_ROOT}/av1/encoder/encodemb.h"
-            "${AOM_ROOT}/av1/encoder/encodemv.c"
-            "${AOM_ROOT}/av1/encoder/encodemv.h"
-            "${AOM_ROOT}/av1/encoder/encode_strategy.c"
-            "${AOM_ROOT}/av1/encoder/encode_strategy.h"
-            "${AOM_ROOT}/av1/encoder/encoder.c"
-            "${AOM_ROOT}/av1/encoder/encoder.h"
-            "${AOM_ROOT}/av1/encoder/encoder_alloc.h"
-            "${AOM_ROOT}/av1/encoder/encoder_utils.c"
-            "${AOM_ROOT}/av1/encoder/encoder_utils.h"
-            "${AOM_ROOT}/av1/encoder/encodetxb.c"
-            "${AOM_ROOT}/av1/encoder/encodetxb.h"
-            "${AOM_ROOT}/av1/encoder/ethread.c"
-            "${AOM_ROOT}/av1/encoder/ethread.h"
-            "${AOM_ROOT}/av1/encoder/extend.c"
-            "${AOM_ROOT}/av1/encoder/extend.h"
-            "${AOM_ROOT}/av1/encoder/firstpass.c"
-            "${AOM_ROOT}/av1/encoder/firstpass.h"
-            "${AOM_ROOT}/av1/encoder/global_motion.c"
-            "${AOM_ROOT}/av1/encoder/global_motion.h"
-            "${AOM_ROOT}/av1/encoder/global_motion_facade.c"
-            "${AOM_ROOT}/av1/encoder/global_motion_facade.h"
-            "${AOM_ROOT}/av1/encoder/gop_structure.c"
-            "${AOM_ROOT}/av1/encoder/gop_structure.h"
-            "${AOM_ROOT}/av1/encoder/grain_test_vectors.h"
-            "${AOM_ROOT}/av1/encoder/hash.c"
-            "${AOM_ROOT}/av1/encoder/hash.h"
-            "${AOM_ROOT}/av1/encoder/hash_motion.c"
-            "${AOM_ROOT}/av1/encoder/hash_motion.h"
-            "${AOM_ROOT}/av1/encoder/hybrid_fwd_txfm.c"
-            "${AOM_ROOT}/av1/encoder/hybrid_fwd_txfm.h"
-            "${AOM_ROOT}/av1/encoder/interp_search.c"
-            "${AOM_ROOT}/av1/encoder/interp_search.h"
-            "${AOM_ROOT}/av1/encoder/level.c"
-            "${AOM_ROOT}/av1/encoder/level.h"
-            "${AOM_ROOT}/av1/encoder/lookahead.c"
-            "${AOM_ROOT}/av1/encoder/lookahead.h"
-            "${AOM_ROOT}/av1/encoder/mcomp.c"
-            "${AOM_ROOT}/av1/encoder/mcomp.h"
-            "${AOM_ROOT}/av1/encoder/ml.c"
-            "${AOM_ROOT}/av1/encoder/ml.h"
-            "${AOM_ROOT}/av1/encoder/model_rd.h"
-            "${AOM_ROOT}/av1/encoder/motion_search_facade.c"
-            "${AOM_ROOT}/av1/encoder/motion_search_facade.h"
-            "${AOM_ROOT}/av1/encoder/mv_prec.c"
-            "${AOM_ROOT}/av1/encoder/mv_prec.h"
-            "${AOM_ROOT}/av1/encoder/palette.c"
-            "${AOM_ROOT}/av1/encoder/palette.h"
-            "${AOM_ROOT}/av1/encoder/partition_search.h"
-            "${AOM_ROOT}/av1/encoder/partition_search.c"
-            "${AOM_ROOT}/av1/encoder/partition_strategy.h"
-            "${AOM_ROOT}/av1/encoder/partition_strategy.c"
-            "${AOM_ROOT}/av1/encoder/pass2_strategy.h"
-            "${AOM_ROOT}/av1/encoder/pass2_strategy.c"
-            "${AOM_ROOT}/av1/encoder/pickcdef.c"
-            "${AOM_ROOT}/av1/encoder/pickcdef.h"
-            "${AOM_ROOT}/av1/encoder/picklpf.c"
-            "${AOM_ROOT}/av1/encoder/picklpf.h"
-            "${AOM_ROOT}/av1/encoder/pickrst.c"
-            "${AOM_ROOT}/av1/encoder/pickrst.h"
-            "${AOM_ROOT}/av1/encoder/ransac.c"
-            "${AOM_ROOT}/av1/encoder/ransac.h"
-            "${AOM_ROOT}/av1/encoder/ratectrl.c"
-            "${AOM_ROOT}/av1/encoder/ratectrl.h"
-            "${AOM_ROOT}/av1/encoder/rc_utils.h"
-            "${AOM_ROOT}/av1/encoder/rd.c"
-            "${AOM_ROOT}/av1/encoder/rd.h"
-            "${AOM_ROOT}/av1/encoder/rdopt.c"
-            "${AOM_ROOT}/av1/encoder/rdopt.h"
-            "${AOM_ROOT}/av1/encoder/rdopt_data_defs.h"
-            "${AOM_ROOT}/av1/encoder/rdopt_utils.h"
-            "${AOM_ROOT}/av1/encoder/reconinter_enc.c"
-            "${AOM_ROOT}/av1/encoder/reconinter_enc.h"
-            "${AOM_ROOT}/av1/encoder/segmentation.c"
-            "${AOM_ROOT}/av1/encoder/segmentation.h"
-            "${AOM_ROOT}/av1/encoder/speed_features.c"
-            "${AOM_ROOT}/av1/encoder/speed_features.h"
-            "${AOM_ROOT}/av1/encoder/subgop.c"
-            "${AOM_ROOT}/av1/encoder/subgop.h"
-            "${AOM_ROOT}/av1/encoder/superres_scale.c"
-            "${AOM_ROOT}/av1/encoder/superres_scale.h"
-            "${AOM_ROOT}/av1/encoder/svc_layercontext.c"
-            "${AOM_ROOT}/av1/encoder/svc_layercontext.h"
-            "${AOM_ROOT}/av1/encoder/temporal_filter.c"
-            "${AOM_ROOT}/av1/encoder/temporal_filter.h"
-            "${AOM_ROOT}/av1/encoder/tokenize.c"
-            "${AOM_ROOT}/av1/encoder/tokenize.h"
-            "${AOM_ROOT}/av1/encoder/tpl_model.c"
-            "${AOM_ROOT}/av1/encoder/tpl_model.h"
-            "${AOM_ROOT}/av1/encoder/tx_search.c"
-            "${AOM_ROOT}/av1/encoder/tx_search.h"
-            "${AOM_ROOT}/av1/encoder/intra_mode_search.c"
-            "${AOM_ROOT}/av1/encoder/intra_mode_search.h"
-            "${AOM_ROOT}/av1/encoder/intra_mode_search_utils.h"
-            "${AOM_ROOT}/av1/encoder/wedge_utils.c"
-            "${AOM_ROOT}/av1/encoder/av1_noise_estimate.c"
-            "${AOM_ROOT}/av1/encoder/av1_noise_estimate.h"
-            "${AOM_ROOT}/third_party/fastfeat/fast.c"
-            "${AOM_ROOT}/third_party/fastfeat/fast.h"
-            "${AOM_ROOT}/third_party/fastfeat/fast_9.c"
-            "${AOM_ROOT}/third_party/fastfeat/nonmax.c"
-            "${AOM_ROOT}/third_party/vector/vector.c"
-            "${AOM_ROOT}/third_party/vector/vector.h"
-            "${AOM_ROOT}/av1/encoder/dwt.c"
-            "${AOM_ROOT}/av1/encoder/dwt.h")
+list(
+  APPEND
+  AOM_AV1_ENCODER_SOURCES
+  "${AOM_ROOT}/av1/av1_cx_iface.c"
+  "${AOM_ROOT}/av1/encoder/aq_complexity.c"
+  "${AOM_ROOT}/av1/encoder/aq_complexity.h"
+  "${AOM_ROOT}/av1/encoder/aq_cyclicrefresh.c"
+  "${AOM_ROOT}/av1/encoder/aq_cyclicrefresh.h"
+  "${AOM_ROOT}/av1/encoder/aq_variance.c"
+  "${AOM_ROOT}/av1/encoder/aq_variance.h"
+  "${AOM_ROOT}/av1/encoder/enc_enums.h"
+  "${AOM_ROOT}/av1/encoder/av1_fwd_txfm1d.c"
+  "${AOM_ROOT}/av1/encoder/av1_fwd_txfm1d.h"
+  "${AOM_ROOT}/av1/encoder/av1_fwd_txfm1d_cfg.h"
+  "${AOM_ROOT}/av1/encoder/av1_fwd_txfm2d.c"
+  "${AOM_ROOT}/av1/encoder/av1_quantize.c"
+  "${AOM_ROOT}/av1/encoder/av1_quantize.h"
+  "${AOM_ROOT}/av1/encoder/bitstream.c"
+  "${AOM_ROOT}/av1/encoder/bitstream.h"
+  "${AOM_ROOT}/av1/encoder/block.h"
+  "${AOM_ROOT}/av1/encoder/cnn.c"
+  "${AOM_ROOT}/av1/encoder/cnn.h"
+  "${AOM_ROOT}/av1/encoder/compound_type.c"
+  "${AOM_ROOT}/av1/encoder/compound_type.h"
+  "${AOM_ROOT}/av1/encoder/context_tree.c"
+  "${AOM_ROOT}/av1/encoder/context_tree.h"
+  "${AOM_ROOT}/av1/encoder/corner_detect.c"
+  "${AOM_ROOT}/av1/encoder/corner_detect.h"
+  "${AOM_ROOT}/av1/encoder/corner_match.c"
+  "${AOM_ROOT}/av1/encoder/corner_match.h"
+  "${AOM_ROOT}/av1/encoder/cost.c"
+  "${AOM_ROOT}/av1/encoder/cost.h"
+  "${AOM_ROOT}/av1/encoder/encodeframe.c"
+  "${AOM_ROOT}/av1/encoder/encodeframe.h"
+  "${AOM_ROOT}/av1/encoder/encodeframe_utils.c"
+  "${AOM_ROOT}/av1/encoder/encodeframe_utils.h"
+  "${AOM_ROOT}/av1/encoder/encodemb.c"
+  "${AOM_ROOT}/av1/encoder/encodemb.h"
+  "${AOM_ROOT}/av1/encoder/encodemv.c"
+  "${AOM_ROOT}/av1/encoder/encodemv.h"
+  "${AOM_ROOT}/av1/encoder/encode_strategy.c"
+  "${AOM_ROOT}/av1/encoder/encode_strategy.h"
+  "${AOM_ROOT}/av1/encoder/encoder.c"
+  "${AOM_ROOT}/av1/encoder/encoder.h"
+  "${AOM_ROOT}/av1/encoder/encoder_alloc.h"
+  "${AOM_ROOT}/av1/encoder/encoder_utils.c"
+  "${AOM_ROOT}/av1/encoder/encoder_utils.h"
+  "${AOM_ROOT}/av1/encoder/encodetxb.c"
+  "${AOM_ROOT}/av1/encoder/encodetxb.h"
+  "${AOM_ROOT}/av1/encoder/ethread.c"
+  "${AOM_ROOT}/av1/encoder/ethread.h"
+  "${AOM_ROOT}/av1/encoder/extend.c"
+  "${AOM_ROOT}/av1/encoder/extend.h"
+  "${AOM_ROOT}/av1/encoder/firstpass.c"
+  "${AOM_ROOT}/av1/encoder/firstpass.h"
+  "${AOM_ROOT}/av1/encoder/global_motion.c"
+  "${AOM_ROOT}/av1/encoder/global_motion.h"
+  "${AOM_ROOT}/av1/encoder/global_motion_facade.c"
+  "${AOM_ROOT}/av1/encoder/global_motion_facade.h"
+  "${AOM_ROOT}/av1/encoder/gop_structure.c"
+  "${AOM_ROOT}/av1/encoder/gop_structure.h"
+  "${AOM_ROOT}/av1/encoder/grain_test_vectors.h"
+  "${AOM_ROOT}/av1/encoder/hash.c"
+  "${AOM_ROOT}/av1/encoder/hash.h"
+  "${AOM_ROOT}/av1/encoder/hash_motion.c"
+  "${AOM_ROOT}/av1/encoder/hash_motion.h"
+  "${AOM_ROOT}/av1/encoder/hybrid_fwd_txfm.c"
+  "${AOM_ROOT}/av1/encoder/hybrid_fwd_txfm.h"
+  "${AOM_ROOT}/av1/encoder/interp_search.c"
+  "${AOM_ROOT}/av1/encoder/interp_search.h"
+  "${AOM_ROOT}/av1/encoder/level.c"
+  "${AOM_ROOT}/av1/encoder/level.h"
+  "${AOM_ROOT}/av1/encoder/lookahead.c"
+  "${AOM_ROOT}/av1/encoder/lookahead.h"
+  "${AOM_ROOT}/av1/encoder/mcomp.c"
+  "${AOM_ROOT}/av1/encoder/mcomp.h"
+  "${AOM_ROOT}/av1/encoder/ml.c"
+  "${AOM_ROOT}/av1/encoder/ml.h"
+  "${AOM_ROOT}/av1/encoder/model_rd.h"
+  "${AOM_ROOT}/av1/encoder/motion_search_facade.c"
+  "${AOM_ROOT}/av1/encoder/motion_search_facade.h"
+  "${AOM_ROOT}/av1/encoder/mv_prec.c"
+  "${AOM_ROOT}/av1/encoder/mv_prec.h"
+  "${AOM_ROOT}/av1/encoder/palette.c"
+  "${AOM_ROOT}/av1/encoder/palette.h"
+  "${AOM_ROOT}/av1/encoder/partition_search.h"
+  "${AOM_ROOT}/av1/encoder/partition_search.c"
+  "${AOM_ROOT}/av1/encoder/partition_strategy.h"
+  "${AOM_ROOT}/av1/encoder/partition_strategy.c"
+  "${AOM_ROOT}/av1/encoder/pass2_strategy.h"
+  "${AOM_ROOT}/av1/encoder/pass2_strategy.c"
+  "${AOM_ROOT}/av1/encoder/pickcdef.c"
+  "${AOM_ROOT}/av1/encoder/pickcdef.h"
+  "${AOM_ROOT}/av1/encoder/picklpf.c"
+  "${AOM_ROOT}/av1/encoder/picklpf.h"
+  "${AOM_ROOT}/av1/encoder/pickrst.c"
+  "${AOM_ROOT}/av1/encoder/pickrst.h"
+  "${AOM_ROOT}/av1/encoder/ransac.c"
+  "${AOM_ROOT}/av1/encoder/ransac.h"
+  "${AOM_ROOT}/av1/encoder/ratectrl.c"
+  "${AOM_ROOT}/av1/encoder/ratectrl.h"
+  "${AOM_ROOT}/av1/encoder/rc_utils.h"
+  "${AOM_ROOT}/av1/encoder/rd.c"
+  "${AOM_ROOT}/av1/encoder/rd.h"
+  "${AOM_ROOT}/av1/encoder/rdopt.c"
+  "${AOM_ROOT}/av1/encoder/rdopt.h"
+  "${AOM_ROOT}/av1/encoder/rdopt_data_defs.h"
+  "${AOM_ROOT}/av1/encoder/rdopt_utils.h"
+  "${AOM_ROOT}/av1/encoder/reconinter_enc.c"
+  "${AOM_ROOT}/av1/encoder/reconinter_enc.h"
+  "${AOM_ROOT}/av1/encoder/segmentation.c"
+  "${AOM_ROOT}/av1/encoder/segmentation.h"
+  "${AOM_ROOT}/av1/encoder/speed_features.c"
+  "${AOM_ROOT}/av1/encoder/speed_features.h"
+  "${AOM_ROOT}/av1/encoder/subgop.c"
+  "${AOM_ROOT}/av1/encoder/subgop.h"
+  "${AOM_ROOT}/av1/encoder/superres_scale.c"
+  "${AOM_ROOT}/av1/encoder/superres_scale.h"
+  "${AOM_ROOT}/av1/encoder/temporal_filter.c"
+  "${AOM_ROOT}/av1/encoder/temporal_filter.h"
+  "${AOM_ROOT}/av1/encoder/tokenize.c"
+  "${AOM_ROOT}/av1/encoder/tokenize.h"
+  "${AOM_ROOT}/av1/encoder/tpl_model.c"
+  "${AOM_ROOT}/av1/encoder/tpl_model.h"
+  "${AOM_ROOT}/av1/encoder/tx_search.c"
+  "${AOM_ROOT}/av1/encoder/tx_search.h"
+  "${AOM_ROOT}/av1/encoder/intra_mode_search.c"
+  "${AOM_ROOT}/av1/encoder/intra_mode_search.h"
+  "${AOM_ROOT}/av1/encoder/intra_mode_search_utils.h"
+  "${AOM_ROOT}/av1/encoder/wedge_utils.c"
+  "${AOM_ROOT}/av1/encoder/av1_noise_estimate.c"
+  "${AOM_ROOT}/av1/encoder/av1_noise_estimate.h"
+  "${AOM_ROOT}/third_party/fastfeat/fast.c"
+  "${AOM_ROOT}/third_party/fastfeat/fast.h"
+  "${AOM_ROOT}/third_party/fastfeat/fast_9.c"
+  "${AOM_ROOT}/third_party/fastfeat/nonmax.c"
+  "${AOM_ROOT}/third_party/vector/vector.c"
+  "${AOM_ROOT}/third_party/vector/vector.h"
+  "${AOM_ROOT}/av1/encoder/dwt.c"
+  "${AOM_ROOT}/av1/encoder/dwt.h")
+
+if(CONFIG_SVC_ENCODER)
+  list(APPEND AOM_AV1_ENCODER_SOURCES
+       "${AOM_ROOT}/av1/encoder/svc_layercontext.c"
+       "${AOM_ROOT}/av1/encoder/svc_layercontext.h")
+endif()
 
 if(CONFIG_TUNE_VMAF)
   list(APPEND AOM_AV1_ENCODER_SOURCES "${AOM_ROOT}/av1/encoder/tune_vmaf.c"
-              "${AOM_ROOT}/av1/encoder/tune_vmaf.h")
+       "${AOM_ROOT}/av1/encoder/tune_vmaf.h")
 endif()
 
 if(CONFIG_OPTICAL_FLOW_API)
   list(APPEND AOM_AV1_ENCODER_SOURCES "${AOM_ROOT}/av1/encoder/optical_flow.c"
-              "${AOM_ROOT}/av1/encoder/optical_flow.h")
+       "${AOM_ROOT}/av1/encoder/optical_flow.h")
 endif()
 
-list(APPEND AOM_AV1_COMMON_INTRIN_SSE2
-            "${AOM_ROOT}/av1/common/cdef_block_sse2.c"
-            "${AOM_ROOT}/av1/common/x86/cfl_sse2.c"
-            "${AOM_ROOT}/av1/common/x86/convolve_2d_sse2.c"
-            "${AOM_ROOT}/av1/common/x86/convolve_sse2.c"
-            "${AOM_ROOT}/av1/common/x86/jnt_convolve_sse2.c"
-            "${AOM_ROOT}/av1/common/x86/wiener_convolve_sse2.c"
-            "${AOM_ROOT}/av1/common/x86/av1_txfm_sse2.h"
-            "${AOM_ROOT}/av1/common/x86/warp_plane_sse2.c")
+list(
+  APPEND
+  AOM_AV1_COMMON_INTRIN_SSE2
+  "${AOM_ROOT}/av1/common/cdef_block_sse2.c"
+  "${AOM_ROOT}/av1/common/x86/cfl_sse2.c"
+  "${AOM_ROOT}/av1/common/x86/convolve_2d_sse2.c"
+  "${AOM_ROOT}/av1/common/x86/convolve_sse2.c"
+  "${AOM_ROOT}/av1/common/x86/jnt_convolve_sse2.c"
+  "${AOM_ROOT}/av1/common/x86/wiener_convolve_sse2.c"
+  "${AOM_ROOT}/av1/common/x86/av1_txfm_sse2.h"
+  "${AOM_ROOT}/av1/common/x86/warp_plane_sse2.c")
 
-list(APPEND AOM_AV1_COMMON_INTRIN_SSSE3
-            "${AOM_ROOT}/av1/common/cdef_block_ssse3.c"
-            "${AOM_ROOT}/av1/common/x86/av1_inv_txfm_ssse3.c"
-            "${AOM_ROOT}/av1/common/x86/av1_inv_txfm_ssse3.h"
-            "${AOM_ROOT}/av1/common/x86/cfl_ssse3.c"
-            "${AOM_ROOT}/av1/common/x86/highbd_convolve_2d_ssse3.c"
-            "${AOM_ROOT}/av1/common/x86/highbd_wiener_convolve_ssse3.c"
-            "${AOM_ROOT}/av1/common/x86/jnt_convolve_ssse3.c"
-            "${AOM_ROOT}/av1/common/x86/reconinter_ssse3.c"
-            "${AOM_ROOT}/av1/common/x86/resize_ssse3.c")
+list(
+  APPEND
+  AOM_AV1_COMMON_INTRIN_SSSE3
+  "${AOM_ROOT}/av1/common/cdef_block_ssse3.c"
+  "${AOM_ROOT}/av1/common/x86/av1_inv_txfm_ssse3.c"
+  "${AOM_ROOT}/av1/common/x86/av1_inv_txfm_ssse3.h"
+  "${AOM_ROOT}/av1/common/x86/cfl_ssse3.c"
+  "${AOM_ROOT}/av1/common/x86/highbd_convolve_2d_ssse3.c"
+  "${AOM_ROOT}/av1/common/x86/highbd_wiener_convolve_ssse3.c"
+  "${AOM_ROOT}/av1/common/x86/jnt_convolve_ssse3.c"
+  "${AOM_ROOT}/av1/common/x86/reconinter_ssse3.c"
+  "${AOM_ROOT}/av1/common/x86/resize_ssse3.c")
 
-list(APPEND AOM_AV1_COMMON_INTRIN_SSE4_1
-            "${AOM_ROOT}/av1/common/cdef_block_sse4.c"
-            "${AOM_ROOT}/av1/common/x86/av1_convolve_horiz_rs_sse4.c"
-            "${AOM_ROOT}/av1/common/x86/av1_convolve_scale_sse4.c"
-            "${AOM_ROOT}/av1/common/x86/av1_txfm_sse4.c"
-            "${AOM_ROOT}/av1/common/x86/av1_txfm_sse4.h"
-            "${AOM_ROOT}/av1/common/x86/filterintra_sse4.c"
-            "${AOM_ROOT}/av1/common/x86/highbd_convolve_2d_sse4.c"
-            "${AOM_ROOT}/av1/common/x86/highbd_inv_txfm_sse4.c"
-            "${AOM_ROOT}/av1/common/x86/highbd_jnt_convolve_sse4.c"
-            "${AOM_ROOT}/av1/common/x86/highbd_warp_plane_sse4.c"
-            "${AOM_ROOT}/av1/common/x86/intra_edge_sse4.c"
-            "${AOM_ROOT}/av1/common/x86/reconinter_sse4.c"
-            "${AOM_ROOT}/av1/common/x86/selfguided_sse4.c"
-            "${AOM_ROOT}/av1/common/x86/warp_plane_sse4.c")
+list(
+  APPEND
+  AOM_AV1_COMMON_INTRIN_SSE4_1
+  "${AOM_ROOT}/av1/common/cdef_block_sse4.c"
+  "${AOM_ROOT}/av1/common/x86/av1_convolve_horiz_rs_sse4.c"
+  "${AOM_ROOT}/av1/common/x86/av1_convolve_scale_sse4.c"
+  "${AOM_ROOT}/av1/common/x86/av1_txfm_sse4.c"
+  "${AOM_ROOT}/av1/common/x86/av1_txfm_sse4.h"
+  "${AOM_ROOT}/av1/common/x86/filterintra_sse4.c"
+  "${AOM_ROOT}/av1/common/x86/highbd_convolve_2d_sse4.c"
+  "${AOM_ROOT}/av1/common/x86/highbd_inv_txfm_sse4.c"
+  "${AOM_ROOT}/av1/common/x86/highbd_jnt_convolve_sse4.c"
+  "${AOM_ROOT}/av1/common/x86/highbd_warp_plane_sse4.c"
+  "${AOM_ROOT}/av1/common/x86/intra_edge_sse4.c"
+  "${AOM_ROOT}/av1/common/x86/optflow_refine_sse4.c"
+  "${AOM_ROOT}/av1/common/x86/reconinter_sse4.c"
+  "${AOM_ROOT}/av1/common/x86/selfguided_sse4.c"
+  "${AOM_ROOT}/av1/common/x86/warp_plane_sse4.c")
 
-list(APPEND AOM_AV1_COMMON_INTRIN_AVX2
-            "${AOM_ROOT}/av1/common/cdef_block_avx2.c"
-            "${AOM_ROOT}/av1/common/x86/av1_inv_txfm_avx2.c"
-            "${AOM_ROOT}/av1/common/x86/av1_inv_txfm_avx2.h"
-            "${AOM_ROOT}/av1/common/x86/cfl_avx2.c"
-            "${AOM_ROOT}/av1/common/x86/convolve_2d_avx2.c"
-            "${AOM_ROOT}/av1/common/x86/convolve_avx2.c"
-            "${AOM_ROOT}/av1/common/x86/highbd_convolve_2d_avx2.c"
-            "${AOM_ROOT}/av1/common/x86/highbd_inv_txfm_avx2.c"
-            "${AOM_ROOT}/av1/common/x86/highbd_jnt_convolve_avx2.c"
-            "${AOM_ROOT}/av1/common/x86/highbd_wiener_convolve_avx2.c"
-            "${AOM_ROOT}/av1/common/x86/highbd_warp_affine_avx2.c"
-            "${AOM_ROOT}/av1/common/x86/jnt_convolve_avx2.c"
-            "${AOM_ROOT}/av1/common/x86/reconinter_avx2.c"
-            "${AOM_ROOT}/av1/common/x86/selfguided_avx2.c"
-            "${AOM_ROOT}/av1/common/x86/warp_plane_avx2.c"
-            "${AOM_ROOT}/av1/common/x86/wiener_convolve_avx2.c")
+list(
+  APPEND
+  AOM_AV1_COMMON_INTRIN_AVX2
+  "${AOM_ROOT}/av1/common/cdef_block_avx2.c"
+  "${AOM_ROOT}/av1/common/x86/av1_inv_txfm_avx2.c"
+  "${AOM_ROOT}/av1/common/x86/av1_inv_txfm_avx2.h"
+  "${AOM_ROOT}/av1/common/x86/cfl_avx2.c"
+  "${AOM_ROOT}/av1/common/x86/convolve_2d_avx2.c"
+  "${AOM_ROOT}/av1/common/x86/convolve_avx2.c"
+  "${AOM_ROOT}/av1/common/x86/highbd_convolve_2d_avx2.c"
+  "${AOM_ROOT}/av1/common/x86/highbd_inv_txfm_avx2.c"
+  "${AOM_ROOT}/av1/common/x86/highbd_jnt_convolve_avx2.c"
+  "${AOM_ROOT}/av1/common/x86/highbd_wiener_convolve_avx2.c"
+  "${AOM_ROOT}/av1/common/x86/highbd_warp_affine_avx2.c"
+  "${AOM_ROOT}/av1/common/x86/jnt_convolve_avx2.c"
+  "${AOM_ROOT}/av1/common/x86/reconinter_avx2.c"
+  "${AOM_ROOT}/av1/common/x86/selfguided_avx2.c"
+  "${AOM_ROOT}/av1/common/x86/warp_plane_avx2.c"
+  "${AOM_ROOT}/av1/common/x86/wiener_convolve_avx2.c")
 
 list(APPEND AOM_AV1_ENCODER_ASM_SSE2 "${AOM_ROOT}/av1/encoder/x86/dct_sse2.asm"
-            "${AOM_ROOT}/av1/encoder/x86/error_sse2.asm")
+     "${AOM_ROOT}/av1/encoder/x86/error_sse2.asm")
 
-list(APPEND AOM_AV1_ENCODER_INTRIN_SSE2
-            "${AOM_ROOT}/av1/encoder/x86/av1_fwd_txfm_sse2.c"
-            "${AOM_ROOT}/av1/encoder/x86/av1_fwd_txfm_sse2.h"
-            "${AOM_ROOT}/av1/encoder/x86/av1_quantize_sse2.c"
-            "${AOM_ROOT}/av1/encoder/x86/encodetxb_sse2.c"
-            "${AOM_ROOT}/av1/encoder/x86/highbd_block_error_intrin_sse2.c"
-            "${AOM_ROOT}/av1/encoder/x86/temporal_filter_sse2.c"
-            "${AOM_ROOT}/av1/encoder/x86/highbd_temporal_filter_sse2.c"
-            "${AOM_ROOT}/av1/encoder/x86/wedge_utils_sse2.c")
+list(
+  APPEND
+  AOM_AV1_ENCODER_INTRIN_SSE2
+  "${AOM_ROOT}/av1/encoder/x86/av1_fwd_txfm_sse2.c"
+  "${AOM_ROOT}/av1/encoder/x86/av1_fwd_txfm_sse2.h"
+  "${AOM_ROOT}/av1/encoder/x86/av1_quantize_sse2.c"
+  "${AOM_ROOT}/av1/encoder/x86/encodetxb_sse2.c"
+  "${AOM_ROOT}/av1/encoder/x86/highbd_block_error_intrin_sse2.c"
+  "${AOM_ROOT}/av1/encoder/x86/temporal_filter_sse2.c"
+  "${AOM_ROOT}/av1/encoder/x86/highbd_temporal_filter_sse2.c"
+  "${AOM_ROOT}/av1/encoder/x86/wedge_utils_sse2.c")
 
 list(APPEND AOM_AV1_ENCODER_INTRIN_SSE3 "${AOM_ROOT}/av1/encoder/x86/ml_sse3.c")
 
 list(APPEND AOM_AV1_ENCODER_ASM_SSSE3_X86_64
-            "${AOM_ROOT}/av1/encoder/x86/av1_quantize_ssse3_x86_64.asm")
+     "${AOM_ROOT}/av1/encoder/x86/av1_quantize_ssse3_x86_64.asm")
 
-list(APPEND AOM_AV1_ENCODER_INTRIN_SSE4_1
-            "${AOM_ROOT}/av1/encoder/x86/av1_fwd_txfm1d_sse4.c"
-            "${AOM_ROOT}/av1/encoder/x86/av1_fwd_txfm2d_sse4.c"
-            "${AOM_ROOT}/av1/encoder/x86/av1_highbd_quantize_sse4.c"
-            "${AOM_ROOT}/av1/encoder/x86/corner_match_sse4.c"
-            "${AOM_ROOT}/av1/encoder/x86/encodetxb_sse4.c"
-            "${AOM_ROOT}/av1/encoder/x86/highbd_fwd_txfm_sse4.c"
-            "${AOM_ROOT}/av1/encoder/x86/rdopt_sse4.c"
-            "${AOM_ROOT}/av1/encoder/x86/pickrst_sse4.c")
+list(
+  APPEND
+  AOM_AV1_ENCODER_INTRIN_SSE4_1
+  "${AOM_ROOT}/av1/encoder/x86/av1_fwd_txfm1d_sse4.c"
+  "${AOM_ROOT}/av1/encoder/x86/av1_fwd_txfm2d_sse4.c"
+  "${AOM_ROOT}/av1/encoder/x86/av1_highbd_quantize_sse4.c"
+  "${AOM_ROOT}/av1/encoder/x86/corner_match_sse4.c"
+  "${AOM_ROOT}/av1/encoder/x86/encodetxb_sse4.c"
+  "${AOM_ROOT}/av1/encoder/x86/highbd_fwd_txfm_sse4.c"
+  "${AOM_ROOT}/av1/encoder/x86/rdopt_sse4.c"
+  "${AOM_ROOT}/av1/encoder/x86/pickrst_sse4.c")
 
-list(APPEND AOM_AV1_ENCODER_INTRIN_AVX2
-            "${AOM_ROOT}/av1/encoder/x86/av1_quantize_avx2.c"
-            "${AOM_ROOT}/av1/encoder/x86/av1_highbd_quantize_avx2.c"
-            "${AOM_ROOT}/av1/encoder/x86/corner_match_avx2.c"
-            "${AOM_ROOT}/av1/encoder/x86/error_intrin_avx2.c"
-            "${AOM_ROOT}/av1/encoder/x86/highbd_block_error_intrin_avx2.c"
-            "${AOM_ROOT}/av1/encoder/x86/av1_fwd_txfm_avx2.h"
-            "${AOM_ROOT}/av1/encoder/x86/av1_fwd_txfm2d_avx2.c"
-            "${AOM_ROOT}/av1/encoder/x86/highbd_fwd_txfm_avx2.c"
-            "${AOM_ROOT}/av1/encoder/x86/wedge_utils_avx2.c"
-            "${AOM_ROOT}/av1/encoder/x86/encodetxb_avx2.c"
-            "${AOM_ROOT}/av1/encoder/x86/rdopt_avx2.c"
-            "${AOM_ROOT}/av1/encoder/x86/temporal_filter_avx2.c"
-            "${AOM_ROOT}/av1/encoder/x86/pickrst_avx2.c")
+list(
+  APPEND
+  AOM_AV1_ENCODER_INTRIN_AVX2
+  "${AOM_ROOT}/av1/encoder/x86/av1_quantize_avx2.c"
+  "${AOM_ROOT}/av1/encoder/x86/av1_highbd_quantize_avx2.c"
+  "${AOM_ROOT}/av1/encoder/x86/corner_match_avx2.c"
+  "${AOM_ROOT}/av1/encoder/x86/error_intrin_avx2.c"
+  "${AOM_ROOT}/av1/encoder/x86/highbd_block_error_intrin_avx2.c"
+  "${AOM_ROOT}/av1/encoder/x86/av1_fwd_txfm_avx2.h"
+  "${AOM_ROOT}/av1/encoder/x86/av1_fwd_txfm2d_avx2.c"
+  "${AOM_ROOT}/av1/encoder/x86/highbd_fwd_txfm_avx2.c"
+  "${AOM_ROOT}/av1/encoder/x86/wedge_utils_avx2.c"
+  "${AOM_ROOT}/av1/encoder/x86/encodetxb_avx2.c"
+  "${AOM_ROOT}/av1/encoder/x86/rdopt_avx2.c"
+  "${AOM_ROOT}/av1/encoder/x86/temporal_filter_avx2.c"
+  "${AOM_ROOT}/av1/encoder/x86/pickrst_avx2.c")
 
-list(APPEND AOM_AV1_ENCODER_INTRIN_NEON
-            "${AOM_ROOT}/av1/encoder/arm/neon/quantize_neon.c"
-            "${AOM_ROOT}/av1/encoder/arm/neon/ml_neon.c"
-            "${AOM_ROOT}/av1/encoder/arm/neon/picksrt_neon.c"
-            "${AOM_ROOT}/av1/encoder/arm/neon/rdopt_neon.c"
-            "${AOM_ROOT}/av1/encoder/arm/neon/av1_error_neon.c"
-            "${AOM_ROOT}/av1/encoder/arm/neon/encodetxb_neon.c"
-            "${AOM_ROOT}/av1/encoder/arm/neon/hybrid_fwd_txfm_neon.c"
-            "${AOM_ROOT}/av1/encoder/arm/neon/av1_fwd_txfm2d_neon.c"
-            "${AOM_ROOT}/av1/encoder/arm/neon/highbd_fwd_txfm_neon.c")
+list(
+  APPEND
+  AOM_AV1_ENCODER_INTRIN_NEON
+  "${AOM_ROOT}/av1/encoder/arm/neon/quantize_neon.c"
+  "${AOM_ROOT}/av1/encoder/arm/neon/ml_neon.c"
+  "${AOM_ROOT}/av1/encoder/arm/neon/picksrt_neon.c"
+  "${AOM_ROOT}/av1/encoder/arm/neon/rdopt_neon.c"
+  "${AOM_ROOT}/av1/encoder/arm/neon/av1_error_neon.c"
+  "${AOM_ROOT}/av1/encoder/arm/neon/encodetxb_neon.c"
+  "${AOM_ROOT}/av1/encoder/arm/neon/hybrid_fwd_txfm_neon.c"
+  "${AOM_ROOT}/av1/encoder/arm/neon/av1_fwd_txfm2d_neon.c"
+  "${AOM_ROOT}/av1/encoder/arm/neon/highbd_fwd_txfm_neon.c")
 
-list(APPEND AOM_AV1_ENCODER_INTRIN_MSA
-            "${AOM_ROOT}/av1/encoder/mips/msa/error_msa.c"
-            "${AOM_ROOT}/av1/encoder/mips/msa/fdct4x4_msa.c"
-            "${AOM_ROOT}/av1/encoder/mips/msa/temporal_filter_msa.c")
+list(
+  APPEND
+  AOM_AV1_ENCODER_INTRIN_MSA
+  "${AOM_ROOT}/av1/encoder/mips/msa/error_msa.c"
+  "${AOM_ROOT}/av1/encoder/mips/msa/fdct4x4_msa.c"
+  "${AOM_ROOT}/av1/encoder/mips/msa/temporal_filter_msa.c")
 
-list(APPEND AOM_AV1_COMMON_INTRIN_NEON
-            "${AOM_ROOT}/av1/common/arm/av1_txfm_neon.c"
-            "${AOM_ROOT}/av1/common/arm/cfl_neon.c"
-            "${AOM_ROOT}/av1/common/arm/convolve_neon.c"
-            "${AOM_ROOT}/av1/common/arm/convolve_neon.h"
-            "${AOM_ROOT}/av1/common/arm/jnt_convolve_neon.c"
-            "${AOM_ROOT}/av1/common/arm/mem_neon.h"
-            "${AOM_ROOT}/av1/common/arm/transpose_neon.h"
-            "${AOM_ROOT}/av1/common/arm/blend_a64_hmask_neon.c"
-            "${AOM_ROOT}/av1/common/arm/blend_a64_vmask_neon.c"
-            "${AOM_ROOT}/av1/common/arm/reconinter_neon.c"
-            "${AOM_ROOT}/av1/common/arm/reconintra_neon.c"
-            "${AOM_ROOT}/av1/common/arm/resize_neon.c"
-            "${AOM_ROOT}/av1/common/arm/wiener_convolve_neon.c"
-            "${AOM_ROOT}/av1/common/arm/selfguided_neon.c"
-            "${AOM_ROOT}/av1/common/arm/av1_inv_txfm_neon.c"
-            "${AOM_ROOT}/av1/common/arm/av1_inv_txfm_neon.h"
-            "${AOM_ROOT}/av1/common/arm/highbd_inv_txfm_neon.c"
-            "${AOM_ROOT}/av1/common/arm/warp_plane_neon.c"
-            "${AOM_ROOT}/av1/common/cdef_block_neon.c")
+list(
+  APPEND
+  AOM_AV1_COMMON_INTRIN_NEON
+  "${AOM_ROOT}/av1/common/arm/av1_txfm_neon.c"
+  "${AOM_ROOT}/av1/common/arm/cfl_neon.c"
+  "${AOM_ROOT}/av1/common/arm/convolve_neon.c"
+  "${AOM_ROOT}/av1/common/arm/convolve_neon.h"
+  "${AOM_ROOT}/av1/common/arm/jnt_convolve_neon.c"
+  "${AOM_ROOT}/av1/common/arm/mem_neon.h"
+  "${AOM_ROOT}/av1/common/arm/transpose_neon.h"
+  "${AOM_ROOT}/av1/common/arm/blend_a64_hmask_neon.c"
+  "${AOM_ROOT}/av1/common/arm/blend_a64_vmask_neon.c"
+  "${AOM_ROOT}/av1/common/arm/reconinter_neon.c"
+  "${AOM_ROOT}/av1/common/arm/reconintra_neon.c"
+  "${AOM_ROOT}/av1/common/arm/resize_neon.c"
+  "${AOM_ROOT}/av1/common/arm/wiener_convolve_neon.c"
+  "${AOM_ROOT}/av1/common/arm/selfguided_neon.c"
+  "${AOM_ROOT}/av1/common/arm/av1_inv_txfm_neon.c"
+  "${AOM_ROOT}/av1/common/arm/av1_inv_txfm_neon.h"
+  "${AOM_ROOT}/av1/common/arm/highbd_inv_txfm_neon.c"
+  "${AOM_ROOT}/av1/common/arm/warp_plane_neon.c"
+  "${AOM_ROOT}/av1/common/cdef_block_neon.c")
 
 list(APPEND AOM_AV1_ENCODER_INTRIN_SSE4_2
-            "${AOM_ROOT}/av1/encoder/x86/hash_sse42.c")
+     "${AOM_ROOT}/av1/encoder/x86/hash_sse42.c")
 
 list(APPEND AOM_AV1_COMMON_INTRIN_VSX "${AOM_ROOT}/av1/common/ppc/cfl_ppc.c")
 
 if(CONFIG_ACCOUNTING)
   list(APPEND AOM_AV1_DECODER_SOURCES "${AOM_ROOT}/av1/decoder/accounting.c"
-              "${AOM_ROOT}/av1/decoder/accounting.h")
+       "${AOM_ROOT}/av1/decoder/accounting.h")
 endif()
 
 if(CONFIG_INSPECTION)
   list(APPEND AOM_AV1_DECODER_SOURCES "${AOM_ROOT}/av1/decoder/inspection.c"
-              "${AOM_ROOT}/av1/decoder/inspection.h")
+       "${AOM_ROOT}/av1/decoder/inspection.h")
 endif()
 
 if(CONFIG_INTERNAL_STATS)
@@ -536,16 +567,16 @@
 
   if(HAVE_NEON)
     if(AOM_AV1_COMMON_INTRIN_NEON)
-      add_intrinsics_object_library("${AOM_NEON_INTRIN_FLAG}" "neon"
-                                    "aom_av1_common"
-                                    "AOM_AV1_COMMON_INTRIN_NEON")
+      add_intrinsics_object_library(
+        "${AOM_NEON_INTRIN_FLAG}" "neon" "aom_av1_common"
+        "AOM_AV1_COMMON_INTRIN_NEON")
     endif()
 
     if(CONFIG_AV1_ENCODER)
       if(AOM_AV1_ENCODER_INTRIN_NEON)
-        add_intrinsics_object_library("${AOM_NEON_INTRIN_FLAG}" "neon"
-                                      "aom_av1_encoder"
-                                      "AOM_AV1_ENCODER_INTRIN_NEON")
+        add_intrinsics_object_library(
+          "${AOM_NEON_INTRIN_FLAG}" "neon" "aom_av1_encoder"
+          "AOM_AV1_ENCODER_INTRIN_NEON")
       endif()
     endif()
   endif()
@@ -564,5 +595,7 @@
 
   # Pass the new lib targets up to the parent scope instance of
   # $AOM_LIB_TARGETS.
-  set(AOM_LIB_TARGETS ${AOM_LIB_TARGETS} PARENT_SCOPE)
+  set(AOM_LIB_TARGETS
+      ${AOM_LIB_TARGETS}
+      PARENT_SCOPE)
 endfunction()
diff --git a/av1/av1_cx_iface.c b/av1/av1_cx_iface.c
index 6400e19..461a378 100644
--- a/av1/av1_cx_iface.c
+++ b/av1/av1_cx_iface.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #include <stdlib.h>
 #include <string.h>
@@ -124,40 +125,47 @@
   int enable_orip;  // enable ORIP
 #endif              // CONFIG_ORIP
 #if CONFIG_IST
-  int enable_ist;                // enable intra secondary transform
-#endif                           // CONFIG_IST
+  int enable_ist;  // enable intra secondary transform
+#endif             // CONFIG_IST
+#if CONFIG_IBP_DC || CONFIG_IBP_DIR
+  int enable_ibp;                // enable intra bi-prediction
+#endif                           // CONFIG_IBP_DC or CONFIG_IBP_DIR
   int min_partition_size;        // min partition size [4,8,16,32,64,128]
   int max_partition_size;        // max partition size [4,8,16,32,64,128]
   int enable_intra_edge_filter;  // enable intra-edge filter for sequence
   int enable_order_hint;         // enable order hint for sequence
   int enable_tx64;               // enable 64-pt transform usage for sequence
   int enable_flip_idtx;          // enable flip and identity transform types
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-  int enable_dist_wtd_comp;          // enable dist wtd compound for sequence
-#endif                               // !CONFIG_REMOVE_DIST_WTD_COMP
-  int max_reference_frames;          // maximum number of references per frame
+  int max_reference_frames;      // maximum number of references per frame
   int enable_reduced_reference_set;  // enable reduced set of references
-  int enable_ref_frame_mvs;          // sequence level
-  int allow_ref_frame_mvs;           // frame level
-  int enable_masked_comp;            // enable masked compound for sequence
-  int enable_onesided_comp;          // enable one sided compound for sequence
-  int enable_interintra_comp;        // enable interintra compound for sequence
-  int enable_smooth_interintra;      // enable smooth interintra mode usage
-  int enable_diff_wtd_comp;          // enable diff-wtd compound usage
-  int enable_interinter_wedge;       // enable interinter-wedge compound usage
-  int enable_interintra_wedge;       // enable interintra-wedge compound usage
-  int enable_global_motion;          // enable global motion usage for sequence
-  int enable_warped_motion;          // sequence level
-  int allow_warped_motion;           // frame level
-  int enable_filter_intra;           // enable filter intra for sequence
-  int enable_smooth_intra;           // enable smooth intra modes for sequence
-  int enable_paeth_intra;            // enable Paeth intra mode for sequence
-  int enable_cfl_intra;              // enable CFL uv intra mode for sequence
+#if CONFIG_NEW_REF_SIGNALING
+  int explicit_ref_frame_map;    // explicitly signal reference frame mapping
+#endif                           // CONFIG_NEW_REF_SIGNALING
+  int enable_ref_frame_mvs;      // sequence level
+  int allow_ref_frame_mvs;       // frame level
+  int enable_masked_comp;        // enable masked compound for sequence
+  int enable_onesided_comp;      // enable one sided compound for sequence
+  int enable_interintra_comp;    // enable interintra compound for sequence
+  int enable_smooth_interintra;  // enable smooth interintra mode usage
+  int enable_diff_wtd_comp;      // enable diff-wtd compound usage
+  int enable_interinter_wedge;   // enable interinter-wedge compound usage
+  int enable_interintra_wedge;   // enable interintra-wedge compound usage
+  int enable_global_motion;      // enable global motion usage for sequence
+  int enable_warped_motion;      // sequence level
+  int allow_warped_motion;       // frame level
+  int enable_filter_intra;       // enable filter intra for sequence
+  int enable_smooth_intra;       // enable smooth intra modes for sequence
+  int enable_paeth_intra;        // enable Paeth intra mode for sequence
+  int enable_cfl_intra;          // enable CFL uv intra mode for sequence
   int enable_superres;
   int enable_overlay;  // enable overlay for filtered arf frames
   int enable_palette;
   int enable_intrabc;
   int enable_angle_delta;
+#if CONFIG_OPTFLOW_REFINEMENT
+  aom_opfl_refine_type enable_opfl_refine;  // optical flow refinement type
+                                            // for sequence
+#endif                                      // CONFIG_OPTFLOW_REFINEMENT
 #if CONFIG_DENOISE
   float noise_level;
   int noise_block_size;
@@ -186,6 +194,9 @@
 #if CONFIG_NEW_INTER_MODES
   unsigned int max_drl_refmvs;
 #endif  // CONFIG_NEW_INTER_MODES
+#if CONFIG_REF_MV_BANK
+  int enable_refmvbank;
+#endif  // CONFIG_REF_MV_BANK
 };
 
 // Example subgop configs. Currently not used by default.
@@ -403,17 +414,20 @@
 #if CONFIG_IST
   1,    // enable intra secondary transform
 #endif  // CONFIG_IST
+#if CONFIG_IBP_DC || CONFIG_IBP_DIR
+  1,    // enable intra bi-prediction
+#endif  // CONFIG_IBP_DC or CONFIG_IBP_DIR
   4,    // min_partition_size
   128,  // max_partition_size
   1,    // enable intra edge filter
   1,    // frame order hint
   1,    // enable 64-pt transform usage
   1,    // enable flip and identity transform
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-  1,                       // dist-wtd compound
-#endif                     // !CONFIG_REMOVE_DIST_WTD_COMP
-  7,                       // max_reference_frames
-  0,                       // enable_reduced_reference_set
+  7,    // max_reference_frames
+  0,    // enable_reduced_reference_set
+#if CONFIG_NEW_REF_SIGNALING
+  0,                       // explicit_ref_frame_map
+#endif                     // CONFIG_NEW_REF_SIGNALING
   1,                       // enable_ref_frame_mvs sequence level
   1,                       // allow ref_frame_mvs frame level
   1,                       // enable masked compound at sequence level
@@ -435,6 +449,9 @@
   1,                       // enable palette
   !CONFIG_SHARP_SETTINGS,  // enable intrabc
   1,                       // enable angle delta
+#if CONFIG_OPTFLOW_REFINEMENT
+  1,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 #if CONFIG_DENOISE
   0,   // noise_level
   32,  // noise_block_size
@@ -467,6 +484,9 @@
 #if CONFIG_NEW_INTER_MODES
   0,    // max_drl_refmvs
 #endif  // CONFIG_NEW_INTER_MODES
+#if CONFIG_REF_MV_BANK
+  1,    // enable_refmvbank
+#endif  // CONFIG_REF_MV_BANK
 };
 
 struct aom_codec_alg_priv {
@@ -730,6 +750,9 @@
 
   RANGE_CHECK(extra_cfg, max_reference_frames, 3, 7);
   RANGE_CHECK(extra_cfg, enable_reduced_reference_set, 0, 1);
+#if CONFIG_NEW_REF_SIGNALING
+  RANGE_CHECK(extra_cfg, explicit_ref_frame_map, 0, 1);
+#endif  // CONFIG_NEW_REF_SIGNALING
   RANGE_CHECK_HI(extra_cfg, chroma_subsampling_x, 1);
   RANGE_CHECK_HI(extra_cfg, chroma_subsampling_y, 1);
 
@@ -825,18 +848,17 @@
   cfg->enable_ccso = extra_cfg->enable_ccso;
 #endif
   cfg->superblock_size =
-      (extra_cfg->superblock_size == AOM_SUPERBLOCK_SIZE_64X64)
-          ? 64
-          : (extra_cfg->superblock_size == AOM_SUPERBLOCK_SIZE_128X128) ? 128
-                                                                        : 0;
+      (extra_cfg->superblock_size == AOM_SUPERBLOCK_SIZE_64X64)     ? 64
+      : (extra_cfg->superblock_size == AOM_SUPERBLOCK_SIZE_128X128) ? 128
+                                                                    : 0;
   cfg->enable_warped_motion = extra_cfg->enable_warped_motion;
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-  cfg->enable_dist_wtd_comp = extra_cfg->enable_dist_wtd_comp;
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
   cfg->enable_diff_wtd_comp = extra_cfg->enable_diff_wtd_comp;
 #if !CONFIG_REMOVE_DUAL_FILTER
   cfg->enable_dual_filter = extra_cfg->enable_dual_filter;
 #endif  // !CONFIG_REMOVE_DUAL_FILTER
+#if CONFIG_OPTFLOW_REFINEMENT
+  cfg->enable_opfl_refine = extra_cfg->enable_opfl_refine;
+#endif  // CONFIG_OPTFLOW_REFINEMENT
   cfg->enable_angle_delta = extra_cfg->enable_angle_delta;
   cfg->disable_ml_partition_speed_features =
       extra_cfg->disable_ml_partition_speed_features;
@@ -857,6 +879,9 @@
 #if CONFIG_IST
   cfg->enable_ist = extra_cfg->enable_ist;
 #endif
+#if CONFIG_IBP_DC || CONFIG_IBP_DIR
+  cfg->enable_ibp = extra_cfg->enable_ibp;
+#endif
   cfg->max_partition_size = extra_cfg->max_partition_size;
   cfg->min_partition_size = extra_cfg->min_partition_size;
   cfg->enable_intra_edge_filter = extra_cfg->enable_intra_edge_filter;
@@ -880,10 +905,16 @@
       (extra_cfg->allow_ref_frame_mvs || extra_cfg->enable_ref_frame_mvs);
   cfg->enable_onesided_comp = extra_cfg->enable_onesided_comp;
   cfg->enable_reduced_reference_set = extra_cfg->enable_reduced_reference_set;
+#if CONFIG_NEW_REF_SIGNALING
+  cfg->explicit_ref_frame_map = extra_cfg->explicit_ref_frame_map;
+#endif  // CONFIG_NEW_REF_SIGNALING
   cfg->reduced_tx_type_set = extra_cfg->reduced_tx_type_set;
 #if CONFIG_NEW_INTER_MODES
   cfg->max_drl_refmvs = extra_cfg->max_drl_refmvs;
 #endif  // CONFIG_NEW_INTER_MODES
+#if CONFIG_REF_MV_BANK
+  cfg->enable_refmvbank = extra_cfg->enable_refmvbank;
+#endif  // CONFIG_REF_MV_BANK
 }
 
 static void update_default_encoder_config(const cfg_options_t *cfg,
@@ -894,19 +925,18 @@
 #if CONFIG_CCSO
   extra_cfg->enable_ccso = cfg->enable_ccso;
 #endif
-  extra_cfg->superblock_size = (cfg->superblock_size == 64)
-                                   ? AOM_SUPERBLOCK_SIZE_64X64
-                                   : (cfg->superblock_size == 128)
-                                         ? AOM_SUPERBLOCK_SIZE_128X128
-                                         : AOM_SUPERBLOCK_SIZE_DYNAMIC;
+  extra_cfg->superblock_size =
+      (cfg->superblock_size == 64)    ? AOM_SUPERBLOCK_SIZE_64X64
+      : (cfg->superblock_size == 128) ? AOM_SUPERBLOCK_SIZE_128X128
+                                      : AOM_SUPERBLOCK_SIZE_DYNAMIC;
   extra_cfg->enable_warped_motion = cfg->enable_warped_motion;
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-  extra_cfg->enable_dist_wtd_comp = cfg->enable_dist_wtd_comp;
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
   extra_cfg->enable_diff_wtd_comp = cfg->enable_diff_wtd_comp;
 #if !CONFIG_REMOVE_DUAL_FILTER
   extra_cfg->enable_dual_filter = cfg->enable_dual_filter;
 #endif  // !CONFIG_REMOVE_DUAL_FILTER
+#if CONFIG_OPTFLOW_REFINEMENT
+  extra_cfg->enable_opfl_refine = cfg->enable_opfl_refine;
+#endif  // CONFIG_OPTFLOW_REFINEMENT
   extra_cfg->enable_angle_delta = cfg->enable_angle_delta;
   extra_cfg->enable_rect_partitions = cfg->enable_rect_partitions;
   extra_cfg->enable_ab_partitions = cfg->enable_ab_partitions;
@@ -927,6 +957,9 @@
 #if CONFIG_IST
   extra_cfg->enable_ist = cfg->enable_ist;
 #endif
+#if CONFIG_IBP_DC || CONFIG_IBP_DIR
+  extra_cfg->enable_ibp = cfg->enable_ibp;
+#endif
   extra_cfg->max_partition_size = cfg->max_partition_size;
   extra_cfg->min_partition_size = cfg->min_partition_size;
   extra_cfg->enable_intra_edge_filter = cfg->enable_intra_edge_filter;
@@ -949,10 +982,16 @@
   extra_cfg->enable_ref_frame_mvs = cfg->enable_ref_frame_mvs;
   extra_cfg->enable_onesided_comp = cfg->enable_onesided_comp;
   extra_cfg->enable_reduced_reference_set = cfg->enable_reduced_reference_set;
+#if CONFIG_NEW_REF_SIGNALING
+  extra_cfg->explicit_ref_frame_map = cfg->explicit_ref_frame_map;
+#endif  // CONFIG_NEW_REF_SIGNALING
   extra_cfg->reduced_tx_type_set = cfg->reduced_tx_type_set;
 #if CONFIG_NEW_INTER_MODES
   extra_cfg->max_drl_refmvs = cfg->max_drl_refmvs;
 #endif  // CONFIG_NEW_INTER_MODES
+#if CONFIG_REF_MV_BANK
+  extra_cfg->enable_refmvbank = cfg->enable_refmvbank;
+#endif  // CONFIG_REF_MV_BANK
 }
 
 static double convert_qp_offset(int qp, int qp_offset, int bit_depth) {
@@ -980,9 +1019,9 @@
     // At higher end of QP the slope of quant step-size grows exponentially,
     // captured by qp_threshold.
 #if CONFIG_EXTQUANT
-    const int max_q = (bit_depth == AOM_BITS_8)
-                          ? MAXQ_8_BITS
-                          : (bit_depth == AOM_BITS_10) ? MAXQ_10_BITS : MAXQ;
+    const int max_q = (bit_depth == AOM_BITS_8)    ? MAXQ_8_BITS
+                      : (bit_depth == AOM_BITS_10) ? MAXQ_10_BITS
+                                                   : MAXQ;
 #else
     const int max_q = MAXQ;
 #endif  // CONFIG_EXTQUANT
@@ -1182,6 +1221,14 @@
 #if CONFIG_NEW_INTER_MODES
   tool_cfg->max_drl_refmvs = extra_cfg->max_drl_refmvs;
 #endif  // CONFIG_NEW_INTER_MODES
+#if CONFIG_REF_MV_BANK
+  tool_cfg->enable_refmvbank = extra_cfg->enable_refmvbank;
+#endif  // CONFIG_REF_MV_BANK
+#if CONFIG_OPTFLOW_REFINEMENT
+  tool_cfg->enable_opfl_refine = extra_cfg->enable_order_hint
+                                     ? extra_cfg->enable_opfl_refine
+                                     : AOM_OPFL_REFINE_NONE;
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   // Set Quantization related configuration.
   q_cfg->using_qm = extra_cfg->enable_qm;
@@ -1346,6 +1393,9 @@
   oxcf->ref_frm_cfg.enable_reduced_reference_set =
       extra_cfg->enable_reduced_reference_set;
   oxcf->ref_frm_cfg.enable_onesided_comp = extra_cfg->enable_onesided_comp;
+#if CONFIG_NEW_REF_SIGNALING
+  oxcf->ref_frm_cfg.explicit_ref_frame_map = extra_cfg->explicit_ref_frame_map;
+#endif  // CONFIG_NEW_REF_SIGNALING
 
   oxcf->row_mt = extra_cfg->row_mt;
 
@@ -1381,6 +1431,9 @@
 #if CONFIG_ORIP
   intra_mode_cfg->enable_orip = extra_cfg->enable_orip;
 #endif
+#if CONFIG_IBP_DC || CONFIG_IBP_DIR
+  intra_mode_cfg->enable_ibp = extra_cfg->enable_ibp;
+#endif
 
   // Set transform size/type configuration.
   txfm_cfg->enable_tx64 = extra_cfg->enable_tx64;
@@ -1396,10 +1449,6 @@
 #endif
 
   // Set compound type configuration.
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-  comp_type_cfg->enable_dist_wtd_comp =
-      extra_cfg->enable_dist_wtd_comp & extra_cfg->enable_order_hint;
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
   comp_type_cfg->enable_masked_comp = extra_cfg->enable_masked_comp;
   comp_type_cfg->enable_diff_wtd_comp =
       extra_cfg->enable_masked_comp & extra_cfg->enable_diff_wtd_comp;
@@ -1957,15 +2006,6 @@
   return update_extra_cfg(ctx, &extra_cfg);
 }
 
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-static aom_codec_err_t ctrl_set_enable_dist_wtd_comp(aom_codec_alg_priv_t *ctx,
-                                                     va_list args) {
-  struct av1_extracfg extra_cfg = ctx->extra_cfg;
-  extra_cfg.enable_dist_wtd_comp = CAST(AV1E_SET_ENABLE_DIST_WTD_COMP, args);
-  return update_extra_cfg(ctx, &extra_cfg);
-}
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
-
 static aom_codec_err_t ctrl_set_max_reference_frames(aom_codec_alg_priv_t *ctx,
                                                      va_list args) {
   struct av1_extracfg extra_cfg = ctx->extra_cfg;
@@ -2514,6 +2554,9 @@
             clamp(lap_lag_in_frames, 0, MAX_LAG_BUFFERS),
             &priv->stats_buf_context);
       }
+#if CONFIG_IBP_DIR
+      init_ibp_info(priv->cpi->common.ibp_directional_weights);
+#endif
     }
   }
 
@@ -2553,14 +2596,20 @@
 
 static aom_codec_frame_flags_t get_frame_pkt_flags(const AV1_COMP *cpi,
                                                    unsigned int lib_flags) {
+#if CONFIG_SVC_ENCODER
   const SVC *const svc = &cpi->svc;
+#endif  // CONFIG_SVC_ENCODER
   aom_codec_frame_flags_t flags = lib_flags << 16;
 
+#if CONFIG_SVC_ENCODER
   if (lib_flags & FRAMEFLAGS_KEY ||
       (cpi->use_svc &&
        svc->layer_context[svc->spatial_layer_id * svc->number_temporal_layers +
                           svc->temporal_layer_id]
            .is_key_frame))
+#else
+  if (lib_flags & FRAMEFLAGS_KEY)
+#endif  // CONFIG_SVC_ENCODER
     flags |= AOM_FRAME_IS_KEY;
   if (lib_flags & FRAMEFLAGS_INTRAONLY) flags |= AOM_FRAME_IS_INTRAONLY;
   if (lib_flags & FRAMEFLAGS_SWITCH) flags |= AOM_FRAME_IS_SWITCH;
@@ -2605,8 +2654,13 @@
   if (!cm->show_existing_frame) {
     // Get reference frame information
     int ref_poc[INTER_REFS_PER_FRAME];
+#if CONFIG_NEW_REF_SIGNALING
+    for (int ref_frame = 0; ref_frame < INTER_REFS_PER_FRAME; ++ref_frame) {
+      const int ref_idx = ref_frame;
+#else
     for (int ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
       const int ref_idx = ref_frame - LAST_FRAME;
+#endif  // CONFIG_NEW_REF_SIGNALING
       const RefCntBuffer *const buf = get_ref_frame_buf(cm, ref_frame);
       ref_poc[ref_idx] = buf ? (int)buf->absolute_poc : -1;
       ref_poc[ref_idx] = (ref_poc[ref_idx] == (int)cm->cur_frame->absolute_poc)
@@ -3180,6 +3234,7 @@
   return AOM_CODEC_OK;
 }
 
+#if CONFIG_SVC_ENCODER
 static aom_codec_err_t ctrl_set_layer_id(aom_codec_alg_priv_t *ctx,
                                          va_list args) {
   aom_svc_layer_id_t *const data = va_arg(args, aom_svc_layer_id_t *);
@@ -3243,6 +3298,7 @@
     cpi->svc.refresh[i] = data->refresh[i];
   return AOM_CODEC_OK;
 }
+#endif  // CONFIG_SVC_ENCODER
 
 static aom_codec_err_t ctrl_set_tune_content(aom_codec_alg_priv_t *ctx,
                                              va_list args) {
@@ -3571,6 +3627,11 @@
                               err_string)) {
     extra_cfg.enable_ist = arg_parse_int_helper(&arg, err_string);
 #endif
+#if CONFIG_IBP_DC || CONFIG_IBP_DIR
+  } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.enable_ibp, argv,
+                              err_string)) {
+    extra_cfg.enable_ibp = arg_parse_int_helper(&arg, err_string);
+#endif
   } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.min_partition_size,
                               argv, err_string)) {
     extra_cfg.min_partition_size = arg_parse_int_helper(&arg, err_string);
@@ -3591,11 +3652,6 @@
   } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.enable_flip_idtx,
                               argv, err_string)) {
     extra_cfg.enable_flip_idtx = arg_parse_int_helper(&arg, err_string);
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-  } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.enable_dist_wtd_comp,
-                              argv, err_string)) {
-    extra_cfg.enable_dist_wtd_comp = arg_parse_int_helper(&arg, err_string);
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
   } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.max_reference_frames,
                               argv, err_string)) {
     extra_cfg.max_reference_frames = arg_parse_int_helper(&arg, err_string);
@@ -3603,6 +3659,12 @@
                               argv, err_string)) {
     extra_cfg.enable_reduced_reference_set =
         arg_parse_int_helper(&arg, err_string);
+#if CONFIG_NEW_REF_SIGNALING
+  } else if (arg_match_helper(&arg,
+                              &g_av1_codec_arg_defs.explicit_ref_frame_map,
+                              argv, err_string)) {
+    extra_cfg.explicit_ref_frame_map = arg_parse_int_helper(&arg, err_string);
+#endif  // CONFIG_NEW_REF_SIGNALING
   } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.enable_ref_frame_mvs,
                               argv, err_string)) {
     extra_cfg.enable_ref_frame_mvs = arg_parse_int_helper(&arg, err_string);
@@ -3661,6 +3723,11 @@
   } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.enable_angle_delta,
                               argv, err_string)) {
     extra_cfg.enable_angle_delta = arg_parse_int_helper(&arg, err_string);
+#if CONFIG_OPTFLOW_REFINEMENT
+  } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.enable_opfl_refine,
+                              argv, err_string)) {
+    extra_cfg.enable_opfl_refine = arg_parse_int_helper(&arg, err_string);
+#endif  // CONFIG_OPTFLOW_REFINEMENT
   } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.reduced_tx_type_set,
                               argv, err_string)) {
     extra_cfg.reduced_tx_type_set = arg_parse_int_helper(&arg, err_string);
@@ -3729,10 +3796,13 @@
 #if CONFIG_NEW_INTER_MODES
   } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.max_drl_refmvs, argv,
                               err_string)) {
-    printf("haha\n");
     extra_cfg.max_drl_refmvs = arg_parse_uint_helper(&arg, err_string);
-    printf("gaga %d\n", extra_cfg.max_drl_refmvs);
 #endif  // CONFIG_NEW_INTER_MODES
+#if CONFIG_REF_MV_BANK
+  } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.enable_refmvbank,
+                              argv, err_string)) {
+    extra_cfg.enable_refmvbank = arg_parse_int_helper(&arg, err_string);
+#endif  // CONFIG_REF_MV_BANK
   } else {
     match = 0;
     snprintf(err_string, ARG_ERR_MSG_MAX_LEN, "Cannot find aom option %s",
@@ -3822,9 +3892,6 @@
   { AV1E_SET_ENABLE_ORDER_HINT, ctrl_set_enable_order_hint },
   { AV1E_SET_ENABLE_TX64, ctrl_set_enable_tx64 },
   { AV1E_SET_ENABLE_FLIP_IDTX, ctrl_set_enable_flip_idtx },
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-  { AV1E_SET_ENABLE_DIST_WTD_COMP, ctrl_set_enable_dist_wtd_comp },
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
   { AV1E_SET_MAX_REFERENCE_FRAMES, ctrl_set_max_reference_frames },
   { AV1E_SET_REDUCED_REFERENCE_SET, ctrl_set_enable_reduced_reference_set },
   { AV1E_SET_ENABLE_REF_FRAME_MVS, ctrl_set_enable_ref_frame_mvs },
@@ -3887,9 +3954,11 @@
   { AV1E_SET_TARGET_SEQ_LEVEL_IDX, ctrl_set_target_seq_level_idx },
   { AV1E_SET_TIER_MASK, ctrl_set_tier_mask },
   { AV1E_SET_MIN_CR, ctrl_set_min_cr },
+#if CONFIG_SVC_ENCODER
   { AV1E_SET_SVC_LAYER_ID, ctrl_set_layer_id },
   { AV1E_SET_SVC_PARAMS, ctrl_set_svc_params },
   { AV1E_SET_SVC_REF_FRAME_CONFIG, ctrl_set_svc_ref_frame_config },
+#endif  // CONFIG_SVC_ENCODER
   { AV1E_SET_VBR_CORPUS_COMPLEXITY_LAP, ctrl_set_vbr_corpus_complexity_lap },
   { AV1E_ENABLE_SB_MULTIPASS_UNIT_TEST, ctrl_enable_sb_multipass_unit_test },
   { AV1E_ENABLE_SUBGOP_STATS, ctrl_enable_subgop_stats },
@@ -3989,22 +4058,32 @@
 #if CONFIG_IST
         1,
 #endif  // CONFIG_IST
+#if CONFIG_IBP_DC || CONFIG_IBP_DIR
+        1,
+#endif  // CONFIG_IBP_DC or CONFIG_IBP_DIR
         1, 1,   1,   1,
 #if CONFIG_CCSO
         1,
 #endif
-        1, 1,   1,
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-        1,
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
-        1, 1,   1,   0, 0, 1, 1, 1, 1,
+        1, 1,   1,   1, 1, 1, 0, 0, 1, 1, 1, 1,
 #if !CONFIG_REMOVE_DUAL_FILTER
         1,
 #endif  // !CONFIG_REMOVE_DUAL_FILTER
-        1, 1,   1,   1, 1, 1, 1, 3, 1, 1, 0,
+        1,
+#if CONFIG_OPTFLOW_REFINEMENT
+        1,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
+        1, 1,   1,   1, 1, 1, 3, 1, 1,
+#if CONFIG_NEW_REF_SIGNALING
+        0,
+#endif  // CONFIG_NEW_REF_SIGNALING
+        0,
 #if CONFIG_NEW_INTER_MODES
         0,
 #endif  // CONFIG_NEW_INTER_MODES
+#if CONFIG_REF_MV_BANK
+        1,
+#endif  // CONFIG_REF_MV_BANK
     },  // cfg
 } };
 
diff --git a/av1/av1_dx_iface.c b/av1/av1_dx_iface.c
index 52d4181..184a906 100644
--- a/av1/av1_dx_iface.c
+++ b/av1/av1_dx_iface.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <stdlib.h>
@@ -108,12 +109,23 @@
     priv->tile_mode = 0;
     priv->decode_tile_row = -1;
     priv->decode_tile_col = -1;
+#if CONFIG_IBP_DIR
+    init_ibp_info(ctx->priv->ibp_directional_weights);
+#endif
   }
 
   return AOM_CODEC_OK;
 }
 
 static aom_codec_err_t decoder_destroy(aom_codec_alg_priv_t *ctx) {
+#if CONFIG_THROUGHPUT_ANALYSIS
+  printf(
+      "avg_ctx_syms : %d\t avg_bypass_syms : %d\t max_ctx_syms : %d\t "
+      "max_bypass_syms : %d\t max_bits : %d\t total_bits : %d\n",
+      (int)(tot_ctx_syms / tot_frames), (int)(tot_bypass_syms / tot_frames),
+      max_ctx_syms, max_bypass_syms, (int)(max_bits / 8), (int)(tot_bits / 8));
+#endif  // CONFIG_THROUGHPUT_ANALYSIS
+
   if (ctx->frame_worker != NULL) {
     AVxWorker *const worker = ctx->frame_worker;
     FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
@@ -138,6 +150,9 @@
     av1_free_internal_frame_buffers(&ctx->buffer_pool->int_frame_buffers);
   }
 
+#if CONFIG_IBP_DIR
+  free_ibp_info(ctx->base.ibp_directional_weights);
+#endif
   aom_free(ctx->frame_worker);
   aom_free(ctx->buffer_pool);
   aom_img_free(&ctx->img);
@@ -472,6 +487,11 @@
   frame_worker_data->pbi->is_fwd_kf_present = 0;
   frame_worker_data->pbi->enable_subgop_stats = ctx->enable_subgop_stats;
   frame_worker_data->pbi->is_arf_frame_present = 0;
+#if CONFIG_IBP_DIR
+  memcpy(frame_worker_data->pbi->common.ibp_directional_weights,
+         ctx->base.ibp_directional_weights,
+         sizeof(ctx->base.ibp_directional_weights));
+#endif
   worker->hook = frame_worker_hook;
 
   init_buffer_callbacks(ctx);
diff --git a/av1/av1_iface_common.h b/av1/av1_iface_common.h
index 24c2d46..0f335ca 100644
--- a/av1/av1_iface_common.h
+++ b/av1/av1_iface_common.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #ifndef AOM_AV1_AV1_IFACE_COMMON_H_
 #define AOM_AV1_AV1_IFACE_COMMON_H_
diff --git a/av1/common/alloccommon.c b/av1/common/alloccommon.c
index d11f8f7..ea2b18f 100644
--- a/av1/common/alloccommon.c
+++ b/av1/common/alloccommon.c
@@ -1,13 +1,14 @@
 /*
  *
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "config/aom_config.h"
diff --git a/av1/common/alloccommon.h b/av1/common/alloccommon.h
index fe8e0c5..68859c4 100644
--- a/av1/common/alloccommon.h
+++ b/av1/common/alloccommon.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_COMMON_ALLOCCOMMON_H_
diff --git a/av1/common/arm/av1_inv_txfm_neon.c b/av1/common/arm/av1_inv_txfm_neon.c
index 2f3567a..a0bbe54 100644
--- a/av1/common/arm/av1_inv_txfm_neon.c
+++ b/av1/common/arm/av1_inv_txfm_neon.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <arm_neon.h>
diff --git a/av1/common/arm/av1_inv_txfm_neon.h b/av1/common/arm/av1_inv_txfm_neon.h
index 9ec6582..644a8bc 100644
--- a/av1/common/arm/av1_inv_txfm_neon.h
+++ b/av1/common/arm/av1_inv_txfm_neon.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #ifndef AOM_AV1_COMMON_ARM_AV1_INV_TXFM_NEON_H_
 #define AOM_AV1_COMMON_ARM_AV1_INV_TXFM_NEON_H_
diff --git a/av1/common/arm/av1_txfm_neon.c b/av1/common/arm/av1_txfm_neon.c
index 7e3a05a..e2a7673 100644
--- a/av1/common/arm/av1_txfm_neon.c
+++ b/av1/common/arm/av1_txfm_neon.c
@@ -1,13 +1,14 @@
 /*
  *
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #include <arm_neon.h>
 #include <assert.h>
diff --git a/av1/common/arm/blend_a64_hmask_neon.c b/av1/common/arm/blend_a64_hmask_neon.c
index 7134f18..70a7c39 100644
--- a/av1/common/arm/blend_a64_hmask_neon.c
+++ b/av1/common/arm/blend_a64_hmask_neon.c
@@ -1,13 +1,14 @@
 /*
  *
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <arm_neon.h>
diff --git a/av1/common/arm/blend_a64_vmask_neon.c b/av1/common/arm/blend_a64_vmask_neon.c
index 194e94c..f1c893a 100644
--- a/av1/common/arm/blend_a64_vmask_neon.c
+++ b/av1/common/arm/blend_a64_vmask_neon.c
@@ -1,13 +1,14 @@
 /*
  *
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <arm_neon.h>
diff --git a/av1/common/arm/cfl_neon.c b/av1/common/arm/cfl_neon.c
index 39025b5..3d0dcb3 100644
--- a/av1/common/arm/cfl_neon.c
+++ b/av1/common/arm/cfl_neon.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #include <arm_neon.h>
 
diff --git a/av1/common/arm/convolve_neon.c b/av1/common/arm/convolve_neon.c
index f72c919..675d707 100644
--- a/av1/common/arm/convolve_neon.c
+++ b/av1/common/arm/convolve_neon.c
@@ -1,13 +1,14 @@
 /*
  *
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/av1/common/arm/highbd_inv_txfm_neon.c b/av1/common/arm/highbd_inv_txfm_neon.c
index 9bd9c4a..0b79320 100644
--- a/av1/common/arm/highbd_inv_txfm_neon.c
+++ b/av1/common/arm/highbd_inv_txfm_neon.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you canzip
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <arm_neon.h>
diff --git a/av1/common/arm/jnt_convolve_neon.c b/av1/common/arm/jnt_convolve_neon.c
index e41e3a5..f145b2f 100644
--- a/av1/common/arm/jnt_convolve_neon.c
+++ b/av1/common/arm/jnt_convolve_neon.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <arm_neon.h>
diff --git a/av1/common/arm/reconinter_neon.c b/av1/common/arm/reconinter_neon.c
index 44e0641..e2e4060 100644
--- a/av1/common/arm/reconinter_neon.c
+++ b/av1/common/arm/reconinter_neon.c
@@ -1,13 +1,14 @@
 /*
  *
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <arm_neon.h>
diff --git a/av1/common/arm/reconintra_neon.c b/av1/common/arm/reconintra_neon.c
index 367d295..9c237e0 100644
--- a/av1/common/arm/reconintra_neon.c
+++ b/av1/common/arm/reconintra_neon.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <arm_neon.h>
diff --git a/av1/common/arm/resize_neon.c b/av1/common/arm/resize_neon.c
index 8808631..76cd713 100644
--- a/av1/common/arm/resize_neon.c
+++ b/av1/common/arm/resize_neon.c
@@ -1,13 +1,14 @@
 /*
  *
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #include <arm_neon.h>
 #include <assert.h>
diff --git a/av1/common/arm/selfguided_neon.c b/av1/common/arm/selfguided_neon.c
index 80d53c4..eaa3d7f 100644
--- a/av1/common/arm/selfguided_neon.c
+++ b/av1/common/arm/selfguided_neon.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <arm_neon.h>
diff --git a/av1/common/arm/warp_plane_neon.c b/av1/common/arm/warp_plane_neon.c
index c31b2a0..74ee90f 100644
--- a/av1/common/arm/warp_plane_neon.c
+++ b/av1/common/arm/warp_plane_neon.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/av1/common/arm/wiener_convolve_neon.c b/av1/common/arm/wiener_convolve_neon.c
index a9bb5bc..4d970ed 100644
--- a/av1/common/arm/wiener_convolve_neon.c
+++ b/av1/common/arm/wiener_convolve_neon.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <arm_neon.h>
diff --git a/av1/common/av1_common_int.h b/av1/common/av1_common_int.h
index 0781160..d85245e 100644
--- a/av1/common/av1_common_int.h
+++ b/av1/common/av1_common_int.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_COMMON_AV1_COMMON_INT_H_
@@ -30,6 +31,9 @@
 #include "av1/common/tile_common.h"
 #include "av1/common/timing.h"
 #include "av1/common/odintrin.h"
+#if CONFIG_IBP_DIR
+#include "av1/common/warped_motion.h"
+#endif
 #include "av1/encoder/hash_motion.h"
 #include "aom_dsp/grain_synthesis.h"
 #include "aom_dsp/grain_table.h"
@@ -89,6 +93,14 @@
 #define TXCOEFF_TIMER 0
 #define TXCOEFF_COST_TIMER 0
 
+#if CONFIG_NEW_REF_SIGNALING
+#define COMPACT_INDEX0_NRS(r) \
+  (((r) == INTRA_FRAME_NRS) ? INTRA_FRAME_INDEX_NRS : (r))
+
+#define COMPACT_INDEX1_NRS(r) \
+  (!is_inter_ref_frame((r)) ? INTRA_FRAME_INDEX_NRS : (r))
+#endif  // CONFIG_NEW_REF_SIGNALING
+
 /*!\cond */
 
 enum {
@@ -110,7 +122,6 @@
   REFRESH_FRAME_CONTEXT_BACKWARD,
 } UENUM1BYTE(REFRESH_FRAME_CONTEXT_MODE);
 
-#define MFMV_STACK_SIZE 3
 typedef struct {
   int_mv mfmv0;
   uint8_t ref_frame_offset;
@@ -137,7 +148,13 @@
   int ref_count;
 
   unsigned int order_hint;
+#if CONFIG_NEW_REF_SIGNALING
+  int ref_order_hints[INTER_REFS_PER_FRAME];
+  int ref_display_order_hint[INTER_REFS_PER_FRAME];
+#else
   unsigned int ref_order_hints[INTER_REFS_PER_FRAME];
+  unsigned int ref_display_order_hint[INTER_REFS_PER_FRAME];
+#endif  // CONFIG_NEW_REF_SIGNALING
 
   // These variables are used only in encoder and compare the absolute
   // display order hint to compute the relative distance and overcome
@@ -145,7 +162,6 @@
   // distance when a very old frame is used as a reference.
   unsigned int display_order_hint;
   unsigned int absolute_poc;
-  unsigned int ref_display_order_hint[INTER_REFS_PER_FRAME];
   // Frame's level within the hierarchical structure
   unsigned int pyramid_level;
 
@@ -158,7 +174,11 @@
   // the sizes that can be derived from the buf structure)
   int width;
   int height;
+#if CONFIG_NEW_REF_SIGNALING
+  WarpedMotionParams global_motion[INTER_REFS_PER_FRAME];
+#else
   WarpedMotionParams global_motion[REF_FRAMES];
+#endif                 // CONFIG_NEW_REF_SIGNALING
   int showable_frame;  // frame can be used as show existing frame in future
   uint8_t film_grain_params_present;
   aom_film_grain_t film_grain_params;
@@ -177,6 +197,9 @@
   int8_t mode_deltas[MAX_MODE_LF_DELTAS];
 
   FRAME_CONTEXT frame_context;
+#if CONFIG_NEW_REF_SIGNALING
+  int base_qindex;
+#endif  // CONFIG_NEW_REF_SIGNALING
 } RefCntBuffer;
 
 typedef struct BufferPool {
@@ -213,6 +236,23 @@
   int cdef_bits; /*!< Number of CDEF strength values in bits */
 } CdefInfo;
 
+#if CONFIG_OPTFLOW_REFINEMENT
+enum {
+  /*!
+   * MV refinement disabled for the current frame.
+   */
+  REFINE_NONE = 0,
+  /*!
+   * MV refinement is switchable per block for the current frame.
+   */
+  REFINE_SWITCHABLE = 1,
+  /*!
+   * MV refinement applied to all compound blocks for the current frame.
+   */
+  REFINE_ALL = 2,
+} UENUM1BYTE(OPTFLOW_REFINE_TYPE);
+#endif  // CONFIG_OPTFLOW_REFINEMENT
+
 #if CONFIG_CCSO
 /** ccso info */
 typedef struct {
@@ -248,12 +288,8 @@
                                 // frame_sign_bias
                                 // if 0, enable_dist_wtd_comp and
                                 // enable_ref_frame_mvs must be set as 0.
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-  int enable_dist_wtd_comp;  // 0 - disable dist-wtd compound modes
-                             // 1 - enable it
-#endif                       // !CONFIG_REMOVE_DIST_WTD_COMP
-  int enable_ref_frame_mvs;  // 0 - disable ref frame mvs
-                             // 1 - enable it
+  int enable_ref_frame_mvs;     // 0 - disable ref frame mvs
+                                // 1 - enable it
 } OrderHintInfo;
 
 // Sequence header structure.
@@ -277,6 +313,10 @@
   BLOCK_SIZE sb_size;  // Size of the superblock used for this frame
   int mib_size;        // Size of the superblock in units of MI blocks
   int mib_size_log2;   // Log 2 of above.
+#if CONFIG_NEW_REF_SIGNALING
+  int explicit_ref_frame_map;  // Explicitly signal the reference frame mapping
+  int max_reference_frames;    // Number of reference frames allowed
+#endif
 
   OrderHintInfo order_hint_info;
 
@@ -303,8 +343,15 @@
 #if CONFIG_IST
   uint8_t enable_ist;  // enables/disables intra secondary transform
 #endif
+#if CONFIG_IBP_DC || CONFIG_IBP_DIR
+  uint8_t enable_ibp;  // enables/disables intra bi-prediction(IBP)
+#endif
   uint8_t enable_interintra_compound;  // enables/disables interintra_compound
   uint8_t enable_masked_compound;      // enables/disables masked compound
+#if CONFIG_OPTFLOW_REFINEMENT
+  aom_opfl_refine_type enable_opfl_refine;  // optical flow refinement type for
+                                            // this frame
+#endif
 #if !CONFIG_REMOVE_DUAL_FILTER
   uint8_t enable_dual_filter;    // 0 - disable dual interpolation filter
 #endif                           // !CONFIG_REMOVE_DUAL_FILTER
@@ -321,6 +368,9 @@
 #if CONFIG_CCSO
   uint8_t enable_ccso;  // To turn on/off CCSO
 #endif
+#if CONFIG_REF_MV_BANK
+  uint8_t enable_refmvbank;  // To turn on/off Ref MV Bank
+#endif                       // CONFIG_REF_MV_BANK
   BITSTREAM_PROFILE profile;
 
   // Color config.
@@ -379,7 +429,9 @@
   unsigned int frame_number;
   SkipModeInfo skip_mode_info;
   int refresh_frame_flags;  // Which ref frames are overwritten by this frame
+#if !CONFIG_NEW_REF_SIGNALING
   int frame_refs_short_signaling;
+#endif  // !CONFIG_NEW_REF_SIGNALING
 } CurrentFrame;
 
 /*!\endcond */
@@ -457,6 +509,13 @@
    */
   int max_drl_bits;
 #endif  // CONFIG_NEW_INTER_MODES
+#if CONFIG_OPTFLOW_REFINEMENT
+  /*!
+   * Ternary symbol for optical flow refinement type. 0: do not refine,
+   * 1: always refine, 2: switchable at block level.
+   */
+  OPTFLOW_REFINE_TYPE opfl_refine_type;
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 } FeatureFlags;
 
 /*!
@@ -793,10 +852,86 @@
   int num_mi_cols;   /*!< Corresponds to cm->mi_params.mi_cols */
 };
 
+#if CONFIG_THROUGHPUT_ANALYSIS
+struct total_sym_stats {
+  /** Frame number (decoding order)*/
+  int frame_dec_order;
+  /** Total number of bits*/
+  int64_t tot_bits;
+  /** total ctx coded symbols. */
+  int64_t tot_ctx_syms;
+  /** total bypass coded symbols. */
+  int64_t tot_bypass_syms;
+  /** peak ctx coded symbols. */
+  int peak_ctx_syms;
+  /** peak bypass coded symbols. */
+  int peak_bypass_syms;
+  /** peak bits. */
+  int peak_bits;
+};
+#endif  // CONFIG_THROUGHPUT_ANALYSIS
+
+#if CONFIG_NEW_REF_SIGNALING
+/*!
+ * \brief Structure to contain information about the reference frame mapping
+ * scheme.
+ */
+typedef struct {
+  /*!
+   * Distance of ref frame from current frame. Negative value indicates
+   * reference in the future, and positive value indicates reference in
+   * the past from the current frame
+   */
+  int ref_frame_distance[INTER_REFS_PER_FRAME];
+  /*!
+   * Total number of reference buffers available to the current frame.
+   */
+  int n_total_refs;
+  /*!
+   * Contains the indices of the frames in ref_frame_map that are future
+   * references.
+   */
+  int future_refs[INTER_REFS_PER_FRAME];
+  /*!
+   * Number of future references.
+   */
+  int n_future_refs;
+  /*!
+   * Contains the indices of the frames in ref_frame_map that are past
+   * references.
+   */
+  int past_refs[INTER_REFS_PER_FRAME];
+  /*!
+   * Number of past references.
+   */
+  int n_past_refs;
+  /*!
+   * Contains the indices of the frames in ref_frame_map with same order hint
+   * as current frame. -1 if unset.
+   */
+  int cur_refs[INTER_REFS_PER_FRAME];
+  /*!
+   * Number of references with the same order hint.
+   */
+  int n_cur_refs;
+} RefFramesInfo;
+#endif  // CONFIG_NEW_REF_SIGNALING
+
 /*!
  * \brief Top level common structure used by both encoder and decoder.
  */
 typedef struct AV1Common {
+#if CONFIG_THROUGHPUT_ANALYSIS
+  /*!
+   * Symbol stats.
+   */
+  struct total_sym_stats sym_stats;
+#endif  // CONFIG_THROUGHPUT_ANALYSIS
+  /*!
+   * Bitmask indicating which reference buffers may be referenced by this frame.
+   */
+  int ref_frame_flags;
+
   /*!
    * Information about the current frame that is being coded.
    */
@@ -884,6 +1019,35 @@
    */
   RefCntBuffer *cur_frame;
 
+#if CONFIG_NEW_REF_SIGNALING
+  /*!
+   * An alternative to remapped_ref_idx (above) which contains a mapping to
+   * ref_frame_map[] according to a "usefulness" score. It also contains all
+   * other relevant data to aid the reference mapping and signaling.
+   */
+  RefFramesInfo ref_frames_info;
+  /*!
+   * For encoder, we have a two-level mapping from reference frame type to the
+   * corresponding buffer in the buffer pool:
+   * * 'remapped_ref_idx[i - 1]' maps reference type 'i' (range: 0 ...
+   * INTER_REFS_PER_FRAME - 1) to a remapped index 'j' in the same range.
+   * * Later, 'cm->ref_frame_map[j]' maps the remapped index 'j' to a pointer to
+   * the reference counted buffer structure RefCntBuffer, taken from the buffer
+   * pool cm->buffer_pool->frame_bufs.
+   *
+   *      0,               ...,            INTER_REFS_PER_FRAME - 1
+   *      |                                           |
+   *      v                                           v
+   * remapped_ref_idx[0],  ...,     remapped_ref_idx[INTER_REFS_PER_FRAME- 1]
+   *      |                                           |
+   *      v                                           v
+   * ref_frame_map[],      ...,                ref_frame_map[]
+   *
+   * Note: INTRA_FRAME always refers to the current frame, so there's no need to
+   * have a remapped index for the same.
+   */
+  int remapped_ref_idx[REF_FRAMES];
+#else
   /*!
    * For encoder, we have a two-level mapping from reference frame type to the
    * corresponding buffer in the buffer pool:
@@ -905,6 +1069,7 @@
    * have a remapped index for the same.
    */
   int remapped_ref_idx[REF_FRAMES];
+#endif  // CONFIG_NEW_REF_SIGNALING
 
   /*!
    * Scale of the current frame with respect to itself.
@@ -1027,7 +1192,11 @@
   /*!
    * Global motion parameters for each reference frame.
    */
+#if CONFIG_NEW_REF_SIGNALING
+  WarpedMotionParams global_motion[INTER_REFS_PER_FRAME];
+#else
   WarpedMotionParams global_motion[REF_FRAMES];
+#endif  // CONFIG_NEW_REF_SIGNALING
 
   /*!
    * Elements part of the sequence header, that are applicable for all the
@@ -1088,13 +1257,21 @@
    * ref_frame_sign_bias[k] is 1 if relative distance between reference 'k' and
    * current frame is positive; and 0 otherwise.
    */
+#if CONFIG_NEW_REF_SIGNALING
+  int ref_frame_sign_bias[INTER_REFS_PER_FRAME];
+#else
   int ref_frame_sign_bias[REF_FRAMES];
+#endif  // CONFIG_NEW_REF_SIGNALING
   /*!
    * ref_frame_side[k] is 1 if relative distance between reference 'k' and
    * current frame is positive, -1 if relative distance is 0; and 0 otherwise.
    * TODO(jingning): This can be combined with sign_bias later.
    */
+#if CONFIG_NEW_REF_SIGNALING
+  int8_t ref_frame_side[INTER_REFS_PER_FRAME];
+#else
   int8_t ref_frame_side[REF_FRAMES];
+#endif  // CONFIG_NEW_REF_SIGNALING
 #if CONFIG_SMVP_IMPROVEMENT
   /*!
    * relative distance between reference 'k' and current frame.
@@ -1121,6 +1298,13 @@
    */
   int spatial_layer_id;
 
+#if CONFIG_IBP_DIR
+  /*!
+   * Weights for IBP of directional modes.
+   */
+  uint8_t *ibp_directional_weights[TX_SIZES_ALL][DIR_MODES_0_90];
+#endif
+
 #if TXCOEFF_TIMER
   int64_t cum_txcoeff_timer;
   int64_t txcoeff_timer;
@@ -1244,8 +1428,16 @@
   return cm->current_frame.frame_type == S_FRAME;
 }
 
-// These functions take a reference frame label between LAST_FRAME and
-// EXTREF_FRAME inclusive.  Note that this is different to the indexing
+#if CONFIG_NEW_REF_SIGNALING
+static INLINE int get_ref_frame_map_idx(const AV1_COMMON *const cm,
+                                        const int ref_frame) {
+  return (ref_frame >= 0 && ref_frame < REF_FRAMES)
+             ? cm->remapped_ref_idx[ref_frame]
+             : INVALID_IDX;
+}
+#else
+// This function takes a reference frame label between LAST_FRAME and
+// EXTREF_FRAME inclusive. Note that this is different to the indexing
 // previously used by the frame_refs[] array.
 static INLINE int get_ref_frame_map_idx(const AV1_COMMON *const cm,
                                         const MV_REFERENCE_FRAME ref_frame) {
@@ -1253,6 +1445,7 @@
              ? cm->remapped_ref_idx[ref_frame - LAST_FRAME]
              : INVALID_IDX;
 }
+#endif  // CONFIG_NEW_REF_SIGNALING
 
 static INLINE RefCntBuffer *get_ref_frame_buf(
     const AV1_COMMON *const cm, const MV_REFERENCE_FRAME ref_frame) {
@@ -1278,7 +1471,11 @@
     const AV1_COMMON *const cm) {
   const int primary_ref_frame = cm->features.primary_ref_frame;
   if (primary_ref_frame == PRIMARY_REF_NONE) return NULL;
+#if CONFIG_NEW_REF_SIGNALING
+  const int map_idx = get_ref_frame_map_idx(cm, primary_ref_frame);
+#else
   const int map_idx = get_ref_frame_map_idx(cm, primary_ref_frame + 1);
+#endif  // CONFIG_NEW_REF_SIGNALING
   return (map_idx != INVALID_IDX) ? cm->ref_frame_map[map_idx] : NULL;
 }
 
@@ -1468,6 +1665,19 @@
     xd->left_mbmi = NULL;
   }
 
+#if CONFIG_AIMC
+  if (xd->up_available) {
+    xd->above_right_mbmi = xd->mi[-xd->mi_stride + bw - 1];
+  } else {
+    xd->above_right_mbmi = NULL;
+  }
+  if (xd->left_available) {
+    xd->bottom_left_mbmi = xd->mi[-1 + xd->mi_stride * (bh - 1)];
+  } else {
+    xd->bottom_left_mbmi = NULL;
+  }
+#endif  // CONFIG_AIMC
+
   const int chroma_ref = ((mi_row & 0x01) || !(bh & 0x01) || !ss_y) &&
                          ((mi_col & 0x01) || !(bw & 0x01) || !ss_x);
   xd->is_chroma_ref = chroma_ref;
@@ -1507,6 +1717,7 @@
     if (!(mi_row & (xd->width - 1))) xd->is_first_horizontal_rect = 1;
 }
 
+#if !CONFIG_AIMC
 static INLINE aom_cdf_prob *get_y_mode_cdf(FRAME_CONTEXT *tile_ctx,
                                            const MB_MODE_INFO *above_mi,
                                            const MB_MODE_INFO *left_mi) {
@@ -1516,6 +1727,7 @@
   const int left_ctx = intra_mode_context[left];
   return tile_ctx->kf_y_cdf[above_ctx][left_ctx];
 }
+#endif  // !CONFIG_AIMC
 
 static INLINE void update_partition_context(MACROBLOCKD *xd, int mi_row,
                                             int mi_col, BLOCK_SIZE subsize,
@@ -2223,7 +2435,162 @@
           seq_level_idx != SEQ_LEVEL_7_0 && seq_level_idx != SEQ_LEVEL_7_1 &&
           seq_level_idx != SEQ_LEVEL_7_2 && seq_level_idx != SEQ_LEVEL_7_3);
 }
+#if CONFIG_IBP_DIR
+// Intra derivative for second directional predictor of IBP
+// second_dr_intra_derivative[x] = 64*64/dr_intra_derivative[x]
+static const int16_t second_dr_intra_derivative[90] = {
+  0,    0, 0,        //
+  4,    0, 0,        // 3, ...
+  7,    0, 0,        // 6, ...
+  11,   0, 0, 0, 0,  // 9, ...
+  15,   0, 0,        // 14, ...
+  19,   0, 0,        // 17, ...
+  23,   0, 0,        // 20, ...
+  27,   0, 0,        // 23, ... (113 & 203 are base angles)
+  31,   0, 0,        // 26, ...
+  35,   0, 0,        // 29, ...
+  40,   0, 0, 0,     // 32, ...
+  46,   0, 0,        // 36, ...
+  51,   0, 0,        // 39, ...
+  58,   0, 0,        // 42, ...
+  64,   0, 0,        // 45, ... (45 & 135 are base angles)
+  72,   0, 0,        // 48, ...
+  80,   0, 0,        // 51, ...
+  91,   0, 0, 0,     // 54, ...
+  102,  0, 0,        // 58, ...
+  117,  0, 0,        // 61, ...
+  132,  0, 0,        // 64, ...
+  152,  0, 0,        // 67, ... (67 & 157 are base angles)
+  178,  0, 0,        // 70, ...
+  216,  0, 0,        // 73, ...
+  273,  0, 0, 0, 0,  // 76, ...
+  372,  0, 0,        // 81, ...
+  585,  0, 0,        // 84, ...
+  1365, 0, 0,        // 87, ...
+};
 
+// Generate the weights per pixel position for IBP
+static void av1_dr_prediction_z1_info(uint8_t *weights, int bw, int bh,
+                                      int txw_log2, int txh_log2, int dy,
+                                      int mode) {
+  int32_t r, c, y;
+
+  int len0 = -1;
+  int len1 = -1;
+  int f0 = 1024;
+  int f1 = 1024;
+  int f2 = 1024;
+  int d0 = 0;
+  int d1 = 0;
+  int d2 = 0;
+  if (mode == D67_PRED) {
+    f0 = ((bw <= 8) && (bh <= 8)) ? 512 : 1024;
+    f1 = ((bw <= 8) && (bh <= 8)) ? 256 : 512;
+    f2 = ((bw <= 8) && (bh <= 8)) ? 128 : 256;
+    d0 = ROUND_POWER_OF_TWO(f0 - f1, (txh_log2 - 1));
+    d1 = ROUND_POWER_OF_TWO(f1 - f2, (txw_log2 - 1));
+    d2 = ROUND_POWER_OF_TWO(f2, (txw_log2 - 1));
+  }
+  if (mode == V_PRED) {
+    f0 = ((bw <= 8) && (bh <= 8)) ? 256 : 512;
+    f1 = ((bw <= 8) && (bh <= 8)) ? 128 : 256;
+    f2 = ((bw <= 8) && (bh <= 8)) ? 64 : 128;
+    d0 = ROUND_POWER_OF_TWO(f0 - f1, (txh_log2 - 2));
+    d1 = ROUND_POWER_OF_TWO(f1 - f2, (txw_log2 - 1));
+    d2 = ROUND_POWER_OF_TWO(f2, (txw_log2 - 1));
+  }
+
+  for (r = 0; r < bh; ++r) {
+    if (mode == D67_PRED) {
+      len0 = (bh - r) >> 1;
+      len1 = ((bh - r) >> 1) + (bw >> 1);
+    }
+    if (mode == V_PRED) {
+      len0 = (bh - r) >> 2;
+      len1 = ((bh - r) >> 2) + (bw >> 1);
+    }
+    y = dy;
+    for (c = 0; c < bw; ++c, y += dy) {
+      uint32_t dist = ((r + 1) << 6) + y;
+      int16_t shift = 0;
+      int16_t div = resolve_divisor_32(dist, &shift);
+      shift -= DIV_LUT_BITS;
+      int32_t weight0 = ROUND_POWER_OF_TWO(y * div, shift);
+      if ((len0 > -1) && (len1 > -1)) {
+        int weight1 = IBP_WEIGHT_MAX - weight0;
+        if (c <= len0) {
+          int fac = ((len0 - c) * d0 + f1);
+          weight1 = (fac > f0) ? weight1 * f0 : weight1 * fac;
+        } else if (c <= len1) {
+          int fac = ((len1 - c) * d1 + f2);
+          weight1 = (fac > f1) ? weight1 * f1 : weight1 * fac;
+        } else {
+          int fac = (f2 - (c - len1) * d2);
+          weight1 = (fac < 0) ? 0 : weight1 * fac;
+        }
+        weight1 = ROUND_POWER_OF_TWO(weight1, 10);
+        weight0 = IBP_WEIGHT_MAX - weight1;
+      }
+      weights[c] = weight0;
+    }
+    weights += bw;
+  }
+}
+static const uint8_t angle_to_mode_index[90] = {
+  0, 0, 0,  0, 0, 0,  0, 0, 0,  0, 0, 0, 0, 0,  0, 0, 0,  0, 0, 0,  0, 0, 0,
+  0, 0, 0,  0, 0, 0,  0, 0, 0,  0, 0, 0, 0, 16, 0, 0, 15, 0, 0, 14, 0, 0, 13,
+  0, 0, 12, 0, 0, 11, 0, 0, 10, 0, 0, 0, 9, 0,  0, 8, 0,  0, 7, 0,  0, 6, 0,
+  0, 5, 0,  0, 4, 0,  0, 3, 0,  0, 0, 0, 2, 0,  0, 1, 0,  0, 0, 0,  0
+};
+
+// Generate weights for IBP of one directional mode
+static INLINE void init_ibp_info_per_mode(
+    uint8_t *weights[TX_SIZES_ALL][DIR_MODES_0_90], int block_idx, int mode,
+    int delta, int txw, int txh, int txw_log2, int txh_log2) {
+  const int angle = mode_to_angle_map[mode] + delta * 3;
+  const int mode_idx = angle_to_mode_index[angle];
+  const int dy = second_dr_intra_derivative[angle];
+  weights[block_idx][mode_idx] =
+      (uint8_t *)(aom_calloc(txw * txh, sizeof(uint8_t)));
+  av1_dr_prediction_z1_info(weights[block_idx][mode_idx], txw, txh, txw_log2,
+                            txh_log2, dy, mode);
+  return;
+}
+
+// Generate weights for IBP of directional modes
+static INLINE void init_ibp_info(
+    uint8_t *weights[TX_SIZES_ALL][DIR_MODES_0_90]) {
+  assert(weights != NULL);
+  for (TX_SIZE iblock = TX_4X4; iblock < TX_SIZES_ALL; iblock++) {
+    const int txw = tx_size_wide[iblock];
+    const int txh = tx_size_high[iblock];
+    const int txw_log2 = tx_size_wide_log2[iblock];
+    const int txh_log2 = tx_size_high_log2[iblock];
+    for (int delta = -3; delta < 0; delta++) {
+      init_ibp_info_per_mode(weights, iblock, V_PRED, delta, txw, txh, txw_log2,
+                             txh_log2);
+      init_ibp_info_per_mode(weights, iblock, D67_PRED, delta, txw, txh,
+                             txw_log2, txh_log2);
+      init_ibp_info_per_mode(weights, iblock, D45_PRED, delta, txw, txh,
+                             txw_log2, txh_log2);
+    }
+    for (int delta = 0; delta <= 3; delta++) {
+      init_ibp_info_per_mode(weights, iblock, D67_PRED, delta, txw, txh,
+                             txw_log2, txh_log2);
+      init_ibp_info_per_mode(weights, iblock, D45_PRED, delta, txw, txh,
+                             txw_log2, txh_log2);
+    }
+  }
+}
+static INLINE void free_ibp_info(
+    uint8_t *weights[TX_SIZES_ALL][DIR_MODES_0_90]) {
+  for (int i = 0; i < TX_SIZES_ALL; i++) {
+    for (int j = 0; j < DIR_MODES_0_90; j++) {
+      aom_free(weights[i][j]);
+    }
+  }
+}
+#endif
 /*!\endcond */
 
 #ifdef __cplusplus
diff --git a/av1/common/av1_inv_txfm1d.c b/av1/common/av1_inv_txfm1d.c
index 8d69efc..1f37ad6 100644
--- a/av1/common/av1_inv_txfm1d.c
+++ b/av1/common/av1_inv_txfm1d.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <stdlib.h>
diff --git a/av1/common/av1_inv_txfm1d.h b/av1/common/av1_inv_txfm1d.h
index e1d5d98..9d1bd6d 100644
--- a/av1/common/av1_inv_txfm1d.h
+++ b/av1/common/av1_inv_txfm1d.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_COMMON_AV1_INV_TXFM1D_H_
diff --git a/av1/common/av1_inv_txfm1d_cfg.h b/av1/common/av1_inv_txfm1d_cfg.h
index 47fedbd..325679e 100644
--- a/av1/common/av1_inv_txfm1d_cfg.h
+++ b/av1/common/av1_inv_txfm1d_cfg.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_COMMON_AV1_INV_TXFM1D_CFG_H_
diff --git a/av1/common/av1_inv_txfm2d.c b/av1/common/av1_inv_txfm2d.c
index 559d121..6f06ab3 100644
--- a/av1/common/av1_inv_txfm2d.c
+++ b/av1/common/av1_inv_txfm2d.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "config/aom_dsp_rtcd.h"
diff --git a/av1/common/av1_loopfilter.c b/av1/common/av1_loopfilter.c
index 6bbb854..152e977 100644
--- a/av1/common/av1_loopfilter.c
+++ b/av1/common/av1_loopfilter.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <math.h>
@@ -36,6 +37,9 @@
   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  // INTRA_MODES
   1, 0, 1,                                // INTER_SINGLE_MODES (GLOBALMV == 0)
   1, 1, 1, 0, 1,  // INTER_COMPOUND_MODES (GLOBAL_GLOBALMV == 0)
+#if CONFIG_OPTFLOW_REFINEMENT
+  1, 1, 1, 1,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 };
 #else
 static const int mode_lf_lut[] = {
@@ -95,15 +99,27 @@
 
     if (cm->lf.mode_ref_delta_enabled) {
       const int scale = 1 << (lvl_seg >> 5);
-      lvl_seg += cm->lf.ref_deltas[mbmi->ref_frame[0]] * scale;
-      if (mbmi->ref_frame[0] > INTRA_FRAME)
+#if CONFIG_NEW_REF_SIGNALING
+      lvl_seg +=
+          cm->lf.ref_deltas[COMPACT_INDEX0_NRS(mbmi->ref_frame[0])] * scale;
+      if (is_inter_ref_frame(mbmi->ref_frame[0]))
         lvl_seg += cm->lf.mode_deltas[mode_lf_lut[mbmi->mode]] * scale;
+#else
+      lvl_seg += cm->lf.ref_deltas[mbmi->ref_frame[0]] * scale;
+      if (is_inter_ref_frame(mbmi->ref_frame[0]))
+        lvl_seg += cm->lf.mode_deltas[mode_lf_lut[mbmi->mode]] * scale;
+#endif  // CONFIG_NEW_REF_SIGNALING
       lvl_seg = clamp(lvl_seg, 0, MAX_LOOP_FILTER);
     }
     return lvl_seg;
   } else {
+#if CONFIG_NEW_REF_SIGNALING
+    return lfi_n->lvl[plane][segment_id][dir_idx][COMPACT_INDEX0_NRS(
+        mbmi->ref_frame[0])][mode_lf_lut[mbmi->mode]];
+#else
     return lfi_n->lvl[plane][segment_id][dir_idx][mbmi->ref_frame[0]]
                      [mode_lf_lut[mbmi->mode]];
+#endif  // CONFIG_NEW_REF_SIGNALING
   }
 }
 
@@ -177,11 +193,18 @@
         } else {
           int ref, mode;
           const int scale = 1 << (lvl_seg >> 5);
+#if CONFIG_NEW_REF_SIGNALING
+          const int intra_lvl =
+              lvl_seg + lf->ref_deltas[INTRA_FRAME_INDEX_NRS] * scale;
+          lfi->lvl[plane][seg_id][dir][INTRA_FRAME_INDEX_NRS][0] =
+              clamp(intra_lvl, 0, MAX_LOOP_FILTER);
+          for (ref = 0; ref < INTER_REFS_PER_FRAME; ++ref) {
+#else
           const int intra_lvl = lvl_seg + lf->ref_deltas[INTRA_FRAME] * scale;
           lfi->lvl[plane][seg_id][dir][INTRA_FRAME][0] =
               clamp(intra_lvl, 0, MAX_LOOP_FILTER);
-
           for (ref = LAST_FRAME; ref < REF_FRAMES; ++ref) {
+#endif  // CONFIG_NEW_REF_SIGNALING
             for (mode = 0; mode < MAX_MODE_LF_DELTAS; ++mode) {
               const int inter_lvl = lvl_seg + lf->ref_deltas[ref] * scale +
                                     lf->mode_deltas[mode] * scale;
diff --git a/av1/common/av1_loopfilter.h b/av1/common/av1_loopfilter.h
index ca16bbe..fabc834 100644
--- a/av1/common/av1_loopfilter.h
+++ b/av1/common/av1_loopfilter.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_COMMON_AV1_LOOPFILTER_H_
@@ -90,8 +91,11 @@
   uint8_t mode_ref_delta_enabled;
   uint8_t mode_ref_delta_update;
 
-  // 0 = Intra, Last, Last2+Last3,
-  // GF, BRF, ARF2, ARF
+#if CONFIG_NEW_REF_SIGNALING
+  // The order is based on the ranked references.
+#else
+  // 0 = Intra, Last, Last2+Last3, GF, BRF, ARF2, ARF
+#endif  // CONFIG_NEW_REF_SIGNALING
   int8_t ref_deltas[REF_FRAMES];
 
   // 0 = ZERO_MV, MV
diff --git a/av1/common/av1_rtcd.c b/av1/common/av1_rtcd.c
index a77a4d2..b178deb 100644
--- a/av1/common/av1_rtcd.c
+++ b/av1/common/av1_rtcd.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #include "config/aom_config.h"
 
diff --git a/av1/common/av1_rtcd_defs.pl b/av1/common/av1_rtcd_defs.pl
index 4861b56..7bc3650 100644
--- a/av1/common/av1_rtcd_defs.pl
+++ b/av1/common/av1_rtcd_defs.pl
@@ -1,12 +1,12 @@
 ##
-## Copyright (c) 2017, Alliance for Open Media. All rights reserved
+## Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ##
-## This source code is subject to the terms of the BSD 2 Clause License and
-## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-## was not distributed with this source code in the LICENSE file, you can
-## obtain it at www.aomedia.org/license/software. If the Alliance for Open
-## Media Patent License 1.0 was not distributed with this source code in the
-## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+## This source code is subject to the terms of the BSD 3-Clause Clear License and the
+## Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+## not distributed with this source code in the LICENSE file, you can obtain it
+## at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+## License 1.0 was not distributed with this source code in the PATENTS file, you
+## can obtain it at aomedia.org/license/patent-license/.
 ##
 sub av1_common_forward_decls() {
 print <<EOF
@@ -115,10 +115,41 @@
     specialize qw/av1_dr_prediction_z3 avx2 neon/;
 }
 
+#if CONFIG_IBP_DIR
+add_proto qw / void av1_ibp_dr_prediction_z1 /,
+    "uint8_t* weights, uint8_t *dst, ptrdiff_t stride, uint8_t* second_pred, ptrdiff_t second_stride, int bw, int bh";
+add_proto qw / void av1_ibp_dr_prediction_z3 /,
+    "uint8_t* weights, uint8_t *dst, ptrdiff_t stride, uint8_t* second_pred, ptrdiff_t second_stride, int bw, int bh";
+#endif
+
 # FILTER_INTRA predictor functions
 add_proto qw/void av1_filter_intra_predictor/, "uint8_t *dst, ptrdiff_t stride, TX_SIZE tx_size, const uint8_t *above, const uint8_t *left, int mode";
 specialize qw/av1_filter_intra_predictor sse4_1 neon/;
 
+# optical flow interpolation function
+if (aom_config("CONFIG_OPTFLOW_REFINEMENT") eq "yes") {
+  add_proto qw/void av1_bicubic_grad_interpolation/, "const int16_t *pred_src,int16_t *x_grad,int16_t *y_grad,const int blk_width,const int blk_height";
+  specialize qw/av1_bicubic_grad_interpolation sse4_1/;
+
+  add_proto qw/void av1_bicubic_grad_interpolation_highbd/, "const int16_t *pred_src,int16_t *x_grad,int16_t *y_grad,const int blk_width,const int blk_height";
+  specialize qw/av1_bicubic_grad_interpolation_highbd sse4_1/;
+
+  add_proto qw/int av1_opfl_mv_refinement_nxn_lowbd/, " const uint8_t *p0, int pstride0, const uint8_t *p1, int pstride1, const int16_t *gx0, const int16_t *gy0, const int16_t *gx1, const int16_t *gy1, int gstride, int bw, int bh, int n, int d0, int d1, int grad_prec_bits, int mv_prec_bits, int *vx0, int *vy0, int *vx1, int *vy1";
+  specialize qw/av1_opfl_mv_refinement_nxn_lowbd sse4_1/;
+
+  add_proto qw/int av1_opfl_mv_refinement_nxn_highbd/, " const uint16_t *p0, int pstride0, const uint16_t *p1, int pstride1, const int16_t *gx0, const int16_t *gy0, const int16_t *gx1, const int16_t *gy1, int gstride, int bw, int bh, int n, int d0, int d1, int grad_prec_bits, int mv_prec_bits, int *vx0, int *vy0, int *vx1, int *vy1";
+  specialize qw/av1_opfl_mv_refinement_nxn_highbd sse4_1/;
+
+  add_proto qw/int av1_opfl_mv_refinement_nxn_interp_grad/, " const int16_t *pdiff, int pstride,const int16_t *gx, const int16_t *gy, int gstride, int bw, int bh, int n,int d0, int d1, int grad_prec_bits,int mv_prec_bits, int *vx0, int *vy0,int *vx1, int *vy1";
+  specialize qw/av1_opfl_mv_refinement_nxn_interp_grad sse4_1/;
+
+  add_proto qw/void av1_copy_pred_array/, "const uint8_t *src1, const uint8_t *src2, int16_t *dst1,int16_t *dst2, int bw, int bh,int d0, int d1";
+  specialize qw/av1_copy_pred_array sse4_1/;
+
+  add_proto qw/void av1_copy_pred_array_highbd/, "const uint16_t *src1, const uint16_t *src2, int16_t *dst1,int16_t *dst2, int bw, int bh, int d0, int d1";
+  specialize qw/av1_copy_pred_array_highbd sse4_1/;
+}
+
 # High bitdepth functions
 
 #
@@ -274,6 +305,13 @@
   specialize qw/av1_highbd_dr_prediction_z3 avx2/;
 }
 
+#if CONFIG_IBP_DIR
+add_proto qw / void av1_highbd_ibp_dr_prediction_z1 /,
+    "uint8_t* weights, uint16_t *dst, ptrdiff_t stride, uint16_t* second_pred, ptrdiff_t second_stride, int bw, int bh";
+add_proto qw / void av1_highbd_ibp_dr_prediction_z3 /,
+    "uint8_t* weights, uint16_t *dst, ptrdiff_t stride, uint16_t* second_pred, ptrdiff_t second_stride, int bw, int bh";
+#endif
+
 # build compound seg mask functions
 add_proto qw/void av1_build_compound_diffwtd_mask/, "uint8_t *mask, DIFFWTD_MASK_TYPE mask_type, const uint8_t *src0, int src0_stride, const uint8_t *src1, int src1_stride, int h, int w";
 specialize qw/av1_build_compound_diffwtd_mask sse4_1 avx2/;
@@ -432,10 +470,14 @@
   specialize qw/av1_get_crc32c_value sse4_2/;
 
   add_proto qw/void av1_compute_stats/,  "int wiener_win, const uint8_t *dgd8, const uint8_t *src8, int h_start, int h_end, int v_start, int v_end, int dgd_stride, int src_stride, int64_t *M, int64_t *H";
-  specialize qw/av1_compute_stats sse4_1 avx2/;
+  if (aom_config("CONFIG_EXCLUDE_SIMD_MISMATCH") ne "yes") {
+      specialize qw/av1_compute_stats sse4_1 avx2/;
+  }
 
   add_proto qw/void av1_compute_stats_highbd/,  "int wiener_win, const uint8_t *dgd8, const uint8_t *src8, int h_start, int h_end, int v_start, int v_end, int dgd_stride, int src_stride, int64_t *M, int64_t *H, aom_bit_depth_t bit_depth";
-  specialize qw/av1_compute_stats_highbd sse4_1 avx2/;
+  if (aom_config("CONFIG_EXCLUDE_SIMD_MISMATCH") ne "yes") {
+      specialize qw/av1_compute_stats_highbd sse4_1 avx2/;
+  }
 
   add_proto qw/void av1_calc_proj_params/, " const uint8_t *src8, int width, int height, int src_stride, const uint8_t *dat8, int dat_stride, int32_t *flt0, int flt0_stride, int32_t *flt1, int flt1_stride, int64_t H[2][2], int64_t C[2], const sgr_params_type *params";
   specialize qw/av1_calc_proj_params avx2/;
@@ -449,7 +491,9 @@
   specialize qw/av1_get_horver_correlation_full sse4_1 avx2 neon/;
 
   add_proto qw/void av1_nn_predict/, " const float *input_nodes, const NN_CONFIG *const nn_config, int reduce_prec, float *const output";
-  specialize qw/av1_nn_predict sse3 neon/;
+  if (aom_config("CONFIG_EXCLUDE_SIMD_MISMATCH") ne "yes") {
+    specialize qw/av1_nn_predict sse3 neon/;
+  }
 }
 # end encoder functions
 
diff --git a/av1/common/av1_txfm.c b/av1/common/av1_txfm.c
index ac43402..0652f02 100644
--- a/av1/common/av1_txfm.c
+++ b/av1/common/av1_txfm.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "config/aom_dsp_rtcd.h"
diff --git a/av1/common/av1_txfm.h b/av1/common/av1_txfm.h
index 20049b6..3e00e41 100644
--- a/av1/common/av1_txfm.h
+++ b/av1/common/av1_txfm.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_COMMON_AV1_TXFM_H_
diff --git a/av1/common/blockd.c b/av1/common/blockd.c
index e8612f2..cab289e 100644
--- a/av1/common/blockd.c
+++ b/av1/common/blockd.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <math.h>
@@ -16,6 +17,18 @@
 #include "av1/common/av1_common_int.h"
 #include "av1/common/blockd.h"
 
+#if CONFIG_AIMC
+PREDICTION_MODE av1_get_joint_mode(const MB_MODE_INFO *mi) {
+  if (!mi) return DC_PRED;
+#if CONFIG_SDP
+  if (is_inter_block(mi, SHARED_PART) || is_intrabc_block(mi, SHARED_PART))
+    return DC_PRED;
+#else
+  if (is_inter_block(mi) || is_intrabc_block(mi)) return DC_PRED;
+#endif  // CONFIG_SDP
+  return mi->joint_y_mode_delta_angle;
+}
+#else
 PREDICTION_MODE av1_left_block_mode(const MB_MODE_INFO *left_mi) {
   if (!left_mi) return DC_PRED;
 #if CONFIG_SDP
@@ -37,6 +50,7 @@
 #endif
   return above_mi->mode;
 }
+#endif  // CONFIG_AIMC
 
 void av1_set_entropy_contexts(const MACROBLOCKD *xd,
                               struct macroblockd_plane *pd, int plane,
diff --git a/av1/common/blockd.h b/av1/common/blockd.h
index 97be296..2fd096c 100644
--- a/av1/common/blockd.h
+++ b/av1/common/blockd.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_COMMON_BLOCKD_H_
@@ -18,6 +19,7 @@
 #include "aom_ports/mem.h"
 #include "aom_scale/yv12config.h"
 
+#include "av1/common/alloccommon.h"
 #include "av1/common/common_data.h"
 #include "av1/common/quant_common.h"
 #include "av1/common/entropy.h"
@@ -109,6 +111,12 @@
     NEWMV,      // NEW_NEARMV
     GLOBALMV,   // GLOBAL_GLOBALMV
     NEWMV,      // NEW_NEWMV
+#if CONFIG_OPTFLOW_REFINEMENT
+    NEARMV,  // NEAR_NEARMV_OPTFLOW
+    NEARMV,  // NEAR_NEWMV_OPTFLOW
+    NEWMV,   // NEW_NEARMV_OPTFLOW
+    NEWMV,   // NEW_NEWMV_OPTFLOW
+#endif       // CONFIG_OPTFLOW_REFINEMENT
   };
   assert(NELEMENTS(lut) == MB_MODE_COUNT);
   assert(is_inter_compound_mode(mode) || is_inter_singleref_mode(mode));
@@ -148,6 +156,12 @@
     NEARMV,     // NEW_NEARMV
     GLOBALMV,   // GLOBAL_GLOBALMV
     NEWMV,      // NEW_NEWMV
+#if CONFIG_OPTFLOW_REFINEMENT
+    NEARMV,  // NEAR_NEARMV_OPTFLOW
+    NEWMV,   // NEAR_NEWMV_OPTFLOW
+    NEARMV,  // NEW_NEARMV_OPTFLOW
+    NEWMV,   // NEW_NEWMV_OPTFLOW
+#endif       // CONFIG_OPTFLOW_REFINEMENT
   };
   assert(NELEMENTS(lut) == MB_MODE_COUNT);
   assert(is_inter_compound_mode(mode));
@@ -156,12 +170,28 @@
 
 static INLINE int have_nearmv_in_inter_mode(PREDICTION_MODE mode) {
   return (mode == NEARMV || mode == NEAR_NEARMV || mode == NEAR_NEWMV ||
+#if CONFIG_OPTFLOW_REFINEMENT
+          mode == NEAR_NEARMV_OPTFLOW || mode == NEAR_NEWMV_OPTFLOW ||
+          mode == NEW_NEARMV_OPTFLOW ||
+#endif  // CONFIG_OPTFLOW_REFINEMENT
           mode == NEW_NEARMV);
 }
 
+static INLINE int have_nearmv_newmv_in_inter_mode(PREDICTION_MODE mode) {
+  return mode == NEAR_NEWMV ||
+#if CONFIG_OPTFLOW_REFINEMENT
+         mode == NEAR_NEWMV_OPTFLOW || mode == NEW_NEARMV_OPTFLOW ||
+#endif  // CONFIG_OPTFLOW_REFINEMENT
+         mode == NEW_NEARMV;
+}
+
 #if CONFIG_NEW_INTER_MODES
 static INLINE int have_newmv_in_inter_mode(PREDICTION_MODE mode) {
   return (mode == NEWMV || mode == NEW_NEWMV || mode == NEAR_NEWMV ||
+#if CONFIG_OPTFLOW_REFINEMENT
+          mode == NEAR_NEWMV_OPTFLOW || mode == NEW_NEARMV_OPTFLOW ||
+          mode == NEW_NEWMV_OPTFLOW ||
+#endif  // CONFIG_OPTFLOW_REFINEMENT
           mode == NEW_NEARMV);
 }
 static INLINE int have_drl_index(PREDICTION_MODE mode) {
@@ -237,6 +267,21 @@
   COMPOUND_TYPE type;
 } INTERINTER_COMPOUND_DATA;
 
+#if CONFIG_OPTFLOW_REFINEMENT
+// Macros for optical flow experiment where offsets are added in nXn blocks
+// rather than adding a single offset to the entire prediction unit.
+#define OF_MIN_BSIZE_LOG2 2
+#define OF_BSIZE_LOG2 3
+// Block size to use to divide up the prediction unit
+#define OF_MIN_BSIZE (1 << OF_MIN_BSIZE_LOG2)
+#define OF_BSIZE (1 << OF_BSIZE_LOG2)
+#define N_OF_OFFSETS_1D (1 << (MAX_SB_SIZE_LOG2 - OF_BSIZE_LOG2))
+// Maximum number of offsets to be computed
+#define N_OF_OFFSETS (N_OF_OFFSETS_1D * N_OF_OFFSETS_1D)
+#else
+#define N_OF_OFFSETS 1
+#endif  // CONFIG_OPTFLOW_REFINEMENT
+
 #define INTER_TX_SIZE_BUF_LEN 16
 #define TXK_TYPE_BUF_LEN 64
 /*!\endcond */
@@ -319,6 +364,18 @@
   /*! \brief Reference line index for multiple reference line selection. */
   uint8_t mrl_index;
 #endif
+#if CONFIG_AIMC
+  /*! \brief mode index of y mode and y delta angle after re-ordering. */
+  uint8_t y_mode_idx;
+  /*! \brief mode index of uv mode after re-ordering. */
+  uint8_t uv_mode_idx;
+  /*! \brief joint mode index of y mode and y delta angle before re-ordering. */
+  uint8_t joint_y_mode_delta_angle;
+  /*! \brief re-ordered mode list for y mode and y delta angle. */
+  uint8_t y_intra_mode_list[LUMA_MODE_COUNT];
+  /*! \brief re-ordered mode list for uv mode. */
+  uint8_t uv_intra_mode_list[UV_INTRA_MODES];
+#endif  // CONFIG_AIMC
   /**@}*/
 
   /*****************************************************************************
@@ -371,8 +428,6 @@
 #endif
   /*! \brief Indicates if masked compound is used(1) or not (0). */
   uint8_t comp_group_idx : 1;
-  /*! \brief Indicates whether dist_wtd_comp(0) is used or not (0). */
-  uint8_t compound_idx : 1;
   /*! \brief Whether to use interintra wedge */
   uint8_t use_wedge_interintra : 1;
   /*! \brief CDEF strength per BLOCK_64X64 */
@@ -434,20 +489,39 @@
   return uv2y[mode];
 }
 
+static INLINE int is_inter_ref_frame(MV_REFERENCE_FRAME ref_frame) {
+#if CONFIG_NEW_REF_SIGNALING
+  return ref_frame != INTRA_FRAME_NRS && ref_frame != INVALID_IDX;
+#else
+  return ref_frame > INTRA_FRAME;
+#endif  // CONFIG_NEW_REF_SIGNALING
+}
+
 #if CONFIG_SDP
 static INLINE int is_inter_block(const MB_MODE_INFO *mbmi, int tree_type) {
-  return is_intrabc_block(mbmi, tree_type) || mbmi->ref_frame[0] > INTRA_FRAME;
+#if CONFIG_NEW_REF_SIGNALING
+  return is_intrabc_block(mbmi, tree_type) ||
+         mbmi->ref_frame[0] != INTRA_FRAME_NRS;
+#else
+  return is_intrabc_block(mbmi, tree_type) ||
+         is_inter_ref_frame(mbmi->ref_frame[0]);
+#endif  // CONFIG_NEW_REF_SIGNALING
 }
 #else
 static INLINE int is_inter_block(const MB_MODE_INFO *mbmi) {
-  return is_intrabc_block(mbmi) || mbmi->ref_frame[0] > INTRA_FRAME;
+#if CONFIG_NEW_REF_SIGNALING
+  return is_intrabc_block(mbmi) || mbmi->ref_frame[0] != INTRA_FRAME_NRS;
+#else
+  return is_intrabc_block(mbmi) || is_inter_ref_frame(mbmi->ref_frame[0]);
+#endif  // CONFIG_NEW_REF_SIGNALING
 }
 #endif
 
 static INLINE int has_second_ref(const MB_MODE_INFO *mbmi) {
-  return mbmi->ref_frame[1] > INTRA_FRAME;
+  return is_inter_ref_frame(mbmi->ref_frame[1]);
 }
 
+#if !CONFIG_NEW_REF_SIGNALING
 static INLINE int has_uni_comp_refs(const MB_MODE_INFO *mbmi) {
   return has_second_ref(mbmi) && (!((mbmi->ref_frame[0] >= BWDREF_FRAME) ^
                                     (mbmi->ref_frame[1] >= BWDREF_FRAME)));
@@ -484,10 +558,15 @@
   assert(NELEMENTS(lut) == TOTAL_UNIDIR_COMP_REFS);
   return lut[ref_idx];
 }
+#endif  // !CONFIG_NEW_REF_SIGNALING
 
+#if CONFIG_AIMC
+PREDICTION_MODE av1_get_joint_mode(const MB_MODE_INFO *mi);
+#else
 PREDICTION_MODE av1_left_block_mode(const MB_MODE_INFO *left_mi);
 
 PREDICTION_MODE av1_above_block_mode(const MB_MODE_INFO *above_mi);
+#endif  // CONFIG_AIMC
 
 static INLINE int is_global_mv_block(const MB_MODE_INFO *const mbmi,
                                      TransformationType type) {
@@ -647,6 +726,30 @@
 
 /*!\endcond */
 
+#if CONFIG_REF_MV_BANK
+#define REF_MV_BANK_SIZE 4
+
+/*! \brief Variables related to reference MV bank. */
+typedef struct {
+  /*!
+   * Number of ref MVs in the buffer.
+   */
+  int rmb_count[MODE_CTX_REF_FRAMES];
+  /*!
+   * Index corresponding to the first ref MV in the buffer.
+   */
+  int rmb_start_idx[MODE_CTX_REF_FRAMES];
+  /*!
+   * Circular buffer storing the ref MVs.
+   */
+  CANDIDATE_MV rmb_buffer[MODE_CTX_REF_FRAMES][REF_MV_BANK_SIZE];
+  /*!
+   * Total number of mbmi updates conducted in SB
+   */
+  int rmb_sb_hits;
+} REF_MV_BANK;
+#endif  // CONFIG_REF_MV_BANK
+
 /*! \brief Variables related to current coding block.
  *
  * This is a common set of variables used by both encoder and decoder.
@@ -667,6 +770,16 @@
    */
   int mi_stride;
 
+#if CONFIG_REF_MV_BANK
+  /**
+   * \name Reference MV bank info.
+   */
+  /**@{*/
+  REF_MV_BANK ref_mv_bank;     /*!< Ref mv bank to update */
+  REF_MV_BANK *ref_mv_bank_pt; /*!< Pointer to bank to refer to */
+  /**@}*/
+#endif  // CONFIG_REF_MV_BANK
+
   /*!
    * True if current block transmits chroma information.
    * More detail:
@@ -729,6 +842,18 @@
    * up_available == true; otherwise NULL.
    */
   MB_MODE_INFO *above_mbmi;
+#if CONFIG_AIMC
+  /*!
+   * MB_MODE_INFO for 4x4 block to the bottom-left of the current block, if
+   * left_available == true; otherwise NULL.
+   */
+  MB_MODE_INFO *bottom_left_mbmi;
+  /*!
+   * MB_MODE_INFO for 4x4 block to the top-right of the current block, if
+   * up_available == true; otherwise NULL.
+   */
+  MB_MODE_INFO *above_right_mbmi;
+#endif  // CONFIG_AIMC
   /*!
    * Above chroma reference block if is_chroma_ref == true for the current block
    * and chroma_up_available == true; otherwise NULL.
@@ -905,7 +1030,11 @@
    * Counts of each reference frame in the above and left neighboring blocks.
    * NOTE: Take into account both single and comp references.
    */
+#if CONFIG_NEW_REF_SIGNALING
+  uint8_t neighbors_ref_counts[INTER_REFS_PER_FRAME];
+#else
   uint8_t neighbors_ref_counts[REF_FRAMES];
+#endif  // CONFIG_NEW_REF_SIGNALING
 
   /*!
    * Current CDFs of all the symbols for the current tile.
@@ -1047,6 +1176,18 @@
   /** ccso blk v */
   uint8_t ccso_blk_v;
 #endif
+
+#if CONFIG_CONTEXT_DERIVATION
+  /** buffer to store AOM_PLANE_U txfm coefficient signs */
+  int32_t tmp_sign[1024];
+  /** variable to store AOM_PLANE_U eob value */
+  uint16_t eob_u;
+#endif  // CONFIG_CONTEXT_DERIVATION
+
+#if CONFIG_CONTEXT_DERIVATION
+  /** variable to store eob_u flag */
+  uint8_t eob_u_flag;
+#endif  // CONFIG_CONTEXT_DERIVATION
 } MACROBLOCKD;
 
 /*!\cond */
@@ -1431,8 +1572,14 @@
   const int height = tx_size_high[tx_size];
   const int sb_size = (width >= 8 && height >= 8) ? 8 : 4;
   bool ist_eob = 1;
+#if CONFIG_IST_FIX_B076
+  // Updated EOB condition
+  if (((sb_size == 4) && (eob > IST_4x4_HEIGHT)) ||
+      ((sb_size == 8) && (eob > IST_8x8_HEIGHT))) {
+#else
   if (((sb_size == 4) && (eob > IST_4x4_HEIGHT - 1)) ||
       ((sb_size == 8) && (eob > IST_8x8_HEIGHT - 1))) {
+#endif  // CONFIG_IST_FIX_B076
     ist_eob = 0;
   }
   const int depth = tx_size_to_depth(tx_size, bs);
@@ -1625,8 +1772,13 @@
 
 #define MAX_INTERINTRA_SB_SQUARE 32 * 32
 static INLINE int is_interintra_mode(const MB_MODE_INFO *mbmi) {
-  return (mbmi->ref_frame[0] > INTRA_FRAME &&
+#if CONFIG_NEW_REF_SIGNALING
+  return (is_inter_ref_frame(mbmi->ref_frame[0]) &&
+          mbmi->ref_frame[1] == INTRA_FRAME_NRS);
+#else
+  return (is_inter_ref_frame(mbmi->ref_frame[0]) &&
           mbmi->ref_frame[1] == INTRA_FRAME);
+#endif  // CONFIG_NEW_REF_SIGNALING
 }
 
 static INLINE int is_interintra_allowed_bsize(const BLOCK_SIZE bsize) {
@@ -1638,7 +1790,7 @@
 }
 
 static INLINE int is_interintra_allowed_ref(const MV_REFERENCE_FRAME rf[2]) {
-  return (rf[0] > INTRA_FRAME) && (rf[1] <= INTRA_FRAME);
+  return is_inter_ref_frame(rf[0]) && !is_inter_ref_frame(rf[1]);
 }
 
 static INLINE int is_interintra_allowed(const MB_MODE_INFO *mbmi) {
@@ -1665,8 +1817,13 @@
 }
 
 static INLINE int is_interintra_pred(const MB_MODE_INFO *mbmi) {
-  return mbmi->ref_frame[0] > INTRA_FRAME &&
+#if CONFIG_NEW_REF_SIGNALING
+  return is_inter_ref_frame(mbmi->ref_frame[0]) &&
+         mbmi->ref_frame[1] == INTRA_FRAME_NRS && is_interintra_allowed(mbmi);
+#else
+  return is_inter_ref_frame(mbmi->ref_frame[0]) &&
          mbmi->ref_frame[1] == INTRA_FRAME && is_interintra_allowed(mbmi);
+#endif  // CONFIG_NEW_REF_SIGNALING
 }
 
 static INLINE int get_vartx_max_txsize(const MACROBLOCKD *xd, BLOCK_SIZE bsize,
@@ -1707,7 +1864,11 @@
 #else
   if (is_motion_variation_allowed_bsize(mbmi->sb_type) &&
 #endif
+#if CONFIG_NEW_REF_SIGNALING
+      is_inter_mode(mbmi->mode) && mbmi->ref_frame[1] != INTRA_FRAME_NRS &&
+#else
       is_inter_mode(mbmi->mode) && mbmi->ref_frame[1] != INTRA_FRAME &&
+#endif  // CONFIG_NEW_REF_SIGNALING
       is_motion_variation_allowed_compound(mbmi)) {
     if (!check_num_overlappable_neighbors(mbmi)) return SIMPLE_TRANSLATION;
     assert(!has_second_ref(mbmi));
diff --git a/av1/common/ccso.c b/av1/common/ccso.c
index 5596ceb..89123d9 100644
--- a/av1/common/ccso.c
+++ b/av1/common/ccso.c
@@ -1,12 +1,13 @@
 /*
  * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/av1/common/ccso.h b/av1/common/ccso.h
index bf05e6f..5990dce 100644
--- a/av1/common/ccso.h
+++ b/av1/common/ccso.h
@@ -1,12 +1,13 @@
 /*
  * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_COMMON_CCSO_H_
diff --git a/av1/common/cdef.c b/av1/common/cdef.c
index ffb0159..77c0726 100644
--- a/av1/common/cdef.c
+++ b/av1/common/cdef.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/av1/common/cdef.h b/av1/common/cdef.h
index 4d6e600..6b6e94f 100644
--- a/av1/common/cdef.h
+++ b/av1/common/cdef.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #ifndef AOM_AV1_COMMON_CDEF_H_
 #define AOM_AV1_COMMON_CDEF_H_
diff --git a/av1/common/cdef_block.c b/av1/common/cdef_block.c
index 7120705..7387360 100644
--- a/av1/common/cdef_block.c
+++ b/av1/common/cdef_block.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <math.h>
diff --git a/av1/common/cdef_block.h b/av1/common/cdef_block.h
index 6b0ae0a..aee6644 100644
--- a/av1/common/cdef_block.h
+++ b/av1/common/cdef_block.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_COMMON_CDEF_BLOCK_H_
diff --git a/av1/common/cdef_block_avx2.c b/av1/common/cdef_block_avx2.c
index e2b85b3..2e52203 100644
--- a/av1/common/cdef_block_avx2.c
+++ b/av1/common/cdef_block_avx2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "aom_dsp/aom_simd.h"
diff --git a/av1/common/cdef_block_neon.c b/av1/common/cdef_block_neon.c
index 2d6bc65..b8aff79 100644
--- a/av1/common/cdef_block_neon.c
+++ b/av1/common/cdef_block_neon.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "aom_dsp/aom_simd.h"
diff --git a/av1/common/cdef_block_simd.h b/av1/common/cdef_block_simd.h
index 5a52bc1..e9dbf38 100644
--- a/av1/common/cdef_block_simd.h
+++ b/av1/common/cdef_block_simd.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_COMMON_CDEF_BLOCK_SIMD_H_
diff --git a/av1/common/cdef_block_sse2.c b/av1/common/cdef_block_sse2.c
index 73f115d..880af78 100644
--- a/av1/common/cdef_block_sse2.c
+++ b/av1/common/cdef_block_sse2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "aom_dsp/aom_simd.h"
diff --git a/av1/common/cdef_block_sse4.c b/av1/common/cdef_block_sse4.c
index 349329a..32a29e0 100644
--- a/av1/common/cdef_block_sse4.c
+++ b/av1/common/cdef_block_sse4.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "aom_dsp/aom_simd.h"
diff --git a/av1/common/cdef_block_ssse3.c b/av1/common/cdef_block_ssse3.c
index 3a93b15..5050bc9 100644
--- a/av1/common/cdef_block_ssse3.c
+++ b/av1/common/cdef_block_ssse3.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "aom_dsp/aom_simd.h"
diff --git a/av1/common/cfl.c b/av1/common/cfl.c
index 718f6c0..b354b6c 100644
--- a/av1/common/cfl.c
+++ b/av1/common/cfl.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "av1/common/av1_common_int.h"
diff --git a/av1/common/cfl.h b/av1/common/cfl.h
index 2463e2d..edda998 100644
--- a/av1/common/cfl.h
+++ b/av1/common/cfl.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_COMMON_CFL_H_
diff --git a/av1/common/common.h b/av1/common/common.h
index bed6083..14c0b2d 100644
--- a/av1/common/common.h
+++ b/av1/common/common.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_COMMON_COMMON_H_
diff --git a/av1/common/common_data.h b/av1/common/common_data.h
index ca47b4a..5758ae0 100644
--- a/av1/common/common_data.h
+++ b/av1/common/common_data.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_COMMON_COMMON_DATA_H_
diff --git a/av1/common/convolve.c b/av1/common/convolve.c
index e55c3c9..26d0ea6 100644
--- a/av1/common/convolve.c
+++ b/av1/common/convolve.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/av1/common/convolve.h b/av1/common/convolve.h
index ee8da60..c93bc55 100644
--- a/av1/common/convolve.h
+++ b/av1/common/convolve.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_COMMON_CONVOLVE_H_
diff --git a/av1/common/debugmodes.c b/av1/common/debugmodes.c
index 4d8a9c2..993846d 100644
--- a/av1/common/debugmodes.c
+++ b/av1/common/debugmodes.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <stdio.h>
diff --git a/av1/common/entropy.c b/av1/common/entropy.c
index a5594c4..085124c 100644
--- a/av1/common/entropy.c
+++ b/av1/common/entropy.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "config/aom_config.h"
@@ -35,8 +36,15 @@
 #endif
 
   av1_copy(cm->fc->txb_skip_cdf, av1_default_txb_skip_cdfs[index]);
+#if CONFIG_CONTEXT_DERIVATION
+  av1_copy(cm->fc->v_txb_skip_cdf, av1_default_v_txb_skip_cdfs[index]);
+#endif  // CONFIG_CONTEXT_DERIVATION
   av1_copy(cm->fc->eob_extra_cdf, av1_default_eob_extra_cdfs[index]);
   av1_copy(cm->fc->dc_sign_cdf, av1_default_dc_sign_cdfs[index]);
+#if CONFIG_CONTEXT_DERIVATION
+  av1_copy(cm->fc->v_dc_sign_cdf, av1_default_v_dc_sign_cdfs[index]);
+  av1_copy(cm->fc->v_ac_sign_cdf, av1_default_v_ac_sign_cdfs[index]);
+#endif  // CONFIG_CONTEXT_DERIVATION
   av1_copy(cm->fc->coeff_br_cdf, av1_default_coeff_lps_multi_cdfs[index]);
   av1_copy(cm->fc->coeff_base_cdf, av1_default_coeff_base_multi_cdfs[index]);
   av1_copy(cm->fc->coeff_base_eob_cdf,
@@ -85,8 +93,15 @@
 
 void av1_reset_cdf_symbol_counters(FRAME_CONTEXT *fc) {
   RESET_CDF_COUNTER(fc->txb_skip_cdf, 2);
+#if CONFIG_CONTEXT_DERIVATION
+  RESET_CDF_COUNTER(fc->v_txb_skip_cdf, 2);
+#endif  // CONFIG_CONTEXT_DERIVATION
   RESET_CDF_COUNTER(fc->eob_extra_cdf, 2);
   RESET_CDF_COUNTER(fc->dc_sign_cdf, 2);
+#if CONFIG_CONTEXT_DERIVATION
+  RESET_CDF_COUNTER(fc->v_dc_sign_cdf, 2);
+  RESET_CDF_COUNTER(fc->v_ac_sign_cdf, 2);
+#endif  // CONFIG_CONTEXT_DERIVATION
   RESET_CDF_COUNTER(fc->eob_flag_cdf16, 5);
   RESET_CDF_COUNTER(fc->eob_flag_cdf32, 6);
   RESET_CDF_COUNTER(fc->eob_flag_cdf64, 7);
@@ -108,7 +123,12 @@
   RESET_CDF_COUNTER(fc->drl_cdf, 2);
   RESET_CDF_COUNTER(fc->refmv_cdf, 2);
 #endif  // CONFIG_NEW_INTER_MODES
+#if CONFIG_OPTFLOW_REFINEMENT
+  RESET_CDF_COUNTER(fc->use_optflow_cdf, 2);
+  RESET_CDF_COUNTER(fc->inter_compound_mode_cdf, INTER_COMPOUND_REF_TYPES);
+#else
   RESET_CDF_COUNTER(fc->inter_compound_mode_cdf, INTER_COMPOUND_MODES);
+#endif  // CONFIG_OPTFLOW_REFINEMENT
   RESET_CDF_COUNTER(fc->compound_type_cdf, MASKED_COMPOUND_TYPES);
   RESET_CDF_COUNTER(fc->wedge_idx_cdf, 16);
   RESET_CDF_COUNTER(fc->interintra_cdf, 2);
@@ -129,10 +149,12 @@
   RESET_CDF_COUNTER(fc->palette_uv_mode_cdf, 2);
   RESET_CDF_COUNTER(fc->comp_inter_cdf, 2);
   RESET_CDF_COUNTER(fc->single_ref_cdf, 2);
+  RESET_CDF_COUNTER(fc->comp_ref_cdf, 2);
+#if !CONFIG_NEW_REF_SIGNALING
   RESET_CDF_COUNTER(fc->comp_ref_type_cdf, 2);
   RESET_CDF_COUNTER(fc->uni_comp_ref_cdf, 2);
-  RESET_CDF_COUNTER(fc->comp_ref_cdf, 2);
   RESET_CDF_COUNTER(fc->comp_bwdref_cdf, 2);
+#endif  // CONFIG_NEW_REF_SIGNALING
 #if CONFIG_NEW_TX_PARTITION
   // Square blocks
   RESET_CDF_COUNTER(fc->inter_4way_txfm_partition_cdf[0], 4);
@@ -143,13 +165,15 @@
 #else   // CONFIG_NEW_TX_PARTITION
   RESET_CDF_COUNTER(fc->txfm_partition_cdf, 2);
 #endif  // CONFIG_NEW_TX_PARTITION
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-  RESET_CDF_COUNTER(fc->compound_index_cdf, 2);
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
   RESET_CDF_COUNTER(fc->comp_group_idx_cdf, 2);
   RESET_CDF_COUNTER(fc->skip_mode_cdfs, 2);
-  RESET_CDF_COUNTER(fc->skip_txfm_cdfs, 2);
+#if CONFIG_CONTEXT_DERIVATION
+  RESET_CDF_COUNTER(fc->intra_inter_cdf[0], 2);
+  RESET_CDF_COUNTER(fc->intra_inter_cdf[1], 2);
+#else
   RESET_CDF_COUNTER(fc->intra_inter_cdf, 2);
+#endif  // CONFIG_CONTEXT_DERIVATION
+  RESET_CDF_COUNTER(fc->skip_txfm_cdfs, 2);
   reset_nmv_counter(&fc->nmvc);
   reset_nmv_counter(&fc->ndvc);
   RESET_CDF_COUNTER(fc->intrabc_cdf, 2);
@@ -164,7 +188,13 @@
   RESET_CDF_COUNTER(fc->switchable_restore_cdf, RESTORE_SWITCHABLE_TYPES);
   RESET_CDF_COUNTER(fc->wiener_restore_cdf, 2);
   RESET_CDF_COUNTER(fc->sgrproj_restore_cdf, 2);
+#if CONFIG_AIMC
+  RESET_CDF_COUNTER(fc->y_mode_set_cdf, INTRA_MODE_SETS);
+  RESET_CDF_COUNTER(fc->y_mode_idx_cdf_0, FIRST_MODE_COUNT);
+  RESET_CDF_COUNTER(fc->y_mode_idx_cdf_1, SECOND_MODE_COUNT);
+#else
   RESET_CDF_COUNTER(fc->y_mode_cdf, INTRA_MODES);
+#endif  // CONFIG_AIMC
   RESET_CDF_COUNTER_STRIDE(fc->uv_mode_cdf[0], UV_INTRA_MODES - 1,
                            CDF_SIZE(UV_INTRA_MODES));
   RESET_CDF_COUNTER(fc->uv_mode_cdf[1], UV_INTRA_MODES);
@@ -195,13 +225,10 @@
   }
 #endif
   RESET_CDF_COUNTER(fc->switchable_interp_cdf, SWITCHABLE_FILTERS);
+#if !CONFIG_AIMC
   RESET_CDF_COUNTER(fc->kf_y_cdf, INTRA_MODES);
-#if CONFIG_ORIP
-  RESET_CDF_COUNTER(fc->angle_delta_cdf_hv,
-                    2 * MAX_ANGLE_DELTA + 1 + ADDITIONAL_ANGLE_DELTA);
-#endif
-
   RESET_CDF_COUNTER(fc->angle_delta_cdf, 2 * MAX_ANGLE_DELTA + 1);
+#endif  // !CONFIG_AIMC
 #if CONFIG_NEW_TX_PARTITION
   RESET_CDF_COUNTER(fc->intra_4way_txfm_partition_cdf[0], 4);
   // Rectangular blocks
diff --git a/av1/common/entropy.h b/av1/common/entropy.h
index ee78f56..f624ca3 100644
--- a/av1/common/entropy.h
+++ b/av1/common/entropy.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_COMMON_ENTROPY_H_
@@ -27,6 +28,12 @@
 
 #define TOKEN_CDF_Q_CTXS 4
 
+#if CONFIG_CONTEXT_DERIVATION
+#define CROSS_COMPONENT_CONTEXTS 3
+#define V_TXB_SKIP_CONTEXTS 12
+#define V_TXB_SKIP_CONTEXT_OFFSET 6
+#endif  // CONFIG_CONTEXT_DERIVATION
+
 #define TXB_SKIP_CONTEXTS 13
 
 #define EOB_COEF_CONTEXTS 9
diff --git a/av1/common/entropymode.c b/av1/common/entropymode.c
index 1396f9a..706e6b9 100644
--- a/av1/common/entropymode.c
+++ b/av1/common/entropymode.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "aom_mem/aom_mem.h"
@@ -17,6 +18,7 @@
 #include "av1/common/seg_common.h"
 #include "av1/common/txb_common.h"
 
+#if !CONFIG_AIMC
 static const aom_cdf_prob
     default_kf_y_mode_cdf[KF_MODE_CONTEXTS][KF_MODE_CONTEXTS][CDF_SIZE(
         INTRA_MODES)] = {
@@ -71,6 +73,7 @@
         { AOM_CDF13(7618, 8288, 9859, 10509, 15386, 18657, 22903, 28776, 29180,
                     31355, 31802, 32593) } }
     };
+#endif
 
 #if CONFIG_MRLS
 static const aom_cdf_prob default_mrl_index_cdf[CDF_SIZE(MRL_LINE_NUMBER)] = {
@@ -78,6 +81,41 @@
 };
 #endif
 
+#if CONFIG_AIMC
+static const aom_cdf_prob default_y_mode_set_cdf[CDF_SIZE(INTRA_MODE_SETS)] = {
+  AOM_CDF4(18000, 24000, 29000)
+};
+static const aom_cdf_prob
+    default_y_first_mode_cdf[Y_MODE_CONTEXTS][CDF_SIZE(FIRST_MODE_COUNT)] = {
+      { AOM_CDF13(13000, 18000, 20000, 22000, 24000, 25000, 26000, 27000, 28000,
+                  29000, 30000, 31000) },
+      { AOM_CDF13(10000, 15000, 17000, 19000, 20000, 25000, 26000, 27000, 28000,
+                  29000, 30000, 31000) },
+      { AOM_CDF13(7000, 12000, 14000, 16000, 17000, 22000, 26000, 27000, 28000,
+                  29000, 30000, 31000) }
+    };
+static const aom_cdf_prob
+    default_y_second_mode_cdf[Y_MODE_CONTEXTS][CDF_SIZE(SECOND_MODE_COUNT)] = {
+      { AOM_CDF16(2048, 4096, 6144, 8192, 10240, 12288, 14336, 16384, 18432,
+                  20480, 22528, 24576, 26624, 28672, 30720) },
+      { AOM_CDF16(2048, 4096, 6144, 8192, 10240, 12288, 14336, 16384, 18432,
+                  20480, 22528, 24576, 26624, 28672, 30720) },
+      { AOM_CDF16(2048, 4096, 6144, 8192, 10240, 12288, 14336, 16384, 18432,
+                  20480, 22528, 24576, 26624, 28672, 30720) }
+    };
+static const aom_cdf_prob
+    default_uv_mode_cdf[CFL_ALLOWED_TYPES][UV_MODE_CONTEXTS][CDF_SIZE(
+        UV_INTRA_MODES)] = {
+      { { AOM_CDF13(22631, 24152, 25378, 25661, 25986, 26520, 27055, 27923,
+                    28244, 30059, 30941, 31961) },
+        { AOM_CDF13(9513, 15881, 22973, 23546, 24118, 25664, 26739, 27824,
+                    28359, 29505, 29800, 31796) } },
+      { { AOM_CDF14(12000, 14000, 16000, 18000, 19000, 20000, 21000, 21300,
+                    21800, 22300, 22800, 23300, 23800) },
+        { AOM_CDF14(11000, 13000, 15000, 17000, 18000, 19000, 20000, 20300,
+                    20800, 21300, 21800, 22300, 22800) } }
+    };
+#else
 #if CONFIG_SDP
 static const aom_cdf_prob default_angle_delta_cdf
     [PARTITION_STRUCTURE_NUM][DIRECTIONAL_MODES]
@@ -99,22 +137,6 @@
         { AOM_CDF7(2240, 11096, 15453, 20341, 22561, 28917) },
         { AOM_CDF7(3605, 10428, 12459, 17676, 21244, 30655) } }
     };
-
-#if CONFIG_ORIP
-static const aom_cdf_prob default_angle_delta_cdf_hv
-    [PARTITION_STRUCTURE_NUM][TOTAL_NUM_ORIP_ANGLE_DELTA]
-    [CDF_SIZE(2 * MAX_ANGLE_DELTA + 1 + ADDITIONAL_ANGLE_DELTA)] = {
-      {
-          { AOM_CDF8(1180, 3032, 4567, 19776, 22989, 25217, 26639) },
-          { AOM_CDF8(1301, 3608, 5801, 20487, 22974, 25330, 26371) },
-      },
-      {
-          { AOM_CDF8(1180, 3032, 4567, 19776, 22989, 25217, 26639) },
-          { AOM_CDF8(1301, 3608, 5801, 20487, 22974, 25330, 26371) },
-      }
-    };
-
-#endif
 #else
 static const aom_cdf_prob default_angle_delta_cdf[DIRECTIONAL_MODES][CDF_SIZE(
     2 * MAX_ANGLE_DELTA + 1)] = {
@@ -127,15 +149,6 @@
   { AOM_CDF7(2240, 11096, 15453, 20341, 22561, 28917) },
   { AOM_CDF7(3605, 10428, 12459, 17676, 21244, 30655) }
 };
-#if CONFIG_ORIP
-static const aom_cdf_prob
-    default_angle_delta_cdf_hv[TOTAL_NUM_ORIP_ANGLE_DELTA][CDF_SIZE(
-        2 * MAX_ANGLE_DELTA + 1 + ADDITIONAL_ANGLE_DELTA)] = {
-      { AOM_CDF8(1180, 3032, 4567, 19776, 22989, 25217, 26639) },
-      { AOM_CDF8(1301, 3608, 5801, 20487, 22974, 25330, 26371) },
-    };
-
-#endif
 #endif
 
 static const aom_cdf_prob default_if_y_mode_cdf[BLOCK_SIZE_GROUPS][CDF_SIZE(
@@ -204,6 +217,7 @@
         { AOM_CDF14(3144, 5087, 7382, 7504, 7593, 7690, 7801, 8064, 8232, 9248,
                     9875, 10521, 29048) } }
     };
+#endif  // CONFIG_AIMC
 #if CONFIG_SDP
 static const aom_cdf_prob
     default_partition_cdf[PARTITION_STRUCTURE_NUM][PARTITION_CONTEXTS][CDF_SIZE(
@@ -580,6 +594,15 @@
       { AOM_CDF3(24626, 24936) }, { AOM_CDF3(10923, 21845) }
     };
 
+#if CONFIG_REF_MV_BANK
+static const aom_cdf_prob
+    default_drl0_cdf_refmvbank[DRL_MODE_CONTEXTS][CDF_SIZE(2)] = {
+      { AOM_CDF2(18923) }, { AOM_CDF2(12861) }, { AOM_CDF2(15472) },
+      { AOM_CDF2(13796) }, { AOM_CDF2(21474) }, { AOM_CDF2(24491) },
+      { AOM_CDF2(23482) }, { AOM_CDF2(23176) }, { AOM_CDF2(15143) },
+      { AOM_CDF2(16155) }, { AOM_CDF2(20465) }, { AOM_CDF2(20185) }
+    };
+#endif  // CONFIG_REF_MV_BANK
 static const aom_cdf_prob default_drl0_cdf[DRL_MODE_CONTEXTS][CDF_SIZE(2)] = {
   { AOM_CDF2(26658) }, { AOM_CDF2(22485) }, { AOM_CDF2(19400) },
   { AOM_CDF2(17600) }, { AOM_CDF2(23001) }, { AOM_CDF2(25649) },
@@ -587,6 +610,15 @@
   { AOM_CDF2(16468) }, { AOM_CDF2(21428) }, { AOM_CDF2(21326) }
 };
 
+#if CONFIG_REF_MV_BANK
+static const aom_cdf_prob
+    default_drl1_cdf_refmvbank[DRL_MODE_CONTEXTS][CDF_SIZE(2)] = {
+      { AOM_CDF2(6862) },  { AOM_CDF2(7013) },  { AOM_CDF2(11644) },
+      { AOM_CDF2(11423) }, { AOM_CDF2(11683) }, { AOM_CDF2(12322) },
+      { AOM_CDF2(11637) }, { AOM_CDF2(10987) }, { AOM_CDF2(16528) },
+      { AOM_CDF2(21970) }, { AOM_CDF2(15118) }, { AOM_CDF2(17207) }
+    };
+#endif  // CONFIG_REF_MV_BANK
 static const aom_cdf_prob default_drl1_cdf[DRL_MODE_CONTEXTS][CDF_SIZE(2)] = {
   { AOM_CDF2(19705) }, { AOM_CDF2(15838) }, { AOM_CDF2(18496) },
   { AOM_CDF2(18312) }, { AOM_CDF2(15248) }, { AOM_CDF2(16292) },
@@ -594,6 +626,15 @@
   { AOM_CDF2(22903) }, { AOM_CDF2(16244) }, { AOM_CDF2(19319) }
 };
 
+#if CONFIG_REF_MV_BANK
+static const aom_cdf_prob
+    default_drl2_cdf_refmvbank[DRL_MODE_CONTEXTS][CDF_SIZE(2)] = {
+      { AOM_CDF2(14694) }, { AOM_CDF2(13186) }, { AOM_CDF2(14211) },
+      { AOM_CDF2(12899) }, { AOM_CDF2(12637) }, { AOM_CDF2(12295) },
+      { AOM_CDF2(14358) }, { AOM_CDF2(13386) }, { AOM_CDF2(12462) },
+      { AOM_CDF2(13917) }, { AOM_CDF2(14188) }, { AOM_CDF2(13904) }
+    };
+#endif  // CONFIG_REF_MV_BANK
 static const aom_cdf_prob default_drl2_cdf[DRL_MODE_CONTEXTS][CDF_SIZE(2)] = {
   { AOM_CDF2(12992) }, { AOM_CDF2(7518) },  { AOM_CDF2(18309) },
   { AOM_CDF2(17119) }, { AOM_CDF2(15195) }, { AOM_CDF2(15214) },
@@ -601,6 +642,27 @@
   { AOM_CDF2(16618) }, { AOM_CDF2(14980) }, { AOM_CDF2(15963) }
 };
 
+#if CONFIG_OPTFLOW_REFINEMENT
+static const aom_cdf_prob
+    default_use_optflow_cdf[INTER_COMPOUND_MODE_CONTEXTS][CDF_SIZE(2)] = {
+      { AOM_CDF2(16384) }, { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
+      { AOM_CDF2(16384) }, { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
+      { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
+    };
+
+static const aom_cdf_prob
+    default_inter_compound_mode_cdf[INTER_COMPOUND_MODE_CONTEXTS]
+                                   [CDF_SIZE(INTER_COMPOUND_REF_TYPES)] = {
+                                     { AOM_CDF5(10510, 17103, 22330, 24536) },
+                                     { AOM_CDF5(14805, 20117, 24655, 25891) },
+                                     { AOM_CDF5(15700, 20333, 24425, 25305) },
+                                     { AOM_CDF5(15047, 20124, 24840, 25223) },
+                                     { AOM_CDF5(22632, 25637, 28394, 29608) },
+                                     { AOM_CDF5(15703, 20315, 24653, 25122) },
+                                     { AOM_CDF5(22458, 25512, 28304, 29008) },
+                                     { AOM_CDF5(21368, 24274, 26890, 27364) }
+                                   };
+#else
 static const aom_cdf_prob
     default_inter_compound_mode_cdf[INTER_COMPOUND_MODE_CONTEXTS][CDF_SIZE(
         INTER_COMPOUND_MODES)] = { { AOM_CDF5(10510, 17103, 22330, 24536) },
@@ -611,6 +673,7 @@
                                    { AOM_CDF5(15703, 20315, 24653, 25122) },
                                    { AOM_CDF5(22458, 25512, 28304, 29008) },
                                    { AOM_CDF5(21368, 24274, 26890, 27364) } };
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 #else
 static const aom_cdf_prob default_newmv_cdf[NEWMV_MODE_CONTEXTS][CDF_SIZE(
     2)] = { { AOM_CDF2(24035) }, { AOM_CDF2(16630) }, { AOM_CDF2(15339) },
@@ -747,6 +810,20 @@
   { AOM_CDF2(26879) }
 };
 
+#if CONFIG_CONTEXT_DERIVATION
+static const aom_cdf_prob
+    default_intra_inter_cdf[INTRA_INTER_SKIP_TXFM_CONTEXTS]
+                           [INTRA_INTER_CONTEXTS][CDF_SIZE(2)] = {
+                             { { AOM_CDF2(806) },
+                               { AOM_CDF2(16662) },
+                               { AOM_CDF2(20186) },
+                               { AOM_CDF2(26538) } },
+                             { { AOM_CDF2(806) },
+                               { AOM_CDF2(16662) },
+                               { AOM_CDF2(20186) },
+                               { AOM_CDF2(26538) } },
+                           };
+#else
 static const aom_cdf_prob default_intra_inter_cdf[INTRA_INTER_CONTEXTS]
                                                  [CDF_SIZE(2)] = {
                                                    { AOM_CDF2(806) },
@@ -754,6 +831,7 @@
                                                    { AOM_CDF2(20186) },
                                                    { AOM_CDF2(26538) }
                                                  };
+#endif  // CONFIG_CONTEXT_DERIVATION
 
 static const aom_cdf_prob default_comp_inter_cdf[COMP_INTER_CONTEXTS][CDF_SIZE(
     2)] = { { AOM_CDF2(26828) },
@@ -762,6 +840,78 @@
             { AOM_CDF2(10640) },
             { AOM_CDF2(2901) } };
 
+#if CONFIG_NEW_REF_SIGNALING
+static const aom_cdf_prob
+    default_single_ref_cdf[REF_CONTEXTS][INTER_REFS_PER_FRAME - 1]
+                          [CDF_SIZE(2)] = { { { AOM_CDF2(26431) },
+                                              { AOM_CDF2(27737) },
+                                              { AOM_CDF2(30341) },
+                                              { AOM_CDF2(30525) },
+                                              { AOM_CDF2(30361) },
+                                              { AOM_CDF2(28368) } },
+                                            { { AOM_CDF2(15825) },
+                                              { AOM_CDF2(15748) },
+                                              { AOM_CDF2(22176) },
+                                              { AOM_CDF2(22342) },
+                                              { AOM_CDF2(19463) },
+                                              { AOM_CDF2(9639) } },
+                                            { { AOM_CDF2(5075) },
+                                              { AOM_CDF2(3515) },
+                                              { AOM_CDF2(7199) },
+                                              { AOM_CDF2(6223) },
+                                              { AOM_CDF2(4186) },
+                                              { AOM_CDF2(927) } } };
+
+static const aom_cdf_prob default_comp_ref_cdf[REF_CONTEXTS][COMPREF_BIT_TYPES]
+                                              [INTER_REFS_PER_FRAME - 2]
+                                              [CDF_SIZE(2)] = {
+                                                { { { AOM_CDF2(9565) },
+                                                    { AOM_CDF2(20372) },
+                                                    { AOM_CDF2(26108) },
+                                                    { AOM_CDF2(25698) },
+                                                    { AOM_CDF2(23235) } },
+                                                  { { AOM_CDF2(901) },
+                                                    { AOM_CDF2(4025) },
+                                                    { AOM_CDF2(11946) },
+                                                    { AOM_CDF2(12060) },
+                                                    { AOM_CDF2(9161) } },
+                                                  { { AOM_CDF2(1294) },
+                                                    { AOM_CDF2(2591) },
+                                                    { AOM_CDF2(8201) },
+                                                    { AOM_CDF2(7951) },
+                                                    { AOM_CDF2(4942) } } },
+                                                { { { AOM_CDF2(29266) },
+                                                    { AOM_CDF2(29841) },
+                                                    { AOM_CDF2(31056) },
+                                                    { AOM_CDF2(31670) },
+                                                    { AOM_CDF2(29626) } },
+                                                  { { AOM_CDF2(18827) },
+                                                    { AOM_CDF2(29089) },
+                                                    { AOM_CDF2(29533) },
+                                                    { AOM_CDF2(29695) },
+                                                    { AOM_CDF2(28668) } },
+                                                  { { AOM_CDF2(20397) },
+                                                    { AOM_CDF2(19716) },
+                                                    { AOM_CDF2(22602) },
+                                                    { AOM_CDF2(23821) },
+                                                    { AOM_CDF2(16842) } } },
+                                                { { { AOM_CDF2(6865) },
+                                                    { AOM_CDF2(16538) },
+                                                    { AOM_CDF2(17412) },
+                                                    { AOM_CDF2(15905) },
+                                                    { AOM_CDF2(11282) } },
+                                                  { { AOM_CDF2(10566) },
+                                                    { AOM_CDF2(8314) },
+                                                    { AOM_CDF2(7659) },
+                                                    { AOM_CDF2(7571) },
+                                                    { AOM_CDF2(5115) } },
+                                                  { { AOM_CDF2(800) },
+                                                    { AOM_CDF2(4065) },
+                                                    { AOM_CDF2(3440) },
+                                                    { AOM_CDF2(2442) },
+                                                    { AOM_CDF2(1696) } } }
+                                              };
+#else
 static const aom_cdf_prob default_comp_ref_type_cdf[COMP_REF_TYPE_CONTEXTS]
                                                    [CDF_SIZE(2)] = {
                                                      { AOM_CDF2(1198) },
@@ -814,6 +964,7 @@
       { { AOM_CDF2(17182) }, { AOM_CDF2(15175) } },
       { { AOM_CDF2(30606) }, { AOM_CDF2(30489) } }
     };
+#endif  // CONFIG_NEW_REF_SIGNALING
 
 static const aom_cdf_prob
     default_palette_y_size_cdf[PALATTE_BSIZE_CTXS][CDF_SIZE(PALETTE_SIZES)] = {
@@ -1016,19 +1167,6 @@
 static const aom_cdf_prob default_skip_mode_cdfs[SKIP_MODE_CONTEXTS][CDF_SIZE(
     2)] = { { AOM_CDF2(32621) }, { AOM_CDF2(20708) }, { AOM_CDF2(8127) } };
 
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-static const aom_cdf_prob
-    default_compound_idx_cdfs[COMP_INDEX_CONTEXTS][CDF_SIZE(2)] = {
-      { AOM_CDF2(18244) }, { AOM_CDF2(12865) }, { AOM_CDF2(7053) },
-      { AOM_CDF2(13259) }, { AOM_CDF2(9334) },  { AOM_CDF2(4644) }
-    };
-
-static const aom_cdf_prob
-    default_comp_group_idx_cdfs[COMP_GROUP_IDX_CONTEXTS][CDF_SIZE(2)] = {
-      { AOM_CDF2(26607) }, { AOM_CDF2(22891) }, { AOM_CDF2(18840) },
-      { AOM_CDF2(24594) }, { AOM_CDF2(19934) }, { AOM_CDF2(22674) }
-    };
-#else
 static const aom_cdf_prob
     default_comp_group_idx_cdfs[COMP_GROUP_IDX_CONTEXTS][CDF_SIZE(2)] = {
       { AOM_CDF2(16384) }, { AOM_CDF2(19384) }, { AOM_CDF2(19384) },
@@ -1036,7 +1174,6 @@
       { AOM_CDF2(15384) }, { AOM_CDF2(17384) }, { AOM_CDF2(17384) },
       { AOM_CDF2(20384) }, { AOM_CDF2(17384) }, { AOM_CDF2(17384) },
     };
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
 
 static const aom_cdf_prob default_intrabc_cdf[CDF_SIZE(2)] = { AOM_CDF2(
     30531) };
@@ -1334,24 +1471,27 @@
 #undef NUM_PALETTE_NEIGHBORS
 #undef MAX_COLOR_CONTEXT_HASH
 
-static void init_mode_probs(FRAME_CONTEXT *fc) {
+static void init_mode_probs(FRAME_CONTEXT *fc,
+                            const SequenceHeader *const seq_params) {
+  (void)seq_params;
   av1_copy(fc->palette_y_size_cdf, default_palette_y_size_cdf);
   av1_copy(fc->palette_uv_size_cdf, default_palette_uv_size_cdf);
   av1_copy(fc->palette_y_color_index_cdf, default_palette_y_color_index_cdf);
   av1_copy(fc->palette_uv_color_index_cdf, default_palette_uv_color_index_cdf);
+#if !CONFIG_AIMC
   av1_copy(fc->kf_y_cdf, default_kf_y_mode_cdf);
-#if CONFIG_ORIP
-  av1_copy(fc->angle_delta_cdf_hv, default_angle_delta_cdf_hv);
-#endif
   av1_copy(fc->angle_delta_cdf, default_angle_delta_cdf);
+#endif  // !CONFIG_AIMC
   av1_copy(fc->comp_inter_cdf, default_comp_inter_cdf);
-  av1_copy(fc->comp_ref_type_cdf, default_comp_ref_type_cdf);
-  av1_copy(fc->uni_comp_ref_cdf, default_uni_comp_ref_cdf);
   av1_copy(fc->palette_y_mode_cdf, default_palette_y_mode_cdf);
   av1_copy(fc->palette_uv_mode_cdf, default_palette_uv_mode_cdf);
-  av1_copy(fc->comp_ref_cdf, default_comp_ref_cdf);
-  av1_copy(fc->comp_bwdref_cdf, default_comp_bwdref_cdf);
   av1_copy(fc->single_ref_cdf, default_single_ref_cdf);
+  av1_copy(fc->comp_ref_cdf, default_comp_ref_cdf);
+#if !CONFIG_NEW_REF_SIGNALING
+  av1_copy(fc->comp_ref_type_cdf, default_comp_ref_type_cdf);
+  av1_copy(fc->uni_comp_ref_cdf, default_uni_comp_ref_cdf);
+  av1_copy(fc->comp_bwdref_cdf, default_comp_bwdref_cdf);
+#endif  // CONFIG_NEW_REF_SIGNALING
 #if CONFIG_NEW_TX_PARTITION
   av1_copy(fc->inter_4way_txfm_partition_cdf,
            default_inter_4way_txfm_partition_cdf);
@@ -1362,15 +1502,24 @@
 #else
   av1_copy(fc->txfm_partition_cdf, default_txfm_partition_cdf);
 #endif  // CONFIG_NEW_TX_PARTITION
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-  av1_copy(fc->compound_index_cdf, default_compound_idx_cdfs);
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
   av1_copy(fc->comp_group_idx_cdf, default_comp_group_idx_cdfs);
 #if CONFIG_NEW_INTER_MODES
   av1_copy(fc->inter_single_mode_cdf, default_inter_single_mode_cdf);
+#if CONFIG_REF_MV_BANK
+  if (seq_params->enable_refmvbank) {
+    av1_copy(fc->drl_cdf[0], default_drl0_cdf_refmvbank);
+    av1_copy(fc->drl_cdf[1], default_drl1_cdf_refmvbank);
+    av1_copy(fc->drl_cdf[2], default_drl2_cdf_refmvbank);
+  } else {
+    av1_copy(fc->drl_cdf[0], default_drl0_cdf);
+    av1_copy(fc->drl_cdf[1], default_drl1_cdf);
+    av1_copy(fc->drl_cdf[2], default_drl2_cdf);
+  }
+#else
   av1_copy(fc->drl_cdf[0], default_drl0_cdf);
   av1_copy(fc->drl_cdf[1], default_drl1_cdf);
   av1_copy(fc->drl_cdf[2], default_drl2_cdf);
+#endif  // CONFIG_REF_MV_BANK
 #else
   av1_copy(fc->newmv_cdf, default_newmv_cdf);
   av1_copy(fc->zeromv_cdf, default_zeromv_cdf);
@@ -1379,6 +1528,9 @@
 #endif  // CONFIG_NEW_INTER_MODES
   av1_copy(fc->motion_mode_cdf, default_motion_mode_cdf);
   av1_copy(fc->obmc_cdf, default_obmc_cdf);
+#if CONFIG_OPTFLOW_REFINEMENT
+  av1_copy(fc->use_optflow_cdf, default_use_optflow_cdf);
+#endif  // CONFIG_OPTFLOW_REFINEMENT
   av1_copy(fc->inter_compound_mode_cdf, default_inter_compound_mode_cdf);
   av1_copy(fc->compound_type_cdf, default_compound_type_cdf);
   av1_copy(fc->wedge_idx_cdf, default_wedge_idx_cdf);
@@ -1392,7 +1544,13 @@
   av1_copy(fc->switchable_restore_cdf, default_switchable_restore_cdf);
   av1_copy(fc->wiener_restore_cdf, default_wiener_restore_cdf);
   av1_copy(fc->sgrproj_restore_cdf, default_sgrproj_restore_cdf);
+#if CONFIG_AIMC
+  av1_copy(fc->y_mode_set_cdf, default_y_mode_set_cdf);
+  av1_copy(fc->y_mode_idx_cdf_0, default_y_first_mode_cdf);
+  av1_copy(fc->y_mode_idx_cdf_1, default_y_second_mode_cdf);
+#else
   av1_copy(fc->y_mode_cdf, default_if_y_mode_cdf);
+#endif  // CONFIG_AIMC
   av1_copy(fc->uv_mode_cdf, default_uv_mode_cdf);
 #if CONFIG_MRLS
   av1_copy(fc->mrl_index_cdf, default_mrl_index_cdf);
@@ -1403,7 +1561,12 @@
   av1_copy(fc->inter_ext_tx_cdf, default_inter_ext_tx_cdf);
   av1_copy(fc->skip_mode_cdfs, default_skip_mode_cdfs);
   av1_copy(fc->skip_txfm_cdfs, default_skip_txfm_cdfs);
+#if CONFIG_CONTEXT_DERIVATION
+  av1_copy(fc->intra_inter_cdf[0], default_intra_inter_cdf[0]);
+  av1_copy(fc->intra_inter_cdf[1], default_intra_inter_cdf[1]);
+#else
   av1_copy(fc->intra_inter_cdf, default_intra_inter_cdf);
+#endif  // CONFIG_CONTEXT_DERIVATION
   for (int i = 0; i < SPATIAL_PREDICTION_PROBS; i++)
     av1_copy(fc->seg.spatial_pred_seg_cdf[i],
              default_spatial_pred_seg_tree_cdf[i]);
@@ -1431,6 +1594,16 @@
 void av1_set_default_ref_deltas(int8_t *ref_deltas) {
   assert(ref_deltas != NULL);
 
+#if CONFIG_NEW_REF_SIGNALING
+  ref_deltas[0] = -1;
+  ref_deltas[1] = -1;
+  ref_deltas[2] = -1;
+  ref_deltas[3] = 0;
+  ref_deltas[4] = 0;
+  ref_deltas[5] = 0;
+  ref_deltas[6] = 0;
+  ref_deltas[INTRA_FRAME_INDEX_NRS] = 1;
+#else
   ref_deltas[INTRA_FRAME] = 1;
   ref_deltas[LAST_FRAME] = 0;
   ref_deltas[LAST2_FRAME] = ref_deltas[LAST_FRAME];
@@ -1439,6 +1612,7 @@
   ref_deltas[GOLDEN_FRAME] = -1;
   ref_deltas[ALTREF2_FRAME] = -1;
   ref_deltas[ALTREF_FRAME] = -1;
+#endif  // CONFIG_NEW_REF_SIGNALING
 }
 
 void av1_set_default_mode_deltas(int8_t *mode_deltas) {
@@ -1466,7 +1640,11 @@
   // TODO(jack.haughton@argondesign.com): don't think this should be necessary,
   // but could do with fuller testing
   if (cm->tiles.large_scale) {
+#if CONFIG_NEW_REF_SIGNALING
+    for (int i = 0; i < INTER_REFS_PER_FRAME; ++i) {
+#else
     for (int i = LAST_FRAME; i <= ALTREF_FRAME; ++i) {
+#endif  // CONFIG_NEW_REF_SIGNALING
       RefCntBuffer *const buf = get_ref_frame_buf(cm, i);
       if (buf != NULL) buf->frame_context = *cm->fc;
     }
@@ -1491,7 +1669,7 @@
   set_default_lf_deltas(&cm->lf);
 
   av1_default_coef_probs(cm);
-  init_mode_probs(cm->fc);
+  init_mode_probs(cm->fc, &cm->seq_params);
   av1_init_mv_probs(cm);
   cm->fc->initialized = 1;
   av1_setup_frame_contexts(cm);
diff --git a/av1/common/entropymode.h b/av1/common/entropymode.h
index 235542b..f971f64 100644
--- a/av1/common/entropymode.h
+++ b/av1/common/entropymode.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_COMMON_ENTROPYMODE_H_
@@ -62,6 +63,10 @@
 
 #define KF_MODE_CONTEXTS 5
 
+#if CONFIG_NEW_REF_SIGNALING
+#define COMPREF_BIT_TYPES 3
+#endif  // CONFIG_NEW_REF_SIGNALING
+
 struct AV1Common;
 
 typedef struct {
@@ -71,9 +76,17 @@
 
 typedef struct frame_contexts {
   aom_cdf_prob txb_skip_cdf[TX_SIZES][TXB_SKIP_CONTEXTS][CDF_SIZE(2)];
+#if CONFIG_CONTEXT_DERIVATION
+  aom_cdf_prob v_txb_skip_cdf[V_TXB_SKIP_CONTEXTS][CDF_SIZE(2)];
+#endif  // CONFIG_CONTEXT_DERIVATION
   aom_cdf_prob eob_extra_cdf[TX_SIZES][PLANE_TYPES][EOB_COEF_CONTEXTS]
                             [CDF_SIZE(2)];
   aom_cdf_prob dc_sign_cdf[PLANE_TYPES][DC_SIGN_CONTEXTS][CDF_SIZE(2)];
+#if CONFIG_CONTEXT_DERIVATION
+  aom_cdf_prob v_dc_sign_cdf[CROSS_COMPONENT_CONTEXTS][DC_SIGN_CONTEXTS]
+                            [CDF_SIZE(2)];
+  aom_cdf_prob v_ac_sign_cdf[CROSS_COMPONENT_CONTEXTS][CDF_SIZE(2)];
+#endif  // CONFIG_CONTEXT_DERIVATION
   aom_cdf_prob eob_flag_cdf16[PLANE_TYPES][2][CDF_SIZE(5)];
   aom_cdf_prob eob_flag_cdf32[PLANE_TYPES][2][CDF_SIZE(6)];
   aom_cdf_prob eob_flag_cdf64[PLANE_TYPES][2][CDF_SIZE(7)];
@@ -99,8 +112,14 @@
   aom_cdf_prob refmv_cdf[REFMV_MODE_CONTEXTS][CDF_SIZE(2)];
 #endif  // CONFIG_NEW_INTER_MODES
 
+#if CONFIG_OPTFLOW_REFINEMENT
+  aom_cdf_prob use_optflow_cdf[INTER_COMPOUND_MODE_CONTEXTS][CDF_SIZE(2)];
+  aom_cdf_prob inter_compound_mode_cdf[INTER_COMPOUND_MODE_CONTEXTS]
+                                      [CDF_SIZE(INTER_COMPOUND_REF_TYPES)];
+#else
   aom_cdf_prob inter_compound_mode_cdf[INTER_COMPOUND_MODE_CONTEXTS]
                                       [CDF_SIZE(INTER_COMPOUND_MODES)];
+#endif  // CONFIG_OPTFLOW_REFINEMENT
   aom_cdf_prob compound_type_cdf[BLOCK_SIZES_ALL]
                                 [CDF_SIZE(MASKED_COMPOUND_TYPES)];
   aom_cdf_prob wedge_idx_cdf[BLOCK_SIZES_ALL][CDF_SIZE(16)];
@@ -122,12 +141,19 @@
                                  [CDF_SIZE(2)];
   aom_cdf_prob palette_uv_mode_cdf[PALETTE_UV_MODE_CONTEXTS][CDF_SIZE(2)];
   aom_cdf_prob comp_inter_cdf[COMP_INTER_CONTEXTS][CDF_SIZE(2)];
+#if CONFIG_NEW_REF_SIGNALING
+  aom_cdf_prob single_ref_cdf[REF_CONTEXTS][INTER_REFS_PER_FRAME - 1]
+                             [CDF_SIZE(2)];
+  aom_cdf_prob comp_ref_cdf[REF_CONTEXTS][COMPREF_BIT_TYPES]
+                           [INTER_REFS_PER_FRAME - 2][CDF_SIZE(2)];
+#else
   aom_cdf_prob single_ref_cdf[REF_CONTEXTS][SINGLE_REFS - 1][CDF_SIZE(2)];
   aom_cdf_prob comp_ref_type_cdf[COMP_REF_TYPE_CONTEXTS][CDF_SIZE(2)];
   aom_cdf_prob uni_comp_ref_cdf[UNI_COMP_REF_CONTEXTS][UNIDIR_COMP_REFS - 1]
                                [CDF_SIZE(2)];
   aom_cdf_prob comp_ref_cdf[REF_CONTEXTS][FWD_REFS - 1][CDF_SIZE(2)];
   aom_cdf_prob comp_bwdref_cdf[REF_CONTEXTS][BWD_REFS - 1][CDF_SIZE(2)];
+#endif  // CONFIG_NEW_REF_SIGNALING
 #if CONFIG_NEW_TX_PARTITION
   aom_cdf_prob inter_4way_txfm_partition_cdf[2][TXFM_PARTITION_INTER_CONTEXTS]
                                             [CDF_SIZE(4)];
@@ -136,11 +162,15 @@
 #else   // CONFIG_NEW_TX_PARTITION
   aom_cdf_prob txfm_partition_cdf[TXFM_PARTITION_CONTEXTS][CDF_SIZE(2)];
 #endif  // CONFIG_NEW_TX_PARTITION
-  aom_cdf_prob compound_index_cdf[COMP_INDEX_CONTEXTS][CDF_SIZE(2)];
   aom_cdf_prob comp_group_idx_cdf[COMP_GROUP_IDX_CONTEXTS][CDF_SIZE(2)];
   aom_cdf_prob skip_mode_cdfs[SKIP_MODE_CONTEXTS][CDF_SIZE(2)];
   aom_cdf_prob skip_txfm_cdfs[SKIP_CONTEXTS][CDF_SIZE(2)];
+#if CONFIG_CONTEXT_DERIVATION
+  aom_cdf_prob intra_inter_cdf[INTRA_INTER_SKIP_TXFM_CONTEXTS]
+                              [INTRA_INTER_CONTEXTS][CDF_SIZE(2)];
+#else
   aom_cdf_prob intra_inter_cdf[INTRA_INTER_CONTEXTS][CDF_SIZE(2)];
+#endif  // CONFIG_CONTEXT_DERIVATION
   nmv_context nmvc;
   nmv_context ndvc;
   aom_cdf_prob intrabc_cdf[CDF_SIZE(2)];
@@ -150,12 +180,23 @@
   aom_cdf_prob switchable_restore_cdf[CDF_SIZE(RESTORE_SWITCHABLE_TYPES)];
   aom_cdf_prob wiener_restore_cdf[CDF_SIZE(2)];
   aom_cdf_prob sgrproj_restore_cdf[CDF_SIZE(2)];
+#if !CONFIG_AIMC
   aom_cdf_prob y_mode_cdf[BLOCK_SIZE_GROUPS][CDF_SIZE(INTRA_MODES)];
   aom_cdf_prob uv_mode_cdf[CFL_ALLOWED_TYPES][INTRA_MODES]
                           [CDF_SIZE(UV_INTRA_MODES)];
+#endif  // !CONFIG_AIMC
 #if CONFIG_MRLS
   aom_cdf_prob mrl_index_cdf[CDF_SIZE(MRL_LINE_NUMBER)];
 #endif
+#if CONFIG_AIMC
+  // y mode cdf
+  aom_cdf_prob y_mode_set_cdf[CDF_SIZE(INTRA_MODE_SETS)];
+  aom_cdf_prob y_mode_idx_cdf_0[Y_MODE_CONTEXTS][CDF_SIZE(FIRST_MODE_COUNT)];
+  aom_cdf_prob y_mode_idx_cdf_1[Y_MODE_CONTEXTS][CDF_SIZE(SECOND_MODE_COUNT)];
+  // uv mode cdf
+  aom_cdf_prob uv_mode_cdf[CFL_ALLOWED_TYPES][UV_MODE_CONTEXTS]
+                          [CDF_SIZE(UV_INTRA_MODES)];
+#endif  // CONFIG_AIMC
 #if CONFIG_SDP
   aom_cdf_prob partition_cdf[PARTITION_STRUCTURE_NUM][PARTITION_CONTEXTS]
                             [CDF_SIZE(EXT_PARTITION_TYPES)];
@@ -164,6 +205,7 @@
 #endif
   aom_cdf_prob switchable_interp_cdf[SWITCHABLE_FILTER_CONTEXTS]
                                     [CDF_SIZE(SWITCHABLE_FILTERS)];
+#if !CONFIG_AIMC
   /* kf_y_cdf is discarded after use, so does not require persistent storage.
      However, we keep it with the other CDFs in this struct since it needs to
      be copied to each tile to support parallelism just like the others.
@@ -174,20 +216,11 @@
 #if CONFIG_SDP
   aom_cdf_prob angle_delta_cdf[PARTITION_STRUCTURE_NUM][DIRECTIONAL_MODES]
                               [CDF_SIZE(2 * MAX_ANGLE_DELTA + 1)];
-#if CONFIG_ORIP
-  aom_cdf_prob angle_delta_cdf_hv[PARTITION_STRUCTURE_NUM]
-                                 [TOTAL_NUM_ORIP_ANGLE_DELTA]
-                                 [CDF_SIZE(2 * MAX_ANGLE_DELTA + 1 +
-                                           ADDITIONAL_ANGLE_DELTA)];
-#endif
 #else
   aom_cdf_prob angle_delta_cdf[DIRECTIONAL_MODES]
                               [CDF_SIZE(2 * MAX_ANGLE_DELTA + 1)];
-#if CONFIG_ORIP
-  aom_cdf_prob angle_delta_cdf_hv[TOTAL_NUM_ORIP_ANGLE_DELTA][CDF_SIZE(
-      2 * MAX_ANGLE_DELTA + 1 + ADDITIONAL_ANGLE_DELTA)];
 #endif
-#endif
+#endif  // !CONFIG_AIMC
 
 #if CONFIG_NEW_TX_PARTITION
   aom_cdf_prob intra_4way_txfm_partition_cdf[2][TX_SIZE_CONTEXTS][CDF_SIZE(4)];
@@ -280,6 +313,28 @@
 }
 #endif  // CONFIG_NEW_INTER_MODES
 
+#if CONFIG_OPTFLOW_REFINEMENT
+static const int comp_idx_to_opfl_mode[5] = { NEAR_NEARMV_OPTFLOW,
+                                              NEAR_NEWMV_OPTFLOW,
+                                              NEW_NEARMV_OPTFLOW, -1,
+                                              NEW_NEWMV_OPTFLOW };
+
+static INLINE int opfl_get_comp_idx(int mode) {
+  switch (mode) {
+    case NEAR_NEARMV:
+    case NEAR_NEARMV_OPTFLOW: return INTER_COMPOUND_OFFSET(NEAR_NEARMV);
+    case NEAR_NEWMV:
+    case NEAR_NEWMV_OPTFLOW: return INTER_COMPOUND_OFFSET(NEAR_NEWMV);
+    case NEW_NEARMV:
+    case NEW_NEARMV_OPTFLOW: return INTER_COMPOUND_OFFSET(NEW_NEARMV);
+    case NEW_NEWMV:
+    case NEW_NEWMV_OPTFLOW: return INTER_COMPOUND_OFFSET(NEW_NEWMV);
+    case GLOBAL_GLOBALMV: return INTER_COMPOUND_OFFSET(GLOBAL_GLOBALMV);
+    default: assert(0); return 0;
+  }
+}
+#endif  // CONFIG_OPTFLOW_REFINEMENT
+
 // Returns the context for palette color index at row 'r' and column 'c',
 // along with the 'color_order' of neighbors and the 'color_idx'.
 // The 'color_map' is a 2D array with the given 'stride'.
diff --git a/av1/common/entropymv.c b/av1/common/entropymv.c
index e1e42f2..a998bd6 100644
--- a/av1/common/entropymv.c
+++ b/av1/common/entropymv.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "av1/common/av1_common_int.h"
diff --git a/av1/common/entropymv.h b/av1/common/entropymv.h
index cddc807..0c5a045 100644
--- a/av1/common/entropymv.h
+++ b/av1/common/entropymv.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_COMMON_ENTROPYMV_H_
diff --git a/av1/common/enums.h b/av1/common/enums.h
index 697fdee..0963743 100644
--- a/av1/common/enums.h
+++ b/av1/common/enums.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_COMMON_ENUMS_H_
@@ -90,6 +91,14 @@
 #if CONFIG_MRLS
 #define MRL_LINE_NUMBER 4
 #endif
+#if CONFIG_AIMC
+#define FIRST_MODE_COUNT 13
+#define SECOND_MODE_COUNT 16
+#define Y_MODE_CONTEXTS 3
+#define UV_MODE_CONTEXTS 2
+#define INTRA_MODE_SETS 4
+#define NON_DIRECTIONAL_MODES_COUNT 5
+#endif  // CONFIG_AIMC
 
 // Intra Secondary Transform
 #if CONFIG_IST
@@ -389,6 +398,7 @@
 #define EXT_TX_SETS_INTER 4  // Sets of transform selections for INTER
 #define EXT_TX_SETS_INTRA 3  // Sets of transform selections for INTRA
 
+#if !CONFIG_NEW_REF_SIGNALING
 enum {
   AOM_LAST_FLAG = 1 << 0,
   AOM_LAST2_FLAG = 1 << 1,
@@ -399,6 +409,7 @@
   AOM_ALT_FLAG = 1 << 6,
   AOM_REFFRAME_ALL = (1 << 7) - 1
 } UENUM1BYTE(AOM_REFFRAME);
+#endif  // !CONFIG_NEW_REF_SIGNALING
 
 enum {
   UNIDIR_COMP_REFERENCE,
@@ -507,6 +518,12 @@
   NEW_NEARMV,
   GLOBAL_GLOBALMV,
   NEW_NEWMV,
+#if CONFIG_OPTFLOW_REFINEMENT
+  NEAR_NEARMV_OPTFLOW,
+  NEAR_NEWMV_OPTFLOW,
+  NEW_NEARMV_OPTFLOW,
+  NEW_NEWMV_OPTFLOW,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
   MB_MODE_COUNT,
   INTRA_MODE_START = DC_PRED,
 #if CONFIG_NEW_INTER_MODES
@@ -532,14 +549,19 @@
 #endif  // CONFIG_NEW_INTER_MODES
   COMP_INTER_MODE_END = MB_MODE_COUNT,
   COMP_INTER_MODE_NUM = COMP_INTER_MODE_END - COMP_INTER_MODE_START,
+#if CONFIG_OPTFLOW_REFINEMENT
+  COMP_OPTFLOW_MODE_START = NEAR_NEARMV_OPTFLOW,
+  INTER_COMPOUND_REF_TYPES = COMP_OPTFLOW_MODE_START - COMP_INTER_MODE_START,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 #if CONFIG_NEW_INTER_MODES
   INTER_MODE_START = NEARMV,
 #else
   INTER_MODE_START = NEARESTMV,
 #endif  // CONFIG_NEW_INTER_MODES
   INTER_MODE_END = MB_MODE_COUNT,
-  INTRA_MODES = PAETH_PRED + 1,  // PAETH_PRED has to be the last intra mode.
-  INTRA_INVALID = MB_MODE_COUNT  // For uv_mode in inter blocks
+  INTRA_MODES = PAETH_PRED + 1,   // PAETH_PRED has to be the last intra mode.
+  INTRA_INVALID = MB_MODE_COUNT,  // For uv_mode in inter blocks
+  MODE_INVALID = 255
 } UENUM1BYTE(PREDICTION_MODE);
 
 // TODO(ltrudeau) Do we really want to pack this?
@@ -586,9 +608,6 @@
 
 enum {
   COMPOUND_AVERAGE,
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-  COMPOUND_DISTWTD,
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
   COMPOUND_WEDGE,
   COMPOUND_DIFFWTD,
   COMPOUND_TYPES,
@@ -639,25 +658,18 @@
 #define MAX_ANGLE_DELTA 3
 #define ANGLE_STEP 3
 
-#if CONFIG_ORIP
-#define ADDITIONAL_ANGLE_DELTA 1
-#define TOTAL_NUM_ORIP_ANGLE_DELTA 2
-#define ANGLE_DELTA_VALUE_ORIP (MAX_ANGLE_DELTA + 1)
+#if CONFIG_AIMC
+// Total delta angles for one nominal directional mode
+#define TOTAL_ANGLE_DELTA_COUNT 7
 #endif
 
-#if CONFIG_NEW_INTER_MODES
-#define INTER_SINGLE_MODES (1 + NEWMV - NEARMV)
-#define INTER_COMPOUND_MODES (1 + NEW_NEWMV - NEAR_NEARMV)
-#else
-#define INTER_SINGLE_MODES (1 + NEWMV - NEARESTMV)
-#define INTER_COMPOUND_MODES (1 + NEW_NEWMV - NEAREST_NEARESTMV)
-#endif  // CONFIG_NEW_INTER_MODES
+#define INTER_SINGLE_MODES SINGLE_INTER_MODE_NUM
+#define INTER_COMPOUND_MODES COMP_INTER_MODE_NUM
 
 #define SKIP_CONTEXTS 3
 #define SKIP_MODE_CONTEXTS 3
 
-#define COMP_INDEX_CONTEXTS 6
-#define COMP_GROUP_IDX_CONTEXTS (6 * (1 + CONFIG_REMOVE_DIST_WTD_COMP))
+#define COMP_GROUP_IDX_CONTEXTS 12
 
 #define NMV_CONTEXTS 3
 #define NEWMV_MODE_CONTEXTS 6
@@ -708,6 +720,9 @@
 
 #define REF_CAT_LEVEL 640
 
+#if CONFIG_CONTEXT_DERIVATION
+#define INTRA_INTER_SKIP_TXFM_CONTEXTS 2
+#endif  // CONFIG_CONTEXT_DERIVATION
 #define INTRA_INTER_CONTEXTS 4
 #define COMP_INTER_CONTEXTS 5
 #define REF_CONTEXTS 3
@@ -722,6 +737,17 @@
 #endif  // CONFIG_NEW_TX_PARTITION
 typedef uint8_t TXFM_CONTEXT;
 
+#if CONFIG_NEW_REF_SIGNALING
+#define INTER_REFS_PER_FRAME 7
+#define REF_FRAMES (INTER_REFS_PER_FRAME + 1)
+#define MODE_CTX_REF_FRAMES \
+  (INTER_REFS_PER_FRAME * (INTER_REFS_PER_FRAME + 1) / 2 + 1)
+#define INTRA_FRAME_NRS (INTER_REFS_PER_FRAME * (INTER_REFS_PER_FRAME + 1) / 2)
+// Used for indexing into arrays that contain reference data for
+// inter and intra.
+#define INTRA_FRAME_INDEX_NRS INTER_REFS_PER_FRAME
+#define AOM_REFFRAME_ALL ((1 << INTER_REFS_PER_FRAME) - 1)
+#else
 // An enum for single reference types (and some derived values).
 enum {
   NONE_FRAME = -1,
@@ -752,6 +778,12 @@
   SINGLE_REFS = FWD_REFS + BWD_REFS,
 };
 
+// NOTE: A limited number of unidirectional reference pairs can be signalled for
+//       compound prediction. The use of skip mode, on the other hand, makes it
+//       possible to have a reference pair not listed for explicit signaling.
+#define MODE_CTX_REF_FRAMES (REF_FRAMES + TOTAL_COMP_REFS)
+#endif  // CONFIG_NEW_REF_SIGNALING
+
 #define REF_FRAMES_LOG2 3
 
 // REF_FRAMES for the cm->ref_frame_map array, 1 scratch frame for the new
@@ -762,6 +794,7 @@
 #define FWD_RF_OFFSET(ref) (ref - LAST_FRAME)
 #define BWD_RF_OFFSET(ref) (ref - BWDREF_FRAME)
 
+#if !CONFIG_NEW_REF_SIGNALING
 enum {
   LAST_LAST2_FRAMES,      // { LAST_FRAME, LAST2_FRAME }
   LAST_LAST3_FRAMES,      // { LAST_FRAME, LAST3_FRAME }
@@ -777,16 +810,12 @@
   //       that are explicitly signaled.
   UNIDIR_COMP_REFS = BWDREF_ALTREF_FRAMES + 1,
 } UENUM1BYTE(UNIDIR_COMP_REF);
+#endif  // !CONFIG_NEW_REF_SIGNALING
 
 #define TOTAL_COMP_REFS (FWD_REFS * BWD_REFS + TOTAL_UNIDIR_COMP_REFS)
 
 #define COMP_REFS (FWD_REFS * BWD_REFS + UNIDIR_COMP_REFS)
 
-// NOTE: A limited number of unidirectional reference pairs can be signalled for
-//       compound prediction. The use of skip mode, on the other hand, makes it
-//       possible to have a reference pair not listed for explicit signaling.
-#define MODE_CTX_REF_FRAMES (REF_FRAMES + TOTAL_COMP_REFS)
-
 // Note: It includes single and compound references. So, it can take values from
 // NONE_FRAME to (MODE_CTX_REF_FRAMES - 1). Hence, it is not defined as an enum.
 typedef int8_t MV_REFERENCE_FRAME;
@@ -832,6 +861,12 @@
 #define MAX_EXTERNAL_REFERENCES 128
 #define MAX_TILES 512
 
+#if CONFIG_IBP_DIR || CONFIG_IBP_DC
+#define DIR_MODES_0_90 17
+#define IBP_WEIGHT_SHIFT 8
+#define IBP_WEIGHT_MAX 255
+#endif
+
 /*!\endcond */
 
 #ifdef __cplusplus
diff --git a/av1/common/filter.h b/av1/common/filter.h
index 16a9450..9e8aba6 100644
--- a/av1/common/filter.h
+++ b/av1/common/filter.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_COMMON_FILTER_H_
diff --git a/av1/common/frame_buffers.c b/av1/common/frame_buffers.c
index f10ccd5..1195779 100644
--- a/av1/common/frame_buffers.c
+++ b/av1/common/frame_buffers.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/av1/common/frame_buffers.h b/av1/common/frame_buffers.h
index 16188e5..6d0fc88 100644
--- a/av1/common/frame_buffers.h
+++ b/av1/common/frame_buffers.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_COMMON_FRAME_BUFFERS_H_
diff --git a/av1/common/idct.c b/av1/common/idct.c
index 457fe62..a6bc0b7 100644
--- a/av1/common/idct.c
+++ b/av1/common/idct.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <math.h>
@@ -211,6 +212,10 @@
   if ((txfm_param->intra_mode < PAETH_PRED) &&
       !xd->lossless[mbmi->segment_id] &&
       !(mbmi->filter_intra_mode_info.use_filter_intra)) {
+#if CONFIG_IST_FIX_B076
+    // updated EOB condition
+    txfm_param->sec_tx_type = get_secondary_tx_type(tx_type);
+#else
     const int width = tx_size_wide[tx_size];
     const int height = tx_size_high[tx_size];
     const int sb_size = (width >= 8 && height >= 8) ? 8 : 4;
@@ -220,6 +225,7 @@
     else if ((sb_size == 8) && (eob > (IST_8x8_HEIGHT - 1)))
       ist_eob = 0;
     if (ist_eob) txfm_param->sec_tx_type = get_secondary_tx_type(tx_type);
+#endif  // CONFIG_IST_FIX_B076
   }
 #else
   txfm_param->tx_type = tx_type;
@@ -415,15 +421,27 @@
 
     const int sb_size = (width >= 8 && height >= 8) ? 8 : 4;
     const int16_t *scan_order_out;
+#if CONFIG_IST_FIX_B076
+    // Align scan order of IST with primary transform scan order
+    const SCAN_ORDER *scan_order_in =
+        get_scan(txfm_param->tx_size, txfm_param->tx_type);
+    const int16_t *const scan = scan_order_in->scan;
+#else
     const int16_t *scan_order_in = (sb_size == 4)
                                        ? stx_scan_orders_4x4[log2width - 2]
                                        : stx_scan_orders_8x8[log2width - 2];
+#endif  // CONFIG_IST_FIX_B076
     tran_low_t buf0[64] = { 0 }, buf1[64] = { 0 };
     tran_low_t *tmp = buf0;
     tran_low_t *src = coeff;
 
     for (int r = 0; r < sb_size * sb_size; r++) {
+#if CONFIG_IST_FIX_B076
+      // Align scan order of IST with primary transform scan order
+      *tmp = src[scan[r]];
+#else
       *tmp = src[scan_order_in[r]];
+#endif  // CONFIG_IST_FIX_B076
       tmp++;
     }
     int8_t transpose = 0;
diff --git a/av1/common/idct.h b/av1/common/idct.h
index 9d71530..216f5ca 100644
--- a/av1/common/idct.h
+++ b/av1/common/idct.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_COMMON_IDCT_H_
diff --git a/av1/common/loopfiltermask.c b/av1/common/loopfiltermask.c
index 1189358..dd21f37 100644
--- a/av1/common/loopfiltermask.c
+++ b/av1/common/loopfiltermask.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2019, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <math.h>
diff --git a/av1/common/mv.h b/av1/common/mv.h
index be539e8..22e407b 100644
--- a/av1/common/mv.h
+++ b/av1/common/mv.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_COMMON_MV_H_
diff --git a/av1/common/mvref_common.c b/av1/common/mvref_common.c
index bd02cf3..ed0e45b 100644
--- a/av1/common/mvref_common.c
+++ b/av1/common/mvref_common.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <stdlib.h>
@@ -21,6 +22,8 @@
 } SINGLE_MV_CANDIDATE;
 #endif  // CONFIG_SMVP_IMPROVEMENT
 
+#define MFMV_STACK_SIZE 3
+
 // Although we assign 32 bit integers, all the values are strictly under 14
 // bits.
 static int div_mult[32] = { 0,    16384, 8192, 5461, 4096, 3276, 2730, 2340,
@@ -57,21 +60,31 @@
   for (h = 0; h < y_mis; h++) {
     MV_REF *mv = frame_mvs;
     for (w = 0; w < x_mis; w++) {
+#if CONFIG_NEW_REF_SIGNALING
+      mv->ref_frame = INVALID_IDX;
+#else
       mv->ref_frame = NONE_FRAME;
+#endif  // CONFIG_NEW_REF_SIGNALING
       mv->mv.as_int = 0;
 
 #if CONFIG_TMVP_IMPROVEMENT
-      if (mi->ref_frame[0] > INTRA_FRAME && mi->ref_frame[1] == NONE_FRAME) {
-        if ((abs(mi->mv[0].as_mv.row) > REFMVS_LIMIT) ||
-            (abs(mi->mv[0].as_mv.col) > REFMVS_LIMIT))
-          continue;
-        mv->ref_frame = mi->ref_frame[0];
-        mv->mv.as_int = mi->mv[0].as_int;
+#if CONFIG_NEW_REF_SIGNALING
+      if (is_inter_ref_frame(mi->ref_frame[0]) &&
+          mi->ref_frame[1] == INVALID_IDX) {
+#else
+      if (is_inter_ref_frame(mi->ref_frame[0]) &&
+          mi->ref_frame[1] == NONE_FRAME) {
+#endif  // CONFIG_NEW_REF_SIGNALING
+        if ((abs(mi->mv[0].as_mv.row) <= REFMVS_LIMIT) &&
+            (abs(mi->mv[0].as_mv.col) <= REFMVS_LIMIT)) {
+          mv->ref_frame = mi->ref_frame[0];
+          mv->mv.as_int = mi->mv[0].as_int;
+        }
       } else {
 #endif  // CONFIG_TMVP_IMPROVEMENT
         for (int idx = 0; idx < 2; ++idx) {
           MV_REFERENCE_FRAME ref_frame = mi->ref_frame[idx];
-          if (ref_frame > INTRA_FRAME) {
+          if (is_inter_ref_frame(ref_frame)) {
             int8_t ref_idx = cm->ref_frame_side[ref_frame];
             if (ref_idx) continue;
             if ((abs(mi->mv[idx].as_mv.row) > REFMVS_LIMIT) ||
@@ -102,7 +115,11 @@
   int index = 0;
   int derived_idx = 0;
 
+#if CONFIG_NEW_REF_SIGNALING
+  if (rf[1] == INVALID_IDX) {
+#else
   if (rf[1] == NONE_FRAME) {
+#endif  // CONFIG_NEW_REF_SIGNALING
     for (derived_idx = 0; derived_idx < derived_mv_count; ++derived_idx) {
       for (index = 0; index < *refmv_count; ++index) {
         if (ref_mv_stack[index].this_mv.as_int ==
@@ -160,7 +177,11 @@
   assert(weight % 2 == 0);
   int index, ref;
 
+#if CONFIG_NEW_REF_SIGNALING
+  if (rf[1] == INVALID_IDX) {
+#else
   if (rf[1] == NONE_FRAME) {
+#endif  // CONFIG_NEW_REF_SIGNALING
     // single reference frame
     for (ref = 0; ref < 2; ++ref) {
       if (candidate->ref_frame[ref] == rf[0]) {
@@ -185,7 +206,7 @@
         ++*ref_match_count;
       }
 #if CONFIG_SMVP_IMPROVEMENT
-      else if (add_more_mvs && candidate->ref_frame[ref] > INTRA_FRAME &&
+      else if (add_more_mvs && is_inter_ref_frame(candidate->ref_frame[ref]) &&
                cm->seq_params.order_hint_info.enable_order_hint) {
         const int cur_blk_ref_side = cm->ref_frame_side[rf[0]];
         const int cand_blk_ref_side =
@@ -376,12 +397,19 @@
     else if (abs(row_offset) > 1)
       len = AOMMAX(len, width_8x8);
 
+#if CONFIG_COMPLEXITY_SCALABLE_MVP
+    // Don't add weight to row_offset < -1 which is in the outer area
+    uint16_t weight = row_offset < -1 ? 0 : 2;
+#else
     uint16_t weight = 2;
+#endif
     if (xd->width >= width_8x8 && xd->width <= n4_w) {
       uint16_t inc = AOMMIN(-max_row_offset + row_offset + 1,
                             mi_size_high[candidate_bsize]);
+#if !CONFIG_COMPLEXITY_SCALABLE_MVP
       // Obtain range used in weight calculation.
       weight = AOMMAX(weight, inc);
+#endif
       // Update processed rows.
       *processed_rows = inc - row_offset - 1;
     }
@@ -438,12 +466,19 @@
     else if (abs(col_offset) > 1)
       len = AOMMAX(len, n8_h_8);
 
+#if CONFIG_COMPLEXITY_SCALABLE_MVP
+    // Don't add weight to col_offset < -1 which is in the outer area
+    uint16_t weight = col_offset < -1 ? 0 : 2;
+#else
     int weight = 2;
+#endif
     if (xd->height >= n8_h_8 && xd->height <= n4_h) {
       int inc = AOMMIN(-max_col_offset + col_offset + 1,
                        mi_size_wide[candidate_bsize]);
+#if !CONFIG_COMPLEXITY_SCALABLE_MVP
       // Obtain range used in weight calculation.
       weight = AOMMAX(weight, inc);
+#endif
       // Update processed cols.
       *processed_cols = inc - col_offset - 1;
     }
@@ -483,6 +518,10 @@
         xd->mi[mi_pos.row * xd->mi_stride + mi_pos.col];
     const int len = mi_size_wide[BLOCK_8X8];
 
+#if CONFIG_COMPLEXITY_SCALABLE_MVP
+    // Don't add weight to (-1,-1) which is in the outer area
+    uint16_t weight = row_offset == -1 && col_offset == -1 ? 0 : 2;
+#endif
     add_ref_mv_candidate(candidate, rf, refmv_count, ref_match_count,
                          newmv_count, ref_mv_stack, ref_mv_weight,
                          gm_mv_candidates, cm->global_motion,
@@ -490,7 +529,11 @@
                          cm, add_more_mvs, single_mv, single_mv_count,
                          derived_mv_stack, derived_mv_weight, derived_mv_count,
 #endif  // CONFIG_SMVP_IMPROVEMENT
+#if CONFIG_COMPLEXITY_SCALABLE_MVP
+                         weight * len);
+#else
                          2 * len);
+#endif
   }  // Analyze a single 8x8 block motion information.
 }
 
@@ -597,7 +640,11 @@
   lower_mv_precision(&this_refmv.as_mv, allow_high_precision_mv,
                      force_integer_mv);
 
+#if CONFIG_NEW_REF_SIGNALING
+  if (rf[1] == INVALID_IDX) {
+#else
   if (rf[1] == NONE_FRAME) {
+#endif  // CONFIG_NEW_REF_SIGNALING
     if (blk_row == 0 && blk_col == 0) {
       if (abs(this_refmv.as_mv.row - gm_mv_candidates[0].as_mv.row) >= 16 ||
           abs(this_refmv.as_mv.col - gm_mv_candidates[0].as_mv.col) >= 16)
@@ -664,7 +711,7 @@
       if (can_rf == rf[cmp_idx] && ref_id_count[cmp_idx] < 2) {
         ref_id[cmp_idx][ref_id_count[cmp_idx]] = candidate->mv[rf_idx];
         ++ref_id_count[cmp_idx];
-      } else if (can_rf > INTRA_FRAME && ref_diff_count[cmp_idx] < 2) {
+      } else if (is_inter_ref_frame(can_rf) && ref_diff_count[cmp_idx] < 2) {
         int_mv this_mv = candidate->mv[rf_idx];
         if (cm->ref_frame_sign_bias[can_rf] !=
             cm->ref_frame_sign_bias[rf[cmp_idx]]) {
@@ -684,7 +731,7 @@
     CANDIDATE_MV ref_mv_stack[MAX_REF_MV_STACK_SIZE],
     uint16_t ref_mv_weight[MAX_REF_MV_STACK_SIZE]) {
   for (int rf_idx = 0; rf_idx < 2; ++rf_idx) {
-    if (candidate->ref_frame[rf_idx] > INTRA_FRAME) {
+    if (is_inter_ref_frame(candidate->ref_frame[rf_idx])) {
       int_mv this_mv = candidate->mv[rf_idx];
       if (cm->ref_frame_sign_bias[candidate->ref_frame[rf_idx]] !=
           cm->ref_frame_sign_bias[ref_frame]) {
@@ -712,6 +759,42 @@
   }
 }
 
+#if CONFIG_REF_MV_BANK
+static AOM_INLINE bool check_rmb_cand(
+    CANDIDATE_MV cand_mv, CANDIDATE_MV *ref_mv_stack, uint16_t *ref_mv_weight,
+    uint8_t *refmv_count, int is_comp, int mi_row, int mi_col, int block_width,
+    int block_height, int frame_width, int frame_height) {
+  // Check if the MV candidate is already existing in the ref MV stack.
+  for (int i = 0; i < *refmv_count; ++i) {
+    if (ref_mv_stack[i].this_mv.as_int == cand_mv.this_mv.as_int &&
+        (!is_comp ||
+         ref_mv_stack[i].comp_mv.as_int == cand_mv.comp_mv.as_int)) {
+      return false;
+    }
+  }
+
+  // Check if the MV candidate is pointing to ref block inside frame boundary.
+  for (int i = 0; i < 1 + is_comp; ++i) {
+    const int mv_row =
+        (i ? cand_mv.comp_mv.as_mv.row : cand_mv.this_mv.as_mv.row) / 8;
+    const int mv_col =
+        (i ? cand_mv.comp_mv.as_mv.col : cand_mv.this_mv.as_mv.col) / 8;
+    const int ref_x = mi_col * MI_SIZE + mv_col;
+    const int ref_y = mi_row * MI_SIZE + mv_row;
+    if (ref_x <= -block_width || ref_y <= -block_height ||
+        ref_x >= frame_width || ref_y >= frame_height) {
+      return false;
+    }
+  }
+
+  ref_mv_stack[*refmv_count] = cand_mv;
+  ref_mv_weight[*refmv_count] = REF_CAT_LEVEL;
+  ++*refmv_count;
+
+  return true;
+}
+#endif  // CONFIG_REF_MV_BANK
+
 static AOM_INLINE void setup_ref_mv_list(
     const AV1_COMMON *cm, const MACROBLOCKD *xd, MV_REFERENCE_FRAME ref_frame,
     uint8_t *const refmv_count,
@@ -901,6 +984,13 @@
   }
 #endif  // CONFIG_SMVP_IMPROVEMENT
 
+#if CONFIG_COMPLEXITY_SCALABLE_MVP
+  // These contexts are independent of the outer area search
+  int new_ctx = 2 * nearest_match + (newmv_count > 0);
+  int ref_ctx = 2 * nearest_match + (newmv_count < 3);
+  mode_context[ref_frame] |= new_ctx;
+  mode_context[ref_frame] |= (ref_ctx << REFMV_OFFSET);
+#else
   const uint8_t ref_match_count = (row_match_count > 0) + (col_match_count > 0);
 
   switch (nearest_match) {
@@ -928,6 +1018,7 @@
       mode_context[ref_frame] |= (5 << REFMV_OFFSET);
       break;
   }
+#endif
 
   // Rank the likelihood and assign nearest and near mvs.
   int len = nearest_refmv_count;
@@ -947,6 +1038,7 @@
     len = nr_len;
   }
 
+#if !CONFIG_COMPLEXITY_SCALABLE_MVP
   len = *refmv_count;
   while (len > nearest_refmv_count) {
     int nr_len = nearest_refmv_count;
@@ -963,6 +1055,7 @@
     }
     len = nr_len;
   }
+#endif
 
 #if CONFIG_SMVP_IMPROVEMENT
 #if CONFIG_NEW_INTER_MODES
@@ -985,7 +1078,11 @@
   int mi_height = AOMMIN(mi_size_high[BLOCK_64X64], xd->height);
   mi_height = AOMMIN(mi_height, cm->mi_params.mi_rows - mi_row);
   const int mi_size = AOMMIN(mi_width, mi_height);
+#if CONFIG_NEW_REF_SIGNALING
+  if (rf[1] > INVALID_IDX) {
+#else
   if (rf[1] > NONE_FRAME) {
+#endif  // CONFIG_NEW_REF_SIGNALING
     // TODO(jingning, yunqing): Refactor and consolidate the compound and
     // single reference frame modes. Reduce unnecessary redundancy.
     if (*refmv_count < MAX_MV_REF_CANDIDATES) {
@@ -1119,6 +1216,49 @@
     }
 #endif  // CONFIG_NEW_INTER_MODES
   }
+#if CONFIG_REF_MV_BANK
+  if (!cm->seq_params.enable_refmvbank) return;
+#if CONFIG_NEW_INTER_MODES
+  const int ref_mv_limit =
+      AOMMIN(cm->features.max_drl_bits + 1, MAX_REF_MV_STACK_SIZE);
+#else
+  const int ref_mv_limit =
+      AOMMIN(USABLE_REF_MV_STACK_SIZE, MAX_REF_MV_STACK_SIZE);
+#endif  // CONFIG_NEW_INTER_MODES
+  // If open slots are available, fetch reference MVs from the ref mv banks.
+#if CONFIG_NEW_REF_SIGNALING
+  if (*refmv_count < ref_mv_limit && ref_frame != INTRA_FRAME_NRS) {
+#else
+  if (*refmv_count < ref_mv_limit && ref_frame != INTRA_FRAME) {
+#endif  // CONFIG_NEW_REF_SIGNALING
+    const REF_MV_BANK *ref_mv_bank = xd->ref_mv_bank_pt;
+    const CANDIDATE_MV *queue = ref_mv_bank->rmb_buffer[ref_frame];
+    const int count = ref_mv_bank->rmb_count[ref_frame];
+    const int start_idx = ref_mv_bank->rmb_start_idx[ref_frame];
+    const int is_comp = is_inter_ref_frame(rf[1]);
+    const int block_width = xd->width * MI_SIZE;
+    const int block_height = xd->height * MI_SIZE;
+
+    for (int idx_bank = 0; idx_bank < count && *refmv_count < ref_mv_limit;
+         ++idx_bank) {
+      const int idx = (start_idx + count - 1 - idx_bank) % REF_MV_BANK_SIZE;
+      const CANDIDATE_MV cand_mv = queue[idx];
+      check_rmb_cand(cand_mv, ref_mv_stack, ref_mv_weight, refmv_count, is_comp,
+                     xd->mi_row, xd->mi_col, block_width, block_height,
+                     cm->width, cm->height);
+    }
+#if !CONFIG_NEW_INTER_MODES
+    if (mv_ref_list != NULL) {
+      for (int idx = *refmv_count; idx < MAX_MV_REF_CANDIDATES; ++idx)
+        mv_ref_list[idx].as_int = gm_mv_candidates[0].as_int;
+      for (int idx = 0; idx < AOMMIN(MAX_MV_REF_CANDIDATES, *refmv_count);
+           ++idx) {
+        mv_ref_list[idx].as_int = ref_mv_stack[idx].this_mv.as_int;
+      }
+    }
+#endif  // !CONFIG_NEW_INTER_MODES
+  }
+#endif  // CONFIG_REF_MV_BANK
 }
 
 void av1_find_mv_refs(const AV1_COMMON *cm, const MACROBLOCKD *xd,
@@ -1132,7 +1272,11 @@
   const int mi_col = xd->mi_col;
   int_mv gm_mv[2];
 
+#if CONFIG_NEW_REF_SIGNALING
+  if (ref_frame == INTRA_FRAME_NRS) {
+#else
   if (ref_frame == INTRA_FRAME) {
+#endif  // CONFIG_NEW_REF_SIGNALING
     gm_mv[0].as_int = gm_mv[1].as_int = 0;
     if (global_mvs != NULL) {
       global_mvs[ref_frame].as_int = INVALID_MV;
@@ -1145,7 +1289,11 @@
 #endif
     const int allow_high_precision_mv = cm->features.allow_high_precision_mv;
     const int force_integer_mv = cm->features.cur_frame_force_integer_mv;
+#if CONFIG_NEW_REF_SIGNALING
+    if (ref_frame < INTER_REFS_PER_FRAME) {
+#else
     if (ref_frame < REF_FRAMES) {
+#endif  // CONFIG_NEW_REF_SIGNALING
       gm_mv[0] = gm_get_motion_vector(&cm->global_motion[ref_frame],
                                       allow_high_precision_mv, bsize, mi_col,
                                       mi_row, force_integer_mv);
@@ -1187,6 +1335,19 @@
   cm->cur_frame->pyramid_level = cm->current_frame.pyramid_level;
 
   MV_REFERENCE_FRAME ref_frame;
+#if CONFIG_NEW_REF_SIGNALING
+  for (ref_frame = 0; ref_frame < INTER_REFS_PER_FRAME; ++ref_frame) {
+    const RefCntBuffer *const buf = get_ref_frame_buf(cm, ref_frame);
+    if (buf != NULL && ref_frame < cm->ref_frames_info.n_total_refs) {
+      cm->cur_frame->ref_order_hints[ref_frame] = buf->order_hint;
+      cm->cur_frame->ref_display_order_hint[ref_frame] =
+          buf->display_order_hint;
+    } else {
+      cm->cur_frame->ref_order_hints[ref_frame] = -1;
+      cm->cur_frame->ref_display_order_hint[ref_frame] = -1;
+    }
+  }
+#else
   for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
     const RefCntBuffer *const buf = get_ref_frame_buf(cm, ref_frame);
     if (buf != NULL) {
@@ -1195,9 +1356,18 @@
           buf->display_order_hint;
     }
   }
+#endif  // CONFIG_NEW_REF_SIGNALING
 }
 
 void av1_setup_frame_sign_bias(AV1_COMMON *cm) {
+  memset(&cm->ref_frame_sign_bias, 0, sizeof(cm->ref_frame_sign_bias));
+#if CONFIG_NEW_REF_SIGNALING
+  for (int ref_frame = 0; ref_frame < cm->ref_frames_info.n_future_refs;
+       ++ref_frame) {
+    const int index = cm->ref_frames_info.future_refs[ref_frame];
+    cm->ref_frame_sign_bias[index] = 1;
+  }
+#else
   MV_REFERENCE_FRAME ref_frame;
   for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
     const RefCntBuffer *const buf = get_ref_frame_buf(cm, ref_frame);
@@ -1212,6 +1382,7 @@
       cm->ref_frame_sign_bias[ref_frame] = 0;
     }
   }
+#endif  // CONFIG_NEW_REF_SIGNALING
 }
 
 #define MAX_OFFSET_WIDTH 64
@@ -1249,21 +1420,8 @@
   return 1;
 }
 
-// Note: motion_filed_projection finds motion vectors of current frame's
-// reference frame, and projects them to current frame. To make it clear,
-// let's call current frame's reference frame as start frame.
-// Call Start frame's reference frames as reference frames.
-// Call ref_offset as frame distances between start frame and its reference
-// frames.
-#if CONFIG_TMVP_IMPROVEMENT
-static int motion_field_projection_bwd(AV1_COMMON *cm,
-                                       MV_REFERENCE_FRAME start_frame,
-                                       int dir) {
-  TPL_MV_REF *tpl_mvs_base = cm->tpl_mvs;
-  int ref_offset[REF_FRAMES] = { 0 };
-
-  const RefCntBuffer *const start_frame_buf =
-      get_ref_frame_buf(cm, start_frame);
+static INLINE int is_ref_motion_field_eligible(
+    const AV1_COMMON *const cm, const RefCntBuffer *const start_frame_buf) {
   if (start_frame_buf == NULL) return 0;
 
   if (start_frame_buf->frame_type == KEY_FRAME ||
@@ -1273,19 +1431,52 @@
   if (start_frame_buf->mi_rows != cm->mi_params.mi_rows ||
       start_frame_buf->mi_cols != cm->mi_params.mi_cols)
     return 0;
+  return 1;
+}
+
+// Note: motion_filed_projection finds motion vectors of current frame's
+// reference frame, and projects them to current frame. To make it clear,
+// let's call current frame's reference frame as start frame.
+// Call Start frame's reference frames as reference frames.
+// Call ref_offset as frame distances between start frame and its reference
+// frames.
+#if CONFIG_TMVP_IMPROVEMENT
+static int motion_field_projection_bwd(AV1_COMMON *cm,
+                                       MV_REFERENCE_FRAME start_frame, int dir,
+                                       int overwrite_mv) {
+  TPL_MV_REF *tpl_mvs_base = cm->tpl_mvs;
+#if CONFIG_NEW_REF_SIGNALING
+  int ref_offset[INTER_REFS_PER_FRAME] = { 0 };
+#else
+  int ref_offset[REF_FRAMES] = { 0 };
+#endif  // CONFIG_NEW_REF_SIGNALING
+
+  const RefCntBuffer *const start_frame_buf =
+      get_ref_frame_buf(cm, start_frame);
+  if (!is_ref_motion_field_eligible(cm, start_frame_buf)) return 0;
 
   const int start_frame_order_hint = start_frame_buf->order_hint;
-  const unsigned int *const ref_order_hints =
-      &start_frame_buf->ref_order_hints[0];
   const int cur_order_hint = cm->cur_frame->order_hint;
   int start_to_current_frame_offset = get_relative_dist(
       &cm->seq_params.order_hint_info, start_frame_order_hint, cur_order_hint);
 
+#if CONFIG_NEW_REF_SIGNALING
+  const int *const ref_order_hints = &start_frame_buf->ref_order_hints[0];
+  for (MV_REFERENCE_FRAME rf = 0; rf < INTER_REFS_PER_FRAME; ++rf) {
+    if (ref_order_hints[rf] != -1)
+      ref_offset[rf] =
+          get_relative_dist(&cm->seq_params.order_hint_info,
+                            start_frame_order_hint, ref_order_hints[rf]);
+  }
+#else
+  const unsigned int *const ref_order_hints =
+      &start_frame_buf->ref_order_hints[0];
   for (MV_REFERENCE_FRAME rf = LAST_FRAME; rf <= INTER_REFS_PER_FRAME; ++rf) {
     ref_offset[rf] = get_relative_dist(&cm->seq_params.order_hint_info,
                                        start_frame_order_hint,
                                        ref_order_hints[rf - LAST_FRAME]);
   }
+#endif  // CONFIG_NEW_REF_SIGNALING
 
   if (dir == 2) start_to_current_frame_offset = -start_to_current_frame_offset;
 
@@ -1298,7 +1489,7 @@
       MV_REF *mv_ref = &mv_ref_base[blk_row * mvs_cols + blk_col];
       MV fwd_mv = mv_ref->mv.as_mv;
 
-      if (mv_ref->ref_frame > INTRA_FRAME) {
+      if (is_inter_ref_frame(mv_ref->ref_frame)) {
         int_mv this_mv;
         int mi_r, mi_c;
         int ref_frame_offset = ref_offset[mv_ref->ref_frame];
@@ -1321,7 +1512,8 @@
           fwd_mv.col = -fwd_mv.col;
 
           const int mi_offset = mi_r * (cm->mi_params.mi_stride >> 1) + mi_c;
-          if (tpl_mvs_base[mi_offset].mfmv0.as_int == INVALID_MV) {
+          if (overwrite_mv ||
+              tpl_mvs_base[mi_offset].mfmv0.as_int == INVALID_MV) {
             tpl_mvs_base[mi_offset].mfmv0.as_mv.row = fwd_mv.row;
             tpl_mvs_base[mi_offset].mfmv0.as_mv.col = fwd_mv.col;
             tpl_mvs_base[mi_offset].ref_frame_offset = ref_frame_offset;
@@ -1336,34 +1528,41 @@
 #endif  // CONFIG_TMVP_IMPROVEMENT
 
 static int motion_field_projection(AV1_COMMON *cm,
-                                   MV_REFERENCE_FRAME start_frame, int dir) {
+                                   MV_REFERENCE_FRAME start_frame, int dir,
+                                   int overwrite_mv) {
   TPL_MV_REF *tpl_mvs_base = cm->tpl_mvs;
+#if CONFIG_NEW_REF_SIGNALING
+  int ref_offset[INTER_REFS_PER_FRAME] = { 0 };
+#else
   int ref_offset[REF_FRAMES] = { 0 };
+#endif  // CONFIG_NEW_REF_SIGNALING
 
   const RefCntBuffer *const start_frame_buf =
       get_ref_frame_buf(cm, start_frame);
-  if (start_frame_buf == NULL) return 0;
-
-  if (start_frame_buf->frame_type == KEY_FRAME ||
-      start_frame_buf->frame_type == INTRA_ONLY_FRAME)
-    return 0;
-
-  if (start_frame_buf->mi_rows != cm->mi_params.mi_rows ||
-      start_frame_buf->mi_cols != cm->mi_params.mi_cols)
-    return 0;
+  if (!is_ref_motion_field_eligible(cm, start_frame_buf)) return 0;
 
   const int start_frame_order_hint = start_frame_buf->order_hint;
-  const unsigned int *const ref_order_hints =
-      &start_frame_buf->ref_order_hints[0];
   const int cur_order_hint = cm->cur_frame->order_hint;
   int start_to_current_frame_offset = get_relative_dist(
       &cm->seq_params.order_hint_info, start_frame_order_hint, cur_order_hint);
 
+#if CONFIG_NEW_REF_SIGNALING
+  const int *const ref_order_hints = &start_frame_buf->ref_order_hints[0];
+  for (MV_REFERENCE_FRAME rf = 0; rf < INTER_REFS_PER_FRAME; ++rf) {
+    if (ref_order_hints[rf] != -1)
+      ref_offset[rf] =
+          get_relative_dist(&cm->seq_params.order_hint_info,
+                            start_frame_order_hint, ref_order_hints[rf]);
+  }
+#else
+  const unsigned int *const ref_order_hints =
+      &start_frame_buf->ref_order_hints[0];
   for (MV_REFERENCE_FRAME rf = LAST_FRAME; rf <= INTER_REFS_PER_FRAME; ++rf) {
     ref_offset[rf] = get_relative_dist(&cm->seq_params.order_hint_info,
                                        start_frame_order_hint,
                                        ref_order_hints[rf - LAST_FRAME]);
   }
+#endif  // CONFIG_NEW_REF_SIGNALING
 
   if (dir == 2) start_to_current_frame_offset = -start_to_current_frame_offset;
 
@@ -1376,7 +1575,7 @@
       MV_REF *mv_ref = &mv_ref_base[blk_row * mvs_cols + blk_col];
       MV fwd_mv = mv_ref->mv.as_mv;
 
-      if (mv_ref->ref_frame > INTRA_FRAME) {
+      if (is_inter_ref_frame(mv_ref->ref_frame)) {
         int_mv this_mv;
         int mi_r, mi_c;
         const int ref_frame_offset = ref_offset[mv_ref->ref_frame];
@@ -1395,15 +1594,12 @@
 
         if (pos_valid) {
           const int mi_offset = mi_r * (cm->mi_params.mi_stride >> 1) + mi_c;
-#if CONFIG_TMVP_IMPROVEMENT
-          if (tpl_mvs_base[mi_offset].mfmv0.as_int == INVALID_MV) {
-#endif  // CONFIG_TMVP_IMPROVEMENT
+          if (overwrite_mv ||
+              tpl_mvs_base[mi_offset].mfmv0.as_int == INVALID_MV) {
             tpl_mvs_base[mi_offset].mfmv0.as_mv.row = fwd_mv.row;
             tpl_mvs_base[mi_offset].mfmv0.as_mv.col = fwd_mv.col;
             tpl_mvs_base[mi_offset].ref_frame_offset = ref_frame_offset;
-#if CONFIG_TMVP_IMPROVEMENT
           }
-#endif  // CONFIG_TMVP_IMPROVEMENT
         }
       }
     }
@@ -1412,6 +1608,24 @@
   return 1;
 }
 
+#if CONFIG_NEW_REF_SIGNALING
+static INLINE int is_ref_overlay_nrs(const AV1_COMMON *const cm, int ref) {
+  const OrderHintInfo *const order_hint_info = &cm->seq_params.order_hint_info;
+  if (!order_hint_info->enable_order_hint) return -1;
+  const RefCntBuffer *const buf = get_ref_frame_buf(cm, ref);
+  if (buf == NULL) return -1;
+  const int ref_order_hint = buf->order_hint;
+  for (int r = 0; r < INTER_REFS_PER_FRAME; ++r) {
+    if (buf->ref_order_hints[r] == -1) continue;
+    const int ref_ref_order_hint = buf->ref_order_hints[r];
+    if (get_relative_dist(order_hint_info, ref_order_hint,
+                          ref_ref_order_hint) == 0)
+      return 1;
+  }
+  return 0;
+}
+#endif  // CONFIG_NEW_REF_SIGNALING
+
 void av1_setup_motion_field(AV1_COMMON *cm) {
   const OrderHintInfo *const order_hint_info = &cm->seq_params.order_hint_info;
 
@@ -1426,10 +1640,30 @@
     tpl_mvs_base[idx].ref_frame_offset = 0;
   }
 
-  const int cur_order_hint = cm->cur_frame->order_hint;
-
   const RefCntBuffer *ref_buf[INTER_REFS_PER_FRAME];
+
+#if CONFIG_NEW_REF_SIGNALING
+  for (int index = 0; index < cm->ref_frames_info.n_past_refs; index++) {
+    const int ref_frame = cm->ref_frames_info.past_refs[index];
+    cm->ref_frame_side[ref_frame] = 0;
+    const RefCntBuffer *const buf = get_ref_frame_buf(cm, ref_frame);
+    ref_buf[ref_frame] = buf;
+  }
+  for (int index = 0; index < cm->ref_frames_info.n_future_refs; index++) {
+    const int ref_frame = cm->ref_frames_info.future_refs[index];
+    cm->ref_frame_side[ref_frame] = 1;
+    const RefCntBuffer *const buf = get_ref_frame_buf(cm, ref_frame);
+    ref_buf[ref_frame] = buf;
+  }
+  for (int index = 0; index < cm->ref_frames_info.n_cur_refs; index++) {
+    const int ref_frame = cm->ref_frames_info.cur_refs[index];
+    cm->ref_frame_side[ref_frame] = -1;
+    const RefCntBuffer *const buf = get_ref_frame_buf(cm, ref_frame);
+    ref_buf[ref_frame] = buf;
+  }
+#else
   int ref_order_hint[INTER_REFS_PER_FRAME];
+  const int cur_order_hint = cm->cur_frame->order_hint;
 
 #if CONFIG_TMVP_IMPROVEMENT
   int has_bwd_ref = 0;
@@ -1462,10 +1696,90 @@
     cm->ref_frame_relative_dist[ref_frame] = abs(relative_dist);
 #endif  // CONFIG_SMVP_IMPROVEMENT
   }
+#endif  // CONFIG_NEW_REF_SIGNALING
 
+#if CONFIG_NEW_REF_SIGNALING
+  int n_refs_used = 0;
+
+  // Implements a strategy where the closest references in the past
+  // and future ranked lists are processed first, followed by
+  // processing the second closest references up to MFMV_STACK_SIZE.
+  //
+  // Find two closest past and future references
+  int dist[2][2] = { { INT_MAX, INT_MAX }, { INT_MAX, INT_MAX } };
+  int closest_ref[2][2] = { { -1, -1 }, { -1, -1 } };
+  for (int ref_frame = 0; ref_frame < cm->ref_frames_info.n_total_refs;
+       ref_frame++) {
+    const int dir = cm->ref_frame_side[ref_frame];
+    if (dir == -1 || is_ref_overlay_nrs(cm, ref_frame) ||
+        !is_ref_motion_field_eligible(cm, ref_buf[ref_frame]))
+      continue;
+    const int absdist = abs(cm->ref_frames_info.ref_frame_distance[ref_frame]);
+    if (absdist < dist[dir][0]) {
+      dist[dir][1] = dist[dir][0];
+      closest_ref[dir][1] = closest_ref[dir][0];
+      dist[dir][0] = absdist;
+      closest_ref[dir][0] = ref_frame;
+    } else if (absdist < dist[dir][1]) {
+      dist[dir][1] = absdist;
+      closest_ref[dir][1] = ref_frame;
+    }
+  }
+#if CONFIG_TMVP_IMPROVEMENT
+  // Do projection on closest past (backward MV), closest future, second
+  // closest future, second closest past (backward MV), closest path (forward
+  // MV), and then second closest past (forward MVs), without overwriting
+  // the MVs.
+  if (closest_ref[0][0] != -1) {
+    const int ret = motion_field_projection_bwd(cm, closest_ref[0][0], 2, 0);
+    n_refs_used += ret;
+  }
+  if (closest_ref[1][0] != -1) {
+    const int ret = motion_field_projection(cm, closest_ref[1][0], 0, 0);
+    n_refs_used += ret;
+  }
+  if (closest_ref[1][1] != -1 && n_refs_used < MFMV_STACK_SIZE) {
+    const int ret = motion_field_projection(cm, closest_ref[1][1], 0, 0);
+    n_refs_used += ret;
+  }
+  if (closest_ref[0][1] != -1 && n_refs_used < MFMV_STACK_SIZE) {
+    const int ret = motion_field_projection_bwd(cm, closest_ref[0][1], 2, 0);
+    n_refs_used += ret;
+  }
+  if (closest_ref[0][0] != -1 && n_refs_used < MFMV_STACK_SIZE) {
+    const int ret = motion_field_projection(cm, closest_ref[0][0], 2, 0);
+    n_refs_used += ret;
+  }
+  if (closest_ref[0][1] != -1 && n_refs_used < MFMV_STACK_SIZE) {
+    const int ret = motion_field_projection(cm, closest_ref[0][1], 2, 0);
+    n_refs_used += ret;
+  }
+#else
+  // Do projection on closest past and future refs if they exist
+  if (closest_ref[0][0] != -1) {
+    const int ret = motion_field_projection(cm, closest_ref[0][0], 2, 1);
+    n_refs_used += ret;
+  }
+  if (closest_ref[1][0] != -1) {
+    const int ret = motion_field_projection(cm, closest_ref[1][0], 0, 1);
+    n_refs_used += ret;
+  }
+  // Add second closest from future and past if there are fewer than
+  // MFMV_STACK_SIZE frames processed so far.
+  if (closest_ref[1][1] != -1 && n_refs_used < MFMV_STACK_SIZE) {
+    const int ret = motion_field_projection(cm, closest_ref[1][1], 0, 0);
+    n_refs_used += ret;
+  }
+  if (closest_ref[0][1] != -1 && n_refs_used < MFMV_STACK_SIZE) {
+    const int ret = motion_field_projection(cm, closest_ref[0][1], 2, 0);
+    n_refs_used += ret;
+  }
+#endif
+#else
   int ref_stamp = MFMV_STACK_SIZE - 1;
 
 #if CONFIG_TMVP_IMPROVEMENT
+  int overwrite_mv = 0;
   if (has_bwd_ref) {
     if (ref_buf[LAST_FRAME - LAST_FRAME] != NULL) {
       const int alt_of_lst_order_hint =
@@ -1474,10 +1788,12 @@
 
       const int is_lst_overlay =
           (alt_of_lst_order_hint == ref_order_hint[GOLDEN_FRAME - LAST_FRAME]);
-      if (!is_lst_overlay) motion_field_projection_bwd(cm, LAST_FRAME, 2);
+      if (!is_lst_overlay)
+        motion_field_projection_bwd(cm, LAST_FRAME, 2, overwrite_mv);
     }
   }
 #else
+  int overwrite_mv = 1;
   if (ref_buf[LAST_FRAME - LAST_FRAME] != NULL) {
     const int alt_of_lst_order_hint =
         ref_buf[LAST_FRAME - LAST_FRAME]
@@ -1485,7 +1801,8 @@
 
     const int is_lst_overlay =
         (alt_of_lst_order_hint == ref_order_hint[GOLDEN_FRAME - LAST_FRAME]);
-    if (!is_lst_overlay) motion_field_projection(cm, LAST_FRAME, 2);
+    if (!is_lst_overlay)
+      motion_field_projection(cm, LAST_FRAME, 2, overwrite_mv);
     --ref_stamp;
   }
 #endif  // CONFIG_TMVP_IMPROVEMENT
@@ -1493,13 +1810,14 @@
   if (get_relative_dist(order_hint_info,
                         ref_order_hint[BWDREF_FRAME - LAST_FRAME],
                         cur_order_hint) > 0) {
-    if (motion_field_projection(cm, BWDREF_FRAME, 0)) --ref_stamp;
+    if (motion_field_projection(cm, BWDREF_FRAME, 0, overwrite_mv)) --ref_stamp;
   }
 
   if (get_relative_dist(order_hint_info,
                         ref_order_hint[ALTREF2_FRAME - LAST_FRAME],
                         cur_order_hint) > 0) {
-    if (motion_field_projection(cm, ALTREF2_FRAME, 0)) --ref_stamp;
+    if (motion_field_projection(cm, ALTREF2_FRAME, 0, overwrite_mv))
+      --ref_stamp;
   }
 
 #if CONFIG_TMVP_IMPROVEMENT
@@ -1510,7 +1828,8 @@
 
     const int is_lst_overlay =
         (alt_of_lst_order_hint == ref_order_hint[GOLDEN_FRAME - LAST_FRAME]);
-    if (!is_lst_overlay) motion_field_projection(cm, LAST_FRAME, 2);
+    if (!is_lst_overlay)
+      motion_field_projection(cm, LAST_FRAME, 2, overwrite_mv);
     --ref_stamp;
   }
 #endif  // CONFIG_TMVP_IMPROVEMENT
@@ -1519,14 +1838,15 @@
                         ref_order_hint[ALTREF_FRAME - LAST_FRAME],
                         cur_order_hint) > 0 &&
       ref_stamp >= 0)
-    if (motion_field_projection(cm, ALTREF_FRAME, 0)) --ref_stamp;
+    if (motion_field_projection(cm, ALTREF_FRAME, 0, overwrite_mv)) --ref_stamp;
 
 #if CONFIG_TMVP_IMPROVEMENT
   if (has_bwd_ref && ref_stamp >= 0) {
-    motion_field_projection_bwd(cm, LAST2_FRAME, 2);
+    motion_field_projection_bwd(cm, LAST2_FRAME, 2, overwrite_mv);
   }
 #endif  // CONFIG_TMVP_IMPROVEMENT
-  if (ref_stamp >= 0) motion_field_projection(cm, LAST2_FRAME, 2);
+  if (ref_stamp >= 0) motion_field_projection(cm, LAST2_FRAME, 2, overwrite_mv);
+#endif  // CONFIG_NEW_REF_SIGNALING
 }
 
 #if CONFIG_SMVP_IMPROVEMENT
@@ -1538,7 +1858,12 @@
 
   const int cur_order_hint = cm->cur_frame->order_hint;
 
+#if CONFIG_NEW_REF_SIGNALING
+  for (int ref_frame = 0; ref_frame < cm->ref_frames_info.n_total_refs;
+       ref_frame++) {
+#else
   for (int ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ref_frame++) {
+#endif  // CONFIG_NEW_REF_SIGNALING
     const RefCntBuffer *const buf = get_ref_frame_buf(cm, ref_frame);
     int order_hint = 0;
 
@@ -1672,7 +1997,12 @@
         }
       }
 #else
+#if CONFIG_NEW_REF_SIGNALING
+      if (mbmi->ref_frame[0] == ref_frame &&
+          mbmi->ref_frame[1] == INVALID_IDX) {
+#else
       if (mbmi->ref_frame[0] == ref_frame && mbmi->ref_frame[1] == NONE_FRAME) {
+#endif  // CONFIG_NEW_REF_SIGNALING
         record_samples(mbmi, pts, pts_inref, 0, -1, col_offset, 1);
         pts += 2;
         pts_inref += 2;
@@ -1702,7 +2032,11 @@
         }
 #else
         if (mbmi->ref_frame[0] == ref_frame &&
+#if CONFIG_NEW_REF_SIGNALING
+            mbmi->ref_frame[1] == INVALID_IDX) {
+#else
             mbmi->ref_frame[1] == NONE_FRAME) {
+#endif  // CONFIG_NEW_REF_SIGNALING
           record_samples(mbmi, pts, pts_inref, 0, -1, i, 1);
           pts += 2;
           pts_inref += 2;
@@ -1744,7 +2078,12 @@
         }
       }
 #else
+#if CONFIG_NEW_REF_SIGNALING
+      if (mbmi->ref_frame[0] == ref_frame &&
+          mbmi->ref_frame[1] == INVALID_IDX) {
+#else
       if (mbmi->ref_frame[0] == ref_frame && mbmi->ref_frame[1] == NONE_FRAME) {
+#endif  // CONFIG_NEW_REF_SIGNALING
         record_samples(mbmi, pts, pts_inref, row_offset, 1, 0, -1);
         pts += 2;
         pts_inref += 2;
@@ -1775,7 +2114,11 @@
         }
 #else
         if (mbmi->ref_frame[0] == ref_frame &&
+#if CONFIG_NEW_REF_SIGNALING
+            mbmi->ref_frame[1] == INVALID_IDX) {
+#else
             mbmi->ref_frame[1] == NONE_FRAME) {
+#endif  // CONFIG_NEW_REF_SIGNALING
           record_samples(mbmi, pts, pts_inref, i, 1, 0, -1);
           pts += 2;
           pts_inref += 2;
@@ -1804,7 +2147,11 @@
       }
     }
 #else
+#if CONFIG_NEW_REF_SIGNALING
+    if (mbmi->ref_frame[0] == ref_frame && mbmi->ref_frame[1] == INVALID_IDX) {
+#else
     if (mbmi->ref_frame[0] == ref_frame && mbmi->ref_frame[1] == NONE_FRAME) {
+#endif  // CONFIG_NEW_REF_SIGNALING
       record_samples(mbmi, pts, pts_inref, 0, -1, 0, -1);
       pts += 2;
       pts_inref += 2;
@@ -1836,7 +2183,12 @@
         }
       }
 #else
+#if CONFIG_NEW_REF_SIGNALING
+      if (mbmi->ref_frame[0] == ref_frame &&
+          mbmi->ref_frame[1] == INVALID_IDX) {
+#else
       if (mbmi->ref_frame[0] == ref_frame && mbmi->ref_frame[1] == NONE_FRAME) {
+#endif  // CONFIG_NEW_REF_SIGNALING
         record_samples(mbmi, pts, pts_inref, 0, -1, xd->width, 1);
         if (++np >= LEAST_SQUARES_SAMPLES_MAX) return LEAST_SQUARES_SAMPLES_MAX;
       }
@@ -1865,8 +2217,13 @@
   int ref_idx[2] = { INVALID_IDX, INVALID_IDX };
 
   // Identify the nearest forward and backward references.
+#if CONFIG_NEW_REF_SIGNALING
+  for (int i = 0; i < cm->ref_frames_info.n_total_refs; ++i) {
+    const RefCntBuffer *const buf = get_ref_frame_buf(cm, i);
+#else
   for (int i = 0; i < INTER_REFS_PER_FRAME; ++i) {
     const RefCntBuffer *const buf = get_ref_frame_buf(cm, LAST_FRAME + i);
+#endif  // CONFIG_NEW_REF_SIGNALING
     if (buf == NULL) continue;
 
     const int ref_order_hint = buf->order_hint;
@@ -1894,14 +2251,23 @@
   if (ref_idx[0] != INVALID_IDX && ref_idx[1] != INVALID_IDX) {
     // == Bi-directional prediction ==
     skip_mode_info->skip_mode_allowed = 1;
+#if CONFIG_NEW_REF_SIGNALING
+    skip_mode_info->ref_frame_idx_0 = ref_idx[0];
+    skip_mode_info->ref_frame_idx_1 = ref_idx[1];
+#else
     skip_mode_info->ref_frame_idx_0 = AOMMIN(ref_idx[0], ref_idx[1]);
     skip_mode_info->ref_frame_idx_1 = AOMMAX(ref_idx[0], ref_idx[1]);
+#endif  // CONFIG_NEW_REF_SIGNALING
   } else if (ref_idx[0] != INVALID_IDX && ref_idx[1] == INVALID_IDX) {
     // == Forward prediction only ==
     // Identify the second nearest forward reference.
     ref_order_hints[1] = -1;
     for (int i = 0; i < INTER_REFS_PER_FRAME; ++i) {
+#if CONFIG_NEW_REF_SIGNALING
+      const RefCntBuffer *const buf = get_ref_frame_buf(cm, i);
+#else
       const RefCntBuffer *const buf = get_ref_frame_buf(cm, LAST_FRAME + i);
+#endif  // CONFIG_NEW_REF_SIGNALING
       if (buf == NULL) continue;
 
       const int ref_order_hint = buf->order_hint;
@@ -1918,12 +2284,18 @@
     }
     if (ref_order_hints[1] != -1) {
       skip_mode_info->skip_mode_allowed = 1;
+#if CONFIG_NEW_REF_SIGNALING
+      skip_mode_info->ref_frame_idx_0 = ref_idx[0];
+      skip_mode_info->ref_frame_idx_1 = ref_idx[1];
+#else
       skip_mode_info->ref_frame_idx_0 = AOMMIN(ref_idx[0], ref_idx[1]);
       skip_mode_info->ref_frame_idx_1 = AOMMAX(ref_idx[0], ref_idx[1]);
+#endif  // CONFIG_NEW_REF_SIGNALING
     }
   }
 }
 
+#if !CONFIG_NEW_REF_SIGNALING
 typedef struct {
   int map_idx;        // frame map index
   RefCntBuffer *buf;  // frame buffer
@@ -2113,3 +2485,62 @@
     assert(ref_flag_list[i] == 1);
   }
 }
+#endif  // !CONFIG_NEW_REF_SIGNALING
+
+#if CONFIG_REF_MV_BANK
+static INLINE void update_ref_mv_bank(const MB_MODE_INFO *const mbmi,
+                                      REF_MV_BANK *ref_mv_bank) {
+  const MV_REFERENCE_FRAME ref_frame = av1_ref_frame_type(mbmi->ref_frame);
+  CANDIDATE_MV *queue = ref_mv_bank->rmb_buffer[ref_frame];
+  const int is_comp = has_second_ref(mbmi);
+  const int start_idx = ref_mv_bank->rmb_start_idx[ref_frame];
+  const int count = ref_mv_bank->rmb_count[ref_frame];
+  int found = -1;
+
+  // If max hits have been reached return.
+  if (ref_mv_bank->rmb_sb_hits >= MAX_RMB_SB_HITS) return;
+  // else increment count and proceed with updating.
+  ++ref_mv_bank->rmb_sb_hits;
+
+  // Check if current MV is already existing in the buffer.
+  for (int i = 0; i < count; ++i) {
+    const int idx = (start_idx + i) % REF_MV_BANK_SIZE;
+    if (mbmi->mv[0].as_int == queue[idx].this_mv.as_int &&
+        (!is_comp || mbmi->mv[1].as_int == queue[idx].comp_mv.as_int)) {
+      found = i;
+      break;
+    }
+  }
+
+  // If current MV is found in the buffer, move it to the end of the buffer.
+  if (found >= 0) {
+    const int idx = (start_idx + found) % REF_MV_BANK_SIZE;
+    const CANDIDATE_MV cand = queue[idx];
+    for (int i = found; i < count - 1; ++i) {
+      const int idx0 = (start_idx + i) % REF_MV_BANK_SIZE;
+      const int idx1 = (start_idx + i + 1) % REF_MV_BANK_SIZE;
+      queue[idx0] = queue[idx1];
+    }
+    const int tail = (start_idx + count - 1) % REF_MV_BANK_SIZE;
+    queue[tail] = cand;
+    return;
+  }
+
+  // If current MV is not found in the buffer, append it to the end of the
+  // buffer, and update the count and start_idx accordingly.
+  const int idx = (start_idx + count) % REF_MV_BANK_SIZE;
+  queue[idx].this_mv = mbmi->mv[0];
+  if (is_comp) queue[idx].comp_mv = mbmi->mv[1];
+  if (count < REF_MV_BANK_SIZE) {
+    ++ref_mv_bank->rmb_count[ref_frame];
+  } else {
+    ++ref_mv_bank->rmb_start_idx[ref_frame];
+  }
+}
+
+void av1_update_ref_mv_bank(const AV1_COMMON *const cm, MACROBLOCKD *const xd,
+                            const MB_MODE_INFO *const mbmi) {
+  update_ref_mv_bank(mbmi, &xd->ref_mv_bank);
+  (void)cm;
+}
+#endif  // CONFIG_REF_MV_BANK
diff --git a/av1/common/mvref_common.h b/av1/common/mvref_common.h
index 4169300..449caa8 100644
--- a/av1/common/mvref_common.h
+++ b/av1/common/mvref_common.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #ifndef AOM_AV1_COMMON_MVREF_COMMON_H_
 #define AOM_AV1_COMMON_MVREF_COMMON_H_
@@ -101,9 +102,76 @@
   }
 }
 
+#if CONFIG_NEW_REF_SIGNALING
+// Converts a pair of distinct indices (rf) each in [0, n-1],
+// to an combined index in [0, n*(n-1)/2].
+// The order of the combined index is as follows:
+// (0, 1), (0, 2), (0, 3), ..., (0, n-1),
+//         (1, 2), (1, 3), ..., (1, n-1),
+//                 (2, 3), ..., (2, n-1),
+//                         ...
+//                              (n-2, n-1)
+static INLINE int8_t single2comb(int n, const int8_t *const rf) {
+  assert(rf[0] < n && rf[1] < n);
+  int8_t rfr[2] = { rf[0], rf[1] };
+  if (rf[1] < rf[0]) {
+    rfr[0] = rf[1];
+    rfr[1] = rf[0];
+  }
+  int off = n * rfr[0] - rfr[0] * (rfr[0] + 1) / 2;
+  int combindex = off + rfr[1] - rfr[0] - 1;
+  return combindex;
+}
+
+// Converts a combined index in [0, n*(n-1)/2] to a pair of single
+// ref indices (rf) each in [0, n-1]. See comment above for order
+// of the combined indexing.
+static INLINE void comb2single(int n, int8_t combindex, int8_t *rf) {
+  assert(combindex < n * (n - 1) / 2);
+  int i = n - 1, j = n - 1;
+  rf[0] = 0;
+  // Starting form n-1, keep reducing the row length by 1 until
+  // combindex < i
+  while (i <= combindex) {
+    rf[0]++;
+    j--;
+    i += j;
+  }
+  rf[1] = combindex - i + j + rf[0] + 1;
+  assert(rf[1] > rf[0]);
+}
+
+static INLINE int8_t av1_ref_frame_type(const MV_REFERENCE_FRAME *const rf) {
+  if (!is_inter_ref_frame(rf[0])) {
+    // Intra or invalid
+    return rf[0];
+  } else if (!is_inter_ref_frame(rf[1])) {
+    // single ref
+    return rf[0];
+  } else {
+    // compound ref
+    assert(rf[0] < INTER_REFS_PER_FRAME);
+    assert(rf[1] < INTER_REFS_PER_FRAME);
+    return single2comb(INTER_REFS_PER_FRAME, rf) + INTER_REFS_PER_FRAME;
+  }
+}
+
+static INLINE void av1_set_ref_frame(MV_REFERENCE_FRAME *rf,
+                                     MV_REFERENCE_FRAME ref_frame_type) {
+  if (ref_frame_type == INTRA_FRAME_NRS ||
+      ref_frame_type < INTER_REFS_PER_FRAME) {
+    rf[0] = ref_frame_type;
+    rf[1] = INVALID_IDX;
+  } else {
+    comb2single(INTER_REFS_PER_FRAME, ref_frame_type - INTER_REFS_PER_FRAME,
+                rf);
+  }
+  return;
+}
+#else
 static INLINE int8_t get_uni_comp_ref_idx(const MV_REFERENCE_FRAME *const rf) {
   // Single ref pred
-  if (rf[1] <= INTRA_FRAME) return -1;
+  if (!is_inter_ref_frame(rf[1])) return -1;
 
   // Bi-directional comp ref pred
   if ((rf[0] < BWDREF_FRAME) && (rf[1] >= BWDREF_FRAME)) return -1;
@@ -116,7 +184,7 @@
 }
 
 static INLINE int8_t av1_ref_frame_type(const MV_REFERENCE_FRAME *const rf) {
-  if (rf[1] > INTRA_FRAME) {
+  if (is_inter_ref_frame(rf[1])) {
     const int8_t uni_comp_ref_idx = get_uni_comp_ref_idx(rf);
     if (uni_comp_ref_idx >= 0) {
       assert((REF_FRAMES + FWD_REFS * BWD_REFS + uni_comp_ref_idx) <
@@ -165,6 +233,7 @@
     rf[1] = NONE_FRAME;
   }
 }
+#endif  // CONFIG_NEW_REF_SIGNALING
 
 static uint16_t compound_mode_ctx_map[3][COMP_NEWMV_CTXS] = {
   { 0, 1, 1, 1, 1 },
@@ -182,7 +251,7 @@
     const int16_t *const mode_context, const MV_REFERENCE_FRAME *const rf) {
   const int8_t ref_frame = av1_ref_frame_type(rf);
 
-  if (rf[1] <= INTRA_FRAME) return mode_context[ref_frame];
+  if (!is_inter_ref_frame(rf[1])) return mode_context[ref_frame];
 
   const int16_t newmv_ctx = mode_context[ref_frame] & NEWMV_CTX_MASK;
   const int16_t refmv_ctx =
@@ -230,8 +299,10 @@
 void av1_setup_frame_sign_bias(AV1_COMMON *cm);
 void av1_setup_skip_mode_allowed(AV1_COMMON *cm);
 void av1_setup_motion_field(AV1_COMMON *cm);
+#if !CONFIG_NEW_REF_SIGNALING
 void av1_set_frame_refs(AV1_COMMON *const cm, int *remapped_ref_idx,
                         int lst_map_idx, int gld_map_idx);
+#endif  // !CONFIG_NEW_REF_SIGNALING
 #if CONFIG_SMVP_IMPROVEMENT
 void av1_setup_ref_frame_sides(AV1_COMMON *cm);
 #endif  // CONFIG_SMVP_IMPROVEMENT
@@ -373,6 +444,12 @@
   return 1;
 }
 
+#if CONFIG_REF_MV_BANK
+#define MAX_RMB_SB_HITS 64
+void av1_update_ref_mv_bank(const AV1_COMMON *const cm, MACROBLOCKD *const xd,
+                            const MB_MODE_INFO *const mbmi);
+#endif  // CONFIG_REF_MV_BANK
+
 #ifdef __cplusplus
 }  // extern "C"
 #endif
diff --git a/av1/common/obmc.h b/av1/common/obmc.h
index 2f233cf..f810bd2 100644
--- a/av1/common/obmc.h
+++ b/av1/common/obmc.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_COMMON_OBMC_H_
diff --git a/av1/common/obu_util.c b/av1/common/obu_util.c
index 7d2694b..dce9e7e 100644
--- a/av1/common/obu_util.c
+++ b/av1/common/obu_util.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #include <assert.h>
 
diff --git a/av1/common/obu_util.h b/av1/common/obu_util.h
index 7c56904..f93ef6e 100644
--- a/av1/common/obu_util.h
+++ b/av1/common/obu_util.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #ifndef AOM_AV1_COMMON_OBU_UTIL_H_
 #define AOM_AV1_COMMON_OBU_UTIL_H_
diff --git a/av1/common/odintrin.c b/av1/common/odintrin.c
index 7584b2e..f665c10 100644
--- a/av1/common/odintrin.c
+++ b/av1/common/odintrin.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2001-2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 /* clang-format off */
diff --git a/av1/common/odintrin.h b/av1/common/odintrin.h
index e1db0f4..21aab8d 100644
--- a/av1/common/odintrin.h
+++ b/av1/common/odintrin.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2001-2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 /* clang-format off */
diff --git a/av1/common/ppc/cfl_ppc.c b/av1/common/ppc/cfl_ppc.c
index 6f88768..b24d942 100644
--- a/av1/common/ppc/cfl_ppc.c
+++ b/av1/common/ppc/cfl_ppc.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <altivec.h>
diff --git a/av1/common/pred_common.c b/av1/common/pred_common.c
index da5e8ad..e23665e 100644
--- a/av1/common/pred_common.c
+++ b/av1/common/pred_common.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "av1/common/common.h"
@@ -15,6 +16,387 @@
 #include "av1/common/reconintra.h"
 #include "av1/common/seg_common.h"
 
+#if CONFIG_NEW_REF_SIGNALING
+// Comparison function to sort reference frames in ascending score order
+static int compare_score_data_asc(const void *a, const void *b) {
+  if (((RefScoreData *)a)->score == ((RefScoreData *)b)->score) {
+    return 0;
+  } else if (((const RefScoreData *)a)->score >
+             ((const RefScoreData *)b)->score) {
+    return 1;
+  } else {
+    return -1;
+  }
+}
+
+// Checks to see if a particular reference frame is already in the reference
+// frame map
+static int is_in_ref_score(RefScoreData *map, int disp_order, int score,
+                           int n_frames) {
+  for (int i = 0; i < n_frames; i++) {
+    if (disp_order == map[i].disp_order && score == map[i].score) return 1;
+  }
+  return 0;
+}
+
+static int get_unmapped_ref(RefScoreData *scores, int n_bufs) {
+  if (n_bufs < INTER_REFS_PER_FRAME) return INVALID_IDX;
+
+  int min_q = INT_MAX;
+  int max_q = INT_MIN;
+  for (int i = n_bufs - 1; i >= 0; i--) {
+    min_q = AOMMIN(min_q, scores[i].base_qindex);
+    max_q = AOMMAX(max_q, scores[i].base_qindex);
+  }
+  const int q_thresh = (max_q + min_q + 1) / 2;
+
+  int unmapped_past_idx = INVALID_IDX;
+  int unmapped_future_idx = INVALID_IDX;
+  int max_past_score = 0;
+  int max_future_score = 0;
+  int n_past = 0;
+  int n_future = 0;
+  for (int i = 0; i < n_bufs; i++) {
+    if (scores[i].base_qindex >= q_thresh) {
+      int dist = scores[i].distance;
+      if (dist > 0) {
+        if (dist > max_past_score) {
+          max_past_score = dist;
+          unmapped_past_idx = i;
+        }
+        n_past++;
+      } else if (dist < 0) {
+        if (-dist > max_future_score) {
+          max_future_score = -dist;
+          unmapped_future_idx = i;
+        }
+        n_future++;
+      }
+    }
+  }
+  if (n_past > n_future) return unmapped_past_idx;
+  if (n_past < n_future) return unmapped_future_idx;
+  if (n_past == n_future && n_past > 0)
+    return max_past_score >= max_future_score ? unmapped_past_idx
+                                              : unmapped_future_idx;
+
+  return INVALID_IDX;
+}
+
+void av1_get_past_future_cur_ref_lists(AV1_COMMON *cm, RefScoreData *scores) {
+  int n_future = 0;
+  int n_past = 0;
+  int n_cur = 0;
+  for (int i = 0; i < cm->ref_frames_info.n_total_refs; i++) {
+    if (scores[i].distance < 0) {
+      cm->ref_frames_info.future_refs[n_future] = i;
+      n_future++;
+    } else if (scores[i].distance > 0) {
+      cm->ref_frames_info.past_refs[n_past] = i;
+      n_past++;
+    } else {
+      cm->ref_frames_info.cur_refs[n_cur] = i;
+      n_cur++;
+    }
+  }
+  cm->ref_frames_info.n_past_refs = n_past;
+  cm->ref_frames_info.n_future_refs = n_future;
+  cm->ref_frames_info.n_cur_refs = n_cur;
+}
+
+#define JOINT_DIST_QINDEX_ORDERING 1
+#define DIST_WEIGHT_BITS 6
+void av1_get_ref_frames(AV1_COMMON *cm, int cur_frame_disp,
+                        RefFrameMapPair *ref_frame_map_pairs) {
+  RefScoreData scores[REF_FRAMES];
+  memset(scores, 0, REF_FRAMES * sizeof(*scores));
+  for (int i = 0; i < REF_FRAMES; i++) {
+    scores[i].score = INT_MAX;
+    cm->remapped_ref_idx[i] = INVALID_IDX;
+  }
+  int n_ranked = 0;
+  // Compute a score for each reference buffer
+  for (int i = 0; i < REF_FRAMES; i++) {
+    // Get reference frame buffer
+    RefFrameMapPair cur_ref = ref_frame_map_pairs[i];
+    if (cur_ref.disp_order == -1) continue;
+    const int ref_disp = cur_ref.disp_order;
+    const int ref_base_qindex = cur_ref.base_qindex;
+    const int disp_diff = cur_frame_disp - ref_disp;
+    const int score = (abs(disp_diff) << DIST_WEIGHT_BITS) + ref_base_qindex;
+    if (is_in_ref_score(scores, ref_disp, score, n_ranked)) continue;
+
+    scores[n_ranked].index = i;
+    scores[n_ranked].score = score;
+    scores[n_ranked].distance = disp_diff;
+    scores[n_ranked].disp_order = ref_disp;
+    scores[n_ranked].base_qindex = ref_base_qindex;
+    n_ranked++;
+  }
+  if (n_ranked > INTER_REFS_PER_FRAME) {
+    const int unmapped_idx = get_unmapped_ref(scores, n_ranked);
+    if (unmapped_idx != INVALID_IDX) scores[unmapped_idx].score = INT_MAX;
+  }
+
+  // Sort the references according to their score
+  qsort(scores, n_ranked, sizeof(scores[0]), compare_score_data_asc);
+
+  cm->ref_frames_info.n_total_refs =
+      AOMMIN(n_ranked, cm->seq_params.max_reference_frames);
+  for (int i = 0; i < cm->ref_frames_info.n_total_refs; i++) {
+    cm->remapped_ref_idx[i] = scores[i].index;
+    cm->ref_frames_info.ref_frame_distance[i] = scores[i].distance;
+  }
+
+  // Fill in RefFramesInfo struct according to computed mapping
+  av1_get_past_future_cur_ref_lists(cm, scores);
+
+  if (n_ranked > INTER_REFS_PER_FRAME)
+    cm->remapped_ref_idx[n_ranked - 1] = scores[n_ranked - 1].index;
+
+  // Fill any slots that are empty (should only happen for the first 7 frames)
+  for (int i = 0; i < REF_FRAMES; i++) {
+    if (cm->remapped_ref_idx[i] == INVALID_IDX) cm->remapped_ref_idx[i] = 0;
+  }
+}
+#else
+/*!\cond */
+// Struct to keep track of relevant reference frame data
+typedef struct {
+  int map_idx;
+  int disp_order;
+  int pyr_level;
+  int used;
+} RefBufMapData;
+/*!\endcond */
+
+// Comparison function to sort reference frames in ascending display order
+static int compare_map_idx_pair_asc(const void *a, const void *b) {
+  if (((RefBufMapData *)a)->disp_order == ((RefBufMapData *)b)->disp_order) {
+    return 0;
+  } else if (((const RefBufMapData *)a)->disp_order >
+             ((const RefBufMapData *)b)->disp_order) {
+    return 1;
+  } else {
+    return -1;
+  }
+}
+
+// Checks to see if a particular reference frame is already in the reference
+// frame map
+static int is_in_ref_map(RefBufMapData *map, int disp_order, int n_frames) {
+  for (int i = 0; i < n_frames; i++) {
+    if (disp_order == map[i].disp_order) return 1;
+  }
+  return 0;
+}
+
+// Add a reference buffer index to a named reference slot
+static void add_ref_to_slot(RefBufMapData *ref, int *const remapped_ref_idx,
+                            int frame) {
+  remapped_ref_idx[frame - LAST_FRAME] = ref->map_idx;
+  ref->used = 1;
+}
+
+// Threshold dictating when we are allowed to start considering
+// leaving lowest level frames unmapped
+#define LOW_LEVEL_FRAMES_TR 5
+
+// Find which reference buffer should be left out of the named mapping.
+// This is because there are 8 reference buffers and only 7 named slots.
+static void set_unmapped_ref(RefBufMapData *buffer_map, int n_bufs,
+                             int n_min_level_refs, int min_level,
+                             int cur_frame_disp) {
+  int max_dist = 0;
+  int unmapped_idx = -1;
+  if (n_bufs <= ALTREF_FRAME) return;
+  for (int i = 0; i < n_bufs; i++) {
+    if (buffer_map[i].used) continue;
+    if (buffer_map[i].pyr_level != min_level ||
+        n_min_level_refs >= LOW_LEVEL_FRAMES_TR) {
+      int dist = abs(cur_frame_disp - buffer_map[i].disp_order);
+      if (dist > max_dist) {
+        max_dist = dist;
+        unmapped_idx = i;
+      }
+    }
+  }
+  assert(unmapped_idx >= 0 && "Unmapped reference not found");
+  buffer_map[unmapped_idx].used = 1;
+}
+
+void av1_get_ref_frames(AV1_COMMON *const cm, int cur_frame_disp,
+                        RefFrameMapPair *ref_frame_map_pairs) {
+  int *const remapped_ref_idx = cm->remapped_ref_idx;
+
+  int buf_map_idx = 0;
+
+  // Initialize reference frame mappings
+  for (int i = 0; i < REF_FRAMES; ++i) remapped_ref_idx[i] = INVALID_IDX;
+
+  RefBufMapData buffer_map[REF_FRAMES];
+  int n_bufs = 0;
+  memset(buffer_map, 0, REF_FRAMES * sizeof(buffer_map[0]));
+  int min_level = INT_MAX;
+  int max_level = 0;
+
+  // Go through current reference buffers and store display order, pyr level,
+  // and map index.
+  for (int map_idx = 0; map_idx < REF_FRAMES; map_idx++) {
+    // Get reference frame buffer
+    RefFrameMapPair ref_pair = ref_frame_map_pairs[map_idx];
+    if (ref_pair.disp_order == -1) continue;
+    const int frame_order = ref_pair.disp_order;
+    // Avoid duplicates
+    if (is_in_ref_map(buffer_map, frame_order, n_bufs)) continue;
+    const int reference_frame_level = ref_pair.pyr_level;
+
+    // Keep track of the lowest and highest levels that currently exist
+    if (reference_frame_level < min_level) min_level = reference_frame_level;
+    if (reference_frame_level > max_level) max_level = reference_frame_level;
+
+    buffer_map[n_bufs].map_idx = map_idx;
+    buffer_map[n_bufs].disp_order = frame_order;
+    buffer_map[n_bufs].pyr_level = reference_frame_level;
+    buffer_map[n_bufs].used = 0;
+    n_bufs++;
+  }
+
+  // Sort frames in ascending display order
+  qsort(buffer_map, n_bufs, sizeof(buffer_map[0]), compare_map_idx_pair_asc);
+
+  int n_min_level_refs = 0;
+  int n_past_high_level = 0;
+  int closest_past_ref = -1;
+  int golden_idx = -1;
+  int altref_idx = -1;
+
+  // Find the GOLDEN_FRAME and BWDREF_FRAME.
+  // Also collect various stats about the reference frames for the remaining
+  // mappings
+  for (int i = n_bufs - 1; i >= 0; i--) {
+    if (buffer_map[i].pyr_level == min_level) {
+      // Keep track of the number of lowest level frames
+      n_min_level_refs++;
+      if (buffer_map[i].disp_order < cur_frame_disp && golden_idx == -1 &&
+          remapped_ref_idx[GOLDEN_FRAME - LAST_FRAME] == INVALID_IDX) {
+        // Save index for GOLDEN
+        golden_idx = i;
+      } else if (buffer_map[i].disp_order > cur_frame_disp &&
+                 altref_idx == -1 &&
+                 remapped_ref_idx[ALTREF_FRAME - LAST_FRAME] == INVALID_IDX) {
+        // Save index for ALTREF
+        altref_idx = i;
+      }
+    } else if (buffer_map[i].disp_order == cur_frame_disp) {
+      // Map the BWDREF_FRAME if this is the show_existing_frame
+      add_ref_to_slot(&buffer_map[i], remapped_ref_idx, BWDREF_FRAME);
+    }
+
+    // Keep track of the number of past frames that are not at the lowest level
+    if (buffer_map[i].disp_order < cur_frame_disp &&
+        buffer_map[i].pyr_level != min_level)
+      n_past_high_level++;
+
+    // Keep track of where the frames change from being past frames to future
+    // frames
+    if (buffer_map[i].disp_order < cur_frame_disp && closest_past_ref < 0)
+      closest_past_ref = i;
+  }
+
+  // Do not map GOLDEN and ALTREF based on their pyramid level if all reference
+  // frames have the same level
+  if (n_min_level_refs <= n_bufs) {
+    // Map the GOLDEN_FRAME
+    if (golden_idx > -1)
+      add_ref_to_slot(&buffer_map[golden_idx], remapped_ref_idx, GOLDEN_FRAME);
+    // Map the ALTREF_FRAME
+    if (altref_idx > -1)
+      add_ref_to_slot(&buffer_map[altref_idx], remapped_ref_idx, ALTREF_FRAME);
+  }
+
+  // Find the buffer to be excluded from the mapping
+  set_unmapped_ref(buffer_map, n_bufs, n_min_level_refs, min_level,
+                   cur_frame_disp);
+
+  // Place past frames in LAST_FRAME, LAST2_FRAME, and LAST3_FRAME
+  for (int frame = LAST_FRAME; frame < GOLDEN_FRAME; frame++) {
+    // Continue if the current ref slot is already full
+    if (remapped_ref_idx[frame - LAST_FRAME] != INVALID_IDX) continue;
+    // Find the next unmapped reference buffer
+    // in decreasing ouptut oreder relative to current picture
+    int next_buf_max = 0;
+    int next_disp_order = INT_MIN;
+    for (buf_map_idx = n_bufs - 1; buf_map_idx >= 0; buf_map_idx--) {
+      if (!buffer_map[buf_map_idx].used &&
+          buffer_map[buf_map_idx].disp_order < cur_frame_disp &&
+          buffer_map[buf_map_idx].disp_order > next_disp_order) {
+        next_disp_order = buffer_map[buf_map_idx].disp_order;
+        next_buf_max = buf_map_idx;
+      }
+    }
+    buf_map_idx = next_buf_max;
+    if (buf_map_idx < 0) break;
+    if (buffer_map[buf_map_idx].used) break;
+    add_ref_to_slot(&buffer_map[buf_map_idx], remapped_ref_idx, frame);
+  }
+
+  // Place future frames (if there are any) in BWDREF_FRAME and ALTREF2_FRAME
+  for (int frame = BWDREF_FRAME; frame < REF_FRAMES; frame++) {
+    // Continue if the current ref slot is already full
+    if (remapped_ref_idx[frame - LAST_FRAME] != INVALID_IDX) continue;
+    // Find the next unmapped reference buffer
+    // in increasing ouptut oreder relative to current picture
+    int next_buf_max = 0;
+    int next_disp_order = INT_MAX;
+    for (buf_map_idx = n_bufs - 1; buf_map_idx >= 0; buf_map_idx--) {
+      if (!buffer_map[buf_map_idx].used &&
+          buffer_map[buf_map_idx].disp_order > cur_frame_disp &&
+          buffer_map[buf_map_idx].disp_order < next_disp_order) {
+        next_disp_order = buffer_map[buf_map_idx].disp_order;
+        next_buf_max = buf_map_idx;
+      }
+    }
+    buf_map_idx = next_buf_max;
+    if (buf_map_idx < 0) break;
+    if (buffer_map[buf_map_idx].used) break;
+    add_ref_to_slot(&buffer_map[buf_map_idx], remapped_ref_idx, frame);
+  }
+
+  // Place remaining past frames
+  buf_map_idx = closest_past_ref;
+  for (int frame = LAST_FRAME; frame < REF_FRAMES; frame++) {
+    // Continue if the current ref slot is already full
+    if (remapped_ref_idx[frame - LAST_FRAME] != INVALID_IDX) continue;
+    // Find the next unmapped reference buffer
+    for (; buf_map_idx >= 0; buf_map_idx--) {
+      if (!buffer_map[buf_map_idx].used) break;
+    }
+    if (buf_map_idx < 0) break;
+    if (buffer_map[buf_map_idx].used) break;
+    add_ref_to_slot(&buffer_map[buf_map_idx], remapped_ref_idx, frame);
+  }
+
+  // Place remaining future frames
+  buf_map_idx = n_bufs - 1;
+  for (int frame = ALTREF_FRAME; frame >= LAST_FRAME; frame--) {
+    // Continue if the current ref slot is already full
+    if (remapped_ref_idx[frame - LAST_FRAME] != INVALID_IDX) continue;
+    // Find the next unmapped reference buffer
+    for (; buf_map_idx > closest_past_ref; buf_map_idx--) {
+      if (!buffer_map[buf_map_idx].used) break;
+    }
+    if (buf_map_idx < 0) break;
+    if (buffer_map[buf_map_idx].used) break;
+    add_ref_to_slot(&buffer_map[buf_map_idx], remapped_ref_idx, frame);
+  }
+
+  // Fill any slots that are empty (should only happen for the first 7 frames)
+  for (int i = 0; i < REF_FRAMES; ++i)
+    if (remapped_ref_idx[i] == INVALID_IDX) remapped_ref_idx[i] = 0;
+}
+#endif  // CONFIG_NEW_REF_SIGNALING
+
 // Returns a context number for the given MB prediction signal
 static InterpFilter get_ref_filter_type(const MB_MODE_INFO *ref_mbmi,
                                         const MACROBLOCKD *xd, int dir,
@@ -36,7 +418,7 @@
 int av1_get_pred_context_switchable_interp(const MACROBLOCKD *xd, int dir) {
   const MB_MODE_INFO *const mbmi = xd->mi[0];
   const int ctx_offset =
-      (mbmi->ref_frame[1] > INTRA_FRAME) * INTER_FILTER_COMP_OFFSET;
+      is_inter_ref_frame(mbmi->ref_frame[1]) * INTER_FILTER_COMP_OFFSET;
   assert(dir == 0 || dir == 1);
   const MV_REFERENCE_FRAME ref_frame = mbmi->ref_frame[0];
   // Note:
@@ -154,11 +536,18 @@
   }
 }
 
+#if CONFIG_NEW_REF_SIGNALING
+#define IS_BACKWARD_REF_FRAME(ref_frame) \
+  (get_dir_rank(cm, ref_frame, NULL) == 1)
+#else
 #define CHECK_BACKWARD_REFS(ref_frame) \
   (((ref_frame) >= BWDREF_FRAME) && ((ref_frame) <= ALTREF_FRAME))
 #define IS_BACKWARD_REF_FRAME(ref_frame) CHECK_BACKWARD_REFS(ref_frame)
+#endif  // CONFIG_NEW_REF_SIGNALING
 
-int av1_get_reference_mode_context(const MACROBLOCKD *xd) {
+int av1_get_reference_mode_context(const AV1_COMMON *cm,
+                                   const MACROBLOCKD *xd) {
+  (void)cm;
   int ctx;
   const MB_MODE_INFO *const above_mbmi = xd->above_mbmi;
   const MB_MODE_INFO *const left_mbmi = xd->left_mbmi;
@@ -208,6 +597,26 @@
   return ctx;
 }
 
+#if CONFIG_NEW_REF_SIGNALING
+int av1_get_ref_pred_context_nrs(const MACROBLOCKD *xd, MV_REFERENCE_FRAME ref,
+                                 int n_total_refs) {
+  assert((ref + 1) < n_total_refs);
+  const uint8_t *const ref_counts = &xd->neighbors_ref_counts[0];
+  const int this_ref_count = ref_counts[ref];
+  int next_refs_count = 0;
+
+  for (int i = ref + 1; i < n_total_refs; i++) {
+    next_refs_count += ref_counts[i];
+  }
+
+  const int pred_context = (this_ref_count == next_refs_count)
+                               ? 1
+                               : ((this_ref_count < next_refs_count) ? 0 : 2);
+
+  assert(pred_context >= 0 && pred_context < REF_CONTEXTS);
+  return pred_context;
+}
+#else
 int av1_get_comp_reference_type_context(const MACROBLOCKD *xd) {
   int pred_context;
   const MB_MODE_INFO *const above_mbmi = xd->above_mbmi;
@@ -531,3 +940,4 @@
 int av1_get_pred_context_single_ref_p6(const MACROBLOCKD *xd) {
   return get_pred_context_brf_or_arf2(xd);
 }
+#endif  // CONFIG_NEW_REF_SIGNALING
diff --git a/av1/common/pred_common.h b/av1/common/pred_common.h
index 593fb50..99b62d0 100644
--- a/av1/common/pred_common.h
+++ b/av1/common/pred_common.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_COMMON_PRED_COMMON_H_
@@ -21,6 +22,160 @@
 extern "C" {
 #endif
 
+typedef struct {
+  int pyr_level;
+  int disp_order;
+#if CONFIG_NEW_REF_SIGNALING
+  int base_qindex;
+#endif  // CONFIG_NEW_REF_SIGNALING
+} RefFrameMapPair;
+
+static INLINE void init_ref_map_pair(AV1_COMMON *cm,
+                                     RefFrameMapPair *ref_frame_map_pairs,
+                                     int is_key) {
+  if (is_key) {
+    memset(ref_frame_map_pairs, -1, sizeof(*ref_frame_map_pairs) * REF_FRAMES);
+    return;
+  }
+  memset(ref_frame_map_pairs, 0, sizeof(*ref_frame_map_pairs) * REF_FRAMES);
+  for (int map_idx = 0; map_idx < REF_FRAMES; map_idx++) {
+    // Get reference frame buffer
+    const RefCntBuffer *const buf = cm->ref_frame_map[map_idx];
+    if (ref_frame_map_pairs[map_idx].disp_order == -1) continue;
+    if (buf == NULL) {
+      ref_frame_map_pairs[map_idx].disp_order = -1;
+      ref_frame_map_pairs[map_idx].pyr_level = -1;
+#if CONFIG_NEW_REF_SIGNALING
+      ref_frame_map_pairs[map_idx].base_qindex = -1;
+#endif  // CONFIG_NEW_REF_SIGNALING
+      continue;
+    } else if (buf->ref_count > 1) {
+      // Once the keyframe is coded, the slots in ref_frame_map will all
+      // point to the same frame. In that case, all subsequent pointers
+      // matching the current are considered "free" slots. This will find
+      // the next occurance of the current pointer if ref_count indicates
+      // there are multiple instances of it and mark it as free.
+      for (int idx2 = map_idx + 1; idx2 < REF_FRAMES; ++idx2) {
+        const RefCntBuffer *const buf2 = cm->ref_frame_map[idx2];
+        if (buf2 == buf) {
+          ref_frame_map_pairs[idx2].disp_order = -1;
+          ref_frame_map_pairs[idx2].pyr_level = -1;
+#if CONFIG_NEW_REF_SIGNALING
+          ref_frame_map_pairs[idx2].base_qindex = -1;
+#endif  // CONFIG_NEW_REF_SIGNALING
+        }
+      }
+    }
+    ref_frame_map_pairs[map_idx].disp_order = (int)buf->display_order_hint;
+    ref_frame_map_pairs[map_idx].pyr_level = buf->pyramid_level;
+#if CONFIG_NEW_REF_SIGNALING
+    ref_frame_map_pairs[map_idx].base_qindex = buf->base_qindex;
+#endif  // CONFIG_NEW_REF_SIGNALING
+  }
+}
+
+#if CONFIG_NEW_REF_SIGNALING
+/*!\cond */
+typedef struct {
+  int score;
+  int index;
+  int distance;
+  int disp_order;
+  int base_qindex;
+} RefScoreData;
+/*!\endcond */
+
+void av1_get_ref_frames(AV1_COMMON *cm, int cur_frame_disp,
+                        RefFrameMapPair *ref_frame_map_pairs);
+
+// Find the reference that is furthest in the future
+static INLINE int get_furthest_future_ref_index(const AV1_COMMON *const cm) {
+  int index = INVALID_IDX;
+  int ref_disp_order = -1;
+  for (int i = 0; i < cm->ref_frames_info.n_future_refs; i++) {
+    const int ref = cm->ref_frames_info.future_refs[i];
+    const RefCntBuffer *const buf = get_ref_frame_buf(cm, ref);
+    if (buf == NULL) continue;
+    if ((int)buf->display_order_hint > ref_disp_order) {
+      index = ref;
+      ref_disp_order = (int)buf->display_order_hint;
+    }
+  }
+  return index;
+}
+
+static INLINE int get_closest_ref_index(const AV1_COMMON *const cm) {
+  int index = INVALID_IDX;
+  int best_dist = INT_MAX;
+  for (int ref = 0; ref < cm->ref_frames_info.n_total_refs; ref++) {
+    const int dist = abs(cm->ref_frames_info.ref_frame_distance[ref]);
+    if (dist < best_dist) {
+      index = ref;
+      best_dist = dist;
+    }
+  }
+  return index;
+}
+
+static INLINE int get_closest_past_ref_index(const AV1_COMMON *const cm) {
+  int index = INVALID_IDX;
+  int best_dist = INT_MAX;
+  for (int i = 0; i < cm->ref_frames_info.n_past_refs; i++) {
+    const int ref = cm->ref_frames_info.past_refs[i];
+    const int dist = cm->ref_frames_info.ref_frame_distance[ref];
+    if (dist < best_dist) {
+      index = ref;
+      best_dist = dist;
+    }
+  }
+  return index;
+}
+
+static INLINE int get_closest_pastcur_ref_index(const AV1_COMMON *const cm) {
+  if (cm->ref_frames_info.n_cur_refs > 0)
+    return cm->ref_frames_info.cur_refs[0];
+  return get_closest_past_ref_index(cm);
+}
+
+static INLINE int get_best_past_ref_index(const AV1_COMMON *const cm) {
+  return cm->ref_frames_info.past_refs[0];
+}
+
+// Gets directional i.e. past/future ref rank from overall rank
+// in dir_refrank[0]/[1] respectively. Returns 0 if found in past
+// list, 1 if found in future list, -1 if not found in either (error).
+// Note dir_refrank can be NULL, in which case only the direction
+// is returned, the ranks are not output.
+static INLINE int get_dir_rank(const AV1_COMMON *const cm, int refrank,
+                               int *dir_refrank) {
+  if (!is_inter_ref_frame(refrank)) return -1;
+  assert(refrank < cm->ref_frames_info.n_total_refs);
+  if (dir_refrank) {
+    dir_refrank[0] = -1;
+    dir_refrank[1] = -1;
+  }
+  for (int i = 0; i < cm->ref_frames_info.n_past_refs; ++i) {
+    if (cm->ref_frames_info.past_refs[i] == refrank) {
+      if (dir_refrank) dir_refrank[0] = i;
+      return 0;
+    }
+  }
+  for (int i = 0; i < cm->ref_frames_info.n_future_refs; ++i) {
+    if (cm->ref_frames_info.future_refs[i] == refrank) {
+      if (dir_refrank) dir_refrank[1] = i;
+      return 1;
+    }
+  }
+  // If refrank has the same distance as a reference return 0 (past)
+  // but the dir_refrank[0] is -1
+  if (cm->ref_frames_info.cur_refs[0] == refrank) return 0;
+  return -1;
+}
+#else
+void av1_get_ref_frames(AV1_COMMON *const cm, int cur_frame_disp,
+                        RefFrameMapPair *ref_frame_map_pairs);
+#endif  // CONFIG_NEW_REF_SIGNALING
+
 static INLINE int get_segment_id(const CommonModeInfoParams *const mi_params,
                                  const uint8_t *segment_ids, BLOCK_SIZE bsize,
                                  int mi_row, int mi_col) {
@@ -96,10 +251,13 @@
   return above_sip + left_sip;
 }
 
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-static INLINE int get_comp_index_context(const AV1_COMMON *cm,
-                                         const MACROBLOCKD *xd) {
+static INLINE int get_comp_group_idx_context(const AV1_COMMON *cm,
+                                             const MACROBLOCKD *xd) {
+  (void)cm;
   MB_MODE_INFO *mbmi = xd->mi[0];
+#if CONFIG_NEW_REF_SIGNALING
+  MV_REFERENCE_FRAME altref_frame = get_furthest_future_ref_index(cm);
+#endif  // CONFIG_NEW_REF_SIGNALING
   const RefCntBuffer *const bck_buf = get_ref_frame_buf(cm, mbmi->ref_frame[0]);
   const RefCntBuffer *const fwd_buf = get_ref_frame_buf(cm, mbmi->ref_frame[1]);
   int bck_frame_index = 0, fwd_frame_index = 0;
@@ -112,92 +270,34 @@
                                   fwd_frame_index, cur_frame_index));
   int bck = abs(get_relative_dist(&cm->seq_params.order_hint_info,
                                   cur_frame_index, bck_frame_index));
-
-  const MB_MODE_INFO *const above_mi = xd->above_mbmi;
-  const MB_MODE_INFO *const left_mi = xd->left_mbmi;
-
-  int above_ctx = 0, left_ctx = 0;
   const int offset = (fwd == bck);
 
-  if (above_mi != NULL) {
-    if (has_second_ref(above_mi))
-      above_ctx = above_mi->compound_idx;
-    else if (above_mi->ref_frame[0] == ALTREF_FRAME)
-      above_ctx = 1;
-  }
-
-  if (left_mi != NULL) {
-    if (has_second_ref(left_mi))
-      left_ctx = left_mi->compound_idx;
-    else if (left_mi->ref_frame[0] == ALTREF_FRAME)
-      left_ctx = 1;
-  }
-
-  return above_ctx + left_ctx + 3 * offset;
-}
-
-static INLINE int get_comp_group_idx_context(const AV1_COMMON *cm,
-                                             const MACROBLOCKD *xd) {
-  (void)cm;
   const MB_MODE_INFO *const above_mi = xd->above_mbmi;
   const MB_MODE_INFO *const left_mi = xd->left_mbmi;
   int above_ctx = 0, left_ctx = 0;
 
   if (above_mi) {
-    if (has_second_ref(above_mi))
-      above_ctx = above_mi->comp_group_idx;
-    else if (above_mi->ref_frame[0] == ALTREF_FRAME)
-      above_ctx = 3;
-  }
-  if (left_mi) {
-    if (has_second_ref(left_mi))
-      left_ctx = left_mi->comp_group_idx;
-    else if (left_mi->ref_frame[0] == ALTREF_FRAME)
-      left_ctx = 3;
-  }
-
-  return AOMMIN(5, above_ctx + left_ctx);
-}
+    if (has_second_ref(above_mi)) above_ctx = above_mi->comp_group_idx;
+#if CONFIG_NEW_REF_SIGNALING
+    else if (above_mi->ref_frame[0] == altref_frame)
 #else
-static INLINE int get_comp_group_idx_context(const AV1_COMMON *cm,
-                                             const MACROBLOCKD *xd) {
-  (void)cm;
-  MB_MODE_INFO *mbmi = xd->mi[0];
-  const RefCntBuffer *const bck_buf = get_ref_frame_buf(cm, mbmi->ref_frame[0]);
-  const RefCntBuffer *const fwd_buf = get_ref_frame_buf(cm, mbmi->ref_frame[1]);
-  int bck_frame_index = 0, fwd_frame_index = 0;
-  int cur_frame_index = cm->cur_frame->order_hint;
-
-  if (bck_buf != NULL) bck_frame_index = bck_buf->order_hint;
-  if (fwd_buf != NULL) fwd_frame_index = fwd_buf->order_hint;
-
-  int fwd = abs(get_relative_dist(&cm->seq_params.order_hint_info,
-                                  fwd_frame_index, cur_frame_index));
-  int bck = abs(get_relative_dist(&cm->seq_params.order_hint_info,
-                                  cur_frame_index, bck_frame_index));
-  const int offset = (fwd == bck);
-
-  const MB_MODE_INFO *const above_mi = xd->above_mbmi;
-  const MB_MODE_INFO *const left_mi = xd->left_mbmi;
-  int above_ctx = 0, left_ctx = 0;
-
-  if (above_mi) {
-    if (has_second_ref(above_mi))
-      above_ctx = above_mi->comp_group_idx;
     else if (above_mi->ref_frame[0] == ALTREF_FRAME)
+#endif  // CONFIG_NEW_REF_SIGNALING
       above_ctx = 2;
   }
   if (left_mi) {
-    if (has_second_ref(left_mi))
-      left_ctx = left_mi->comp_group_idx;
+    if (has_second_ref(left_mi)) left_ctx = left_mi->comp_group_idx;
+#if CONFIG_NEW_REF_SIGNALING
+    else if (left_mi->ref_frame[0] == altref_frame)
+#else
     else if (left_mi->ref_frame[0] == ALTREF_FRAME)
+#endif  // CONFIG_NEW_REF_SIGNALING
       left_ctx = 2;
   }
   const int ctxmap[3 * 3] = { 0, 1, 2, 1, 3, 4, 2, 4, 5 };
 
   return ctxmap[3 * above_ctx + left_ctx] + offset * 6;
 }
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
 
 static INLINE aom_cdf_prob *av1_get_pred_cdf_seg_id(
     struct segmentation_probs *segp, const MACROBLOCKD *xd) {
@@ -252,16 +352,50 @@
 
 int av1_get_intra_inter_context(const MACROBLOCKD *xd);
 
-int av1_get_reference_mode_context(const MACROBLOCKD *xd);
+int av1_get_reference_mode_context(const AV1_COMMON *cm, const MACROBLOCKD *xd);
 
-static INLINE aom_cdf_prob *av1_get_reference_mode_cdf(const MACROBLOCKD *xd) {
-  return xd->tile_ctx->comp_inter_cdf[av1_get_reference_mode_context(xd)];
+static INLINE aom_cdf_prob *av1_get_reference_mode_cdf(const AV1_COMMON *cm,
+                                                       const MACROBLOCKD *xd) {
+  return xd->tile_ctx->comp_inter_cdf[av1_get_reference_mode_context(cm, xd)];
 }
 
 static INLINE aom_cdf_prob *av1_get_skip_txfm_cdf(const MACROBLOCKD *xd) {
   return xd->tile_ctx->skip_txfm_cdfs[av1_get_skip_txfm_context(xd)];
 }
 
+#if CONFIG_NEW_REF_SIGNALING
+// == Single contexts ==
+int av1_get_ref_pred_context_nrs(const MACROBLOCKD *xd, MV_REFERENCE_FRAME ref,
+                                 int n_total_refs);
+
+static INLINE aom_cdf_prob *av1_get_pred_cdf_single_ref_nrs(
+    const MACROBLOCKD *xd, MV_REFERENCE_FRAME ref, int n_total_refs) {
+  assert((ref + 1) < n_total_refs);
+  return xd->tile_ctx->single_ref_cdf[av1_get_ref_pred_context_nrs(
+      xd, ref, n_total_refs)][ref];
+}
+
+// == Compound contexts ==
+static INLINE int av1_get_compound_ref_bit_type(
+    int n_bits, const RefFramesInfo *const ref_frames_info, int i, int j) {
+  const int bit_type =
+      (n_bits == 0 ? 0
+                   : 1 + ((ref_frames_info->ref_frame_distance[i] >= 0) ^
+                          (ref_frames_info->ref_frame_distance[j] >= 0)));
+  return bit_type;
+}
+
+static INLINE aom_cdf_prob *av1_get_pred_cdf_compound_ref_nrs(
+    const MACROBLOCKD *xd, MV_REFERENCE_FRAME ref, int n_bits, int bit_type,
+    int n_total_refs) {
+  assert((ref + 1) < n_total_refs);
+  assert(n_bits < 2);
+  assert(ref - n_bits < n_total_refs - 2);
+  assert(bit_type < COMPREF_BIT_TYPES);
+  return xd->tile_ctx->comp_ref_cdf[av1_get_ref_pred_context_nrs(
+      xd, ref, n_total_refs)][bit_type][ref - n_bits];
+}
+#else
 int av1_get_comp_reference_type_context(const MACROBLOCKD *xd);
 
 // == Uni-directional contexts ==
@@ -381,6 +515,7 @@
   return xd->tile_ctx
       ->single_ref_cdf[av1_get_pred_context_single_ref_p6(xd)][5];
 }
+#endif  // CONFIG_NEW_REF_SIGNALING
 
 // Returns a context number for the given MB prediction signal
 // The mode info data structure has a one element border above and to the
diff --git a/av1/common/quant_common.c b/av1/common/quant_common.c
index 9318e53..124da6b 100644
--- a/av1/common/quant_common.c
+++ b/av1/common/quant_common.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "av1/common/av1_common_int.h"
@@ -316,9 +317,9 @@
     q_clamped = 0;
   else
     q_clamped = clamp(qindex + base_dc_delta_q + delta, 1,
-                      bit_depth == AOM_BITS_8
-                          ? MAXQ_8_BITS
-                          : bit_depth == AOM_BITS_10 ? MAXQ_10_BITS : MAXQ);
+                      bit_depth == AOM_BITS_8    ? MAXQ_8_BITS
+                      : bit_depth == AOM_BITS_10 ? MAXQ_10_BITS
+                                                 : MAXQ);
 
   if (q_clamped == 0) return (int32_t)ac_qlookup_QTX[q_clamped];
 
@@ -390,9 +391,9 @@
     q_clamped = 0;
   else
     q_clamped = clamp(qindex + delta, 1,
-                      bit_depth == AOM_BITS_8
-                          ? MAXQ_8_BITS
-                          : bit_depth == AOM_BITS_10 ? MAXQ_10_BITS : MAXQ);
+                      bit_depth == AOM_BITS_8    ? MAXQ_8_BITS
+                      : bit_depth == AOM_BITS_10 ? MAXQ_10_BITS
+                                                 : MAXQ);
 
   if (q_clamped == 0) return (int32_t)ac_qlookup_QTX[q_clamped];
 
@@ -469,9 +470,9 @@
     const int seg_qindex = base_qindex + data;
 #if CONFIG_EXTQUANT
     return clamp(seg_qindex, 0,
-                 bit_depth == AOM_BITS_8
-                     ? MAXQ_8_BITS
-                     : bit_depth == AOM_BITS_10 ? MAXQ_10_BITS : MAXQ);
+                 bit_depth == AOM_BITS_8    ? MAXQ_8_BITS
+                 : bit_depth == AOM_BITS_10 ? MAXQ_10_BITS
+                                            : MAXQ);
 #else
     return clamp(seg_qindex, 0, MAXQ);
 #endif
diff --git a/av1/common/quant_common.h b/av1/common/quant_common.h
index 5cde276..d3aa16a 100644
--- a/av1/common/quant_common.h
+++ b/av1/common/quant_common.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_COMMON_QUANT_COMMON_H_
@@ -85,10 +86,9 @@
 ) {
 #if CONFIG_EXTQUANT
   return first + (qindex * (last + 1 - first)) /
-                     (bit_depth == AOM_BITS_8
-                          ? QINDEX_RANGE_8_BITS
-                          : bit_depth == AOM_BITS_10 ? QINDEX_RANGE_10_BITS
-                                                     : QINDEX_RANGE);
+                     (bit_depth == AOM_BITS_8    ? QINDEX_RANGE_8_BITS
+                      : bit_depth == AOM_BITS_10 ? QINDEX_RANGE_10_BITS
+                                                 : QINDEX_RANGE);
 #else
   return first + (qindex * (last + 1 - first)) / QINDEX_RANGE;
 #endif
diff --git a/av1/common/reconinter.c b/av1/common/reconinter.c
index b03024e..b6fa239 100644
--- a/av1/common/reconinter.c
+++ b/av1/common/reconinter.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
@@ -70,6 +71,10 @@
 ) {
   inter_pred_params->block_width = block_width;
   inter_pred_params->block_height = block_height;
+#if CONFIG_OPTFLOW_REFINEMENT
+  inter_pred_params->orig_block_width = block_width;
+  inter_pred_params->orig_block_height = block_height;
+#endif  // CONFIG_OPTFLOW_REFINEMENT
   inter_pred_params->pix_row = pix_row;
   inter_pred_params->pix_col = pix_col;
   inter_pred_params->subsampling_x = subsampling_x;
@@ -624,6 +629,967 @@
   }
 }
 
+#if CONFIG_OPTFLOW_REFINEMENT
+// Restrict MV delta to 1 or 2 pixels. This restriction would reduce complexity
+// in hardware.
+#define OPFL_CLAMP_MV_DELTA 1
+#define OPFL_MV_DELTA_LIMIT (1 << MV_REFINE_PREC_BITS)
+
+static INLINE int opfl_get_subblock_size(int bw, int bh, int plane) {
+  return (plane || (bh <= 8 && bw <= 8)) ? OF_MIN_BSIZE : OF_BSIZE;
+}
+
+void av1_opfl_build_inter_predictor(
+    const AV1_COMMON *cm, MACROBLOCKD *xd, int plane, const MB_MODE_INFO *mi,
+    int bw, int bh, int mi_x, int mi_y, uint8_t **mc_buf,
+    InterPredParams *inter_pred_params,
+    CalcSubpelParamsFunc calc_subpel_params_func, int ref, uint8_t *pred_dst) {
+  assert(cm->seq_params.order_hint_info.enable_order_hint);
+#if CONFIG_SDP
+  const int is_intrabc = is_intrabc_block(mi, xd->tree_type);
+#else
+  const int is_intrabc = is_intrabc_block(mi);
+#endif  // CONFIG_SDP
+
+  // Do references one at a time
+  const int is_compound = 0;
+  struct macroblockd_plane *const pd = &xd->plane[plane];
+  struct buf_2d *const dst_buf = &pd->dst;
+
+  const WarpedMotionParams *const wm = &xd->global_motion[mi->ref_frame[ref]];
+  const WarpTypesAllowed warp_types = { is_global_mv_block(mi, wm->wmtype),
+                                        mi->motion_mode == WARPED_CAUSAL };
+  const struct scale_factors *const sf =
+      is_intrabc ? &cm->sf_identity : xd->block_ref_scale_factors[ref];
+
+#if CONFIG_SDP
+  const BLOCK_SIZE bsize = mi->sb_type[PLANE_TYPE_Y];
+#else
+  const BLOCK_SIZE bsize = mi->sb_type;
+#endif
+  const int ss_x = pd->subsampling_x;
+  const int ss_y = pd->subsampling_y;
+  const int row_start = (block_size_high[bsize] == 4) && ss_y ? -1 : 0;
+  const int col_start = (block_size_wide[bsize] == 4) && ss_x ? -1 : 0;
+  const int pre_x = (mi_x + MI_SIZE * col_start) >> ss_x;
+  const int pre_y = (mi_y + MI_SIZE * row_start) >> ss_y;
+
+  struct buf_2d *const pre_buf = is_intrabc ? dst_buf : &pd->pre[ref];
+
+  av1_init_inter_params(inter_pred_params, bw, bh, pre_y, pre_x,
+                        pd->subsampling_x, pd->subsampling_y, xd->bd,
+#if CONFIG_SDP
+                        is_cur_buf_hbd(xd), mi->use_intrabc[0], sf, pre_buf,
+#else
+                        is_cur_buf_hbd(xd), mi->use_intrabc, sf, pre_buf,
+#endif  // CONFIG_SDP
+#if CONFIG_REMOVE_DUAL_FILTER
+                        mi->interp_fltr);
+#else
+                        mi->interp_filters);
+#endif  // CONFIG_REMOVE_DUAL_FILTER
+
+  inter_pred_params->conv_params = get_conv_params_no_round(
+      0, plane, xd->tmp_conv_dst, MAX_SB_SIZE, is_compound, xd->bd);
+
+  av1_init_warp_params(inter_pred_params, &warp_types, ref, xd, mi);
+  if (inter_pred_params->mode == WARP_PRED) return;
+
+  assert(mi->interinter_comp.type == COMPOUND_AVERAGE);
+  av1_build_one_inter_predictor(pred_dst, bw, &mi->mv[ref].as_mv,
+                                inter_pred_params, xd, mi_x, mi_y, ref, mc_buf,
+                                calc_subpel_params_func);
+}
+
+// Note: grad_prec_bits param returned correspond to the precision
+// of the gradient information in bits assuming gradient
+// computed at unit pixel step normalization is 0 scale.
+// Negative values indicate gradient returned at reduced precision, and
+// positive values indicate gradient returned at higher precision.
+void av1_compute_subpel_gradients_mc_highbd(
+    MACROBLOCKD *xd, const MB_MODE_INFO *mi, int bw, int bh, int mi_x, int mi_y,
+    uint8_t **mc_buf, InterPredParams *inter_pred_params,
+    CalcSubpelParamsFunc calc_subpel_params_func, int ref, int *grad_prec_bits,
+    int16_t *x_grad, int16_t *y_grad) {
+  *grad_prec_bits = 3 - SUBPEL_GRAD_DELTA_BITS - 2;
+
+  // Original predictor
+  const MV mv_orig = mi->mv[ref].as_mv;
+  MV mv_modified = mv_orig;
+  uint16_t tmp_buf1[MAX_SB_SIZE * MAX_SB_SIZE] = { 0 };
+  uint16_t tmp_buf2[MAX_SB_SIZE * MAX_SB_SIZE] = { 0 };
+  uint8_t *tmp_buf1_8 = CONVERT_TO_BYTEPTR(tmp_buf1);
+  uint8_t *tmp_buf2_8 = CONVERT_TO_BYTEPTR(tmp_buf2);
+  // X gradient
+  // Get predictor to the left
+  mv_modified.col = mv_orig.col - (1 << (3 - SUBPEL_GRAD_DELTA_BITS));
+  mv_modified.row = mv_orig.row;
+  av1_build_one_inter_predictor(tmp_buf1_8, bw, &mv_modified, inter_pred_params,
+                                xd, mi_x, mi_y, ref, mc_buf,
+                                calc_subpel_params_func);
+  // Get predictor to the right
+  mv_modified.col = mv_orig.col + (1 << (3 - SUBPEL_GRAD_DELTA_BITS));
+  mv_modified.row = mv_orig.row;
+  av1_build_one_inter_predictor(tmp_buf2_8, bw, &mv_modified, inter_pred_params,
+                                xd, mi_x, mi_y, ref, mc_buf,
+                                calc_subpel_params_func);
+  // Compute difference.
+  // Note since the deltas are at +2^g/8 and -2^g/8 subpel locations
+  // (g = 3 - SUBPEL_GRAD_DELTA_BITS), the actual unit pel gradient is
+  // 4/2^g = 2^(2-g) times the difference. Therefore the gradient returned
+  // is at reduced precision by 2-g bits. That explains the grad_prec_bits
+  // return value of g-2 at the end of this function.
+
+  aom_highbd_subtract_block(bh, bw, x_grad, bw, CONVERT_TO_BYTEPTR(tmp_buf2),
+                            bw, CONVERT_TO_BYTEPTR(tmp_buf1), bw, xd->bd);
+
+  // Y gradient
+  // Get predictor below
+  mv_modified.col = mv_orig.col;
+  mv_modified.row = mv_orig.row - (1 << (3 - SUBPEL_GRAD_DELTA_BITS));
+  av1_build_one_inter_predictor(tmp_buf1_8, bw, &mv_modified, inter_pred_params,
+                                xd, mi_x, mi_y, ref, mc_buf,
+                                calc_subpel_params_func);
+  // Get predictor above
+  mv_modified.col = mv_orig.col;
+  mv_modified.row = mv_orig.row + (1 << (3 - SUBPEL_GRAD_DELTA_BITS));
+  av1_build_one_inter_predictor(tmp_buf2_8, bw, &mv_modified, inter_pred_params,
+                                xd, mi_x, mi_y, ref, mc_buf,
+                                calc_subpel_params_func);
+  // Compute difference.
+  // Note since the deltas are at +2^g/8 and -2^g/8 subpel locations
+  // (g = 3 - SUBPEL_GRAD_DELTA_BITS), the actual unit pel gradient is
+  // 4/2^g = 2^(2-g) times the difference. Therefore the gradient returned
+  // is at reduced precision by 2-g bits. That explains the grad_prec_bits
+  // return value of g-2 at the end of this function.
+
+  aom_highbd_subtract_block(bh, bw, y_grad, bw, CONVERT_TO_BYTEPTR(tmp_buf2),
+                            bw, CONVERT_TO_BYTEPTR(tmp_buf1), bw, xd->bd);
+}
+
+// Note: grad_prec_bits param returned correspond to the precision
+// of the gradient information in bits assuming gradient
+// computed at unit pixel step normalization is 0 scale.
+// Negative values indicate gradient returned at reduced precision, and
+// positive values indicate gradient returned at higher precision.
+void av1_compute_subpel_gradients_mc_lowbd(
+    MACROBLOCKD *xd, const MB_MODE_INFO *mi, int bw, int bh, int mi_x, int mi_y,
+    uint8_t **mc_buf, InterPredParams *inter_pred_params,
+    CalcSubpelParamsFunc calc_subpel_params_func, int ref, int *grad_prec_bits,
+    int16_t *x_grad, int16_t *y_grad) {
+  *grad_prec_bits = 3 - SUBPEL_GRAD_DELTA_BITS - 2;
+
+  // Original predictor
+  const MV mv_orig = mi->mv[ref].as_mv;
+  MV mv_modified = mv_orig;
+  uint8_t tmp_buf1[MAX_SB_SIZE * MAX_SB_SIZE] = { 0 };
+  uint8_t tmp_buf2[MAX_SB_SIZE * MAX_SB_SIZE] = { 0 };
+  // X gradient
+  // Get predictor to the left
+  mv_modified.col = mv_orig.col - (1 << (3 - SUBPEL_GRAD_DELTA_BITS));
+  mv_modified.row = mv_orig.row;
+  av1_build_one_inter_predictor(tmp_buf1, bw, &mv_modified, inter_pred_params,
+                                xd, mi_x, mi_y, ref, mc_buf,
+                                calc_subpel_params_func);
+  // Get predictor to the right
+  mv_modified.col = mv_orig.col + (1 << (3 - SUBPEL_GRAD_DELTA_BITS));
+  mv_modified.row = mv_orig.row;
+  av1_build_one_inter_predictor(tmp_buf2, bw, &mv_modified, inter_pred_params,
+                                xd, mi_x, mi_y, ref, mc_buf,
+                                calc_subpel_params_func);
+  // Compute difference.
+  // Note since the deltas are at +2^g/8 and -2^g/8 subpel locations
+  // (g = 3 - SUBPEL_GRAD_DELTA_BITS), the actual unit pel gradient is
+  // 4/2^g = 2^(2-g) times the difference. Therefore the gradient returned
+  // is at reduced precision by 2-g bits. That explains the grad_prec_bits
+  // return value of g-2 at the end of this function.
+
+  aom_subtract_block(bh, bw, x_grad, bw, tmp_buf2, bw, tmp_buf1, bw);
+
+  // Y gradient
+  // Get predictor below
+  mv_modified.col = mv_orig.col;
+  mv_modified.row = mv_orig.row - (1 << (3 - SUBPEL_GRAD_DELTA_BITS));
+  av1_build_one_inter_predictor(tmp_buf1, bw, &mv_modified, inter_pred_params,
+                                xd, mi_x, mi_y, ref, mc_buf,
+                                calc_subpel_params_func);
+  // Get predictor above
+  mv_modified.col = mv_orig.col;
+  mv_modified.row = mv_orig.row + (1 << (3 - SUBPEL_GRAD_DELTA_BITS));
+  av1_build_one_inter_predictor(tmp_buf2, bw, &mv_modified, inter_pred_params,
+                                xd, mi_x, mi_y, ref, mc_buf,
+                                calc_subpel_params_func);
+  // Compute difference.
+  // Note since the deltas are at +2^g/8 and -2^g/8 subpel locations
+  // (g = 3 - SUBPEL_GRAD_DELTA_BITS), the actual unit pel gradient is
+  // 4/2^g = 2^(2-g) times the difference. Therefore the gradient returned
+  // is at reduced precision by 2-g bits. That explains the grad_prec_bits
+  // return value of g-2 at the end of this function.
+
+  aom_subtract_block(bh, bw, y_grad, bw, tmp_buf2, bw, tmp_buf1, bw);
+}
+
+void av1_bicubic_grad_interpolation_c(const int16_t *pred_src, int16_t *x_grad,
+                                      int16_t *y_grad, const int bw,
+                                      const int bh) {
+#if OPFL_BICUBIC_GRAD
+  for (int i = 0; i < bh; i++) {
+    for (int j = 0; j < bw; j++) {
+      int id_prev, id_prev2, id_next, id_next2, is_boundary;
+      int32_t temp = 0;
+#if OPFL_DOWNSAMP_QUINCUNX
+      if ((i + j) % 2 == 1) continue;
+#endif
+      // Subtract interpolated pixel at (i, j+delta) by the one at (i, j-delta)
+      id_prev = AOMMAX(j - 1, 0);
+      id_prev2 = AOMMAX(j - 2, 0);
+      id_next = AOMMIN(j + 1, bw - 1);
+      id_next2 = AOMMIN(j + 2, bw - 1);
+      is_boundary = (j + 1 > bw - 1 || j - 1 < 0);
+      temp = coeffs_bicubic[SUBPEL_GRAD_DELTA_BITS][0][is_boundary] *
+                 (int32_t)(pred_src[i * bw + id_next] -
+                           pred_src[i * bw + id_prev]) +
+             coeffs_bicubic[SUBPEL_GRAD_DELTA_BITS][1][is_boundary] *
+                 (int32_t)(pred_src[i * bw + id_next2] -
+                           pred_src[i * bw + id_prev2]);
+      x_grad[i * bw + j] = clamp(ROUND_POWER_OF_TWO_SIGNED(temp, bicubic_bits),
+                                 INT16_MIN, INT16_MAX);
+
+      // Subtract interpolated pixel at (i+delta, j) by the one at (i-delta, j)
+      id_prev = AOMMAX(i - 1, 0);
+      id_prev2 = AOMMAX(i - 2, 0);
+      id_next = AOMMIN(i + 1, bh - 1);
+      id_next2 = AOMMIN(i + 2, bh - 1);
+      is_boundary = (i + 1 > bh - 1 || i - 1 < 0);
+      temp = coeffs_bicubic[SUBPEL_GRAD_DELTA_BITS][0][is_boundary] *
+                 (int32_t)(pred_src[id_next * bw + j] -
+                           pred_src[id_prev * bw + j]) +
+             coeffs_bicubic[SUBPEL_GRAD_DELTA_BITS][1][is_boundary] *
+                 (int32_t)(pred_src[id_next2 * bw + j] -
+                           pred_src[id_prev2 * bw + j]);
+      y_grad[i * bw + j] = clamp(ROUND_POWER_OF_TWO_SIGNED(temp, bicubic_bits),
+                                 INT16_MIN, INT16_MAX);
+    }
+  }
+#else
+  (void)pred_src;
+  (void)x_grad;
+  (void)y_grad;
+  (void)bw;
+  (void)bh;
+#endif  // OPFL_BICUBIC_GRAD
+}
+
+void av1_bicubic_grad_interpolation_highbd_c(const int16_t *pred_src,
+                                             int16_t *x_grad, int16_t *y_grad,
+                                             const int bw, const int bh) {
+  av1_bicubic_grad_interpolation_c(pred_src, x_grad, y_grad, bw, bh);
+}
+
+#if OPFL_BILINEAR_GRAD
+void av1_bilinear_grad_interpolation_c(const int16_t *pred_src, int16_t *x_grad,
+                                       int16_t *y_grad, const int bw,
+                                       const int bh) {
+  int id_next, id_prev, is_boundary;
+  int32_t temp = 0;
+  for (int i = 0; i < bh; i++) {
+    for (int j = 0; j < bw; j++) {
+#if OPFL_DOWNSAMP_QUINCUNX
+      if ((i + j) % 2 == 1) continue;
+#endif
+      // Subtract interpolated pixel at (i, j+delta) by the one at (i, j-delta)
+      id_next = AOMMIN(j + 1, bw - 1);
+      id_prev = AOMMAX(j - 1, 0);
+      is_boundary = (j + 1 > bw - 1 || j - 1 < 0);
+      temp = coeffs_bilinear[SUBPEL_GRAD_DELTA_BITS][is_boundary] *
+             (int32_t)(pred_src[i * bw + id_next] - pred_src[i * bw + id_prev]);
+      x_grad[i * bw + j] = clamp(ROUND_POWER_OF_TWO_SIGNED(temp, bilinear_bits),
+                                 INT16_MIN, INT16_MAX);
+      // Subtract interpolated pixel at (i+delta, j) by the one at (i-delta, j)
+      id_next = AOMMIN(i + 1, bh - 1);
+      id_prev = AOMMAX(i - 1, 0);
+      is_boundary = (i + 1 > bh - 1 || i - 1 < 0);
+      temp = coeffs_bilinear[SUBPEL_GRAD_DELTA_BITS][is_boundary] *
+             (int32_t)(pred_src[id_next * bw + j] - pred_src[id_prev * bw + j]);
+      y_grad[i * bw + j] = clamp(ROUND_POWER_OF_TWO_SIGNED(temp, bilinear_bits),
+                                 INT16_MIN, INT16_MAX);
+    }
+  }
+}
+#endif  // OPFL_BILINEAR_GRAD
+
+#if OPFL_BILINEAR_GRAD || OPFL_BICUBIC_GRAD
+void av1_compute_subpel_gradients_interp(int16_t *pred_dst, int bw, int bh,
+                                         int *grad_prec_bits, int16_t *x_grad,
+                                         int16_t *y_grad, int is_hbd) {
+  // Reuse pixels in pred_dst to compute gradients
+#if OPFL_BILINEAR_GRAD
+  (void)is_hbd;
+  av1_bilinear_grad_interpolation_c(pred_dst, x_grad, y_grad, bw, bh);
+#else
+  if (is_hbd)
+    av1_bicubic_grad_interpolation_highbd(pred_dst, x_grad, y_grad, bw, bh);
+  else
+    av1_bicubic_grad_interpolation(pred_dst, x_grad, y_grad, bw, bh);
+#endif  // OPFL_BILINEAR_GRAD
+  *grad_prec_bits = 3 - SUBPEL_GRAD_DELTA_BITS - 2;
+}
+#endif  // OPFL_BILINEAR_GRAD || OPFL_BICUBIC_GRAD
+
+// Optical flow based mv refinement computation function:
+//
+// p0, pstride0: predictor 0 and its stride
+// p1, pstride1: predictor 1 and its stride
+// gx0, gy0: x and y gradients for p0
+// gx1, gy1: x and y gradients for p1
+// gstride: stride for all the gradients assumed to be the same
+// bw, bh: block dimensions
+// d0: distances of p0 to current frame, where positive value refers to p0
+//     before the current frame.
+// d1: distances of p1 to current frame, where positive value refers to p1
+//     before the current frame.
+// max_prec_bits: maximum offset in bits
+// vx0, vy0: output high resolution mv offset for p0
+// vx1, vy1: output high resolution mv offset for p1
+void av1_opfl_mv_refinement_lowbd(const uint8_t *p0, int pstride0,
+                                  const uint8_t *p1, int pstride1,
+                                  const int16_t *gx0, const int16_t *gy0,
+                                  const int16_t *gx1, const int16_t *gy1,
+                                  int gstride, int bw, int bh, int d0, int d1,
+                                  int grad_prec_bits, int mv_prec_bits,
+                                  int *vx0, int *vy0, int *vx1, int *vy1) {
+  assert(IMPLIES(OPFL_DIST_RATIO_THR == 1, d0 + d1 == 0));
+  int64_t su2 = 0;
+  int64_t suv = 0;
+  int64_t sv2 = 0;
+  int64_t suw = 0;
+  int64_t svw = 0;
+  for (int i = 0; i < bh; ++i) {
+    for (int j = 0; j < bw; ++j) {
+#if OPFL_DOWNSAMP_QUINCUNX
+      if ((i + j) % 2 == 1) continue;
+#endif
+      const int64_t u = d0 * gx0[i * gstride + j] - d1 * gx1[i * gstride + j];
+      const int64_t v = d0 * gy0[i * gstride + j] - d1 * gy1[i * gstride + j];
+      const int64_t w = d0 * (p0[i * pstride0 + j] - p1[i * pstride1 + j]);
+      su2 += (u * u);
+      suv += (u * v);
+      sv2 += (v * v);
+      suw += (u * w);
+      svw += (v * w);
+    }
+  }
+  const int bits = mv_prec_bits + grad_prec_bits;
+#if OPFL_REGULARIZED_LS
+  const int rls_alpha = (bw * bh >> 4) << OPFL_RLS_PARAM_BITS;
+  su2 += rls_alpha;
+  sv2 += rls_alpha;
+#endif
+
+  // Clamp su2, sv2, suv, suw, and svw to avoid overflow in det, det_x, and
+  // det_y
+  su2 = (int64_t)clamp((int)su2, -OPFL_COV_CLAMP_VAL, OPFL_COV_CLAMP_VAL);
+  sv2 = (int64_t)clamp((int)sv2, -OPFL_COV_CLAMP_VAL, OPFL_COV_CLAMP_VAL);
+  suv = (int64_t)clamp((int)suv, -OPFL_COV_CLAMP_VAL, OPFL_COV_CLAMP_VAL);
+  suw = (int64_t)clamp((int)suw, -OPFL_COV_CLAMP_VAL, OPFL_COV_CLAMP_VAL);
+  svw = (int64_t)clamp((int)svw, -OPFL_COV_CLAMP_VAL, OPFL_COV_CLAMP_VAL);
+
+  // Solve 2x2 matrix inverse: [ su2  suv ]   [ vx0 ]     [ -suw ]
+  //                           [ suv  sv2 ] * [ vy0 ]  =  [ -svw ]
+  const int64_t det = su2 * sv2 - suv * suv;
+  if (det == 0) return;
+  const int64_t det_x = (suv * svw - sv2 * suw) * (1 << bits);
+  const int64_t det_y = (suv * suw - su2 * svw) * (1 << bits);
+
+  *vx0 = (int)divide_and_round_signed(det_x, det);
+  *vy0 = (int)divide_and_round_signed(det_y, det);
+  const int tx1 = (*vx0) * d1;
+  const int ty1 = (*vy0) * d1;
+  *vx1 = (int)divide_and_round_signed(tx1, d0);
+  *vy1 = (int)divide_and_round_signed(ty1, d0);
+}
+
+void av1_opfl_mv_refinement_highbd(const uint16_t *p0, int pstride0,
+                                   const uint16_t *p1, int pstride1,
+                                   const int16_t *gx0, const int16_t *gy0,
+                                   const int16_t *gx1, const int16_t *gy1,
+                                   int gstride, int bw, int bh, int d0, int d1,
+                                   int grad_prec_bits, int mv_prec_bits,
+                                   int *vx0, int *vy0, int *vx1, int *vy1) {
+  assert(IMPLIES(OPFL_DIST_RATIO_THR == 1, d0 + d1 == 0));
+  int64_t su2 = 0;
+  int64_t suv = 0;
+  int64_t sv2 = 0;
+  int64_t suw = 0;
+  int64_t svw = 0;
+  for (int i = 0; i < bh; ++i) {
+    for (int j = 0; j < bw; ++j) {
+#if OPFL_DOWNSAMP_QUINCUNX
+      if ((i + j) % 2 == 1) continue;
+#endif
+      const int64_t u = d0 * gx0[i * gstride + j] - d1 * gx1[i * gstride + j];
+      const int64_t v = d0 * gy0[i * gstride + j] - d1 * gy1[i * gstride + j];
+      const int64_t w = d0 * (p0[i * pstride0 + j] - p1[i * pstride1 + j]);
+      su2 += (u * u);
+      suv += (u * v);
+      sv2 += (v * v);
+      suw += (u * w);
+      svw += (v * w);
+    }
+  }
+  const int bits = mv_prec_bits + grad_prec_bits;
+#if OPFL_REGULARIZED_LS
+  const int rls_alpha = (bw * bh >> 4) << OPFL_RLS_PARAM_BITS;
+  su2 += rls_alpha;
+  sv2 += rls_alpha;
+#endif
+
+  // Clamp su2, sv2, suv, suw, and svw to avoid overflow in det, det_x, and
+  // det_y
+  su2 = (int64_t)clamp((int)su2, -OPFL_COV_CLAMP_VAL, OPFL_COV_CLAMP_VAL);
+  sv2 = (int64_t)clamp((int)sv2, -OPFL_COV_CLAMP_VAL, OPFL_COV_CLAMP_VAL);
+  suv = (int64_t)clamp((int)suv, -OPFL_COV_CLAMP_VAL, OPFL_COV_CLAMP_VAL);
+  suw = (int64_t)clamp((int)suw, -OPFL_COV_CLAMP_VAL, OPFL_COV_CLAMP_VAL);
+  svw = (int64_t)clamp((int)svw, -OPFL_COV_CLAMP_VAL, OPFL_COV_CLAMP_VAL);
+
+  // Solve 2x2 matrix inverse: [ su2  suv ]   [ vx0 ]     [ -suw ]
+  //                           [ suv  sv2 ] * [ vy0 ]  =  [ -svw ]
+  const int64_t det = su2 * sv2 - suv * suv;
+  if (det == 0) return;
+  const int64_t det_x = (suv * svw - sv2 * suw) * (1 << bits);
+  const int64_t det_y = (suv * suw - su2 * svw) * (1 << bits);
+
+  *vx0 = (int)divide_and_round_signed(det_x, det);
+  *vy0 = (int)divide_and_round_signed(det_y, det);
+  const int tx1 = (*vx0) * d1;
+  const int ty1 = (*vy0) * d1;
+  *vx1 = (int)divide_and_round_signed(tx1, d0);
+  *vy1 = (int)divide_and_round_signed(ty1, d0);
+}
+
+#if OPFL_COMBINE_INTERP_GRAD_LS
+// Solve vx and vy given pdiff = P0 - P1 and the gradients gx/gy of
+// d0 * P0 - d1 * P1.
+void av1_opfl_mv_refinement_interp_grad(const int16_t *pdiff, int pstride0,
+                                        const int16_t *gx, const int16_t *gy,
+                                        int gstride, int bw, int bh, int d0,
+                                        int d1, int grad_prec_bits,
+                                        int mv_prec_bits, int *vx0, int *vy0,
+                                        int *vx1, int *vy1) {
+  assert(IMPLIES(OPFL_DIST_RATIO_THR == 1, d0 + d1 == 0));
+  int64_t su2 = 0;
+  int64_t suv = 0;
+  int64_t sv2 = 0;
+  int64_t suw = 0;
+  int64_t svw = 0;
+  for (int i = 0; i < bh; ++i) {
+    for (int j = 0; j < bw; ++j) {
+#if OPFL_DOWNSAMP_QUINCUNX
+      if ((i + j) % 2 == 1) continue;
+#endif
+      const int u = gx[i * gstride + j];
+      const int v = gy[i * gstride + j];
+      const int w = pdiff[i * pstride0 + j];
+      su2 += (u * u);
+      suv += (u * v);
+      sv2 += (v * v);
+      suw += (u * w);
+      svw += (v * w);
+    }
+  }
+  const int bits = mv_prec_bits + grad_prec_bits;
+#if OPFL_REGULARIZED_LS
+  const int rls_alpha = (bw * bh >> 4) << OPFL_RLS_PARAM_BITS;
+  su2 += rls_alpha;
+  sv2 += rls_alpha;
+#endif
+
+  // Clamp su2, sv2, suv, suw, and svw to avoid overflow in det, det_x, and
+  // det_y
+  su2 = (int64_t)clamp((int)su2, -OPFL_COV_CLAMP_VAL, OPFL_COV_CLAMP_VAL);
+  sv2 = (int64_t)clamp((int)sv2, -OPFL_COV_CLAMP_VAL, OPFL_COV_CLAMP_VAL);
+  suv = (int64_t)clamp((int)suv, -OPFL_COV_CLAMP_VAL, OPFL_COV_CLAMP_VAL);
+  suw = (int64_t)clamp((int)suw, -OPFL_COV_CLAMP_VAL, OPFL_COV_CLAMP_VAL);
+  svw = (int64_t)clamp((int)svw, -OPFL_COV_CLAMP_VAL, OPFL_COV_CLAMP_VAL);
+
+  // Solve 2x2 matrix inverse: [ su2  suv ]   [ vx0 ]     [ -suw ]
+  //                           [ suv  sv2 ] * [ vy0 ]  =  [ -svw ]
+  const int64_t det = su2 * sv2 - suv * suv;
+  if (det == 0) return;
+  const int64_t det_x = (suv * svw - sv2 * suw) * (1 << bits);
+  const int64_t det_y = (suv * suw - su2 * svw) * (1 << bits);
+
+  *vx0 = (int)divide_and_round_signed(det_x, det);
+  *vy0 = (int)divide_and_round_signed(det_y, det);
+  const int tx1 = (*vx0) * d1;
+  const int ty1 = (*vy0) * d1;
+  *vx1 = (int)divide_and_round_signed(tx1, d0);
+  *vy1 = (int)divide_and_round_signed(ty1, d0);
+}
+#endif  // OPFL_COMBINE_INTERP_GRAD_LS
+
+int av1_opfl_mv_refinement_nxn_interp_grad_c(
+    const int16_t *pdiff, int pstride, const int16_t *gx, const int16_t *gy,
+    int gstride, int bw, int bh, int n, int d0, int d1, int grad_prec_bits,
+    int mv_prec_bits, int *vx0, int *vy0, int *vx1, int *vy1) {
+  assert(bw % n == 0 && bh % n == 0);
+  int n_blocks = 0;
+#if OPFL_COMBINE_INTERP_GRAD_LS
+  for (int i = 0; i < bh; i += n) {
+    for (int j = 0; j < bw; j += n) {
+      av1_opfl_mv_refinement_interp_grad(
+          pdiff + (i * pstride + j), pstride, gx + (i * gstride + j),
+          gy + (i * gstride + j), gstride, n, n, d0, d1, grad_prec_bits,
+          mv_prec_bits, vx0 + n_blocks, vy0 + n_blocks, vx1 + n_blocks,
+          vy1 + n_blocks);
+      n_blocks++;
+    }
+  }
+#else
+  (void)pdiff;
+  (void)pstride;
+  (void)gx;
+  (void)gy;
+  (void)gstride;
+  (void)bw;
+  (void)bh;
+  (void)n;
+  (void)d0;
+  (void)d1;
+  (void)grad_prec_bits;
+  (void)mv_prec_bits;
+  (void)vx0;
+  (void)vy0;
+  (void)vx1;
+  (void)vy1;
+#endif  // OPFL_COMBINE_INTERP_GRAD_LS
+  return n_blocks;
+}
+
+// Function to compute optical flow offsets in nxn blocks
+int av1_opfl_mv_refinement_nxn_highbd_c(const uint16_t *p0, int pstride0,
+                                        const uint16_t *p1, int pstride1,
+                                        const int16_t *gx0, const int16_t *gy0,
+                                        const int16_t *gx1, const int16_t *gy1,
+                                        int gstride, int bw, int bh, int n,
+                                        int d0, int d1, int grad_prec_bits,
+                                        int mv_prec_bits, int *vx0, int *vy0,
+                                        int *vx1, int *vy1) {
+  assert(bw % n == 0 && bh % n == 0);
+  int n_blocks = 0;
+  for (int i = 0; i < bh; i += n) {
+    for (int j = 0; j < bw; j += n) {
+      av1_opfl_mv_refinement_highbd(
+          p0 + (i * pstride0 + j), pstride0, p1 + (i * pstride1 + j), pstride1,
+          gx0 + (i * gstride + j), gy0 + (i * gstride + j),
+          gx1 + (i * gstride + j), gy1 + (i * gstride + j), gstride, n, n, d0,
+          d1, grad_prec_bits, mv_prec_bits, vx0 + n_blocks, vy0 + n_blocks,
+          vx1 + n_blocks, vy1 + n_blocks);
+      n_blocks++;
+    }
+  }
+  return n_blocks;
+}
+
+// Function to compute optical flow offsets in nxn blocks
+int av1_opfl_mv_refinement_nxn_lowbd_c(const uint8_t *p0, int pstride0,
+                                       const uint8_t *p1, int pstride1,
+                                       const int16_t *gx0, const int16_t *gy0,
+                                       const int16_t *gx1, const int16_t *gy1,
+                                       int gstride, int bw, int bh, int n,
+                                       int d0, int d1, int grad_prec_bits,
+                                       int mv_prec_bits, int *vx0, int *vy0,
+                                       int *vx1, int *vy1) {
+  assert(bw % n == 0 && bh % n == 0);
+  int n_blocks = 0;
+  for (int i = 0; i < bh; i += n) {
+    for (int j = 0; j < bw; j += n) {
+      av1_opfl_mv_refinement_lowbd(
+          p0 + (i * pstride0 + j), pstride0, p1 + (i * pstride1 + j), pstride1,
+          gx0 + (i * gstride + j), gy0 + (i * gstride + j),
+          gx1 + (i * gstride + j), gy1 + (i * gstride + j), gstride, n, n, d0,
+          d1, grad_prec_bits, mv_prec_bits, vx0 + n_blocks, vy0 + n_blocks,
+          vx1 + n_blocks, vy1 + n_blocks);
+      n_blocks++;
+    }
+  }
+  return n_blocks;
+}
+
+#if OPFL_COMBINE_INTERP_GRAD_LS
+static AOM_FORCE_INLINE void compute_pred_using_interp_grad(
+    const uint8_t *src1, const uint8_t *src2, int16_t *dst1, int16_t *dst2,
+    int bw, int bh, int d0, int d1) {
+  for (int i = 0; i < bh; ++i) {
+    for (int j = 0; j < bw; ++j) {
+      // To avoid overflow, we clamp d0*P0-d1*P1 and P0-P1. Since d0 and d1 are
+      // at most 5 bits, this clamping is only required in highbd, but it is
+      // also added here for consistency.
+      int32_t tmp_dst =
+          d0 * (int32_t)src1[i * bw + j] - d1 * (int32_t)src2[i * bw + j];
+      dst1[i * bw + j] = clamp(tmp_dst, INT16_MIN, INT16_MAX);
+      tmp_dst = d0 * ((int32_t)src1[i * bw + j] - (int32_t)src2[i * bw + j]);
+      dst2[i * bw + j] = clamp(tmp_dst, INT16_MIN, INT16_MAX);
+    }
+  }
+}
+#endif  // OPFL_COMBINE_INTERP_GRAD_LS
+
+void av1_copy_pred_array_c(const uint8_t *src1, const uint8_t *src2,
+                           int16_t *dst1, int16_t *dst2, int bw, int bh, int d0,
+                           int d1) {
+#if OPFL_BILINEAR_GRAD || OPFL_BICUBIC_GRAD
+#if OPFL_COMBINE_INTERP_GRAD_LS
+  compute_pred_using_interp_grad(src1, src2, dst1, dst2, bw, bh, d0, d1);
+#else
+  (void)src2;
+  (void)dst2;
+  (void)d0;
+  (void)d1;
+  for (int i = 0; i < bh; ++i)
+    for (int j = 0; j < bw; ++j) dst1[i * bw + j] = (int16_t)src1[i * bw + j];
+#endif  // OPFL_COMBINE_INTERP_GRAD_LS
+#else
+  (void)src1;
+  (void)dst1;
+  (void)src2;
+  (void)dst2;
+  (void)d0;
+  (void)d1;
+  (void)bw;
+  (void)bh;
+#endif  // OPFL_BILINEAR_GRAD || OPFL_BICUBIC_GRAD
+}
+
+#if OPFL_COMBINE_INTERP_GRAD_LS
+static AOM_FORCE_INLINE void compute_pred_using_interp_grad_highbd(
+    const uint16_t *src1, const uint16_t *src2, int16_t *dst1, int16_t *dst2,
+    int bw, int bh, int d0, int d1) {
+  for (int i = 0; i < bh; ++i) {
+    for (int j = 0; j < bw; ++j) {
+      // To avoid overflow, we clamp d0*P0-d1*P1 and P0-P1.
+      int32_t tmp_dst =
+          d0 * (int32_t)src1[i * bw + j] - d1 * (int32_t)src2[i * bw + j];
+      dst1[i * bw + j] = clamp(tmp_dst, INT16_MIN, INT16_MAX);
+      tmp_dst = d0 * ((int32_t)src1[i * bw + j] - (int32_t)src2[i * bw + j]);
+      dst2[i * bw + j] = clamp(tmp_dst, INT16_MIN, INT16_MAX);
+    }
+  }
+}
+#endif  // OPFL_COMBINE_INTERP_GRAD_LS
+
+void av1_copy_pred_array_highbd_c(const uint16_t *src1, const uint16_t *src2,
+                                  int16_t *dst1, int16_t *dst2, int bw, int bh,
+                                  int d0, int d1) {
+#if OPFL_BILINEAR_GRAD || OPFL_BICUBIC_GRAD
+#if OPFL_COMBINE_INTERP_GRAD_LS
+  compute_pred_using_interp_grad_highbd(src1, src2, dst1, dst2, bw, bh, d0, d1);
+#else
+  (void)src2;
+  (void)dst2;
+  (void)d0;
+  (void)d1;
+  for (int i = 0; i < bh; ++i)
+    for (int j = 0; j < bw; ++j) dst1[i * bw + j] = (int16_t)src1[i * bw + j];
+#endif  // OPFL_COMBINE_INTERP_GRAD_LS
+#else
+  (void)src1;
+  (void)dst1;
+  (void)src2;
+  (void)dst2;
+  (void)d0;
+  (void)d1;
+  (void)bw;
+  (void)bh;
+#endif  // OPFL_BILINEAR_GRAD || OPFL_BICUBIC_GRAD
+}
+
+static int get_optflow_based_mv_highbd(
+    const AV1_COMMON *cm, MACROBLOCKD *xd, int plane, const MB_MODE_INFO *mbmi,
+    int_mv *mv_refined, int bw, int bh, int mi_x, int mi_y, uint8_t **mc_buf,
+    CalcSubpelParamsFunc calc_subpel_params_func, int16_t *gx0, int16_t *gy0,
+    int16_t *gx1, int16_t *gy1, int *vx0, int *vy0, int *vx1, int *vy1,
+    uint16_t *dst0, uint16_t *dst1) {
+  const int target_prec = MV_REFINE_PREC_BITS;
+  // Convert output MV to 1/16th pel
+  assert(MV_REFINE_PREC_BITS >= 3);
+  for (int mvi = 0; mvi < N_OF_OFFSETS; mvi++) {
+    mv_refined[mvi * 2].as_mv.row *= 1 << (MV_REFINE_PREC_BITS - 3);
+    mv_refined[mvi * 2].as_mv.col *= 1 << (MV_REFINE_PREC_BITS - 3);
+    mv_refined[mvi * 2 + 1].as_mv.row *= 1 << (MV_REFINE_PREC_BITS - 3);
+    mv_refined[mvi * 2 + 1].as_mv.col *= 1 << (MV_REFINE_PREC_BITS - 3);
+  }
+
+  // Obtain d0 and d1
+  const RefCntBuffer *const r0_buf = get_ref_frame_buf(cm, mbmi->ref_frame[0]);
+  const RefCntBuffer *const r1_buf = get_ref_frame_buf(cm, mbmi->ref_frame[1]);
+  int d0 = get_relative_dist(&cm->seq_params.order_hint_info,
+                             cm->cur_frame->order_hint, r0_buf->order_hint);
+  int d1 = get_relative_dist(&cm->seq_params.order_hint_info,
+                             cm->cur_frame->order_hint, r1_buf->order_hint);
+  if (d0 == 0 || d1 == 0) return target_prec;
+
+  // Obrain P0 and P1
+  InterPredParams params0, params1;
+  av1_opfl_build_inter_predictor(cm, xd, plane, mbmi, bw, bh, mi_x, mi_y,
+                                 mc_buf, &params0, calc_subpel_params_func, 0,
+                                 CONVERT_TO_BYTEPTR(dst0));
+  av1_opfl_build_inter_predictor(cm, xd, plane, mbmi, bw, bh, mi_x, mi_y,
+                                 mc_buf, &params1, calc_subpel_params_func, 1,
+                                 CONVERT_TO_BYTEPTR(dst1));
+
+  int n_blocks = 1;
+  int grad_prec_bits;
+  int n = opfl_get_subblock_size(bw, bh, plane);
+
+#if OPFL_BILINEAR_GRAD || OPFL_BICUBIC_GRAD
+  // Compute gradients of P0 and P1 with interpolation
+#if OPFL_COMBINE_INTERP_GRAD_LS
+  (void)gx1;
+  (void)gy1;
+
+  // Compute tmp1 = P0 - P1 and gradients of tmp0 = d0 * P0 - d1 * P1
+  int16_t *tmp0 =
+      (int16_t *)aom_memalign(16, MAX_SB_SIZE * MAX_SB_SIZE * sizeof(int16_t));
+  int16_t *tmp1 =
+      (int16_t *)aom_memalign(16, MAX_SB_SIZE * MAX_SB_SIZE * sizeof(int16_t));
+  av1_copy_pred_array_highbd(dst0, dst1, tmp0, tmp1, bw, bh, d0, d1);
+  // Buffers gx0 and gy0 are used to store the gradients of tmp0
+  av1_compute_subpel_gradients_interp(tmp0, bw, bh, &grad_prec_bits, gx0, gy0,
+                                      is_cur_buf_hbd(xd));
+
+  n_blocks = av1_opfl_mv_refinement_nxn_interp_grad(
+      tmp1, bw, gx0, gy0, bw, bw, bh, n, d0, d1, grad_prec_bits, target_prec,
+      vx0, vy0, vx1, vy1);
+
+  aom_free(tmp0);
+  aom_free(tmp1);
+#else
+  int16_t *tmp =
+      (int16_t *)aom_memalign(16, MAX_SB_SIZE * MAX_SB_SIZE * sizeof(int16_t));
+  av1_copy_pred_array_highbd(dst0, NULL, tmp, NULL, bw, bh, d0, d1);
+  av1_compute_subpel_gradients_interp(tmp, bw, bh, &grad_prec_bits, gx0, gy0,
+                                      is_cur_buf_hbd(xd));
+
+  av1_copy_pred_array_highbd(dst1, NULL, tmp, NULL, bw, bh, d0, d1);
+  av1_compute_subpel_gradients_interp(tmp, bw, bh, &grad_prec_bits, gx1, gy1,
+                                      is_cur_buf_hbd(xd));
+
+  n_blocks = av1_opfl_mv_refinement_nxn_highbd(
+      dst0, bw, dst1, bw, gx0, gy0, gx1, gy1, bw, bw, bh, n, d0, d1,
+      grad_prec_bits, target_prec, vx0, vy0, vx1, vy1);
+
+  aom_free(tmp);
+#endif  // OPFL_COMBINE_INTERP_GRAD_LS
+#else
+  // Compute gradients of P0 and P1 with MC
+  av1_compute_subpel_gradients_mc_highbd(xd, mbmi, bw, bh, mi_x, mi_y, mc_buf,
+                                         &params0, calc_subpel_params_func, 0,
+                                         &grad_prec_bits, gx0, gy0);
+  av1_compute_subpel_gradients_mc_highbd(xd, mbmi, bw, bh, mi_x, mi_y, mc_buf,
+                                         &params1, calc_subpel_params_func, 1,
+                                         &grad_prec_bits, gx1, gy1);
+
+  n_blocks = av1_opfl_mv_refinement_nxn_highbd(
+      dst0, bw, dst1, bw, gx0, gy0, gx1, gy1, bw, bw, bh, n, d0, d1,
+      grad_prec_bits, target_prec, vx0, vy0, vx1, vy1);
+
+#endif  // OPFL_BILINEAR_GRAD || OPFL_BICUBIC_GRAD
+
+  for (int i = 0; i < n_blocks; i++) {
+#if OPFL_CLAMP_MV_DELTA
+    mv_refined[i * 2].as_mv.row +=
+        clamp(vy0[i], -OPFL_MV_DELTA_LIMIT, OPFL_MV_DELTA_LIMIT);
+    mv_refined[i * 2].as_mv.col +=
+        clamp(vx0[i], -OPFL_MV_DELTA_LIMIT, OPFL_MV_DELTA_LIMIT);
+    mv_refined[i * 2 + 1].as_mv.row +=
+        clamp(vy1[i], -OPFL_MV_DELTA_LIMIT, OPFL_MV_DELTA_LIMIT);
+    mv_refined[i * 2 + 1].as_mv.col +=
+        clamp(vx1[i], -OPFL_MV_DELTA_LIMIT, OPFL_MV_DELTA_LIMIT);
+#else
+    mv_refined[i * 2].as_mv.row += vy0[i];
+    mv_refined[i * 2].as_mv.col += vx0[i];
+    mv_refined[i * 2 + 1].as_mv.row += vy1[i];
+    mv_refined[i * 2 + 1].as_mv.col += vx1[i];
+#endif
+  }
+
+  return target_prec;
+}
+
+static int get_optflow_based_mv_lowbd(
+    const AV1_COMMON *cm, MACROBLOCKD *xd, int plane, const MB_MODE_INFO *mbmi,
+    int_mv *mv_refined, int bw, int bh, int mi_x, int mi_y, uint8_t **mc_buf,
+    CalcSubpelParamsFunc calc_subpel_params_func, int16_t *gx0, int16_t *gy0,
+    int16_t *gx1, int16_t *gy1, int *vx0, int *vy0, int *vx1, int *vy1,
+    uint8_t *dst0, uint8_t *dst1) {
+  const int target_prec = MV_REFINE_PREC_BITS;
+  // Convert output MV to 1/16th pel
+  assert(MV_REFINE_PREC_BITS >= 3);
+  for (int mvi = 0; mvi < N_OF_OFFSETS; mvi++) {
+    mv_refined[mvi * 2].as_mv.row *= 1 << (MV_REFINE_PREC_BITS - 3);
+    mv_refined[mvi * 2].as_mv.col *= 1 << (MV_REFINE_PREC_BITS - 3);
+    mv_refined[mvi * 2 + 1].as_mv.row *= 1 << (MV_REFINE_PREC_BITS - 3);
+    mv_refined[mvi * 2 + 1].as_mv.col *= 1 << (MV_REFINE_PREC_BITS - 3);
+  }
+
+  // Obtain d0 and d1
+  const RefCntBuffer *const r0_buf = get_ref_frame_buf(cm, mbmi->ref_frame[0]);
+  const RefCntBuffer *const r1_buf = get_ref_frame_buf(cm, mbmi->ref_frame[1]);
+  int d0 = get_relative_dist(&cm->seq_params.order_hint_info,
+                             cm->cur_frame->order_hint, r0_buf->order_hint);
+  int d1 = get_relative_dist(&cm->seq_params.order_hint_info,
+                             cm->cur_frame->order_hint, r1_buf->order_hint);
+  if (d0 == 0 || d1 == 0) return target_prec;
+
+  // Obrain P0 and P1
+  InterPredParams params0, params1;
+  av1_opfl_build_inter_predictor(cm, xd, plane, mbmi, bw, bh, mi_x, mi_y,
+                                 mc_buf, &params0, calc_subpel_params_func, 0,
+                                 dst0);
+  av1_opfl_build_inter_predictor(cm, xd, plane, mbmi, bw, bh, mi_x, mi_y,
+                                 mc_buf, &params1, calc_subpel_params_func, 1,
+                                 dst1);
+
+  int n_blocks = 1;
+  int grad_prec_bits;
+  int n = opfl_get_subblock_size(bw, bh, plane);
+
+#if OPFL_BILINEAR_GRAD || OPFL_BICUBIC_GRAD
+  // Compute gradients of P0 and P1 with interpolation
+#if OPFL_COMBINE_INTERP_GRAD_LS
+  (void)gx1;
+  (void)gy1;
+
+  // Compute tmp1 = P0 - P1 and gradients of tmp0 = d0 * P0 - d1 * P1
+  int16_t *tmp0 =
+      (int16_t *)aom_memalign(16, MAX_SB_SIZE * MAX_SB_SIZE * sizeof(int16_t));
+  int16_t *tmp1 =
+      (int16_t *)aom_memalign(16, MAX_SB_SIZE * MAX_SB_SIZE * sizeof(int16_t));
+  av1_copy_pred_array(dst0, dst1, tmp0, tmp1, bw, bh, d0, d1);
+  // Buffers gx0 and gy0 are used to store the gradients of tmp0
+  av1_compute_subpel_gradients_interp(tmp0, bw, bh, &grad_prec_bits, gx0, gy0,
+                                      is_cur_buf_hbd(xd));
+
+  n_blocks = av1_opfl_mv_refinement_nxn_interp_grad(
+      tmp1, bw, gx0, gy0, bw, bw, bh, n, d0, d1, grad_prec_bits, target_prec,
+      vx0, vy0, vx1, vy1);
+
+  aom_free(tmp0);
+  aom_free(tmp1);
+#else
+  int16_t *tmp =
+      (int16_t *)aom_memalign(16, MAX_SB_SIZE * MAX_SB_SIZE * sizeof(int16_t));
+  av1_copy_pred_array(dst0, NULL, tmp, NULL, bw, bh, d0, d1);
+  av1_compute_subpel_gradients_interp(tmp, bw, bh, &grad_prec_bits, gx0, gy0,
+                                      is_cur_buf_hbd(xd));
+  av1_copy_pred_array(dst1, NULL, tmp, NULL, bw, bh, d0, d1);
+  av1_compute_subpel_gradients_interp(tmp, bw, bh, &grad_prec_bits, gx1, gy1,
+                                      is_cur_buf_hbd(xd));
+
+  n_blocks = av1_opfl_mv_refinement_nxn_lowbd(
+      dst0, bw, dst1, bw, gx0, gy0, gx1, gy1, bw, bw, bh, n, d0, d1,
+      grad_prec_bits, target_prec, vx0, vy0, vx1, vy1);
+
+  aom_free(tmp);
+#endif  // OPFL_COMBINE_INTERP_GRAD_LS
+#else
+  // Compute gradients of P0 and P1 with MC
+  av1_compute_subpel_gradients_mc_lowbd(xd, mbmi, bw, bh, mi_x, mi_y, mc_buf,
+                                        &params0, calc_subpel_params_func, 0,
+                                        &grad_prec_bits, gx0, gy0);
+  av1_compute_subpel_gradients_mc_lowbd(xd, mbmi, bw, bh, mi_x, mi_y, mc_buf,
+                                        &params1, calc_subpel_params_func, 1,
+                                        &grad_prec_bits, gx1, gy1);
+
+  n_blocks = av1_opfl_mv_refinement_nxn_lowbd(
+      dst0, bw, dst1, bw, gx0, gy0, gx1, gy1, bw, bw, bh, n, d0, d1,
+      grad_prec_bits, target_prec, vx0, vy0, vx1, vy1);
+
+#endif  // OPFL_BILINEAR_GRAD || OPFL_BICUBIC_GRAD
+
+  for (int i = 0; i < n_blocks; i++) {
+#if OPFL_CLAMP_MV_DELTA
+    mv_refined[i * 2].as_mv.row +=
+        clamp(vy0[i], -OPFL_MV_DELTA_LIMIT, OPFL_MV_DELTA_LIMIT);
+    mv_refined[i * 2].as_mv.col +=
+        clamp(vx0[i], -OPFL_MV_DELTA_LIMIT, OPFL_MV_DELTA_LIMIT);
+    mv_refined[i * 2 + 1].as_mv.row +=
+        clamp(vy1[i], -OPFL_MV_DELTA_LIMIT, OPFL_MV_DELTA_LIMIT);
+    mv_refined[i * 2 + 1].as_mv.col +=
+        clamp(vx1[i], -OPFL_MV_DELTA_LIMIT, OPFL_MV_DELTA_LIMIT);
+#else
+    mv_refined[i * 2].as_mv.row += vy0[i];
+    mv_refined[i * 2].as_mv.col += vx0[i];
+    mv_refined[i * 2 + 1].as_mv.row += vy1[i];
+    mv_refined[i * 2 + 1].as_mv.col += vx1[i];
+#endif
+  }
+
+  return target_prec;
+}
+
+// Makes the interpredictor for the region by dividing it up into nxn blocks
+// and running the interpredictor code on each one.
+void make_inter_pred_of_nxn(uint8_t *dst, int dst_stride,
+                            int_mv *const mv_refined,
+                            InterPredParams *inter_pred_params, MACROBLOCKD *xd,
+                            int mi_x, int mi_y, int ref, uint8_t **mc_buf,
+                            CalcSubpelParamsFunc calc_subpel_params_func, int n,
+                            SubpelParams *subpel_params) {
+  int n_blocks = 0;
+  int w = inter_pred_params->orig_block_width;
+  int h = inter_pred_params->orig_block_height;
+  assert(w % n == 0);
+  assert(h % n == 0);
+  CONV_BUF_TYPE *orig_conv_dst = inter_pred_params->conv_params.dst;
+  inter_pred_params->block_width = n;
+  inter_pred_params->block_height = n;
+
+  uint8_t *pre;
+  int src_stride = 0;
+
+  // Process whole nxn blocks.
+  for (int j = 0; j <= h - n; j += n) {
+    for (int i = 0; i <= w - n; i += n) {
+      calc_subpel_params_func(&(mv_refined[n_blocks * 2 + ref].as_mv),
+                              inter_pred_params, xd, mi_x + i, mi_y + j, ref, 1,
+                              mc_buf, &pre, subpel_params, &src_stride);
+      av1_make_inter_predictor(pre, src_stride, dst, dst_stride,
+                               inter_pred_params, subpel_params);
+      n_blocks++;
+      dst += n;
+      inter_pred_params->conv_params.dst += n;
+      inter_pred_params->pix_col += n;
+    }
+    dst -= w;
+    inter_pred_params->conv_params.dst -= w;
+    inter_pred_params->pix_col -= w;
+
+    dst += n * dst_stride;
+    inter_pred_params->conv_params.dst +=
+        n * inter_pred_params->conv_params.dst_stride;
+    inter_pred_params->pix_row += n;
+  }
+
+  inter_pred_params->conv_params.dst = orig_conv_dst;
+}
+
+// Use a second pass of motion compensation to rebuild inter predictor
+void av1_opfl_rebuild_inter_predictor(
+    uint8_t *dst, int dst_stride, int plane, int_mv *const mv_refined,
+    InterPredParams *inter_pred_params, MACROBLOCKD *xd, int mi_x, int mi_y,
+    int ref, uint8_t **mc_buf, CalcSubpelParamsFunc calc_subpel_params_func) {
+  SubpelParams subpel_params;
+  int w = inter_pred_params->block_width;
+  int h = inter_pred_params->block_height;
+  int n = opfl_get_subblock_size(w, h, plane);
+  make_inter_pred_of_nxn(dst, dst_stride, mv_refined, inter_pred_params, xd,
+                         mi_x, mi_y, ref, mc_buf, calc_subpel_params_func, n,
+                         &subpel_params);
+}
+#endif  // CONFIG_OPTFLOW_REFINEMENT
+
 // Equation of line: f(x, y) = a[0]*(x - a[2]*w/8) + a[1]*(y - a[3]*h/8) = 0
 void av1_init_wedge_masks() {
   init_wedge_master_masks();
@@ -700,6 +1666,9 @@
   uint8_t *src;
   int src_stride;
   calc_subpel_params_func(src_mv, inter_pred_params, xd, mi_x, mi_y, ref,
+#if CONFIG_OPTFLOW_REFINEMENT
+                          0, /* use_optflow_refinement */
+#endif                       // CONFIG_OPTFLOW_REFINEMENT
                           mc_buf, &src, &subpel_params, &src_stride);
 
   if (inter_pred_params->comp_mode == UNIFORM_SINGLE ||
@@ -712,54 +1681,6 @@
   }
 }
 
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-void av1_dist_wtd_comp_weight_assign(const AV1_COMMON *cm,
-                                     const MB_MODE_INFO *mbmi, int *fwd_offset,
-                                     int *bck_offset, int is_compound) {
-  assert(fwd_offset != NULL && bck_offset != NULL);
-  if (!is_compound || mbmi->compound_idx) {
-    *fwd_offset = 1 << (DIST_PRECISION_BITS - 1);
-    *bck_offset = 1 << (DIST_PRECISION_BITS - 1);
-    return;
-  }
-
-  const RefCntBuffer *const bck_buf = get_ref_frame_buf(cm, mbmi->ref_frame[0]);
-  const RefCntBuffer *const fwd_buf = get_ref_frame_buf(cm, mbmi->ref_frame[1]);
-  const int cur_frame_index = cm->cur_frame->order_hint;
-  int bck_frame_index = 0, fwd_frame_index = 0;
-
-  if (bck_buf != NULL) bck_frame_index = bck_buf->order_hint;
-  if (fwd_buf != NULL) fwd_frame_index = fwd_buf->order_hint;
-
-  int d0 = clamp(abs(get_relative_dist(&cm->seq_params.order_hint_info,
-                                       fwd_frame_index, cur_frame_index)),
-                 0, MAX_FRAME_DISTANCE);
-  int d1 = clamp(abs(get_relative_dist(&cm->seq_params.order_hint_info,
-                                       cur_frame_index, bck_frame_index)),
-                 0, MAX_FRAME_DISTANCE);
-
-  const int order = d0 <= d1;
-
-  if (d0 == 0 || d1 == 0) {
-    *fwd_offset = quant_dist_lookup_table[3][order];
-    *bck_offset = quant_dist_lookup_table[3][1 - order];
-    return;
-  }
-
-  int i;
-  for (i = 0; i < 3; ++i) {
-    int c0 = quant_dist_weight[i][order];
-    int c1 = quant_dist_weight[i][!order];
-    int d0_c0 = d0 * c0;
-    int d1_c1 = d1 * c1;
-    if ((d0 > d1 && d0_c0 < d1_c1) || (d0 <= d1 && d0_c0 > d1_c1)) break;
-  }
-
-  *fwd_offset = quant_dist_lookup_table[i][order];
-  *bck_offset = quant_dist_lookup_table[i][1 - order];
-}
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
-
 // True if the following hold:
 //  1. Not intrabc and not build_for_obmc
 //  2. At least one dimension is size 4 with subsampling
@@ -888,7 +1809,7 @@
 }
 
 static void build_inter_predictors_8x8_and_bigger(
-    const AV1_COMMON *cm, MACROBLOCKD *xd, int plane, const MB_MODE_INFO *mi,
+    const AV1_COMMON *cm, MACROBLOCKD *xd, int plane, MB_MODE_INFO *mi,
     int build_for_obmc, int bw, int bh, int mi_x, int mi_y, uint8_t **mc_buf,
     CalcSubpelParamsFunc calc_subpel_params_func) {
   const int is_compound = has_second_ref(mi);
@@ -921,6 +1842,88 @@
   const int pre_x = (mi_x + MI_SIZE * col_start) >> ss_x;
   const int pre_y = (mi_y + MI_SIZE * row_start) >> ss_y;
 
+#if CONFIG_OPTFLOW_REFINEMENT
+  int_mv mv_refined[2 * N_OF_OFFSETS];
+  const int use_optflow_refinement =
+      (mi->mode > NEW_NEWMV ||
+       (cm->features.opfl_refine_type == REFINE_ALL &&
+        mi->mode != GLOBAL_GLOBALMV &&
+        mi->interinter_comp.type == COMPOUND_AVERAGE)) &&
+      is_compound && is_opfl_refine_allowed(cm, mi);
+
+  assert(IMPLIES(mi->mode > NEW_NEWMV,
+                 cm->features.opfl_refine_type == REFINE_SWITCHABLE));
+  assert(IMPLIES(use_optflow_refinement, !build_for_obmc));
+
+  // Optical flow refinement with masked comp types or with non-sharp
+  // interpolation filter should only exist in REFINE_ALL.
+  assert(IMPLIES(
+      use_optflow_refinement && mi->interinter_comp.type != COMPOUND_AVERAGE,
+      cm->features.opfl_refine_type == REFINE_ALL));
+#if CONFIG_REMOVE_DUAL_FILTER
+  assert(IMPLIES(use_optflow_refinement && mi->interp_fltr != MULTITAP_SHARP,
+                 cm->features.opfl_refine_type == REFINE_ALL));
+#else
+  assert(
+      IMPLIES(use_optflow_refinement &&
+                  (mi->interp_filters.as_filters.x_filter != MULTITAP_SHARP ||
+                   mi->interp_filters.as_filters.y_filter != MULTITAP_SHARP),
+              cm->features.opfl_refine_type == REFINE_ALL));
+#endif
+
+  // Arrays to hold optical flow offsets.
+  int vx0[N_OF_OFFSETS] = { 0 };
+  int vx1[N_OF_OFFSETS] = { 0 };
+  int vy0[N_OF_OFFSETS] = { 0 };
+  int vy1[N_OF_OFFSETS] = { 0 };
+
+  // Pointers to gradient and dst buffers
+  int16_t *gx0, *gy0, *gx1, *gy1;
+  uint8_t *dst0 = NULL, *dst1 = NULL;
+
+  if (use_optflow_refinement && plane == 0) {
+    // Allocate gradient and dst buffers
+    gx0 = aom_memalign(32, 2 * MAX_SB_SIZE * MAX_SB_SIZE * sizeof(*gx0));
+    gx1 = aom_memalign(32, 2 * MAX_SB_SIZE * MAX_SB_SIZE * sizeof(*gx1));
+    gy0 = gx0 + (MAX_SB_SIZE * MAX_SB_SIZE);
+    gy1 = gx1 + (MAX_SB_SIZE * MAX_SB_SIZE);
+
+    // Initialize refined mv
+    const MV mv0 = mi->mv[0].as_mv;
+    const MV mv1 = mi->mv[1].as_mv;
+    for (int mvi = 0; mvi < N_OF_OFFSETS; mvi++) {
+      mv_refined[mvi * 2].as_mv = mv0;
+      mv_refined[mvi * 2 + 1].as_mv = mv1;
+    }
+    // Refine MV using optical flow. The final output MV will be in 1/16
+    // precision.
+    if (is_cur_buf_hbd(xd)) {
+      dst0 = CONVERT_TO_BYTEPTR(
+          aom_calloc(1, MAX_SB_SIZE * MAX_SB_SIZE * sizeof(uint16_t)));
+      dst1 = CONVERT_TO_BYTEPTR(
+          aom_calloc(1, MAX_SB_SIZE * MAX_SB_SIZE * sizeof(uint16_t)));
+      get_optflow_based_mv_highbd(
+          cm, xd, plane, mi, mv_refined, bw, bh, mi_x, mi_y, mc_buf,
+          calc_subpel_params_func, gx0, gy0, gx1, gy1, vx0, vy0, vx1, vy1,
+          CONVERT_TO_SHORTPTR(dst0), CONVERT_TO_SHORTPTR(dst1));
+      aom_free(CONVERT_TO_SHORTPTR(dst0));
+      aom_free(CONVERT_TO_SHORTPTR(dst1));
+    } else {
+      dst0 =
+          (uint8_t *)aom_calloc(1, MAX_SB_SIZE * MAX_SB_SIZE * sizeof(uint8_t));
+      dst1 =
+          (uint8_t *)aom_calloc(1, MAX_SB_SIZE * MAX_SB_SIZE * sizeof(uint8_t));
+      get_optflow_based_mv_lowbd(cm, xd, plane, mi, mv_refined, bw, bh, mi_x,
+                                 mi_y, mc_buf, calc_subpel_params_func, gx0,
+                                 gy0, gx1, gy1, vx0, vy0, vx1, vy1, dst0, dst1);
+      aom_free(dst0);
+      aom_free(dst1);
+    }
+    aom_free(gx0);
+    aom_free(gx1);
+  }
+#endif  // CONFIG_OPTFLOW_REFINEMENT
+
   for (int ref = 0; ref < 1 + is_compound; ++ref) {
     const struct scale_factors *const sf =
         is_intrabc ? &cm->sf_identity : xd->block_ref_scale_factors[ref];
@@ -947,12 +1950,6 @@
     inter_pred_params.conv_params = get_conv_params_no_round(
         ref, plane, xd->tmp_conv_dst, MAX_SB_SIZE, is_compound, xd->bd);
 
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-    av1_dist_wtd_comp_weight_assign(
-        cm, mi, &inter_pred_params.conv_params.fwd_offset,
-        &inter_pred_params.conv_params.bck_offset, is_compound);
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
-
     if (!build_for_obmc)
       av1_init_warp_params(&inter_pred_params, &warp_types, ref, xd, mi);
 
@@ -971,6 +1968,31 @@
       inter_pred_params.mask_comp.seg_mask = xd->seg_mask;
     }
 
+#if CONFIG_OPTFLOW_REFINEMENT
+    if (use_optflow_refinement && plane == 0) {
+      int n = opfl_get_subblock_size(bw, bh, plane);
+      inter_pred_params.interp_filter_params[0] =
+          av1_get_interp_filter_params_with_block_size(
+#if CONFIG_REMOVE_DUAL_FILTER
+              mi->interp_fltr,
+#else
+              mi->interp_filters.as_filters.x_filter,
+#endif  // CONFIG_REMOVE_DUAL_FILTER
+              n);
+      inter_pred_params.interp_filter_params[1] =
+          av1_get_interp_filter_params_with_block_size(
+#if CONFIG_REMOVE_DUAL_FILTER
+              mi->interp_fltr,
+#else
+              mi->interp_filters.as_filters.y_filter,
+#endif  // CONFIG_REMOVE_DUAL_FILTER
+              n);
+      av1_opfl_rebuild_inter_predictor(dst, dst_buf->stride, plane, mv_refined,
+                                       &inter_pred_params, xd, mi_x, mi_y, ref,
+                                       mc_buf, calc_subpel_params_func);
+      continue;
+    }
+#endif  // CONFIG_OPTFLOW_REFINEMENT
     av1_build_one_inter_predictor(dst, dst_buf->stride, &mv, &inter_pred_params,
                                   xd, mi_x, mi_y, ref, mc_buf,
                                   calc_subpel_params_func);
@@ -978,9 +2000,9 @@
 }
 
 void av1_build_inter_predictors(const AV1_COMMON *cm, MACROBLOCKD *xd,
-                                int plane, const MB_MODE_INFO *mi,
-                                int build_for_obmc, int bw, int bh, int mi_x,
-                                int mi_y, uint8_t **mc_buf,
+                                int plane, MB_MODE_INFO *mi, int build_for_obmc,
+                                int bw, int bh, int mi_x, int mi_y,
+                                uint8_t **mc_buf,
                                 CalcSubpelParamsFunc calc_subpel_params_func) {
 #if CONFIG_SDP
   if (is_sub8x8_inter(xd, plane, mi->sb_type[PLANE_TYPE_Y],
@@ -1073,17 +2095,17 @@
   }
 }
 
-static INLINE void increment_int_ptr(MACROBLOCKD *xd, int rel_mi_row,
-                                     int rel_mi_col, uint8_t op_mi_size,
-                                     int dir, MB_MODE_INFO *mi, void *fun_ctxt,
-                                     const int num_planes) {
+static INLINE void increment_uint8_t_ptr(MACROBLOCKD *xd, int rel_mi_row,
+                                         int rel_mi_col, uint8_t op_mi_size,
+                                         int dir, MB_MODE_INFO *mi,
+                                         void *fun_ctxt, const int num_planes) {
   (void)xd;
   (void)rel_mi_row;
   (void)rel_mi_col;
   (void)op_mi_size;
   (void)dir;
   (void)mi;
-  ++*(int *)fun_ctxt;
+  ++*(uint8_t *)fun_ctxt;
   (void)num_planes;
 }
 
@@ -1098,9 +2120,10 @@
   if (!is_motion_variation_allowed_bsize(mbmi->sb_type)) return;
 #endif
 
-  foreach_overlappable_nb_above(cm, xd, INT_MAX, increment_int_ptr,
+  foreach_overlappable_nb_above(cm, xd, INT_MAX, increment_uint8_t_ptr,
                                 &mbmi->overlappable_neighbors[0]);
-  foreach_overlappable_nb_left(cm, xd, INT_MAX, increment_int_ptr,
+  if (mbmi->overlappable_neighbors[0]) return;
+  foreach_overlappable_nb_left(cm, xd, INT_MAX, increment_uint8_t_ptr,
                                &mbmi->overlappable_neighbors[1]);
 }
 
@@ -1130,7 +2153,11 @@
 }
 
 void av1_modify_neighbor_predictor_for_obmc(MB_MODE_INFO *mbmi) {
+#if CONFIG_NEW_REF_SIGNALING
+  mbmi->ref_frame[1] = INVALID_IDX;
+#else
   mbmi->ref_frame[1] = NONE_FRAME;
+#endif  // CONFIG_NEW_REF_SIGNALING
   mbmi->interinter_comp.type = COMPOUND_AVERAGE;
 
   return;
@@ -1433,12 +2460,7 @@
   av1_predict_intra_block(cm, xd, pd->width, pd->height,
                           max_txsize_rect_lookup[plane_bsize], mode, 0, 0,
                           FILTER_INTRA_MODES, ctx->plane[plane],
-                          ctx->stride[plane], dst, dst_stride, 0, 0,
-#if CONFIG_ORIP
-                          plane, 0);
-#else
-                          plane);
-#endif
+                          ctx->stride[plane], dst, dst_stride, 0, 0, plane);
 }
 
 void av1_combine_interintra(MACROBLOCKD *xd, BLOCK_SIZE bsize, int plane,
diff --git a/av1/common/reconinter.h b/av1/common/reconinter.h
index 6e6ab2c..5bac718 100644
--- a/av1/common/reconinter.h
+++ b/av1/common/reconinter.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_COMMON_RECONINTER_H_
@@ -110,6 +111,14 @@
   const InterpFilterParams *interp_filter_params[2];
   int block_width;
   int block_height;
+#if CONFIG_OPTFLOW_REFINEMENT
+  // In optical flow refinement, block_width and block_height will pass the
+  // subblock size into av1_make_inter_predictor, while orig_block_width and
+  // orig_block_height keep the original block size that is needed by
+  // calc_subpel_params_func
+  int orig_block_width;
+  int orig_block_height;
+#endif  // CONFIG_OPTFLOW_REFINEMENT
   int pix_row;
   int pix_col;
   struct buf_2d ref_frame_buf;
@@ -123,6 +132,69 @@
   int is_intrabc;
 } InterPredParams;
 
+#if CONFIG_OPTFLOW_REFINEMENT
+
+// Apply bilinear and bicubic interpolation for subpel gradient to avoid
+// calls of build_one_inter_predictor function. Bicubic interpolation
+// brings better quality but the speed results are neutral. As such, bilinear
+// interpolation is used by default for a better trade-off between quality
+// and complexity.
+#define OPFL_BILINEAR_GRAD 0
+#define OPFL_BICUBIC_GRAD 1
+
+// Use downsampled gradient arrays to compute MV offsets
+#define OPFL_DOWNSAMP_QUINCUNX 1
+
+// Delta to use for computing gradients in bits, with 0 referring to
+// integer-pel. The actual delta value used from the 1/8-pel original MVs
+// is 2^(3 - SUBPEL_GRAD_DELTA_BITS). The max value of this macro is 3.
+#define SUBPEL_GRAD_DELTA_BITS 3
+
+// Combine computations of interpolated gradients and the least squares
+// solver. The basic idea is that, typically we would compute the following:
+// 1. d0, d1, P0 and P1
+// 2. Gradients of P0 and P1: gx0, gx1, gy0, and gy1
+// 3. Solving least squares for vx and vy, which requires d0*gx0-d1*gx1,
+//    d0*gy0-d1*gy1, and P0-P1.
+// When this flag is turned on, we compute the following
+// 1. d0, d1, P0 and P1
+// 2. tmp0 = d0*P0-d1*P1 and tmp1 = P0-P1
+// 3. Gradients of tmp0: gx and gy
+// 4. Solving least squares for vx and vy using gx, gy and tmp1
+// Note that this only requires 2 gradient operators instead of 4 and thus
+// reduces the complexity. However, it is only feasible when gradients are
+// obtained using bilinear or bicubic interpolation. Thus, this flag should
+// only be on when either of OPFL_BILINEAR_GRAD and OPFL_BICUBIC_GRAD is on.
+#define OPFL_COMBINE_INTERP_GRAD_LS 1
+
+// Bilinear and bicubic coefficients. Note that, at boundary, we apply
+// coefficients that are doubled because spatial distance between the two
+// interpolated pixels is halved. In other words, instead of computing
+//   coeff * (v[delta] - v[-delta]) / (2 * delta),
+// we are practically computing
+//   coeff * (v[delta] - v[0]) / (2 * delta).
+// Thus, coeff is doubled to get a better gradient quality.
+#if OPFL_BILINEAR_GRAD
+static const int bilinear_bits = 3;
+static const int32_t coeffs_bilinear[4][2] = {
+  { 8, 16 },  // delta = 1 (SUBPEL_GRAD_DELTA_BITS = 0)
+  { 4, 8 },   // delta = 0.5 (SUBPEL_GRAD_DELTA_BITS = 1)
+  { 2, 4 },   // delta = 0.25 (SUBPEL_GRAD_DELTA_BITS = 2)
+  { 1, 2 },   // delta = 0.125 (SUBPEL_GRAD_DELTA_BITS = 3)
+};
+#endif
+
+#if OPFL_BICUBIC_GRAD
+static const int bicubic_bits = 7;
+static const int32_t coeffs_bicubic[4][2][2] = {
+  { { 128, 256 }, { 0, 0 } },    // delta = 1 (SUBPEL_GRAD_DELTA_BITS = 0)
+  { { 80, 160 }, { -8, -16 } },  // delta = 0.5 (SUBPEL_GRAD_DELTA_BITS = 1)
+  { { 42, 84 }, { -5, -10 } },   // delta = 0.25 (SUBPEL_GRAD_DELTA_BITS = 2)
+  { { 21, 42 }, { -3, -6 } },    // delta = 0.125 (SUBPEL_GRAD_DELTA_BITS = 3)
+};
+#endif
+#endif  // CONFIG_OPTFLOW_REFINEMENT
+
 void av1_init_inter_params(InterPredParams *inter_pred_params, int block_width,
                            int block_height, int pix_row, int pix_col,
                            int subsampling_x, int subsampling_y, int bit_depth,
@@ -207,9 +279,6 @@
   const int comp_allowed = is_comp_ref_allowed(sb_type);
   switch (type) {
     case COMPOUND_AVERAGE:
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-    case COMPOUND_DISTWTD:
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
     case COMPOUND_DIFFWTD: return comp_allowed;
     case COMPOUND_WEDGE:
       return comp_allowed && av1_wedge_params_lookup[sb_type].wedge_types > 0;
@@ -246,7 +315,11 @@
 typedef void (*CalcSubpelParamsFunc)(const MV *const src_mv,
                                      InterPredParams *const inter_pred_params,
                                      MACROBLOCKD *xd, int mi_x, int mi_y,
-                                     int ref, uint8_t **mc_buf, uint8_t **pre,
+                                     int ref,
+#if CONFIG_OPTFLOW_REFINEMENT
+                                     int use_optflow_refinement,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
+                                     uint8_t **mc_buf, uint8_t **pre,
                                      SubpelParams *subpel_params,
                                      int *src_stride);
 
@@ -256,14 +329,129 @@
     int ref, uint8_t **mc_buf, CalcSubpelParamsFunc calc_subpel_params_func);
 
 void av1_build_inter_predictors(const AV1_COMMON *cm, MACROBLOCKD *xd,
-                                int plane, const MB_MODE_INFO *mi,
-                                int build_for_obmc, int bw, int bh, int mi_x,
-                                int mi_y, uint8_t **mc_buf,
+                                int plane, MB_MODE_INFO *mi, int build_for_obmc,
+                                int bw, int bh, int mi_x, int mi_y,
+                                uint8_t **mc_buf,
                                 CalcSubpelParamsFunc calc_subpel_params_func);
 
+#if CONFIG_OPTFLOW_REFINEMENT
+// This parameter k=OPFL_DIST_RATIO_THR is used to prune MV refinement for the
+// case where d0 and d1 are very different. Assuming a = max(|d0|, |d1|) and
+// b = min(|d0|, |d1|), MV refinement will only be allowed only if a/b <= k.
+// If k is set to 0, refinement will always be enabled.
+// If k is set to 1, refinement will only be enabled when |d0|=|d1|.
+#define OPFL_DIST_RATIO_THR 0
+
+// Apply regularized least squares (RLS). The RLS parameter is bw * bh * 2^(b-4)
+// where b = OPFL_RLS_PARAM_BITS.
+#define OPFL_REGULARIZED_LS 1
+#define OPFL_RLS_PARAM_BITS 4
+
+// Number of bits allowed for covariance matrix elements (su2, sv2, suv, suw
+// and svw) so that det, det_x, and det_y does not cause overflow issue in
+// int64_t. Its value must be <= (64 - mv_prec_bits - grad_prec_bits) / 2.
+#define OPFL_COV_CLAMP_BITS 28
+#define OPFL_COV_CLAMP_VAL (1 << OPFL_COV_CLAMP_BITS)
+
+// Precision of refined MV returned, 0 being integer pel. For now, only 1/8 or
+// 1/16-pel can be used.
+#define MV_REFINE_PREC_BITS 4  // (1/16-pel)
+void av1_opfl_mv_refinement_lowbd(const uint8_t *p0, int pstride0,
+                                  const uint8_t *p1, int pstride1,
+                                  const int16_t *gx0, const int16_t *gy0,
+                                  const int16_t *gx1, const int16_t *gy1,
+                                  int gstride, int bw, int bh, int d0, int d1,
+                                  int grad_prec_bits, int mv_prec_bits,
+                                  int *vx0, int *vy0, int *vx1, int *vy1);
+void av1_opfl_mv_refinement_highbd(const uint16_t *p0, int pstride0,
+                                   const uint16_t *p1, int pstride1,
+                                   const int16_t *gx0, const int16_t *gy0,
+                                   const int16_t *gx1, const int16_t *gy1,
+                                   int gstride, int bw, int bh, int d0, int d1,
+                                   int grad_prec_bits, int mv_prec_bits,
+                                   int *vx0, int *vy0, int *vx1, int *vy1);
+static INLINE int is_opfl_refine_allowed(const AV1_COMMON *cm,
+                                         const MB_MODE_INFO *mbmi) {
+  if (cm->seq_params.enable_opfl_refine == AOM_OPFL_REFINE_NONE ||
+      cm->features.opfl_refine_type == REFINE_NONE)
+    return 0;
+  if (!mbmi->ref_frame[1]) return 0;
+  const unsigned int cur_index = cm->cur_frame->order_hint;
+  const RefCntBuffer *const ref0 = get_ref_frame_buf(cm, mbmi->ref_frame[0]);
+  const RefCntBuffer *const ref1 = get_ref_frame_buf(cm, mbmi->ref_frame[1]);
+  const int d0 = (int)cur_index - (int)ref0->order_hint;
+  const int d1 = (int)cur_index - (int)ref1->order_hint;
+  if (!((d0 <= 0) ^ (d1 <= 0))) return 0;
+
+  return OPFL_DIST_RATIO_THR == 0 ||
+         (AOMMAX(abs(d0), abs(d1)) <=
+          OPFL_DIST_RATIO_THR * AOMMIN(abs(d0), abs(d1)));
+}
+
+// Integer division based on lookup table.
+// num: numerator
+// den: denominator
+// out: output result (num / den)
+static INLINE int32_t divide_and_round_signed(int64_t num, int64_t den) {
+  if (llabs(den) == 1) return (int32_t)(den < 0 ? -num : num);
+  const int optflow_prec_bits = 16;
+  int16_t shift;
+  const int sign_den = (den < 0 ? -1 : 1);
+  uint16_t inverse_den = resolve_divisor_64(llabs(den), &shift);
+  shift -= optflow_prec_bits;
+  if (shift < 0) {
+    inverse_den <<= (-shift);
+    shift = 0;
+  }
+  int32_t out;
+  // Make sure 1) the bits for right shift is < 63 and 2) the bit depth
+  // of num is < 48 to avoid overflow in num * inverse_den
+  if (optflow_prec_bits + shift >= 63 ||
+      ROUND_POWER_OF_TWO_SIGNED_64(num, 63 - optflow_prec_bits) != 0) {
+    int64_t out_tmp = ROUND_POWER_OF_TWO_SIGNED_64(num, optflow_prec_bits);
+    out = (int32_t)ROUND_POWER_OF_TWO_SIGNED_64(
+        out_tmp * (int64_t)inverse_den * sign_den, shift);
+  } else {
+    out = (int32_t)ROUND_POWER_OF_TWO_SIGNED_64(
+        num * (int64_t)inverse_den * sign_den, optflow_prec_bits + shift);
+  }
+#ifndef NDEBUG
+  // Verify that the result is consistent with built-in division.
+  // Quick overflow check
+  int32_t out_div = (llabs(num) + llabs(den) < 0)
+                        ? (int32_t)DIVIDE_AND_ROUND_SIGNED(
+                              ROUND_POWER_OF_TWO_SIGNED_64(num, 2),
+                              ROUND_POWER_OF_TWO_SIGNED_64(den, 2))
+                        : (int32_t)DIVIDE_AND_ROUND_SIGNED(num, den);
+  // check if error is at most 1 at usable values of out_div
+  if (abs(out_div - out) > 1 && abs(out_div) <= 64) {
+    printf("Warning: num = %" PRId64 ", den = %" PRId64
+           ", inverse_den = %d, shift = %d, v0 = %d, v = %d\n",
+           num, den, inverse_den, shift, out_div, out);
+  }
+#endif  // NDEBUG
+  return out;
+}
+
+// Return 1 if current frame is REFINE_ALL and the current block uses optical
+// flow refinement, i.e., inter mode is in {NEAR_NEARMV, NEAR_NEWMV,
+// NEW_NEARMV, NEW_NEWMV}, and compound type is simple compound average.
+static INLINE int use_opfl_refine_all(const AV1_COMMON *cm,
+                                      const MB_MODE_INFO *mbmi) {
+  return cm->features.opfl_refine_type == REFINE_ALL &&
+         mbmi->mode >= COMP_INTER_MODE_START &&
+         mbmi->mode < COMP_OPTFLOW_MODE_START &&
+         mbmi->mode != GLOBAL_GLOBALMV &&
+         mbmi->interinter_comp.type == COMPOUND_AVERAGE;
+}
+#endif  // CONFIG_OPTFLOW_REFINEMENT
+
 // TODO(jkoleszar): yet another mv clamping function :-(
 static INLINE MV clamp_mv_to_umv_border_sb(const MACROBLOCKD *xd,
                                            const MV *src_mv, int bw, int bh,
+#if CONFIG_OPTFLOW_REFINEMENT
+                                           int use_optflow_refinement,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
                                            int ss_x, int ss_y) {
   // If the MV points so far into the UMV border that no visible pixels
   // are used for reconstruction, the subpel part of the MV can be
@@ -272,8 +460,23 @@
   const int spel_right = spel_left - SUBPEL_SHIFTS;
   const int spel_top = (AOM_INTERP_EXTEND + bh) << SUBPEL_BITS;
   const int spel_bottom = spel_top - SUBPEL_SHIFTS;
+#if CONFIG_OPTFLOW_REFINEMENT
+  MV clamped_mv;
+  if (use_optflow_refinement) {
+    // optflow refinement always returns MVs with 1/16 precision so it is not
+    // necessary to shift the MV before clamping
+    clamped_mv.row = (int16_t)ROUND_POWER_OF_TWO_SIGNED(
+        src_mv->row * (1 << SUBPEL_BITS), MV_REFINE_PREC_BITS + ss_y);
+    clamped_mv.col = (int16_t)ROUND_POWER_OF_TWO_SIGNED(
+        src_mv->col * (1 << SUBPEL_BITS), MV_REFINE_PREC_BITS + ss_x);
+  } else {
+    clamped_mv.row = (int16_t)(src_mv->row * (1 << (1 - ss_y)));
+    clamped_mv.col = (int16_t)(src_mv->col * (1 << (1 - ss_x)));
+  }
+#else
   MV clamped_mv = { (int16_t)(src_mv->row * (1 << (1 - ss_y))),
                     (int16_t)(src_mv->col * (1 << (1 - ss_x))) };
+#endif  // CONFIG_OPTFLOW_REFINEMENT
   assert(ss_x <= 1);
   assert(ss_y <= 1);
   const SubpelMvLimits mv_limits = {
@@ -327,18 +530,42 @@
                           const struct scale_factors *sf, const int num_planes);
 
 static INLINE void set_default_interp_filters(
-    MB_MODE_INFO *const mbmi, InterpFilter frame_interp_filter) {
+    MB_MODE_INFO *const mbmi,
+#if CONFIG_OPTFLOW_REFINEMENT
+    const AV1_COMMON *cm,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
+    InterpFilter frame_interp_filter) {
+#if CONFIG_OPTFLOW_REFINEMENT
+#if CONFIG_REMOVE_DUAL_FILTER
+  mbmi->interp_fltr = (mbmi->mode > NEW_NEWMV || use_opfl_refine_all(cm, mbmi))
+                          ? MULTITAP_SHARP
+                          : av1_unswitchable_filter(frame_interp_filter);
+#else
+  mbmi->interp_filters =
+      (mbmi->mode > NEW_NEWMV || use_opfl_refine_all(cm, mbmi))
+          ? av1_broadcast_interp_filter(av1_unswitchable_filter(MULTITAP_SHARP))
+          : av1_broadcast_interp_filter(
+                av1_unswitchable_filter(frame_interp_filter));
+#endif  // CONFIG_REMOVE_DUAL_FILTER
+#else
 #if CONFIG_REMOVE_DUAL_FILTER
   mbmi->interp_fltr = av1_unswitchable_filter(frame_interp_filter);
 #else
   mbmi->interp_filters =
       av1_broadcast_interp_filter(av1_unswitchable_filter(frame_interp_filter));
 #endif  // CONFIG_REMOVE_DUAL_FILTER
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 }
 
-static INLINE int av1_is_interp_needed(const MACROBLOCKD *const xd) {
+static INLINE int av1_is_interp_needed(const AV1_COMMON *const cm,
+                                       const MACROBLOCKD *const xd) {
+  (void)cm;
   const MB_MODE_INFO *const mbmi = xd->mi[0];
   if (mbmi->skip_mode) return 0;
+#if CONFIG_OPTFLOW_REFINEMENT
+  // No interpolation filter search when optical flow MV refinement is used.
+  if (mbmi->mode > NEW_NEWMV || use_opfl_refine_all(cm, mbmi)) return 0;
+#endif  // CONFIG_OPTFLOW_REFINEMENT
   if (mbmi->motion_mode == WARPED_CAUSAL) return 0;
   if (is_nontrans_global_motion(xd, xd->mi[0])) return 0;
   return 1;
@@ -378,12 +605,6 @@
   return av1_wedge_params_lookup[sb_type].masks[wedge_sign][wedge_index];
 }
 
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-void av1_dist_wtd_comp_weight_assign(const AV1_COMMON *cm,
-                                     const MB_MODE_INFO *mbmi, int *fwd_offset,
-                                     int *bck_offset, int is_compound);
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
-
 const uint8_t *av1_get_compound_type_mask(
     const INTERINTER_COMPOUND_DATA *const comp_data, BLOCK_SIZE sb_type);
 
diff --git a/av1/common/reconintra.c b/av1/common/reconintra.c
index 73197b8..0c24219 100644
--- a/av1/common/reconintra.c
+++ b/av1/common/reconintra.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <math.h>
@@ -464,12 +465,18 @@
 
 static intra_pred_fn pred[INTRA_MODES][TX_SIZES_ALL];
 static intra_pred_fn dc_pred[2][2][TX_SIZES_ALL];
+#if CONFIG_IBP_DC
+static intra_pred_fn ibp_dc_pred[2][2][TX_SIZES_ALL];
+#endif
 
 typedef void (*intra_high_pred_fn)(uint16_t *dst, ptrdiff_t stride,
                                    const uint16_t *above, const uint16_t *left,
                                    int bd);
 static intra_high_pred_fn pred_high[INTRA_MODES][TX_SIZES_ALL];
 static intra_high_pred_fn dc_pred_high[2][2][TX_SIZES_ALL];
+#if CONFIG_IBP_DC
+static intra_high_pred_fn ibp_dc_pred_high[2][2][TX_SIZES_ALL];
+#endif
 
 static void init_intra_predictors_internal(void) {
   assert(NELEMENTS(mode_to_angle_map) == INTRA_MODES);
@@ -511,6 +518,12 @@
   INIT_ALL_SIZES(dc_pred[0][1], dc_top);
   INIT_ALL_SIZES(dc_pred[1][0], dc_left);
   INIT_ALL_SIZES(dc_pred[1][1], dc);
+#if CONFIG_IBP_DC
+  INIT_ALL_SIZES(ibp_dc_pred[0][0], dc_128);
+  INIT_ALL_SIZES(ibp_dc_pred[0][1], ibp_dc_top);
+  INIT_ALL_SIZES(ibp_dc_pred[1][0], ibp_dc_left);
+  INIT_ALL_SIZES(ibp_dc_pred[1][1], ibp_dc);
+#endif
   INIT_ALL_SIZES(pred_high[V_PRED], highbd_v);
   INIT_ALL_SIZES(pred_high[H_PRED], highbd_h);
   INIT_ALL_SIZES(pred_high[PAETH_PRED], highbd_paeth);
@@ -521,9 +534,179 @@
   INIT_ALL_SIZES(dc_pred_high[0][1], highbd_dc_top);
   INIT_ALL_SIZES(dc_pred_high[1][0], highbd_dc_left);
   INIT_ALL_SIZES(dc_pred_high[1][1], highbd_dc);
+#if CONFIG_IBP_DC
+  INIT_ALL_SIZES(ibp_dc_pred_high[0][0], highbd_dc_128);
+  INIT_ALL_SIZES(ibp_dc_pred_high[0][1], highbd_ibp_dc_top);
+  INIT_ALL_SIZES(ibp_dc_pred_high[1][0], highbd_ibp_dc_left);
+  INIT_ALL_SIZES(ibp_dc_pred_high[1][1], highbd_ibp_dc);
+#endif
 #undef intra_pred_allsizes
 }
 
+#if CONFIG_AIMC
+// get the context for y_mode_idx
+// the context of y_mode_idx depends on the count of directional neighboring
+// modes
+int get_y_mode_idx_ctx(MACROBLOCKD *const xd) {
+  const PREDICTION_MODE above_joint_mode =
+      av1_get_joint_mode(xd->above_right_mbmi);
+  const PREDICTION_MODE left_joint_mode =
+      av1_get_joint_mode(xd->bottom_left_mbmi);
+  const int is_above_angular =
+      above_joint_mode >= NON_DIRECTIONAL_MODES_COUNT ? 1 : 0;
+  const int is_left_angular =
+      left_joint_mode >= NON_DIRECTIONAL_MODES_COUNT ? 1 : 0;
+  return is_above_angular + is_left_angular;
+}
+/*! \brief set the luma intra mode and delta angles for a given mode index.
+ * \param[in]    mode_idx           mode index in intra mode decision
+ *                                  process.
+ * \param[in]    mbmi               Pointer to structure holding
+ *                                  the mode info for the current macroblock.
+ */
+void set_y_mode_and_delta_angle(const int mode_idx, MB_MODE_INFO *const mbmi) {
+  if (mode_idx < NON_DIRECTIONAL_MODES_COUNT) {
+    mbmi->mode = mode_idx;
+    mbmi->angle_delta[PLANE_TYPE_Y] = 0;
+  } else {
+    mbmi->mode =
+        (mode_idx - NON_DIRECTIONAL_MODES_COUNT) / TOTAL_ANGLE_DELTA_COUNT +
+        NON_DIRECTIONAL_MODES_COUNT;
+    mbmi->angle_delta[PLANE_TYPE_Y] =
+        (mode_idx - NON_DIRECTIONAL_MODES_COUNT) % TOTAL_ANGLE_DELTA_COUNT -
+        MAX_ANGLE_DELTA;
+  }
+  mbmi->mode = reordered_y_mode[mbmi->mode];
+}
+
+// re-order the intra prediction modes for y component based
+// on the neighboring intra prediction modes. The intra prediction
+// mode list for 4x4, 4x8, and 8x4 blocks are fixed, and not dependent
+// on the intra prediction modes of neighboring blocks
+void get_y_intra_mode_set(MB_MODE_INFO *mi, MACROBLOCKD *const xd) {
+  int neighbor_joint_modes[2];
+  neighbor_joint_modes[0] = av1_get_joint_mode(xd->bottom_left_mbmi);
+  neighbor_joint_modes[1] = av1_get_joint_mode(xd->above_right_mbmi);
+  const int is_left_directional_mode =
+      neighbor_joint_modes[0] >= NON_DIRECTIONAL_MODES_COUNT ? 1 : 0;
+  const int is_above_directional_mode =
+      neighbor_joint_modes[1] >= NON_DIRECTIONAL_MODES_COUNT ? 1 : 0;
+  // To mark whether each intra prediction mode is added into intra mode list or
+  // not
+  int is_mode_selected_list[LUMA_MODE_COUNT];
+
+  const int is_small_block = (mi->sb_type[PLANE_TYPE_Y] < BLOCK_8X8);
+
+  int i, j;
+  int mode_idx = 0;
+  for (i = 0; i < LUMA_MODE_COUNT; i++) {
+    is_mode_selected_list[i] = -1;
+    mi->y_intra_mode_list[i] = -1;
+  }
+
+  // always put non-directional modes into the first positions of the mode list
+  for (i = 0; i < NON_DIRECTIONAL_MODES_COUNT; ++i) {
+    mi->y_intra_mode_list[mode_idx++] = i;
+    is_mode_selected_list[i] = 1;
+  }
+
+  if (is_small_block == 0) {
+    int directional_mode_cnt =
+        is_above_directional_mode + is_left_directional_mode;
+    if (directional_mode_cnt == 2 &&
+        neighbor_joint_modes[0] == neighbor_joint_modes[1])
+      directional_mode_cnt = 1;
+    // copy above mode to left mode, if left mode is non-directiona mode and
+    // above mode is directional mode
+    if (directional_mode_cnt == 1 && is_left_directional_mode == 0) {
+      neighbor_joint_modes[0] = neighbor_joint_modes[1];
+    }
+    for (i = 0; i < directional_mode_cnt; ++i) {
+      mi->y_intra_mode_list[mode_idx++] = neighbor_joint_modes[i];
+      is_mode_selected_list[neighbor_joint_modes[i]] = 1;
+    }
+
+    // Add offsets to derive the neighboring modes
+    for (i = 0; i < 4; ++i) {
+      for (j = 0; j < directional_mode_cnt; ++j) {
+        int left_derived_ode = (neighbor_joint_modes[j] - i +
+                                (56 - NON_DIRECTIONAL_MODES_COUNT - 1)) %
+                                   56 +
+                               NON_DIRECTIONAL_MODES_COUNT;
+        int right_derived_mode =
+            (neighbor_joint_modes[j] + i - (NON_DIRECTIONAL_MODES_COUNT - 1)) %
+                56 +
+            NON_DIRECTIONAL_MODES_COUNT;
+
+        if (is_mode_selected_list[left_derived_ode] == -1) {
+          mi->y_intra_mode_list[mode_idx++] = left_derived_ode;
+          is_mode_selected_list[left_derived_ode] = 1;
+        }
+        if (is_mode_selected_list[right_derived_mode] == -1) {
+          mi->y_intra_mode_list[mode_idx++] = right_derived_mode;
+          is_mode_selected_list[right_derived_mode] = 1;
+        }
+      }
+    }
+  }
+
+  // fill the remaining list with default modes
+  for (i = 0; i < LUMA_MODE_COUNT - NON_DIRECTIONAL_MODES_COUNT &&
+              mode_idx < LUMA_MODE_COUNT;
+       ++i) {
+    if (is_mode_selected_list[default_mode_list_y[i] +
+                              NON_DIRECTIONAL_MODES_COUNT] == -1) {
+      mi->y_intra_mode_list[mode_idx++] =
+          default_mode_list_y[i] + NON_DIRECTIONAL_MODES_COUNT;
+      is_mode_selected_list[default_mode_list_y[i] +
+                            NON_DIRECTIONAL_MODES_COUNT] = 1;
+    }
+  }
+}
+
+// re-order the intra prediction mode of uv component based on the
+// intra prediction mode of co-located y block
+void get_uv_intra_mode_set(MB_MODE_INFO *mi) {
+  int is_mode_selected_list[UV_INTRA_MODES];
+  int i;
+  int mode_idx = 0;
+  for (i = 0; i < UV_INTRA_MODES; i++) {
+    is_mode_selected_list[i] = -1;
+    mi->uv_intra_mode_list[i] = -1;
+  }
+  // check whether co-located y mode is directional mode or not
+  if (av1_is_directional_mode(mi->mode)) {
+    mi->uv_intra_mode_list[mode_idx++] = mi->mode;
+    is_mode_selected_list[mi->mode] = 1;
+  }
+
+  // put non-directional modes into the mode list
+  mi->uv_intra_mode_list[mode_idx++] = UV_DC_PRED;
+  is_mode_selected_list[UV_DC_PRED] = 1;
+  mi->uv_intra_mode_list[mode_idx++] = UV_SMOOTH_PRED;
+  is_mode_selected_list[UV_SMOOTH_PRED] = 1;
+  mi->uv_intra_mode_list[mode_idx++] = UV_SMOOTH_V_PRED;
+  is_mode_selected_list[UV_SMOOTH_V_PRED] = 1;
+  mi->uv_intra_mode_list[mode_idx++] = UV_SMOOTH_H_PRED;
+  is_mode_selected_list[UV_SMOOTH_H_PRED] = 1;
+  mi->uv_intra_mode_list[mode_idx++] = UV_PAETH_PRED;
+  is_mode_selected_list[UV_PAETH_PRED] = 1;
+
+  // fill the remaining list with default modes
+  const int directional_mode_count = DIR_MODE_END - DIR_MODE_START;
+  for (i = 0; i < directional_mode_count; ++i) {
+    if (is_mode_selected_list[default_mode_list_uv[i]] == -1) {
+      mi->uv_intra_mode_list[mode_idx++] = default_mode_list_uv[i];
+      is_mode_selected_list[default_mode_list_uv[i]] = 1;
+    }
+  }
+
+  // put cfl mode into the mode list
+  mi->uv_intra_mode_list[mode_idx++] = UV_CFL_PRED;
+  is_mode_selected_list[UV_CFL_PRED] = 1;
+}
+#endif  // CONFIG_AIMC
+
 // Directional prediction, zone 1: 0 < angle < 90
 void av1_dr_prediction_z1_c(uint8_t *dst, ptrdiff_t stride, int bw, int bh,
                             const uint8_t *above, const uint8_t *left,
@@ -718,7 +901,38 @@
     pred[H_PRED][tx_size](dst, stride, above, left);
   }
 }
+#if CONFIG_IBP_DIR
+// Generate the second directional predictor for IBP
+static void second_dr_predictor(uint8_t *dst, ptrdiff_t stride, TX_SIZE tx_size,
+                                const uint8_t *above, const uint8_t *left,
+                                int upsample_above, int upsample_left,
+                                int angle) {
+  const int bw = tx_size_wide[tx_size];
+  const int bh = tx_size_high[tx_size];
 
+  if (angle > 0 && angle < 90) {
+    int dy = second_dr_intra_derivative[angle];
+    int dx = 1;
+#if CONFIG_MRLS
+    av1_dr_prediction_z3(dst, stride, bw, bh, above, left, upsample_left, dx,
+                         dy, 0);
+#else
+    av1_dr_prediction_z3(dst, stride, bw, bh, above, left, upsample_left, dx,
+                         dy);
+#endif
+  } else if (angle > 180 && angle < 270) {
+    int dx = second_dr_intra_derivative[270 - angle];
+    int dy = 1;
+#if CONFIG_MRLS
+    av1_dr_prediction_z1(dst, stride, bw, bh, above, left, upsample_above, dx,
+                         dy, 0);
+#else
+    av1_dr_prediction_z1(dst, stride, bw, bh, above, left, upsample_above, dx,
+                         dy);
+#endif
+  }
+}
+#endif
 // Directional prediction, zone 1: 0 < angle < 90
 void av1_highbd_dr_prediction_z1_c(uint16_t *dst, ptrdiff_t stride, int bw,
                                    int bh, const uint16_t *above,
@@ -921,7 +1135,38 @@
     pred_high[H_PRED][tx_size](dst, stride, above, left, bd);
   }
 }
+#if CONFIG_IBP_DIR
+// Generate the second directional predictor for IBP
+static void highbd_second_dr_predictor(uint16_t *dst, ptrdiff_t stride,
+                                       TX_SIZE tx_size, const uint16_t *above,
+                                       const uint16_t *left, int upsample_above,
+                                       int upsample_left, int angle, int bd) {
+  const int bw = tx_size_wide[tx_size];
+  const int bh = tx_size_high[tx_size];
 
+  if (angle > 0 && angle < 90) {
+    int dy = second_dr_intra_derivative[angle];
+    int dx = 1;
+#if CONFIG_MRLS
+    av1_highbd_dr_prediction_z3(dst, stride, bw, bh, above, left, upsample_left,
+                                dx, dy, bd, 0);
+#else
+    av1_highbd_dr_prediction_z3(dst, stride, bw, bh, above, left, upsample_left,
+                                dx, dy, bd);
+#endif
+  } else if (angle > 180 && angle < 270) {
+    int dx = second_dr_intra_derivative[270 - angle];
+    int dy = 1;
+#if CONFIG_MRLS
+    av1_highbd_dr_prediction_z1(dst, stride, bw, bh, above, left,
+                                upsample_above, dx, dy, bd, 0);
+#else
+    av1_highbd_dr_prediction_z1(dst, stride, bw, bh, above, left,
+                                upsample_above, dx, dy, bd);
+#endif
+  }
+}
+#endif
 DECLARE_ALIGNED(16, const int8_t,
                 av1_filter_intra_taps[FILTER_INTRA_MODES][8][8]) = {
   {
@@ -1264,7 +1509,79 @@
     p[2 * i] = in[i + 2];
   }
 }
+#if CONFIG_IBP_DIR
+void av1_highbd_ibp_dr_prediction_z1_c(uint8_t *weights, uint16_t *dst,
+                                       ptrdiff_t stride, uint16_t *second_pred,
+                                       ptrdiff_t second_stride, int bw,
+                                       int bh) {
+  int r, c;
+  for (r = 0; r < bh; ++r) {
+    for (c = 0; c < bw; ++c) {
+      dst[c] = ROUND_POWER_OF_TWO(
+          dst[c] * weights[c] + second_pred[c] * (IBP_WEIGHT_MAX - weights[c]),
+          IBP_WEIGHT_SHIFT);
+    }
+    weights += bw;
+    dst += stride;
+    second_pred += second_stride;
+  }
+}
 
+void av1_highbd_ibp_dr_prediction_z3_c(uint8_t *weights, uint16_t *dst,
+                                       ptrdiff_t stride, uint16_t *second_pred,
+                                       ptrdiff_t second_stride, int bw,
+                                       int bh) {
+  int r, c;
+  for (c = 0; c < bw; ++c) {
+    uint16_t *tmp_dst = dst + c;
+    uint16_t *tmp_second = second_pred + c;
+    for (r = 0; r < bh; ++r) {
+      tmp_dst[0] =
+          ROUND_POWER_OF_TWO(tmp_dst[0] * weights[r] +
+                                 tmp_second[0] * (IBP_WEIGHT_MAX - weights[r]),
+                             IBP_WEIGHT_SHIFT);
+      tmp_dst += stride;
+      tmp_second += second_stride;
+    }
+    weights += bh;
+  }
+}
+
+void av1_ibp_dr_prediction_z1_c(uint8_t *weights, uint8_t *dst,
+                                ptrdiff_t stride, uint8_t *second_pred,
+                                ptrdiff_t second_stride, int bw, int bh) {
+  int r, c;
+  for (r = 0; r < bh; ++r) {
+    for (c = 0; c < bw; ++c) {
+      dst[c] = ROUND_POWER_OF_TWO(
+          dst[c] * weights[c] + second_pred[c] * (IBP_WEIGHT_MAX - weights[c]),
+          IBP_WEIGHT_SHIFT);
+    }
+    weights += bw;
+    dst += stride;
+    second_pred += second_stride;
+  }
+}
+
+void av1_ibp_dr_prediction_z3_c(uint8_t *weights, uint8_t *dst,
+                                ptrdiff_t stride, uint8_t *second_pred,
+                                ptrdiff_t second_stride, int bw, int bh) {
+  int r, c;
+  for (c = 0; c < bw; ++c) {
+    uint8_t *tmp_dst = dst + c;
+    uint8_t *tmp_second = second_pred + c;
+    for (r = 0; r < bh; ++r) {
+      tmp_dst[0] =
+          ROUND_POWER_OF_TWO(tmp_dst[0] * weights[r] +
+                                 tmp_second[0] * (IBP_WEIGHT_MAX - weights[r]),
+                             IBP_WEIGHT_SHIFT);
+      tmp_dst += stride;
+      tmp_second += second_stride;
+    }
+    weights += bh;
+  }
+}
+#endif
 static void build_intra_predictors_high(
     const MACROBLOCKD *xd, const uint8_t *ref8, int ref_stride, uint8_t *dst8,
     int dst_stride, PREDICTION_MODE mode, int angle_delta,
@@ -1277,15 +1594,25 @@
 #endif
 #if CONFIG_ORIP
     ,
-    const int disable_intra_pred_filter_for_hor_ver_mode,
     const int seq_intra_pred_filter_flag
 #endif
+#if CONFIG_IBP_DIR || CONFIG_IBP_DC
+    ,
+    const int seq_ibp_flag
+#endif
+#if CONFIG_IBP_DIR
+    ,
+    uint8_t *const ibp_weights[TX_SIZES_ALL][DIR_MODES_0_90]
+#endif
 ) {
   int i;
   uint16_t *dst = CONVERT_TO_SHORTPTR(dst8);
   uint16_t *ref = CONVERT_TO_SHORTPTR(ref8);
   DECLARE_ALIGNED(16, uint16_t, left_data[NUM_INTRA_NEIGHBOUR_PIXELS]);
   DECLARE_ALIGNED(16, uint16_t, above_data[NUM_INTRA_NEIGHBOUR_PIXELS]);
+#if CONFIG_IBP_DIR
+  DECLARE_ALIGNED(16, uint16_t, second_pred_data[MAX_TX_SQUARE + 32]);
+#endif
 #if CONFIG_MRLS
   uint16_t *const above_row = above_data + 32;
   uint16_t *const left_col = left_data + 32;
@@ -1293,6 +1620,9 @@
   uint16_t *const above_row = above_data + 16;
   uint16_t *const left_col = left_data + 16;
 #endif
+#if CONFIG_IBP_DIR
+  uint16_t *const second_pred = second_pred_data + 16;
+#endif
   const int txwpx = tx_size_wide[tx_size];
   const int txhpx = tx_size_high[tx_size];
   int need_left = extend_modes[mode] & NEED_LEFT;
@@ -1350,11 +1680,15 @@
       need_above = 1, need_left = 1, need_above_left = 1;
     else
       need_above = 0, need_left = 1, need_above_left = 1;
+#if CONFIG_IBP_DIR
+    if (seq_ibp_flag) {
+      need_above = 1, need_left = 1, need_above_left = 1;
+    }
+#endif
 
-#if CONFIG_ORIP
+#if CONFIG_ORIP && !CONFIG_ORIP_NONDC_DISABLED
     if (apply_sub_block_based_refinement_filter &&
-        (p_angle == 90 || p_angle == 180) &&
-        !disable_intra_pred_filter_for_hor_ver_mode) {
+        (p_angle == 90 || p_angle == 180)) {
       need_above = 1;
       need_left = 1;
       need_above_left = 1;
@@ -1386,7 +1720,13 @@
   if (need_left) {
     int need_bottom = extend_modes[mode] & NEED_BOTTOMLEFT;
     if (use_filter_intra) need_bottom = 0;
+#if CONFIG_IBP_DIR
+    if (is_dr_mode)
+      need_bottom =
+          seq_ibp_flag ? (p_angle < 90) || (p_angle > 180) : p_angle > 180;
+#else
     if (is_dr_mode) need_bottom = p_angle > 180;
+#endif
 #if CONFIG_MRLS
     const int num_left_pixels_needed =
         txhpx + (need_bottom ? txwpx : 3) + (mrl_index << 1);
@@ -1412,7 +1752,13 @@
   if (need_above) {
     int need_right = extend_modes[mode] & NEED_ABOVERIGHT;
     if (use_filter_intra) need_right = 0;
+#if CONFIG_IBP_DIR
+    if (is_dr_mode)
+      need_right =
+          seq_ibp_flag ? (p_angle < 90) || (p_angle > 180) : p_angle < 90;
+#else
     if (is_dr_mode) need_right = p_angle < 90;
+#endif
 #if CONFIG_MRLS
     const int num_top_pixels_needed =
         txwpx + (need_right ? txhpx : 0) + (mrl_index << 1);
@@ -1482,35 +1828,76 @@
 #else
     if (!disable_edge_filter) {
 #endif
+#if CONFIG_IBP_DIR
+      int need_right = p_angle < 90;
+      int need_bottom = p_angle > 180;
+      int filt_type_above = get_filt_type(xd, plane);
+      int filt_type_left = filt_type_above;
+      int angle_above = p_angle - 90;
+      int angle_left = p_angle - 180;
+      if (seq_ibp_flag) {
+        need_right |= p_angle > 180;
+        need_bottom |= p_angle < 90;
+        const MB_MODE_INFO *ab =
+            (plane == 0) ? xd->above_mbmi : xd->chroma_above_mbmi;
+        const MB_MODE_INFO *le =
+            (plane == 0) ? xd->left_mbmi : xd->chroma_left_mbmi;
+        filt_type_above = ab ? is_smooth(ab, plane) : 0;
+        filt_type_left = le ? is_smooth(le, plane) : 0;
+        angle_above = p_angle > 180 ? (p_angle - 180 - 90) : angle_above;
+        angle_left = p_angle < 90 ? p_angle : angle_left;
+      }
+#else
       const int need_right = p_angle < 90;
       const int need_bottom = p_angle > 180;
       const int filt_type = get_filt_type(xd, plane);
+#endif
       if (p_angle != 90 && p_angle != 180) {
         const int ab_le = need_above_left ? 1 : 0;
         if (need_above && need_left && (txwpx + txhpx >= 24)) {
           filter_intra_edge_corner_high(above_row, left_col);
         }
         if (need_above && n_top_px > 0) {
+#if CONFIG_IBP_DIR
+          const int strength = intra_edge_filter_strength(
+              txwpx, txhpx, angle_above, filt_type_above);
+#else
           const int strength =
               intra_edge_filter_strength(txwpx, txhpx, p_angle - 90, filt_type);
+#endif
           const int n_px = n_top_px + ab_le + (need_right ? txhpx : 0);
           av1_filter_intra_edge_high(above_row - ab_le, n_px, strength);
         }
         if (need_left && n_left_px > 0) {
+#if CONFIG_IBP_DIR
+          const int strength = intra_edge_filter_strength(
+              txhpx, txwpx, angle_left, filt_type_left);
+#else
           const int strength = intra_edge_filter_strength(
               txhpx, txwpx, p_angle - 180, filt_type);
+#endif
           const int n_px = n_left_px + ab_le + (need_bottom ? txwpx : 0);
           av1_filter_intra_edge_high(left_col - ab_le, n_px, strength);
         }
       }
+#if CONFIG_IBP_DIR
+      upsample_above = av1_use_intra_edge_upsample(txwpx, txhpx, angle_above,
+                                                   filt_type_above);
+#else
       upsample_above =
           av1_use_intra_edge_upsample(txwpx, txhpx, p_angle - 90, filt_type);
+#endif
       if (need_above && upsample_above) {
         const int n_px = txwpx + (need_right ? txhpx : 0);
         av1_upsample_intra_edge_high(above_row, n_px, xd->bd);
       }
+#if CONFIG_IBP_DIR
+      upsample_left =
+          av1_use_intra_edge_upsample(txhpx, txwpx, angle_left, filt_type_left);
+#else
       upsample_left =
           av1_use_intra_edge_upsample(txhpx, txwpx, p_angle - 180, filt_type);
+#endif
       if (need_left && upsample_left) {
         const int n_px = txhpx + (need_bottom ? txwpx : 0);
         av1_upsample_intra_edge_high(left_col, n_px, xd->bd);
@@ -1523,15 +1910,45 @@
                         mrl_index
 #endif
     );
+#if CONFIG_IBP_DIR
+    if (seq_ibp_flag) {
+#if CONFIG_MRLS
+      if (mrl_index == 0) {
+#endif
+        if (p_angle > 0 && p_angle < 90) {
+          int mode_index = angle_to_mode_index[p_angle];
+          uint8_t *weights = ibp_weights[tx_size][mode_index];
+          highbd_second_dr_predictor(second_pred, txwpx, tx_size, above_row,
+                                     left_col, upsample_above, upsample_left,
+                                     p_angle, xd->bd);
+          av1_highbd_ibp_dr_prediction_z1_c(weights, dst, dst_stride,
+                                            second_pred, txwpx, txwpx, txhpx);
+        }
+        if (p_angle > 180 && p_angle < 270) {
+          int mode_index = angle_to_mode_index[270 - p_angle];
+          int transpose_tsize = transpose_tx_size[tx_size];
+          uint8_t *weights = ibp_weights[transpose_tsize][mode_index];
+          highbd_second_dr_predictor(second_pred, txwpx, tx_size, above_row,
+                                     left_col, upsample_above, upsample_left,
+                                     p_angle, xd->bd);
+          av1_highbd_ibp_dr_prediction_z3_c(weights, dst, dst_stride,
+                                            second_pred, txwpx, txwpx, txhpx);
+        }
+#if CONFIG_MRLS
+      }
+#endif
+    }
+#endif
 #if CONFIG_ORIP
+#if !CONFIG_ORIP_NONDC_DISABLED
     // Apply sub-block based filter for horizontal/vertical intra mode
-    apply_sub_block_based_refinement_filter &=
-        av1_allow_orip_dir(p_angle, disable_intra_pred_filter_for_hor_ver_mode);
-    if (apply_sub_block_based_refinement_filter) {
+    if (apply_sub_block_based_refinement_filter &&
+        av1_allow_orip_dir(p_angle)) {
       av1_apply_orip_4x4subblock_hbd(dst, dst_stride, tx_size, above_row,
                                      left_col, mode, xd->bd);
     }
 #endif
+#endif
     return;
   }
 
@@ -1539,6 +1956,13 @@
   if (mode == DC_PRED) {
     dc_pred_high[n_left_px > 0][n_top_px > 0][tx_size](
         dst, dst_stride, above_row, left_col, xd->bd);
+#if CONFIG_IBP_DC
+    if (seq_ibp_flag && ((plane == 0) || (xd->mi[0]->uv_mode != UV_CFL_PRED)) &&
+        ((n_left_px > 0) || (n_top_px > 0))) {
+      ibp_dc_pred_high[n_left_px > 0][n_top_px > 0][tx_size](
+          dst, dst_stride, above_row, left_col, xd->bd);
+    }
+#endif
   } else {
     pred_high[mode][tx_size](dst, dst_stride, above_row, left_col, xd->bd);
   }
@@ -1566,9 +1990,16 @@
 #endif
 #if CONFIG_ORIP
     ,
-    const int disable_intra_pred_filter_for_hor_ver_mode,
     const int seq_intra_pred_filter_flag
 #endif
+#if CONFIG_IBP_DIR || CONFIG_IBP_DC
+    ,
+    const int seq_ibp_flag
+#endif
+#if CONFIG_IBP_DIR
+    ,
+    uint8_t *const ibp_weights[TX_SIZES_ALL][DIR_MODES_0_90]
+#endif
 ) {
   int i;
 #if CONFIG_MRLS
@@ -1590,6 +2021,9 @@
 #endif
   DECLARE_ALIGNED(16, uint8_t, left_data[NUM_INTRA_NEIGHBOUR_PIXELS]);
   DECLARE_ALIGNED(16, uint8_t, above_data[NUM_INTRA_NEIGHBOUR_PIXELS]);
+#if CONFIG_IBP_DIR
+  DECLARE_ALIGNED(16, uint8_t, second_pred_data[MAX_TX_SQUARE + 32]);
+#endif
 #if CONFIG_MRLS
   uint8_t *const above_row = above_data + 32;
   uint8_t *const left_col = left_data + 32;
@@ -1597,6 +2031,9 @@
   uint8_t *const above_row = above_data + 16;
   uint8_t *const left_col = left_data + 16;
 #endif
+#if CONFIG_IBP_DIR
+  uint8_t *const second_pred = second_pred_data + 16;
+#endif
   const int txwpx = tx_size_wide[tx_size];
   const int txhpx = tx_size_high[tx_size];
   int need_left = extend_modes[mode] & NEED_LEFT;
@@ -1637,11 +2074,15 @@
       need_above = 1, need_left = 1, need_above_left = 1;
     else
       need_above = 0, need_left = 1, need_above_left = 1;
+#if CONFIG_IBP_DIR
+    if (seq_ibp_flag) {
+      need_above = 1, need_left = 1, need_above_left = 1;
+    }
+#endif
 
-#if CONFIG_ORIP
+#if CONFIG_ORIP && !CONFIG_ORIP_NONDC_DISABLED
     if (apply_sub_block_based_refinement_filter &&
-        (p_angle == 90 || p_angle == 180) &&
-        !disable_intra_pred_filter_for_hor_ver_mode) {
+        (p_angle == 90 || p_angle == 180)) {
       need_above = 1;
       need_left = 1;
       need_above_left = 1;
@@ -1673,7 +2114,13 @@
   if (need_left) {
     int need_bottom = extend_modes[mode] & NEED_BOTTOMLEFT;
     if (use_filter_intra) need_bottom = 0;
+#if CONFIG_IBP_DIR
+    if (is_dr_mode)
+      need_bottom =
+          seq_ibp_flag ? (p_angle < 90) || (p_angle > 180) : p_angle > 180;
+#else
     if (is_dr_mode) need_bottom = p_angle > 180;
+#endif
 #if CONFIG_MRLS
     const int num_left_pixels_needed =
         txhpx + (need_bottom ? txwpx : 3) + (mrl_index << 1);
@@ -1699,7 +2146,13 @@
   if (need_above) {
     int need_right = extend_modes[mode] & NEED_ABOVERIGHT;
     if (use_filter_intra) need_right = 0;
+#if CONFIG_IBP_DIR
+    if (is_dr_mode)
+      need_right =
+          seq_ibp_flag ? (p_angle < 90) || (p_angle > 180) : p_angle < 90;
+#else
     if (is_dr_mode) need_right = p_angle < 90;
+#endif
 #if CONFIG_MRLS
     const int num_top_pixels_needed =
         txwpx + (need_right ? txhpx : 0) + (mrl_index << 1);
@@ -1766,35 +2219,76 @@
 #else
     if (!disable_edge_filter) {
 #endif
+#if CONFIG_IBP_DIR
+      int need_right = p_angle < 90;
+      int need_bottom = p_angle > 180;
+      int filt_type_above = get_filt_type(xd, plane);
+      int filt_type_left = filt_type_above;
+      int angle_above = p_angle - 90;
+      int angle_left = p_angle - 180;
+      if (seq_ibp_flag) {
+        need_right |= p_angle > 180;
+        need_bottom |= p_angle < 90;
+        const MB_MODE_INFO *ab =
+            (plane == 0) ? xd->above_mbmi : xd->chroma_above_mbmi;
+        const MB_MODE_INFO *le =
+            (plane == 0) ? xd->left_mbmi : xd->chroma_left_mbmi;
+        filt_type_above = ab ? is_smooth(ab, plane) : 0;
+        filt_type_left = le ? is_smooth(le, plane) : 0;
+        angle_above = p_angle > 180 ? (p_angle - 180 - 90) : angle_above;
+        angle_left = p_angle < 90 ? p_angle : angle_left;
+      }
+#else
       const int need_right = p_angle < 90;
       const int need_bottom = p_angle > 180;
       const int filt_type = get_filt_type(xd, plane);
+#endif
       if (p_angle != 90 && p_angle != 180) {
         const int ab_le = need_above_left ? 1 : 0;
         if (need_above && need_left && (txwpx + txhpx >= 24)) {
           filter_intra_edge_corner(above_row, left_col);
         }
         if (need_above && n_top_px > 0) {
+#if CONFIG_IBP_DIR
+          const int strength = intra_edge_filter_strength(
+              txwpx, txhpx, angle_above, filt_type_above);
+#else
           const int strength =
               intra_edge_filter_strength(txwpx, txhpx, p_angle - 90, filt_type);
+#endif
           const int n_px = n_top_px + ab_le + (need_right ? txhpx : 0);
           av1_filter_intra_edge(above_row - ab_le, n_px, strength);
         }
         if (need_left && n_left_px > 0) {
+#if CONFIG_IBP_DIR
+          const int strength = intra_edge_filter_strength(
+              txhpx, txwpx, angle_left, filt_type_left);
+#else
           const int strength = intra_edge_filter_strength(
               txhpx, txwpx, p_angle - 180, filt_type);
+#endif
           const int n_px = n_left_px + ab_le + (need_bottom ? txwpx : 0);
           av1_filter_intra_edge(left_col - ab_le, n_px, strength);
         }
       }
+#if CONFIG_IBP_DIR
+      upsample_above = av1_use_intra_edge_upsample(txwpx, txhpx, angle_above,
+                                                   filt_type_above);
+#else
       upsample_above =
           av1_use_intra_edge_upsample(txwpx, txhpx, p_angle - 90, filt_type);
+#endif
       if (need_above && upsample_above) {
         const int n_px = txwpx + (need_right ? txhpx : 0);
         av1_upsample_intra_edge(above_row, n_px);
       }
+#if CONFIG_IBP_DIR
+      upsample_left =
+          av1_use_intra_edge_upsample(txhpx, txwpx, angle_left, filt_type_left);
+#else
       upsample_left =
           av1_use_intra_edge_upsample(txhpx, txwpx, p_angle - 180, filt_type);
+#endif
       if (need_left && upsample_left) {
         const int n_px = txhpx + (need_bottom ? txwpx : 0);
         av1_upsample_intra_edge(left_col, n_px);
@@ -1807,16 +2301,44 @@
                  mrl_index
 #endif
     );
+#if CONFIG_IBP_DIR
+    if (seq_ibp_flag) {
+#if CONFIG_MRLS
+      if (mrl_index == 0) {
+#endif
+        if (p_angle > 0 && p_angle < 90) {
+          int mode_index = angle_to_mode_index[p_angle];
+          uint8_t *weights = ibp_weights[tx_size][mode_index];
+          second_dr_predictor(second_pred, txwpx, tx_size, above_row, left_col,
+                              upsample_above, upsample_left, p_angle);
+          av1_ibp_dr_prediction_z1_c(weights, dst, dst_stride, second_pred,
+                                     txwpx, txwpx, txhpx);
+        }
+        if (p_angle > 180 && p_angle < 270) {
+          int mode_index = angle_to_mode_index[270 - p_angle];
+          int transpose_tsize = transpose_tx_size[tx_size];
+          uint8_t *weights = ibp_weights[transpose_tsize][mode_index];
+          second_dr_predictor(second_pred, txwpx, tx_size, above_row, left_col,
+                              upsample_above, upsample_left, p_angle);
+          av1_ibp_dr_prediction_z3_c(weights, dst, dst_stride, second_pred,
+                                     txwpx, txwpx, txhpx);
+        }
+#if CONFIG_MRLS
+      }
+#endif
+    }
+#endif
 
 #if CONFIG_ORIP
+#if !CONFIG_ORIP_NONDC_DISABLED
     // Apply sub-block based filter for horizontal/vertical intra mode
-    apply_sub_block_based_refinement_filter &=
-        av1_allow_orip_dir(p_angle, disable_intra_pred_filter_for_hor_ver_mode);
-    if (apply_sub_block_based_refinement_filter) {
+    if (apply_sub_block_based_refinement_filter &&
+        av1_allow_orip_dir(p_angle)) {
       av1_apply_orip_4x4subblock(dst, dst_stride, tx_size, above_row, left_col,
                                  mode);
     }
 #endif
+#endif
     return;
   }
 
@@ -1824,6 +2346,13 @@
   if (mode == DC_PRED) {
     dc_pred[n_left_px > 0][n_top_px > 0][tx_size](dst, dst_stride, above_row,
                                                   left_col);
+#if CONFIG_IBP_DC
+    if (seq_ibp_flag && ((plane == 0) || (xd->mi[0]->uv_mode != UV_CFL_PRED)) &&
+        ((n_left_px > 0) || (n_top_px > 0))) {
+      ibp_dc_pred[n_left_px > 0][n_top_px > 0][tx_size](dst, dst_stride,
+                                                        above_row, left_col);
+    }
+#endif
   } else {
     pred[mode][tx_size](dst, dst_stride, above_row, left_col);
   }
@@ -1893,12 +2422,7 @@
     const AV1_COMMON *cm, const MACROBLOCKD *xd, int wpx, int hpx,
     TX_SIZE tx_size, PREDICTION_MODE mode, int angle_delta, int use_palette,
     FILTER_INTRA_MODE filter_intra_mode, const uint8_t *ref, int ref_stride,
-    uint8_t *dst, int dst_stride, int col_off, int row_off, int plane
-#if CONFIG_ORIP
-    ,
-    const int disable_intra_pred_filter_for_hor_ver_mode
-#endif
-) {
+    uint8_t *dst, int dst_stride, int col_off, int row_off, int plane) {
   const MB_MODE_INFO *const mbmi = xd->mi[0];
   const int txwpx = tx_size_wide[tx_size];
   const int txhpx = tx_size_high[tx_size];
@@ -1978,39 +2502,55 @@
 #endif
 
   if (is_cur_buf_hbd(xd)) {
-    build_intra_predictors_high(
-        xd, ref, ref_stride, dst, dst_stride, mode, angle_delta,
-        filter_intra_mode, tx_size, disable_edge_filter,
-        have_top ? AOMMIN(txwpx, xr + txwpx) : 0,
-        have_top_right ? AOMMIN(txwpx, xr) : 0,
-        have_left ? AOMMIN(txhpx, yd + txhpx) : 0,
-        have_bottom_left ? AOMMIN(txhpx, yd) : 0, plane
+    build_intra_predictors_high(xd, ref, ref_stride, dst, dst_stride, mode,
+                                angle_delta, filter_intra_mode, tx_size,
+                                disable_edge_filter,
+                                have_top ? AOMMIN(txwpx, xr + txwpx) : 0,
+                                have_top_right ? AOMMIN(txwpx, xr) : 0,
+                                have_left ? AOMMIN(txhpx, yd + txhpx) : 0,
+                                have_bottom_left ? AOMMIN(txhpx, yd) : 0, plane
 #if CONFIG_MRLS
-        ,
-        is_sb_boundary
+                                ,
+                                is_sb_boundary
 #endif
 #if CONFIG_ORIP
-        ,
-        disable_intra_pred_filter_for_hor_ver_mode, cm->seq_params.enable_orip
+                                ,
+                                cm->seq_params.enable_orip
+#endif
+#if CONFIG_IBP_DIR || CONFIG_IBP_DC
+                                ,
+                                cm->seq_params.enable_ibp
+#endif
+#if CONFIG_IBP_DIR
+                                ,
+                                cm->ibp_directional_weights
 #endif
     );
     return;
   }
 
-  build_intra_predictors(
-      xd, ref, ref_stride, dst, dst_stride, mode, angle_delta,
-      filter_intra_mode, tx_size, disable_edge_filter,
-      have_top ? AOMMIN(txwpx, xr + txwpx) : 0,
-      have_top_right ? AOMMIN(txwpx, xr) : 0,
-      have_left ? AOMMIN(txhpx, yd + txhpx) : 0,
-      have_bottom_left ? AOMMIN(txhpx, yd) : 0, plane
+  build_intra_predictors(xd, ref, ref_stride, dst, dst_stride, mode,
+                         angle_delta, filter_intra_mode, tx_size,
+                         disable_edge_filter,
+                         have_top ? AOMMIN(txwpx, xr + txwpx) : 0,
+                         have_top_right ? AOMMIN(txwpx, xr) : 0,
+                         have_left ? AOMMIN(txhpx, yd + txhpx) : 0,
+                         have_bottom_left ? AOMMIN(txhpx, yd) : 0, plane
 #if CONFIG_MRLS
-      ,
-      is_sb_boundary
+                         ,
+                         is_sb_boundary
 #endif
 #if CONFIG_ORIP
-      ,
-      disable_intra_pred_filter_for_hor_ver_mode, cm->seq_params.enable_orip
+                         ,
+                         cm->seq_params.enable_orip
+#endif
+#if CONFIG_IBP_DIR || CONFIG_IBP_DC
+                         ,
+                         cm->seq_params.enable_ibp
+#endif
+#if CONFIG_IBP_DIR
+                         ,
+                         cm->ibp_directional_weights
 #endif
   );
 }
@@ -2030,34 +2570,7 @@
           ? mbmi->filter_intra_mode_info.filter_intra_mode
           : FILTER_INTRA_MODES;
 
-#if CONFIG_ORIP
-#if CONFIG_SDP
-  const BLOCK_SIZE bsize = mbmi->sb_type[AOM_PLANE_Y];
-#else
-  const BLOCK_SIZE bsize = mbmi->sb_type;
-#endif
-  const int angle_delta =
-      cm->seq_params.enable_orip
-          ? ((mbmi->angle_delta[plane != AOM_PLANE_Y] == ANGLE_DELTA_VALUE_ORIP)
-                 ? 0
-                 : mbmi->angle_delta[plane != AOM_PLANE_Y] * ANGLE_STEP)
-          : mbmi->angle_delta[plane != AOM_PLANE_Y] * ANGLE_STEP;
-  const int disable_intra_pred_filter_for_hor_ver_mode =
-      cm->seq_params.enable_orip
-          ? ((mbmi->angle_delta[plane != AOM_PLANE_Y] == ANGLE_DELTA_VALUE_ORIP)
-                 ? 1
-                 : 0)
-          : 1;
-  if (cm->seq_params.enable_orip) {
-    int violate_orip = disable_intra_pred_filter_for_hor_ver_mode;
-    violate_orip &= !av1_signal_orip_for_horver_modes(
-        cm, mbmi, plane != AOM_PLANE_Y, bsize);
-    assert(violate_orip == 0);
-  }
-
-#else
   const int angle_delta = mbmi->angle_delta[plane != AOM_PLANE_Y] * ANGLE_STEP;
-#endif
 
   if (plane != AOM_PLANE_Y && mbmi->uv_mode == UV_CFL_PRED) {
 #if CONFIG_DEBUG
@@ -2084,13 +2597,7 @@
       av1_predict_intra_block(cm, xd, pd->width, pd->height, tx_size, mode,
                               angle_delta, use_palette, filter_intra_mode, dst,
                               dst_stride, dst, dst_stride, blk_col, blk_row,
-#if CONFIG_ORIP
-                              plane,
-                              disable_intra_pred_filter_for_hor_ver_mode);
-#else
                               plane);
-#endif
-
       if (cfl->use_dc_pred_cache) {
         cfl_store_dc_pred(xd, dst, pred_plane, tx_size_wide[tx_size]);
         cfl->dc_pred_is_cached[pred_plane] = 1;
@@ -2112,12 +2619,7 @@
 
   av1_predict_intra_block(cm, xd, pd->width, pd->height, tx_size, mode,
                           angle_delta, use_palette, filter_intra_mode, dst,
-#if CONFIG_ORIP
-                          dst_stride, dst, dst_stride, blk_col, blk_row, plane,
-                          disable_intra_pred_filter_for_hor_ver_mode);
-#else
                           dst_stride, dst, dst_stride, blk_col, blk_row, plane);
-#endif
 }
 
 void av1_init_intra_predictors(void) {
diff --git a/av1/common/reconintra.h b/av1/common/reconintra.h
index a0e6e9a..67486d8 100644
--- a/av1/common/reconintra.h
+++ b/av1/common/reconintra.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_COMMON_RECONINTRA_H_
@@ -22,24 +23,47 @@
 extern "C" {
 #endif
 
+#if CONFIG_AIMC
+/*! \brief set the luma intra mode and delta angles for a given mode index.
+ * \param[in]    mode_idx           mode index in intra mode decision
+ *                                  process.
+ * \param[in]    mbmi               Pointer to structure holding
+ *                                  the mode info for the current macroblock.
+ */
+void set_y_mode_and_delta_angle(const int mode_idx, MB_MODE_INFO *const mbmi);
+int get_y_mode_idx_ctx(MACROBLOCKD *const xd);
+void get_y_intra_mode_set(MB_MODE_INFO *mi, MACROBLOCKD *const xd);
+void get_uv_intra_mode_set(MB_MODE_INFO *mi);
+static const PREDICTION_MODE reordered_y_mode[INTRA_MODES] = {
+  DC_PRED,   SMOOTH_PRED, SMOOTH_V_PRED, SMOOTH_H_PRED, PAETH_PRED,
+  D45_PRED,  D67_PRED,    V_PRED,        D113_PRED,     D135_PRED,
+  D157_PRED, H_PRED,      D203_PRED
+};
+static const int
+    default_mode_list_y[LUMA_MODE_COUNT - NON_DIRECTIONAL_MODES_COUNT] = {
+      17, 45, 3, 10, 24, 31, 38, 52,
+      //  (-2, +2)
+      15, 19, 43, 47, 1, 5, 8, 12, 22, 26, 29, 33, 36, 40, 50, 54,
+      //  (-1, +1)
+      16, 18, 44, 46, 2, 4, 9, 11, 23, 25, 30, 32, 37, 39, 51, 53,
+      //  (-3, +3)
+      14, 20, 42, 48, 0, 6, 7, 13, 21, 27, 28, 34, 35, 41, 49, 55
+    };
+static const int default_mode_list_uv[DIR_MODE_END - DIR_MODE_START] = {
+  UV_V_PRED,   UV_H_PRED,    UV_D45_PRED,  UV_D135_PRED,
+  UV_D67_PRED, UV_D113_PRED, UV_D157_PRED, UV_D203_PRED
+};
+#endif  // CONFIG_AIMC
+
 void av1_init_intra_predictors(void);
 void av1_predict_intra_block_facade(const AV1_COMMON *cm, MACROBLOCKD *xd,
                                     int plane, int blk_col, int blk_row,
                                     TX_SIZE tx_size);
-#if CONFIG_ORIP
-void av1_predict_intra_block(
-    const AV1_COMMON *cm, const MACROBLOCKD *xd, int wpx, int hpx,
-    TX_SIZE tx_size, PREDICTION_MODE mode, int angle_delta, int use_palette,
-    FILTER_INTRA_MODE filter_intra_mode, const uint8_t *ref, int ref_stride,
-    uint8_t *dst, int dst_stride, int col_off, int row_off, int plane,
-    const int disable_intra_pred_filter_for_hor_ver_mode);
-#else
 void av1_predict_intra_block(
     const AV1_COMMON *cm, const MACROBLOCKD *xd, int wpx, int hpx,
     TX_SIZE tx_size, PREDICTION_MODE mode, int angle_delta, int use_palette,
     FILTER_INTRA_MODE filter_intra_mode, const uint8_t *ref, int ref_stride,
     uint8_t *dst, int dst_stride, int col_off, int row_off, int plane);
-#endif
 
 #if CONFIG_ORIP
 void av1_apply_orip_4x4subblock_hbd(uint16_t *dst, ptrdiff_t stride,
@@ -105,11 +129,25 @@
 
 #if CONFIG_ORIP
 static INLINE int av1_allow_orip_smooth_dc(PREDICTION_MODE mode, int plane) {
+#if CONFIG_ORIP_DC_DISABLED
+#if CONFIG_ORIP_NONDC_DISABLED
+  return 0;
+#else
+  if (plane == AOM_PLANE_Y) return (mode == SMOOTH_PRED);
+  return (mode == UV_SMOOTH_PRED);
+#endif
+#else
+#if CONFIG_ORIP_NONDC_DISABLED
+  if (plane == AOM_PLANE_Y) return (mode == DC_PRED);
+  return 0;
+#else
   if (plane == AOM_PLANE_Y) return (mode == SMOOTH_PRED || mode == DC_PRED);
   return (mode == UV_SMOOTH_PRED);
+#endif
+#endif
 }
-static INLINE int av1_allow_orip_dir(int p_angle, int disable_filter) {
-  return (!disable_filter && (p_angle == 90 || p_angle == 180));
+static INLINE int av1_allow_orip_dir(int p_angle) {
+  return (p_angle == 90 || p_angle == 180);
 }
 #endif
 
@@ -187,42 +225,12 @@
   return type ? (blk_wh <= 8) : (blk_wh <= 16);
 }
 
-#if CONFIG_ORIP
-// This function returns if enable/disable ORIP is signalled in the bitstream
-// 1 means signal; 0 means does not signal
-static INLINE int av1_signal_orip_for_horver_modes(const AV1_COMMON *cm,
-                                                   const MB_MODE_INFO *mbmi,
-                                                   PLANE_TYPE plane,
-                                                   BLOCK_SIZE bsize) {
-  if (!cm->seq_params.enable_orip) return 0;
-
-#if CONFIG_SDP
-  const int use_intrabc = mbmi->use_intrabc[PLANE_TYPE_Y];
-  const int is_inter = is_inter_block(mbmi, SHARED_PART);
-#else
-  const int use_intrabc = mbmi->use_intrabc;
-  const int is_inter = is_inter_block(mbmi);
-#endif
-
-  if (plane != PLANE_TYPE_Y || is_inter || use_intrabc) return 0;
-  if (!av1_use_angle_delta(bsize)) return 0;
-
-#if CONFIG_MRLS
-  if (mbmi->mrl_index) return 0;
-#endif
-
-  if (mbmi->mode == V_PRED || mbmi->mode == H_PRED) return 1;
-  return 0;
-}
-
-static INLINE int get_angle_delta_to_idx(int angle_delta) {
-  return (MAX_ANGLE_DELTA + angle_delta);
-}
-
-static INLINE int get_idx_to_angle_delta(int index) {
-  return (index - MAX_ANGLE_DELTA);
-}
-
+#if CONFIG_IBP_DIR
+static const int32_t transpose_tx_size[TX_SIZES_ALL] = {
+  TX_4X4,  TX_8X8,  TX_16X16, TX_32X32, TX_64X64, TX_8X4,   TX_4X8,
+  TX_16X8, TX_8X16, TX_32X16, TX_16X32, TX_64X32, TX_32X64, TX_16X4,
+  TX_4X16, TX_32X8, TX_8X32,  TX_64X16, TX_16X64,
+};
 #endif
 
 #ifdef __cplusplus
diff --git a/av1/common/resize.c b/av1/common/resize.c
index 95d3368..2c3def8 100644
--- a/av1/common/resize.c
+++ b/av1/common/resize.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/av1/common/resize.h b/av1/common/resize.h
index b08de80..f15fe4f 100644
--- a/av1/common/resize.h
+++ b/av1/common/resize.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_COMMON_RESIZE_H_
diff --git a/av1/common/restoration.c b/av1/common/restoration.c
index d1f64c4..e66f9c6 100644
--- a/av1/common/restoration.c
+++ b/av1/common/restoration.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  *
  */
 
diff --git a/av1/common/restoration.h b/av1/common/restoration.h
index 338c9e7c..cb8a2ae 100644
--- a/av1/common/restoration.h
+++ b/av1/common/restoration.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_COMMON_RESTORATION_H_
diff --git a/av1/common/scale.c b/av1/common/scale.c
index 5bcd8df..4a290a5 100644
--- a/av1/common/scale.c
+++ b/av1/common/scale.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "config/aom_dsp_rtcd.h"
diff --git a/av1/common/scale.h b/av1/common/scale.h
index fd30416..1508a9e 100644
--- a/av1/common/scale.h
+++ b/av1/common/scale.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_COMMON_SCALE_H_
diff --git a/av1/common/scan.c b/av1/common/scan.c
index c1d4f35..476ec48 100644
--- a/av1/common/scan.c
+++ b/av1/common/scan.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/av1/common/scan.h b/av1/common/scan.h
index 9e5cbb0..3955a28 100644
--- a/av1/common/scan.h
+++ b/av1/common/scan.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_COMMON_SCAN_H_
diff --git a/av1/common/seg_common.c b/av1/common/seg_common.c
index 60b1851..5d707c9 100644
--- a/av1/common/seg_common.c
+++ b/av1/common/seg_common.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
@@ -16,16 +17,20 @@
 #include "av1/common/seg_common.h"
 #include "av1/common/quant_common.h"
 
-static const int seg_feature_data_signed[SEG_LVL_MAX] = {
-  1, 1, 1, 1, 1, 0, 0, 0
-};
+static const int seg_feature_data_signed[SEG_LVL_MAX] = { 1, 1, 1, 1, 1,
+#if !CONFIG_NEW_REF_SIGNALING
+                                                          0,
+#endif  // !CONFIG_NEW_REF_SIGNALING
+                                                          0, 0 };
 
 static const int seg_feature_data_max[SEG_LVL_MAX] = { MAXQ,
                                                        MAX_LOOP_FILTER,
                                                        MAX_LOOP_FILTER,
                                                        MAX_LOOP_FILTER,
                                                        MAX_LOOP_FILTER,
+#if !CONFIG_NEW_REF_SIGNALING
                                                        7,
+#endif  // !CONFIG_NEW_REF_SIGNALING
                                                        0,
                                                        0 };
 
@@ -45,7 +50,11 @@
   for (int i = 0; i < MAX_SEGMENTS; i++) {
     for (int j = 0; j < SEG_LVL_MAX; j++) {
       if (seg->feature_mask[i] & (1 << j)) {
+#if CONFIG_NEW_REF_SIGNALING
+        seg->segid_preskip |= (j >= SEG_LVL_ALT_LF_V);
+#else
         seg->segid_preskip |= (j >= SEG_LVL_REF_FRAME);
+#endif  // CONFIG_NEW_REF_SIGNALING
         seg->last_active_segid = i;
       }
     }
diff --git a/av1/common/seg_common.h b/av1/common/seg_common.h
index aeb9c17..62a1026 100644
--- a/av1/common/seg_common.h
+++ b/av1/common/seg_common.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_COMMON_SEG_COMMON_H_
@@ -30,8 +31,10 @@
   SEG_LVL_ALT_LF_Y_H,  // Use alternate loop filter value on y plane horizontal
   SEG_LVL_ALT_LF_U,    // Use alternate loop filter value on u plane
   SEG_LVL_ALT_LF_V,    // Use alternate loop filter value on v plane
-  SEG_LVL_REF_FRAME,   // Optional Segment reference frame
-  SEG_LVL_SKIP,        // Optional Segment (0,0) + skip mode
+#if !CONFIG_NEW_REF_SIGNALING
+  SEG_LVL_REF_FRAME,  // Optional Segment reference frame
+#endif                // !CONFIG_NEW_REF_SIGNALING
+  SEG_LVL_SKIP,       // Optional Segment (0,0) + skip mode
   SEG_LVL_GLOBALMV,
   SEG_LVL_MAX
 } UENUM1BYTE(SEG_LVL_FEATURES);
diff --git a/av1/common/thread_common.c b/av1/common/thread_common.c
index f3c8795..92fdb20 100644
--- a/av1/common/thread_common.c
+++ b/av1/common/thread_common.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "config/aom_config.h"
diff --git a/av1/common/thread_common.h b/av1/common/thread_common.h
index 7397f1c..0f09b33 100644
--- a/av1/common/thread_common.h
+++ b/av1/common/thread_common.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_COMMON_THREAD_COMMON_H_
diff --git a/av1/common/tile_common.c b/av1/common/tile_common.c
index 1b11bd7..e7c6c8f 100644
--- a/av1/common/tile_common.c
+++ b/av1/common/tile_common.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "av1/common/av1_common_int.h"
diff --git a/av1/common/tile_common.h b/av1/common/tile_common.h
index ca7c5f4..5bbea5f 100644
--- a/av1/common/tile_common.h
+++ b/av1/common/tile_common.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_COMMON_TILE_COMMON_H_
diff --git a/av1/common/timing.c b/av1/common/timing.c
index a959cdf..0f34914 100644
--- a/av1/common/timing.c
+++ b/av1/common/timing.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "av1/common/timing.h"
diff --git a/av1/common/timing.h b/av1/common/timing.h
index 9192124..955a1c0 100644
--- a/av1/common/timing.h
+++ b/av1/common/timing.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_COMMON_TIMING_H_
diff --git a/av1/common/token_cdfs.h b/av1/common/token_cdfs.h
index f1edda5..35d0d2e 100644
--- a/av1/common/token_cdfs.h
+++ b/av1/common/token_cdfs.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_COMMON_TOKEN_CDFS_H_
@@ -16,6 +17,98 @@
 
 #include "av1/common/entropy.h"
 
+#if CONFIG_CONTEXT_DERIVATION
+static const aom_cdf_prob
+    av1_default_v_dc_sign_cdfs[TOKEN_CDF_Q_CTXS][CROSS_COMPONENT_CONTEXTS]
+                              [DC_SIGN_CONTEXTS][CDF_SIZE(2)] = {
+                                { {
+                                      { AOM_CDF2(128 * 125) },
+                                      { AOM_CDF2(128 * 102) },
+                                      { AOM_CDF2(128 * 147) },
+                                  },
+                                  {
+                                      { AOM_CDF2(128 * 119) },
+                                      { AOM_CDF2(128 * 101) },
+                                      { AOM_CDF2(128 * 135) },
+                                  },
+                                  {
+                                      { AOM_CDF2(128 * 119) },
+                                      { AOM_CDF2(128 * 101) },
+                                      { AOM_CDF2(128 * 135) },
+                                  } },
+                                { {
+                                      { AOM_CDF2(128 * 125) },
+                                      { AOM_CDF2(128 * 102) },
+                                      { AOM_CDF2(128 * 147) },
+                                  },
+                                  {
+                                      { AOM_CDF2(128 * 119) },
+                                      { AOM_CDF2(128 * 101) },
+                                      { AOM_CDF2(128 * 135) },
+                                  },
+                                  {
+                                      { AOM_CDF2(128 * 119) },
+                                      { AOM_CDF2(128 * 101) },
+                                      { AOM_CDF2(128 * 135) },
+                                  } },
+                                { {
+                                      { AOM_CDF2(128 * 125) },
+                                      { AOM_CDF2(128 * 102) },
+                                      { AOM_CDF2(128 * 147) },
+                                  },
+                                  {
+                                      { AOM_CDF2(128 * 119) },
+                                      { AOM_CDF2(128 * 101) },
+                                      { AOM_CDF2(128 * 135) },
+                                  },
+                                  {
+                                      { AOM_CDF2(128 * 119) },
+                                      { AOM_CDF2(128 * 101) },
+                                      { AOM_CDF2(128 * 135) },
+                                  } },
+                                { {
+                                      { AOM_CDF2(128 * 125) },
+                                      { AOM_CDF2(128 * 102) },
+                                      { AOM_CDF2(128 * 147) },
+                                  },
+                                  {
+                                      { AOM_CDF2(128 * 119) },
+                                      { AOM_CDF2(128 * 101) },
+                                      { AOM_CDF2(128 * 135) },
+                                  },
+                                  {
+                                      { AOM_CDF2(128 * 119) },
+                                      { AOM_CDF2(128 * 101) },
+                                      { AOM_CDF2(128 * 135) },
+                                  } },
+                              };
+
+static const aom_cdf_prob av1_default_v_ac_sign_cdfs[TOKEN_CDF_Q_CTXS]
+                                                    [CROSS_COMPONENT_CONTEXTS]
+                                                    [CDF_SIZE(2)] = {
+                                                      {
+                                                          { AOM_CDF2(16384) },
+                                                          { AOM_CDF2(16384) },
+                                                          { AOM_CDF2(16384) },
+                                                      },
+                                                      {
+                                                          { AOM_CDF2(16384) },
+                                                          { AOM_CDF2(16384) },
+                                                          { AOM_CDF2(16384) },
+                                                      },
+                                                      {
+                                                          { AOM_CDF2(16384) },
+                                                          { AOM_CDF2(16384) },
+                                                          { AOM_CDF2(16384) },
+                                                      },
+                                                      {
+                                                          { AOM_CDF2(16384) },
+                                                          { AOM_CDF2(16384) },
+                                                          { AOM_CDF2(16384) },
+                                                      },
+                                                    };
+#endif  // CONFIG_CONTEXT_DERIVATION
+
 static const aom_cdf_prob
     av1_default_dc_sign_cdfs[TOKEN_CDF_Q_CTXS][PLANE_TYPES][DC_SIGN_CONTEXTS]
                             [CDF_SIZE(2)] = {
@@ -324,6 +417,67 @@
                                                    { AOM_CDF2(16384) },
                                                    { AOM_CDF2(16384) } } } };
 
+#if CONFIG_CONTEXT_DERIVATION
+static const aom_cdf_prob
+    av1_default_v_txb_skip_cdfs[TOKEN_CDF_Q_CTXS][V_TXB_SKIP_CONTEXTS]
+                               [CDF_SIZE(2)] = { {
+                                                     { AOM_CDF2(16384) },
+                                                     { AOM_CDF2(16384) },
+                                                     { AOM_CDF2(16384) },
+                                                     { AOM_CDF2(16384) },
+                                                     { AOM_CDF2(16384) },
+                                                     { AOM_CDF2(16384) },
+                                                     { AOM_CDF2(16384) },
+                                                     { AOM_CDF2(16384) },
+                                                     { AOM_CDF2(16384) },
+                                                     { AOM_CDF2(16384) },
+                                                     { AOM_CDF2(16384) },
+                                                     { AOM_CDF2(16384) },
+                                                 },
+                                                 {
+                                                     { AOM_CDF2(16384) },
+                                                     { AOM_CDF2(16384) },
+                                                     { AOM_CDF2(16384) },
+                                                     { AOM_CDF2(16384) },
+                                                     { AOM_CDF2(16384) },
+                                                     { AOM_CDF2(16384) },
+                                                     { AOM_CDF2(16384) },
+                                                     { AOM_CDF2(16384) },
+                                                     { AOM_CDF2(16384) },
+                                                     { AOM_CDF2(16384) },
+                                                     { AOM_CDF2(16384) },
+                                                     { AOM_CDF2(16384) },
+                                                 },
+                                                 {
+                                                     { AOM_CDF2(16384) },
+                                                     { AOM_CDF2(16384) },
+                                                     { AOM_CDF2(16384) },
+                                                     { AOM_CDF2(16384) },
+                                                     { AOM_CDF2(16384) },
+                                                     { AOM_CDF2(16384) },
+                                                     { AOM_CDF2(16384) },
+                                                     { AOM_CDF2(16384) },
+                                                     { AOM_CDF2(16384) },
+                                                     { AOM_CDF2(16384) },
+                                                     { AOM_CDF2(16384) },
+                                                     { AOM_CDF2(16384) },
+                                                 },
+                                                 {
+                                                     { AOM_CDF2(16384) },
+                                                     { AOM_CDF2(16384) },
+                                                     { AOM_CDF2(16384) },
+                                                     { AOM_CDF2(16384) },
+                                                     { AOM_CDF2(16384) },
+                                                     { AOM_CDF2(16384) },
+                                                     { AOM_CDF2(16384) },
+                                                     { AOM_CDF2(16384) },
+                                                     { AOM_CDF2(16384) },
+                                                     { AOM_CDF2(16384) },
+                                                     { AOM_CDF2(16384) },
+                                                     { AOM_CDF2(16384) },
+                                                 } };
+#endif  // CONFIG_CONTEXT_DERIVATION
+
 static const aom_cdf_prob
     av1_default_eob_extra_cdfs[TOKEN_CDF_Q_CTXS][TX_SIZES][PLANE_TYPES]
                               [EOB_COEF_CONTEXTS][CDF_SIZE(2)] = {
diff --git a/av1/common/txb_common.c b/av1/common/txb_common.c
index eb4be64..fc639d8 100644
--- a/av1/common/txb_common.c
+++ b/av1/common/txb_common.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #include "aom/aom_integer.h"
 #include "av1/common/av1_common_int.h"
diff --git a/av1/common/txb_common.h b/av1/common/txb_common.h
index 306ba3d..47cad3f 100644
--- a/av1/common/txb_common.h
+++ b/av1/common/txb_common.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_COMMON_TXB_COMMON_H_
@@ -354,11 +355,27 @@
     }
   } else {
     const int ctx_base = get_entropy_context(tx_size, a, l);
+#if CONFIG_CONTEXT_DERIVATION
+    int ctx_offset = 0;
+    if (plane == AOM_PLANE_U) {
+      ctx_offset = (num_pels_log2_lookup[plane_bsize] >
+                    num_pels_log2_lookup[txsize_to_bsize[tx_size]])
+                       ? 10
+                       : 7;
+    } else {
+      ctx_offset = (num_pels_log2_lookup[plane_bsize] >
+                    num_pels_log2_lookup[txsize_to_bsize[tx_size]])
+                       ? (V_TXB_SKIP_CONTEXT_OFFSET >> 1)
+                       : 0;
+    }
+    txb_ctx->txb_skip_ctx = ctx_base + ctx_offset;
+#else
     const int ctx_offset = (num_pels_log2_lookup[plane_bsize] >
                             num_pels_log2_lookup[txsize_to_bsize[tx_size]])
                                ? 10
                                : 7;
     txb_ctx->txb_skip_ctx = ctx_base + ctx_offset;
+#endif  // CONFIG_CONTEXT_DERIVATION
   }
 #undef MAX_TX_SIZE_UNIT
 }
diff --git a/av1/common/warped_motion.c b/av1/common/warped_motion.c
index 00d24b5..d82763c 100644
--- a/av1/common/warped_motion.c
+++ b/av1/common/warped_motion.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <stdio.h>
@@ -192,11 +193,7 @@
 
 /* clang-format on */
 
-#define DIV_LUT_PREC_BITS 14
-#define DIV_LUT_BITS 8
-#define DIV_LUT_NUM (1 << DIV_LUT_BITS)
-
-static const uint16_t div_lut[DIV_LUT_NUM + 1] = {
+const uint16_t div_lut[DIV_LUT_NUM + 1] = {
   16384, 16320, 16257, 16194, 16132, 16070, 16009, 15948, 15888, 15828, 15768,
   15709, 15650, 15592, 15534, 15477, 15420, 15364, 15308, 15252, 15197, 15142,
   15087, 15033, 14980, 14926, 14873, 14821, 14769, 14717, 14665, 14614, 14564,
@@ -223,41 +220,6 @@
   8240,  8224,  8208,  8192,
 };
 
-// Decomposes a divisor D such that 1/D = y/2^shift, where y is returned
-// at precision of DIV_LUT_PREC_BITS along with the shift.
-static int16_t resolve_divisor_64(uint64_t D, int16_t *shift) {
-  int64_t f;
-  *shift = (int16_t)((D >> 32) ? get_msb((unsigned int)(D >> 32)) + 32
-                               : get_msb((unsigned int)D));
-  // e is obtained from D after resetting the most significant 1 bit.
-  const int64_t e = D - ((uint64_t)1 << *shift);
-  // Get the most significant DIV_LUT_BITS (8) bits of e into f
-  if (*shift > DIV_LUT_BITS)
-    f = ROUND_POWER_OF_TWO_64(e, *shift - DIV_LUT_BITS);
-  else
-    f = e << (DIV_LUT_BITS - *shift);
-  assert(f <= DIV_LUT_NUM);
-  *shift += DIV_LUT_PREC_BITS;
-  // Use f as lookup into the precomputed table of multipliers
-  return div_lut[f];
-}
-
-static int16_t resolve_divisor_32(uint32_t D, int16_t *shift) {
-  int32_t f;
-  *shift = get_msb(D);
-  // e is obtained from D after resetting the most significant 1 bit.
-  const int32_t e = D - ((uint32_t)1 << *shift);
-  // Get the most significant DIV_LUT_BITS (8) bits of e into f
-  if (*shift > DIV_LUT_BITS)
-    f = ROUND_POWER_OF_TWO(e, *shift - DIV_LUT_BITS);
-  else
-    f = e << (DIV_LUT_BITS - *shift);
-  assert(f <= DIV_LUT_NUM);
-  *shift += DIV_LUT_PREC_BITS;
-  // Use f as lookup into the precomputed table of multipliers
-  return div_lut[f];
-}
-
 static int is_affine_valid(const WarpedMotionParams *const wm) {
   const int32_t *mat = wm->wmmat;
   return (mat[2] > 0);
diff --git a/av1/common/warped_motion.h b/av1/common/warped_motion.h
index 14dc0fe..7dd2550 100644
--- a/av1/common/warped_motion.h
+++ b/av1/common/warped_motion.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_COMMON_WARPED_MOTION_H_
@@ -34,6 +35,47 @@
 #define WARP_ERROR_BLOCK_LOG 5
 #define WARP_ERROR_BLOCK (1 << WARP_ERROR_BLOCK_LOG)
 
+#define DIV_LUT_PREC_BITS 14
+#define DIV_LUT_BITS 8
+#define DIV_LUT_NUM (1 << DIV_LUT_BITS)
+
+extern const uint16_t div_lut[DIV_LUT_NUM + 1];
+
+// Decomposes a divisor D such that 1/D = y/2^shift, where y is returned
+// at precision of DIV_LUT_PREC_BITS along with the shift.
+static INLINE int16_t resolve_divisor_64(uint64_t D, int16_t *shift) {
+  int64_t f;
+  *shift = (int16_t)((D >> 32) ? get_msb((unsigned int)(D >> 32)) + 32
+                               : get_msb((unsigned int)D));
+  // e is obtained from D after resetting the most significant 1 bit.
+  const int64_t e = D - ((uint64_t)1 << *shift);
+  // Get the most significant DIV_LUT_BITS (8) bits of e into f
+  if (*shift > DIV_LUT_BITS)
+    f = ROUND_POWER_OF_TWO_64(e, *shift - DIV_LUT_BITS);
+  else
+    f = e << (DIV_LUT_BITS - *shift);
+  assert(f <= DIV_LUT_NUM);
+  *shift += DIV_LUT_PREC_BITS;
+  // Use f as lookup into the precomputed table of multipliers
+  return div_lut[f];
+}
+
+static INLINE int16_t resolve_divisor_32(uint32_t D, int16_t *shift) {
+  int32_t f;
+  *shift = get_msb(D);
+  // e is obtained from D after resetting the most significant 1 bit.
+  const int32_t e = D - ((uint32_t)1 << *shift);
+  // Get the most significant DIV_LUT_BITS (8) bits of e into f
+  if (*shift > DIV_LUT_BITS)
+    f = ROUND_POWER_OF_TWO(e, *shift - DIV_LUT_BITS);
+  else
+    f = e << (DIV_LUT_BITS - *shift);
+  assert(f <= DIV_LUT_NUM);
+  *shift += DIV_LUT_PREC_BITS;
+  // Use f as lookup into the precomputed table of multipliers
+  return div_lut[f];
+}
+
 extern const int16_t av1_warped_filter[WARPEDPIXEL_PREC_SHIFTS * 3 + 1][8];
 
 DECLARE_ALIGNED(8, extern const int8_t,
diff --git a/av1/common/x86/av1_convolve_horiz_rs_sse4.c b/av1/common/x86/av1_convolve_horiz_rs_sse4.c
index 8aa1469..727ff16 100644
--- a/av1/common/x86/av1_convolve_horiz_rs_sse4.c
+++ b/av1/common/x86/av1_convolve_horiz_rs_sse4.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/av1/common/x86/av1_convolve_scale_sse4.c b/av1/common/x86/av1_convolve_scale_sse4.c
index 5d31168..8c0245c 100644
--- a/av1/common/x86/av1_convolve_scale_sse4.c
+++ b/av1/common/x86/av1_convolve_scale_sse4.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/av1/common/x86/av1_inv_txfm_avx2.c b/av1/common/x86/av1_inv_txfm_avx2.c
index 0fbd5ea..e8a8558 100644
--- a/av1/common/x86/av1_inv_txfm_avx2.c
+++ b/av1/common/x86/av1_inv_txfm_avx2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "config/aom_config.h"
diff --git a/av1/common/x86/av1_inv_txfm_avx2.h b/av1/common/x86/av1_inv_txfm_avx2.h
index f74cbae..88bd196 100644
--- a/av1/common/x86/av1_inv_txfm_avx2.h
+++ b/av1/common/x86/av1_inv_txfm_avx2.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #ifndef AOM_AV1_COMMON_X86_AV1_INV_TXFM_AVX2_H_
 #define AOM_AV1_COMMON_X86_AV1_INV_TXFM_AVX2_H_
diff --git a/av1/common/x86/av1_inv_txfm_ssse3.c b/av1/common/x86/av1_inv_txfm_ssse3.c
index 46c051f..642e7a2 100644
--- a/av1/common/x86/av1_inv_txfm_ssse3.c
+++ b/av1/common/x86/av1_inv_txfm_ssse3.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "config/aom_config.h"
diff --git a/av1/common/x86/av1_inv_txfm_ssse3.h b/av1/common/x86/av1_inv_txfm_ssse3.h
index 7d5055d..1551527 100644
--- a/av1/common/x86/av1_inv_txfm_ssse3.h
+++ b/av1/common/x86/av1_inv_txfm_ssse3.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #ifndef AOM_AV1_COMMON_X86_AV1_INV_TXFM_SSSE3_H_
 #define AOM_AV1_COMMON_X86_AV1_INV_TXFM_SSSE3_H_
diff --git a/av1/common/x86/av1_txfm_sse2.h b/av1/common/x86/av1_txfm_sse2.h
index 77aeb6e..c09e643 100644
--- a/av1/common/x86/av1_txfm_sse2.h
+++ b/av1/common/x86/av1_txfm_sse2.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #ifndef AOM_AV1_COMMON_X86_AV1_TXFM_SSE2_H_
 #define AOM_AV1_COMMON_X86_AV1_TXFM_SSE2_H_
diff --git a/av1/common/x86/av1_txfm_sse4.c b/av1/common/x86/av1_txfm_sse4.c
index 65ccd19..706ff12 100644
--- a/av1/common/x86/av1_txfm_sse4.c
+++ b/av1/common/x86/av1_txfm_sse4.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "config/av1_rtcd.h"
diff --git a/av1/common/x86/av1_txfm_sse4.h b/av1/common/x86/av1_txfm_sse4.h
index 6cad821..1b10e51 100644
--- a/av1/common/x86/av1_txfm_sse4.h
+++ b/av1/common/x86/av1_txfm_sse4.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_COMMON_X86_AV1_TXFM_SSE4_H_
diff --git a/av1/common/x86/cfl_avx2.c b/av1/common/x86/cfl_avx2.c
index 3356984..ec26f98 100644
--- a/av1/common/x86/cfl_avx2.c
+++ b/av1/common/x86/cfl_avx2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #include <immintrin.h>
 
diff --git a/av1/common/x86/cfl_simd.h b/av1/common/x86/cfl_simd.h
index 25ae45b..ba362ac 100644
--- a/av1/common/x86/cfl_simd.h
+++ b/av1/common/x86/cfl_simd.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_COMMON_X86_CFL_SIMD_H_
diff --git a/av1/common/x86/cfl_sse2.c b/av1/common/x86/cfl_sse2.c
index 4783fe0..1006fab 100644
--- a/av1/common/x86/cfl_sse2.c
+++ b/av1/common/x86/cfl_sse2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <emmintrin.h>
diff --git a/av1/common/x86/cfl_ssse3.c b/av1/common/x86/cfl_ssse3.c
index bbf0072..52e1cc3 100644
--- a/av1/common/x86/cfl_ssse3.c
+++ b/av1/common/x86/cfl_ssse3.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <tmmintrin.h>
diff --git a/av1/common/x86/convolve_2d_avx2.c b/av1/common/x86/convolve_2d_avx2.c
index 211f258..a982574 100644
--- a/av1/common/x86/convolve_2d_avx2.c
+++ b/av1/common/x86/convolve_2d_avx2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <immintrin.h>
diff --git a/av1/common/x86/convolve_2d_sse2.c b/av1/common/x86/convolve_2d_sse2.c
index a3a8857..038ee40 100644
--- a/av1/common/x86/convolve_2d_sse2.c
+++ b/av1/common/x86/convolve_2d_sse2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <emmintrin.h>
diff --git a/av1/common/x86/convolve_avx2.c b/av1/common/x86/convolve_avx2.c
index 1a9bf5e..e942eae 100644
--- a/av1/common/x86/convolve_avx2.c
+++ b/av1/common/x86/convolve_avx2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <immintrin.h>
diff --git a/av1/common/x86/convolve_sse2.c b/av1/common/x86/convolve_sse2.c
index 7273cde..5ceb40b 100644
--- a/av1/common/x86/convolve_sse2.c
+++ b/av1/common/x86/convolve_sse2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <emmintrin.h>
diff --git a/av1/common/x86/filterintra_sse4.c b/av1/common/x86/filterintra_sse4.c
index c11edc1..5830819 100644
--- a/av1/common/x86/filterintra_sse4.c
+++ b/av1/common/x86/filterintra_sse4.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <smmintrin.h>
diff --git a/av1/common/x86/highbd_convolve_2d_avx2.c b/av1/common/x86/highbd_convolve_2d_avx2.c
index 12d1962..b1927e9 100644
--- a/av1/common/x86/highbd_convolve_2d_avx2.c
+++ b/av1/common/x86/highbd_convolve_2d_avx2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <immintrin.h>
diff --git a/av1/common/x86/highbd_convolve_2d_sse4.c b/av1/common/x86/highbd_convolve_2d_sse4.c
index 185bdd6..b14147c 100644
--- a/av1/common/x86/highbd_convolve_2d_sse4.c
+++ b/av1/common/x86/highbd_convolve_2d_sse4.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <tmmintrin.h>
diff --git a/av1/common/x86/highbd_convolve_2d_ssse3.c b/av1/common/x86/highbd_convolve_2d_ssse3.c
index 5318fca..201a927 100644
--- a/av1/common/x86/highbd_convolve_2d_ssse3.c
+++ b/av1/common/x86/highbd_convolve_2d_ssse3.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <tmmintrin.h>
diff --git a/av1/common/x86/highbd_inv_txfm_avx2.c b/av1/common/x86/highbd_inv_txfm_avx2.c
index 93e98e4..adc2ff2 100644
--- a/av1/common/x86/highbd_inv_txfm_avx2.c
+++ b/av1/common/x86/highbd_inv_txfm_avx2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #include <assert.h>
 #include <immintrin.h>
diff --git a/av1/common/x86/highbd_inv_txfm_sse4.c b/av1/common/x86/highbd_inv_txfm_sse4.c
index 7c32b49..eddf5b0 100644
--- a/av1/common/x86/highbd_inv_txfm_sse4.c
+++ b/av1/common/x86/highbd_inv_txfm_sse4.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #include <assert.h>
 #include <smmintrin.h> /* SSE4.1 */
diff --git a/av1/common/x86/highbd_jnt_convolve_avx2.c b/av1/common/x86/highbd_jnt_convolve_avx2.c
index fa27571..62674f8 100644
--- a/av1/common/x86/highbd_jnt_convolve_avx2.c
+++ b/av1/common/x86/highbd_jnt_convolve_avx2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <immintrin.h>
diff --git a/av1/common/x86/highbd_jnt_convolve_sse4.c b/av1/common/x86/highbd_jnt_convolve_sse4.c
index 00ff22f..dd351ac 100644
--- a/av1/common/x86/highbd_jnt_convolve_sse4.c
+++ b/av1/common/x86/highbd_jnt_convolve_sse4.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <smmintrin.h>
diff --git a/av1/common/x86/highbd_txfm_utility_sse4.h b/av1/common/x86/highbd_txfm_utility_sse4.h
index 5734810..641994d 100644
--- a/av1/common/x86/highbd_txfm_utility_sse4.h
+++ b/av1/common/x86/highbd_txfm_utility_sse4.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_COMMON_X86_HIGHBD_TXFM_UTILITY_SSE4_H_
diff --git a/av1/common/x86/highbd_warp_affine_avx2.c b/av1/common/x86/highbd_warp_affine_avx2.c
index 5ba83f0..4b0effc 100644
--- a/av1/common/x86/highbd_warp_affine_avx2.c
+++ b/av1/common/x86/highbd_warp_affine_avx2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #include <immintrin.h>
 
diff --git a/av1/common/x86/highbd_warp_plane_sse4.c b/av1/common/x86/highbd_warp_plane_sse4.c
index 9e1cc26..f228e47 100644
--- a/av1/common/x86/highbd_warp_plane_sse4.c
+++ b/av1/common/x86/highbd_warp_plane_sse4.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <smmintrin.h>
diff --git a/av1/common/x86/highbd_wiener_convolve_avx2.c b/av1/common/x86/highbd_wiener_convolve_avx2.c
index 0c8a850..419a48d 100644
--- a/av1/common/x86/highbd_wiener_convolve_avx2.c
+++ b/av1/common/x86/highbd_wiener_convolve_avx2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <immintrin.h>
diff --git a/av1/common/x86/highbd_wiener_convolve_ssse3.c b/av1/common/x86/highbd_wiener_convolve_ssse3.c
index 818b109..26c3f9a 100644
--- a/av1/common/x86/highbd_wiener_convolve_ssse3.c
+++ b/av1/common/x86/highbd_wiener_convolve_ssse3.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <tmmintrin.h>
diff --git a/av1/common/x86/intra_edge_sse4.c b/av1/common/x86/intra_edge_sse4.c
index fc69f41..3ed27bb 100644
--- a/av1/common/x86/intra_edge_sse4.c
+++ b/av1/common/x86/intra_edge_sse4.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/av1/common/x86/jnt_convolve_avx2.c b/av1/common/x86/jnt_convolve_avx2.c
index c42ebc1..95d40dc 100644
--- a/av1/common/x86/jnt_convolve_avx2.c
+++ b/av1/common/x86/jnt_convolve_avx2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <immintrin.h>
@@ -118,11 +119,17 @@
           }
         } else {
           const __m128i res_0 = _mm256_castsi256_si128(res_unsigned);
-          _mm_store_si128((__m128i *)(&dst[i * dst_stride + j]), res_0);
-
           const __m128i res_1 = _mm256_extracti128_si256(res_unsigned, 1);
+
+#if CONFIG_OPTFLOW_REFINEMENT
+          _mm_storeu_si128((__m128i *)(&dst[i * dst_stride + j]), res_0);
+          _mm_storeu_si128((__m128i *)(&dst[i * dst_stride + j + dst_stride]),
+                           res_1);
+#else
+          _mm_store_si128((__m128i *)(&dst[i * dst_stride + j]), res_0);
           _mm_store_si128((__m128i *)(&dst[i * dst_stride + j + dst_stride]),
                           res_1);
+#endif  // CONFIG_OPTFLOW_REFINEMENT
         }
       }
     }
@@ -173,11 +180,16 @@
           }
         } else {
           const __m128i res_0 = _mm256_castsi256_si128(res_unsigned);
-          _mm_store_si128((__m128i *)(&dst[i * dst_stride + j]), res_0);
-
           const __m128i res_1 = _mm256_extracti128_si256(res_unsigned, 1);
+#if CONFIG_OPTFLOW_REFINEMENT
+          _mm_storeu_si128((__m128i *)(&dst[i * dst_stride + j]), res_0);
+          _mm_storeu_si128((__m128i *)(&dst[i * dst_stride + j + dst_stride]),
+                           res_1);
+#else
+          _mm_store_si128((__m128i *)(&dst[i * dst_stride + j]), res_0);
           _mm_store_si128((__m128i *)(&dst[i * dst_stride + j + dst_stride]),
                           res_1);
+#endif  // CONFIG_OPTFLOW_REFINEMENT
         }
       }
     }
@@ -312,11 +324,17 @@
             }
           } else {
             const __m128i res_0 = _mm256_castsi256_si128(res_lo_unsigned);
-            _mm_store_si128((__m128i *)(&dst[i * dst_stride + j]), res_0);
-
             const __m128i res_1 = _mm256_extracti128_si256(res_lo_unsigned, 1);
+
+#if CONFIG_OPTFLOW_REFINEMENT
+            _mm_storeu_si128((__m128i *)(&dst[i * dst_stride + j]), res_0);
+            _mm_storeu_si128((__m128i *)(&dst[i * dst_stride + j + dst_stride]),
+                             res_1);
+#else
+            _mm_store_si128((__m128i *)(&dst[i * dst_stride + j]), res_0);
             _mm_store_si128((__m128i *)(&dst[i * dst_stride + j + dst_stride]),
                             res_1);
+#endif  // CONFIG_OPTFLOW_REFINEMENT
           }
         } else {
           __m256i res_hi = convolve_lowbd_4tap(s + 3, coeffs + 1);
@@ -369,28 +387,43 @@
             const __m128i res_0 = _mm256_castsi256_si128(res_8);
             const __m128i res_1 = _mm256_extracti128_si256(res_8, 1);
 
+#if CONFIG_OPTFLOW_REFINEMENT
+            _mm_storeu_si128((__m128i *)(&dst0[i * dst_stride0 + j]), res_0);
+            _mm_storeu_si128(
+                (__m128i *)((&dst0[i * dst_stride0 + j + dst_stride0])), res_1);
+#else
             _mm_store_si128((__m128i *)(&dst0[i * dst_stride0 + j]), res_0);
             _mm_store_si128(
                 (__m128i *)((&dst0[i * dst_stride0 + j + dst_stride0])), res_1);
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
           } else {
             const __m128i res_lo_0 = _mm256_castsi256_si128(res_lo_unsigned);
-            _mm_store_si128((__m128i *)(&dst[i * dst_stride + j]), res_lo_0);
-
             const __m128i res_lo_1 =
                 _mm256_extracti128_si256(res_lo_unsigned, 1);
-            _mm_store_si128((__m128i *)(&dst[i * dst_stride + j + dst_stride]),
-                            res_lo_1);
-
             const __m128i res_hi_0 = _mm256_castsi256_si128(res_hi_unsigned);
-            _mm_store_si128((__m128i *)(&dst[i * dst_stride + j + 8]),
-                            res_hi_0);
-
             const __m128i res_hi_1 =
                 _mm256_extracti128_si256(res_hi_unsigned, 1);
+
+#if CONFIG_OPTFLOW_REFINEMENT
+            _mm_storeu_si128((__m128i *)(&dst[i * dst_stride + j]), res_lo_0);
+            _mm_storeu_si128((__m128i *)(&dst[i * dst_stride + j + dst_stride]),
+                             res_lo_1);
+            _mm_storeu_si128((__m128i *)(&dst[i * dst_stride + j + 8]),
+                             res_hi_0);
+            _mm_storeu_si128(
+                (__m128i *)(&dst[i * dst_stride + j + 8 + dst_stride]),
+                res_hi_1);
+#else
+            _mm_store_si128((__m128i *)(&dst[i * dst_stride + j]), res_lo_0);
+            _mm_store_si128((__m128i *)(&dst[i * dst_stride + j + dst_stride]),
+                            res_lo_1);
+            _mm_store_si128((__m128i *)(&dst[i * dst_stride + j + 8]),
+                            res_hi_0);
             _mm_store_si128(
                 (__m128i *)(&dst[i * dst_stride + j + 8 + dst_stride]),
                 res_hi_1);
+#endif  // CONFIG_OPTFLOW_REFINEMENT
           }
         }
         s[0] = s[1];
@@ -491,11 +524,17 @@
             }
           } else {
             const __m128i res_0 = _mm256_castsi256_si128(res_lo_unsigned);
-            _mm_store_si128((__m128i *)(&dst[i * dst_stride + j]), res_0);
-
             const __m128i res_1 = _mm256_extracti128_si256(res_lo_unsigned, 1);
+
+#if CONFIG_OPTFLOW_REFINEMENT
+            _mm_storeu_si128((__m128i *)(&dst[i * dst_stride + j]), res_0);
+            _mm_storeu_si128((__m128i *)(&dst[i * dst_stride + j + dst_stride]),
+                             res_1);
+#else
+            _mm_store_si128((__m128i *)(&dst[i * dst_stride + j]), res_0);
             _mm_store_si128((__m128i *)(&dst[i * dst_stride + j + dst_stride]),
                             res_1);
+#endif  // CONFIG_OPTFLOW_REFINEMENT
           }
         } else {
           __m256i res_hi = convolve_lowbd(s + 4, coeffs);
@@ -548,28 +587,43 @@
             const __m128i res_0 = _mm256_castsi256_si128(res_8);
             const __m128i res_1 = _mm256_extracti128_si256(res_8, 1);
 
+#if CONFIG_OPTFLOW_REFINEMENT
+            _mm_storeu_si128((__m128i *)(&dst0[i * dst_stride0 + j]), res_0);
+            _mm_storeu_si128(
+                (__m128i *)((&dst0[i * dst_stride0 + j + dst_stride0])), res_1);
+#else
             _mm_store_si128((__m128i *)(&dst0[i * dst_stride0 + j]), res_0);
             _mm_store_si128(
                 (__m128i *)((&dst0[i * dst_stride0 + j + dst_stride0])), res_1);
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
           } else {
             const __m128i res_lo_0 = _mm256_castsi256_si128(res_lo_unsigned);
-            _mm_store_si128((__m128i *)(&dst[i * dst_stride + j]), res_lo_0);
-
             const __m128i res_lo_1 =
                 _mm256_extracti128_si256(res_lo_unsigned, 1);
-            _mm_store_si128((__m128i *)(&dst[i * dst_stride + j + dst_stride]),
-                            res_lo_1);
-
             const __m128i res_hi_0 = _mm256_castsi256_si128(res_hi_unsigned);
-            _mm_store_si128((__m128i *)(&dst[i * dst_stride + j + 8]),
-                            res_hi_0);
-
             const __m128i res_hi_1 =
                 _mm256_extracti128_si256(res_hi_unsigned, 1);
+
+#if CONFIG_OPTFLOW_REFINEMENT
+            _mm_storeu_si128((__m128i *)(&dst[i * dst_stride + j]), res_lo_0);
+            _mm_storeu_si128((__m128i *)(&dst[i * dst_stride + j + dst_stride]),
+                             res_lo_1);
+            _mm_storeu_si128((__m128i *)(&dst[i * dst_stride + j + 8]),
+                             res_hi_0);
+            _mm_storeu_si128(
+                (__m128i *)(&dst[i * dst_stride + j + 8 + dst_stride]),
+                res_hi_1);
+#else
+            _mm_store_si128((__m128i *)(&dst[i * dst_stride + j]), res_lo_0);
+            _mm_store_si128((__m128i *)(&dst[i * dst_stride + j + dst_stride]),
+                            res_lo_1);
+            _mm_store_si128((__m128i *)(&dst[i * dst_stride + j + 8]),
+                            res_hi_0);
             _mm_store_si128(
                 (__m128i *)(&dst[i * dst_stride + j + 8 + dst_stride]),
                 res_hi_1);
+#endif  // CONFIG_OPTFLOW_REFINEMENT
           }
         }
         s[0] = s[1];
@@ -729,11 +783,17 @@
                 (__m128i *)((&dst0[i * dst_stride0 + j + dst_stride0])), res_1);
           } else {
             const __m128i res_0 = _mm256_castsi256_si128(res_unsigned);
-            _mm_store_si128((__m128i *)(&dst[i * dst_stride + j]), res_0);
-
             const __m128i res_1 = _mm256_extracti128_si256(res_unsigned, 1);
+
+#if CONFIG_OPTFLOW_REFINEMENT
+            _mm_storeu_si128((__m128i *)(&dst[i * dst_stride + j]), res_0);
+            _mm_storeu_si128((__m128i *)(&dst[i * dst_stride + j + dst_stride]),
+                             res_1);
+#else
+            _mm_store_si128((__m128i *)(&dst[i * dst_stride + j]), res_0);
             _mm_store_si128((__m128i *)(&dst[i * dst_stride + j + dst_stride]),
                             res_1);
+#endif  // CONFIG_OPTFLOW_REFINEMENT
           }
         } else {
           const __m256i res_16b = _mm256_packs_epi32(res_a_round, res_a_round);
@@ -762,11 +822,17 @@
 
           } else {
             const __m128i res_0 = _mm256_castsi256_si128(res_unsigned);
-            _mm_store_si128((__m128i *)(&dst[i * dst_stride + j]), res_0);
-
             const __m128i res_1 = _mm256_extracti128_si256(res_unsigned, 1);
+
+#if CONFIG_OPTFLOW_REFINEMENT
+            _mm_storeu_si128((__m128i *)(&dst[i * dst_stride + j]), res_0);
+            _mm_storeu_si128((__m128i *)(&dst[i * dst_stride + j + dst_stride]),
+                             res_1);
+#else
+            _mm_store_si128((__m128i *)(&dst[i * dst_stride + j]), res_0);
             _mm_store_si128((__m128i *)(&dst[i * dst_stride + j + dst_stride]),
                             res_1);
+#endif  // CONFIG_OPTFLOW_REFINEMENT
           }
         }
         s[0] = s[1];
@@ -891,11 +957,17 @@
           }
         } else {
           const __m128i res_0 = _mm256_castsi256_si128(res_unsigned);
-          _mm_store_si128((__m128i *)(&dst[i * dst_stride + j]), res_0);
-
           const __m128i res_1 = _mm256_extracti128_si256(res_unsigned, 1);
+
+#if CONFIG_OPTFLOW_REFINEMENT
+          _mm_storeu_si128((__m128i *)(&dst[i * dst_stride + j]), res_0);
+          _mm_storeu_si128((__m128i *)(&dst[i * dst_stride + j + dst_stride]),
+                           res_1);
+#else
+          _mm_store_si128((__m128i *)(&dst[i * dst_stride + j]), res_0);
           _mm_store_si128((__m128i *)(&dst[i * dst_stride + j + dst_stride]),
                           res_1);
+#endif  // CONFIG_OPTFLOW_REFINEMENT
         }
       }
     }
diff --git a/av1/common/x86/jnt_convolve_sse2.c b/av1/common/x86/jnt_convolve_sse2.c
index 973e225..a756b3b 100644
--- a/av1/common/x86/jnt_convolve_sse2.c
+++ b/av1/common/x86/jnt_convolve_sse2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <emmintrin.h>
diff --git a/av1/common/x86/jnt_convolve_ssse3.c b/av1/common/x86/jnt_convolve_ssse3.c
index 733f433..5068a41 100644
--- a/av1/common/x86/jnt_convolve_ssse3.c
+++ b/av1/common/x86/jnt_convolve_ssse3.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <tmmintrin.h>
diff --git a/av1/common/x86/optflow_refine_sse4.c b/av1/common/x86/optflow_refine_sse4.c
new file mode 100644
index 0000000..0d315d9
--- /dev/null
+++ b/av1/common/x86/optflow_refine_sse4.c
@@ -0,0 +1,1553 @@
+/*
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
+ *
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
+ */
+
+#include <assert.h>
+#include <emmintrin.h>  // SSE2
+#include <smmintrin.h>  /* SSE4.1 */
+
+#include "aom/aom_integer.h"
+#include "av1/common/blockd.h"
+#include "av1/common/reconinter.h"
+#include "aom_dsp/x86/synonyms.h"
+
+#if CONFIG_OPTFLOW_REFINEMENT
+static INLINE __m128i round_power_of_two_signed_epi16(__m128i v_val_d,
+                                                      const __m128i v_bias_d,
+                                                      const __m128i ones,
+                                                      const int bits) {
+  const __m128i v_sign_d = _mm_sign_epi16(ones, v_val_d);
+  __m128i reg = _mm_mullo_epi16(v_val_d, v_sign_d);
+  reg = _mm_srli_epi16(_mm_adds_epi16(reg, v_bias_d), bits);
+  return _mm_mullo_epi16(reg, v_sign_d);
+}
+
+static INLINE __m128i round_power_of_two_signed_epi32(__m128i temp1,
+                                                      __m128i temp2,
+                                                      const __m128i v_bias_d,
+                                                      const __m128i ones,
+                                                      const int bits) {
+  __m128i v_sign_d = _mm_sign_epi32(ones, temp1);
+  __m128i reg = _mm_mullo_epi32(temp1, v_sign_d);
+  reg = _mm_srli_epi32(_mm_add_epi32(reg, v_bias_d), bits);
+  temp1 = _mm_mullo_epi32(reg, v_sign_d);
+
+  v_sign_d = _mm_sign_epi32(ones, temp2);
+  reg = _mm_mullo_epi32(temp2, v_sign_d);
+  reg = _mm_srli_epi32(_mm_add_epi32(reg, v_bias_d), bits);
+  temp2 = _mm_mullo_epi32(reg, v_sign_d);
+  return (_mm_packs_epi32(temp1, temp2));
+}
+
+void av1_bicubic_grad_interpolation_sse4_1(const int16_t *pred_src,
+                                           int16_t *x_grad, int16_t *y_grad,
+                                           const int bw, const int bh) {
+#if OPFL_BICUBIC_GRAD
+  assert(bw % 8 == 0);
+  assert(bh % 8 == 0);
+
+  __m128i coeff_bi[4][2];
+  coeff_bi[0][0] =
+      _mm_set1_epi16((int16_t)coeffs_bicubic[SUBPEL_GRAD_DELTA_BITS][0][0]);
+  coeff_bi[0][1] =
+      _mm_set1_epi16((int16_t)coeffs_bicubic[SUBPEL_GRAD_DELTA_BITS][1][0]);
+  coeff_bi[1][0] =
+      _mm_set1_epi16((int16_t)coeffs_bicubic[SUBPEL_GRAD_DELTA_BITS][0][1]);
+  coeff_bi[1][1] =
+      _mm_set1_epi16((int16_t)coeffs_bicubic[SUBPEL_GRAD_DELTA_BITS][1][1]);
+  coeff_bi[2][0] = _mm_insert_epi16(coeff_bi[0][0], 42, 0);
+  coeff_bi[2][1] = _mm_insert_epi16(coeff_bi[0][1], -6, 0);
+  coeff_bi[3][0] = _mm_insert_epi16(coeff_bi[0][0], 42, 7);
+  coeff_bi[3][1] = _mm_insert_epi16(coeff_bi[0][1], -6, 7);
+  const __m128i v_bias_d = _mm_set1_epi16((1 << bicubic_bits) >> 1);
+  const __m128i ones = _mm_set1_epi16(1);
+
+#if OPFL_DOWNSAMP_QUINCUNX
+  __m128i mask_val[2] = { _mm_set_epi16(0, 1, 0, 1, 0, 1, 0, 1),
+                          _mm_set_epi16(1, 0, 1, 0, 1, 0, 1, 0) };
+#endif
+  if (bw < 16) {
+    __m128i coeff[2];
+    coeff[0] = _mm_insert_epi16(coeff_bi[2][0], 42, 7);
+    coeff[1] = _mm_insert_epi16(coeff_bi[2][1], -6, 7);
+
+    for (int col = 0; col < bh; col++) {
+      const int is_y_boundary = (col + 1 > bh - 1 || col - 1 < 0);
+      const int id_prev1 = AOMMAX(col - 1, 0);
+      const int id_prev2 = AOMMAX(col - 2, 0);
+      const int id_next1 = AOMMIN(col + 1, bh - 1);
+      const int id_next2 = AOMMIN(col + 2, bh - 1);
+#if OPFL_DOWNSAMP_QUINCUNX
+      __m128i mask = mask_val[col & 0x1];
+#endif
+      for (int row = 0; row < bw; row += 8) {
+        __m128i vpred_next1, vpred_prev1, vpred_next2, vpred_prev2;
+        __m128i temp, sub1, sub2;
+
+        // Subtract interpolated pixel at (i, j+delta) by the one at (i,
+        // j-delta)
+        const int16_t *src = &pred_src[col * bw + row];
+        vpred_prev1 =
+            _mm_set_epi16(*(src + 6), *(src + 5), *(src + 4), *(src + 3),
+                          *(src + 2), *(src + 1), *src, *src);
+        vpred_prev2 = _mm_set_epi16(*(src + 5), *(src + 4), *(src + 3),
+                                    *(src + 2), *(src + 1), *src, *src, *src);
+        vpred_next1 =
+            _mm_set_epi16(*(src + 7), *(src + 7), *(src + 6), *(src + 5),
+                          *(src + 4), *(src + 3), *(src + 2), *(src + 1));
+        vpred_next2 =
+            _mm_set_epi16(*(src + 7), *(src + 7), *(src + 7), *(src + 6),
+                          *(src + 5), *(src + 4), *(src + 3), *(src + 2));
+
+        sub1 = _mm_sub_epi16(vpred_next1, vpred_prev1);
+        sub2 = _mm_sub_epi16(vpred_next2, vpred_prev2);
+
+        temp = _mm_add_epi16(_mm_mullo_epi16(sub1, coeff[0]),
+                             _mm_mullo_epi16(sub2, coeff[1]));
+
+#if OPFL_DOWNSAMP_QUINCUNX
+        temp = _mm_mullo_epi16(temp, mask);
+#endif
+        temp =
+            round_power_of_two_signed_epi16(temp, v_bias_d, ones, bicubic_bits);
+
+        const int idx = col * bw + row;
+        xx_storeu_128(x_grad + idx, temp);
+
+        // Subtract interpolated pixel at (i+delta, j) by the one at (i-delta,
+        // j)
+        src = pred_src + row;
+        vpred_prev1 = xx_loadu_128(src + id_prev1 * bw);
+        vpred_prev2 = xx_loadu_128(src + id_prev2 * bw);
+        vpred_next1 = xx_loadu_128(src + id_next1 * bw);
+        vpred_next2 = xx_loadu_128(src + id_next2 * bw);
+
+        sub1 = _mm_sub_epi16(vpred_next1, vpred_prev1);
+        sub2 = _mm_sub_epi16(vpred_next2, vpred_prev2);
+
+        temp = _mm_add_epi16(_mm_mullo_epi16(sub1, coeff_bi[is_y_boundary][0]),
+                             _mm_mullo_epi16(sub2, coeff_bi[is_y_boundary][1]));
+
+#if OPFL_DOWNSAMP_QUINCUNX
+        temp = _mm_mullo_epi16(temp, mask);
+#endif
+        temp =
+            round_power_of_two_signed_epi16(temp, v_bias_d, ones, bicubic_bits);
+        xx_storeu_128(y_grad + idx, temp);
+      }
+    }
+  } else {
+    for (int col = 0; col < bh; col++) {
+      const int is_y_boundary = (col + 1 > bh - 1 || col - 1 < 0);
+      const int id_prev = AOMMAX(col - 1, 0);
+      const int id_prev2 = AOMMAX(col - 2, 0);
+      const int id_next = AOMMIN(col + 1, bh - 1);
+      const int id_next2 = AOMMIN(col + 2, bh - 1);
+#if OPFL_DOWNSAMP_QUINCUNX
+      __m128i mask = mask_val[col & 0x1];
+#endif
+      for (int row = 0; row < bw; row += 16) {
+        __m128i vpred_next1_1, vpred_prev1_1, vpred_next2_1, vpred_prev2_1;
+        __m128i vpred_next1_2, vpred_prev1_2, vpred_next2_2, vpred_prev2_2;
+        __m128i temp1, temp2;
+        __m128i sub1, sub2, sub3, sub4;
+
+        // Subtract interpolated pixel at (i, j+delta) by the one at (i,
+        // j-delta)
+        const int16_t *src = &pred_src[col * bw + row];
+        if (row - 1 < 0) {
+          vpred_prev1_1 =
+              _mm_set_epi16(*(src + 6), *(src + 5), *(src + 4), *(src + 3),
+                            *(src + 2), *(src + 1), *src, *src);
+          vpred_prev2_1 =
+              _mm_set_epi16(*(src + 5), *(src + 4), *(src + 3), *(src + 2),
+                            *(src + 1), *src, *src, *src);
+        } else {
+          vpred_prev1_1 = xx_loadu_128((__m128i *)(src - 1));
+          vpred_prev2_1 = xx_loadu_128((__m128i *)(src - 2));
+        }
+        if (row + 16 > bw - 1) {
+          vpred_next1_2 =
+              _mm_set_epi16(*(src + 15), *(src + 15), *(src + 14), *(src + 13),
+                            *(src + 12), *(src + 11), *(src + 10), *(src + 9));
+          vpred_next2_2 =
+              _mm_set_epi16(*(src + 15), *(src + 15), *(src + 15), *(src + 14),
+                            *(src + 13), *(src + 12), *(src + 11), *(src + 10));
+        } else {
+          vpred_next1_2 = xx_loadu_128(src + 9);
+          vpred_next2_2 = xx_loadu_128(src + 10);
+        }
+        vpred_prev1_2 = xx_loadu_128(src + 7);
+        vpred_prev2_2 = xx_loadu_128(src + 6);
+        vpred_next1_1 = xx_loadu_128(src + 1);
+        vpred_next2_1 = xx_loadu_128(src + 2);
+
+        sub1 = _mm_sub_epi16(vpred_next1_1, vpred_prev1_1);
+        sub2 = _mm_sub_epi16(vpred_next2_1, vpred_prev2_1);
+
+        sub3 = _mm_sub_epi16(vpred_next1_2, vpred_prev1_2);
+        sub4 = _mm_sub_epi16(vpred_next2_2, vpred_prev2_2);
+
+        const int is_left_boundary = row - 1 < 0 ? 2 : 0;
+        const int is_right_boundary = row + 16 > bw - 1 ? 3 : 0;
+        temp1 =
+            _mm_add_epi16(_mm_mullo_epi16(sub1, coeff_bi[is_left_boundary][0]),
+                          _mm_mullo_epi16(sub2, coeff_bi[is_left_boundary][1]));
+        temp2 = _mm_add_epi16(
+            _mm_mullo_epi16(sub3, coeff_bi[is_right_boundary][0]),
+            _mm_mullo_epi16(sub4, coeff_bi[is_right_boundary][1]));
+
+#if OPFL_DOWNSAMP_QUINCUNX
+        temp1 = _mm_mullo_epi16(temp1, mask);
+        temp2 = _mm_mullo_epi16(temp2, mask);
+#endif
+        temp1 = round_power_of_two_signed_epi16(temp1, v_bias_d, ones,
+                                                bicubic_bits);
+        temp2 = round_power_of_two_signed_epi16(temp2, v_bias_d, ones,
+                                                bicubic_bits);
+
+        const int idx = col * bw + row;
+        xx_storeu_128(x_grad + idx, temp1);
+        xx_storeu_128(x_grad + idx + 8, temp2);
+
+        // Subtract interpolated pixel at (i+delta, j) by the one at (i-delta,
+        // j)
+        src = pred_src + row;
+        vpred_prev1_1 = xx_loadu_128(src + bw * id_prev);
+        vpred_prev2_1 = xx_loadu_128(src + bw * id_prev2);
+        vpred_next1_1 = xx_loadu_128(src + id_next * bw);
+        vpred_next2_1 = xx_loadu_128(src + id_next2 * bw);
+
+        vpred_prev1_2 = xx_loadu_128(src + bw * id_prev + 8);
+        vpred_prev2_2 = xx_loadu_128(src + bw * id_prev2 + 8);
+        vpred_next1_2 = xx_loadu_128(src + id_next * bw + 8);
+        vpred_next2_2 = xx_loadu_128(src + id_next2 * bw + 8);
+
+        sub1 = _mm_sub_epi16(vpred_next1_1, vpred_prev1_1);
+        sub2 = _mm_sub_epi16(vpred_next2_1, vpred_prev2_1);
+
+        sub3 = _mm_sub_epi16(vpred_next1_2, vpred_prev1_2);
+        sub4 = _mm_sub_epi16(vpred_next2_2, vpred_prev2_2);
+
+        temp1 =
+            _mm_add_epi16(_mm_mullo_epi16(sub1, coeff_bi[is_y_boundary][0]),
+                          _mm_mullo_epi16(sub2, coeff_bi[is_y_boundary][1]));
+        temp2 =
+            _mm_add_epi16(_mm_mullo_epi16(sub3, coeff_bi[is_y_boundary][0]),
+                          _mm_mullo_epi16(sub4, coeff_bi[is_y_boundary][1]));
+#if OPFL_DOWNSAMP_QUINCUNX
+        temp1 = _mm_mullo_epi16(temp1, mask);
+        temp2 = _mm_mullo_epi16(temp2, mask);
+#endif
+        temp1 = round_power_of_two_signed_epi16(temp1, v_bias_d, ones,
+                                                bicubic_bits);
+        temp2 = round_power_of_two_signed_epi16(temp2, v_bias_d, ones,
+                                                bicubic_bits);
+
+        xx_storeu_128(y_grad + idx, temp1);
+        xx_storeu_128(y_grad + idx + 8, temp2);
+      }
+    }
+  }
+#else
+  (void)pred_src;
+  (void)x_grad;
+  (void)y_grad;
+  (void)bw;
+  (void)bh;
+#endif  // OPFL_BICUBIC_GRAD
+}
+
+void av1_bicubic_grad_interpolation_highbd_sse4_1(const int16_t *pred_src,
+                                                  int16_t *x_grad,
+                                                  int16_t *y_grad, const int bw,
+                                                  const int bh) {
+#if OPFL_BICUBIC_GRAD
+  assert(bw % 8 == 0);
+  assert(bh % 8 == 0);
+
+  __m128i coeff_bi[4][2];
+  coeff_bi[0][0] = _mm_set1_epi32(coeffs_bicubic[SUBPEL_GRAD_DELTA_BITS][0][0]);
+  coeff_bi[0][1] = _mm_set1_epi32(coeffs_bicubic[SUBPEL_GRAD_DELTA_BITS][1][0]);
+  coeff_bi[1][0] = _mm_set1_epi32(coeffs_bicubic[SUBPEL_GRAD_DELTA_BITS][0][1]);
+  coeff_bi[1][1] = _mm_set1_epi32(coeffs_bicubic[SUBPEL_GRAD_DELTA_BITS][1][1]);
+  coeff_bi[2][0] = _mm_insert_epi32(coeff_bi[0][0], 42, 0);
+  coeff_bi[2][1] = _mm_insert_epi32(coeff_bi[0][1], -6, 0);
+  coeff_bi[3][0] = _mm_insert_epi32(coeff_bi[0][0], 42, 3);
+  coeff_bi[3][1] = _mm_insert_epi32(coeff_bi[0][1], -6, 3);
+  const __m128i v_bias_d = _mm_set1_epi32((1 << bicubic_bits) >> 1);
+  __m128i zero = _mm_setzero_si128();
+  const __m128i ones = _mm_set1_epi32(1);
+
+#if OPFL_DOWNSAMP_QUINCUNX
+  __m128i mask_val[2] = { _mm_set_epi32(0, 1, 0, 1),
+                          _mm_set_epi32(1, 0, 1, 0) };
+#endif
+
+  if (bw < 16) {
+    for (int col = 0; col < bh; col++) {
+      const int is_y_boundary = (col + 1 > bh - 1 || col - 1 < 0);
+      const int id_prev1 = AOMMAX(col - 1, 0);
+      const int id_prev2 = AOMMAX(col - 2, 0);
+      const int id_next1 = AOMMIN(col + 1, bh - 1);
+      const int id_next2 = AOMMIN(col + 2, bh - 1);
+
+#if OPFL_DOWNSAMP_QUINCUNX
+      __m128i mask = mask_val[col & 0x1];
+#endif
+      for (int row = 0; row < bw; row += 8) {
+        __m128i vpred_next1, vpred_prev1, vpred_next2, vpred_prev2;
+        __m128i temp1, temp2, sub1, sub2, sub3, sub4;
+        const int16_t *src = &pred_src[col * bw + row];
+        vpred_prev1 =
+            _mm_set_epi16(*(src + 6), *(src + 5), *(src + 4), *(src + 3),
+                          *(src + 2), *(src + 1), *src, *src);
+        vpred_prev2 = _mm_set_epi16(*(src + 5), *(src + 4), *(src + 3),
+                                    *(src + 2), *(src + 1), *src, *src, *src);
+        vpred_next1 =
+            _mm_set_epi16(*(src + 7), *(src + 7), *(src + 6), *(src + 5),
+                          *(src + 4), *(src + 3), *(src + 2), *(src + 1));
+        vpred_next2 =
+            _mm_set_epi16(*(src + 7), *(src + 7), *(src + 7), *(src + 6),
+                          *(src + 5), *(src + 4), *(src + 3), *(src + 2));
+
+        sub1 = _mm_sub_epi32(_mm_unpacklo_epi16(vpred_next1, zero),
+                             _mm_unpacklo_epi16(vpred_prev1, zero));
+        sub2 = _mm_sub_epi32(_mm_unpackhi_epi16(vpred_next1, zero),
+                             _mm_unpackhi_epi16(vpred_prev1, zero));
+        sub3 = _mm_sub_epi32(_mm_unpacklo_epi16(vpred_next2, zero),
+                             _mm_unpacklo_epi16(vpred_prev2, zero));
+        sub4 = _mm_sub_epi32(_mm_unpackhi_epi16(vpred_next2, zero),
+                             _mm_unpackhi_epi16(vpred_prev2, zero));
+
+        temp1 = _mm_add_epi32(_mm_mullo_epi32(sub1, coeff_bi[2][0]),
+                              _mm_mullo_epi32(sub3, coeff_bi[2][1]));
+        temp2 = _mm_add_epi32(_mm_mullo_epi32(sub2, coeff_bi[3][0]),
+                              _mm_mullo_epi32(sub4, coeff_bi[3][1]));
+
+#if OPFL_DOWNSAMP_QUINCUNX
+        temp1 = _mm_mullo_epi32(temp1, mask);
+        temp2 = _mm_mullo_epi32(temp2, mask);
+#endif
+        temp1 = round_power_of_two_signed_epi32(temp1, temp2, v_bias_d, ones,
+                                                bicubic_bits);
+
+        const int idx = col * bw + row;
+        xx_storeu_128(x_grad + idx, temp1);
+
+        src = pred_src + row;
+        vpred_prev1 = xx_loadu_128(src + id_prev1 * bw);
+        vpred_prev2 = xx_loadu_128(src + id_prev2 * bw);
+        vpred_next1 = xx_loadu_128(src + id_next1 * bw);
+        vpred_next2 = xx_loadu_128(src + id_next2 * bw);
+
+        sub1 = _mm_sub_epi32(_mm_unpacklo_epi16(vpred_next1, zero),
+                             _mm_unpacklo_epi16(vpred_prev1, zero));
+        sub2 = _mm_sub_epi32(_mm_unpackhi_epi16(vpred_next1, zero),
+                             _mm_unpackhi_epi16(vpred_prev1, zero));
+        sub3 = _mm_sub_epi32(_mm_unpacklo_epi16(vpred_next2, zero),
+                             _mm_unpacklo_epi16(vpred_prev2, zero));
+        sub4 = _mm_sub_epi32(_mm_unpackhi_epi16(vpred_next2, zero),
+                             _mm_unpackhi_epi16(vpred_prev2, zero));
+
+        temp1 =
+            _mm_add_epi32(_mm_mullo_epi32(sub1, coeff_bi[is_y_boundary][0]),
+                          _mm_mullo_epi32(sub3, coeff_bi[is_y_boundary][1]));
+        temp2 =
+            _mm_add_epi32(_mm_mullo_epi32(sub2, coeff_bi[is_y_boundary][0]),
+                          _mm_mullo_epi32(sub4, coeff_bi[is_y_boundary][1]));
+
+#if OPFL_DOWNSAMP_QUINCUNX
+        temp1 = _mm_mullo_epi32(temp1, mask);
+        temp2 = _mm_mullo_epi32(temp2, mask);
+#endif
+        temp1 = round_power_of_two_signed_epi32(temp1, temp2, v_bias_d, ones,
+                                                bicubic_bits);
+        xx_storeu_128(y_grad + idx, temp1);
+      }
+    }
+  } else {
+    for (int col = 0; col < bh; col++) {
+      const int is_y_boundary = (col + 1 > bh - 1 || col - 1 < 0);
+      const int id_prev = AOMMAX(col - 1, 0);
+      const int id_prev2 = AOMMAX(col - 2, 0);
+      const int id_next = AOMMIN(col + 1, bh - 1);
+      const int id_next2 = AOMMIN(col + 2, bh - 1);
+#if OPFL_DOWNSAMP_QUINCUNX
+      __m128i mask = mask_val[col & 0x1];
+#endif
+      for (int row = 0; row < bw; row += 16) {
+        __m128i vpred_next1_1, vpred_prev1_1, vpred_next2_1, vpred_prev2_1;
+        __m128i vpred_next1_2, vpred_prev1_2, vpred_next2_2, vpred_prev2_2;
+        __m128i temp1, temp2;
+        __m128i sub1, sub2, sub3, sub4;
+
+        const int16_t *src = &pred_src[col * bw + row];
+
+        if (row - 1 < 0) {
+          vpred_prev1_1 =
+              _mm_set_epi16(*(src + 6), *(src + 5), *(src + 4), *(src + 3),
+                            *(src + 2), *(src + 1), *src, *src);
+          vpred_prev2_1 =
+              _mm_set_epi16(*(src + 5), *(src + 4), *(src + 3), *(src + 2),
+                            *(src + 1), *src, *src, *src);
+        } else {
+          vpred_prev1_1 = xx_loadu_128((__m128i *)(src - 1));
+          vpred_prev2_1 = xx_loadu_128((__m128i *)(src - 2));
+        }
+        if (row + 16 > bw - 1) {
+          vpred_next1_2 =
+              _mm_set_epi16(*(src + 15), *(src + 15), *(src + 14), *(src + 13),
+                            *(src + 12), *(src + 11), *(src + 10), *(src + 9));
+          vpred_next2_2 =
+              _mm_set_epi16(*(src + 15), *(src + 15), *(src + 15), *(src + 14),
+                            *(src + 13), *(src + 12), *(src + 11), *(src + 10));
+        } else {
+          vpred_next1_2 = xx_loadu_128(src + 9);
+          vpred_next2_2 = xx_loadu_128(src + 10);
+        }
+        vpred_prev1_2 = xx_loadu_128(src + 7);
+        vpred_prev2_2 = xx_loadu_128(src + 6);
+        vpred_next1_1 = xx_loadu_128(src + 1);
+        vpred_next2_1 = xx_loadu_128(src + 2);
+
+        sub1 = _mm_sub_epi32(_mm_unpacklo_epi16(vpred_next1_1, zero),
+                             _mm_unpacklo_epi16(vpred_prev1_1, zero));
+        sub2 = _mm_sub_epi32(_mm_unpackhi_epi16(vpred_next1_1, zero),
+                             _mm_unpackhi_epi16(vpred_prev1_1, zero));
+        sub3 = _mm_sub_epi32(_mm_unpacklo_epi16(vpred_next2_1, zero),
+                             _mm_unpacklo_epi16(vpred_prev2_1, zero));
+        sub4 = _mm_sub_epi32(_mm_unpackhi_epi16(vpred_next2_1, zero),
+                             _mm_unpackhi_epi16(vpred_prev2_1, zero));
+
+        const int is_left_boundary = row - 1 < 0 ? 2 : 0;
+        const int is_right_boundary = row + 16 > bw - 1 ? 3 : 0;
+        temp1 =
+            _mm_add_epi32(_mm_mullo_epi32(sub1, coeff_bi[is_left_boundary][0]),
+                          _mm_mullo_epi32(sub3, coeff_bi[is_left_boundary][1]));
+        temp2 = _mm_add_epi32(_mm_mullo_epi32(sub2, coeff_bi[0][0]),
+                              _mm_mullo_epi32(sub4, coeff_bi[0][1]));
+
+#if OPFL_DOWNSAMP_QUINCUNX
+        temp1 = _mm_mullo_epi32(temp1, mask);
+        temp2 = _mm_mullo_epi32(temp2, mask);
+#endif
+        temp1 = round_power_of_two_signed_epi32(temp1, temp2, v_bias_d, ones,
+                                                bicubic_bits);
+
+        const int idx = col * bw + row;
+        xx_storeu_128(x_grad + idx, temp1);
+
+        sub1 = _mm_sub_epi32(_mm_unpacklo_epi16(vpred_next1_2, zero),
+                             _mm_unpacklo_epi16(vpred_prev1_2, zero));
+        sub2 = _mm_sub_epi32(_mm_unpackhi_epi16(vpred_next1_2, zero),
+                             _mm_unpackhi_epi16(vpred_prev1_2, zero));
+        sub3 = _mm_sub_epi32(_mm_unpacklo_epi16(vpred_next2_2, zero),
+                             _mm_unpacklo_epi16(vpred_prev2_2, zero));
+        sub4 = _mm_sub_epi32(_mm_unpackhi_epi16(vpred_next2_2, zero),
+                             _mm_unpackhi_epi16(vpred_prev2_2, zero));
+
+        temp1 = _mm_add_epi32(_mm_mullo_epi32(sub1, coeff_bi[0][0]),
+                              _mm_mullo_epi32(sub3, coeff_bi[0][1]));
+        temp2 = _mm_add_epi32(
+            _mm_mullo_epi32(sub2, coeff_bi[is_right_boundary][0]),
+            _mm_mullo_epi32(sub4, coeff_bi[is_right_boundary][1]));
+
+#if OPFL_DOWNSAMP_QUINCUNX
+        temp1 = _mm_mullo_epi32(temp1, mask);
+        temp2 = _mm_mullo_epi32(temp2, mask);
+#endif
+        temp1 = round_power_of_two_signed_epi32(temp1, temp2, v_bias_d, ones,
+                                                bicubic_bits);
+        xx_storeu_128(x_grad + idx + 8, temp1);
+
+        src = pred_src + row;
+        vpred_prev1_1 = xx_loadu_128(src + bw * id_prev);
+        vpred_prev2_1 = xx_loadu_128(src + bw * id_prev2);
+        vpred_next1_1 = xx_loadu_128(src + id_next * bw);
+        vpred_next2_1 = xx_loadu_128(src + id_next2 * bw);
+
+        vpred_prev1_2 = xx_loadu_128(src + bw * id_prev + 8);
+        vpred_prev2_2 = xx_loadu_128(src + bw * id_prev2 + 8);
+        vpred_next1_2 = xx_loadu_128(src + id_next * bw + 8);
+        vpred_next2_2 = xx_loadu_128(src + id_next2 * bw + 8);
+
+        sub1 = _mm_sub_epi32(_mm_unpacklo_epi16(vpred_next1_1, zero),
+                             _mm_unpacklo_epi16(vpred_prev1_1, zero));
+        sub2 = _mm_sub_epi32(_mm_unpackhi_epi16(vpred_next1_1, zero),
+                             _mm_unpackhi_epi16(vpred_prev1_1, zero));
+        sub3 = _mm_sub_epi32(_mm_unpacklo_epi16(vpred_next2_1, zero),
+                             _mm_unpacklo_epi16(vpred_prev2_1, zero));
+        sub4 = _mm_sub_epi32(_mm_unpackhi_epi16(vpred_next2_1, zero),
+                             _mm_unpackhi_epi16(vpred_prev2_1, zero));
+
+        temp1 =
+            _mm_add_epi32(_mm_mullo_epi32(sub1, coeff_bi[is_y_boundary][0]),
+                          _mm_mullo_epi32(sub3, coeff_bi[is_y_boundary][1]));
+        temp2 =
+            _mm_add_epi32(_mm_mullo_epi32(sub2, coeff_bi[is_y_boundary][0]),
+                          _mm_mullo_epi32(sub4, coeff_bi[is_y_boundary][1]));
+#if OPFL_DOWNSAMP_QUINCUNX
+        temp1 = _mm_mullo_epi32(temp1, mask);
+        temp2 = _mm_mullo_epi32(temp2, mask);
+#endif
+
+        temp1 = round_power_of_two_signed_epi32(temp1, temp2, v_bias_d, ones,
+                                                bicubic_bits);
+        xx_storeu_128(y_grad + idx, temp1);
+
+        sub1 = _mm_sub_epi32(_mm_unpacklo_epi16(vpred_next1_2, zero),
+                             _mm_unpacklo_epi16(vpred_prev1_2, zero));
+        sub2 = _mm_sub_epi32(_mm_unpackhi_epi16(vpred_next1_2, zero),
+                             _mm_unpackhi_epi16(vpred_prev1_2, zero));
+        sub3 = _mm_sub_epi32(_mm_unpacklo_epi16(vpred_next2_2, zero),
+                             _mm_unpacklo_epi16(vpred_prev2_2, zero));
+        sub4 = _mm_sub_epi32(_mm_unpackhi_epi16(vpred_next2_2, zero),
+                             _mm_unpackhi_epi16(vpred_prev2_2, zero));
+        temp1 =
+            _mm_add_epi32(_mm_mullo_epi32(sub1, coeff_bi[is_y_boundary][0]),
+                          _mm_mullo_epi32(sub3, coeff_bi[is_y_boundary][1]));
+        temp2 =
+            _mm_add_epi32(_mm_mullo_epi32(sub2, coeff_bi[is_y_boundary][0]),
+                          _mm_mullo_epi32(sub4, coeff_bi[is_y_boundary][1]));
+#if OPFL_DOWNSAMP_QUINCUNX
+        temp1 = _mm_mullo_epi32(temp1, mask);
+        temp2 = _mm_mullo_epi32(temp2, mask);
+#endif
+        temp1 = round_power_of_two_signed_epi32(temp1, temp2, v_bias_d, ones,
+                                                bicubic_bits);
+        xx_storeu_128(y_grad + idx + 8, temp1);
+      }
+    }
+  }
+#else
+  (void)pred_src;
+  (void)x_grad;
+  (void)y_grad;
+  (void)bw;
+  (void)bh;
+#endif  // OPFL_BICUBIC_GRAD
+}
+
+static INLINE __m128i LoadLo8(const void *a) {
+  return _mm_loadl_epi64((const __m128i *)a);
+}
+
+static INLINE __m128i LoadAligned16(const void *a) {
+  return _mm_load_si128((const __m128i *)a);
+}
+
+static INLINE __m128i LoadUnaligned16(const void *a) {
+  return _mm_loadu_si128((const __m128i *)a);
+}
+
+static AOM_FORCE_INLINE void down_sample(
+    __m128i *gradX0, __m128i *gradX1, __m128i *gradY0, __m128i *gradY1,
+    __m128i *pred0, __m128i *pred1, const __m128i *pred0_odd,
+    const __m128i *pred1_odd, const int16_t *gx0, const int16_t *gx1,
+    const int16_t *gy0, const int16_t *gy1, int gstride) {
+  const __m128i odd = _mm_set_epi16(0xFFFF, 0, 0xFFFF, 0, 0xFFFF, 0, 0xFFFF, 0);
+  const __m128i even =
+      _mm_set_epi16(0, 0xFFFF, 0, 0xFFFF, 0, 0xFFFF, 0, 0xFFFF);
+
+  const __m128i gradX01 = LoadAligned16(gx0 + gstride);
+  const __m128i gradX11 = LoadAligned16(gx1 + gstride);
+  const __m128i gradY01 = LoadAligned16(gy0 + gstride);
+  const __m128i gradY11 = LoadAligned16(gy1 + gstride);
+
+  gradX0[0] =
+      _mm_or_si128(_mm_and_si128(gradX0[0], even), _mm_and_si128(gradX01, odd));
+  gradX1[0] =
+      _mm_or_si128(_mm_and_si128(gradX1[0], even), _mm_and_si128(gradX11, odd));
+  gradY0[0] =
+      _mm_or_si128(_mm_and_si128(gradY0[0], even), _mm_and_si128(gradY01, odd));
+  gradY1[0] =
+      _mm_or_si128(_mm_and_si128(gradY1[0], even), _mm_and_si128(gradY11, odd));
+
+  pred0[0] = _mm_or_si128(_mm_and_si128(pred0[0], even),
+                          _mm_and_si128(pred0_odd[0], odd));
+  pred1[0] = _mm_or_si128(_mm_and_si128(pred1[0], even),
+                          _mm_and_si128(pred1_odd[0], odd));
+}
+
+static AOM_FORCE_INLINE void set_distance(__m128i *dist_d0, __m128i *dist_d0d1,
+                                          int d0, int d1) {
+  __m128i zero = _mm_setzero_si128();
+  dist_d0[0] = _mm_set1_epi16(d0);
+  dist_d0d1[0] = _mm_set1_epi16(d1);
+  dist_d0d1[0] = _mm_sub_epi16(zero, dist_d0d1[0]);
+  dist_d0d1[0] = _mm_unpacklo_epi16(_mm_set1_epi16(d0), dist_d0d1[0]);
+  dist_d0[0] = _mm_sub_epi16(zero, dist_d0[0]);
+  dist_d0[0] = _mm_unpacklo_epi16(_mm_set1_epi16(d0), dist_d0[0]);
+}
+
+static AOM_FORCE_INLINE void leastsquare_8x8(__m128i *grad0, __m128i *grad1,
+                                             __m128i *grad0_13,
+                                             __m128i *grad1_13, __m128i *g2,
+                                             const __m128i dist_d0d1) {
+  __m128i samplesL, samplesH, temp;
+
+  samplesL = _mm_unpacklo_epi16(grad0[0], grad1[0]);
+  samplesH = _mm_unpackhi_epi16(grad0[0], grad1[0]);
+  grad0[0] = _mm_madd_epi16(samplesL, dist_d0d1);
+  grad1[0] = _mm_madd_epi16(samplesH, dist_d0d1);
+  temp = _mm_add_epi64(g2[0], _mm_mul_epi32(grad0[0], grad0[0]));
+  g2[0] = _mm_add_epi64(temp, _mm_mul_epi32(grad1[0], grad1[0]));
+  grad0_13[0] = _mm_srli_si128(grad0[0], 4);
+  temp = _mm_add_epi64(g2[0], _mm_mul_epi32(grad0_13[0], grad0_13[0]));
+  grad1_13[0] = _mm_srli_si128(grad1[0], 4);
+  g2[0] = _mm_add_epi64(temp, _mm_mul_epi32(grad1_13[0], grad1_13[0]));
+}
+
+static AOM_FORCE_INLINE void leastsquare_8x4(
+    __m128i *grad0_02, __m128i *grad1_02, __m128i *grad0_13, __m128i *grad1_13,
+    __m128i *g2_0, __m128i *g2_1, const __m128i dist_d0d1) {
+  __m128i samplesL, samplesH, temp;
+
+  samplesL = _mm_unpacklo_epi16(grad0_02[0], grad1_02[0]);
+  samplesH = _mm_unpackhi_epi16(grad0_02[0], grad1_02[0]);
+  grad0_02[0] = _mm_madd_epi16(samplesL, dist_d0d1);
+  temp = _mm_add_epi64(g2_0[0], _mm_mul_epi32(grad0_02[0], grad0_02[0]));
+  grad0_13[0] = _mm_srli_si128(grad0_02[0], 4);
+  g2_0[0] = _mm_add_epi64(temp, _mm_mul_epi32(grad0_13[0], grad0_13[0]));
+
+  grad1_02[0] = _mm_madd_epi16(samplesH, dist_d0d1);
+  temp = _mm_add_epi64(g2_1[0], _mm_mul_epi32(grad1_02[0], grad1_02[0]));
+  grad1_13[0] = _mm_srli_si128(grad1_02[0], 4);
+  g2_1[0] = _mm_add_epi64(temp, _mm_mul_epi32(grad1_13[0], grad1_13[0]));
+}
+
+static AOM_FORCE_INLINE void accumulate_8x4(
+    const __m128i gradX0_02, const __m128i gradY0_02, const __m128i gradX1_02,
+    const __m128i gradY1_02, const __m128i gradX0_13, const __m128i gradY0_13,
+    const __m128i gradX1_13, const __m128i gradY1_13, __m128i *gg_0,
+    __m128i *gg_1) {
+  gg_0[0] = _mm_add_epi64(gg_0[0], _mm_mul_epi32(gradX0_02, gradY0_02));
+  gg_0[0] = _mm_add_epi64(gg_0[0], _mm_mul_epi32(gradX0_13, gradY0_13));
+
+  gg_1[0] = _mm_add_epi64(gg_1[0], _mm_mul_epi32(gradX1_02, gradY1_02));
+  gg_1[0] = _mm_add_epi64(gg_1[0], _mm_mul_epi32(gradX1_13, gradY1_13));
+}
+
+static AOM_FORCE_INLINE void accumulate_8x8(
+    const __m128i gradX0_02, const __m128i gradY0_02, const __m128i gradX1_02,
+    const __m128i gradY1_02, const __m128i gradX0_13, const __m128i gradY0_13,
+    const __m128i gradX1_13, const __m128i gradY1_13, __m128i *gg) {
+  gg[0] = _mm_add_epi64(gg[0], _mm_mul_epi32(gradX0_02, gradY0_02));
+  gg[0] = _mm_add_epi64(gg[0], _mm_mul_epi32(gradX1_02, gradY1_02));
+  gg[0] = _mm_add_epi64(gg[0], _mm_mul_epi32(gradX0_13, gradY0_13));
+  gg[0] = _mm_add_epi64(gg[0], _mm_mul_epi32(gradX1_13, gradY1_13));
+}
+
+static AOM_FORCE_INLINE void square_accumulate_8x4(
+    __m128i gradX0, __m128i gradX1, __m128i gradY0, __m128i gradY1,
+    __m128i *u2_0, __m128i *v2_0, __m128i *uv_0, __m128i *uw_0, __m128i *vw_0,
+    __m128i *u2_1, __m128i *v2_1, __m128i *uv_1, __m128i *uw_1, __m128i *vw_1,
+    __m128i *pred0, __m128i *pred1, const __m128i dist_d0,
+    const __m128i dist_d0d1) {
+  __m128i gradX0_13, gradX1_13, gradY0_13, gradY1_13;
+  __m128i samplesL, samplesH;
+
+  leastsquare_8x4(&gradX0, &gradX1, &gradX0_13, &gradX1_13, u2_0, u2_1,
+                  dist_d0d1);
+  leastsquare_8x4(&gradY0, &gradY1, &gradY0_13, &gradY1_13, v2_0, v2_1,
+                  dist_d0d1);
+
+  accumulate_8x4(gradX0, gradY0, gradX1, gradY1, gradX0_13, gradY0_13,
+                 gradX1_13, gradY1_13, uv_0, uv_1);
+
+  samplesL = _mm_unpacklo_epi16(pred0[0], pred1[0]);
+  samplesL = _mm_madd_epi16(samplesL, dist_d0);
+
+  samplesH = _mm_unpackhi_epi16(pred0[0], pred1[0]);
+  samplesH = _mm_madd_epi16(samplesH, dist_d0);
+
+  pred0[0] = _mm_srli_si128(samplesL, 4);
+  pred1[0] = _mm_srli_si128(samplesH, 4);
+  accumulate_8x4(gradX0, samplesL, gradX1, samplesH, gradX0_13, pred0[0],
+                 gradX1_13, pred1[0], uw_0, uw_1);
+  accumulate_8x4(gradY0, samplesL, gradY1, samplesH, gradY0_13, pred0[0],
+                 gradY1_13, pred1[0], vw_0, vw_1);
+}
+
+static AOM_FORCE_INLINE void square_accumulate_8x8(
+    __m128i gradX0, __m128i gradX1, __m128i gradY0, __m128i gradY1, __m128i *u2,
+    __m128i *v2, __m128i *uv, __m128i *uw, __m128i *vw, __m128i *pred0,
+    __m128i *pred1, const __m128i dist_d0, const __m128i dist_d0d1) {
+  __m128i gradX0_13, gradX1_13, gradY0_13, gradY1_13;
+  __m128i samplesL, samplesH;
+  leastsquare_8x8(&gradX0, &gradX1, &gradX0_13, &gradX1_13, u2, dist_d0d1);
+  leastsquare_8x8(&gradY0, &gradY1, &gradY0_13, &gradY1_13, v2, dist_d0d1);
+
+  accumulate_8x8(gradX0, gradY0, gradX1, gradY1, gradX0_13, gradY0_13,
+                 gradX1_13, gradY1_13, uv);
+
+  samplesL = _mm_unpacklo_epi16(pred0[0], pred1[0]);
+  samplesH = _mm_unpackhi_epi16(pred0[0], pred1[0]);
+  samplesL = _mm_madd_epi16(samplesL, dist_d0);
+  samplesH = _mm_madd_epi16(samplesH, dist_d0);
+
+  pred0[0] = _mm_srli_si128(samplesL, 4);
+  pred1[0] = _mm_srli_si128(samplesH, 4);
+  accumulate_8x8(gradX0, samplesL, gradX1, samplesH, gradX0_13, pred0[0],
+                 gradX1_13, pred1[0], uw);
+  accumulate_8x8(gradY0, samplesL, gradY1, samplesH, gradY0_13, pred0[0],
+                 gradY1_13, pred1[0], vw);
+}
+
+static AOM_FORCE_INLINE void calc_mv_process(int64_t su2, int64_t sv2,
+                                             int64_t suv, int64_t suw,
+                                             int64_t svw, const int d0,
+                                             const int d1, const int bits,
+                                             const int rls_alpha, int *vx0,
+                                             int *vy0, int *vx1, int *vy1) {
+#if OPFL_REGULARIZED_LS
+  su2 += rls_alpha;
+  sv2 += rls_alpha;
+#else
+  (void)rls_alpha;
+#endif
+  // Clamp su2, sv2, suv, suw, and svw to avoid overflow in det, det_x, and
+  // det_y
+  su2 = (int64_t)clamp((int)su2, -OPFL_COV_CLAMP_VAL, OPFL_COV_CLAMP_VAL);
+  sv2 = (int64_t)clamp((int)sv2, -OPFL_COV_CLAMP_VAL, OPFL_COV_CLAMP_VAL);
+  suv = (int64_t)clamp((int)suv, -OPFL_COV_CLAMP_VAL, OPFL_COV_CLAMP_VAL);
+  suw = (int64_t)clamp((int)suw, -OPFL_COV_CLAMP_VAL, OPFL_COV_CLAMP_VAL);
+  svw = (int64_t)clamp((int)svw, -OPFL_COV_CLAMP_VAL, OPFL_COV_CLAMP_VAL);
+
+  // Solve 2x2 matrix inverse: [ su2  suv ]   [ vx0 ]     [ -suw ]
+  //                           [ suv  sv2 ] * [ vy0 ]  =  [ -svw ]
+  const int64_t det = su2 * sv2 - suv * suv;
+  if (det == 0) return;
+  const int64_t det_x = (suv * svw - sv2 * suw) * (1 << bits);
+  const int64_t det_y = (suv * suw - su2 * svw) * (1 << bits);
+  *vx0 = (int)divide_and_round_signed(det_x, det);
+  *vy0 = (int)divide_and_round_signed(det_y, det);
+  const int tx1 = (*vx0) * d1;
+  const int ty1 = (*vy0) * d1;
+  *vx1 = (int)divide_and_round_signed(tx1, d0);
+  *vy1 = (int)divide_and_round_signed(ty1, d0);
+}
+
+static AOM_FORCE_INLINE void calculate_mv_8x4(
+    __m128i u2_0, __m128i v2_0, __m128i uv_0, __m128i uw_0, __m128i vw_0,
+    __m128i u2_1, __m128i v2_1, __m128i uv_1, __m128i uw_1, __m128i vw_1,
+    int d0, int d1, int mv_prec_bits, int grad_prec_bits, int *vx0, int *vy0,
+    int *vx1, int *vy1) {
+  const int bits = mv_prec_bits + grad_prec_bits;
+  int64_t su2, suv, sv2, suw, svw;
+  // As processing block size is 4x4, here '(bw * bh >> 4)' can be replaced
+  // by 1.
+  const int rls_alpha = 1 << OPFL_RLS_PARAM_BITS;
+  int64_t su2_1, suv_1, sv2_1, suw_1, svw_1;
+  u2_0 = _mm_add_epi32(u2_0, _mm_srli_si128(u2_0, 8));
+  u2_1 = _mm_add_epi32(u2_1, _mm_srli_si128(u2_1, 8));
+
+  v2_0 = _mm_add_epi32(v2_0, _mm_srli_si128(v2_0, 8));
+  v2_1 = _mm_add_epi32(v2_1, _mm_srli_si128(v2_1, 8));
+
+  uv_0 = _mm_add_epi32(uv_0, _mm_srli_si128(uv_0, 8));
+  uv_1 = _mm_add_epi32(uv_1, _mm_srli_si128(uv_1, 8));
+
+  uw_0 = _mm_add_epi32(uw_0, _mm_srli_si128(uw_0, 8));
+  uw_1 = _mm_add_epi32(uw_1, _mm_srli_si128(uw_1, 8));
+
+  vw_0 = _mm_add_epi32(vw_0, _mm_srli_si128(vw_0, 8));
+  vw_1 = _mm_add_epi32(vw_1, _mm_srli_si128(vw_1, 8));
+
+  _mm_storel_epi64((__m128i *)&su2, u2_0);
+  _mm_storel_epi64((__m128i *)&suv, uv_0);
+  _mm_storel_epi64((__m128i *)&sv2, v2_0);
+  _mm_storel_epi64((__m128i *)&suw, uw_0);
+  _mm_storel_epi64((__m128i *)&svw, vw_0);
+
+  _mm_storel_epi64((__m128i *)&su2_1, u2_1);
+  _mm_storel_epi64((__m128i *)&suv_1, uv_1);
+  _mm_storel_epi64((__m128i *)&sv2_1, v2_1);
+  _mm_storel_epi64((__m128i *)&suw_1, uw_1);
+  _mm_storel_epi64((__m128i *)&svw_1, vw_1);
+
+  calc_mv_process(su2, sv2, suv, suw, svw, d0, d1, bits, rls_alpha, vx0, vy0,
+                  vx1, vy1);
+  calc_mv_process(su2_1, sv2_1, suv_1, suw_1, svw_1, d0, d1, bits, rls_alpha,
+                  vx0 + 1, vy0 + 1, vx1 + 1, vy1 + 1);
+}
+
+static AOM_FORCE_INLINE void calculate_mv_8x8(__m128i u2, __m128i v2,
+                                              __m128i uv, __m128i uw,
+                                              __m128i vw, int d0, int d1,
+                                              int mv_prec_bits,
+                                              int grad_prec_bits, int *vx0,
+                                              int *vy0, int *vx1, int *vy1) {
+  u2 = _mm_add_epi32(u2, _mm_srli_si128(u2, 8));
+  v2 = _mm_add_epi32(v2, _mm_srli_si128(v2, 8));
+  uv = _mm_add_epi32(uv, _mm_srli_si128(uv, 8));
+  uw = _mm_add_epi32(uw, _mm_srli_si128(uw, 8));
+  vw = _mm_add_epi32(vw, _mm_srli_si128(vw, 8));
+
+  int64_t su2, suv, sv2, suw, svw;
+  const int bits = mv_prec_bits + grad_prec_bits;
+  // As processing block size is 8x8, here '(bw * bh >> 4)' can be replaced
+  // by 4.
+  const int rls_alpha = 4 << OPFL_RLS_PARAM_BITS;
+  _mm_storel_epi64((__m128i *)&su2, u2);
+  _mm_storel_epi64((__m128i *)&suv, uv);
+  _mm_storel_epi64((__m128i *)&sv2, v2);
+  _mm_storel_epi64((__m128i *)&suw, uw);
+  _mm_storel_epi64((__m128i *)&svw, vw);
+  calc_mv_process(su2, sv2, suv, suw, svw, d0, d1, bits, rls_alpha, vx0, vy0,
+                  vx1, vy1);
+}
+
+static void opfl_mv_refinement_lowbd_8x4_sse4_1(
+    const __m128i dist_d0, const __m128i dist_d0d1, const uint8_t *p0,
+    int pstride0, const uint8_t *p1, int pstride1, const int16_t *gx0,
+    const int16_t *gy0, const int16_t *gx1, const int16_t *gy1, int gstride,
+    int d0, int d1, int grad_prec_bits, int mv_prec_bits, int *vx0, int *vy0,
+    int *vx1, int *vy1) {
+  int bHeight = 4;
+  __m128i u2_0 = _mm_setzero_si128();
+  __m128i v2_0 = _mm_setzero_si128();
+  __m128i uv_0 = _mm_setzero_si128();
+  __m128i uw_0 = _mm_setzero_si128();
+  __m128i vw_0 = _mm_setzero_si128();
+  __m128i u2_1 = _mm_setzero_si128();
+  __m128i v2_1 = _mm_setzero_si128();
+  __m128i uv_1 = _mm_setzero_si128();
+  __m128i uw_1 = _mm_setzero_si128();
+  __m128i vw_1 = _mm_setzero_si128();
+
+  do {
+    __m128i gradX0 = LoadAligned16(gx0);
+    __m128i gradX1 = LoadAligned16(gx1);
+    __m128i gradY0 = LoadAligned16(gy0);
+    __m128i gradY1 = LoadAligned16(gy1);
+    __m128i pred0 = _mm_cvtepu8_epi16(LoadLo8(p0));
+    __m128i pred1 = _mm_cvtepu8_epi16(LoadLo8(p1));
+
+#if OPFL_DOWNSAMP_QUINCUNX
+    const __m128i pred0_odd = _mm_cvtepu8_epi16(LoadLo8(p0 + pstride0));
+    const __m128i pred1_odd = _mm_cvtepu8_epi16(LoadLo8(p1 + pstride1));
+
+    down_sample(&gradX0, &gradX1, &gradY0, &gradY1, &pred0, &pred1, &pred0_odd,
+                &pred1_odd, gx0, gx1, gy0, gy1, gstride);
+#endif  // OPFL_DOWNSAMP_QUINCUNX
+
+    square_accumulate_8x4(gradX0, gradX1, gradY0, gradY1, &u2_0, &v2_0, &uv_0,
+                          &uw_0, &vw_0, &u2_1, &v2_1, &uv_1, &uw_1, &vw_1,
+                          &pred0, &pred1, dist_d0, dist_d0d1);
+
+#if OPFL_DOWNSAMP_QUINCUNX
+    gx0 += gstride << 1;
+    gx1 += gstride << 1;
+    gy0 += gstride << 1;
+    gy1 += gstride << 1;
+    p0 += pstride0 << 1;
+    p1 += pstride1 << 1;
+    bHeight -= 2;
+#else
+    gx0 += gstride;
+    gx1 += gstride;
+    gy0 += gstride;
+    gy1 += gstride;
+    p0 += pstride0;
+    p1 += pstride1;
+    bHeight -= 1;
+#endif  // OPFL_DOWNSAMP_QUINCUNX
+  } while (bHeight != 0);
+
+  calculate_mv_8x4(u2_0, v2_0, uv_0, uw_0, vw_0, u2_1, v2_1, uv_1, uw_1, vw_1,
+                   d0, d1, mv_prec_bits, grad_prec_bits, vx0, vy0, vx1, vy1);
+}
+
+static void opfl_mv_refinement_lowbd_8x8_sse4_1(
+    const __m128i dist_d0, const __m128i dist_d0d1, const uint8_t *p0,
+    int pstride0, const uint8_t *p1, int pstride1, const int16_t *gx0,
+    const int16_t *gy0, const int16_t *gx1, const int16_t *gy1, int gstride,
+    int d0, int d1, int grad_prec_bits, int mv_prec_bits, int *vx0, int *vy0,
+    int *vx1, int *vy1) {
+  int bHeight = 8;
+  __m128i u2 = _mm_setzero_si128();
+  __m128i uv = _mm_setzero_si128();
+  __m128i v2 = _mm_setzero_si128();
+  __m128i uw = _mm_setzero_si128();
+  __m128i vw = _mm_setzero_si128();
+
+  do {
+    __m128i gradX0 = LoadAligned16(gx0);
+    __m128i gradX1 = LoadAligned16(gx1);
+    __m128i gradY0 = LoadAligned16(gy0);
+    __m128i gradY1 = LoadAligned16(gy1);
+    __m128i pred0 = _mm_cvtepu8_epi16(LoadLo8(p0));
+    __m128i pred1 = _mm_cvtepu8_epi16(LoadLo8(p1));
+
+#if OPFL_DOWNSAMP_QUINCUNX
+    const __m128i pred0_odd = _mm_cvtepu8_epi16(LoadLo8(p0 + pstride0));
+    const __m128i pred1_odd = _mm_cvtepu8_epi16(LoadLo8(p1 + pstride1));
+
+    down_sample(&gradX0, &gradX1, &gradY0, &gradY1, &pred0, &pred1, &pred0_odd,
+                &pred1_odd, gx0, gx1, gy0, gy1, gstride);
+#endif  // OPFL_DOWNSAMP_QUINCUNX
+
+    square_accumulate_8x8(gradX0, gradX1, gradY0, gradY1, &u2, &v2, &uv, &uw,
+                          &vw, &pred0, &pred1, dist_d0, dist_d0d1);
+
+#if OPFL_DOWNSAMP_QUINCUNX
+    gx0 += gstride << 1;
+    gx1 += gstride << 1;
+    gy0 += gstride << 1;
+    gy1 += gstride << 1;
+    p0 += pstride0 << 1;
+    p1 += pstride1 << 1;
+    bHeight -= 2;
+#else
+    gx0 += gstride;
+    gx1 += gstride;
+    gy0 += gstride;
+    gy1 += gstride;
+    p0 += pstride0;
+    p1 += pstride1;
+    bHeight -= 1;
+#endif  // OPFL_DOWNSAMP_QUINCUNX
+  } while (bHeight != 0);
+
+  calculate_mv_8x8(u2, v2, uv, uw, vw, d0, d1, mv_prec_bits, grad_prec_bits,
+                   vx0, vy0, vx1, vy1);
+}
+
+static void opfl_mv_refinement_lowbd_sse4_1(
+    const __m128i dist_d0, const __m128i dist_d0d1, const uint8_t *p0,
+    int pstride0, const uint8_t *p1, int pstride1, const int16_t *gx0,
+    const int16_t *gy0, const int16_t *gx1, const int16_t *gy1, int gstride,
+    int bw, int bh, int d0, int d1, int grad_prec_bits, int mv_prec_bits,
+    int *vx0, int *vy0, int *vx1, int *vy1) {
+  (void)bh;
+  if (bw == 4)
+    opfl_mv_refinement_lowbd_8x4_sse4_1(
+        dist_d0, dist_d0d1, p0, pstride0, p1, pstride1, gx0, gy0, gx1, gy1,
+        gstride, d0, d1, grad_prec_bits, mv_prec_bits, vx0, vy0, vx1, vy1);
+  else
+    opfl_mv_refinement_lowbd_8x8_sse4_1(
+        dist_d0, dist_d0d1, p0, pstride0, p1, pstride1, gx0, gy0, gx1, gy1,
+        gstride, d0, d1, grad_prec_bits, mv_prec_bits, vx0, vy0, vx1, vy1);
+}
+
+// Function to compute optical flow offsets in nxn blocks
+int av1_opfl_mv_refinement_nxn_lowbd_sse4_1(
+    const uint8_t *p0, int pstride0, const uint8_t *p1, int pstride1,
+    const int16_t *gx0, const int16_t *gy0, const int16_t *gx1,
+    const int16_t *gy1, int gstride, int bw, int bh, int n, int d0, int d1,
+    int grad_prec_bits, int mv_prec_bits, int *vx0, int *vy0, int *vx1,
+    int *vy1) {
+  assert(bw % n == 0 && bh % n == 0);
+  int n_blocks = 0;
+
+  __m128i dist_d0, dist_d0d1;
+  set_distance(&dist_d0, &dist_d0d1, d0, d1);
+
+  for (int i = 0; i < bh; i += n) {
+    for (int j = 0; j < bw; j += 8) {
+      opfl_mv_refinement_lowbd_sse4_1(
+          dist_d0, dist_d0d1, p0 + (i * pstride0 + j), pstride0,
+          p1 + (i * pstride1 + j), pstride1, gx0 + (i * gstride + j),
+          gy0 + (i * gstride + j), gx1 + (i * gstride + j),
+          gy1 + (i * gstride + j), gstride, n, n, d0, d1, grad_prec_bits,
+          mv_prec_bits, vx0 + n_blocks, vy0 + n_blocks, vx1 + n_blocks,
+          vy1 + n_blocks);
+      n_blocks += (n == 4) ? 2 : 1;
+    }
+  }
+  return n_blocks;
+}
+
+static void opfl_mv_refinement_highbd_8x4_sse4_1(
+    const __m128i dist_d0, const __m128i dist_d0d1, const uint16_t *p0,
+    int pstride0, const uint16_t *p1, int pstride1, const int16_t *gx0,
+    const int16_t *gy0, const int16_t *gx1, const int16_t *gy1, int gstride,
+    int d0, int d1, int grad_prec_bits, int mv_prec_bits, int *vx0, int *vy0,
+    int *vx1, int *vy1) {
+  int bHeight = 4;
+  __m128i u2_0 = _mm_setzero_si128();
+  __m128i v2_0 = _mm_setzero_si128();
+  __m128i uv_0 = _mm_setzero_si128();
+  __m128i uw_0 = _mm_setzero_si128();
+  __m128i vw_0 = _mm_setzero_si128();
+  __m128i u2_1 = _mm_setzero_si128();
+  __m128i v2_1 = _mm_setzero_si128();
+  __m128i uv_1 = _mm_setzero_si128();
+  __m128i uw_1 = _mm_setzero_si128();
+  __m128i vw_1 = _mm_setzero_si128();
+
+  do {
+    __m128i gradX0 = LoadAligned16(gx0);
+    __m128i gradX1 = LoadAligned16(gx1);
+    __m128i gradY0 = LoadAligned16(gy0);
+    __m128i gradY1 = LoadAligned16(gy1);
+    __m128i pred0 = LoadAligned16(p0);
+    __m128i pred1 = LoadAligned16(p1);
+
+#if OPFL_DOWNSAMP_QUINCUNX
+    const __m128i pred0_odd = LoadAligned16(p0 + pstride0);
+    const __m128i pred1_odd = LoadAligned16(p1 + pstride1);
+
+    down_sample(&gradX0, &gradX1, &gradY0, &gradY1, &pred0, &pred1, &pred0_odd,
+                &pred1_odd, gx0, gx1, gy0, gy1, gstride);
+#endif  // OPFL_DOWNSAMP_QUINCUNX
+
+    square_accumulate_8x4(gradX0, gradX1, gradY0, gradY1, &u2_0, &v2_0, &uv_0,
+                          &uw_0, &vw_0, &u2_1, &v2_1, &uv_1, &uw_1, &vw_1,
+                          &pred0, &pred1, dist_d0, dist_d0d1);
+
+#if OPFL_DOWNSAMP_QUINCUNX
+    gx0 += gstride << 1;
+    gx1 += gstride << 1;
+    gy0 += gstride << 1;
+    gy1 += gstride << 1;
+    p0 += pstride0 << 1;
+    p1 += pstride1 << 1;
+    bHeight -= 2;
+#else
+    gx0 += gstride;
+    gx1 += gstride;
+    gy0 += gstride;
+    gy1 += gstride;
+    p0 += pstride0;
+    p1 += pstride1;
+    bHeight -= 1;
+#endif  // OPFL_DOWNSAMP_QUINCUNX
+  } while (bHeight != 0);
+
+  calculate_mv_8x4(u2_0, v2_0, uv_0, uw_0, vw_0, u2_1, v2_1, uv_1, uw_1, vw_1,
+                   d0, d1, mv_prec_bits, grad_prec_bits, vx0, vy0, vx1, vy1);
+}
+
+static void opfl_mv_refinement_highbd_8x8_sse4_1(
+    const __m128i dist_d0, const __m128i dist_d0d1, const uint16_t *p0,
+    int pstride0, const uint16_t *p1, int pstride1, const int16_t *gx0,
+    const int16_t *gy0, const int16_t *gx1, const int16_t *gy1, int gstride,
+    int d0, int d1, int grad_prec_bits, int mv_prec_bits, int *vx0, int *vy0,
+    int *vx1, int *vy1) {
+  int bHeight = 8;
+  __m128i u2 = _mm_setzero_si128();
+  __m128i uv = _mm_setzero_si128();
+  __m128i v2 = _mm_setzero_si128();
+  __m128i uw = _mm_setzero_si128();
+  __m128i vw = _mm_setzero_si128();
+
+  do {
+    __m128i gradX0 = LoadAligned16(gx0);
+    __m128i gradX1 = LoadAligned16(gx1);
+    __m128i gradY0 = LoadAligned16(gy0);
+    __m128i gradY1 = LoadAligned16(gy1);
+    __m128i pred0 = LoadAligned16(p0);
+    __m128i pred1 = LoadAligned16(p1);
+
+#if OPFL_DOWNSAMP_QUINCUNX
+    const __m128i pred0_odd = LoadAligned16(p0 + pstride0);
+    const __m128i pred1_odd = LoadAligned16(p1 + pstride1);
+
+    down_sample(&gradX0, &gradX1, &gradY0, &gradY1, &pred0, &pred1, &pred0_odd,
+                &pred1_odd, gx0, gx1, gy0, gy1, gstride);
+#endif  // OPFL_DOWNSAMP_QUINCUNX
+    square_accumulate_8x8(gradX0, gradX1, gradY0, gradY1, &u2, &v2, &uv, &uw,
+                          &vw, &pred0, &pred1, dist_d0, dist_d0d1);
+#if OPFL_DOWNSAMP_QUINCUNX
+    gx0 += gstride << 1;
+    gx1 += gstride << 1;
+    gy0 += gstride << 1;
+    gy1 += gstride << 1;
+    p0 += pstride0 << 1;
+    p1 += pstride1 << 1;
+    bHeight -= 2;
+#else
+    gx0 += gstride;
+    gx1 += gstride;
+    gy0 += gstride;
+    gy1 += gstride;
+    p0 += pstride0;
+    p1 += pstride1;
+    bHeight -= 1;
+#endif  // OPFL_DOWNSAMP_QUINCUNX
+  } while (bHeight != 0);
+
+  calculate_mv_8x8(u2, v2, uv, uw, vw, d0, d1, mv_prec_bits, grad_prec_bits,
+                   vx0, vy0, vx1, vy1);
+}
+
+static void opfl_mv_refinement_highbd_sse4_1(
+    const __m128i dist_d0, const __m128i dist_d0d1, const uint16_t *p0,
+    int pstride0, const uint16_t *p1, int pstride1, const int16_t *gx0,
+    const int16_t *gy0, const int16_t *gx1, const int16_t *gy1, int gstride,
+    int bw, int bh, int d0, int d1, int grad_prec_bits, int mv_prec_bits,
+    int *vx0, int *vy0, int *vx1, int *vy1) {
+  (void)bh;
+  if (bw == 4)
+    opfl_mv_refinement_highbd_8x4_sse4_1(
+        dist_d0, dist_d0d1, p0, pstride0, p1, pstride1, gx0, gy0, gx1, gy1,
+        gstride, d0, d1, grad_prec_bits, mv_prec_bits, vx0, vy0, vx1, vy1);
+  else
+    opfl_mv_refinement_highbd_8x8_sse4_1(
+        dist_d0, dist_d0d1, p0, pstride0, p1, pstride1, gx0, gy0, gx1, gy1,
+        gstride, d0, d1, grad_prec_bits, mv_prec_bits, vx0, vy0, vx1, vy1);
+}
+
+// Function to compute optical flow offsets in nxn blocks
+int av1_opfl_mv_refinement_nxn_highbd_sse4_1(
+    const uint16_t *p0, int pstride0, const uint16_t *p1, int pstride1,
+    const int16_t *gx0, const int16_t *gy0, const int16_t *gx1,
+    const int16_t *gy1, int gstride, int bw, int bh, int n, int d0, int d1,
+    int grad_prec_bits, int mv_prec_bits, int *vx0, int *vy0, int *vx1,
+    int *vy1) {
+  assert(bw % n == 0 && bh % n == 0);
+  int n_blocks = 0;
+
+  __m128i dist_d0, dist_d0d1;
+  set_distance(&dist_d0, &dist_d0d1, d0, d1);
+
+  for (int i = 0; i < bh; i += n) {
+    for (int j = 0; j < bw; j += 8) {
+      opfl_mv_refinement_highbd_sse4_1(
+          dist_d0, dist_d0d1, p0 + (i * pstride0 + j), pstride0,
+          p1 + (i * pstride1 + j), pstride1, gx0 + (i * gstride + j),
+          gy0 + (i * gstride + j), gx1 + (i * gstride + j),
+          gy1 + (i * gstride + j), gstride, n, n, d0, d1, grad_prec_bits,
+          mv_prec_bits, vx0 + n_blocks, vy0 + n_blocks, vx1 + n_blocks,
+          vy1 + n_blocks);
+      n_blocks += (n == 4) ? 2 : 1;
+    }
+  }
+  return n_blocks;
+}
+
+#if OPFL_COMBINE_INTERP_GRAD_LS
+static AOM_FORCE_INLINE void calc_mv(const __m128i u2, const __m128i v2,
+                                     const __m128i uv, const __m128i uw,
+                                     const __m128i vw, const int d0,
+                                     const int d1, const int bits,
+                                     const uint8_t block_num,
+                                     const int rls_alpha, int *vx0, int *vy0,
+                                     int *vx1, int *vy1) {
+  int64_t su2, suv, sv2, suw, svw;
+  if (block_num == 0) {
+    su2 = _mm_extract_epi32(u2, 0) + _mm_extract_epi32(u2, 1);
+    sv2 = _mm_extract_epi32(v2, 0) + _mm_extract_epi32(v2, 1);
+    suv = _mm_extract_epi32(uv, 0) + _mm_extract_epi32(uv, 1);
+    suw = _mm_extract_epi32(uw, 0) + _mm_extract_epi32(uw, 1);
+    svw = _mm_extract_epi32(vw, 0) + _mm_extract_epi32(vw, 1);
+  } else {
+    su2 = _mm_extract_epi32(u2, 2) + _mm_extract_epi32(u2, 3);
+    sv2 = _mm_extract_epi32(v2, 2) + _mm_extract_epi32(v2, 3);
+    suv = _mm_extract_epi32(uv, 2) + _mm_extract_epi32(uv, 3);
+    suw = _mm_extract_epi32(uw, 2) + _mm_extract_epi32(uw, 3);
+    svw = _mm_extract_epi32(vw, 2) + _mm_extract_epi32(vw, 3);
+  }
+
+  calc_mv_process(su2, sv2, suv, suw, svw, d0, d1, bits, rls_alpha, vx0, vy0,
+                  vx1, vy1);
+}
+
+static void opfl_mv_refinement_interp_grad_8x4_sse4_1(
+    const int16_t *pdiff, int pstride, const int16_t *gx, const int16_t *gy,
+    int gstride, int d0, int d1, int grad_prec_bits, int mv_prec_bits, int *vx0,
+    int *vy0, int *vx1, int *vy1) {
+  int bHeight = 4;
+  __m128i u2 = _mm_setzero_si128();
+  __m128i uv = _mm_setzero_si128();
+  __m128i v2 = _mm_setzero_si128();
+  __m128i uw = _mm_setzero_si128();
+  __m128i vw = _mm_setzero_si128();
+#if OPFL_DOWNSAMP_QUINCUNX
+  const __m128i even_row =
+      _mm_set_epi16(0, 0xFFFF, 0, 0xFFFF, 0, 0xFFFF, 0, 0xFFFF);
+  const __m128i odd_row =
+      _mm_set_epi16(0xFFFF, 0, 0xFFFF, 0, 0xFFFF, 0, 0xFFFF, 0);
+#endif
+  do {
+    __m128i gradX = LoadUnaligned16(gx);
+    __m128i gradY = LoadUnaligned16(gy);
+    __m128i pred = LoadUnaligned16(pdiff);
+    __m128i reg;
+#if OPFL_DOWNSAMP_QUINCUNX
+    const __m128i gradX1 = LoadUnaligned16(gx + gstride);
+    const __m128i gradY1 = LoadUnaligned16(gy + gstride);
+    const __m128i pred1 = LoadUnaligned16(pdiff + pstride);
+    gradX = _mm_or_si128(_mm_and_si128(gradX, even_row),
+                         _mm_and_si128(gradX1, odd_row));
+    gradY = _mm_or_si128(_mm_and_si128(gradY, even_row),
+                         _mm_and_si128(gradY1, odd_row));
+    pred = _mm_or_si128(_mm_and_si128(pred, even_row),
+                        _mm_and_si128(pred1, odd_row));
+#endif
+    reg = _mm_madd_epi16(gradX, gradX);
+    u2 = _mm_add_epi32(reg, u2);
+
+    reg = _mm_madd_epi16(gradY, gradY);
+    v2 = _mm_add_epi32(reg, v2);
+
+    reg = _mm_madd_epi16(gradX, gradY);
+    uv = _mm_add_epi32(reg, uv);
+
+    reg = _mm_madd_epi16(gradX, pred);
+    uw = _mm_add_epi32(reg, uw);
+
+    reg = _mm_madd_epi16(gradY, pred);
+    vw = _mm_add_epi32(reg, vw);
+#if OPFL_DOWNSAMP_QUINCUNX
+    gx += gstride << 1;
+    gy += gstride << 1;
+    pdiff += pstride << 1;
+    bHeight -= 2;
+#else
+    gx += gstride;
+    gy += gstride;
+    pdiff += pstride;
+    bHeight -= 1;
+#endif
+  } while (bHeight != 0);
+
+  const int bits = mv_prec_bits + grad_prec_bits;
+  // As processing block size is 4x4, here '(bw * bh >> 4)' can be replaced
+  // by 1.
+  const int rls_alpha = 1 << OPFL_RLS_PARAM_BITS;
+  calc_mv(u2, v2, uv, uw, vw, d0, d1, bits, 0, rls_alpha, vx0, vy0, vx1, vy1);
+  calc_mv(u2, v2, uv, uw, vw, d0, d1, bits, 1, rls_alpha, vx0 + 1, vy0 + 1,
+          vx1 + 1, vy1 + 1);
+}
+
+static void opfl_mv_refinement_interp_grad_8x8_sse4_1(
+    const int16_t *pdiff, int pstride, const int16_t *gx, const int16_t *gy,
+    int gstride, int d0, int d1, int grad_prec_bits, int mv_prec_bits, int *vx0,
+    int *vy0, int *vx1, int *vy1) {
+  int bHeight = 8;
+  __m128i u2 = _mm_setzero_si128();
+  __m128i uv = _mm_setzero_si128();
+  __m128i v2 = _mm_setzero_si128();
+  __m128i uw = _mm_setzero_si128();
+  __m128i vw = _mm_setzero_si128();
+#if OPFL_DOWNSAMP_QUINCUNX
+  const __m128i even_row =
+      _mm_set_epi16(0, 0xFFFF, 0, 0xFFFF, 0, 0xFFFF, 0, 0xFFFF);
+  const __m128i odd_row =
+      _mm_set_epi16(0xFFFF, 0, 0xFFFF, 0, 0xFFFF, 0, 0xFFFF, 0);
+#endif
+  do {
+    __m128i gradX = LoadUnaligned16(gx);
+    __m128i gradY = LoadUnaligned16(gy);
+    __m128i pred = LoadUnaligned16(pdiff);
+    __m128i reg;
+#if OPFL_DOWNSAMP_QUINCUNX
+    const __m128i gradX1 = LoadUnaligned16(gx + gstride);
+    const __m128i gradY1 = LoadUnaligned16(gy + gstride);
+    const __m128i pred1 = LoadUnaligned16(pdiff + pstride);
+    gradX = _mm_or_si128(_mm_and_si128(gradX, even_row),
+                         _mm_and_si128(gradX1, odd_row));
+    gradY = _mm_or_si128(_mm_and_si128(gradY, even_row),
+                         _mm_and_si128(gradY1, odd_row));
+    pred = _mm_or_si128(_mm_and_si128(pred, even_row),
+                        _mm_and_si128(pred1, odd_row));
+#endif
+    reg = _mm_madd_epi16(gradX, gradX);
+    u2 = _mm_add_epi32(u2, reg);
+
+    reg = _mm_madd_epi16(gradY, gradY);
+    v2 = _mm_add_epi32(v2, reg);
+
+    reg = _mm_madd_epi16(gradX, gradY);
+    uv = _mm_add_epi32(uv, reg);
+
+    reg = _mm_madd_epi16(gradX, pred);
+    uw = _mm_add_epi32(uw, reg);
+
+    reg = _mm_madd_epi16(gradY, pred);
+    vw = _mm_add_epi32(vw, reg);
+#if OPFL_DOWNSAMP_QUINCUNX
+    gx += gstride << 1;
+    gy += gstride << 1;
+    pdiff += pstride << 1;
+    bHeight -= 2;
+#else
+    gx += gstride;
+    gy += gstride;
+    pdiff += pstride;
+    bHeight -= 1;
+#endif
+  } while (bHeight != 0);
+
+  u2 = _mm_add_epi32(u2, _mm_srli_si128(u2, 8));
+  v2 = _mm_add_epi32(v2, _mm_srli_si128(v2, 8));
+  uv = _mm_add_epi32(uv, _mm_srli_si128(uv, 8));
+  uw = _mm_add_epi32(uw, _mm_srli_si128(uw, 8));
+  vw = _mm_add_epi32(vw, _mm_srli_si128(vw, 8));
+
+  const int bits = mv_prec_bits + grad_prec_bits;
+  // As processing block size is 8x8, here '(bw * bh >> 4)' can be replaced
+  // by 4.
+  const int rls_alpha = 4 << OPFL_RLS_PARAM_BITS;
+  calc_mv(u2, v2, uv, uw, vw, d0, d1, bits, 0, rls_alpha, vx0, vy0, vx1, vy1);
+}
+
+static AOM_INLINE void opfl_mv_refinement_interp_grad_sse4_1(
+    const int16_t *pdiff, int pstride, const int16_t *gx, const int16_t *gy,
+    int gstride, int bw, int bh, int d0, int d1, int grad_prec_bits,
+    int mv_prec_bits, int *vx0, int *vy0, int *vx1, int *vy1) {
+  (void)bh;
+  if (bw == 4)
+    opfl_mv_refinement_interp_grad_8x4_sse4_1(pdiff, pstride, gx, gy, gstride,
+                                              d0, d1, grad_prec_bits,
+                                              mv_prec_bits, vx0, vy0, vx1, vy1);
+  else
+    opfl_mv_refinement_interp_grad_8x8_sse4_1(pdiff, pstride, gx, gy, gstride,
+                                              d0, d1, grad_prec_bits,
+                                              mv_prec_bits, vx0, vy0, vx1, vy1);
+}
+#endif  // OPFL_COMBINE_INTERP_GRAD_LS
+
+// Function to compute optical flow offsets in nxn blocks
+int av1_opfl_mv_refinement_nxn_interp_grad_sse4_1(
+    const int16_t *pdiff, int pstride, const int16_t *gx, const int16_t *gy,
+    int gstride, int bw, int bh, int n, int d0, int d1, int grad_prec_bits,
+    int mv_prec_bits, int *vx0, int *vy0, int *vx1, int *vy1) {
+  assert(bw % n == 0 && bh % n == 0);
+  int n_blocks = 0;
+#if OPFL_COMBINE_INTERP_GRAD_LS
+  for (int i = 0; i < bh; i += n) {
+    for (int j = 0; j < bw; j += 8) {
+      opfl_mv_refinement_interp_grad_sse4_1(
+          pdiff + (i * pstride + j), pstride, gx + (i * gstride + j),
+          gy + (i * gstride + j), gstride, n, n, d0, d1, grad_prec_bits,
+          mv_prec_bits, vx0 + n_blocks, vy0 + n_blocks, vx1 + n_blocks,
+          vy1 + n_blocks);
+      n_blocks += (n == 4) ? 2 : 1;
+    }
+  }
+#else
+  (void)pdiff;
+  (void)pstride;
+  (void)gx;
+  (void)gy;
+  (void)gstride;
+  (void)bw;
+  (void)bh;
+  (void)n;
+  (void)d0;
+  (void)d1;
+  (void)grad_prec_bits;
+  (void)mv_prec_bits;
+  (void)vx0;
+  (void)vy0;
+  (void)vx1;
+  (void)vy1;
+#endif  // OPFL_COMBINE_INTERP_GRAD_LS
+  return n_blocks;
+}
+
+#if OPFL_COMBINE_INTERP_GRAD_LS
+static AOM_FORCE_INLINE void compute_pred_using_interp_grad_sse4_1(
+    const uint8_t *src1, const uint8_t *src2, int16_t *dst1, int16_t *dst2,
+    int bw, int bh, int d0, int d1) {
+  const __m128i zero = _mm_setzero_si128();
+  const __m128i mul1 = _mm_set1_epi16(d0);
+  const __m128i mul2 = _mm_sub_epi16(zero, _mm_set1_epi16(d1));
+  const __m128i mul_val1 = _mm_unpacklo_epi16(mul1, mul2);
+  const __m128i mul_val2 = _mm_unpacklo_epi16(mul1, _mm_sub_epi16(zero, mul1));
+
+  if (bw < 16) {
+    for (int i = 0; i < bh; i++) {
+      const uint8_t *inp1 = src1 + i * bw;
+      const uint8_t *inp2 = src2 + i * bw;
+      int16_t *out1 = dst1 + i * bw;
+      int16_t *out2 = dst2 + i * bw;
+      for (int j = 0; j < bw; j = j + 8) {
+        const __m128i src_buf1 = _mm_cvtepu8_epi16(xx_loadl_64(inp1 + j));
+        const __m128i src_buf2 = _mm_cvtepu8_epi16(xx_loadl_64(inp2 + j));
+
+        __m128i temp1, temp2;
+        __m128i reg1 = _mm_unpacklo_epi16(src_buf1, src_buf2);
+        __m128i reg2 = _mm_unpackhi_epi16(src_buf1, src_buf2);
+
+        temp1 = _mm_madd_epi16(reg1, mul_val1);
+        temp2 = _mm_madd_epi16(reg2, mul_val1);
+        temp1 = _mm_packs_epi32(temp1, temp2);
+
+        reg1 = _mm_madd_epi16(reg1, mul_val2);
+        reg2 = _mm_madd_epi16(reg2, mul_val2);
+        temp2 = _mm_packs_epi32(reg1, reg2);
+
+        xx_store_128(out1 + j, temp1);
+        xx_store_128(out2 + j, temp2);
+      }
+    }
+  } else {
+    for (int i = 0; i < bh; i++) {
+      const uint8_t *inp1 = src1 + i * bw;
+      const uint8_t *inp2 = src2 + i * bw;
+      int16_t *out1 = dst1 + i * bw;
+      int16_t *out2 = dst2 + i * bw;
+      for (int j = 0; j < bw; j = j + 16) {
+        const __m128i src_buf1 = xx_load_128(inp1 + j);
+        const __m128i src_buf2 = xx_load_128(inp2 + j);
+
+        __m128i temp1 = _mm_unpacklo_epi8(src_buf1, zero);
+        __m128i temp2 = _mm_unpackhi_epi8(src_buf1, zero);
+        __m128i temp3 = _mm_unpacklo_epi8(src_buf2, zero);
+        __m128i temp4 = _mm_unpackhi_epi8(src_buf2, zero);
+
+        __m128i res1, res2, res3, res4;
+        __m128i reg1, reg2, reg3, reg4;
+        reg1 = _mm_unpacklo_epi16(temp1, temp3);
+        reg2 = _mm_unpackhi_epi16(temp1, temp3);
+        reg3 = _mm_unpacklo_epi16(temp2, temp4);
+        reg4 = _mm_unpackhi_epi16(temp2, temp4);
+
+        temp1 = _mm_madd_epi16(reg1, mul_val1);
+        temp2 = _mm_madd_epi16(reg2, mul_val1);
+        res1 = _mm_packs_epi32(temp1, temp2);
+
+        temp2 = _mm_madd_epi16(reg3, mul_val1);
+        temp3 = _mm_madd_epi16(reg4, mul_val1);
+        res2 = _mm_packs_epi32(temp2, temp3);
+
+        temp3 = _mm_madd_epi16(reg1, mul_val2);
+        temp4 = _mm_madd_epi16(reg2, mul_val2);
+        res3 = _mm_packs_epi32(temp3, temp4);
+
+        temp3 = _mm_madd_epi16(reg3, mul_val2);
+        temp4 = _mm_madd_epi16(reg4, mul_val2);
+        res4 = _mm_packs_epi32(temp3, temp4);
+
+        xx_store_128(out1 + j, res1);
+        xx_store_128(out1 + j + 8, res2);
+        xx_store_128(out2 + j, res3);
+        xx_store_128(out2 + j + 8, res4);
+      }
+    }
+  }
+}
+#endif  // OPFL_COMBINE_INTERP_GRAD_LS
+
+void av1_copy_pred_array_sse4_1(const uint8_t *src1, const uint8_t *src2,
+                                int16_t *dst1, int16_t *dst2, int bw, int bh,
+                                int d0, int d1) {
+#if OPFL_BILINEAR_GRAD || OPFL_BICUBIC_GRAD
+#if OPFL_COMBINE_INTERP_GRAD_LS
+  compute_pred_using_interp_grad_sse4_1(src1, src2, dst1, dst2, bw, bh, d0, d1);
+#else
+  (void)src2;
+  (void)dst2;
+  (void)d0;
+  (void)d1;
+  if (bw < 16) {
+    for (int i = 0; i < bh; i++) {
+      const uint8_t *inp1 = src1 + i * bw;
+      int16_t *out1 = dst1 + i * bw;
+      for (int j = 0; j < bw; j = j + 8) {
+        const __m128i src_buf = xx_loadl_64(inp1 + j);
+        xx_store_128(out1 + j, _mm_cvtepu8_epi16(src_buf));
+      }
+    }
+  } else {
+    const __m128i zero = _mm_setzero_si128();
+    for (int i = 0; i < bh; i++) {
+      const uint8_t *inp1 = src1 + i * bw;
+      int16_t *out1 = dst1 + i * bw;
+      for (int j = 0; j < bw; j = j + 16) {
+        const __m128i src_buf = xx_load_128(inp1 + j);
+        xx_store_128(out1 + j, _mm_unpacklo_epi8(src_buf, zero));
+        xx_store_128(out1 + j + 8, _mm_unpackhi_epi8(src_buf, zero));
+      }
+    }
+  }
+#endif  // OPFL_COMBINE_INTERP_GRAD_LS
+#else
+  (void)src1;
+  (void)dst1;
+  (void)src2;
+  (void)dst2;
+  (void)d0;
+  (void)d1;
+  (void)bw;
+  (void)bh;
+#endif  // OPFL_BILINEAR_GRAD || OPFL_BICUBIC_GRAD
+}
+
+#if OPFL_COMBINE_INTERP_GRAD_LS
+static AOM_FORCE_INLINE void compute_pred_using_interp_grad_highbd_sse4_1(
+    const uint16_t *src1, const uint16_t *src2, int16_t *dst1, int16_t *dst2,
+    int bw, int bh, int d0, int d1) {
+  const __m128i zero = _mm_setzero_si128();
+  const __m128i mul1 = _mm_set1_epi16(d0);
+  const __m128i mul2 = _mm_sub_epi16(zero, _mm_set1_epi16(d1));
+  const __m128i mul_val1 = _mm_unpacklo_epi16(mul1, mul2);
+  const __m128i mul_val2 = _mm_unpacklo_epi16(mul1, _mm_sub_epi16(zero, mul1));
+
+  for (int i = 0; i < bh; i++) {
+    const uint16_t *inp1 = src1 + i * bw;
+    const uint16_t *inp2 = src2 + i * bw;
+    int16_t *out1 = dst1 + i * bw;
+    int16_t *out2 = dst2 + i * bw;
+    for (int j = 0; j < bw; j = j + 8) {
+      const __m128i src_buf1 = xx_load_128(inp1 + j);
+      const __m128i src_buf2 = xx_load_128(inp2 + j);
+
+      __m128i temp1, temp2;
+      __m128i reg1 = _mm_unpacklo_epi16(src_buf1, src_buf2);
+      __m128i reg2 = _mm_unpackhi_epi16(src_buf1, src_buf2);
+
+      temp1 = _mm_madd_epi16(reg1, mul_val1);
+      temp2 = _mm_madd_epi16(reg2, mul_val1);
+      temp1 = _mm_packs_epi32(temp1, temp2);
+
+      reg1 = _mm_madd_epi16(reg1, mul_val2);
+      reg2 = _mm_madd_epi16(reg2, mul_val2);
+      temp2 = _mm_packs_epi32(reg1, reg2);
+
+      xx_store_128(out1 + j, temp1);
+      xx_store_128(out2 + j, temp2);
+    }
+  }
+}
+#endif  // OPFL_COMBINE_INTERP_GRAD_LS
+
+void av1_copy_pred_array_highbd_sse4_1(const uint16_t *src1,
+                                       const uint16_t *src2, int16_t *dst1,
+                                       int16_t *dst2, int bw, int bh, int d0,
+                                       int d1) {
+#if OPFL_BILINEAR_GRAD || OPFL_BICUBIC_GRAD
+#if OPFL_COMBINE_INTERP_GRAD_LS
+  compute_pred_using_interp_grad_highbd_sse4_1(src1, src2, dst1, dst2, bw, bh,
+                                               d0, d1);
+#else
+  (void)src2;
+  (void)dst2;
+  (void)d0;
+  (void)d1;
+  for (int i = 0; i < bh; i++) {
+    const uint16_t *inp1 = src1 + i * bw;
+    int16_t *out1 = dst1 + i * bw;
+    for (int j = 0; j < bw; j = j + 8) {
+      const __m128i src_buf = xx_load_128(inp1 + j);
+      xx_store_128(out1 + j, src_buf);
+    }
+  }
+#endif  // OPFL_COMBINE_INTERP_GRAD_LS
+#else
+  (void)src1;
+  (void)dst1;
+  (void)src2;
+  (void)dst2;
+  (void)d0;
+  (void)d1;
+  (void)bw;
+  (void)bh;
+#endif  // OPFL_BILINEAR_GRAD || OPFL_BICUBIC_GRAD
+}
+
+#endif  // CONFIG_OPTFLOW_REFINEMENT
diff --git a/av1/common/x86/reconinter_avx2.c b/av1/common/x86/reconinter_avx2.c
index a38bd83..06641cd 100644
--- a/av1/common/x86/reconinter_avx2.c
+++ b/av1/common/x86/reconinter_avx2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <immintrin.h>
diff --git a/av1/common/x86/reconinter_sse4.c b/av1/common/x86/reconinter_sse4.c
index 5171ca4..b883e3c 100644
--- a/av1/common/x86/reconinter_sse4.c
+++ b/av1/common/x86/reconinter_sse4.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <emmintrin.h>  // SSE2
diff --git a/av1/common/x86/reconinter_ssse3.c b/av1/common/x86/reconinter_ssse3.c
index cf68444..f94f959 100644
--- a/av1/common/x86/reconinter_ssse3.c
+++ b/av1/common/x86/reconinter_ssse3.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <tmmintrin.h>
diff --git a/av1/common/x86/resize_ssse3.c b/av1/common/x86/resize_ssse3.c
index 0929392..337c480 100644
--- a/av1/common/x86/resize_ssse3.c
+++ b/av1/common/x86/resize_ssse3.c
@@ -1,13 +1,14 @@
 /*
  *
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <tmmintrin.h>  // SSSE3
diff --git a/av1/common/x86/selfguided_avx2.c b/av1/common/x86/selfguided_avx2.c
index 3c5558d..5636cf0 100644
--- a/av1/common/x86/selfguided_avx2.c
+++ b/av1/common/x86/selfguided_avx2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <immintrin.h>
diff --git a/av1/common/x86/selfguided_sse4.c b/av1/common/x86/selfguided_sse4.c
index 72c7708..1767d50 100644
--- a/av1/common/x86/selfguided_sse4.c
+++ b/av1/common/x86/selfguided_sse4.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <smmintrin.h>
diff --git a/av1/common/x86/warp_plane_avx2.c b/av1/common/x86/warp_plane_avx2.c
index d48f255..5729336 100644
--- a/av1/common/x86/warp_plane_avx2.c
+++ b/av1/common/x86/warp_plane_avx2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2019, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <immintrin.h>
diff --git a/av1/common/x86/warp_plane_sse2.c b/av1/common/x86/warp_plane_sse2.c
index 6ff6665..35caad6 100644
--- a/av1/common/x86/warp_plane_sse2.c
+++ b/av1/common/x86/warp_plane_sse2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2019, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <emmintrin.h>
diff --git a/av1/common/x86/warp_plane_sse4.c b/av1/common/x86/warp_plane_sse4.c
index ebb6a28..a47d6ad 100644
--- a/av1/common/x86/warp_plane_sse4.c
+++ b/av1/common/x86/warp_plane_sse4.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <emmintrin.h>
diff --git a/av1/common/x86/wiener_convolve_avx2.c b/av1/common/x86/wiener_convolve_avx2.c
index b7ac683..44ed35c 100644
--- a/av1/common/x86/wiener_convolve_avx2.c
+++ b/av1/common/x86/wiener_convolve_avx2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <immintrin.h>
diff --git a/av1/common/x86/wiener_convolve_sse2.c b/av1/common/x86/wiener_convolve_sse2.c
index f9d00b7..bcdcef7 100644
--- a/av1/common/x86/wiener_convolve_sse2.c
+++ b/av1/common/x86/wiener_convolve_sse2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <emmintrin.h>
diff --git a/av1/decoder/accounting.c b/av1/decoder/accounting.c
index 2e58d09..b8c1e5a 100644
--- a/av1/decoder/accounting.c
+++ b/av1/decoder/accounting.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
@@ -68,6 +69,8 @@
   accounting->syms.num_syms = 0;
   accounting->syms.num_binary_syms = 0;
   accounting->syms.num_multi_syms = 0;
+  accounting->syms.num_bypass_coded = 0;
+  accounting->syms.num_ctx_coded = 0;
   accounting->context.x = -1;
   accounting->context.y = -1;
   accounting->last_tell_frac = 0;
diff --git a/av1/decoder/accounting.h b/av1/decoder/accounting.h
index ad2e8b6..e4d3037 100644
--- a/av1/decoder/accounting.h
+++ b/av1/decoder/accounting.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #ifndef AOM_AV1_DECODER_ACCOUNTING_H_
 #define AOM_AV1_DECODER_ACCOUNTING_H_
@@ -55,6 +56,10 @@
   int num_multi_syms;
   /** Raw binary symbol decoding calls. */
   int num_binary_syms;
+  /** Bypass coded. */
+  int num_bypass_coded;
+  /** Context coded. */
+  int num_ctx_coded;
   /** Dictionary for translating strings into id. */
   AccountingDictionary dictionary;
 } AccountingSymbols;
diff --git a/av1/decoder/decodeframe.c b/av1/decoder/decodeframe.c
index 5e25082..9ea8036 100644
--- a/av1/decoder/decodeframe.c
+++ b/av1/decoder/decodeframe.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
@@ -76,6 +77,16 @@
   (((MAX_SB_SIZE)*2 + (AOM_INTERP_EXTEND)*2) * \
    ((MAX_SB_SIZE)*2 + (AOM_INTERP_EXTEND)*2))
 
+#if CONFIG_THROUGHPUT_ANALYSIS
+int64_t tot_ctx_syms = { 0 };
+int64_t tot_bypass_syms = { 0 };
+int max_ctx_syms = { 0 };
+int max_bypass_syms = { 0 };
+int max_bits = { 0 };
+int64_t tot_bits = { 0 };
+int tot_frames = { 0 };
+#endif  // CONFIG_THROUGHPUT_ANALYSIS
+
 // Checks that the remaining bits start with a 1 and ends with 0s.
 // It consumes an additional byte, if already byte aligned before the check.
 int av1_check_trailing_bits(AV1Decoder *pbi, struct aom_read_bit_buffer *rb) {
@@ -551,16 +562,22 @@
     const struct scale_factors *const sf, struct buf_2d *const pre_buf,
     MV32 scaled_mv, PadBlock *block, int subpel_x_mv, int subpel_y_mv,
     int do_warp, int is_intrabc, int *x_pad, int *y_pad) {
-  const int is_scaled = av1_is_scaled(sf);
   // Get reference width and height.
   int frame_width = pre_buf->width;
   int frame_height = pre_buf->height;
 
   // Do border extension if there is motion or
   // width/height is not a multiple of 8 pixels.
+#if CONFIG_OPTFLOW_REFINEMENT
+  // Extension is needed in optical flow refinement to obtain MV offsets
+  (void)scaled_mv;
+  if (!is_intrabc && !do_warp) {
+#else
+  const int is_scaled = av1_is_scaled(sf);
   if ((!is_intrabc) && (!do_warp) &&
       (is_scaled || scaled_mv.col || scaled_mv.row || (frame_width & 0x7) ||
        (frame_height & 0x7))) {
+#endif  // CONFIG_OPTFLOW_REFINEMENT
     if (subpel_x_mv || (sf->x_step_q4 != SUBPEL_SHIFTS)) {
       block->x0 -= AOM_INTERP_EXTEND - 1;
       block->x1 += AOM_INTERP_EXTEND;
@@ -616,25 +633,46 @@
   }
 }
 
-static void dec_calc_subpel_params(const MV *const src_mv,
-                                   InterPredParams *const inter_pred_params,
-                                   const MACROBLOCKD *const xd, int mi_x,
-                                   int mi_y, uint8_t **pre,
-                                   SubpelParams *subpel_params, int *src_stride,
-                                   PadBlock *block, MV32 *scaled_mv,
-                                   int *subpel_x_mv, int *subpel_y_mv) {
+static void dec_calc_subpel_params(
+    const MV *const src_mv, InterPredParams *const inter_pred_params,
+    const MACROBLOCKD *const xd, int mi_x, int mi_y, uint8_t **pre,
+    SubpelParams *subpel_params, int *src_stride, PadBlock *block,
+#if CONFIG_OPTFLOW_REFINEMENT
+    int use_optflow_refinement,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
+    MV32 *scaled_mv, int *subpel_x_mv, int *subpel_y_mv) {
   const struct scale_factors *sf = inter_pred_params->scale_factors;
   struct buf_2d *pre_buf = &inter_pred_params->ref_frame_buf;
+#if CONFIG_OPTFLOW_REFINEMENT
+  // Use original block size to clamp MV and to extend block boundary
+  const int bw = use_optflow_refinement ? inter_pred_params->orig_block_width
+                                        : inter_pred_params->block_width;
+  const int bh = use_optflow_refinement ? inter_pred_params->orig_block_height
+                                        : inter_pred_params->block_height;
+#else
   const int bw = inter_pred_params->block_width;
   const int bh = inter_pred_params->block_height;
+#endif  // CONFIG_OPTFLOW_REFINEMENT
   const int is_scaled = av1_is_scaled(sf);
   if (is_scaled) {
     int ssx = inter_pred_params->subsampling_x;
     int ssy = inter_pred_params->subsampling_y;
     int orig_pos_y = inter_pred_params->pix_row << SUBPEL_BITS;
-    orig_pos_y += src_mv->row * (1 << (1 - ssy));
     int orig_pos_x = inter_pred_params->pix_col << SUBPEL_BITS;
+#if CONFIG_OPTFLOW_REFINEMENT
+    if (use_optflow_refinement) {
+      orig_pos_y += ROUND_POWER_OF_TWO_SIGNED(src_mv->row * (1 << SUBPEL_BITS),
+                                              MV_REFINE_PREC_BITS + ssy);
+      orig_pos_x += ROUND_POWER_OF_TWO_SIGNED(src_mv->col * (1 << SUBPEL_BITS),
+                                              MV_REFINE_PREC_BITS + ssx);
+    } else {
+      orig_pos_y += src_mv->row * (1 << (1 - ssy));
+      orig_pos_x += src_mv->col * (1 << (1 - ssx));
+    }
+#else
+    orig_pos_y += src_mv->row * (1 << (1 - ssy));
     orig_pos_x += src_mv->col * (1 << (1 - ssx));
+#endif  // CONFIG_OPTFLOW_REFINEMENT
     int pos_y = sf->scale_value_y(orig_pos_y, sf);
     int pos_x = sf->scale_value_x(orig_pos_x, sf);
     pos_x += SCALE_EXTRA_OFF;
@@ -659,12 +697,19 @@
 
     // Get reference block bottom right coordinate.
     block->x1 =
-        ((pos_x + (bw - 1) * subpel_params->xs) >> SCALE_SUBPEL_BITS) + 1;
+        ((pos_x + (inter_pred_params->block_width - 1) * subpel_params->xs) >>
+         SCALE_SUBPEL_BITS) +
+        1;
     block->y1 =
-        ((pos_y + (bh - 1) * subpel_params->ys) >> SCALE_SUBPEL_BITS) + 1;
+        ((pos_y + (inter_pred_params->block_height - 1) * subpel_params->ys) >>
+         SCALE_SUBPEL_BITS) +
+        1;
 
     MV temp_mv;
     temp_mv = clamp_mv_to_umv_border_sb(xd, src_mv, bw, bh,
+#if CONFIG_OPTFLOW_REFINEMENT
+                                        use_optflow_refinement,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
                                         inter_pred_params->subsampling_x,
                                         inter_pred_params->subsampling_y);
     *scaled_mv = av1_scale_mv(&temp_mv, mi_x, mi_y, sf);
@@ -679,8 +724,11 @@
     int pos_y = inter_pred_params->pix_row << SUBPEL_BITS;
 
     const MV mv_q4 = clamp_mv_to_umv_border_sb(
-        xd, src_mv, bw, bh, inter_pred_params->subsampling_x,
-        inter_pred_params->subsampling_y);
+        xd, src_mv, bw, bh,
+#if CONFIG_OPTFLOW_REFINEMENT
+        use_optflow_refinement,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
+        inter_pred_params->subsampling_x, inter_pred_params->subsampling_y);
     subpel_params->xs = subpel_params->ys = SCALE_SUBPEL_SHIFTS;
     subpel_params->subpel_x = (mv_q4.col & SUBPEL_MASK) << SCALE_EXTRA_BITS;
     subpel_params->subpel_y = (mv_q4.row & SUBPEL_MASK) << SCALE_EXTRA_BITS;
@@ -692,8 +740,10 @@
     block->y0 = pos_y >> SUBPEL_BITS;
 
     // Get reference block bottom right coordinate.
-    block->x1 = (pos_x >> SUBPEL_BITS) + (bw - 1) + 1;
-    block->y1 = (pos_y >> SUBPEL_BITS) + (bh - 1) + 1;
+    block->x1 =
+        (pos_x >> SUBPEL_BITS) + (inter_pred_params->block_width - 1) + 1;
+    block->y1 =
+        (pos_y >> SUBPEL_BITS) + (inter_pred_params->block_height - 1) + 1;
 
     scaled_mv->row = mv_q4.row;
     scaled_mv->col = mv_q4.col;
@@ -706,14 +756,21 @@
 
 static void dec_calc_subpel_params_and_extend(
     const MV *const src_mv, InterPredParams *const inter_pred_params,
-    MACROBLOCKD *const xd, int mi_x, int mi_y, int ref, uint8_t **mc_buf,
-    uint8_t **pre, SubpelParams *subpel_params, int *src_stride) {
+    MACROBLOCKD *const xd, int mi_x, int mi_y, int ref,
+#if CONFIG_OPTFLOW_REFINEMENT
+    int use_optflow_refinement,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
+    uint8_t **mc_buf, uint8_t **pre, SubpelParams *subpel_params,
+    int *src_stride) {
   PadBlock block;
   MV32 scaled_mv;
   int subpel_x_mv, subpel_y_mv;
   dec_calc_subpel_params(src_mv, inter_pred_params, xd, mi_x, mi_y, pre,
-                         subpel_params, src_stride, &block, &scaled_mv,
-                         &subpel_x_mv, &subpel_y_mv);
+                         subpel_params, src_stride, &block,
+#if CONFIG_OPTFLOW_REFINEMENT
+                         use_optflow_refinement,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
+                         &scaled_mv, &subpel_x_mv, &subpel_y_mv);
   extend_mc_border(
       inter_pred_params->scale_factors, &inter_pred_params->ref_frame_buf,
       scaled_mv, block, subpel_x_mv, subpel_y_mv,
@@ -723,9 +780,8 @@
 
 static void dec_build_inter_predictors(const AV1_COMMON *cm,
                                        DecoderCodingBlock *dcb, int plane,
-                                       const MB_MODE_INFO *mi,
-                                       int build_for_obmc, int bw, int bh,
-                                       int mi_x, int mi_y) {
+                                       MB_MODE_INFO *mi, int build_for_obmc,
+                                       int bw, int bh, int mi_x, int mi_y) {
   av1_build_inter_predictors(cm, &dcb->xd, plane, mi, build_for_obmc, bw, bh,
                              mi_x, mi_y, dcb->mc_buf,
                              dec_calc_subpel_params_and_extend);
@@ -940,13 +996,17 @@
   const int mi_col = xd->mi_col;
   for (int ref = 0; ref < 1 + has_second_ref(mbmi); ++ref) {
     const MV_REFERENCE_FRAME frame = mbmi->ref_frame[ref];
+#if CONFIG_NEW_REF_SIGNALING
+    if (frame == INTRA_FRAME_NRS) {
+#else
     if (frame < LAST_FRAME) {
+      assert(frame == INTRA_FRAME);
+#endif  // CONFIG_NEW_REF_SIGNALING
 #if CONFIG_SDP
       assert(is_intrabc_block(mbmi, xd->tree_type));
 #else
       assert(is_intrabc_block(mbmi));
 #endif
-      assert(frame == INTRA_FRAME);
       assert(ref == 0);
     } else {
       const RefCntBuffer *ref_buf = get_ref_frame_buf(cm, frame);
@@ -963,6 +1023,7 @@
   if (mbmi->motion_mode == OBMC_CAUSAL) {
     dec_build_obmc_inter_predictors_sb(cm, dcb);
   }
+
 #if CONFIG_MISMATCH_DEBUG
   for (int plane = 0; plane < num_planes; ++plane) {
     const struct macroblockd_plane *pd = &xd->plane[plane];
@@ -2505,7 +2566,11 @@
   int width, height;
   int found = 0;
   int has_valid_ref_frame = 0;
+#if CONFIG_NEW_REF_SIGNALING
+  for (int i = 0; i < INTER_REFS_PER_FRAME; ++i) {
+#else
   for (int i = LAST_FRAME; i <= ALTREF_FRAME; ++i) {
+#endif  // CONFIG_NEW_REF_SIGNALING
     if (aom_rb_read_bit(rb)) {
       const RefCntBuffer *const ref_buf = get_ref_frame_buf(cm, i);
       // This will never be NULL in a normal stream, as streams are required to
@@ -2545,9 +2610,13 @@
     aom_internal_error(&cm->error, AOM_CODEC_CORRUPT_FRAME,
                        "Invalid frame size");
 
-  // Check to make sure at least one of frames that this frame references
-  // has valid dimensions.
+    // Check to make sure at least one of frames that this frame references has
+    // valid dimensions.
+#if CONFIG_NEW_REF_SIGNALING
+  for (int i = 0; i < INTER_REFS_PER_FRAME; ++i) {
+#else
   for (int i = LAST_FRAME; i <= ALTREF_FRAME; ++i) {
+#endif  // CONFIG_NEW_REF_SIGNALING
     const RefCntBuffer *const ref_frame = get_ref_frame_buf(cm, i);
     has_valid_ref_frame |=
         valid_ref_frame_size(ref_frame->buf.y_crop_width,
@@ -2556,7 +2625,11 @@
   if (!has_valid_ref_frame)
     aom_internal_error(&cm->error, AOM_CODEC_CORRUPT_FRAME,
                        "Referenced frame has invalid size");
+#if CONFIG_NEW_REF_SIGNALING
+  for (int i = 0; i < INTER_REFS_PER_FRAME; ++i) {
+#else
   for (int i = LAST_FRAME; i <= ALTREF_FRAME; ++i) {
+#endif  // CONFIG_NEW_REF_SIGNALING
     const RefCntBuffer *const ref_frame = get_ref_frame_buf(cm, i);
     if (!valid_ref_frame_img_fmt(
             ref_frame->buf.bit_depth, ref_frame->buf.subsampling_x,
@@ -3104,7 +3177,12 @@
 
     sync_read(&tile_data->dec_row_mt_sync, sb_row_in_tile, sb_col_in_tile);
 
-    // Decoding of the super-block
+#if CONFIG_REF_MV_BANK
+    DecoderCodingBlock *const dcb = &td->dcb;
+    MACROBLOCKD *const xd = &dcb->xd;
+    xd->ref_mv_bank.rmb_sb_hits = 0;
+#endif  // CONFIG_REF_MV_BANK
+        // Decoding of the super-block
 #if CONFIG_SDP
     decode_partition_sb(pbi, td, mi_row, mi_col, td->bit_reader,
                         cm->seq_params.sb_size, 0x2);
@@ -3180,6 +3258,11 @@
   av1_reset_loop_filter_delta(xd, num_planes);
   av1_reset_loop_restoration(xd, num_planes);
 
+#if CONFIG_REF_MV_BANK
+  av1_zero(xd->ref_mv_bank);
+  xd->ref_mv_bank_pt = &td->ref_mv_bank;
+#endif  // CONFIG_REF_MV_BANK
+
   for (int mi_row = tile_info.mi_row_start; mi_row < tile_info.mi_row_end;
        mi_row += cm->seq_params.mib_size) {
     av1_zero_left_context(xd);
@@ -3187,6 +3270,13 @@
     for (int mi_col = tile_info.mi_col_start; mi_col < tile_info.mi_col_end;
          mi_col += cm->seq_params.mib_size) {
       set_cb_buffer(pbi, dcb, &td->cb_buffer_base, num_planes, 0, 0);
+#if CONFIG_REF_MV_BANK
+      // td->ref_mv_bank is initialized as xd->ref_mv_bank, and used
+      // for MV referencing during decoding the tile.
+      // xd->ref_mv_bank is updated as decoding goes.
+      xd->ref_mv_bank.rmb_sb_hits = 0;
+      td->ref_mv_bank = xd->ref_mv_bank;
+#endif  // CONFIG_REF_MV_BANK
 #if CONFIG_SDP
       decode_partition_sb(pbi, td, mi_row, mi_col, td->bit_reader,
                           cm->seq_params.sb_size, 0x3);
@@ -3207,6 +3297,47 @@
   aom_merge_corrupted_flag(&dcb->corrupted, corrupted);
 }
 
+#if CONFIG_THROUGHPUT_ANALYSIS
+static void aom_accounting_cal_total(AV1Decoder *pbi) {
+  if (pbi->decoding_first_frame) {
+    pbi->common.sym_stats.frame_dec_order = 0;
+    pbi->common.sym_stats.tot_ctx_syms = 0;
+    pbi->common.sym_stats.tot_bypass_syms = 0;
+    pbi->common.sym_stats.tot_bits = 0;
+    pbi->common.sym_stats.peak_ctx_syms = 0;
+    pbi->common.sym_stats.peak_bypass_syms = 0;
+    pbi->common.sym_stats.peak_bits = 0;
+  }
+  Accounting accounting = pbi->accounting;
+  int frm_ctx_syms = accounting.syms.num_ctx_coded;
+  int frm_bypass_syms = accounting.syms.num_bypass_coded;
+  int frm_bits = 0;
+  for (int i = 0; i < accounting.syms.num_syms; i++) {
+    AccountingSymbol sym = accounting.syms.syms[i];
+    frm_bits += sym.bits;
+  }
+  int peak_ctx_syms = pbi->common.sym_stats.peak_ctx_syms;
+  int peak_bypass_syms = pbi->common.sym_stats.peak_bypass_syms;
+  pbi->common.sym_stats.tot_ctx_syms += frm_ctx_syms;
+  pbi->common.sym_stats.tot_bypass_syms += frm_bypass_syms;
+  pbi->common.sym_stats.frame_dec_order += 1;
+  pbi->common.sym_stats.tot_bits += frm_bits;
+  if (frm_ctx_syms * 4 + frm_bypass_syms >
+      peak_ctx_syms * 4 + peak_bypass_syms) {
+    pbi->common.sym_stats.peak_ctx_syms = frm_ctx_syms;
+    pbi->common.sym_stats.peak_bypass_syms = frm_bypass_syms;
+    pbi->common.sym_stats.peak_bits = frm_bits;
+  }
+  tot_ctx_syms = pbi->common.sym_stats.tot_ctx_syms;
+  tot_bypass_syms = pbi->common.sym_stats.tot_bypass_syms;
+  tot_bits = pbi->common.sym_stats.tot_bits;
+  max_ctx_syms = pbi->common.sym_stats.peak_ctx_syms;
+  max_bypass_syms = pbi->common.sym_stats.peak_bypass_syms;
+  max_bits = pbi->common.sym_stats.peak_bits;
+  tot_frames = pbi->common.sym_stats.frame_dec_order;
+}
+#endif  // CONFIG_THROUGHPUT_ANALYSIS
+
 static const uint8_t *decode_tiles(AV1Decoder *pbi, const uint8_t *data,
                                    const uint8_t *data_end, int start_tile,
                                    int end_tile) {
@@ -3346,7 +3477,11 @@
     return raw_data_end;
   }
   TileDataDec *const tile_data = pbi->tile_data + end_tile;
-
+#if CONFIG_THROUGHPUT_ANALYSIS
+  if (pbi->acct_enabled) {
+    aom_accounting_cal_total(pbi);
+  }
+#endif  // CONFIG_THROUGHPUT_ANALYSIS
   return aom_reader_find_end(&tile_data->bit_reader);
 }
 
@@ -3620,6 +3755,11 @@
   av1_reset_loop_filter_delta(xd, num_planes);
   av1_reset_loop_restoration(xd, num_planes);
 
+#if CONFIG_REF_MV_BANK
+  av1_zero(xd->ref_mv_bank);
+  xd->ref_mv_bank_pt = &td->ref_mv_bank;
+#endif  // CONFIG_REF_MV_BANK
+
   for (int mi_row = tile_info.mi_row_start; mi_row < tile_info.mi_row_end;
        mi_row += cm->seq_params.mib_size) {
     av1_zero_left_context(xd);
@@ -3628,7 +3768,11 @@
          mi_col += cm->seq_params.mib_size) {
       set_cb_buffer(pbi, dcb, pbi->cb_buffer_base, num_planes, mi_row, mi_col);
 
-      // Bit-stream parsing of the superblock
+#if CONFIG_REF_MV_BANK
+      xd->ref_mv_bank.rmb_sb_hits = 0;
+      td->ref_mv_bank = xd->ref_mv_bank;
+#endif  // CONFIG_REF_MV_BANK
+        // Bit-stream parsing of the superblock
 #if CONFIG_SDP
       decode_partition_sb(pbi, td, mi_row, mi_col, td->bit_reader,
                           cm->seq_params.sb_size, 0x1);
@@ -3901,6 +4045,11 @@
   }
 #if CONFIG_ACCOUNTING
   if (pbi->acct_enabled) {
+#if CONFIG_THROUGHPUT_ANALYSIS
+    aom_accounting_cal_total(pbi);
+#else
+    aom_accounting_dump(&pbi->accounting);
+#endif  // CONFIG_THROUGHPUT_ANALYSIS
     aom_accounting_reset(&pbi->accounting);
   }
 #endif
@@ -4688,13 +4837,13 @@
     seq_params->enable_dual_filter = 0;
 #endif  // !CONFIG_REMOVE_DUAL_FILTER
     seq_params->order_hint_info.enable_order_hint = 0;
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-    seq_params->order_hint_info.enable_dist_wtd_comp = 0;
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
     seq_params->order_hint_info.enable_ref_frame_mvs = 0;
     seq_params->force_screen_content_tools = 2;  // SELECT_SCREEN_CONTENT_TOOLS
     seq_params->force_integer_mv = 2;            // SELECT_INTEGER_MV
     seq_params->order_hint_info.order_hint_bits_minus_1 = -1;
+#if CONFIG_OPTFLOW_REFINEMENT
+    seq_params->enable_opfl_refine = AOM_OPFL_REFINE_NONE;
+#endif  // CONFIG_OPTFLOW_REFINEMENT
   } else {
     seq_params->enable_interintra_compound = aom_rb_read_bit(rb);
     seq_params->enable_masked_compound = aom_rb_read_bit(rb);
@@ -4704,10 +4853,6 @@
 #endif  // !CONFIG_REMOVE_DUAL_FILTER
 
     seq_params->order_hint_info.enable_order_hint = aom_rb_read_bit(rb);
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-    seq_params->order_hint_info.enable_dist_wtd_comp =
-        seq_params->order_hint_info.enable_order_hint ? aom_rb_read_bit(rb) : 0;
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
     seq_params->order_hint_info.enable_ref_frame_mvs =
         seq_params->order_hint_info.enable_order_hint ? aom_rb_read_bit(rb) : 0;
 
@@ -4740,6 +4885,17 @@
 
 void av1_read_sequence_header_beyond_av1(struct aom_read_bit_buffer *rb,
                                          SequenceHeader *seq_params) {
+#if CONFIG_REF_MV_BANK
+  seq_params->enable_refmvbank = aom_rb_read_bit(rb);
+#endif  // CONFIG_REF_MV_BANK
+#if CONFIG_NEW_REF_SIGNALING
+  seq_params->explicit_ref_frame_map = aom_rb_read_bit(rb);
+  if (aom_rb_read_bit(rb)) {
+    seq_params->max_reference_frames = 3 + aom_rb_read_literal(rb, 2);
+  } else {
+    seq_params->max_reference_frames = 7;
+  }
+#endif  // CONFIG_NEW_REF_SIGNALING
 #if CONFIG_SDP
   seq_params->enable_sdp = aom_rb_read_bit(rb);
 #endif
@@ -4755,6 +4911,14 @@
 #if CONFIG_ORIP
   seq_params->enable_orip = aom_rb_read_bit(rb);
 #endif
+#if CONFIG_OPTFLOW_REFINEMENT
+  seq_params->enable_opfl_refine = seq_params->order_hint_info.enable_order_hint
+                                       ? aom_rb_read_literal(rb, 2)
+                                       : AOM_OPFL_REFINE_NONE;
+#endif  // CONFIG_OPTFLOW_REFINEMENT
+#if CONFIG_IBP_DC || CONFIG_IBP_DIR
+  seq_params->enable_ibp = aom_rb_read_bit(rb);
+#endif
 }
 
 static int read_global_motion_params(WarpedMotionParams *params,
@@ -4831,7 +4995,11 @@
 
 static AOM_INLINE void read_global_motion(AV1_COMMON *cm,
                                           struct aom_read_bit_buffer *rb) {
+#if CONFIG_NEW_REF_SIGNALING
+  for (int frame = 0; frame < cm->ref_frames_info.n_total_refs; ++frame) {
+#else
   for (int frame = LAST_FRAME; frame <= ALTREF_FRAME; ++frame) {
+#endif  // CONFIG_NEW_REF_SIGNALING
     const WarpedMotionParams *ref_params =
         cm->prev_frame ? &cm->prev_frame->global_motion[frame]
                        : &default_warp_params;
@@ -4868,8 +5036,13 @@
            cm->global_motion[frame].wmmat[3]);
            */
   }
+#if CONFIG_NEW_REF_SIGNALING
+  memcpy(cm->cur_frame->global_motion, cm->global_motion,
+         INTER_REFS_PER_FRAME * sizeof(WarpedMotionParams));
+#else
   memcpy(cm->cur_frame->global_motion, cm->global_motion,
          REF_FRAMES * sizeof(WarpedMotionParams));
+#endif  // CONFIG_NEW_REF_SIGNALING
 }
 
 // Release the references to the frame buffers in cm->ref_frame_map and reset
@@ -4943,6 +5116,49 @@
   unlock_buffer_pool(cm->buffer_pool);
 }
 
+static INLINE int get_disp_order_hint(AV1_COMMON *const cm) {
+  CurrentFrame *const current_frame = &cm->current_frame;
+  if (current_frame->frame_type == KEY_FRAME && cm->show_existing_frame)
+    return 0;
+
+#if CONFIG_NEW_REF_SIGNALING
+  // Derive the exact display order hint from the signaled order_hint.
+  // This requires scaling up order_hints corresponding to frame
+  // numbers that exceed the number of bits available to send the order_hints.
+
+  // Find the reference frame with the largest order_hint
+  int max_disp_order_hint = 0;
+  for (int map_idx = 0; map_idx < REF_FRAMES; map_idx++) {
+    // Get reference frame buffer
+    const RefCntBuffer *const buf = cm->ref_frame_map[map_idx];
+    if (buf == NULL) continue;
+    if ((int)buf->display_order_hint > max_disp_order_hint)
+      max_disp_order_hint = buf->display_order_hint;
+  }
+
+  // If the order_hint is above the threshold distance of 32 frames from the
+  // found reference frame, we assume it was modified using:
+  // order_hint = display_order_hint % display_order_hint_factor. Here, the
+  // actual display_order_hint is recovered.
+  const int order_hint = current_frame->order_hint;
+  int cur_disp_order_hint = order_hint;
+  // Check if the display order of the max reference is greater than the
+  // threshold of 32 frames apart from the current frame.
+  if (abs(max_disp_order_hint - order_hint) > 32) {
+    assert(order_hint < max_disp_order_hint);
+    const int display_order_hint_factor =
+        (1 << (cm->seq_params.order_hint_info.order_hint_bits_minus_1 + 1));
+    const int upper_order_factor =
+        order_hint +
+        (display_order_hint_factor - (order_hint % display_order_hint_factor));
+    cur_disp_order_hint += upper_order_factor;
+  }
+  return cur_disp_order_hint;
+#else
+  return current_frame->order_hint;
+#endif  // CONFIG_NEW_REF_SIGNALING
+}
+
 // On success, returns 0. On failure, calls aom_internal_error and does not
 // return.
 static int read_uncompressed_header(AV1Decoder *pbi,
@@ -5166,6 +5382,7 @@
 
     current_frame->order_hint = aom_rb_read_literal(
         rb, seq_params->order_hint_info.order_hint_bits_minus_1 + 1);
+    current_frame->display_order_hint = get_disp_order_hint(cm);
     current_frame->frame_number = current_frame->order_hint;
 
     if (!features->error_resilient_mode && !frame_is_intra_only(cm)) {
@@ -5291,6 +5508,7 @@
   }
 
   if (current_frame->frame_type == KEY_FRAME) {
+    cm->current_frame.pyramid_level = 1;
     setup_frame_size(cm, frame_size_override_flag, rb);
 
     if (features->allow_screen_content_tools && !av1_superres_scaled(cm))
@@ -5308,6 +5526,14 @@
         features->allow_intrabc = aom_rb_read_bit(rb);
 
     } else if (pbi->need_resync != 1) { /* Skip if need resync */
+#if CONFIG_NEW_REF_SIGNALING
+      // Implicitly derive the reference mapping
+      RefFrameMapPair ref_frame_map_pairs[REF_FRAMES];
+      init_ref_map_pair(cm, ref_frame_map_pairs,
+                        current_frame->frame_type == KEY_FRAME);
+      av1_get_ref_frames(cm, current_frame->display_order_hint,
+                         ref_frame_map_pairs);
+#else
       int frame_refs_short_signaling = 0;
       // Frame refs short signaling is off when error resilient mode is on.
       if (seq_params->order_hint_info.enable_order_hint)
@@ -5337,10 +5563,27 @@
 
         av1_set_frame_refs(cm, cm->remapped_ref_idx, lst_ref, gld_ref);
       }
+#endif  // CONFIG_NEW_REF_SIGNALING
 
+#if CONFIG_NEW_REF_SIGNALING
+      for (int i = 0; i < cm->ref_frames_info.n_total_refs; ++i) {
+        int ref = 0;
+        // Reference rankings have been implicitly derived in
+        // av1_get_ref_frames. However, if explicti_ref_frame_map is on, ref
+        // idx will be overwritten by what is signaled here.
+        if (!seq_params->explicit_ref_frame_map &&
+            seq_params->order_hint_info.enable_order_hint) {
+          ref = cm->remapped_ref_idx[i];
+          if (cm->ref_frame_map[ref] == NULL)
+            aom_internal_error(&cm->error, AOM_CODEC_CORRUPT_FRAME,
+                               "Inter frame requests nonexistent reference");
+#else
       for (int i = 0; i < INTER_REFS_PER_FRAME; ++i) {
         int ref = 0;
-        if (!frame_refs_short_signaling) {
+        if (frame_refs_short_signaling) {
+          ref = cm->remapped_ref_idx[i];
+#endif  // CONFIG_NEW_REF_SIGNALING
+        } else {
           ref = aom_rb_read_literal(rb, REF_FRAMES_LOG2);
 
           // Most of the time, streams start with a keyframe. In that case,
@@ -5353,15 +5596,15 @@
             aom_internal_error(&cm->error, AOM_CODEC_CORRUPT_FRAME,
                                "Inter frame requests nonexistent reference");
           cm->remapped_ref_idx[i] = ref;
-        } else {
-          ref = cm->remapped_ref_idx[i];
         }
         // Check valid for referencing
         if (pbi->valid_for_referencing[ref] == 0)
           aom_internal_error(&cm->error, AOM_CODEC_CORRUPT_FRAME,
                              "Reference frame not valid for referencing");
 
+#if !CONFIG_NEW_REF_SIGNALING
         cm->ref_frame_sign_bias[LAST_FRAME + i] = 0;
+#endif  // !CONFIG_NEW_REF_SIGNALING
 
         if (seq_params->frame_id_numbers_present_flag) {
           int frame_id_length = seq_params->frame_id_length;
@@ -5378,6 +5621,21 @@
                                "Reference buffer frame ID mismatch");
         }
       }
+#if CONFIG_NEW_REF_SIGNALING
+      // With explicit_ref_frame_map, cm->remapped_ref_idx has been
+      // overwritten. The reference lists also needs to be reset.
+      if (seq_params->explicit_ref_frame_map) {
+        RefScoreData scores[REF_FRAMES];
+        for (int i = 0; i < REF_FRAMES; i++) scores[i].score = INT_MAX;
+        for (int i = 0; i < cm->ref_frames_info.n_total_refs; i++) {
+          scores[i].score = i;
+          int ref = cm->remapped_ref_idx[i];
+          scores[i].distance = current_frame->display_order_hint -
+                               ref_frame_map_pairs[ref].disp_order;
+        }
+        av1_get_past_future_cur_ref_lists(cm, scores);
+      }
+#endif  // CONFIG_NEW_REF_SIGNALING
 
       if (!features->error_resilient_mode && frame_size_override_flag) {
         setup_frame_size_with_refs(cm, rb);
@@ -5398,6 +5656,13 @@
       }
       features->interp_filter = read_frame_interp_filter(rb);
       features->switchable_motion_mode = aom_rb_read_bit(rb);
+#if CONFIG_OPTFLOW_REFINEMENT
+      if (cm->seq_params.enable_opfl_refine == AOM_OPFL_REFINE_AUTO) {
+        features->opfl_refine_type = aom_rb_read_literal(rb, 2);
+      } else {
+        features->opfl_refine_type = cm->seq_params.enable_opfl_refine;
+      }
+#endif  // CONFIG_OPTFLOW_REFINEMENT
     }
 
     cm->prev_frame = get_primary_ref_frame_buf(cm);
@@ -5415,8 +5680,14 @@
       else
         features->allow_ref_frame_mvs = 0;
 
+#if CONFIG_NEW_REF_SIGNALING
+      for (int i = 0; i < INTER_REFS_PER_FRAME; ++i) {
+        const RefCntBuffer *const ref_buf = get_ref_frame_buf(cm, i);
+        if (!ref_buf) continue;
+#else
       for (int i = LAST_FRAME; i <= ALTREF_FRAME; ++i) {
         const RefCntBuffer *const ref_buf = get_ref_frame_buf(cm, i);
+#endif  // CONFIG_NEW_REF_SIGNALING
         struct scale_factors *const ref_scale_factors =
             get_ref_scale_factors(cm, i);
         av1_setup_scale_factors_for_frame(
@@ -5488,6 +5759,9 @@
   CommonQuantParams *const quant_params = &cm->quant_params;
   setup_quantization(quant_params, av1_num_planes(cm), cm->seq_params.bit_depth,
                      cm->seq_params.separate_uv_delta_q, rb);
+#if CONFIG_NEW_REF_SIGNALING
+  cm->cur_frame->base_qindex = quant_params->base_qindex;
+#endif  // CONFIG_NEW_REF_SIGNALING
   xd->bd = (int)seq_params->bit_depth;
 
   CommonContexts *const above_contexts = &cm->above_contexts;
@@ -5663,7 +5937,11 @@
   mismatch_move_frame_idx_r();
 #endif
 
+#if CONFIG_NEW_REF_SIGNALING
+  for (int i = 0; i < INTER_REFS_PER_FRAME; ++i) {
+#else
   for (int i = LAST_FRAME; i <= ALTREF_FRAME; ++i) {
+#endif  // CONFIG_NEW_REF_SIGNALING
     cm->global_motion[i] = default_warp_params;
     cm->cur_frame->global_motion[i] = default_warp_params;
   }
diff --git a/av1/decoder/decodeframe.h b/av1/decoder/decodeframe.h
index 6d69453..d09c4e8 100644
--- a/av1/decoder/decodeframe.h
+++ b/av1/decoder/decodeframe.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_DECODER_DECODEFRAME_H_
@@ -16,6 +17,16 @@
 extern "C" {
 #endif
 
+#if CONFIG_THROUGHPUT_ANALYSIS
+extern int64_t tot_ctx_syms;
+extern int64_t tot_bypass_syms;
+extern int max_ctx_syms;
+extern int max_bypass_syms;
+extern int max_bits;
+extern int64_t tot_bits;
+extern int tot_frames;
+#endif  // CONFIG_THROUGHPUT_ANALYSIS
+
 struct AV1Decoder;
 struct aom_read_bit_buffer;
 struct ThreadData;
diff --git a/av1/decoder/decodemv.c b/av1/decoder/decodemv.c
index 9509e18..6a0728c 100644
--- a/av1/decoder/decodemv.c
+++ b/av1/decoder/decodemv.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
@@ -32,9 +33,11 @@
 
 #define DEC_MISMATCH_DEBUG 0
 
+#if !CONFIG_AIMC
 static PREDICTION_MODE read_intra_mode(aom_reader *r, aom_cdf_prob *cdf) {
   return (PREDICTION_MODE)aom_read_symbol(r, cdf, INTRA_MODES, ACCT_STR);
 }
+#endif  // !CONFIG_AIMC
 
 static void read_cdef(AV1_COMMON *cm, aom_reader *r, MACROBLOCKD *const xd) {
 #if CONFIG_SDP
@@ -202,6 +205,7 @@
 }
 #endif
 
+#if !CONFIG_AIMC
 static UV_PREDICTION_MODE read_intra_mode_uv(FRAME_CONTEXT *ec_ctx,
                                              aom_reader *r,
                                              CFL_ALLOWED_TYPE cfl_allowed,
@@ -211,6 +215,7 @@
                       UV_INTRA_MODES - !cfl_allowed, ACCT_STR);
   return uv_mode;
 }
+#endif  // !CONFIG_AIMC
 
 static uint8_t read_cfl_alphas(FRAME_CONTEXT *const ec_ctx, aom_reader *r,
                                int8_t *signs_out) {
@@ -350,11 +355,34 @@
 }
 
 static PREDICTION_MODE read_inter_compound_mode(MACROBLOCKD *xd, aom_reader *r,
+#if CONFIG_OPTFLOW_REFINEMENT
+                                                const AV1_COMMON *cm,
+                                                MB_MODE_INFO *const mbmi,
+#endif  // CONFIG_OPTFLOW_REFINEMNET
                                                 int16_t ctx) {
+#if CONFIG_OPTFLOW_REFINEMENT
+  int use_optical_flow = 0;
+  if (cm->features.opfl_refine_type == REFINE_SWITCHABLE &&
+      is_opfl_refine_allowed(cm, mbmi)) {
+    use_optical_flow =
+        aom_read_symbol(r, xd->tile_ctx->use_optflow_cdf[ctx], 2, ACCT_STR);
+  }
+#endif  // CONFIG_OPTFLOW_REFINEMENT
   const int mode =
+#if CONFIG_OPTFLOW_REFINEMENT
+      aom_read_symbol(r, xd->tile_ctx->inter_compound_mode_cdf[ctx],
+                      INTER_COMPOUND_REF_TYPES, ACCT_STR);
+#else
       aom_read_symbol(r, xd->tile_ctx->inter_compound_mode_cdf[ctx],
                       INTER_COMPOUND_MODES, ACCT_STR);
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 #if CONFIG_NEW_INTER_MODES
+#if CONFIG_OPTFLOW_REFINEMENT
+  if (use_optical_flow) {
+    assert(is_inter_compound_mode(comp_idx_to_opfl_mode[mode]));
+    return comp_idx_to_opfl_mode[mode];
+  }
+#endif  // CONFIG_OPTFLOW_REFINEMENT
   assert(is_inter_compound_mode(NEAR_NEARMV + mode));
   return NEAR_NEARMV + mode;
 #else
@@ -546,8 +574,12 @@
   if (!is_comp_ref_allowed(xd->mi[0]->sb_type)) return 0;
 #endif
 
+#if CONFIG_NEW_REF_SIGNALING
+  if (segfeature_active(&cm->seg, segment_id, SEG_LVL_GLOBALMV)) {
+#else
   if (segfeature_active(&cm->seg, segment_id, SEG_LVL_REF_FRAME) ||
       segfeature_active(&cm->seg, segment_id, SEG_LVL_GLOBALMV)) {
+#endif  // CONFIG_NEW_REF_SIGNALING
     // These features imply single-reference mode, while skip mode implies
     // compound reference. Hence, the two are mutually exclusive.
     // In other words, skip_mode is implicitly 0 here.
@@ -730,18 +762,12 @@
   }
 }
 
-#if CONFIG_ORIP
-static int read_angle_delta_hv(aom_reader *r, aom_cdf_prob *cdf) {
-  const int sym = aom_read_symbol(
-      r, cdf, 2 * MAX_ANGLE_DELTA + 1 + ADDITIONAL_ANGLE_DELTA, ACCT_STR);
-  return get_idx_to_angle_delta(sym);
-}
-#endif
-
+#if !CONFIG_AIMC
 static int read_angle_delta(aom_reader *r, aom_cdf_prob *cdf) {
   const int sym = aom_read_symbol(r, cdf, 2 * MAX_ANGLE_DELTA + 1, ACCT_STR);
   return sym - MAX_ANGLE_DELTA;
 }
+#endif  // !CONFIG_AIMC
 
 static void read_filter_intra_mode_info(const AV1_COMMON *const cm,
                                         MACROBLOCKD *const xd, aom_reader *r) {
@@ -923,15 +949,24 @@
     mbmi->motion_mode = SIMPLE_TRANSLATION;
 
     int16_t inter_mode_ctx[MODE_CTX_REF_FRAMES];
-    int_mv ref_mvs[INTRA_FRAME + 1][MAX_MV_REF_CANDIDATES];
+    int_mv nearestmv, nearmv;
 
+#if CONFIG_NEW_REF_SIGNALING
+    // TODO(kslu): Rework av1_find_mv_refs_nrs to avoid having this big array
+    // ref_mvs
+    int_mv ref_mvs[INTRA_FRAME_NRS + 1][MAX_MV_REF_CANDIDATES];
+    av1_find_mv_refs(cm, xd, mbmi, INTRA_FRAME_NRS, dcb->ref_mv_count,
+                     xd->ref_mv_stack, xd->weight, ref_mvs,
+                     /*global_mvs=*/NULL, inter_mode_ctx);
+    av1_find_best_ref_mvs(0, ref_mvs[INTRA_FRAME_NRS], &nearestmv, &nearmv, 0);
+#else
+    int_mv ref_mvs[INTRA_FRAME + 1][MAX_MV_REF_CANDIDATES];
     av1_find_mv_refs(cm, xd, mbmi, INTRA_FRAME, dcb->ref_mv_count,
                      xd->ref_mv_stack, xd->weight, ref_mvs, /*global_mvs=*/NULL,
                      inter_mode_ctx);
-
-    int_mv nearestmv, nearmv;
-
     av1_find_best_ref_mvs(0, ref_mvs[INTRA_FRAME], &nearestmv, &nearmv, 0);
+#endif  // CONFIG_NEW_REF_SIGNALING
+
     int_mv dv_ref = nearestmv.as_int == 0 ? nearmv : nearestmv;
     if (dv_ref.as_int == 0)
       av1_find_ref_dv(&dv_ref, &xd->tile, cm->seq_params.mib_size, xd->mi_row);
@@ -961,11 +996,11 @@
         read_delta_qindex(cm, xd, r, mbmi) * delta_q_info->delta_q_res;
     /* Normative: Clamp to [1,MAXQ] to not interfere with lossless mode */
 #if CONFIG_EXTQUANT
-    xd->current_base_qindex = clamp(
-        xd->current_base_qindex, 1,
-        cm->seq_params.bit_depth == AOM_BITS_8
-            ? MAXQ_8_BITS
-            : cm->seq_params.bit_depth == AOM_BITS_10 ? MAXQ_10_BITS : MAXQ);
+    xd->current_base_qindex =
+        clamp(xd->current_base_qindex, 1,
+              cm->seq_params.bit_depth == AOM_BITS_8    ? MAXQ_8_BITS
+              : cm->seq_params.bit_depth == AOM_BITS_10 ? MAXQ_10_BITS
+                                                        : MAXQ);
 #else
     xd->current_base_qindex = clamp(xd->current_base_qindex, 1, MAXQ);
 #endif
@@ -1008,12 +1043,60 @@
   }
 }
 
+#if CONFIG_AIMC
+// read mode set index and mode index in set for y component,
+// and map it to y mode and delta angle
+static void read_intra_luma_mode(MACROBLOCKD *const xd, aom_reader *r) {
+  FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
+  MB_MODE_INFO *const mbmi = xd->mi[0];
+  uint8_t mode_idx = 0;
+  const int context = get_y_mode_idx_ctx(xd);
+  int mode_set_index =
+      aom_read_symbol(r, ec_ctx->y_mode_set_cdf, INTRA_MODE_SETS, ACCT_STR);
+  if (mode_set_index == 0) {
+    mode_idx = aom_read_symbol(r, ec_ctx->y_mode_idx_cdf_0[context],
+                               FIRST_MODE_COUNT, ACCT_STR);
+  } else {
+    mode_idx = FIRST_MODE_COUNT + (mode_set_index - 1) * SECOND_MODE_COUNT +
+               aom_read_symbol(r, ec_ctx->y_mode_idx_cdf_1[context],
+                               SECOND_MODE_COUNT, ACCT_STR);
+  }
+  assert(mode_idx >= 0 && mode_idx < LUMA_MODE_COUNT);
+  get_y_intra_mode_set(mbmi, xd);
+  mbmi->joint_y_mode_delta_angle = mbmi->y_intra_mode_list[mode_idx];
+  set_y_mode_and_delta_angle(mbmi->joint_y_mode_delta_angle, mbmi);
+  mbmi->y_mode_idx = mode_idx;
+  if (mbmi->joint_y_mode_delta_angle < NON_DIRECTIONAL_MODES_COUNT)
+    assert(mbmi->joint_y_mode_delta_angle == mbmi->y_mode_idx);
+}
+
+// read mode index for uv component and map it to uv mode and delta angle
+static void read_intra_uv_mode(MACROBLOCKD *const xd,
+                               CFL_ALLOWED_TYPE cfl_allowed, aom_reader *r) {
+  FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
+  MB_MODE_INFO *const mbmi = xd->mi[0];
+  const int context = av1_is_directional_mode(mbmi->mode) ? 1 : 0;
+  const int uv_mode_idx =
+      aom_read_symbol(r, ec_ctx->uv_mode_cdf[cfl_allowed][context],
+                      UV_INTRA_MODES - !cfl_allowed, ACCT_STR);
+  assert(uv_mode_idx >= 0 && uv_mode_idx < UV_INTRA_MODES);
+  get_uv_intra_mode_set(mbmi);
+  mbmi->uv_mode = mbmi->uv_intra_mode_list[uv_mode_idx];
+  if (mbmi->uv_mode == mbmi->mode)
+    mbmi->angle_delta[PLANE_TYPE_UV] = mbmi->angle_delta[PLANE_TYPE_Y];
+  else
+    mbmi->angle_delta[PLANE_TYPE_UV] = 0;
+}
+#endif  // CONFIG_AIMC
+
 static void read_intra_frame_mode_info(AV1_COMMON *const cm,
                                        DecoderCodingBlock *dcb, aom_reader *r) {
   MACROBLOCKD *const xd = &dcb->xd;
   MB_MODE_INFO *const mbmi = xd->mi[0];
+#if !CONFIG_AIMC
   const MB_MODE_INFO *above_mi = xd->above_mbmi;
   const MB_MODE_INFO *left_mi = xd->left_mbmi;
+#endif  // !CONFIG_AIMC
 #if CONFIG_SDP
   const BLOCK_SIZE bsize = mbmi->sb_type[xd->tree_type == CHROMA_PART];
 #else
@@ -1059,8 +1142,13 @@
 
   mbmi->current_qindex = xd->current_base_qindex;
 
+#if CONFIG_NEW_REF_SIGNALING
+  mbmi->ref_frame[0] = INTRA_FRAME_NRS;
+  mbmi->ref_frame[1] = INVALID_IDX;
+#else
   mbmi->ref_frame[0] = INTRA_FRAME;
   mbmi->ref_frame[1] = NONE_FRAME;
+#endif  // CONFIG_NEW_REF_SIGNALING
 #if CONFIG_SDP
   if (xd->tree_type != CHROMA_PART)
 #endif
@@ -1088,66 +1176,35 @@
     if (is_intrabc_block(mbmi)) return;
 #endif
   }
-
+#if !CONFIG_AIMC
   const int use_angle_delta = av1_use_angle_delta(bsize);
+#endif  // !CONFIG_AIMC
 #if CONFIG_SDP
   if (xd->tree_type != CHROMA_PART) {
 #endif  // CONFIG_SDP
-    mbmi->mode = read_intra_mode(r, get_y_mode_cdf(ec_ctx, above_mi, left_mi));
-#if CONFIG_ORIP
-#if CONFIG_MRLS
-    // when both ORIP and MRLS are enabled, mrl index are signalled right after
-    // intra mode and before angle delta
-    // Parsing reference line index
-    mbmi->mrl_index =
-        (cm->seq_params.enable_mrls && av1_is_directional_mode(mbmi->mode))
-            ? read_mrl_index(ec_ctx, r)
-            : 0;
-#endif  // CONFIG_MRLS
-
-    if (use_angle_delta && av1_is_directional_mode(mbmi->mode)) {
-      int signal_intra_filter =
-          av1_signal_orip_for_horver_modes(cm, mbmi, PLANE_TYPE_Y, bsize);
-      aom_cdf_prob *anglecdf =
-          signal_intra_filter
-#if CONFIG_SDP
-              ? ec_ctx->angle_delta_cdf_hv[PLANE_TYPE_Y][mbmi->mode - V_PRED]
-              : ec_ctx->angle_delta_cdf[PLANE_TYPE_Y][mbmi->mode - V_PRED];
+#if CONFIG_AIMC
+    read_intra_luma_mode(xd, r);
 #else
-              ? ec_ctx->angle_delta_cdf_hv[mbmi->mode - V_PRED]
-              : ec_ctx->angle_delta_cdf[mbmi->mode - V_PRED];
-#endif  // CONFIG_SDP
-
-      mbmi->angle_delta[PLANE_TYPE_Y] = signal_intra_filter
-                                            ? read_angle_delta_hv(r, anglecdf)
-                                            : read_angle_delta(r, anglecdf);
-    } else {
-      mbmi->angle_delta[PLANE_TYPE_Y] = 0;
-    }
-#elif CONFIG_SDP
+  mbmi->mode = read_intra_mode(r, get_y_mode_cdf(ec_ctx, above_mi, left_mi));
+#if CONFIG_SDP
   mbmi->angle_delta[PLANE_TYPE_Y] =
       (use_angle_delta && av1_is_directional_mode(mbmi->mode))
           ? read_angle_delta(
                 r, ec_ctx->angle_delta_cdf[PLANE_TYPE_Y][mbmi->mode - V_PRED])
           : 0;
 #else
-mbmi->angle_delta[PLANE_TYPE_Y] =
-    (use_angle_delta && av1_is_directional_mode(mbmi->mode))
-        ? read_angle_delta(r, ec_ctx->angle_delta_cdf[mbmi->mode - V_PRED])
-        : 0;
-#endif  // CONFIG_ORIP
-
-#if CONFIG_MRLS && !CONFIG_ORIP
-    // When both ORIP and MRLS are enabled, mrl index are signalled right after
-    // intra mode and before angle delta
-    // However when MRLS is enabled but ORIP is disabled, mrl_index is signalled
-    // here ( after angle delta)
-    // Parsing reference line index
+  mbmi->angle_delta[PLANE_TYPE_Y] =
+      (use_angle_delta && av1_is_directional_mode(mbmi->mode))
+          ? read_angle_delta(r, ec_ctx->angle_delta_cdf[mbmi->mode - V_PRED])
+          : 0;
+#endif  // CONFIG_SDP
+#endif  // CONFIG_AIMC
+#if CONFIG_MRLS
     mbmi->mrl_index =
         (cm->seq_params.enable_mrls && av1_is_directional_mode(mbmi->mode))
             ? read_mrl_index(ec_ctx, r)
             : 0;
-#endif
+#endif  // CONFIG_MRLS
 
 #if CONFIG_SDP
   }
@@ -1157,30 +1214,29 @@
   if (xd->tree_type != LUMA_PART) {
 #endif
     if (!cm->seq_params.monochrome && xd->is_chroma_ref) {
-      mbmi->uv_mode =
-          read_intra_mode_uv(ec_ctx, r, is_cfl_allowed(xd), mbmi->mode);
-      if (mbmi->uv_mode == UV_CFL_PRED) {
-        mbmi->cfl_alpha_idx =
-            read_cfl_alphas(ec_ctx, r, &mbmi->cfl_alpha_signs);
-      }
+#if CONFIG_AIMC
+      read_intra_uv_mode(xd, is_cfl_allowed(xd), r);
+#else
+    mbmi->uv_mode =
+        read_intra_mode_uv(ec_ctx, r, is_cfl_allowed(xd), mbmi->mode);
 #if CONFIG_SDP
-      if (cm->seq_params.enable_sdp) {
-        mbmi->angle_delta[PLANE_TYPE_UV] =
-            (use_angle_delta &&
-             av1_is_directional_mode(get_uv_mode(mbmi->uv_mode)))
-                ? read_angle_delta(
-                      r, ec_ctx->angle_delta_cdf[PLANE_TYPE_UV]
-                                                [mbmi->uv_mode - V_PRED])
-                : 0;
-      } else {
-        mbmi->angle_delta[PLANE_TYPE_UV] =
-            (use_angle_delta &&
-             av1_is_directional_mode(get_uv_mode(mbmi->uv_mode)))
-                ? read_angle_delta(
-                      r, ec_ctx->angle_delta_cdf[PLANE_TYPE_Y]
-                                                [mbmi->uv_mode - V_PRED])
-                : 0;
-      }
+    if (cm->seq_params.enable_sdp) {
+      mbmi->angle_delta[PLANE_TYPE_UV] =
+          (use_angle_delta &&
+           av1_is_directional_mode(get_uv_mode(mbmi->uv_mode)))
+              ? read_angle_delta(
+                    r, ec_ctx->angle_delta_cdf[PLANE_TYPE_UV]
+                                              [mbmi->uv_mode - V_PRED])
+              : 0;
+    } else {
+      mbmi->angle_delta[PLANE_TYPE_UV] =
+          (use_angle_delta &&
+           av1_is_directional_mode(get_uv_mode(mbmi->uv_mode)))
+              ? read_angle_delta(
+                    r, ec_ctx->angle_delta_cdf[PLANE_TYPE_Y]
+                                              [mbmi->uv_mode - V_PRED])
+              : 0;
+    }
 #else
     mbmi->angle_delta[PLANE_TYPE_UV] =
         (use_angle_delta && av1_is_directional_mode(get_uv_mode(mbmi->uv_mode)))
@@ -1188,6 +1244,11 @@
                                ec_ctx->angle_delta_cdf[mbmi->uv_mode - V_PRED])
             : 0;
 #endif
+#endif  // CONFIG_AIMC
+      if (mbmi->uv_mode == UV_CFL_PRED) {
+        mbmi->cfl_alpha_idx =
+            read_cfl_alphas(ec_ctx, r, &mbmi->cfl_alpha_signs);
+      }
     } else {
       // Avoid decoding angle_info if there is is no chroma prediction
       mbmi->uv_mode = UV_DC_PRED;
@@ -1276,7 +1337,7 @@
   if (!is_comp_ref_allowed(xd->mi[0]->sb_type)) return SINGLE_REFERENCE;
 #endif
   if (cm->current_frame.reference_mode == REFERENCE_MODE_SELECT) {
-    const int ctx = av1_get_reference_mode_context(xd);
+    const int ctx = av1_get_reference_mode_context(cm, xd);
     const REFERENCE_MODE mode = (REFERENCE_MODE)aom_read_symbol(
         r, xd->tile_ctx->comp_inter_cdf[ctx], 2, ACCT_STR);
     return mode;  // SINGLE_REFERENCE or COMPOUND_REFERENCE
@@ -1286,6 +1347,42 @@
   }
 }
 
+#if CONFIG_NEW_REF_SIGNALING
+static AOM_INLINE void read_single_ref_nrs(
+    MACROBLOCKD *const xd, MV_REFERENCE_FRAME ref_frame[2],
+    const RefFramesInfo *const ref_frames_info, aom_reader *r) {
+  const int n_refs = ref_frames_info->n_total_refs;
+  for (int i = 0; i < n_refs - 1; i++) {
+    const int bit = aom_read_symbol(
+        r, av1_get_pred_cdf_single_ref_nrs(xd, i, n_refs), 2, ACCT_STR);
+    if (bit) {
+      ref_frame[0] = i;
+      return;
+    }
+  }
+  ref_frame[0] = n_refs - 1;
+}
+
+static AOM_INLINE void read_compound_ref_nrs(
+    const MACROBLOCKD *xd, MV_REFERENCE_FRAME ref_frame[2],
+    const RefFramesInfo *const ref_frames_info, aom_reader *r) {
+  const int n_refs = ref_frames_info->n_total_refs;
+  assert(n_refs >= 2);
+  int n_bits = 0;
+  for (int i = 0; i < n_refs + n_bits - 2 && n_bits < 2; i++) {
+    const int bit_type =
+        av1_get_compound_ref_bit_type(n_bits, ref_frames_info, ref_frame[0], i);
+    const int bit = aom_read_symbol(
+        r, av1_get_pred_cdf_compound_ref_nrs(xd, i, n_bits, bit_type, n_refs),
+        2, ACCT_STR);
+    if (bit) {
+      ref_frame[n_bits++] = i;
+    }
+  }
+  if (n_bits < 2) ref_frame[1] = n_refs - 1;
+  if (n_bits < 1) ref_frame[0] = n_refs - 2;
+}
+#else
 #define READ_REF_BIT(pname) \
   aom_read_symbol(r, av1_get_pred_cdf_##pname(xd), 2, ACCT_STR)
 
@@ -1297,14 +1394,20 @@
           r, xd->tile_ctx->comp_ref_type_cdf[ctx], 2, ACCT_STR);
   return comp_ref_type;  // UNIDIR_COMP_REFERENCE or BIDIR_COMP_REFERENCE
 }
+#endif  // CONFIG_NEW_REF_SIGNALING
 
 static void set_ref_frames_for_skip_mode(AV1_COMMON *const cm,
                                          MV_REFERENCE_FRAME ref_frame[2]) {
+#if CONFIG_NEW_REF_SIGNALING
+  ref_frame[0] = cm->current_frame.skip_mode_info.ref_frame_idx_0;
+  ref_frame[1] = cm->current_frame.skip_mode_info.ref_frame_idx_1;
+#else
   ref_frame[0] = LAST_FRAME + cm->current_frame.skip_mode_info.ref_frame_idx_0;
   ref_frame[1] = LAST_FRAME + cm->current_frame.skip_mode_info.ref_frame_idx_1;
+#endif  // CONFIG_NEW_REF_SIGNALING
 }
 
-// Read the referncence frame
+// Read the reference frame
 static void read_ref_frames(AV1_COMMON *const cm, MACROBLOCKD *const xd,
                             aom_reader *r, int segment_id,
                             MV_REFERENCE_FRAME ref_frame[2]) {
@@ -1313,6 +1416,12 @@
     return;
   }
 
+#if CONFIG_NEW_REF_SIGNALING
+  if (segfeature_active(&cm->seg, segment_id, SEG_LVL_SKIP) ||
+      segfeature_active(&cm->seg, segment_id, SEG_LVL_GLOBALMV)) {
+    ref_frame[0] = get_closest_pastcur_ref_index(cm);
+    ref_frame[1] = INVALID_IDX;
+#else
   if (segfeature_active(&cm->seg, segment_id, SEG_LVL_REF_FRAME)) {
     ref_frame[0] = (MV_REFERENCE_FRAME)get_segdata(&cm->seg, segment_id,
                                                    SEG_LVL_REF_FRAME);
@@ -1321,10 +1430,14 @@
              segfeature_active(&cm->seg, segment_id, SEG_LVL_GLOBALMV)) {
     ref_frame[0] = LAST_FRAME;
     ref_frame[1] = NONE_FRAME;
+#endif  // CONFIG_NEW_REF_SIGNALING
   } else {
     const REFERENCE_MODE mode = read_block_reference_mode(cm, xd, r);
 
     if (mode == COMPOUND_REFERENCE) {
+#if CONFIG_NEW_REF_SIGNALING
+      read_compound_ref_nrs(xd, ref_frame, &cm->ref_frames_info, r);
+#else
       const COMP_REFERENCE_TYPE comp_ref_type = read_comp_reference_type(xd, r);
 
       if (comp_ref_type == UNIDIR_COMP_REFERENCE) {
@@ -1373,7 +1486,12 @@
       } else {
         ref_frame[idx] = ALTREF_FRAME;
       }
+#endif  // CONFIG_NEW_REF_SIGNALING
     } else if (mode == SINGLE_REFERENCE) {
+#if CONFIG_NEW_REF_SIGNALING
+      read_single_ref_nrs(xd, ref_frame, &cm->ref_frames_info, r);
+      ref_frame[1] = INVALID_IDX;
+#else
       const int bit0 = READ_REF_BIT(single_ref_p1);
       if (bit0) {
         const int bit1 = READ_REF_BIT(single_ref_p2);
@@ -1395,6 +1513,7 @@
       }
 
       ref_frame[1] = NONE_FRAME;
+#endif  // CONFIG_NEW_REF_SIGNALING
     } else {
       assert(0 && "Invalid prediction mode.");
     }
@@ -1403,6 +1522,7 @@
 
 static INLINE void read_mb_interp_filter(const MACROBLOCKD *const xd,
                                          InterpFilter interp_filter,
+                                         const AV1_COMMON *cm,
 #if !CONFIG_REMOVE_DUAL_FILTER
                                          bool enable_dual_filter,
 #endif  // !CONFIG_REMOVE_DUAL_FILTER
@@ -1410,8 +1530,12 @@
                                          aom_reader *r) {
   FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
 
-  if (!av1_is_interp_needed(xd)) {
-    set_default_interp_filters(mbmi, interp_filter);
+  if (!av1_is_interp_needed(cm, xd)) {
+    set_default_interp_filters(mbmi,
+#if CONFIG_OPTFLOW_REFINEMENT
+                               cm,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
+                               interp_filter);
     return;
   }
 
@@ -1455,46 +1579,24 @@
 #else
   const BLOCK_SIZE bsize = mbmi->sb_type;
 #endif
-  const int use_angle_delta = av1_use_angle_delta(bsize);
 
+#if CONFIG_NEW_REF_SIGNALING
+  mbmi->ref_frame[0] = INTRA_FRAME_NRS;
+  mbmi->ref_frame[1] = INVALID_IDX;
+#else
   mbmi->ref_frame[0] = INTRA_FRAME;
   mbmi->ref_frame[1] = NONE_FRAME;
+#endif  // CONFIG_NEW_REF_SIGNALING
 
   FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
 
+#if CONFIG_AIMC
+  read_intra_luma_mode(xd, r);
+#else
+  const int use_angle_delta = av1_use_angle_delta(bsize);
   mbmi->mode = read_intra_mode(r, ec_ctx->y_mode_cdf[size_group_lookup[bsize]]);
 
-#if CONFIG_MRLS && CONFIG_ORIP
 #if CONFIG_SDP
-  if (xd->tree_type != CHROMA_PART)
-#endif
-    // Parsing reference line index
-    mbmi->mrl_index =
-        (cm->seq_params.enable_mrls && av1_is_directional_mode(mbmi->mode))
-            ? read_mrl_index(ec_ctx, r)
-            : 0;
-#endif
-
-#if CONFIG_ORIP
-  if (use_angle_delta && av1_is_directional_mode(mbmi->mode)) {
-    int signal_intra_filter =
-        av1_signal_orip_for_horver_modes(cm, mbmi, PLANE_TYPE_Y, bsize);
-    aom_cdf_prob *anglecdf =
-        signal_intra_filter
-#if CONFIG_SDP
-            ? ec_ctx->angle_delta_cdf_hv[PLANE_TYPE_Y][mbmi->mode - V_PRED]
-            : ec_ctx->angle_delta_cdf[PLANE_TYPE_Y][mbmi->mode - V_PRED];
-#else
-            ? ec_ctx->angle_delta_cdf_hv[mbmi->mode - V_PRED]
-            : ec_ctx->angle_delta_cdf[mbmi->mode - V_PRED];
-#endif
-    mbmi->angle_delta[PLANE_TYPE_Y] = signal_intra_filter
-                                          ? read_angle_delta_hv(r, anglecdf)
-                                          : read_angle_delta(r, anglecdf);
-  } else {
-    mbmi->angle_delta[PLANE_TYPE_Y] = 0;
-  }
-#elif CONFIG_SDP
   mbmi->angle_delta[PLANE_TYPE_Y] =
       use_angle_delta && av1_is_directional_mode(mbmi->mode)
           ? read_angle_delta(
@@ -1505,9 +1607,10 @@
       use_angle_delta && av1_is_directional_mode(mbmi->mode)
           ? read_angle_delta(r, ec_ctx->angle_delta_cdf[mbmi->mode - V_PRED])
           : 0;
-#endif  // CONFIG_ORIP
+#endif  // CONFIG_SDP
+#endif  // CONFIG_AIMC
 
-#if CONFIG_MRLS && !CONFIG_ORIP
+#if CONFIG_MRLS
 #if CONFIG_SDP
   if (xd->tree_type != CHROMA_PART)
 #endif
@@ -1516,15 +1619,14 @@
         (cm->seq_params.enable_mrls && av1_is_directional_mode(mbmi->mode))
             ? read_mrl_index(ec_ctx, r)
             : 0;
-#endif
+#endif  // CONFIG_MRLS
 
   if (!cm->seq_params.monochrome && xd->is_chroma_ref) {
+#if CONFIG_AIMC
+    read_intra_uv_mode(xd, is_cfl_allowed(xd), r);
+#else
     mbmi->uv_mode =
         read_intra_mode_uv(ec_ctx, r, is_cfl_allowed(xd), mbmi->mode);
-    if (mbmi->uv_mode == UV_CFL_PRED) {
-      mbmi->cfl_alpha_idx =
-          read_cfl_alphas(xd->tile_ctx, r, &mbmi->cfl_alpha_signs);
-    }
 #if CONFIG_SDP
     if (cm->seq_params.enable_sdp) {
       mbmi->angle_delta[PLANE_TYPE_UV] =
@@ -1548,6 +1650,11 @@
                                ec_ctx->angle_delta_cdf[mbmi->uv_mode - V_PRED])
             : 0;
 #endif
+#endif  // CONFIG_AIMC
+    if (mbmi->uv_mode == UV_CFL_PRED) {
+      mbmi->cfl_alpha_idx =
+          read_cfl_alphas(xd->tile_ctx, r, &mbmi->cfl_alpha_signs);
+    }
   } else {
     // Avoid decoding angle_info if there is is no chroma prediction
     mbmi->uv_mode = UV_DC_PRED;
@@ -1620,7 +1727,11 @@
                          .as_int;
       break;
     }
-    case NEW_NEWMV: {
+    case NEW_NEWMV:
+#if CONFIG_OPTFLOW_REFINEMENT
+    case NEW_NEWMV_OPTFLOW:
+#endif  // CONFIG_OPTFLOW_REFINEMENT
+    {
       assert(is_compound);
       for (int i = 0; i < 2; ++i) {
         nmv_context *const nmvc = &ec_ctx->nmvc;
@@ -1636,7 +1747,11 @@
       break;
     }
 #endif  // !CONFIG_NEW_INTER_MODES
-    case NEAR_NEARMV: {
+    case NEAR_NEARMV:
+#if CONFIG_OPTFLOW_REFINEMENT
+    case NEAR_NEARMV_OPTFLOW:
+#endif  // CONFIG_OPTFLOW_REFINEMENT
+    {
       assert(is_compound);
       mv[0].as_int = near_mv[0].as_int;
       mv[1].as_int = near_mv[1].as_int;
@@ -1658,14 +1773,22 @@
       break;
     }
 #endif  // !CONFIG_NEW_INTER_MODES
-    case NEAR_NEWMV: {
+    case NEAR_NEWMV:
+#if CONFIG_OPTFLOW_REFINEMENT
+    case NEAR_NEWMV_OPTFLOW:
+#endif  // CONFIG_OPTFLOW_REFINEMENT
+    {
       nmv_context *const nmvc = &ec_ctx->nmvc;
       mv[0].as_int = near_mv[0].as_int;
       read_mv(r, &mv[1].as_mv, &ref_mv[1].as_mv, nmvc, allow_hp);
       assert(is_compound);
       break;
     }
-    case NEW_NEARMV: {
+    case NEW_NEARMV:
+#if CONFIG_OPTFLOW_REFINEMENT
+    case NEW_NEARMV_OPTFLOW:
+#endif  // CONFIG_OPTFLOW_REFINEMENT
+    {
       nmv_context *const nmvc = &ec_ctx->nmvc;
       read_mv(r, &mv[0].as_mv, &ref_mv[0].as_mv, nmvc, allow_hp);
       assert(is_compound);
@@ -1686,7 +1809,9 @@
                          .as_int;
       break;
     }
-    default: { return 0; }
+    default: {
+      return 0;
+    }
   }
 
   int ret = is_mv_valid(&mv[0].as_mv);
@@ -1697,19 +1822,30 @@
 }
 
 static int read_is_inter_block(AV1_COMMON *const cm, MACROBLOCKD *const xd,
-                               int segment_id, aom_reader *r) {
+                               int segment_id, aom_reader *r
+#if CONFIG_CONTEXT_DERIVATION
+                               ,
+                               const int skip_txfm
+#endif  // CONFIG_CONTEXT_DERIVATION
+) {
+#if !CONFIG_NEW_REF_SIGNALING
   if (segfeature_active(&cm->seg, segment_id, SEG_LVL_REF_FRAME)) {
     const int frame = get_segdata(&cm->seg, segment_id, SEG_LVL_REF_FRAME);
     if (frame < LAST_FRAME) return 0;
     return frame != INTRA_FRAME;
   }
+#endif  // !CONFIG_NEW_REF_SIGNALING
   if (segfeature_active(&cm->seg, segment_id, SEG_LVL_GLOBALMV)) {
     return 1;
   }
   const int ctx = av1_get_intra_inter_context(xd);
   FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
   const int is_inter =
+#if CONFIG_CONTEXT_DERIVATION
+      aom_read_symbol(r, ec_ctx->intra_inter_cdf[skip_txfm][ctx], 2, ACCT_STR);
+#else
       aom_read_symbol(r, ec_ctx->intra_inter_cdf[ctx], 2, ACCT_STR);
+#endif  // CONFIG_CONTEXT_DERIVATION
   return is_inter;
 }
 
@@ -1796,7 +1932,11 @@
       const int16_t mode_ctx =
           av1_mode_context_analyzer(inter_mode_ctx, mbmi->ref_frame);
       if (is_compound)
+#if CONFIG_OPTFLOW_REFINEMENT
+        mbmi->mode = read_inter_compound_mode(xd, r, cm, mbmi, mode_ctx);
+#else
         mbmi->mode = read_inter_compound_mode(xd, r, mode_ctx);
+#endif  // CONFIG_OPTFLOW_REFINEMENT
       else
         mbmi->mode = read_inter_mode(ec_ctx, r, mode_ctx);
       if (have_drl_index(mbmi->mode))
@@ -1892,11 +2032,19 @@
     const int bsize_group = size_group_lookup[bsize];
     const int interintra =
         aom_read_symbol(r, ec_ctx->interintra_cdf[bsize_group], 2, ACCT_STR);
+#if CONFIG_NEW_REF_SIGNALING
+    assert(mbmi->ref_frame[1] == INVALID_IDX);
+#else
     assert(mbmi->ref_frame[1] == NONE_FRAME);
+#endif  // CONFIG_NEW_REF_SIGNALING
     if (interintra) {
       const INTERINTRA_MODE interintra_mode =
           read_interintra_mode(xd, r, bsize_group);
+#if CONFIG_NEW_REF_SIGNALING
+      mbmi->ref_frame[1] = INTRA_FRAME_NRS;
+#else
       mbmi->ref_frame[1] = INTRA_FRAME;
+#endif  // CONFIG_NEW_REF_SIGNALING
       mbmi->interintra_mode = interintra_mode;
       mbmi->angle_delta[PLANE_TYPE_Y] = 0;
       mbmi->angle_delta[PLANE_TYPE_UV] = 0;
@@ -1929,15 +2077,22 @@
   }
   av1_count_overlappable_neighbors(cm, xd);
 
+#if CONFIG_NEW_REF_SIGNALING
+  if (mbmi->ref_frame[1] != INTRA_FRAME_NRS)
+#else
   if (mbmi->ref_frame[1] != INTRA_FRAME)
+#endif  // CONFIG_NEW_REF_SIGNALING
     mbmi->motion_mode = read_motion_mode(cm, xd, mbmi, r);
 
   // init
   mbmi->comp_group_idx = 0;
-  mbmi->compound_idx = 1;
   mbmi->interinter_comp.type = COMPOUND_AVERAGE;
 
-  if (has_second_ref(mbmi) && !mbmi->skip_mode) {
+  if (has_second_ref(mbmi) &&
+#if CONFIG_OPTFLOW_REFINEMENT
+      mbmi->mode <= NEW_NEWMV &&
+#endif  // CONFIG_OPTFLOW_REFINEMENT
+      !mbmi->skip_mode) {
     // Read idx to indicate current compound inter prediction mode group
     const int masked_compound_used = is_any_masked_compound_used(bsize) &&
                                      cm->seq_params.enable_masked_compound;
@@ -1949,21 +2104,7 @@
     }
 
     if (mbmi->comp_group_idx == 0) {
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-      if (cm->seq_params.order_hint_info.enable_dist_wtd_comp) {
-        const int comp_index_ctx = get_comp_index_context(cm, xd);
-        mbmi->compound_idx = (uint8_t)aom_read_symbol(
-            r, ec_ctx->compound_index_cdf[comp_index_ctx], 2, ACCT_STR);
-        mbmi->interinter_comp.type =
-            mbmi->compound_idx ? COMPOUND_AVERAGE : COMPOUND_DISTWTD;
-      } else {
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
-        // Distance-weighted compound is disabled, so always use average
-        mbmi->compound_idx = 1;
-        mbmi->interinter_comp.type = COMPOUND_AVERAGE;
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-      }
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
+      mbmi->interinter_comp.type = COMPOUND_AVERAGE;
     } else {
       assert(cm->current_frame.reference_mode != SINGLE_REFERENCE &&
              is_inter_compound_mode(mbmi->mode) &&
@@ -1993,7 +2134,7 @@
     }
   }
 
-  read_mb_interp_filter(xd, features->interp_filter,
+  read_mb_interp_filter(xd, features->interp_filter, cm,
 #if !CONFIG_REMOVE_DUAL_FILTER
                         cm->seq_params.enable_dual_filter,
 #endif  // !CONFIG_REMOVE_DUAL_FILTER
@@ -2025,6 +2166,10 @@
 #endif
     xd->cfl.store_y = store_cfl_required(cm, xd);
 
+#if CONFIG_REF_MV_BANK
+  if (cm->seq_params.enable_refmvbank) av1_update_ref_mv_bank(cm, xd, mbmi);
+#endif  // CONFIG_REF_MV_BANK
+
 #if DEC_MISMATCH_DEBUG
   dec_dump_logs(cm, mi, mi_row, mi_col, mode_ctx);
 #endif  // DEC_MISMATCH_DEBUG
@@ -2068,7 +2213,18 @@
   read_delta_q_params(cm, xd, r);
 
   if (!mbmi->skip_mode)
-    inter_block = read_is_inter_block(cm, xd, mbmi->segment_id, r);
+    inter_block =
+        read_is_inter_block(cm, xd, mbmi->segment_id, r
+#if CONFIG_CONTEXT_DERIVATION
+#if CONFIG_SDP
+                            ,
+                            mbmi->skip_txfm[xd->tree_type == CHROMA_PART]
+#else
+                            ,
+                            mbmi->skip_txfm
+#endif
+#endif  // CONFIG_CONTEXT_DERIVATION
+        );
 
   mbmi->current_qindex = xd->current_base_qindex;
 
@@ -2094,7 +2250,11 @@
   for (int h = 0; h < y_mis; h++) {
     MV_REF *mv = frame_mvs;
     for (int w = 0; w < x_mis; w++) {
+#if CONFIG_NEW_REF_SIGNALING
+      mv->ref_frame = INVALID_IDX;
+#else
       mv->ref_frame = NONE_FRAME;
+#endif  // CONFIG_NEW_REF_SIGNALING
       mv++;
     }
     frame_mvs += frame_mvs_stride;
diff --git a/av1/decoder/decodemv.h b/av1/decoder/decodemv.h
index 57e18a6..e8d40ba 100644
--- a/av1/decoder/decodemv.h
+++ b/av1/decoder/decodemv.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_DECODER_DECODEMV_H_
diff --git a/av1/decoder/decoder.c b/av1/decoder/decoder.c
index caf274f..5486053 100644
--- a/av1/decoder/decoder.c
+++ b/av1/decoder/decoder.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
@@ -28,6 +29,7 @@
 #include "av1/common/alloccommon.h"
 #include "av1/common/av1_common_int.h"
 #include "av1/common/av1_loopfilter.h"
+#include "av1/common/pred_common.h"
 #include "av1/common/quant_common.h"
 #include "av1/common/reconinter.h"
 #include "av1/common/reconintra.h"
@@ -479,7 +481,12 @@
     // TODO(jkoleszar): Error concealment is undefined and non-normative
     // at this point, but if it becomes so, [0] may not always be the correct
     // thing to do here.
+#if CONFIG_NEW_REF_SIGNALING
+    const int last_frame = get_closest_pastcur_ref_index(cm);
+    RefCntBuffer *ref_buf = get_ref_frame_buf(cm, last_frame);
+#else
     RefCntBuffer *ref_buf = get_ref_frame_buf(cm, LAST_FRAME);
+#endif  // CONFIG_NEW_REF_SIGNALING
     if (ref_buf != NULL) ref_buf->buf.corrupted = 1;
   }
 
diff --git a/av1/decoder/decoder.h b/av1/decoder/decoder.h
index 45355ad..d7ab3a7 100644
--- a/av1/decoder/decoder.h
+++ b/av1/decoder/decoder.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_DECODER_DECODER_H_
@@ -127,6 +128,10 @@
   decode_block_visitor_fn_t inverse_tx_inter_block_visit;
   predict_inter_block_visitor_fn_t predict_inter_block_visit;
   cfl_store_inter_block_visitor_fn_t cfl_store_inter_block_visit;
+
+#if CONFIG_REF_MV_BANK
+  REF_MV_BANK ref_mv_bank;
+#endif  // CONFIG_REF_MV_BANK
 } ThreadData;
 
 typedef struct AV1DecRowMTJobInfo {
diff --git a/av1/decoder/decodetxb.c b/av1/decoder/decodetxb.c
index 2f5c152..aaa4ec6 100644
--- a/av1/decoder/decodetxb.c
+++ b/av1/decoder/decodetxb.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "av1/decoder/decodetxb.h"
@@ -117,6 +118,11 @@
                             const TXB_CTX *const txb_ctx,
                             const TX_SIZE tx_size) {
   MACROBLOCKD *const xd = &dcb->xd;
+#if CONFIG_CONTEXT_DERIVATION
+  if (plane == AOM_PLANE_U) {
+    xd->eob_u = 0;
+  }
+#endif  // CONFIG_CONTEXT_DERIVATION
   FRAME_CONTEXT *const ec_ctx = xd->tile_ctx;
   const int32_t max_value = (1 << (7 + xd->bd)) - 1;
   const int32_t min_value = -(1 << (7 + xd->bd));
@@ -138,8 +144,21 @@
   int dc_val = 0;
   uint8_t levels_buf[TX_PAD_2D];
   uint8_t *const levels = set_levels(levels_buf, width);
+#if CONFIG_CONTEXT_DERIVATION
+  int txb_skip_ctx = txb_ctx->txb_skip_ctx;
+  int all_zero;
+  if (plane == AOM_PLANE_Y || plane == AOM_PLANE_U) {
+    all_zero = aom_read_symbol(r, ec_ctx->txb_skip_cdf[txs_ctx][txb_skip_ctx],
+                               2, ACCT_STR);
+  } else {
+    txb_skip_ctx += (xd->eob_u_flag ? V_TXB_SKIP_CONTEXT_OFFSET : 0);
+    all_zero =
+        aom_read_symbol(r, ec_ctx->v_txb_skip_cdf[txb_skip_ctx], 2, ACCT_STR);
+  }
+#else
   const int all_zero = aom_read_symbol(
       r, ec_ctx->txb_skip_cdf[txs_ctx][txb_ctx->txb_skip_ctx], 2, ACCT_STR);
+#endif  // CONFIG_CONTEXT_DERIVATION
   eob_info *eob_data = dcb->eob_data[plane] + dcb->txb_offset[plane];
   uint16_t *const eob = &(eob_data->eob);
   uint16_t *const max_scan_line = &(eob_data->max_scan_line);
@@ -165,6 +184,12 @@
           xd->mi_row, xd->mi_col, blk_row, blk_col, plane, tx_size);
 #endif
 
+#if CONFIG_CONTEXT_DERIVATION
+  if (plane == AOM_PLANE_U) {
+    xd->eob_u_flag = all_zero ? 0 : 1;
+  }
+#endif  // CONFIG_CONTEXT_DERIVATION
+
   if (all_zero) {
     *max_scan_line = 0;
     if (plane == 0) {
@@ -258,6 +283,12 @@
   }
   *eob = rec_eob_pos(eob_pt, eob_extra);
 
+#if CONFIG_CONTEXT_DERIVATION
+  if (plane == AOM_PLANE_U) {
+    xd->eob_u = *eob;
+  }
+#endif  // CONFIG_CONTEXT_DERIVATION
+
 #if CONFIG_IST
   // read  sec_tx_type here
   // Only y plane's sec_tx_type is transmitted
@@ -316,14 +347,44 @@
     const int pos = scan[c];
     uint8_t sign;
     tran_low_t level = levels[get_padded_idx(pos, bwl)];
+#if CONFIG_CONTEXT_DERIVATION
+    if (plane == AOM_PLANE_U) {
+      xd->tmp_sign[pos] = 0;
+    }
+#endif  // CONFIG_CONTEXT_DERIVATION
     if (level) {
       *max_scan_line = AOMMAX(*max_scan_line, pos);
       if (c == 0) {
         const int dc_sign_ctx = txb_ctx->dc_sign_ctx;
+#if CONFIG_CONTEXT_DERIVATION
+        if (plane == AOM_PLANE_Y || plane == AOM_PLANE_U) {
+          sign = aom_read_symbol(
+              r, ec_ctx->dc_sign_cdf[plane_type][dc_sign_ctx], 2, ACCT_STR);
+        } else {
+          int32_t tmp_sign = 0;
+          if (c < xd->eob_u) tmp_sign = xd->tmp_sign[0];
+          sign = aom_read_symbol(
+              r, ec_ctx->v_dc_sign_cdf[tmp_sign][dc_sign_ctx], 2, ACCT_STR);
+        }
+        if (plane == AOM_PLANE_U) xd->tmp_sign[0] = (sign ? 2 : 1);
+#else
         sign = aom_read_symbol(r, ec_ctx->dc_sign_cdf[plane_type][dc_sign_ctx],
                                2, ACCT_STR);
+#endif  // CONFIG_CONTEXT_DERIVATION
       } else {
+#if CONFIG_CONTEXT_DERIVATION
+        if (plane == AOM_PLANE_Y || plane == AOM_PLANE_U)
+          sign = aom_read_bit(r, ACCT_STR);
+        else {
+          int32_t tmp_sign = 0;
+          if (c < xd->eob_u) tmp_sign = xd->tmp_sign[pos];
+          sign =
+              aom_read_symbol(r, ec_ctx->v_ac_sign_cdf[tmp_sign], 2, ACCT_STR);
+        }
+        if (plane == AOM_PLANE_U) xd->tmp_sign[pos] = (sign ? 2 : 1);
+#else
         sign = aom_read_bit(r, ACCT_STR);
+#endif  // CONFIG_CONTEXT_DERIVATION
       }
       if (level >= MAX_BASE_BR_RANGE) {
         level += read_golomb(xd, r);
diff --git a/av1/decoder/decodetxb.h b/av1/decoder/decodetxb.h
index fd34d40..c37db2b 100644
--- a/av1/decoder/decodetxb.h
+++ b/av1/decoder/decodetxb.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_DECODER_DECODETXB_H_
diff --git a/av1/decoder/detokenize.c b/av1/decoder/detokenize.c
index 406a6b4..f23ee3d 100644
--- a/av1/decoder/detokenize.c
+++ b/av1/decoder/detokenize.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "config/aom_config.h"
diff --git a/av1/decoder/detokenize.h b/av1/decoder/detokenize.h
index 173b437..32e3473 100644
--- a/av1/decoder/detokenize.h
+++ b/av1/decoder/detokenize.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_DECODER_DETOKENIZE_H_
diff --git a/av1/decoder/dthread.h b/av1/decoder/dthread.h
index f82b9d8..c06280b 100644
--- a/av1/decoder/dthread.h
+++ b/av1/decoder/dthread.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_DECODER_DTHREAD_H_
diff --git a/av1/decoder/inspection.c b/av1/decoder/inspection.c
index 7113d50..5bdb723 100644
--- a/av1/decoder/inspection.c
+++ b/av1/decoder/inspection.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #include "av1/decoder/decoder.h"
 #include "av1/decoder/inspection.h"
diff --git a/av1/decoder/inspection.h b/av1/decoder/inspection.h
index 9a17254..68eb589 100644
--- a/av1/decoder/inspection.h
+++ b/av1/decoder/inspection.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #ifndef AOM_AV1_DECODER_INSPECTION_H_
 #define AOM_AV1_DECODER_INSPECTION_H_
diff --git a/av1/decoder/obu.c b/av1/decoder/obu.c
index 963a9e6..d1b7a24 100644
--- a/av1/decoder/obu.c
+++ b/av1/decoder/obu.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/av1/decoder/obu.h b/av1/decoder/obu.h
index d8ebe36..879f374 100644
--- a/av1/decoder/obu.h
+++ b/av1/decoder/obu.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_DECODER_OBU_H_
diff --git a/av1/encoder/aq_complexity.c b/av1/encoder/aq_complexity.c
index 4a45fc7..9b40562 100644
--- a/av1/encoder/aq_complexity.c
+++ b/av1/encoder/aq_complexity.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <limits.h>
@@ -48,11 +49,17 @@
 
 static bool is_frame_aq_enabled(const AV1_COMP *const cpi) {
   const AV1_COMMON *const cm = &cpi->common;
-  const RefreshFrameFlagsInfo *const refresh_frame_flags = &cpi->refresh_frame;
 
+#if CONFIG_NEW_REF_SIGNALING
+  (void)cm;
+  // TODO(kslu) enable this for nrs
+  return 0;
+#else
+  const RefreshFrameFlagsInfo *const refresh_frame_flags = &cpi->refresh_frame;
   return frame_is_intra_only(cm) || cm->features.error_resilient_mode ||
          refresh_frame_flags->alt_ref_frame ||
          (refresh_frame_flags->golden_frame && !cpi->rc.is_src_frame_alt_ref);
+#endif  // CONFIG_NEW_REF_SIGNALING
 }
 
 // Segmentation only makes sense if the target bits per SB is above a threshold.
diff --git a/av1/encoder/aq_complexity.h b/av1/encoder/aq_complexity.h
index 3421d74..6483461 100644
--- a/av1/encoder/aq_complexity.h
+++ b/av1/encoder/aq_complexity.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_AQ_COMPLEXITY_H_
diff --git a/av1/encoder/aq_cyclicrefresh.c b/av1/encoder/aq_cyclicrefresh.c
index 5036fbe..80aecba 100644
--- a/av1/encoder/aq_cyclicrefresh.c
+++ b/av1/encoder/aq_cyclicrefresh.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <limits.h>
@@ -45,14 +46,13 @@
     return NULL;
   }
 #if CONFIG_EXTQUANT
-  assert(bit_depth == AOM_BITS_8
-             ? (MAXQ_8_BITS <= (QINDEX_RANGE_8_BITS - 1))
-             : bit_depth == AOM_BITS_10
-                   ? (MAXQ_10_BITS <= (QINDEX_RANGE_10_BITS - 1))
-                   : (MAXQ <= (QINDEX_RANGE - 1)));
-  const uint16_t qinit = bit_depth == AOM_BITS_8
-                             ? MAXQ_8_BITS
-                             : bit_depth == AOM_BITS_10 ? MAXQ_10_BITS : MAXQ;
+  assert(bit_depth == AOM_BITS_8 ? (MAXQ_8_BITS <= (QINDEX_RANGE_8_BITS - 1))
+         : bit_depth == AOM_BITS_10
+             ? (MAXQ_10_BITS <= (QINDEX_RANGE_10_BITS - 1))
+             : (MAXQ <= (QINDEX_RANGE - 1)));
+  const uint16_t qinit = bit_depth == AOM_BITS_8    ? MAXQ_8_BITS
+                         : bit_depth == AOM_BITS_10 ? MAXQ_10_BITS
+                                                    : MAXQ;
   for (int i = 0; i < mi_rows * mi_cols; ++i) cr->last_coded_q_map[i] = qinit;
 #else
   assert(MAXQ <= 255);
@@ -377,7 +377,9 @@
   int qp_max_thresh = 118 * MAXQ >> 7;
   cr->apply_cyclic_refresh = 1;
   if (frame_is_intra_only(cm) || is_lossless_requested(&cpi->oxcf.rc_cfg) ||
+#if CONFIG_SVC_ENCODER
       cpi->svc.temporal_layer_id > 0 ||
+#endif  // CONFIG_SVC_ENCODER
       rc->avg_frame_qindex[INTER_FRAME] < qp_thresh ||
       (rc->frames_since_key > 20 &&
        rc->avg_frame_qindex[INTER_FRAME] > qp_max_thresh) ||
@@ -416,10 +418,12 @@
     cr->percent_refresh = 10;
     cr->rate_ratio_qdelta = 1.5;
     cr->rate_boost_fac = 10;
+#if !CONFIG_NEW_REF_SIGNALING
     if (cpi->refresh_frame.golden_frame) {
       cr->percent_refresh = 0;
       cr->rate_ratio_qdelta = 1.0;
     }
+#endif  // !CONFIG_NEW_REF_SIGNALING
   }
   // Weight for segment prior to encoding: take the average of the target
   // number for the frame to be encoded and the actual from the previous frame.
@@ -457,9 +461,9 @@
 #if CONFIG_EXTQUANT
       for (int i = 0; i <= (cm->mi_params.mi_rows * cm->mi_params.mi_cols); i++)
         cr->last_coded_q_map[i] =
-            cm->seq_params.bit_depth == AOM_BITS_8
-                ? MAXQ_8_BITS
-                : cm->seq_params.bit_depth == AOM_BITS_10 ? MAXQ_10_BITS : MAXQ;
+            cm->seq_params.bit_depth == AOM_BITS_8    ? MAXQ_8_BITS
+            : cm->seq_params.bit_depth == AOM_BITS_10 ? MAXQ_10_BITS
+                                                      : MAXQ;
 #else
       memset(cr->last_coded_q_map, MAXQ,
              cm->mi_params.mi_rows * cm->mi_params.mi_cols *
@@ -511,9 +515,9 @@
     const int qindex2 = clamp(
         quant_params->base_qindex + quant_params->y_dc_delta_q + qindex_delta,
         0,
-        cm->seq_params.bit_depth == AOM_BITS_8
-            ? MAXQ_8_BITS
-            : cm->seq_params.bit_depth == AOM_BITS_10 ? MAXQ_10_BITS : MAXQ);
+        cm->seq_params.bit_depth == AOM_BITS_8    ? MAXQ_8_BITS
+        : cm->seq_params.bit_depth == AOM_BITS_10 ? MAXQ_10_BITS
+                                                  : MAXQ);
 #else
     const int qindex2 = clamp(
         quant_params->base_qindex + quant_params->y_dc_delta_q + qindex_delta,
@@ -545,6 +549,8 @@
   CYCLIC_REFRESH *const cr = cpi->cyclic_refresh;
   memset(cr->map, 0, cm->mi_params.mi_rows * cm->mi_params.mi_cols);
   cr->sb_index = 0;
+#if !CONFIG_NEW_REF_SIGNALING
   cpi->refresh_frame.golden_frame = true;
+#endif  // !CONFIG_NEW_REF_SIGNALING
   cr->apply_cyclic_refresh = 0;
 }
diff --git a/av1/encoder/aq_cyclicrefresh.h b/av1/encoder/aq_cyclicrefresh.h
index 93a408a..7418c4c 100644
--- a/av1/encoder/aq_cyclicrefresh.h
+++ b/av1/encoder/aq_cyclicrefresh.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_AQ_CYCLICREFRESH_H_
diff --git a/av1/encoder/aq_variance.c b/av1/encoder/aq_variance.c
index 4479dcb..e02dded 100644
--- a/av1/encoder/aq_variance.c
+++ b/av1/encoder/aq_variance.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <math.h>
@@ -44,7 +45,9 @@
 
 void av1_vaq_frame_setup(AV1_COMP *cpi) {
   AV1_COMMON *cm = &cpi->common;
+#if !CONFIG_NEW_REF_SIGNALING
   const RefreshFrameFlagsInfo *const refresh_frame_flags = &cpi->refresh_frame;
+#endif  // !CONFIG_NEW_REF_SIGNALING
   const int base_qindex = cm->quant_params.base_qindex;
   struct segmentation *seg = &cm->seg;
   int i;
@@ -65,9 +68,13 @@
     av1_disable_segmentation(seg);
     return;
   }
+#if CONFIG_NEW_REF_SIGNALING
+  if (frame_is_intra_only(cm) || cm->features.error_resilient_mode) {
+#else
   if (frame_is_intra_only(cm) || cm->features.error_resilient_mode ||
       refresh_frame_flags->alt_ref_frame ||
       (refresh_frame_flags->golden_frame && !cpi->rc.is_src_frame_alt_ref)) {
+#endif  // CONFIG_NEW_REF_SIGNALING
     cpi->vaq_refresh = 1;
 
     av1_enable_segmentation(seg);
diff --git a/av1/encoder/aq_variance.h b/av1/encoder/aq_variance.h
index 543eb0b..77684f6 100644
--- a/av1/encoder/aq_variance.h
+++ b/av1/encoder/aq_variance.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_AQ_VARIANCE_H_
diff --git a/av1/encoder/arm/neon/av1_fwd_txfm2d_neon.c b/av1/encoder/arm/neon/av1_fwd_txfm2d_neon.c
index b9a314d..ba27a8e 100644
--- a/av1/encoder/arm/neon/av1_fwd_txfm2d_neon.c
+++ b/av1/encoder/arm/neon/av1_fwd_txfm2d_neon.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <arm_neon.h>
diff --git a/av1/encoder/arm/neon/encodetxb_neon.c b/av1/encoder/arm/neon/encodetxb_neon.c
index 4ededd8..38869f7 100644
--- a/av1/encoder/arm/neon/encodetxb_neon.c
+++ b/av1/encoder/arm/neon/encodetxb_neon.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <arm_neon.h>
diff --git a/av1/encoder/arm/neon/highbd_fwd_txfm_neon.c b/av1/encoder/arm/neon/highbd_fwd_txfm_neon.c
index e17cd90..e539dd3 100644
--- a/av1/encoder/arm/neon/highbd_fwd_txfm_neon.c
+++ b/av1/encoder/arm/neon/highbd_fwd_txfm_neon.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <arm_neon.h>
diff --git a/av1/encoder/arm/neon/hybrid_fwd_txfm_neon.c b/av1/encoder/arm/neon/hybrid_fwd_txfm_neon.c
index 0ad1131..35f5f33 100644
--- a/av1/encoder/arm/neon/hybrid_fwd_txfm_neon.c
+++ b/av1/encoder/arm/neon/hybrid_fwd_txfm_neon.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <arm_neon.h>
diff --git a/av1/encoder/arm/neon/ml_neon.c b/av1/encoder/arm/neon/ml_neon.c
index fcff3a9..1c914bb 100644
--- a/av1/encoder/arm/neon/ml_neon.c
+++ b/av1/encoder/arm/neon/ml_neon.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <stdbool.h>
diff --git a/av1/encoder/arm/neon/picksrt_neon.c b/av1/encoder/arm/neon/picksrt_neon.c
index 34595e8..7e461ac 100644
--- a/av1/encoder/arm/neon/picksrt_neon.c
+++ b/av1/encoder/arm/neon/picksrt_neon.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <arm_neon.h>
diff --git a/av1/encoder/arm/neon/quantize_neon.c b/av1/encoder/arm/neon/quantize_neon.c
index 7c41354..7481668 100644
--- a/av1/encoder/arm/neon/quantize_neon.c
+++ b/av1/encoder/arm/neon/quantize_neon.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <arm_neon.h>
diff --git a/av1/encoder/arm/neon/rdopt_neon.c b/av1/encoder/arm/neon/rdopt_neon.c
index 1786b27..74d2931 100644
--- a/av1/encoder/arm/neon/rdopt_neon.c
+++ b/av1/encoder/arm/neon/rdopt_neon.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/av1/encoder/av1_fwd_txfm1d.c b/av1/encoder/av1_fwd_txfm1d.c
index 6601c19..2d87d13 100644
--- a/av1/encoder/av1_fwd_txfm1d.c
+++ b/av1/encoder/av1_fwd_txfm1d.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <stdlib.h>
diff --git a/av1/encoder/av1_fwd_txfm1d.h b/av1/encoder/av1_fwd_txfm1d.h
index 9ef54fe..c125944 100644
--- a/av1/encoder/av1_fwd_txfm1d.h
+++ b/av1/encoder/av1_fwd_txfm1d.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_AV1_FWD_TXFM1D_H_
diff --git a/av1/encoder/av1_fwd_txfm1d_cfg.h b/av1/encoder/av1_fwd_txfm1d_cfg.h
index 2777cc2..5719107 100644
--- a/av1/encoder/av1_fwd_txfm1d_cfg.h
+++ b/av1/encoder/av1_fwd_txfm1d_cfg.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_AV1_FWD_TXFM1D_CFG_H_
diff --git a/av1/encoder/av1_fwd_txfm2d.c b/av1/encoder/av1_fwd_txfm2d.c
index 39b0b1c..6ba66c2 100644
--- a/av1/encoder/av1_fwd_txfm2d.c
+++ b/av1/encoder/av1_fwd_txfm2d.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/av1/encoder/av1_noise_estimate.c b/av1/encoder/av1_noise_estimate.c
index d1dceaf..58c3152 100644
--- a/av1/encoder/av1_noise_estimate.c
+++ b/av1/encoder/av1_noise_estimate.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
@@ -22,13 +23,15 @@
 #include "av1/encoder/encoder.h"
 
 #if CONFIG_AV1_TEMPORAL_DENOISING
+#if CONFIG_SVC_ENCODER
 // For SVC: only do noise estimation on top spatial layer.
 static INLINE int noise_est_svc(const struct AV1_COMP *const cpi) {
   return (!cpi->use_svc ||
           (cpi->use_svc &&
            cpi->svc.spatial_layer_id == cpi->svc.number_spatial_layers - 1));
 }
-#endif
+#endif  // CONFIG_SVC_ENCODER
+#endif  // CONFIG_AV1_TEMPORAL_DENOISING
 
 void av1_noise_estimate_init(NOISE_ESTIMATE *const ne, int width, int height) {
   ne->enabled = 0;
@@ -61,7 +64,10 @@
 
 // Enable noise estimation if denoising is on.
 #if CONFIG_AV1_TEMPORAL_DENOISING
-  if (cpi->oxcf.noise_sensitivity > 0 && noise_est_svc(cpi) &&
+  if (cpi->oxcf.noise_sensitivity > 0 &&
+#if CONFIG_SVC_ENCODER
+      noise_est_svc(cpi) &&
+#endif  // CONFIG_SVC_ENCODER
       cpi->common.width >= 320 && cpi->common.height >= 180)
     return 1;
 #endif
@@ -71,7 +77,10 @@
   // Not enabled for low resolutions.
   if (cpi->oxcf.pass == 0 && cpi->oxcf.rc_cfg.mode == AOM_CBR &&
       cpi->oxcf.q_cfg.aq_mode == CYCLIC_REFRESH_AQ && cpi->oxcf.speed >= 5 &&
-      resize_pending == 0 && !cpi->use_svc &&
+      resize_pending == 0 &&
+#if CONFIG_SVC_ENCODER
+      !cpi->use_svc &&
+#endif  // CONFIG_SVC_ENCODER
       cpi->oxcf.tune_cfg.content != AOM_CONTENT_SCREEN &&
       cpi->common.width * cpi->common.height >= 640 * 360)
     return 1;
@@ -116,7 +125,9 @@
   const CommonModeInfoParams *const mi_params = &cm->mi_params;
 
   NOISE_ESTIMATE *const ne = &cpi->noise_estimate;
+#if CONFIG_SVC_ENCODER
   const int low_res = (cm->width <= 352 && cm->height <= 288);
+#endif  // CONFIG_SVC_ENCODER
   // Estimate of noise level every frame_period frames.
   int frame_period = 8;
   int thresh_consec_zeromv = 6;
@@ -124,7 +135,11 @@
   // Estimate is between current source and last source.
   YV12_BUFFER_CONFIG *last_source = cpi->last_source;
 #if CONFIG_AV1_TEMPORAL_DENOISING
-  if (cpi->oxcf.noise_sensitivity > 0 && noise_est_svc(cpi)) {
+  if (cpi->oxcf.noise_sensitivity > 0
+#if CONFIG_SVC_ENCODER
+      && noise_est_svc(cpi)
+#endif  // CONFIG_SVC_ENCODER
+  ) {
     last_source = &cpi->denoiser.last_source;
     // Tune these thresholds for different resolutions when denoising is
     // enabled.
@@ -134,14 +149,23 @@
   }
 #endif
   ne->enabled = enable_noise_estimation(cpi);
+#if CONFIG_SVC_ENCODER
   if (cpi->svc.number_spatial_layers > 1)
     frame_counter = cpi->svc.current_superframe;
+#endif  // CONFIG_SVC_ENCODER
   if (!ne->enabled || frame_counter % frame_period != 0 ||
       last_source == NULL ||
-      (cpi->svc.number_spatial_layers == 1 &&
-       (ne->last_w != cm->width || ne->last_h != cm->height))) {
+      (
+#if CONFIG_SVC_ENCODER
+          cpi->svc.number_spatial_layers == 1 &&
+#endif  // CONFIG_SVC_ENCODER
+          (ne->last_w != cm->width || ne->last_h != cm->height))) {
 #if CONFIG_AV1_TEMPORAL_DENOISING
-    if (cpi->oxcf.noise_sensitivity > 0 && noise_est_svc(cpi))
+    if (cpi->oxcf.noise_sensitivity > 0
+#if CONFIG_SVC_ENCODER
+        && noise_est_svc(cpi)
+#endif  // CONFIG_SVC_ENCODER
+    )
       copy_frame(&cpi->denoiser.last_source, cpi->source);
 #endif
     if (last_source != NULL) {
@@ -149,6 +173,7 @@
       ne->last_h = cm->height;
     }
     return;
+#if CONFIG_SVC_ENCODER
   } else if (frame_counter > 60 && cpi->svc.num_encoded_top_layer > 1 &&
              cpi->rc.frames_since_key > cpi->svc.number_spatial_layers &&
              cpi->svc.spatial_layer_id == cpi->svc.number_spatial_layers - 1 &&
@@ -165,6 +190,7 @@
     }
 #endif
     return;
+#endif  // CONFIG_SVC_ENCODER
   } else {
     unsigned int bin_size = 100;
     unsigned int hist[MAX_VAR_HIST_BINS] = { 0 };
@@ -292,13 +318,21 @@
       ne->count = 0;
       ne->level = av1_noise_estimate_extract_level(ne);
 #if CONFIG_AV1_TEMPORAL_DENOISING
-      if (cpi->oxcf.noise_sensitivity > 0 && noise_est_svc(cpi))
+      if (cpi->oxcf.noise_sensitivity > 0
+#if CONFIG_SVC_ENCODER
+          && noise_est_svc(cpi)
+#endif  // CONFIG_SVC_ENCODER
+      )
         av1_denoiser_set_noise_level(cpi, ne->level);
 #endif
     }
   }
 #if CONFIG_AV1_TEMPORAL_DENOISING
-  if (cpi->oxcf.noise_sensitivity > 0 && noise_est_svc(cpi))
+  if (cpi->oxcf.noise_sensitivity > 0
+#if CONFIG_SVC_ENCODER
+      && noise_est_svc(cpi)
+#endif  // CONFIG_SVC_ENCODER
+  )
     copy_frame(&cpi->denoiser.last_source, cpi->source);
 #endif
 }
diff --git a/av1/encoder/av1_noise_estimate.h b/av1/encoder/av1_noise_estimate.h
index 8553066..78ac54f 100644
--- a/av1/encoder/av1_noise_estimate.h
+++ b/av1/encoder/av1_noise_estimate.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_AV1_NOISE_ESTIMATE_H_
diff --git a/av1/encoder/av1_quantize.c b/av1/encoder/av1_quantize.c
index 3b6d15f..538e191 100644
--- a/av1/encoder/av1_quantize.c
+++ b/av1/encoder/av1_quantize.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <math.h>
@@ -782,10 +783,9 @@
   int i, q, quant_QTX;
 
 #if CONFIG_EXTQUANT
-  int qindex_range =
-      (bit_depth == AOM_BITS_8
-           ? QINDEX_RANGE_8_BITS
-           : bit_depth == AOM_BITS_10 ? QINDEX_RANGE_10_BITS : QINDEX_RANGE);
+  int qindex_range = (bit_depth == AOM_BITS_8    ? QINDEX_RANGE_8_BITS
+                      : bit_depth == AOM_BITS_10 ? QINDEX_RANGE_10_BITS
+                                                 : QINDEX_RANGE);
 #else
   int qindex_range = QINDEX_RANGE;
 #endif
@@ -932,15 +932,14 @@
   const QUANTS *const quants = &cpi->enc_quant_dequant_params.quants;
   const Dequants *const dequants = &cpi->enc_quant_dequant_params.dequants;
 #if CONFIG_EXTQUANT
-  int current_qindex =
-      AOMMAX(0, AOMMIN(cm->seq_params.bit_depth == AOM_BITS_8
-                           ? QINDEX_RANGE_8_BITS - 1
-                           : cm->seq_params.bit_depth == AOM_BITS_10
-                                 ? QINDEX_RANGE_10_BITS - 1
-                                 : QINDEX_RANGE - 1,
-                       cm->delta_q_info.delta_q_present_flag
-                           ? quant_params->base_qindex + x->delta_qindex
-                           : quant_params->base_qindex));
+  int current_qindex = AOMMAX(
+      0, AOMMIN(cm->seq_params.bit_depth == AOM_BITS_8 ? QINDEX_RANGE_8_BITS - 1
+                : cm->seq_params.bit_depth == AOM_BITS_10
+                    ? QINDEX_RANGE_10_BITS - 1
+                    : QINDEX_RANGE - 1,
+                cm->delta_q_info.delta_q_present_flag
+                    ? quant_params->base_qindex + x->delta_qindex
+                    : quant_params->base_qindex));
   const int qindex = av1_get_qindex(&cm->seg, segment_id, current_qindex,
                                     cm->seq_params.bit_depth);
 #else
@@ -1082,6 +1081,9 @@
   // delta_q changes.
   CommonQuantParams *quant_params = &cm->quant_params;
   quant_params->base_qindex = AOMMAX(cm->delta_q_info.delta_q_present_flag, q);
+#if CONFIG_NEW_REF_SIGNALING
+  cm->cur_frame->base_qindex = quant_params->base_qindex;
+#endif  // CONFIG_NEW_REF_SIGNALING
   set_frame_dc_delta_q(cm, &quant_params->y_dc_delta_q, enable_chroma_deltaq,
                        &quant_params->u_dc_delta_q, &quant_params->v_dc_delta_q,
                        &quant_params->u_ac_delta_q,
diff --git a/av1/encoder/av1_quantize.h b/av1/encoder/av1_quantize.h
index 314d4ae..0885c93 100644
--- a/av1/encoder/av1_quantize.h
+++ b/av1/encoder/av1_quantize.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_AV1_QUANTIZE_H_
diff --git a/av1/encoder/bitstream.c b/av1/encoder/bitstream.c
index d830a00..4b83713 100644
--- a/av1/encoder/bitstream.c
+++ b/av1/encoder/bitstream.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
@@ -68,6 +69,7 @@
     const AV1_COMMON *const cm, MACROBLOCKD *xd, const RestorationUnitInfo *rui,
     aom_writer *const w, int plane, FRAME_COUNTS *counts);
 
+#if !CONFIG_AIMC
 static AOM_INLINE void write_intra_y_mode_kf(FRAME_CONTEXT *frame_ctx,
                                              const MB_MODE_INFO *mi,
                                              const MB_MODE_INFO *above_mi,
@@ -83,7 +85,7 @@
   aom_write_symbol(w, mode, get_y_mode_cdf(frame_ctx, above_mi, left_mi),
                    INTRA_MODES);
 }
-
+#endif  // !CONFIG_AIMC
 static AOM_INLINE void write_inter_mode(aom_writer *w, PREDICTION_MODE mode,
                                         FRAME_CONTEXT *ec_ctx,
                                         const int16_t mode_ctx) {
@@ -168,11 +170,28 @@
 
 static AOM_INLINE void write_inter_compound_mode(MACROBLOCKD *xd, aom_writer *w,
                                                  PREDICTION_MODE mode,
+#if CONFIG_OPTFLOW_REFINEMENT
+                                                 const AV1_COMMON *cm,
+                                                 const MB_MODE_INFO *const mbmi,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
                                                  const int16_t mode_ctx) {
   assert(is_inter_compound_mode(mode));
+#if CONFIG_OPTFLOW_REFINEMENT
+  if (cm->features.opfl_refine_type == REFINE_SWITCHABLE &&
+      is_opfl_refine_allowed(cm, mbmi)) {
+    const int use_optical_flow = mode > NEW_NEWMV;
+    aom_write_symbol(w, use_optical_flow,
+                     xd->tile_ctx->use_optflow_cdf[mode_ctx], 2);
+  }
+  int comp_mode_idx = opfl_get_comp_idx(mode);
+  aom_write_symbol(w, comp_mode_idx,
+                   xd->tile_ctx->inter_compound_mode_cdf[mode_ctx],
+                   INTER_COMPOUND_REF_TYPES);
+#else
   aom_write_symbol(w, INTER_COMPOUND_OFFSET(mode),
                    xd->tile_ctx->inter_compound_mode_cdf[mode_ctx],
                    INTER_COMPOUND_MODES);
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 }
 
 #if CONFIG_NEW_TX_PARTITION
@@ -378,8 +397,12 @@
     assert(!skip_mode);
     return 0;
   }
+#if CONFIG_NEW_REF_SIGNALING
+  if (segfeature_active(&cm->seg, segment_id, SEG_LVL_GLOBALMV)) {
+#else
   if (segfeature_active(&cm->seg, segment_id, SEG_LVL_REF_FRAME) ||
       segfeature_active(&cm->seg, segment_id, SEG_LVL_GLOBALMV)) {
+#endif  // CONFIG_NEW_REF_SIGNALING
     // These features imply single-reference mode, while skip mode implies
     // compound reference. Hence, the two are mutually exclusive.
     // In other words, skip_mode is implicitly 0 here.
@@ -393,16 +416,29 @@
 
 static AOM_INLINE void write_is_inter(const AV1_COMMON *cm,
                                       const MACROBLOCKD *xd, int segment_id,
-                                      aom_writer *w, const int is_inter) {
+                                      aom_writer *w, const int is_inter
+#if CONFIG_CONTEXT_DERIVATION
+                                      ,
+                                      const int skip_txfm
+#endif  // CONFIG_CONTEXT_DERIVATION
+) {
+#if !CONFIG_NEW_REF_SIGNALING
   if (!segfeature_active(&cm->seg, segment_id, SEG_LVL_REF_FRAME)) {
+#endif  // !CONFIG_NEW_REF_SIGNALING
     if (segfeature_active(&cm->seg, segment_id, SEG_LVL_GLOBALMV)) {
       assert(is_inter);
       return;
     }
     const int ctx = av1_get_intra_inter_context(xd);
     FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
-    aom_write_symbol(w, is_inter, ec_ctx->intra_inter_cdf[ctx], 2);
+#if CONFIG_CONTEXT_DERIVATION
+    aom_write_symbol(w, is_inter, ec_ctx->intra_inter_cdf[skip_txfm][ctx], 2);
+#else
+  aom_write_symbol(w, is_inter, ec_ctx->intra_inter_cdf[ctx], 2);
+#endif  // CONFIG_CONTEXT_DERIVATION
+#if !CONFIG_NEW_REF_SIGNALING
   }
+#endif  // !CONFIG_NEW_REF_SIGNALING
 }
 
 static AOM_INLINE void write_motion_mode(const AV1_COMMON *cm, MACROBLOCKD *xd,
@@ -686,8 +722,48 @@
 #endif
 }
 
+#if CONFIG_NEW_REF_SIGNALING
+static AOM_INLINE void write_single_ref_nrs(
+    const MACROBLOCKD *xd, const RefFramesInfo *const ref_frames_info,
+    aom_writer *w) {
+  const MB_MODE_INFO *const mbmi = xd->mi[0];
+  MV_REFERENCE_FRAME ref = mbmi->ref_frame[0];
+  const int n_refs = ref_frames_info->n_total_refs;
+  assert(ref < n_refs);
+  for (int i = 0; i < n_refs - 1; i++) {
+    const int bit = ref == i;
+    aom_write_symbol(w, bit, av1_get_pred_cdf_single_ref_nrs(xd, i, n_refs), 2);
+    if (bit) return;
+  }
+  assert(ref == (n_refs - 1));
+}
+
+static AOM_INLINE void write_compound_ref_nrs(
+    const MACROBLOCKD *xd, const RefFramesInfo *const ref_frames_info,
+    aom_writer *w) {
+  const MB_MODE_INFO *const mbmi = xd->mi[0];
+  MV_REFERENCE_FRAME ref0 = mbmi->ref_frame[0];
+  MV_REFERENCE_FRAME ref1 = mbmi->ref_frame[1];
+  const int n_refs = ref_frames_info->n_total_refs;
+  assert(n_refs >= 2);
+  assert(ref0 < ref1);
+  int n_bits = 0;
+  for (int i = 0; i < n_refs + n_bits - 2 && n_bits < 2; i++) {
+    const int bit = ref0 == i || ref1 == i;
+    const int bit_type =
+        av1_get_compound_ref_bit_type(n_bits, ref_frames_info, ref0, i);
+    aom_write_symbol(
+        w, bit,
+        av1_get_pred_cdf_compound_ref_nrs(xd, i, n_bits, bit_type, n_refs), 2);
+    n_bits += bit;
+  }
+  assert(IMPLIES(n_bits < 2, AOMMAX(ref0, ref1) == n_refs - 1));
+  assert(IMPLIES(n_bits < 1, AOMMIN(ref0, ref1) == n_refs - 2));
+}
+#else
 #define WRITE_REF_BIT(bname, pname) \
   aom_write_symbol(w, bname, av1_get_pred_cdf_##pname(xd), 2)
+#endif  // !CONFIG_NEW_REF_SIGNALING
 
 // This function encodes the reference frame
 static AOM_INLINE void write_ref_frames(const AV1_COMMON *cm,
@@ -698,14 +774,20 @@
 
   // If segment level coding of this signal is disabled...
   // or the segment allows multiple reference frame options
+#if CONFIG_NEW_REF_SIGNALING
+  if (segfeature_active(&cm->seg, segment_id, SEG_LVL_SKIP) ||
+      segfeature_active(&cm->seg, segment_id, SEG_LVL_GLOBALMV)) {
+    assert(mbmi->ref_frame[0] == get_closest_pastcur_ref_index(cm));
+#else
   if (segfeature_active(&cm->seg, segment_id, SEG_LVL_REF_FRAME)) {
     assert(!is_compound);
     assert(mbmi->ref_frame[0] ==
            get_segdata(&cm->seg, segment_id, SEG_LVL_REF_FRAME));
   } else if (segfeature_active(&cm->seg, segment_id, SEG_LVL_SKIP) ||
              segfeature_active(&cm->seg, segment_id, SEG_LVL_GLOBALMV)) {
-    assert(!is_compound);
     assert(mbmi->ref_frame[0] == LAST_FRAME);
+#endif  // CONFIG_NEW_REF_SIGNALING
+    assert(!is_compound);
   } else {
     // does the feature use compound prediction or not
     // (if not specified at the frame/segment level)
@@ -715,13 +797,16 @@
 #else
       if (is_comp_ref_allowed(mbmi->sb_type))
 #endif
-        aom_write_symbol(w, is_compound, av1_get_reference_mode_cdf(xd), 2);
+        aom_write_symbol(w, is_compound, av1_get_reference_mode_cdf(cm, xd), 2);
     } else {
       assert((!is_compound) ==
              (cm->current_frame.reference_mode == SINGLE_REFERENCE));
     }
 
     if (is_compound) {
+#if CONFIG_NEW_REF_SIGNALING
+      write_compound_ref_nrs(xd, &cm->ref_frames_info, w);
+#else
       const COMP_REFERENCE_TYPE comp_ref_type = has_uni_comp_refs(mbmi)
                                                     ? UNIDIR_COMP_REFERENCE
                                                     : BIDIR_COMP_REFERENCE;
@@ -768,8 +853,12 @@
       if (!bit_bwd) {
         WRITE_REF_BIT(mbmi->ref_frame[1] == ALTREF2_FRAME, comp_bwdref_p1);
       }
+#endif  // CONFIG_NEW_REF_SIGNALING
 
     } else {
+#if CONFIG_NEW_REF_SIGNALING
+      write_single_ref_nrs(xd, &cm->ref_frames_info, w);
+#else
       const int bit0 = (mbmi->ref_frame[0] <= ALTREF_FRAME &&
                         mbmi->ref_frame[0] >= BWDREF_FRAME);
       WRITE_REF_BIT(bit0, single_ref_p1);
@@ -794,6 +883,7 @@
           WRITE_REF_BIT(bit4, single_ref_p5);
         }
       }
+#endif  // CONFIG_NEW_REF_SIGNALING
     }
   }
 }
@@ -823,19 +913,13 @@
   }
 }
 
-#if CONFIG_ORIP
-static AOM_INLINE void write_angle_delta_hv(aom_writer *w, int angle_delta,
-                                            aom_cdf_prob *cdf) {
-  aom_write_symbol(w, get_angle_delta_to_idx(angle_delta), cdf,
-                   2 * MAX_ANGLE_DELTA + 1 + ADDITIONAL_ANGLE_DELTA);
-}
-#endif
-
+#if !CONFIG_AIMC
 static AOM_INLINE void write_angle_delta(aom_writer *w, int angle_delta,
                                          aom_cdf_prob *cdf) {
   aom_write_symbol(w, angle_delta + MAX_ANGLE_DELTA, cdf,
                    2 * MAX_ANGLE_DELTA + 1);
 }
+#endif  // !CONFIG_AIMC
 
 static AOM_INLINE void write_mb_interp_filter(AV1_COMMON *const cm,
                                               const MACROBLOCKD *xd,
@@ -843,19 +927,44 @@
   const MB_MODE_INFO *const mbmi = xd->mi[0];
   FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
 
-  if (!av1_is_interp_needed(xd)) {
-#if CONFIG_REMOVE_DUAL_FILTER
-    assert(mbmi->interp_fltr ==
-           av1_unswitchable_filter(cm->features.interp_filter));
+  if (!av1_is_interp_needed(cm, xd)) {
+#if CONFIG_DEBUG
+#if CONFIG_OPTFLOW_REFINEMENT
+    // Sharp filter is always used whenever optical flow refinement is applied.
+    int mb_interp_filter =
+        (mbmi->mode > NEW_NEWMV || use_opfl_refine_all(cm, mbmi))
+            ? MULTITAP_SHARP
+            : cm->features.interp_filter;
 #else
-    int_interpfilters filters = av1_broadcast_interp_filter(
-        av1_unswitchable_filter(cm->features.interp_filter));
+    int mb_interp_filter = cm->features.interp_filter;
+#endif  // CONFIG_OPTFLOW_REFINEMENT
+#if CONFIG_REMOVE_DUAL_FILTER
+    assert(mbmi->interp_fltr == av1_unswitchable_filter(mb_interp_filter));
+#else
+    int_interpfilters filters =
+        av1_broadcast_interp_filter(av1_unswitchable_filter(mb_interp_filter));
     assert(mbmi->interp_filters.as_int == filters.as_int);
     (void)filters;
 #endif  // CONFIG_REMOVE_DUAL_FILTER
+    (void)mb_interp_filter;
+#endif  // CONFIG_DEBUG
     return;
   }
   if (cm->features.interp_filter == SWITCHABLE) {
+#if CONFIG_OPTFLOW_REFINEMENT
+    if (mbmi->mode > NEW_NEWMV || use_opfl_refine_all(cm, mbmi)) {
+#if CONFIG_REMOVE_DUAL_FILTER
+      assert(IMPLIES(mbmi->mode > NEW_NEWMV || use_opfl_refine_all(cm, mbmi),
+                     mbmi->interp_fltr == MULTITAP_SHARP));
+#else
+      assert(IMPLIES(
+          mbmi->mode > NEW_NEWMV || use_opfl_refine_all(cm, mbmi),
+          mbmi->interp_filters.as_filters.x_filter == MULTITAP_SHARP &&
+              mbmi->interp_filters.as_filters.y_filter == MULTITAP_SHARP));
+#endif
+      return;
+    }
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 #if CONFIG_REMOVE_DUAL_FILTER
     const int ctx = av1_get_pred_context_switchable_interp(xd, 0);
     const InterpFilter filter = mbmi->interp_fltr;
@@ -1146,7 +1255,7 @@
   }
 }
 #endif
-
+#if !CONFIG_AIMC
 static AOM_INLINE void write_intra_y_mode_nonkf(FRAME_CONTEXT *frame_ctx,
                                                 BLOCK_SIZE bsize,
                                                 PREDICTION_MODE mode,
@@ -1154,14 +1263,14 @@
   aom_write_symbol(w, mode, frame_ctx->y_mode_cdf[size_group_lookup[bsize]],
                    INTRA_MODES);
 }
-
+#endif  // !CONFIG_AIMC
 #if CONFIG_MRLS
 static AOM_INLINE void write_mrl_index(FRAME_CONTEXT *ec_ctx, uint8_t mrl_index,
                                        aom_writer *w) {
   aom_write_symbol(w, mrl_index, ec_ctx->mrl_index_cdf, MRL_LINE_NUMBER);
 }
 #endif
-
+#if !CONFIG_AIMC
 static AOM_INLINE void write_intra_uv_mode(FRAME_CONTEXT *frame_ctx,
                                            UV_PREDICTION_MODE uv_mode,
                                            PREDICTION_MODE y_mode,
@@ -1170,7 +1279,7 @@
   aom_write_symbol(w, uv_mode, frame_ctx->uv_mode_cdf[cfl_allowed][y_mode],
                    UV_INTRA_MODES - !cfl_allowed);
 }
-
+#endif  // !CONFIG_AIMC
 static AOM_INLINE void write_cfl_alphas(FRAME_CONTEXT *const ec_ctx,
                                         uint8_t idx, int8_t joint_sign,
                                         aom_writer *w) {
@@ -1350,8 +1459,53 @@
   }
 }
 
+#if CONFIG_AIMC
+// write mode set index and mode index in set for y component
+static AOM_INLINE void write_intra_luma_mode(MACROBLOCKD *const xd,
+                                             aom_writer *w) {
+  FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
+  MB_MODE_INFO *const mbmi = xd->mi[0];
+  const int mode_idx = mbmi->y_mode_idx;
+  assert(mode_idx >= 0 && mode_idx < LUMA_MODE_COUNT);
+  assert(mbmi->joint_y_mode_delta_angle >= 0 &&
+         mbmi->joint_y_mode_delta_angle < LUMA_MODE_COUNT);
+  if (mbmi->joint_y_mode_delta_angle < NON_DIRECTIONAL_MODES_COUNT)
+    assert(mbmi->joint_y_mode_delta_angle == mbmi->y_mode_idx);
+  const int context = get_y_mode_idx_ctx(xd);
+  int mode_set_index = mode_idx < FIRST_MODE_COUNT ? 0 : 1;
+  mode_set_index += ((mode_idx - FIRST_MODE_COUNT) / SECOND_MODE_COUNT);
+  aom_write_symbol(w, mode_set_index, ec_ctx->y_mode_set_cdf, INTRA_MODE_SETS);
+  if (mode_set_index == 0) {
+    aom_write_symbol(w, mode_idx, ec_ctx->y_mode_idx_cdf_0[context],
+                     FIRST_MODE_COUNT);
+  } else {
+    aom_write_symbol(
+        w,
+        mode_idx - FIRST_MODE_COUNT - (mode_set_index - 1) * SECOND_MODE_COUNT,
+        ec_ctx->y_mode_idx_cdf_1[context], SECOND_MODE_COUNT);
+  }
+  if (mbmi->joint_y_mode_delta_angle < NON_DIRECTIONAL_MODES_COUNT)
+    assert(mbmi->joint_y_mode_delta_angle == mbmi->y_mode_idx);
+}
+
+// write mode mode index for uv component
+static AOM_INLINE void write_intra_uv_mode(MACROBLOCKD *const xd,
+                                           CFL_ALLOWED_TYPE cfl_allowed,
+                                           aom_writer *w) {
+  FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
+  MB_MODE_INFO *const mbmi = xd->mi[0];
+  const int uv_mode_idx = mbmi->uv_mode_idx;
+  assert(uv_mode_idx >= 0 && uv_mode_idx < UV_INTRA_MODES);
+  const int context = av1_is_directional_mode(mbmi->mode) ? 1 : 0;
+  aom_write_symbol(w, uv_mode_idx, ec_ctx->uv_mode_cdf[cfl_allowed][context],
+                   UV_INTRA_MODES - !cfl_allowed);
+}
+#endif  // CONFIG_AIMC
+
 static AOM_INLINE void write_intra_prediction_modes(AV1_COMP *cpi,
+#if !CONFIG_AIMC
                                                     int is_keyframe,
+#endif  // !CONFIG_AIMC
                                                     aom_writer *w) {
   const AV1_COMMON *const cm = &cpi->common;
   MACROBLOCK *const x = &cpi->td.mb;
@@ -1364,60 +1518,37 @@
 #else
   const BLOCK_SIZE bsize = mbmi->sb_type;
 #endif
+#if !CONFIG_AIMC
+  const int use_angle_delta = av1_use_angle_delta(bsize);
+#endif  // !CONFIG_AIMC
 
   // Y mode.
 #if CONFIG_SDP
-  const int use_angle_delta = av1_use_angle_delta(bsize);
   if (xd->tree_type != CHROMA_PART) {
 #endif
-    if (is_keyframe) {
-      const MB_MODE_INFO *const above_mi = xd->above_mbmi;
-      const MB_MODE_INFO *const left_mi = xd->left_mbmi;
-      write_intra_y_mode_kf(ec_ctx, mbmi, above_mi, left_mi, mode, w);
-    } else {
-      write_intra_y_mode_nonkf(ec_ctx, bsize, mode, w);
-    }
-
-#if CONFIG_MRLS && CONFIG_ORIP
-    // Encoding reference line index before angle delta if ORIP is enable
-    if (cm->seq_params.enable_mrls && av1_is_directional_mode(mode)) {
-      write_mrl_index(ec_ctx, mbmi->mrl_index, w);
-    }
-#endif
-
-    // Y angle delta.
-#if !CONFIG_SDP
-    const int use_angle_delta = av1_use_angle_delta(bsize);
-#endif
-    if (use_angle_delta && av1_is_directional_mode(mode)) {
-#if CONFIG_ORIP
-      int signal_intra_filter =
-          av1_signal_orip_for_horver_modes(cm, mbmi, PLANE_TYPE_Y, bsize);
-      aom_cdf_prob *cdf_angle =
-          signal_intra_filter
-#if CONFIG_SDP
-              ? ec_ctx->angle_delta_cdf_hv[PLANE_TYPE_Y][mode - V_PRED]
-              : ec_ctx->angle_delta_cdf[PLANE_TYPE_Y][mode - V_PRED];
+#if CONFIG_AIMC
+    write_intra_luma_mode(xd, w);
 #else
-              ? ec_ctx->angle_delta_cdf_hv[mode - V_PRED]
-              : ec_ctx->angle_delta_cdf[mode - V_PRED];
+  if (is_keyframe) {
+    const MB_MODE_INFO *const above_mi = xd->above_mbmi;
+    const MB_MODE_INFO *const left_mi = xd->left_mbmi;
+    write_intra_y_mode_kf(ec_ctx, mbmi, above_mi, left_mi, mode, w);
+  } else {
+    write_intra_y_mode_nonkf(ec_ctx, bsize, mode, w);
+  }
 
-#endif  // CONFIG_SDP
-      assert(mbmi->angle_delta[PLANE_TYPE_Y] >= -3 &&
-             mbmi->angle_delta[PLANE_TYPE_Y] <= ANGLE_DELTA_VALUE_ORIP);
-      if (signal_intra_filter)
-        write_angle_delta_hv(w, mbmi->angle_delta[PLANE_TYPE_Y], cdf_angle);
-      else
-        write_angle_delta(w, mbmi->angle_delta[PLANE_TYPE_Y], cdf_angle);
-#elif CONFIG_SDP
+  // Y angle delta.
+  if (use_angle_delta && av1_is_directional_mode(mode)) {
+#if CONFIG_SDP
     write_angle_delta(w, mbmi->angle_delta[PLANE_TYPE_Y],
                       ec_ctx->angle_delta_cdf[PLANE_TYPE_Y][mode - V_PRED]);
 #else
     write_angle_delta(w, mbmi->angle_delta[PLANE_TYPE_Y],
                       ec_ctx->angle_delta_cdf[mode - V_PRED]);
-#endif  // CONFIG_ORIP
-    }
-#if CONFIG_MRLS && !CONFIG_ORIP
+#endif  // CONFIG_SDP
+  }
+#endif  // CONFIG_AIMC
+#if CONFIG_MRLS
     // Encoding reference line index
     if (cm->seq_params.enable_mrls && av1_is_directional_mode(mode)) {
       write_mrl_index(ec_ctx, mbmi->mrl_index, w);
@@ -1435,9 +1566,10 @@
   if (!cm->seq_params.monochrome && xd->is_chroma_ref) {
 #endif
     const UV_PREDICTION_MODE uv_mode = mbmi->uv_mode;
+#if CONFIG_AIMC
+    write_intra_uv_mode(xd, is_cfl_allowed(xd), w);
+#else
     write_intra_uv_mode(ec_ctx, uv_mode, mode, is_cfl_allowed(xd), w);
-    if (uv_mode == UV_CFL_PRED)
-      write_cfl_alphas(ec_ctx, mbmi->cfl_alpha_idx, mbmi->cfl_alpha_signs, w);
     if (use_angle_delta && av1_is_directional_mode(get_uv_mode(uv_mode))) {
 #if CONFIG_SDP
       if (cm->seq_params.enable_sdp) {
@@ -1454,6 +1586,9 @@
                         ec_ctx->angle_delta_cdf[uv_mode - V_PRED]);
 #endif
     }
+#endif  // CONFIG_AIMC
+    if (uv_mode == UV_CFL_PRED)
+      write_cfl_alphas(ec_ctx, mbmi->cfl_alpha_idx, mbmi->cfl_alpha_signs, w);
   }
 
   // Palette.
@@ -1467,7 +1602,7 @@
 
 static INLINE int16_t mode_context_analyzer(
     const int16_t mode_context, const MV_REFERENCE_FRAME *const rf) {
-  if (rf[1] <= INTRA_FRAME) return mode_context;
+  if (!is_inter_ref_frame(rf[1])) return mode_context;
 
   const int16_t newmv_ctx = mode_context & NEWMV_CTX_MASK;
   const int16_t refmv_ctx = (mode_context >> REFMV_OFFSET) & REFMV_CTX_MASK;
@@ -1483,7 +1618,7 @@
   const int8_t ref_frame_type = av1_ref_frame_type(ref_frame);
   const CANDIDATE_MV *curr_ref_mv_stack = mbmi_ext_frame->ref_mv_stack;
 
-  if (ref_frame[1] > INTRA_FRAME) {
+  if (is_inter_ref_frame(ref_frame[1])) {
     assert(ref_idx == 0 || ref_idx == 1);
     return ref_idx ? curr_ref_mv_stack[ref_mv_idx].comp_mv
                    : curr_ref_mv_stack[ref_mv_idx].this_mv;
@@ -1499,7 +1634,7 @@
   const MACROBLOCKD *xd = &x->e_mbd;
   const MB_MODE_INFO *mbmi = xd->mi[0];
   int ref_mv_idx = mbmi->ref_mv_idx;
-  if (mbmi->mode == NEAR_NEWMV || mbmi->mode == NEW_NEARMV) {
+  if (have_nearmv_newmv_in_inter_mode(mbmi->mode)) {
     assert(has_second_ref(mbmi));
 #if !CONFIG_NEW_INTER_MODES
     ref_mv_idx += 1;
@@ -1556,12 +1691,22 @@
 
   write_delta_q_params(cpi, skip, w);
 
-  if (!mbmi->skip_mode) write_is_inter(cm, xd, mbmi->segment_id, w, is_inter);
+  if (!mbmi->skip_mode)
+    write_is_inter(cm, xd, mbmi->segment_id, w, is_inter
+#if CONFIG_CONTEXT_DERIVATION
+                   ,
+                   skip
+#endif  // CONFIG_CONTEXT_DERIVATION
+    );
 
   if (mbmi->skip_mode) return;
 
   if (!is_inter) {
+#if CONFIG_AIMC
+    write_intra_prediction_modes(cpi, w);
+#else
     write_intra_prediction_modes(cpi, 0, w);
+#endif  // CONFIG_AIMC
   } else {
     int16_t mode_ctx;
 
@@ -1575,7 +1720,11 @@
     // If segment skip is not enabled code the mode.
     if (!segfeature_active(seg, segment_id, SEG_LVL_SKIP)) {
       if (is_inter_compound_mode(mode))
-        write_inter_compound_mode(xd, w, mode, mode_ctx);
+        write_inter_compound_mode(xd, w, mode,
+#if CONFIG_OPTFLOW_REFINEMENT
+                                  cm, mbmi,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
+                                  mode_ctx);
       else if (is_inter_singleref_mode(mode))
         write_inter_mode(w, mode, ec_ctx, mode_ctx);
 
@@ -1589,7 +1738,11 @@
         assert(mbmi->ref_mv_idx == 0);
     }
 
-    if (mode == NEWMV || mode == NEW_NEWMV) {
+    if (mode == NEWMV ||
+#if CONFIG_OPTFLOW_REFINEMENT
+        mode == NEW_NEWMV_OPTFLOW ||
+#endif  // CONFIG_OPTFLOW_REFINEMENT
+        mode == NEW_NEWMV) {
       for (ref = 0; ref < 1 + is_compound; ++ref) {
         nmv_context *nmvc = &ec_ctx->nmvc;
         const int_mv ref_mv = get_ref_mv(x, ref);
@@ -1597,11 +1750,19 @@
                       allow_hp);
       }
 #if CONFIG_NEW_INTER_MODES
+#if CONFIG_OPTFLOW_REFINEMENT
+    } else if (mode == NEAR_NEWMV || mode == NEAR_NEWMV_OPTFLOW) {
+#else
     } else if (mode == NEAR_NEWMV) {
+#endif  // CONFIG_OPTFLOW_REFINEMENT
       nmv_context *nmvc = &ec_ctx->nmvc;
       const int_mv ref_mv = get_ref_mv(x, 1);
       av1_encode_mv(cpi, w, &mbmi->mv[1].as_mv, &ref_mv.as_mv, nmvc, allow_hp);
+#if CONFIG_OPTFLOW_REFINEMENT
+    } else if (mode == NEW_NEARMV || mode == NEW_NEARMV_OPTFLOW) {
+#else
     } else if (mode == NEW_NEARMV) {
+#endif  // CONFIG_OPTFLOW_REFINEMENT
       nmv_context *nmvc = &ec_ctx->nmvc;
       const int_mv ref_mv = get_ref_mv(x, 0);
       av1_encode_mv(cpi, w, &mbmi->mv[0].as_mv, &ref_mv.as_mv, nmvc, allow_hp);
@@ -1621,7 +1782,11 @@
     if (cpi->common.current_frame.reference_mode != COMPOUND_REFERENCE &&
         cpi->common.seq_params.enable_interintra_compound &&
         is_interintra_allowed(mbmi)) {
+#if CONFIG_NEW_REF_SIGNALING
+      const int interintra = mbmi->ref_frame[1] == INTRA_FRAME_NRS;
+#else
       const int interintra = mbmi->ref_frame[1] == INTRA_FRAME;
+#endif  // CONFIG_NEW_REF_SIGNALING
       const int bsize_group = size_group_lookup[bsize];
       aom_write_symbol(w, interintra, ec_ctx->interintra_cdf[bsize_group], 2);
       if (interintra) {
@@ -1639,12 +1804,21 @@
       }
     }
 
-    if (mbmi->ref_frame[1] != INTRA_FRAME) write_motion_mode(cm, xd, mbmi, w);
+#if CONFIG_NEW_REF_SIGNALING
+    if (mbmi->ref_frame[1] != INTRA_FRAME_NRS)
+#else
+    if (mbmi->ref_frame[1] != INTRA_FRAME)
+#endif  // CONFIG_NEW_REF_SIGNALING
+      write_motion_mode(cm, xd, mbmi, w);
 
-    // First write idx to indicate current compound inter prediction mode group
-    // Group A (0): dist_wtd_comp, compound_average
-    // Group B (1): interintra, compound_diffwtd, wedge
+      // First write idx to indicate current compound inter prediction mode
+      // group Group A (0): dist_wtd_comp, compound_average Group B (1):
+      // interintra, compound_diffwtd, wedge
+#if CONFIG_OPTFLOW_REFINEMENT
+    if (has_second_ref(mbmi) && mbmi->mode <= NEW_NEWMV) {
+#else
     if (has_second_ref(mbmi)) {
+#endif  // CONFIG_OPTFLOW_REFINEMENT
       const int masked_compound_used = is_any_masked_compound_used(bsize) &&
                                        cm->seq_params.enable_masked_compound;
 
@@ -1657,20 +1831,7 @@
       }
 
       if (mbmi->comp_group_idx == 0) {
-        if (mbmi->compound_idx)
-          assert(mbmi->interinter_comp.type == COMPOUND_AVERAGE);
-
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-        if (cm->seq_params.order_hint_info.enable_dist_wtd_comp) {
-          const int comp_index_ctx = get_comp_index_context(cm, xd);
-          aom_write_symbol(w, mbmi->compound_idx,
-                           ec_ctx->compound_index_cdf[comp_index_ctx], 2);
-        } else {
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
-          assert(mbmi->compound_idx == 1);
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-        }
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
+        assert(mbmi->interinter_comp.type == COMPOUND_AVERAGE);
       } else {
         assert(cpi->common.current_frame.reference_mode != SINGLE_REFERENCE &&
                is_inter_compound_mode(mbmi->mode) &&
@@ -1770,7 +1931,11 @@
 #endif
   }
 
+#if CONFIG_AIMC
+  write_intra_prediction_modes(cpi, w);
+#else
   write_intra_prediction_modes(cpi, 1, w);
+#endif  // CONFIG_AIMC
 }
 
 #if CONFIG_RD_DEBUG
@@ -3012,7 +3177,11 @@
   int found = 0;
 
   MV_REFERENCE_FRAME ref_frame;
+#if CONFIG_NEW_REF_SIGNALING
+  for (ref_frame = 0; ref_frame < INTER_REFS_PER_FRAME; ++ref_frame) {
+#else
   for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
+#endif  // CONFIG_NEW_REF_SIGNALING
     const YV12_BUFFER_CONFIG *cfg = get_ref_frame_yv12_buf(cm, ref_frame);
 
     if (cfg != NULL) {
@@ -3187,8 +3356,13 @@
 
   if (!pars->update_parameters) {
     int ref_frame, ref_idx;
+#if CONFIG_NEW_REF_SIGNALING
+    for (ref_frame = 0; ref_frame < INTER_REFS_PER_FRAME; ref_frame++) {
+      ref_idx = get_ref_frame_map_idx(cm, ref_frame);
+#else
     for (ref_frame = LAST_FRAME; ref_frame < REF_FRAMES; ref_frame++) {
       ref_idx = get_ref_frame_map_idx(cm, ref_frame);
+#endif  // CONFIG_NEW_REF_SIGNALING
       assert(ref_idx != INVALID_IDX);
       const RefCntBuffer *const buf = cm->ref_frame_map[ref_idx];
       if (buf->film_grain_params_present &&
@@ -3325,9 +3499,6 @@
     aom_wb_write_bit(wb, seq_params->order_hint_info.enable_order_hint);
 
     if (seq_params->order_hint_info.enable_order_hint) {
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-      aom_wb_write_bit(wb, seq_params->order_hint_info.enable_dist_wtd_comp);
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
       aom_wb_write_bit(wb, seq_params->order_hint_info.enable_ref_frame_mvs);
     }
     if (seq_params->force_screen_content_tools == 2) {
@@ -3358,6 +3529,15 @@
 
 static AOM_INLINE void write_sequence_header_beyond_av1(
     const SequenceHeader *const seq_params, struct aom_write_bit_buffer *wb) {
+#if CONFIG_REF_MV_BANK
+  aom_wb_write_bit(wb, seq_params->enable_refmvbank);
+#endif  // CONFIG_REF_MV_BANK
+#if CONFIG_NEW_REF_SIGNALING
+  aom_wb_write_bit(wb, seq_params->explicit_ref_frame_map);
+  aom_wb_write_bit(wb, seq_params->max_reference_frames < 7);
+  if (seq_params->max_reference_frames < 7)
+    aom_wb_write_literal(wb, seq_params->max_reference_frames - 3, 2);
+#endif  // CONFIG_NEW_REF_SIGNALING
 #if CONFIG_SDP
   aom_wb_write_bit(wb, seq_params->enable_sdp);
 #endif
@@ -3373,6 +3553,13 @@
 #if CONFIG_ORIP
   aom_wb_write_bit(wb, seq_params->enable_orip);
 #endif
+#if CONFIG_OPTFLOW_REFINEMENT
+  if (seq_params->order_hint_info.enable_order_hint)
+    aom_wb_write_literal(wb, seq_params->enable_opfl_refine, 2);
+#endif  // CONFIG_OPTFLOW_REFINEMENT
+#if CONFIG_IBP_DC || CONFIG_IBP_DIR
+  aom_wb_write_bit(wb, seq_params->enable_ibp);
+#endif
 }
 
 static AOM_INLINE void write_global_motion_params(
@@ -3432,7 +3619,11 @@
                                            struct aom_write_bit_buffer *wb) {
   AV1_COMMON *const cm = &cpi->common;
   int frame;
+#if CONFIG_NEW_REF_SIGNALING
+  for (frame = 0; frame < cm->ref_frames_info.n_total_refs; ++frame) {
+#else
   for (frame = LAST_FRAME; frame <= ALTREF_FRAME; ++frame) {
+#endif  // CONFIG_NEW_REF_SIGNALING
     const WarpedMotionParams *ref_params =
         cm->prev_frame ? &cm->prev_frame->global_motion[frame]
                        : &default_warp_params;
@@ -3463,6 +3654,7 @@
   }
 }
 
+#if !CONFIG_NEW_REF_SIGNALING
 static int check_frame_refs_short_signaling(AV1_COMMON *const cm) {
   // Check whether all references are distinct frames.
   const RefCntBuffer *seen_bufs[FRAME_BUFFERS] = { NULL };
@@ -3530,6 +3722,7 @@
 
   return frame_refs_short_signaling;
 }
+#endif  // !CONFIG_NEW_REF_SIGNALING
 
 // New function based on HLS R18
 static AOM_INLINE void write_uncompressed_header_obu(
@@ -3542,7 +3735,9 @@
   CurrentFrame *const current_frame = &cm->current_frame;
   FeatureFlags *const features = &cm->features;
 
+#if !CONFIG_NEW_REF_SIGNALING
   current_frame->frame_refs_short_signaling = 0;
+#endif  // !CONFIG_NEW_REF_SIGNALING
 
   if (seq_params->still_picture) {
     assert(cm->show_existing_frame == 0);
@@ -3707,6 +3902,7 @@
           seq_params->order_hint_info.enable_order_hint;
 #endif  // FRAME_REFS_SHORT_SIGNALING
 
+#if !CONFIG_NEW_REF_SIGNALING
       if (current_frame->frame_refs_short_signaling) {
         // NOTE(zoeliu@google.com):
         //   An example solution for encoder-side implementation on frame refs
@@ -3726,12 +3922,26 @@
         const int gld_ref = get_ref_frame_map_idx(cm, GOLDEN_FRAME);
         aom_wb_write_literal(wb, gld_ref, REF_FRAMES_LOG2);
       }
+#endif  // !CONFIG_NEW_REF_SIGNALING
 
+#if CONFIG_NEW_REF_SIGNALING
+      for (ref_frame = 0; ref_frame < cm->ref_frames_info.n_total_refs;
+           ++ref_frame) {
+        assert(get_ref_frame_map_idx(cm, ref_frame) != INVALID_IDX);
+        // By default, no need to signal ref mapping indices in NRS because
+        // decoder can derive them unless order_hint is not available. Explicit
+        // signaling is enabled only when explicit_ref_frame_map is on.
+        if (seq_params->explicit_ref_frame_map ||
+            !seq_params->order_hint_info.enable_order_hint)
+          aom_wb_write_literal(wb, get_ref_frame_map_idx(cm, ref_frame),
+                               REF_FRAMES_LOG2);
+#else
       for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
         assert(get_ref_frame_map_idx(cm, ref_frame) != INVALID_IDX);
         if (!current_frame->frame_refs_short_signaling)
           aom_wb_write_literal(wb, get_ref_frame_map_idx(cm, ref_frame),
                                REF_FRAMES_LOG2);
+#endif  // CONFIG_NEW_REF_SIGNALING
         if (seq_params->frame_id_numbers_present_flag) {
           int i = get_ref_frame_map_idx(cm, ref_frame);
           int frame_id_len = seq_params->frame_id_length;
@@ -3766,6 +3976,11 @@
       }
       write_frame_interp_filter(features->interp_filter, wb);
       aom_wb_write_bit(wb, features->switchable_motion_mode);
+#if CONFIG_OPTFLOW_REFINEMENT
+      if (cm->seq_params.enable_opfl_refine == AOM_OPFL_REFINE_AUTO) {
+        aom_wb_write_literal(wb, features->opfl_refine_type, 2);
+      }
+#endif  // CONFIG_OPTFLOW_REFINEMENT
       if (frame_might_allow_ref_frame_mvs(cm)) {
         aom_wb_write_bit(wb, features->allow_ref_frame_mvs);
       } else {
diff --git a/av1/encoder/bitstream.h b/av1/encoder/bitstream.h
index f09960b..484c58c 100644
--- a/av1/encoder/bitstream.h
+++ b/av1/encoder/bitstream.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_BITSTREAM_H_
diff --git a/av1/encoder/block.h b/av1/encoder/block.h
index 4bf2617..9100d6d 100644
--- a/av1/encoder/block.h
+++ b/av1/encoder/block.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 /*! \file
@@ -90,7 +91,9 @@
   //! The color map needed to reconstruct palette mode.
   uint8_t color_index_map[MAX_SB_SQUARE];
   //! The current winner mode.
-  THR_MODES mode_index;
+  REFERENCE_MODE mode;
+  //! Reference frame(s) for winner mode.
+  int refs[2];
 } WinnerModeStats;
 
 /*! \brief Each source plane of the current macroblock
@@ -164,6 +167,10 @@
 typedef struct {
   //! Cost to skip txfm for the current txfm block.
   int txb_skip_cost[TXB_SKIP_CONTEXTS][2];
+#if CONFIG_CONTEXT_DERIVATION
+  //! Cost to skip txfm for the current AOM_PLANE_V txfm block.
+  int v_txb_skip_cost[V_TXB_SKIP_CONTEXTS][2];
+#endif  // CONFIG_CONTEXT_DERIVATION
   /*! \brief Cost for encoding the base_eob of a level.
    *
    * Decoder uses base_eob to derive the base_level as base_eob := base_eob+1.
@@ -181,6 +188,12 @@
   int eob_extra_cost[EOB_COEF_CONTEXTS][2];
   //! Cost for encoding the dc_sign
   int dc_sign_cost[DC_SIGN_CONTEXTS][2];
+#if CONFIG_CONTEXT_DERIVATION
+  //! Cost for encoding the AOM_PLANE_V txfm coefficient dc_sign
+  int v_dc_sign_cost[CROSS_COMPONENT_CONTEXTS][DC_SIGN_CONTEXTS][2];
+  //! Cost for encoding the AOM_PLANE_V txfm coefficient ac_sign
+  int v_ac_sign_cost[CROSS_COMPONENT_CONTEXTS][2];
+#endif  // CONFIG_CONTEXT_DERIVATION
   //! Cost for encoding an increment to the coefficient
   int lps_cost[LEVEL_CONTEXTS][COEFF_BASE_RANGE + 1 + COEFF_BASE_RANGE + 1];
 } LV_MAP_COEFF_COST;
@@ -220,7 +233,11 @@
   //! Number of ref mvs in the drl.
   uint8_t ref_mv_count[MODE_CTX_REF_FRAMES];
   //! Global mvs
+#if CONFIG_NEW_REF_SIGNALING
+  int_mv global_mvs[INTER_REFS_PER_FRAME];
+#else
   int_mv global_mvs[REF_FRAMES];
+#endif  // CONFIG_NEW_REF_SIGNALING
   //! Context used to encode the current mode.
   int16_t mode_context[MODE_CTX_REF_FRAMES];
 } MB_MODE_INFO_EXT;
@@ -240,7 +257,11 @@
   uint8_t ref_mv_count;
   // TODO(Ravi/Remya): Reduce the buffer size of global_mvs
   //! \copydoc MB_MODE_INFO_EXT::global_mvs
+#if CONFIG_NEW_REF_SIGNALING
+  int_mv global_mvs[INTER_REFS_PER_FRAME];
+#else
   int_mv global_mvs[REF_FRAMES];
+#endif  // CONFIG_NEW_REF_SIGNALING
   //! \copydoc MB_MODE_INFO_EXT::mode_context
   int16_t mode_context;
   //! Offset of current coding block's coeff buffer relative to the sb.
@@ -617,8 +638,10 @@
   int mbmode_cost[BLOCK_SIZE_GROUPS][INTRA_MODES];
   //! Luma mode cost for intra frame.
   int y_mode_costs[INTRA_MODES][INTRA_MODES][INTRA_MODES];
+#if !CONFIG_AIMC
   //! Chroma mode cost
   int intra_uv_mode_cost[CFL_ALLOWED_TYPES][INTRA_MODES][UV_INTRA_MODES];
+#endif  // !CONFIG_AIMC
   //! filter_intra_cost
   int filter_intra_cost[BLOCK_SIZES_ALL][2];
   //! filter_intra_mode_cost
@@ -627,17 +650,7 @@
   //! angle_delta_cost
   int angle_delta_cost[PARTITION_STRUCTURE_NUM][DIRECTIONAL_MODES]
                       [2 * MAX_ANGLE_DELTA + 1];
-#if CONFIG_ORIP
-  //! angle_delta_cost_hv
-  int angle_delta_cost_hv[PARTITION_STRUCTURE_NUM][TOTAL_NUM_ORIP_ANGLE_DELTA]
-                         [2 * MAX_ANGLE_DELTA + 1 + ADDITIONAL_ANGLE_DELTA];
-#endif
 #else
-#if CONFIG_ORIP
-  //! angle_delta_cost_hv
-  int angle_delta_cost_hv[TOTAL_NUM_ORIP_ANGLE_DELTA]
-                         [2 * MAX_ANGLE_DELTA + 1 + ADDITIONAL_ANGLE_DELTA];
-#endif
   //! angle_delta_cost
   int angle_delta_cost[DIRECTIONAL_MODES][2 * MAX_ANGLE_DELTA + 1];
 #endif
@@ -646,6 +659,16 @@
   //! mrl_index_cost
   int mrl_index_cost[MRL_LINE_NUMBER];
 #endif
+#if CONFIG_AIMC
+  //! y primary flag cost
+  int y_primary_flag_cost[INTRA_MODE_SETS];
+  //! y first mode cost
+  int y_first_mode_costs[Y_MODE_CONTEXTS][FIRST_MODE_COUNT];
+  //! y second mode cost
+  int y_second_mode_costs[Y_MODE_CONTEXTS][SECOND_MODE_COUNT];
+  //! uv mode cost
+  int intra_uv_mode_cost[CFL_ALLOWED_TYPES][UV_MODE_CONTEXTS][UV_INTRA_MODES];
+#endif  // CONFIG_AIMC
 
 #if CONFIG_IST
   //! Cost of signaling secondary transform index
@@ -706,10 +729,15 @@
    * \name Inter Costs: Ref Frame Types
    ****************************************************************************/
   /**@{*/
+#if CONFIG_NEW_REF_SIGNALING
+  //! single_ref_cost
+  int single_ref_cost[REF_CONTEXTS][INTER_REFS_PER_FRAME - 1][2];
+  //! comp_ref_cost
+  int comp_ref_cost[REF_CONTEXTS][COMPREF_BIT_TYPES][INTER_REFS_PER_FRAME - 2]
+                   [2];
+#else
   //! single_ref_cost
   int single_ref_cost[REF_CONTEXTS][SINGLE_REFS - 1][2];
-  //! comp_inter_cost
-  int comp_inter_cost[COMP_INTER_CONTEXTS][2];
   //! comp_ref_type_cost
   int comp_ref_type_cost[COMP_REF_TYPE_CONTEXTS]
                         [CDF_SIZE(COMP_REFERENCE_TYPES)];
@@ -726,6 +754,9 @@
    * Includes ALTREF_FRAME, ALTREF2_FRAME, and BWDREF_FRAME.
    */
   int comp_bwdref_cost[REF_CONTEXTS][BWD_REFS - 1][2];
+#endif  // CONFIG_NEW_REF_SIGNALING
+  //! comp_inter_cost
+  int comp_inter_cost[COMP_INTER_CONTEXTS][2];
   /**@}*/
 
   /*****************************************************************************
@@ -733,10 +764,23 @@
    ****************************************************************************/
   /**@{*/
   //! intra_inter_cost
+#if CONFIG_CONTEXT_DERIVATION
+  int intra_inter_cost[INTRA_INTER_SKIP_TXFM_CONTEXTS][INTRA_INTER_CONTEXTS][2];
+#else
   int intra_inter_cost[INTRA_INTER_CONTEXTS][2];
+#endif  // CONFIG_CONTEXT_DERIVATION
   //! inter_compound_mode_cost
+#if CONFIG_OPTFLOW_REFINEMENT
+  /*! use_optflow_cost */
+  int use_optflow_cost[INTER_COMPOUND_MODE_CONTEXTS][2];
+  /*! inter_compound_mode_cost */
+  int inter_compound_mode_cost[INTER_COMPOUND_MODE_CONTEXTS]
+                              [INTER_COMPOUND_REF_TYPES];
+#else
+  /*! inter_compound_mode_cost */
   int inter_compound_mode_cost[INTER_COMPOUND_MODE_CONTEXTS]
                               [INTER_COMPOUND_MODES];
+#endif  // CONFIG_OPTFLOW_REFINEMENT
   //! compound_type_cost
   int compound_type_cost[BLOCK_SIZES_ALL][MASKED_COMPOUND_TYPES];
   //! wedge_idx_cost
@@ -753,10 +797,6 @@
    * \name Inter Costs: Compound Masks
    ****************************************************************************/
   /**@{*/
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-  //! comp_idx_cost
-  int comp_idx_cost[COMP_INDEX_CONTEXTS][2];
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
   //! comp_group_idx_cost
   int comp_group_idx_cost[COMP_GROUP_IDX_CONTEXTS][2];
   /**@}*/
@@ -1094,7 +1134,11 @@
    * current mode. If the current best rd is already <= threshold, then we skip
    * the current mode.
    */
+#if CONFIG_NEW_REF_SIGNALING
+  int thresh_freq_fact[BLOCK_SIZES_ALL][MB_MODE_COUNT];
+#else
   int thresh_freq_fact[BLOCK_SIZES_ALL][MAX_MODES];
+#endif  // CONFIG_NEW_REF_SIGNALING
 
   /*! \brief Tracks the winner modes in the current coding block.
    *
@@ -1136,9 +1180,6 @@
   // processing.
   struct inter_modes_info *inter_modes_info;
 
-  //! How to blend the compound predictions.
-  uint8_t compound_idx;
-
   //! A caches of results of compound type search so they can be reused later.
   COMP_RD_STATS comp_rd_stats[MAX_COMP_RD_STATS];
   //! The idx for the latest compound mode in the cache \ref comp_rd_stats.
diff --git a/av1/encoder/blockiness.c b/av1/encoder/blockiness.c
index f7cff9e..3d54584 100644
--- a/av1/encoder/blockiness.c
+++ b/av1/encoder/blockiness.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "config/av1_rtcd.h"
diff --git a/av1/encoder/cnn.c b/av1/encoder/cnn.c
index 6b2a55a..ab2b217 100644
--- a/av1/encoder/cnn.c
+++ b/av1/encoder/cnn.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2019, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/av1/encoder/cnn.h b/av1/encoder/cnn.h
index 706be44..8e2dac7 100644
--- a/av1/encoder/cnn.h
+++ b/av1/encoder/cnn.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2019, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_COMMON_CNN_H_
diff --git a/av1/encoder/compound_type.c b/av1/encoder/compound_type.c
index f33094d..4c7fc4c 100644
--- a/av1/encoder/compound_type.c
+++ b/av1/encoder/compound_type.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "av1/common/pred_common.h"
@@ -693,12 +694,20 @@
       mbmi->mv[0].as_int = tmp_mv->as_int;
       // Set ref_frame[1] to NONE_FRAME temporarily so that the intra
       // predictor is not calculated again in av1_enc_build_inter_predictor().
+#if CONFIG_NEW_REF_SIGNALING
+      mbmi->ref_frame[1] = INVALID_IDX;
+#else
       mbmi->ref_frame[1] = NONE_FRAME;
+#endif  // CONFIG_NEW_REF_SIGNALING
       const int mi_row = xd->mi_row;
       const int mi_col = xd->mi_col;
       av1_enc_build_inter_predictor(cm, xd, mi_row, mi_col, orig_dst, bsize,
                                     AOM_PLANE_Y, AOM_PLANE_Y);
+#if CONFIG_NEW_REF_SIGNALING
+      mbmi->ref_frame[1] = INTRA_FRAME_NRS;
+#else
       mbmi->ref_frame[1] = INTRA_FRAME;
+#endif  // CONFIG_NEW_REF_SIGNALING
       av1_combine_interintra(xd, bsize, 0, xd->plane[AOM_PLANE_Y].dst.buf,
                              xd->plane[AOM_PLANE_Y].dst.stride, intrapred, bw);
       model_rd_sb_fn[MODELRD_TYPE_MASKED_COMPOUND](
@@ -752,7 +761,11 @@
   const int mi_col = xd->mi_col;
 
   // Single reference inter prediction
+#if CONFIG_NEW_REF_SIGNALING
+  mbmi->ref_frame[1] = INVALID_IDX;
+#else
   mbmi->ref_frame[1] = NONE_FRAME;
+#endif  // CONFIG_NEW_REF_SIGNALING
   xd->plane[0].dst.buf = tmp_buf;
   xd->plane[0].dst.stride = bw;
   av1_enc_build_inter_predictor(cm, xd, mi_row, mi_col, NULL, bsize,
@@ -761,7 +774,11 @@
 
   // Restore the buffers for intra prediction
   restore_dst_buf(xd, *orig_dst, num_planes);
+#if CONFIG_NEW_REF_SIGNALING
+  mbmi->ref_frame[1] = INTRA_FRAME_NRS;
+#else
   mbmi->ref_frame[1] = INTRA_FRAME;
+#endif  // CONFIG_NEW_REF_SIGNALING
   INTERINTRA_MODE best_interintra_mode =
       args->inter_intra_mode[mbmi->ref_frame[0]];
 
@@ -843,28 +860,27 @@
     COMPOUND_TYPE *valid_comp_types) {
   int valid_type_count = 0;
   int comp_type, valid_check;
+#if CONFIG_OPTFLOW_REFINEMENT
+  MACROBLOCKD *xd = &x->e_mbd;
+  MB_MODE_INFO *mbmi = xd->mi[0];
+  const PREDICTION_MODE this_mode = mbmi->mode;
+  // For implementation simplicity, set compound type to COMPOUND_AVERAGE for
+  // now to avoid compound type RD search. In practice, dist_wtd will always
+  // be applied instead.
+  if (this_mode > NEW_NEWMV) {
+    *try_average_and_distwtd_comp = 0;
+    valid_comp_types[0] = COMPOUND_AVERAGE;
+    return 1;
+  }
+#endif  // CONFIG_OPTFLOW_REFINEMENT
   int8_t enable_masked_type[MASKED_COMPOUND_TYPES] = { 0, 0 };
 
   const int try_average_comp = (mode_search_mask & (1 << COMPOUND_AVERAGE));
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-  const AV1_COMMON *cm = &cpi->common;
-  const int try_distwtd_comp =
-      ((mode_search_mask & (1 << COMPOUND_DISTWTD)) &&
-       cm->seq_params.order_hint_info.enable_dist_wtd_comp == 1 &&
-       cpi->sf.inter_sf.use_dist_wtd_comp_flag != DIST_WTD_COMP_DISABLED);
-  *try_average_and_distwtd_comp = try_average_comp && try_distwtd_comp;
-#else
   *try_average_and_distwtd_comp = 0;
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
 
   // Check if COMPOUND_AVERAGE and COMPOUND_DISTWTD are valid cases
   for (comp_type = COMPOUND_AVERAGE; comp_type < COMPOUND_WEDGE; comp_type++) {
-    valid_check =
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-        (comp_type == COMPOUND_AVERAGE) ? try_average_comp : try_distwtd_comp;
-#else
-        (comp_type == COMPOUND_AVERAGE) ? try_average_comp : 0;
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
+    valid_check = (comp_type == COMPOUND_AVERAGE) ? try_average_comp : 0;
     if (!*try_average_and_distwtd_comp && valid_check &&
         is_interinter_compound_used(comp_type, bsize))
       valid_comp_types[valid_type_count++] = comp_type;
@@ -890,9 +906,6 @@
 static INLINE void calc_masked_type_cost(const ModeCosts *mode_costs,
                                          BLOCK_SIZE bsize,
                                          int comp_group_idx_ctx,
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-                                         int comp_index_ctx,
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
                                          int masked_compound_used,
                                          int *masked_type_cost) {
   av1_zero_array(masked_type_cost, COMPOUND_TYPES);
@@ -903,21 +916,12 @@
     // Compound group index of wedge and diffwtd is 1
     masked_type_cost[COMPOUND_AVERAGE] +=
         mode_costs->comp_group_idx_cost[comp_group_idx_ctx][0];
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-    masked_type_cost[COMPOUND_DISTWTD] += masked_type_cost[COMPOUND_AVERAGE];
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
     masked_type_cost[COMPOUND_WEDGE] +=
         mode_costs->comp_group_idx_cost[comp_group_idx_ctx][1];
     masked_type_cost[COMPOUND_DIFFWTD] += masked_type_cost[COMPOUND_WEDGE];
   }
 
   // Compute the cost to signal compound index/type
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-  masked_type_cost[COMPOUND_AVERAGE] +=
-      mode_costs->comp_idx_cost[comp_index_ctx][1];
-  masked_type_cost[COMPOUND_DISTWTD] +=
-      mode_costs->comp_idx_cost[comp_index_ctx][0];
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
   masked_type_cost[COMPOUND_WEDGE] += mode_costs->compound_type_cost[bsize][0];
   masked_type_cost[COMPOUND_DIFFWTD] +=
       mode_costs->compound_type_cost[bsize][1];
@@ -928,11 +932,6 @@
                                                  COMPOUND_TYPE cur_type) {
   mbmi->interinter_comp.type = cur_type;
   mbmi->comp_group_idx = (cur_type >= COMPOUND_WEDGE);
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-  mbmi->compound_idx = (cur_type != COMPOUND_DISTWTD);
-#else
-  mbmi->compound_idx = 1;
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
 }
 
 // When match is found, populate the compound type data
@@ -987,27 +986,6 @@
   }
 }
 
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-// Choose the better of the two COMPOUND_AVERAGE,
-// COMPOUND_DISTWTD based on modeled cost
-static int find_best_avg_distwtd_comp_type(MACROBLOCK *x, int *comp_model_rate,
-                                           int64_t *comp_model_dist,
-                                           int rate_mv, int64_t *best_rd) {
-  int64_t est_rd[2];
-  est_rd[COMPOUND_AVERAGE] =
-      RDCOST(x->rdmult, comp_model_rate[COMPOUND_AVERAGE] + rate_mv,
-             comp_model_dist[COMPOUND_AVERAGE]);
-  est_rd[COMPOUND_DISTWTD] =
-      RDCOST(x->rdmult, comp_model_rate[COMPOUND_DISTWTD] + rate_mv,
-             comp_model_dist[COMPOUND_DISTWTD]);
-  int best_type = (est_rd[COMPOUND_AVERAGE] <= est_rd[COMPOUND_DISTWTD])
-                      ? COMPOUND_AVERAGE
-                      : COMPOUND_DISTWTD;
-  *best_rd = est_rd[best_type];
-  return best_type;
-}
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
-
 static INLINE void save_comp_rd_search_stat(
     MACROBLOCK *x, const MB_MODE_INFO *const mbmi, const int32_t *comp_rate,
     const int64_t *comp_dist, const int32_t *comp_model_rate,
@@ -1312,22 +1290,11 @@
   int masked_type_cost[COMPOUND_TYPES];
 
   int calc_pred_masked_compound = 1;
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-  int64_t comp_dist[COMPOUND_TYPES] = { INT64_MAX, INT64_MAX, INT64_MAX,
-                                        INT64_MAX };
-  int32_t comp_rate[COMPOUND_TYPES] = { INT_MAX, INT_MAX, INT_MAX, INT_MAX };
-  int comp_rs2[COMPOUND_TYPES] = { INT_MAX, INT_MAX, INT_MAX, INT_MAX };
-  int32_t comp_model_rate[COMPOUND_TYPES] = { INT_MAX, INT_MAX, INT_MAX,
-                                              INT_MAX };
-  int64_t comp_model_dist[COMPOUND_TYPES] = { INT64_MAX, INT64_MAX, INT64_MAX,
-                                              INT64_MAX };
-#else
   int64_t comp_dist[COMPOUND_TYPES] = { INT64_MAX, INT64_MAX, INT64_MAX };
   int32_t comp_rate[COMPOUND_TYPES] = { INT_MAX, INT_MAX, INT_MAX };
   int comp_rs2[COMPOUND_TYPES] = { INT_MAX, INT_MAX, INT_MAX };
   int32_t comp_model_rate[COMPOUND_TYPES] = { INT_MAX, INT_MAX, INT_MAX };
   int64_t comp_model_dist[COMPOUND_TYPES] = { INT64_MAX, INT64_MAX, INT64_MAX };
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
   int match_index = 0;
   const int match_found =
       find_comp_rd_in_stats(cpi, x, mbmi, comp_rate, comp_dist, comp_model_rate,
@@ -1340,18 +1307,9 @@
 
   // Local array to store the valid compound types to be evaluated in the core
   // loop
-  COMPOUND_TYPE valid_comp_types[COMPOUND_TYPES] = {
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-    COMPOUND_AVERAGE,
-    COMPOUND_DISTWTD,
-    COMPOUND_WEDGE,
-    COMPOUND_DIFFWTD
-#else
-    COMPOUND_AVERAGE,
-    COMPOUND_WEDGE,
-    COMPOUND_DIFFWTD
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
-  };
+  COMPOUND_TYPE valid_comp_types[COMPOUND_TYPES] = { COMPOUND_AVERAGE,
+                                                     COMPOUND_WEDGE,
+                                                     COMPOUND_DIFFWTD };
   int valid_type_count = 0;
   int try_average_and_distwtd_comp = 0;
   // compute_valid_comp_types() returns the number of valid compound types to be
@@ -1363,17 +1321,15 @@
 
   // The following context indices are independent of compound type
   const int comp_group_idx_ctx = get_comp_group_idx_context(cm, xd);
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-  const int comp_index_ctx = get_comp_index_context(cm, xd);
 
-  // Populates masked_type_cost local array for the 4 compound types
-  calc_masked_type_cost(&x->mode_costs, bsize, comp_group_idx_ctx,
-                        comp_index_ctx, masked_compound_used, masked_type_cost);
-#else
-  // Populates masked_type_cost local array for the 4 compound types
-  calc_masked_type_cost(&x->mode_costs, bsize, comp_group_idx_ctx,
-                        masked_compound_used, masked_type_cost);
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
+#if CONFIG_OPTFLOW_REFINEMENT
+  if (this_mode > NEW_NEWMV)
+    av1_zero_array(masked_type_cost, COMPOUND_TYPES);
+  else
+#endif  // CONFIG_OPTFLOW_REFINEMENT
+    // Populates masked_type_cost local array for the 4 compound types
+    calc_masked_type_cost(&x->mode_costs, bsize, comp_group_idx_ctx,
+                          masked_compound_used, masked_type_cost);
 
   int64_t comp_model_rd_cur = INT64_MAX;
   int64_t best_rd_cur = INT64_MAX;
@@ -1382,105 +1338,15 @@
 
   // If the match is found, calculate the rd cost using the
   // stored stats and update the mbmi appropriately.
-  if (match_found && cpi->sf.inter_sf.reuse_compound_type_decision) {
+  if (match_found &&
+#if CONFIG_OPTFLOW_REFINEMENT
+      this_mode <= NEW_NEWMV &&
+#endif  // CONFIG_OPTFLOW_REFINEMENT
+      cpi->sf.inter_sf.reuse_compound_type_decision) {
     return populate_reuse_comp_type_data(x, mbmi, &best_type_stats, cur_mv,
                                          comp_rate, comp_dist, comp_rs2,
                                          rate_mv, rd, match_index);
   }
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-  // Special handling if both compound_average and compound_distwtd
-  // are to be searched. In this case, first estimate between the two
-  // modes and then call estimate_yrd_for_sb() only for the better of
-  // the two.
-  if (try_average_and_distwtd_comp) {
-    int est_rate[2];
-    int64_t est_dist[2], est_rd;
-    COMPOUND_TYPE best_type;
-    // Since modelled rate and dist are separately stored,
-    // compute better of COMPOUND_AVERAGE and COMPOUND_DISTWTD
-    // using the stored stats.
-    if ((comp_model_rate[COMPOUND_AVERAGE] != INT_MAX) &&
-        comp_model_rate[COMPOUND_DISTWTD] != INT_MAX) {
-      // Choose the better of the COMPOUND_AVERAGE,
-      // COMPOUND_DISTWTD on modeled cost.
-      best_type = find_best_avg_distwtd_comp_type(
-          x, comp_model_rate, comp_model_dist, *rate_mv, &est_rd);
-      update_mbmi_for_compound_type(mbmi, best_type);
-      if (comp_rate[best_type] != INT_MAX)
-        best_rd_cur = RDCOST(
-            x->rdmult,
-            masked_type_cost[best_type] + *rate_mv + comp_rate[best_type],
-            comp_dist[best_type]);
-      comp_model_rd_cur = est_rd;
-      // Update stats for best compound type
-      if (best_rd_cur < *rd) {
-        update_best_info(mbmi, rd, &best_type_stats, best_rd_cur,
-                         comp_model_rd_cur, masked_type_cost[best_type]);
-      }
-      restore_dst_buf(xd, *tmp_dst, 1);
-    } else {
-      int64_t sse_y[COMPOUND_DISTWTD + 1];
-      // Calculate model_rd for COMPOUND_AVERAGE and COMPOUND_DISTWTD
-      for (int comp_type = COMPOUND_AVERAGE; comp_type <= COMPOUND_DISTWTD;
-           comp_type++) {
-        update_mbmi_for_compound_type(mbmi, comp_type);
-        av1_enc_build_inter_predictor(cm, xd, mi_row, mi_col, orig_dst, bsize,
-                                      AOM_PLANE_Y, AOM_PLANE_Y);
-        model_rd_sb_fn[MODELRD_CURVFIT](
-            cpi, bsize, x, xd, 0, 0, &est_rate[comp_type], &est_dist[comp_type],
-            NULL, NULL, NULL, NULL, NULL);
-        est_rate[comp_type] += masked_type_cost[comp_type];
-        comp_model_rate[comp_type] = est_rate[comp_type];
-        comp_model_dist[comp_type] = est_dist[comp_type];
-        sse_y[comp_type] = x->pred_sse[xd->mi[0]->ref_frame[0]];
-        if (comp_type == COMPOUND_AVERAGE) {
-          *is_luma_interp_done = 1;
-          restore_dst_buf(xd, *tmp_dst, 1);
-        }
-      }
-      // Choose the better of the two based on modeled cost and call
-      // estimate_yrd_for_sb() for that one.
-      best_type = find_best_avg_distwtd_comp_type(
-          x, comp_model_rate, comp_model_dist, *rate_mv, &est_rd);
-      update_mbmi_for_compound_type(mbmi, best_type);
-      if (best_type == COMPOUND_AVERAGE) restore_dst_buf(xd, *orig_dst, 1);
-      rs2 = masked_type_cost[best_type];
-      RD_STATS est_rd_stats;
-      const int64_t mode_rd = RDCOST(x->rdmult, rs2 + *rate_mv, 0);
-      const int64_t tmp_rd_thresh = AOMMIN(*rd, rd_thresh) - mode_rd;
-      int64_t est_rd_ = INT64_MAX;
-      int eval_txfm = 1;
-      // Check if the mode is good enough based on skip rd
-      if (cpi->sf.inter_sf.txfm_rd_gate_level) {
-        int64_t skip_rd =
-            RDCOST(x->rdmult, rs2 + *rate_mv, (sse_y[best_type] << 4));
-        eval_txfm = check_txfm_eval(x, bsize, ref_skip_rd, skip_rd,
-                                    cpi->sf.inter_sf.txfm_rd_gate_level, 1);
-      }
-      // Evaluate further if skip rd is low enough
-      if (eval_txfm) {
-        est_rd_ =
-            estimate_yrd_for_sb(cpi, bsize, x, tmp_rd_thresh, &est_rd_stats);
-      }
-
-      if (est_rd_ != INT64_MAX) {
-        best_rd_cur = RDCOST(x->rdmult, rs2 + *rate_mv + est_rd_stats.rate,
-                             est_rd_stats.dist);
-        // Backup rate and distortion for future reuse
-        backup_stats(best_type, comp_rate, comp_dist, comp_model_rate,
-                     comp_model_dist, est_rate[best_type], est_dist[best_type],
-                     &est_rd_stats, comp_rs2, rs2);
-        comp_model_rd_cur = est_rd;
-      }
-      if (best_type == COMPOUND_AVERAGE) restore_dst_buf(xd, *tmp_dst, 1);
-      // Update stats for best compound type
-      if (best_rd_cur < *rd) {
-        update_best_info(mbmi, rd, &best_type_stats, best_rd_cur,
-                         comp_model_rd_cur, rs2);
-      }
-    }
-  }
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
 
   // If COMPOUND_AVERAGE is not valid, use the spare buffer
   if (valid_comp_types[0] != COMPOUND_AVERAGE) restore_dst_buf(xd, *tmp_dst, 1);
@@ -1595,12 +1461,6 @@
   if (mbmi->interinter_comp.type != best_type_stats.best_compound_data.type) {
     mbmi->comp_group_idx =
         (best_type_stats.best_compound_data.type < COMPOUND_WEDGE) ? 0 : 1;
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-    mbmi->compound_idx =
-        !(best_type_stats.best_compound_data.type == COMPOUND_DISTWTD);
-#else
-    mbmi->compound_idx = 1;
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
     mbmi->interinter_comp = best_type_stats.best_compound_data;
     memcpy(xd->seg_mask, buffers->tmp_best_mask_buf, mask_len);
   }
diff --git a/av1/encoder/compound_type.h b/av1/encoder/compound_type.h
index bad0ba8..7543aa0 100644
--- a/av1/encoder/compound_type.h
+++ b/av1/encoder/compound_type.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_COMPOUND_TYPE_H_
diff --git a/av1/encoder/context_tree.c b/av1/encoder/context_tree.c
index 6d07ef2..99e18e6 100644
--- a/av1/encoder/context_tree.c
+++ b/av1/encoder/context_tree.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "av1/encoder/context_tree.h"
@@ -23,9 +24,9 @@
 
   dst_ctx->num_4x4_blk = src_ctx->num_4x4_blk;
   dst_ctx->skippable = src_ctx->skippable;
-#if CONFIG_INTERNAL_STATS
+#if CONFIG_INTERNAL_STATS && !CONFIG_NEW_REF_SIGNALING
   dst_ctx->best_mode_index = src_ctx->best_mode_index;
-#endif  // CONFIG_INTERNAL_STATS
+#endif  // CONFIG_INTERNAL_STATS && !CONFIG_NEW_REF_SIGNALING
 
   memcpy(dst_ctx->blk_skip, src_ctx->blk_skip,
          sizeof(uint8_t) * src_ctx->num_4x4_blk);
diff --git a/av1/encoder/context_tree.h b/av1/encoder/context_tree.h
index f243233..0a62c5e 100644
--- a/av1/encoder/context_tree.h
+++ b/av1/encoder/context_tree.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_CONTEXT_TREE_H_
@@ -49,9 +50,9 @@
   // For current partition, only if all Y, U, and V transform blocks'
   // coefficients are quantized to 0, skippable is set to 1.
   int skippable;
-#if CONFIG_INTERNAL_STATS
+#if CONFIG_INTERNAL_STATS && !CONFIG_NEW_REF_SIGNALING
   THR_MODES best_mode_index;
-#endif  // CONFIG_INTERNAL_STATS
+#endif  // CONFIG_INTERNAL_STATS && !CONFIG_NEW_REF_SIGNALING
   int hybrid_pred_diff;
   int comp_pred_diff;
   int single_pred_diff;
diff --git a/av1/encoder/corner_detect.c b/av1/encoder/corner_detect.c
index 597bb30..1dd7705 100644
--- a/av1/encoder/corner_detect.c
+++ b/av1/encoder/corner_detect.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <stdlib.h>
diff --git a/av1/encoder/corner_detect.h b/av1/encoder/corner_detect.h
index 15062f2..c4a5668 100644
--- a/av1/encoder/corner_detect.h
+++ b/av1/encoder/corner_detect.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_CORNER_DETECT_H_
diff --git a/av1/encoder/corner_match.c b/av1/encoder/corner_match.c
index c2f1b2e..686d8ec 100644
--- a/av1/encoder/corner_match.c
+++ b/av1/encoder/corner_match.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <stdlib.h>
diff --git a/av1/encoder/corner_match.h b/av1/encoder/corner_match.h
index 45c90f3..3392630 100644
--- a/av1/encoder/corner_match.h
+++ b/av1/encoder/corner_match.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #ifndef AOM_AV1_ENCODER_CORNER_MATCH_H_
 #define AOM_AV1_ENCODER_CORNER_MATCH_H_
diff --git a/av1/encoder/cost.c b/av1/encoder/cost.c
index 323e2ae..347789c 100644
--- a/av1/encoder/cost.c
+++ b/av1/encoder/cost.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #include <assert.h>
 
diff --git a/av1/encoder/cost.h b/av1/encoder/cost.h
index be0241a..8ce12af 100644
--- a/av1/encoder/cost.h
+++ b/av1/encoder/cost.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_COST_H_
diff --git a/av1/encoder/dwt.c b/av1/encoder/dwt.c
index 04088b2..f11bf84 100644
--- a/av1/encoder/dwt.c
+++ b/av1/encoder/dwt.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/av1/encoder/dwt.h b/av1/encoder/dwt.h
index 37306c6..e095ad7 100644
--- a/av1/encoder/dwt.h
+++ b/av1/encoder/dwt.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_DWT_H_
diff --git a/av1/encoder/enc_enums.h b/av1/encoder/enc_enums.h
index 3777d66..bf82ec4 100644
--- a/av1/encoder/enc_enums.h
+++ b/av1/encoder/enc_enums.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2019, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_ENC_ENUMS_H_
@@ -16,6 +17,9 @@
 extern "C" {
 #endif
 
+#if CONFIG_NEW_REF_SIGNALING
+#define NUM_SINGLE_REF_MODES (INTER_REFS_PER_FRAME * SINGLE_INTER_MODE_NUM)
+#else
 // This enumerator type needs to be kept aligned with the mode order in
 // const MODE_DEFINITION av1_mode_defs[MAX_MODES] used in the rd code.
 #if CONFIG_NEW_INTER_MODES
@@ -65,81 +69,177 @@
   THR_COMP_NEAR_NEWLA,
   THR_COMP_NEW_NEWLA,
   THR_COMP_GLOBAL_GLOBALLA,
+#if CONFIG_OPTFLOW_REFINEMENT
+  THR_COMP_NEAR_NEAR_OPTFLOWLA,
+  THR_COMP_NEAR_NEW_OPTFLOWLA,
+  THR_COMP_NEW_NEAR_OPTFLOWLA,
+  THR_COMP_NEW_NEW_OPTFLOWLA,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   THR_COMP_NEW_NEARL2A,
   THR_COMP_NEAR_NEWL2A,
   THR_COMP_NEW_NEWL2A,
   THR_COMP_GLOBAL_GLOBALL2A,
+#if CONFIG_OPTFLOW_REFINEMENT
+  THR_COMP_NEAR_NEAR_OPTFLOWL2A,
+  THR_COMP_NEAR_NEW_OPTFLOWL2A,
+  THR_COMP_NEW_NEAR_OPTFLOWL2A,
+  THR_COMP_NEW_NEW_OPTFLOWL2A,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   THR_COMP_NEW_NEARL3A,
   THR_COMP_NEAR_NEWL3A,
   THR_COMP_NEW_NEWL3A,
   THR_COMP_GLOBAL_GLOBALL3A,
+#if CONFIG_OPTFLOW_REFINEMENT
+  THR_COMP_NEAR_NEAR_OPTFLOWL3A,
+  THR_COMP_NEAR_NEW_OPTFLOWL3A,
+  THR_COMP_NEW_NEAR_OPTFLOWL3A,
+  THR_COMP_NEW_NEW_OPTFLOWL3A,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   THR_COMP_NEW_NEARGA,
   THR_COMP_NEAR_NEWGA,
   THR_COMP_NEW_NEWGA,
   THR_COMP_GLOBAL_GLOBALGA,
+#if CONFIG_OPTFLOW_REFINEMENT
+  THR_COMP_NEAR_NEAR_OPTFLOWGA,
+  THR_COMP_NEAR_NEW_OPTFLOWGA,
+  THR_COMP_NEW_NEAR_OPTFLOWGA,
+  THR_COMP_NEW_NEW_OPTFLOWGA,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   THR_COMP_NEW_NEARLB,
   THR_COMP_NEAR_NEWLB,
   THR_COMP_NEW_NEWLB,
   THR_COMP_GLOBAL_GLOBALLB,
+#if CONFIG_OPTFLOW_REFINEMENT
+  THR_COMP_NEAR_NEAR_OPTFLOWLB,
+  THR_COMP_NEAR_NEW_OPTFLOWLB,
+  THR_COMP_NEW_NEAR_OPTFLOWLB,
+  THR_COMP_NEW_NEW_OPTFLOWLB,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   THR_COMP_NEW_NEARL2B,
   THR_COMP_NEAR_NEWL2B,
   THR_COMP_NEW_NEWL2B,
   THR_COMP_GLOBAL_GLOBALL2B,
+#if CONFIG_OPTFLOW_REFINEMENT
+  THR_COMP_NEAR_NEAR_OPTFLOWL2B,
+  THR_COMP_NEAR_NEW_OPTFLOWL2B,
+  THR_COMP_NEW_NEAR_OPTFLOWL2B,
+  THR_COMP_NEW_NEW_OPTFLOWL2B,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   THR_COMP_NEW_NEARL3B,
   THR_COMP_NEAR_NEWL3B,
   THR_COMP_NEW_NEWL3B,
   THR_COMP_GLOBAL_GLOBALL3B,
+#if CONFIG_OPTFLOW_REFINEMENT
+  THR_COMP_NEAR_NEAR_OPTFLOWL3B,
+  THR_COMP_NEAR_NEW_OPTFLOWL3B,
+  THR_COMP_NEW_NEAR_OPTFLOWL3B,
+  THR_COMP_NEW_NEW_OPTFLOWL3B,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   THR_COMP_NEW_NEARGB,
   THR_COMP_NEAR_NEWGB,
   THR_COMP_NEW_NEWGB,
   THR_COMP_GLOBAL_GLOBALGB,
+#if CONFIG_OPTFLOW_REFINEMENT
+  THR_COMP_NEAR_NEAR_OPTFLOWGB,
+  THR_COMP_NEAR_NEW_OPTFLOWGB,
+  THR_COMP_NEW_NEAR_OPTFLOWGB,
+  THR_COMP_NEW_NEW_OPTFLOWGB,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   THR_COMP_NEW_NEARLA2,
   THR_COMP_NEAR_NEWLA2,
   THR_COMP_NEW_NEWLA2,
   THR_COMP_GLOBAL_GLOBALLA2,
+#if CONFIG_OPTFLOW_REFINEMENT
+  THR_COMP_NEAR_NEAR_OPTFLOWLA2,
+  THR_COMP_NEAR_NEW_OPTFLOWLA2,
+  THR_COMP_NEW_NEAR_OPTFLOWLA2,
+  THR_COMP_NEW_NEW_OPTFLOWLA2,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   THR_COMP_NEW_NEARL2A2,
   THR_COMP_NEAR_NEWL2A2,
   THR_COMP_NEW_NEWL2A2,
   THR_COMP_GLOBAL_GLOBALL2A2,
+#if CONFIG_OPTFLOW_REFINEMENT
+  THR_COMP_NEAR_NEAR_OPTFLOWL2A2,
+  THR_COMP_NEAR_NEW_OPTFLOWL2A2,
+  THR_COMP_NEW_NEAR_OPTFLOWL2A2,
+  THR_COMP_NEW_NEW_OPTFLOWL2A2,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   THR_COMP_NEW_NEARL3A2,
   THR_COMP_NEAR_NEWL3A2,
   THR_COMP_NEW_NEWL3A2,
   THR_COMP_GLOBAL_GLOBALL3A2,
+#if CONFIG_OPTFLOW_REFINEMENT
+  THR_COMP_NEAR_NEAR_OPTFLOWL3A2,
+  THR_COMP_NEAR_NEW_OPTFLOWL3A2,
+  THR_COMP_NEW_NEAR_OPTFLOWL3A2,
+  THR_COMP_NEW_NEW_OPTFLOWL3A2,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   THR_COMP_NEW_NEARGA2,
   THR_COMP_NEAR_NEWGA2,
   THR_COMP_NEW_NEWGA2,
   THR_COMP_GLOBAL_GLOBALGA2,
+#if CONFIG_OPTFLOW_REFINEMENT
+  THR_COMP_NEAR_NEAR_OPTFLOWGA2,
+  THR_COMP_NEAR_NEW_OPTFLOWGA2,
+  THR_COMP_NEW_NEAR_OPTFLOWGA2,
+  THR_COMP_NEW_NEW_OPTFLOWGA2,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   THR_COMP_NEW_NEARLL2,
   THR_COMP_NEAR_NEWLL2,
   THR_COMP_NEW_NEWLL2,
   THR_COMP_GLOBAL_GLOBALLL2,
+#if CONFIG_OPTFLOW_REFINEMENT
+  THR_COMP_NEAR_NEAR_OPTFLOWLL2,
+  THR_COMP_NEAR_NEW_OPTFLOWLL2,
+  THR_COMP_NEW_NEAR_OPTFLOWLL2,
+  THR_COMP_NEW_NEW_OPTFLOWLL2,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   THR_COMP_NEW_NEARLL3,
   THR_COMP_NEAR_NEWLL3,
   THR_COMP_NEW_NEWLL3,
   THR_COMP_GLOBAL_GLOBALLL3,
+#if CONFIG_OPTFLOW_REFINEMENT
+  THR_COMP_NEAR_NEAR_OPTFLOWLL3,
+  THR_COMP_NEAR_NEW_OPTFLOWLL3,
+  THR_COMP_NEW_NEAR_OPTFLOWLL3,
+  THR_COMP_NEW_NEW_OPTFLOWLL3,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   THR_COMP_NEW_NEARLG,
   THR_COMP_NEAR_NEWLG,
   THR_COMP_NEW_NEWLG,
   THR_COMP_GLOBAL_GLOBALLG,
+#if CONFIG_OPTFLOW_REFINEMENT
+  THR_COMP_NEAR_NEAR_OPTFLOWLG,
+  THR_COMP_NEAR_NEW_OPTFLOWLG,
+  THR_COMP_NEW_NEAR_OPTFLOWLG,
+  THR_COMP_NEW_NEW_OPTFLOWLG,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   THR_COMP_NEW_NEARBA,
   THR_COMP_NEAR_NEWBA,
   THR_COMP_NEW_NEWBA,
   THR_COMP_GLOBAL_GLOBALBA,
+#if CONFIG_OPTFLOW_REFINEMENT
+  THR_COMP_NEAR_NEAR_OPTFLOWBA,
+  THR_COMP_NEAR_NEW_OPTFLOWBA,
+  THR_COMP_NEW_NEAR_OPTFLOWBA,
+  THR_COMP_NEW_NEW_OPTFLOWBA,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   THR_DC,
   THR_PAETH,
@@ -394,6 +494,7 @@
 
   MAX_REFS
 } UENUM1BYTE(THR_MODES_SUB8X8);
+#endif  // CONFIG_NEW_REF_SIGNALING
 
 enum {
   FULL_TXFM_RD,
diff --git a/av1/encoder/encode_strategy.c b/av1/encoder/encode_strategy.c
index 8adec1e..5fdfb90 100644
--- a/av1/encoder/encode_strategy.c
+++ b/av1/encoder/encode_strategy.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2019, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <stdint.h>
@@ -41,6 +42,7 @@
 
 #define TEMPORAL_FILTER_KEY_FRAME 1
 
+#if !CONFIG_NEW_REF_SIGNALING
 static INLINE void set_refresh_frame_flags(
     RefreshFrameFlagsInfo *const refresh_frame_flags, bool refresh_gf,
     bool refresh_bwdref, bool refresh_arf) {
@@ -48,6 +50,7 @@
   refresh_frame_flags->bwd_ref_frame = refresh_bwdref;
   refresh_frame_flags->alt_ref_frame = refresh_arf;
 }
+#endif  // !CONFIG_NEW_REF_SIGNALING
 
 // Get the subgop config corresponding to the current frame within the
 // gf group
@@ -61,6 +64,39 @@
   return &subgop_cfg->step[index - offset];
 }
 
+#if CONFIG_NEW_REF_SIGNALING
+// Encoder-only version for the reference mapping
+void av1_get_ref_frames_enc(AV1_COMMON *cm, int cur_frame_disp,
+                            RefFrameMapPair *ref_frame_map_pairs) {
+  assert(cm->seq_params.explicit_ref_frame_map);
+  // With explicit_ref_frame_map on, an encoder-only ranking scheme can be
+  // implemented here. For now, av1_get_ref_frames is used as a placeholder.
+  av1_get_ref_frames(cm, cur_frame_disp, ref_frame_map_pairs);
+}
+
+void av1_configure_buffer_updates(AV1_COMP *const cpi,
+                                  const FRAME_UPDATE_TYPE type) {
+  // NOTE(weitinglin): Should we define another function to take care of
+  // cpi->rc.is_$Source_Type to make this function as it is in the comment?
+
+  cpi->rc.is_src_frame_alt_ref = 0;
+
+  switch (type) {
+    case OVERLAY_UPDATE:
+    case KFFLT_OVERLAY_UPDATE:
+    case INTNL_OVERLAY_UPDATE: cpi->rc.is_src_frame_alt_ref = 1; break;
+
+    case KF_UPDATE:
+    case LF_UPDATE:
+    case GF_UPDATE:
+    case ARF_UPDATE:
+    case KFFLT_UPDATE:
+    case INTNL_ARF_UPDATE: break;
+
+    default: assert(0); break;
+  }
+}
+#else
 void av1_configure_buffer_updates(
     AV1_COMP *const cpi, RefreshFrameFlagsInfo *const refresh_frame_flags,
     const FRAME_UPDATE_TYPE type, const FRAME_TYPE frame_type,
@@ -125,6 +161,7 @@
   if (force_refresh_all)
     set_refresh_frame_flags(refresh_frame_flags, true, true, true);
 }
+#endif  // CONFIG_NEW_REF_SIGNALING
 
 static void set_additional_frame_flags(const AV1_COMMON *const cm,
                                        unsigned int *const frame_flags) {
@@ -146,14 +183,24 @@
   }
 }
 
+#if CONFIG_NEW_REF_SIGNALING && CONFIG_SVC_ENCODER
+static INLINE int is_frame_droppable(const SVC *const svc) {
+  // Droppable frame is only used by external refresh flags. VoD setting won't
+  // trigger its use case.
+  return svc->external_ref_frame_config ? svc->non_reference_frame : 0;
+}
+#elif !CONFIG_NEW_REF_SIGNALING
 static INLINE int is_frame_droppable(
+#if CONFIG_SVC_ENCODER
     const SVC *const svc,
+#endif  // CONFIG_SVC_ENCODER
     const ExtRefreshFrameFlagsInfo *const ext_refresh_frame_flags) {
   // Droppable frame is only used by external refresh flags. VoD setting won't
   // trigger its use case.
-  if (svc->external_ref_frame_config)
-    return svc->non_reference_frame;
-  else if (ext_refresh_frame_flags->update_pending)
+#if CONFIG_SVC_ENCODER
+  if (svc->external_ref_frame_config) return svc->non_reference_frame;
+#endif  // CONFIG_SVC_ENCODER
+  if (ext_refresh_frame_flags->update_pending)
     return !(ext_refresh_frame_flags->alt_ref_frame ||
              ext_refresh_frame_flags->alt2_ref_frame ||
              ext_refresh_frame_flags->bwd_ref_frame ||
@@ -162,14 +209,26 @@
   else
     return 0;
 }
+#endif  // CONFIG_NEW_REF_SIGNALING && CONFIG_SVC_ENCODER
 
 static INLINE void update_frames_till_gf_update(AV1_COMP *cpi) {
   // TODO(weitinglin): Updating this counter for is_frame_droppable
   // is a work-around to handle the condition when a frame is drop.
   // We should fix the cpi->common.show_frame flag
   // instead of checking the other condition to update the counter properly.
-  if (cpi->common.show_frame ||
-      is_frame_droppable(&cpi->svc, &cpi->ext_flags.refresh_frame)) {
+#if CONFIG_NEW_REF_SIGNALING
+  if (cpi->common.show_frame
+#if CONFIG_SVC_ENCODER
+      || is_frame_droppable(&cpi->svc)
+#endif  // CONFIG_SVC_ENCODER
+  ) {
+#else
+  if (cpi->common.show_frame || is_frame_droppable(
+#if CONFIG_SVC_ENCODER
+                                    &cpi->svc,
+#endif  // CONFIG_SVC_ENCODER
+                                    &cpi->ext_flags.refresh_frame)) {
+#endif  // CONFIG_NEW_REF_SIGNALING
     // Decrement count down till next gf
     if (cpi->rc.frames_till_gf_update_due > 0)
       cpi->rc.frames_till_gf_update_due--;
@@ -272,9 +331,15 @@
   // Note(yunqing): In other cases, primary_ref_frame is chosen based on
   // cpi->gf_group.layer_depth[cpi->gf_group.index], which also controls
   // frame bit allocation.
+#if CONFIG_NEW_REF_SIGNALING
+  if (cm->tiles.large_scale) return 0;
+#else
   if (cm->tiles.large_scale) return (LAST_FRAME - LAST_FRAME);
+#endif  // CONFIG_NEW_REF_SIGNALING
 
+#if CONFIG_SVC_ENCODER
   if (cpi->use_svc) return av1_svc_primary_ref_frame(cpi);
+#endif  // CONFIG_SVC_ENCODER
 
   // Find the most recent reference frame with the same reference type as the
   // current frame
@@ -282,11 +347,20 @@
   int wanted_fb = cpi->fb_of_context_type[current_ref_type];
 
   int primary_ref_frame = PRIMARY_REF_NONE;
+#if CONFIG_NEW_REF_SIGNALING
+  const int n_refs = cm->ref_frames_info.n_total_refs;
+  for (int ref_frame = 0; ref_frame < n_refs; ref_frame++) {
+    if (get_ref_frame_map_idx(cm, ref_frame) == wanted_fb) {
+      primary_ref_frame = ref_frame;
+    }
+  }
+#else
   for (int ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ref_frame++) {
     if (get_ref_frame_map_idx(cm, ref_frame) == wanted_fb) {
       primary_ref_frame = ref_frame - LAST_FRAME;
     }
   }
+#endif  // CONFIG_NEW_REF_SIGNALING
 
   return primary_ref_frame;
 }
@@ -307,6 +381,16 @@
   // No references specified
   if (step_gop_cfg->num_references < 0) return;
 
+#if CONFIG_NEW_REF_SIGNALING
+  // Mask to indicate whether or not each ref is allowed by the GOP config
+  int ref_frame_used[INTER_REFS_PER_FRAME] = { 0 };
+  // Structures to hash each reference frame based on its pyramid level. This
+  // will allow us to match the pyramid levels specified in the cfg to the best
+  // reference frame index.
+  int n_references[MAX_ARF_LAYERS + 1] = { 0 };
+  int references[MAX_ARF_LAYERS + 1][INTER_REFS_PER_FRAME] = { { 0 } };
+  int disp_orders[MAX_ARF_LAYERS + 1][INTER_REFS_PER_FRAME] = { { 0 } };
+#else
   // Mask to indicate whether or not each ref is allowed by the GOP config
   int ref_frame_used[REF_FRAMES] = { 0 };
   // Structures to hash each reference frame based on its pyramid level. This
@@ -315,10 +399,15 @@
   int n_references[MAX_ARF_LAYERS + 1] = { 0 };
   int references[MAX_ARF_LAYERS + 1][REF_FRAMES] = { { 0 } };
   int disp_orders[MAX_ARF_LAYERS + 1][REF_FRAMES] = { { 0 } };
+#endif  // CONFIG_NEW_REF_SIGNALING
 
   int frame_level = -1;
   // Loop over each reference frame and hash it based on its pyramid level
+#if CONFIG_NEW_REF_SIGNALING
+  for (int frame = 0; frame < INTER_REFS_PER_FRAME; frame++) {
+#else
   for (int frame = LAST_FRAME; frame <= ALTREF_FRAME; frame++) {
+#endif  // CONFIG_NEW_REF_SIGNALING
     // Get reference frame buffer
     const RefCntBuffer *const buf = get_ref_frame_buf(&cpi->common, frame);
     if (buf == NULL) continue;
@@ -384,10 +473,14 @@
   }
 
   // Avoid using references that were not specified by the cfg
-  for (int frame = LAST_FRAME; frame <= ALTREF_FRAME; frame++) {
+#if CONFIG_NEW_REF_SIGNALING
+  for (int frame = 0; frame < INTER_REFS_PER_FRAME; frame++)
+    if (!ref_frame_used[frame]) *ref_frame_flags &= ~(1 << (frame));
+#else
+  for (int frame = LAST_FRAME; frame <= ALTREF_FRAME; frame++)
     if (!ref_frame_used[frame])
       *ref_frame_flags &= ~(1 << (frame - LAST_FRAME));
-  }
+#endif  // CONFIG_NEW_REF_SIGNALING
 }
 
 static void update_fb_of_context_type(
@@ -397,14 +490,24 @@
   const int current_frame_ref_type =
       get_current_frame_ref_type(cpi, frame_params);
 
+#if CONFIG_NEW_REF_SIGNALING
+  const int golden_frame = cm->ref_frames_info.past_refs[0];
+  const int altref_frame = get_furthest_future_ref_index(cm);
+#endif  // CONFIG_NEW_REF_SIGNALING
   if (frame_is_intra_only(cm) || cm->features.error_resilient_mode ||
       cpi->ext_flags.use_primary_ref_none) {
     for (int i = 0; i < REF_FRAMES; i++) {
       fb_of_context_type[i] = -1;
     }
+#if CONFIG_NEW_REF_SIGNALING
+    fb_of_context_type[current_frame_ref_type] =
+        cm->show_frame ? get_ref_frame_map_idx(cm, golden_frame)
+                       : get_ref_frame_map_idx(cm, altref_frame);
+#else
     fb_of_context_type[current_frame_ref_type] =
         cm->show_frame ? get_ref_frame_map_idx(cm, GOLDEN_FRAME)
                        : get_ref_frame_map_idx(cm, ALTREF_FRAME);
+#endif  // CONFIG_NEW_REF_SIGNALING
   }
 
   if (!encode_show_existing_frame(cm)) {
@@ -434,11 +537,13 @@
   // Clear down mmx registers
   aom_clear_system_state();
 
+#if CONFIG_SVC_ENCODER
   if (cpi->use_svc && cpi->svc.spatial_layer_id > 0) {
     cpi->framerate = cpi->svc.base_framerate;
     av1_rc_update_framerate(cpi, cpi->common.width, cpi->common.height);
     return;
   }
+#endif  // CONFIG_SVC_ENCODER
 
   if (ts_start == time_stamps->first_ever) {
     this_duration = ts_end - ts_start;
@@ -580,6 +685,7 @@
   return !(is_error_resilient || is_s_frame) || is_key_frame;
 }
 
+#if !CONFIG_NEW_REF_SIGNALING
 // Update frame_flags to tell the encoder's caller what sort of frame was
 // encoded.
 static void update_frame_flags(
@@ -618,6 +724,7 @@
     *frame_flags &= ~FRAMEFLAGS_KEY;
   }
 }
+#endif  // !CONFIG_NEW_REF_SIGNALING
 
 #define DUMP_REF_FRAME_IMAGES 0
 
@@ -781,11 +888,9 @@
     const AV1_COMP *const cpi, const EncodeFrameParams *const frame_params,
     FRAME_UPDATE_TYPE frame_update_type, int gf_index, int cur_disp_order,
     RefFrameMapPair ref_frame_map_pairs[REF_FRAMES]) {
-  const AV1_COMMON *const cm = &cpi->common;
-  const ExtRefreshFrameFlagsInfo *const ext_refresh_frame_flags =
-      &cpi->ext_flags.refresh_frame;
-
+#if CONFIG_SVC_ENCODER
   const SVC *const svc = &cpi->svc;
+#endif  // CONFIG_SVC_ENCODER
   // Switch frames and shown key-frames overwrite all reference slots
   if ((frame_params->frame_type == KEY_FRAME && !cpi->no_show_fwd_kf) ||
       frame_params->frame_type == S_FRAME)
@@ -799,11 +904,22 @@
     return 0;
   }
 
-  if (is_frame_droppable(svc, ext_refresh_frame_flags)) return 0;
-
   int refresh_mask = 0;
+#if CONFIG_NEW_REF_SIGNALING && CONFIG_SVC_ENCODER
+  if (is_frame_droppable(svc)) return 0;
+#elif !CONFIG_NEW_REF_SIGNALING
+  const AV1_COMMON *const cm = &cpi->common;
+  const ExtRefreshFrameFlagsInfo *const ext_refresh_frame_flags =
+      &cpi->ext_flags.refresh_frame;
+
+#if CONFIG_SVC_ENCODER
+  if (is_frame_droppable(svc, ext_refresh_frame_flags)) return 0;
+#else
+  if (is_frame_droppable(ext_refresh_frame_flags)) return 0;
+#endif  // CONFIG_SVC_ENCODER
 
   if (ext_refresh_frame_flags->update_pending) {
+#if CONFIG_SVC_ENCODER
     if (svc->external_ref_frame_config) {
       for (unsigned int i = 0; i < INTER_REFS_PER_FRAME; i++) {
         int ref_frame_map_idx = svc->ref_idx[i];
@@ -811,6 +927,7 @@
       }
       return refresh_mask;
     }
+#endif  // CONFIG_SVC_ENCODER
     // Unfortunately the encoder interface reflects the old refresh_*_frame
     // flags so we have to replicate the old refresh_frame_flags logic here in
     // order to preserve the behaviour of the flag overrides.
@@ -847,6 +964,7 @@
     }
     return refresh_mask;
   }
+#endif  // CONFIG_NEW_REF_SIGNALING && CONFIG_SVC_ENCODER
 
   // Search for the open slot to store the current frame.
   int free_fb_index = get_free_ref_map_index(ref_frame_map_pairs);
@@ -1023,243 +1141,6 @@
   return AOM_CODEC_OK;
 }
 
-/*!\cond */
-// Struct to keep track of relevant reference frame data
-typedef struct {
-  int map_idx;
-  int disp_order;
-  int pyr_level;
-  int used;
-} RefBufMapData;
-/*!\endcond */
-
-// Comparison function to sort reference frames in ascending display order
-static int compare_map_idx_pair_asc(const void *a, const void *b) {
-  if (((RefBufMapData *)a)->disp_order == ((RefBufMapData *)b)->disp_order) {
-    return 0;
-  } else if (((const RefBufMapData *)a)->disp_order >
-             ((const RefBufMapData *)b)->disp_order) {
-    return 1;
-  } else {
-    return -1;
-  }
-}
-
-// Checks to see if a particular reference frame is already in the reference
-// frame map
-static int is_in_ref_map(RefBufMapData *map, int disp_order, int n_frames) {
-  for (int i = 0; i < n_frames; i++) {
-    if (disp_order == map[i].disp_order) return 1;
-  }
-  return 0;
-}
-
-// Add a reference buffer index to a named reference slot
-static void add_ref_to_slot(RefBufMapData *ref, int *const remapped_ref_idx,
-                            int frame) {
-  remapped_ref_idx[frame - LAST_FRAME] = ref->map_idx;
-  ref->used = 1;
-}
-
-// Threshold dictating when we are allowed to start considering
-// leaving lowest level frames unmapped
-#define LOW_LEVEL_FRAMES_TR 5
-
-// Find which reference buffer should be left out of the named mapping.
-// This is because there are 8 reference buffers and only 7 named slots.
-static void set_unmapped_ref(RefBufMapData *buffer_map, int n_bufs,
-                             int n_min_level_refs, int min_level,
-                             int cur_frame_disp) {
-  int max_dist = 0;
-  int unmapped_idx = -1;
-  if (n_bufs <= ALTREF_FRAME) return;
-  for (int i = 0; i < n_bufs; i++) {
-    if (buffer_map[i].used) continue;
-    if (buffer_map[i].pyr_level != min_level ||
-        n_min_level_refs >= LOW_LEVEL_FRAMES_TR) {
-      int dist = abs(cur_frame_disp - buffer_map[i].disp_order);
-      if (dist > max_dist) {
-        max_dist = dist;
-        unmapped_idx = i;
-      }
-    }
-  }
-  assert(unmapped_idx >= 0 && "Unmapped reference not found");
-  buffer_map[unmapped_idx].used = 1;
-}
-
-void av1_get_ref_frames(AV1_COMP *const cpi, int cur_frame_disp,
-                        RefFrameMapPair ref_frame_map_pairs[REF_FRAMES]) {
-  AV1_COMMON *cm = &cpi->common;
-  int *const remapped_ref_idx = cm->remapped_ref_idx;
-
-  int buf_map_idx = 0;
-
-  // Initialize reference frame mappings
-  for (int i = 0; i < REF_FRAMES; ++i) remapped_ref_idx[i] = INVALID_IDX;
-
-  RefBufMapData buffer_map[REF_FRAMES];
-  int n_bufs = 0;
-  memset(buffer_map, 0, REF_FRAMES * sizeof(buffer_map[0]));
-  int min_level = MAX_ARF_LAYERS;
-  int max_level = 0;
-
-  // Go through current reference buffers and store display order, pyr level,
-  // and map index.
-  for (int map_idx = 0; map_idx < REF_FRAMES; map_idx++) {
-    // Get reference frame buffer
-    RefFrameMapPair ref_pair = ref_frame_map_pairs[map_idx];
-    if (ref_pair.disp_order == -1) continue;
-    const int frame_order = ref_pair.disp_order;
-    // Avoid duplicates
-    if (is_in_ref_map(buffer_map, frame_order, n_bufs)) continue;
-    const int reference_frame_level = ref_pair.pyr_level;
-
-    // Keep track of the lowest and highest levels that currently exist
-    if (reference_frame_level < min_level) min_level = reference_frame_level;
-    if (reference_frame_level > max_level) max_level = reference_frame_level;
-
-    buffer_map[n_bufs].map_idx = map_idx;
-    buffer_map[n_bufs].disp_order = frame_order;
-    buffer_map[n_bufs].pyr_level = reference_frame_level;
-    buffer_map[n_bufs].used = 0;
-    n_bufs++;
-  }
-
-  // Sort frames in ascending display order
-  qsort(buffer_map, n_bufs, sizeof(buffer_map[0]), compare_map_idx_pair_asc);
-
-  int n_min_level_refs = 0;
-  int n_past_high_level = 0;
-  int closest_past_ref = -1;
-  int golden_idx = -1;
-  int altref_idx = -1;
-
-  // Find the GOLDEN_FRAME and BWDREF_FRAME.
-  // Also collect various stats about the reference frames for the remaining
-  // mappings
-  for (int i = n_bufs - 1; i >= 0; i--) {
-    if (buffer_map[i].pyr_level == min_level) {
-      // Keep track of the number of lowest level frames
-      n_min_level_refs++;
-      if (buffer_map[i].disp_order < cur_frame_disp && golden_idx == -1 &&
-          remapped_ref_idx[GOLDEN_FRAME - LAST_FRAME] == INVALID_IDX) {
-        // Save index for GOLDEN
-        golden_idx = i;
-      } else if (buffer_map[i].disp_order > cur_frame_disp &&
-                 altref_idx == -1 &&
-                 remapped_ref_idx[ALTREF_FRAME - LAST_FRAME] == INVALID_IDX) {
-        // Save index for ALTREF
-        altref_idx = i;
-      }
-    } else if (buffer_map[i].disp_order == cur_frame_disp) {
-      // Map the BWDREF_FRAME if this is the show_existing_frame
-      add_ref_to_slot(&buffer_map[i], remapped_ref_idx, BWDREF_FRAME);
-    }
-
-    // Keep track of the number of past frames that are not at the lowest level
-    if (buffer_map[i].disp_order < cur_frame_disp &&
-        buffer_map[i].pyr_level != min_level)
-      n_past_high_level++;
-
-    // Keep track of where the frames change from being past frames to future
-    // frames
-    if (buffer_map[i].disp_order < cur_frame_disp && closest_past_ref < 0)
-      closest_past_ref = i;
-  }
-
-  // Do not map GOLDEN and ALTREF based on their pyramid level if all reference
-  // frames have the same level
-  if (n_min_level_refs <= n_bufs) {
-    // Map the GOLDEN_FRAME
-    if (golden_idx > -1)
-      add_ref_to_slot(&buffer_map[golden_idx], remapped_ref_idx, GOLDEN_FRAME);
-    // Map the ALTREF_FRAME
-    if (altref_idx > -1)
-      add_ref_to_slot(&buffer_map[altref_idx], remapped_ref_idx, ALTREF_FRAME);
-  }
-
-  // Find the buffer to be excluded from the mapping
-  set_unmapped_ref(buffer_map, n_bufs, n_min_level_refs, min_level,
-                   cur_frame_disp);
-
-  // Place past frames in LAST_FRAME, LAST2_FRAME, and LAST3_FRAME
-  for (int frame = LAST_FRAME; frame < GOLDEN_FRAME; frame++) {
-    // Continue if the current ref slot is already full
-    if (remapped_ref_idx[frame - LAST_FRAME] != INVALID_IDX) continue;
-    // Find the next unmapped reference buffer
-    // in decreasing ouptut oreder relative to current picture
-    int next_buf_max = 0;
-    int next_disp_order = INT_MIN;
-    for (buf_map_idx = n_bufs - 1; buf_map_idx >= 0; buf_map_idx--) {
-      if (!buffer_map[buf_map_idx].used &&
-          buffer_map[buf_map_idx].disp_order < cur_frame_disp &&
-          buffer_map[buf_map_idx].disp_order > next_disp_order) {
-        next_disp_order = buffer_map[buf_map_idx].disp_order;
-        next_buf_max = buf_map_idx;
-      }
-    }
-    buf_map_idx = next_buf_max;
-    if (buf_map_idx < 0) break;
-    if (buffer_map[buf_map_idx].used) break;
-    add_ref_to_slot(&buffer_map[buf_map_idx], remapped_ref_idx, frame);
-  }
-
-  // Place future frames (if there are any) in BWDREF_FRAME and ALTREF2_FRAME
-  for (int frame = BWDREF_FRAME; frame < REF_FRAMES; frame++) {
-    // Continue if the current ref slot is already full
-    if (remapped_ref_idx[frame - LAST_FRAME] != INVALID_IDX) continue;
-    // Find the next unmapped reference buffer
-    // in increasing ouptut oreder relative to current picture
-    int next_buf_max = 0;
-    int next_disp_order = INT_MAX;
-    for (buf_map_idx = n_bufs - 1; buf_map_idx >= 0; buf_map_idx--) {
-      if (!buffer_map[buf_map_idx].used &&
-          buffer_map[buf_map_idx].disp_order > cur_frame_disp &&
-          buffer_map[buf_map_idx].disp_order < next_disp_order) {
-        next_disp_order = buffer_map[buf_map_idx].disp_order;
-        next_buf_max = buf_map_idx;
-      }
-    }
-    buf_map_idx = next_buf_max;
-    if (buf_map_idx < 0) break;
-    if (buffer_map[buf_map_idx].used) break;
-    add_ref_to_slot(&buffer_map[buf_map_idx], remapped_ref_idx, frame);
-  }
-
-  // Place remaining past frames
-  buf_map_idx = closest_past_ref;
-  for (int frame = LAST_FRAME; frame < REF_FRAMES; frame++) {
-    // Continue if the current ref slot is already full
-    if (remapped_ref_idx[frame - LAST_FRAME] != INVALID_IDX) continue;
-    // Find the next unmapped reference buffer
-    for (; buf_map_idx >= 0; buf_map_idx--) {
-      if (!buffer_map[buf_map_idx].used) break;
-    }
-    if (buf_map_idx < 0) break;
-    if (buffer_map[buf_map_idx].used) break;
-    add_ref_to_slot(&buffer_map[buf_map_idx], remapped_ref_idx, frame);
-  }
-
-  // Place remaining future frames
-  buf_map_idx = n_bufs - 1;
-  for (int frame = ALTREF_FRAME; frame >= LAST_FRAME; frame--) {
-    // Continue if the current ref slot is already full
-    if (remapped_ref_idx[frame - LAST_FRAME] != INVALID_IDX) continue;
-    // Find the next unmapped reference buffer
-    for (; buf_map_idx > closest_past_ref; buf_map_idx--) {
-      if (!buffer_map[buf_map_idx].used) break;
-    }
-    if (buf_map_idx < 0) break;
-    if (buffer_map[buf_map_idx].used) break;
-    add_ref_to_slot(&buffer_map[buf_map_idx], remapped_ref_idx, frame);
-  }
-
-  // Fill any slots that are empty (should only happen for the first 7 frames)
-  for (int i = 0; i < REF_FRAMES; ++i)
-    if (remapped_ref_idx[i] == INVALID_IDX) remapped_ref_idx[i] = 0;
-}
-
 int av1_encode_strategy(AV1_COMP *const cpi, size_t *const size,
                         uint8_t *const dest, unsigned int *frame_flags,
                         int64_t *const time_stamp, int64_t *const time_end,
@@ -1431,33 +1312,55 @@
        frame_params.frame_type == S_FRAME) &&
       !frame_params.show_existing_frame;
 
+#if CONFIG_NEW_REF_SIGNALING
+  (void)force_refresh_all;
+  av1_configure_buffer_updates(cpi, frame_update_type);
+#else
   av1_configure_buffer_updates(cpi, &frame_params.refresh_frame,
                                frame_update_type, frame_params.frame_type,
                                force_refresh_all);
+#endif  // CONFIG_NEW_REF_SIGNALING
 
+  const int order_offset = gf_group->arf_src_offset[gf_group->index];
+  const int cur_frame_disp =
+      cpi->common.current_frame.frame_number + order_offset;
   RefFrameMapPair ref_frame_map_pairs[REF_FRAMES];
-  init_ref_map_pair(cpi, ref_frame_map_pairs);
+  init_ref_map_pair(&cpi->common, ref_frame_map_pairs,
+                    gf_group->update_type[gf_group->index] == KF_UPDATE);
 
   if (!is_stat_generation_stage(cpi)) {
-    const RefCntBuffer *ref_frames[INTER_REFS_PER_FRAME];
-    const YV12_BUFFER_CONFIG *ref_frame_buf[INTER_REFS_PER_FRAME];
-
     if (!ext_flags->refresh_frame.update_pending) {
-      const int order_offset = gf_group->arf_src_offset[gf_group->index];
-      const int cur_frame_disp =
-          cpi->common.current_frame.frame_number + order_offset;
-      av1_get_ref_frames(cpi, cur_frame_disp, ref_frame_map_pairs);
+#if !CONFIG_NEW_REF_SIGNALING
+      av1_get_ref_frames(cm, cur_frame_disp, ref_frame_map_pairs);
+#endif  // !CONFIG_NEW_REF_SIGNALING
+#if CONFIG_SVC_ENCODER
     } else if (cpi->svc.external_ref_frame_config) {
       for (unsigned int i = 0; i < INTER_REFS_PER_FRAME; i++)
         cm->remapped_ref_idx[i] = cpi->svc.ref_idx[i];
+#endif  // CONFIG_SVC_ENCODER
     }
 
+#if CONFIG_NEW_REF_SIGNALING
+    if (cm->seq_params.explicit_ref_frame_map)
+      av1_get_ref_frames_enc(cm, cur_frame_disp, ref_frame_map_pairs);
+    else
+      av1_get_ref_frames(cm, cur_frame_disp, ref_frame_map_pairs);
+#else
+    const RefCntBuffer *ref_frames[INTER_REFS_PER_FRAME];
+    const YV12_BUFFER_CONFIG *ref_frame_buf[INTER_REFS_PER_FRAME];
     // Get the reference frames
     for (int i = 0; i < INTER_REFS_PER_FRAME; ++i) {
       ref_frames[i] = get_ref_frame_buf(cm, ref_frame_priority_order[i]);
       ref_frame_buf[i] = ref_frames[i] != NULL ? &ref_frames[i]->buf : NULL;
     }
+#endif  // CONFIG_NEW_REF_SIGNALING
 
+#if CONFIG_NEW_REF_SIGNALING
+    // TODO(sarahparker) Initialize this using a nrs version of
+    // ext_flags->ref_frame_flags. See aomedia:3110.
+    frame_params.ref_frame_flags =
+        (1 << cpi->common.ref_frames_info.n_total_refs) - 1;
+#else
     // Work out which reference frame slots may be used.
     if (av1_check_keyframe_overlay(gf_group->index, gf_group,
                                    cpi->rc.frames_since_key)) {
@@ -1469,6 +1372,7 @@
       frame_params.ref_frame_flags =
           get_ref_frame_flags(ref_frame_buf, ext_flags->ref_frame_flags);
     }
+#endif  // CONFIG_NEW_REF_SIGNALING
 
     frame_params.primary_ref_frame =
         choose_primary_ref_frame(cpi, &frame_params);
@@ -1481,9 +1385,6 @@
                                frame_params.order_offset);
     }
 
-    const int cur_frame_disp =
-        cpi->common.current_frame.frame_number + frame_params.order_offset;
-
     frame_params.refresh_frame_flags = av1_get_refresh_frame_flags(
         cpi, &frame_params, frame_update_type, cpi->gf_group.index,
         cur_frame_disp, ref_frame_map_pairs);
@@ -1522,11 +1423,13 @@
     return AOM_CODEC_ERROR;
   }
 
+#if !CONFIG_NEW_REF_SIGNALING
   if (!is_stat_generation_stage(cpi)) {
     // First pass doesn't modify reference buffer assignment or produce frame
     // flags
     update_frame_flags(&cpi->common, &cpi->refresh_frame, frame_flags);
   }
+#endif  // !CONFIG_NEW_REF_SIGNALING
 
   if (!is_stat_generation_stage(cpi)) {
 #if TXCOEFF_COST_TIMER
@@ -1559,10 +1462,20 @@
 
   // Leave a signal for a higher level caller about if this frame is droppable
   if (*size > 0) {
+#if CONFIG_NEW_REF_SIGNALING && CONFIG_SVC_ENCODER
+    cpi->droppable = is_frame_droppable(&cpi->svc);
+#elif CONFIG_NEW_REF_SIGNALING && !CONFIG_SVC_ENCODER
+    cpi->droppable = 0;
+#elif !CONFIG_NEW_REF_SIGNALING && CONFIG_SVC_ENCODER
     cpi->droppable = is_frame_droppable(&cpi->svc, &ext_flags->refresh_frame);
+#else
+    cpi->droppable = is_frame_droppable(&ext_flags->refresh_frame);
+#endif  // CONFIG_NEW_REF_SIGNALING
   }
 
+#if CONFIG_SVC_ENCODER
   if (cpi->use_svc) av1_save_layer_context(cpi);
+#endif  // CONFIG_SVC_ENCODER
 
   return AOM_CODEC_OK;
 }
diff --git a/av1/encoder/encode_strategy.h b/av1/encoder/encode_strategy.h
index 00c2d39..2a54572 100644
--- a/av1/encoder/encode_strategy.h
+++ b/av1/encoder/encode_strategy.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2019, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 /*!\file
@@ -61,10 +62,17 @@
 // Set individual buffer update flags based on frame reference type.
 // force_refresh_all is used when we have a KEY_FRAME or S_FRAME.  It forces all
 // refresh_*_frame flags to be set, because we refresh all buffers in this case.
+#if CONFIG_NEW_REF_SIGNALING
+void av1_get_ref_frames_enc(AV1_COMMON *cm, int cur_frame_disp,
+                            RefFrameMapPair *ref_frame_map_paris);
+void av1_configure_buffer_updates(AV1_COMP *const cpi,
+                                  const FRAME_UPDATE_TYPE type);
+#else
 void av1_configure_buffer_updates(
     AV1_COMP *const cpi, RefreshFrameFlagsInfo *const refresh_frame_flags,
     const FRAME_UPDATE_TYPE type, const FRAME_TYPE frame_type,
     int force_refresh_all);
+#endif  // CONFIG_NEW_REF_SIGNALING
 
 int av1_get_refresh_frame_flags(
     const AV1_COMP *const cpi, const EncodeFrameParams *const frame_params,
@@ -73,9 +81,6 @@
 
 int av1_get_refresh_ref_frame_map(int refresh_frame_flags);
 
-void av1_get_ref_frames(AV1_COMP *const cpi, int cur_frame_disp,
-                        RefFrameMapPair ref_frame_map_pairs[REF_FRAMES]);
-
 int get_forced_keyframe_position(struct lookahead_ctx *lookahead,
                                  const int up_to_index,
                                  const COMPRESSOR_STAGE compressor_stage);
diff --git a/av1/encoder/encodeframe.c b/av1/encoder/encodeframe.c
index 0592a0b..e338fd9 100644
--- a/av1/encoder/encodeframe.c
+++ b/av1/encoder/encodeframe.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <limits.h>
@@ -173,7 +174,12 @@
   unsigned int sse, var;
   uint8_t *last_y;
   const YV12_BUFFER_CONFIG *last =
+#if CONFIG_NEW_REF_SIGNALING
+      get_ref_frame_yv12_buf(&cpi->common,
+                             get_closest_pastcur_ref_index(&cpi->common));
+#else
       get_ref_frame_yv12_buf(&cpi->common, LAST_FRAME);
+#endif  // CONFIG_NEW_REF_SIGNALING
 
   assert(last != NULL);
   last_y =
@@ -378,10 +384,17 @@
           best_rf_idx = idx;
         }
       }
+#if CONFIG_NEW_REF_SIGNALING
+      // tpl_pred_error is the pred_error reduction of best_ref w.r.t.
+      // rank 0 frame.
+      tpl_pred_error[best_rf_idx] =
+          this_stats->pred_error[best_rf_idx] - this_stats->pred_error[0];
+#else
       // tpl_pred_error is the pred_error reduction of best_ref w.r.t.
       // LAST_FRAME.
       tpl_pred_error[best_rf_idx] = this_stats->pred_error[best_rf_idx] -
                                     this_stats->pred_error[LAST_FRAME - 1];
+#endif  // CONFIG_NEW_REF_SIGNALING
 
       for (int rf_idx = 1; rf_idx < INTER_REFS_PER_FRAME; ++rf_idx)
         inter_cost[rf_idx] += tpl_pred_error[rf_idx];
@@ -400,12 +413,21 @@
     }
   }
 
+#if CONFIG_NEW_REF_SIGNALING
+  x->tpl_keep_ref_frame[INTRA_FRAME_INDEX_NRS] = 1;
+  x->tpl_keep_ref_frame[0] = 1;
+#else
   x->tpl_keep_ref_frame[INTRA_FRAME] = 1;
   x->tpl_keep_ref_frame[LAST_FRAME] = 1;
+#endif  // CONFIG_NEW_REF_SIGNALING
 
   int cutoff_ref = 0;
   for (int idx = 0; idx < INTER_REFS_PER_FRAME - 1; ++idx) {
+#if CONFIG_NEW_REF_SIGNALING
+    x->tpl_keep_ref_frame[rank_index[idx]] = 1;
+#else
     x->tpl_keep_ref_frame[rank_index[idx] + LAST_FRAME] = 1;
+#endif  // CONFIG_NEW_REF_SIGNALING
     if (idx > 2) {
       if (!cutoff_ref) {
         // If the predictive coding gains are smaller than the previous more
@@ -417,7 +439,11 @@
           cutoff_ref = 1;
       }
 
+#if CONFIG_NEW_REF_SIGNALING
+      if (cutoff_ref) x->tpl_keep_ref_frame[rank_index[idx]] = 0;
+#else
       if (cutoff_ref) x->tpl_keep_ref_frame[rank_index[idx] + LAST_FRAME] = 0;
+#endif  // CONFIG_NEW_REF_SIGNALING
     }
   }
 }
@@ -739,6 +765,10 @@
     x->source_variance = UINT_MAX;
     td->mb.cb_coef_buff = av1_get_cb_coeff_buffer(cpi, mi_row, mi_col);
 
+#if CONFIG_REF_MV_BANK
+    xd->ref_mv_bank.rmb_sb_hits = 0;
+#endif  // CONFIG_REF_MV_BANK
+
     // Get segment id and skip flag
     const struct segmentation *const seg = &cm->seg;
     int seg_skip = 0;
@@ -898,6 +928,11 @@
   av1_crc32c_calculator_init(
       &td->mb.txfm_search_info.mb_rd_record.crc_calculator);
 
+#if CONFIG_REF_MV_BANK
+  av1_zero(td->mb.e_mbd.ref_mv_bank);
+  td->mb.e_mbd.ref_mv_bank_pt = &td->mb.e_mbd.ref_mv_bank;
+#endif  // CONFIG_REF_MV_BANK
+
   for (int mi_row = tile_info->mi_row_start; mi_row < tile_info->mi_row_end;
        mi_row += cm->seq_params.mib_size) {
     av1_encode_sb_row(cpi, td, tile_row, tile_col, mi_row);
@@ -943,6 +978,17 @@
     const int ref_frame_flags) {
   MV_REFERENCE_FRAME ref_frame;
   int min_past_dist = INT32_MAX, min_future_dist = INT32_MAX;
+#if CONFIG_NEW_REF_SIGNALING
+  ref_frame_dist_info->nearest_past_ref = INVALID_IDX;
+  ref_frame_dist_info->nearest_future_ref = INVALID_IDX;
+  for (ref_frame = 0; ref_frame < INTER_REFS_PER_FRAME; ++ref_frame) {
+    ref_frame_dist_info->ref_relative_dist[ref_frame] = 0;
+    if (ref_frame_flags & (1 << ref_frame)) {
+      int dist = av1_encoder_get_relative_dist(
+          cm->cur_frame->ref_display_order_hint[ref_frame],
+          cm->current_frame.display_order_hint);
+      ref_frame_dist_info->ref_relative_dist[ref_frame] = dist;
+#else
   ref_frame_dist_info->nearest_past_ref = NONE_FRAME;
   ref_frame_dist_info->nearest_future_ref = NONE_FRAME;
   for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
@@ -952,6 +998,7 @@
           cm->cur_frame->ref_display_order_hint[ref_frame - LAST_FRAME],
           cm->current_frame.display_order_hint);
       ref_frame_dist_info->ref_relative_dist[ref_frame - LAST_FRAME] = dist;
+#endif  // CONFIG_NEW_REF_SIGNALING
       // Get the nearest ref_frame in the past
       if (abs(dist) < min_past_dist && dist < 0) {
         ref_frame_dist_info->nearest_past_ref = ref_frame;
@@ -969,6 +1016,11 @@
 static INLINE int refs_are_one_sided(const AV1_COMMON *cm) {
   assert(!frame_is_intra_only(cm));
 
+#if CONFIG_NEW_REF_SIGNALING
+  return (cm->ref_frames_info.n_past_refs == 0 &&
+          cm->ref_frames_info.n_cur_refs == 0) ||
+         cm->ref_frames_info.n_future_refs == 0;
+#else
   int one_sided_refs = 1;
   const int cur_display_order_hint = cm->current_frame.display_order_hint;
   for (int ref = LAST_FRAME; ref <= ALTREF_FRAME; ++ref) {
@@ -981,6 +1033,7 @@
     }
   }
   return one_sided_refs;
+#endif  // CONFIG_NEW_REF_SIGNALING
 }
 
 static INLINE void get_skip_mode_ref_offsets(const AV1_COMMON *cm,
@@ -989,10 +1042,17 @@
   ref_order_hint[0] = ref_order_hint[1] = 0;
   if (!skip_mode_info->skip_mode_allowed) return;
 
+#if CONFIG_NEW_REF_SIGNALING
+  const RefCntBuffer *const buf_0 =
+      get_ref_frame_buf(cm, skip_mode_info->ref_frame_idx_0);
+  const RefCntBuffer *const buf_1 =
+      get_ref_frame_buf(cm, skip_mode_info->ref_frame_idx_1);
+#else
   const RefCntBuffer *const buf_0 =
       get_ref_frame_buf(cm, LAST_FRAME + skip_mode_info->ref_frame_idx_0);
   const RefCntBuffer *const buf_1 =
       get_ref_frame_buf(cm, LAST_FRAME + skip_mode_info->ref_frame_idx_1);
+#endif  // CONFIG_NEW_REF_SIGNALING
   assert(buf_0 != NULL && buf_1 != NULL);
 
   ref_order_hint[0] = buf_0->order_hint;
@@ -1019,6 +1079,13 @@
   // High Latency: Turn off skip mode if all refs are fwd.
   if (cpi->all_one_sided_refs && cpi->oxcf.gf_cfg.lag_in_frames > 0) return 0;
 
+#if CONFIG_NEW_REF_SIGNALING
+  const int ref_frame[2] = { cm->current_frame.skip_mode_info.ref_frame_idx_0,
+                             cm->current_frame.skip_mode_info.ref_frame_idx_1 };
+  if (!(cpi->common.ref_frame_flags & (1 << ref_frame[0])) ||
+      !(cpi->common.ref_frame_flags & (1 << ref_frame[1])))
+    return 0;
+#else
   static const int flag_list[REF_FRAMES] = { 0,
                                              AOM_LAST_FLAG,
                                              AOM_LAST2_FLAG,
@@ -1031,9 +1098,10 @@
     cm->current_frame.skip_mode_info.ref_frame_idx_0 + LAST_FRAME,
     cm->current_frame.skip_mode_info.ref_frame_idx_1 + LAST_FRAME
   };
-  if (!(cpi->ref_frame_flags & flag_list[ref_frame[0]]) ||
-      !(cpi->ref_frame_flags & flag_list[ref_frame[1]]))
+  if (!(cm->ref_frame_flags & flag_list[ref_frame[0]]) ||
+      !(cm->ref_frame_flags & flag_list[ref_frame[1]]))
     return 0;
+#endif  // CONFIG_NEW_REF_SIGNALING
 
   return 1;
 }
@@ -1046,6 +1114,7 @@
                         : INTERP_SKIP_LUMA_SKIP_CHROMA;
 }
 
+#if !CONFIG_NEW_REF_SIGNALING
 static AOM_INLINE void setup_prune_ref_frame_mask(AV1_COMP *cpi) {
   if ((!cpi->oxcf.ref_frm_cfg.enable_onesided_comp ||
        cpi->sf.inter_sf.disable_onesided_comp) &&
@@ -1068,8 +1137,8 @@
     for (int ref_idx = REF_FRAMES; ref_idx < MODE_CTX_REF_FRAMES; ++ref_idx) {
       MV_REFERENCE_FRAME rf[2];
       av1_set_ref_frame(rf, ref_idx);
-      if (!(cpi->ref_frame_flags & av1_ref_frame_flag_list[rf[0]]) ||
-          !(cpi->ref_frame_flags & av1_ref_frame_flag_list[rf[1]])) {
+      if (!(cm->ref_frame_flags & av1_ref_frame_flag_list[rf[0]]) ||
+          !(cm->ref_frame_flags & av1_ref_frame_flag_list[rf[1]])) {
         continue;
       }
 
@@ -1090,7 +1159,7 @@
 
       if (cpi->sf.inter_sf.selective_ref_frame >= 4 &&
           (rf[0] == ALTREF2_FRAME || rf[1] == ALTREF2_FRAME) &&
-          (cpi->ref_frame_flags & av1_ref_frame_flag_list[BWDREF_FRAME])) {
+          (cm->ref_frame_flags & av1_ref_frame_flag_list[BWDREF_FRAME])) {
         // Check if both ALTREF2_FRAME and BWDREF_FRAME are future references.
         if (arf2_dist > 0 && bwd_dist > 0 && bwd_dist <= arf2_dist) {
           // Drop ALTREF2_FRAME as a reference if BWDREF_FRAME is a closer
@@ -1101,6 +1170,7 @@
     }
   }
 }
+#endif  // !CONFIG_NEW_REF_SIGNALING
 
 /*!\brief Encoder setup(only for the current frame), encoding, and recontruction
  * for a single frame
@@ -1304,8 +1374,10 @@
       frame_is_intra_only(cm) ? 0 : refs_are_one_sided(cm);
 
   cpi->prune_ref_frame_mask = 0;
+#if !CONFIG_NEW_REF_SIGNALING
   // Figure out which ref frames can be skipped at frame level.
   setup_prune_ref_frame_mask(cpi);
+#endif  // !CONFIG_NEW_REF_SIGNALING
 
   x->txfm_search_info.txb_split_count = 0;
 #if CONFIG_SPEED_STATS
@@ -1490,9 +1562,8 @@
   }
 
   av1_setup_frame_buf_refs(cm);
-  enforce_max_ref_frames(cpi, &cpi->ref_frame_flags);
-  set_rel_frame_dist(&cpi->common, &cpi->ref_frame_dist_info,
-                     cpi->ref_frame_flags);
+  enforce_max_ref_frames(cpi, &cm->ref_frame_flags);
+  set_rel_frame_dist(cm, &cpi->ref_frame_dist_info, cm->ref_frame_flags);
   av1_setup_frame_sign_bias(cm);
 
 #if CONFIG_MISMATCH_DEBUG
@@ -1517,6 +1588,18 @@
     rdc->compound_ref_used_flag = 0;
     rdc->skip_mode_used_flag = 0;
 
+#if CONFIG_OPTFLOW_REFINEMENT
+    if (cm->seq_params.enable_opfl_refine == AOM_OPFL_REFINE_AUTO) {
+      // Auto mode: encoder decides which refine type to use for each frame.
+      // For now, set all frame to REFINE_SWITCHABLE. The search or heuristic
+      // that encoder can use is left for future work.
+      features->opfl_refine_type = REFINE_SWITCHABLE;
+    } else {
+      // 0: REFINE_NONE, 1: REFINE_SWTICHABLE, 2: REFINE_ALL
+      features->opfl_refine_type = cm->seq_params.enable_opfl_refine;
+    }
+#endif  // CONFIG_OPTFLOW_REFINEMENT
+
     encode_frame_internal(cpi);
 
     if (current_frame->reference_mode == REFERENCE_MODE_SELECT) {
diff --git a/av1/encoder/encodeframe.h b/av1/encoder/encodeframe.h
index 36b38d5..9b0adac 100644
--- a/av1/encoder/encodeframe.h
+++ b/av1/encoder/encodeframe.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_ENCODEFRAME_H_
diff --git a/av1/encoder/encodeframe_utils.c b/av1/encoder/encodeframe_utils.c
index eddfe72..a380f5f 100644
--- a/av1/encoder/encodeframe_utils.c
+++ b/av1/encoder/encodeframe_utils.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "aom_ports/system_state.h"
@@ -362,7 +363,7 @@
 
   if (dry_run) return;
 
-#if CONFIG_INTERNAL_STATS
+#if CONFIG_INTERNAL_STATS && !CONFIG_NEW_REF_SIGNALING
   {
     unsigned int *const mode_chosen_counts =
         (unsigned int *)cpi->mode_chosen_counts;  // Cast const away.
@@ -388,7 +389,7 @@
       ++mode_chosen_counts[ctx->best_mode_index];
     }
   }
-#endif
+#endif  // CONFIG_INTERNAL_STATS && !CONFIG_NEW_REF_SIGNALING
   if (!frame_is_intra_only(cm)) {
 #if CONFIG_SDP
     if (is_inter_block(mi_addr, xd->tree_type)) {
@@ -520,11 +521,17 @@
 }
 
 void av1_sum_intra_stats(const AV1_COMMON *const cm, FRAME_COUNTS *counts,
-                         MACROBLOCKD *xd, const MB_MODE_INFO *const mbmi,
+                         MACROBLOCKD *xd, const MB_MODE_INFO *const mbmi
+#if !CONFIG_AIMC
+                         ,
                          const MB_MODE_INFO *above_mi,
-                         const MB_MODE_INFO *left_mi, const int intraonly) {
+                         const MB_MODE_INFO *left_mi, const int intraonly
+#endif  // !CONFIG_AIMC
+) {
   FRAME_CONTEXT *fc = xd->tile_ctx;
+#if !CONFIG_AIMC
   const PREDICTION_MODE y_mode = mbmi->mode;
+#endif  // !CONFIG_AIMC
   (void)counts;
 #if CONFIG_SDP
   const BLOCK_SIZE bsize = mbmi->sb_type[xd->tree_type == CHROMA_PART];
@@ -534,21 +541,37 @@
 #if CONFIG_SDP
   if (xd->tree_type != CHROMA_PART) {
 #endif
-    if (intraonly) {
-#if CONFIG_ENTROPY_STATS
-      const PREDICTION_MODE above = av1_above_block_mode(above_mi);
-      const PREDICTION_MODE left = av1_left_block_mode(left_mi);
-      const int above_ctx = intra_mode_context[above];
-      const int left_ctx = intra_mode_context[left];
-      ++counts->kf_y_mode[above_ctx][left_ctx][y_mode];
-#endif  // CONFIG_ENTROPY_STATS
-      update_cdf(get_y_mode_cdf(fc, above_mi, left_mi), y_mode, INTRA_MODES);
+#if CONFIG_AIMC
+    const int context = get_y_mode_idx_ctx(xd);
+    const int mode_idx = mbmi->y_mode_idx;
+    int mode_set_index = mode_idx < FIRST_MODE_COUNT ? 0 : 1;
+    mode_set_index += ((mode_idx - FIRST_MODE_COUNT) / SECOND_MODE_COUNT);
+    update_cdf(fc->y_mode_set_cdf, mode_set_index, INTRA_MODE_SETS);
+    if (mode_set_index == 0) {
+      update_cdf(fc->y_mode_idx_cdf_0[context], mode_idx, FIRST_MODE_COUNT);
     } else {
-#if CONFIG_ENTROPY_STATS
-      ++counts->y_mode[size_group_lookup[bsize]][y_mode];
-#endif  // CONFIG_ENTROPY_STATS
-      update_cdf(fc->y_mode_cdf[size_group_lookup[bsize]], y_mode, INTRA_MODES);
+      update_cdf(fc->y_mode_idx_cdf_1[context],
+                 mode_idx - FIRST_MODE_COUNT -
+                     SECOND_MODE_COUNT * (mode_set_index - 1),
+                 SECOND_MODE_COUNT);
     }
+#else
+  if (intraonly) {
+#if CONFIG_ENTROPY_STATS
+    const PREDICTION_MODE above = av1_above_block_mode(above_mi);
+    const PREDICTION_MODE left = av1_left_block_mode(left_mi);
+    const int above_ctx = intra_mode_context[above];
+    const int left_ctx = intra_mode_context[left];
+    ++counts->kf_y_mode[above_ctx][left_ctx][y_mode];
+#endif  // CONFIG_ENTROPY_STATS
+    update_cdf(get_y_mode_cdf(fc, above_mi, left_mi), y_mode, INTRA_MODES);
+  } else {
+#if CONFIG_ENTROPY_STATS
+    ++counts->y_mode[size_group_lookup[bsize]][y_mode];
+#endif  // CONFIG_ENTROPY_STATS
+    update_cdf(fc->y_mode_cdf[size_group_lookup[bsize]], y_mode, INTRA_MODES);
+  }
+#endif  // CONFIG_AIMC
 #if CONFIG_MRLS
     if (cm->seq_params.enable_mrls && av1_is_directional_mode(mbmi->mode)) {
       update_cdf(fc->mrl_index_cdf, mbmi->mrl_index, MRL_LINE_NUMBER);
@@ -582,37 +605,22 @@
                    FILTER_INTRA_MODES);
       }
     }
+#if !CONFIG_AIMC
     if (av1_is_directional_mode(mbmi->mode) && av1_use_angle_delta(bsize)) {
 #if CONFIG_ENTROPY_STATS
       ++counts->angle_delta[mbmi->mode - V_PRED]
                            [mbmi->angle_delta[PLANE_TYPE_Y] + MAX_ANGLE_DELTA];
 #endif
 
-#if CONFIG_ORIP
-      int signal_intra_filter =
-          av1_signal_orip_for_horver_modes(cm, mbmi, PLANE_TYPE_Y, bsize);
-      if (signal_intra_filter) {
 #if CONFIG_SDP
-        update_cdf(fc->angle_delta_cdf_hv[PLANE_TYPE_Y][mbmi->mode - V_PRED],
+      update_cdf(fc->angle_delta_cdf[PLANE_TYPE_Y][mbmi->mode - V_PRED],
 #else
-        update_cdf(fc->angle_delta_cdf_hv[mbmi->mode - V_PRED],
+      update_cdf(fc->angle_delta_cdf[mbmi->mode - V_PRED],
 #endif
-                   get_angle_delta_to_idx(mbmi->angle_delta[PLANE_TYPE_Y]),
-                   2 * MAX_ANGLE_DELTA + 1 + ADDITIONAL_ANGLE_DELTA);
-      } else {
-#endif
-#if CONFIG_SDP
-        update_cdf(fc->angle_delta_cdf[PLANE_TYPE_Y][mbmi->mode - V_PRED],
-#else
-    update_cdf(fc->angle_delta_cdf[mbmi->mode - V_PRED],
-#endif
-                   mbmi->angle_delta[PLANE_TYPE_Y] + MAX_ANGLE_DELTA,
-                   2 * MAX_ANGLE_DELTA + 1);
-
-#if CONFIG_ORIP
-      }
-#endif
+                 mbmi->angle_delta[PLANE_TYPE_Y] + MAX_ANGLE_DELTA,
+                 2 * MAX_ANGLE_DELTA + 1);
     }
+#endif  // !CONFIG_AIMC
 #if CONFIG_SDP
   }
 #endif
@@ -623,11 +631,17 @@
 #endif
     const UV_PREDICTION_MODE uv_mode = mbmi->uv_mode;
     const CFL_ALLOWED_TYPE cfl_allowed = is_cfl_allowed(xd);
-#if CONFIG_ENTROPY_STATS
+#if CONFIG_ENTROPY_STATS && !CONFIG_AIMC
     ++counts->uv_mode[cfl_allowed][y_mode][uv_mode];
-#endif  // CONFIG_ENTROPY_STATS
-    update_cdf(fc->uv_mode_cdf[cfl_allowed][y_mode], uv_mode,
+#endif  // CONFIG_ENTROPY_STATS && !CONFIG_AIMC
+#if CONFIG_AIMC
+    const int uv_context = av1_is_directional_mode(mbmi->mode) ? 1 : 0;
+    update_cdf(fc->uv_mode_cdf[cfl_allowed][uv_context], mbmi->uv_mode_idx,
                UV_INTRA_MODES - !cfl_allowed);
+#else
+  update_cdf(fc->uv_mode_cdf[cfl_allowed][y_mode], uv_mode,
+             UV_INTRA_MODES - !cfl_allowed);
+#endif  // CONFIG_AIMC
     if (uv_mode == UV_CFL_PRED) {
       const int8_t joint_sign = mbmi->cfl_alpha_signs;
       const uint8_t idx = mbmi->cfl_alpha_idx;
@@ -653,6 +667,7 @@
         update_cdf(cdf_v, CFL_IDX_V(idx), CFL_ALPHABET_SIZE);
       }
     }
+#if !CONFIG_AIMC
     if (av1_is_directional_mode(get_uv_mode(uv_mode)) &&
         av1_use_angle_delta(bsize)) {
 #if CONFIG_ENTROPY_STATS
@@ -669,11 +684,12 @@
                    mbmi->angle_delta[PLANE_TYPE_UV] + MAX_ANGLE_DELTA,
                    2 * MAX_ANGLE_DELTA + 1);
 #else
-    update_cdf(fc->angle_delta_cdf[uv_mode - UV_V_PRED],
-               mbmi->angle_delta[PLANE_TYPE_UV] + MAX_ANGLE_DELTA,
-               2 * MAX_ANGLE_DELTA + 1);
+      update_cdf(fc->angle_delta_cdf[uv_mode - UV_V_PRED],
+                 mbmi->angle_delta[PLANE_TYPE_UV] + MAX_ANGLE_DELTA,
+                 2 * MAX_ANGLE_DELTA + 1);
 #endif
     }
+#endif  // !CONFIG_AIMC
 #if CONFIG_SDP
   }
 #endif
@@ -1120,11 +1136,10 @@
   offset = AOMMAX(offset, -delta_q_info->delta_q_res * 9 + 1);
   int qindex = cm->quant_params.base_qindex + offset;
 #if CONFIG_EXTQUANT
-  qindex = AOMMIN(qindex, cm->seq_params.bit_depth == AOM_BITS_8
-                              ? MAXQ_8_BITS
-                              : cm->seq_params.bit_depth == AOM_BITS_10
-                                    ? MAXQ_10_BITS
-                                    : MAXQ);
+  qindex =
+      AOMMIN(qindex, cm->seq_params.bit_depth == AOM_BITS_8    ? MAXQ_8_BITS
+                     : cm->seq_params.bit_depth == AOM_BITS_10 ? MAXQ_10_BITS
+                                                               : MAXQ);
 #else
   qindex = AOMMIN(qindex, MAXQ);
 #endif
@@ -1216,8 +1231,15 @@
 void av1_avg_cdf_symbols(FRAME_CONTEXT *ctx_left, FRAME_CONTEXT *ctx_tr,
                          int wt_left, int wt_tr) {
   AVERAGE_CDF(ctx_left->txb_skip_cdf, ctx_tr->txb_skip_cdf, 2);
+#if CONFIG_CONTEXT_DERIVATION
+  AVERAGE_CDF(ctx_left->v_txb_skip_cdf, ctx_tr->v_txb_skip_cdf, 2);
+#endif  // CONFIG_CONTEXT_DERIVATION
   AVERAGE_CDF(ctx_left->eob_extra_cdf, ctx_tr->eob_extra_cdf, 2);
   AVERAGE_CDF(ctx_left->dc_sign_cdf, ctx_tr->dc_sign_cdf, 2);
+#if CONFIG_CONTEXT_DERIVATION
+  AVERAGE_CDF(ctx_left->v_dc_sign_cdf, ctx_tr->v_dc_sign_cdf, 2);
+  AVERAGE_CDF(ctx_left->v_ac_sign_cdf, ctx_tr->v_ac_sign_cdf, 2);
+#endif  // CONFIG_CONTEXT_DERIVATION
   AVERAGE_CDF(ctx_left->eob_flag_cdf16, ctx_tr->eob_flag_cdf16, 5);
   AVERAGE_CDF(ctx_left->eob_flag_cdf32, ctx_tr->eob_flag_cdf32, 6);
   AVERAGE_CDF(ctx_left->eob_flag_cdf64, ctx_tr->eob_flag_cdf64, 7);
@@ -1240,8 +1262,13 @@
   AVERAGE_CDF(ctx_left->refmv_cdf, ctx_tr->refmv_cdf, 2);
   AVERAGE_CDF(ctx_left->drl_cdf, ctx_tr->drl_cdf, 2);
 #endif  // CONFIG_NEW_INTER_MODES
+#if CONFIG_OPTFLOW_REFINEMENT
+  AVERAGE_CDF(ctx_left->inter_compound_mode_cdf,
+              ctx_tr->inter_compound_mode_cdf, INTER_COMPOUND_REF_TYPES);
+#else
   AVERAGE_CDF(ctx_left->inter_compound_mode_cdf,
               ctx_tr->inter_compound_mode_cdf, INTER_COMPOUND_MODES);
+#endif  // CONFIG_OPTFLOW_REFINEMENT
   AVERAGE_CDF(ctx_left->compound_type_cdf, ctx_tr->compound_type_cdf,
               MASKED_COMPOUND_TYPES);
   AVERAGE_CDF(ctx_left->wedge_idx_cdf, ctx_tr->wedge_idx_cdf, 16);
@@ -1268,10 +1295,12 @@
   AVERAGE_CDF(ctx_left->palette_uv_mode_cdf, ctx_tr->palette_uv_mode_cdf, 2);
   AVERAGE_CDF(ctx_left->comp_inter_cdf, ctx_tr->comp_inter_cdf, 2);
   AVERAGE_CDF(ctx_left->single_ref_cdf, ctx_tr->single_ref_cdf, 2);
+  AVERAGE_CDF(ctx_left->comp_ref_cdf, ctx_tr->comp_ref_cdf, 2);
+#if !CONFIG_NEW_REF_SIGNALING
   AVERAGE_CDF(ctx_left->comp_ref_type_cdf, ctx_tr->comp_ref_type_cdf, 2);
   AVERAGE_CDF(ctx_left->uni_comp_ref_cdf, ctx_tr->uni_comp_ref_cdf, 2);
-  AVERAGE_CDF(ctx_left->comp_ref_cdf, ctx_tr->comp_ref_cdf, 2);
   AVERAGE_CDF(ctx_left->comp_bwdref_cdf, ctx_tr->comp_bwdref_cdf, 2);
+#endif  // CONFIG_NEW_REF_SIGNALING
 #if CONFIG_NEW_TX_PARTITION
   // Square blocks
   AVERAGE_CDF(ctx_left->inter_4way_txfm_partition_cdf[0],
@@ -1286,13 +1315,15 @@
 #else   // CONFIG_NEW_TX_PARTITION
   AVERAGE_CDF(ctx_left->txfm_partition_cdf, ctx_tr->txfm_partition_cdf, 2);
 #endif  // CONFIG_NEW_TX_PARTITION
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-  AVERAGE_CDF(ctx_left->compound_index_cdf, ctx_tr->compound_index_cdf, 2);
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
   AVERAGE_CDF(ctx_left->comp_group_idx_cdf, ctx_tr->comp_group_idx_cdf, 2);
   AVERAGE_CDF(ctx_left->skip_mode_cdfs, ctx_tr->skip_mode_cdfs, 2);
   AVERAGE_CDF(ctx_left->skip_txfm_cdfs, ctx_tr->skip_txfm_cdfs, 2);
+#if CONFIG_CONTEXT_DERIVATION
+  AVERAGE_CDF(ctx_left->intra_inter_cdf[0], ctx_tr->intra_inter_cdf[0], 2);
+  AVERAGE_CDF(ctx_left->intra_inter_cdf[1], ctx_tr->intra_inter_cdf[1], 2);
+#else
   AVERAGE_CDF(ctx_left->intra_inter_cdf, ctx_tr->intra_inter_cdf, 2);
+#endif  // CONFIG_CONTEXT_DERIVATION
   avg_nmv(&ctx_left->nmvc, &ctx_tr->nmvc, wt_left, wt_tr);
   avg_nmv(&ctx_left->ndvc, &ctx_tr->ndvc, wt_left, wt_tr);
   AVERAGE_CDF(ctx_left->intrabc_cdf, ctx_tr->intrabc_cdf, 2);
@@ -1310,7 +1341,16 @@
 #if CONFIG_MRLS
   AVERAGE_CDF(ctx_left->mrl_index_cdf, ctx_tr->mrl_index_cdf, MRL_LINE_NUMBER);
 #endif
+#if CONFIG_AIMC
+  AVERAGE_CDF(ctx_left->y_mode_set_cdf, ctx_tr->y_mode_set_cdf,
+              INTRA_MODE_SETS);
+  AVERAGE_CDF(ctx_left->y_mode_idx_cdf_0, ctx_tr->y_mode_idx_cdf_0,
+              FIRST_MODE_COUNT);
+  AVERAGE_CDF(ctx_left->y_mode_idx_cdf_1, ctx_tr->y_mode_idx_cdf_1,
+              SECOND_MODE_COUNT);
+#else
   AVERAGE_CDF(ctx_left->y_mode_cdf, ctx_tr->y_mode_cdf, INTRA_MODES);
+#endif  // CONFIG_AIMC
   AVG_CDF_STRIDE(ctx_left->uv_mode_cdf[0], ctx_tr->uv_mode_cdf[0],
                  UV_INTRA_MODES - 1, CDF_SIZE(UV_INTRA_MODES));
   AVERAGE_CDF(ctx_left->uv_mode_cdf[1], ctx_tr->uv_mode_cdf[1], UV_INTRA_MODES);
@@ -1345,13 +1385,12 @@
 #endif
   AVERAGE_CDF(ctx_left->switchable_interp_cdf, ctx_tr->switchable_interp_cdf,
               SWITCHABLE_FILTERS);
+#if !CONFIG_AIMC
   AVERAGE_CDF(ctx_left->kf_y_cdf, ctx_tr->kf_y_cdf, INTRA_MODES);
   AVERAGE_CDF(ctx_left->angle_delta_cdf, ctx_tr->angle_delta_cdf,
               2 * MAX_ANGLE_DELTA + 1);
-#if CONFIG_ORIP
-  AVERAGE_CDF(ctx_left->angle_delta_cdf_hv, ctx_tr->angle_delta_cdf_hv,
-              2 * MAX_ANGLE_DELTA + 1 + ADDITIONAL_ANGLE_DELTA);
-#endif
+#endif  // !CONFIG_AIMC
+
 #if CONFIG_NEW_TX_PARTITION
   // Square blocks
   AVERAGE_CDF(ctx_left->intra_4way_txfm_partition_cdf[0],
@@ -1462,10 +1501,10 @@
   sb_fp_stats->current_qindex =
       cm->mi_params.mi_alloc[alloc_mi_idx].current_qindex;
 
-#if CONFIG_INTERNAL_STATS
+#if CONFIG_INTERNAL_STATS && !CONFIG_NEW_REF_SIGNALING
   memcpy(sb_fp_stats->mode_chosen_counts, cpi->mode_chosen_counts,
          sizeof(sb_fp_stats->mode_chosen_counts));
-#endif  // CONFIG_INTERNAL_STATS
+#endif  // CONFIG_INTERNAL_STATS && !CONFIG_NEW_REF_SIGNALING
 }
 
 void av1_restore_sb_state(const SB_FIRST_PASS_STATS *sb_fp_stats, AV1_COMP *cpi,
@@ -1494,10 +1533,10 @@
   cm->mi_params.mi_alloc[alloc_mi_idx].current_qindex =
       sb_fp_stats->current_qindex;
 
-#if CONFIG_INTERNAL_STATS
+#if CONFIG_INTERNAL_STATS && !CONFIG_NEW_REF_SIGNALING
   memcpy(cpi->mode_chosen_counts, sb_fp_stats->mode_chosen_counts,
          sizeof(sb_fp_stats->mode_chosen_counts));
-#endif  // CONFIG_INTERNAL_STATS
+#endif  // CONFIG_INTERNAL_STATS && !CONFIG_NEW_REF_SIGNALING
 }
 
 // Update the rate costs of some symbols according to the frequency directed
diff --git a/av1/encoder/encodeframe_utils.h b/av1/encoder/encodeframe_utils.h
index 5fde760..54a4774 100644
--- a/av1/encoder/encodeframe_utils.h
+++ b/av1/encoder/encodeframe_utils.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_ENCODEFRAME_UTILS_H_
@@ -54,12 +55,16 @@
   int split_count;
   FRAME_COUNTS fc;
   InterModeRdModel inter_mode_rd_models[BLOCK_SIZES_ALL];
+#if CONFIG_NEW_REF_SIGNALING
+  int thresh_freq_fact[BLOCK_SIZES_ALL][MB_MODE_COUNT];
+#else
   int thresh_freq_fact[BLOCK_SIZES_ALL][MAX_MODES];
+#endif  // CONFIG_NEW_REF_SIGNALING
   int current_qindex;
 
-#if CONFIG_INTERNAL_STATS
+#if CONFIG_INTERNAL_STATS && !CONFIG_NEW_REF_SIGNALING
   unsigned int mode_chosen_counts[MAX_MODES];
-#endif  // CONFIG_INTERNAL_STATS
+#endif  // CONFIG_INTERNAL_STATS && !CONFIG_NEW_REF_SIGNALING
 } SB_FIRST_PASS_STATS;
 
 // This structure contains block size related
@@ -290,9 +295,13 @@
                                  PREDICTION_MODE mode, int16_t mode_context);
 
 void av1_sum_intra_stats(const AV1_COMMON *const cm, FRAME_COUNTS *counts,
-                         MACROBLOCKD *xd, const MB_MODE_INFO *const mbmi,
+                         MACROBLOCKD *xd, const MB_MODE_INFO *const mbmi
+#if !CONFIG_AIMC
+                         ,
                          const MB_MODE_INFO *above_mi,
-                         const MB_MODE_INFO *left_mi, const int intraonly);
+                         const MB_MODE_INFO *left_mi, const int intraonly
+#endif  // !CONFIG_AIMC
+);
 
 void av1_restore_context(MACROBLOCK *x, const RD_SEARCH_MACROBLOCK_CONTEXT *ctx,
                          int mi_row, int mi_col, BLOCK_SIZE bsize,
diff --git a/av1/encoder/encodemb.c b/av1/encoder/encodemb.c
index 4d67ab4..ddd624f 100644
--- a/av1/encoder/encodemb.c
+++ b/av1/encoder/encodemb.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "config/aom_config.h"
@@ -89,7 +90,12 @@
 
   if (eob == 0 || !cpi->optimize_seg_arr[segment_id] ||
       xd->lossless[segment_id]) {
-    *rate_cost = av1_cost_skip_txb(&x->coeff_costs, txb_ctx, plane, tx_size);
+    *rate_cost = av1_cost_skip_txb(&x->coeff_costs, txb_ctx, plane, tx_size
+#if CONFIG_CONTEXT_DERIVATION
+                                   ,
+                                   x, block
+#endif  // CONFIG_CONTEXT_DERIVATION
+    );
     return eob;
   }
 
@@ -361,6 +367,23 @@
       av1_quantize_skip(n_coeffs, qcoeff, dqcoeff, eob);
     }
   }
+
+#if CONFIG_CONTEXT_DERIVATION
+  MACROBLOCKD *const xd = &x->e_mbd;
+  const int16_t *const scan = scan_order->scan;
+  if (plane == AOM_PLANE_U) {
+    xd->eob_u_flag = *eob ? 1 : 0;
+    const int width = get_txb_wide(txfm_param->tx_size);
+    const int height = get_txb_high(txfm_param->tx_size);
+    memset(xd->tmp_sign, 0, width * height * sizeof(int32_t));
+    for (int c = 0; c < *eob; ++c) {
+      const int pos = scan[c];
+      int sign = (qcoeff[pos] < 0) ? 1 : 0;
+      if (abs(qcoeff[pos])) xd->tmp_sign[pos] = (sign ? 2 : 1);
+    }
+  }
+#endif  // CONFIG_CONTEXT_DERIVATION
+
   // use_optimize_b is true means av1_optimze_b will be called,
   // thus cannot update entropy ctx now (performed in optimize_b)
   if (qparam->use_optimize_b) {
diff --git a/av1/encoder/encodemb.h b/av1/encoder/encodemb.h
index 91b47cc..78fbdfe 100644
--- a/av1/encoder/encodemb.h
+++ b/av1/encoder/encodemb.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_ENCODEMB_H_
diff --git a/av1/encoder/encodemv.c b/av1/encoder/encodemv.c
index 4b455eb..ea96b9f 100644
--- a/av1/encoder/encodemv.c
+++ b/av1/encoder/encodemv.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <math.h>
@@ -232,7 +233,7 @@
   const CANDIDATE_MV *curr_ref_mv_stack =
       mbmi_ext->ref_mv_stack[ref_frame_type];
 
-  if (ref_frame[1] > INTRA_FRAME) {
+  if (is_inter_ref_frame(ref_frame[1])) {
     assert(ref_idx == 0 || ref_idx == 1);
     return ref_idx ? curr_ref_mv_stack[ref_mv_idx].comp_mv
                    : curr_ref_mv_stack[ref_mv_idx].this_mv;
@@ -248,7 +249,7 @@
   const MACROBLOCKD *xd = &x->e_mbd;
   const MB_MODE_INFO *mbmi = xd->mi[0];
   int ref_mv_idx = mbmi->ref_mv_idx;
-  if (mbmi->mode == NEAR_NEWMV || mbmi->mode == NEW_NEARMV) {
+  if (have_nearmv_newmv_in_inter_mode(mbmi->mode)) {
     assert(has_second_ref(mbmi));
 #if !CONFIG_NEW_INTER_MODES
     ref_mv_idx += 1;
@@ -276,7 +277,11 @@
                                        int is_integer) {
   int_mv mv;
   bool found_ref_mv = false;
+#if CONFIG_NEW_REF_SIGNALING
+  MV_REFERENCE_FRAME ref_frames[2] = { ref_frame, INVALID_IDX };
+#else
   MV_REFERENCE_FRAME ref_frames[2] = { ref_frame, NONE_FRAME };
+#endif  // CONFIG_NEW_REF_SIGNALING
   int range = AOMMIN(mbmi_ext->ref_mv_count[ref_frame], MAX_REF_MV_STACK_SIZE);
   for (int i = 0; i < range; i++) {
     mv = av1_get_ref_mv_from_stack(0, ref_frames, i, mbmi_ext);
@@ -296,7 +301,11 @@
                                         int is_integer) {
   int_mv mv;
   const int ref_idx = 0;
+#if CONFIG_NEW_REF_SIGNALING
+  MV_REFERENCE_FRAME ref_frames[2] = { ref_frame, INVALID_IDX };
+#else
   MV_REFERENCE_FRAME ref_frames[2] = { ref_frame, NONE_FRAME };
+#endif  // CONFIG_NEW_REF_SIGNALING
   mv = av1_get_ref_mv_from_stack(ref_idx, ref_frames, 0, mbmi_ext);
   lower_mv_precision(&mv.as_mv, allow_hp, is_integer);
   return mv;
@@ -308,7 +317,11 @@
                                       int_mv *nearest_mv, int_mv *near_mv,
                                       int is_integer) {
   const int ref_idx = 0;
+#if CONFIG_NEW_REF_SIGNALING
+  MV_REFERENCE_FRAME ref_frames[2] = { ref_frame, INVALID_IDX };
+#else
   MV_REFERENCE_FRAME ref_frames[2] = { ref_frame, NONE_FRAME };
+#endif  // CONFIG_NEW_REF_SIGNALING
   *nearest_mv = av1_get_ref_mv_from_stack(ref_idx, ref_frames, 0, mbmi_ext);
   lower_mv_precision(&nearest_mv->as_mv, allow_hp, is_integer);
   *near_mv = av1_get_ref_mv_from_stack(ref_idx, ref_frames, 1, mbmi_ext);
diff --git a/av1/encoder/encodemv.h b/av1/encoder/encodemv.h
index 45f0fe2..b67c699 100644
--- a/av1/encoder/encodemv.h
+++ b/av1/encoder/encodemv.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_ENCODEMV_H_
@@ -85,7 +86,11 @@
   MACROBLOCKD *xd = &x->e_mbd;
   MB_MODE_INFO *mbmi = xd->mi[0];
   const PREDICTION_MODE this_mode = mbmi->mode;
+#if CONFIG_OPTFLOW_REFINEMENT
+  if (this_mode == NEW_NEWMV || this_mode == NEW_NEWMV_OPTFLOW) {
+#else
   if (this_mode == NEW_NEWMV) {
+#endif  // CONFIG_OPTFLOW_REFINEMENT
     const int_mv ref_mv_0 = av1_get_ref_mv(x, 0);
     const int_mv ref_mv_1 = av1_get_ref_mv(x, 1);
     if (mbmi->mv[0].as_int == ref_mv_0.as_int ||
@@ -93,7 +98,11 @@
       return 0;
     }
 #if CONFIG_NEW_INTER_MODES
+#if CONFIG_OPTFLOW_REFINEMENT
+  } else if (this_mode == NEAR_NEWMV || this_mode == NEAR_NEWMV_OPTFLOW) {
+#else
   } else if (this_mode == NEAR_NEWMV) {
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 #else
   } else if (this_mode == NEAREST_NEWMV || this_mode == NEAR_NEWMV) {
 #endif  // CONFIG_NEW_INTER_MODES
@@ -102,7 +111,11 @@
       return 0;
     }
 #if CONFIG_NEW_INTER_MODES
+#if CONFIG_OPTFLOW_REFINEMENT
+  } else if (this_mode == NEW_NEARMV || this_mode == NEW_NEARMV_OPTFLOW) {
+#else
   } else if (this_mode == NEW_NEARMV) {
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 #else
   } else if (this_mode == NEW_NEARESTMV || this_mode == NEW_NEARMV) {
 #endif  // CONFIG_NEW_INTER_MODES
diff --git a/av1/encoder/encoder.c b/av1/encoder/encoder.c
index 43ea020..b44742b 100644
--- a/av1/encoder/encoder.c
+++ b/av1/encoder/encoder.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <limits.h>
@@ -391,7 +392,12 @@
 }
 
 void av1_init_seq_coding_tools(SequenceHeader *seq, AV1_COMMON *cm,
-                               const AV1EncoderConfig *oxcf, int use_svc) {
+                               const AV1EncoderConfig *oxcf
+#if CONFIG_SVC_ENCODER
+                               ,
+                               int use_svc
+#endif  // CONFIG_SVC_ENCODER
+) {
   const FrameDimensionCfg *const frm_dim_cfg = &oxcf->frm_dim_cfg;
   const ToolCfg *const tool_cfg = &oxcf->tool_cfg;
 
@@ -405,7 +411,10 @@
   seq->frame_id_numbers_present_flag =
       !(seq->still_picture && seq->reduced_still_picture_hdr) &&
       !oxcf->tile_cfg.enable_large_scale_tile &&
-      tool_cfg->error_resilient_mode && !use_svc;
+#if CONFIG_SVC_ENCODER
+      !use_svc &&
+#endif  // CONFIG_SVC_ENCODER
+      tool_cfg->error_resilient_mode;
   if (seq->still_picture && seq->reduced_still_picture_hdr) {
     seq->order_hint_info.enable_order_hint = 0;
     seq->force_screen_content_tools = 2;
@@ -415,6 +424,10 @@
       seq->order_hint_info.enable_order_hint
           ? DEFAULT_EXPLICIT_ORDER_HINT_BITS - 1
           : -1;
+#if CONFIG_NEW_REF_SIGNALING
+  seq->explicit_ref_frame_map = oxcf->ref_frm_cfg.explicit_ref_frame_map;
+  seq->max_reference_frames = oxcf->ref_frm_cfg.max_reference_frames;
+#endif  // CONFIG_NEW_REF_SIGNALING
 
   seq->max_frame_width = frm_dim_cfg->forced_max_frame_width
                              ? frm_dim_cfg->forced_max_frame_width
@@ -435,12 +448,6 @@
 #if !CONFIG_REMOVE_DUAL_FILTER
   seq->enable_dual_filter = tool_cfg->enable_dual_filter;
 #endif  // !CONFIG_REMOVE_DUAL_FILTER
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-  seq->order_hint_info.enable_dist_wtd_comp =
-      oxcf->comp_type_cfg.enable_dist_wtd_comp;
-  seq->order_hint_info.enable_dist_wtd_comp &=
-      seq->order_hint_info.enable_order_hint;
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
   seq->order_hint_info.enable_ref_frame_mvs = tool_cfg->ref_frame_mvs_present;
   seq->order_hint_info.enable_ref_frame_mvs &=
       seq->order_hint_info.enable_order_hint;
@@ -450,6 +457,9 @@
 #if CONFIG_CCSO
   seq->enable_ccso = tool_cfg->enable_ccso;
 #endif
+#if CONFIG_OPTFLOW_REFINEMENT
+  seq->enable_opfl_refine = tool_cfg->enable_opfl_refine;
+#endif  // CONFIG_OPTFLOW_REFINEMENT
   seq->enable_warped_motion = oxcf->motion_mode_cfg.enable_warped_motion;
   seq->enable_interintra_compound = tool_cfg->enable_interintra_comp;
   seq->enable_masked_compound = oxcf->comp_type_cfg.enable_masked_comp;
@@ -467,6 +477,9 @@
 #if CONFIG_IST
   seq->enable_ist = oxcf->txfm_cfg.enable_ist;
 #endif
+#if CONFIG_IBP_DC || CONFIG_IBP_DIR
+  seq->enable_ibp = oxcf->intra_mode_cfg.enable_ibp;
+#endif
   set_bitstream_level_tier(seq, cm, frm_dim_cfg->width, frm_dim_cfg->height,
                            oxcf->input_cfg.init_framerate);
 
@@ -505,6 +518,9 @@
     seq->base_uv_dc_delta_q = -3;
   }
 #endif  // CONFIG_EXTQUANT
+#if CONFIG_REF_MV_BANK
+  seq->enable_refmvbank = tool_cfg->enable_refmvbank;
+#endif  // CONFIG_REF_MV_BANK
 }
 
 static void init_config(struct AV1_COMP *cpi, AV1EncoderConfig *oxcf) {
@@ -593,11 +609,13 @@
   cpi->td.counts = &cpi->counts;
 
   // Set init SVC parameters.
+#if CONFIG_SVC_ENCODER
   cpi->use_svc = 0;
   cpi->svc.external_ref_frame_config = 0;
   cpi->svc.non_reference_frame = 0;
   cpi->svc.number_spatial_layers = 1;
   cpi->svc.number_temporal_layers = 1;
+#endif  // CONFIG_SVC_ENCODER
   cm->number_spatial_layers = 1;
   cm->number_temporal_layers = 1;
   cm->spatial_layer_id = 0;
@@ -606,7 +624,7 @@
   // change includes all joint functionality
   av1_change_config(cpi, oxcf);
 
-  cpi->ref_frame_flags = 0;
+  cm->ref_frame_flags = 0;
 
   // Reset resize pending flags
   resize_pending_params->width = 0;
@@ -647,7 +665,9 @@
   MACROBLOCK *const x = &cpi->td.mb;
   AV1LevelParams *const level_params = &cpi->level_params;
   InitialDimensions *const initial_dimensions = &cpi->initial_dimensions;
+#if !CONFIG_NEW_REF_SIGNALING
   RefreshFrameFlagsInfo *const refresh_frame_flags = &cpi->refresh_frame;
+#endif  // !CONFIG_NEW_REF_SIGNALING
   const FrameDimensionCfg *const frm_dim_cfg = &cpi->oxcf.frm_dim_cfg;
   const DecoderModelCfg *const dec_model_cfg = &oxcf->dec_model_cfg;
   const ColorCfg *const color_cfg = &oxcf->color_cfg;
@@ -739,8 +759,10 @@
 
   rc->baseline_gf_interval = (MIN_GF_INTERVAL + MAX_GF_INTERVAL) / 2;
 
+#if !CONFIG_NEW_REF_SIGNALING
   refresh_frame_flags->golden_frame = false;
   refresh_frame_flags->bwd_ref_frame = false;
+#endif  // !CONFIG_NEW_REF_SIGNALING
 
   cm->features.refresh_frame_context =
       (oxcf->tool_cfg.frame_parallel_decoding_mode)
@@ -799,6 +821,9 @@
   cm->features.interp_filter =
       oxcf->tile_cfg.enable_large_scale_tile ? EIGHTTAP_REGULAR : SWITCHABLE;
   cm->features.switchable_motion_mode = 1;
+#if CONFIG_OPTFLOW_REFINEMENT
+  cm->features.opfl_refine_type = REFINE_SWITCHABLE;
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   if (frm_dim_cfg->render_width > 0 && frm_dim_cfg->render_height > 0) {
     cm->render_width = frm_dim_cfg->render_width;
@@ -838,8 +863,12 @@
 
   set_tile_info(cm, &cpi->oxcf.tile_cfg);
 
+#if CONFIG_SVC_ENCODER
   if (!cpi->svc.external_ref_frame_config)
     cpi->ext_flags.refresh_frame.update_pending = 0;
+#else
+  cpi->ext_flags.refresh_frame.update_pending = 0;
+#endif  // CONFIG_SVC_ENCODER
   cpi->ext_flags.refresh_frame_context_pending = 0;
 
   highbd_set_var_fns(cpi);
@@ -851,11 +880,17 @@
         (cm->number_spatial_layers > 1 || cm->number_temporal_layers > 1)
             ? cm->number_spatial_layers * cm->number_temporal_layers - 1
             : 0;
+#if CONFIG_SVC_ENCODER
     av1_init_seq_coding_tools(&cm->seq_params, cm, oxcf, cpi->use_svc);
+#else
+    av1_init_seq_coding_tools(&cm->seq_params, cm, oxcf);
+#endif  // CONFIG_SVC_ENCODER
   }
 
+#if CONFIG_SVC_ENCODER
   if (cpi->use_svc)
     av1_update_layer_context_change_config(cpi, rc_cfg->target_bandwidth);
+#endif  // CONFIG_SVC_ENCODER
 
   // restore the value of lag_in_frame for LAP stage.
   if (lap_lag_in_frames != -1) {
@@ -1004,7 +1039,9 @@
   cpi->last_show_frame_buf = NULL;
   realloc_segmentation_maps(cpi);
 
+#if !CONFIG_NEW_REF_SIGNALING
   cpi->refresh_frame.alt_ref_frame = false;
+#endif  // !CONFIG_NEW_REF_SIGNALING
 
   cpi->b_calculate_psnr = CONFIG_INTERNAL_STATS;
 #if CONFIG_INTERNAL_STATS
@@ -1590,6 +1627,9 @@
   }
 
   dealloc_compressor_data(cpi);
+#if CONFIG_IBP_DIR
+  free_ibp_info(cm->ibp_directional_weights);
+#endif
 
 #if CONFIG_INTERNAL_STATS
   aom_free(cpi->ssim_vars);
@@ -2034,7 +2074,11 @@
   if (!is_stat_generation_stage(cpi)) alloc_util_frame_buffers(cpi);
   init_motion_estimation(cpi);
 
+#if CONFIG_NEW_REF_SIGNALING
+  for (ref_frame = 0; ref_frame < INTER_REFS_PER_FRAME; ++ref_frame) {
+#else
   for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
+#endif  // CONFIG_NEW_REF_SIGNALING
     RefCntBuffer *const buf = get_ref_frame_buf(cm, ref_frame);
     if (buf != NULL) {
       struct scale_factors *sf = get_ref_scale_factors(cm, ref_frame);
@@ -2048,7 +2092,11 @@
   av1_setup_scale_factors_for_frame(&cm->sf_identity, cm->width, cm->height,
                                     cm->width, cm->height);
 
+#if CONFIG_NEW_REF_SIGNALING
+  set_ref_ptrs(cm, xd, 0, 0);
+#else
   set_ref_ptrs(cm, xd, LAST_FRAME, LAST_FRAME);
+#endif  // CONFIG_NEW_REF_SIGNALING
 }
 
 /*!\brief Select and apply cdef filters and switchable restoration filters
@@ -2281,7 +2329,9 @@
 static int encode_without_recode(AV1_COMP *cpi) {
   AV1_COMMON *const cm = &cpi->common;
   const QuantizationCfg *const q_cfg = &cpi->oxcf.q_cfg;
+#if CONFIG_SVC_ENCODER
   SVC *const svc = &cpi->svc;
+#endif  // CONFIG_SVC_ENCODER
   ResizePendingParams *const resize_pending_params =
       &cpi->resize_pending_params;
   const int resize_pending =
@@ -2291,18 +2341,26 @@
 
   int top_index = 0, bottom_index = 0, q = 0;
   YV12_BUFFER_CONFIG *unscaled = cpi->unscaled_source;
+#if CONFIG_SVC_ENCODER
   InterpFilter filter_scaler =
       cpi->use_svc ? svc->downsample_filter_type[svc->spatial_layer_id]
                    : EIGHTTAP_SMOOTH;
   int phase_scaler =
       cpi->use_svc ? svc->downsample_filter_phase[svc->spatial_layer_id] : 0;
+#else
+  InterpFilter filter_scaler = EIGHTTAP_SMOOTH;
+  int phase_scaler = 0;
+#endif  // CONFIG_SVC_ENCODER
 
   set_size_independent_vars(cpi);
   cpi->source->buf_8bit_valid = 0;
   av1_setup_frame_size(cpi);
   av1_set_size_dependent_vars(cpi, &q, &bottom_index, &top_index);
 
-  if (!cpi->use_svc) {
+#if CONFIG_SVC_ENCODER
+  if (!cpi->use_svc)
+#endif  // CONFIG_SVC_ENCODER
+  {
     phase_scaler = 8;
     // 2:1 scaling.
     if ((cm->width << 1) == unscaled->y_crop_width &&
@@ -2345,32 +2403,55 @@
         phase_scaler, true, false);
   }
 
+#if CONFIG_SVC_ENCODER
   // For 1 spatial layer encoding: if the (non-LAST) reference has different
   // resolution from the source then disable that reference. This is to avoid
   // significant increase in encode time from scaling the references in
   // av1_scale_references. Note GOLDEN is forced to update on the (first/tigger)
   // resized frame and ALTREF will be refreshed ~4 frames later, so both
   // references become available again after few frames.
-  if (svc->number_spatial_layers == 1) {
-    if (cpi->ref_frame_flags & av1_ref_frame_flag_list[GOLDEN_FRAME]) {
+  if (svc->number_spatial_layers == 1)
+#endif  // CONFIG_SVC_ENCODER
+  {
+#if CONFIG_NEW_REF_SIGNALING
+    const MV_REFERENCE_FRAME golden_frame = get_best_past_ref_index(cm);
+    const MV_REFERENCE_FRAME altref_frame = get_furthest_future_ref_index(cm);
+    if (cm->ref_frame_flags & (1 << golden_frame)) {
+      const YV12_BUFFER_CONFIG *const ref =
+          get_ref_frame_yv12_buf(cm, golden_frame);
+      if (ref->y_crop_width != cm->width || ref->y_crop_height != cm->height)
+        cm->ref_frame_flags ^= (1 << golden_frame);
+    }
+    if (cm->ref_frame_flags & (1 << altref_frame)) {
+      const YV12_BUFFER_CONFIG *const ref =
+          get_ref_frame_yv12_buf(cm, altref_frame);
+      if (ref->y_crop_width != cm->width || ref->y_crop_height != cm->height)
+        cm->ref_frame_flags ^= (1 << altref_frame);
+    }
+#else
+    if (cm->ref_frame_flags & av1_ref_frame_flag_list[GOLDEN_FRAME]) {
       const YV12_BUFFER_CONFIG *const ref =
           get_ref_frame_yv12_buf(cm, GOLDEN_FRAME);
       if (ref->y_crop_width != cm->width || ref->y_crop_height != cm->height)
-        cpi->ref_frame_flags ^= AOM_GOLD_FLAG;
+        cm->ref_frame_flags ^= AOM_GOLD_FLAG;
     }
-    if (cpi->ref_frame_flags & av1_ref_frame_flag_list[ALTREF_FRAME]) {
+    if (cm->ref_frame_flags & av1_ref_frame_flag_list[ALTREF_FRAME]) {
       const YV12_BUFFER_CONFIG *const ref =
           get_ref_frame_yv12_buf(cm, ALTREF_FRAME);
       if (ref->y_crop_width != cm->width || ref->y_crop_height != cm->height)
-        cpi->ref_frame_flags ^= AOM_ALT_FLAG;
+        cm->ref_frame_flags ^= AOM_ALT_FLAG;
     }
+#endif  // CONFIG_NEW_REF_SIGNALING
   }
 
   // For SVC the inter-layer/spatial prediction is not done for newmv
   // (zero_mode is forced), and since the scaled references are only
   // use for newmv search, we can avoid scaling here.
-  if (!frame_is_intra_only(cm) &&
-      !(cpi->use_svc && cpi->svc.force_zero_mode_spatial_ref))
+  if (!frame_is_intra_only(cm)
+#if CONFIG_SVC_ENCODER
+      && !(cpi->use_svc && cpi->svc.force_zero_mode_spatial_ref)
+#endif  // CONFIG_SVC_ENCODER
+  )
     av1_scale_references(cpi, filter_scaler, phase_scaler, 1);
 
   av1_set_quantizer(cm, q_cfg->qm_minlevel, q_cfg->qm_maxlevel, q,
@@ -2738,6 +2819,7 @@
   cm->cur_frame->buf.color_range = seq_params->color_range;
   cm->cur_frame->buf.render_width = cm->render_width;
   cm->cur_frame->buf.render_height = cm->render_height;
+  cm->cur_frame->buf.bit_depth = (unsigned int)seq_params->bit_depth;
 
   // Pick the loop filter level for the frame.
   if (!cm->features.allow_intrabc) {
@@ -3116,10 +3198,10 @@
 
   aom_clear_system_state();
 
-#if CONFIG_INTERNAL_STATS
+#if CONFIG_INTERNAL_STATS && !CONFIG_NEW_REF_SIGNALING
   memset(cpi->mode_chosen_counts, 0,
          MAX_MODES * sizeof(*cpi->mode_chosen_counts));
-#endif
+#endif  // CONFIG_INTERNAL_STATS && !CONFIG_NEW_REF_SIGNALING
 
   if (seq_params->frame_id_numbers_present_flag) {
     /* Non-normative definition of current_frame_id ("frame counter" with
@@ -3196,8 +3278,10 @@
     }
   }
 
+#if CONFIG_SVC_ENCODER
   if (cpi->svc.spatial_layer_id == cpi->svc.number_spatial_layers - 1)
     cpi->svc.num_encoded_top_layer++;
+#endif  // CONFIG_SVC_ENCODER
 
   if (cm->seg.enabled) {
     if (cm->seg.update_map) {
@@ -3303,7 +3387,7 @@
   cm->features.primary_ref_frame = frame_params->primary_ref_frame;
   cm->current_frame.frame_type = frame_params->frame_type;
   cm->show_frame = frame_params->show_frame;
-  cpi->ref_frame_flags = frame_params->ref_frame_flags;
+  cm->ref_frame_flags = frame_params->ref_frame_flags;
   cpi->speed = frame_params->speed;
   cm->show_existing_frame = frame_params->show_existing_frame;
   cpi->existing_fb_idx_to_show = frame_params->existing_fb_idx_to_show;
@@ -3311,8 +3395,10 @@
   memcpy(cm->remapped_ref_idx, frame_params->remapped_ref_idx,
          REF_FRAMES * sizeof(*cm->remapped_ref_idx));
 
+#if !CONFIG_NEW_REF_SIGNALING
   memcpy(&cpi->refresh_frame, &frame_params->refresh_frame,
          sizeof(cpi->refresh_frame));
+#endif  // !CONFIG_NEW_REF_SIGNALING
 
   if (current_frame->frame_type == KEY_FRAME && !cpi->no_show_fwd_kf) {
     current_frame->key_frame_number += current_frame->frame_number;
@@ -3561,9 +3647,11 @@
   aom_bitstream_queue_set_frame_write(cm->current_frame.order_hint * 2 +
                                       cm->show_frame);
 #endif
+#if CONFIG_SVC_ENCODER
   if (cpi->use_svc && cm->number_spatial_layers > 1) {
     av1_one_pass_cbr_svc_start_layer(cpi);
   }
+#endif  // CONFIG_SVC_ENCODER
 
   cm->showable_frame = 0;
   *size = 0;
@@ -3756,14 +3844,17 @@
   return AOM_CODEC_OK;
 }
 
+#if CONFIG_SVC_ENCODER
 static void svc_set_updates_external_ref_frame_config(
     ExtRefreshFrameFlagsInfo *const ext_refresh_frame_flags, SVC *const svc) {
   ext_refresh_frame_flags->update_pending = 1;
+#if !CONFIG_NEW_REF_SIGNALING
   ext_refresh_frame_flags->last_frame = svc->refresh[svc->ref_idx[0]];
   ext_refresh_frame_flags->golden_frame = svc->refresh[svc->ref_idx[3]];
   ext_refresh_frame_flags->bwd_ref_frame = svc->refresh[svc->ref_idx[4]];
   ext_refresh_frame_flags->alt2_ref_frame = svc->refresh[svc->ref_idx[5]];
   ext_refresh_frame_flags->alt_ref_frame = svc->refresh[svc->ref_idx[6]];
+#endif  // !CONFIG_NEW_REF_SIGNALING
   svc->non_reference_frame = 1;
   for (int i = 0; i < REF_FRAMES; i++) {
     if (svc->refresh[i] == 1) {
@@ -3782,6 +3873,7 @@
   }
   return ref;
 }
+#endif  // CONFIG_SVC_ENCODER
 
 void av1_apply_encoding_flags(AV1_COMP *cpi, aom_enc_frame_flags_t flags) {
   // TODO(yunqingwang): For what references to use, external encoding flags
@@ -3794,6 +3886,20 @@
   ExtRefreshFrameFlagsInfo *const ext_refresh_frame_flags =
       &ext_flags->refresh_frame;
   ext_flags->ref_frame_flags = AOM_REFFRAME_ALL;
+#if CONFIG_NEW_REF_SIGNALING
+#if CONFIG_SVC_ENCODER
+  if (cpi->svc.external_ref_frame_config) {
+    int ref = svc_set_references_external_ref_frame_config(cpi);
+    av1_use_as_reference(&ext_flags->ref_frame_flags, ref);
+    svc_set_updates_external_ref_frame_config(ext_refresh_frame_flags,
+                                              &cpi->svc);
+  } else {
+    ext_refresh_frame_flags->update_pending = 0;
+  }
+#else
+  ext_refresh_frame_flags->update_pending = 0;
+#endif
+#else
   if (flags &
       (AOM_EFLAG_NO_REF_LAST | AOM_EFLAG_NO_REF_LAST2 | AOM_EFLAG_NO_REF_LAST3 |
        AOM_EFLAG_NO_REF_GF | AOM_EFLAG_NO_REF_ARF | AOM_EFLAG_NO_REF_BWD |
@@ -3817,10 +3923,12 @@
 
     av1_use_as_reference(&ext_flags->ref_frame_flags, ref);
   } else {
+#if CONFIG_SVC_ENCODER
     if (cpi->svc.external_ref_frame_config) {
       int ref = svc_set_references_external_ref_frame_config(cpi);
       av1_use_as_reference(&ext_flags->ref_frame_flags, ref);
     }
+#endif  // CONFIG_SVC_ENCODER
   }
 
   if (flags &
@@ -3845,12 +3953,15 @@
     ext_refresh_frame_flags->alt2_ref_frame = (upd & AOM_ALT2_FLAG) != 0;
     ext_refresh_frame_flags->update_pending = 1;
   } else {
+#if CONFIG_SVC_ENCODER
     if (cpi->svc.external_ref_frame_config)
       svc_set_updates_external_ref_frame_config(ext_refresh_frame_flags,
                                                 &cpi->svc);
     else
+#endif  // CONFIG_SVC_ENCODER
       ext_refresh_frame_flags->update_pending = 0;
   }
+#endif  // CONFIG_NEW_REF_SIGNALING
 
   ext_flags->use_ref_frame_mvs = cpi->oxcf.tool_cfg.enable_ref_frame_mvs &
                                  ((flags & AOM_EFLAG_NO_REF_FRAME_MVS) == 0);
diff --git a/av1/encoder/encoder.h b/av1/encoder/encoder.h
index 71a1158..a785c25 100644
--- a/av1/encoder/encoder.h
+++ b/av1/encoder/encoder.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 /*!\file
@@ -27,6 +28,7 @@
 #include "av1/common/blockd.h"
 #include "av1/common/entropymode.h"
 #include "av1/common/enums.h"
+#include "av1/common/pred_common.h"
 #include "av1/common/resize.h"
 #include "av1/common/thread_common.h"
 #include "av1/common/timing.h"
@@ -43,7 +45,9 @@
 #include "av1/encoder/ratectrl.h"
 #include "av1/encoder/rd.h"
 #include "av1/encoder/speed_features.h"
+#if CONFIG_SVC_ENCODER
 #include "av1/encoder/svc_layercontext.h"
+#endif  // CONFIG_SVC_ENCODER
 #include "av1/encoder/tokenize.h"
 #include "av1/encoder/tpl_model.h"
 #include "av1/encoder/av1_noise_estimate.h"
@@ -278,6 +282,12 @@
    */
   bool enable_orip;
 #endif
+#if CONFIG_IBP_DC || CONFIG_IBP_DIR
+  /*!
+   * Flag to indicate if IBP should be enabled
+   */
+  bool enable_ibp;
+#endif
 } IntraModeCfg;
 
 /*!
@@ -328,12 +338,6 @@
  * \brief Encoder flags for compound prediction modes.
  */
 typedef struct {
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-  /*!
-   * Flag to indicate if distance-weighted compound type should be enabled.
-   */
-  bool enable_dist_wtd_comp;
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
   /*!
    * Flag to indicate if masked (wedge/diff-wtd) compound type should be
    * enabled.
@@ -650,6 +654,9 @@
   bool enable_reduced_reference_set;
   // Indicates if one-sided compound should be enabled.
   bool enable_onesided_comp;
+#if CONFIG_NEW_REF_SIGNALING
+  bool explicit_ref_frame_map;
+#endif  // CONFIG_NEW_REF_SIGNALING
 } RefFrameCfg;
 
 typedef struct {
@@ -833,6 +840,14 @@
 #if CONFIG_NEW_INTER_MODES
   unsigned int max_drl_refmvs;
 #endif  // CONFIG_NEW_INTER_MODES
+#if CONFIG_REF_MV_BANK
+  // Indicates if ref MV Bank should be enabled.
+  bool enable_refmvbank;
+#endif  // CONFIG_REF_MV_BANK
+#if CONFIG_OPTFLOW_REFINEMENT
+  // Indicates if optical flow refinement should be enabled
+  aom_opfl_refine_type enable_opfl_refine;
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 } ToolCfg;
 
 #define MAX_SUBGOP_CONFIGS 64
@@ -1158,9 +1173,17 @@
                                      [PALETTE_COLORS];
   unsigned int partition[PARTITION_CONTEXTS][EXT_PARTITION_TYPES];
   unsigned int txb_skip[TOKEN_CDF_Q_CTXS][TX_SIZES][TXB_SKIP_CONTEXTS][2];
+#if CONFIG_CONTEXT_DERIVATION
+  unsigned int v_txb_skip[TOKEN_CDF_Q_CTXS][V_TXB_SKIP_CONTEXTS][2];
+#endif
   unsigned int eob_extra[TOKEN_CDF_Q_CTXS][TX_SIZES][PLANE_TYPES]
                         [EOB_COEF_CONTEXTS][2];
-  unsigned int dc_sign[PLANE_TYPES][DC_SIGN_CONTEXTS][2];
+  unsigned int dc_sign[TOKEN_CDF_Q_CTXS][PLANE_TYPES][DC_SIGN_CONTEXTS][2];
+#if CONFIG_CONTEXT_DERIVATION
+  unsigned int v_dc_sign[TOKEN_CDF_Q_CTXS][CROSS_COMPONENT_CONTEXTS]
+                        [DC_SIGN_CONTEXTS][2];
+  unsigned int v_ac_sign[TOKEN_CDF_Q_CTXS][CROSS_COMPONENT_CONTEXTS][2];
+#endif  // CONFIG_CONTEXT_DERIVATION
   unsigned int coeff_lps[TX_SIZES][PLANE_TYPES][BR_CDF_SIZE - 1][LEVEL_CONTEXTS]
                         [2];
   unsigned int eob_flag[TX_SIZES][PLANE_TYPES][EOB_COEF_CONTEXTS][2];
@@ -1187,8 +1210,14 @@
   unsigned int refmv_mode[REFMV_MODE_CONTEXTS][2];
   unsigned int drl_mode[DRL_MODE_CONTEXTS][2];
 #endif  // CONFIG_NEW_INTER_MODES
+#if CONFIG_OPTFLOW_REFINEMENT
+  unsigned int use_optflow[INTER_COMPOUND_MODE_CONTEXTS][2];
+  unsigned int inter_compound_mode[INTER_COMPOUND_MODE_CONTEXTS]
+                                  [INTER_COMPOUND_REF_TYPES];
+#else
   unsigned int inter_compound_mode[INTER_COMPOUND_MODE_CONTEXTS]
                                   [INTER_COMPOUND_MODES];
+#endif  // CONFIG_OPTFLOW_REFINEMENT
   unsigned int wedge_idx[BLOCK_SIZES_ALL][16];
   unsigned int interintra[BLOCK_SIZE_GROUPS][2];
   unsigned int interintra_mode[BLOCK_SIZE_GROUPS][INTERINTRA_MODES];
@@ -1196,13 +1225,24 @@
   unsigned int compound_type[BLOCK_SIZES_ALL][MASKED_COMPOUND_TYPES];
   unsigned int motion_mode[BLOCK_SIZES_ALL][MOTION_MODES];
   unsigned int obmc[BLOCK_SIZES_ALL][2];
+#if CONFIG_CONTEXT_DERIVATION
+  unsigned int intra_inter[INTRA_INTER_SKIP_TXFM_CONTEXTS][INTRA_INTER_CONTEXTS]
+                          [2];
+#else
   unsigned int intra_inter[INTRA_INTER_CONTEXTS][2];
+#endif
   unsigned int comp_inter[COMP_INTER_CONTEXTS][2];
+#if CONFIG_NEW_REF_SIGNALING
+  unsigned int single_ref[REF_CONTEXTS][INTER_REFS_PER_FRAME - 1][2];
+  unsigned int comp_ref[REF_CONTEXTS][COMPREF_BIT_TYPES]
+                       [INTER_REFS_PER_FRAME - 2][2];
+#else
   unsigned int comp_ref_type[COMP_REF_TYPE_CONTEXTS][2];
   unsigned int uni_comp_ref[UNI_COMP_REF_CONTEXTS][UNIDIR_COMP_REFS - 1][2];
   unsigned int single_ref[REF_CONTEXTS][SINGLE_REFS - 1][2];
   unsigned int comp_ref[REF_CONTEXTS][FWD_REFS - 1][2];
   unsigned int comp_bwdref[REF_CONTEXTS][BWD_REFS - 1][2];
+#endif  // CONFIG_NEW_REF_SIGNALING
   unsigned int intrabc[2];
 
 #if CONFIG_NEW_TX_PARTITION
@@ -1218,7 +1258,6 @@
 #endif  // CONFIG_NEW_TX_PARTITION
   unsigned int skip_mode[SKIP_MODE_CONTEXTS][2];
   unsigned int skip_txfm[SKIP_CONTEXTS][2];
-  unsigned int compound_index[COMP_INDEX_CONTEXTS][2];
   unsigned int comp_group_idx[COMP_GROUP_IDX_CONTEXTS][2];
   unsigned int delta_q[DELTA_Q_PROBS][2];
   unsigned int delta_lf_multi[FRAME_LF_COUNT][DELTA_LF_PROBS][2];
@@ -1263,7 +1302,11 @@
 } RdIdxPair;
 // TODO(angiebird): This is an estimated size. We still need to figure what is
 // the maximum number of modes.
+#if CONFIG_OPTFLOW_REFINEMENT
+#define MAX_INTER_MODES 1536
+#else
 #define MAX_INTER_MODES 1024
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 // TODO(any): rename this struct to something else. There is already another
 // struct called inter_mode_info, which makes this terribly confusing.
 /*!\endcond */
@@ -1441,7 +1484,11 @@
 typedef struct RD_COUNTS {
   int64_t comp_pred_diff[REFERENCE_MODES];
   // Stores number of 4x4 blocks using global motion per reference frame.
+#if CONFIG_NEW_REF_SIGNALING
+  int global_motion_used[INTER_REFS_PER_FRAME];
+#else
   int global_motion_used[REF_FRAMES];
+#endif  // CONFIG_NEW_REF_SIGNALING
   int compound_ref_used_flag;
   int skip_mode_used_flag;
   int tx_type_used[TX_SIZES_ALL][TX_TYPES];
@@ -1759,7 +1806,11 @@
    * each reference frame. gmparams_cost[i] stores the cost of signalling global
    * motion for the ith reference frame.
    */
+#if CONFIG_NEW_REF_SIGNALING
+  int params_cost[INTER_REFS_PER_FRAME];
+#else
   int params_cost[REF_FRAMES];
+#endif  // CONFIG_NEW_REF_SIGNALING
 
   /*!
    * Flag to indicate if global motion search needs to be rerun.
@@ -1771,7 +1822,11 @@
    * ref_buf[i] stores the pointer to the reference frame of the ith
    * reference frame type.
    */
+#if CONFIG_NEW_REF_SIGNALING
+  YV12_BUFFER_CONFIG *ref_buf[INTER_REFS_PER_FRAME];
+#else
   YV12_BUFFER_CONFIG *ref_buf[REF_FRAMES];
+#endif  // CONFIG_NEW_REF_SIGNALING
 
   /*!
    * Pointer to the source frame buffer.
@@ -1791,7 +1846,11 @@
    * reference_frames[i][j] holds the jth valid reference frame type in the
    * direction 'i' and its temporal distance from the source frame .
    */
+#if CONFIG_NEW_REF_SIGNALING
+  FrameDistPair reference_frames[MAX_DIRECTIONS][INTER_REFS_PER_FRAME];
+#else
   FrameDistPair reference_frames[MAX_DIRECTIONS][REF_FRAMES - 1];
+#endif  // CONFIG_NEW_REF_SIGNALING
 
   /**
    * \name Dimensions for which segment map is allocated.
@@ -1877,6 +1936,7 @@
   search_site_config search_site_cfg[SS_CFG_TOTAL][NUM_DISTINCT_SEARCH_METHODS];
 } MotionVectorSearchParams;
 
+#if !CONFIG_NEW_REF_SIGNALING
 /*!
  * \brief Refresh frame flags for different type of frames.
  *
@@ -1890,6 +1950,7 @@
   bool bwd_ref_frame; /*!< Refresh flag for bwd-ref frame */
   bool alt_ref_frame; /*!< Refresh flag for alt-ref frame */
 } RefreshFrameFlagsInfo;
+#endif  // !CONFIG_NEW_REF_SIGNALING
 
 /*!
  * \brief Desired dimensions for an externally triggered resize.
@@ -1995,11 +2056,13 @@
  * reference frame buffer with the contents of the current frame.
  */
 typedef struct {
+#if !CONFIG_NEW_REF_SIGNALING
   bool last_frame;     /*!< Refresh flag for last frame */
   bool golden_frame;   /*!< Refresh flag for golden frame */
   bool bwd_ref_frame;  /*!< Refresh flag for bwd-ref frame */
   bool alt2_ref_frame; /*!< Refresh flag for alt2-ref frame */
   bool alt_ref_frame;  /*!< Refresh flag for alt-ref frame */
+#endif                 // !CONFIG_NEW_REF_SIGNALING
   /*!
    * Flag indicating if the update of refresh frame flags is pending.
    */
@@ -2266,10 +2329,12 @@
    */
   RefCntBuffer *last_show_frame_buf;
 
+#if !CONFIG_NEW_REF_SIGNALING
   /*!
    * Refresh frame flags for golden, bwd-ref and alt-ref frames.
    */
   RefreshFrameFlagsInfo refresh_frame;
+#endif  // !CONFIG_NEW_REF_SIGNALING
 
   /*!
    * For each type of reference frame, this contains the index of a reference
@@ -2344,11 +2409,6 @@
   struct aom_codec_pkt_list *output_pkt_list;
 
   /*!
-   * Bitmask indicating which reference buffers may be referenced by this frame.
-   */
-  int ref_frame_flags;
-
-  /*!
    * speed is passed as a per-frame parameter into the encoder.
    */
   int speed;
@@ -2436,8 +2496,9 @@
   /*!\cond */
   uint64_t time_receive_data;
   uint64_t time_compress_data;
-
+#if !CONFIG_NEW_REF_SIGNALING
   unsigned int mode_chosen_counts[MAX_MODES];
+#endif  // !CONFIG_NEW_REF_SIGNALING
 
   int count;
   uint64_t total_sq_error;
@@ -2668,6 +2729,7 @@
   TuneVMAFInfo vmaf_info;
 #endif
 
+#if CONFIG_SVC_ENCODER
   /*!
    * Indicates whether to use SVC.
    */
@@ -2676,6 +2738,7 @@
    * Parameters for scalable video coding.
    */
   SVC svc;
+#endif  // CONFIG_SVC_ENCODER
 
   /*!
    * Flag indicating whether look ahead processing (LAP) is enabled.
@@ -2784,11 +2847,13 @@
    */
   int remapped_ref_idx[REF_FRAMES];
 
+#if !CONFIG_NEW_REF_SIGNALING
   /*!
    *  Flags which determine which reference buffers are refreshed by this
    *  frame.
    */
   RefreshFrameFlagsInfo refresh_frame;
+#endif  // !CONFIG_NEW_REF_SIGNALING
 
   /*!
    *  Speed level to use for this frame: Bigger number means faster.
@@ -2821,8 +2886,13 @@
 void av1_check_initial_width(AV1_COMP *cpi, int use_highbitdepth,
                              int subsampling_x, int subsampling_y);
 
+#if CONFIG_SVC_ENCODER
 void av1_init_seq_coding_tools(SequenceHeader *seq, AV1_COMMON *cm,
                                const AV1EncoderConfig *oxcf, int use_svc);
+#else
+void av1_init_seq_coding_tools(SequenceHeader *seq, AV1_COMMON *cm,
+                               const AV1EncoderConfig *oxcf);
+#endif  // CONFIG_SVC_ENCODER
 
 /*!\endcond */
 
@@ -2929,45 +2999,6 @@
 void av1_set_screen_content_options(const struct AV1_COMP *cpi,
                                     FeatureFlags *features);
 
-typedef struct {
-  int pyr_level;
-  int disp_order;
-} RefFrameMapPair;
-
-static INLINE void init_ref_map_pair(
-    AV1_COMP *cpi, RefFrameMapPair ref_frame_map_pairs[REF_FRAMES]) {
-  if (cpi->gf_group.update_type[cpi->gf_group.index] == KF_UPDATE) {
-    memset(ref_frame_map_pairs, -1, sizeof(*ref_frame_map_pairs) * REF_FRAMES);
-    return;
-  }
-  memset(ref_frame_map_pairs, 0, sizeof(*ref_frame_map_pairs) * REF_FRAMES);
-  for (int map_idx = 0; map_idx < REF_FRAMES; map_idx++) {
-    // Get reference frame buffer
-    const RefCntBuffer *const buf = cpi->common.ref_frame_map[map_idx];
-    if (ref_frame_map_pairs[map_idx].disp_order == -1) continue;
-    if (buf == NULL) {
-      ref_frame_map_pairs[map_idx].disp_order = -1;
-      ref_frame_map_pairs[map_idx].pyr_level = -1;
-      continue;
-    } else if (buf->ref_count > 1) {
-      // Once the keyframe is coded, the slots in ref_frame_map will all
-      // point to the same frame. In that case, all subsequent pointers
-      // matching the current are considered "free" slots. This will find
-      // the next occurance of the current pointer if ref_count indicates
-      // there are multiple instances of it and mark it as free.
-      for (int idx2 = map_idx + 1; idx2 < REF_FRAMES; ++idx2) {
-        const RefCntBuffer *const buf2 = cpi->common.ref_frame_map[idx2];
-        if (buf2 == buf) {
-          ref_frame_map_pairs[idx2].disp_order = -1;
-          ref_frame_map_pairs[idx2].pyr_level = -1;
-        }
-      }
-    }
-    ref_frame_map_pairs[map_idx].disp_order = (int)buf->display_order_hint;
-    ref_frame_map_pairs[map_idx].pyr_level = buf->pyramid_level;
-  }
-}
-
 // av1 uses 10,000,000 ticks/second as time stamp
 #define TICKS_PER_SEC 10000000LL
 
@@ -3007,12 +3038,20 @@
 static INLINE int enc_is_ref_frame_buf(const AV1_COMMON *const cm,
                                        const RefCntBuffer *const frame_buf) {
   MV_REFERENCE_FRAME ref_frame;
+#if CONFIG_NEW_REF_SIGNALING
+  for (ref_frame = 0; ref_frame < INTER_REFS_PER_FRAME; ++ref_frame) {
+#else
   for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
+#endif  // CONFIG_NEW_REF_SIGNALING
     const RefCntBuffer *const buf = get_ref_frame_buf(cm, ref_frame);
     if (buf == NULL) continue;
     if (frame_buf == buf) break;
   }
+#if CONFIG_NEW_REF_SIGNALING
+  return (ref_frame < INTER_REFS_PER_FRAME);
+#else
   return (ref_frame <= ALTREF_FRAME);
+#endif  // CONFIG_NEW_REF_SIGNALING
 }
 
 static INLINE void alloc_frame_mvs(AV1_COMMON *const cm, RefCntBuffer *buf) {
@@ -3093,10 +3132,17 @@
 static INLINE void set_ref_ptrs(const AV1_COMMON *cm, MACROBLOCKD *xd,
                                 MV_REFERENCE_FRAME ref0,
                                 MV_REFERENCE_FRAME ref1) {
+#if CONFIG_NEW_REF_SIGNALING
+  xd->block_ref_scale_factors[0] =
+      get_ref_scale_factors_const(cm, ref0 < INTER_REFS_PER_FRAME ? ref0 : 0);
+  xd->block_ref_scale_factors[1] =
+      get_ref_scale_factors_const(cm, ref1 < INTER_REFS_PER_FRAME ? ref1 : 0);
+#else
   xd->block_ref_scale_factors[0] =
       get_ref_scale_factors_const(cm, ref0 >= LAST_FRAME ? ref0 : 1);
   xd->block_ref_scale_factors[1] =
       get_ref_scale_factors_const(cm, ref1 >= LAST_FRAME ? ref1 : 1);
+#endif  // CONFIG_NEW_REF_SIGNALING
 }
 
 static INLINE int get_chessboard_index(int frame_index) {
@@ -3187,6 +3233,7 @@
   return (BLOCK_SIZE)int_size;
 }
 
+#if !CONFIG_NEW_REF_SIGNALING
 static const uint8_t av1_ref_frame_flag_list[REF_FRAMES] = { 0,
                                                              AOM_LAST_FLAG,
                                                              AOM_LAST2_FLAG,
@@ -3205,14 +3252,6 @@
   GOLDEN_FRAME,
 };
 
-static INLINE int get_max_allowed_ref_frames(
-    int selective_ref_frame, unsigned int max_reference_frames) {
-  const unsigned int max_allowed_refs_for_given_speed =
-      (selective_ref_frame >= 3) ? INTER_REFS_PER_FRAME - 1
-                                 : INTER_REFS_PER_FRAME;
-  return AOMMIN(max_allowed_refs_for_given_speed, max_reference_frames);
-}
-
 static const MV_REFERENCE_FRAME
     ref_frame_priority_order[INTER_REFS_PER_FRAME] = {
       LAST_FRAME,    ALTREF_FRAME, BWDREF_FRAME, GOLDEN_FRAME,
@@ -3240,6 +3279,15 @@
   }
   return flags;
 }
+#endif  // !CONFIG_NEW_REF_SIGNALING
+
+static INLINE int get_max_allowed_ref_frames(
+    int selective_ref_frame, unsigned int max_reference_frames) {
+  const unsigned int max_allowed_refs_for_given_speed =
+      (selective_ref_frame >= 3) ? INTER_REFS_PER_FRAME - 1
+                                 : INTER_REFS_PER_FRAME;
+  return AOMMIN(max_allowed_refs_for_given_speed, max_reference_frames);
+}
 
 // Enforce the number of references for each arbitrary frame based on user
 // options and speed.
@@ -3248,23 +3296,34 @@
   MV_REFERENCE_FRAME ref_frame;
   int total_valid_refs = 0;
 
+#if CONFIG_NEW_REF_SIGNALING
+  for (ref_frame = 0; ref_frame < INTER_REFS_PER_FRAME; ++ref_frame) {
+    if (*ref_frame_flags & (1 << ref_frame)) {
+      total_valid_refs++;
+    }
+  }
+#else
   for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
     if (*ref_frame_flags & av1_ref_frame_flag_list[ref_frame]) {
       total_valid_refs++;
     }
   }
+#endif  // CONFIG_NEW_REF_SIGNALING
 
   const int max_allowed_refs =
       get_max_allowed_ref_frames(cpi->sf.inter_sf.selective_ref_frame,
                                  cpi->oxcf.ref_frm_cfg.max_reference_frames);
 
   for (int i = 0; i < 4 && total_valid_refs > max_allowed_refs; ++i) {
-    const MV_REFERENCE_FRAME ref_frame_to_disable = disable_order[i];
+    const MV_REFERENCE_FRAME ref_frame_to_disable =
+        INTER_REFS_PER_FRAME - i - 1;
 
-    if (!(*ref_frame_flags & av1_ref_frame_flag_list[ref_frame_to_disable])) {
+    if (!(*ref_frame_flags & (1 << ref_frame_to_disable))) {
       continue;
     }
-
+#if CONFIG_NEW_REF_SIGNALING
+    *ref_frame_flags &= ~(1 << ref_frame_to_disable);
+#else
     switch (ref_frame_to_disable) {
       case LAST3_FRAME: *ref_frame_flags &= ~AOM_LAST3_FLAG; break;
       case LAST2_FRAME: *ref_frame_flags &= ~AOM_LAST2_FLAG; break;
@@ -3272,9 +3331,9 @@
       case GOLDEN_FRAME: *ref_frame_flags &= ~AOM_GOLD_FLAG; break;
       default: assert(0);
     }
+#endif  // CONFIG_NEW_REF_SIGNALING
     --total_valid_refs;
   }
-  assert(total_valid_refs <= max_allowed_refs);
 }
 
 // Returns a Sequence Header OBU stored in an aom_fixed_buf_t, or NULL upon
diff --git a/av1/encoder/encoder_alloc.h b/av1/encoder/encoder_alloc.h
index b4291d2..bbb2266 100644
--- a/av1/encoder/encoder_alloc.h
+++ b/av1/encoder/encoder_alloc.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_ENCODER_ALLOC_H_
@@ -318,7 +319,9 @@
     aom_free(cpi->level_params.level_info[i]);
   }
 
+#if CONFIG_SVC_ENCODER
   if (cpi->use_svc) av1_free_svc_cyclic_refresh(cpi);
+#endif  // CONFIG_SVC_ENCODE
 
   if (cpi->consec_zero_mv) {
     aom_free(cpi->consec_zero_mv);
diff --git a/av1/encoder/encoder_utils.c b/av1/encoder/encoder_utils.c
index 5a3466d..d9e00d8 100644
--- a/av1/encoder/encoder_utils.c
+++ b/av1/encoder/encoder_utils.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "aom_ports/system_state.h"
@@ -496,15 +497,25 @@
   const int num_planes = av1_num_planes(cm);
   MV_REFERENCE_FRAME ref_frame;
 
+#if CONFIG_NEW_REF_SIGNALING
+  for (ref_frame = 0; ref_frame < INTER_REFS_PER_FRAME; ++ref_frame) {
+    // Need to convert from AOM_REFFRAME to index into ref_mask (subtract 1).
+    if (cm->ref_frame_flags & (1 << ref_frame)) {
+#else
   for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
     // Need to convert from AOM_REFFRAME to index into ref_mask (subtract 1).
-    if (cpi->ref_frame_flags & av1_ref_frame_flag_list[ref_frame]) {
+    if (cm->ref_frame_flags & av1_ref_frame_flag_list[ref_frame]) {
+#endif  // CONFIG_NEW_REF_SIGNALING
       BufferPool *const pool = cm->buffer_pool;
       const YV12_BUFFER_CONFIG *const ref =
           get_ref_frame_yv12_buf(cm, ref_frame);
 
       if (ref == NULL) {
+#if CONFIG_NEW_REF_SIGNALING
+        cpi->scaled_ref_buf[ref_frame] = NULL;
+#else
         cpi->scaled_ref_buf[ref_frame - 1] = NULL;
+#endif  // CONFIG_NEW_REF_SIGNALING
         continue;
       }
 
@@ -524,7 +535,11 @@
           }
         }
         int force_scaling = 0;
+#if CONFIG_NEW_REF_SIGNALING
+        RefCntBuffer *new_fb = cpi->scaled_ref_buf[ref_frame];
+#else
         RefCntBuffer *new_fb = cpi->scaled_ref_buf[ref_frame - 1];
+#endif  // CONFIG_NEW_REF_SIGNALING
         if (new_fb == NULL) {
           const int new_fb_idx = get_free_fb(cm);
           if (new_fb_idx == INVALID_IDX) {
@@ -555,18 +570,30 @@
           else
             av1_resize_and_extend_frame_nonnormative(
                 ref, &new_fb->buf, (int)cm->seq_params.bit_depth, num_planes);
+#if CONFIG_NEW_REF_SIGNALING
+          cpi->scaled_ref_buf[ref_frame] = new_fb;
+#else
           cpi->scaled_ref_buf[ref_frame - 1] = new_fb;
+#endif  // CONFIG_NEW_REF_SIGNALING
           alloc_frame_mvs(cm, new_fb);
         }
       } else {
         RefCntBuffer *buf = get_ref_frame_buf(cm, ref_frame);
         buf->buf.y_crop_width = ref->y_crop_width;
         buf->buf.y_crop_height = ref->y_crop_height;
+#if CONFIG_NEW_REF_SIGNALING
+        cpi->scaled_ref_buf[ref_frame] = buf;
+#else
         cpi->scaled_ref_buf[ref_frame - 1] = buf;
+#endif  // CONFIG_NEW_REF_SIGNALING
         ++buf->ref_count;
       }
     } else {
+#if CONFIG_NEW_REF_SIGNALING
+      if (!has_no_stats_stage(cpi)) cpi->scaled_ref_buf[ref_frame] = NULL;
+#else
       if (!has_no_stats_stage(cpi)) cpi->scaled_ref_buf[ref_frame - 1] = NULL;
+#endif  // CONFIG_NEW_REF_SIGNALING
     }
   }
 }
@@ -582,7 +609,10 @@
 
   assert(oxcf->tool_cfg.superblock_size == AOM_SUPERBLOCK_SIZE_DYNAMIC);
 
-  if (cpi->svc.number_spatial_layers > 1 ||
+  if (
+#if CONFIG_SVC_ENCODER
+      cpi->svc.number_spatial_layers > 1 ||
+#endif  // CONFIG_SVC_ENCODER
       oxcf->resize_cfg.resize_mode != RESIZE_NONE) {
     // Use the configured size (top resolution) for spatial layers or
     // on resize.
@@ -843,7 +873,11 @@
                                        int *const gm_params_cost) {
   int i;
   int recode = 0;
+#if CONFIG_NEW_REF_SIGNALING
+  for (i = 0; i < INTER_REFS_PER_FRAME; ++i) {
+#else
   for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) {
+#endif  // CONFIG_NEW_REF_SIGNALING
     if (global_motion[i].wmtype != IDENTITY &&
         global_motion_used[i] * GM_RECODE_LOOP_NUM4X4_FACTOR <
             gm_params_cost[i]) {
diff --git a/av1/encoder/encoder_utils.h b/av1/encoder/encoder_utils.h
index 60f9096..94e8f48 100644
--- a/av1/encoder/encoder_utils.h
+++ b/av1/encoder/encoder_utils.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_ENCODER_UTILS_H_
@@ -117,7 +118,11 @@
 static AOM_INLINE void init_buffer_indices(
     ForceIntegerMVInfo *const force_intpel_info, int *const remapped_ref_idx) {
   int fb_idx;
+#if CONFIG_NEW_REF_SIGNALING
+  for (fb_idx = 0; fb_idx < INTER_REFS_PER_FRAME; ++fb_idx)
+#else
   for (fb_idx = 0; fb_idx < REF_FRAMES; ++fb_idx)
+#endif  // CONFIG_NEW_REF_SIGNALING
     remapped_ref_idx[fb_idx] = fb_idx;
   force_intpel_info->rate_index = 0;
   force_intpel_info->rate_size = 0;
@@ -868,7 +873,11 @@
 static AOM_INLINE void set_size_independent_vars(AV1_COMP *cpi) {
   int i;
   AV1_COMMON *const cm = &cpi->common;
+#if CONFIG_NEW_REF_SIGNALING
+  for (i = 0; i < INTER_REFS_PER_FRAME; ++i) {
+#else
   for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) {
+#endif  // CONFIG_NEW_REF_SIGNALING
     cm->global_motion[i] = default_warp_params;
   }
   cpi->gm_info.search_done = 0;
@@ -877,6 +886,9 @@
   av1_set_rd_speed_thresholds(cpi);
   cm->features.interp_filter = SWITCHABLE;
   cm->features.switchable_motion_mode = 1;
+#if CONFIG_OPTFLOW_REFINEMENT
+  cm->features.opfl_refine_type = REFINE_SWITCHABLE;
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 }
 
 static AOM_INLINE void release_scaled_references(AV1_COMP *cpi) {
diff --git a/av1/encoder/encodetxb.c b/av1/encoder/encodetxb.c
index 3bffabd..3905650 100644
--- a/av1/encoder/encodetxb.c
+++ b/av1/encoder/encodetxb.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "av1/encoder/encodetxb.h"
@@ -329,6 +330,12 @@
                           int block, TX_SIZE tx_size) {
   MACROBLOCKD *xd = &x->e_mbd;
   const CB_COEFF_BUFFER *cb_coef_buff = x->cb_coef_buff;
+#if CONFIG_CONTEXT_DERIVATION
+  const int width = get_txb_wide(tx_size);
+  const int height = get_txb_high(tx_size);
+  if (plane == AOM_PLANE_U)
+    memset(xd->tmp_sign, 0, width * height * sizeof(int32_t));
+#endif  // CONFIG_CONTEXT_DERIVATION
 #if CONFIG_SDP
   const int txb_offset =
       x->mbmi_ext_frame->cb_offset[plane > 0 && xd->tree_type == CHROMA_PART] /
@@ -340,10 +347,30 @@
   const uint16_t *eob_txb = cb_coef_buff->eobs[plane] + txb_offset;
   const uint16_t eob = eob_txb[block];
   const uint8_t *entropy_ctx = cb_coef_buff->entropy_ctx[plane] + txb_offset;
+#if CONFIG_CONTEXT_DERIVATION
+  int txb_skip_ctx = (entropy_ctx[block] & TXB_SKIP_CTX_MASK);
+  if (plane == AOM_PLANE_V) {
+    txb_skip_ctx += (xd->eob_u_flag ? V_TXB_SKIP_CONTEXT_OFFSET : 0);
+  }
+#else
   const int txb_skip_ctx = entropy_ctx[block] & TXB_SKIP_CTX_MASK;
+#endif  // CONFIG_CONTEXT_DERIVATION
   const TX_SIZE txs_ctx = get_txsize_entropy_ctx(tx_size);
   FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
+
+#if CONFIG_CONTEXT_DERIVATION
+  if (plane == AOM_PLANE_U) {
+    xd->eob_u_flag = eob ? 1 : 0;
+  }
+  if (plane == AOM_PLANE_Y || plane == AOM_PLANE_U) {
+    aom_write_symbol(w, eob == 0, ec_ctx->txb_skip_cdf[txs_ctx][txb_skip_ctx],
+                     2);
+  } else {
+    aom_write_symbol(w, eob == 0, ec_ctx->v_txb_skip_cdf[txb_skip_ctx], 2);
+  }
+#else
   aom_write_symbol(w, eob == 0, ec_ctx->txb_skip_cdf[txs_ctx][txb_skip_ctx], 2);
+#endif  // CONFIG_CONTEXT_DERIVATION
   if (eob == 0) return;
 
   const PLANE_TYPE plane_type = get_plane_type(plane);
@@ -426,8 +453,10 @@
   fprintf(cm->fEncCoeffLog, "tx_type=%d, eob=%d\n", tx_type, eob);
 #endif
 
+#if !CONFIG_CONTEXT_DERIVATION
   const int width = get_txb_wide(tx_size);
   const int height = get_txb_high(tx_size);
+#endif  // CONFIG_CONTEXT_DERIVATION
   uint8_t levels_buf[TX_PAD_2D];
   uint8_t *const levels = set_levels(levels_buf, width);
 #if CONFIG_SDP
@@ -494,10 +523,30 @@
       if (c == 0) {
         const int dc_sign_ctx =
             (entropy_ctx[block] >> DC_SIGN_CTX_SHIFT) & DC_SIGN_CTX_MASK;
+#if CONFIG_CONTEXT_DERIVATION
+        if (plane == AOM_PLANE_U) xd->tmp_sign[0] = (sign ? 2 : 1);
+        if (plane == AOM_PLANE_V) {
+          aom_write_symbol(
+              w, sign, ec_ctx->v_dc_sign_cdf[xd->tmp_sign[0]][dc_sign_ctx], 2);
+        } else {
+          aom_write_symbol(w, sign,
+                           ec_ctx->dc_sign_cdf[plane_type][dc_sign_ctx], 2);
+        }
+#else
         aom_write_symbol(w, sign, ec_ctx->dc_sign_cdf[plane_type][dc_sign_ctx],
                          2);
+#endif  // CONFIG_CONTEXT_DERIVATION
       } else {
+#if CONFIG_CONTEXT_DERIVATION
+        if (plane == AOM_PLANE_U) xd->tmp_sign[scan[c]] = (sign ? 2 : 1);
+        if (plane == AOM_PLANE_Y || plane == AOM_PLANE_U)
+          aom_write_bit(w, sign);
+        else
+          aom_write_symbol(w, sign,
+                           ec_ctx->v_ac_sign_cdf[xd->tmp_sign[scan[c]]], 2);
+#else
         aom_write_bit(w, sign);
+#endif  // CONFIG_CONTEXT_DERIVATION
       }
       if (level > COEFF_BASE_RANGE + NUM_BASE_LEVELS)
         write_golomb(w, level - COEFF_BASE_RANGE - 1 - NUM_BASE_LEVELS);
@@ -674,7 +723,15 @@
     const MACROBLOCKD *const xd, const TX_TYPE tx_type, const TX_CLASS tx_class,
     int reduced_tx_set_used) {
   const tran_low_t *const qcoeff = p->qcoeff + BLOCK_OFFSET(block);
+#if CONFIG_CONTEXT_DERIVATION
+  const struct macroblock_plane *pu = &x->plane[AOM_PLANE_U];
+  int txb_skip_ctx = txb_ctx->txb_skip_ctx;
+  if (plane == AOM_PLANE_V) {
+    txb_skip_ctx += (pu->eobs[block] ? V_TXB_SKIP_CONTEXT_OFFSET : 0);
+  }
+#else
   const int txb_skip_ctx = txb_ctx->txb_skip_ctx;
+#endif  // CONFIG_CONTEXT_DERIVATION
   const int bwl = get_txb_bwl(tx_size);
   const int width = get_txb_wide(tx_size);
   const int height = get_txb_high(tx_size);
@@ -686,7 +743,16 @@
   const int eob_multi_size = txsize_log2_minus4[tx_size];
   const LV_MAP_EOB_COST *const eob_costs =
       &x->coeff_costs.eob_costs[eob_multi_size][plane_type];
+#if CONFIG_CONTEXT_DERIVATION
+  int cost;
+  if (plane == AOM_PLANE_V) {
+    cost = coeff_costs->v_txb_skip_cost[txb_skip_ctx][0];
+  } else {
+    cost = coeff_costs->txb_skip_cost[txb_skip_ctx][0];
+  }
+#else
   int cost = coeff_costs->txb_skip_cost[txb_skip_ctx][0];
+#endif  // CONFIG_CONTEXT_DERIVATION
 
   av1_txb_init_levels(qcoeff, width, height, levels);
 
@@ -719,11 +785,29 @@
         cost += get_br_cost(level, lps_cost[ctx]);
       }
       if (c) {
+#if CONFIG_CONTEXT_DERIVATION
+        if (plane == AOM_PLANE_V) {
+          const int sign01 = (sign ^ sign) - sign;
+          cost += coeff_costs->v_ac_sign_cost[xd->tmp_sign[pos]][sign01];
+        } else {
+          cost += av1_cost_literal(1);
+        }
+#else
         cost += av1_cost_literal(1);
+#endif  // CONFIG_CONTEXT_DERIVATION
       } else {
         const int sign01 = (sign ^ sign) - sign;
         const int dc_sign_ctx = txb_ctx->dc_sign_ctx;
+#if CONFIG_CONTEXT_DERIVATION
+        if (plane == AOM_PLANE_V) {
+          cost +=
+              coeff_costs->v_dc_sign_cost[xd->tmp_sign[0]][dc_sign_ctx][sign01];
+        } else {
+          cost += coeff_costs->dc_sign_cost[dc_sign_ctx][sign01];
+        }
+#else
         cost += coeff_costs->dc_sign_cost[dc_sign_ctx][sign01];
+#endif  // CONFIG_CONTEXT_DERIVATION
         return cost;
       }
     }
@@ -737,7 +821,17 @@
     cost += base_cost[coeff_ctx][AOMMIN(level, 3)];
     if (v) {
       // sign bit cost
+#if CONFIG_CONTEXT_DERIVATION
+      if (plane == AOM_PLANE_V) {
+        const int sign = AOMSIGN(v);
+        const int sign01 = (sign ^ sign) - sign;
+        cost += coeff_costs->v_ac_sign_cost[xd->tmp_sign[pos]][sign01];
+      } else {
+        cost += av1_cost_literal(1);
+      }
+#else
       cost += av1_cost_literal(1);
+#endif  // CONFIG_CONTEXT_DERIVATION
       if (level > NUM_BASE_LEVELS) {
         const int ctx = get_br_ctx(levels, pos, bwl, tx_class);
         cost += get_br_cost(level, lps_cost[ctx]);
@@ -757,7 +851,16 @@
       // sign bit cost
       const int sign01 = (sign ^ sign) - sign;
       const int dc_sign_ctx = txb_ctx->dc_sign_ctx;
+#if CONFIG_CONTEXT_DERIVATION
+      if (plane == AOM_PLANE_V) {
+        cost +=
+            coeff_costs->v_dc_sign_cost[xd->tmp_sign[0]][dc_sign_ctx][sign01];
+      } else {
+        cost += coeff_costs->dc_sign_cost[dc_sign_ctx][sign01];
+      }
+#else
       cost += coeff_costs->dc_sign_cost[dc_sign_ctx][sign01];
+#endif  // CONFIG_CONTEXT_DERIVATION
       if (level > NUM_BASE_LEVELS) {
         const int ctx = get_br_ctx(levels, pos, bwl, tx_class);
         cost += get_br_cost(level, lps_cost[ctx]);
@@ -773,12 +876,29 @@
     const PLANE_TYPE plane_type, const LV_MAP_COEFF_COST *const coeff_costs,
     const MACROBLOCKD *const xd, const TX_TYPE tx_type, const TX_CLASS tx_class,
     int reduced_tx_set_used) {
+#if CONFIG_CONTEXT_DERIVATION
+  int txb_skip_ctx = txb_ctx->txb_skip_ctx;
+  if (plane == AOM_PLANE_V) {
+    txb_skip_ctx +=
+        (x->plane[AOM_PLANE_U].eobs[block] ? V_TXB_SKIP_CONTEXT_OFFSET : 0);
+  }
+#else
   const int txb_skip_ctx = txb_ctx->txb_skip_ctx;
+#endif  // CONFIG_CONTEXT_DERIVATION
 
   const int eob_multi_size = txsize_log2_minus4[tx_size];
   const LV_MAP_EOB_COST *const eob_costs =
       &x->coeff_costs.eob_costs[eob_multi_size][plane_type];
+#if CONFIG_CONTEXT_DERIVATION
+  int cost;
+  if (plane == AOM_PLANE_V) {
+    cost = coeff_costs->v_txb_skip_cost[txb_skip_ctx][0];
+  } else {
+    cost = coeff_costs->txb_skip_cost[txb_skip_ctx][0];
+  }
+#else
   int cost = coeff_costs->txb_skip_cost[txb_skip_ctx][0];
+#endif  // CONFIG_CONTEXT_DERIVATION
 
   cost += get_tx_type_cost(x, xd, plane, tx_size, tx_type, reduced_tx_set_used
 #if CONFIG_IST
@@ -847,7 +967,18 @@
   const LV_MAP_COEFF_COST *const coeff_costs =
       &x->coeff_costs.coeff_costs[txs_ctx][plane_type];
   if (eob == 0) {
+#if CONFIG_CONTEXT_DERIVATION
+    int txb_skip_ctx = txb_ctx->txb_skip_ctx;
+    if (plane == AOM_PLANE_Y || plane == AOM_PLANE_U) {
+      return coeff_costs->txb_skip_cost[txb_skip_ctx][1];
+    } else {
+      txb_skip_ctx +=
+          (x->plane[AOM_PLANE_U].eobs[block] ? V_TXB_SKIP_CONTEXT_OFFSET : 0);
+      return coeff_costs->v_txb_skip_cost[txb_skip_ctx][1];
+    }
+#else
     return coeff_costs->txb_skip_cost[txb_ctx->txb_skip_ctx][1];
+#endif  // CONFIG_CONTEXT_DERIVATION
   }
 
   const MACROBLOCKD *const xd = &x->e_mbd;
@@ -887,7 +1018,18 @@
   const LV_MAP_COEFF_COST *const coeff_costs =
       &x->coeff_costs.coeff_costs[txs_ctx][plane_type];
   if (eob == 0) {
+#if CONFIG_CONTEXT_DERIVATION
+    int txb_skip_ctx = txb_ctx->txb_skip_ctx;
+    if (plane == AOM_PLANE_Y || plane == AOM_PLANE_U) {
+      return coeff_costs->txb_skip_cost[txb_skip_ctx][1];
+    } else {
+      txb_skip_ctx +=
+          (x->plane[AOM_PLANE_U].eobs[block] ? V_TXB_SKIP_CONTEXT_OFFSET : 0);
+      return coeff_costs->v_txb_skip_cost[txb_skip_ctx][1];
+    }
+#else
     return coeff_costs->txb_skip_cost[txb_ctx->txb_skip_ctx][1];
+#endif  // CONFIG_CONTEXT_DERIVATION
   }
 
   const MACROBLOCKD *const xd = &x->e_mbd;
@@ -930,14 +1072,33 @@
 static INLINE int get_coeff_cost_eob(int ci, tran_low_t abs_qc, int sign,
                                      int coeff_ctx, int dc_sign_ctx,
                                      const LV_MAP_COEFF_COST *txb_costs,
-                                     int bwl, TX_CLASS tx_class) {
+                                     int bwl, TX_CLASS tx_class
+#if CONFIG_CONTEXT_DERIVATION
+                                     ,
+                                     int32_t *tmp_sign, int plane
+#endif  // CONFIG_CONTEXT_DERIVATION
+) {
   int cost = 0;
   cost += txb_costs->base_eob_cost[coeff_ctx][AOMMIN(abs_qc, 3) - 1];
   if (abs_qc != 0) {
     if (ci == 0) {
+#if CONFIG_CONTEXT_DERIVATION
+      if (plane == AOM_PLANE_V)
+        cost += txb_costs->v_dc_sign_cost[tmp_sign[0]][dc_sign_ctx][sign];
+      else
+        cost += txb_costs->dc_sign_cost[dc_sign_ctx][sign];
+#else
       cost += txb_costs->dc_sign_cost[dc_sign_ctx][sign];
+#endif  // CONFIG_CONTEXT_DERIVATION
     } else {
+#if CONFIG_CONTEXT_DERIVATION
+      if (plane == AOM_PLANE_V)
+        cost += txb_costs->v_ac_sign_cost[tmp_sign[ci]][sign];
+      else
+        cost += av1_cost_literal(1);
+#else
       cost += av1_cost_literal(1);
+#endif  // CONFIG_CONTEXT_DERIVATION
     }
     if (abs_qc > NUM_BASE_LEVELS) {
       int br_ctx;
@@ -953,7 +1114,12 @@
                                          int dc_sign_ctx,
                                          const LV_MAP_COEFF_COST *txb_costs,
                                          int bwl, TX_CLASS tx_class,
-                                         const uint8_t *levels) {
+                                         const uint8_t *levels
+#if CONFIG_CONTEXT_DERIVATION
+                                         ,
+                                         int32_t *tmp_sign, int plane
+#endif  // CONFIG_CONTEXT_DERIVATION
+) {
   int cost = 0;
   if (is_last) {
     cost += txb_costs->base_eob_cost[coeff_ctx][AOMMIN(abs_qc, 3) - 1];
@@ -962,9 +1128,23 @@
   }
   if (abs_qc != 0) {
     if (ci == 0) {
+#if CONFIG_CONTEXT_DERIVATION
+      if (plane == AOM_PLANE_V)
+        cost += txb_costs->v_dc_sign_cost[tmp_sign[0]][dc_sign_ctx][sign];
+      else
+        cost += txb_costs->dc_sign_cost[dc_sign_ctx][sign];
+#else
       cost += txb_costs->dc_sign_cost[dc_sign_ctx][sign];
+#endif  // CONFIG_CONTEXT_DERIVATION
     } else {
+#if CONFIG_CONTEXT_DERIVATION
+      if (plane == AOM_PLANE_V)
+        cost += txb_costs->v_ac_sign_cost[tmp_sign[ci]][sign];
+      else
+        cost += av1_cost_literal(1);
+#else
       cost += av1_cost_literal(1);
+#endif  // CONFIG_CONTEXT_DERIVATION
     }
     if (abs_qc > NUM_BASE_LEVELS) {
       int br_ctx;
@@ -1005,7 +1185,12 @@
 #endif
     const LV_MAP_COEFF_COST *txb_costs, const tran_low_t *tcoeff,
     tran_low_t *qcoeff, tran_low_t *dqcoeff, uint8_t *levels,
-    const qm_val_t *iqmatrix) {
+    const qm_val_t *iqmatrix
+#if CONFIG_CONTEXT_DERIVATION
+    ,
+    int32_t *tmp_sign, int plane
+#endif  // CONFIG_CONTEXT_DERIVATION
+) {
   const int dqv = get_dqv(dequant, scan[si], iqmatrix);
   const int ci = scan[si];
   const tran_low_t qc = qcoeff[ci];
@@ -1023,7 +1208,12 @@
     const int64_t dist0 = get_coeff_dist(tqc, 0, shift);
     const int rate =
         get_coeff_cost_general(is_last, ci, abs_qc, sign, coeff_ctx,
-                               dc_sign_ctx, txb_costs, bwl, tx_class, levels);
+                               dc_sign_ctx, txb_costs, bwl, tx_class, levels
+#if CONFIG_CONTEXT_DERIVATION
+                               ,
+                               tmp_sign, plane
+#endif  // CONFIG_CONTEXT_DERIVATION
+        );
     const int64_t rd = RDCOST(rdmult, rate, dist);
 
     tran_low_t qc_low, dqc_low;
@@ -1040,7 +1230,12 @@
       dist_low = get_coeff_dist(tqc, dqc_low, shift);
       rate_low =
           get_coeff_cost_general(is_last, ci, abs_qc_low, sign, coeff_ctx,
-                                 dc_sign_ctx, txb_costs, bwl, tx_class, levels);
+                                 dc_sign_ctx, txb_costs, bwl, tx_class, levels
+#if CONFIG_CONTEXT_DERIVATION
+                                 ,
+                                 tmp_sign, plane
+#endif  // CONFIG_CONTEXT_DERIVATION
+          );
     }
 
     rd_low = RDCOST(rdmult, rate_low, dist_low);
@@ -1129,7 +1324,12 @@
     const int16_t *scan, const LV_MAP_EOB_COST *txb_eob_costs,
     const LV_MAP_COEFF_COST *txb_costs, const tran_low_t *tcoeff,
     tran_low_t *qcoeff, tran_low_t *dqcoeff, uint8_t *levels, int sharpness,
-    const qm_val_t *iqmatrix) {
+    const qm_val_t *iqmatrix
+#if CONFIG_CONTEXT_DERIVATION
+    ,
+    int32_t *tmp_sign, int plane
+#endif  // CONFIG_CONTEXT_DERIVATION
+) {
   const int dqv = get_dqv(dequant, scan[si], iqmatrix);
   assert(si != *eob - 1);
   const int ci = scan[si];
@@ -1148,7 +1348,12 @@
     int64_t dist = get_coeff_dist(tqc, dqc, shift) - dist0;
     int rate =
         get_coeff_cost_general(0, ci, abs_qc, sign, coeff_ctx, dc_sign_ctx,
-                               txb_costs, bwl, tx_class, levels);
+                               txb_costs, bwl, tx_class, levels
+#if CONFIG_CONTEXT_DERIVATION
+                               ,
+                               tmp_sign, plane
+#endif  // CONFIG_CONTEXT_DERIVATION
+        );
     int64_t rd = RDCOST(rdmult, *accu_rate + rate, *accu_dist + dist);
 
     tran_low_t qc_low, dqc_low;
@@ -1167,7 +1372,12 @@
       dist_low = get_coeff_dist(tqc, dqc_low, shift) - dist0;
       rate_low =
           get_coeff_cost_general(0, ci, abs_qc_low, sign, coeff_ctx,
-                                 dc_sign_ctx, txb_costs, bwl, tx_class, levels);
+                                 dc_sign_ctx, txb_costs, bwl, tx_class, levels
+#if CONFIG_CONTEXT_DERIVATION
+                                 ,
+                                 tmp_sign, plane
+#endif  // CONFIG_CONTEXT_DERIVATION
+          );
       rd_low = RDCOST(rdmult, *accu_rate + rate_low, *accu_dist + dist_low);
     }
 
@@ -1178,8 +1388,12 @@
         get_eob_cost(new_eob, txb_eob_costs, txb_costs, tx_class);
     int rate_coeff_eob =
         new_eob_cost + get_coeff_cost_eob(ci, abs_qc, sign, coeff_ctx_new_eob,
-                                          dc_sign_ctx, txb_costs, bwl,
-                                          tx_class);
+                                          dc_sign_ctx, txb_costs, bwl, tx_class
+#if CONFIG_CONTEXT_DERIVATION
+                                          ,
+                                          tmp_sign, plane
+#endif  // CONFIG_CONTEXT_DERIVATION
+                       );
     int64_t dist_new_eob = dist;
     int64_t rd_new_eob = RDCOST(rdmult, rate_coeff_eob, dist_new_eob);
 
@@ -1187,7 +1401,12 @@
       const int rate_coeff_eob_low =
           new_eob_cost + get_coeff_cost_eob(ci, abs_qc_low, sign,
                                             coeff_ctx_new_eob, dc_sign_ctx,
-                                            txb_costs, bwl, tx_class);
+                                            txb_costs, bwl, tx_class
+#if CONFIG_CONTEXT_DERIVATION
+                                            ,
+                                            tmp_sign, plane
+#endif  // CONFIG_CONTEXT_DERIVATION
+                         );
       const int64_t dist_new_eob_low = dist_low;
       const int64_t rd_new_eob_low =
           RDCOST(rdmult, rate_coeff_eob_low, dist_new_eob_low);
@@ -1331,10 +1550,25 @@
 
   if (eob > 1) av1_txb_init_levels(qcoeff, width, height, levels);
 
-  // TODO(angirbird): check iqmatrix
+    // TODO(angirbird): check iqmatrix
 
+#if CONFIG_CONTEXT_DERIVATION
+  int txb_skip_ctx = txb_ctx->txb_skip_ctx;
+  int non_skip_cost = 0;
+  int skip_cost = 0;
+  if (plane == AOM_PLANE_V) {
+    txb_skip_ctx +=
+        (x->plane[AOM_PLANE_U].eobs[block] ? V_TXB_SKIP_CONTEXT_OFFSET : 0);
+    non_skip_cost = txb_costs->v_txb_skip_cost[txb_skip_ctx][0];
+    skip_cost = txb_costs->v_txb_skip_cost[txb_skip_ctx][1];
+  } else {
+    non_skip_cost = txb_costs->txb_skip_cost[txb_skip_ctx][0];
+    skip_cost = txb_costs->txb_skip_cost[txb_skip_ctx][1];
+  }
+#else
   const int non_skip_cost = txb_costs->txb_skip_cost[txb_ctx->txb_skip_ctx][0];
   const int skip_cost = txb_costs->txb_skip_cost[txb_ctx->txb_skip_ctx][1];
+#endif  // CONFIG_CONTEXT_DERIVATION
   const int eob_cost = get_eob_cost(eob, txb_eob_costs, txb_costs, tx_class);
   int accu_rate = eob_cost;
   int64_t accu_dist = 0;
@@ -1350,14 +1584,24 @@
     update_coeff_general(&accu_rate, &accu_dist, si, eob, tx_size, tx_class,
                          bwl, height, rdmult, shift, txb_ctx->dc_sign_ctx,
                          dequant, scan, txb_costs, tcoeff, qcoeff, dqcoeff,
-                         levels, iqmatrix);
+                         levels, iqmatrix
+#if CONFIG_CONTEXT_DERIVATION
+                         ,
+                         xd->tmp_sign, plane
+#endif  // CONFIG_CONTEXT_DERIVATION
+    );
     --si;
   } else {
     assert(abs_qc == 1);
     const int coeff_ctx = get_lower_levels_ctx_eob(bwl, height, si);
     accu_rate +=
         get_coeff_cost_eob(ci, abs_qc, sign, coeff_ctx, txb_ctx->dc_sign_ctx,
-                           txb_costs, bwl, tx_class);
+                           txb_costs, bwl, tx_class
+#if CONFIG_CONTEXT_DERIVATION
+                           ,
+                           xd->tmp_sign, plane
+#endif  // CONFIG_CONTEXT_DERIVATION
+        );
     const tran_low_t tqc = tcoeff[ci];
     const tran_low_t dqc = dqcoeff[ci];
     const int64_t dist = get_coeff_dist(tqc, dqc, shift);
@@ -1366,6 +1610,18 @@
     --si;
   }
 
+#if CONFIG_CONTEXT_DERIVATION
+#define UPDATE_COEFF_EOB_CASE(tx_class_literal)                            \
+  case tx_class_literal:                                                   \
+    for (; si >= 0 && nz_num <= max_nz_num; --si) {                        \
+      update_coeff_eob(&accu_rate, &accu_dist, &eob, &nz_num, nz_ci, si,   \
+                       tx_size, tx_class_literal, bwl, height,             \
+                       txb_ctx->dc_sign_ctx, rdmult, shift, dequant, scan, \
+                       txb_eob_costs, txb_costs, tcoeff, qcoeff, dqcoeff,  \
+                       levels, sharpness, iqmatrix, xd->tmp_sign, plane);  \
+    }                                                                      \
+    break;
+#else
 #define UPDATE_COEFF_EOB_CASE(tx_class_literal)                            \
   case tx_class_literal:                                                   \
     for (; si >= 0 && nz_num <= max_nz_num; --si) {                        \
@@ -1376,6 +1632,7 @@
                        levels, sharpness, iqmatrix);                       \
     }                                                                      \
     break;
+#endif  // CONFIG_CONTEXT_DERIVATION
   switch (tx_class) {
     UPDATE_COEFF_EOB_CASE(TX_CLASS_2D);
     UPDATE_COEFF_EOB_CASE(TX_CLASS_HORIZ);
@@ -1412,7 +1669,12 @@
     update_coeff_general(&accu_rate, &dummy_dist, si, eob, tx_size, tx_class,
                          bwl, height, rdmult, shift, txb_ctx->dc_sign_ctx,
                          dequant, scan, txb_costs, tcoeff, qcoeff, dqcoeff,
-                         levels, iqmatrix);
+                         levels, iqmatrix
+#if CONFIG_CONTEXT_DERIVATION
+                         ,
+                         xd->tmp_sign, plane
+#endif  // CONFIG_CONTEXT_DERIVATION
+    );
   }
 
   const int tx_type_cost = get_tx_type_cost(x, xd, plane, tx_size, tx_type,
@@ -1528,8 +1790,13 @@
         else
           intra_dir = mbmi->mode;
 #if CONFIG_ENTROPY_STATS
+#if CONFIG_IST
+        const TX_TYPE primary_tx_type = get_primary_tx_type(tx_type);
+#else
+        const TX_TYPE primary_tx_type = tx_type;
+#endif  // CONFIG_IST
         ++counts->intra_ext_tx[eset][txsize_sqr_map[tx_size]][intra_dir]
-                              [av1_ext_tx_ind[tx_set_type][tx_type]];
+                              [av1_ext_tx_ind[tx_set_type][primary_tx_type]];
 #endif  // CONFIG_ENTROPY_STATS
         if (allow_update_cdf) {
           update_cdf(
@@ -1549,6 +1816,21 @@
       }
     }
   }
+#if CONFIG_IST_FIX_B076
+  // CDF update for txsize_sqr_up_map[tx_size] >= TX_32X32
+  else if (!is_inter &&
+#if CONFIG_SDP
+           cm->quant_params.base_qindex > 0 &&
+           !mbmi->skip_txfm[xd->tree_type == CHROMA_PART] &&
+#else
+           cm->quant_params.base_qindex > 0 && !mbmi->skip_txfm &&
+#endif
+           !segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) {
+    if (cm->seq_params.enable_ist)
+      update_cdf(fc->stx_cdf[txsize_sqr_map[tx_size]],
+                 get_secondary_tx_type(tx_type), STX_TYPES);
+  }
+#endif  // CONFIG_IST_FIX_B076
 }
 
 void av1_update_and_record_txb_context(int plane, int block, int blk_row,
@@ -1586,11 +1868,31 @@
     FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
 #if CONFIG_ENTROPY_STATS
     int cdf_idx = cm->coef_cdf_category;
+#if CONFIG_CONTEXT_DERIVATION
+    if (plane == AOM_PLANE_Y || plane == AOM_PLANE_U) {
+      ++td->counts
+            ->txb_skip[cdf_idx][txsize_ctx][txb_ctx.txb_skip_ctx][eob == 0];
+    } else {
+      ++td->counts->v_txb_skip[cdf_idx][txb_ctx.txb_skip_ctx][eob == 0];
+    }
+#else
     ++td->counts->txb_skip[cdf_idx][txsize_ctx][txb_ctx.txb_skip_ctx][eob == 0];
+#endif
 #endif  // CONFIG_ENTROPY_STATS
     if (allow_update_cdf) {
+#if CONFIG_CONTEXT_DERIVATION
+      int txb_skip_ctx = txb_ctx.txb_skip_ctx;
+      if (plane == AOM_PLANE_Y || plane == AOM_PLANE_U) {
+        update_cdf(ec_ctx->txb_skip_cdf[txsize_ctx][txb_skip_ctx], eob == 0, 2);
+      } else {
+        txb_skip_ctx +=
+            (x->plane[AOM_PLANE_U].eobs[block] ? V_TXB_SKIP_CONTEXT_OFFSET : 0);
+        update_cdf(ec_ctx->v_txb_skip_cdf[txb_skip_ctx], eob == 0, 2);
+      }
+#else
       update_cdf(ec_ctx->txb_skip_cdf[txsize_ctx][txb_ctx.txb_skip_ctx],
                  eob == 0, 2);
+#endif  // CONFIG_CONTEXT_DERIVATION
     }
 
     CB_COEFF_BUFFER *cb_coef_buff = x->cb_coef_buff;
@@ -1715,12 +2017,49 @@
       const int dc_sign = (tcoeff[0] < 0) ? 1 : 0;
       const int dc_sign_ctx = txb_ctx.dc_sign_ctx;
 #if CONFIG_ENTROPY_STATS
-      ++td->counts->dc_sign[plane_type][dc_sign_ctx][dc_sign];
+#if CONFIG_CONTEXT_DERIVATION
+      if (allow_update_cdf) {
+        if (plane == AOM_PLANE_V) {
+          ++td->counts
+                ->v_dc_sign[cdf_idx][xd->tmp_sign[0]][dc_sign_ctx][dc_sign];
+        } else {
+          ++td->counts->dc_sign[cdf_idx][plane_type][dc_sign_ctx][dc_sign];
+        }
+      }
+#else
+      if (allow_update_cdf)
+        ++td->counts->dc_sign[cdf_idx][plane_type][dc_sign_ctx][dc_sign];
+#endif  // CONFIG_CONTEXT_DERIVATION
 #endif  // CONFIG_ENTROPY_STATS
+#if CONFIG_CONTEXT_DERIVATION
+      if (allow_update_cdf) {
+        if (plane == AOM_PLANE_V) {
+          update_cdf(ec_ctx->v_dc_sign_cdf[xd->tmp_sign[0]][dc_sign_ctx],
+                     dc_sign, 2);
+        } else {
+          update_cdf(ec_ctx->dc_sign_cdf[plane_type][dc_sign_ctx], dc_sign, 2);
+        }
+      }
+#else
       if (allow_update_cdf)
         update_cdf(ec_ctx->dc_sign_cdf[plane_type][dc_sign_ctx], dc_sign, 2);
+#endif  // CONFIG_CONTEXT_DERIVATION
       entropy_ctx[block] |= dc_sign_ctx << DC_SIGN_CTX_SHIFT;
     }
+#if CONFIG_CONTEXT_DERIVATION
+    if (allow_update_cdf && plane == AOM_PLANE_V) {
+      for (int c = eob - 1; c >= 1; --c) {
+        int pos = scan[c];
+        if (tcoeff[pos] != 0) {
+          int ac_sign = (tcoeff[pos] < 0) ? 1 : 0;
+#if CONFIG_ENTROPY_STATS
+          ++td->counts->v_ac_sign[cdf_idx][xd->tmp_sign[pos]][ac_sign];
+#endif  // CONFIG_ENTROPY_STATS
+          update_cdf(ec_ctx->v_ac_sign_cdf[xd->tmp_sign[pos]], ac_sign, 2);
+        }
+      }
+    }
+#endif  // CONFIG_CONTEXT_DERIVATION
   } else {
     tcoeff = qcoeff;
   }
diff --git a/av1/encoder/encodetxb.h b/av1/encoder/encodetxb.h
index 64072b2..41a3aec 100644
--- a/av1/encoder/encodetxb.h
+++ b/av1/encoder/encodetxb.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_ENCODETXB_H_
@@ -25,6 +26,7 @@
 #endif
 
 /*!\cond */
+
 #define TXB_SKIP_CTX_MASK 15
 #define DC_SIGN_CTX_SHIFT 4
 #define DC_SIGN_CTX_MASK 3
@@ -362,6 +364,22 @@
 CB_COEFF_BUFFER *av1_get_cb_coeff_buffer(const struct AV1_COMP *cpi, int mi_row,
                                          int mi_col);
 
+#if CONFIG_CONTEXT_DERIVATION
+/*!\brief Returns the entropy cost associated with skipping the current
+ * transform block.
+ *
+ * \ingroup coefficient_coding
+ *
+ * \param[in]    coeff_costs    Table of entropy cost for coefficient coding.
+ * \param[in]    txb_ctx        Context info for entropy coding transform block
+ * skip flag (tx_skip) and the sign of DC coefficient (dc_sign).
+ * \param[in]    plane          The index of the current plane
+ * \param[in]    tx_size        The transform size
+ * \param[in]    x              Pointer to structure holding the data for the
+                                current encoding macroblock
+ * \param[in]    block          The index of the current transform block
+ */
+#else
 /*!\brief Returns the entropy cost associated with skipping the current
  * transform block.
  *
@@ -373,14 +391,31 @@
  * \param[in]    plane          The index of the current plane
  * \param[in]    tx_size        The transform size
  */
+#endif  // CONFIG_CONTEXT_DERIVATION
 static INLINE int av1_cost_skip_txb(const CoeffCosts *coeff_costs,
                                     const TXB_CTX *const txb_ctx, int plane,
-                                    TX_SIZE tx_size) {
+                                    TX_SIZE tx_size
+#if CONFIG_CONTEXT_DERIVATION
+                                    ,
+                                    MACROBLOCK *x, int block
+#endif  // CONFIG_CONTEXT_DERIVATION
+) {
   const TX_SIZE txs_ctx = get_txsize_entropy_ctx(tx_size);
   const PLANE_TYPE plane_type = get_plane_type(plane);
   const LV_MAP_COEFF_COST *const coeff_costs_ =
       &coeff_costs->coeff_costs[txs_ctx][plane_type];
+#if CONFIG_CONTEXT_DERIVATION
+  int txb_skip_ctx = txb_ctx->txb_skip_ctx;
+  if (plane == AOM_PLANE_Y || plane == AOM_PLANE_U) {
+    return coeff_costs_->txb_skip_cost[txb_skip_ctx][1];
+  } else {
+    txb_skip_ctx +=
+        (x->plane[AOM_PLANE_U].eobs[block] ? V_TXB_SKIP_CONTEXT_OFFSET : 0);
+    return coeff_costs_->v_txb_skip_cost[txb_skip_ctx][1];
+  }
+#else
   return coeff_costs_->txb_skip_cost[txb_ctx->txb_skip_ctx][1];
+#endif  // CONFIG_CONTEXT_DERIVATION
 }
 
 /*!\cond */
diff --git a/av1/encoder/ethread.c b/av1/encoder/ethread.c
index 0f754b7..6bde5a8 100644
--- a/av1/encoder/ethread.c
+++ b/av1/encoder/ethread.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "av1/common/warped_motion.h"
@@ -26,7 +27,11 @@
   for (int i = 0; i < REFERENCE_MODES; i++)
     td->rd_counts.comp_pred_diff[i] += td_t->rd_counts.comp_pred_diff[i];
 
+#if CONFIG_NEW_REF_SIGNALING
+  for (int i = 0; i < INTER_REFS_PER_FRAME; i++)
+#else
   for (int i = 0; i < REF_FRAMES; i++)
+#endif  // CONFIG_NEW_REF_SIGNALING
     td->rd_counts.global_motion_used[i] +=
         td_t->rd_counts.global_motion_used[i];
 
@@ -473,6 +478,10 @@
     cfl_init(&td->mb.e_mbd.cfl, &cm->seq_params);
     av1_crc32c_calculator_init(
         &td->mb.txfm_search_info.mb_rd_record.crc_calculator);
+#if CONFIG_REF_MV_BANK
+    av1_zero(td->mb.e_mbd.ref_mv_bank);
+    td->mb.e_mbd.ref_mv_bank_pt = &td->mb.e_mbd.ref_mv_bank;
+#endif  // CONFIG_REF_MV_BANK}
 
     av1_encode_sb_row(cpi, td, tile_row, tile_col, current_mi_row);
 #if CONFIG_MULTITHREAD
@@ -794,6 +803,11 @@
             thread_data->td->mb.tmp_pred_bufs[j];
       }
     }
+#if CONFIG_REF_MV_BANK
+    av1_zero(thread_data->td->mb.e_mbd.ref_mv_bank);
+    thread_data->td->mb.e_mbd.ref_mv_bank_pt =
+        &thread_data->td->mb.e_mbd.ref_mv_bank;
+#endif  // CONFIG_REF_MV_BANK
   }
 }
 
diff --git a/av1/encoder/ethread.h b/av1/encoder/ethread.h
index fae9d10..96b7174 100644
--- a/av1/encoder/ethread.h
+++ b/av1/encoder/ethread.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_ETHREAD_H_
diff --git a/av1/encoder/extend.c b/av1/encoder/extend.c
index 381aec8..258938c 100644
--- a/av1/encoder/extend.c
+++ b/av1/encoder/extend.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "aom_dsp/aom_dsp_common.h"
diff --git a/av1/encoder/extend.h b/av1/encoder/extend.h
index b8cc5b9..c4df432 100644
--- a/av1/encoder/extend.h
+++ b/av1/encoder/extend.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_EXTEND_H_
diff --git a/av1/encoder/firstpass.c b/av1/encoder/firstpass.c
index 62e520b..16d2a8b 100644
--- a/av1/encoder/firstpass.c
+++ b/av1/encoder/firstpass.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <limits.h>
@@ -277,11 +278,9 @@
   aom_clear_system_state();
 #if CONFIG_EXTQUANT
   return av1_find_qindex(FIRST_PASS_Q, bit_depth, 0,
-                         bit_depth == AOM_BITS_8
-                             ? QINDEX_RANGE_8_BITS - 1
-                             : bit_depth == AOM_BITS_10
-                                   ? QINDEX_RANGE_10_BITS - 1
-                                   : QINDEX_RANGE - 1);
+                         bit_depth == AOM_BITS_8    ? QINDEX_RANGE_8_BITS - 1
+                         : bit_depth == AOM_BITS_10 ? QINDEX_RANGE_10_BITS - 1
+                                                    : QINDEX_RANGE - 1);
 #else
   return av1_find_qindex(FIRST_PASS_Q, bit_depth, 0, QINDEX_RANGE - 1);
 #endif
@@ -362,7 +361,11 @@
 #else
   xd->mi[0]->sb_type = bsize;
 #endif
+#if CONFIG_NEW_REF_SIGNALING
+  xd->mi[0]->ref_frame[0] = INTRA_FRAME_NRS;
+#else
   xd->mi[0]->ref_frame[0] = INTRA_FRAME;
+#endif  // CONFIG_NEW_REF_SIGNALING
   set_mi_row_col(xd, tile, mb_row * mb_scale, mi_size_high[bsize],
                  mb_col * mb_scale, mi_size_wide[bsize], mi_params->mi_rows,
                  mi_params->mi_cols);
@@ -690,8 +693,13 @@
     xd->mi[0]->mode = NEWMV;
     xd->mi[0]->mv[0].as_mv = best_mv;
     xd->mi[0]->tx_size = TX_4X4;
+#if CONFIG_NEW_REF_SIGNALING
+    xd->mi[0]->ref_frame[0] = get_closest_pastcur_ref_index(cm);
+    xd->mi[0]->ref_frame[1] = INVALID_IDX;
+#else
     xd->mi[0]->ref_frame[0] = LAST_FRAME;
     xd->mi[0]->ref_frame[1] = NONE_FRAME;
+#endif  // CONFIG_NEW_REF_SIGNALING
     av1_enc_build_inter_predictor(cm, xd, mb_row * mb_scale, mb_col * mb_scale,
                                   NULL, bsize, AOM_PLANE_Y, AOM_PLANE_Y);
     av1_encode_sby_pass1(cpi, x, bsize);
@@ -929,6 +937,11 @@
   }
 }
 
+#if CONFIG_NEW_REF_SIGNALING
+#define LAST_FRAME_PROXY 0
+#define GOLDEN_FRAME_PROXY 2  // Any proxy index will do
+#endif                        // CONFIG_NEW_REF_SIGNALING
+
 void av1_first_pass_row(AV1_COMP *cpi, ThreadData *td, TileDataEnc *tile_data,
                         int mb_row) {
   MACROBLOCK *const x = &td->mb;
@@ -952,10 +965,17 @@
   AV1EncRowMultiThreadInfo *const enc_row_mt = &mt_info->enc_row_mt;
   AV1EncRowMultiThreadSync *const row_mt_sync = &tile_data->row_mt_sync;
 
+#if CONFIG_NEW_REF_SIGNALING
+  const YV12_BUFFER_CONFIG *const last_frame =
+      get_ref_frame_yv12_buf(cm, LAST_FRAME_PROXY);
+  const YV12_BUFFER_CONFIG *golden_frame =
+      get_ref_frame_yv12_buf(cm, GOLDEN_FRAME_PROXY);
+#else
   const YV12_BUFFER_CONFIG *const last_frame =
       get_ref_frame_yv12_buf(cm, LAST_FRAME);
   const YV12_BUFFER_CONFIG *golden_frame =
       get_ref_frame_yv12_buf(cm, GOLDEN_FRAME);
+#endif  // CONFIG_NEW_REF_SIGNALING
   const YV12_BUFFER_CONFIG *alt_ref_frame = NULL;
   const int alt_ref_offset =
       FIRST_PASS_ALT_REF_DISTANCE -
@@ -1103,10 +1123,17 @@
 
   av1_init_tile_data(cpi);
 
+#if CONFIG_NEW_REF_SIGNALING
+  const YV12_BUFFER_CONFIG *const last_frame =
+      get_ref_frame_yv12_buf(cm, LAST_FRAME_PROXY);
+  const YV12_BUFFER_CONFIG *golden_frame =
+      get_ref_frame_yv12_buf(cm, GOLDEN_FRAME_PROXY);
+#else
   const YV12_BUFFER_CONFIG *const last_frame =
       get_ref_frame_yv12_buf(cm, LAST_FRAME);
   const YV12_BUFFER_CONFIG *golden_frame =
       get_ref_frame_yv12_buf(cm, GOLDEN_FRAME);
+#endif  // CONFIG_NEW_REF_SIGNALING
   YV12_BUFFER_CONFIG *const this_frame = &cm->cur_frame->buf;
   // First pass code requires valid last and new frame buffers.
   assert(this_frame != NULL);
@@ -1200,9 +1227,15 @@
        ((this_frame_stats->intra_error /
          DOUBLE_DIVIDE_CHECK(this_frame_stats->coded_error)) > 2.0))) {
     if (golden_frame != NULL) {
+#if CONFIG_NEW_REF_SIGNALING
+      assign_frame_buffer_p(
+          &cm->ref_frame_map[get_ref_frame_map_idx(cm, GOLDEN_FRAME_PROXY)],
+          cm->ref_frame_map[get_ref_frame_map_idx(cm, LAST_FRAME_PROXY)]);
+#else
       assign_frame_buffer_p(
           &cm->ref_frame_map[get_ref_frame_map_idx(cm, GOLDEN_FRAME)],
           cm->ref_frame_map[get_ref_frame_map_idx(cm, LAST_FRAME)]);
+#endif  // CONFIG_NEW_REF_SIGNALING
     }
     twopass->sr_update_lag = 1;
   } else {
@@ -1212,17 +1245,32 @@
   aom_extend_frame_borders(this_frame, num_planes);
 
   // The frame we just compressed now becomes the last frame.
+#if CONFIG_NEW_REF_SIGNALING
+  assign_frame_buffer_p(
+      &cm->ref_frame_map[get_ref_frame_map_idx(cm, LAST_FRAME_PROXY)],
+      cm->cur_frame);
+#else
   assign_frame_buffer_p(
       &cm->ref_frame_map[get_ref_frame_map_idx(cm, LAST_FRAME)], cm->cur_frame);
+#endif  // CONFIG_NEW_REF_SIGNALING
 
   // Special case for the first frame. Copy into the GF buffer as a second
   // reference.
+#if CONFIG_NEW_REF_SIGNALING
+  if (current_frame->frame_number == 0 &&
+      get_ref_frame_map_idx(cm, GOLDEN_FRAME_PROXY) != INVALID_IDX) {
+    assign_frame_buffer_p(
+        &cm->ref_frame_map[get_ref_frame_map_idx(cm, GOLDEN_FRAME_PROXY)],
+        cm->ref_frame_map[get_ref_frame_map_idx(cm, LAST_FRAME_PROXY)]);
+  }
+#else
   if (current_frame->frame_number == 0 &&
       get_ref_frame_map_idx(cm, GOLDEN_FRAME) != INVALID_IDX) {
     assign_frame_buffer_p(
         &cm->ref_frame_map[get_ref_frame_map_idx(cm, GOLDEN_FRAME)],
         cm->ref_frame_map[get_ref_frame_map_idx(cm, LAST_FRAME)]);
   }
+#endif  // CONFIG_NEW_REF_SIGNALING
 
   print_reconstruction_frame(last_frame, current_frame->frame_number,
                              /*do_print=*/0);
diff --git a/av1/encoder/firstpass.h b/av1/encoder/firstpass.h
index e4908f8..358fb82 100644
--- a/av1/encoder/firstpass.h
+++ b/av1/encoder/firstpass.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_FIRSTPASS_H_
diff --git a/av1/encoder/global_motion.c b/av1/encoder/global_motion.c
index b6e2bc1..66f9bef 100644
--- a/av1/encoder/global_motion.c
+++ b/av1/encoder/global_motion.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <stdio.h>
diff --git a/av1/encoder/global_motion.h b/av1/encoder/global_motion.h
index a70bfa8..bfc1fec 100644
--- a/av1/encoder/global_motion.h
+++ b/av1/encoder/global_motion.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_GLOBAL_MOTION_H_
diff --git a/av1/encoder/global_motion_facade.c b/av1/encoder/global_motion_facade.c
index 4cb4c43..40d0297 100644
--- a/av1/encoder/global_motion_facade.c
+++ b/av1/encoder/global_motion_facade.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "aom_dsp/binary_codes_writer.h"
@@ -78,8 +79,13 @@
 // For the given reference frame, computes the global motion parameters for
 // different motion models and finds the best.
 static AOM_INLINE void compute_global_motion_for_ref_frame(
-    AV1_COMP *cpi, YV12_BUFFER_CONFIG *ref_buf[REF_FRAMES], int frame,
-    int num_src_corners, int *src_corners, unsigned char *src_buffer,
+    AV1_COMP *cpi,
+#if CONFIG_NEW_REF_SIGNALING
+    YV12_BUFFER_CONFIG *ref_buf[INTER_REFS_PER_FRAME],
+#else
+    YV12_BUFFER_CONFIG *ref_buf[REF_FRAMES],
+#endif  // CONFIG_NEW_REF_SIGNALING
+    int frame, int num_src_corners, int *src_corners, unsigned char *src_buffer,
     MotionModel *params_by_motion, uint8_t *segment_map,
     const int segment_map_w, const int segment_map_h,
     const WarpedMotionParams *ref_params) {
@@ -107,9 +113,15 @@
   // TODO(sarahparker, debargha): Explore do_adaptive_gm_estimation = 1
   const int do_adaptive_gm_estimation = 0;
 
+#if CONFIG_NEW_REF_SIGNALING
+  const int ref_frame_dist = get_relative_dist(
+      &cm->seq_params.order_hint_info, cm->current_frame.order_hint,
+      cm->cur_frame->ref_order_hints[frame]);
+#else
   const int ref_frame_dist = get_relative_dist(
       &cm->seq_params.order_hint_info, cm->current_frame.order_hint,
       cm->cur_frame->ref_order_hints[frame - LAST_FRAME]);
+#endif  // CONFIG_NEW_REF_SIGNALING
   const GlobalMotionEstimationType gm_estimation_type =
       cm->seq_params.order_hint_info.enable_order_hint &&
               abs(ref_frame_dist) <= 2 && do_adaptive_gm_estimation
@@ -203,8 +215,13 @@
 
 // Computes global motion for the given reference frame.
 void av1_compute_gm_for_valid_ref_frames(
-    AV1_COMP *cpi, YV12_BUFFER_CONFIG *ref_buf[REF_FRAMES], int frame,
-    int num_src_corners, int *src_corners, unsigned char *src_buffer,
+    AV1_COMP *cpi,
+#if CONFIG_NEW_REF_SIGNALING
+    YV12_BUFFER_CONFIG *ref_buf[INTER_REFS_PER_FRAME],
+#else
+    YV12_BUFFER_CONFIG *ref_buf[REF_FRAMES],
+#endif  // CONFIG_NEW_REF_SIGNALING
+    int frame, int num_src_corners, int *src_corners, unsigned char *src_buffer,
     MotionModel *params_by_motion, uint8_t *segment_map, int segment_map_w,
     int segment_map_h) {
   AV1_COMMON *const cm = &cpi->common;
@@ -226,11 +243,17 @@
 
 // Loops over valid reference frames and computes global motion estimation.
 static AOM_INLINE void compute_global_motion_for_references(
-    AV1_COMP *cpi, YV12_BUFFER_CONFIG *ref_buf[REF_FRAMES],
-    FrameDistPair reference_frame[REF_FRAMES - 1], int num_ref_frames,
-    int num_src_corners, int *src_corners, unsigned char *src_buffer,
-    MotionModel *params_by_motion, uint8_t *segment_map,
-    const int segment_map_w, const int segment_map_h) {
+    AV1_COMP *cpi,
+#if CONFIG_NEW_REF_SIGNALING
+    YV12_BUFFER_CONFIG *ref_buf[INTER_REFS_PER_FRAME],
+    FrameDistPair reference_frame[INTER_REFS_PER_FRAME],
+#else
+    YV12_BUFFER_CONFIG *ref_buf[REF_FRAMES],
+    FrameDistPair reference_frame[REF_FRAMES - 1],
+#endif  // CONFIG_NEW_REF_SIGNALING
+    int num_ref_frames, int num_src_corners, int *src_corners,
+    unsigned char *src_buffer, MotionModel *params_by_motion,
+    uint8_t *segment_map, const int segment_map_w, const int segment_map_h) {
   // Computation of frame corners for the source frame will be done already.
   assert(num_src_corners != -1);
   AV1_COMMON *const cm = &cpi->common;
@@ -267,6 +290,38 @@
 
 // Function to decide if we can skip the global motion parameter computation
 // for a particular ref frame.
+#if CONFIG_NEW_REF_SIGNALING
+static AOM_INLINE int skip_gm_frame_nrs(AV1_COMMON *const cm, int refrank) {
+  const RefCntBuffer *const refbuf = get_ref_frame_buf(cm, refrank);
+  if (refbuf == NULL) return 1;
+  const int d0 = get_dir_rank(cm, refrank, NULL);
+  for (int i = 0; i < refrank; ++i) {
+    const int di = get_dir_rank(cm, i, NULL);
+    if (di == d0 && cm->global_motion[i].wmtype != IDENTITY) {
+      // Same direction higher ranked ref has a non-identity gm.
+      // Allow search if distance is smaller in this case.
+      return (abs(cm->ref_frames_info.ref_frame_distance[i]) >
+              abs(cm->ref_frames_info.ref_frame_distance[refrank]));
+    }
+  }
+  return 0;
+}
+
+// Prunes reference frames for global motion estimation based on the speed
+// feature 'gm_search_type'.
+static int do_gm_search_logic_nrs(SPEED_FEATURES *const sf, int refrank) {
+  switch (sf->gm_sf.gm_search_type) {
+    case GM_FULL_SEARCH: return 1;
+    case GM_REDUCED_REF_SEARCH_SKIP_LEV2:
+      return refrank < INTER_REFS_PER_FRAME - 2;
+    case GM_REDUCED_REF_SEARCH_SKIP_LEV3:
+      return refrank < INTER_REFS_PER_FRAME - 4;
+    case GM_DISABLE_SEARCH: return 0;
+    default: assert(0);
+  }
+  return 1;
+}
+#else
 static AOM_INLINE int skip_gm_frame(AV1_COMMON *const cm, int ref_frame) {
   if ((ref_frame == LAST3_FRAME || ref_frame == LAST2_FRAME) &&
       cm->global_motion[GOLDEN_FRAME].wmtype != IDENTITY) {
@@ -294,12 +349,19 @@
   }
   return 1;
 }
+#endif  // CONFIG_NEW_REF_SIGNALING
 
 // Populates valid reference frames in past/future directions in
 // 'reference_frames' and their count in 'num_ref_frames'.
 static AOM_INLINE void update_valid_ref_frames_for_gm(
-    AV1_COMP *cpi, YV12_BUFFER_CONFIG *ref_buf[REF_FRAMES],
+    AV1_COMP *cpi,
+#if CONFIG_NEW_REF_SIGNALING
+    YV12_BUFFER_CONFIG *ref_buf[INTER_REFS_PER_FRAME],
+    FrameDistPair reference_frames[MAX_DIRECTIONS][INTER_REFS_PER_FRAME],
+#else
+    YV12_BUFFER_CONFIG *ref_buf[REF_FRAMES],
     FrameDistPair reference_frames[MAX_DIRECTIONS][REF_FRAMES - 1],
+#endif  // CONFIG_NEW_REF_SIGNALING
     int *num_ref_frames) {
   AV1_COMMON *const cm = &cpi->common;
   int *num_past_ref_frames = &num_ref_frames[0];
@@ -308,13 +370,19 @@
   int ref_pruning_enabled = is_frame_eligible_for_ref_pruning(
       gf_group, cpi->sf.inter_sf.selective_ref_frame, 1, gf_group->index);
 
+#if CONFIG_NEW_REF_SIGNALING
+  for (int frame = cm->ref_frames_info.n_total_refs - 1; frame >= 0; --frame) {
+    const MV_REFERENCE_FRAME ref_frame[2] = { frame, INVALID_IDX };
+    const int ref_disabled = !(cm->ref_frame_flags & (1 << frame));
+#else
   for (int frame = ALTREF_FRAME; frame >= LAST_FRAME; --frame) {
     const MV_REFERENCE_FRAME ref_frame[2] = { frame, NONE_FRAME };
-    RefCntBuffer *buf = get_ref_frame_buf(cm, frame);
     const int ref_disabled =
-        !(cpi->ref_frame_flags & av1_ref_frame_flag_list[frame]);
+        !(cm->ref_frame_flags & av1_ref_frame_flag_list[frame]);
+#endif  // CONFIG_NEW_REF_SIGNALING
     ref_buf[frame] = NULL;
     cm->global_motion[frame] = default_warp_params;
+    RefCntBuffer *buf = get_ref_frame_buf(cm, frame);
     // Skip global motion estimation for invalid ref frames
     if (buf == NULL ||
         (ref_disabled && cpi->sf.hl_sf.recode_loop != DISALLOW_RECODE)) {
@@ -324,15 +392,28 @@
       ref_buf[frame] = &buf->buf;
     }
 
+#if CONFIG_NEW_REF_SIGNALING
+    int prune_ref_frames =
+        ref_pruning_enabled &&
+        prune_ref_by_selective_ref_frame_nrs(cpi, NULL, ref_frame);
+#else
     int prune_ref_frames =
         ref_pruning_enabled &&
         prune_ref_by_selective_ref_frame(cpi, NULL, ref_frame,
                                          cm->cur_frame->ref_display_order_hint);
+#endif  // CONFIG_NEW_REF_SIGNALING
 
     if (ref_buf[frame]->y_crop_width == cpi->source->y_crop_width &&
         ref_buf[frame]->y_crop_height == cpi->source->y_crop_height &&
-        do_gm_search_logic(&cpi->sf, frame) && !prune_ref_frames &&
-        !(cpi->sf.gm_sf.selective_ref_gm && skip_gm_frame(cm, frame))) {
+#if CONFIG_NEW_REF_SIGNALING
+        do_gm_search_logic_nrs(&cpi->sf, ref_frame[0]) &&
+        !(cpi->sf.gm_sf.selective_ref_gm &&
+          skip_gm_frame_nrs(cm, ref_frame[0])) &&
+#else
+        do_gm_search_logic(&cpi->sf, frame) &&
+        !(cpi->sf.gm_sf.selective_ref_gm && skip_gm_frame(cm, frame)) &&
+#endif  // CONFIG_NEW_REF_SIGNALING
+        !prune_ref_frames) {
       assert(ref_buf[frame] != NULL);
       const int relative_frame_dist = av1_encoder_get_relative_dist(
           buf->display_order_hint, cm->cur_frame->display_order_hint);
@@ -398,9 +479,15 @@
   gm_info->segment_map_h =
       (source->y_height + WARP_ERROR_BLOCK) >> WARP_ERROR_BLOCK_LOG;
 
+#if CONFIG_NEW_REF_SIGNALING
+  memset(gm_info->reference_frames, -1,
+         sizeof(gm_info->reference_frames[0][0]) * MAX_DIRECTIONS *
+             (INTER_REFS_PER_FRAME));
+#else
   memset(gm_info->reference_frames, -1,
          sizeof(gm_info->reference_frames[0][0]) * MAX_DIRECTIONS *
              (REF_FRAMES - 1));
+#endif  // CONFIG_NEW_REF_SIGNALING
   av1_zero(gm_info->num_ref_frames);
 
   // Populate ref_buf for valid ref frames in global motion
diff --git a/av1/encoder/global_motion_facade.h b/av1/encoder/global_motion_facade.h
index 52df19d..474cebb 100644
--- a/av1/encoder/global_motion_facade.h
+++ b/av1/encoder/global_motion_facade.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_GLOBAL_MOTION_FACADE_H_
@@ -19,8 +20,13 @@
 struct AV1_COMP;
 
 void av1_compute_gm_for_valid_ref_frames(
-    struct AV1_COMP *cpi, YV12_BUFFER_CONFIG *ref_buf[REF_FRAMES], int frame,
-    int num_src_corners, int *src_corners, unsigned char *src_buffer,
+    struct AV1_COMP *cpi,
+#if CONFIG_NEW_REF_SIGNALING
+    YV12_BUFFER_CONFIG *ref_buf[INTER_REFS_PER_FRAME],
+#else
+    YV12_BUFFER_CONFIG *ref_buf[REF_FRAMES],
+#endif  // CONFIG_NEW_REF_SIGNALING
+    int frame, int num_src_corners, int *src_corners, unsigned char *src_buffer,
     MotionModel *params_by_motion, uint8_t *segment_map, int segment_map_w,
     int segment_map_h);
 void av1_compute_global_motion_facade(struct AV1_COMP *cpi);
diff --git a/av1/encoder/gop_structure.c b/av1/encoder/gop_structure.c
index d305553..8bf8234 100644
--- a/av1/encoder/gop_structure.c
+++ b/av1/encoder/gop_structure.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2019, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <stdint.h>
diff --git a/av1/encoder/gop_structure.h b/av1/encoder/gop_structure.h
index 6cfca22..3851fe0 100644
--- a/av1/encoder/gop_structure.h
+++ b/av1/encoder/gop_structure.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2019, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_GOP_STRUCTURE_H_
diff --git a/av1/encoder/grain_test_vectors.h b/av1/encoder/grain_test_vectors.h
index 945dc37..572f7d8 100644
--- a/av1/encoder/grain_test_vectors.h
+++ b/av1/encoder/grain_test_vectors.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #ifndef AOM_AV1_ENCODER_GRAIN_TEST_VECTORS_H_
 #define AOM_AV1_ENCODER_GRAIN_TEST_VECTORS_H_
diff --git a/av1/encoder/hash.c b/av1/encoder/hash.c
index 3091037..f277840 100644
--- a/av1/encoder/hash.c
+++ b/av1/encoder/hash.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "av1/encoder/hash.h"
diff --git a/av1/encoder/hash.h b/av1/encoder/hash.h
index d8e8cc3..143947a 100644
--- a/av1/encoder/hash.h
+++ b/av1/encoder/hash.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_HASH_H_
diff --git a/av1/encoder/hash_motion.c b/av1/encoder/hash_motion.c
index 310cde8..402a01b 100644
--- a/av1/encoder/hash_motion.c
+++ b/av1/encoder/hash_motion.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/av1/encoder/hash_motion.h b/av1/encoder/hash_motion.h
index e4ea1f3..4a56e2c 100644
--- a/av1/encoder/hash_motion.h
+++ b/av1/encoder/hash_motion.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_HASH_MOTION_H_
diff --git a/av1/encoder/hybrid_fwd_txfm.c b/av1/encoder/hybrid_fwd_txfm.c
index 1552f94..1862dee 100644
--- a/av1/encoder/hybrid_fwd_txfm.c
+++ b/av1/encoder/hybrid_fwd_txfm.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "config/aom_config.h"
@@ -327,9 +328,16 @@
     const int log2width = tx_size_wide_log2[txfm_param->tx_size];
     const int sb_size = (width >= 8 && height >= 8) ? 8 : 4;
     const int16_t *scan_order_in;
+#if CONFIG_IST_FIX_B076
+    // Align scan order of IST with primary transform scan order
+    const SCAN_ORDER *scan_order_out =
+        get_scan(txfm_param->tx_size, txfm_param->tx_type);
+    const int16_t *const scan = scan_order_out->scan;
+#else
     const int16_t *scan_order_out = (sb_size == 4)
                                         ? stx_scan_orders_4x4[log2width - 2]
                                         : stx_scan_orders_8x8[log2width - 2];
+#endif  // CONFIG_IST_FIX_B076
     tran_low_t buf0[64] = { 0 }, buf1[64] = { 0 };
     tran_low_t *tmp = buf0;
     tran_low_t *src = coeff;
@@ -357,7 +365,12 @@
     memset(coeff, 0, width * height * sizeof(tran_low_t));
     tmp = buf1;
     for (int i = 0; i < sb_size * sb_size; i++) {
+#if CONFIG_IST_FIX_B076
+      // Align scan order of IST with primary transform scan order
+      coeff[scan[i]] = *tmp++;
+#else
       coeff[scan_order_out[i]] = *tmp++;
+#endif  // CONFIG_IST_FIX_B076
     }
   }
 }
diff --git a/av1/encoder/hybrid_fwd_txfm.h b/av1/encoder/hybrid_fwd_txfm.h
index ee82f29..e171f67 100644
--- a/av1/encoder/hybrid_fwd_txfm.h
+++ b/av1/encoder/hybrid_fwd_txfm.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_HYBRID_FWD_TXFM_H_
diff --git a/av1/encoder/interp_search.c b/av1/encoder/interp_search.c
index cad2f35..9884350 100644
--- a/av1/encoder/interp_search.c
+++ b/av1/encoder/interp_search.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "av1/common/pred_common.h"
@@ -28,7 +29,6 @@
 
   if (skip_level == 1 && is_comp) {
     if (st->comp_type != mi->interinter_comp.type) return INT_MAX;
-    if (st->compound_idx != mi->compound_idx) return INT_MAX;
   }
 
   int mv_diff = 0;
@@ -53,7 +53,6 @@
       { mbmi->mv[0], mbmi->mv[1] },
       { mbmi->ref_frame[0], mbmi->ref_frame[1] },
       mbmi->interinter_comp.type,
-      mbmi->compound_idx,
       rd,
       pred_sse
     };
@@ -111,7 +110,11 @@
         cpi->sf.interp_sf.use_interp_filter);
 
   if (!need_search || match_found_idx == -1)
-    set_default_interp_filters(mbmi, assign_filter);
+    set_default_interp_filters(mbmi,
+#if CONFIG_OPTFLOW_REFINEMENT
+                               &cpi->common,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
+                               assign_filter);
   return match_found_idx;
 }
 
@@ -127,6 +130,9 @@
 static INLINE int get_switchable_rate(MACROBLOCK *const x,
                                       const InterpFilter interp_fltr,
                                       const int ctx[2]) {
+#if CONFIG_OPTFLOW_REFINEMENT
+  if (x->e_mbd.mi[0]->mode > NEW_NEWMV) return 0;
+#endif  // CONFIG_OPTFLOW_REFINEMENT
   const int inter_filter_cost =
       x->mode_costs.switchable_interp_costs[ctx[0]][interp_fltr];
   return SWITCHABLE_INTERP_RATE_FACTOR * inter_filter_cost;
@@ -135,6 +141,9 @@
 static INLINE int get_switchable_rate(MACROBLOCK *const x,
                                       const int_interpfilters filters,
                                       int dual_filter, const int ctx[2]) {
+#if CONFIG_OPTFLOW_REFINEMENT
+  if (x->e_mbd.mi[0]->mode > NEW_NEWMV) return 0;
+#endif  // CONFIG_OPTFLOW_REFINEMENT
   const InterpFilter filter0 = filters.as_filters.y_filter;
   int inter_filter_cost =
       x->mode_costs.switchable_interp_costs[ctx[0]][filter0];
@@ -643,8 +652,12 @@
       struct macroblockd_plane *const pd = &xd->plane[plane_idx];
       const int bw = pd->width;
       const int bh = pd->height;
-      const MV mv_q4 = clamp_mv_to_umv_border_sb(
-          xd, &mv, bw, bh, pd->subsampling_x, pd->subsampling_y);
+      const MV mv_q4 =
+          clamp_mv_to_umv_border_sb(xd, &mv, bw, bh,
+#if CONFIG_OPTFLOW_REFINEMENT
+                                    0,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
+                                    pd->subsampling_x, pd->subsampling_y);
       const int sub_x = (mv_q4.col & SUBPEL_MASK) << SCALE_EXTRA_BITS;
       const int sub_y = (mv_q4.row & SUBPEL_MASK) << SCALE_EXTRA_BITS;
       skip_hor_plane |= ((sub_x == 0) << plane_idx);
@@ -662,8 +675,7 @@
   // vertical filter decision may be incorrect as temporary MC evaluation
   // overwrites the mask. Make skip_ver as 0 for this case so that mask is
   // populated during luma MC
-  if (is_compound && mbmi->compound_idx == 1 &&
-      mbmi->interinter_comp.type == COMPOUND_DIFFWTD) {
+  if (is_compound && mbmi->interinter_comp.type == COMPOUND_DIFFWTD) {
     assert(mbmi->comp_group_idx == 1);
     if (*skip_hor == 0 && *skip_ver == 1) *skip_ver = 0;
   }
@@ -717,8 +729,12 @@
   const int num_planes = av1_num_planes(cm);
   MACROBLOCKD *const xd = &x->e_mbd;
   MB_MODE_INFO *const mbmi = xd->mi[0];
-  const int need_search = av1_is_interp_needed(xd);
+  const int need_search = av1_is_interp_needed(cm, xd);
+#if CONFIG_NEW_REF_SIGNALING
+  const int ref_frame = COMPACT_INDEX0_NRS(xd->mi[0]->ref_frame[0]);
+#else
   const int ref_frame = xd->mi[0]->ref_frame[0];
+#endif  // CONFIG_NEW_REF_SIGNALING
   RD_STATS rd_stats_luma, rd_stats;
 
   // Initialization of rd_stats structures with default values
@@ -780,17 +796,34 @@
   }
   if (!need_search) {
 #if CONFIG_REMOVE_DUAL_FILTER
+#if CONFIG_OPTFLOW_REFINEMENT
+    assert(mbmi->interp_fltr ==
+           ((mbmi->mode > NEW_NEWMV || use_opfl_refine_all(cm, mbmi))
+                ? MULTITAP_SHARP
+                : EIGHTTAP_REGULAR));
+#else
     assert(mbmi->interp_fltr == EIGHTTAP_REGULAR);
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 #else
     const int_interpfilters filters =
-        av1_broadcast_interp_filter(EIGHTTAP_REGULAR);
+#if CONFIG_OPTFLOW_REFINEMENT
+        (mbmi->mode > NEW_NEWMV || use_opfl_refine_all(cm, mbmi))
+            ? av1_broadcast_interp_filter(MULTITAP_SHARP)
+            :
+#endif  // CONFIG_OPTFLOW_REFINEMENT
+            av1_broadcast_interp_filter(EIGHTTAP_REGULAR);
     assert(mbmi->interp_filters.as_int == filters.as_int);
     (void)filters;
 #endif  // CONFIG_REMOVE_DUAL_FILTER
     return 0;
   }
   if (args->modelled_rd != NULL) {
+#if CONFIG_OPTFLOW_REFINEMENT
+    if (has_second_ref(mbmi) && mbmi->mode <= NEW_NEWMV &&
+        !use_opfl_refine_all(cm, mbmi)) {
+#else
     if (has_second_ref(mbmi)) {
+#endif  // CONFIG_OPTFLOW_REFINEMENT
       const int ref_mv_idx = mbmi->ref_mv_idx;
       MV_REFERENCE_FRAME *refs = mbmi->ref_frame;
       const int mode0 = compound_ref0_mode(mbmi->mode);
diff --git a/av1/encoder/interp_search.h b/av1/encoder/interp_search.h
index 257205f..b4c1ebc 100644
--- a/av1/encoder/interp_search.h
+++ b/av1/encoder/interp_search.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_INTERP_FILTER_SEARCH_H_
@@ -33,7 +34,6 @@
   int_mv mv[2];
   int8_t ref_frames[2];
   COMPOUND_TYPE comp_type;
-  int compound_idx;
   int64_t rd;
   unsigned int pred_sse;
 } INTERPOLATION_FILTER_STATS;
diff --git a/av1/encoder/intra_mode_search.c b/av1/encoder/intra_mode_search.c
index b40def7..027e9ff 100644
--- a/av1/encoder/intra_mode_search.c
+++ b/av1/encoder/intra_mode_search.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "av1/common/reconintra.h"
@@ -48,6 +49,10 @@
 #if CONFIG_MRLS
   mbmi->mrl_index = 0;
 #endif
+#if CONFIG_AIMC
+  mbmi->joint_y_mode_delta_angle = DC_PRED;
+  mbmi->y_mode_idx = DC_PRED;
+#endif  // CONFIG_AIMC
 
 #if CONFIG_ORIP
   mbmi->angle_delta[PLANE_TYPE_Y] = 0;
@@ -72,8 +77,9 @@
 
     // Collect mode stats for multiwinner mode processing
     const int txfm_search_done = 1;
+    const MV_REFERENCE_FRAME refs[2] = { -1, -1 };
     store_winner_mode_stats(
-        &cpi->common, x, mbmi, NULL, NULL, NULL, 0, NULL, bsize, this_rd,
+        &cpi->common, x, mbmi, NULL, NULL, NULL, refs, 0, NULL, bsize, this_rd,
         cpi->sf.winner_mode_sf.multi_winner_mode_type, txfm_search_done);
     if (this_rd < *best_rd) {
       *best_rd = this_rd;
@@ -101,6 +107,10 @@
 #endif  // CONFIG_NEW_TX_PARTITION
     mbmi->filter_intra_mode_info = filter_intra_mode_info;
     av1_copy_array(ctx->tx_type_map, best_tx_type_map, ctx->num_4x4_blk);
+#if CONFIG_AIMC
+    mbmi->joint_y_mode_delta_angle = DC_PRED;
+    mbmi->y_mode_idx = DC_PRED;
+#endif  // CONFIG_AIMC
 #if CONFIG_ORIP
     mbmi->angle_delta[PLANE_TYPE_Y] = 0;
     mbmi->angle_delta[PLANE_TYPE_UV] = 0;
@@ -172,6 +182,7 @@
   }
 }
 
+#if !CONFIG_AIMC
 /*! \brief set the luma intra mode and delta angles for a given mode index.
  * \param[in]    mode_idx           mode index in intra mode decision
  *                                  process.
@@ -179,14 +190,6 @@
  *                                  the mode info for the current macroblock.
  */
 void set_y_mode_and_delta_angle(const int mode_idx, MB_MODE_INFO *const mbmi) {
-#if CONFIG_ORIP
-  if (mode_idx >= LUMA_MODE_COUNT) {
-    mbmi->mode = (mode_idx == LUMA_MODE_COUNT) ? H_PRED : V_PRED;
-    mbmi->angle_delta[PLANE_TYPE_Y] = ANGLE_DELTA_VALUE_ORIP;
-    return;
-  }
-#endif
-
   if (mode_idx < INTRA_MODE_END) {
     mbmi->mode = intra_rd_search_mode_order[mode_idx];
     mbmi->angle_delta[PLANE_TYPE_Y] = 0;
@@ -197,6 +200,7 @@
         (angle_delta < 3 ? (angle_delta - 3) : (angle_delta - 2));
   }
 }
+#endif  // !CONFIG_AIMC
 
 /*! \brief prune luma intra mode    based on the model rd.
  * \param[in]    this_model_rd      model rd for current mode.
@@ -229,7 +233,7 @@
   if (this_model_rd < *best_model_rd) *best_model_rd = this_model_rd;
   return 0;
 }
-
+#if !CONFIG_AIMC
 // Run RD calculation with given chroma intra prediction angle., and return
 // the RD cost. Update the best mode info. if the RD cost is the best so far.
 static int64_t pick_intra_angle_routine_sbuv(
@@ -261,7 +265,6 @@
   }
   return this_rd;
 }
-
 /*!\brief Search for the best angle delta for chroma prediction
  *
  * \ingroup intra_mode_search
@@ -329,6 +332,7 @@
   mbmi->angle_delta[PLANE_TYPE_UV] = best_angle_delta;
   return rd_stats->rate != INT_MAX;
 }
+#endif  // !CONFIG_AIMC
 
 #define PLANE_SIGN_TO_JOINT_SIGN(plane, a, b) \
   (plane == CFL_PRED_U ? a * CFL_SIGNS + b - 1 : b * CFL_SIGNS + a - 1)
@@ -360,15 +364,124 @@
   }
 
   xd->cfl.use_dc_pred_cache = 1;
+#if CONFIG_AIMC
+  const int uv_context = av1_is_directional_mode(mbmi->mode) ? 1 : 0;
+  const int64_t mode_rd = RDCOST(
+      x->rdmult,
+      mode_costs->intra_uv_mode_cost[CFL_ALLOWED][uv_context][UV_CFL_PRED], 0);
+#else
   const int64_t mode_rd = RDCOST(
       x->rdmult,
       mode_costs->intra_uv_mode_cost[CFL_ALLOWED][mbmi->mode][UV_CFL_PRED], 0);
+#endif
   int64_t best_rd_uv[CFL_JOINT_SIGNS][CFL_PRED_PLANES];
   int best_c[CFL_JOINT_SIGNS][CFL_PRED_PLANES];
 #if CONFIG_DEBUG
   int best_rate_uv[CFL_JOINT_SIGNS][CFL_PRED_PLANES];
 #endif  // CONFIG_DEBUG
 
+#if CONFIG_CONTEXT_DERIVATION
+  const int skip_trellis = 0;
+  int8_t best_joint_sign = -1;
+  // process CFL_PRED_U
+  RD_STATS rd_stats;
+  av1_init_rd_stats(&rd_stats);
+  for (int plane = 0; plane < CFL_PRED_PLANES; plane++) {
+    for (int joint_sign = 0; joint_sign < CFL_JOINT_SIGNS; joint_sign++) {
+      best_rd_uv[joint_sign][plane] = INT64_MAX;
+      best_c[joint_sign][plane] = 0;
+    }
+  }
+  // Collect RD stats for an alpha value of zero in CFL_PRED_U.
+  // Skip i == CFL_SIGN_ZERO as (0, 0) is invalid.
+  for (int i = CFL_SIGN_NEG; i < CFL_SIGNS; i++) {
+    const int8_t joint_sign =
+        PLANE_SIGN_TO_JOINT_SIGN(CFL_PRED_U, CFL_SIGN_ZERO, i);
+    mbmi->cfl_alpha_idx = 0;
+    mbmi->cfl_alpha_signs = joint_sign;
+    av1_txfm_rd_in_plane(x, cpi, &rd_stats, best_rd, 0, 1, plane_bsize, tx_size,
+                         FTXS_NONE, skip_trellis);
+    if (rd_stats.rate == INT_MAX) break;
+    const int alpha_rate = mode_costs->cfl_cost[joint_sign][CFL_PRED_U][0];
+    best_rd_uv[joint_sign][CFL_PRED_U] =
+        RDCOST(x->rdmult, rd_stats.rate + alpha_rate, rd_stats.dist);
+#if CONFIG_DEBUG
+    best_rate_uv[joint_sign][CFL_PRED_U] = rd_stats.rate;
+#endif  // CONFIG_DEBUG
+  }
+  // Collect RD stats for alpha values other than zero in CFL_PRED_U.
+  for (int pn_sign = CFL_SIGN_NEG; pn_sign < CFL_SIGNS; pn_sign++) {
+    int progress = 0;
+    for (int c = 0; c < CFL_ALPHABET_SIZE; c++) {
+      int flag = 0;
+      if (c > 2 && progress < c) break;
+      av1_init_rd_stats(&rd_stats);
+      for (int i = 0; i < CFL_SIGNS; i++) {
+        const int8_t joint_sign =
+            PLANE_SIGN_TO_JOINT_SIGN(CFL_PRED_U, pn_sign, i);
+        mbmi->cfl_alpha_idx = (c << CFL_ALPHABET_SIZE_LOG2) + c;
+        mbmi->cfl_alpha_signs = joint_sign;
+        av1_txfm_rd_in_plane(x, cpi, &rd_stats, best_rd, 0, 1, plane_bsize,
+                             tx_size, FTXS_NONE, skip_trellis);
+        if (rd_stats.rate == INT_MAX) break;
+        const int alpha_rate = mode_costs->cfl_cost[joint_sign][CFL_PRED_U][c];
+        int64_t this_rd =
+            RDCOST(x->rdmult, rd_stats.rate + alpha_rate, rd_stats.dist);
+        if (this_rd >= best_rd_uv[joint_sign][CFL_PRED_U]) continue;
+        best_rd_uv[joint_sign][CFL_PRED_U] = this_rd;
+        best_c[joint_sign][CFL_PRED_U] = c;
+#if CONFIG_DEBUG
+        best_rate_uv[joint_sign][CFL_PRED_U] = rd_stats.rate;
+#endif  // CONFIG_DEBUG
+        flag = 2;
+        if (best_rd_uv[joint_sign][CFL_PRED_V] == INT64_MAX) continue;
+        this_rd += mode_rd + best_rd_uv[joint_sign][CFL_PRED_V];
+        if (this_rd >= best_rd) continue;
+        best_rd = this_rd;
+        best_joint_sign = joint_sign;
+      }
+      progress += flag;
+    }
+  }
+  // process CFL_PRED_V
+  // Collect RD stats for all alpha values and joint_signs for CFL_PRED_V
+  // taking into consideration the best alpha for CFL_PRED_U for that
+  // joint_sign. This is necessary due to cross component dependency from
+  // CONFIG_CONTEXT_DERIVATION. The combined (CFL_PRED_U and CFL_PRED_V) RDCOST
+  // will be used to decide the best_joint_sign.
+  for (int joint_sign = 0; joint_sign < CFL_JOINT_SIGNS; joint_sign++) {
+    int progress = 0;
+    for (int c = 0; c < CFL_ALPHABET_SIZE; c++) {
+      int flag = 0;
+      if (c > 2 && progress < c) break;
+      av1_init_rd_stats(&rd_stats);
+      mbmi->cfl_alpha_idx =
+          (best_c[joint_sign][CFL_PRED_U] << CFL_ALPHABET_SIZE_LOG2) + c;
+      mbmi->cfl_alpha_signs = joint_sign;
+      av1_txfm_rd_in_plane(x, cpi, &rd_stats, best_rd, 0, 1, plane_bsize,
+                           tx_size, FTXS_NONE, skip_trellis);
+      av1_txfm_rd_in_plane(x, cpi, &rd_stats, best_rd, 0, 2, plane_bsize,
+                           tx_size, FTXS_NONE, skip_trellis);
+      if (rd_stats.rate == INT_MAX) break;
+      const int alpha_rate = mode_costs->cfl_cost[joint_sign][CFL_PRED_V][c];
+      int64_t this_rd =
+          RDCOST(x->rdmult, rd_stats.rate + alpha_rate, rd_stats.dist);
+      if (this_rd >= best_rd_uv[joint_sign][CFL_PRED_V]) continue;
+      best_rd_uv[joint_sign][CFL_PRED_V] = this_rd;
+      best_c[joint_sign][CFL_PRED_V] = c;
+#if CONFIG_DEBUG
+      best_rate_uv[joint_sign][CFL_PRED_V] = rd_stats.rate;
+#endif  // CONFIG_DEBUG
+      flag = 2;
+      if (best_rd_uv[joint_sign][CFL_PRED_U] == INT64_MAX) continue;
+      this_rd += mode_rd + best_rd_uv[joint_sign][CFL_PRED_U];
+      if (this_rd >= best_rd) continue;
+      best_rd = this_rd;
+      best_joint_sign = joint_sign;
+      progress += flag;
+    }
+  }
+#else
   const int skip_trellis = 0;
   for (int plane = 0; plane < CFL_PRED_PLANES; plane++) {
     RD_STATS rd_stats;
@@ -437,6 +550,7 @@
       }
     }
   }
+#endif
 
   int best_rate_overhead = INT_MAX;
   uint8_t ind = 0;
@@ -448,7 +562,11 @@
                          mode_costs->cfl_cost[best_joint_sign][CFL_PRED_V][v];
 #if CONFIG_DEBUG
     xd->cfl.rate =
+#if CONFIG_AIMC
+        mode_costs->intra_uv_mode_cost[CFL_ALLOWED][uv_context][UV_CFL_PRED] +
+#else
         mode_costs->intra_uv_mode_cost[CFL_ALLOWED][mbmi->mode][UV_CFL_PRED] +
+#endif
         best_rate_overhead + best_rate_uv[best_joint_sign][CFL_PRED_U] +
         best_rate_uv[best_joint_sign][CFL_PRED_V];
 #endif  // CONFIG_DEBUG
@@ -464,6 +582,14 @@
   return best_rate_overhead;
 }
 
+#if CONFIG_AIMC
+int get_uv_mode_cost(MB_MODE_INFO *mbmi, const ModeCosts mode_costs,
+                     CFL_ALLOWED_TYPE cfl_allowed, int mode_index) {
+  const int uv_context = av1_is_directional_mode(mbmi->mode) ? 1 : 0;
+  return mode_costs.intra_uv_mode_cost[cfl_allowed][uv_context][mode_index];
+}
+#endif  // CONFIG_AIMC
+
 int64_t av1_rd_pick_intra_sbuv_mode(const AV1_COMP *const cpi, MACROBLOCK *x,
                                     int *rate, int *rate_tokenonly,
                                     int64_t *distortion, int *skippable,
@@ -520,11 +646,26 @@
 #endif
 
   // Search through all non-palette modes.
+#if CONFIG_AIMC
+  get_uv_intra_mode_set(mbmi);
   for (int mode_idx = 0; mode_idx < UV_INTRA_MODES; ++mode_idx) {
+    mbmi->uv_mode_idx = mode_idx;
+    mbmi->uv_mode = mbmi->uv_intra_mode_list[mode_idx];
+    if (mbmi->uv_mode == mbmi->mode)
+      mbmi->angle_delta[PLANE_TYPE_UV] = mbmi->angle_delta[PLANE_TYPE_Y];
+    else
+      mbmi->angle_delta[PLANE_TYPE_UV] = 0;
+    UV_PREDICTION_MODE mode = mbmi->uv_mode;
+    int mode_cost = get_uv_mode_cost(mbmi, x->mode_costs, is_cfl_allowed(xd),
+                                     mbmi->uv_mode_idx);
+#else
+  for (int mode_idx = 0; mode_idx < UV_INTRA_MODES; ++mode_idx) {
+    UV_PREDICTION_MODE mode = uv_rd_search_mode_order[mode_idx];
+    mbmi->uv_mode = mode;
+    mbmi->angle_delta[PLANE_TYPE_UV] = 0;
+#endif  // CONFIG_AIMC
     int this_rate;
     RD_STATS tokenonly_rd_stats;
-    UV_PREDICTION_MODE mode = uv_rd_search_mode_order[mode_idx];
-    const int is_directional_mode = av1_is_directional_mode(get_uv_mode(mode));
     if (!(cpi->sf.intra_sf.intra_uv_mode_mask[txsize_sqr_up_map[max_tx_size]] &
           (1 << mode)))
       continue;
@@ -534,18 +675,21 @@
 
     if (!intra_mode_cfg->enable_paeth_intra && mode == UV_PAETH_PRED) continue;
 
-    mbmi->uv_mode = mode;
-
     // Init variables for cfl and angle delta
     int cfl_alpha_rate = 0;
     if (mode == UV_CFL_PRED) {
       if (!is_cfl_allowed(xd) || !intra_mode_cfg->enable_cfl_intra) continue;
-      assert(!is_directional_mode);
       const TX_SIZE uv_tx_size = av1_get_tx_size(AOM_PLANE_U, xd);
       cfl_alpha_rate = cfl_rd_pick_alpha(x, cpi, uv_tx_size, best_rd);
       if (cfl_alpha_rate == INT_MAX) continue;
     }
-    mbmi->angle_delta[PLANE_TYPE_UV] = 0;
+#if CONFIG_AIMC
+    mode_cost += cfl_alpha_rate;
+    if (!av1_txfm_uvrd(cpi, x, &tokenonly_rd_stats, bsize, best_rd)) {
+      continue;
+    }
+#else
+    const int is_directional_mode = av1_is_directional_mode(get_uv_mode(mode));
 #if CONFIG_SDP
     if (is_directional_mode &&
         av1_use_angle_delta(mbmi->sb_type[PLANE_TYPE_UV]) &&
@@ -569,6 +713,7 @@
     const int mode_cost =
         mode_costs->intra_uv_mode_cost[is_cfl_allowed(xd)][mbmi->mode][mode] +
         cfl_alpha_rate;
+#endif  // CONFIG_AIMC
     this_rate = tokenonly_rd_stats.rate +
                 intra_mode_info_cost_uv(cpi, x, mbmi, bsize, mode_cost);
     if (mode == UV_CFL_PRED) {
@@ -604,10 +749,18 @@
 #endif
   if (try_palette) {
     uint8_t *best_palette_color_map = x->palette_buffer->best_palette_color_map;
+#if CONFIG_AIMC
+    const int uv_context = av1_is_directional_mode(mbmi->mode) ? 1 : 0;
+#endif  // CONFIG_AIMC
     av1_rd_pick_palette_intra_sbuv(
         cpi, x,
+#if CONFIG_AIMC
+        mode_costs
+            ->intra_uv_mode_cost[is_cfl_allowed(xd)][uv_context][UV_DC_PRED],
+#else
         mode_costs
             ->intra_uv_mode_cost[is_cfl_allowed(xd)][mbmi->mode][UV_DC_PRED],
+#endif
         best_palette_color_map, &best_mbmi, &best_rd, rate, rate_tokenonly,
         distortion, skippable);
   }
@@ -647,8 +800,13 @@
 
   mbmi->mode = DC_PRED;
   mbmi->uv_mode = UV_DC_PRED;
+#if CONFIG_NEW_REF_SIGNALING
+  mbmi->ref_frame[0] = INTRA_FRAME_NRS;
+  mbmi->ref_frame[1] = INVALID_IDX;
+#else
   mbmi->ref_frame[0] = INTRA_FRAME;
   mbmi->ref_frame[1] = NONE_FRAME;
+#endif  // CONFIG_NEW_REF_SIGNALING
   RD_STATS rd_stats_y;
   av1_invalid_rd_stats(&rd_stats_y);
   av1_rd_pick_palette_intra_sby(
@@ -671,7 +829,10 @@
   distortion2 = rd_stats_y.dist;
   rate2 = rd_stats_y.rate + ref_frame_cost;
   if (num_planes > 1) {
-    if (intra_search_state->rate_uv_intra == INT_MAX) {
+#if !CONFIG_AIMC
+    if (intra_search_state->rate_uv_intra == INT_MAX)
+#endif  // !CONFIG_AIMC
+    {
       // We have not found any good uv mode yet, so we need to search for it.
       TX_SIZE uv_tx = av1_get_tx_size(AOM_PLANE_U, xd);
       av1_rd_pick_intra_sbuv_mode(cpi, x, &intra_search_state->rate_uv_intra,
@@ -722,7 +883,12 @@
  * \return Returns whether the current mode is an improvement over best_rd.
  */
 static AOM_INLINE int intra_block_yrd(const AV1_COMP *const cpi, MACROBLOCK *x,
-                                      BLOCK_SIZE bsize, const int *bmode_costs,
+                                      BLOCK_SIZE bsize,
+#if CONFIG_AIMC
+                                      const int mode_costs,
+#else
+                                      const int *bmode_costs,
+#endif  // CONFIG_AIMC
                                       int64_t *best_rd, int *rate,
                                       int *rate_tokenonly, int64_t *distortion,
                                       int *skippable, MB_MODE_INFO *best_mbmi,
@@ -748,8 +914,12 @@
     this_rate_tokenonly -= tx_size_cost(x, bsize, mbmi->tx_size);
   }
   const int this_rate =
-      rd_stats.rate +
-      intra_mode_info_cost_y(cpi, x, mbmi, bsize, bmode_costs[mbmi->mode]);
+      rd_stats.rate + intra_mode_info_cost_y(cpi, x, mbmi, bsize,
+#if CONFIG_AIMC
+                                             mode_costs);
+#else
+                                             bmode_costs[mbmi->mode]);
+#endif  // CONFIG_AIMC
   const int64_t this_rd = RDCOST(x->rdmult, this_rate, rd_stats.dist);
   if (this_rd < *best_rd) {
     *best_mbmi = *mbmi;
@@ -858,7 +1028,11 @@
   const SPEED_FEATURES *const sf = &cpi->sf;
   MACROBLOCKD *const xd = &x->e_mbd;
   MB_MODE_INFO *const mbmi = xd->mi[0];
+#if CONFIG_NEW_REF_SIGNALING
+  assert(mbmi->ref_frame[0] == INTRA_FRAME_NRS);
+#else
   assert(mbmi->ref_frame[0] == INTRA_FRAME);
+#endif  // CONFIG_NEW_REF_SIGNALING
   const PREDICTION_MODE mode = mbmi->mode;
   const ModeCosts *mode_costs = &x->mode_costs;
 #if CONFIG_MRLS
@@ -867,11 +1041,32 @@
                          ? x->mode_costs.mrl_index_cost[mbmi->mrl_index]
                          : 0;
 #endif
+#if CONFIG_AIMC
+  int mode_cost = 0;
+  const int context = get_y_mode_idx_ctx(xd);
+  int mode_set_index = mbmi->y_mode_idx < FIRST_MODE_COUNT ? 0 : 1;
+  mode_set_index += ((mbmi->y_mode_idx - FIRST_MODE_COUNT) / SECOND_MODE_COUNT);
+  mode_cost += x->mode_costs.y_primary_flag_cost[mode_set_index];
+  if (mbmi->y_mode_idx < FIRST_MODE_COUNT) {
+    mode_cost += x->mode_costs.y_first_mode_costs[context][mbmi->y_mode_idx];
+  } else {
+    mode_cost +=
+        x->mode_costs
+            .y_second_mode_costs[context]
+                                [mbmi->y_mode_idx - FIRST_MODE_COUNT -
+                                 SECOND_MODE_COUNT * (mode_set_index - 1)];
+  }
+  mode_cost += ref_frame_cost;
+#if CONFIG_MRLS
+  mode_cost += mrl_idx_cost;
+#endif  // CONFIG_MRLS
+#else
   const int mode_cost = mode_costs->mbmode_cost[size_group_lookup[bsize]][mode]
 #if CONFIG_MRLS
                         + mrl_idx_cost
 #endif
                         + ref_frame_cost;
+#endif  // CONFIG_AIMC
   const int intra_cost_penalty = av1_get_intra_cost_penalty(
       cm->quant_params.base_qindex, cm->quant_params.y_dc_delta_q,
 #if CONFIG_EXTQUANT
@@ -891,7 +1086,10 @@
   }
 
   const int is_directional_mode = av1_is_directional_mode(mode);
-  if (is_directional_mode && av1_use_angle_delta(bsize) &&
+  if (is_directional_mode &&
+#if !CONFIG_AIMC
+      av1_use_angle_delta(bsize) &&
+#endif  // !CONFIG_AIMC
       cpi->oxcf.intra_mode_cfg.enable_angle_delta) {
     if (sf->intra_sf.intra_pruning_with_hog &&
         !intra_search_state->dir_mode_skip_mask_ready) {
@@ -900,7 +1098,13 @@
                                 intra_search_state->directional_mode_skip_mask);
       intra_search_state->dir_mode_skip_mask_ready = 1;
     }
+#if CONFIG_AIMC
+    if (intra_search_state->directional_mode_skip_mask[mode] &&
+        mbmi->y_mode_idx >= FIRST_MODE_COUNT)
+      return INT64_MAX;
+#else
     if (intra_search_state->directional_mode_skip_mask[mode]) return INT64_MAX;
+#endif  // CONFIG_AIMC
   }
   int64_t this_model_rd = intra_model_yrd(cpi, x, bsize, mode_cost);
   if (prune_intra_y_mode(this_model_rd, best_model_rd, top_intra_model_rd))
@@ -947,7 +1151,9 @@
         av1_allow_palette(cm->features.allow_screen_content_tools,
                           mbmi->sb_type);
 #endif
+#if !CONFIG_AIMC
     if (intra_search_state->rate_uv_intra == INT_MAX) {
+#endif  // !CONFIG_AIMC
       // If no good uv-predictor had been found, search for it.
       const int rate_y = rd_stats_y->skip_txfm
                              ? mode_costs->skip_txfm_cost[skip_ctx][1]
@@ -967,6 +1173,9 @@
       if (try_palette) intra_search_state->pmi_uv = *pmi;
       intra_search_state->uv_angle_delta = mbmi->angle_delta[PLANE_TYPE_UV];
 
+#if CONFIG_AIMC
+      intra_search_state->uv_mode_idx = mbmi->uv_mode_idx;
+#endif  // CONFIG_AIMC
       const int uv_rate = intra_search_state->rate_uv_tokenonly;
       const int64_t uv_dist = intra_search_state->dist_uvs;
       const int64_t uv_rd = RDCOST(x->rdmult, uv_rate, uv_dist);
@@ -976,7 +1185,9 @@
         intra_search_state->skip_intra_modes = 1;
         return INT64_MAX;
       }
+#if !CONFIG_AIMC
     }
+#endif  // !CONFIG_AIMC
 
     // If we are here, then the encoder has found at least one good intra uv
     // predictor, so we can directly copy its statistics over.
@@ -987,6 +1198,9 @@
     rd_stats_uv->skip_txfm = intra_search_state->skip_uvs;
     rd_stats->skip_txfm = rd_stats_y->skip_txfm && rd_stats_uv->skip_txfm;
     mbmi->uv_mode = intra_search_state->mode_uv;
+#if CONFIG_AIMC
+    mbmi->uv_mode_idx = intra_search_state->uv_mode_idx;
+#endif  // CONFIG_AIMC
     if (try_palette) {
       pmi->palette_size[1] = intra_search_state->pmi_uv.palette_size[1];
       memcpy(pmi->palette_colors + PALETTE_MAX_SIZE,
@@ -1006,7 +1220,12 @@
   }
   if (num_planes > 1 && xd->is_chroma_ref) {
     const int uv_mode_cost =
+#if CONFIG_AIMC
+        get_uv_mode_cost(mbmi, x->mode_costs, is_cfl_allowed(xd),
+                         mbmi->uv_mode_idx);
+#else
         mode_costs->intra_uv_mode_cost[is_cfl_allowed(xd)][mode][mbmi->uv_mode];
+#endif  // CONFIG_AIMC
     rd_stats->rate +=
         rd_stats_uv->rate +
         intra_mode_info_cost_uv(cpi, x, mbmi, bsize, uv_mode_cost);
@@ -1060,7 +1279,6 @@
   // Flag to check rd of any intra mode is better than best_rd passed to this
   // function
   int beat_best_rd = 0;
-  const int *bmode_costs;
   PALETTE_MODE_INFO *const pmi = &mbmi->palette_mode_info;
 #if CONFIG_SDP
   const int try_palette =
@@ -1075,6 +1293,11 @@
 #endif
   uint8_t *best_palette_color_map =
       try_palette ? x->palette_buffer->best_palette_color_map : NULL;
+#if CONFIG_AIMC
+  const int context = get_y_mode_idx_ctx(xd);
+  int mode_costs = 0;
+#else
+  const int *bmode_costs;
   const MB_MODE_INFO *above_mi = xd->above_mbmi;
   const MB_MODE_INFO *left_mi = xd->left_mbmi;
   const PREDICTION_MODE A = av1_above_block_mode(above_mi);
@@ -1082,6 +1305,7 @@
   const int above_ctx = intra_mode_context[A];
   const int left_ctx = intra_mode_context[L];
   bmode_costs = x->mode_costs.y_mode_costs[above_ctx][left_ctx];
+#endif  // CONFIG_AIMC
 
   mbmi->angle_delta[PLANE_TYPE_Y] = 0;
   if (cpi->sf.intra_sf.intra_pruning_with_hog) {
@@ -1095,6 +1319,10 @@
   // Set params for mode evaluation
   set_mode_eval_params(cpi, x, MODE_EVAL);
 
+#if CONFIG_AIMC
+  get_y_intra_mode_set(mbmi, xd);
+#endif  // CONFIG_AIMC
+
   MB_MODE_INFO best_mbmi = *mbmi;
   av1_zero(x->winner_mode_stats);
   x->winner_mode_count = 0;
@@ -1111,17 +1339,29 @@
     mbmi->mrl_index = mrl_idx;
 #endif
 
-#if CONFIG_ORIP
-    int total_num_mode = cpi->common.seq_params.enable_orip
-                             ? (LUMA_MODE_COUNT + TOTAL_NUM_ORIP_ANGLE_DELTA)
-                             : LUMA_MODE_COUNT;
-    for (int mode_idx = INTRA_MODE_START; mode_idx < total_num_mode;
+    for (int mode_idx = INTRA_MODE_START; mode_idx < LUMA_MODE_COUNT;
          ++mode_idx) {
+#if CONFIG_AIMC
+      mbmi->y_mode_idx = mode_idx;
+      mbmi->joint_y_mode_delta_angle = mbmi->y_intra_mode_list[mode_idx];
+      set_y_mode_and_delta_angle(mbmi->joint_y_mode_delta_angle, mbmi);
+      mode_costs = 0;
+      int mode_set_index = mbmi->y_mode_idx < FIRST_MODE_COUNT ? 0 : 1;
+      mode_set_index +=
+          ((mbmi->y_mode_idx - FIRST_MODE_COUNT) / SECOND_MODE_COUNT);
+      mode_costs += x->mode_costs.y_primary_flag_cost[mode_set_index];
+      if (mode_idx < FIRST_MODE_COUNT) {
+        mode_costs += x->mode_costs.y_first_mode_costs[context][mode_idx];
+      } else {
+        mode_costs +=
+            x->mode_costs
+                .y_second_mode_costs[context]
+                                    [mbmi->y_mode_idx - FIRST_MODE_COUNT -
+                                     SECOND_MODE_COUNT * (mode_set_index - 1)];
+      }
 #else
-  for (int mode_idx = INTRA_MODE_START; mode_idx < LUMA_MODE_COUNT;
-       ++mode_idx) {
-#endif
-      set_y_mode_and_delta_angle(mode_idx, mbmi);
+    set_y_mode_and_delta_angle(mode_idx, mbmi);
+#endif  // CONFIG_AIMC
       RD_STATS this_rd_stats;
       int this_rate, this_rate_tokenonly, s;
       int64_t this_distortion, this_rd;
@@ -1134,29 +1374,19 @@
           mbmi->mode == PAETH_PRED)
         continue;
       is_directional_mode = av1_is_directional_mode(mbmi->mode);
+#if !CONFIG_AIMC
       if (is_directional_mode && av1_use_angle_delta(bsize) == 0 &&
           mbmi->angle_delta[PLANE_TYPE_Y] != 0)
         continue;
-      if (is_directional_mode && directional_mode_skip_mask[mbmi->mode])
+#endif  // !CONFIG_AIMC
+#if CONFIG_AIMC
+      if (is_directional_mode && directional_mode_skip_mask[mbmi->mode] &&
+          mode_idx >= FIRST_MODE_COUNT)
+#else
+    if (is_directional_mode && directional_mode_skip_mask[mbmi->mode])
+#endif  // CONFIG_AIMC
         continue;
 
-#if CONFIG_ORIP
-      int signal_intra_filter = av1_signal_orip_for_horver_modes(
-          &cpi->common, mbmi, PLANE_TYPE_Y, bsize);
-      if (!signal_intra_filter &&
-          mbmi->angle_delta[PLANE_TYPE_Y] == ANGLE_DELTA_VALUE_ORIP)
-        continue;
-      if (mbmi->angle_delta[PLANE_TYPE_Y] == ANGLE_DELTA_VALUE_ORIP) {
-        if (mbmi->mode == H_PRED && best_mbmi.mode != H_PRED) {
-          continue;
-        } else if (mbmi->mode == V_PRED && best_mbmi.mode != V_PRED) {
-          continue;
-        } else if (best_mbmi.angle_delta[PLANE_TYPE_Y]) {
-          continue;
-        }
-      }
-#endif
-
 #if CONFIG_MRLS
       if (!is_directional_mode && mrl_idx) continue;
       if (best_mbmi.mrl_index == 0 && mbmi->mrl_index > 1 &&
@@ -1166,14 +1396,19 @@
       int mrl_idx_cost = (is_directional_mode && enable_mrls_flag)
                              ? x->mode_costs.mrl_index_cost[mbmi->mrl_index]
                              : 0;
+#if CONFIG_AIMC
+      mode_costs += mrl_idx_cost;
+#endif  // CONFIG_AIMC
 #endif
       int64_t this_model_rd;
       this_model_rd = intra_model_yrd(cpi, x, bsize,
-#if CONFIG_MRLS
-                                      bmode_costs[mbmi->mode] + mrl_idx_cost);
+#if CONFIG_AIMC
+                                      mode_costs);
+#elif CONFIG_MRLS
+                                    bmode_costs[mbmi->mode] + mrl_idx_cost);
 #else
-                                    bmode_costs[mbmi->mode]);
-#endif
+                                      bmode_costs[mbmi->mode]);
+#endif  // CONFIG_AIMC
 
       if (prune_intra_y_mode(this_model_rd, &best_model_rd, top_intra_model_rd))
         continue;
@@ -1197,19 +1432,26 @@
         this_rate_tokenonly -= tx_size_cost(x, bsize, mbmi->tx_size);
       }
       this_rate =
-          this_rd_stats.rate +
-#if CONFIG_MRLS
-          intra_mode_info_cost_y(cpi, x, mbmi, bsize,
-                                 bmode_costs[mbmi->mode] + mrl_idx_cost);
+          this_rd_stats.rate + intra_mode_info_cost_y(cpi, x, mbmi, bsize
+#if CONFIG_AIMC
+                                                      ,
+                                                      mode_costs);
+#elif CONFIG_MRLS
+                                                    ,
+                                                    bmode_costs[mbmi->mode] +
+                                                        mrl_idx_cost);
 #else
-        intra_mode_info_cost_y(cpi, x, mbmi, bsize, bmode_costs[mbmi->mode]);
-#endif
+                                                    ,
+                                                    bmode_costs[mbmi->mode]);
+#endif  // CONFIG_AIMC
       this_rd = RDCOST(x->rdmult, this_rate, this_distortion);
       // Collect mode stats for multiwinner mode processing
       const int txfm_search_done = 1;
-      store_winner_mode_stats(
-          &cpi->common, x, mbmi, NULL, NULL, NULL, 0, NULL, bsize, this_rd,
-          cpi->sf.winner_mode_sf.multi_winner_mode_type, txfm_search_done);
+      const MV_REFERENCE_FRAME refs[2] = { -1, -1 };
+      store_winner_mode_stats(&cpi->common, x, mbmi, NULL, NULL, NULL, refs, 0,
+                              NULL, bsize, this_rd,
+                              cpi->sf.winner_mode_sf.multi_winner_mode_type,
+                              txfm_search_done);
       if (this_rd < best_rd) {
         best_mbmi = *mbmi;
         best_rd = this_rd;
@@ -1229,17 +1471,32 @@
   }
 #endif
   // Searches palette
+#if CONFIG_AIMC
+  mode_costs = x->mode_costs.y_primary_flag_cost[DC_PRED];
+  mode_costs += x->mode_costs.y_first_mode_costs[context][DC_PRED];
+#endif  // CONFIG_AIMC
   if (try_palette) {
-    av1_rd_pick_palette_intra_sby(
-        cpi, x, bsize, bmode_costs[DC_PRED], &best_mbmi, best_palette_color_map,
-        &best_rd, &best_model_rd, rate, rate_tokenonly, distortion, skippable,
-        &beat_best_rd, ctx, ctx->blk_skip, ctx->tx_type_map);
+    av1_rd_pick_palette_intra_sby(cpi, x, bsize,
+#if CONFIG_AIMC
+                                  mode_costs,
+#else
+                                  bmode_costs[DC_PRED],
+#endif  // CONFIG_AIMC
+                                  &best_mbmi, best_palette_color_map, &best_rd,
+                                  &best_model_rd, rate, rate_tokenonly,
+                                  distortion, skippable, &beat_best_rd, ctx,
+                                  ctx->blk_skip, ctx->tx_type_map);
   }
 
   // Searches filter_intra
   if (beat_best_rd && av1_filter_intra_allowed_bsize(&cpi->common, bsize)) {
     if (rd_pick_filter_intra_sby(cpi, x, rate, rate_tokenonly, distortion,
-                                 skippable, bsize, bmode_costs[DC_PRED],
+                                 skippable, bsize,
+#if CONFIG_AIMC
+                                 mode_costs,
+#else
+                                 bmode_costs[DC_PRED],
+#endif  // CONFIG_AIMC
                                  &best_rd, &best_model_rd, ctx)) {
       best_mbmi = *mbmi;
     }
@@ -1277,9 +1534,14 @@
         // If previous searches use only the default tx type/no R-D optimization
         // of quantized coeffs, do an extra search for the best tx type/better
         // R-D optimization of quantized coeffs
-        if (intra_block_yrd(cpi, x, bsize, bmode_costs, &best_rd, rate,
-                            rate_tokenonly, distortion, skippable, &best_mbmi,
-                            ctx))
+        if (intra_block_yrd(cpi, x, bsize,
+#if CONFIG_AIMC
+                            mode_costs,
+#else
+                            bmode_costs,
+#endif  // CONFIG_AIMC
+                            &best_rd, rate, rate_tokenonly, distortion,
+                            skippable, &best_mbmi, ctx))
           best_mode_idx = mode_idx;
       }
     }
@@ -1298,11 +1560,21 @@
       // Set params for winner mode evaluation
       set_mode_eval_params(cpi, x, WINNER_MODE_EVAL);
       *mbmi = best_mbmi;
-      intra_block_yrd(cpi, x, bsize, bmode_costs, &best_rd, rate,
-                      rate_tokenonly, distortion, skippable, &best_mbmi, ctx);
+      intra_block_yrd(cpi, x, bsize,
+#if CONFIG_AIMC
+                      mode_costs,
+#else
+                      bmode_costs,
+#endif  // CONFIG_AIMC
+                      &best_rd, rate, rate_tokenonly, distortion, skippable,
+                      &best_mbmi, ctx);
     }
   }
   *mbmi = best_mbmi;
+#if CONFIG_AIMC
+  if (mbmi->joint_y_mode_delta_angle < NON_DIRECTIONAL_MODES_COUNT)
+    assert(mbmi->joint_y_mode_delta_angle == mbmi->y_mode_idx);
+#endif  // CONFIG_AIMC
   av1_copy_array(xd->tx_type_map, ctx->tx_type_map, ctx->num_4x4_blk);
   return best_rd;
 }
diff --git a/av1/encoder/intra_mode_search.h b/av1/encoder/intra_mode_search.h
index 48ea734..556bc1c 100644
--- a/av1/encoder/intra_mode_search.h
+++ b/av1/encoder/intra_mode_search.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 /*!\file
@@ -87,6 +88,9 @@
   UV_PREDICTION_MODE mode_uv; /*!< \brief The best uv mode */
   PALETTE_MODE_INFO pmi_uv;   /*!< \brief Color map if mode_uv is palette */
   int8_t uv_angle_delta;      /*!< \brief Angle delta if mode_uv directional */
+#if CONFIG_AIMC
+  int uv_mode_idx; /*!< \brief UV mode Index */
+#endif             // CONFIG_AIMC
   /**@}*/
 
   /*!
@@ -95,6 +99,13 @@
   int64_t best_pred_rd[REFERENCE_MODES];
 } IntraModeSearchState;
 
+#if CONFIG_AIMC
+/*!\brief Get mode cost for chroma channels.
+ */
+int get_uv_mode_cost(MB_MODE_INFO *mbmi, const ModeCosts mode_costs,
+                     CFL_ALLOWED_TYPE cfl_allowed, int mode_index);
+#endif  // CONFIG_AIMC
+
 /*!\brief Evaluate a given intra-mode for inter frames.
  *
  * \ingroup intra_mode_search
@@ -266,7 +277,7 @@
                              int cols, int bit_depth, int *val_count,
                              int *val_count_8bit, int *num_color_bins,
                              int *num_colors);
-
+#if !CONFIG_AIMC
 /*! \brief set the luma intra mode and delta angles for a given mode index.
  * \param[in]    mode_idx           mode index in intra mode decision
  *                                  process.
@@ -274,7 +285,7 @@
  *                                  the mode info for the current macroblock.
  */
 void set_y_mode_and_delta_angle(const int mode_idx, MB_MODE_INFO *const mbmi);
-
+#endif
 /*! \brief prune luma intra mode    based on the model rd.
  * \param[in]    this_model_rd      model rd for current mode.
  * \param[in]    best_model_rd      Best model RD seen for this block so
diff --git a/av1/encoder/intra_mode_search_utils.h b/av1/encoder/intra_mode_search_utils.h
index 208f9ef..9a327b9 100644
--- a/av1/encoder/intra_mode_search_utils.h
+++ b/av1/encoder/intra_mode_search_utils.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 /*!\file
@@ -304,42 +305,23 @@
                                                  .filter_intra_mode];
     }
   }
+#if !CONFIG_AIMC
   if (av1_is_directional_mode(mbmi->mode)) {
     if (av1_use_angle_delta(bsize)) {
-#if CONFIG_ORIP
-      int signal_intra_filter = av1_signal_orip_for_horver_modes(
-          &cpi->common, mbmi, PLANE_TYPE_Y, bsize);
-#endif  // CONFIG_ORIP
 #if CONFIG_SDP
-#if CONFIG_ORIP
-      if (signal_intra_filter)
-        total_rate +=
-            mode_costs
-                ->angle_delta_cost_hv[PLANE_TYPE_Y][mbmi->mode - V_PRED]
-                                     [get_angle_delta_to_idx(
-                                         mbmi->angle_delta[PLANE_TYPE_Y])];
-      else
-#endif
-        total_rate +=
-            mode_costs->angle_delta_cost[PLANE_TYPE_Y][mbmi->mode - V_PRED]
-                                        [MAX_ANGLE_DELTA +
-                                         mbmi->angle_delta[PLANE_TYPE_Y]];
+      total_rate +=
+          mode_costs->angle_delta_cost[PLANE_TYPE_Y][mbmi->mode - V_PRED]
+                                      [MAX_ANGLE_DELTA +
+                                       mbmi->angle_delta[PLANE_TYPE_Y]];
 #else
-#if CONFIG_ORIP
-      if (signal_intra_filter)
-        total_rate +=
-            mode_costs->angle_delta_cost_hv[mbmi->mode -
-                                            V_PRED][get_angle_delta_to_idx(
-                mbmi->angle_delta[PLANE_TYPE_Y])];
-      else
-#endif
-        total_rate +=
-            mode_costs->angle_delta_cost[mbmi->mode - V_PRED]
-                                        [MAX_ANGLE_DELTA +
-                                         mbmi->angle_delta[PLANE_TYPE_Y]];
+      total_rate +=
+          mode_costs->angle_delta_cost[mbmi->mode - V_PRED]
+                                      [MAX_ANGLE_DELTA +
+                                       mbmi->angle_delta[PLANE_TYPE_Y]];
 #endif
     }
   }
+#endif  // !CONFIG_AIMC
 #if CONFIG_SDP
   if (av1_allow_intrabc(&cpi->common) && xd->tree_type != CHROMA_PART)
 #else
@@ -399,6 +381,7 @@
       total_rate += palette_mode_cost;
     }
   }
+#if !CONFIG_AIMC
   if (av1_is_directional_mode(get_uv_mode(mode))) {
     if (av1_use_angle_delta(bsize)) {
 #if CONFIG_SDP
@@ -421,6 +404,7 @@
 #endif
     }
   }
+#endif  // !CONFIG_AIMC
   return total_rate;
 }
 
@@ -459,40 +443,19 @@
   model_rd_sb_fn[MODELRD_TYPE_INTRA](
       cpi, bsize, x, xd, 0, 0, &this_rd_stats.rate, &this_rd_stats.dist,
       &this_rd_stats.skip_txfm, &temp_sse, NULL, NULL, NULL);
+#if !CONFIG_AIMC
   if (av1_is_directional_mode(mbmi->mode) && av1_use_angle_delta(bsize)) {
-#if CONFIG_ORIP
-    int signal_intra_filter =
-        av1_signal_orip_for_horver_modes(cm, mbmi, PLANE_TYPE_Y, bsize);
-#endif  // CONFIG_ORIP
 #if CONFIG_SDP
-#if CONFIG_ORIP
-    if (signal_intra_filter)
-      mode_cost +=
-          mode_costs->angle_delta_cost_hv[PLANE_TYPE_Y][mbmi->mode - V_PRED]
-                                         [get_angle_delta_to_idx(
-                                             mbmi->angle_delta[PLANE_TYPE_Y])];
-    else
-#endif  // CONFIG_ORIP
-      mode_cost +=
-          mode_costs->angle_delta_cost[PLANE_TYPE_Y][mbmi->mode - V_PRED]
-                                      [MAX_ANGLE_DELTA +
-                                       mbmi->angle_delta[PLANE_TYPE_Y]];
+    mode_cost += mode_costs->angle_delta_cost[PLANE_TYPE_Y][mbmi->mode - V_PRED]
+                                             [MAX_ANGLE_DELTA +
+                                              mbmi->angle_delta[PLANE_TYPE_Y]];
 #else
-#if CONFIG_ORIP
-    if (signal_intra_filter)
-      mode_cost +=
-          mode_costs
-              ->angle_delta_cost_hv[mbmi->mode - V_PRED][get_angle_delta_to_idx(
-                  mbmi->angle_delta[PLANE_TYPE_Y])];
-    else
-#endif  // CONFIG_ORIP
-      mode_cost +=
-          mode_costs->angle_delta_cost[mbmi->mode - V_PRED]
-                                      [MAX_ANGLE_DELTA +
-                                       mbmi->angle_delta[PLANE_TYPE_Y]];
+    mode_cost += mode_costs->angle_delta_cost[mbmi->mode - V_PRED]
+                                             [MAX_ANGLE_DELTA +
+                                              mbmi->angle_delta[PLANE_TYPE_Y]];
 #endif  // CONFIG_SDP
   }
-
+#endif  // !CONFIG_AIMC
 #if CONFIG_SDP
   if (mbmi->mode == DC_PRED &&
       av1_filter_intra_allowed_bsize(cm, mbmi->sb_type[PLANE_TYPE_Y])) {
diff --git a/av1/encoder/k_means_template.h b/av1/encoder/k_means_template.h
index 9e526b8..703e4ec 100644
--- a/av1/encoder/k_means_template.h
+++ b/av1/encoder/k_means_template.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/av1/encoder/level.c b/av1/encoder/level.c
index a7005a3..7c5c2ff 100644
--- a/av1/encoder/level.c
+++ b/av1/encoder/level.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2019, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "aom_ports/system_state.h"
diff --git a/av1/encoder/level.h b/av1/encoder/level.h
index 5e0cce2..89932eb 100644
--- a/av1/encoder/level.h
+++ b/av1/encoder/level.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2019, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_LEVEL_H_
diff --git a/av1/encoder/lookahead.c b/av1/encoder/lookahead.c
index f2bcb27..9c79ecb 100644
--- a/av1/encoder/lookahead.c
+++ b/av1/encoder/lookahead.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #include <assert.h>
 #include <stdlib.h>
diff --git a/av1/encoder/lookahead.h b/av1/encoder/lookahead.h
index 8861fd1..9506c9b 100644
--- a/av1/encoder/lookahead.h
+++ b/av1/encoder/lookahead.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 /*!\file
diff --git a/av1/encoder/mathutils.h b/av1/encoder/mathutils.h
index 64f9361..3319a5c 100644
--- a/av1/encoder/mathutils.h
+++ b/av1/encoder/mathutils.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_MATHUTILS_H_
diff --git a/av1/encoder/mcomp.c b/av1/encoder/mcomp.c
index 8601b55..cb4460e 100644
--- a/av1/encoder/mcomp.c
+++ b/av1/encoder/mcomp.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <limits.h>
diff --git a/av1/encoder/mcomp.h b/av1/encoder/mcomp.h
index 2519cc8..16c2a55 100644
--- a/av1/encoder/mcomp.h
+++ b/av1/encoder/mcomp.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_MCOMP_H_
diff --git a/av1/encoder/mips/msa/error_msa.c b/av1/encoder/mips/msa/error_msa.c
index 2e86dee..4e99b3d 100644
--- a/av1/encoder/mips/msa/error_msa.c
+++ b/av1/encoder/mips/msa/error_msa.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "config/av1_rtcd.h"
diff --git a/av1/encoder/mips/msa/fdct4x4_msa.c b/av1/encoder/mips/msa/fdct4x4_msa.c
index 085c08b..3e35f36 100644
--- a/av1/encoder/mips/msa/fdct4x4_msa.c
+++ b/av1/encoder/mips/msa/fdct4x4_msa.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/av1/encoder/mips/msa/temporal_filter_msa.c b/av1/encoder/mips/msa/temporal_filter_msa.c
index effa75b..afd479d 100644
--- a/av1/encoder/mips/msa/temporal_filter_msa.c
+++ b/av1/encoder/mips/msa/temporal_filter_msa.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "config/av1_rtcd.h"
diff --git a/av1/encoder/misc_model_weights.h b/av1/encoder/misc_model_weights.h
index f00aeab..78f1115 100644
--- a/av1/encoder/misc_model_weights.h
+++ b/av1/encoder/misc_model_weights.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2019, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_MISC_MODEL_WEIGHTS_H_
diff --git a/av1/encoder/ml.c b/av1/encoder/ml.c
index 69a0cb4..58d9c20 100644
--- a/av1/encoder/ml.c
+++ b/av1/encoder/ml.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/av1/encoder/ml.h b/av1/encoder/ml.h
index 62d543d..583b6d2 100644
--- a/av1/encoder/ml.h
+++ b/av1/encoder/ml.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_ML_H_
diff --git a/av1/encoder/mode_prune_model_weights.h b/av1/encoder/mode_prune_model_weights.h
index 98ec368..e593db5 100644
--- a/av1/encoder/mode_prune_model_weights.h
+++ b/av1/encoder/mode_prune_model_weights.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2019, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_MODE_PRUNE_MODEL_WEIGHTS_H_
diff --git a/av1/encoder/model_rd.h b/av1/encoder/model_rd.h
index d4d6e4d..0fe3d8c 100644
--- a/av1/encoder/model_rd.h
+++ b/av1/encoder/model_rd.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_MODEL_RD_H_
@@ -176,7 +177,11 @@
   // Hence quantizer step is also 8 times. To get effective quantizer
   // we need to divide by 8 before sending to modeling function.
   int plane;
+#if CONFIG_NEW_REF_SIGNALING
+  const int ref = COMPACT_INDEX0_NRS(xd->mi[0]->ref_frame[0]);
+#else
   const int ref = xd->mi[0]->ref_frame[0];
+#endif  // CONFIG_NEW_REF_SIGNALING
 
   int64_t rate_sum = 0;
   int64_t dist_sum = 0;
@@ -227,7 +232,11 @@
   // Note our transform coeffs are 8 times an orthogonal transform.
   // Hence quantizer step is also 8 times. To get effective quantizer
   // we need to divide by 8 before sending to modeling function.
+#if CONFIG_NEW_REF_SIGNALING
+  const int ref = COMPACT_INDEX0_NRS(xd->mi[0]->ref_frame[0]);
+#else
   const int ref = xd->mi[0]->ref_frame[0];
+#endif  // CONFIG_NEW_REF_SIGNALING
 
   int64_t rate_sum = 0;
   int64_t dist_sum = 0;
diff --git a/av1/encoder/motion_search_facade.c b/av1/encoder/motion_search_facade.c
index ca271ad..fd3ae46 100644
--- a/av1/encoder/motion_search_facade.c
+++ b/av1/encoder/motion_search_facade.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "aom_ports/system_state.h"
@@ -82,9 +83,16 @@
     // Take the weighted average of the step_params based on the last frame's
     // max mv magnitude and that based on the best ref mvs of the current
     // block for the given reference.
+#if CONFIG_NEW_REF_SIGNALING
+    const MV_REFERENCE_FRAME rfn = COMPACT_INDEX0_NRS(ref);
+    step_param = (av1_init_search_range(x->max_mv_context[rfn]) +
+                  mv_search_params->mv_step_param) /
+                 2;
+#else
     step_param = (av1_init_search_range(x->max_mv_context[ref]) +
                   mv_search_params->mv_step_param) /
                  2;
+#endif  // CONFIG_NEW_REF_SIGNALING
   } else {
     step_param = mv_search_params->mv_step_param;
   }
@@ -125,8 +133,13 @@
 
         for (int k = 0; k < nh; k++) {
           for (int l = 0; l < nw; l++) {
+#if CONFIG_NEW_REF_SIGNALING
+            const int_mv mv =
+                sb_enc->tpl_mv[start + k * sb_enc->tpl_stride + l][ref];
+#else
             const int_mv mv = sb_enc->tpl_mv[start + k * sb_enc->tpl_stride + l]
                                             [ref - LAST_FRAME];
+#endif  // CONFIG_NEW_REF_SIGNALING
             if (mv.as_int == INVALID_MV) {
               valid = 0;
               break;
@@ -275,6 +288,11 @@
     int_mv fractional_ms_list[3];
     av1_set_fractional_mv(fractional_ms_list);
     int dis; /* TODO: use dis in distortion calculation later. */
+#if CONFIG_NEW_REF_SIGNALING
+    const int ref_pred = COMPACT_INDEX0_NRS(ref);
+#else
+    const int ref_pred = ref;
+#endif  // CONFIG_NEW_REF_SIGNALING
 
     SUBPEL_MOTION_SEARCH_PARAMS ms_params;
     av1_make_default_subpel_ms_params(&ms_params, cpi, x, bsize, &ref_mv,
@@ -288,7 +306,7 @@
                                  second_best_mv.as_int != best_mv->as_int;
           const int best_mv_var = mv_search_params->find_fractional_mv_step(
               xd, cm, &ms_params, subpel_start_mv, &best_mv->as_mv, &dis,
-              &x->pred_sse[ref], fractional_ms_list);
+              &x->pred_sse[ref_pred], fractional_ms_list);
 
           if (try_second) {
             MV this_best_mv;
@@ -297,20 +315,20 @@
                                          subpel_start_mv)) {
               const int this_var = mv_search_params->find_fractional_mv_step(
                   xd, cm, &ms_params, subpel_start_mv, &this_best_mv, &dis,
-                  &x->pred_sse[ref], fractional_ms_list);
+                  &x->pred_sse[ref_pred], fractional_ms_list);
               if (this_var < best_mv_var) best_mv->as_mv = this_best_mv;
             }
           }
         } else {
           mv_search_params->find_fractional_mv_step(
               xd, cm, &ms_params, subpel_start_mv, &best_mv->as_mv, &dis,
-              &x->pred_sse[ref], NULL);
+              &x->pred_sse[ref_pred], NULL);
         }
         break;
       case OBMC_CAUSAL:
-        av1_find_best_obmc_sub_pixel_tree_up(xd, cm, &ms_params,
-                                             subpel_start_mv, &best_mv->as_mv,
-                                             &dis, &x->pred_sse[ref], NULL);
+        av1_find_best_obmc_sub_pixel_tree_up(
+            xd, cm, &ms_params, subpel_start_mv, &best_mv->as_mv, &dis,
+            &x->pred_sse[ref_pred], NULL);
         break;
       default: assert(0 && "Invalid motion mode!\n");
     }
@@ -333,7 +351,7 @@
   // This function should only ever be called for compound modes
   assert(has_second_ref(mbmi));
   const int_mv init_mv[2] = { cur_mv[0], cur_mv[1] };
-  const int refs[2] = { mbmi->ref_frame[0], mbmi->ref_frame[1] };
+  const MV_REFERENCE_FRAME refs[2] = { mbmi->ref_frame[0], mbmi->ref_frame[1] };
   const MvCosts *mv_costs = &x->mv_costs;
   int_mv ref_mv[2];
   int ite, ref;
@@ -698,11 +716,15 @@
   const INTERINTER_COMPOUND_DATA *compound_data = &mbmi->interinter_comp;
 
 #if CONFIG_NEW_INTER_MODES
-  const int mixed_new = this_mode == NEAR_NEWMV || this_mode == NEW_NEARMV;
+  const int mixed_new = have_nearmv_newmv_in_inter_mode(this_mode);
 #else
   const int mixed_new = this_mode >= NEAREST_NEWMV && this_mode <= NEW_NEARMV;
 #endif  // CONFIG_NEW_INTER_MODES
+#if CONFIG_OPTFLOW_REFINEMENT
+  if (this_mode == NEW_NEWMV || this_mode == NEW_NEWMV_OPTFLOW) {
+#else
   if (this_mode == NEW_NEWMV) {
+#endif  // CONFIG_OPTFLOW_REFINEMENT
     do_masked_motion_search_indexed(cpi, x, cur_mv, compound_data, bsize,
                                     tmp_mv, &tmp_rate_mv, 2);
     mbmi->mv[0].as_int = tmp_mv[0].as_int;
@@ -738,7 +760,11 @@
   mbmi->sb_type = bsize;
 #endif
   mbmi->ref_frame[0] = ref;
+#if CONFIG_NEW_REF_SIGNALING
+  mbmi->ref_frame[1] = INVALID_IDX;
+#else
   mbmi->ref_frame[1] = NONE_FRAME;
+#endif  // CONFIG_NEW_REF_SIGNALING
   mbmi->motion_mode = SIMPLE_TRANSLATION;
 #if CONFIG_REMOVE_DUAL_FILTER
   mbmi->interp_fltr = EIGHTTAP_REGULAR;
@@ -801,7 +827,12 @@
 
     cpi->mv_search_params.find_fractional_mv_step(
         xd, cm, &ms_params, subpel_start_mv, &best_mv.as_mv, &not_used,
-        &x->pred_sse[ref], NULL);
+#if CONFIG_NEW_REF_SIGNALING
+        &x->pred_sse[COMPACT_INDEX0_NRS(ref)],
+#else
+        &x->pred_sse[ref],
+#endif  // CONFIG_NEW_REF_SIGNALING
+        NULL);
   } else {
     // Manually convert from units of pixel to 1/8-pixels if we are not doing
     // subpel search
@@ -828,8 +859,12 @@
                                  const FULLPEL_MV start_mv, int use_subpixel,
                                  unsigned int *sse, unsigned int *var) {
   MACROBLOCKD *xd = &x->e_mbd;
+#if CONFIG_NEW_REF_SIGNALING
+  const MV_REFERENCE_FRAME ref = get_closest_pastcur_ref_index(&cpi->common);
+#else
   const MV_REFERENCE_FRAME ref =
       cpi->rc.is_src_frame_alt_ref ? ALTREF_FRAME : LAST_FRAME;
+#endif  // CONFIG_NEW_REF_SIGNALING
 
   int_mv best_mv = av1_simple_motion_search(cpi, x, mi_row, mi_col, bsize, ref,
                                             start_mv, 1, use_subpixel);
diff --git a/av1/encoder/motion_search_facade.h b/av1/encoder/motion_search_facade.h
index e631c4e..fe420b6 100644
--- a/av1/encoder/motion_search_facade.h
+++ b/av1/encoder/motion_search_facade.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_MOTION_SEARCH_H_
diff --git a/av1/encoder/mv_prec.c b/av1/encoder/mv_prec.c
index a923533..c41707e 100644
--- a/av1/encoder/mv_prec.c
+++ b/av1/encoder/mv_prec.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2019, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "config/aom_config.h"
@@ -21,7 +22,7 @@
     const MB_MODE_INFO *mbmi, const MB_MODE_INFO_EXT_FRAME *mbmi_ext_frame,
     int ref_idx) {
   int ref_mv_idx = mbmi->ref_mv_idx;
-  if (mbmi->mode == NEAR_NEWMV || mbmi->mode == NEW_NEARMV) {
+  if (have_nearmv_newmv_in_inter_mode(mbmi->mode)) {
     assert(has_second_ref(mbmi));
 #if !CONFIG_NEW_INTER_MODES
     ref_mv_idx += 1;
@@ -32,7 +33,7 @@
   const int8_t ref_frame_type = av1_ref_frame_type(ref_frames);
   const CANDIDATE_MV *curr_ref_mv_stack = mbmi_ext_frame->ref_mv_stack;
 
-  if (ref_frames[1] > INTRA_FRAME) {
+  if (is_inter_ref_frame(ref_frames[1])) {
     assert(ref_idx == 0 || ref_idx == 1);
     return ref_idx ? curr_ref_mv_stack[ref_mv_idx].comp_mv
                    : curr_ref_mv_stack[ref_mv_idx].this_mv;
@@ -201,7 +202,11 @@
   const PREDICTION_MODE mode = mbmi->mode;
   const int is_compound = has_second_ref(mbmi);
 
-  if (mode == NEWMV || mode == NEW_NEWMV) {
+  if (mode == NEWMV ||
+#if CONFIG_OPTFLOW_REFINEMENT
+      mode == NEW_NEWMV_OPTFLOW ||
+#endif  // CONFIG_OPTFLOW_REFINEMENT
+      mode == NEW_NEWMV) {
     // All mvs are new
     for (int ref_idx = 0; ref_idx < 1 + is_compound; ++ref_idx) {
       const MV ref_mv =
@@ -210,7 +215,7 @@
       keep_one_mv_stat(mv_stats, &ref_mv, &cur_mv, cpi);
     }
 #if CONFIG_NEW_INTER_MODES
-  } else if (mode == NEAR_NEWMV || mode == NEW_NEARMV) {
+  } else if (have_nearmv_newmv_in_inter_mode(mode)) {
 #else
   } else if (mode == NEAREST_NEWMV || mode == NEAR_NEWMV ||
              mode == NEW_NEARESTMV || mode == NEW_NEARMV) {
@@ -218,7 +223,11 @@
     // has exactly one new_mv
     mv_stats->default_mvs += 1;
 #if CONFIG_NEW_INTER_MODES
+#if CONFIG_OPTFLOW_REFINEMENT
+    const int ref_idx = (mode == NEAR_NEWMV || mode == NEAR_NEWMV_OPTFLOW);
+#else
     const int ref_idx = (mode == NEAR_NEWMV);
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 #else
     const int ref_idx = (mode == NEAREST_NEWMV || mode == NEAR_NEWMV);
 #endif  // CONFIG_NEW_INTER_MODES
diff --git a/av1/encoder/mv_prec.h b/av1/encoder/mv_prec.h
index 95ff393..285c5a8 100644
--- a/av1/encoder/mv_prec.h
+++ b/av1/encoder/mv_prec.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2019, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_MV_PREC_H_
diff --git a/av1/encoder/optical_flow.c b/av1/encoder/optical_flow.c
index 6360ac8..5899fc2 100644
--- a/av1/encoder/optical_flow.c
+++ b/av1/encoder/optical_flow.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #include <math.h>
 #include <limits.h>
diff --git a/av1/encoder/optical_flow.h b/av1/encoder/optical_flow.h
index 5056af3..d39f8eb 100644
--- a/av1/encoder/optical_flow.h
+++ b/av1/encoder/optical_flow.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_OPTICAL_FLOW_H_
diff --git a/av1/encoder/palette.c b/av1/encoder/palette.c
index fb483d0..eb7207d 100644
--- a/av1/encoder/palette.c
+++ b/av1/encoder/palette.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <math.h>
@@ -280,8 +281,9 @@
   }
   // Collect mode stats for multiwinner mode processing
   const int txfm_search_done = 1;
+  const MV_REFERENCE_FRAME refs[2] = { -1, -1 };
   store_winner_mode_stats(
-      &cpi->common, x, mbmi, NULL, NULL, NULL, THR_DC, color_map, bsize,
+      &cpi->common, x, mbmi, NULL, NULL, NULL, refs, DC_PRED, color_map, bsize,
       this_rd, cpi->sf.winner_mode_sf.multi_winner_mode_type, txfm_search_done);
   if (this_rd < *best_rd) {
     *best_rd = this_rd;
@@ -491,6 +493,10 @@
     }
 
     mbmi->mode = DC_PRED;
+#if CONFIG_AIMC
+    mbmi->joint_y_mode_delta_angle = DC_PRED;
+    mbmi->y_mode_idx = DC_PRED;
+#endif  // CONFIG_AIMC
     mbmi->filter_intra_mode_info.use_filter_intra = 0;
 
     uint16_t color_cache[2 * PALETTE_MAX_SIZE];
@@ -686,6 +692,15 @@
                            &plane_block_height, &rows, &cols);
 
   mbmi->uv_mode = UV_DC_PRED;
+#if CONFIG_AIMC
+  if (av1_is_directional_mode(mbmi->mode))
+    mbmi->uv_mode_idx = 1;
+  else
+    mbmi->uv_mode_idx = 0;
+  dc_mode_cost = get_uv_mode_cost(mbmi, x->mode_costs, is_cfl_allowed(xd),
+                                  mbmi->uv_mode_idx);
+  assert(mbmi->uv_mode_idx >= 0 && mbmi->uv_mode_idx < UV_INTRA_MODES);
+#endif                         // CONFIG_AIMC
   int count_buf[1 << 12];      // Maximum (1 << 12) color levels.
   int count_buf_8bit[1 << 8];  // Maximum (1 << 8) bins for hbd path.
   if (seq_params->use_highbitdepth) {
diff --git a/av1/encoder/palette.h b/av1/encoder/palette.h
index 0c77aa1..e34abd2 100644
--- a/av1/encoder/palette.h
+++ b/av1/encoder/palette.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 /*!\file
diff --git a/av1/encoder/partition_cnn_weights.h b/av1/encoder/partition_cnn_weights.h
index 504038c..0fa2643 100644
--- a/av1/encoder/partition_cnn_weights.h
+++ b/av1/encoder/partition_cnn_weights.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2019, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_PARTITION_CNN_WEIGHTS_H_
diff --git a/av1/encoder/partition_model_weights.h b/av1/encoder/partition_model_weights.h
index 71c1ace..9cc3bb2 100644
--- a/av1/encoder/partition_model_weights.h
+++ b/av1/encoder/partition_model_weights.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_PARTITION_MODEL_WEIGHTS_H_
diff --git a/av1/encoder/partition_search.c b/av1/encoder/partition_search.c
index 947dca1..4840665 100644
--- a/av1/encoder/partition_search.c
+++ b/av1/encoder/partition_search.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "aom_ports/system_state.h"
@@ -27,6 +28,8 @@
 #include "av1/encoder/reconinter_enc.h"
 #include "av1/encoder/tokenize.h"
 
+#include "aom_util/debug_util.h"
+
 #if CONFIG_TUNE_VMAF
 #include "av1/encoder/tune_vmaf.h"
 #endif
@@ -548,6 +551,10 @@
       if (intra_tx_size != max_txsize_rect_lookup[bsize])
         ++x->txfm_search_info.txb_split_count;
     }
+#if CONFIG_REF_MV_BANK
+    if (cm->seq_params.enable_refmvbank && is_inter)
+      av1_update_ref_mv_bank(cm, xd, mbmi);
+#endif  // CONFIG_REF_MV_BANK
   }
 #if CONFIG_SDP
   if (txfm_params->tx_mode_search_type == TX_MODE_SELECT &&
@@ -960,8 +967,12 @@
   const BLOCK_SIZE bsize = mbmi->sb_type;
 #endif
   FRAME_CONTEXT *fc = xd->tile_ctx;
+#if CONFIG_NEW_REF_SIGNALING
+  const int seg_ref_active = 0;
+#else
   const int seg_ref_active =
       segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_REF_FRAME);
+#endif  // CONFIG_NEW_REF_SIGNALING
 
   if (current_frame->skip_mode_info.skip_mode_flag && !seg_ref_active &&
       is_comp_ref_allowed(bsize)) {
@@ -1039,8 +1050,12 @@
 #else
   if (!is_inter_block(mbmi)) {
 #endif
-    av1_sum_intra_stats(cm, td->counts, xd, mbmi, xd->above_mbmi, xd->left_mbmi,
-                        frame_is_intra_only(cm));
+    av1_sum_intra_stats(cm, td->counts, xd, mbmi
+#if !CONFIG_AIMC
+                        ,
+                        xd->above_mbmi, xd->left_mbmi, frame_is_intra_only(cm)
+#endif  // !CONFIG_AIMC
+    );
   }
 #if CONFIG_SDP
   if (av1_allow_intrabc(cm) && xd->tree_type != CHROMA_PART) {
@@ -1068,11 +1083,25 @@
 #endif
 
   if (!seg_ref_active) {
-#if CONFIG_ENTROPY_STATS
+#if CONFIG_ENTROPY_STATS && !CONFIG_CONTEXT_DERIVATION
     counts->intra_inter[av1_get_intra_inter_context(xd)][inter_block]++;
-#endif
+#endif  // CONFIG_ENTROPY_STATS && !CONFIG_CONTEXT_DERIVATION
+#if CONFIG_CONTEXT_DERIVATION
+#if CONFIG_SDP
+    const int skip_txfm = mbmi->skip_txfm[xd->tree_type == CHROMA_PART];
+#else
+    const int skip_txfm = mbmi->skip_txfm;
+#endif  // CONFIG_SDP
+#if CONFIG_ENTROPY_STATS
+    counts->intra_inter[skip_txfm][av1_get_intra_inter_context(xd)]
+                       [inter_block]++;
+#endif  // CONFIG_ENTROPY_STATS
+    update_cdf(fc->intra_inter_cdf[skip_txfm][av1_get_intra_inter_context(xd)],
+               inter_block, 2);
+#else
     update_cdf(fc->intra_inter_cdf[av1_get_intra_inter_context(xd)],
                inter_block, 2);
+#endif  // CONFIG_CONTEXT_DERIVATION
     // If the segment reference feature is enabled we have only a single
     // reference frame allowed for the segment so exclude it from
     // the reference frame counts used to work out probabilities.
@@ -1082,14 +1111,33 @@
       if (current_frame->reference_mode == REFERENCE_MODE_SELECT) {
         if (is_comp_ref_allowed(bsize)) {
 #if CONFIG_ENTROPY_STATS
-          counts->comp_inter[av1_get_reference_mode_context(xd)]
+          counts->comp_inter[av1_get_reference_mode_context(cm, xd)]
                             [has_second_ref(mbmi)]++;
 #endif  // CONFIG_ENTROPY_STATS
-          update_cdf(av1_get_reference_mode_cdf(xd), has_second_ref(mbmi), 2);
+          update_cdf(av1_get_reference_mode_cdf(cm, xd), has_second_ref(mbmi),
+                     2);
         }
       }
 
       if (has_second_ref(mbmi)) {
+#if CONFIG_NEW_REF_SIGNALING
+        const int n_refs = cm->ref_frames_info.n_total_refs;
+        int n_bits = 0;
+        assert(ref0 < ref1);
+        for (int i = 0; i < n_refs + n_bits - 2 && n_bits < 2; i++) {
+          const int bit = ref0 == i || ref1 == i;
+          const int bit_type = av1_get_compound_ref_bit_type(
+              n_bits, &cm->ref_frames_info, ref0, i);
+          update_cdf(av1_get_pred_cdf_compound_ref_nrs(xd, i, n_bits, bit_type,
+                                                       n_refs),
+                     bit, 2);
+#if CONFIG_ENTROPY_STATS
+          counts->comp_ref[av1_get_ref_pred_context_nrs(xd, i, n_refs)]
+                          [bit_type][i - n_bits][bit]++;
+#endif  // CONFIG_ENTROPY_STATS
+          n_bits += bit;
+        }
+#else
         const COMP_REFERENCE_TYPE comp_ref_type = has_uni_comp_refs(mbmi)
                                                       ? UNIDIR_COMP_REFERENCE
                                                       : BIDIR_COMP_REFERENCE;
@@ -1159,7 +1207,21 @@
 #endif  // CONFIG_ENTROPY_STATS
           }
         }
+#endif  // CONFIG_NEW_REF_SIGNALING
       } else {
+#if CONFIG_NEW_REF_SIGNALING
+        const int n_refs = cm->ref_frames_info.n_total_refs;
+        const MV_REFERENCE_FRAME ref0_nrs = mbmi->ref_frame[0];
+        for (int i = 0; i < n_refs - 1; i++) {
+          const int bit = ref0_nrs == i;
+          update_cdf(av1_get_pred_cdf_single_ref_nrs(xd, i, n_refs), bit, 2);
+#if CONFIG_ENTROPY_STATS
+          counts->single_ref[av1_get_ref_pred_context_nrs(xd, i, n_refs)][i]
+                            [bit]++;
+#endif  // CONFIG_ENTROPY_STATS
+          if (bit) break;
+        }
+#else
         const int bit = (ref0 >= BWDREF_FRAME);
         update_cdf(av1_get_pred_cdf_single_ref_p1(xd), bit, 2);
 #if CONFIG_ENTROPY_STATS
@@ -1203,12 +1265,17 @@
 #endif  // CONFIG_ENTROPY_STATS
           }
         }
+#endif  // CONFIG_NEW_REF_SIGNALING
       }
 
       if (cm->seq_params.enable_interintra_compound &&
           is_interintra_allowed(mbmi)) {
         const int bsize_group = size_group_lookup[bsize];
+#if CONFIG_NEW_REF_SIGNALING
+        if (mbmi->ref_frame[1] == INTRA_FRAME_NRS) {
+#else
         if (mbmi->ref_frame[1] == INTRA_FRAME) {
+#endif  // CONFIG_NEW_REF_SIGNALING
 #if CONFIG_ENTROPY_STATS
           counts->interintra[bsize_group][1]++;
 #endif
@@ -1245,7 +1312,11 @@
               ? motion_mode_allowed(xd->global_motion, xd, mbmi,
                                     cm->features.allow_warped_motion)
               : SIMPLE_TRANSLATION;
+#if CONFIG_NEW_REF_SIGNALING
+      if (mbmi->ref_frame[1] != INTRA_FRAME_NRS) {
+#else
       if (mbmi->ref_frame[1] != INTRA_FRAME) {
+#endif  // CONFIG_NEW_REF_SIGNALING
         if (motion_allowed == WARPED_CAUSAL) {
 #if CONFIG_ENTROPY_STATS
           counts->motion_mode[bsize][mbmi->motion_mode]++;
@@ -1260,7 +1331,11 @@
         }
       }
 
+#if CONFIG_OPTFLOW_REFINEMENT
+      if (has_second_ref(mbmi) && mbmi->mode <= NEW_NEWMV) {
+#else
       if (has_second_ref(mbmi)) {
+#endif  // CONFIG_OPTFLOW_REFINEMENT
         assert(current_frame->reference_mode != SINGLE_REFERENCE &&
                is_inter_compound_mode(mbmi->mode) &&
                mbmi->motion_mode == SIMPLE_TRANSLATION);
@@ -1276,18 +1351,7 @@
                      mbmi->comp_group_idx, 2);
         }
 
-        if (mbmi->comp_group_idx == 0) {
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-          const int comp_index_ctx = get_comp_index_context(cm, xd);
-#if CONFIG_ENTROPY_STATS
-          ++counts->compound_index[comp_index_ctx][mbmi->compound_idx];
-#endif
-          update_cdf(fc->compound_index_cdf[comp_index_ctx], mbmi->compound_idx,
-                     2);
-#else
-          assert(mbmi->compound_idx == 1);
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
-        } else {
+        if (mbmi->comp_group_idx == 1) {
           assert(masked_compound_used);
           if (is_interinter_compound_used(COMPOUND_WEDGE, bsize)) {
 #if CONFIG_ENTROPY_STATS
@@ -1327,16 +1391,37 @@
     const int16_t mode_ctx =
         av1_mode_context_analyzer(mbmi_ext->mode_context, mbmi->ref_frame);
     if (has_second_ref(mbmi)) {
+#if CONFIG_OPTFLOW_REFINEMENT
+      if (cm->features.opfl_refine_type == REFINE_SWITCHABLE &&
+          is_opfl_refine_allowed(cm, mbmi)) {
+        const int use_optical_flow = mode > NEW_NEWMV;
+#if CONFIG_ENTROPY_STATS
+        ++counts->use_optflow[mode_ctx][use_optical_flow];
+#endif
+        update_cdf(fc->use_optflow_cdf[mode_ctx], use_optical_flow, 2);
+      }
+      const int comp_mode_idx = opfl_get_comp_idx(mode);
+#if CONFIG_ENTROPY_STATS
+      ++counts->inter_compound_mode[mode_ctx][comp_mode_idx];
+#endif
+      update_cdf(fc->inter_compound_mode_cdf[mode_ctx], comp_mode_idx,
+                 INTER_COMPOUND_REF_TYPES);
+#else
 #if CONFIG_ENTROPY_STATS
       ++counts->inter_compound_mode[mode_ctx][INTER_COMPOUND_OFFSET(mode)];
 #endif
       update_cdf(fc->inter_compound_mode_cdf[mode_ctx],
                  INTER_COMPOUND_OFFSET(mode), INTER_COMPOUND_MODES);
+#endif  // CONFIG_OPTFLOW_REFINEMENT
     } else {
       av1_update_inter_mode_stats(fc, counts, mode, mode_ctx);
     }
 
-    const int new_mv = mbmi->mode == NEWMV || mbmi->mode == NEW_NEWMV;
+    const int new_mv = mbmi->mode == NEWMV ||
+#if CONFIG_OPTFLOW_REFINEMENT
+                       mbmi->mode == NEW_NEWMV_OPTFLOW ||
+#endif  // CONFIG_OPTFLOW_REFINEMENT
+                       mbmi->mode == NEW_NEWMV;
 #if CONFIG_NEW_INTER_MODES
     if (have_drl_index(mbmi->mode)) {
       const int16_t mode_ctx_pristine =
@@ -1389,8 +1474,12 @@
                               allow_hp);
         }
 #if CONFIG_NEW_INTER_MODES
-      } else if (mbmi->mode == NEAR_NEWMV || mbmi->mode == NEW_NEARMV) {
-        const int ref = mbmi->mode == NEAR_NEWMV;
+      } else if (have_nearmv_newmv_in_inter_mode(mbmi->mode)) {
+        const int ref =
+#if CONFIG_OPTFLOW_REFINEMENT
+            mbmi->mode == NEAR_NEWMV_OPTFLOW ||
+#endif  // CONFIG_OPTFLOW_REFINEMENT
+            mbmi->mode == NEAR_NEWMV;
         const int_mv ref_mv = av1_get_ref_mv(x, ref);
         av1_update_mv_stats(&mbmi->mv[ref].as_mv, &ref_mv.as_mv, &fc->nmvc,
                             allow_hp);
@@ -1492,8 +1581,7 @@
       mbmi->delta_lf_from_base = xd->delta_lf_from_base;
     }
     if (has_second_ref(mbmi)) {
-      if (mbmi->compound_idx == 0 ||
-          mbmi->interinter_comp.type == COMPOUND_AVERAGE)
+      if (mbmi->interinter_comp.type == COMPOUND_AVERAGE)
         mbmi->comp_group_idx = 0;
       else
         mbmi->comp_group_idx = 1;
@@ -1536,8 +1624,12 @@
       }
       set_ref_ptrs(cm, xd, mbmi->ref_frame[0], mbmi->ref_frame[1]);
     } else {
+#if CONFIG_NEW_REF_SIGNALING
+      const int seg_ref_active = 0;
+#else
       const int seg_ref_active =
           segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_REF_FRAME);
+#endif  // CONFIG_NEW_REF_SIGNALING
       if (!seg_ref_active) {
         // If the segment reference feature is enabled we have only a single
         // reference frame allowed for the segment so exclude it from
@@ -1571,8 +1663,12 @@
 #else
       const int inter_block = is_inter_block(mbmi);
 #endif
+#if CONFIG_NEW_REF_SIGNALING
+      const int seg_ref_active = 0;
+#else
       const int seg_ref_active =
           segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_REF_FRAME);
+#endif  // CONFIG_NEW_REF_SIGNALING
       if (!seg_ref_active && inter_block) {
         const MOTION_MODE motion_allowed =
             cm->features.switchable_motion_mode
@@ -1580,7 +1676,11 @@
                                       cm->features.allow_warped_motion)
                 : SIMPLE_TRANSLATION;
 
+#if CONFIG_NEW_REF_SIGNALING
+        if (mbmi->ref_frame[1] != INTRA_FRAME_NRS) {
+#else
         if (mbmi->ref_frame[1] != INTRA_FRAME) {
+#endif  // CONFIG_NEW_REF_SIGNALING
           if (motion_allowed >= OBMC_CAUSAL) {
             td->rd_counts.obmc_used[bsize][mbmi->motion_mode == OBMC_CAUSAL]++;
           }
diff --git a/av1/encoder/partition_search.h b/av1/encoder/partition_search.h
index 9d1aa2d..97ec7a2 100644
--- a/av1/encoder/partition_search.h
+++ b/av1/encoder/partition_search.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_PARTITION_SEARCH_H_
diff --git a/av1/encoder/partition_strategy.c b/av1/encoder/partition_strategy.c
index 7499e87..f443387 100644
--- a/av1/encoder/partition_strategy.c
+++ b/av1/encoder/partition_strategy.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2019, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <float.h>
@@ -343,7 +344,11 @@
   for (int ref_idx = 0; ref_idx < num_refs; ref_idx++) {
     const int ref = refs[ref_idx];
 
-    if (cpi->ref_frame_flags & av1_ref_frame_flag_list[ref]) {
+#if CONFIG_NEW_REF_SIGNALING
+    if (cm->ref_frame_flags & (1 << ref)) {
+#else
+    if (cm->ref_frame_flags & av1_ref_frame_flag_list[ref]) {
+#endif  // CONFIG_NEW_REF_SIGNALING
       const FULLPEL_MV *start_mvs = sms_tree->start_mvs;
       unsigned int curr_sse = 0, curr_var = 0;
       int_mv best_mv =
@@ -397,11 +402,14 @@
   assert(mi_size_wide[bsize] == mi_size_high[bsize]);
   // Setting up motion search
   int ref_list[1];
+#if CONFIG_NEW_REF_SIGNALING
+  ref_list[0] = get_closest_pastcur_ref_index(&cpi->common);
+#else
   ref_list[0] = LAST_FRAME;
-  if (!(cpi->ref_frame_flags & av1_ref_frame_flag_list[LAST_FRAME]) &&
-      !(cpi->ref_frame_flags & av1_ref_frame_flag_list[ALTREF_FRAME])) {
+  if (!(cpi->common.ref_frame_flags & av1_ref_frame_flag_list[LAST_FRAME]) &&
+      !(cpi->common.ref_frame_flags & av1_ref_frame_flag_list[ALTREF_FRAME])) {
     for (int i = LAST_FRAME; i <= ALTREF_FRAME; i++) {
-      if (cpi->ref_frame_flags & av1_ref_frame_flag_list[i]) {
+      if (cpi->common.ref_frame_flags & av1_ref_frame_flag_list[i]) {
         ref_list[0] = i;
         break;
       }
@@ -410,6 +418,7 @@
     // Setting up motion search
     ref_list[0] = cpi->rc.is_src_frame_alt_ref ? ALTREF_FRAME : LAST_FRAME;
   }
+#endif  // CONFIG_NEW_REF_SIGNALING
 
   const int num_refs = 1;
   const int use_subpixel = 1;
@@ -1458,11 +1467,10 @@
   // Threshold for number of winners
   // Conservative pruning for high quantizers
   const int num_win_thresh = AOMMIN(3 * (2 * (MAXQ - qindex) / MAXQ), 3);
-  int sub_part_win = (rect_part_win_info == NULL)
-                         ? (pc_tree->partitioning == rect_part)
-                         : (rect_part == PARTITION_HORZ)
-                               ? rect_part_win_info->rect_part_win[HORZ]
-                               : rect_part_win_info->rect_part_win[VERT];
+  int sub_part_win =
+      (rect_part_win_info == NULL)    ? (pc_tree->partitioning == rect_part)
+      : (rect_part == PARTITION_HORZ) ? rect_part_win_info->rect_part_win[HORZ]
+                                      : rect_part_win_info->rect_part_win[VERT];
   num_win += (sub_part_win) ? 1 : 0;
   if (pc_tree->split[split_idx1]) {
     num_win +=
diff --git a/av1/encoder/partition_strategy.h b/av1/encoder/partition_strategy.h
index a386bf9..ec87781 100644
--- a/av1/encoder/partition_strategy.h
+++ b/av1/encoder/partition_strategy.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2019, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_PARTITION_STRATEGY_H_
diff --git a/av1/encoder/pass2_strategy.c b/av1/encoder/pass2_strategy.c
index 6764479..ea77972 100644
--- a/av1/encoder/pass2_strategy.c
+++ b/av1/encoder/pass2_strategy.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2019, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 /*!\defgroup gf_group_algo Golden Frame Group
@@ -723,11 +724,10 @@
   }
 
   // Clamp odd edge cases.
-  total_group_bits = (total_group_bits < 0)
-                         ? 0
-                         : (total_group_bits > twopass->kf_group_bits)
-                               ? twopass->kf_group_bits
-                               : total_group_bits;
+  total_group_bits = (total_group_bits < 0) ? 0
+                     : (total_group_bits > twopass->kf_group_bits)
+                         ? twopass->kf_group_bits
+                         : total_group_bits;
 
   // Clip based on user supplied data rate variability limit.
   if (total_group_bits > (int64_t)max_bits * rc->baseline_gf_interval)
diff --git a/av1/encoder/pass2_strategy.h b/av1/encoder/pass2_strategy.h
index aeca356..6a8c91e 100644
--- a/av1/encoder/pass2_strategy.h
+++ b/av1/encoder/pass2_strategy.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2019, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_PASS2_STRATEGY_H_
diff --git a/av1/encoder/pickccso.c b/av1/encoder/pickccso.c
index 3b90267..94a6c5d 100644
--- a/av1/encoder/pickccso.c
+++ b/av1/encoder/pickccso.c
@@ -1,12 +1,13 @@
 /*
  * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <math.h>
diff --git a/av1/encoder/pickccso.h b/av1/encoder/pickccso.h
index a4465cc..64ec407 100644
--- a/av1/encoder/pickccso.h
+++ b/av1/encoder/pickccso.h
@@ -1,12 +1,13 @@
 /*
  * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_PICKCCSO_H_
diff --git a/av1/encoder/pickcdef.c b/av1/encoder/pickcdef.c
index e88cf87..51f4a98 100644
--- a/av1/encoder/pickcdef.c
+++ b/av1/encoder/pickcdef.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <math.h>
@@ -335,14 +336,13 @@
   cdef_info->cdef_bits = 0;
   cdef_info->nb_cdef_strengths = 1;
 #if CONFIG_EXTQUANT
-  int damping_offset = clamp(cm->quant_params.base_qindex -
-                                 (cm->seq_params.bit_depth == AOM_BITS_8
-                                      ? 0
-                                      : cm->seq_params.bit_depth == AOM_BITS_10
-                                            ? 2 * MAXQ_OFFSET
-                                            : 4 * MAXQ_OFFSET),
-                             MINQ, MAXQ_8_BITS) >>
-                       6;
+  int damping_offset =
+      clamp(cm->quant_params.base_qindex -
+                (cm->seq_params.bit_depth == AOM_BITS_8    ? 0
+                 : cm->seq_params.bit_depth == AOM_BITS_10 ? 2 * MAXQ_OFFSET
+                                                           : 4 * MAXQ_OFFSET),
+            MINQ, MAXQ_8_BITS) >>
+      6;
   cdef_info->cdef_damping = AOMMIN(3 + damping_offset, 6);
 #else
   cdef_info->cdef_damping = 3 + (cm->quant_params.base_qindex >> 6);
@@ -414,14 +414,13 @@
   const int nhfb = (mi_params->mi_cols + MI_SIZE_64X64 - 1) / MI_SIZE_64X64;
   int *sb_index = aom_malloc(nvfb * nhfb * sizeof(*sb_index));
 #if CONFIG_EXTQUANT
-  int damping_offset = clamp(cm->quant_params.base_qindex -
-                                 (cm->seq_params.bit_depth == AOM_BITS_8
-                                      ? 0
-                                      : cm->seq_params.bit_depth == AOM_BITS_10
-                                            ? 2 * MAXQ_OFFSET
-                                            : 4 * MAXQ_OFFSET),
-                             MINQ, MAXQ_8_BITS) >>
-                       6;
+  int damping_offset =
+      clamp(cm->quant_params.base_qindex -
+                (cm->seq_params.bit_depth == AOM_BITS_8    ? 0
+                 : cm->seq_params.bit_depth == AOM_BITS_10 ? 2 * MAXQ_OFFSET
+                                                           : 4 * MAXQ_OFFSET),
+            MINQ, MAXQ_8_BITS) >>
+      6;
   const int damping = AOMMIN(3 + damping_offset, 6);
 #else
   const int damping = 3 + (cm->quant_params.base_qindex >> 6);
diff --git a/av1/encoder/pickcdef.h b/av1/encoder/pickcdef.h
index fc81617..8740a66 100644
--- a/av1/encoder/pickcdef.h
+++ b/av1/encoder/pickcdef.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #ifndef AOM_AV1_ENCODER_PICKCDEF_H_
 #define AOM_AV1_ENCODER_PICKCDEF_H_
diff --git a/av1/encoder/picklpf.c b/av1/encoder/picklpf.c
index b715a40..b27b94d 100644
--- a/av1/encoder/picklpf.c
+++ b/av1/encoder/picklpf.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/av1/encoder/picklpf.h b/av1/encoder/picklpf.h
index 7273355..d639857 100644
--- a/av1/encoder/picklpf.h
+++ b/av1/encoder/picklpf.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_PICKLPF_H_
diff --git a/av1/encoder/pickrst.c b/av1/encoder/pickrst.c
index bc46945..e6ea8d4 100644
--- a/av1/encoder/pickrst.c
+++ b/av1/encoder/pickrst.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/av1/encoder/pickrst.h b/av1/encoder/pickrst.h
index 3c8efe3..04b7e9f 100644
--- a/av1/encoder/pickrst.h
+++ b/av1/encoder/pickrst.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #ifndef AOM_AV1_ENCODER_PICKRST_H_
 #define AOM_AV1_ENCODER_PICKRST_H_
diff --git a/av1/encoder/pustats.h b/av1/encoder/pustats.h
index 2e87101..added6d 100644
--- a/av1/encoder/pustats.h
+++ b/av1/encoder/pustats.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_PUSTATS_H_
diff --git a/av1/encoder/random.h b/av1/encoder/random.h
index 0bca391..a6ab114 100644
--- a/av1/encoder/random.h
+++ b/av1/encoder/random.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_RANDOM_H_
diff --git a/av1/encoder/ransac.c b/av1/encoder/ransac.c
index 07e1a5f..53beb15 100644
--- a/av1/encoder/ransac.c
+++ b/av1/encoder/ransac.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #include <memory.h>
 #include <math.h>
diff --git a/av1/encoder/ransac.h b/av1/encoder/ransac.h
index 583d971..18e5468 100644
--- a/av1/encoder/ransac.h
+++ b/av1/encoder/ransac.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_RANSAC_H_
diff --git a/av1/encoder/ratectrl.c b/av1/encoder/ratectrl.c
index e3d5fe6..fc7aaf7 100644
--- a/av1/encoder/ratectrl.c
+++ b/av1/encoder/ratectrl.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
@@ -120,11 +121,9 @@
 
 #if CONFIG_EXTQUANT
   return av1_find_qindex(minqtarget, bit_depth, 0,
-                         bit_depth == AOM_BITS_8
-                             ? QINDEX_RANGE_8_BITS - 1
-                             : bit_depth == AOM_BITS_10
-                                   ? QINDEX_RANGE_10_BITS - 1
-                                   : QINDEX_RANGE - 1);
+                         bit_depth == AOM_BITS_8    ? QINDEX_RANGE_8_BITS - 1
+                         : bit_depth == AOM_BITS_10 ? QINDEX_RANGE_10_BITS - 1
+                                                    : QINDEX_RANGE - 1);
 #else
   return av1_find_qindex(minqtarget, bit_depth, 0, QINDEX_RANGE - 1);
 #endif
@@ -136,10 +135,9 @@
                            aom_bit_depth_t bit_depth) {
   int i;
 #if CONFIG_EXTQUANT
-  for (i = 0; i < (bit_depth == AOM_BITS_8
-                       ? QINDEX_RANGE_8_BITS
-                       : bit_depth == AOM_BITS_10 ? QINDEX_RANGE_10_BITS
-                                                  : QINDEX_RANGE);
+  for (i = 0; i < (bit_depth == AOM_BITS_8    ? QINDEX_RANGE_8_BITS
+                   : bit_depth == AOM_BITS_10 ? QINDEX_RANGE_10_BITS
+                                              : QINDEX_RANGE);
        i++) {
 #else
   for (i = 0; i < QINDEX_RANGE; i++) {
@@ -266,6 +264,7 @@
   return target;
 }
 
+#if CONFIG_SVC_ENCODER
 // Update the buffer level for higher temporal layers, given the encoded current
 // temporal layer.
 static void update_layer_buffer_level(SVC *svc, int encoded_frame_size) {
@@ -284,6 +283,8 @@
     lrc->buffer_level = lrc->bits_off_target;
   }
 }
+#endif  // CONFIG_SVC_ENCODER
+
 // Update the buffer level: leaky bucket model.
 static void update_buffer_level(AV1_COMP *cpi, int encoded_frame_size) {
   const AV1_COMMON *const cm = &cpi->common;
@@ -299,7 +300,9 @@
   rc->bits_off_target = AOMMIN(rc->bits_off_target, rc->maximum_buffer_size);
   rc->buffer_level = rc->bits_off_target;
 
+#if CONFIG_SVC_ENCODER
   if (cpi->use_svc) update_layer_buffer_level(&cpi->svc, encoded_frame_size);
+#endif  // CONFIG_SVC_ENCODER
 }
 
 int av1_rc_get_default_min_gf_interval(int width, int height,
@@ -431,7 +434,12 @@
 static int adjust_q_cbr(const AV1_COMP *cpi, int q, int active_worst_quality) {
   const RATE_CONTROL *const rc = &cpi->rc;
   const AV1_COMMON *const cm = &cpi->common;
+#if CONFIG_NEW_REF_SIGNALING
+  const GF_GROUP *const gf_group = &cpi->gf_group;
+  const int level = gf_group->layer_depth[gf_group->index];
+#else
   const RefreshFrameFlagsInfo *const refresh_frame_flags = &cpi->refresh_frame;
+#endif  // CONFIG_NEW_REF_SIGNALING
   const int max_delta = 16;
   const int change_avg_frame_bandwidth =
       abs(rc->avg_frame_bandwidth - rc->prev_avg_frame_bandwidth) >
@@ -443,11 +451,18 @@
       (cm->width != cm->prev_frame->width ||
        cm->height != cm->prev_frame->height || change_avg_frame_bandwidth);
   // Apply some control/clamp to QP under certain conditions.
-  if (cm->current_frame.frame_type != KEY_FRAME && !cpi->use_svc &&
+  if (cm->current_frame.frame_type != KEY_FRAME &&
+#if CONFIG_SVC_ENCODER
+      !cpi->use_svc &&
+#endif  // CONFIG_SVC_ENCODER
       rc->frames_since_key > 1 && !change_target_bits_mb &&
       (!cpi->oxcf.rc_cfg.gf_cbr_boost_pct ||
+#if CONFIG_NEW_REF_SIGNALING
+       (level > 1))) {
+#else
        !(refresh_frame_flags->alt_ref_frame ||
          refresh_frame_flags->golden_frame))) {
+#endif  // CONFIG_NEW_REF_SIGNALING
     // Make sure q is between oscillating Qs to prevent resonance.
     if (rc->rc_1_frame * rc->rc_2_frame == -1 &&
         rc->q_1_frame != rc->q_2_frame) {
@@ -459,7 +474,10 @@
   }
   // For single spatial layer: if resolution has increased push q closer
   // to the active_worst to avoid excess overshoot.
-  if (cpi->svc.number_spatial_layers <= 1 && cm->prev_frame &&
+  if (cm->prev_frame &&
+#if CONFIG_SVC_ENCODER
+      cpi->svc.number_spatial_layers <= 1 &&
+#endif  // CONFIG_SVC_ENCODER
       (cm->width * cm->height >
        1.5 * cm->prev_frame->width * cm->prev_frame->height))
     q = (q + active_worst_quality) >> 1;
@@ -500,7 +518,12 @@
 static double get_rate_correction_factor(const AV1_COMP *cpi, int width,
                                          int height) {
   const RATE_CONTROL *const rc = &cpi->rc;
+#if CONFIG_NEW_REF_SIGNALING
+  const GF_GROUP *const gf_group = &cpi->gf_group;
+  const int level = gf_group->layer_depth[gf_group->index];
+#else
   const RefreshFrameFlagsInfo *const refresh_frame_flags = &cpi->refresh_frame;
+#endif  // CONFIG_NEW_REF_SIGNALING
   double rcf;
 
   if (cpi->common.current_frame.frame_type == KEY_FRAME) {
@@ -509,9 +532,17 @@
     const RATE_FACTOR_LEVEL rf_lvl = get_rate_factor_level(&cpi->gf_group);
     rcf = rc->rate_correction_factors[rf_lvl];
   } else {
-    if ((refresh_frame_flags->alt_ref_frame ||
+    if (
+#if CONFIG_NEW_REF_SIGNALING
+        level <= 1 &&
+#else
+        (refresh_frame_flags->alt_ref_frame ||
          refresh_frame_flags->golden_frame) &&
-        !rc->is_src_frame_alt_ref && !cpi->use_svc &&
+        !rc->is_src_frame_alt_ref &&
+#endif  // CONFIG_NEW_REF_SIGNALING
+#if CONFIG_SVC_ENCODER
+        !cpi->use_svc &&
+#endif  // CONFIG_SVC_ENCODER
         (cpi->oxcf.rc_cfg.mode != AOM_CBR ||
          cpi->oxcf.rc_cfg.gf_cbr_boost_pct > 20))
       rcf = rc->rate_correction_factors[GF_ARF_STD];
@@ -540,7 +571,12 @@
 static void set_rate_correction_factor(AV1_COMP *cpi, double factor, int width,
                                        int height) {
   RATE_CONTROL *const rc = &cpi->rc;
+#if CONFIG_NEW_REF_SIGNALING
+  const GF_GROUP *const gf_group = &cpi->gf_group;
+  const int level = gf_group->layer_depth[gf_group->index];
+#else
   const RefreshFrameFlagsInfo *const refresh_frame_flags = &cpi->refresh_frame;
+#endif  // CONFIG_NEW_REF_SIGNALING
 
   // Normalize RCF to account for the size-dependent scaling factor.
   factor /= resize_rate_factor(&cpi->oxcf.frm_dim_cfg, width, height);
@@ -553,9 +589,17 @@
     const RATE_FACTOR_LEVEL rf_lvl = get_rate_factor_level(&cpi->gf_group);
     rc->rate_correction_factors[rf_lvl] = factor;
   } else {
-    if ((refresh_frame_flags->alt_ref_frame ||
+    if (
+#if CONFIG_NEW_REF_SIGNALING
+        level <= 1 &&
+#else
+        (refresh_frame_flags->alt_ref_frame ||
          refresh_frame_flags->golden_frame) &&
-        !rc->is_src_frame_alt_ref && !cpi->use_svc &&
+        !rc->is_src_frame_alt_ref &&
+#endif  // CONFIG_NEW_REF_SIGNALING
+#if CONFIG_SVC_ENCODER
+        !cpi->use_svc &&
+#endif  // CONFIG_SVC_ENCODER
         (cpi->oxcf.rc_cfg.mode != AOM_CBR ||
          cpi->oxcf.rc_cfg.gf_cbr_boost_pct > 20))
       rc->rate_correction_factors[GF_ARF_STD] = factor;
@@ -795,7 +839,12 @@
 
 static int calc_active_worst_quality_no_stats_vbr(const AV1_COMP *cpi) {
   const RATE_CONTROL *const rc = &cpi->rc;
+#if CONFIG_NEW_REF_SIGNALING
+  const GF_GROUP *const gf_group = &cpi->gf_group;
+  const int level = gf_group->layer_depth[gf_group->index];
+#else
   const RefreshFrameFlagsInfo *const refresh_frame_flags = &cpi->refresh_frame;
+#endif  // CONFIG_NEW_REF_SIGNALING
   const unsigned int curr_frame = cpi->common.current_frame.frame_number;
   int active_worst_quality;
 
@@ -803,9 +852,13 @@
     active_worst_quality =
         curr_frame == 0 ? rc->worst_quality : rc->last_q[KEY_FRAME] * 2;
   } else {
+#if CONFIG_NEW_REF_SIGNALING
+    if (!rc->is_src_frame_alt_ref && level <= 1) {
+#else
     if (!rc->is_src_frame_alt_ref && (refresh_frame_flags->golden_frame ||
                                       refresh_frame_flags->bwd_ref_frame ||
                                       refresh_frame_flags->alt_ref_frame)) {
+#endif  // CONFIG_NEW_REF_SIGNALING
       active_worst_quality = curr_frame == 1 ? rc->last_q[KEY_FRAME] * 5 / 4
                                              : rc->last_q[INTER_FRAME];
     } else {
@@ -878,7 +931,12 @@
                                                  int width, int height) {
   const AV1_COMMON *const cm = &cpi->common;
   const RATE_CONTROL *const rc = &cpi->rc;
+#if CONFIG_NEW_REF_SIGNALING
+  const GF_GROUP *const gf_group = &cpi->gf_group;
+  const int level = gf_group->layer_depth[gf_group->index];
+#else
   const RefreshFrameFlagsInfo *const refresh_frame_flags = &cpi->refresh_frame;
+#endif  // CONFIG_NEW_REF_SIGNALING
   const CurrentFrame *const current_frame = &cm->current_frame;
   int *rtc_minq;
   const int bit_depth = cm->seq_params.bit_depth;
@@ -911,10 +969,17 @@
       active_best_quality +=
           av1_compute_qdelta(rc, q_val, q_val * q_adj_factor, bit_depth);
     }
-  } else if (!rc->is_src_frame_alt_ref && !cpi->use_svc &&
+  } else if (!rc->is_src_frame_alt_ref &&
+#if CONFIG_SVC_ENCODER
+             !cpi->use_svc &&
+#endif  // CONFIG_SVC_ENCODER
              cpi->oxcf.rc_cfg.gf_cbr_boost_pct &&
+#if CONFIG_NEW_REF_SIGNALING
+             level <= 1) {
+#else
              (refresh_frame_flags->golden_frame ||
               refresh_frame_flags->alt_ref_frame)) {
+#endif  // CONFIG_NEW_REF_SIGNALING
     // Use the lower of active_worst_quality and recent
     // average Q as basis for GF/ARF best Q limit unless last frame was
     // a key frame.
@@ -1136,8 +1201,12 @@
   const RATE_CONTROL *const rc = &cpi->rc;
   const CurrentFrame *const current_frame = &cm->current_frame;
   const AV1EncoderConfig *const oxcf = &cpi->oxcf;
-  const RefreshFrameFlagsInfo *const refresh_frame_flags = &cpi->refresh_frame;
   const GF_GROUP *const gf_group = &cpi->gf_group;
+#if CONFIG_NEW_REF_SIGNALING
+  const int level = gf_group->layer_depth[gf_group->index];
+#else
+  const RefreshFrameFlagsInfo *const refresh_frame_flags = &cpi->refresh_frame;
+#endif  // CONFIG_NEW_REF_SIGNALING
   const enum aom_rc_mode rc_mode = oxcf->rc_cfg.mode;
 
   assert(has_no_stats_stage(cpi));
@@ -1197,8 +1266,12 @@
       }
     }
   } else if (!rc->is_src_frame_alt_ref &&
+#if CONFIG_NEW_REF_SIGNALING
+             level <= 1) {
+#else
              (refresh_frame_flags->golden_frame ||
               refresh_frame_flags->alt_ref_frame)) {
+#endif  // CONFIG_NEW_REF_SIGNALING
     // Use the lower of active_worst_quality and recent
     // average Q as basis for GF/ARF best Q limit unless last frame was
     // a key frame.
@@ -1217,7 +1290,11 @@
       const int qindex = qp;
       const double q_val = av1_convert_qindex_to_q(qindex, bit_depth);
       const int delta_qindex =
+#if CONFIG_NEW_REF_SIGNALING
+          (level <= 1)
+#else
           (refresh_frame_flags->alt_ref_frame)
+#endif  // CONFIG_NEW_REF_SIGNALING
               ? av1_compute_qdelta(rc, q_val, q_val * 0.40, bit_depth)
               : av1_compute_qdelta(rc, q_val, q_val * 0.50, bit_depth);
       active_best_quality = AOMMAX(qindex + delta_qindex, rc->best_quality);
@@ -1257,8 +1334,12 @@
           &cpi->rc, current_frame->frame_type, active_worst_quality, 2.0,
           cpi->is_screen_content_type, bit_depth);
     } else if (!rc->is_src_frame_alt_ref &&
+#if CONFIG_NEW_REF_SIGNALING
+               (level <= 1)) {
+#else
                (refresh_frame_flags->golden_frame ||
                 refresh_frame_flags->alt_ref_frame)) {
+#endif  // CONFIG_NEW_REF_SIGNALING
       qdelta = av1_compute_qdelta_by_rate(
           &cpi->rc, current_frame->frame_type, active_worst_quality, 1.75,
           cpi->is_screen_content_type, bit_depth);
@@ -1420,17 +1501,26 @@
                                                  int *active_best) {
   const AV1_COMMON *const cm = &cpi->common;
   const RATE_CONTROL *const rc = &cpi->rc;
+#if CONFIG_NEW_REF_SIGNALING
+  const GF_GROUP *const gf_group = &cpi->gf_group;
+  const int level = gf_group->layer_depth[gf_group->index];
+#else
   const RefreshFrameFlagsInfo *const refresh_frame_flags = &cpi->refresh_frame;
+#endif  // CONFIG_NEW_REF_SIGNALING
   const int bit_depth = cpi->common.seq_params.bit_depth;
   int active_best_quality = *active_best;
   int active_worst_quality = *active_worst;
   // Extension to max or min Q if undershoot or overshoot is outside
   // the permitted range.
   if (cpi->oxcf.rc_cfg.mode != AOM_Q) {
-    if (frame_is_intra_only(cm) ||
-        (!rc->is_src_frame_alt_ref &&
-         (refresh_frame_flags->golden_frame || is_intrl_arf_boost ||
-          refresh_frame_flags->alt_ref_frame))) {
+    if (frame_is_intra_only(cm) || (!rc->is_src_frame_alt_ref &&
+#if CONFIG_NEW_REF_SIGNALING
+                                    (level <= 1 || is_intrl_arf_boost))) {
+#else
+                                    (refresh_frame_flags->golden_frame ||
+                                     is_intrl_arf_boost ||
+                                     refresh_frame_flags->alt_ref_frame))) {
+#endif  // CONFIG_NEW_REF_SIGNALING
       active_best_quality -=
           (cpi->twopass.extend_minq + cpi->twopass.extend_minq_fast);
       active_worst_quality += (cpi->twopass.extend_maxq / 2);
@@ -1533,8 +1623,6 @@
   const int bit_depth = cm->seq_params.bit_depth;
   const RATE_CONTROL *const rc = &cpi->rc;
   const AV1EncoderConfig *const oxcf = &cpi->oxcf;
-  const RefreshFrameFlagsInfo *const refresh_frame_flags = &cpi->refresh_frame;
-  (void)refresh_frame_flags;
   const GF_GROUP *gf_group = &cpi->gf_group;
   const enum aom_rc_mode rc_mode = oxcf->rc_cfg.mode;
   int *inter_minq;
@@ -1625,8 +1713,12 @@
   const AV1_COMMON *const cm = &cpi->common;
   const RATE_CONTROL *const rc = &cpi->rc;
   const AV1EncoderConfig *const oxcf = &cpi->oxcf;
-  const RefreshFrameFlagsInfo *const refresh_frame_flags = &cpi->refresh_frame;
   const GF_GROUP *gf_group = &cpi->gf_group;
+#if CONFIG_NEW_REF_SIGNALING
+  const int level = gf_group->layer_depth[gf_group->index];
+#else
+  const RefreshFrameFlagsInfo *const refresh_frame_flags = &cpi->refresh_frame;
+#endif  // CONFIG_NEW_REF_SIGNALING
   assert(IMPLIES(has_no_stats_stage(cpi),
                  cpi->oxcf.rc_cfg.mode == AOM_Q &&
                      gf_group->update_type[gf_index] != ARF_UPDATE &&
@@ -1680,8 +1772,12 @@
     // leaf (non arf) frames. This is important to the TPL model which assumes
     // Q drops with each arf level.
     if (!(rc->is_src_frame_alt_ref) &&
+#if CONFIG_NEW_REF_SIGNALING
+        (level <= 1 || is_intrl_arf_boost)) {
+#else
         (refresh_frame_flags->golden_frame ||
          refresh_frame_flags->alt_ref_frame || is_intrl_arf_boost)) {
+#endif  // CONFIG_NEW_REF_SIGNALING
       active_worst_quality =
           (active_best_quality + (3 * active_worst_quality) + 2) / 4;
     }
@@ -1787,8 +1883,15 @@
 static void update_golden_frame_stats(AV1_COMP *cpi) {
   RATE_CONTROL *const rc = &cpi->rc;
 
+#if CONFIG_NEW_REF_SIGNALING
+  const GF_GROUP *const gf_group = &cpi->gf_group;
+  // Update the Golden frame usage counts.
+  if (gf_group->update_type[gf_group->index] == GF_UPDATE ||
+      rc->is_src_frame_alt_ref) {
+#else
   // Update the Golden frame usage counts.
   if (cpi->refresh_frame.golden_frame || rc->is_src_frame_alt_ref) {
+#endif  // CONFIG_NEW_REF_SIGNALING
     rc->frames_since_golden = 0;
   } else if (cpi->common.show_frame) {
     rc->frames_since_golden++;
@@ -1800,7 +1903,11 @@
   const CurrentFrame *const current_frame = &cm->current_frame;
   RATE_CONTROL *const rc = &cpi->rc;
   const GF_GROUP *const gf_group = &cpi->gf_group;
+#if CONFIG_NEW_REF_SIGNALING
+  const int level = gf_group->layer_depth[gf_group->index];
+#else
   const RefreshFrameFlagsInfo *const refresh_frame_flags = &cpi->refresh_frame;
+#endif  // CONFIG_NEW_REF_SIGNALING
 
   const int is_intrnl_arf =
       gf_group->update_type[gf_group->index] == INTNL_ARF_UPDATE;
@@ -1819,10 +1926,17 @@
     rc->avg_frame_qindex[KEY_FRAME] =
         ROUND_POWER_OF_TWO(3 * rc->avg_frame_qindex[KEY_FRAME] + qindex, 2);
   } else {
-    if ((cpi->use_svc && cpi->oxcf.rc_cfg.mode == AOM_CBR) ||
+    if (
+#if CONFIG_SVC_ENCODER
+        (cpi->use_svc && cpi->oxcf.rc_cfg.mode == AOM_CBR) ||
+#endif  // CONFIG_SVC_ENCODER
         (!rc->is_src_frame_alt_ref &&
+#if CONFIG_NEW_REF_SIGNALING
+         !(level <= 1 || is_intrnl_arf))) {
+#else
          !(refresh_frame_flags->golden_frame || is_intrnl_arf ||
            refresh_frame_flags->alt_ref_frame))) {
+#endif  // CONFIG_NEW_REF_SIGNALING
       rc->last_q[INTER_FRAME] = qindex;
       rc->avg_frame_qindex[INTER_FRAME] =
           ROUND_POWER_OF_TWO(3 * rc->avg_frame_qindex[INTER_FRAME] + qindex, 2);
@@ -1844,8 +1958,12 @@
   if ((qindex < rc->last_boosted_qindex) ||
       (current_frame->frame_type == KEY_FRAME) ||
       (!rc->constrained_gf_group &&
+#if CONFIG_NEW_REF_SIGNALING
+       (level <= 1 || is_intrnl_arf))) {
+#else
        (refresh_frame_flags->alt_ref_frame || is_intrnl_arf ||
         (refresh_frame_flags->golden_frame && !rc->is_src_frame_alt_ref)))) {
+#endif  // CONFIG_NEW_REF_SIGNALING
     rc->last_boosted_qindex = qindex;
   }
   if (current_frame->frame_type == KEY_FRAME) rc->last_kf_qindex = qindex;
@@ -1878,7 +1996,11 @@
 
   if (is_altref_enabled(cpi->oxcf.gf_cfg.lag_in_frames,
                         cpi->oxcf.gf_cfg.enable_auto_arf) &&
+#if CONFIG_NEW_REF_SIGNALING
+      gf_group->update_type[gf_group->index] == ARF_UPDATE &&
+#else
       refresh_frame_flags->alt_ref_frame &&
+#endif  // CONFIG_NEW_REF_SIGNALING
       (current_frame->frame_type != KEY_FRAME && !frame_is_sframe(cm)))
     // Update the alternate reference frame stats as appropriate.
     update_alt_ref_frame_stats(cpi);
@@ -2138,6 +2260,7 @@
   } else {
     target = rc->avg_frame_bandwidth;
   }
+#if CONFIG_SVC_ENCODER
   if (cpi->use_svc) {
     // Note that for layers, avg_frame_bandwidth is the cumulative
     // per-frame-bandwidth. For the target size of this frame, use the
@@ -2149,6 +2272,7 @@
     target = lc->avg_frame_size;
     min_frame_target = AOMMAX(lc->avg_frame_size >> 4, FRAME_OVERHEAD_BITS);
   }
+#endif  // CONFIG_SVC_ENCODER
   if (diff > 0) {
     // Lower the target bandwidth for this frame.
     const int pct_low =
diff --git a/av1/encoder/ratectrl.h b/av1/encoder/ratectrl.h
index bfaeb94..11893a3 100644
--- a/av1/encoder/ratectrl.h
+++ b/av1/encoder/ratectrl.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_RATECTRL_H_
diff --git a/av1/encoder/rc_utils.h b/av1/encoder/rc_utils.h
index 71eb635..d5325e8 100644
--- a/av1/encoder/rc_utils.h
+++ b/av1/encoder/rc_utils.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_RC_UTILS_H_
diff --git a/av1/encoder/rd.c b/av1/encoder/rd.c
index 0e4e0a0..a23a46a 100644
--- a/av1/encoder/rd.c
+++ b/av1/encoder/rd.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
@@ -40,6 +41,7 @@
 #include "av1/encoder/mcomp.h"
 #include "av1/encoder/ratectrl.h"
 #include "av1/encoder/rd.h"
+#include "av1/encoder/rdopt_utils.h"
 #include "av1/encoder/tokenize.h"
 
 #define RD_THRESH_POW 1.25
@@ -126,20 +128,35 @@
                              fc->skip_txfm_cdfs[i], NULL);
   }
 
+#if CONFIG_MRLS
+  av1_cost_tokens_from_cdf(mode_costs->mrl_index_cost, fc->mrl_index_cdf, NULL);
+#endif
+#if CONFIG_AIMC
+  av1_cost_tokens_from_cdf(mode_costs->y_primary_flag_cost, fc->y_mode_set_cdf,
+                           NULL);
+  for (i = 0; i < Y_MODE_CONTEXTS; ++i) {
+    // y mode costs
+    av1_cost_tokens_from_cdf(mode_costs->y_first_mode_costs[i],
+                             fc->y_mode_idx_cdf_0[i], NULL);
+    av1_cost_tokens_from_cdf(mode_costs->y_second_mode_costs[i],
+                             fc->y_mode_idx_cdf_1[i], NULL);
+  }
+#else
   for (i = 0; i < KF_MODE_CONTEXTS; ++i)
     for (j = 0; j < KF_MODE_CONTEXTS; ++j)
       av1_cost_tokens_from_cdf(mode_costs->y_mode_costs[i][j],
                                fc->kf_y_cdf[i][j], NULL);
-
-#if CONFIG_MRLS
-  av1_cost_tokens_from_cdf(mode_costs->mrl_index_cost, fc->mrl_index_cdf, NULL);
-#endif
-
   for (i = 0; i < BLOCK_SIZE_GROUPS; ++i)
     av1_cost_tokens_from_cdf(mode_costs->mbmode_cost[i], fc->y_mode_cdf[i],
                              NULL);
+#endif  // CONFIG_AIMC
+
   for (i = 0; i < CFL_ALLOWED_TYPES; ++i)
+#if CONFIG_AIMC
+    for (j = 0; j < UV_MODE_CONTEXTS; ++j)
+#else
     for (j = 0; j < INTRA_MODES; ++j)
+#endif
       av1_cost_tokens_from_cdf(mode_costs->intra_uv_mode_cost[i][j],
                                fc->uv_mode_cdf[i][j], NULL);
 
@@ -260,6 +277,7 @@
       }
     }
   }
+#if !CONFIG_AIMC
 #if CONFIG_SDP
   for (i = 0; i < PARTITION_STRUCTURE_NUM; ++i) {
     for (j = 0; j < DIRECTIONAL_MODES; ++j) {
@@ -268,28 +286,13 @@
     }
   }
 
-#if CONFIG_ORIP
-  for (i = 0; i < PARTITION_STRUCTURE_NUM; ++i) {
-    for (j = 0; j < TOTAL_NUM_ORIP_ANGLE_DELTA; ++j) {
-      av1_cost_tokens_from_cdf(mode_costs->angle_delta_cost_hv[i][j],
-                               fc->angle_delta_cdf_hv[i][j], NULL);
-    }
-  }
-#endif
-
 #else
   for (i = 0; i < DIRECTIONAL_MODES; ++i) {
     av1_cost_tokens_from_cdf(mode_costs->angle_delta_cost[i],
                              fc->angle_delta_cdf[i], NULL);
   }
-#if CONFIG_ORIP
-  for (i = 0; i < TOTAL_NUM_ORIP_ANGLE_DELTA; ++i) {
-    av1_cost_tokens_from_cdf(mode_costs->angle_delta_cost_hv[i],
-                             fc->angle_delta_cdf_hv[i], NULL);
-  }
-#endif
 #endif  // CONFIG_SDP
-
+#endif  // !CONFIG_AIMC
   av1_cost_tokens_from_cdf(mode_costs->intrabc_cost, fc->intrabc_cdf, NULL);
 
 #if CONFIG_IST
@@ -305,6 +308,23 @@
                                fc->comp_inter_cdf[i], NULL);
     }
 
+#if CONFIG_NEW_REF_SIGNALING
+    for (i = 0; i < REF_CONTEXTS; ++i) {
+      for (j = 0; j < INTER_REFS_PER_FRAME - 1; ++j) {
+        av1_cost_tokens_from_cdf(mode_costs->single_ref_cost[i][j],
+                                 fc->single_ref_cdf[i][j], NULL);
+      }
+    }
+
+    for (i = 0; i < REF_CONTEXTS; ++i) {
+      for (j = 0; j < COMPREF_BIT_TYPES; j++) {
+        for (int k = 0; k < INTER_REFS_PER_FRAME - 2; ++k) {
+          av1_cost_tokens_from_cdf(mode_costs->comp_ref_cost[i][j][k],
+                                   fc->comp_ref_cdf[i][j][k], NULL);
+        }
+      }
+    }
+#else
     for (i = 0; i < REF_CONTEXTS; ++i) {
       for (j = 0; j < SINGLE_REFS - 1; ++j) {
         av1_cost_tokens_from_cdf(mode_costs->single_ref_cost[i][j],
@@ -337,11 +357,21 @@
                                  fc->comp_bwdref_cdf[i][j], NULL);
       }
     }
+#endif  // CONFIG_NEW_REF_SIGNALING
 
+#if CONFIG_CONTEXT_DERIVATION
+    for (j = 0; j < INTRA_INTER_SKIP_TXFM_CONTEXTS; ++j) {
+      for (i = 0; i < INTRA_INTER_CONTEXTS; ++i) {
+        av1_cost_tokens_from_cdf(mode_costs->intra_inter_cost[j][i],
+                                 fc->intra_inter_cdf[j][i], NULL);
+      }
+    }
+#else
     for (i = 0; i < INTRA_INTER_CONTEXTS; ++i) {
       av1_cost_tokens_from_cdf(mode_costs->intra_inter_cost[i],
                                fc->intra_inter_cdf[i], NULL);
     }
+#endif  // CONFIG_CONTEXT_DERIVATION
 
 #if CONFIG_NEW_INTER_MODES
     for (i = 0; i < INTER_SINGLE_MODE_CONTEXTS; ++i) {
@@ -378,6 +408,12 @@
                                NULL);
     }
 #endif  // CONFIG_NEW_INTER_MODES
+
+#if CONFIG_OPTFLOW_REFINEMENT
+    for (i = 0; i < INTER_COMPOUND_MODE_CONTEXTS; ++i)
+      av1_cost_tokens_from_cdf(mode_costs->use_optflow_cost[i],
+                               fc->use_optflow_cdf[i], NULL);
+#endif  // CONFIG_OPTFLOW_REFINEMENT
     for (i = 0; i < INTER_COMPOUND_MODE_CONTEXTS; ++i)
       av1_cost_tokens_from_cdf(mode_costs->inter_compound_mode_cost[i],
                                fc->inter_compound_mode_cdf[i], NULL);
@@ -408,12 +444,6 @@
       av1_cost_tokens_from_cdf(mode_costs->motion_mode_cost1[i],
                                fc->obmc_cdf[i], NULL);
     }
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-    for (i = 0; i < COMP_INDEX_CONTEXTS; ++i) {
-      av1_cost_tokens_from_cdf(mode_costs->comp_idx_cost[i],
-                               fc->compound_index_cdf[i], NULL);
-    }
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
     for (i = 0; i < COMP_GROUP_IDX_CONTEXTS; ++i) {
       av1_cost_tokens_from_cdf(mode_costs->comp_group_idx_cost[i],
                                fc->comp_group_idx_cdf[i], NULL);
@@ -531,11 +561,10 @@
                            cpi->common.seq_params.bit_depth);
 #if CONFIG_EXTQUANT
     } while (newq > q &&
-             (qindex < (cpi->common.seq_params.bit_depth == AOM_BITS_8
-                            ? MAXQ_8_BITS
-                            : cpi->common.seq_params.bit_depth == AOM_BITS_10
-                                  ? MAXQ_10_BITS
-                                  : MAXQ)));
+             (qindex <
+              (cpi->common.seq_params.bit_depth == AOM_BITS_8    ? MAXQ_8_BITS
+               : cpi->common.seq_params.bit_depth == AOM_BITS_10 ? MAXQ_10_BITS
+                                                                 : MAXQ)));
 #else
     } while (newq > q && qindex < MAXQ);
 #endif
@@ -660,14 +689,14 @@
 
   for (segment_id = 0; segment_id < MAX_SEGMENTS; ++segment_id) {
 #if CONFIG_EXTQUANT
-    const int qindex = clamp(
-        av1_get_qindex(&cm->seg, segment_id, cm->quant_params.base_qindex,
-                       cm->seq_params.bit_depth) +
-            cm->quant_params.y_dc_delta_q,
-        0,
-        cm->seq_params.bit_depth == AOM_BITS_8
-            ? MAXQ_8_BITS
-            : cm->seq_params.bit_depth == AOM_BITS_10 ? MAXQ_10_BITS : MAXQ);
+    const int qindex =
+        clamp(av1_get_qindex(&cm->seg, segment_id, cm->quant_params.base_qindex,
+                             cm->seq_params.bit_depth) +
+                  cm->quant_params.y_dc_delta_q,
+              0,
+              cm->seq_params.bit_depth == AOM_BITS_8    ? MAXQ_8_BITS
+              : cm->seq_params.bit_depth == AOM_BITS_10 ? MAXQ_10_BITS
+                                                        : MAXQ);
 #else
     const int qindex = clamp(
         av1_get_qindex(&cm->seg, segment_id, cm->quant_params.base_qindex) +
@@ -687,7 +716,11 @@
       const int t = q * rd_thresh_block_size_factor[bsize];
       const int thresh_max = INT_MAX / t;
 
+#if CONFIG_NEW_REF_SIGNALING
+      for (i = 0; i < MB_MODE_COUNT; ++i)
+#else
       for (i = 0; i < MAX_MODES; ++i)
+#endif  // CONFIG_NEW_REF_SIGNALING
         rd->threshes[segment_id][bsize][i] = rd->thresh_mult[i] < thresh_max
                                                  ? rd->thresh_mult[i] * t / 4
                                                  : INT_MAX;
@@ -725,7 +758,11 @@
       for (int ctx = 0; ctx < TXB_SKIP_CONTEXTS; ++ctx)
         av1_cost_tokens_from_cdf(pcost->txb_skip_cost[ctx],
                                  fc->txb_skip_cdf[tx_size][ctx], NULL);
-
+#if CONFIG_CONTEXT_DERIVATION
+      for (int ctx = 0; ctx < V_TXB_SKIP_CONTEXTS; ++ctx)
+        av1_cost_tokens_from_cdf(pcost->v_txb_skip_cost[ctx],
+                                 fc->v_txb_skip_cdf[ctx], NULL);
+#endif  // CONFIG_CONTEXT_DERIVATION
       for (int ctx = 0; ctx < SIG_COEF_CONTEXTS_EOB; ++ctx)
         av1_cost_tokens_from_cdf(pcost->base_eob_cost[ctx],
                                  fc->coeff_base_eob_cdf[tx_size][plane][ctx],
@@ -752,6 +789,17 @@
       for (int ctx = 0; ctx < DC_SIGN_CONTEXTS; ++ctx)
         av1_cost_tokens_from_cdf(pcost->dc_sign_cost[ctx],
                                  fc->dc_sign_cdf[plane][ctx], NULL);
+#if CONFIG_CONTEXT_DERIVATION
+      if (plane == PLANE_TYPE_UV) {
+        for (int i = 0; i < CROSS_COMPONENT_CONTEXTS; ++i)
+          for (int ctx = 0; ctx < DC_SIGN_CONTEXTS; ++ctx)
+            av1_cost_tokens_from_cdf(pcost->v_dc_sign_cost[i][ctx],
+                                     fc->v_dc_sign_cdf[i][ctx], NULL);
+        for (int i = 0; i < CROSS_COMPONENT_CONTEXTS; ++i)
+          av1_cost_tokens_from_cdf(pcost->v_ac_sign_cost[i],
+                                   fc->v_ac_sign_cdf[i], NULL);
+      }
+#endif  // CONFIG_CONTEXT_DERIVATION
 
       for (int ctx = 0; ctx < LEVEL_CONTEXTS; ++ctx) {
         int br_rate[BR_CDF_SIZE];
@@ -1210,7 +1258,11 @@
 
 void av1_mv_pred(const AV1_COMP *cpi, MACROBLOCK *x, uint8_t *ref_y_buffer,
                  int ref_y_stride, int ref_frame, BLOCK_SIZE block_size) {
+#if CONFIG_NEW_REF_SIGNALING
+  const MV_REFERENCE_FRAME ref_frames[2] = { ref_frame, INVALID_IDX };
+#else
   const MV_REFERENCE_FRAME ref_frames[2] = { ref_frame, NONE_FRAME };
+#endif  // CONFIG_NEW_REF_SIGNALING
   const int_mv ref_mv =
       av1_get_ref_mv_from_stack(0, ref_frames, 0, x->mbmi_ext);
   const int_mv ref_mv1 =
@@ -1250,8 +1302,14 @@
   }
 
   // Note the index of the mv that worked best in the reference list.
+#if CONFIG_NEW_REF_SIGNALING
+  const MV_REFERENCE_FRAME rfn = COMPACT_INDEX0_NRS(ref_frame);
+  x->max_mv_context[rfn] = max_mv;
+  x->pred_mv_sad[rfn] = best_sad;
+#else
   x->max_mv_context[ref_frame] = max_mv;
   x->pred_mv_sad[ref_frame] = best_sad;
+#endif  // CONFIG_NEW_REF_SIGNALING
 }
 
 void av1_setup_pred_block(const MACROBLOCKD *xd,
@@ -1286,9 +1344,14 @@
 }
 
 YV12_BUFFER_CONFIG *av1_get_scaled_ref_frame(const AV1_COMP *cpi,
-                                             int ref_frame) {
+                                             MV_REFERENCE_FRAME ref_frame) {
+#if CONFIG_NEW_REF_SIGNALING
+  assert(ref_frame < cpi->common.ref_frames_info.n_total_refs);
+  RefCntBuffer *const scaled_buf = cpi->scaled_ref_buf[ref_frame];
+#else
   assert(ref_frame >= LAST_FRAME && ref_frame <= ALTREF_FRAME);
   RefCntBuffer *const scaled_buf = cpi->scaled_ref_buf[ref_frame - 1];
+#endif  // CONFIG_NEW_REF_SIGNALING
   const RefCntBuffer *const ref_buf =
       get_ref_frame_buf(&cpi->common, ref_frame);
   return (scaled_buf != ref_buf && scaled_buf != NULL) ? &scaled_buf->buf
@@ -1302,6 +1365,9 @@
                             InterpFilter interp_filter) {
   if (interp_filter == SWITCHABLE) {
     const MB_MODE_INFO *const mbmi = xd->mi[0];
+#if CONFIG_OPTFLOW_REFINEMENT
+    if (mbmi->mode > NEW_NEWMV) return 0;
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 #if CONFIG_REMOVE_DUAL_FILTER
     const int ctx = av1_get_pred_context_switchable_interp(xd, 0);
     const int inter_filter_cost =
@@ -1328,6 +1394,35 @@
   // Set baseline threshold values.
   av1_zero(rd->thresh_mult);
 
+#if CONFIG_NEW_REF_SIGNALING
+#if !CONFIG_NEW_INTER_MODES
+  rd->thresh_mult[NEARESTMV] = 300;
+  rd->thresh_mult[NEAREST_NEARESTMV] = 1000;
+  rd->thresh_mult[NEAREST_NEWMV] = 1500;
+  rd->thresh_mult[NEW_NEARESTMV] = 1500;
+#endif  // !CONFIG_NEW_INTER_MODES
+  rd->thresh_mult[NEWMV] = 1000;
+  rd->thresh_mult[NEARMV] = 1000;
+  rd->thresh_mult[GLOBALMV] = 2200;
+  rd->thresh_mult[NEAR_NEARMV] = 1500;
+  rd->thresh_mult[NEAR_NEWMV] = 1500;
+  rd->thresh_mult[NEW_NEARMV] = 1500;
+  rd->thresh_mult[NEW_NEWMV] = 1500;
+  rd->thresh_mult[GLOBAL_GLOBALMV] = 1500;
+  rd->thresh_mult[DC_PRED] = 1000;
+  rd->thresh_mult[PAETH_PRED] = 1000;
+  rd->thresh_mult[SMOOTH_PRED] = 2200;
+  rd->thresh_mult[SMOOTH_V_PRED] = 2000;
+  rd->thresh_mult[SMOOTH_H_PRED] = 2000;
+  rd->thresh_mult[H_PRED] = 2000;
+  rd->thresh_mult[V_PRED] = 1800;
+  rd->thresh_mult[D135_PRED] = 2500;
+  rd->thresh_mult[D203_PRED] = 2000;
+  rd->thresh_mult[D157_PRED] = 2500;
+  rd->thresh_mult[D67_PRED] = 2000;
+  rd->thresh_mult[D113_PRED] = 2500;
+  rd->thresh_mult[D45_PRED] = 2500;
+#else
 #if !CONFIG_NEW_INTER_MODES
   rd->thresh_mult[THR_NEARESTMV] = 300;
   rd->thresh_mult[THR_NEARESTL2] = 300;
@@ -1409,6 +1504,12 @@
   rd->thresh_mult[THR_COMP_NEW_NEARLA] = 1870;
   rd->thresh_mult[THR_COMP_NEW_NEWLA] = 2400;
   rd->thresh_mult[THR_COMP_GLOBAL_GLOBALLA] = 2750;
+#if CONFIG_OPTFLOW_REFINEMENT
+  rd->thresh_mult[THR_COMP_NEAR_NEAR_OPTFLOWLA] = 1530;
+  rd->thresh_mult[THR_COMP_NEAR_NEW_OPTFLOWLA] = 1530;
+  rd->thresh_mult[THR_COMP_NEW_NEAR_OPTFLOWLA] = 1530;
+  rd->thresh_mult[THR_COMP_NEW_NEW_OPTFLOWLA] = 1530;
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   rd->thresh_mult[THR_COMP_NEAR_NEARL2A] = 1200;
 #if !CONFIG_NEW_INTER_MODES
@@ -1419,6 +1520,12 @@
   rd->thresh_mult[THR_COMP_NEW_NEARL2A] = 1700;
   rd->thresh_mult[THR_COMP_NEW_NEWL2A] = 1800;
   rd->thresh_mult[THR_COMP_GLOBAL_GLOBALL2A] = 2500;
+#if CONFIG_OPTFLOW_REFINEMENT
+  rd->thresh_mult[THR_COMP_NEAR_NEAR_OPTFLOWL2A] = 1870;
+  rd->thresh_mult[THR_COMP_NEAR_NEW_OPTFLOWL2A] = 1870;
+  rd->thresh_mult[THR_COMP_NEW_NEAR_OPTFLOWL2A] = 1870;
+  rd->thresh_mult[THR_COMP_NEW_NEW_OPTFLOWL2A] = 1870;
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   rd->thresh_mult[THR_COMP_NEAR_NEARL3A] = 1200;
 #if !CONFIG_NEW_INTER_MODES
@@ -1429,6 +1536,12 @@
   rd->thresh_mult[THR_COMP_NEW_NEARL3A] = 1700;
   rd->thresh_mult[THR_COMP_NEW_NEWL3A] = 2000;
   rd->thresh_mult[THR_COMP_GLOBAL_GLOBALL3A] = 3000;
+#if CONFIG_OPTFLOW_REFINEMENT
+  rd->thresh_mult[THR_COMP_NEAR_NEAR_OPTFLOWL3A] = 1700;
+  rd->thresh_mult[THR_COMP_NEAR_NEW_OPTFLOWL3A] = 1700;
+  rd->thresh_mult[THR_COMP_NEW_NEAR_OPTFLOWL3A] = 1700;
+  rd->thresh_mult[THR_COMP_NEW_NEW_OPTFLOWL3A] = 1700;
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   rd->thresh_mult[THR_COMP_NEAR_NEARGA] = 1320;
 #if !CONFIG_NEW_INTER_MODES
@@ -1439,6 +1552,12 @@
   rd->thresh_mult[THR_COMP_NEW_NEARGA] = 1700;
   rd->thresh_mult[THR_COMP_NEW_NEWGA] = 2000;
   rd->thresh_mult[THR_COMP_GLOBAL_GLOBALGA] = 2250;
+#if CONFIG_OPTFLOW_REFINEMENT
+  rd->thresh_mult[THR_COMP_NEAR_NEAR_OPTFLOWGA] = 2040;
+  rd->thresh_mult[THR_COMP_NEAR_NEW_OPTFLOWGA] = 2040;
+  rd->thresh_mult[THR_COMP_NEW_NEAR_OPTFLOWGA] = 2040;
+  rd->thresh_mult[THR_COMP_NEW_NEW_OPTFLOWGA] = 2040;
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   rd->thresh_mult[THR_COMP_NEAR_NEARLB] = 1200;
 #if !CONFIG_NEW_INTER_MODES
@@ -1449,6 +1568,12 @@
   rd->thresh_mult[THR_COMP_NEW_NEARLB] = 1700;
   rd->thresh_mult[THR_COMP_NEW_NEWLB] = 2400;
   rd->thresh_mult[THR_COMP_GLOBAL_GLOBALLB] = 2250;
+#if CONFIG_OPTFLOW_REFINEMENT
+  rd->thresh_mult[THR_COMP_NEAR_NEAR_OPTFLOWLB] = 1360;
+  rd->thresh_mult[THR_COMP_NEAR_NEW_OPTFLOWLB] = 1360;
+  rd->thresh_mult[THR_COMP_NEW_NEAR_OPTFLOWLB] = 1360;
+  rd->thresh_mult[THR_COMP_NEW_NEW_OPTFLOWLB] = 1360;
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   rd->thresh_mult[THR_COMP_NEAR_NEARL2B] = 1200;
 #if !CONFIG_NEW_INTER_MODES
@@ -1459,6 +1584,12 @@
   rd->thresh_mult[THR_COMP_NEW_NEARL2B] = 1700;
   rd->thresh_mult[THR_COMP_NEW_NEWL2B] = 2000;
   rd->thresh_mult[THR_COMP_GLOBAL_GLOBALL2B] = 2500;
+#if CONFIG_OPTFLOW_REFINEMENT
+  rd->thresh_mult[THR_COMP_NEAR_NEAR_OPTFLOWL2B] = 1700;
+  rd->thresh_mult[THR_COMP_NEAR_NEW_OPTFLOWL2B] = 1700;
+  rd->thresh_mult[THR_COMP_NEW_NEAR_OPTFLOWL2B] = 1700;
+  rd->thresh_mult[THR_COMP_NEW_NEW_OPTFLOWL2B] = 1700;
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   rd->thresh_mult[THR_COMP_NEAR_NEARL3B] = 1200;
 #if !CONFIG_NEW_INTER_MODES
@@ -1469,6 +1600,12 @@
   rd->thresh_mult[THR_COMP_NEW_NEARL3B] = 1700;
   rd->thresh_mult[THR_COMP_NEW_NEWL3B] = 2000;
   rd->thresh_mult[THR_COMP_GLOBAL_GLOBALL3B] = 2500;
+#if CONFIG_OPTFLOW_REFINEMENT
+  rd->thresh_mult[THR_COMP_NEAR_NEAR_OPTFLOWL3B] = 1870;
+  rd->thresh_mult[THR_COMP_NEAR_NEW_OPTFLOWL3B] = 1870;
+  rd->thresh_mult[THR_COMP_NEW_NEAR_OPTFLOWL3B] = 1870;
+  rd->thresh_mult[THR_COMP_NEW_NEW_OPTFLOWL3B] = 1870;
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   rd->thresh_mult[THR_COMP_NEAR_NEARGB] = 1200;
 #if !CONFIG_NEW_INTER_MODES
@@ -1479,6 +1616,12 @@
   rd->thresh_mult[THR_COMP_NEW_NEARGB] = 1700;
   rd->thresh_mult[THR_COMP_NEW_NEWGB] = 2000;
   rd->thresh_mult[THR_COMP_GLOBAL_GLOBALGB] = 2500;
+#if CONFIG_OPTFLOW_REFINEMENT
+  rd->thresh_mult[THR_COMP_NEAR_NEAR_OPTFLOWGB] = 1700;
+  rd->thresh_mult[THR_COMP_NEAR_NEW_OPTFLOWGB] = 1700;
+  rd->thresh_mult[THR_COMP_NEW_NEAR_OPTFLOWGB] = 1700;
+  rd->thresh_mult[THR_COMP_NEW_NEW_OPTFLOWGB] = 1700;
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   rd->thresh_mult[THR_COMP_NEAR_NEARLA2] = 1200;
 #if !CONFIG_NEW_INTER_MODES
@@ -1489,6 +1632,12 @@
   rd->thresh_mult[THR_COMP_NEW_NEARLA2] = 1700;
   rd->thresh_mult[THR_COMP_NEW_NEWLA2] = 2000;
   rd->thresh_mult[THR_COMP_GLOBAL_GLOBALLA2] = 2500;
+#if CONFIG_OPTFLOW_REFINEMENT
+  rd->thresh_mult[THR_COMP_NEAR_NEAR_OPTFLOWLA2] = 1700;
+  rd->thresh_mult[THR_COMP_NEAR_NEW_OPTFLOWLA2] = 1700;
+  rd->thresh_mult[THR_COMP_NEW_NEAR_OPTFLOWLA2] = 1700;
+  rd->thresh_mult[THR_COMP_NEW_NEW_OPTFLOWLA2] = 1700;
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   rd->thresh_mult[THR_COMP_NEAR_NEARL2A2] = 1200;
 #if !CONFIG_NEW_INTER_MODES
@@ -1499,6 +1648,12 @@
   rd->thresh_mult[THR_COMP_NEW_NEARL2A2] = 1700;
   rd->thresh_mult[THR_COMP_NEW_NEWL2A2] = 2000;
   rd->thresh_mult[THR_COMP_GLOBAL_GLOBALL2A2] = 2500;
+#if CONFIG_OPTFLOW_REFINEMENT
+  rd->thresh_mult[THR_COMP_NEAR_NEAR_OPTFLOWL2A2] = 1700;
+  rd->thresh_mult[THR_COMP_NEAR_NEW_OPTFLOWL2A2] = 1700;
+  rd->thresh_mult[THR_COMP_NEW_NEAR_OPTFLOWL2A2] = 1700;
+  rd->thresh_mult[THR_COMP_NEW_NEW_OPTFLOWL2A2] = 1700;
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   rd->thresh_mult[THR_COMP_NEAR_NEARL3A2] = 1440;
 #if !CONFIG_NEW_INTER_MODES
@@ -1509,6 +1664,12 @@
   rd->thresh_mult[THR_COMP_NEW_NEARL3A2] = 1700;
   rd->thresh_mult[THR_COMP_NEW_NEWL3A2] = 2000;
   rd->thresh_mult[THR_COMP_GLOBAL_GLOBALL3A2] = 2500;
+#if CONFIG_OPTFLOW_REFINEMENT
+  rd->thresh_mult[THR_COMP_NEAR_NEAR_OPTFLOWL3A2] = 1700;
+  rd->thresh_mult[THR_COMP_NEAR_NEW_OPTFLOWL3A2] = 1700;
+  rd->thresh_mult[THR_COMP_NEW_NEAR_OPTFLOWL3A2] = 1700;
+  rd->thresh_mult[THR_COMP_NEW_NEW_OPTFLOWL3A2] = 1700;
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   rd->thresh_mult[THR_COMP_NEAR_NEARGA2] = 1200;
 #if !CONFIG_NEW_INTER_MODES
@@ -1519,6 +1680,12 @@
   rd->thresh_mult[THR_COMP_NEW_NEARGA2] = 1700;
   rd->thresh_mult[THR_COMP_NEW_NEWGA2] = 2000;
   rd->thresh_mult[THR_COMP_GLOBAL_GLOBALGA2] = 2750;
+#if CONFIG_OPTFLOW_REFINEMENT
+  rd->thresh_mult[THR_COMP_NEAR_NEAR_OPTFLOWGA2] = 1700;
+  rd->thresh_mult[THR_COMP_NEAR_NEW_OPTFLOWGA2] = 1700;
+  rd->thresh_mult[THR_COMP_NEW_NEAR_OPTFLOWGA2] = 1700;
+  rd->thresh_mult[THR_COMP_NEW_NEW_OPTFLOWGA2] = 1700;
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   rd->thresh_mult[THR_COMP_NEAR_NEARLL2] = 1600;
 #if !CONFIG_NEW_INTER_MODES
@@ -1529,6 +1696,12 @@
   rd->thresh_mult[THR_COMP_NEW_NEARLL2] = 2200;
   rd->thresh_mult[THR_COMP_NEW_NEWLL2] = 2400;
   rd->thresh_mult[THR_COMP_GLOBAL_GLOBALLL2] = 3200;
+#if CONFIG_OPTFLOW_REFINEMENT
+  rd->thresh_mult[THR_COMP_NEAR_NEAR_OPTFLOWLL2] = 2640;
+  rd->thresh_mult[THR_COMP_NEAR_NEW_OPTFLOWLL2] = 2640;
+  rd->thresh_mult[THR_COMP_NEW_NEAR_OPTFLOWLL2] = 2640;
+  rd->thresh_mult[THR_COMP_NEW_NEW_OPTFLOWLL2] = 2640;
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   rd->thresh_mult[THR_COMP_NEAR_NEARLL3] = 1600;
 #if !CONFIG_NEW_INTER_MODES
@@ -1539,6 +1712,12 @@
   rd->thresh_mult[THR_COMP_NEW_NEARLL3] = 2200;
   rd->thresh_mult[THR_COMP_NEW_NEWLL3] = 2400;
   rd->thresh_mult[THR_COMP_GLOBAL_GLOBALLL3] = 3200;
+#if CONFIG_OPTFLOW_REFINEMENT
+  rd->thresh_mult[THR_COMP_NEAR_NEAR_OPTFLOWLL3] = 2200;
+  rd->thresh_mult[THR_COMP_NEAR_NEW_OPTFLOWLL3] = 2200;
+  rd->thresh_mult[THR_COMP_NEW_NEAR_OPTFLOWLL3] = 2200;
+  rd->thresh_mult[THR_COMP_NEW_NEW_OPTFLOWLL3] = 2200;
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   rd->thresh_mult[THR_COMP_NEAR_NEARLG] = 1760;
 #if !CONFIG_NEW_INTER_MODES
@@ -1549,17 +1728,28 @@
   rd->thresh_mult[THR_COMP_NEW_NEARLG] = 2640;
   rd->thresh_mult[THR_COMP_NEW_NEWLG] = 2400;
   rd->thresh_mult[THR_COMP_GLOBAL_GLOBALLG] = 3200;
+#if CONFIG_OPTFLOW_REFINEMENT
+  rd->thresh_mult[THR_COMP_NEAR_NEAR_OPTFLOWLG] = 1760;
+  rd->thresh_mult[THR_COMP_NEAR_NEW_OPTFLOWLG] = 1760;
+  rd->thresh_mult[THR_COMP_NEW_NEAR_OPTFLOWLG] = 1760;
+  rd->thresh_mult[THR_COMP_NEW_NEW_OPTFLOWLG] = 1760;
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   rd->thresh_mult[THR_COMP_NEAR_NEARBA] = 1600;
 #if !CONFIG_NEW_INTER_MODES
   rd->thresh_mult[THR_COMP_NEAREST_NEWBA] = 2000;
   rd->thresh_mult[THR_COMP_NEW_NEARESTBA] = 2000;
-
 #endif  // !CONFIG_NEW_INTER_MODES
   rd->thresh_mult[THR_COMP_NEAR_NEWBA] = 2200;
   rd->thresh_mult[THR_COMP_NEW_NEARBA] = 1980;
   rd->thresh_mult[THR_COMP_NEW_NEWBA] = 2640;
   rd->thresh_mult[THR_COMP_GLOBAL_GLOBALBA] = 3200;
+#if CONFIG_OPTFLOW_REFINEMENT
+  rd->thresh_mult[THR_COMP_NEAR_NEAR_OPTFLOWBA] = 2200;
+  rd->thresh_mult[THR_COMP_NEAR_NEW_OPTFLOWBA] = 2200;
+  rd->thresh_mult[THR_COMP_NEW_NEAR_OPTFLOWBA] = 2200;
+  rd->thresh_mult[THR_COMP_NEW_NEW_OPTFLOWBA] = 2200;
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   rd->thresh_mult[THR_DC] = 1000;
   rd->thresh_mult[THR_PAETH] = 1000;
@@ -1574,14 +1764,25 @@
   rd->thresh_mult[THR_D67_PRED] = 2000;
   rd->thresh_mult[THR_D113_PRED] = 2500;
   rd->thresh_mult[THR_D45_PRED] = 2500;
+#endif  // CONFIG_NEW_REF_SIGNALING
 }
 
 void av1_update_rd_thresh_fact(const AV1_COMMON *const cm,
+#if CONFIG_NEW_REF_SIGNALING
+                               int (*factor_buf)[MB_MODE_COUNT],
+#else
                                int (*factor_buf)[MAX_MODES],
+#endif  // CONFIG_NEW_REF_SIGNALING
                                int use_adaptive_rd_thresh, BLOCK_SIZE bsize,
-                               THR_MODES best_mode_index) {
+#if !CONFIG_NEW_REF_SIGNALING
+                               MV_REFERENCE_FRAME *ref_frames,
+#endif  // !CONFIG_NEW_REF_SIGNALING
+                               PREDICTION_MODE best_mode) {
   assert(use_adaptive_rd_thresh > 0);
-  const THR_MODES top_mode = MAX_MODES;
+#if !CONFIG_NEW_REF_SIGNALING
+  const int best_mode_index =
+      get_prediction_mode_idx(best_mode, ref_frames[0], ref_frames[1]);
+#endif  // !CONFIG_NEW_REF_SIGNALING
   const int max_rd_thresh_factor = use_adaptive_rd_thresh * RD_THRESH_MAX_FACT;
 
   const int bsize_is_1_to_4 = bsize > cm->seq_params.sb_size;
@@ -1596,10 +1797,18 @@
     max_size = AOMMIN(bsize + 2, (int)cm->seq_params.sb_size);
   }
 
-  for (THR_MODES mode = 0; mode < top_mode; ++mode) {
+#if CONFIG_NEW_REF_SIGNALING
+  for (PREDICTION_MODE mode = 0; mode < MB_MODE_COUNT; ++mode) {
+#else
+  for (THR_MODES mode = 0; mode < MAX_MODES; ++mode) {
+#endif  // CONFIG_NEW_REF_SIGNALING
     for (BLOCK_SIZE bs = min_size; bs <= max_size; ++bs) {
       int *const fact = &factor_buf[bs][mode];
+#if CONFIG_NEW_REF_SIGNALING
+      if (mode == best_mode) {
+#else
       if (mode == best_mode_index) {
+#endif  // CONFIG_NEW_REF_SIGNALING
         *fact -= (*fact >> RD_THRESH_LOG_DEC_FACTOR);
       } else {
         *fact = AOMMIN(*fact + RD_THRESH_INC, max_rd_thresh_factor);
diff --git a/av1/encoder/rd.h b/av1/encoder/rd.h
index 41c8eec..9848efc 100644
--- a/av1/encoder/rd.h
+++ b/av1/encoder/rd.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_RD_H_
@@ -72,9 +73,13 @@
   // means that we will accept the best mode so far more often. This number
   // is used in combination with the current block size, and thresh_freq_fact
   // to pick a threshold.
+#if CONFIG_NEW_REF_SIGNALING
+  int thresh_mult[MB_MODE_COUNT];
+  int threshes[MAX_SEGMENTS][BLOCK_SIZES_ALL][MB_MODE_COUNT];
+#else
   int thresh_mult[MAX_MODES];
-
   int threshes[MAX_SEGMENTS][BLOCK_SIZES_ALL][MAX_MODES];
+#endif  // CONFIG_NEW_REF_SIGNALING
 
   int RDMULT;
 
@@ -249,7 +254,7 @@
                             InterpFilter interp_filter);
 
 YV12_BUFFER_CONFIG *av1_get_scaled_ref_frame(const struct AV1_COMP *cpi,
-                                             int ref_frame);
+                                             MV_REFERENCE_FRAME ref_frame);
 
 void av1_init_me_luts(void);
 
@@ -263,12 +268,24 @@
 void av1_set_rd_speed_thresholds(struct AV1_COMP *cpi);
 
 void av1_update_rd_thresh_fact(const AV1_COMMON *const cm,
-                               int (*fact)[MAX_MODES], int rd_thresh,
-                               BLOCK_SIZE bsize, THR_MODES best_mode_index);
+#if CONFIG_NEW_REF_SIGNALING
+                               int (*fact)[MB_MODE_COUNT],
+#else
+                               int (*fact)[MAX_MODES],
+#endif  // CONFIG_NEW_REF_SIGNALING
+                               int rd_thresh, BLOCK_SIZE bsize,
+#if !CONFIG_NEW_REF_SIGNALING
+                               MV_REFERENCE_FRAME *ref_frames,
+#endif  // !CONFIG_NEW_REF_SIGNALING
+                               PREDICTION_MODE best_mode);
 
 static INLINE void reset_thresh_freq_fact(MACROBLOCK *const x) {
   for (int i = 0; i < BLOCK_SIZES_ALL; ++i) {
+#if CONFIG_NEW_REF_SIGNALING
+    for (int j = 0; j < MB_MODE_COUNT; ++j) {
+#else
     for (int j = 0; j < MAX_MODES; ++j) {
+#endif  // CONFIG_NEW_REF_SIGNALING
       x->thresh_freq_fact[i][j] = RD_THRESH_FAC_FRAC_VAL;
     }
   }
diff --git a/av1/encoder/rdopt.c b/av1/encoder/rdopt.c
index 5a8b113..c52c82f 100644
--- a/av1/encoder/rdopt.c
+++ b/av1/encoder/rdopt.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
@@ -102,6 +103,7 @@
   4144,  4120,  4096
 };
 
+#if !CONFIG_NEW_REF_SIGNALING
 #if CONFIG_NEW_INTER_MODES
 static const THR_MODES av1_default_mode_order[MAX_MODES] = {
   THR_NEARMV,
@@ -150,81 +152,177 @@
   THR_COMP_NEAR_NEWLA,
   THR_COMP_NEW_NEWLA,
   THR_COMP_GLOBAL_GLOBALLA,
+#if CONFIG_OPTFLOW_REFINEMENT
+  THR_COMP_NEAR_NEAR_OPTFLOWLA,
+  THR_COMP_NEAR_NEW_OPTFLOWLA,
+  THR_COMP_NEW_NEAR_OPTFLOWLA,
+  THR_COMP_NEW_NEW_OPTFLOWLA,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   THR_COMP_NEW_NEARL2A,
   THR_COMP_NEAR_NEWL2A,
   THR_COMP_NEW_NEWL2A,
   THR_COMP_GLOBAL_GLOBALL2A,
+#if CONFIG_OPTFLOW_REFINEMENT
+  THR_COMP_NEAR_NEAR_OPTFLOWL2A,
+  THR_COMP_NEAR_NEW_OPTFLOWL2A,
+  THR_COMP_NEW_NEAR_OPTFLOWL2A,
+  THR_COMP_NEW_NEW_OPTFLOWL2A,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   THR_COMP_NEW_NEARL3A,
   THR_COMP_NEAR_NEWL3A,
   THR_COMP_NEW_NEWL3A,
   THR_COMP_GLOBAL_GLOBALL3A,
+#if CONFIG_OPTFLOW_REFINEMENT
+  THR_COMP_NEAR_NEAR_OPTFLOWL3A,
+  THR_COMP_NEAR_NEW_OPTFLOWL3A,
+  THR_COMP_NEW_NEAR_OPTFLOWL3A,
+  THR_COMP_NEW_NEW_OPTFLOWL3A,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   THR_COMP_NEW_NEARGA,
   THR_COMP_NEAR_NEWGA,
   THR_COMP_NEW_NEWGA,
   THR_COMP_GLOBAL_GLOBALGA,
+#if CONFIG_OPTFLOW_REFINEMENT
+  THR_COMP_NEAR_NEAR_OPTFLOWGA,
+  THR_COMP_NEAR_NEW_OPTFLOWGA,
+  THR_COMP_NEW_NEAR_OPTFLOWGA,
+  THR_COMP_NEW_NEW_OPTFLOWGA,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   THR_COMP_NEW_NEARLB,
   THR_COMP_NEAR_NEWLB,
   THR_COMP_NEW_NEWLB,
   THR_COMP_GLOBAL_GLOBALLB,
+#if CONFIG_OPTFLOW_REFINEMENT
+  THR_COMP_NEAR_NEAR_OPTFLOWLB,
+  THR_COMP_NEAR_NEW_OPTFLOWLB,
+  THR_COMP_NEW_NEAR_OPTFLOWLB,
+  THR_COMP_NEW_NEW_OPTFLOWLB,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   THR_COMP_NEW_NEARL2B,
   THR_COMP_NEAR_NEWL2B,
   THR_COMP_NEW_NEWL2B,
   THR_COMP_GLOBAL_GLOBALL2B,
+#if CONFIG_OPTFLOW_REFINEMENT
+  THR_COMP_NEAR_NEAR_OPTFLOWL2B,
+  THR_COMP_NEAR_NEW_OPTFLOWL2B,
+  THR_COMP_NEW_NEAR_OPTFLOWL2B,
+  THR_COMP_NEW_NEW_OPTFLOWL2B,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   THR_COMP_NEW_NEARL3B,
   THR_COMP_NEAR_NEWL3B,
   THR_COMP_NEW_NEWL3B,
   THR_COMP_GLOBAL_GLOBALL3B,
+#if CONFIG_OPTFLOW_REFINEMENT
+  THR_COMP_NEAR_NEAR_OPTFLOWL3B,
+  THR_COMP_NEAR_NEW_OPTFLOWL3B,
+  THR_COMP_NEW_NEAR_OPTFLOWL3B,
+  THR_COMP_NEW_NEW_OPTFLOWL3B,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   THR_COMP_NEW_NEARGB,
   THR_COMP_NEAR_NEWGB,
   THR_COMP_NEW_NEWGB,
   THR_COMP_GLOBAL_GLOBALGB,
+#if CONFIG_OPTFLOW_REFINEMENT
+  THR_COMP_NEAR_NEAR_OPTFLOWGB,
+  THR_COMP_NEAR_NEW_OPTFLOWGB,
+  THR_COMP_NEW_NEAR_OPTFLOWGB,
+  THR_COMP_NEW_NEW_OPTFLOWGB,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   THR_COMP_NEW_NEARLA2,
   THR_COMP_NEAR_NEWLA2,
   THR_COMP_NEW_NEWLA2,
   THR_COMP_GLOBAL_GLOBALLA2,
+#if CONFIG_OPTFLOW_REFINEMENT
+  THR_COMP_NEAR_NEAR_OPTFLOWLA2,
+  THR_COMP_NEAR_NEW_OPTFLOWLA2,
+  THR_COMP_NEW_NEAR_OPTFLOWLA2,
+  THR_COMP_NEW_NEW_OPTFLOWLA2,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   THR_COMP_NEW_NEARL2A2,
   THR_COMP_NEAR_NEWL2A2,
   THR_COMP_NEW_NEWL2A2,
   THR_COMP_GLOBAL_GLOBALL2A2,
+#if CONFIG_OPTFLOW_REFINEMENT
+  THR_COMP_NEAR_NEAR_OPTFLOWL2A2,
+  THR_COMP_NEAR_NEW_OPTFLOWL2A2,
+  THR_COMP_NEW_NEAR_OPTFLOWL2A2,
+  THR_COMP_NEW_NEW_OPTFLOWL2A2,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   THR_COMP_NEW_NEARL3A2,
   THR_COMP_NEAR_NEWL3A2,
   THR_COMP_NEW_NEWL3A2,
   THR_COMP_GLOBAL_GLOBALL3A2,
+#if CONFIG_OPTFLOW_REFINEMENT
+  THR_COMP_NEAR_NEAR_OPTFLOWL3A2,
+  THR_COMP_NEAR_NEW_OPTFLOWL3A2,
+  THR_COMP_NEW_NEAR_OPTFLOWL3A2,
+  THR_COMP_NEW_NEW_OPTFLOWL3A2,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   THR_COMP_NEW_NEARGA2,
   THR_COMP_NEAR_NEWGA2,
   THR_COMP_NEW_NEWGA2,
   THR_COMP_GLOBAL_GLOBALGA2,
+#if CONFIG_OPTFLOW_REFINEMENT
+  THR_COMP_NEAR_NEAR_OPTFLOWGA2,
+  THR_COMP_NEAR_NEW_OPTFLOWGA2,
+  THR_COMP_NEW_NEAR_OPTFLOWGA2,
+  THR_COMP_NEW_NEW_OPTFLOWGA2,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   THR_COMP_NEW_NEARLL2,
   THR_COMP_NEAR_NEWLL2,
   THR_COMP_NEW_NEWLL2,
   THR_COMP_GLOBAL_GLOBALLL2,
+#if CONFIG_OPTFLOW_REFINEMENT
+  THR_COMP_NEAR_NEAR_OPTFLOWLL2,
+  THR_COMP_NEAR_NEW_OPTFLOWLL2,
+  THR_COMP_NEW_NEAR_OPTFLOWLL2,
+  THR_COMP_NEW_NEW_OPTFLOWLL2,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   THR_COMP_NEW_NEARLL3,
   THR_COMP_NEAR_NEWLL3,
   THR_COMP_NEW_NEWLL3,
   THR_COMP_GLOBAL_GLOBALLL3,
+#if CONFIG_OPTFLOW_REFINEMENT
+  THR_COMP_NEAR_NEAR_OPTFLOWLL3,
+  THR_COMP_NEAR_NEW_OPTFLOWLL3,
+  THR_COMP_NEW_NEAR_OPTFLOWLL3,
+  THR_COMP_NEW_NEW_OPTFLOWLL3,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   THR_COMP_NEW_NEARLG,
   THR_COMP_NEAR_NEWLG,
   THR_COMP_NEW_NEWLG,
   THR_COMP_GLOBAL_GLOBALLG,
+#if CONFIG_OPTFLOW_REFINEMENT
+  THR_COMP_NEAR_NEAR_OPTFLOWLG,
+  THR_COMP_NEAR_NEW_OPTFLOWLG,
+  THR_COMP_NEW_NEAR_OPTFLOWLG,
+  THR_COMP_NEW_NEW_OPTFLOWLG,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   THR_COMP_NEW_NEARBA,
   THR_COMP_NEAR_NEWBA,
   THR_COMP_NEW_NEWBA,
   THR_COMP_GLOBAL_GLOBALBA,
+#if CONFIG_OPTFLOW_REFINEMENT
+  THR_COMP_NEAR_NEAR_OPTFLOWBA,
+  THR_COMP_NEAR_NEW_OPTFLOWBA,
+  THR_COMP_NEW_NEAR_OPTFLOWBA,
+  THR_COMP_NEW_NEW_OPTFLOWBA,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   THR_DC,
   THR_PAETH,
@@ -434,6 +532,7 @@
   THR_D45_PRED,
 };
 #endif  // CONFIG_NEW_INTER_MODES
+#endif  // !CONFIG_NEW_REF_SIGNALING
 
 /*!\cond */
 typedef struct SingleInterModeState {
@@ -450,11 +549,14 @@
   int best_rate_uv;
   int best_mode_skippable;
   int best_skip2;
-  THR_MODES best_mode_index;
   int num_available_refs;
   int64_t dist_refs[REF_FRAMES];
   int dist_order_refs[REF_FRAMES];
+#if CONFIG_NEW_REF_SIGNALING
+  int64_t mode_threshold[MB_MODE_COUNT];
+#else
   int64_t mode_threshold[MAX_MODES];
+#endif  // CONFIG_NEW_REF_SIGNALING
   int64_t best_intra_rd;
   unsigned int best_pred_sse;
   int64_t best_pred_diff[REFERENCE_MODES];
@@ -469,12 +571,19 @@
   PREDICTION_MODE best_single_mode[REF_FRAMES];
 
   // Single search results by [directions][modes][reference frames]
-  SingleInterModeState single_state[2][SINGLE_INTER_MODE_NUM][FWD_REFS];
   int single_state_cnt[2][SINGLE_INTER_MODE_NUM];
+  int single_state_modelled_cnt[2][SINGLE_INTER_MODE_NUM];
+#if CONFIG_NEW_REF_SIGNALING
+  SingleInterModeState single_state[2][SINGLE_INTER_MODE_NUM][REF_FRAMES];
+  SingleInterModeState single_state_modelled[2][SINGLE_INTER_MODE_NUM]
+                                            [REF_FRAMES];
+  MV_REFERENCE_FRAME single_rd_order[2][SINGLE_INTER_MODE_NUM][REF_FRAMES];
+#else
+  SingleInterModeState single_state[2][SINGLE_INTER_MODE_NUM][FWD_REFS];
   SingleInterModeState single_state_modelled[2][SINGLE_INTER_MODE_NUM]
                                             [FWD_REFS];
-  int single_state_modelled_cnt[2][SINGLE_INTER_MODE_NUM];
   MV_REFERENCE_FRAME single_rd_order[2][SINGLE_INTER_MODE_NUM][FWD_REFS];
+#endif  // CONFIG_NEW_REF_SIGNALING
   IntraModeSearchState intra_search_state;
 } InterModeSearchState;
 /*!\endcond */
@@ -822,10 +931,26 @@
 }
 
 static int cost_mv_ref(const ModeCosts *const mode_costs, PREDICTION_MODE mode,
+#if CONFIG_OPTFLOW_REFINEMENT
+                       const AV1_COMMON *cm, const MB_MODE_INFO *const mbmi,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
                        int16_t mode_context) {
   if (is_inter_compound_mode(mode)) {
+#if CONFIG_OPTFLOW_REFINEMENT
+    int use_optical_flow_cost = 0;
+    if (cm->features.opfl_refine_type == REFINE_SWITCHABLE &&
+        is_opfl_refine_allowed(cm, mbmi)) {
+      const int use_optical_flow = mode > NEW_NEWMV;
+      use_optical_flow_cost =
+          mode_costs->use_optflow_cost[mode_context][use_optical_flow];
+    }
+    const int comp_mode_idx = opfl_get_comp_idx(mode);
+    return use_optical_flow_cost +
+           mode_costs->inter_compound_mode_cost[mode_context][comp_mode_idx];
+#else
     return mode_costs
         ->inter_compound_mode_cost[mode_context][INTER_COMPOUND_OFFSET(mode)];
+#endif  // CONFIG_OPTFLOW_REFINEMENT
   }
 
   assert(is_inter_mode(mode));
@@ -867,8 +992,13 @@
     const AV1_COMMON *cm, const MACROBLOCKD *xd, const ModeCosts *mode_costs,
     int segment_id, unsigned int *ref_costs_single,
     unsigned int (*ref_costs_comp)[REF_FRAMES]) {
+#if CONFIG_NEW_REF_SIGNALING
+  (void)segment_id;
+  int seg_ref_active = 0;
+#else
   int seg_ref_active =
       segfeature_active(&cm->seg, segment_id, SEG_LVL_REF_FRAME);
+#endif  // CONFIG_NEW_REF_SIGNALING
   if (seg_ref_active) {
     memset(ref_costs_single, 0, REF_FRAMES * sizeof(*ref_costs_single));
     int ref_frame;
@@ -877,10 +1007,45 @@
              REF_FRAMES * sizeof((*ref_costs_comp)[0]));
   } else {
     int intra_inter_ctx = av1_get_intra_inter_context(xd);
+#if CONFIG_CONTEXT_DERIVATION
+#if CONFIG_SDP
+    const int skip_txfm = xd->mi[0]->skip_txfm[xd->tree_type == CHROMA_PART];
+#else
+    const int skip_txfm = xd->mi[0]->skip_txfm;
+#endif
+#if CONFIG_NEW_REF_SIGNALING
+    ref_costs_single[INTRA_FRAME_INDEX_NRS] =
+#else
     ref_costs_single[INTRA_FRAME] =
+#endif  // CONFIG_NEW_REF_SIGNALING
+        mode_costs->intra_inter_cost[skip_txfm][intra_inter_ctx][0];
+    unsigned int base_cost =
+        mode_costs->intra_inter_cost[skip_txfm][intra_inter_ctx][1];
+#else
+#if CONFIG_NEW_REF_SIGNALING
+    ref_costs_single[INTRA_FRAME_INDEX_NRS] =
+#else
+    ref_costs_single[INTRA_FRAME] =
+#endif  // CONFIG_NEW_REF_SIGNALING
         mode_costs->intra_inter_cost[intra_inter_ctx][0];
     unsigned int base_cost = mode_costs->intra_inter_cost[intra_inter_ctx][1];
+#endif  // CONFIG_CONTEXT_DERIVATION
 
+#if CONFIG_NEW_REF_SIGNALING
+    for (int i = 0; i < INTER_REFS_PER_FRAME; ++i)
+      ref_costs_single[i] = base_cost;
+
+    const int n_refs = cm->ref_frames_info.n_total_refs;
+    for (int i = 0; i < n_refs; i++) {
+      for (int j = 0; j <= AOMMIN(i, n_refs - 2); j++) {
+        aom_cdf_prob ctx = av1_get_ref_pred_context_nrs(xd, j, n_refs);
+        const int bit = i == j;
+        ref_costs_single[i] += mode_costs->single_ref_cost[ctx][j][bit];
+      }
+    }
+    for (int i = n_refs; i < INTER_REFS_PER_FRAME; i++)
+      ref_costs_single[i] = INT_MAX;
+#else
     for (int i = LAST_FRAME; i <= ALTREF_FRAME; ++i)
       ref_costs_single[i] = base_cost;
 
@@ -929,7 +1094,60 @@
     ref_costs_single[BWDREF_FRAME] += mode_costs->single_ref_cost[ctx_p6][5][0];
     ref_costs_single[ALTREF2_FRAME] +=
         mode_costs->single_ref_cost[ctx_p6][5][1];
+#endif  // CONFIG_NEW_REF_SIGNALING
 
+#if CONFIG_NEW_REF_SIGNALING
+    if (cm->current_frame.reference_mode != SINGLE_REFERENCE) {
+      for (int i = 0; i < REF_FRAMES; i++)
+        for (int j = 0; j < REF_FRAMES; j++) ref_costs_comp[i][j] = INT_MAX;
+
+      for (int i = 0; i < n_refs - 1; i++) {
+        int prev_cost = base_cost;
+        for (int j = 0; j < n_refs; j++) {
+          if (j <= i) {
+            if (n_refs == 2) continue;  // No bits need to be sent in this case
+            // Keep track of the cost to encode the first reference
+            aom_cdf_prob ctx = av1_get_ref_pred_context_nrs(xd, j, n_refs);
+            const int bit_type =
+                av1_get_compound_ref_bit_type(0, &cm->ref_frames_info, i, j);
+            const int bit = i == j;
+            if (j < n_refs - 2)
+              prev_cost += mode_costs->comp_ref_cost[ctx][bit_type][j][bit];
+          } else {
+            // Assign the cost of signaling both references
+            ref_costs_comp[i][j] = prev_cost;
+            ref_costs_comp[j][i] = prev_cost;
+            if (j < n_refs - 1) {
+              aom_cdf_prob ctx = av1_get_ref_pred_context_nrs(xd, j, n_refs);
+              const int bit_type =
+                  av1_get_compound_ref_bit_type(1, &cm->ref_frames_info, i, j);
+              ref_costs_comp[i][j] +=
+                  mode_costs->comp_ref_cost[ctx][bit_type][j - 1][1];
+              ref_costs_comp[j][i] +=
+                  mode_costs->comp_ref_cost[ctx][bit_type][j - 1][1];
+              // Maintain the cost of sending a 0 bit for the 2nd reference to
+              // be used in the next iteration.
+              prev_cost += mode_costs->comp_ref_cost[ctx][bit_type][j - 1][0];
+            }
+          }
+        }
+      }
+#ifndef NDEBUG
+      for (int i = 0; i < n_refs - 1; i++) {
+        for (int j = i + 1; j < n_refs; j++) {
+          assert(ref_costs_comp[i][j] != INT_MAX);
+        }
+      }
+#endif  // NDEBUG
+    } else {
+      for (int ref0 = 0; ref0 < REF_FRAMES; ++ref0) {
+        for (int ref1 = ref0 + 1; ref1 < REF_FRAMES; ++ref1) {
+          ref_costs_comp[ref0][ref1] = 512;
+          ref_costs_comp[ref1][ref0] = 512;
+        }
+      }
+    }
+#else
     if (cm->current_frame.reference_mode != SINGLE_REFERENCE) {
       // Similar to single ref, determine cost of compound ref frames.
       // cost_compound_refs = cost_first_ref + cost_second_ref
@@ -1022,15 +1240,16 @@
       ref_costs_comp[LAST_FRAME][GOLDEN_FRAME] = 512;
       ref_costs_comp[BWDREF_FRAME][ALTREF_FRAME] = 512;
     }
+#endif  // CONFIG_NEW_REF_SIGNALING
   }
 }
 
 static AOM_INLINE void store_coding_context(
-#if CONFIG_INTERNAL_STATS
+#if CONFIG_INTERNAL_STATS && !CONFIG_NEW_REF_SIGNALING
     MACROBLOCK *x, PICK_MODE_CONTEXT *ctx, int mode_index,
 #else
     MACROBLOCK *x, PICK_MODE_CONTEXT *ctx,
-#endif  // CONFIG_INTERNAL_STATS
+#endif  // CONFIG_INTERNAL_STATS && !CONFIG_NEW_REF_SIGNALING
     int64_t comp_pred_diff[REFERENCE_MODES], int skippable) {
   MACROBLOCKD *const xd = &x->e_mbd;
 
@@ -1038,9 +1257,9 @@
   // restored if we decide to encode this way
   ctx->rd_stats.skip_txfm = x->txfm_search_info.skip_txfm;
   ctx->skippable = skippable;
-#if CONFIG_INTERNAL_STATS
+#if CONFIG_INTERNAL_STATS && !CONFIG_NEW_REF_SIGNALING
   ctx->best_mode_index = mode_index;
-#endif  // CONFIG_INTERNAL_STATS
+#endif  // CONFIG_INTERNAL_STATS && !CONFIG_NEW_REF_SIGNALING
   ctx->mic = *xd->mi[0];
 #if CONFIG_SDP
   if (xd->tree_type != CHROMA_PART)
@@ -1119,7 +1338,7 @@
                             PREDICTION_MODE this_mode,
                             const MV_REFERENCE_FRAME ref_frames[2],
                             InterModeSearchState *search_state) {
-  const int is_comp_pred = ref_frames[1] > INTRA_FRAME;
+  const int is_comp_pred = is_inter_ref_frame(ref_frames[1]);
   if (is_comp_pred) {
     return 0;
   }
@@ -1148,18 +1367,36 @@
     return 0;
   }
 
+#if CONFIG_NEW_REF_SIGNALING
+  const MV_REFERENCE_FRAME ref_frame0 = COMPACT_INDEX0_NRS(ref_frames[0]);
+  if (search_state->modelled_rd[compare_mode][0][ref_frame0] == INT64_MAX) {
+#else
   if (search_state->modelled_rd[compare_mode][0][ref_frames[0]] == INT64_MAX) {
+#endif  // CONFIG_NEW_REF_SIGNALING
     return 0;
   }
   const int16_t mode_ctx =
       av1_mode_context_analyzer(mbmi_ext->mode_context, ref_frames);
+#if CONFIG_OPTFLOW_REFINEMENT
+  const MB_MODE_INFO *const mbmi = x->e_mbd.mi[0];
+  const int compare_cost =
+      cost_mv_ref(&x->mode_costs, compare_mode, cm, mbmi, mode_ctx);
+  const int this_cost =
+      cost_mv_ref(&x->mode_costs, this_mode, cm, mbmi, mode_ctx);
+#else
   const int compare_cost = cost_mv_ref(&x->mode_costs, compare_mode, mode_ctx);
   const int this_cost = cost_mv_ref(&x->mode_costs, this_mode, mode_ctx);
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   // Only skip if the mode cost is larger than compare mode cost
   if (this_cost > compare_cost) {
+#if CONFIG_NEW_REF_SIGNALING
+    search_state->modelled_rd[this_mode][0][ref_frame0] =
+        search_state->modelled_rd[compare_mode][0][ref_frame0];
+#else
     search_state->modelled_rd[this_mode][0][ref_frames[0]] =
         search_state->modelled_rd[compare_mode][0][ref_frames[0]];
+#endif  // CONFIG_NEW_REF_SIGNALING
     return 1;
   }
   return 0;
@@ -1170,7 +1407,7 @@
                             PREDICTION_MODE this_mode,
                             const MV_REFERENCE_FRAME ref_frames[2],
                             InterModeSearchState *search_state) {
-  const int is_comp_pred = ref_frames[1] > INTRA_FRAME;
+  const int is_comp_pred = is_inter_ref_frame(ref_frames[1]);
   const uint8_t ref_frame_type = av1_ref_frame_type(ref_frames);
   const MB_MODE_INFO_EXT *const mbmi_ext = x->mbmi_ext;
   const int ref_mv_count = mbmi_ext->ref_mv_count[ref_frame_type];
@@ -1201,8 +1438,13 @@
 
     if (compare_mode != MB_MODE_COUNT) {
       // Use modelled_rd to check whether compare mode was searched
+#if CONFIG_NEW_REF_SIGNALING
+      const MV_REFERENCE_FRAME ref_frame0 = COMPACT_INDEX0_NRS(ref_frames[0]);
+      if (search_state->modelled_rd[compare_mode][0][ref_frame0] != INT64_MAX) {
+#else
       if (search_state->modelled_rd[compare_mode][0][ref_frames[0]] !=
           INT64_MAX) {
+#endif  // CONFIG_NEW_REF_SIGNALING
         const int16_t mode_ctx =
             av1_mode_context_analyzer(mbmi_ext->mode_context, ref_frames);
         const int compare_cost =
@@ -1211,8 +1453,13 @@
 
         // Only skip if the mode cost is larger than compare mode cost
         if (this_cost > compare_cost) {
+#if CONFIG_NEW_REF_SIGNALING
+          search_state->modelled_rd[this_mode][0][ref_frame0] =
+              search_state->modelled_rd[compare_mode][0][ref_frame0];
+#else
           search_state->modelled_rd[this_mode][0][ref_frames[0]] =
               search_state->modelled_rd[compare_mode][0][ref_frames[0]];
+#endif  // CONFIG_NEW_REF_SIGNALING
           return 1;
         }
       }
@@ -1254,15 +1501,25 @@
   MB_MODE_INFO *const mbmi = xd->mi[0];
   const int is_comp_pred = has_second_ref(mbmi);
   const PREDICTION_MODE this_mode = mbmi->mode;
-  const int refs[2] = { mbmi->ref_frame[0],
-                        mbmi->ref_frame[1] < 0 ? 0 : mbmi->ref_frame[1] };
+#if CONFIG_NEW_REF_SIGNALING
+  const MV_REFERENCE_FRAME refs[2] = { mbmi->ref_frame[0],
+                                       COMPACT_INDEX1_NRS(mbmi->ref_frame[1]) };
+#else
+  const MV_REFERENCE_FRAME refs[2] = {
+    mbmi->ref_frame[0], mbmi->ref_frame[1] < 0 ? 0 : mbmi->ref_frame[1]
+  };
+#endif  // CONFIG_NEW_REF_SIGNALING
   const int ref_mv_idx = mbmi->ref_mv_idx;
 
   if (is_comp_pred) {
     const int valid_mv0 = args->single_newmv_valid[ref_mv_idx][refs[0]];
     const int valid_mv1 = args->single_newmv_valid[ref_mv_idx][refs[1]];
 
+#if CONFIG_OPTFLOW_REFINEMENT
+    if (this_mode == NEW_NEWMV || this_mode == NEW_NEWMV_OPTFLOW) {
+#else
     if (this_mode == NEW_NEWMV) {
+#endif  // CONFIG_OPTFLOW_REFINEMENT
       if (valid_mv0) {
         cur_mv[0].as_int = args->single_newmv[ref_mv_idx][refs[0]].as_int;
         clamp_mv_in_range(x, &cur_mv[0], 0);
@@ -1275,20 +1532,8 @@
       // aomenc1
       if (cpi->sf.inter_sf.comp_inter_joint_search_thresh <= bsize ||
           !valid_mv0 || !valid_mv1) {
-        mbmi->compound_idx = 1;
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-        InterPredParams inter_pred_params;
-        av1_dist_wtd_comp_weight_assign(
-            &cpi->common, mbmi, &inter_pred_params.conv_params.fwd_offset,
-            &inter_pred_params.conv_params.bck_offset, 1);
-        uint8_t mask_value = inter_pred_params.conv_params.fwd_offset * 4;
-        memset(xd->seg_mask, mask_value, sizeof(xd->seg_mask));
-        av1_joint_motion_search(cpi, x, bsize, cur_mv, xd->seg_mask,
-                                block_size_wide[bsize], rate_mv);
-#else
         // uint8_t mask_value = 32;
         av1_joint_motion_search(cpi, x, bsize, cur_mv, NULL, 0, rate_mv);
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
       } else {
         *rate_mv = 0;
         for (int i = 0; i < 2; ++i) {
@@ -1299,7 +1544,11 @@
         }
       }
 #if CONFIG_NEW_INTER_MODES
+#if CONFIG_OPTFLOW_REFINEMENT
+    } else if (this_mode == NEAR_NEWMV || this_mode == NEAR_NEWMV_OPTFLOW) {
+#else
     } else if (this_mode == NEAR_NEWMV) {
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 #else
     } else if (this_mode == NEAREST_NEWMV || this_mode == NEAR_NEWMV) {
 #endif  // CONFIG_NEW_INTER_MODES
@@ -1321,7 +1570,11 @@
       }
     } else {
 #if CONFIG_NEW_INTER_MODES
+#if CONFIG_OPTFLOW_REFINEMENT
+      assert(this_mode == NEW_NEARMV || this_mode == NEW_NEARMV_OPTFLOW);
+#else
       assert(this_mode == NEW_NEARMV);
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 #else
       assert(this_mode == NEW_NEARESTMV || this_mode == NEW_NEARMV);
 #endif  // CONFIG_NEW_INTER_MODES
@@ -1500,12 +1753,15 @@
   uint8_t best_blk_skip[MAX_MIB_SIZE * MAX_MIB_SIZE];
   uint8_t best_tx_type_map[MAX_MIB_SIZE * MAX_MIB_SIZE];
   const int rate_mv0 = *rate_mv;
-  const int interintra_allowed = cm->seq_params.enable_interintra_compound &&
-                                 is_interintra_allowed(mbmi) &&
-                                 mbmi->compound_idx;
+  const int interintra_allowed =
+      cm->seq_params.enable_interintra_compound && is_interintra_allowed(mbmi);
   int pts0[SAMPLES_ARRAY_SIZE], pts_inref0[SAMPLES_ARRAY_SIZE];
 
+#if CONFIG_NEW_REF_SIGNALING
+  assert(mbmi->ref_frame[1] != INTRA_FRAME_NRS);
+#else
   assert(mbmi->ref_frame[1] != INTRA_FRAME);
+#endif  // CONFIG_NEW_REF_SIGNALING
   const MV_REFERENCE_FRAME ref_frame_1 = mbmi->ref_frame[1];
   (void)tile_data;
   av1_invalid_rd_stats(&best_rd_stats);
@@ -1535,7 +1791,7 @@
   MB_MODE_INFO best_mbmi;
   const int interp_filter = features->interp_filter;
   const int switchable_rate =
-      av1_is_interp_needed(xd)
+      av1_is_interp_needed(cm, xd)
           ? av1_get_switchable_rate(x, xd,
 #if !CONFIG_REMOVE_DUAL_FILTER
                                     cm->seq_params.enable_dual_filter,
@@ -1571,7 +1827,11 @@
       mbmi->motion_mode = SIMPLE_TRANSLATION;
     } else {
       mbmi->motion_mode = (MOTION_MODE)mode_index;
+#if CONFIG_NEW_REF_SIGNALING
+      assert(mbmi->ref_frame[1] != INTRA_FRAME_NRS);
+#else
       assert(mbmi->ref_frame[1] != INTRA_FRAME);
+#endif  // CONFIG_NEW_REF_SIGNALING
     }
 
     // Do not search OBMC if the probability of selecting it is below a
@@ -1690,10 +1950,18 @@
     if (interintra_allowed) {
       rd_stats->rate +=
           mode_costs->interintra_cost[size_group_lookup[bsize]]
+#if CONFIG_NEW_REF_SIGNALING
+                                     [mbmi->ref_frame[1] == INTRA_FRAME_NRS];
+#else
                                      [mbmi->ref_frame[1] == INTRA_FRAME];
+#endif  // CONFIG_NEW_REF_SIGNALING
     }
     if ((last_motion_mode_allowed > SIMPLE_TRANSLATION) &&
+#if CONFIG_NEW_REF_SIGNALING
+        (mbmi->ref_frame[1] != INTRA_FRAME_NRS)) {
+#else
         (mbmi->ref_frame[1] != INTRA_FRAME)) {
+#endif  // CONFIG_NEW_REF_SIGNALING
       if (last_motion_mode_allowed == WARPED_CAUSAL) {
         rd_stats->rate +=
             mode_costs->motion_mode_cost[bsize][mbmi->motion_mode];
@@ -1722,7 +1990,11 @@
         model_rd_sb_fn[MODELRD_TYPE_MOTION_MODE_RD](
             cpi, bsize, x, xd, 0, num_planes - 1, &est_residue_cost, &est_dist,
             NULL, &curr_sse, NULL, NULL, NULL);
+#if CONFIG_NEW_REF_SIGNALING
+        sse_y = x->pred_sse[COMPACT_INDEX0_NRS(xd->mi[0]->ref_frame[0])];
+#else
         sse_y = x->pred_sse[xd->mi[0]->ref_frame[0]];
+#endif  // CONFIG_NEW_REF_SIGNALING
       }
       est_rd = RDCOST(x->rdmult, rd_stats->rate + est_residue_cost, est_dist);
       if (est_rd * 0.80 > *best_est_rd) {
@@ -1823,7 +2095,12 @@
 
     const int64_t tmp_rd = RDCOST(x->rdmult, rd_stats->rate, rd_stats->dist);
     if (mode_index == 0) {
+#if CONFIG_NEW_REF_SIGNALING
+      args->simple_rd[this_mode][mbmi->ref_mv_idx]
+                     [COMPACT_INDEX0_NRS(mbmi->ref_frame[0])] = tmp_rd;
+#else
       args->simple_rd[this_mode][mbmi->ref_mv_idx][mbmi->ref_frame[0]] = tmp_rd;
+#endif  // CONFIG_NEW_REF_SIGNALING
     }
     if (mode_index == 0 || tmp_rd < best_rd) {
       // Update best_rd data if this is the best motion mode so far
@@ -2170,6 +2447,10 @@
     const RefFrameDistanceInfo *const ref_frame_dist_info, MACROBLOCK *x,
     const HandleInterModeArgs *const args, int64_t ref_best_rd,
     int ref_mv_idx) {
+#if CONFIG_NEW_REF_SIGNALING
+  (void)ref_frame_dist_info;
+  const AV1_COMMON *const cm = &cpi->common;
+#endif  // CONFIG_NEW_REF_SIGNALING
   const SPEED_FEATURES *const sf = &cpi->sf;
   MACROBLOCKD *xd = &x->e_mbd;
   MB_MODE_INFO *mbmi = xd->mi[0];
@@ -2177,10 +2458,21 @@
   const int8_t ref_frame_type = av1_ref_frame_type(mbmi->ref_frame);
   const int is_comp_pred = has_second_ref(mbmi);
   if (sf->inter_sf.reduce_inter_modes && ref_mv_idx > 0) {
+#if CONFIG_NEW_REF_SIGNALING
+    // NOTE: This section changes the stats.
+    int ranks[2][2], dir[2] = { -1, -1 };
+    if (mbmi->ref_frame[0] != INTRA_FRAME_NRS)
+      dir[0] = get_dir_rank(cm, mbmi->ref_frame[0], ranks[0]);
+    if (is_inter_ref_frame(mbmi->ref_frame[1]))
+      dir[1] = get_dir_rank(cm, mbmi->ref_frame[1], ranks[1]);
+    if ((dir[0] != -1 && ranks[0][dir[0]] > 3) ||
+        (dir[1] != -1 && ranks[1][dir[1]] > 2)) {
+#else
     if (mbmi->ref_frame[0] == LAST2_FRAME ||
         mbmi->ref_frame[0] == LAST3_FRAME ||
         mbmi->ref_frame[1] == LAST2_FRAME ||
         mbmi->ref_frame[1] == LAST3_FRAME) {
+#endif  // CONFIG_NEW_REF_SIGNALING
 #if CONFIG_NEW_INTER_MODES
       const int has_nearmv = 0;
 #else
@@ -2194,8 +2486,15 @@
     // TODO(any): Experiment with reduce_inter_modes for compound prediction
     if (sf->inter_sf.reduce_inter_modes >= 2 && !is_comp_pred &&
         have_newmv_in_inter_mode(mbmi->mode)) {
+#if CONFIG_NEW_REF_SIGNALING
+      if ((cm->ref_frames_info.n_future_refs == 0 ||
+           mbmi->ref_frame[0] != cm->ref_frames_info.future_refs[0]) &&
+          (cm->ref_frames_info.n_past_refs == 0 ||
+           mbmi->ref_frame[0] != cm->ref_frames_info.past_refs[0])) {
+#else
       if (mbmi->ref_frame[0] != ref_frame_dist_info->nearest_past_ref &&
           mbmi->ref_frame[0] != ref_frame_dist_info->nearest_future_ref) {
+#endif  // CONFIG_NEW_REF_SIGNALING
 #if CONFIG_NEW_INTER_MODES
         const int has_nearmv = 0;
 #else
@@ -2256,9 +2555,13 @@
 
   mbmi->interinter_comp.type = COMPOUND_AVERAGE;
   mbmi->comp_group_idx = 0;
-  mbmi->compound_idx = 1;
+#if CONFIG_NEW_REF_SIGNALING
+  if (mbmi->ref_frame[1] == INTRA_FRAME_NRS) {
+    mbmi->ref_frame[1] = INVALID_IDX;
+#else
   if (mbmi->ref_frame[1] == INTRA_FRAME) {
     mbmi->ref_frame[1] = NONE_FRAME;
+#endif  // CONFIG_NEW_REF_SIGNALING
   }
   int16_t mode_ctx =
       av1_mode_context_analyzer(mbmi_ext->mode_context, mbmi->ref_frame);
@@ -2286,7 +2589,11 @@
   for (int i = 0; i < is_comp_pred + 1; ++i) {
     mbmi->mv[i].as_int = cur_mv[i].as_int;
   }
-  const int ref_mv_cost = cost_mv_ref(mode_costs, mbmi->mode, mode_ctx);
+  const int ref_mv_cost = cost_mv_ref(mode_costs, mbmi->mode,
+#if CONFIG_OPTFLOW_REFINEMENT
+                                      cm, mbmi,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
+                                      mode_ctx);
   rd_stats->rate += ref_mv_cost;
 
   if (RDCOST(x->rdmult, rd_stats->rate, 0) > ref_best_rd) {
@@ -2299,9 +2606,12 @@
     // Only compound_average
     mbmi->interinter_comp.type = COMPOUND_AVERAGE;
     mbmi->comp_group_idx = 0;
-    mbmi->compound_idx = 1;
   }
-  set_default_interp_filters(mbmi, cm->features.interp_filter);
+  set_default_interp_filters(mbmi,
+#if CONFIG_OPTFLOW_REFINEMENT
+                             cm,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
+                             cm->features.interp_filter);
 
   const int mi_row = xd->mi_row;
   const int mi_col = xd->mi_col;
@@ -2363,7 +2673,7 @@
   // Do not prune when there is internal resizing. TODO(elliottk) fix this
   // so b/2384 can be resolved.
   if (av1_is_scaled(get_ref_scale_factors(cm, mbmi->ref_frame[0])) ||
-      (mbmi->ref_frame[1] > 0 &&
+      (is_inter_ref_frame(mbmi->ref_frame[1]) &&
        av1_is_scaled(get_ref_scale_factors(cm, mbmi->ref_frame[1])))) {
     return good_indices;
   }
@@ -2568,7 +2878,6 @@
     AV1_COMP *cpi, BLOCK_SIZE bsize, int mi_row, int mi_col, int *valid_refs,
     PruneInfoFromTpl *inter_cost_info_from_tpl) {
   const GF_GROUP *const gf_group = &cpi->gf_group;
-  AV1_COMMON *const cm = &cpi->common;
 
   assert(IMPLIES(gf_group->size > 0, gf_group->index < gf_group->size));
   const int tpl_idx = gf_group->index;
@@ -2578,6 +2887,7 @@
     return;
   }
 
+  AV1_COMMON *const cm = &cpi->common;
   const TplDepStats *tpl_stats = tpl_frame->tpl_stats_ptr;
   const int mi_wide = mi_size_wide[bsize];
   const int mi_high = mi_size_high[bsize];
@@ -2623,8 +2933,8 @@
 
 static AOM_INLINE int prune_modes_based_on_tpl_stats(
     const FeatureFlags *const features,
-    PruneInfoFromTpl *inter_cost_info_from_tpl, const int *refs, int ref_mv_idx,
-    const PREDICTION_MODE this_mode, int prune_mode_level) {
+    PruneInfoFromTpl *inter_cost_info_from_tpl, const MV_REFERENCE_FRAME *refs,
+    int ref_mv_idx, const PREDICTION_MODE this_mode, int prune_mode_level) {
   (void)features;
   const int have_newmv = have_newmv_in_inter_mode(this_mode);
   if ((prune_mode_level < 3) && have_newmv) return 0;
@@ -2656,7 +2966,20 @@
 #endif  // CONFIG_NEW_INTER_MODES
   };
 
-  const int is_comp_pred = (refs[1] > INTRA_FRAME);
+  const int is_comp_pred = is_inter_ref_frame(refs[1]);
+#if CONFIG_NEW_REF_SIGNALING
+  if (!is_comp_pred) {
+    cur_inter_cost = inter_cost_info_from_tpl->ref_inter_cost[refs[0]];
+  } else {
+    const int64_t inter_cost_ref0 =
+        inter_cost_info_from_tpl->ref_inter_cost[refs[0]];
+    const int64_t inter_cost_ref1 =
+        inter_cost_info_from_tpl->ref_inter_cost[refs[1]];
+    // Choose maximum inter_cost among inter_cost_ref0 and inter_cost_ref1 for
+    // more aggressive pruning
+    cur_inter_cost = AOMMAX(inter_cost_ref0, inter_cost_ref1);
+  }
+#else
   if (!is_comp_pred) {
     cur_inter_cost = inter_cost_info_from_tpl->ref_inter_cost[refs[0] - 1];
   } else {
@@ -2668,6 +2991,7 @@
     // more aggressive pruning
     cur_inter_cost = AOMMAX(inter_cost_ref0, inter_cost_ref1);
   }
+#endif  // CONFIG_NEW_REF_SIGNALING
 
   // Prune the mode if cur_inter_cost is greater than threshold times
   // best_inter_cost
@@ -2692,8 +3016,9 @@
     MB_MODE_INFO *best_mbmi, motion_mode_candidate *motion_mode_cand,
     int64_t *ref_best_rd, RD_STATS *best_rd_stats, RD_STATS *best_rd_stats_y,
     RD_STATS *best_rd_stats_uv, inter_mode_info *mode_info,
-    HandleInterModeArgs *args, int drl_cost, const int *refs, int_mv *cur_mv,
-    int64_t *best_rd, const BUFFER_SET orig_dst, int ref_mv_idx) {
+    HandleInterModeArgs *args, int drl_cost, const MV_REFERENCE_FRAME *refs,
+    int_mv *cur_mv, int64_t *best_rd, const BUFFER_SET orig_dst,
+    int ref_mv_idx) {
   // This feature only works for NEWMV when a previous mv has been searched
   if (this_mode != NEWMV || ref_mv_idx == 0) return 0;
   MACROBLOCKD *xd = &x->e_mbd;
@@ -2755,12 +3080,10 @@
     }
   }
   if (skip) {
-    const THR_MODES mode_enum = get_prediction_mode_idx(
-        best_mbmi->mode, best_mbmi->ref_frame[0], best_mbmi->ref_frame[1]);
     // Collect mode stats for multiwinner mode processing
     store_winner_mode_stats(
         &cpi->common, x, best_mbmi, best_rd_stats, best_rd_stats_y,
-        best_rd_stats_uv, mode_enum, NULL, bsize, *best_rd,
+        best_rd_stats_uv, refs, best_mbmi->mode, NULL, bsize, *best_rd,
         cpi->sf.winner_mode_sf.multi_winner_mode_type, do_tx_search);
     args->modelled_rd[this_mode][ref_mv_idx][refs[0]] =
         args->modelled_rd[this_mode][i][refs[0]];
@@ -2835,17 +3158,14 @@
   const AV1_COMMON *cm = &cpi->common;
   const int masked_compound_used = is_any_masked_compound_used(bsize) &&
                                    cm->seq_params.enable_masked_compound;
-  int mode_search_mask = (1 << COMPOUND_AVERAGE) |
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-                         (1 << COMPOUND_DISTWTD) |
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
-                         (1 << COMPOUND_WEDGE) | (1 << COMPOUND_DIFFWTD);
+  int mode_search_mask =
+      (1 << COMPOUND_AVERAGE) | (1 << COMPOUND_WEDGE) | (1 << COMPOUND_DIFFWTD);
 
   const int num_planes = av1_num_planes(cm);
   const int mi_row = xd->mi_row;
   const int mi_col = xd->mi_col;
   // Find matching interp filter or set to default interp filter
-  const int need_search = av1_is_interp_needed(xd);
+  const int need_search = av1_is_interp_needed(cm, xd);
   const InterpFilter assign_filter = cm->features.interp_filter;
   int is_luma_interp_done = 0;
   av1_find_interp_filter_match(mbmi, cpi, assign_filter, need_search,
@@ -3015,8 +3335,14 @@
       tpl_idx < MAX_TPL_FRAME_IDX && tpl_frame->is_valid;
   int i;
   // Reference frames for this mode
-  const int refs[2] = { mbmi->ref_frame[0],
-                        (mbmi->ref_frame[1] < 0 ? 0 : mbmi->ref_frame[1]) };
+#if CONFIG_NEW_REF_SIGNALING
+  const MV_REFERENCE_FRAME refs[2] = { COMPACT_INDEX0_NRS(mbmi->ref_frame[0]),
+                                       COMPACT_INDEX1_NRS(mbmi->ref_frame[1]) };
+#else
+  const MV_REFERENCE_FRAME refs[2] = {
+    mbmi->ref_frame[0], (mbmi->ref_frame[1] < 0 ? 0 : mbmi->ref_frame[1])
+  };
+#endif  // CONFIG_NEW_REF_SIGNALING
   int rate_mv = 0;
   int64_t rd = INT64_MAX;
   // Do first prediction into the destination buffer. Do the next
@@ -3070,7 +3396,11 @@
   const int idx_mask = ref_mv_idx_to_search(cpi, x, rd_stats, args, ref_best_rd,
                                             mode_info, bsize, ref_set);
   const ModeCosts *mode_costs = &x->mode_costs;
-  const int ref_mv_cost = cost_mv_ref(mode_costs, this_mode, mode_ctx);
+  const int ref_mv_cost = cost_mv_ref(mode_costs, this_mode,
+#if CONFIG_OPTFLOW_REFINEMENT
+                                      cm, mbmi,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
+                                      mode_ctx);
   const int base_rate =
       args->ref_frame_cost + args->single_comp_cost + ref_mv_cost;
 
@@ -3110,8 +3440,11 @@
     // Initialize compound mode data
     mbmi->interinter_comp.type = COMPOUND_AVERAGE;
     mbmi->comp_group_idx = 0;
-    mbmi->compound_idx = 1;
+#if CONFIG_NEW_REF_SIGNALING
+    if (mbmi->ref_frame[1] == INTRA_FRAME_NRS) mbmi->ref_frame[1] = INVALID_IDX;
+#else
     if (mbmi->ref_frame[1] == INTRA_FRAME) mbmi->ref_frame[1] = NONE_FRAME;
+#endif  // CONFIG_NEW_REF_SIGNALING
 
     mbmi->num_proj_ref = 0;
     mbmi->motion_mode = SIMPLE_TRANSLATION;
@@ -3175,9 +3508,12 @@
     }
 
 #if CONFIG_NEW_INTER_MODES
-    const int like_nearest =
-        (mbmi->mode == NEARMV || mbmi->mode == NEAR_NEARMV) &&
-        mbmi->ref_mv_idx == 0;
+    const int like_nearest = (mbmi->mode == NEARMV ||
+#if CONFIG_OPTFLOW_REFINEMENT
+                              mbmi->mode == NEAR_NEARMV_OPTFLOW ||
+#endif  // CONFIG_OPTFLOW_REFINEMENT
+                              mbmi->mode == NEAR_NEARMV) &&
+                             mbmi->ref_mv_idx == 0;
     if (RDCOST(x->rdmult, rd_stats->rate, 0) > ref_best_rd && !like_nearest) {
       continue;
     }
@@ -3241,7 +3577,11 @@
 
     // Compute modelled RD if enabled
     if (args->modelled_rd != NULL) {
+#if CONFIG_OPTFLOW_REFINEMENT
+      if (is_comp_pred && this_mode <= NEW_NEWMV) {
+#else
       if (is_comp_pred) {
+#endif  // CONFIG_OPTFLOW_REFINEMENT
         const int mode0 = compound_ref0_mode(this_mode);
         const int mode1 = compound_ref1_mode(this_mode);
         const int64_t mrd =
@@ -3284,13 +3624,11 @@
         mode_info[ref_mv_idx].rate_mv = rate_mv;
         mode_info[ref_mv_idx].rd = tmp_rd;
       }
-      const THR_MODES mode_enum = get_prediction_mode_idx(
-          mbmi->mode, mbmi->ref_frame[0], mbmi->ref_frame[1]);
       // Collect mode stats for multiwinner mode processing
-      store_winner_mode_stats(&cpi->common, x, mbmi, rd_stats, rd_stats_y,
-                              rd_stats_uv, mode_enum, NULL, bsize, tmp_rd,
-                              cpi->sf.winner_mode_sf.multi_winner_mode_type,
-                              do_tx_search);
+      store_winner_mode_stats(
+          &cpi->common, x, mbmi, rd_stats, rd_stats_y, rd_stats_uv, refs,
+          mbmi->mode, NULL, bsize, tmp_rd,
+          cpi->sf.winner_mode_sf.multi_winner_mode_type, do_tx_search);
       if (tmp_rd < best_rd) {
         // Update the best rd stats if we found the best mode so far
         best_rd_stats = *rd_stats;
@@ -3373,7 +3711,11 @@
   const int sb_col = mi_col >> cm->seq_params.mib_size_log2;
 
   MB_MODE_INFO_EXT *const mbmi_ext = x->mbmi_ext;
+#if CONFIG_NEW_REF_SIGNALING
+  MV_REFERENCE_FRAME ref_frame = INTRA_FRAME_NRS;
+#else
   MV_REFERENCE_FRAME ref_frame = INTRA_FRAME;
+#endif  // CONFIG_NEW_REF_SIGNALING
   av1_find_mv_refs(cm, xd, mbmi, ref_frame, mbmi_ext->ref_mv_count,
                    xd->ref_mv_stack, xd->weight, NULL, mbmi_ext->global_mvs,
                    mbmi_ext->mode_context);
@@ -3406,7 +3748,11 @@
   // Ref DV should not have sub-pel.
   assert((dv_ref.as_mv.col & 7) == 0);
   assert((dv_ref.as_mv.row & 7) == 0);
+#if CONFIG_NEW_REF_SIGNALING
+  mbmi_ext->ref_mv_stack[INTRA_FRAME_NRS][0].this_mv = dv_ref;
+#else
   mbmi_ext->ref_mv_stack[INTRA_FRAME][0].this_mv = dv_ref;
+#endif  // CONFIG_NEW_REF_SIGNALING
 
   struct buf_2d yv12_mb[MAX_MB_PLANE];
   av1_setup_pred_block(xd, yv12_mb, xd->cur_buf, NULL, NULL, num_planes);
@@ -3585,8 +3931,13 @@
   int64_t dist_y = 0, dist_uv = 0;
 
   ctx->rd_stats.skip_txfm = 0;
-  mbmi->ref_frame[0] = INTRA_FRAME;
+#if CONFIG_NEW_REF_SIGNALING
+  mbmi->ref_frame[0] = INTRA_FRAME_NRS;
+  mbmi->ref_frame[1] = INVALID_IDX;
+#else
   mbmi->ref_frame[1] = NONE_FRAME;
+  mbmi->ref_frame[0] = INTRA_FRAME;
+#endif  // CONFIG_NEW_REF_SIGNALING
 #if CONFIG_SDP
   mbmi->use_intrabc[xd->tree_type == CHROMA_PART] = 0;
   if (xd->tree_type != CHROMA_PART) {
@@ -3685,7 +4036,6 @@
   MB_MODE_INFO *const mbmi = xd->mi[0];
   const TxfmSearchParams *txfm_params = &x->txfm_search_params;
 
-  x->compound_idx = 1;  // COMPOUND_AVERAGE
   RD_STATS skip_mode_rd_stats;
   av1_invalid_rd_stats(&skip_mode_rd_stats);
 
@@ -3694,22 +4044,29 @@
     return;
   }
 
+#if CONFIG_NEW_REF_SIGNALING
+  const MV_REFERENCE_FRAME ref_frame = skip_mode_info->ref_frame_idx_0;
+  const MV_REFERENCE_FRAME second_ref_frame = skip_mode_info->ref_frame_idx_1;
+#else
   const MV_REFERENCE_FRAME ref_frame =
       LAST_FRAME + skip_mode_info->ref_frame_idx_0;
   const MV_REFERENCE_FRAME second_ref_frame =
       LAST_FRAME + skip_mode_info->ref_frame_idx_1;
+#endif  // CONFIG_NEW_REF_SIGNALING
 
 #if CONFIG_NEW_INTER_MODES
   const PREDICTION_MODE this_mode = NEAR_NEARMV;
 #else
   const PREDICTION_MODE this_mode = NEAREST_NEARESTMV;
 #endif  // CONFIG_NEW_INTER_MODES
+#if !CONFIG_NEW_REF_SIGNALING
   const THR_MODES mode_index =
       get_prediction_mode_idx(this_mode, ref_frame, second_ref_frame);
 
   if (mode_index == THR_INVALID) {
     return;
   }
+#endif  // !CONFIG_NEW_REF_SIGNALING
 
   if ((!cpi->oxcf.ref_frm_cfg.enable_onesided_comp ||
        cpi->sf.inter_sf.disable_onesided_comp) &&
@@ -3754,7 +4111,6 @@
   mbmi->filter_intra_mode_info.use_filter_intra = 0;
   mbmi->interintra_mode = (INTERINTRA_MODE)(II_DC_PRED - 1);
   mbmi->comp_group_idx = 0;
-  mbmi->compound_idx = x->compound_idx;
   mbmi->interinter_comp.type = COMPOUND_AVERAGE;
   mbmi->motion_mode = SIMPLE_TRANSLATION;
   mbmi->ref_mv_idx = 0;
@@ -3764,7 +4120,11 @@
   mbmi->skip_mode = mbmi->skip_txfm = 1;
 #endif
 
-  set_default_interp_filters(mbmi, cm->features.interp_filter);
+  set_default_interp_filters(mbmi,
+#if CONFIG_OPTFLOW_REFINEMENT
+                             cm,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
+                             cm->features.interp_filter);
 
   set_ref_ptrs(cm, xd, mbmi->ref_frame[0], mbmi->ref_frame[1]);
   for (int i = 0; i < num_planes; i++) {
@@ -3796,7 +4156,9 @@
 
   if (skip_mode_rd_stats.rdcost <= best_intra_inter_mode_cost &&
       (!xd->lossless[mbmi->segment_id] || skip_mode_rd_stats.dist == 0)) {
+#if !CONFIG_NEW_REF_SIGNALING
     assert(mode_index != THR_INVALID);
+#endif  // !CONFIG_NEW_REF_SIGNALING
     search_state->best_mbmode.skip_mode = 1;
     search_state->best_mbmode = *mbmi;
 #if CONFIG_SDP
@@ -3841,7 +4203,6 @@
     search_state->best_mbmode.palette_mode_info.palette_size[1] = 0;
 
     search_state->best_mbmode.comp_group_idx = 0;
-    search_state->best_mbmode.compound_idx = x->compound_idx;
     search_state->best_mbmode.interinter_comp.type = COMPOUND_AVERAGE;
     search_state->best_mbmode.motion_mode = SIMPLE_TRANSLATION;
 
@@ -3850,10 +4211,11 @@
     search_state->best_mbmode.filter_intra_mode_info.use_filter_intra = 0;
 
     set_default_interp_filters(&search_state->best_mbmode,
+#if CONFIG_OPTFLOW_REFINEMENT
+                               cm,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
                                cm->features.interp_filter);
 
-    search_state->best_mode_index = mode_index;
-
     // Update rd_cost
     rd_cost->rate = skip_mode_rd_stats.rate;
     rd_cost->dist = rd_cost->sse = skip_mode_rd_stats.dist;
@@ -3871,10 +4233,9 @@
 // Get winner mode stats of given mode index
 static AOM_INLINE MB_MODE_INFO *get_winner_mode_stats(
     MACROBLOCK *x, MB_MODE_INFO *best_mbmode, RD_STATS *best_rd_cost,
-    int best_rate_y, int best_rate_uv, THR_MODES *best_mode_index,
-    RD_STATS **winner_rd_cost, int *winner_rate_y, int *winner_rate_uv,
-    THR_MODES *winner_mode_index, MULTI_WINNER_MODE_TYPE multi_winner_mode_type,
-    int mode_idx) {
+    int best_rate_y, int best_rate_uv, RD_STATS **winner_rd_cost,
+    int *winner_rate_y, int *winner_rate_uv, PREDICTION_MODE *winner_mode,
+    MULTI_WINNER_MODE_TYPE multi_winner_mode_type, int mode_idx) {
   MB_MODE_INFO *winner_mbmi;
   if (multi_winner_mode_type) {
     assert(mode_idx >= 0 && mode_idx < x->winner_mode_count);
@@ -3884,13 +4245,13 @@
     *winner_rd_cost = &winner_mode_stat->rd_cost;
     *winner_rate_y = winner_mode_stat->rate_y;
     *winner_rate_uv = winner_mode_stat->rate_uv;
-    *winner_mode_index = winner_mode_stat->mode_index;
+    *winner_mode = winner_mode_stat->mode;
   } else {
     winner_mbmi = best_mbmode;
     *winner_rd_cost = best_rd_cost;
     *winner_rate_y = best_rate_y;
     *winner_rate_uv = best_rate_uv;
-    *winner_mode_index = *best_mode_index;
+    *winner_mode = best_mbmode->mode;
   }
   return winner_mbmi;
 }
@@ -3902,9 +4263,9 @@
 // transform types and get accurate rdcost.
 static AOM_INLINE void refine_winner_mode_tx(
     const AV1_COMP *cpi, MACROBLOCK *x, RD_STATS *rd_cost, BLOCK_SIZE bsize,
-    PICK_MODE_CONTEXT *ctx, THR_MODES *best_mode_index,
-    MB_MODE_INFO *best_mbmode, struct buf_2d yv12_mb[REF_FRAMES][MAX_MB_PLANE],
-    int best_rate_y, int best_rate_uv, int *best_skip2, int winner_mode_count) {
+    PICK_MODE_CONTEXT *ctx, MB_MODE_INFO *best_mbmode,
+    struct buf_2d yv12_mb[REF_FRAMES][MAX_MB_PLANE], int best_rate_y,
+    int best_rate_uv, int *best_skip2, int winner_mode_count) {
   const AV1_COMMON *const cm = &cpi->common;
   MACROBLOCKD *const xd = &x->e_mbd;
   MB_MODE_INFO *const mbmi = xd->mi[0];
@@ -3920,23 +4281,23 @@
   set_mode_eval_params(cpi, x, WINNER_MODE_EVAL);
 
   // No best mode identified so far
-  if (*best_mode_index == THR_INVALID) return;
+  if (best_mbmode->mode == MODE_INVALID) return;
 
   best_rd = RDCOST(x->rdmult, rd_cost->rate, rd_cost->dist);
   for (int mode_idx = 0; mode_idx < winner_mode_count; mode_idx++) {
     RD_STATS *winner_rd_stats = NULL;
     int winner_rate_y = 0, winner_rate_uv = 0;
-    THR_MODES winner_mode_index = 0;
+    PREDICTION_MODE winner_mode = 0;
 
     // TODO(any): Combine best mode and multi-winner mode processing paths
     // Get winner mode stats for current mode index
     MB_MODE_INFO *winner_mbmi = get_winner_mode_stats(
-        x, best_mbmode, rd_cost, best_rate_y, best_rate_uv, best_mode_index,
-        &winner_rd_stats, &winner_rate_y, &winner_rate_uv, &winner_mode_index,
+        x, best_mbmode, rd_cost, best_rate_y, best_rate_uv, &winner_rd_stats,
+        &winner_rate_y, &winner_rate_uv, &winner_mode,
         cpi->sf.winner_mode_sf.multi_winner_mode_type, mode_idx);
 
     if (xd->lossless[winner_mbmi->segment_id] == 0 &&
-        winner_mode_index != THR_INVALID &&
+        winner_mode != MODE_INVALID &&
         is_winner_mode_processing_enabled(cpi, winner_mbmi,
                                           winner_mbmi->mode)) {
       RD_STATS rd_stats = *winner_rd_stats;
@@ -4011,7 +4372,6 @@
           RDCOST(x->rdmult, this_rate, (rd_stats_y.dist + rd_stats_uv.dist));
       if (best_rd > this_rd) {
         *best_mbmode = *mbmi;
-        *best_mode_index = winner_mode_index;
         av1_copy_array(ctx->blk_skip, txfm_info->blk_skip, ctx->num_4x4_blk);
         av1_copy_array(ctx->tx_type_map, xd->tx_type_map, ctx->num_4x4_blk);
         rd_cost->rate = this_rate;
@@ -4032,12 +4392,62 @@
   uint32_t pred_modes[REF_FRAMES];
   // If ref_combo[i][j + 1] is true, do NOT try prediction using combination of
   // reference frames (i, j).
-  // Note: indexing with 'j + 1' is due to the fact that 2nd reference can be -1
-  // (NONE_FRAME).
+  // Indexing with 'j + 1' is due to the fact that 2nd reference can be -1
+  // (INVALID_FRAME).
+  // NOTE: In CONFIG_NEW_REF_SIGNALING, indexing for the reference has the
+  // order the INTER references followed by INTRA
   bool ref_combo[REF_FRAMES][REF_FRAMES + 1];
 } mode_skip_mask_t;
 /*!\endcond */
 
+#if CONFIG_NEW_REF_SIGNALING
+// Update 'ref_combo' mask to disable given 'ref' in single and compound modes.
+static AOM_INLINE void disable_reference(
+    MV_REFERENCE_FRAME ref, bool ref_combo[REF_FRAMES][REF_FRAMES + 1]) {
+  ref = (ref == INTRA_FRAME_NRS ? INTER_REFS_PER_FRAME : ref);
+  for (MV_REFERENCE_FRAME ref2 = INVALID_IDX; ref2 < REF_FRAMES; ++ref2) {
+    ref_combo[ref][ref2 + 1] = true;
+  }
+}
+
+static const MV_REFERENCE_FRAME reduced_ref_combos[][2] = {
+  { 0, INVALID_IDX },
+  { 1, INVALID_IDX },
+  { 2, INVALID_IDX },
+  { 3, INVALID_IDX },
+  { 4, INVALID_IDX },
+  { INTRA_FRAME_NRS, INVALID_IDX },
+  { 0, INTRA_FRAME_NRS },
+  { 1, INTRA_FRAME_NRS },
+  { 2, INTRA_FRAME_NRS },
+  { 3, INTRA_FRAME_NRS },
+  { 0, 1 },
+  { 0, 2 },
+  { 0, 3 },
+  { 1, 2 },
+  { 1, 3 },
+  { 2, 3 },
+};
+
+static void set_mask_combo_bit_nrs(bool ref_combo[REF_FRAMES][REF_FRAMES + 1],
+                                   const MV_REFERENCE_FRAME *refs, bool val) {
+  const MV_REFERENCE_FRAME r0 =
+      (refs[0] == INTRA_FRAME_NRS ? INTER_REFS_PER_FRAME : refs[0]);
+  const MV_REFERENCE_FRAME r1 =
+      (refs[1] == INTRA_FRAME_NRS ? INTER_REFS_PER_FRAME : refs[1]);
+  ref_combo[r0][r1 + 1] = val;
+}
+
+static bool get_mask_combo_bit_nrs(
+    const bool ref_combo[REF_FRAMES][REF_FRAMES + 1],
+    const MV_REFERENCE_FRAME *refs) {
+  const MV_REFERENCE_FRAME r0 =
+      (refs[0] == INTRA_FRAME_NRS ? INTER_REFS_PER_FRAME : refs[0]);
+  const MV_REFERENCE_FRAME r1 =
+      (refs[1] == INTRA_FRAME_NRS ? INTER_REFS_PER_FRAME : refs[1]);
+  return ref_combo[r0][r1 + 1];
+}
+#else
 // Update 'ref_combo' mask to disable given 'ref' in single and compound modes.
 static AOM_INLINE void disable_reference(
     MV_REFERENCE_FRAME ref, bool ref_combo[REF_FRAMES][REF_FRAMES + 1]) {
@@ -4067,6 +4477,7 @@
   { BWDREF_FRAME, NONE_FRAME },   { BWDREF_FRAME, ALTREF_FRAME },
   { ALTREF_FRAME, INTRA_FRAME },  { BWDREF_FRAME, INTRA_FRAME },
 };
+#endif  // CONFIG_NEW_REF_SIGNALING
 
 typedef enum { REF_SET_FULL, REF_SET_REDUCED } REF_SET;
 
@@ -4079,11 +4490,10 @@
     // All modes available by default.
     memset(mask->pred_modes, 0, sizeof(mask->pred_modes));
     // All references disabled first.
-    for (MV_REFERENCE_FRAME ref1 = INTRA_FRAME; ref1 < REF_FRAMES; ++ref1) {
-      for (MV_REFERENCE_FRAME ref2 = NONE_FRAME; ref2 < REF_FRAMES; ++ref2) {
-        mask->ref_combo[ref1][ref2 + 1] = true;
-      }
-    }
+    bool *mask_ref_combo = &mask->ref_combo[0][0];
+    for (int k = 0; k < REF_FRAMES * (REF_FRAMES + 1); k++)
+      mask_ref_combo[k] = true;
+
     const MV_REFERENCE_FRAME(*ref_set_combos)[2];
     int num_ref_combos;
 
@@ -4099,7 +4509,11 @@
 
     for (int i = 0; i < num_ref_combos; ++i) {
       const MV_REFERENCE_FRAME *const this_combo = ref_set_combos[i];
+#if CONFIG_NEW_REF_SIGNALING
+      set_mask_combo_bit_nrs(mask->ref_combo, this_combo, false);
+#else
       mask->ref_combo[this_combo[0]][this_combo[1] + 1] = false;
+#endif  // CONFIG_NEW_REF_SIGNALING
     }
   }
 }
@@ -4108,10 +4522,12 @@
                                            const AV1_COMP *cpi, MACROBLOCK *x,
                                            BLOCK_SIZE bsize) {
   const AV1_COMMON *const cm = &cpi->common;
+#if !CONFIG_NEW_REF_SIGNALING
   const struct segmentation *const seg = &cm->seg;
   MACROBLOCKD *const xd = &x->e_mbd;
   MB_MODE_INFO *const mbmi = xd->mi[0];
   unsigned char segment_id = mbmi->segment_id;
+#endif  // !CONFIG_NEW_REF_SIGNALING
   const SPEED_FEATURES *const sf = &cpi->sf;
   REF_SET ref_set = REF_SET_FULL;
 
@@ -4122,11 +4538,21 @@
 
   int min_pred_mv_sad = INT_MAX;
   MV_REFERENCE_FRAME ref_frame;
+#if CONFIG_NEW_REF_SIGNALING
+  for (ref_frame = 0; ref_frame < cm->ref_frames_info.n_total_refs; ++ref_frame)
+#else
   for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame)
+#endif  // CONFIG_NEW_REF_SIGNALING
     min_pred_mv_sad = AOMMIN(min_pred_mv_sad, x->pred_mv_sad[ref_frame]);
 
+#if CONFIG_NEW_REF_SIGNALING
+  for (ref_frame = 0; ref_frame < cm->ref_frames_info.n_total_refs;
+       ++ref_frame) {
+    if (!(cm->ref_frame_flags & (1 << ref_frame))) {
+#else
   for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
-    if (!(cpi->ref_frame_flags & av1_ref_frame_flag_list[ref_frame])) {
+    if (!(cm->ref_frame_flags & av1_ref_frame_flag_list[ref_frame])) {
+#endif  // CONFIG_NEW_REF_SIGNALING
       // Skip checking missing reference in both single and compound reference
       // modes.
       disable_reference(ref_frame, mask->ref_combo);
@@ -4136,12 +4562,16 @@
         mask->pred_modes[ref_frame] |= INTER_NEAREST_NEAR_ZERO;
       }
     }
+#if !CONFIG_NEW_REF_SIGNALING
     if (segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME) &&
         get_segdata(seg, segment_id, SEG_LVL_REF_FRAME) != (int)ref_frame) {
       // Reference not used for the segment.
       disable_reference(ref_frame, mask->ref_combo);
     }
+#endif  // !CONFIG_NEW_REF_SIGNALING
   }
+
+#if !CONFIG_NEW_REF_SIGNALING
   // Note: We use the following drop-out only if the SEG_LVL_REF_FRAME feature
   // is disabled for this segment. This is to prevent the possibility that we
   // end up unable to pick any mode.
@@ -4172,7 +4602,7 @@
 
   if (cpi->rc.is_src_frame_alt_ref) {
     if (sf->inter_sf.alt_ref_search_fp) {
-      assert(cpi->ref_frame_flags & av1_ref_frame_flag_list[ALTREF_FRAME]);
+      assert(cm->ref_frame_flags & av1_ref_frame_flag_list[ALTREF_FRAME]);
       mask->pred_modes[ALTREF_FRAME] = 0;
       disable_inter_references_except_altref(mask->ref_combo);
       disable_reference(INTRA_FRAME, mask->ref_combo);
@@ -4192,12 +4622,21 @@
       }
     }
   }
+#endif  // !CONFIG_NEW_REF_SIGNALING
 
   if (bsize > sf->part_sf.max_intra_bsize) {
+#if CONFIG_NEW_REF_SIGNALING
+    disable_reference(INTRA_FRAME_NRS, mask->ref_combo);
+#else
     disable_reference(INTRA_FRAME, mask->ref_combo);
+#endif  // CONFIG_NEW_REF_SIGNALING
   }
 
+#if CONFIG_NEW_REF_SIGNALING
+  mask->pred_modes[INTRA_FRAME_INDEX_NRS] |=
+#else
   mask->pred_modes[INTRA_FRAME] |=
+#endif  // CONFIG_NEW_REF_SIGNALING
       ~(sf->intra_sf.intra_y_mode_mask[max_txsize_lookup[bsize]]);
 }
 
@@ -4226,6 +4665,35 @@
   }
 }
 
+#if CONFIG_NEW_REF_SIGNALING
+static AOM_INLINE int prune_ref_frame(const AV1_COMP *cpi, const MACROBLOCK *x,
+                                      const MV_REFERENCE_FRAME ref_frame) {
+  const AV1_COMMON *const cm = &cpi->common;
+  MV_REFERENCE_FRAME rf[2];
+  av1_set_ref_frame(rf, ref_frame);
+  const int comp_pred = is_inter_ref_frame(rf[1]);
+  if (comp_pred) {
+    if (!cpi->oxcf.ref_frm_cfg.enable_onesided_comp ||
+        cpi->sf.inter_sf.disable_onesided_comp) {
+      // Disable all compound references
+      if (cpi->all_one_sided_refs) return 1;
+      // If both references are on the same side prune
+      if (get_dir_rank(cm, rf[0], NULL) == get_dir_rank(cm, rf[1], NULL))
+        return 1;
+    } else if (cpi->sf.inter_sf.selective_ref_frame >= 2) {
+      // If both references are on the same side prune
+      if (get_dir_rank(cm, rf[0], NULL) == get_dir_rank(cm, rf[1], NULL))
+        return 1;
+    }
+  }
+
+  if (prune_ref_by_selective_ref_frame_nrs(cpi, x, rf)) {
+    return 1;
+  }
+
+  return 0;
+}
+#else
 static AOM_INLINE int prune_ref_frame(const AV1_COMP *cpi, const MACROBLOCK *x,
                                       MV_REFERENCE_FRAME ref_frame) {
   const AV1_COMMON *const cm = &cpi->common;
@@ -4241,6 +4709,27 @@
 
   return 0;
 }
+#endif  // CONFIG_NEW_REF_SIGNALING
+
+static AOM_INLINE int is_ref_frame_used_by_compound_ref(
+    int ref_frame, int skip_ref_frame_mask) {
+#if CONFIG_NEW_REF_SIGNALING
+  for (int r = INTER_REFS_PER_FRAME; r < INTRA_FRAME_NRS; ++r) {
+    if (!(skip_ref_frame_mask & (1 << r))) {
+      MV_REFERENCE_FRAME rf[2];
+      av1_set_ref_frame(rf, r);
+#else
+  for (int r = ALTREF_FRAME + 1; r < MODE_CTX_REF_FRAMES; ++r) {
+    if (!(skip_ref_frame_mask & (1 << r))) {
+      const MV_REFERENCE_FRAME *rf = ref_frame_map[r - REF_FRAMES];
+#endif  // CONFIG_NEW_REF_SIGNALING
+      if (rf[0] == ref_frame || rf[1] == ref_frame) {
+        return 1;
+      }
+    }
+  }
+  return 0;
+}
 
 // Please add/modify parameter setting in this function, making it consistent
 // and easy to read and maintain.
@@ -4262,49 +4751,61 @@
 
   const int mi_row = xd->mi_row;
   const int mi_col = xd->mi_col;
-  MV_REFERENCE_FRAME ref_frame;
   x->best_pred_mv_sad = INT_MAX;
+  MV_REFERENCE_FRAME ref_frame;
+#if CONFIG_NEW_REF_SIGNALING
+  for (ref_frame = 0; ref_frame < INTER_REFS_PER_FRAME; ++ref_frame) {
+    x->mbmi_ext->mode_context[ref_frame] = 0;
+    mbmi_ext->ref_mv_count[ref_frame] = UINT8_MAX;
+    if ((cm->ref_frame_flags & (1 << ref_frame))) {
+      x->pred_mv_sad[ref_frame] = INT_MAX;
+#else
   for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
     x->pred_mv_sad[ref_frame] = INT_MAX;
     x->mbmi_ext->mode_context[ref_frame] = 0;
     mbmi_ext->ref_mv_count[ref_frame] = UINT8_MAX;
-    if (cpi->ref_frame_flags & av1_ref_frame_flag_list[ref_frame]) {
+    if (cm->ref_frame_flags & av1_ref_frame_flag_list[ref_frame]) {
+#endif  // CONFIG_NEW_REF_SIGNALING
       if (mbmi->partition != PARTITION_NONE &&
           mbmi->partition != PARTITION_SPLIT) {
-        if (skip_ref_frame_mask & (1 << ref_frame)) {
-          int skip = 1;
-          for (int r = ALTREF_FRAME + 1; r < MODE_CTX_REF_FRAMES; ++r) {
-            if (!(skip_ref_frame_mask & (1 << r))) {
-              const MV_REFERENCE_FRAME *rf = ref_frame_map[r - REF_FRAMES];
-              if (rf[0] == ref_frame || rf[1] == ref_frame) {
-                skip = 0;
-                break;
-              }
-            }
-          }
-          if (skip) continue;
-        }
+        if (skip_ref_frame_mask & (1 << ref_frame) &&
+            !is_ref_frame_used_by_compound_ref(ref_frame, skip_ref_frame_mask))
+          continue;
       }
       assert(get_ref_frame_yv12_buf(cm, ref_frame) != NULL);
       setup_buffer_ref_mvs_inter(cpi, x, ref_frame, bsize, yv12_mb);
     }
+#if !CONFIG_NEW_REF_SIGNALING
     // Store the best pred_mv_sad across all past frames
     if (cpi->sf.inter_sf.alt_ref_search_fp &&
         cpi->ref_frame_dist_info.ref_relative_dist[ref_frame - LAST_FRAME] < 0)
       x->best_pred_mv_sad =
           AOMMIN(x->best_pred_mv_sad, x->pred_mv_sad[ref_frame]);
+#endif  // !CONFIG_NEW_REF_SIGNALING
   }
-  // ref_frame = ALTREF_FRAME
+
   if (is_comp_ref_allowed(bsize)) {
     // No second reference on RT ref set, so no need to initialize
     for (; ref_frame < MODE_CTX_REF_FRAMES; ++ref_frame) {
       x->mbmi_ext->mode_context[ref_frame] = 0;
       mbmi_ext->ref_mv_count[ref_frame] = UINT8_MAX;
-      const MV_REFERENCE_FRAME *rf = ref_frame_map[ref_frame - REF_FRAMES];
-      if (!((cpi->ref_frame_flags & av1_ref_frame_flag_list[rf[0]]) &&
-            (cpi->ref_frame_flags & av1_ref_frame_flag_list[rf[1]]))) {
+#if CONFIG_NEW_REF_SIGNALING
+      MV_REFERENCE_FRAME rf[2];
+      av1_set_ref_frame(rf, ref_frame);
+      if (rf[0] >= cm->ref_frames_info.n_total_refs ||
+          rf[1] >= cm->ref_frames_info.n_total_refs)
+        continue;
+      if (!((cm->ref_frame_flags & (1 << rf[0])) &&
+            (cm->ref_frame_flags & (1 << rf[1])))) {
         continue;
       }
+#else
+      const MV_REFERENCE_FRAME *rf = ref_frame_map[ref_frame - REF_FRAMES];
+      if (!((cm->ref_frame_flags & av1_ref_frame_flag_list[rf[0]]) &&
+            (cm->ref_frame_flags & av1_ref_frame_flag_list[rf[1]]))) {
+        continue;
+      }
+#endif  // CONFIG_NEW_REF_SIGNALING
 
       if (mbmi->partition != PARTITION_NONE &&
           mbmi->partition != PARTITION_SPLIT) {
@@ -4388,6 +4889,8 @@
 
   av1_zero(search_state->best_mbmode);
 
+  search_state->best_mbmode.mode = MODE_INVALID;
+
   search_state->best_rate_y = INT_MAX;
 
   search_state->best_rate_uv = INT_MAX;
@@ -4396,8 +4899,6 @@
 
   search_state->best_skip2 = 0;
 
-  search_state->best_mode_index = THR_INVALID;
-
   const MACROBLOCKD *const xd = &x->e_mbd;
   const MB_MODE_INFO *const mbmi = xd->mi[0];
   const unsigned char segment_id = mbmi->segment_id;
@@ -4407,6 +4908,16 @@
   memset(search_state->dist_order_refs, -1,
          sizeof(search_state->dist_order_refs));
 
+#if CONFIG_NEW_REF_SIGNALING
+  const int *const rd_threshes = cpi->rd.threshes[segment_id][bsize];
+  for (int i = 0; i < MB_MODE_COUNT; ++i)
+    search_state->mode_threshold[i] =
+        ((int64_t)rd_threshes[i] * x->thresh_freq_fact[bsize][i]) >>
+        RD_THRESH_FAC_FRAC_BITS;
+#if !CONFIG_NEW_INTER_MODES
+  search_state->mode_threshold[NEARESTMV] = 0;
+#endif  // !CONFIG_NEW_INTER_MODES
+#else
   for (int i = 0; i <= LAST_NEW_MV_INDEX; ++i)
     search_state->mode_threshold[i] = 0;
   const int *const rd_threshes = cpi->rd.threshes[segment_id][bsize];
@@ -4414,6 +4925,7 @@
     search_state->mode_threshold[i] =
         ((int64_t)rd_threshes[i] * x->thresh_freq_fact[bsize][i]) >>
         RD_THRESH_FAC_FRAC_BITS;
+#endif  // CONFIG_NEW_REF_SIGNALING
 
   search_state->best_intra_rd = INT64_MAX;
 
@@ -4433,23 +4945,40 @@
 
   for (int dir = 0; dir < 2; ++dir) {
     for (int mode = 0; mode < SINGLE_INTER_MODE_NUM; ++mode) {
+#if CONFIG_NEW_REF_SIGNALING
+      for (int ref_frame = 0; ref_frame < REF_FRAMES; ++ref_frame) {
+#else
       for (int ref_frame = 0; ref_frame < FWD_REFS; ++ref_frame) {
+#endif  // CONFIG_NEW_REF_SIGNALING
         SingleInterModeState *state;
 
         state = &search_state->single_state[dir][mode][ref_frame];
+#if CONFIG_NEW_REF_SIGNALING
+        state->ref_frame = INVALID_IDX;
+#else
         state->ref_frame = NONE_FRAME;
+#endif  // CONFIG_NEW_REF_SIGNALING
         state->rd = INT64_MAX;
 
         state = &search_state->single_state_modelled[dir][mode][ref_frame];
+#if CONFIG_NEW_REF_SIGNALING
+        state->ref_frame = INVALID_IDX;
+#else
         state->ref_frame = NONE_FRAME;
+#endif  // CONFIG_NEW_REF_SIGNALING
         state->rd = INT64_MAX;
       }
     }
   }
   for (int dir = 0; dir < 2; ++dir) {
     for (int mode = 0; mode < SINGLE_INTER_MODE_NUM; ++mode) {
+#if CONFIG_NEW_REF_SIGNALING
+      for (int ref_frame = 0; ref_frame < REF_FRAMES; ++ref_frame) {
+        search_state->single_rd_order[dir][mode][ref_frame] = INVALID_IDX;
+#else
       for (int ref_frame = 0; ref_frame < FWD_REFS; ++ref_frame) {
         search_state->single_rd_order[dir][mode][ref_frame] = NONE_FRAME;
+#endif  // CONFIG_NEW_REF_SIGNALING
       }
     }
   }
@@ -4464,23 +4993,35 @@
 static bool mask_says_skip(const mode_skip_mask_t *mode_skip_mask,
                            const MV_REFERENCE_FRAME *ref_frame,
                            const PREDICTION_MODE this_mode) {
+#if CONFIG_NEW_REF_SIGNALING
+  if (mode_skip_mask->pred_modes[COMPACT_INDEX0_NRS(ref_frame[0])] &
+      (1 << this_mode)) {
+#else
   if (mode_skip_mask->pred_modes[ref_frame[0]] & (1 << this_mode)) {
+#endif  // CONFIG_NEW_REF_SIGNALING
     return true;
   }
 
+#if CONFIG_NEW_REF_SIGNALING
+  return get_mask_combo_bit_nrs(mode_skip_mask->ref_combo, ref_frame);
+#else
   return mode_skip_mask->ref_combo[ref_frame[0]][ref_frame[1] + 1];
+#endif  // CONFIG_NEW_REF_SIGNALING
 }
 
 static int inter_mode_compatible_skip(const AV1_COMP *cpi, const MACROBLOCK *x,
                                       BLOCK_SIZE bsize,
                                       PREDICTION_MODE curr_mode,
                                       const MV_REFERENCE_FRAME *ref_frames) {
-  const int comp_pred = ref_frames[1] > INTRA_FRAME;
+  const int comp_pred = is_inter_ref_frame(ref_frames[1]);
   if (comp_pred) {
     if (!is_comp_ref_allowed(bsize)) return 1;
-    if (!(cpi->ref_frame_flags & av1_ref_frame_flag_list[ref_frames[1]])) {
+#if CONFIG_NEW_REF_SIGNALING
+    if (!(cpi->common.ref_frame_flags & (1 << ref_frames[1])))
+#else
+    if (!(cpi->common.ref_frame_flags & av1_ref_frame_flag_list[ref_frames[1]]))
+#endif  // CONFIG_NEW_REF_SIGNALING
       return 1;
-    }
 
     const AV1_COMMON *const cm = &cpi->common;
     if (frame_is_intra_only(cm)) return 1;
@@ -4488,14 +5029,22 @@
     const CurrentFrame *const current_frame = &cm->current_frame;
     if (current_frame->reference_mode == SINGLE_REFERENCE) return 1;
 
+#if CONFIG_NEW_REF_SIGNALING
+    (void)x;
+#else
     const struct segmentation *const seg = &cm->seg;
     const unsigned char segment_id = x->e_mbd.mi[0]->segment_id;
     // Do not allow compound prediction if the segment level reference frame
     // feature is in use as in this case there can only be one reference.
     if (segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME)) return 1;
+#endif  // CONFIG_NEW_REF_SIGNALING
   }
 
-  if (ref_frames[0] > INTRA_FRAME && ref_frames[1] == INTRA_FRAME) {
+#if CONFIG_NEW_REF_SIGNALING
+  if (is_inter_ref_frame(ref_frames[0]) && ref_frames[1] == INTRA_FRAME_NRS) {
+#else
+  if (is_inter_ref_frame(ref_frames[0]) && ref_frames[1] == INTRA_FRAME) {
+#endif  // CONFIG_NEW_REF_SIGNALING
     // Mode must be compatible
     if (!is_interintra_allowed_bsize(bsize)) return 1;
     if (!is_interintra_allowed_mode(curr_mode)) return 1;
@@ -4539,7 +5088,11 @@
 
   // This is only used in motion vector unit test.
   if (cpi->oxcf.unit_test_cfg.motion_vector_unit_test &&
+#if CONFIG_NEW_REF_SIGNALING
+      ref_frame[0] == INTRA_FRAME_NRS)
+#else
       ref_frame[0] == INTRA_FRAME)
+#endif  // CONFIG_NEW_REF_SIGNALING
     return 1;
 
   const AV1_COMMON *const cm = &cpi->common;
@@ -4557,6 +5110,17 @@
   int skip_motion_mode = 0;
   if (mbmi->partition != PARTITION_NONE && mbmi->partition != PARTITION_SPLIT) {
     int skip_ref = skip_ref_frame_mask & (1 << ref_type);
+#if CONFIG_NEW_REF_SIGNALING
+    if (ref_type < INTER_REFS_PER_FRAME && skip_ref) {
+      // Since the compound ref modes depends on the motion estimation result of
+      // two single ref modes( best mv of single ref modes as the start point )
+      // If current single ref mode is marked skip, we need to check if it will
+      // be used in compound ref modes.
+      for (int r = INTER_REFS_PER_FRAME; r < INTRA_FRAME_NRS; ++r) {
+        if (skip_ref_frame_mask & (1 << r)) continue;
+        MV_REFERENCE_FRAME rf[2];
+        av1_set_ref_frame(rf, r);
+#else
     if (ref_type <= ALTREF_FRAME && skip_ref) {
       // Since the compound ref modes depends on the motion estimation result of
       // two single ref modes( best mv of single ref modes as the start point )
@@ -4565,6 +5129,7 @@
       for (int r = ALTREF_FRAME + 1; r < MODE_CTX_REF_FRAMES; ++r) {
         if (skip_ref_frame_mask & (1 << r)) continue;
         const MV_REFERENCE_FRAME *rf = ref_frame_map[r - REF_FRAMES];
+#endif  // CONFIG_NEW_REF_SIGNALING
         if (rf[0] == ref_type || rf[1] == ref_type) {
           // Found a not skipped compound ref mode which contains current
           // single ref. So this single ref can't be skipped completly
@@ -4599,18 +5164,28 @@
   mbmi->mv[0].as_int = mbmi->mv[1].as_int = 0;
   mbmi->motion_mode = SIMPLE_TRANSLATION;
   mbmi->interintra_mode = (INTERINTRA_MODE)(II_DC_PRED - 1);
-  set_default_interp_filters(mbmi, cm->features.interp_filter);
+  set_default_interp_filters(mbmi,
+#if CONFIG_OPTFLOW_REFINEMENT
+                             cm,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
+                             cm->features.interp_filter);
 }
 
-static AOM_INLINE void collect_single_states(const FeatureFlags *const features,
+static AOM_INLINE void collect_single_states(const AV1_COMMON *const cm,
                                              MACROBLOCK *x,
                                              InterModeSearchState *search_state,
                                              const MB_MODE_INFO *const mbmi) {
+  const FeatureFlags *const features = &cm->features;
   (void)features;
   int i, j;
-  const MV_REFERENCE_FRAME ref_frame = mbmi->ref_frame[0];
   const PREDICTION_MODE this_mode = mbmi->mode;
+#if CONFIG_NEW_REF_SIGNALING
+  const MV_REFERENCE_FRAME ref_frame = COMPACT_INDEX0_NRS(mbmi->ref_frame[0]);
+  const int dir = get_dir_rank(cm, ref_frame, NULL);
+#else
+  const MV_REFERENCE_FRAME ref_frame = mbmi->ref_frame[0];
   const int dir = ref_frame <= GOLDEN_FRAME ? 0 : 1;
+#endif  // CONFIG_NEW_REF_SIGNALING
   const int mode_offset = INTER_OFFSET(this_mode);
   const int ref_set = get_drl_refmv_count(
 #if CONFIG_NEW_INTER_MODES
@@ -4662,7 +5237,11 @@
 
   for (dir = 0; dir < 2; ++dir) {
     int64_t best_rd;
+#if CONFIG_NEW_REF_SIGNALING
+    SingleInterModeState(*state)[REF_FRAMES];
+#else
     SingleInterModeState(*state)[FWD_REFS];
+#endif  // CONFIG_NEW_REF_SIGNALING
     const int prune_factor = prune_level >= 2 ? 6 : 5;
 
     // Use the best rd of GLOBALMV or NEWMV to prune the unlikely
@@ -4753,10 +5332,18 @@
       search_state->single_state_modelled[dir][mode_offset];
 
   int max_candidates = 0;
+#if CONFIG_NEW_REF_SIGNALING
+  for (int i = 0; i < INTER_REFS_PER_FRAME; ++i) {
+    if (search_state->single_rd_order[dir][mode_offset][i] == INVALID_IDX)
+      break;
+    max_candidates++;
+  }
+#else
   for (int i = 0; i < FWD_REFS; ++i) {
     if (search_state->single_rd_order[dir][mode_offset][i] == NONE_FRAME) break;
     max_candidates++;
   }
+#endif  // CONFIG_NEW_REF_SIGNALING
 
   int candidates = max_candidates;
   if (cpi->sf.inter_sf.prune_comp_search_by_single_result >= 2) {
@@ -4785,8 +5372,13 @@
   const int mode[2] = { compound_ref0_mode(this_mode),
                         compound_ref1_mode(this_mode) };
   const int mode_offset[2] = { INTER_OFFSET(mode[0]), INTER_OFFSET(mode[1]) };
+#if CONFIG_NEW_REF_SIGNALING
+  const int mode_dir[2] = { get_dir_rank(&cpi->common, refs[0], NULL),
+                            get_dir_rank(&cpi->common, refs[1], NULL) };
+#else
   const int mode_dir[2] = { refs[0] <= GOLDEN_FRAME ? 0 : 1,
                             refs[1] <= GOLDEN_FRAME ? 0 : 1 };
+#endif  // CONFIG_NEW_REF_SIGNALING
   int ref_searched[2] = { 0, 0 };
   int ref_mv_match[2] = { 1, 1 };
   int i, j;
@@ -4819,7 +5411,11 @@
       continue;
     }
 #endif  // CONFIG_NEW_INTER_MODES
+#if CONFIG_NEW_REF_SIGNALING
+    const MV_REFERENCE_FRAME single_refs[2] = { refs[i], INVALID_IDX };
+#else
     const MV_REFERENCE_FRAME single_refs[2] = { refs[i], NONE_FRAME };
+#endif  // CONFIG_NEW_REF_SIGNALING
     for (int ref_mv_idx = 0; ref_mv_idx < ref_set; ref_mv_idx++) {
       int_mv single_mv;
       int_mv comp_mv;
@@ -4905,9 +5501,14 @@
                                            const PREDICTION_MODE this_mode,
                                            const MV_REFERENCE_FRAME ref_frame,
                                            int64_t this_rd) {
-  if (this_rd < search_state->best_single_rd[ref_frame]) {
-    search_state->best_single_rd[ref_frame] = this_rd;
-    search_state->best_single_mode[ref_frame] = this_mode;
+#if CONFIG_NEW_REF_SIGNALING
+  const MV_REFERENCE_FRAME rf = COMPACT_INDEX0_NRS(ref_frame);
+#else
+  const MV_REFERENCE_FRAME rf = ref_frame;
+#endif  // CONFIG_NEW_REF_SIGNALING
+  if (this_rd < search_state->best_single_rd[rf]) {
+    search_state->best_single_rd[rf] = this_rd;
+    search_state->best_single_mode[rf] = this_mode;
   }
 }
 
@@ -4963,12 +5564,11 @@
     InterModeSearchState *search_state, RD_STATS *best_rd_stats_dst,
     PICK_MODE_CONTEXT *ctx, const RD_STATS *new_best_rd_stats,
     const RD_STATS *new_best_rd_stats_y, const RD_STATS *new_best_rd_stats_uv,
-    THR_MODES new_best_mode, const MACROBLOCK *x, int txfm_search_done) {
+    PREDICTION_MODE new_best_mode, const MACROBLOCK *x, int txfm_search_done) {
   const MACROBLOCKD *xd = &x->e_mbd;
   const MB_MODE_INFO *mbmi = xd->mi[0];
   const int skip_ctx = av1_get_skip_txfm_context(xd);
-  const int mode_is_intra =
-      (av1_mode_defs[new_best_mode].mode < INTRA_MODE_END);
+  const int mode_is_intra = (new_best_mode < INTRA_MODE_END);
 #if CONFIG_SDP
   const int skip_txfm =
       mbmi->skip_txfm[xd->tree_type == CHROMA_PART] && !mode_is_intra;
@@ -4978,7 +5578,6 @@
   const TxfmSearchInfo *txfm_info = &x->txfm_search_info;
 
   search_state->best_rd = new_best_rd_stats->rdcost;
-  search_state->best_mode_index = new_best_mode;
   *best_rd_stats_dst = *new_best_rd_stats;
   search_state->best_mbmode = *mbmi;
   search_state->best_skip2 = skip_txfm;
@@ -5002,10 +5601,15 @@
 // Find the best RD for a reference frame (among single reference modes)
 // and store +10% of it in the 0-th element in ref_frame_rd.
 static AOM_INLINE void find_top_ref(int64_t ref_frame_rd[REF_FRAMES]) {
-  assert(ref_frame_rd[0] == INT64_MAX);
   int64_t ref_copy[REF_FRAMES - 1];
+#if CONFIG_NEW_REF_SIGNALING
+  assert(ref_frame_rd[INTRA_FRAME_INDEX_NRS] == INT64_MAX);
+  memcpy(ref_copy, ref_frame_rd, sizeof(ref_frame_rd[0]) * (REF_FRAMES - 1));
+#else
+  assert(ref_frame_rd[0] == INT64_MAX);
   memcpy(ref_copy, ref_frame_rd + 1,
          sizeof(ref_frame_rd[0]) * (REF_FRAMES - 1));
+#endif  // CONFIG_NEW_REF_SIGNALING
   qsort(ref_copy, REF_FRAMES - 1, sizeof(int64_t), compare_int64);
 
   int64_t cutoff = ref_copy[0];
@@ -5014,16 +5618,26 @@
     assert(cutoff < INT64_MAX / 200);
     cutoff = (110 * cutoff) / 100;
   }
+#if CONFIG_NEW_REF_SIGNALING
+  ref_frame_rd[INTRA_FRAME_INDEX_NRS] = cutoff;
+#else
   ref_frame_rd[0] = cutoff;
+#endif  // CONFIG_NEW_REF_SIGNALING
 }
 
 // Check if either frame is within the cutoff.
 static INLINE bool in_single_ref_cutoff(int64_t ref_frame_rd[REF_FRAMES],
                                         MV_REFERENCE_FRAME frame1,
                                         MV_REFERENCE_FRAME frame2) {
+#if CONFIG_NEW_REF_SIGNALING
+  assert(is_inter_ref_frame(frame2));
+  return ref_frame_rd[frame1] <= ref_frame_rd[INTRA_FRAME_INDEX_NRS] ||
+         ref_frame_rd[frame2] <= ref_frame_rd[INTRA_FRAME_INDEX_NRS];
+#else
   assert(frame2 > 0);
   return ref_frame_rd[frame1] <= ref_frame_rd[0] ||
          ref_frame_rd[frame2] <= ref_frame_rd[0];
+#endif  // CONFIG_NEW_REF_SIGNALING
 }
 
 static AOM_INLINE void evaluate_motion_mode_for_winner_candidates(
@@ -5071,7 +5685,7 @@
     // Initialize motion mode to simple translation
     // Calculation of switchable rate depends on it.
     mbmi->motion_mode = 0;
-    const int is_comp_pred = mbmi->ref_frame[1] > INTRA_FRAME;
+    const int is_comp_pred = is_inter_ref_frame(mbmi->ref_frame[1]);
     for (int i = 0; i < num_planes; i++) {
       xd->plane[i].pre[0] = yv12_mb[mbmi->ref_frame[0]][i];
       if (is_comp_pred) xd->plane[i].pre[1] = yv12_mb[mbmi->ref_frame[1]][i];
@@ -5086,16 +5700,15 @@
 
     if (ret_value != INT64_MAX) {
       rd_stats.rdcost = RDCOST(x->rdmult, rd_stats.rate, rd_stats.dist);
-      const THR_MODES mode_enum = get_prediction_mode_idx(
-          mbmi->mode, mbmi->ref_frame[0], mbmi->ref_frame[1]);
+      MV_REFERENCE_FRAME refs[2] = { mbmi->ref_frame[0], mbmi->ref_frame[1] };
       // Collect mode stats for multiwinner mode processing
       store_winner_mode_stats(
-          &cpi->common, x, mbmi, &rd_stats, &rd_stats_y, &rd_stats_uv,
-          mode_enum, NULL, bsize, rd_stats.rdcost,
+          &cpi->common, x, mbmi, &rd_stats, &rd_stats_y, &rd_stats_uv, refs,
+          mbmi->mode, NULL, bsize, rd_stats.rdcost,
           cpi->sf.winner_mode_sf.multi_winner_mode_type, do_tx_search);
       if (rd_stats.rdcost < search_state->best_rd) {
         update_search_state(search_state, rd_cost, ctx, &rd_stats, &rd_stats_y,
-                            &rd_stats_uv, mode_enum, x, do_tx_search);
+                            &rd_stats_uv, mbmi->mode, x, do_tx_search);
         if (do_tx_search) search_state->best_skip_rd[0] = skip_rd[0];
       }
     }
@@ -5111,26 +5724,32 @@
   int skip_ref_frame_mask;
   int reach_first_comp_mode;
   int mode_thresh_mul_fact;
-  int *intra_mode_idx_ls;
-  int *intra_mode_num;
   int *num_single_modes_processed;
   int prune_cpd_using_sr_stats_ready;
 } InterModeSFArgs;
 /*!\endcond */
 
 static int skip_inter_mode(AV1_COMP *cpi, MACROBLOCK *x, const BLOCK_SIZE bsize,
-                           int64_t *ref_frame_rd, int midx,
+                           int64_t *ref_frame_rd,
+#if CONFIG_NEW_REF_SIGNALING
+                           PREDICTION_MODE this_mode,
+                           const MV_REFERENCE_FRAME *ref_frames,
+#else
+                           int midx,
+#endif  // CONFIG_NEW_REF_SIGNALING
                            InterModeSFArgs *args) {
   const SPEED_FEATURES *const sf = &cpi->sf;
   MACROBLOCKD *const xd = &x->e_mbd;
+#if !CONFIG_NEW_REF_SIGNALING
   // Get the actual prediction mode we are trying in this iteration
   const THR_MODES mode_enum = av1_default_mode_order[midx];
   const MODE_DEFINITION *mode_def = &av1_mode_defs[mode_enum];
   const PREDICTION_MODE this_mode = mode_def->mode;
   const MV_REFERENCE_FRAME *ref_frames = mode_def->ref_frame;
+#endif  // CONFIG_NEW_REF_SIGNALING
   const MV_REFERENCE_FRAME ref_frame = ref_frames[0];
   const MV_REFERENCE_FRAME second_ref_frame = ref_frames[1];
-  const int comp_pred = second_ref_frame > INTRA_FRAME;
+  const int comp_pred = is_inter_ref_frame(second_ref_frame);
 
   // Check if this mode should be skipped because it is incompatible with the
   // current frame
@@ -5138,7 +5757,7 @@
     return 1;
   const int ret = inter_mode_search_order_independent_skip(
       cpi, x, args->mode_skip_mask, args->search_state,
-      args->skip_ref_frame_mask, this_mode, mode_def->ref_frame);
+      args->skip_ref_frame_mask, this_mode, ref_frames);
   if (ret == 1) return 1;
   *(args->skip_motion_mode) = (ret == 2);
 
@@ -5154,23 +5773,37 @@
   int mul_fact = args->search_state->best_mode_skippable
                      ? args->mode_thresh_mul_fact
                      : (1 << MODE_THRESH_QBITS);
+#if CONFIG_NEW_REF_SIGNALING
+  int64_t mode_threshold =
+      (args->search_state->mode_threshold[this_mode] * mul_fact) >>
+      MODE_THRESH_QBITS;
+#else
   int64_t mode_threshold =
       (args->search_state->mode_threshold[mode_enum] * mul_fact) >>
       MODE_THRESH_QBITS;
+#endif  // CONFIG_NEW_REF_SIGNALING
 
   if (args->search_state->best_rd < mode_threshold) return 1;
 
   // Skip this compound mode based on the RD results from the single prediction
   // modes
-  if (sf->inter_sf.prune_comp_search_by_single_result > 0 && comp_pred) {
+  if (sf->inter_sf.prune_comp_search_by_single_result > 0 &&
+#if CONFIG_OPTFLOW_REFINEMENT
+      this_mode <= NEW_NEWMV &&
+#endif  // CONFIG_OPTFLOW_REFINEMENT
+      comp_pred) {
     if (compound_skip_by_single_states(cpi, args->search_state, this_mode,
                                        ref_frame, second_ref_frame, x))
       return 1;
   }
 
   // Speed features to prune out INTRA frames
+#if CONFIG_NEW_REF_SIGNALING
+  if (ref_frame == INTRA_FRAME_NRS) {
+#else
   if (ref_frame == INTRA_FRAME) {
-    // Intra modes will be handled in another loop later
+#endif  // CONFIG_NEW_REF_SIGNALING
+        // Intra modes will be handled in another loop later
     return 1;
   }
 
@@ -5258,11 +5891,12 @@
   InterModesInfo *inter_modes_info = x->inter_modes_info;
   inter_modes_info_sort(inter_modes_info, inter_modes_info->rd_idx_pair_arr);
   search_state->best_rd = best_rd_so_far;
-  search_state->best_mode_index = THR_INVALID;
+  search_state->best_mbmode.mode = MODE_INVALID;
   // Initialize best mode stats for winner mode processing
   x->winner_mode_count = 0;
-  store_winner_mode_stats(&cpi->common, x, mbmi, NULL, NULL, NULL, THR_INVALID,
-                          NULL, bsize, best_rd_so_far,
+  const MV_REFERENCE_FRAME init_refs[2] = { -1, -1 };
+  store_winner_mode_stats(&cpi->common, x, mbmi, NULL, NULL, NULL, init_refs,
+                          MODE_INVALID, NULL, bsize, best_rd_so_far,
                           cpi->sf.winner_mode_sf.multi_winner_mode_type, 0);
   const int64_t top_est_rd =
       inter_modes_info->num > 0
@@ -5280,7 +5914,7 @@
     set_ref_ptrs(cm, xd, mbmi->ref_frame[0], mbmi->ref_frame[1]);
 
     // Select prediction reference frames.
-    const int is_comp_pred = mbmi->ref_frame[1] > INTRA_FRAME;
+    const int is_comp_pred = is_inter_ref_frame(mbmi->ref_frame[1]);
     for (int i = 0; i < num_planes; i++) {
       xd->plane[i].pre[0] = yv12_mb[mbmi->ref_frame[0]][i];
       if (is_comp_pred) xd->plane[i].pre[1] = yv12_mb[mbmi->ref_frame[1]][i];
@@ -5333,19 +5967,19 @@
     }
     rd_stats.rdcost = RDCOST(x->rdmult, rd_stats.rate, rd_stats.dist);
 
-    const THR_MODES mode_enum = get_prediction_mode_idx(
-        mbmi->mode, mbmi->ref_frame[0], mbmi->ref_frame[1]);
+    const MV_REFERENCE_FRAME refs[2] = { mbmi->ref_frame[0],
+                                         mbmi->ref_frame[1] };
 
     // Collect mode stats for multiwinner mode processing
     const int txfm_search_done = 1;
     store_winner_mode_stats(
-        &cpi->common, x, mbmi, &rd_stats, &rd_stats_y, &rd_stats_uv, mode_enum,
-        NULL, bsize, rd_stats.rdcost,
+        &cpi->common, x, mbmi, &rd_stats, &rd_stats_y, &rd_stats_uv, refs,
+        mbmi->mode, NULL, bsize, rd_stats.rdcost,
         cpi->sf.winner_mode_sf.multi_winner_mode_type, txfm_search_done);
 
     if (rd_stats.rdcost < search_state->best_rd) {
       update_search_state(search_state, rd_cost, ctx, &rd_stats, &rd_stats_y,
-                          &rd_stats_uv, mode_enum, x, txfm_search_done);
+                          &rd_stats_uv, mbmi->mode, x, txfm_search_done);
       search_state->best_skip_rd[0] = skip_rd;
     }
   }
@@ -5413,7 +6047,7 @@
   int i;
   const ModeCosts *mode_costs = &x->mode_costs;
   const int *comp_inter_cost =
-      mode_costs->comp_inter_cost[av1_get_reference_mode_context(xd)];
+      mode_costs->comp_inter_cost[av1_get_reference_mode_context(cm, xd)];
 
   InterModeSearchState search_state;
   init_inter_mode_search_state(&search_state, cpi, x, bsize, best_rd_so_far);
@@ -5436,9 +6070,9 @@
     0,
     interintra_modes,
 #if CONFIG_REMOVE_DUAL_FILTER
-    { { 0, { { 0 } }, { 0 }, 0, 0, 0, 0 } },
+    { { 0, { { 0 } }, { 0 }, 0, 0, 0 } },
 #else
-    { { { 0 }, { { 0 } }, { 0 }, 0, 0, 0, 0 } },
+    { { { 0 }, { { 0 } }, { 0 }, 0, 0, 0 } },
 #endif  // CONFIG_REMOVE_DUAL_FILTER
     0
   };
@@ -5497,13 +6131,7 @@
   InterModesInfo *inter_modes_info = x->inter_modes_info;
   inter_modes_info->num = 0;
 
-  int intra_mode_num = 0;
   int num_single_modes_processed = 0;
-  int intra_mode_idx_ls[INTRA_MODES];
-
-  for (i = 0; i < INTRA_MODES; ++i) {
-    intra_mode_idx_ls[i] = i + THR_DC;
-  }
 
   // Temporary buffers used by handle_inter_mode().
   uint8_t *const tmp_buf = get_buf_by_bd(xd, x->tmp_pred_bufs[0]);
@@ -5533,6 +6161,13 @@
     // 'inter_cost_info_from_tpl.best_inter_cost' does not correspond to a
     // pruned ref frame.
     int valid_refs[INTER_REFS_PER_FRAME];
+#if CONFIG_NEW_REF_SIGNALING
+    for (MV_REFERENCE_FRAME frame = 0; frame < INTER_REFS_PER_FRAME; frame++) {
+      const MV_REFERENCE_FRAME refs[2] = { frame, INVALID_IDX };
+      valid_refs[frame] = x->tpl_keep_ref_frame[frame] ||
+                          !prune_ref_by_selective_ref_frame_nrs(cpi, x, refs);
+    }
+#else
     for (MV_REFERENCE_FRAME frame = LAST_FRAME; frame < REF_FRAMES; frame++) {
       const MV_REFERENCE_FRAME refs[2] = { frame, NONE_FRAME };
       valid_refs[frame - 1] =
@@ -5540,6 +6175,7 @@
           !prune_ref_by_selective_ref_frame(
               cpi, x, refs, cm->cur_frame->ref_display_order_hint);
     }
+#endif  // CONFIG_NEW_REF_SIGNALING
     av1_zero(inter_cost_info_from_tpl);
     get_block_level_tpl_stats(cpi, bsize, mi_row, mi_col, valid_refs,
                               &inter_cost_info_from_tpl);
@@ -5580,8 +6216,9 @@
   // Initialize best mode stats for winner mode processing
   av1_zero(x->winner_mode_stats);
   x->winner_mode_count = 0;
-  store_winner_mode_stats(&cpi->common, x, mbmi, NULL, NULL, NULL, THR_INVALID,
-                          NULL, bsize, best_rd_so_far,
+  const MV_REFERENCE_FRAME init_refs[2] = { -1, -1 };
+  store_winner_mode_stats(&cpi->common, x, mbmi, NULL, NULL, NULL, init_refs,
+                          MODE_INVALID, NULL, bsize, best_rd_so_far,
                           cpi->sf.winner_mode_sf.multi_winner_mode_type, 0);
 
   int mode_thresh_mul_fact = (1 << MODE_THRESH_QBITS);
@@ -5597,8 +6234,6 @@
                               skip_ref_frame_mask,
                               0,
                               mode_thresh_mul_fact,
-                              intra_mode_idx_ls,
-                              &intra_mode_num,
                               &num_single_modes_processed,
                               0 };
 
@@ -5609,6 +6244,32 @@
   // with av1_default_mode_order to get the enum that defines the mode, which
   // can be used with av1_mode_defs to get the prediction mode and the ref
   // frames.
+#if CONFIG_NEW_REF_SIGNALING
+  for (PREDICTION_MODE this_mode = 0; this_mode < MB_MODE_COUNT; ++this_mode) {
+    for (MV_REFERENCE_FRAME rf = INVALID_IDX;
+         rf < cm->ref_frames_info.n_total_refs; ++rf) {
+      MV_REFERENCE_FRAME ref_frame = (rf == INVALID_IDX) ? INTRA_FRAME_NRS : rf;
+      if (this_mode < INTRA_MODE_END && ref_frame != INTRA_FRAME_NRS) continue;
+      if (this_mode >= INTRA_MODE_END && ref_frame == INTRA_FRAME_NRS) continue;
+      for (MV_REFERENCE_FRAME second_rf = INVALID_IDX;
+           second_rf < cm->ref_frames_info.n_total_refs; ++second_rf) {
+        MV_REFERENCE_FRAME second_ref_frame = second_rf;
+        if (second_ref_frame != INVALID_IDX &&
+            this_mode < COMP_INTER_MODE_START)
+          continue;
+        if (this_mode >= COMP_INTER_MODE_START &&
+            this_mode < COMP_INTER_MODE_END && second_ref_frame == INVALID_IDX)
+          continue;
+        if (is_inter_ref_frame(second_ref_frame) &&
+            second_ref_frame <= ref_frame)
+          continue;
+
+        const MV_REFERENCE_FRAME ref_frames[2] = { ref_frame,
+                                                   second_ref_frame };
+
+        const int is_single_pred =
+            ref_frame != INTRA_FRAME_NRS && second_ref_frame == INVALID_IDX;
+#else
   for (THR_MODES midx = THR_MODE_START; midx < THR_MODE_END; ++midx) {
     // Get the actual prediction mode we are trying in this iteration
     const THR_MODES mode_enum = av1_default_mode_order[midx];
@@ -5619,109 +6280,143 @@
     const MV_REFERENCE_FRAME ref_frame = ref_frames[0];
     const MV_REFERENCE_FRAME second_ref_frame = ref_frames[1];
     const int is_single_pred =
-        ref_frame > INTRA_FRAME && second_ref_frame == NONE_FRAME;
-    const int comp_pred = second_ref_frame > INTRA_FRAME;
+        is_inter_ref_frame(ref_frame) && second_ref_frame == NONE_FRAME;
+#endif  // CONFIG_NEW_REF_SIGNALING
+        const int comp_pred = is_inter_ref_frame(second_ref_frame);
 
-    init_mbmi(mbmi, this_mode, ref_frames, cm);
+        init_mbmi(mbmi, this_mode, ref_frames, cm);
 
-    txfm_info->skip_txfm = 0;
-    num_single_modes_processed += is_single_pred;
-    set_ref_ptrs(cm, xd, ref_frame, second_ref_frame);
+#if CONFIG_OPTFLOW_REFINEMENT
+        // Optical flow compound modes are only enabled with enable_order_hint
+        // and when prediction is bi-directional
+        if (this_mode > NEW_NEWMV &&
+            (!cm->seq_params.order_hint_info.enable_order_hint ||
+             !has_second_ref(mbmi) || !is_opfl_refine_allowed(cm, mbmi)))
+          continue;
+        // In REFINE_ALL, optical flow refinement has been applied to regular
+        // compound modes.
+        if (cm->features.opfl_refine_type == REFINE_ALL &&
+            (this_mode > NEW_NEWMV || this_mode == GLOBAL_GLOBALMV))
+          continue;
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
-    // Apply speed features to decide if this inter mode can be skipped
-    if (skip_inter_mode(cpi, x, bsize, ref_frame_rd, midx, &sf_args)) continue;
+        txfm_info->skip_txfm = 0;
+        num_single_modes_processed += is_single_pred;
+        set_ref_ptrs(cm, xd, ref_frame, second_ref_frame);
 
-    // Select prediction reference frames.
-    for (i = 0; i < num_planes; i++) {
-      xd->plane[i].pre[0] = yv12_mb[ref_frame][i];
-      if (comp_pred) xd->plane[i].pre[1] = yv12_mb[second_ref_frame][i];
-    }
+        // Apply speed features to decide if this inter mode can be skipped
+        if (skip_inter_mode(cpi, x, bsize, ref_frame_rd,
+#if CONFIG_NEW_REF_SIGNALING
+                            this_mode, ref_frames,
+#else
+                        midx,
+#endif  // CONFIG_NEW_REF_SIGNALING
+                            &sf_args))
+          continue;
 
-    mbmi->angle_delta[PLANE_TYPE_Y] = 0;
-    mbmi->angle_delta[PLANE_TYPE_UV] = 0;
-    mbmi->filter_intra_mode_info.use_filter_intra = 0;
-    mbmi->ref_mv_idx = 0;
+        // Select prediction reference frames.
+        for (i = 0; i < num_planes; i++) {
+          xd->plane[i].pre[0] = yv12_mb[ref_frame][i];
+          if (comp_pred) xd->plane[i].pre[1] = yv12_mb[second_ref_frame][i];
+        }
 
-    const int64_t ref_best_rd = search_state.best_rd;
-    RD_STATS rd_stats, rd_stats_y, rd_stats_uv;
-    av1_init_rd_stats(&rd_stats);
+        mbmi->angle_delta[PLANE_TYPE_Y] = 0;
+        mbmi->angle_delta[PLANE_TYPE_UV] = 0;
+        mbmi->filter_intra_mode_info.use_filter_intra = 0;
+        mbmi->ref_mv_idx = 0;
 
-    const int ref_frame_cost = comp_pred
-                                   ? ref_costs_comp[ref_frame][second_ref_frame]
-                                   : ref_costs_single[ref_frame];
+        const int64_t ref_best_rd = search_state.best_rd;
+        RD_STATS rd_stats, rd_stats_y, rd_stats_uv;
+        av1_init_rd_stats(&rd_stats);
+
+        const int ref_frame_cost =
+            comp_pred ? ref_costs_comp[ref_frame][second_ref_frame]
+                      : ref_costs_single[ref_frame];
 #if CONFIG_SDP
-    const int compmode_cost = is_comp_ref_allowed(mbmi->sb_type[PLANE_TYPE_Y])
-                                  ? comp_inter_cost[comp_pred]
-                                  : 0;
+        const int compmode_cost =
+            is_comp_ref_allowed(mbmi->sb_type[PLANE_TYPE_Y])
+                ? comp_inter_cost[comp_pred]
+                : 0;
 #else
     const int compmode_cost =
         is_comp_ref_allowed(mbmi->sb_type) ? comp_inter_cost[comp_pred] : 0;
 #endif
-    const int real_compmode_cost =
-        cm->current_frame.reference_mode == REFERENCE_MODE_SELECT
-            ? compmode_cost
-            : 0;
-    // Point to variables that are maintained between loop iterations
-    args.single_newmv = search_state.single_newmv;
-    args.single_newmv_rate = search_state.single_newmv_rate;
-    args.single_newmv_valid = search_state.single_newmv_valid;
-    args.single_comp_cost = real_compmode_cost;
-    args.ref_frame_cost = ref_frame_cost;
+        const int real_compmode_cost =
+            cm->current_frame.reference_mode == REFERENCE_MODE_SELECT
+                ? compmode_cost
+                : 0;
+        // Point to variables that are maintained between loop iterations
+        args.single_newmv = search_state.single_newmv;
+        args.single_newmv_rate = search_state.single_newmv_rate;
+        args.single_newmv_valid = search_state.single_newmv_valid;
+        args.single_comp_cost = real_compmode_cost;
+        args.ref_frame_cost = ref_frame_cost;
 
-    int64_t skip_rd[2] = { search_state.best_skip_rd[0],
-                           search_state.best_skip_rd[1] };
-    int64_t this_rd = handle_inter_mode(
-        cpi, tile_data, x, bsize, &rd_stats, &rd_stats_y, &rd_stats_uv, &args,
-        ref_best_rd, tmp_buf, &x->comp_rd_buffer, &best_est_rd, do_tx_search,
-        inter_modes_info, &motion_mode_cand, skip_rd,
-        &inter_cost_info_from_tpl);
+        int64_t skip_rd[2] = { search_state.best_skip_rd[0],
+                               search_state.best_skip_rd[1] };
+        int64_t this_rd = handle_inter_mode(
+            cpi, tile_data, x, bsize, &rd_stats, &rd_stats_y, &rd_stats_uv,
+            &args, ref_best_rd, tmp_buf, &x->comp_rd_buffer, &best_est_rd,
+            do_tx_search, inter_modes_info, &motion_mode_cand, skip_rd,
+            &inter_cost_info_from_tpl);
 
-    if (sf->inter_sf.prune_comp_search_by_single_result > 0 &&
-        is_inter_singleref_mode(this_mode)) {
-      collect_single_states(&cm->features, x, &search_state, mbmi);
-    }
+        if (sf->inter_sf.prune_comp_search_by_single_result > 0 &&
+            is_inter_singleref_mode(this_mode)) {
+          collect_single_states(cm, x, &search_state, mbmi);
+        }
 
-    if (sf->inter_sf.prune_comp_using_best_single_mode_ref > 0 &&
-        is_inter_singleref_mode(this_mode))
-      update_best_single_mode(&search_state, this_mode, ref_frame, this_rd);
+        if (sf->inter_sf.prune_comp_using_best_single_mode_ref > 0 &&
+            is_inter_singleref_mode(this_mode))
+          update_best_single_mode(&search_state, this_mode, ref_frame, this_rd);
 
-    if (this_rd == INT64_MAX) continue;
+        if (this_rd == INT64_MAX) continue;
 #if CONFIG_SDP
-    if (mbmi->skip_txfm[xd->tree_type == CHROMA_PART]) {
+        if (mbmi->skip_txfm[xd->tree_type == CHROMA_PART]) {
 #else
     if (mbmi->skip_txfm) {
 #endif
-      rd_stats_y.rate = 0;
-      rd_stats_uv.rate = 0;
-    }
+          rd_stats_y.rate = 0;
+          rd_stats_uv.rate = 0;
+        }
 
-    if (sf->inter_sf.prune_compound_using_single_ref && is_single_pred &&
-        this_rd < ref_frame_rd[ref_frame]) {
-      ref_frame_rd[ref_frame] = this_rd;
-    }
+        if (sf->inter_sf.prune_compound_using_single_ref && is_single_pred &&
+            this_rd < ref_frame_rd[ref_frame]) {
+          ref_frame_rd[ref_frame] = this_rd;
+        }
 
-    // Did this mode help, i.e., is it the new best mode
-    if (this_rd < search_state.best_rd) {
-      assert(IMPLIES(comp_pred,
-                     cm->current_frame.reference_mode != SINGLE_REFERENCE));
+        // Did this mode help, i.e., is it the new best mode
+        if (this_rd < search_state.best_rd) {
+          assert(IMPLIES(comp_pred,
+                         cm->current_frame.reference_mode != SINGLE_REFERENCE));
+#if CONFIG_NEW_REF_SIGNALING
+          search_state.best_pred_sse =
+              x->pred_sse[COMPACT_INDEX0_NRS(ref_frame)];
+#else
       search_state.best_pred_sse = x->pred_sse[ref_frame];
-      update_search_state(&search_state, rd_cost, ctx, &rd_stats, &rd_stats_y,
-                          &rd_stats_uv, mode_enum, x, do_tx_search);
-      if (do_tx_search) search_state.best_skip_rd[0] = skip_rd[0];
-      search_state.best_skip_rd[1] = skip_rd[1];
-    }
-    if (cpi->sf.winner_mode_sf.motion_mode_for_winner_cand) {
-      // Add this mode to motion mode candidate list for motion mode search
-      // if using motion_mode_for_winner_cand speed feature
-      handle_winner_cand(mbmi, &best_motion_mode_cands,
-                         max_winner_motion_mode_cand, this_rd,
-                         &motion_mode_cand, args.skip_motion_mode);
-    }
+#endif  // CONFIG_NEW_REF_SIGNALING
+          update_search_state(&search_state, rd_cost, ctx, &rd_stats,
+                              &rd_stats_y, &rd_stats_uv, this_mode, x,
+                              do_tx_search);
+          if (do_tx_search) search_state.best_skip_rd[0] = skip_rd[0];
+          search_state.best_skip_rd[1] = skip_rd[1];
+        }
+        if (cpi->sf.winner_mode_sf.motion_mode_for_winner_cand) {
+          // Add this mode to motion mode candidate list for motion mode search
+          // if using motion_mode_for_winner_cand speed feature
+          handle_winner_cand(mbmi, &best_motion_mode_cands,
+                             max_winner_motion_mode_cand, this_rd,
+                             &motion_mode_cand, args.skip_motion_mode);
+        }
 
-    /* keep record of best compound/single-only prediction */
-    record_best_compound(cm->current_frame.reference_mode, &rd_stats, comp_pred,
-                         x->rdmult, &search_state, compmode_cost);
-  }
+        /* keep record of best compound/single-only prediction */
+        record_best_compound(cm->current_frame.reference_mode, &rd_stats,
+                             comp_pred, x->rdmult, &search_state,
+                             compmode_cost);
+#if CONFIG_NEW_REF_SIGNALING
+      }  // end of ref1 loop
+    }    // end of ref0 loop
+#endif   // CONFIG_NEW_REF_SIGNALING
+  }      // end of mode loop
 
   if (cpi->sf.winner_mode_sf.motion_mode_for_winner_cand) {
     // For the single ref winner candidates, evaluate other motion modes (non
@@ -5793,41 +6488,38 @@
     }
   }
 
+#if CONFIG_NEW_REF_SIGNALING
+  const unsigned int intra_ref_frame_cost =
+      ref_costs_single[INTRA_FRAME_INDEX_NRS];
+#else
   const unsigned int intra_ref_frame_cost = ref_costs_single[INTRA_FRAME];
+#endif  // CONFIG_NEW_REF_SIGNALING
   int64_t best_model_rd = INT64_MAX;
   int64_t top_intra_model_rd[TOP_INTRA_MODEL_COUNT];
   for (i = 0; i < TOP_INTRA_MODEL_COUNT; i++) {
     top_intra_model_rd[i] = INT64_MAX;
   }
+#if CONFIG_AIMC
+  get_y_intra_mode_set(mbmi, xd);
+#endif  // CONFIG_AIMC
 #if CONFIG_MRLS
   uint8_t enable_mrls_flag = cm->seq_params.enable_mrls;
   for (int mrl_index = 0; mrl_index < (enable_mrls_flag ? MRL_LINE_NUMBER : 1);
        mrl_index++) {
     mbmi->mrl_index = mrl_index;
 #endif
-
-#if CONFIG_ORIP
-    int total_num_mode = cpi->common.seq_params.enable_orip
-                             ? (LUMA_MODE_COUNT + TOTAL_NUM_ORIP_ANGLE_DELTA)
-                             : LUMA_MODE_COUNT;
-    for (int mode_idx = INTRA_MODE_START; mode_idx < total_num_mode;
+    for (int mode_idx = INTRA_MODE_START; mode_idx < LUMA_MODE_COUNT;
          ++mode_idx) {
-#else
-
-  for (int mode_idx = INTRA_MODE_START; mode_idx < LUMA_MODE_COUNT;
-       ++mode_idx) {
-#endif
       if (sf->intra_sf.skip_intra_in_interframe &&
           search_state.intra_search_state.skip_intra_modes)
         break;
-      set_y_mode_and_delta_angle(mode_idx, mbmi);
-      THR_MODES mode_enum = 0;
-      for (i = 0; i < INTRA_MODE_END; i++) {
-        if (mbmi->mode == av1_mode_defs[intra_mode_idx_ls[i]].mode) {
-          mode_enum = intra_mode_idx_ls[i];
-          break;
-        }
-      }
+#if CONFIG_AIMC
+      mbmi->y_mode_idx = mode_idx;
+      mbmi->joint_y_mode_delta_angle = mbmi->y_intra_mode_list[mode_idx];
+      set_y_mode_and_delta_angle(mbmi->joint_y_mode_delta_angle, mbmi);
+#else
+    set_y_mode_and_delta_angle(mode_idx, mbmi);
+#endif  // CONFIG_AIMC
       if ((!cpi->oxcf.intra_mode_cfg.enable_smooth_intra ||
            cpi->sf.intra_sf.disable_smooth_intra) &&
           (mbmi->mode == SMOOTH_PRED || mbmi->mode == SMOOTH_H_PRED ||
@@ -5836,28 +6528,30 @@
       if (!cpi->oxcf.intra_mode_cfg.enable_paeth_intra &&
           mbmi->mode == PAETH_PRED)
         continue;
+#if !CONFIG_AIMC
       if (av1_is_directional_mode(mbmi->mode) &&
           av1_use_angle_delta(bsize) == 0 &&
           mbmi->angle_delta[PLANE_TYPE_Y] != 0)
         continue;
+#endif  // !CONFIG_AIMC
 #if CONFIG_MRLS
       if (mbmi->mrl_index > 0 && av1_is_directional_mode(mbmi->mode) == 0) {
         continue;
       }
 #endif
-
-#if CONFIG_ORIP
-      int signal_intra_filter = av1_signal_orip_for_horver_modes(
-          &cpi->common, mbmi, PLANE_TYPE_Y, bsize);
-      if (!signal_intra_filter &&
-          mbmi->angle_delta[PLANE_TYPE_Y] == ANGLE_DELTA_VALUE_ORIP)
-        continue;
-#endif
       const PREDICTION_MODE this_mode = mbmi->mode;
 
-      assert(av1_mode_defs[mode_enum].ref_frame[0] == INTRA_FRAME);
-      assert(av1_mode_defs[mode_enum].ref_frame[1] == NONE_FRAME);
-      init_mbmi(mbmi, this_mode, av1_mode_defs[mode_enum].ref_frame, cm);
+#if CONFIG_NEW_REF_SIGNALING
+      MV_REFERENCE_FRAME refs[2] = { INTRA_FRAME_NRS, INVALID_IDX };
+#else
+    THR_MODES mode_enum = mbmi->mode + THR_DC;
+    MV_REFERENCE_FRAME refs[2] = { av1_mode_defs[mode_enum].ref_frame[0],
+                                   av1_mode_defs[mode_enum].ref_frame[1] };
+    assert(av1_mode_defs[mode_enum].ref_frame[0] == INTRA_FRAME);
+    assert(av1_mode_defs[mode_enum].ref_frame[1] == NONE_FRAME);
+#endif  // CONFIG_NEW_REF_SIGNALING
+
+      init_mbmi(mbmi, this_mode, refs, cm);
       txfm_info->skip_txfm = 0;
 
       RD_STATS intra_rd_stats, intra_rd_stats_y, intra_rd_stats_uv;
@@ -5869,13 +6563,14 @@
 
       // Collect mode stats for multiwinner mode processing
       const int txfm_search_done = 1;
-      store_winner_mode_stats(
-          &cpi->common, x, mbmi, &intra_rd_stats, &intra_rd_stats_y,
-          &intra_rd_stats_uv, mode_enum, NULL, bsize, intra_rd_stats.rdcost,
-          cpi->sf.winner_mode_sf.multi_winner_mode_type, txfm_search_done);
+      store_winner_mode_stats(&cpi->common, x, mbmi, &intra_rd_stats,
+                              &intra_rd_stats_y, &intra_rd_stats_uv, refs,
+                              this_mode, NULL, bsize, intra_rd_stats.rdcost,
+                              cpi->sf.winner_mode_sf.multi_winner_mode_type,
+                              txfm_search_done);
       if (intra_rd_stats.rdcost < search_state.best_rd) {
         update_search_state(&search_state, rd_cost, ctx, &intra_rd_stats,
-                            &intra_rd_stats_y, &intra_rd_stats_uv, mode_enum, x,
+                            &intra_rd_stats_y, &intra_rd_stats_uv, this_mode, x,
                             txfm_search_done);
       }
     }
@@ -5889,10 +6584,10 @@
   int winner_mode_count =
       cpi->sf.winner_mode_sf.multi_winner_mode_type ? x->winner_mode_count : 1;
   // In effect only when fast tx search speed features are enabled.
-  refine_winner_mode_tx(
-      cpi, x, rd_cost, bsize, ctx, &search_state.best_mode_index,
-      &search_state.best_mbmode, yv12_mb, search_state.best_rate_y,
-      search_state.best_rate_uv, &search_state.best_skip2, winner_mode_count);
+  refine_winner_mode_tx(cpi, x, rd_cost, bsize, ctx, &search_state.best_mbmode,
+                        yv12_mb, search_state.best_rate_y,
+                        search_state.best_rate_uv, &search_state.best_skip2,
+                        winner_mode_count);
 
   // Initialize default mode evaluation params
   set_mode_eval_params(cpi, x, DEFAULT_EVAL);
@@ -5917,7 +6612,6 @@
         &search_state.intra_search_state, cpi, x, bsize, intra_ref_frame_cost,
         ctx, &this_rd_cost, search_state.best_rd);
     if (this_rd_cost.rdcost < search_state.best_rd) {
-      search_state.best_mode_index = THR_DC;
       mbmi->mv[0].as_int = 0;
       rd_cost->rate = this_rd_cost.rate;
       rd_cost->dist = this_rd_cost.dist;
@@ -5935,11 +6629,15 @@
   search_state.best_mbmode.skip_mode = 0;
   if (cm->current_frame.skip_mode_info.skip_mode_flag &&
       is_comp_ref_allowed(bsize)) {
+#if CONFIG_NEW_REF_SIGNALING
+    rd_pick_skip_mode(rd_cost, &search_state, cpi, x, bsize, yv12_mb);
+#else
     const struct segmentation *const seg = &cm->seg;
     unsigned char segment_id = mbmi->segment_id;
     if (!segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME)) {
       rd_pick_skip_mode(rd_cost, &search_state, cpi, x, bsize, yv12_mb);
     }
+#endif  // CONFIG_NEW_REF_SIGNALING
   }
 
   // Make sure that the ref_mv_idx is only nonzero when we're
@@ -5947,11 +6645,14 @@
   if (search_state.best_mbmode.ref_mv_idx != 0 &&
       !(search_state.best_mbmode.mode == NEWMV ||
         search_state.best_mbmode.mode == NEW_NEWMV ||
+#if CONFIG_OPTFLOW_REFINEMENT
+        search_state.best_mbmode.mode == NEW_NEWMV_OPTFLOW ||
+#endif  // CONFIG_OPTFLOW_REFINEMENT
         have_nearmv_in_inter_mode(search_state.best_mbmode.mode))) {
     search_state.best_mbmode.ref_mv_idx = 0;
   }
 
-  if (search_state.best_mode_index == THR_INVALID ||
+  if (search_state.best_mbmode.mode == MODE_INVALID ||
       search_state.best_rd >= best_rd_so_far) {
     rd_cost->rate = INT_MAX;
     rd_cost->rdcost = INT64_MAX;
@@ -5995,7 +6696,10 @@
   if (!cpi->rc.is_src_frame_alt_ref && cpi->sf.inter_sf.adaptive_rd_thresh) {
     av1_update_rd_thresh_fact(cm, x->thresh_freq_fact,
                               sf->inter_sf.adaptive_rd_thresh, bsize,
-                              search_state.best_mode_index);
+#if !CONFIG_NEW_REF_SIGNALING
+                              search_state.best_mbmode.ref_frame,
+#endif  // !CONFIG_NEW_REF_SIGNALING
+                              search_state.best_mbmode.mode);
   }
   // macroblock modes
   *mbmi = search_state.best_mbmode;
@@ -6031,16 +6735,18 @@
 
   txfm_info->skip_txfm |= search_state.best_mode_skippable;
 
-  assert(search_state.best_mode_index != THR_INVALID);
+  assert(search_state.best_mbmode.mode != MODE_INVALID);
 
-#if CONFIG_INTERNAL_STATS
-  store_coding_context(x, ctx, search_state.best_mode_index,
-                       search_state.best_pred_diff,
+#if CONFIG_INTERNAL_STATS && !CONFIG_NEW_REF_SIGNALING
+  const THR_MODES best_mode_enum = get_prediction_mode_idx(
+      search_state.best_mbmode.mode, search_state.best_mbmode.ref_frame[0],
+      search_state.best_mbmode.ref_frame[1]);
+  store_coding_context(x, ctx, best_mode_enum, search_state.best_pred_diff,
                        search_state.best_mode_skippable);
 #else
   store_coding_context(x, ctx, search_state.best_pred_diff,
                        search_state.best_mode_skippable);
-#endif  // CONFIG_INTERNAL_STATS
+#endif  // CONFIG_INTERNAL_STATS && !CONFIG_NEW_REF_SIGNALING
 
   if (mbmi->palette_mode_info.palette_size[1] > 0) {
     assert(try_palette);
@@ -6066,7 +6772,7 @@
   unsigned int ref_costs_comp[REF_FRAMES][REF_FRAMES];
   const ModeCosts *mode_costs = &x->mode_costs;
   const int *comp_inter_cost =
-      mode_costs->comp_inter_cost[av1_get_reference_mode_context(xd)];
+      mode_costs->comp_inter_cost[av1_get_reference_mode_context(cm, xd)];
   InterpFilter best_filter = SWITCHABLE;
   int64_t this_rd = INT64_MAX;
   int rate2 = 0;
@@ -6081,7 +6787,11 @@
                            ref_costs_comp);
 
   for (i = 0; i < REF_FRAMES; ++i) x->pred_sse[i] = INT_MAX;
+#if CONFIG_NEW_REF_SIGNALING
+  for (i = 0; i < REF_FRAMES; ++i) x->pred_mv_sad[i] = INT_MAX;
+#else
   for (i = LAST_FRAME; i < REF_FRAMES; ++i) x->pred_mv_sad[i] = INT_MAX;
+#endif  // CONFIG_NEW_REF_SIGNALING
 
   rd_cost->rate = INT_MAX;
 
@@ -6093,11 +6803,17 @@
   mbmi->mode = GLOBALMV;
   mbmi->motion_mode = SIMPLE_TRANSLATION;
   mbmi->uv_mode = UV_DC_PRED;
+#if CONFIG_NEW_REF_SIGNALING
+  const MV_REFERENCE_FRAME last_frame = get_closest_pastcur_ref_index(cm);
+  mbmi->ref_frame[0] = last_frame;
+  mbmi->ref_frame[1] = INVALID_IDX;
+#else
   if (segfeature_active(&cm->seg, segment_id, SEG_LVL_REF_FRAME))
     mbmi->ref_frame[0] = get_segdata(&cm->seg, segment_id, SEG_LVL_REF_FRAME);
   else
     mbmi->ref_frame[0] = LAST_FRAME;
   mbmi->ref_frame[1] = NONE_FRAME;
+#endif  // CONFIG_NEW_REF_SIGNALING
   mbmi->mv[0].as_int =
       gm_get_motion_vector(&cm->global_motion[mbmi->ref_frame[0]],
                            features->allow_high_precision_mv, bsize, mi_col,
@@ -6120,13 +6836,17 @@
   }
 
   const InterpFilter interp_filter = features->interp_filter;
-  set_default_interp_filters(mbmi, interp_filter);
+  set_default_interp_filters(mbmi,
+#if CONFIG_OPTFLOW_REFINEMENT
+                             cm,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
+                             interp_filter);
 
   if (interp_filter != SWITCHABLE) {
     best_filter = interp_filter;
   } else {
     best_filter = EIGHTTAP_REGULAR;
-    if (av1_is_interp_needed(xd)) {
+    if (av1_is_interp_needed(cm, xd)) {
       int rs;
       int best_rs = INT_MAX;
       for (i = 0; i < SWITCHABLE_FILTERS; ++i) {
@@ -6162,9 +6882,13 @@
   if (cm->current_frame.reference_mode == REFERENCE_MODE_SELECT)
     rate2 += comp_inter_cost[comp_pred];
 
-  // Estimate the reference frame signaling cost and add it
-  // to the rolling cost variable.
+    // Estimate the reference frame signaling cost and add it
+    // to the rolling cost variable.
+#if CONFIG_NEW_REF_SIGNALING
+  rate2 += ref_costs_single[last_frame];
+#else
   rate2 += ref_costs_single[LAST_FRAME];
+#endif  // CONFIG_NEW_REF_SIGNALING
   this_rd = RDCOST(x->rdmult, rate2, distortion2);
 
   rd_cost->rate = rate2;
@@ -6185,18 +6909,24 @@
 #endif  // CONFIG_REMOVE_DUAL_FILTER
 
   if (cpi->sf.inter_sf.adaptive_rd_thresh) {
+#if !CONFIG_NEW_REF_SIGNALING
+    MV_REFERENCE_FRAME global_mv_refs[2] = { LAST_FRAME, INTRA_FRAME };
+#endif  // !CONFIG_NEW_REF_SIGNALING
     av1_update_rd_thresh_fact(cm, x->thresh_freq_fact,
                               cpi->sf.inter_sf.adaptive_rd_thresh, bsize,
-                              THR_GLOBALMV);
+#if !CONFIG_NEW_REF_SIGNALING
+                              global_mv_refs,
+#endif  // !CONFIG_NEW_REF_SIGNALING
+                              GLOBALMV);
   }
 
   av1_zero(best_pred_diff);
 
-#if CONFIG_INTERNAL_STATS
+#if CONFIG_INTERNAL_STATS && !CONFIG_NEW_REF_SIGNALING
   store_coding_context(x, ctx, THR_GLOBALMV, best_pred_diff, 0);
 #else
   store_coding_context(x, ctx, best_pred_diff, 0);
-#endif  // CONFIG_INTERNAL_STATS
+#endif  // CONFIG_INTERNAL_STATS && !CONFIG_NEW_REF_SIGNALING
 }
 
 /*!\cond */
diff --git a/av1/encoder/rdopt.h b/av1/encoder/rdopt.h
index c9b81f4..2400ad4 100644
--- a/av1/encoder/rdopt.h
+++ b/av1/encoder/rdopt.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_RDOPT_H_
@@ -176,6 +177,91 @@
          USABLE_REF_MV_STACK_SIZE * sizeof(xd->ref_mv_stack[0][0]));
 }
 
+#if CONFIG_NEW_REF_SIGNALING
+static INLINE int prune_ref_by_selective_ref_frame_nrs(
+    const AV1_COMP *const cpi, const MACROBLOCK *const x,
+    const MV_REFERENCE_FRAME *const ref_frame) {
+  (void)x;
+  const AV1_COMMON *const cm = &cpi->common;
+  const SPEED_FEATURES *const sf = &cpi->sf;
+
+  if (!sf->inter_sf.selective_ref_frame) return 0;
+  assert(ref_frame[0] != INVALID_IDX);
+  if (ref_frame[0] == INTRA_FRAME_NRS) return 0;
+
+  const int comp_pred = is_inter_ref_frame(ref_frame[1]);
+
+  if (x != NULL) {
+    const int n_refs = cm->ref_frames_info.n_total_refs;
+    if (sf->inter_sf.selective_ref_frame >= 2 ||
+        (sf->inter_sf.selective_ref_frame == 1 && comp_pred)) {
+      if ((n_refs - 1) >= 0 && x->tpl_keep_ref_frame[n_refs - 1] &&
+          (ref_frame[0] == (n_refs - 1) || ref_frame[1] == (n_refs - 1)))
+        return 0;
+      if ((n_refs - 2) >= 0 && x->tpl_keep_ref_frame[n_refs - 2] &&
+          (ref_frame[0] == (n_refs - 2) || ref_frame[1] == (n_refs - 2)))
+        return 0;
+    }
+    if (sf->inter_sf.selective_ref_frame >= 3) {
+      if ((n_refs - 3) >= 0 && x->tpl_keep_ref_frame[n_refs - 3] &&
+          (ref_frame[0] == (n_refs - 3) || ref_frame[1] == (n_refs - 3)))
+        return 0;
+      if ((n_refs - 4) >= 0 && x->tpl_keep_ref_frame[n_refs - 4] &&
+          (ref_frame[0] == (n_refs - 4) || ref_frame[1] == (n_refs - 4)))
+        return 0;
+    }
+  }
+
+  int dir_refrank[2][2] = { { -1, -1 }, { -1, -1 } };
+  int d0 = get_dir_rank(cm, ref_frame[0], dir_refrank[0]);
+  assert(d0 != -1);
+  int d1 = -1;
+  if (comp_pred) {
+    d1 = get_dir_rank(cm, ref_frame[1], dir_refrank[1]);
+    assert(d1 != -1);
+  }
+  const int one_sided_comp = (d0 == d1);
+
+  switch (sf->inter_sf.selective_ref_frame) {
+    case 0: return 0;
+    case 1:
+      if (comp_pred) {
+        if (one_sided_comp) {
+          if (AOMMIN(dir_refrank[0][d0], dir_refrank[1][d1]) > 1) return 1;
+        } else {
+          if (AOMMIN(dir_refrank[0][d0], dir_refrank[1][d1]) > 2) return 1;
+        }
+      } else {
+        if (dir_refrank[0][d0] > INTER_REFS_PER_FRAME - 2) return 1;
+      }
+      break;
+    case 2:
+      if (comp_pred) {
+        if (one_sided_comp) {
+          if (AOMMIN(dir_refrank[0][d0], dir_refrank[1][d1]) > 0) return 1;
+        } else {
+          if (AOMMIN(dir_refrank[0][d0], dir_refrank[1][d1]) > 1) return 1;
+        }
+      } else {
+        if (dir_refrank[0][d0] > INTER_REFS_PER_FRAME - 3) return 1;
+      }
+      break;
+    case 3:
+    default:
+      if (comp_pred) {
+        if (one_sided_comp) {
+          if (AOMMIN(dir_refrank[0][d0], dir_refrank[1][d1]) > 0) return 1;
+        } else {
+          if (AOMMIN(dir_refrank[0][d0], dir_refrank[1][d1]) > 0) return 1;
+        }
+      } else {
+        if (dir_refrank[0][d0] > INTER_REFS_PER_FRAME - 4) return 1;
+      }
+      break;
+  }
+  return 0;
+}
+#else
 // This function prunes the mode if either of the reference frame falls in the
 // pruning list
 static INLINE int prune_ref(const MV_REFERENCE_FRAME *const ref_frame,
@@ -203,7 +289,7 @@
   const SPEED_FEATURES *const sf = &cpi->sf;
   if (!sf->inter_sf.selective_ref_frame) return 0;
 
-  const int comp_pred = ref_frame[1] > INTRA_FRAME;
+  const int comp_pred = is_inter_ref_frame(ref_frame[1]);
 
   if (sf->inter_sf.selective_ref_frame >= 2 ||
       (sf->inter_sf.selective_ref_frame == 1 && comp_pred)) {
@@ -236,6 +322,7 @@
 
   return 0;
 }
+#endif  // CONFIG_NEW_REF_SIGNALING
 
 // This function will copy the best reference mode information from
 // MB_MODE_INFO_EXT to MB_MODE_INFO_EXT_FRAME.
diff --git a/av1/encoder/rdopt_data_defs.h b/av1/encoder/rdopt_data_defs.h
index 995c213..7395852 100644
--- a/av1/encoder/rdopt_data_defs.h
+++ b/av1/encoder/rdopt_data_defs.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2019, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_RDOPT_DATA_DEFS_H_
@@ -291,6 +292,104 @@
             { THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID,
             THR_INVALID, THR_INVALID, THR_INVALID, },
         },
+#if CONFIG_OPTFLOW_REFINEMENT
+        // NEAR_NEARMV_OPTFLOW,
+        {
+            { THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID,
+              THR_INVALID, THR_INVALID, THR_INVALID, },
+            { THR_INVALID, THR_INVALID, THR_COMP_NEAR_NEAR_OPTFLOWLL2,
+              THR_COMP_NEAR_NEAR_OPTFLOWLL3, THR_COMP_NEAR_NEAR_OPTFLOWLG,
+              THR_COMP_NEAR_NEAR_OPTFLOWLB, THR_COMP_NEAR_NEAR_OPTFLOWLA2,
+              THR_COMP_NEAR_NEAR_OPTFLOWLA, },
+            { THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID,
+              THR_COMP_NEAR_NEAR_OPTFLOWL2B, THR_COMP_NEAR_NEAR_OPTFLOWL2A2,
+              THR_COMP_NEAR_NEAR_OPTFLOWL2A, },
+            { THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID,
+              THR_COMP_NEAR_NEAR_OPTFLOWL3B, THR_COMP_NEAR_NEAR_OPTFLOWL3A2,
+              THR_COMP_NEAR_NEAR_OPTFLOWL3A, },
+            { THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID,
+              THR_COMP_NEAR_NEAR_OPTFLOWGB, THR_COMP_NEAR_NEAR_OPTFLOWGA2,
+              THR_COMP_NEAR_NEAR_OPTFLOWGA, },
+            { THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID,
+              THR_INVALID, THR_INVALID, THR_COMP_NEAR_NEAR_OPTFLOWBA, },
+            { THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID,
+              THR_INVALID, THR_INVALID, THR_INVALID, },
+            { THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID,
+              THR_INVALID, THR_INVALID, THR_INVALID, },
+        },
+        // NEAR_NEWMV_OPTFLOW,
+        {
+            { THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID,
+              THR_INVALID, THR_INVALID, THR_INVALID, },
+            { THR_INVALID, THR_INVALID, THR_COMP_NEAR_NEW_OPTFLOWLL2,
+              THR_COMP_NEAR_NEW_OPTFLOWLL3, THR_COMP_NEAR_NEW_OPTFLOWLG,
+              THR_COMP_NEAR_NEW_OPTFLOWLB, THR_COMP_NEAR_NEW_OPTFLOWLA2,
+              THR_COMP_NEAR_NEW_OPTFLOWLA, },
+            { THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID,
+              THR_COMP_NEAR_NEW_OPTFLOWL2B, THR_COMP_NEAR_NEW_OPTFLOWL2A2,
+              THR_COMP_NEAR_NEW_OPTFLOWL2A, },
+            { THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID,
+              THR_COMP_NEAR_NEW_OPTFLOWL3B, THR_COMP_NEAR_NEW_OPTFLOWL3A2,
+              THR_COMP_NEAR_NEW_OPTFLOWL3A, },
+            { THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID,
+              THR_COMP_NEAR_NEW_OPTFLOWGB, THR_COMP_NEAR_NEW_OPTFLOWGA2,
+              THR_COMP_NEAR_NEW_OPTFLOWGA, },
+            { THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID,
+              THR_INVALID, THR_INVALID, THR_COMP_NEAR_NEW_OPTFLOWBA, },
+            { THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID,
+              THR_INVALID, THR_INVALID, THR_INVALID, },
+            { THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID,
+              THR_INVALID, THR_INVALID, THR_INVALID, },
+        },
+        // NEW_NEARMV_OPTFLOW,
+        {
+            { THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID,
+              THR_INVALID, THR_INVALID, THR_INVALID, },
+            { THR_INVALID, THR_INVALID, THR_COMP_NEW_NEAR_OPTFLOWLL2,
+              THR_COMP_NEW_NEAR_OPTFLOWLL3, THR_COMP_NEW_NEAR_OPTFLOWLG,
+              THR_COMP_NEW_NEAR_OPTFLOWLB, THR_COMP_NEW_NEAR_OPTFLOWLA2,
+              THR_COMP_NEW_NEAR_OPTFLOWLA, },
+            { THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID,
+              THR_COMP_NEW_NEAR_OPTFLOWL2B, THR_COMP_NEW_NEAR_OPTFLOWL2A2,
+              THR_COMP_NEW_NEAR_OPTFLOWL2A, },
+            { THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID,
+              THR_COMP_NEW_NEAR_OPTFLOWL3B, THR_COMP_NEW_NEAR_OPTFLOWL3A2,
+              THR_COMP_NEW_NEAR_OPTFLOWL3A, },
+            { THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID,
+              THR_COMP_NEW_NEAR_OPTFLOWGB, THR_COMP_NEW_NEAR_OPTFLOWGA2,
+              THR_COMP_NEW_NEAR_OPTFLOWGA, },
+            { THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID,
+              THR_INVALID, THR_INVALID, THR_COMP_NEW_NEAR_OPTFLOWBA, },
+            { THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID,
+              THR_INVALID, THR_INVALID, THR_INVALID, },
+            { THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID,
+              THR_INVALID, THR_INVALID, THR_INVALID, },
+        },
+        // NEW_NEWMV_OPTFLOW,
+        {
+            { THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID,
+              THR_INVALID, THR_INVALID, THR_INVALID, },
+            { THR_INVALID, THR_INVALID, THR_COMP_NEW_NEW_OPTFLOWLL2,
+              THR_COMP_NEW_NEW_OPTFLOWLL3, THR_COMP_NEW_NEW_OPTFLOWLG,
+              THR_COMP_NEW_NEW_OPTFLOWLB, THR_COMP_NEW_NEW_OPTFLOWLA2,
+              THR_COMP_NEW_NEW_OPTFLOWLA, },
+            { THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID,
+              THR_COMP_NEW_NEW_OPTFLOWL2B, THR_COMP_NEW_NEW_OPTFLOWL2A2,
+              THR_COMP_NEW_NEW_OPTFLOWL2A, },
+            { THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID,
+              THR_COMP_NEW_NEW_OPTFLOWL3B, THR_COMP_NEW_NEW_OPTFLOWL3A2,
+              THR_COMP_NEW_NEW_OPTFLOWL3A, },
+            { THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID,
+              THR_COMP_NEW_NEW_OPTFLOWGB, THR_COMP_NEW_NEW_OPTFLOWGA2,
+              THR_COMP_NEW_NEW_OPTFLOWGA, },
+            { THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID,
+              THR_INVALID, THR_INVALID, THR_COMP_NEW_NEW_OPTFLOWBA, },
+            { THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID,
+              THR_INVALID, THR_INVALID, THR_INVALID, },
+            { THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID, THR_INVALID,
+              THR_INVALID, THR_INVALID, THR_INVALID, },
+        },
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 };
 
 #ifdef __cplusplus
diff --git a/av1/encoder/rdopt_utils.h b/av1/encoder/rdopt_utils.h
index ed44e4a..090b57e 100644
--- a/av1/encoder/rdopt_utils.h
+++ b/av1/encoder/rdopt_utils.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2019, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_RDOPT_UTILS_H_
@@ -16,7 +17,9 @@
 #include "av1/encoder/block.h"
 #include "av1/common/cfl.h"
 #include "av1/common/pred_common.h"
+#if !CONFIG_NEW_REF_SIGNALING
 #include "av1/encoder/rdopt_data_defs.h"
+#endif  // !CONFIG_NEW_REF_SIGNALING
 
 #ifdef __cplusplus
 extern "C" {
@@ -35,6 +38,7 @@
   MV_REFERENCE_FRAME ref_frame[2];
 } MODE_DEFINITION;
 
+#if !CONFIG_NEW_REF_SIGNALING
 // This array defines the mapping from the enums in THR_MODES to the actual
 // prediction modes and refrence frames
 #if CONFIG_NEW_INTER_MODES
@@ -86,81 +90,177 @@
   { NEAR_NEWMV, { LAST_FRAME, ALTREF_FRAME } },
   { NEW_NEWMV, { LAST_FRAME, ALTREF_FRAME } },
   { GLOBAL_GLOBALMV, { LAST_FRAME, ALTREF_FRAME } },
+#if CONFIG_OPTFLOW_REFINEMENT
+  { NEAR_NEARMV_OPTFLOW, { LAST_FRAME, ALTREF_FRAME } },
+  { NEAR_NEWMV_OPTFLOW, { LAST_FRAME, ALTREF_FRAME } },
+  { NEW_NEARMV_OPTFLOW, { LAST_FRAME, ALTREF_FRAME } },
+  { NEW_NEWMV_OPTFLOW, { LAST_FRAME, ALTREF_FRAME } },
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   { NEW_NEARMV, { LAST2_FRAME, ALTREF_FRAME } },
   { NEAR_NEWMV, { LAST2_FRAME, ALTREF_FRAME } },
   { NEW_NEWMV, { LAST2_FRAME, ALTREF_FRAME } },
   { GLOBAL_GLOBALMV, { LAST2_FRAME, ALTREF_FRAME } },
+#if CONFIG_OPTFLOW_REFINEMENT
+  { NEAR_NEARMV_OPTFLOW, { LAST2_FRAME, ALTREF_FRAME } },
+  { NEAR_NEWMV_OPTFLOW, { LAST2_FRAME, ALTREF_FRAME } },
+  { NEW_NEARMV_OPTFLOW, { LAST2_FRAME, ALTREF_FRAME } },
+  { NEW_NEWMV_OPTFLOW, { LAST2_FRAME, ALTREF_FRAME } },
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   { NEW_NEARMV, { LAST3_FRAME, ALTREF_FRAME } },
   { NEAR_NEWMV, { LAST3_FRAME, ALTREF_FRAME } },
   { NEW_NEWMV, { LAST3_FRAME, ALTREF_FRAME } },
   { GLOBAL_GLOBALMV, { LAST3_FRAME, ALTREF_FRAME } },
+#if CONFIG_OPTFLOW_REFINEMENT
+  { NEAR_NEARMV_OPTFLOW, { LAST3_FRAME, ALTREF_FRAME } },
+  { NEAR_NEWMV_OPTFLOW, { LAST3_FRAME, ALTREF_FRAME } },
+  { NEW_NEARMV_OPTFLOW, { LAST3_FRAME, ALTREF_FRAME } },
+  { NEW_NEWMV_OPTFLOW, { LAST3_FRAME, ALTREF_FRAME } },
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   { NEW_NEARMV, { GOLDEN_FRAME, ALTREF_FRAME } },
   { NEAR_NEWMV, { GOLDEN_FRAME, ALTREF_FRAME } },
   { NEW_NEWMV, { GOLDEN_FRAME, ALTREF_FRAME } },
   { GLOBAL_GLOBALMV, { GOLDEN_FRAME, ALTREF_FRAME } },
+#if CONFIG_OPTFLOW_REFINEMENT
+  { NEAR_NEARMV_OPTFLOW, { GOLDEN_FRAME, ALTREF_FRAME } },
+  { NEAR_NEWMV_OPTFLOW, { GOLDEN_FRAME, ALTREF_FRAME } },
+  { NEW_NEARMV_OPTFLOW, { GOLDEN_FRAME, ALTREF_FRAME } },
+  { NEW_NEWMV_OPTFLOW, { GOLDEN_FRAME, ALTREF_FRAME } },
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   { NEW_NEARMV, { LAST_FRAME, BWDREF_FRAME } },
   { NEAR_NEWMV, { LAST_FRAME, BWDREF_FRAME } },
   { NEW_NEWMV, { LAST_FRAME, BWDREF_FRAME } },
   { GLOBAL_GLOBALMV, { LAST_FRAME, BWDREF_FRAME } },
+#if CONFIG_OPTFLOW_REFINEMENT
+  { NEAR_NEARMV_OPTFLOW, { LAST_FRAME, BWDREF_FRAME } },
+  { NEAR_NEWMV_OPTFLOW, { LAST_FRAME, BWDREF_FRAME } },
+  { NEW_NEARMV_OPTFLOW, { LAST_FRAME, BWDREF_FRAME } },
+  { NEW_NEWMV_OPTFLOW, { LAST_FRAME, BWDREF_FRAME } },
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   { NEW_NEARMV, { LAST2_FRAME, BWDREF_FRAME } },
   { NEAR_NEWMV, { LAST2_FRAME, BWDREF_FRAME } },
   { NEW_NEWMV, { LAST2_FRAME, BWDREF_FRAME } },
   { GLOBAL_GLOBALMV, { LAST2_FRAME, BWDREF_FRAME } },
+#if CONFIG_OPTFLOW_REFINEMENT
+  { NEAR_NEARMV_OPTFLOW, { LAST2_FRAME, BWDREF_FRAME } },
+  { NEAR_NEWMV_OPTFLOW, { LAST2_FRAME, BWDREF_FRAME } },
+  { NEW_NEARMV_OPTFLOW, { LAST2_FRAME, BWDREF_FRAME } },
+  { NEW_NEWMV_OPTFLOW, { LAST2_FRAME, BWDREF_FRAME } },
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   { NEW_NEARMV, { LAST3_FRAME, BWDREF_FRAME } },
   { NEAR_NEWMV, { LAST3_FRAME, BWDREF_FRAME } },
   { NEW_NEWMV, { LAST3_FRAME, BWDREF_FRAME } },
   { GLOBAL_GLOBALMV, { LAST3_FRAME, BWDREF_FRAME } },
+#if CONFIG_OPTFLOW_REFINEMENT
+  { NEAR_NEARMV_OPTFLOW, { LAST3_FRAME, BWDREF_FRAME } },
+  { NEAR_NEWMV_OPTFLOW, { LAST3_FRAME, BWDREF_FRAME } },
+  { NEW_NEARMV_OPTFLOW, { LAST3_FRAME, BWDREF_FRAME } },
+  { NEW_NEWMV_OPTFLOW, { LAST3_FRAME, BWDREF_FRAME } },
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   { NEW_NEARMV, { GOLDEN_FRAME, BWDREF_FRAME } },
   { NEAR_NEWMV, { GOLDEN_FRAME, BWDREF_FRAME } },
   { NEW_NEWMV, { GOLDEN_FRAME, BWDREF_FRAME } },
   { GLOBAL_GLOBALMV, { GOLDEN_FRAME, BWDREF_FRAME } },
+#if CONFIG_OPTFLOW_REFINEMENT
+  { NEAR_NEARMV_OPTFLOW, { GOLDEN_FRAME, BWDREF_FRAME } },
+  { NEAR_NEWMV_OPTFLOW, { GOLDEN_FRAME, BWDREF_FRAME } },
+  { NEW_NEARMV_OPTFLOW, { GOLDEN_FRAME, BWDREF_FRAME } },
+  { NEW_NEWMV_OPTFLOW, { GOLDEN_FRAME, BWDREF_FRAME } },
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   { NEW_NEARMV, { LAST_FRAME, ALTREF2_FRAME } },
   { NEAR_NEWMV, { LAST_FRAME, ALTREF2_FRAME } },
   { NEW_NEWMV, { LAST_FRAME, ALTREF2_FRAME } },
   { GLOBAL_GLOBALMV, { LAST_FRAME, ALTREF2_FRAME } },
+#if CONFIG_OPTFLOW_REFINEMENT
+  { NEAR_NEARMV_OPTFLOW, { LAST_FRAME, ALTREF2_FRAME } },
+  { NEAR_NEWMV_OPTFLOW, { LAST_FRAME, ALTREF2_FRAME } },
+  { NEW_NEARMV_OPTFLOW, { LAST_FRAME, ALTREF2_FRAME } },
+  { NEW_NEWMV_OPTFLOW, { LAST_FRAME, ALTREF2_FRAME } },
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   { NEW_NEARMV, { LAST2_FRAME, ALTREF2_FRAME } },
   { NEAR_NEWMV, { LAST2_FRAME, ALTREF2_FRAME } },
   { NEW_NEWMV, { LAST2_FRAME, ALTREF2_FRAME } },
   { GLOBAL_GLOBALMV, { LAST2_FRAME, ALTREF2_FRAME } },
+#if CONFIG_OPTFLOW_REFINEMENT
+  { NEAR_NEARMV_OPTFLOW, { LAST2_FRAME, ALTREF2_FRAME } },
+  { NEAR_NEWMV_OPTFLOW, { LAST2_FRAME, ALTREF2_FRAME } },
+  { NEW_NEARMV_OPTFLOW, { LAST2_FRAME, ALTREF2_FRAME } },
+  { NEW_NEWMV_OPTFLOW, { LAST2_FRAME, ALTREF2_FRAME } },
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   { NEW_NEARMV, { LAST3_FRAME, ALTREF2_FRAME } },
   { NEAR_NEWMV, { LAST3_FRAME, ALTREF2_FRAME } },
   { NEW_NEWMV, { LAST3_FRAME, ALTREF2_FRAME } },
   { GLOBAL_GLOBALMV, { LAST3_FRAME, ALTREF2_FRAME } },
+#if CONFIG_OPTFLOW_REFINEMENT
+  { NEAR_NEARMV_OPTFLOW, { LAST3_FRAME, ALTREF2_FRAME } },
+  { NEAR_NEWMV_OPTFLOW, { LAST3_FRAME, ALTREF2_FRAME } },
+  { NEW_NEARMV_OPTFLOW, { LAST3_FRAME, ALTREF2_FRAME } },
+  { NEW_NEWMV_OPTFLOW, { LAST3_FRAME, ALTREF2_FRAME } },
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   { NEW_NEARMV, { GOLDEN_FRAME, ALTREF2_FRAME } },
   { NEAR_NEWMV, { GOLDEN_FRAME, ALTREF2_FRAME } },
   { NEW_NEWMV, { GOLDEN_FRAME, ALTREF2_FRAME } },
   { GLOBAL_GLOBALMV, { GOLDEN_FRAME, ALTREF2_FRAME } },
+#if CONFIG_OPTFLOW_REFINEMENT
+  { NEAR_NEARMV_OPTFLOW, { GOLDEN_FRAME, ALTREF2_FRAME } },
+  { NEAR_NEWMV_OPTFLOW, { GOLDEN_FRAME, ALTREF2_FRAME } },
+  { NEW_NEARMV_OPTFLOW, { GOLDEN_FRAME, ALTREF2_FRAME } },
+  { NEW_NEWMV_OPTFLOW, { GOLDEN_FRAME, ALTREF2_FRAME } },
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   { NEW_NEARMV, { LAST_FRAME, LAST2_FRAME } },
   { NEAR_NEWMV, { LAST_FRAME, LAST2_FRAME } },
   { NEW_NEWMV, { LAST_FRAME, LAST2_FRAME } },
   { GLOBAL_GLOBALMV, { LAST_FRAME, LAST2_FRAME } },
+#if CONFIG_OPTFLOW_REFINEMENT
+  { NEAR_NEARMV_OPTFLOW, { LAST_FRAME, LAST2_FRAME } },
+  { NEAR_NEWMV_OPTFLOW, { LAST_FRAME, LAST2_FRAME } },
+  { NEW_NEARMV_OPTFLOW, { LAST_FRAME, LAST2_FRAME } },
+  { NEW_NEWMV_OPTFLOW, { LAST_FRAME, LAST2_FRAME } },
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   { NEW_NEARMV, { LAST_FRAME, LAST3_FRAME } },
   { NEAR_NEWMV, { LAST_FRAME, LAST3_FRAME } },
   { NEW_NEWMV, { LAST_FRAME, LAST3_FRAME } },
   { GLOBAL_GLOBALMV, { LAST_FRAME, LAST3_FRAME } },
+#if CONFIG_OPTFLOW_REFINEMENT
+  { NEAR_NEARMV_OPTFLOW, { LAST_FRAME, LAST3_FRAME } },
+  { NEAR_NEWMV_OPTFLOW, { LAST_FRAME, LAST3_FRAME } },
+  { NEW_NEARMV_OPTFLOW, { LAST_FRAME, LAST3_FRAME } },
+  { NEW_NEWMV_OPTFLOW, { LAST_FRAME, LAST3_FRAME } },
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   { NEW_NEARMV, { LAST_FRAME, GOLDEN_FRAME } },
   { NEAR_NEWMV, { LAST_FRAME, GOLDEN_FRAME } },
   { NEW_NEWMV, { LAST_FRAME, GOLDEN_FRAME } },
   { GLOBAL_GLOBALMV, { LAST_FRAME, GOLDEN_FRAME } },
+#if CONFIG_OPTFLOW_REFINEMENT
+  { NEAR_NEARMV_OPTFLOW, { LAST_FRAME, GOLDEN_FRAME } },
+  { NEAR_NEWMV_OPTFLOW, { LAST_FRAME, GOLDEN_FRAME } },
+  { NEW_NEARMV_OPTFLOW, { LAST_FRAME, GOLDEN_FRAME } },
+  { NEW_NEWMV_OPTFLOW, { LAST_FRAME, GOLDEN_FRAME } },
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   { NEW_NEARMV, { BWDREF_FRAME, ALTREF_FRAME } },
   { NEAR_NEWMV, { BWDREF_FRAME, ALTREF_FRAME } },
   { NEW_NEWMV, { BWDREF_FRAME, ALTREF_FRAME } },
   { GLOBAL_GLOBALMV, { BWDREF_FRAME, ALTREF_FRAME } },
+#if CONFIG_OPTFLOW_REFINEMENT
+  { NEAR_NEARMV_OPTFLOW, { BWDREF_FRAME, ALTREF_FRAME } },
+  { NEAR_NEWMV_OPTFLOW, { BWDREF_FRAME, ALTREF_FRAME } },
+  { NEW_NEARMV_OPTFLOW, { BWDREF_FRAME, ALTREF_FRAME } },
+  { NEW_NEWMV_OPTFLOW, { BWDREF_FRAME, ALTREF_FRAME } },
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   // intra modes
   { DC_PRED, { INTRA_FRAME, NONE_FRAME } },
@@ -376,6 +476,32 @@
 };
 #endif  // CONFIG_NEW_INTER_MODES
 
+static AOM_INLINE THR_MODES
+get_prediction_mode_idx(PREDICTION_MODE this_mode, MV_REFERENCE_FRAME ref_frame,
+                        MV_REFERENCE_FRAME second_ref_frame) {
+  if (this_mode < INTRA_MODE_END) {
+    assert(ref_frame == INTRA_FRAME);
+    assert(second_ref_frame == NONE_FRAME);
+    return intra_to_mode_idx[this_mode - INTRA_MODE_START];
+  }
+  if (this_mode >= SINGLE_INTER_MODE_START &&
+      this_mode < SINGLE_INTER_MODE_END) {
+    assert(is_inter_ref_frame(ref_frame) && (ref_frame <= ALTREF_FRAME));
+    return single_inter_to_mode_idx[this_mode - SINGLE_INTER_MODE_START]
+                                   [ref_frame];
+  }
+  if (this_mode >= COMP_INTER_MODE_START && this_mode < COMP_INTER_MODE_END) {
+    assert(is_inter_ref_frame(ref_frame) && (ref_frame <= ALTREF_FRAME));
+    assert(is_inter_ref_frame(second_ref_frame) &&
+           (second_ref_frame <= ALTREF_FRAME));
+    return comp_inter_to_mode_idx[this_mode - COMP_INTER_MODE_START][ref_frame]
+                                 [second_ref_frame];
+  }
+  assert(0);
+  return THR_INVALID;
+}
+#endif  // !CONFIG_NEW_REF_SIGNALING
+
 static AOM_INLINE void restore_dst_buf(MACROBLOCKD *xd, const BUFFER_SET dst,
                                        const int num_planes) {
   for (int i = 0; i < num_planes; i++) {
@@ -398,31 +524,6 @@
   return rd_thresh;
 }
 
-static AOM_INLINE THR_MODES
-get_prediction_mode_idx(PREDICTION_MODE this_mode, MV_REFERENCE_FRAME ref_frame,
-                        MV_REFERENCE_FRAME second_ref_frame) {
-  if (this_mode < INTRA_MODE_END) {
-    assert(ref_frame == INTRA_FRAME);
-    assert(second_ref_frame == NONE_FRAME);
-    return intra_to_mode_idx[this_mode - INTRA_MODE_START];
-  }
-  if (this_mode >= SINGLE_INTER_MODE_START &&
-      this_mode < SINGLE_INTER_MODE_END) {
-    assert((ref_frame > INTRA_FRAME) && (ref_frame <= ALTREF_FRAME));
-    return single_inter_to_mode_idx[this_mode - SINGLE_INTER_MODE_START]
-                                   [ref_frame];
-  }
-  if (this_mode >= COMP_INTER_MODE_START && this_mode < COMP_INTER_MODE_END) {
-    assert((ref_frame > INTRA_FRAME) && (ref_frame <= ALTREF_FRAME));
-    assert((second_ref_frame > INTRA_FRAME) &&
-           (second_ref_frame <= ALTREF_FRAME));
-    return comp_inter_to_mode_idx[this_mode - COMP_INTER_MODE_START][ref_frame]
-                                 [second_ref_frame];
-  }
-  assert(0);
-  return THR_INVALID;
-}
-
 static AOM_INLINE int inter_mode_data_block_idx(BLOCK_SIZE bsize) {
   if (bsize == BLOCK_4X4 || bsize == BLOCK_4X8 || bsize == BLOCK_8X4 ||
       bsize == BLOCK_4X16 || bsize == BLOCK_16X4) {
@@ -750,8 +851,9 @@
 static INLINE void store_winner_mode_stats(
     const AV1_COMMON *const cm, MACROBLOCK *x, const MB_MODE_INFO *mbmi,
     RD_STATS *rd_cost, RD_STATS *rd_cost_y, RD_STATS *rd_cost_uv,
-    THR_MODES mode_index, uint8_t *color_map, BLOCK_SIZE bsize, int64_t this_rd,
-    int multi_winner_mode_type, int txfm_search_done) {
+    const MV_REFERENCE_FRAME *refs, PREDICTION_MODE mode, uint8_t *color_map,
+    BLOCK_SIZE bsize, int64_t this_rd, int multi_winner_mode_type,
+    int txfm_search_done) {
   WinnerModeStats *winner_mode_stats = x->winner_mode_stats;
   int mode_idx = 0;
   int is_palette_mode = mbmi->palette_mode_info.palette_size[PLANE_TYPE_Y] > 0;
@@ -790,13 +892,15 @@
   // Add a mode stat for winner mode processing
   winner_mode_stats[mode_idx].mbmi = *mbmi;
   winner_mode_stats[mode_idx].rd = this_rd;
-  winner_mode_stats[mode_idx].mode_index = mode_index;
+  winner_mode_stats[mode_idx].mode = mode;
+  winner_mode_stats[mode_idx].refs[0] = refs[0];
+  winner_mode_stats[mode_idx].refs[1] = refs[1];
 
   // Update rd stats required for inter frame
   if (!frame_is_intra_only(cm) && rd_cost && rd_cost_y && rd_cost_uv) {
     const MACROBLOCKD *xd = &x->e_mbd;
     const int skip_ctx = av1_get_skip_txfm_context(xd);
-    const int is_intra_mode = av1_mode_defs[mode_index].mode < INTRA_MODE_END;
+    const int is_intra_mode = mode < INTRA_MODE_END;
 #if CONFIG_SDP
     const int skip_txfm =
         mbmi->skip_txfm[xd->tree_type == CHROMA_PART] && !is_intra_mode;
diff --git a/av1/encoder/reconinter_enc.c b/av1/encoder/reconinter_enc.c
index 288ab4c..ae01865 100644
--- a/av1/encoder/reconinter_enc.c
+++ b/av1/encoder/reconinter_enc.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
@@ -31,6 +32,9 @@
 static void enc_calc_subpel_params(const MV *const src_mv,
                                    InterPredParams *const inter_pred_params,
                                    MACROBLOCKD *xd, int mi_x, int mi_y, int ref,
+#if CONFIG_OPTFLOW_REFINEMENT
+                                   int use_optflow_refinement,
+#endif  // CONFIG_OPTFLOW_REFINEMENT
                                    uint8_t **mc_buf, uint8_t **pre,
                                    SubpelParams *subpel_params,
                                    int *src_stride) {
@@ -43,32 +47,68 @@
   (void)mc_buf;
 
   const struct scale_factors *sf = inter_pred_params->scale_factors;
-
   struct buf_2d *pre_buf = &inter_pred_params->ref_frame_buf;
-  int ssx = inter_pred_params->subsampling_x;
-  int ssy = inter_pred_params->subsampling_y;
-  int orig_pos_y = inter_pred_params->pix_row << SUBPEL_BITS;
+#if CONFIG_OPTFLOW_REFINEMENT
+  const int is_scaled = av1_is_scaled(sf);
+  if (is_scaled || !xd) {
+#endif  // CONFIG_OPTFLOW_REFINEMENT
+    int ssx = inter_pred_params->subsampling_x;
+    int ssy = inter_pred_params->subsampling_y;
+    int orig_pos_y = inter_pred_params->pix_row << SUBPEL_BITS;
+    int orig_pos_x = inter_pred_params->pix_col << SUBPEL_BITS;
+#if CONFIG_OPTFLOW_REFINEMENT
+    if (use_optflow_refinement) {
+      orig_pos_y += ROUND_POWER_OF_TWO_SIGNED(src_mv->row * (1 << SUBPEL_BITS),
+                                              MV_REFINE_PREC_BITS + ssy);
+      orig_pos_x += ROUND_POWER_OF_TWO_SIGNED(src_mv->col * (1 << SUBPEL_BITS),
+                                              MV_REFINE_PREC_BITS + ssx);
+    } else {
+      orig_pos_y += src_mv->row * (1 << (1 - ssy));
+      orig_pos_x += src_mv->col * (1 << (1 - ssx));
+    }
+#else
   orig_pos_y += src_mv->row * (1 << (1 - ssy));
-  int orig_pos_x = inter_pred_params->pix_col << SUBPEL_BITS;
   orig_pos_x += src_mv->col * (1 << (1 - ssx));
-  int pos_y = sf->scale_value_y(orig_pos_y, sf);
-  int pos_x = sf->scale_value_x(orig_pos_x, sf);
-  pos_x += SCALE_EXTRA_OFF;
-  pos_y += SCALE_EXTRA_OFF;
+#endif  // CONFIG_OPTFLOW_REFINEMENT
+    int pos_y = sf->scale_value_y(orig_pos_y, sf);
+    int pos_x = sf->scale_value_x(orig_pos_x, sf);
+    pos_x += SCALE_EXTRA_OFF;
+    pos_y += SCALE_EXTRA_OFF;
 
-  const int top = -AOM_LEFT_TOP_MARGIN_SCALED(ssy);
-  const int left = -AOM_LEFT_TOP_MARGIN_SCALED(ssx);
-  const int bottom = (pre_buf->height + AOM_INTERP_EXTEND) << SCALE_SUBPEL_BITS;
-  const int right = (pre_buf->width + AOM_INTERP_EXTEND) << SCALE_SUBPEL_BITS;
-  pos_y = clamp(pos_y, top, bottom);
-  pos_x = clamp(pos_x, left, right);
+    const int top = -AOM_LEFT_TOP_MARGIN_SCALED(ssy);
+    const int left = -AOM_LEFT_TOP_MARGIN_SCALED(ssx);
+    const int bottom = (pre_buf->height + AOM_INTERP_EXTEND)
+                       << SCALE_SUBPEL_BITS;
+    const int right = (pre_buf->width + AOM_INTERP_EXTEND) << SCALE_SUBPEL_BITS;
+    pos_y = clamp(pos_y, top, bottom);
+    pos_x = clamp(pos_x, left, right);
 
-  subpel_params->subpel_x = pos_x & SCALE_SUBPEL_MASK;
-  subpel_params->subpel_y = pos_y & SCALE_SUBPEL_MASK;
-  subpel_params->xs = sf->x_step_q4;
-  subpel_params->ys = sf->y_step_q4;
-  *pre = pre_buf->buf0 + (pos_y >> SCALE_SUBPEL_BITS) * pre_buf->stride +
-         (pos_x >> SCALE_SUBPEL_BITS);
+    subpel_params->subpel_x = pos_x & SCALE_SUBPEL_MASK;
+    subpel_params->subpel_y = pos_y & SCALE_SUBPEL_MASK;
+    subpel_params->xs = sf->x_step_q4;
+    subpel_params->ys = sf->y_step_q4;
+    *pre = pre_buf->buf0 + (pos_y >> SCALE_SUBPEL_BITS) * pre_buf->stride +
+           (pos_x >> SCALE_SUBPEL_BITS);
+#if CONFIG_OPTFLOW_REFINEMENT
+  } else {
+    int pos_x = inter_pred_params->pix_col << SUBPEL_BITS;
+    int pos_y = inter_pred_params->pix_row << SUBPEL_BITS;
+    const int bw = use_optflow_refinement ? inter_pred_params->orig_block_width
+                                          : inter_pred_params->block_width;
+    const int bh = use_optflow_refinement ? inter_pred_params->orig_block_height
+                                          : inter_pred_params->block_height;
+    const MV mv_q4 = clamp_mv_to_umv_border_sb(
+        xd, src_mv, bw, bh, use_optflow_refinement,
+        inter_pred_params->subsampling_x, inter_pred_params->subsampling_y);
+    subpel_params->xs = subpel_params->ys = SCALE_SUBPEL_SHIFTS;
+    subpel_params->subpel_x = (mv_q4.col & SUBPEL_MASK) << SCALE_EXTRA_BITS;
+    subpel_params->subpel_y = (mv_q4.row & SUBPEL_MASK) << SCALE_EXTRA_BITS;
+    pos_x += mv_q4.col;
+    pos_y += mv_q4.row;
+    *pre = pre_buf->buf0 + (pos_y >> SUBPEL_BITS) * pre_buf->stride +
+           (pos_x >> SUBPEL_BITS);
+  }
+#endif  // CONFIG_OPTFLOW_REFINEMENT
   *src_stride = pre_buf->stride;
 }
 
@@ -81,8 +121,8 @@
 }
 
 static void enc_build_inter_predictors(const AV1_COMMON *cm, MACROBLOCKD *xd,
-                                       int plane, const MB_MODE_INFO *mi,
-                                       int bw, int bh, int mi_x, int mi_y) {
+                                       int plane, MB_MODE_INFO *mi, int bw,
+                                       int bh, int mi_x, int mi_y) {
   av1_build_inter_predictors(cm, xd, plane, mi, 0 /* build_for_obmc */, bw, bh,
                              mi_x, mi_y, NULL /* mc_buf */,
                              enc_calc_subpel_params);
diff --git a/av1/encoder/reconinter_enc.h b/av1/encoder/reconinter_enc.h
index fdc1f31..cd92813 100644
--- a/av1/encoder/reconinter_enc.h
+++ b/av1/encoder/reconinter_enc.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_RECONINTER_ENC_H_
diff --git a/av1/encoder/segmentation.c b/av1/encoder/segmentation.c
index a240b59..0d454a6 100644
--- a/av1/encoder/segmentation.c
+++ b/av1/encoder/segmentation.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <limits.h>
diff --git a/av1/encoder/segmentation.h b/av1/encoder/segmentation.h
index 1ad13d6..d59d110 100644
--- a/av1/encoder/segmentation.h
+++ b/av1/encoder/segmentation.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_SEGMENTATION_H_
diff --git a/av1/encoder/speed_features.c b/av1/encoder/speed_features.c
index cc42808..0b93300 100644
--- a/av1/encoder/speed_features.c
+++ b/av1/encoder/speed_features.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <limits.h>
@@ -306,7 +307,11 @@
 
   // Speed 0 for all speed features that give neutral coding performance change.
   sf->gm_sf.gm_disable_recode = 1;
+#if CONFIG_NEW_REF_SIGNALING
+  sf->gm_sf.gm_search_type = GM_REDUCED_REF_SEARCH_SKIP_LEV2;
+#else
   sf->gm_sf.gm_search_type = GM_REDUCED_REF_SEARCH_SKIP_L2_L3;
+#endif  // CONFIG_NEW_REF_SIGNALING
 
   sf->part_sf.less_rectangular_check_level = 1;
   sf->part_sf.ml_prune_4_partition = 1;
@@ -329,9 +334,6 @@
   sf->inter_sf.prune_wedge_pred_diff_based = 1;
   sf->inter_sf.reduce_inter_modes = 1;
   sf->inter_sf.selective_ref_frame = 1;
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-  sf->inter_sf.use_dist_wtd_comp_flag = DIST_WTD_COMP_SKIP_MV_SEARCH;
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
 
 #if !CONFIG_REMOVE_DUAL_FILTER
   sf->interp_sf.use_fast_interpolation_filter_search = 1;
@@ -359,7 +361,11 @@
   sf->hl_sf.superres_auto_search_type = SUPERRES_AUTO_DUAL;
 
   if (speed >= 1) {
+#if CONFIG_NEW_REF_SIGNALING
+    sf->gm_sf.gm_search_type = GM_REDUCED_REF_SEARCH_SKIP_LEV3;
+#else
     sf->gm_sf.gm_search_type = GM_REDUCED_REF_SEARCH_SKIP_L2_L3_ARF2;
+#endif  // CONFIG_NEW_REF_SIGNALING
     sf->gm_sf.prune_ref_frame_for_gm_search = boosted ? 0 : 1;
 
     sf->part_sf.intra_cnn_split = 1;
@@ -434,9 +440,6 @@
     sf->inter_sf.prune_compound_using_neighbors = 1;
     sf->inter_sf.prune_comp_type_by_comp_avg = 2;
     sf->inter_sf.selective_ref_frame = 3;
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-    sf->inter_sf.use_dist_wtd_comp_flag = DIST_WTD_COMP_DISABLED;
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
 
     // TODO(Sachin): Enable/Enhance this speed feature for speed 2 & 3
 #if !CONFIG_REMOVE_DUAL_FILTER
@@ -513,10 +516,9 @@
         frame_is_intra_only(&cpi->common) ? 0 : 1;
     sf->winner_mode_sf.enable_winner_mode_for_use_tx_domain_dist = 1;
     sf->winner_mode_sf.motion_mode_for_winner_cand =
-        boosted
-            ? 0
-            : gf_group->update_type[gf_group->index] == INTNL_ARF_UPDATE ? 1
-                                                                         : 2;
+        boosted                                                      ? 0
+        : gf_group->update_type[gf_group->index] == INTNL_ARF_UPDATE ? 1
+                                                                     : 2;
 
     // TODO(any): evaluate if these lpf features can be moved to speed 2.
     // For screen content, "prune_sgr_based_on_wiener = 2" cause large quality
@@ -535,7 +537,9 @@
     sf->part_sf.prune_ab_partition_using_split_info = 1;
     sf->part_sf.early_term_after_none_split = 1;
 
+#if !CONFIG_NEW_REF_SIGNALING
     sf->inter_sf.alt_ref_search_fp = 1;
+#endif  // !CONFIG_NEW_REF_SIGNALING
     sf->inter_sf.txfm_rd_gate_level = boosted ? 0 : 4;
 
     sf->inter_sf.prune_inter_modes_based_on_tpl = boosted ? 0 : 3;
@@ -730,15 +734,14 @@
   inter_sf->adaptive_rd_thresh = 0;
   inter_sf->model_based_post_interp_filter_breakout = 0;
   inter_sf->reduce_inter_modes = 0;
+#if !CONFIG_NEW_REF_SIGNALING
   inter_sf->alt_ref_search_fp = 0;
+#endif  // !CONFIG_NEW_REF_SIGNALING
   inter_sf->selective_ref_frame = 0;
   inter_sf->prune_ref_frame_for_rect_partitions = 0;
   inter_sf->disable_wedge_search_var_thresh = 0;
   inter_sf->fast_wedge_sign_estimate = 0;
   inter_sf->prune_wedge_pred_diff_based = 0;
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-  inter_sf->use_dist_wtd_comp_flag = DIST_WTD_COMP_ENABLED;
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
   inter_sf->reuse_inter_intra_mode = 0;
   inter_sf->disable_sb_level_coeff_cost_upd = 0;
   inter_sf->disable_sb_level_mv_cost_upd = 0;
diff --git a/av1/encoder/speed_features.h b/av1/encoder/speed_features.h
index d52d2fc..63d9f7c 100644
--- a/av1/encoder/speed_features.h
+++ b/av1/encoder/speed_features.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_SPEED_FEATURES_H_
@@ -33,19 +34,16 @@
 
 enum {
   GM_FULL_SEARCH,
+#if CONFIG_NEW_REF_SIGNALING
+  GM_REDUCED_REF_SEARCH_SKIP_LEV2,
+  GM_REDUCED_REF_SEARCH_SKIP_LEV3,
+#else
   GM_REDUCED_REF_SEARCH_SKIP_L2_L3,
   GM_REDUCED_REF_SEARCH_SKIP_L2_L3_ARF2,
+#endif  // CONFIG_NEW_REF_SIGNALING
   GM_DISABLE_SEARCH
 } UENUM1BYTE(GM_SEARCH_TYPE);
 
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-enum {
-  DIST_WTD_COMP_ENABLED,
-  DIST_WTD_COMP_SKIP_MV_SEARCH,
-  DIST_WTD_COMP_DISABLED,
-} UENUM1BYTE(DIST_WTD_COMP_FLAG);
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
-
 enum {
   INTRA_ALL = (1 << DC_PRED) | (1 << V_PRED) | (1 << H_PRED) | (1 << D45_PRED) |
               (1 << D135_PRED) | (1 << D113_PRED) | (1 << D157_PRED) |
@@ -100,6 +98,7 @@
 };
 #endif  // CONFIG_NEW_INTER_MODES
 
+#if !CONFIG_NEW_REF_SIGNALING
 enum {
   DISABLE_ALL_INTER_SPLIT = (1 << THR_COMP_GA) | (1 << THR_COMP_LA) |
                             (1 << THR_ALTR) | (1 << THR_GOLD) | (1 << THR_LAST),
@@ -111,6 +110,7 @@
   LAST_AND_INTRA_SPLIT_ONLY = (1 << THR_COMP_GA) | (1 << THR_COMP_LA) |
                               (1 << THR_ALTR) | (1 << THR_GOLD)
 };
+#endif  // !CONFIG_NEW_REF_SIGNALING
 
 enum {
   TXFM_CODING_SF = 1,
@@ -607,7 +607,10 @@
   // 2 implies prune horiz, vert and extended partition
   int prune_ref_frame_for_rect_partitions;
 
+#if !CONFIG_NEW_REF_SIGNALING
+  // Removed with CONFIG_NEW_REF_SIGNALING for now.
   int alt_ref_search_fp;
+#endif  // !CONFIG_NEW_REF_SIGNALING
 
   // flag to skip NEWMV mode in drl if the motion search result is the same
   int skip_repeated_newmv;
@@ -728,11 +731,6 @@
   // Disable interinter_wedge
   int disable_interinter_wedge;
 
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-  // Decide when and how to use joint_comp.
-  DIST_WTD_COMP_FLAG use_dist_wtd_comp_flag;
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
-
   // Whether to override and disable sb level coeff cost updates, if
   // cpi->oxcf.cost_upd_freq.coeff = COST_UPD_SB (i.e. set at SB level)
   int disable_sb_level_coeff_cost_upd;
diff --git a/av1/encoder/subgop.c b/av1/encoder/subgop.c
index 9effaca..025fb82 100644
--- a/av1/encoder/subgop.c
+++ b/av1/encoder/subgop.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <ctype.h>
diff --git a/av1/encoder/subgop.h b/av1/encoder/subgop.h
index e04ffb6..4ee44ae 100644
--- a/av1/encoder/subgop.h
+++ b/av1/encoder/subgop.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_SUBGOP_H_
diff --git a/av1/encoder/superres_scale.c b/av1/encoder/superres_scale.c
index 1ab260d..71acd94 100644
--- a/av1/encoder/superres_scale.c
+++ b/av1/encoder/superres_scale.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "av1/encoder/encoder_alloc.h"
@@ -349,12 +350,14 @@
   size_params_type rsz = { frm_dim_cfg->width, frm_dim_cfg->height,
                            SCALE_NUMERATOR };
   int resize_denom = SCALE_NUMERATOR;
+#if CONFIG_SVC_ENCODER
   if (has_no_stats_stage(cpi) && cpi->use_svc &&
       cpi->svc.spatial_layer_id < cpi->svc.number_spatial_layers - 1) {
     rsz.resize_width = cpi->common.width;
     rsz.resize_height = cpi->common.height;
     return rsz;
   }
+#endif  // CONFIG_SVC_ENCODER
   if (is_stat_generation_stage(cpi)) return rsz;
   if (resize_pending_params->width && resize_pending_params->height) {
     rsz.resize_width = resize_pending_params->width;
diff --git a/av1/encoder/superres_scale.h b/av1/encoder/superres_scale.h
index 450a4ed..8213c2f 100644
--- a/av1/encoder/superres_scale.h
+++ b/av1/encoder/superres_scale.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_SUPERRES_SCALE_H_
diff --git a/av1/encoder/svc_layercontext.c b/av1/encoder/svc_layercontext.c
index 5a16790..9cd7488 100644
--- a/av1/encoder/svc_layercontext.c
+++ b/av1/encoder/svc_layercontext.c
@@ -204,6 +204,18 @@
   // This is to skip testing nonzero-mv for that reference if it was last
   // refreshed (i.e., buffer slot holding that reference was refreshed) on the
   // previous spatial layer(s) at the same time (current_superframe).
+#if CONFIG_NEW_REF_SIGNALING
+  if (svc->external_ref_frame_config && svc->force_zero_mode_spatial_ref) {
+    int ref_frame_idx = svc->ref_idx[get_closest_pastcur_ref_index(cm)];
+    if (svc->buffer_time_index[ref_frame_idx] == svc->current_superframe &&
+        svc->buffer_spatial_layer[ref_frame_idx] <= svc->spatial_layer_id - 1)
+      svc->skip_nonzeromv_last = 1;
+    ref_frame_idx = svc->ref_idx[cm->ref_frames_info.past_refs[0]];
+    if (svc->buffer_time_index[ref_frame_idx] == svc->current_superframe &&
+        svc->buffer_spatial_layer[ref_frame_idx] <= svc->spatial_layer_id - 1)
+      svc->skip_nonzeromv_gf = 1;
+  }
+#else
   if (svc->external_ref_frame_config && svc->force_zero_mode_spatial_ref) {
     int ref_frame_idx = svc->ref_idx[LAST_FRAME - 1];
     if (svc->buffer_time_index[ref_frame_idx] == svc->current_superframe &&
@@ -214,6 +226,7 @@
         svc->buffer_spatial_layer[ref_frame_idx] <= svc->spatial_layer_id - 1)
       svc->skip_nonzeromv_gf = 1;
   }
+#endif  // CONFIG_NEW_REF_SIGNALING
 }
 
 void av1_save_layer_context(AV1_COMP *const cpi) {
@@ -286,12 +299,21 @@
     }
   }
   if (wanted_fb != -1) {
+#if CONFIG_NEW_REF_SIGNALING
+    const int n_refs = cm->ref_frames_info.n_total_refs;
+    for (int ref_frame = 0; ref_frame < n_refs; ref_frame++) {
+      if (get_ref_frame_map_idx(cm, ref_frame) == wanted_fb) {
+        primary_ref_frame = ref_frame;
+      }
+    }
+#else
     for (int ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ref_frame++) {
       if (get_ref_frame_map_idx(cm, ref_frame) == wanted_fb) {
         primary_ref_frame = ref_frame - LAST_FRAME;
         break;
       }
     }
+#endif  // CONFIG_NEW_REF_SIGNALING
   }
   return primary_ref_frame;
 }
diff --git a/av1/encoder/temporal_filter.c b/av1/encoder/temporal_filter.c
index 5de5295..3105c00 100644
--- a/av1/encoder/temporal_filter.c
+++ b/av1/encoder/temporal_filter.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <math.h>
diff --git a/av1/encoder/temporal_filter.h b/av1/encoder/temporal_filter.h
index f4f07f7..73e28de 100644
--- a/av1/encoder/temporal_filter.h
+++ b/av1/encoder/temporal_filter.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_TEMPORAL_FILTER_H_
diff --git a/av1/encoder/tokenize.c b/av1/encoder/tokenize.c
index 1613bf8..08b5180 100644
--- a/av1/encoder/tokenize.c
+++ b/av1/encoder/tokenize.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/av1/encoder/tokenize.h b/av1/encoder/tokenize.h
index 85bec53..0da5bc6 100644
--- a/av1/encoder/tokenize.h
+++ b/av1/encoder/tokenize.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_TOKENIZE_H_
diff --git a/av1/encoder/tpl_model.c b/av1/encoder/tpl_model.c
index 6a2e5cc..fbf04b9 100644
--- a/av1/encoder/tpl_model.c
+++ b/av1/encoder/tpl_model.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2019, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <stdint.h>
@@ -286,7 +287,11 @@
   xd->mi[0]->motion_mode = SIMPLE_TRANSLATION;
 
   // Intra prediction search
+#if CONFIG_NEW_REF_SIGNALING
+  xd->mi[0]->ref_frame[0] = INTRA_FRAME_NRS;
+#else
   xd->mi[0]->ref_frame[0] = INTRA_FRAME;
+#endif  // CONFIG_NEW_REF_SIGNALING
 
   // Pre-load the bottom left line.
   if (xd->left_available &&
@@ -312,12 +317,7 @@
     av1_predict_intra_block(cm, xd, block_size_wide[bsize],
                             block_size_high[bsize], tx_size, mode, 0, 0,
                             FILTER_INTRA_MODES, dst_buffer, dst_buffer_stride,
-                            predictor, bw, 0, 0,
-#if CONFIG_ORIP
-                            0, 0);
-#else
-                            0);
-#endif
+                            predictor, bw, 0, 0, 0);
 
     intra_cost = tpl_get_satd_cost(x, src_diff, bw, src_mb_buffer, src_stride,
                                    predictor, bw, coeff, bw, bh, tx_size);
@@ -328,7 +328,11 @@
   }
 
   // Motion compensated prediction
+#if CONFIG_NEW_REF_SIGNALING
+  xd->mi[0]->ref_frame[0] = INTRA_FRAME_NRS;
+#else
   xd->mi[0]->ref_frame[0] = INTRA_FRAME;
+#endif  // CONFIG_NEW_REF_SIGNALING
 
   int best_rf_idx = -1;
   int_mv best_mv;
@@ -456,7 +460,11 @@
       best_mv.as_int = best_rfidx_mv.as_int;
       if (best_inter_cost < best_intra_cost) {
         best_mode = NEWMV;
+#if CONFIG_NEW_REF_SIGNALING
+        xd->mi[0]->ref_frame[0] = best_rf_idx;
+#else
         xd->mi[0]->ref_frame[0] = best_rf_idx + LAST_FRAME;
+#endif  // CONFIG_NEW_REF_SIGNALING
         xd->mi[0]->mv[0].as_int = best_mv.as_int;
       }
     }
@@ -497,14 +505,7 @@
     av1_predict_intra_block(cm, xd, block_size_wide[bsize],
                             block_size_high[bsize], tx_size, best_mode, 0, 0,
                             FILTER_INTRA_MODES, dst_buffer, dst_buffer_stride,
-                            dst_buffer, dst_buffer_stride, 0, 0
-#if CONFIG_ORIP
-                            ,
-                            0, 0);
-#else
-                            ,
-                            0);
-#endif
+                            dst_buffer, dst_buffer_stride, 0, 0, 0);
   }
 
   int rate_cost;
@@ -766,14 +767,11 @@
   TplParams *const tpl_data = &cpi->tpl_data;
   TplDepFrame *tpl_frame = &tpl_data->tpl_frame[frame_idx];
   const YV12_BUFFER_CONFIG *this_frame = tpl_frame->gf_picture;
-  const YV12_BUFFER_CONFIG *ref_frames_ordered[INTER_REFS_PER_FRAME];
-  uint32_t ref_frame_display_indices[INTER_REFS_PER_FRAME];
   GF_GROUP *gf_group = &cpi->gf_group;
   int ref_pruning_enabled = is_frame_eligible_for_ref_pruning(
       gf_group, cpi->sf.inter_sf.selective_ref_frame,
       cpi->sf.tpl_sf.prune_ref_frames_in_tpl, frame_idx);
   int gop_length = get_gop_length(gf_group);
-  int ref_frame_flags;
   AV1_COMMON *cm = &cpi->common;
   int rdmult, idx;
   ThreadData *td = &cpi->td;
@@ -790,14 +788,25 @@
 
   xd->cur_buf = this_frame;
 
+#if !CONFIG_NEW_REF_SIGNALING
+  uint32_t ref_frame_display_indices[INTER_REFS_PER_FRAME];
+#endif  // !CONFIG_NEW_REF_SIGNALING
   for (idx = 0; idx < INTER_REFS_PER_FRAME; ++idx) {
     TplDepFrame *tpl_ref_frame =
         &tpl_data->tpl_frame[tpl_frame->ref_map_index[idx]];
     tpl_data->ref_frame[idx] = tpl_ref_frame->rec_picture;
     tpl_data->src_ref_frame[idx] = tpl_ref_frame->gf_picture;
+#if !CONFIG_NEW_REF_SIGNALING
     ref_frame_display_indices[idx] = tpl_ref_frame->frame_display_index;
+#endif  // !CONFIG_NEW_REF_SIGNALING
   }
 
+  // TODO(debargha,kslu) Apply ref_frame_flags and prune references here.
+  // See example of how this is done in init_mc_flow_dispenser().
+  // aomedia:3159
+#if !CONFIG_NEW_REF_SIGNALING
+  int ref_frame_flags;
+  const YV12_BUFFER_CONFIG *ref_frames_ordered[INTER_REFS_PER_FRAME];
   // Store the reference frames based on priority order
   for (int i = 0; i < INTER_REFS_PER_FRAME; ++i) {
     ref_frames_ordered[i] =
@@ -816,6 +825,7 @@
       tpl_data->ref_frame[idx] = NULL;
     }
   }
+#endif  // !CONFIG_NEW_REF_SIGNALING
 
   // Skip motion estimation w.r.t. reference frames which are not
   // considered in RD search, using "selective_ref_frame" speed feature.
@@ -824,9 +834,14 @@
   // differ from the frames considered during RD search.
   if (ref_pruning_enabled && (frame_idx < gop_length)) {
     for (idx = 0; idx < INTER_REFS_PER_FRAME; ++idx) {
+#if CONFIG_NEW_REF_SIGNALING
+      const MV_REFERENCE_FRAME refs[2] = { idx + 1, INVALID_IDX };
+      if (prune_ref_by_selective_ref_frame_nrs(cpi, NULL, refs)) {
+#else
       const MV_REFERENCE_FRAME refs[2] = { idx + 1, NONE_FRAME };
       if (prune_ref_by_selective_ref_frame(cpi, NULL, refs,
                                            ref_frame_display_indices)) {
+#endif  // CONFIG_NEW_REF_SIGNALING
         tpl_data->ref_frame[idx] = NULL;
       }
     }
@@ -943,7 +958,9 @@
   int cur_frame_idx = gf_group->index;
   *pframe_qindex = 0;
   RefFrameMapPair ref_frame_map_pairs[REF_FRAMES];
-  init_ref_map_pair(cpi, ref_frame_map_pairs);
+  init_ref_map_pair(
+      cm, ref_frame_map_pairs,
+      cpi->gf_group.update_type[cpi->gf_group.index] == KF_UPDATE);
 
   EncodeFrameParams frame_params = *init_frame_params;
   TplParams *const tpl_data = &cpi->tpl_data;
@@ -1028,7 +1045,12 @@
     const int true_disp =
         (int)(tpl_frame->frame_display_index) -
         (gf_group->subgop_cfg != NULL && frame_params.show_frame);
-    av1_get_ref_frames(cpi, true_disp, ref_frame_map_pairs);
+#if CONFIG_NEW_REF_SIGNALING
+    if (cm->seq_params.explicit_ref_frame_map)
+      av1_get_ref_frames_enc(cm, true_disp, ref_frame_map_pairs);
+    else
+#endif  // CONFIG_NEW_REF_SIGNALING
+      av1_get_ref_frames(cm, true_disp, ref_frame_map_pairs);
     int refresh_mask =
         av1_get_refresh_frame_flags(cpi, &frame_params, frame_update_type,
                                     gf_index, true_disp, ref_frame_map_pairs);
@@ -1043,16 +1065,41 @@
                              cpi->gf_group.max_layer_depth);
     }
 
+#if CONFIG_NEW_REF_SIGNALING
+    for (int i = 0; i < INTER_REFS_PER_FRAME; ++i) {
+      if (cm->remapped_ref_idx[i] != -1) {
+        tpl_frame->ref_map_index[i] = ref_picture_map[cm->remapped_ref_idx[i]];
+      } else {
+        tpl_frame->ref_map_index[i] = ref_picture_map[0];
+      }
+    }
+#else
     for (int i = LAST_FRAME; i <= ALTREF_FRAME; ++i)
       tpl_frame->ref_map_index[i - LAST_FRAME] =
           ref_picture_map[cm->remapped_ref_idx[i - LAST_FRAME]];
+#endif  // CONFIG_NEW_REF_SIGNALING
 
     if (refresh_mask) ref_picture_map[refresh_frame_map_index] = gf_index;
 
     ++*tpl_group_frames;
   }
 
-  if (cpi->rc.frames_since_key == 0) return;
+  if (cpi->rc.frames_since_key == 0) {
+#if CONFIG_NEW_REF_SIGNALING
+    TplDepFrame *tpl_frame = &tpl_data->tpl_frame[cur_frame_idx];
+    const int true_disp =
+        (int)(tpl_frame->frame_display_index) -
+        (gf_group->subgop_cfg != NULL && init_frame_params->show_frame);
+    init_ref_map_pair(
+        cm, ref_frame_map_pairs,
+        cpi->gf_group.update_type[cpi->gf_group.index] == KEY_FRAME);
+    if (cm->seq_params.explicit_ref_frame_map)
+      av1_get_ref_frames_enc(cm, true_disp, ref_frame_map_pairs);
+    else
+      av1_get_ref_frames(cm, true_disp, ref_frame_map_pairs);
+#endif  // CONFIG_NEW_REF_SIGNALING
+    return;
+  }
 
   int extend_frame_count = 0;
   int extend_frame_length = AOMMIN(
@@ -1100,8 +1147,13 @@
     const int true_disp =
         (int)(tpl_frame->frame_display_index) -
         (gf_group->subgop_cfg != NULL && frame_params.show_frame);
-    av1_get_ref_frames(cpi, true_disp, ref_frame_map_pairs);
-    // TODO(sarahparker) av1_get_refresh_frame_flags()
+#if CONFIG_NEW_REF_SIGNALING
+    if (cm->seq_params.explicit_ref_frame_map)
+      av1_get_ref_frames_enc(cm, true_disp, ref_frame_map_pairs);
+    else
+#endif  // CONFIG_NEW_REF_SIGNALING
+      av1_get_ref_frames(cm, true_disp, ref_frame_map_pairs);
+    // TODO(kslu) av1_get_refresh_frame_flags()
     // will execute default behavior even when
     // subgop cfg is enabled. This should be addressed if we ever remove the
     // frame_update_type.
@@ -1117,6 +1169,15 @@
                              cpi->gf_group.max_layer_depth);
     }
 
+#if CONFIG_NEW_REF_SIGNALING
+    for (int i = 0; i < INTER_REFS_PER_FRAME; ++i) {
+      if (cm->remapped_ref_idx[i] != -1) {
+        tpl_frame->ref_map_index[i] = ref_picture_map[cm->remapped_ref_idx[i]];
+      } else {
+        tpl_frame->ref_map_index[i] = ref_picture_map[0];
+      }
+    }
+#else
     for (int i = LAST_FRAME; i <= ALTREF_FRAME; ++i)
       tpl_frame->ref_map_index[i - LAST_FRAME] =
           ref_picture_map[cm->remapped_ref_idx[i - LAST_FRAME]];
@@ -1125,6 +1186,7 @@
     tpl_frame->ref_map_index[LAST3_FRAME - LAST_FRAME] = -1;
     tpl_frame->ref_map_index[BWDREF_FRAME - LAST_FRAME] = -1;
     tpl_frame->ref_map_index[ALTREF2_FRAME - LAST_FRAME] = -1;
+#endif  // CONFIG_NEW_REF_SIGNALING
 
     if (refresh_mask) ref_picture_map[refresh_frame_map_index] = gf_index;
 
@@ -1137,8 +1199,15 @@
   const int true_disp =
       (int)(tpl_frame->frame_display_index) -
       (gf_group->subgop_cfg != NULL && init_frame_params->show_frame);
-  init_ref_map_pair(cpi, ref_frame_map_pairs);
-  av1_get_ref_frames(cpi, true_disp, ref_frame_map_pairs);
+  init_ref_map_pair(
+      cm, ref_frame_map_pairs,
+      cpi->gf_group.update_type[cpi->gf_group.index] == KF_UPDATE);
+#if CONFIG_NEW_REF_SIGNALING
+  if (cm->seq_params.explicit_ref_frame_map)
+    av1_get_ref_frames_enc(cm, true_disp, ref_frame_map_pairs);
+  else
+#endif  // CONFIG_NEW_REF_SIGNALING
+    av1_get_ref_frames(cm, true_disp, ref_frame_map_pairs);
 }
 
 void av1_init_tpl_stats(TplParams *const tpl_data) {
@@ -1171,12 +1240,17 @@
   cm->current_frame.frame_type = frame_params->frame_type;
   for (int gf_index = gf_group->index; gf_index < (gf_group->size - 1);
        ++gf_index) {
+#if CONFIG_NEW_REF_SIGNALING
+    (void)this_frame_params;
+    av1_configure_buffer_updates(cpi, gf_group->update_type[gf_index]);
+#else
     av1_configure_buffer_updates(cpi, &this_frame_params.refresh_frame,
                                  gf_group->update_type[gf_index],
                                  cm->current_frame.frame_type, 0);
 
     memcpy(&cpi->refresh_frame, &this_frame_params.refresh_frame,
            sizeof(cpi->refresh_frame));
+#endif  // CONFIG_NEW_REF_SIGNALING
 
     cm->show_frame = gf_group->update_type[gf_index] != ARF_UPDATE &&
                      gf_group->update_type[gf_index] != KFFLT_UPDATE &&
@@ -1238,9 +1312,13 @@
     mc_flow_synthesizer(cpi, frame_idx);
   }
 
+#if CONFIG_NEW_REF_SIGNALING
+  av1_configure_buffer_updates(cpi, gf_group->update_type[gf_group->index]);
+#else
   av1_configure_buffer_updates(cpi, &this_frame_params.refresh_frame,
                                gf_group->update_type[gf_group->index],
                                frame_params->frame_type, 0);
+#endif  // CONFIG_NEW_REF_SIGNALING
   cm->current_frame.frame_type = frame_params->frame_type;
   cm->show_frame = frame_params->show_frame;
 }
diff --git a/av1/encoder/tpl_model.h b/av1/encoder/tpl_model.h
index 1337a73..c7c3eb2 100644
--- a/av1/encoder/tpl_model.h
+++ b/av1/encoder/tpl_model.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2019, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_TPL_MODEL_H_
diff --git a/av1/encoder/tune_vmaf.c b/av1/encoder/tune_vmaf.c
index e6573e3..a95b501 100644
--- a/av1/encoder/tune_vmaf.c
+++ b/av1/encoder/tune_vmaf.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2019, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "av1/encoder/tune_vmaf.h"
diff --git a/av1/encoder/tune_vmaf.h b/av1/encoder/tune_vmaf.h
index c19d5a3..11f21d5 100644
--- a/av1/encoder/tune_vmaf.h
+++ b/av1/encoder/tune_vmaf.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2019, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_TUNE_VMAF_H_
diff --git a/av1/encoder/tx_prune_model_weights.h b/av1/encoder/tx_prune_model_weights.h
index 76efe93..e2d4ddc 100644
--- a/av1/encoder/tx_prune_model_weights.h
+++ b/av1/encoder/tx_prune_model_weights.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_TX_PRUNE_MODEL_WEIGHTS_H_
diff --git a/av1/encoder/tx_search.c b/av1/encoder/tx_search.c
index 9b7ae7f..3219ecf 100644
--- a/av1/encoder/tx_search.c
+++ b/av1/encoder/tx_search.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "av1/common/cfl.h"
@@ -2257,8 +2258,19 @@
     TXB_CTX txb_ctx_tmp;
     const PLANE_TYPE plane_type = get_plane_type(plane);
     get_txb_ctx(plane_bsize, tx_size, plane, ta, tl, &txb_ctx_tmp);
+#if CONFIG_CONTEXT_DERIVATION
+    int zero_blk_rate = 0;
+    if (plane == AOM_PLANE_Y || plane == AOM_PLANE_U) {
+      zero_blk_rate = x->coeff_costs.coeff_costs[txs_ctx][plane_type]
+                          .txb_skip_cost[txb_ctx_tmp.txb_skip_ctx][1];
+    } else {
+      zero_blk_rate = x->coeff_costs.coeff_costs[txs_ctx][plane_type]
+                          .v_txb_skip_cost[txb_ctx_tmp.txb_skip_ctx][1];
+    }
+#else
     const int zero_blk_rate = x->coeff_costs.coeff_costs[txs_ctx][plane_type]
                                   .txb_skip_cost[txb_ctx_tmp.txb_skip_ctx][1];
+#endif  // CONFIG_CONTEXT_DERIVATION
     best_rd_stats->rate = zero_blk_rate;
 
     best_rd_stats->rdcost =
@@ -2421,6 +2433,11 @@
       // Therefore transform domain distortion is not valid for these
       // transform sizes.
       (txsize_sqr_up_map[tx_size] != TX_64X64) &&
+#if CONFIG_IST
+      // Use pixel domain distortion for IST
+      // TODO: Make IST compatible with tx domain distortion
+      !cm->seq_params.enable_ist &&
+#endif
       // Use pixel domain distortion for DC only blocks
       !dc_only_blk;
   // Flag to indicate if an extra calculation of distortion in the pixel domain
diff --git a/av1/encoder/tx_search.h b/av1/encoder/tx_search.h
index 5a5d259..4320218 100644
--- a/av1/encoder/tx_search.h
+++ b/av1/encoder/tx_search.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_TRANSFORM_SEARCH_H_
diff --git a/av1/encoder/use_flat_gop_model_params.h b/av1/encoder/use_flat_gop_model_params.h
index cf07766..d0b5496 100644
--- a/av1/encoder/use_flat_gop_model_params.h
+++ b/av1/encoder/use_flat_gop_model_params.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_USE_FLAT_GOP_MODEL_PARAMS_H_
diff --git a/av1/encoder/wedge_utils.c b/av1/encoder/wedge_utils.c
index 4067017..b97f3cf 100644
--- a/av1/encoder/wedge_utils.c
+++ b/av1/encoder/wedge_utils.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/av1/encoder/x86/av1_fwd_txfm1d_sse4.c b/av1/encoder/x86/av1_fwd_txfm1d_sse4.c
index 62eaa30..542eec5 100644
--- a/av1/encoder/x86/av1_fwd_txfm1d_sse4.c
+++ b/av1/encoder/x86/av1_fwd_txfm1d_sse4.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "av1/encoder/x86/av1_txfm1d_sse4.h"
diff --git a/av1/encoder/x86/av1_fwd_txfm2d_avx2.c b/av1/encoder/x86/av1_fwd_txfm2d_avx2.c
index 634d50b..f6d46cd 100644
--- a/av1/encoder/x86/av1_fwd_txfm2d_avx2.c
+++ b/av1/encoder/x86/av1_fwd_txfm2d_avx2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "config/av1_rtcd.h"
diff --git a/av1/encoder/x86/av1_fwd_txfm2d_sse4.c b/av1/encoder/x86/av1_fwd_txfm2d_sse4.c
index 0bc3fbc..8032fb7 100644
--- a/av1/encoder/x86/av1_fwd_txfm2d_sse4.c
+++ b/av1/encoder/x86/av1_fwd_txfm2d_sse4.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "config/av1_rtcd.h"
diff --git a/av1/encoder/x86/av1_fwd_txfm_avx2.h b/av1/encoder/x86/av1_fwd_txfm_avx2.h
index aaad76e..4c66b09 100644
--- a/av1/encoder/x86/av1_fwd_txfm_avx2.h
+++ b/av1/encoder/x86/av1_fwd_txfm_avx2.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_X86_AV1_FWD_TXFM_AVX2_H_
diff --git a/av1/encoder/x86/av1_fwd_txfm_sse2.c b/av1/encoder/x86/av1_fwd_txfm_sse2.c
index 694e613..5fe1179 100644
--- a/av1/encoder/x86/av1_fwd_txfm_sse2.c
+++ b/av1/encoder/x86/av1_fwd_txfm_sse2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "av1/common/x86/av1_txfm_sse2.h"
diff --git a/av1/encoder/x86/av1_fwd_txfm_sse2.h b/av1/encoder/x86/av1_fwd_txfm_sse2.h
index a0e32f5..927e43e 100644
--- a/av1/encoder/x86/av1_fwd_txfm_sse2.h
+++ b/av1/encoder/x86/av1_fwd_txfm_sse2.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #ifndef AOM_AV1_ENCODER_X86_AV1_FWD_TXFM_SSE2_H_
 #define AOM_AV1_ENCODER_X86_AV1_FWD_TXFM_SSE2_H_
diff --git a/av1/encoder/x86/av1_highbd_quantize_avx2.c b/av1/encoder/x86/av1_highbd_quantize_avx2.c
index 5999241..312ca3b 100644
--- a/av1/encoder/x86/av1_highbd_quantize_avx2.c
+++ b/av1/encoder/x86/av1_highbd_quantize_avx2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <immintrin.h>
diff --git a/av1/encoder/x86/av1_highbd_quantize_sse4.c b/av1/encoder/x86/av1_highbd_quantize_sse4.c
index bd9af6d..92486e4 100644
--- a/av1/encoder/x86/av1_highbd_quantize_sse4.c
+++ b/av1/encoder/x86/av1_highbd_quantize_sse4.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <smmintrin.h>
diff --git a/av1/encoder/x86/av1_quantize_avx2.c b/av1/encoder/x86/av1_quantize_avx2.c
index 4a82bd7..ba8ed3c 100644
--- a/av1/encoder/x86/av1_quantize_avx2.c
+++ b/av1/encoder/x86/av1_quantize_avx2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <immintrin.h>
diff --git a/av1/encoder/x86/av1_quantize_sse2.c b/av1/encoder/x86/av1_quantize_sse2.c
index 2d2d595..dc8aafd 100644
--- a/av1/encoder/x86/av1_quantize_sse2.c
+++ b/av1/encoder/x86/av1_quantize_sse2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <emmintrin.h>
diff --git a/av1/encoder/x86/av1_quantize_ssse3_x86_64.asm b/av1/encoder/x86/av1_quantize_ssse3_x86_64.asm
index ad4ae27..d5998cd 100644
--- a/av1/encoder/x86/av1_quantize_ssse3_x86_64.asm
+++ b/av1/encoder/x86/av1_quantize_ssse3_x86_64.asm
@@ -1,12 +1,12 @@
 ;
-; Copyright (c) 2016, Alliance for Open Media. All rights reserved
+; Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ;
-; This source code is subject to the terms of the BSD 2 Clause License and
-; the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-; was not distributed with this source code in the LICENSE file, you can
-; obtain it at www.aomedia.org/license/software. If the Alliance for Open
-; Media Patent License 1.0 was not distributed with this source code in the
-; PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+; This source code is subject to the terms of the BSD 3-Clause Clear License and the
+; Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+; not distributed with this source code in the LICENSE file, you can obtain it
+; at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+; License 1.0 was not distributed with this source code in the PATENTS file, you
+; can obtain it at aomedia.org/license/patent-license/.
 ;
 
 ;
diff --git a/av1/encoder/x86/av1_ssim_opt_x86_64.asm b/av1/encoder/x86/av1_ssim_opt_x86_64.asm
index 6187581..1d993d4 100644
--- a/av1/encoder/x86/av1_ssim_opt_x86_64.asm
+++ b/av1/encoder/x86/av1_ssim_opt_x86_64.asm
@@ -1,12 +1,12 @@
 ;
-; Copyright (c) 2016, Alliance for Open Media. All rights reserved
+; Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ;
-; This source code is subject to the terms of the BSD 2 Clause License and
-; the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-; was not distributed with this source code in the LICENSE file, you can
-; obtain it at www.aomedia.org/license/software. If the Alliance for Open
-; Media Patent License 1.0 was not distributed with this source code in the
-; PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+; This source code is subject to the terms of the BSD 3-Clause Clear License and the
+; Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+; not distributed with this source code in the LICENSE file, you can obtain it
+; at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+; License 1.0 was not distributed with this source code in the PATENTS file, you
+; can obtain it at aomedia.org/license/patent-license/.
 ;
 
 ;
diff --git a/av1/encoder/x86/av1_txfm1d_sse4.h b/av1/encoder/x86/av1_txfm1d_sse4.h
index 7a0f328..aa4674b 100644
--- a/av1/encoder/x86/av1_txfm1d_sse4.h
+++ b/av1/encoder/x86/av1_txfm1d_sse4.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_AV1_ENCODER_X86_AV1_TXFM1D_SSE4_H_
diff --git a/av1/encoder/x86/corner_match_avx2.c b/av1/encoder/x86/corner_match_avx2.c
index 8d7eb3f..8ee997a 100644
--- a/av1/encoder/x86/corner_match_avx2.c
+++ b/av1/encoder/x86/corner_match_avx2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <math.h>
diff --git a/av1/encoder/x86/corner_match_sse4.c b/av1/encoder/x86/corner_match_sse4.c
index 5c9ca20..a718e85 100644
--- a/av1/encoder/x86/corner_match_sse4.c
+++ b/av1/encoder/x86/corner_match_sse4.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <stdlib.h>
diff --git a/av1/encoder/x86/dct_sse2.asm b/av1/encoder/x86/dct_sse2.asm
index b185548..fbf2f10 100644
--- a/av1/encoder/x86/dct_sse2.asm
+++ b/av1/encoder/x86/dct_sse2.asm
@@ -1,12 +1,12 @@
 ;
-; Copyright (c) 2016, Alliance for Open Media. All rights reserved
+; Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ;
-; This source code is subject to the terms of the BSD 2 Clause License and
-; the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-; was not distributed with this source code in the LICENSE file, you can
-; obtain it at www.aomedia.org/license/software. If the Alliance for Open
-; Media Patent License 1.0 was not distributed with this source code in the
-; PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+; This source code is subject to the terms of the BSD 3-Clause Clear License and the
+; Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+; not distributed with this source code in the LICENSE file, you can obtain it
+; at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+; License 1.0 was not distributed with this source code in the PATENTS file, you
+; can obtain it at aomedia.org/license/patent-license/.
 ;
 
 %define private_prefix av1
diff --git a/av1/encoder/x86/encodetxb_avx2.c b/av1/encoder/x86/encodetxb_avx2.c
index 30a4129..c64de4e 100644
--- a/av1/encoder/x86/encodetxb_avx2.c
+++ b/av1/encoder/x86/encodetxb_avx2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/av1/encoder/x86/encodetxb_sse2.c b/av1/encoder/x86/encodetxb_sse2.c
index 394befb..038f738 100644
--- a/av1/encoder/x86/encodetxb_sse2.c
+++ b/av1/encoder/x86/encodetxb_sse2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/av1/encoder/x86/encodetxb_sse4.c b/av1/encoder/x86/encodetxb_sse4.c
index aeb57f2..f081372 100644
--- a/av1/encoder/x86/encodetxb_sse4.c
+++ b/av1/encoder/x86/encodetxb_sse4.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/av1/encoder/x86/error_intrin_avx2.c b/av1/encoder/x86/error_intrin_avx2.c
index 12dda3a..0f259c7 100644
--- a/av1/encoder/x86/error_intrin_avx2.c
+++ b/av1/encoder/x86/error_intrin_avx2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <immintrin.h>  // AVX2
diff --git a/av1/encoder/x86/error_sse2.asm b/av1/encoder/x86/error_sse2.asm
index f4b4968..2cffb1e 100644
--- a/av1/encoder/x86/error_sse2.asm
+++ b/av1/encoder/x86/error_sse2.asm
@@ -1,12 +1,12 @@
 ;
-; Copyright (c) 2016, Alliance for Open Media. All rights reserved
+; Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ;
-; This source code is subject to the terms of the BSD 2 Clause License and
-; the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-; was not distributed with this source code in the LICENSE file, you can
-; obtain it at www.aomedia.org/license/software. If the Alliance for Open
-; Media Patent License 1.0 was not distributed with this source code in the
-; PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+; This source code is subject to the terms of the BSD 3-Clause Clear License and the
+; Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+; not distributed with this source code in the LICENSE file, you can obtain it
+; at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+; License 1.0 was not distributed with this source code in the PATENTS file, you
+; can obtain it at aomedia.org/license/patent-license/.
 ;
 
 ;
diff --git a/av1/encoder/x86/hash_sse42.c b/av1/encoder/x86/hash_sse42.c
index 0becdf9..4b792d8 100644
--- a/av1/encoder/x86/hash_sse42.c
+++ b/av1/encoder/x86/hash_sse42.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <stdint.h>
diff --git a/av1/encoder/x86/highbd_block_error_intrin_avx2.c b/av1/encoder/x86/highbd_block_error_intrin_avx2.c
index ee3714d..100be5e 100644
--- a/av1/encoder/x86/highbd_block_error_intrin_avx2.c
+++ b/av1/encoder/x86/highbd_block_error_intrin_avx2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2019, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <immintrin.h>
diff --git a/av1/encoder/x86/highbd_block_error_intrin_sse2.c b/av1/encoder/x86/highbd_block_error_intrin_sse2.c
index 4579e4e..2b7157f 100644
--- a/av1/encoder/x86/highbd_block_error_intrin_sse2.c
+++ b/av1/encoder/x86/highbd_block_error_intrin_sse2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <emmintrin.h>
diff --git a/av1/encoder/x86/highbd_fwd_txfm_avx2.c b/av1/encoder/x86/highbd_fwd_txfm_avx2.c
index a81378c..5fdf3f2 100644
--- a/av1/encoder/x86/highbd_fwd_txfm_avx2.c
+++ b/av1/encoder/x86/highbd_fwd_txfm_avx2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #include <assert.h>
 #include <immintrin.h> /*AVX2*/
diff --git a/av1/encoder/x86/highbd_fwd_txfm_sse4.c b/av1/encoder/x86/highbd_fwd_txfm_sse4.c
index 4aefa3d..44d8797 100644
--- a/av1/encoder/x86/highbd_fwd_txfm_sse4.c
+++ b/av1/encoder/x86/highbd_fwd_txfm_sse4.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #include <assert.h>
 #include <smmintrin.h> /* SSE4.1 */
diff --git a/av1/encoder/x86/highbd_temporal_filter_sse2.c b/av1/encoder/x86/highbd_temporal_filter_sse2.c
index af623b8..4d86fb9 100644
--- a/av1/encoder/x86/highbd_temporal_filter_sse2.c
+++ b/av1/encoder/x86/highbd_temporal_filter_sse2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/av1/encoder/x86/ml_sse3.c b/av1/encoder/x86/ml_sse3.c
index 89b1e6a..1529ec9 100644
--- a/av1/encoder/x86/ml_sse3.c
+++ b/av1/encoder/x86/ml_sse3.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <stdbool.h>
diff --git a/av1/encoder/x86/pickrst_avx2.c b/av1/encoder/x86/pickrst_avx2.c
index 5f9b5b9..d2dc280 100644
--- a/av1/encoder/x86/pickrst_avx2.c
+++ b/av1/encoder/x86/pickrst_avx2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <immintrin.h>  // AVX2
diff --git a/av1/encoder/x86/pickrst_sse4.c b/av1/encoder/x86/pickrst_sse4.c
index 43e7182..b7fc1e8 100644
--- a/av1/encoder/x86/pickrst_sse4.c
+++ b/av1/encoder/x86/pickrst_sse4.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/av1/encoder/x86/rdopt_avx2.c b/av1/encoder/x86/rdopt_avx2.c
index fefc036..3c9e076 100644
--- a/av1/encoder/x86/rdopt_avx2.c
+++ b/av1/encoder/x86/rdopt_avx2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/av1/encoder/x86/rdopt_sse4.c b/av1/encoder/x86/rdopt_sse4.c
index 67d94b4..2d35f10 100644
--- a/av1/encoder/x86/rdopt_sse4.c
+++ b/av1/encoder/x86/rdopt_sse4.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/av1/encoder/x86/temporal_filter_avx2.c b/av1/encoder/x86/temporal_filter_avx2.c
index 5f36737..d53da44 100644
--- a/av1/encoder/x86/temporal_filter_avx2.c
+++ b/av1/encoder/x86/temporal_filter_avx2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2019, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/av1/encoder/x86/temporal_filter_sse2.c b/av1/encoder/x86/temporal_filter_sse2.c
index 9fc92a6..8f204a7 100644
--- a/av1/encoder/x86/temporal_filter_sse2.c
+++ b/av1/encoder/x86/temporal_filter_sse2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2019, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/av1/encoder/x86/wedge_utils_avx2.c b/av1/encoder/x86/wedge_utils_avx2.c
index c06bad8..1a42639 100644
--- a/av1/encoder/x86/wedge_utils_avx2.c
+++ b/av1/encoder/x86/wedge_utils_avx2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/av1/encoder/x86/wedge_utils_sse2.c b/av1/encoder/x86/wedge_utils_sse2.c
index f3f4b8a..4b89f94 100644
--- a/av1/encoder/x86/wedge_utils_sse2.c
+++ b/av1/encoder/x86/wedge_utils_sse2.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/build/cmake/aom_config.c.template b/build/cmake/aom_config.c.template
index 62f0a10..19dc4cf 100644
--- a/build/cmake/aom_config.c.template
+++ b/build/cmake/aom_config.c.template
@@ -1,12 +1,12 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License and the
+ * Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+ * not distributed with this source code in the LICENSE file, you can obtain it
+ * at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+ * License 1.0 was not distributed with this source code in the PATENTS file, you
+ * can obtain it at aomedia.org/license/patent-license/.
  */
 #include "aom/aom_codec.h"
 static const char* const cfg = "${AOM_CMAKE_CONFIG}";
diff --git a/build/cmake/aom_config_defaults.cmake b/build/cmake/aom_config_defaults.cmake
index ddab3cc..e5acf79 100644
--- a/build/cmake/aom_config_defaults.cmake
+++ b/build/cmake/aom_config_defaults.cmake
@@ -1,12 +1,12 @@
 #
-# Copyright (c) 2016, Alliance for Open Media. All rights reserved
+# Copyright (c) 2021, Alliance for Open Media. All rights reserved
 #
-# This source code is subject to the terms of the BSD 2 Clause License and the
-# Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License was
-# not distributed with this source code in the LICENSE file, you can obtain it
-# at www.aomedia.org/license/software. If the Alliance for Open Media Patent
-# License 1.0 was not distributed with this source code in the PATENTS file, you
-# can obtain it at www.aomedia.org/license/patent.
+# This source code is subject to the terms of the BSD 3-Clause Clear License and
+# the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+# License was not distributed with this source code in the LICENSE file, you can
+# obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance
+# for Open Media Patent License 1.0 was not distributed with this source code in
+# the PATENTS file, you can obtain it at aomedia.org/license/patent-license/.
 
 include("${AOM_ROOT}/build/cmake/util.cmake")
 
@@ -86,6 +86,8 @@
 # Debugging flags.
 set_aom_config_var(CONFIG_DEBUG 0 "Debug build flag.")
 set_aom_config_var(CONFIG_MISMATCH_DEBUG 0 "Mismatch debugging flag.")
+set_aom_config_var(CONFIG_EXCLUDE_SIMD_MISMATCH 0
+                   "Exclude mismatch in SIMD functions for testing/debugging.")
 
 # AV1 feature flags.
 set_aom_config_var(CONFIG_ACCOUNTING 0 "Enables bit accounting.")
@@ -105,6 +107,7 @@
 set_aom_config_var(DECODE_WIDTH_LIMIT 0 "Set limit for decode width.")
 set_aom_config_var(CONFIG_TUNE_VMAF 0 "Enable encoding tuning for VMAF.")
 set_aom_config_var(CONFIG_USE_VMAF_RC 0 "Use libvmaf_rc tune for VMAF_NEG.")
+set_aom_config_var(CONFIG_SVC_ENCODER 0 "Use SVC encoder features.")
 
 # AV1 experiment flags.
 set_aom_config_var(CONFIG_SPEED_STATS 0 "AV1 experiment flag.")
@@ -135,8 +138,6 @@
                    "Use zero offset for non-normative bit upshift")
 
 # AV2 experiment flags.
-set_aom_config_var(CONFIG_REMOVE_DIST_WTD_COMP 1
-                   "AV2 experiment flag to remove dist_wtd_comp tool.")
 set_aom_config_var(CONFIG_REMOVE_DUAL_FILTER 1
                    "AV2 experiment flag to remove dual filter.")
 
@@ -152,16 +153,42 @@
 set_aom_config_var(
   CONFIG_ORIP 1
   "AV2 experiment flag to enable offset based refinement of intra prediction.")
+set_aom_config_var(CONFIG_ORIP_DC_DISABLED 0
+                   "AV2 experiment flag to disable ORIP for DC mode.")
+set_aom_config_var(CONFIG_ORIP_NONDC_DISABLED 0
+                   "AV2 experiment flag to disable ORIP for non-DC modes.")
 set_aom_config_var(CONFIG_IST 1 NUMBER
                    "AV2 experiment flag to enable intra secondary transform.")
 set_aom_config_var(CONFIG_NEW_INTER_MODES 1 NUMBER
                    "AV2 inter mode consolidation experiment flag")
 set_aom_config_var(CONFIG_SMVP_IMPROVEMENT 1 "Enable SMVP improvement")
 set_aom_config_var(CONFIG_TMVP_IMPROVEMENT 1 "Enable TMVP improvement")
+set_aom_config_var(CONFIG_REF_MV_BANK 1 "AV2 ref mv bank experiment flag")
+set_aom_config_var(CONFIG_NEW_REF_SIGNALING 0
+                   "AV2 experiment flag for the new reference syntax")
 set_aom_config_var(
   CONFIG_CCSO 1 "AV2 experiment flag to enable cross component sample offset.")
 set_aom_config_var(CONFIG_QBASED_QP_OFFSET 1
                    "AV2 experiment flag to adjust q_offset based on QP.")
+set_aom_config_var(CONFIG_OPTFLOW_REFINEMENT 1
+                   "AV2 experiment flag for optical flow MV refinement")
+set_aom_config_var(
+  CONFIG_IBP_DIR 1
+  "AV2 experiment flag to enable intra bi-prediction for directional modes.")
+set_aom_config_var(
+  CONFIG_IBP_DC 1
+  "AV2 experiment flag to enable intra bi-prediction for DC mode.")
+set_aom_config_var(CONFIG_AIMC 1 "AV2 adaptive intra mode coding flag.")
+set_aom_config_var(CONFIG_COMPLEXITY_SCALABLE_MVP 1
+                   "Enable complexity scalable mvp")
+set_aom_config_var(CONFIG_IST_FIX_B076 1
+                   "AV2 experiment flag to enable IST scan alignment.")
+set_aom_config_var(
+  CONFIG_CONTEXT_DERIVATION 1
+  "AV2 experiment flag to enable modified context derivation : CWG-B065.")
+# Source of throughput analysis : CWG-B065
+set_aom_config_var(CONFIG_THROUGHPUT_ANALYSIS 0
+                   "AV2 experiment flag to measure throughput.")
 #
 # Variables in this section control optional features of the build system.
 #
@@ -200,10 +227,10 @@
                    ON)
 
 # x86/x86_64 assembly/intrinsics flags.
-set_aom_option_var(ENABLE_MMX "Enables MMX optimizations on x86/x86_64 targets."
-                   ON)
-set_aom_option_var(ENABLE_SSE "Enables SSE optimizations on x86/x86_64 targets."
-                   ON)
+set_aom_option_var(ENABLE_MMX
+                   "Enables MMX optimizations on x86/x86_64 targets." ON)
+set_aom_option_var(ENABLE_SSE
+                   "Enables SSE optimizations on x86/x86_64 targets." ON)
 set_aom_option_var(ENABLE_SSE2
                    "Enables SSE2 optimizations on x86/x86_64 targets." ON)
 set_aom_option_var(ENABLE_SSE3
@@ -214,7 +241,7 @@
                    "Enables SSE4_1 optimizations on x86/x86_64 targets." ON)
 set_aom_option_var(ENABLE_SSE4_2
                    "Enables SSE4_2 optimizations on x86/x86_64 targets." ON)
-set_aom_option_var(ENABLE_AVX "Enables AVX optimizations on x86/x86_64 targets."
-                   ON)
+set_aom_option_var(ENABLE_AVX
+                   "Enables AVX optimizations on x86/x86_64 targets." ON)
 set_aom_option_var(ENABLE_AVX2
                    "Enables AVX2 optimizations on x86/x86_64 targets." ON)
diff --git a/build/cmake/aom_configure.cmake b/build/cmake/aom_configure.cmake
index 2fdc83a..08af3b1 100644
--- a/build/cmake/aom_configure.cmake
+++ b/build/cmake/aom_configure.cmake
@@ -1,12 +1,12 @@
 #
-# Copyright (c) 2016, Alliance for Open Media. All rights reserved
+# Copyright (c) 2021, Alliance for Open Media. All rights reserved
 #
-# This source code is subject to the terms of the BSD 2 Clause License and the
-# Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License was
-# not distributed with this source code in the LICENSE file, you can obtain it
-# at www.aomedia.org/license/software. If the Alliance for Open Media Patent
-# License 1.0 was not distributed with this source code in the PATENTS file, you
-# can obtain it at www.aomedia.org/license/patent.
+# This source code is subject to the terms of the BSD 3-Clause Clear License and
+# the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+# License was not distributed with this source code in the LICENSE file, you can
+# obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance
+# for Open Media Patent License 1.0 was not distributed with this source code in
+# the PATENTS file, you can obtain it at aomedia.org/license/patent-license/.
 #
 if(AOM_BUILD_CMAKE_AOM_CONFIGURE_CMAKE_)
   return()
@@ -32,7 +32,10 @@
 # Generate the user config settings.
 list(APPEND aom_build_vars ${AOM_CONFIG_VARS} ${AOM_OPTION_VARS})
 foreach(cache_var ${aom_build_vars})
-  get_property(cache_var_helpstring CACHE ${cache_var} PROPERTY HELPSTRING)
+  get_property(
+    cache_var_helpstring
+    CACHE ${cache_var}
+    PROPERTY HELPSTRING)
   if("${cache_var_helpstring}" STREQUAL "${cmake_cmdline_helpstring}")
     set(AOM_CMAKE_CONFIG "${AOM_CMAKE_CONFIG} -D${cache_var}=${${cache_var}}")
   endif()
@@ -42,24 +45,25 @@
 # Detect target CPU.
 if(NOT AOM_TARGET_CPU)
   string(TOLOWER "${CMAKE_SYSTEM_PROCESSOR}" cpu_lowercase)
-  if("${cpu_lowercase}" STREQUAL "amd64"
-     OR "${cpu_lowercase}" STREQUAL "x86_64")
+  if("${cpu_lowercase}" STREQUAL "amd64" OR "${cpu_lowercase}" STREQUAL
+                                            "x86_64")
     if(${CMAKE_SIZEOF_VOID_P} EQUAL 4)
       set(AOM_TARGET_CPU "x86")
     elseif(${CMAKE_SIZEOF_VOID_P} EQUAL 8)
       set(AOM_TARGET_CPU "x86_64")
     else()
       message(
-        FATAL_ERROR "--- Unexpected pointer size (${CMAKE_SIZEOF_VOID_P}) for\n"
-                    "      CMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME}\n"
-                    "      CMAKE_SYSTEM_PROCESSOR=${CMAKE_SYSTEM_PROCESSOR}\n"
-                    "      CMAKE_GENERATOR=${CMAKE_GENERATOR}\n")
+        FATAL_ERROR
+          "--- Unexpected pointer size (${CMAKE_SIZEOF_VOID_P}) for\n"
+          "      CMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME}\n"
+          "      CMAKE_SYSTEM_PROCESSOR=${CMAKE_SYSTEM_PROCESSOR}\n"
+          "      CMAKE_GENERATOR=${CMAKE_GENERATOR}\n")
     endif()
-  elseif("${cpu_lowercase}" STREQUAL "i386"
-         OR "${cpu_lowercase}" STREQUAL "x86")
+  elseif("${cpu_lowercase}" STREQUAL "i386" OR "${cpu_lowercase}" STREQUAL
+                                               "x86")
     set(AOM_TARGET_CPU "x86")
-  elseif("${cpu_lowercase}" MATCHES "^arm"
-         OR "${cpu_lowercase}" MATCHES "^mips")
+  elseif("${cpu_lowercase}" MATCHES "^arm" OR "${cpu_lowercase}" MATCHES
+                                              "^mips")
     set(AOM_TARGET_CPU "${cpu_lowercase}")
   elseif("${cpu_lowercase}" MATCHES "aarch64")
     set(AOM_TARGET_CPU "arm64")
@@ -109,8 +113,8 @@
     # TODO(tomfinegan): clang needs -pie in CMAKE_EXE_LINKER_FLAGS for this to
     # work.
     set(CMAKE_POSITION_INDEPENDENT_CODE ON)
-    if("${AOM_TARGET_SYSTEM}" STREQUAL "Linux"
-       AND "${AOM_TARGET_CPU}" MATCHES "^armv[78]")
+    if("${AOM_TARGET_SYSTEM}" STREQUAL "Linux" AND "${AOM_TARGET_CPU}" MATCHES
+                                                   "^armv[78]")
       set(AOM_AS_FLAGS ${AOM_AS_FLAGS} --defsym PIC=1)
     else()
       set(AOM_AS_FLAGS ${AOM_AS_FLAGS} -DPIC)
@@ -211,12 +215,15 @@
 
 if(NOT MSVC)
   aom_push_var(CMAKE_REQUIRED_LIBRARIES "m")
-  aom_check_c_compiles("fenv_check" "#define _GNU_SOURCE
+  aom_check_c_compiles(
+    "fenv_check"
+    "#define _GNU_SOURCE
                         #include <fenv.h>
                         void unused(void) {
                           (void)unused;
                           (void)feenableexcept(FE_DIVBYZERO | FE_INVALID);
-                        }" HAVE_FEXCEPT)
+                        }"
+    HAVE_FEXCEPT)
   aom_pop_var(CMAKE_REQUIRED_LIBRARIES)
 endif()
 
@@ -276,8 +283,8 @@
   add_compiler_flag_if_supported("-Wunused")
   add_compiler_flag_if_supported("-Wvla")
 
-  if(CMAKE_C_COMPILER_ID MATCHES "GNU"
-     AND "${SANITIZE}" MATCHES "address|undefined")
+  if(CMAKE_C_COMPILER_ID MATCHES "GNU" AND "${SANITIZE}" MATCHES
+                                           "address|undefined")
 
     # This combination has more stack overhead, so we account for it by
     # providing higher stack limit than usual.
@@ -334,9 +341,9 @@
 set(aom_config_asm_template "${AOM_CONFIG_DIR}/config/aom_config.asm.cmake")
 set(aom_config_h_template "${AOM_CONFIG_DIR}/config/aom_config.h.cmake")
 execute_process(
-  COMMAND ${CMAKE_COMMAND}
-          -DAOM_CONFIG_DIR=${AOM_CONFIG_DIR} -DAOM_ROOT=${AOM_ROOT} -P
-          "${AOM_ROOT}/build/cmake/generate_aom_config_templates.cmake")
+  COMMAND
+    ${CMAKE_COMMAND} -DAOM_CONFIG_DIR=${AOM_CONFIG_DIR} -DAOM_ROOT=${AOM_ROOT}
+    -P "${AOM_ROOT}/build/cmake/generate_aom_config_templates.cmake")
 
 # Generate aom_config.{asm,h}.
 configure_file("${aom_config_asm_template}"
@@ -359,15 +366,18 @@
   message(FATAL_ERROR "Perl is required to build libaom.")
 endif()
 
-set(AOM_RTCD_CONFIG_FILE_LIST "${AOM_ROOT}/aom_dsp/aom_dsp_rtcd_defs.pl"
-                              "${AOM_ROOT}/aom_scale/aom_scale_rtcd.pl"
-                              "${AOM_ROOT}/av1/common/av1_rtcd_defs.pl")
-set(AOM_RTCD_HEADER_FILE_LIST "${AOM_CONFIG_DIR}/config/aom_dsp_rtcd.h"
-                              "${AOM_CONFIG_DIR}/config/aom_scale_rtcd.h"
-                              "${AOM_CONFIG_DIR}/config/av1_rtcd.h")
-set(AOM_RTCD_SOURCE_FILE_LIST "${AOM_ROOT}/aom_dsp/aom_dsp_rtcd.c"
-                              "${AOM_ROOT}/aom_scale/aom_scale_rtcd.c"
-                              "${AOM_ROOT}/av1/common/av1_rtcd.c")
+set(AOM_RTCD_CONFIG_FILE_LIST
+    "${AOM_ROOT}/aom_dsp/aom_dsp_rtcd_defs.pl"
+    "${AOM_ROOT}/aom_scale/aom_scale_rtcd.pl"
+    "${AOM_ROOT}/av1/common/av1_rtcd_defs.pl")
+set(AOM_RTCD_HEADER_FILE_LIST
+    "${AOM_CONFIG_DIR}/config/aom_dsp_rtcd.h"
+    "${AOM_CONFIG_DIR}/config/aom_scale_rtcd.h"
+    "${AOM_CONFIG_DIR}/config/av1_rtcd.h")
+set(AOM_RTCD_SOURCE_FILE_LIST
+    "${AOM_ROOT}/aom_dsp/aom_dsp_rtcd.c"
+    "${AOM_ROOT}/aom_scale/aom_scale_rtcd.c"
+    "${AOM_ROOT}/av1/common/av1_rtcd.c")
 set(AOM_RTCD_SYMBOL_LIST aom_dsp_rtcd aom_scale_rtcd av1_rtcd)
 list(LENGTH AOM_RTCD_SYMBOL_LIST AOM_RTCD_CUSTOM_COMMAND_COUNT)
 math(EXPR AOM_RTCD_CUSTOM_COMMAND_COUNT "${AOM_RTCD_CUSTOM_COMMAND_COUNT} - 1")
@@ -380,16 +390,14 @@
   execute_process(
     COMMAND
       ${PERL_EXECUTABLE} "${AOM_ROOT}/build/cmake/rtcd.pl"
-      --arch=${AOM_TARGET_CPU}
-      --sym=${AOM_RTCD_SYMBOL} ${AOM_RTCD_FLAGS}
+      --arch=${AOM_TARGET_CPU} --sym=${AOM_RTCD_SYMBOL} ${AOM_RTCD_FLAGS}
       --config=${AOM_CONFIG_DIR}/config/aom_config.h ${AOM_RTCD_CONFIG_FILE}
     OUTPUT_FILE ${AOM_RTCD_HEADER_FILE})
 endforeach()
 
 # Generate aom_version.h.
-execute_process(COMMAND ${CMAKE_COMMAND}
-                        -DAOM_CONFIG_DIR=${AOM_CONFIG_DIR}
-                        -DAOM_ROOT=${AOM_ROOT}
-                        -DGIT_EXECUTABLE=${GIT_EXECUTABLE}
-                        -DPERL_EXECUTABLE=${PERL_EXECUTABLE} -P
-                        "${AOM_ROOT}/build/cmake/version.cmake")
+execute_process(
+  COMMAND
+    ${CMAKE_COMMAND} -DAOM_CONFIG_DIR=${AOM_CONFIG_DIR} -DAOM_ROOT=${AOM_ROOT}
+    -DGIT_EXECUTABLE=${GIT_EXECUTABLE} -DPERL_EXECUTABLE=${PERL_EXECUTABLE} -P
+    "${AOM_ROOT}/build/cmake/version.cmake")
diff --git a/build/cmake/aom_experiment_deps.cmake b/build/cmake/aom_experiment_deps.cmake
index 2e36157..4d94494 100644
--- a/build/cmake/aom_experiment_deps.cmake
+++ b/build/cmake/aom_experiment_deps.cmake
@@ -1,12 +1,12 @@
 #
-# Copyright (c) 2017, Alliance for Open Media. All rights reserved
+# Copyright (c) 2021, Alliance for Open Media. All rights reserved
 #
-# This source code is subject to the terms of the BSD 2 Clause License and the
-# Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License was
-# not distributed with this source code in the LICENSE file, you can obtain it
-# at www.aomedia.org/license/software. If the Alliance for Open Media Patent
-# License 1.0 was not distributed with this source code in the PATENTS file, you
-# can obtain it at www.aomedia.org/license/patent.
+# This source code is subject to the terms of the BSD 3-Clause Clear License and
+# the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+# License was not distributed with this source code in the LICENSE file, you can
+# obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance
+# for Open Media Patent License 1.0 was not distributed with this source code in
+# the PATENTS file, you can obtain it at aomedia.org/license/patent-license/.
 #
 if(AOM_BUILD_CMAKE_AOM_EXPERIMENT_DEPS_CMAKE_)
   return()
@@ -25,4 +25,18 @@
     change_config_and_warn(CONFIG_DIST_8X8 0 CONFIG_MULTITHREAD)
   endif()
 
+  # CONFIG_OPTFLOW_REFINEMENT requires CONFIG_NEW_INTER_MODES. If
+  # CONFIG_NEW_INTER_MODES is off, we also turn off CONFIG_OPTFLOW_REFINEMENT.
+  if(NOT CONFIG_NEW_INTER_MODES AND CONFIG_OPTFLOW_REFINEMENT)
+    change_config_and_warn(CONFIG_OPTFLOW_REFINEMENT 0 !CONFIG_NEW_INTER_MODES)
+  endif()
+
+  if(CONFIG_IST)
+    change_config_and_warn(CONFIG_IST_FIX_B076 1 CONFIG_IST)
+  endif()
+
+  if(CONFIG_THROUGHPUT_ANALYSIS)
+    change_config_and_warn(CONFIG_ACCOUNTING 1 CONFIG_THROUGHPUT_ANALYSIS)
+  endif()
+
 endmacro()
diff --git a/build/cmake/aom_install.cmake b/build/cmake/aom_install.cmake
index cd40fe4..816611c 100644
--- a/build/cmake/aom_install.cmake
+++ b/build/cmake/aom_install.cmake
@@ -1,26 +1,31 @@
 #
-# Copyright (c) 2018, Alliance for Open Media. All rights reserved
+# Copyright (c) 2021, Alliance for Open Media. All rights reserved
 #
-# This source code is subject to the terms of the BSD 2 Clause License and the
-# Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License was
-# not distributed with this source code in the LICENSE file, you can obtain it
-# at www.aomedia.org/license/software. If the Alliance for Open Media Patent
-# License 1.0 was not distributed with this source code in the PATENTS file, you
-# can obtain it at www.aomedia.org/license/patent.
+# This source code is subject to the terms of the BSD 3-Clause Clear License and
+# the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+# License was not distributed with this source code in the LICENSE file, you can
+# obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance
+# for Open Media Patent License 1.0 was not distributed with this source code in
+# the PATENTS file, you can obtain it at aomedia.org/license/patent-license/.
 #
-list(APPEND AOM_INSTALL_INCS "${AOM_ROOT}/aom/aom.h"
-            "${AOM_ROOT}/aom/aom_codec.h" "${AOM_ROOT}/aom/aom_frame_buffer.h"
-            "${AOM_ROOT}/aom/aom_image.h" "${AOM_ROOT}/aom/aom_integer.h"
-            "${AOM_ROOT}/aom/aom.h")
+list(
+  APPEND
+  AOM_INSTALL_INCS
+  "${AOM_ROOT}/aom/aom.h"
+  "${AOM_ROOT}/aom/aom_codec.h"
+  "${AOM_ROOT}/aom/aom_frame_buffer.h"
+  "${AOM_ROOT}/aom/aom_image.h"
+  "${AOM_ROOT}/aom/aom_integer.h"
+  "${AOM_ROOT}/aom/aom.h")
 
 if(CONFIG_AV1_DECODER)
   list(APPEND AOM_INSTALL_INCS "${AOM_ROOT}/aom/aom_decoder.h"
-              "${AOM_ROOT}/aom/aomdx.h")
+       "${AOM_ROOT}/aom/aomdx.h")
 endif()
 
 if(CONFIG_AV1_ENCODER)
   list(APPEND AOM_INSTALL_INCS "${AOM_ROOT}/aom/aomcx.h"
-              "${AOM_ROOT}/aom/aom_encoder.h")
+       "${AOM_ROOT}/aom/aom_encoder.h")
 endif()
 
 # Generate aom.pc and setup dependencies to ensure it is created when necessary.
@@ -38,21 +43,24 @@
     # Setup a rule to generate aom.pc.
     add_custom_command(
       OUTPUT "${AOM_PKG_CONFIG_FILE}"
-      COMMAND ${CMAKE_COMMAND} ARGS
-              -DAOM_CONFIG_DIR=${AOM_CONFIG_DIR} -DAOM_ROOT=${AOM_ROOT}
-              -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
-              -DCMAKE_INSTALL_BINDIR=${CMAKE_INSTALL_BINDIR}
-              -DCMAKE_INSTALL_INCLUDEDIR=${CMAKE_INSTALL_INCLUDEDIR}
-              -DCMAKE_INSTALL_LIBDIR=${CMAKE_INSTALL_LIBDIR}
-              -DCMAKE_PROJECT_NAME=${CMAKE_PROJECT_NAME}
-              -DCONFIG_MULTITHREAD=${CONFIG_MULTITHREAD}
-              -DHAVE_PTHREAD_H=${HAVE_PTHREAD_H} -P
-              "${AOM_ROOT}/build/cmake/pkg_config.cmake"
+      COMMAND
+        ${CMAKE_COMMAND} ARGS -DAOM_CONFIG_DIR=${AOM_CONFIG_DIR}
+        -DAOM_ROOT=${AOM_ROOT} -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
+        -DCMAKE_INSTALL_BINDIR=${CMAKE_INSTALL_BINDIR}
+        -DCMAKE_INSTALL_INCLUDEDIR=${CMAKE_INSTALL_INCLUDEDIR}
+        -DCMAKE_INSTALL_LIBDIR=${CMAKE_INSTALL_LIBDIR}
+        -DCMAKE_PROJECT_NAME=${CMAKE_PROJECT_NAME}
+        -DCONFIG_MULTITHREAD=${CONFIG_MULTITHREAD}
+        -DHAVE_PTHREAD_H=${HAVE_PTHREAD_H} -P
+        "${AOM_ROOT}/build/cmake/pkg_config.cmake"
       COMMENT "Writing aom.pc"
       VERBATIM)
 
     # Explicitly add a dependency on the pkg-config file to ensure it's built.
-    get_property(aom_pc_sources TARGET aom_pc PROPERTY SOURCES)
+    get_property(
+      aom_pc_sources
+      TARGET aom_pc
+      PROPERTY SOURCES)
     set_source_files_properties(${aom_pc_sources} OBJECT_DEPENDS
                                 "${AOM_PKG_CONFIG_FILE}")
 
@@ -85,12 +93,12 @@
     install(
       FILES "${AOM_PKG_CONFIG_FILE}"
       DESTINATION "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/pkgconfig")
-    install(TARGETS ${AOM_INSTALL_LIBS} DESTINATION
-                    "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
+    install(TARGETS ${AOM_INSTALL_LIBS}
+            DESTINATION "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
 
     if(ENABLE_EXAMPLES)
-      install(TARGETS ${AOM_INSTALL_BINS} DESTINATION
-                      "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}")
+      install(TARGETS ${AOM_INSTALL_BINS}
+              DESTINATION "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}")
     endif()
   endif()
 endmacro()
diff --git a/build/cmake/aom_optimization.cmake b/build/cmake/aom_optimization.cmake
index d8b258f..42045a4 100644
--- a/build/cmake/aom_optimization.cmake
+++ b/build/cmake/aom_optimization.cmake
@@ -1,12 +1,12 @@
 #
-# Copyright (c) 2017, Alliance for Open Media. All rights reserved
+# Copyright (c) 2021, Alliance for Open Media. All rights reserved
 #
-# This source code is subject to the terms of the BSD 2 Clause License and the
-# Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License was
-# not distributed with this source code in the LICENSE file, you can obtain it
-# at www.aomedia.org/license/software. If the Alliance for Open Media Patent
-# License 1.0 was not distributed with this source code in the PATENTS file, you
-# can obtain it at www.aomedia.org/license/patent.
+# This source code is subject to the terms of the BSD 3-Clause Clear License and
+# the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+# License was not distributed with this source code in the LICENSE file, you can
+# obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance
+# for Open Media Patent License 1.0 was not distributed with this source code in
+# the PATENTS file, you can obtain it at aomedia.org/license/patent-license/.
 #
 if(AOM_BUILD_CMAKE_AOM_OPTIMIZATION_CMAKE_)
   return()
@@ -19,9 +19,13 @@
 # variable named by $translated_flag (or unset it, when MSVC needs no flag).
 function(get_msvc_intrinsic_flag flag translated_flag)
   if("${flag}" STREQUAL "-mavx")
-    set(${translated_flag} "/arch:AVX" PARENT_SCOPE)
+    set(${translated_flag}
+        "/arch:AVX"
+        PARENT_SCOPE)
   elseif("${flag}" STREQUAL "-mavx2")
-    set(${translated_flag} "/arch:AVX2" PARENT_SCOPE)
+    set(${translated_flag}
+        "/arch:AVX2"
+        PARENT_SCOPE)
   else()
 
     # MSVC does not need flags for intrinsics flavors other than AVX/AVX2.
@@ -75,7 +79,9 @@
 
   # Add the new lib target to the global list of aom library targets.
   list(APPEND AOM_LIB_TARGETS ${target_name})
-  set(AOM_LIB_TARGETS ${AOM_LIB_TARGETS} PARENT_SCOPE)
+  set(AOM_LIB_TARGETS
+      ${AOM_LIB_TARGETS}
+      PARENT_SCOPE)
 endfunction()
 
 # Adds sources in list named by $sources to $target and adds $flag to the
@@ -87,7 +93,10 @@
   endif()
   if(flag)
     foreach(source ${${sources}})
-      set_property(SOURCE ${source} APPEND PROPERTY COMPILE_FLAGS ${flag})
+      set_property(
+        SOURCE ${source}
+        APPEND
+        PROPERTY COMPILE_FLAGS ${flag})
     endforeach()
   endif()
 endfunction()
@@ -99,8 +108,8 @@
   if("${AOM_TARGET_CPU}" STREQUAL "x86_64")
     if("${AOM_TARGET_SYSTEM}" STREQUAL "Darwin")
       set(objformat "macho64")
-    elseif("${AOM_TARGET_SYSTEM}" STREQUAL "MSYS"
-           OR "${AOM_TARGET_SYSTEM}" STREQUAL "Windows")
+    elseif("${AOM_TARGET_SYSTEM}" STREQUAL "MSYS" OR "${AOM_TARGET_SYSTEM}"
+                                                     STREQUAL "Windows")
       set(objformat "win64")
     else()
       set(objformat "elf64")
@@ -108,8 +117,8 @@
   elseif("${AOM_TARGET_CPU}" STREQUAL "x86")
     if("${AOM_TARGET_SYSTEM}" STREQUAL "Darwin")
       set(objformat "macho32")
-    elseif("${AOM_TARGET_SYSTEM}" STREQUAL "MSYS"
-           OR "${AOM_TARGET_SYSTEM}" STREQUAL "Windows")
+    elseif("${AOM_TARGET_SYSTEM}" STREQUAL "MSYS" OR "${AOM_TARGET_SYSTEM}"
+                                                     STREQUAL "Windows")
       set(objformat "win32")
     else()
       set(objformat "elf32")
@@ -119,7 +128,9 @@
       FATAL_ERROR "Unknown obj format: ${AOM_TARGET_CPU}-${AOM_TARGET_SYSTEM}")
   endif()
 
-  set(${out_format} ${objformat} PARENT_SCOPE)
+  set(${out_format}
+      ${objformat}
+      PARENT_SCOPE)
 endfunction()
 
 # Adds library target named $lib_name for ASM files in variable named by
@@ -144,14 +155,14 @@
   foreach(asm_source ${${asm_sources}})
     get_filename_component(asm_source_name "${asm_source}" NAME)
     set(asm_object "${asm_lib_obj_dir}/${asm_source_name}.o")
-    add_custom_command(OUTPUT "${asm_object}"
-                       COMMAND ${AS_EXECUTABLE} ARGS ${AOM_AS_FLAGS}
-                               -I${AOM_ROOT}/ -I${AOM_CONFIG_DIR}/ -o
-                               "${asm_object}" "${asm_source}"
-                       DEPENDS "${asm_source}"
-                       COMMENT "Building ASM object ${asm_object}"
-                       WORKING_DIRECTORY "${AOM_CONFIG_DIR}"
-                       VERBATIM)
+    add_custom_command(
+      OUTPUT "${asm_object}"
+      COMMAND ${AS_EXECUTABLE} ARGS ${AOM_AS_FLAGS} -I${AOM_ROOT}/
+              -I${AOM_CONFIG_DIR}/ -o "${asm_object}" "${asm_source}"
+      DEPENDS "${asm_source}"
+      COMMENT "Building ASM object ${asm_object}"
+      WORKING_DIRECTORY "${AOM_CONFIG_DIR}"
+      VERBATIM)
     target_sources(aom PRIVATE "${asm_object}")
     if(BUILD_SHARED_LIBS)
       target_sources(aom_static PRIVATE "${asm_object}")
@@ -167,7 +178,9 @@
 
   # Add the new lib target to the global list of aom library targets.
   list(APPEND AOM_LIB_TARGETS ${lib_name})
-  set(AOM_LIB_TARGETS ${AOM_LIB_TARGETS} PARENT_SCOPE)
+  set(AOM_LIB_TARGETS
+      ${AOM_LIB_TARGETS}
+      PARENT_SCOPE)
 endfunction()
 
 # Terminates generation if nasm found in PATH does not meet requirements.
@@ -187,8 +200,8 @@
         message(
           FATAL_ERROR "Unsupported nasm: macho32 object format not supported.")
       endif()
-    elseif("${AOM_TARGET_SYSTEM}" STREQUAL "MSYS"
-           OR "${AOM_TARGET_SYSTEM}" STREQUAL "Windows")
+    elseif("${AOM_TARGET_SYSTEM}" STREQUAL "MSYS" OR "${AOM_TARGET_SYSTEM}"
+                                                     STREQUAL "Windows")
       if(NOT "${nasm_helptext}" MATCHES "win32")
         message(
           FATAL_ERROR "Unsupported nasm: win32 object format not supported.")
@@ -205,8 +218,8 @@
         message(
           FATAL_ERROR "Unsupported nasm: macho64 object format not supported.")
       endif()
-    elseif("${AOM_TARGET_SYSTEM}" STREQUAL "MSYS"
-           OR "${AOM_TARGET_SYSTEM}" STREQUAL "Windows")
+    elseif("${AOM_TARGET_SYSTEM}" STREQUAL "MSYS" OR "${AOM_TARGET_SYSTEM}"
+                                                     STREQUAL "Windows")
       if(NOT "${nasm_helptext}" MATCHES "win64")
         message(
           FATAL_ERROR "Unsupported nasm: win64 object format not supported.")
@@ -227,10 +240,10 @@
 function(add_rtcd_build_step config output source symbol)
   add_custom_command(
     OUTPUT ${output}
-    COMMAND ${PERL_EXECUTABLE} ARGS "${AOM_ROOT}/build/cmake/rtcd.pl"
-            --arch=${AOM_TARGET_CPU}
-            --sym=${symbol} ${AOM_RTCD_FLAGS}
-            --config=${AOM_CONFIG_DIR}/config/aom_config.h ${config} > ${output}
+    COMMAND
+      ${PERL_EXECUTABLE} ARGS "${AOM_ROOT}/build/cmake/rtcd.pl"
+      --arch=${AOM_TARGET_CPU} --sym=${symbol} ${AOM_RTCD_FLAGS}
+      --config=${AOM_CONFIG_DIR}/config/aom_config.h ${config} > ${output}
     DEPENDS ${config}
     COMMENT "Generating ${output}"
     WORKING_DIRECTORY ${AOM_CONFIG_DIR}
diff --git a/build/cmake/compiler_flags.cmake b/build/cmake/compiler_flags.cmake
index 24484bc..3d23af5 100644
--- a/build/cmake/compiler_flags.cmake
+++ b/build/cmake/compiler_flags.cmake
@@ -1,12 +1,12 @@
 #
-# Copyright (c) 2016, Alliance for Open Media. All rights reserved
+# Copyright (c) 2021, Alliance for Open Media. All rights reserved
 #
-# This source code is subject to the terms of the BSD 2 Clause License and the
-# Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License was
-# not distributed with this source code in the LICENSE file, you can obtain it
-# at www.aomedia.org/license/software. If the Alliance for Open Media Patent
-# License 1.0 was not distributed with this source code in the PATENTS file, you
-# can obtain it at www.aomedia.org/license/patent.
+# This source code is subject to the terms of the BSD 3-Clause Clear License and
+# the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+# License was not distributed with this source code in the LICENSE file, you can
+# obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance
+# for Open Media Patent License 1.0 was not distributed with this source code in
+# the PATENTS file, you can obtain it at aomedia.org/license/patent-license/.
 #
 if(AOM_BUILD_CMAKE_COMPILER_FLAGS_CMAKE_)
   return()
@@ -30,9 +30,13 @@
 function(is_flag_present flag_cache flag out_is_present)
   string(FIND "${${flag_cache}}" "${flag}" flag_pos)
   if(${flag_pos} EQUAL -1)
-    set(${out_is_present} NO PARENT_SCOPE)
+    set(${out_is_present}
+        NO
+        PARENT_SCOPE)
   else()
-    set(${out_is_present} YES PARENT_SCOPE)
+    set(${out_is_present}
+        YES
+        PARENT_SCOPE)
   endif()
 endfunction()
 
@@ -40,7 +44,9 @@
 function(append_flag flags flag)
   string(FIND "${${flags}}" "${flag}" found)
   if(${found} EQUAL -1)
-    set(${flags} "${${flags}} ${flag}" CACHE STRING "" FORCE)
+    set(${flags}
+        "${${flags}} ${flag}"
+        CACHE STRING "" FORCE)
   endif()
 endfunction()
 
@@ -142,7 +148,9 @@
   append_flag(AOM_C_FLAGS "${c_flag}")
   if(update_c_flags)
     foreach(config ${AOM_C_CONFIGS})
-      set(${config} "${${config}} ${c_flag}" CACHE STRING "" FORCE)
+      set(${config}
+          "${${config}} ${c_flag}"
+          CACHE STRING "" FORCE)
     endforeach()
   endif()
 endfunction()
@@ -178,7 +186,9 @@
   append_flag(AOM_CXX_FLAGS "${cxx_flag}")
   if(update_cxx_flags)
     foreach(config ${AOM_CXX_CONFIGS})
-      set(${config} "${${config}} ${cxx_flag}" CACHE STRING "" FORCE)
+      set(${config}
+          "${${config}} ${cxx_flag}"
+          CACHE STRING "" FORCE)
     endforeach()
   endif()
 endfunction()
@@ -224,7 +234,9 @@
   endif()
 
   foreach(config ${AOM_C_CONFIGS})
-    set(${config} "${${config}} ${preproc_def}" CACHE STRING "" FORCE)
+    set(${config}
+        "${${config}} ${preproc_def}"
+        CACHE STRING "" FORCE)
   endforeach()
 endfunction()
 
@@ -238,7 +250,9 @@
   endif()
 
   foreach(config ${AOM_CXX_CONFIGS})
-    set(${config} "${${config}} ${preproc_def}" CACHE STRING "" FORCE)
+    set(${config}
+        "${${config}} ${preproc_def}"
+        CACHE STRING "" FORCE)
   endforeach()
 endfunction()
 
diff --git a/build/cmake/compiler_tests.cmake b/build/cmake/compiler_tests.cmake
index 0402832..5361151 100644
--- a/build/cmake/compiler_tests.cmake
+++ b/build/cmake/compiler_tests.cmake
@@ -1,12 +1,12 @@
 #
-# Copyright (c) 2016, Alliance for Open Media. All rights reserved
+# Copyright (c) 2021, Alliance for Open Media. All rights reserved
 #
-# This source code is subject to the terms of the BSD 2 Clause License and the
-# Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License was
-# not distributed with this source code in the LICENSE file, you can obtain it
-# at www.aomedia.org/license/software. If the Alliance for Open Media Patent
-# License 1.0 was not distributed with this source code in the PATENTS file, you
-# can obtain it at www.aomedia.org/license/patent.
+# This source code is subject to the terms of the BSD 3-Clause Clear License and
+# the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+# License was not distributed with this source code in the LICENSE file, you can
+# obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance
+# for Open Media Patent License 1.0 was not distributed with this source code in
+# the PATENTS file, you can obtain it at aomedia.org/license/patent-license/.
 #
 if(AOM_BUILD_CMAKE_COMPILER_TESTS_CMAKE_)
   return()
@@ -57,12 +57,18 @@
 set(AOM_CXX_FAILED_TESTS)
 
 function(aom_push_var var new_value)
-  set(SAVED_${var} ${${var}} PARENT_SCOPE)
-  set(${var} "${${var}} ${new_value}" PARENT_SCOPE)
+  set(SAVED_${var}
+      ${${var}}
+      PARENT_SCOPE)
+  set(${var}
+      "${${var}} ${new_value}"
+      PARENT_SCOPE)
 endfunction()
 
 function(aom_pop_var var)
-  set(var ${SAVED_${var}} PARENT_SCOPE)
+  set(var
+      ${SAVED_${var}}
+      PARENT_SCOPE)
   unset(SAVED_${var} PARENT_SCOPE)
 endfunction()
 
@@ -84,7 +90,9 @@
     unset(C_TEST_COMPILED CACHE)
     message("Running C compiler test: ${test_name}")
     check_c_source_compiles("${test_source} ${AOM_C_MAIN}" C_TEST_COMPILED)
-    set(${result_var} ${C_TEST_COMPILED} PARENT_SCOPE)
+    set(${result_var}
+        ${C_TEST_COMPILED}
+        PARENT_SCOPE)
 
     if(C_TEST_COMPILED)
       set(AOM_C_PASSED_TESTS
@@ -97,7 +105,9 @@
       message("C Compiler test ${test_name} failed.")
     endif()
   elseif(NOT ${C_TEST_PASSED} EQUAL -1)
-    set(${result_var} 1 PARENT_SCOPE)
+    set(${result_var}
+        1
+        PARENT_SCOPE)
   else() # ${C_TEST_FAILED} NOT EQUAL -1
     unset(${result_var} PARENT_SCOPE)
   endif()
@@ -122,7 +132,9 @@
     message("Running CXX compiler test: ${test_name}")
     check_cxx_source_compiles("${test_source} ${AOM_CXX_MAIN}"
                               CXX_TEST_COMPILED)
-    set(${result_var} ${CXX_TEST_COMPILED} PARENT_SCOPE)
+    set(${result_var}
+        ${CXX_TEST_COMPILED}
+        PARENT_SCOPE)
 
     if(CXX_TEST_COMPILED)
       set(AOM_CXX_PASSED_TESTS
@@ -135,7 +147,9 @@
       message("CXX Compiler test ${test_name} failed.")
     endif()
   elseif(NOT ${CXX_TEST_PASSED} EQUAL -1)
-    set(${result_var} 1 PARENT_SCOPE)
+    set(${result_var}
+        1
+        PARENT_SCOPE)
   else() # ${CXX_TEST_FAILED} NOT EQUAL -1
     unset(${result_var} PARENT_SCOPE)
   endif()
@@ -152,28 +166,34 @@
   aom_check_c_compiles(${test_name} ${test_source} C_PASSED)
   aom_check_cxx_compiles(${test_name} ${test_source} CXX_PASSED)
   if(C_PASSED AND CXX_PASSED)
-    set(${result_var} 1 PARENT_SCOPE)
+    set(${result_var}
+        1
+        PARENT_SCOPE)
   else()
-    set(${result_var} 0 PARENT_SCOPE)
+    set(${result_var}
+        0
+        PARENT_SCOPE)
   endif()
 endfunction()
 
 # When inline support is detected for the current compiler the supported
 # inlining keyword is written to $result in caller scope.
 function(aom_get_inline result)
-  aom_check_source_compiles("inline_check_1"
-                            "static inline void function(void) {}"
-                            HAVE_INLINE_1)
+  aom_check_source_compiles(
+    "inline_check_1" "static inline void function(void) {}" HAVE_INLINE_1)
   if(HAVE_INLINE_1 EQUAL 1)
-    set(${result} "inline" PARENT_SCOPE)
+    set(${result}
+        "inline"
+        PARENT_SCOPE)
     return()
   endif()
 
   # Check __inline.
-  aom_check_source_compiles("inline_check_2"
-                            "static __inline void function(void) {}"
-                            HAVE_INLINE_2)
+  aom_check_source_compiles(
+    "inline_check_2" "static __inline void function(void) {}" HAVE_INLINE_2)
   if(HAVE_INLINE_2 EQUAL 1)
-    set(${result} "__inline" PARENT_SCOPE)
+    set(${result}
+        "__inline"
+        PARENT_SCOPE)
   endif()
 endfunction()
diff --git a/build/cmake/cpu.cmake b/build/cmake/cpu.cmake
index ef2d755..e050217 100644
--- a/build/cmake/cpu.cmake
+++ b/build/cmake/cpu.cmake
@@ -1,12 +1,12 @@
 #
-# Copyright (c) 2017, Alliance for Open Media. All rights reserved
+# Copyright (c) 2021, Alliance for Open Media. All rights reserved
 #
-# This source code is subject to the terms of the BSD 2 Clause License and the
-# Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License was
-# not distributed with this source code in the LICENSE file, you can obtain it
-# at www.aomedia.org/license/software. If the Alliance for Open Media Patent
-# License 1.0 was not distributed with this source code in the PATENTS file, you
-# can obtain it at www.aomedia.org/license/patent.
+# This source code is subject to the terms of the BSD 3-Clause Clear License and
+# the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+# License was not distributed with this source code in the LICENSE file, you can
+# obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance
+# for Open Media Patent License 1.0 was not distributed with this source code in
+# the PATENTS file, you can obtain it at aomedia.org/license/patent-license/.
 #
 
 if("${AOM_TARGET_CPU}" MATCHES "^arm")
diff --git a/build/cmake/dist.cmake b/build/cmake/dist.cmake
index 5b9fc95..21aea67 100644
--- a/build/cmake/dist.cmake
+++ b/build/cmake/dist.cmake
@@ -1,12 +1,12 @@
 #
-# Copyright (c) 2017, Alliance for Open Media. All rights reserved
+# Copyright (c) 2021, Alliance for Open Media. All rights reserved
 #
-# This source code is subject to the terms of the BSD 2 Clause License and the
-# Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License was
-# not distributed with this source code in the LICENSE file, you can obtain it
-# at www.aomedia.org/license/software. If the Alliance for Open Media Patent
-# License 1.0 was not distributed with this source code in the PATENTS file, you
-# can obtain it at www.aomedia.org/license/patent.
+# This source code is subject to the terms of the BSD 3-Clause Clear License and
+# the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+# License was not distributed with this source code in the LICENSE file, you can
+# obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance
+# for Open Media Patent License 1.0 was not distributed with this source code in
+# the PATENTS file, you can obtain it at aomedia.org/license/patent-license/.
 #
 cmake_minimum_required(VERSION 3.5)
 
@@ -14,11 +14,13 @@
 # $out_string. In CMake's eyes this converts the input string to a list.
 function(listify_string in_string out_string)
   string(REPLACE " " ";" ${out_string} ${in_string})
-  set(${out_string} "${${out_string}}" PARENT_SCOPE)
+  set(${out_string}
+      "${${out_string}}"
+      PARENT_SCOPE)
 endfunction()
 
-set(REQUIRED_ARGS "AOM_ROOT" "AOM_CONFIG_DIR" "AOM_DIST_DIR" "AOM_DIST_INCLUDES"
-                  "AOM_DIST_LIBS" "ENABLE_DOCS")
+set(REQUIRED_ARGS "AOM_ROOT" "AOM_CONFIG_DIR" "AOM_DIST_DIR"
+                  "AOM_DIST_INCLUDES" "AOM_DIST_LIBS" "ENABLE_DOCS")
 
 foreach(arg ${REQUIRED_ARGS})
   if("${${arg}}" STREQUAL "")
diff --git a/build/cmake/exports.cmake b/build/cmake/exports.cmake
index fa7842c..e0bfd12 100644
--- a/build/cmake/exports.cmake
+++ b/build/cmake/exports.cmake
@@ -1,12 +1,12 @@
 #
-# Copyright (c) 2017, Alliance for Open Media. All rights reserved
+# Copyright (c) 2021, Alliance for Open Media. All rights reserved
 #
-# This source code is subject to the terms of the BSD 2 Clause License and the
-# Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License was
-# not distributed with this source code in the LICENSE file, you can obtain it
-# at www.aomedia.org/license/software. If the Alliance for Open Media Patent
-# License 1.0 was not distributed with this source code in the PATENTS file, you
-# can obtain it at www.aomedia.org/license/patent.
+# This source code is subject to the terms of the BSD 3-Clause Clear License and
+# the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+# License was not distributed with this source code in the LICENSE file, you can
+# obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance
+# for Open Media Patent License 1.0 was not distributed with this source code in
+# the PATENTS file, you can obtain it at aomedia.org/license/patent-license/.
 #
 if(AOM_BUILD_CMAKE_EXPORTS_CMAKE_)
   return()
@@ -27,48 +27,48 @@
 
   set(aom_sym_file "${AOM_CONFIG_DIR}/libaom.${symbol_file_ext}")
 
-  add_custom_target(generate_exports
-                    COMMAND ${CMAKE_COMMAND}
-                            -DAOM_ROOT="${AOM_ROOT}"
-                            -DAOM_CONFIG_DIR="${AOM_CONFIG_DIR}"
-                            -DAOM_TARGET_SYSTEM=${AOM_TARGET_SYSTEM}
-                            -DAOM_SYM_FILE="${aom_sym_file}"
-                            -DAOM_MSVC=${MSVC}
-                            -DAOM_XCODE=${XCODE}
-                            -DCONFIG_NAME=$<CONFIG>
-                            -DCONFIG_AV1_DECODER=${CONFIG_AV1_DECODER}
-                            -DCONFIG_AV1_ENCODER=${CONFIG_AV1_ENCODER}
-                            -DCONFIG_INSPECTION=${CONFIG_INSPECTION}
-                            -DENABLE_TESTS=${ENABLE_TESTS}
-                            -P
-                            "${AOM_ROOT}/build/cmake/generate_exports.cmake"
-                    SOURCES ${AOM_EXPORTS_SOURCES}
-                    DEPENDS ${AOM_EXPORTS_SOURCES})
+  add_custom_target(
+    generate_exports
+    COMMAND
+      ${CMAKE_COMMAND} -DAOM_ROOT="${AOM_ROOT}"
+      -DAOM_CONFIG_DIR="${AOM_CONFIG_DIR}"
+      -DAOM_TARGET_SYSTEM=${AOM_TARGET_SYSTEM} -DAOM_SYM_FILE="${aom_sym_file}"
+      -DAOM_MSVC=${MSVC} -DAOM_XCODE=${XCODE} -DCONFIG_NAME=$<CONFIG>
+      -DCONFIG_AV1_DECODER=${CONFIG_AV1_DECODER}
+      -DCONFIG_AV1_ENCODER=${CONFIG_AV1_ENCODER}
+      -DCONFIG_INSPECTION=${CONFIG_INSPECTION} -DENABLE_TESTS=${ENABLE_TESTS} -P
+      "${AOM_ROOT}/build/cmake/generate_exports.cmake"
+    SOURCES ${AOM_EXPORTS_SOURCES}
+    DEPENDS ${AOM_EXPORTS_SOURCES})
 
   # Make libaom depend on the exports file, and set flags to pick it up when
   # creating the dylib.
   add_dependencies(aom generate_exports)
 
   if(APPLE)
-    set_property(TARGET aom
-                 APPEND_STRING
-                 PROPERTY LINK_FLAGS "-exported_symbols_list ${aom_sym_file}")
+    set_property(
+      TARGET aom
+      APPEND_STRING
+      PROPERTY LINK_FLAGS "-exported_symbols_list ${aom_sym_file}")
   elseif(WIN32)
     if(NOT MSVC)
-      set_property(TARGET aom
-                   APPEND_STRING
-                   PROPERTY LINK_FLAGS "-Wl,--version-script ${aom_sym_file}")
+      set_property(
+        TARGET aom
+        APPEND_STRING
+        PROPERTY LINK_FLAGS "-Wl,--version-script ${aom_sym_file}")
     else()
-      set_property(TARGET aom
-                   APPEND_STRING
-                   PROPERTY LINK_FLAGS "/DEF:${aom_sym_file}")
+      set_property(
+        TARGET aom
+        APPEND_STRING
+        PROPERTY LINK_FLAGS "/DEF:${aom_sym_file}")
     endif()
 
     # TODO(tomfinegan): Sort out the import lib situation and flags for MSVC.
 
   else()
-    set_property(TARGET aom
-                 APPEND_STRING
-                 PROPERTY LINK_FLAGS "-Wl,--version-script,${aom_sym_file}")
+    set_property(
+      TARGET aom
+      APPEND_STRING
+      PROPERTY LINK_FLAGS "-Wl,--version-script,${aom_sym_file}")
   endif()
 endfunction()
diff --git a/build/cmake/exports_sources.cmake b/build/cmake/exports_sources.cmake
index 46bf001..72d418d 100644
--- a/build/cmake/exports_sources.cmake
+++ b/build/cmake/exports_sources.cmake
@@ -1,12 +1,12 @@
 #
-# Copyright (c) 2017, Alliance for Open Media. All rights reserved
+# Copyright (c) 2021, Alliance for Open Media. All rights reserved
 #
-# This source code is subject to the terms of the BSD 2 Clause License and the
-# Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License was
-# not distributed with this source code in the LICENSE file, you can obtain it
-# at www.aomedia.org/license/software. If the Alliance for Open Media Patent
-# License 1.0 was not distributed with this source code in the PATENTS file, you
-# can obtain it at www.aomedia.org/license/patent.
+# This source code is subject to the terms of the BSD 3-Clause Clear License and
+# the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+# License was not distributed with this source code in the LICENSE file, you can
+# obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance
+# for Open Media Patent License 1.0 was not distributed with this source code in
+# the PATENTS file, you can obtain it at aomedia.org/license/patent-license/.
 #
 if(AOM_BUILD_CMAKE_EXPORTS_SOURCES_CMAKE_)
   return()
@@ -14,11 +14,11 @@
 set(AOM_BUILD_CMAKE_EXPORTS_SOURCES_CMAKE_ 1)
 
 list(APPEND AOM_EXPORTS_SOURCES "${AOM_ROOT}/aom/exports_com"
-            "${AOM_ROOT}/av1/exports_com")
+     "${AOM_ROOT}/av1/exports_com")
 
 if(CONFIG_AV1_DECODER)
   list(APPEND AOM_EXPORTS_SOURCES "${AOM_ROOT}/aom/exports_dec"
-              "${AOM_ROOT}/av1/exports_dec")
+       "${AOM_ROOT}/av1/exports_dec")
   if(CONFIG_INSPECTION)
     list(APPEND AOM_EXPORTS_SOURCES "${AOM_ROOT}/av1/exports_ident")
   endif()
@@ -26,10 +26,10 @@
 
 if(CONFIG_AV1_ENCODER)
   list(APPEND AOM_EXPORTS_SOURCES "${AOM_ROOT}/aom/exports_enc"
-              "${AOM_ROOT}/av1/exports_enc")
+       "${AOM_ROOT}/av1/exports_enc")
 endif()
 
 if(ENABLE_TESTS)
   list(APPEND AOM_EXPORTS_SOURCES "${AOM_ROOT}/aom/exports_test"
-              "${AOM_ROOT}/av1/exports_test")
+       "${AOM_ROOT}/av1/exports_test")
 endif()
diff --git a/build/cmake/generate_aom_config_templates.cmake b/build/cmake/generate_aom_config_templates.cmake
index 529daaf..3907bd9 100644
--- a/build/cmake/generate_aom_config_templates.cmake
+++ b/build/cmake/generate_aom_config_templates.cmake
@@ -1,49 +1,52 @@
 #
-# Copyright (c) 2017, Alliance for Open Media. All rights reserved
+# Copyright (c) 2021, Alliance for Open Media. All rights reserved
 #
-# This source code is subject to the terms of the BSD 2 Clause License and the
-# Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License was
-# not distributed with this source code in the LICENSE file, you can obtain it
-# at www.aomedia.org/license/software. If the Alliance for Open Media Patent
-# License 1.0 was not distributed with this source code in the PATENTS file, you
-# can obtain it at www.aomedia.org/license/patent.
+# This source code is subject to the terms of the BSD 3-Clause Clear License and
+# the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+# License was not distributed with this source code in the LICENSE file, you can
+# obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance
+# for Open Media Patent License 1.0 was not distributed with this source code in
+# the PATENTS file, you can obtain it at aomedia.org/license/patent-license/.
 #
 cmake_minimum_required(VERSION 3.5)
 
 string(TIMESTAMP year "%Y")
-set(asm_file_header_block "\;
+set(asm_file_header_block
+    "\;
 \; Copyright (c) ${year}, Alliance for Open Media. All rights reserved
 \;
-\; This source code is subject to the terms of the BSD 2 Clause License and
-\; the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-\; was not distributed with this source code in the LICENSE file, you can
-\; obtain it at www.aomedia.org/license/software. If the Alliance for Open
-\; Media Patent License 1.0 was not distributed with this source code in the
-\; PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+\; This source code is subject to the terms of the BSD 3-Clause Clear License and the
+\; Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+\; not distributed with this source code in the LICENSE file, you can obtain it
+\; at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+\; License 1.0 was not distributed with this source code in the PATENTS file, you
+\; can obtain it at aomedia.org/license/patent-license/.
 \;
 ")
-set(h_file_header_block "/*
+set(h_file_header_block
+    "/*
  * Copyright (c) ${year}, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License and the
+ * Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+ * not distributed with this source code in the LICENSE file, you can obtain it
+ * at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+ * License 1.0 was not distributed with this source code in the PATENTS file, you
+ * can obtain it at aomedia.org/license/patent-license/.
  */
 \#ifndef AOM_CONFIG_H_
 \#define AOM_CONFIG_H_
 ")
-set(cmake_file_header_block "##
+set(cmake_file_header_block
+    "##
 ## Copyright (c) ${year}, Alliance for Open Media. All rights reserved
 ##
-## This source code is subject to the terms of the BSD 2 Clause License and
-## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-## was not distributed with this source code in the LICENSE file, you can
-## obtain it at www.aomedia.org/license/software. If the Alliance for Open
-## Media Patent License 1.0 was not distributed with this source code in the
-## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+## This source code is subject to the terms of the BSD 3-Clause Clear License and the
+## Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+## not distributed with this source code in the LICENSE file, you can obtain it
+## at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+## License 1.0 was not distributed with this source code in the PATENTS file, you
+## can obtain it at aomedia.org/license/patent-license/.
 ##
 ")
 
@@ -85,8 +88,8 @@
 set(aom_asm_config_template "${AOM_CONFIG_DIR}/config/aom_config.asm.cmake")
 file(WRITE "${aom_asm_config_template}" ${asm_file_header_block})
 foreach(aom_var ${aom_build_vars})
-  if(NOT "${aom_var}" STREQUAL "INLINE"
-     AND NOT "${aom_var}" STREQUAL "AOM_RTCD_FLAGS")
+  if(NOT "${aom_var}" STREQUAL "INLINE" AND NOT "${aom_var}" STREQUAL
+                                            "AOM_RTCD_FLAGS")
     file(APPEND "${aom_asm_config_template}" "${aom_var} equ \${${aom_var}}\n")
   endif()
 endforeach()
diff --git a/build/cmake/generate_exports.cmake b/build/cmake/generate_exports.cmake
index f1d15a0..e4fc265 100644
--- a/build/cmake/generate_exports.cmake
+++ b/build/cmake/generate_exports.cmake
@@ -1,17 +1,17 @@
 #
-# Copyright (c) 2017, Alliance for Open Media. All rights reserved
+# Copyright (c) 2021, Alliance for Open Media. All rights reserved
 #
-# This source code is subject to the terms of the BSD 2 Clause License and the
-# Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License was
-# not distributed with this source code in the LICENSE file, you can obtain it
-# at www.aomedia.org/license/software. If the Alliance for Open Media Patent
-# License 1.0 was not distributed with this source code in the PATENTS file, you
-# can obtain it at www.aomedia.org/license/patent.
+# This source code is subject to the terms of the BSD 3-Clause Clear License and
+# the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+# License was not distributed with this source code in the LICENSE file, you can
+# obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance
+# for Open Media Patent License 1.0 was not distributed with this source code in
+# the PATENTS file, you can obtain it at aomedia.org/license/patent-license/.
 #
 cmake_minimum_required(VERSION 3.5)
 
-set(REQUIRED_ARGS "AOM_ROOT" "AOM_CONFIG_DIR" "AOM_TARGET_SYSTEM" "AOM_SYM_FILE"
-                  "CONFIG_AV1_DECODER" "CONFIG_AV1_ENCODER")
+set(REQUIRED_ARGS "AOM_ROOT" "AOM_CONFIG_DIR" "AOM_TARGET_SYSTEM"
+                  "AOM_SYM_FILE" "CONFIG_AV1_DECODER" "CONFIG_AV1_ENCODER")
 
 foreach(arg ${REQUIRED_ARGS})
   if("${${arg}}" STREQUAL "")
diff --git a/build/cmake/iosbuild.sh b/build/cmake/iosbuild.sh
index 167ece2..4d4c062 100755
--- a/build/cmake/iosbuild.sh
+++ b/build/cmake/iosbuild.sh
@@ -1,12 +1,12 @@
 #!/bin/sh
-## Copyright (c) 2016, Alliance for Open Media. All rights reserved
+## Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ##
-## This source code is subject to the terms of the BSD 2 Clause License and
-## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-## was not distributed with this source code in the LICENSE file, you can
-## obtain it at www.aomedia.org/license/software. If the Alliance for Open
-## Media Patent License 1.0 was not distributed with this source code in the
-## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+## This source code is subject to the terms of the BSD 3-Clause Clear License and the
+## Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+## not distributed with this source code in the LICENSE file, you can obtain it
+## at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+## License 1.0 was not distributed with this source code in the PATENTS file, you
+## can obtain it at aomedia.org/license/patent-license/.
 ##
 ## This script generates 'AOM.framework'. An iOS app can encode and decode AVx
 ## video by including 'AOM.framework'.
diff --git a/build/cmake/msvc_runtime.cmake b/build/cmake/msvc_runtime.cmake
index 9e4cbea..d39eccc 100644
--- a/build/cmake/msvc_runtime.cmake
+++ b/build/cmake/msvc_runtime.cmake
@@ -1,12 +1,12 @@
 #
-# Copyright (c) 2017, Alliance for Open Media. All rights reserved
+# Copyright (c) 2021, Alliance for Open Media. All rights reserved
 #
-# This source code is subject to the terms of the BSD 2 Clause License and the
-# Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License was
-# not distributed with this source code in the LICENSE file, you can obtain it
-# at www.aomedia.org/license/software. If the Alliance for Open Media Patent
-# License 1.0 was not distributed with this source code in the PATENTS file, you
-# can obtain it at www.aomedia.org/license/patent.
+# This source code is subject to the terms of the BSD 3-Clause Clear License and
+# the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+# License was not distributed with this source code in the LICENSE file, you can
+# obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance
+# for Open Media Patent License 1.0 was not distributed with this source code in
+# the PATENTS file, you can obtain it at aomedia.org/license/patent-license/.
 #
 if(AOM_BUILD_CMAKE_MSVC_RUNTIME_CMAKE_)
   return()
@@ -18,17 +18,18 @@
   # CMake defaults to producing code linked to the DLL MSVC runtime. That will
   # not work with googletest, and isn't what we want anyway.
   if(NOT "${MSVC_RUNTIME}" STREQUAL "dll")
-    foreach(flag_var
-            CMAKE_C_FLAGS
-            CMAKE_C_FLAGS_DEBUG
-            CMAKE_C_FLAGS_RELEASE
-            CMAKE_C_FLAGS_MINSIZEREL
-            CMAKE_C_FLAGS_RELWITHDEBINFO
-            CMAKE_CXX_FLAGS
-            CMAKE_CXX_FLAGS_DEBUG
-            CMAKE_CXX_FLAGS_RELEASE
-            CMAKE_CXX_FLAGS_MINSIZEREL
-            CMAKE_CXX_FLAGS_RELWITHDEBINFO)
+    foreach(
+      flag_var
+      CMAKE_C_FLAGS
+      CMAKE_C_FLAGS_DEBUG
+      CMAKE_C_FLAGS_RELEASE
+      CMAKE_C_FLAGS_MINSIZEREL
+      CMAKE_C_FLAGS_RELWITHDEBINFO
+      CMAKE_CXX_FLAGS
+      CMAKE_CXX_FLAGS_DEBUG
+      CMAKE_CXX_FLAGS_RELEASE
+      CMAKE_CXX_FLAGS_MINSIZEREL
+      CMAKE_CXX_FLAGS_RELWITHDEBINFO)
       if(${flag_var} MATCHES "/MD")
         string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
       endif(${flag_var} MATCHES "/MD")
diff --git a/build/cmake/pkg_config.cmake b/build/cmake/pkg_config.cmake
index c3914d7..87ac3b0 100644
--- a/build/cmake/pkg_config.cmake
+++ b/build/cmake/pkg_config.cmake
@@ -1,19 +1,25 @@
 #
-# Copyright (c) 2017, Alliance for Open Media. All rights reserved
+# Copyright (c) 2021, Alliance for Open Media. All rights reserved
 #
-# This source code is subject to the terms of the BSD 2 Clause License and the
-# Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License was
-# not distributed with this source code in the LICENSE file, you can obtain it
-# at www.aomedia.org/license/software. If the Alliance for Open Media Patent
-# License 1.0 was not distributed with this source code in the PATENTS file, you
-# can obtain it at www.aomedia.org/license/patent.
+# This source code is subject to the terms of the BSD 3-Clause Clear License and
+# the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+# License was not distributed with this source code in the LICENSE file, you can
+# obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance
+# for Open Media Patent License 1.0 was not distributed with this source code in
+# the PATENTS file, you can obtain it at aomedia.org/license/patent-license/.
 #
 cmake_minimum_required(VERSION 3.5)
 
-set(REQUIRED_ARGS "AOM_ROOT" "AOM_CONFIG_DIR" "CMAKE_INSTALL_PREFIX"
-                  "CMAKE_INSTALL_BINDIR" "CMAKE_INSTALL_INCLUDEDIR"
-                  "CMAKE_INSTALL_LIBDIR" "CMAKE_PROJECT_NAME"
-                  "CONFIG_MULTITHREAD" "HAVE_PTHREAD_H")
+set(REQUIRED_ARGS
+    "AOM_ROOT"
+    "AOM_CONFIG_DIR"
+    "CMAKE_INSTALL_PREFIX"
+    "CMAKE_INSTALL_BINDIR"
+    "CMAKE_INSTALL_INCLUDEDIR"
+    "CMAKE_INSTALL_LIBDIR"
+    "CMAKE_PROJECT_NAME"
+    "CONFIG_MULTITHREAD"
+    "HAVE_PTHREAD_H")
 
 foreach(arg ${REQUIRED_ARGS})
   if("${${arg}}" STREQUAL "")
diff --git a/build/cmake/rtcd.pl b/build/cmake/rtcd.pl
index e9f75dd..5865c32 100755
--- a/build/cmake/rtcd.pl
+++ b/build/cmake/rtcd.pl
@@ -1,13 +1,13 @@
 #!/usr/bin/env perl
 ##
-## Copyright (c) 2017, Alliance for Open Media. All rights reserved
+## Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ##
-## This source code is subject to the terms of the BSD 2 Clause License and
-## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-## was not distributed with this source code in the LICENSE file, you can
-## obtain it at www.aomedia.org/license/software. If the Alliance for Open
-## Media Patent License 1.0 was not distributed with this source code in the
-## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+## This source code is subject to the terms of the BSD 3-Clause Clear License and the
+## Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+## not distributed with this source code in the LICENSE file, you can obtain it
+## at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+## License 1.0 was not distributed with this source code in the PATENTS file, you
+## can obtain it at aomedia.org/license/patent-license/.
 ##
 no strict 'refs';
 use warnings;
diff --git a/build/cmake/sanitizers.cmake b/build/cmake/sanitizers.cmake
index f8caa58..48019c4 100644
--- a/build/cmake/sanitizers.cmake
+++ b/build/cmake/sanitizers.cmake
@@ -1,12 +1,12 @@
 #
-# Copyright (c) 2017, Alliance for Open Media. All rights reserved
+# Copyright (c) 2021, Alliance for Open Media. All rights reserved
 #
-# This source code is subject to the terms of the BSD 2 Clause License and the
-# Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License was
-# not distributed with this source code in the LICENSE file, you can obtain it
-# at www.aomedia.org/license/software. If the Alliance for Open Media Patent
-# License 1.0 was not distributed with this source code in the PATENTS file, you
-# can obtain it at www.aomedia.org/license/patent.
+# This source code is subject to the terms of the BSD 3-Clause Clear License and
+# the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+# License was not distributed with this source code in the LICENSE file, you can
+# obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance
+# for Open Media Patent License 1.0 was not distributed with this source code in
+# the PATENTS file, you can obtain it at aomedia.org/license/patent-license/.
 #
 if(AOM_BUILD_CMAKE_SANITIZERS_CMAKE_)
   return()
@@ -24,8 +24,7 @@
 # Require the sanitizer requested. cfi sanitizer requires all the flags in order
 # for the compiler to accept it.
 if("${SANITIZE}" MATCHES "cfi" AND CMAKE_C_COMPILER_ID MATCHES "Clang")
-  require_linker_flag("-fsanitize=${SANITIZE} -flto -fno-sanitize-trap=cfi"
-    YES)
+  require_linker_flag("-fsanitize=${SANITIZE} -flto -fno-sanitize-trap=cfi" YES)
   require_compiler_flag("-fsanitize=${SANITIZE} -flto -fvisibility=hidden \
     -fno-sanitize-trap=cfi" YES)
 else()
@@ -39,8 +38,8 @@
 # Fix link errors due to missing rt compiler lib in 32-bit builds.
 # http://llvm.org/bugs/show_bug.cgi?id=17693
 if(CMAKE_C_COMPILER_ID MATCHES "Clang")
-  if(${CMAKE_SIZEOF_VOID_P} EQUAL 4
-     AND "${SANITIZE}" MATCHES "integer|undefined")
+  if(${CMAKE_SIZEOF_VOID_P} EQUAL 4 AND "${SANITIZE}" MATCHES
+                                        "integer|undefined")
     require_linker_flag("--rtlib=compiler-rt -lgcc_s")
   endif()
 endif()
diff --git a/build/cmake/tensorflow_lite.cmake b/build/cmake/tensorflow_lite.cmake
index 6439069..9dd678d 100644
--- a/build/cmake/tensorflow_lite.cmake
+++ b/build/cmake/tensorflow_lite.cmake
@@ -1,12 +1,12 @@
 #
-# Copyright (c) 2020, Alliance for Open Media. All rights reserved
+# Copyright (c) 2021, Alliance for Open Media. All rights reserved
 #
-# This source code is subject to the terms of the BSD 2 Clause License and the
-# Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License was
-# not distributed with this source code in the LICENSE file, you can obtain it
-# at www.aomedia.org/license/software. If the Alliance for Open Media Patent
-# License 1.0 was not distributed with this source code in the PATENTS file, you
-# can obtain it at www.aomedia.org/license/patent.
+# This source code is subject to the terms of the BSD 3-Clause Clear License and
+# the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+# License was not distributed with this source code in the LICENSE file, you can
+# obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance
+# for Open Media Patent License 1.0 was not distributed with this source code in
+# the PATENTS file, you can obtain it at aomedia.org/license/patent-license/.
 #
 if(AOM_BUILD_CMAKE_TENSORFLOW_LITE_CMAKE_)
   return()
@@ -34,15 +34,22 @@
   # Note that "git submodule update --init" must be run from inside the git
   # repository; the --git-dir flag does not work.
   message("Checking out Tensorflow-Lite submodule")
-  execute_process(COMMAND "${GIT_EXECUTABLE}" submodule update --init
-                  WORKING_DIRECTORY "${AOM_ROOT}"
-                  OUTPUT_VARIABLE submodule_out
-                  ERROR_VARIABLE submodule_err
-                  RESULT_VARIABLE submodule_result)
+  execute_process(
+    COMMAND "${GIT_EXECUTABLE}" submodule update --init
+    WORKING_DIRECTORY "${AOM_ROOT}"
+    OUTPUT_VARIABLE submodule_out
+    ERROR_VARIABLE submodule_err
+    RESULT_VARIABLE submodule_result)
   if(NOT ${submodule_result} EQUAL 0)
-    message(FATAL_ERROR "Unable to run 'git submodule update --init': "
-                        "Return code: " ${submodule_result} ", STDOUT: "
-                        ${submodule_out} ", STDERR: " ${submodule_err})
+    message(
+      FATAL_ERROR
+        "Unable to run 'git submodule update --init': "
+        "Return code: "
+        ${submodule_result}
+        ", STDOUT: "
+        ${submodule_out}
+        ", STDERR: "
+        ${submodule_err})
   endif()
 endfunction()
 
@@ -63,7 +70,7 @@
     ${named_target}
     PRIVATE
       "${CMAKE_BINARY_DIR}/tensorflow_lite/${subdir}${STATIC_LIBRARY_DIR}${CMAKE_STATIC_LIBRARY_PREFIX}${libname}${CMAKE_STATIC_LIBRARY_SUFFIX}"
-    )
+  )
 endfunction()
 
 # Add TF-lite libraries onto the named target at link time (e.g., an executable
@@ -97,24 +104,22 @@
                            absl_cord)
   target_link_tf_lite_dep_(${named_target} _deps/abseil-cpp-build/absl/strings/
                            absl_str_format_internal)
-  target_link_tf_lite_dep_(${named_target}
-                           _deps/abseil-cpp-build/absl/synchronization/
-                           absl_synchronization)
-  target_link_tf_lite_dep_(${named_target}
-                           _deps/abseil-cpp-build/absl/debugging/
-                           absl_stacktrace)
-  target_link_tf_lite_dep_(${named_target}
-                           _deps/abseil-cpp-build/absl/debugging/
-                           absl_symbolize)
-  target_link_tf_lite_dep_(${named_target}
-                           _deps/abseil-cpp-build/absl/debugging/
-                           absl_debugging_internal)
-  target_link_tf_lite_dep_(${named_target}
-                           _deps/abseil-cpp-build/absl/debugging/
-                           absl_demangle_internal)
-  target_link_tf_lite_dep_(${named_target}
-                           _deps/abseil-cpp-build/absl/synchronization/
-                           absl_graphcycles_internal)
+  target_link_tf_lite_dep_(
+    ${named_target} _deps/abseil-cpp-build/absl/synchronization/
+    absl_synchronization)
+  target_link_tf_lite_dep_(
+    ${named_target} _deps/abseil-cpp-build/absl/debugging/ absl_stacktrace)
+  target_link_tf_lite_dep_(
+    ${named_target} _deps/abseil-cpp-build/absl/debugging/ absl_symbolize)
+  target_link_tf_lite_dep_(
+    ${named_target} _deps/abseil-cpp-build/absl/debugging/
+    absl_debugging_internal)
+  target_link_tf_lite_dep_(
+    ${named_target} _deps/abseil-cpp-build/absl/debugging/
+    absl_demangle_internal)
+  target_link_tf_lite_dep_(
+    ${named_target} _deps/abseil-cpp-build/absl/synchronization/
+    absl_graphcycles_internal)
   target_link_tf_lite_dep_(${named_target} _deps/abseil-cpp-build/absl/base/
                            absl_malloc_internal)
   target_link_tf_lite_dep_(${named_target} _deps/abseil-cpp-build/absl/time/
@@ -162,7 +167,9 @@
   if(CMAKE_TOOLCHAIN_FILE)
     message("TOOLCHAIN: ${CMAKE_TOOLCHAIN_FILE}")
     message(WARNING "No cross-compile support for TensorFlow Lite; disabling")
-    set(${result} 0 PARENT_SCOPE)
+    set(${result}
+        0
+        PARENT_SCOPE)
     return()
   endif()
   # TF-Lite specifies a minimum CMake version of 3.16, but Jenkins uses 3.7.2.
@@ -172,10 +179,14 @@
     message(
       WARNING "Tensorflow Lite requres CMake version 3.16 or higher; version "
               "${CMAKE_VERSION} detected; disabling")
-    set(${result} 0 PARENT_SCOPE)
+    set(${result}
+        0
+        PARENT_SCOPE)
     return()
   endif()
-  set(${result} 1 PARENT_SCOPE)
+  set(${result}
+      1
+      PARENT_SCOPE)
 endfunction()
 
 # Adds appropriate build rules / targets. Only invoke this function if
@@ -206,7 +217,7 @@
   # supported in static builds. Use a dummy implementation (callers must not use
   # delegation).
   add_library(fake_dl OBJECT "${AOM_ROOT}/common/fake_dl.h"
-                      "${AOM_ROOT}/common/fake_dl.cc")
+                             "${AOM_ROOT}/common/fake_dl.cc")
 
   # TF-Lite depends on this, and downloads it during compilation.
   include_directories(
@@ -230,10 +241,16 @@
   if(NOT ${supported})
     # Disable the experiment so Gerrit will not test this case.
     message(WARNING "Disabling ${experiment_name}.")
-    set(${experiment_name} 0 PARENT_SCOPE)
-    set(CONFIG_TENSORFLOW_LITE 0 PARENT_SCOPE)
+    set(${experiment_name}
+        0
+        PARENT_SCOPE)
+    set(CONFIG_TENSORFLOW_LITE
+        0
+        PARENT_SCOPE)
     return()
   endif()
   # Otherwise, enable TF-lite.
-  set(CONFIG_TENSORFLOW_LITE 1 PARENT_SCOPE)
+  set(CONFIG_TENSORFLOW_LITE
+      1
+      PARENT_SCOPE)
 endfunction()
diff --git a/build/cmake/toolchains/arm-ios-common.cmake b/build/cmake/toolchains/arm-ios-common.cmake
index 053e33a..aab62b7 100644
--- a/build/cmake/toolchains/arm-ios-common.cmake
+++ b/build/cmake/toolchains/arm-ios-common.cmake
@@ -1,12 +1,12 @@
 #
-# Copyright (c) 2017, Alliance for Open Media. All rights reserved
+# Copyright (c) 2021, Alliance for Open Media. All rights reserved
 #
-# This source code is subject to the terms of the BSD 2 Clause License and the
-# Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License was
-# not distributed with this source code in the LICENSE file, you can obtain it
-# at www.aomedia.org/license/software. If the Alliance for Open Media Patent
-# License 1.0 was not distributed with this source code in the PATENTS file, you
-# can obtain it at www.aomedia.org/license/patent.
+# This source code is subject to the terms of the BSD 3-Clause Clear License and
+# the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+# License was not distributed with this source code in the LICENSE file, you can
+# obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance
+# for Open Media Patent License 1.0 was not distributed with this source code in
+# the PATENTS file, you can obtain it at aomedia.org/license/patent-license/.
 #
 if(AOM_BUILD_CMAKE_TOOLCHAINS_ARM_IOS_COMMON_CMAKE_)
   return()
@@ -21,6 +21,8 @@
 set(CMAKE_CXX_COMPILER_ARG1 "-arch ${CMAKE_SYSTEM_PROCESSOR}")
 
 # No runtime cpu detect for arm*-ios targets.
-set(CONFIG_RUNTIME_CPU_DETECT 0 CACHE STRING "")
+set(CONFIG_RUNTIME_CPU_DETECT
+    0
+    CACHE STRING "")
 
 # TODO(tomfinegan): Handle bit code embedding.
diff --git a/build/cmake/toolchains/arm64-android-clang.cmake b/build/cmake/toolchains/arm64-android-clang.cmake
index c13b1d9..a992640 100644
--- a/build/cmake/toolchains/arm64-android-clang.cmake
+++ b/build/cmake/toolchains/arm64-android-clang.cmake
@@ -1,12 +1,12 @@
 #
-# Copyright (c) 2019, Alliance for Open Media. All rights reserved
+# Copyright (c) 2021, Alliance for Open Media. All rights reserved
 #
-# This source code is subject to the terms of the BSD 2 Clause License and the
-# Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License was
-# not distributed with this source code in the LICENSE file, you can obtain it
-# at www.aomedia.org/license/software. If the Alliance for Open Media Patent
-# License 1.0 was not distributed with this source code in the PATENTS file, you
-# can obtain it at www.aomedia.org/license/patent.
+# This source code is subject to the terms of the BSD 3-Clause Clear License and
+# the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+# License was not distributed with this source code in the LICENSE file, you can
+# obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance
+# for Open Media Patent License 1.0 was not distributed with this source code in
+# the PATENTS file, you can obtain it at aomedia.org/license/patent-license/.
 #
 if(AOM_BUILD_CMAKE_TOOLCHAINS_ARM64_ANDROID_CLANG_CMAKE_)
   return()
@@ -43,6 +43,8 @@
 set(AOM_NEON_INTRIN_FLAG "")
 
 # No runtime cpu detect for arm64-android-clang.
-set(CONFIG_RUNTIME_CPU_DETECT 0 CACHE STRING "")
+set(CONFIG_RUNTIME_CPU_DETECT
+    0
+    CACHE STRING "")
 
 set(CMAKE_SYSTEM_NAME "Android")
diff --git a/build/cmake/toolchains/arm64-ios.cmake b/build/cmake/toolchains/arm64-ios.cmake
index 6feb109..96f3dbd 100644
--- a/build/cmake/toolchains/arm64-ios.cmake
+++ b/build/cmake/toolchains/arm64-ios.cmake
@@ -1,12 +1,12 @@
 #
-# Copyright (c) 2017, Alliance for Open Media. All rights reserved
+# Copyright (c) 2021, Alliance for Open Media. All rights reserved
 #
-# This source code is subject to the terms of the BSD 2 Clause License and the
-# Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License was
-# not distributed with this source code in the LICENSE file, you can obtain it
-# at www.aomedia.org/license/software. If the Alliance for Open Media Patent
-# License 1.0 was not distributed with this source code in the PATENTS file, you
-# can obtain it at www.aomedia.org/license/patent.
+# This source code is subject to the terms of the BSD 3-Clause Clear License and
+# the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+# License was not distributed with this source code in the LICENSE file, you can
+# obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance
+# for Open Media Patent License 1.0 was not distributed with this source code in
+# the PATENTS file, you can obtain it at aomedia.org/license/patent-license/.
 #
 if(AOM_BUILD_CMAKE_TOOLCHAINS_ARM64_IOS_CMAKE_)
   return()
diff --git a/build/cmake/toolchains/arm64-linux-gcc.cmake b/build/cmake/toolchains/arm64-linux-gcc.cmake
index a6c9543..3e1d267 100644
--- a/build/cmake/toolchains/arm64-linux-gcc.cmake
+++ b/build/cmake/toolchains/arm64-linux-gcc.cmake
@@ -1,12 +1,12 @@
 #
-# Copyright (c) 2017, Alliance for Open Media. All rights reserved
+# Copyright (c) 2021, Alliance for Open Media. All rights reserved
 #
-# This source code is subject to the terms of the BSD 2 Clause License and the
-# Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License was
-# not distributed with this source code in the LICENSE file, you can obtain it
-# at www.aomedia.org/license/software. If the Alliance for Open Media Patent
-# License 1.0 was not distributed with this source code in the PATENTS file, you
-# can obtain it at www.aomedia.org/license/patent.
+# This source code is subject to the terms of the BSD 3-Clause Clear License and
+# the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+# License was not distributed with this source code in the LICENSE file, you can
+# obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance
+# for Open Media Patent License 1.0 was not distributed with this source code in
+# the PATENTS file, you can obtain it at aomedia.org/license/patent-license/.
 #
 if(AOM_BUILD_CMAKE_TOOLCHAINS_ARM64_LINUX_GCC_CMAKE_)
   return()
@@ -33,4 +33,6 @@
 set(AOM_NEON_INTRIN_FLAG "")
 
 # No runtime cpu detect for arm64-linux-gcc.
-set(CONFIG_RUNTIME_CPU_DETECT 0 CACHE STRING "")
+set(CONFIG_RUNTIME_CPU_DETECT
+    0
+    CACHE STRING "")
diff --git a/build/cmake/toolchains/arm64-mingw-gcc.cmake b/build/cmake/toolchains/arm64-mingw-gcc.cmake
index a8e15cb..4a1b62f 100644
--- a/build/cmake/toolchains/arm64-mingw-gcc.cmake
+++ b/build/cmake/toolchains/arm64-mingw-gcc.cmake
@@ -1,12 +1,12 @@
 #
-# Copyright (c) 2018, Alliance for Open Media. All rights reserved
+# Copyright (c) 2021, Alliance for Open Media. All rights reserved
 #
-# This source code is subject to the terms of the BSD 2 Clause License and the
-# Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License was
-# not distributed with this source code in the LICENSE file, you can obtain it
-# at www.aomedia.org/license/software. If the Alliance for Open Media Patent
-# License 1.0 was not distributed with this source code in the PATENTS file, you
-# can obtain it at www.aomedia.org/license/patent.
+# This source code is subject to the terms of the BSD 3-Clause Clear License and
+# the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+# License was not distributed with this source code in the LICENSE file, you can
+# obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance
+# for Open Media Patent License 1.0 was not distributed with this source code in
+# the PATENTS file, you can obtain it at aomedia.org/license/patent-license/.
 #
 if(AOM_BUILD_CMAKE_TOOLCHAINS_ARM64_MINGW_GCC_CMAKE_)
   return()
@@ -22,8 +22,14 @@
 
 set(CMAKE_C_COMPILER ${CROSS}gcc)
 set(CMAKE_CXX_COMPILER ${CROSS}g++)
-set(CMAKE_AR ${CROSS}ar CACHE FILEPATH Archiver)
-set(CMAKE_RANLIB ${CROSS}ranlib CACHE FILEPATH Indexer)
+set(CMAKE_AR
+    ${CROSS}ar
+    CACHE FILEPATH Archiver)
+set(CMAKE_RANLIB
+    ${CROSS}ranlib
+    CACHE FILEPATH Indexer)
 
 # No runtime cpu detect for arm64-mingw-gcc.
-set(CONFIG_RUNTIME_CPU_DETECT 0 CACHE STRING "")
+set(CONFIG_RUNTIME_CPU_DETECT
+    0
+    CACHE STRING "")
diff --git a/build/cmake/toolchains/armv7-ios.cmake b/build/cmake/toolchains/armv7-ios.cmake
index 11f7e16..9f50284 100644
--- a/build/cmake/toolchains/armv7-ios.cmake
+++ b/build/cmake/toolchains/armv7-ios.cmake
@@ -1,12 +1,12 @@
 #
-# Copyright (c) 2017, Alliance for Open Media. All rights reserved
+# Copyright (c) 2021, Alliance for Open Media. All rights reserved
 #
-# This source code is subject to the terms of the BSD 2 Clause License and the
-# Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License was
-# not distributed with this source code in the LICENSE file, you can obtain it
-# at www.aomedia.org/license/software. If the Alliance for Open Media Patent
-# License 1.0 was not distributed with this source code in the PATENTS file, you
-# can obtain it at www.aomedia.org/license/patent.
+# This source code is subject to the terms of the BSD 3-Clause Clear License and
+# the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+# License was not distributed with this source code in the LICENSE file, you can
+# obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance
+# for Open Media Patent License 1.0 was not distributed with this source code in
+# the PATENTS file, you can obtain it at aomedia.org/license/patent-license/.
 #
 if(AOM_BUILD_CMAKE_TOOLCHAINS_ARMV7_IOS_CMAKE_)
   return()
@@ -28,4 +28,6 @@
 set(AOM_NEON_INTRIN_FLAG "")
 
 # No runtime cpu detect for armv7s-ios.
-set(CONFIG_RUNTIME_CPU_DETECT 0 CACHE STRING "")
+set(CONFIG_RUNTIME_CPU_DETECT
+    0
+    CACHE STRING "")
diff --git a/build/cmake/toolchains/armv7-linux-gcc.cmake b/build/cmake/toolchains/armv7-linux-gcc.cmake
index b898b4b..06498ca 100644
--- a/build/cmake/toolchains/armv7-linux-gcc.cmake
+++ b/build/cmake/toolchains/armv7-linux-gcc.cmake
@@ -1,12 +1,12 @@
 #
-# Copyright (c) 2017, Alliance for Open Media. All rights reserved
+# Copyright (c) 2021, Alliance for Open Media. All rights reserved
 #
-# This source code is subject to the terms of the BSD 2 Clause License and the
-# Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License was
-# not distributed with this source code in the LICENSE file, you can obtain it
-# at www.aomedia.org/license/software. If the Alliance for Open Media Patent
-# License 1.0 was not distributed with this source code in the PATENTS file, you
-# can obtain it at www.aomedia.org/license/patent.
+# This source code is subject to the terms of the BSD 3-Clause Clear License and
+# the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+# License was not distributed with this source code in the LICENSE file, you can
+# obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance
+# for Open Media Patent License 1.0 was not distributed with this source code in
+# the PATENTS file, you can obtain it at aomedia.org/license/patent-license/.
 #
 if(AOM_BUILD_CMAKE_TOOLCHAINS_ARMV7_LINUX_GCC_CMAKE_)
   return()
@@ -37,4 +37,6 @@
 set(AOM_NEON_INTRIN_FLAG "-mfpu=neon")
 
 # No runtime cpu detect for armv7-linux-gcc.
-set(CONFIG_RUNTIME_CPU_DETECT 0 CACHE STRING "")
+set(CONFIG_RUNTIME_CPU_DETECT
+    0
+    CACHE STRING "")
diff --git a/build/cmake/toolchains/armv7-mingw-gcc.cmake b/build/cmake/toolchains/armv7-mingw-gcc.cmake
index 2dc4b18..f629c58 100644
--- a/build/cmake/toolchains/armv7-mingw-gcc.cmake
+++ b/build/cmake/toolchains/armv7-mingw-gcc.cmake
@@ -1,12 +1,12 @@
 #
-# Copyright (c) 2018, Alliance for Open Media. All rights reserved
+# Copyright (c) 2021, Alliance for Open Media. All rights reserved
 #
-# This source code is subject to the terms of the BSD 2 Clause License and the
-# Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License was
-# not distributed with this source code in the LICENSE file, you can obtain it
-# at www.aomedia.org/license/software. If the Alliance for Open Media Patent
-# License 1.0 was not distributed with this source code in the PATENTS file, you
-# can obtain it at www.aomedia.org/license/patent.
+# This source code is subject to the terms of the BSD 3-Clause Clear License and
+# the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+# License was not distributed with this source code in the LICENSE file, you can
+# obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance
+# for Open Media Patent License 1.0 was not distributed with this source code in
+# the PATENTS file, you can obtain it at aomedia.org/license/patent-license/.
 #
 if(AOM_BUILD_CMAKE_TOOLCHAINS_ARMV7_MINGW_GCC_CMAKE_)
   return()
@@ -22,8 +22,14 @@
 
 set(CMAKE_C_COMPILER ${CROSS}gcc)
 set(CMAKE_CXX_COMPILER ${CROSS}g++)
-set(CMAKE_AR ${CROSS}ar CACHE FILEPATH Archiver)
-set(CMAKE_RANLIB ${CROSS}ranlib CACHE FILEPATH Indexer)
+set(CMAKE_AR
+    ${CROSS}ar
+    CACHE FILEPATH Archiver)
+set(CMAKE_RANLIB
+    ${CROSS}ranlib
+    CACHE FILEPATH Indexer)
 
 # No runtime cpu detect for armv7-mingw-gcc.
-set(CONFIG_RUNTIME_CPU_DETECT 0 CACHE STRING "")
+set(CONFIG_RUNTIME_CPU_DETECT
+    0
+    CACHE STRING "")
diff --git a/build/cmake/toolchains/armv7s-ios.cmake b/build/cmake/toolchains/armv7s-ios.cmake
index faa2933..6f4bfa2 100644
--- a/build/cmake/toolchains/armv7s-ios.cmake
+++ b/build/cmake/toolchains/armv7s-ios.cmake
@@ -1,12 +1,12 @@
 #
-# Copyright (c) 2017, Alliance for Open Media. All rights reserved
+# Copyright (c) 2021, Alliance for Open Media. All rights reserved
 #
-# This source code is subject to the terms of the BSD 2 Clause License and the
-# Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License was
-# not distributed with this source code in the LICENSE file, you can obtain it
-# at www.aomedia.org/license/software. If the Alliance for Open Media Patent
-# License 1.0 was not distributed with this source code in the PATENTS file, you
-# can obtain it at www.aomedia.org/license/patent.
+# This source code is subject to the terms of the BSD 3-Clause Clear License and
+# the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+# License was not distributed with this source code in the LICENSE file, you can
+# obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance
+# for Open Media Patent License 1.0 was not distributed with this source code in
+# the PATENTS file, you can obtain it at aomedia.org/license/patent-license/.
 #
 if(AOM_BUILD_CMAKE_TOOLCHAINS_ARMV7S_IOS_CMAKE_)
   return()
@@ -28,4 +28,6 @@
 set(AOM_NEON_INTRIN_FLAG "")
 
 # No runtime cpu detect for armv7s-ios.
-set(CONFIG_RUNTIME_CPU_DETECT 0 CACHE STRING "")
+set(CONFIG_RUNTIME_CPU_DETECT
+    0
+    CACHE STRING "")
diff --git a/build/cmake/toolchains/ios-simulator-common.cmake b/build/cmake/toolchains/ios-simulator-common.cmake
index 76e0bd1..1c0efa2 100644
--- a/build/cmake/toolchains/ios-simulator-common.cmake
+++ b/build/cmake/toolchains/ios-simulator-common.cmake
@@ -1,12 +1,12 @@
 #
-# Copyright (c) 2017, Alliance for Open Media. All rights reserved
+# Copyright (c) 2021, Alliance for Open Media. All rights reserved
 #
-# This source code is subject to the terms of the BSD 2 Clause License and the
-# Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License was
-# not distributed with this source code in the LICENSE file, you can obtain it
-# at www.aomedia.org/license/software. If the Alliance for Open Media Patent
-# License 1.0 was not distributed with this source code in the PATENTS file, you
-# can obtain it at www.aomedia.org/license/patent.
+# This source code is subject to the terms of the BSD 3-Clause Clear License and
+# the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+# License was not distributed with this source code in the LICENSE file, you can
+# obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance
+# for Open Media Patent License 1.0 was not distributed with this source code in
+# the PATENTS file, you can obtain it at aomedia.org/license/patent-license/.
 #
 if(AOM_BUILD_CMAKE_TOOLCHAINS_IOS_SIMULATOR_COMMON_CMAKE_)
   return()
diff --git a/build/cmake/toolchains/mips32-linux-gcc.cmake b/build/cmake/toolchains/mips32-linux-gcc.cmake
index c644eec..6a36477 100644
--- a/build/cmake/toolchains/mips32-linux-gcc.cmake
+++ b/build/cmake/toolchains/mips32-linux-gcc.cmake
@@ -1,12 +1,12 @@
 #
-# Copyright (c) 2017, Alliance for Open Media. All rights reserved
+# Copyright (c) 2021, Alliance for Open Media. All rights reserved
 #
-# This source code is subject to the terms of the BSD 2 Clause License and the
-# Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License was
-# not distributed with this source code in the LICENSE file, you can obtain it
-# at www.aomedia.org/license/software. If the Alliance for Open Media Patent
-# License 1.0 was not distributed with this source code in the PATENTS file, you
-# can obtain it at www.aomedia.org/license/patent.
+# This source code is subject to the terms of the BSD 3-Clause Clear License and
+# the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+# License was not distributed with this source code in the LICENSE file, you can
+# obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance
+# for Open Media Patent License 1.0 was not distributed with this source code in
+# the PATENTS file, you can obtain it at aomedia.org/license/patent-license/.
 #
 if(AOM_BUILD_CMAKE_TOOLCHAINS_MIPS32_LINUX_GCC_CMAKE_)
   return()
@@ -20,7 +20,9 @@
 endif()
 
 if(ENABLE_DSPR2)
-  set(HAVE_DSPR2 1 CACHE BOOL "" FORCE)
+  set(HAVE_DSPR2
+      1
+      CACHE BOOL "" FORCE)
 
   if("${CROSS}" STREQUAL "")
 
@@ -31,7 +33,9 @@
   set(MIPS_CFLAGS "-mdspr2")
   set(MIPS_CXXFLAGS "-mdspr2")
 elseif(ENABLE_MSA)
-  set(HAVE_MSA 1 CACHE BOOL "" FORCE)
+  set(HAVE_MSA
+      1
+      CACHE BOOL "" FORCE)
 
   if("${CROSS}" STREQUAL "")
 
@@ -74,4 +78,6 @@
   message("--- CONFIG_RUNTIME_CPU_DETECT not supported for mips32 targets.")
 endif()
 
-set(CONFIG_RUNTIME_CPU_DETECT 0 CACHE STRING "" FORCE)
+set(CONFIG_RUNTIME_CPU_DETECT
+    0
+    CACHE STRING "" FORCE)
diff --git a/build/cmake/toolchains/mips64-linux-gcc.cmake b/build/cmake/toolchains/mips64-linux-gcc.cmake
index 442d910..7596745 100644
--- a/build/cmake/toolchains/mips64-linux-gcc.cmake
+++ b/build/cmake/toolchains/mips64-linux-gcc.cmake
@@ -1,12 +1,12 @@
 #
-# Copyright (c) 2017, Alliance for Open Media. All rights reserved
+# Copyright (c) 2021, Alliance for Open Media. All rights reserved
 #
-# This source code is subject to the terms of the BSD 2 Clause License and the
-# Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License was
-# not distributed with this source code in the LICENSE file, you can obtain it
-# at www.aomedia.org/license/software. If the Alliance for Open Media Patent
-# License 1.0 was not distributed with this source code in the PATENTS file, you
-# can obtain it at www.aomedia.org/license/patent.
+# This source code is subject to the terms of the BSD 3-Clause Clear License and
+# the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+# License was not distributed with this source code in the LICENSE file, you can
+# obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance
+# for Open Media Patent License 1.0 was not distributed with this source code in
+# the PATENTS file, you can obtain it at aomedia.org/license/patent-license/.
 #
 if(AOM_BUILD_CMAKE_TOOLCHAINS_MIPS64_LINUX_GCC_CMAKE_)
   return()
@@ -25,7 +25,9 @@
 endif()
 
 if(ENABLE_MSA)
-  set(HAVE_MSA 1 CACHE BOOL "" FORCE)
+  set(HAVE_MSA
+      1
+      CACHE BOOL "" FORCE)
   set(MIPS_CFLAGS "-mmsa")
   set(MIPS_CXXFLAGS "-mmsa")
 endif()
@@ -51,4 +53,6 @@
   message("--- CONFIG_RUNTIME_CPU_DETECT not supported for mips64 targets.")
 endif()
 
-set(CONFIG_RUNTIME_CPU_DETECT 0 CACHE STRING "" FORCE)
+set(CONFIG_RUNTIME_CPU_DETECT
+    0
+    CACHE STRING "" FORCE)
diff --git a/build/cmake/toolchains/ppc-linux-gcc.cmake b/build/cmake/toolchains/ppc-linux-gcc.cmake
index 54db99b..7e798e6 100644
--- a/build/cmake/toolchains/ppc-linux-gcc.cmake
+++ b/build/cmake/toolchains/ppc-linux-gcc.cmake
@@ -1,12 +1,12 @@
 #
-# Copyright (c) 2018, Alliance for Open Media. All rights reserved
+# Copyright (c) 2021, Alliance for Open Media. All rights reserved
 #
-# This source code is subject to the terms of the BSD 2 Clause License and the
-# Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License was
-# not distributed with this source code in the LICENSE file, you can obtain it
-# at www.aomedia.org/license/software. If the Alliance for Open Media Patent
-# License 1.0 was not distributed with this source code in the PATENTS file, you
-# can obtain it at www.aomedia.org/license/patent.
+# This source code is subject to the terms of the BSD 3-Clause Clear License and
+# the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+# License was not distributed with this source code in the LICENSE file, you can
+# obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance
+# for Open Media Patent License 1.0 was not distributed with this source code in
+# the PATENTS file, you can obtain it at aomedia.org/license/patent-license/.
 #
 if(AOM_BUILD_CMAKE_TOOLCHAINS_PPC_LINUX_GCC_CMAKE_)
   return()
@@ -26,4 +26,6 @@
 set(AS_EXECUTABLE ${CROSS}as)
 set(CMAKE_SYSTEM_PROCESSOR "ppc")
 
-set(CONFIG_RUNTIME_CPU_DETECT 0 CACHE STRING "")
+set(CONFIG_RUNTIME_CPU_DETECT
+    0
+    CACHE STRING "")
diff --git a/build/cmake/toolchains/x86-ios-simulator.cmake b/build/cmake/toolchains/x86-ios-simulator.cmake
index caacb8c..5e1a60b 100644
--- a/build/cmake/toolchains/x86-ios-simulator.cmake
+++ b/build/cmake/toolchains/x86-ios-simulator.cmake
@@ -1,12 +1,12 @@
 #
-# Copyright (c) 2017, Alliance for Open Media. All rights reserved
+# Copyright (c) 2021, Alliance for Open Media. All rights reserved
 #
-# This source code is subject to the terms of the BSD 2 Clause License and the
-# Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License was
-# not distributed with this source code in the LICENSE file, you can obtain it
-# at www.aomedia.org/license/software. If the Alliance for Open Media Patent
-# License 1.0 was not distributed with this source code in the PATENTS file, you
-# can obtain it at www.aomedia.org/license/patent.
+# This source code is subject to the terms of the BSD 3-Clause Clear License and
+# the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+# License was not distributed with this source code in the LICENSE file, you can
+# obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance
+# for Open Media Patent License 1.0 was not distributed with this source code in
+# the PATENTS file, you can obtain it at aomedia.org/license/patent-license/.
 #
 if(AOM_BUILD_CMAKE_TOOLCHAINS_X86_IOS_SIMULATOR_CMAKE_)
   return()
@@ -23,6 +23,8 @@
 set(CMAKE_OSX_ARCHITECTURES "i386")
 
 # Avoid noisy PIC/PIE warnings.
-set(CONFIG_PIC 1 CACHE STRING "")
+set(CONFIG_PIC
+    1
+    CACHE STRING "")
 
 include("${CMAKE_CURRENT_LIST_DIR}/ios-simulator-common.cmake")
diff --git a/build/cmake/toolchains/x86-linux.cmake b/build/cmake/toolchains/x86-linux.cmake
index c2a700b..aaeb560 100644
--- a/build/cmake/toolchains/x86-linux.cmake
+++ b/build/cmake/toolchains/x86-linux.cmake
@@ -1,12 +1,12 @@
 #
-# Copyright (c) 2017, Alliance for Open Media. All rights reserved
+# Copyright (c) 2021, Alliance for Open Media. All rights reserved
 #
-# This source code is subject to the terms of the BSD 2 Clause License and the
-# Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License was
-# not distributed with this source code in the LICENSE file, you can obtain it
-# at www.aomedia.org/license/software. If the Alliance for Open Media Patent
-# License 1.0 was not distributed with this source code in the PATENTS file, you
-# can obtain it at www.aomedia.org/license/patent.
+# This source code is subject to the terms of the BSD 3-Clause Clear License and
+# the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+# License was not distributed with this source code in the LICENSE file, you can
+# obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance
+# for Open Media Patent License 1.0 was not distributed with this source code in
+# the PATENTS file, you can obtain it at aomedia.org/license/patent-license/.
 #
 if(AOM_BUILD_CMAKE_TOOLCHAINS_X86_LINUX_CMAKE_)
   return()
diff --git a/build/cmake/toolchains/x86-macos.cmake b/build/cmake/toolchains/x86-macos.cmake
index 095ef18..f5bb1f2 100644
--- a/build/cmake/toolchains/x86-macos.cmake
+++ b/build/cmake/toolchains/x86-macos.cmake
@@ -1,12 +1,12 @@
 #
-# Copyright (c) 2017, Alliance for Open Media. All rights reserved
+# Copyright (c) 2021, Alliance for Open Media. All rights reserved
 #
-# This source code is subject to the terms of the BSD 2 Clause License and the
-# Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License was
-# not distributed with this source code in the LICENSE file, you can obtain it
-# at www.aomedia.org/license/software. If the Alliance for Open Media Patent
-# License 1.0 was not distributed with this source code in the PATENTS file, you
-# can obtain it at www.aomedia.org/license/patent.
+# This source code is subject to the terms of the BSD 3-Clause Clear License and
+# the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+# License was not distributed with this source code in the LICENSE file, you can
+# obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance
+# for Open Media Patent License 1.0 was not distributed with this source code in
+# the PATENTS file, you can obtain it at aomedia.org/license/patent-license/.
 #
 set(CMAKE_SYSTEM_PROCESSOR "x86")
 set(CMAKE_SYSTEM_NAME "Darwin")
@@ -15,4 +15,6 @@
 set(CMAKE_CXX_COMPILER_ARG1 "-arch i386")
 
 # Apple tools always complain in 32 bit mode without PIC.
-set(CONFIG_PIC 1 CACHE STRING "")
+set(CONFIG_PIC
+    1
+    CACHE STRING "")
diff --git a/build/cmake/toolchains/x86-mingw-gcc.cmake b/build/cmake/toolchains/x86-mingw-gcc.cmake
index 4839c9d..9f2cdba 100644
--- a/build/cmake/toolchains/x86-mingw-gcc.cmake
+++ b/build/cmake/toolchains/x86-mingw-gcc.cmake
@@ -1,12 +1,12 @@
 #
-# Copyright (c) 2017, Alliance for Open Media. All rights reserved
+# Copyright (c) 2021, Alliance for Open Media. All rights reserved
 #
-# This source code is subject to the terms of the BSD 2 Clause License and the
-# Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License was
-# not distributed with this source code in the LICENSE file, you can obtain it
-# at www.aomedia.org/license/software. If the Alliance for Open Media Patent
-# License 1.0 was not distributed with this source code in the PATENTS file, you
-# can obtain it at www.aomedia.org/license/patent.
+# This source code is subject to the terms of the BSD 3-Clause Clear License and
+# the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+# License was not distributed with this source code in the LICENSE file, you can
+# obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance
+# for Open Media Patent License 1.0 was not distributed with this source code in
+# the PATENTS file, you can obtain it at aomedia.org/license/patent-license/.
 #
 if(AOM_BUILD_CMAKE_TOOLCHAINS_X86_MINGW_GCC_CMAKE_)
   return()
@@ -24,5 +24,9 @@
 
 set(CMAKE_C_COMPILER ${CROSS}gcc)
 set(CMAKE_CXX_COMPILER ${CROSS}g++)
-set(CMAKE_AR ${CROSS}ar CACHE FILEPATH Archiver)
-set(CMAKE_RANLIB ${CROSS}ranlib CACHE FILEPATH Indexer)
+set(CMAKE_AR
+    ${CROSS}ar
+    CACHE FILEPATH Archiver)
+set(CMAKE_RANLIB
+    ${CROSS}ranlib
+    CACHE FILEPATH Indexer)
diff --git a/build/cmake/toolchains/x86_64-ios-simulator.cmake b/build/cmake/toolchains/x86_64-ios-simulator.cmake
index d4b40ed..b45964b 100644
--- a/build/cmake/toolchains/x86_64-ios-simulator.cmake
+++ b/build/cmake/toolchains/x86_64-ios-simulator.cmake
@@ -1,12 +1,12 @@
 #
-# Copyright (c) 2017, Alliance for Open Media. All rights reserved
+# Copyright (c) 2021, Alliance for Open Media. All rights reserved
 #
-# This source code is subject to the terms of the BSD 2 Clause License and the
-# Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License was
-# not distributed with this source code in the LICENSE file, you can obtain it
-# at www.aomedia.org/license/software. If the Alliance for Open Media Patent
-# License 1.0 was not distributed with this source code in the PATENTS file, you
-# can obtain it at www.aomedia.org/license/patent.
+# This source code is subject to the terms of the BSD 3-Clause Clear License and
+# the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+# License was not distributed with this source code in the LICENSE file, you can
+# obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance
+# for Open Media Patent License 1.0 was not distributed with this source code in
+# the PATENTS file, you can obtain it at aomedia.org/license/patent-license/.
 #
 if(AOM_BUILD_CMAKE_TOOLCHAINS_X86_64_IOS_SIMULATOR_CMAKE_)
   return()
diff --git a/build/cmake/toolchains/x86_64-mingw-gcc.cmake b/build/cmake/toolchains/x86_64-mingw-gcc.cmake
index 4b2d28d..9f50411 100644
--- a/build/cmake/toolchains/x86_64-mingw-gcc.cmake
+++ b/build/cmake/toolchains/x86_64-mingw-gcc.cmake
@@ -1,12 +1,12 @@
 #
-# Copyright (c) 2017, Alliance for Open Media. All rights reserved
+# Copyright (c) 2021, Alliance for Open Media. All rights reserved
 #
-# This source code is subject to the terms of the BSD 2 Clause License and the
-# Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License was
-# not distributed with this source code in the LICENSE file, you can obtain it
-# at www.aomedia.org/license/software. If the Alliance for Open Media Patent
-# License 1.0 was not distributed with this source code in the PATENTS file, you
-# can obtain it at www.aomedia.org/license/patent.
+# This source code is subject to the terms of the BSD 3-Clause Clear License and
+# the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+# License was not distributed with this source code in the LICENSE file, you can
+# obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance
+# for Open Media Patent License 1.0 was not distributed with this source code in
+# the PATENTS file, you can obtain it at aomedia.org/license/patent-license/.
 #
 if(AOM_BUILD_CMAKE_TOOLCHAINS_X86_64_MINGW_GCC_CMAKE_)
   return()
@@ -22,5 +22,9 @@
 
 set(CMAKE_C_COMPILER ${CROSS}gcc)
 set(CMAKE_CXX_COMPILER ${CROSS}g++)
-set(CMAKE_AR ${CROSS}ar CACHE FILEPATH Archiver)
-set(CMAKE_RANLIB ${CROSS}ranlib CACHE FILEPATH Indexer)
+set(CMAKE_AR
+    ${CROSS}ar
+    CACHE FILEPATH Archiver)
+set(CMAKE_RANLIB
+    ${CROSS}ranlib
+    CACHE FILEPATH Indexer)
diff --git a/build/cmake/util.cmake b/build/cmake/util.cmake
index 9b3da84..b33ed93 100644
--- a/build/cmake/util.cmake
+++ b/build/cmake/util.cmake
@@ -1,12 +1,12 @@
 #
-# Copyright (c) 2017, Alliance for Open Media. All rights reserved
+# Copyright (c) 2021, Alliance for Open Media. All rights reserved
 #
-# This source code is subject to the terms of the BSD 2 Clause License and the
-# Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License was
-# not distributed with this source code in the LICENSE file, you can obtain it
-# at www.aomedia.org/license/software. If the Alliance for Open Media Patent
-# License 1.0 was not distributed with this source code in the PATENTS file, you
-# can obtain it at www.aomedia.org/license/patent.
+# This source code is subject to the terms of the BSD 3-Clause Clear License and
+# the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+# License was not distributed with this source code in the LICENSE file, you can
+# obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance
+# for Open Media Patent License 1.0 was not distributed with this source code in
+# the PATENTS file, you can obtain it at aomedia.org/license/patent-license/.
 #
 if(AOM_BUILD_CMAKE_UTIL_CMAKE_)
   return()
@@ -21,11 +21,12 @@
 # variable referred to by $out_file_list_var parameter.
 macro(create_dummy_source_file basename extension out_file_list_var)
   set(dummy_source_file "${AOM_GEN_SRC_DIR}/${basename}_dummy.${extension}")
-  file(WRITE "${dummy_source_file}"
-       "// Generated file. DO NOT EDIT!\n"
-       "// ${target_name} needs a ${extension} file to force link language, \n"
-       "// or to silence a harmless CMake warning: Ignore me.\n"
-       "void aom_${target_name}_dummy_function(void) {}\n")
+  file(
+    WRITE "${dummy_source_file}"
+    "// Generated file. DO NOT EDIT!\n"
+    "// ${target_name} needs a ${extension} file to force link language, \n"
+    "// or to silence a harmless CMake warning: Ignore me.\n"
+    "void aom_${target_name}_dummy_function(void) {}\n")
   list(APPEND "${out_file_list_var}" "${dummy_source_file}")
 endmacro()
 
@@ -45,7 +46,9 @@
   if(${feature} EQUAL ${value})
     return()
   endif()
-  set(${feature} ${value} PARENT_SCOPE)
+  set(${feature}
+      ${value}
+      PARENT_SCOPE)
   if(${value} EQUAL 1)
     set(verb "Enabled")
     set(reason "required for")
@@ -71,7 +74,9 @@
   if(${v_pos} EQUAL 0)
     string(SUBSTRING "${aom_version}" 1 -1 aom_version)
   endif()
-  set("${version_string_out_var}" "${aom_version}" PARENT_SCOPE)
+  set("${version_string_out_var}"
+      "${aom_version}"
+      PARENT_SCOPE)
 endfunction()
 
 # Sets CMake compiler launcher to $launcher_name when $launcher_name is found in
@@ -80,8 +85,12 @@
 function(set_compiler_launcher launcher_flag launcher_name)
   find_program(launcher_path "${launcher_name}")
   if(launcher_path)
-    set(CMAKE_C_COMPILER_LAUNCHER "${launcher_path}" PARENT_SCOPE)
-    set(CMAKE_CXX_COMPILER_LAUNCHER "${launcher_path}" PARENT_SCOPE)
+    set(CMAKE_C_COMPILER_LAUNCHER
+        "${launcher_path}"
+        PARENT_SCOPE)
+    set(CMAKE_CXX_COMPILER_LAUNCHER
+        "${launcher_path}"
+        PARENT_SCOPE)
     message("--- Using ${launcher_name} as compiler launcher.")
   else()
     message(
@@ -111,9 +120,14 @@
   # Update the variable only when it does not carry the CMake assigned help
   # string for variables specified via the command line.
   unset(cache_helpstring)
-  get_property(cache_helpstring CACHE ${name} PROPERTY HELPSTRING)
+  get_property(
+    cache_helpstring
+    CACHE ${name}
+    PROPERTY HELPSTRING)
   if(NOT "${cache_helpstring}" STREQUAL "${cmake_cmdline_helpstring}")
-    set(${name} ${value} CACHE STRING "${helpstring}")
+    set(${name}
+        ${value}
+        CACHE STRING "${helpstring}")
     mark_as_advanced(${name})
   else()
     message(
@@ -141,9 +155,14 @@
   # Update the variable only when it does not carry the CMake assigned help
   # string for variables specified via the command line.
   unset(cache_helpstring)
-  get_property(cache_helpstring CACHE ${name} PROPERTY HELPSTRING)
+  get_property(
+    cache_helpstring
+    CACHE ${name}
+    PROPERTY HELPSTRING)
   if(NOT "${cache_helpstring}" STREQUAL "${cmake_cmdline_helpstring}")
-    set(${name} ${value} CACHE STRING "${helpstring}")
+    set(${name}
+        ${value}
+        CACHE STRING "${helpstring}")
   endif()
 endmacro()
 
@@ -165,7 +184,10 @@
   # Update the variable only when it does not carry the CMake assigned help
   # string for variables specified via the command line.
   unset(cache_helpstring)
-  get_property(cache_helpstring CACHE ${name} PROPERTY HELPSTRING)
+  get_property(
+    cache_helpstring
+    CACHE ${name}
+    PROPERTY HELPSTRING)
   if(NOT "${cache_helpstring}" STREQUAL "${cmake_cmdline_helpstring}")
     option(${name} "${helpstring}" ${value})
   endif()
diff --git a/build/cmake/version.cmake b/build/cmake/version.cmake
index ff3813b..5ae1456 100644
--- a/build/cmake/version.cmake
+++ b/build/cmake/version.cmake
@@ -1,12 +1,12 @@
 #
-# Copyright (c) 2017, Alliance for Open Media. All rights reserved
+# Copyright (c) 2021, Alliance for Open Media. All rights reserved
 #
-# This source code is subject to the terms of the BSD 2 Clause License and the
-# Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License was
-# not distributed with this source code in the LICENSE file, you can obtain it
-# at www.aomedia.org/license/software. If the Alliance for Open Media Patent
-# License 1.0 was not distributed with this source code in the PATENTS file, you
-# can obtain it at www.aomedia.org/license/patent.
+# This source code is subject to the terms of the BSD 3-Clause Clear License and
+# the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+# License was not distributed with this source code in the LICENSE file, you can
+# obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance
+# for Open Media Patent License 1.0 was not distributed with this source code in
+# the PATENTS file, you can obtain it at aomedia.org/license/patent-license/.
 #
 cmake_minimum_required(VERSION 3.5)
 
@@ -25,13 +25,12 @@
 # before the version string 'v*'.
 unset(aom_version)
 if(EXISTS "${GIT_EXECUTABLE}")
-  execute_process(COMMAND ${GIT_EXECUTABLE}
-                          --git-dir=${AOM_ROOT}/.git describe
-                          --match "*-v[0-9]*"
-                          --match "v[0-9]*"
-                  OUTPUT_VARIABLE aom_version
-                  ERROR_QUIET
-                  RESULT_VARIABLE version_check_result)
+  execute_process(
+    COMMAND ${GIT_EXECUTABLE} --git-dir=${AOM_ROOT}/.git describe --match
+            "*-v[0-9]*" --match "v[0-9]*"
+    OUTPUT_VARIABLE aom_version
+    ERROR_QUIET
+    RESULT_VARIABLE version_check_result)
 
   if(${version_check_result} EQUAL 0)
     string(STRIP "${aom_version}" aom_version)
@@ -69,8 +68,8 @@
 if(NOT "${aom_version}" STREQUAL "${last_aom_version}")
   # TODO(tomfinegan): Perl dependency is unnecessary. CMake can do everything
   # that is done by version.pl on its own (if a bit more verbosely...).
-  execute_process(COMMAND ${PERL_EXECUTABLE}
-                          "${AOM_ROOT}/build/cmake/version.pl"
-                          --version_data=${aom_version}
-                          --version_filename=${version_file} VERBATIM)
+  execute_process(
+    COMMAND
+      ${PERL_EXECUTABLE} "${AOM_ROOT}/build/cmake/version.pl"
+      --version_data=${aom_version} --version_filename=${version_file} VERBATIM)
 endif()
diff --git a/build/cmake/version.pl b/build/cmake/version.pl
index 7d23f2b..3878ef3 100755
--- a/build/cmake/version.pl
+++ b/build/cmake/version.pl
@@ -1,13 +1,13 @@
 #!/usr/bin/env perl
 ##
-## Copyright (c) 2016, Alliance for Open Media. All rights reserved
+## Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ##
-## This source code is subject to the terms of the BSD 2 Clause License and
-## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-## was not distributed with this source code in the LICENSE file, you can
-## obtain it at www.aomedia.org/license/software. If the Alliance for Open
-## Media Patent License 1.0 was not distributed with this source code in the
-## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+## This source code is subject to the terms of the BSD 3-Clause Clear License and the
+## Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+## not distributed with this source code in the LICENSE file, you can obtain it
+## at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+## License 1.0 was not distributed with this source code in the PATENTS file, you
+## can obtain it at aomedia.org/license/patent-license/.
 ##
 use strict;
 use warnings;
diff --git a/common/args.c b/common/args.c
index 6665645..cf5a22f 100644
--- a/common/args.c
+++ b/common/args.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "common/args.h"
@@ -94,6 +95,9 @@
 #if CONFIG_IST
     GET_PARAMS(enable_ist);
 #endif
+#if CONFIG_IBP_DC || CONFIG_IBP_DIR
+    GET_PARAMS(enable_ibp);
+#endif
     GET_PARAMS(enable_flip_idtx);
     GET_PARAMS(enable_deblocking);
     GET_PARAMS(enable_cdef);
@@ -104,9 +108,6 @@
     GET_PARAMS(enable_obmc);
     GET_PARAMS(enable_warped_motion);
     GET_PARAMS(enable_global_motion);
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-    GET_PARAMS(enable_dist_wtd_comp);
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
     GET_PARAMS(enable_diff_wtd_comp);
     GET_PARAMS(enable_interintra_comp);
     GET_PARAMS(enable_masked_comp);
@@ -120,6 +121,9 @@
     GET_PARAMS(enable_dual_filter);
 #endif  // !CONFIG_REMOVE_DUAL_FILTER
     GET_PARAMS(enable_angle_delta);
+#if CONFIG_OPTFLOW_REFINEMENT
+    GET_PARAMS(enable_opfl_refine);
+#endif  // CONFIG_OPTFLOW_REFINEMENT
     GET_PARAMS(enable_intra_edge_filter);
     GET_PARAMS(enable_tx64);
     GET_PARAMS(enable_smooth_interintra);
@@ -133,6 +137,9 @@
 #if CONFIG_NEW_INTER_MODES
     GET_PARAMS(max_drl_refmvs);
 #endif  // CONFIG_NEW_INTER_MODES
+#if CONFIG_REF_MV_BANK
+    GET_PARAMS(enable_refmvbank);
+#endif  // CONFIG_REF_MV_BANK
 
     fprintf(stderr, "\nInvalid parameter: %s", left);
     exit(-1);
diff --git a/common/args.h b/common/args.h
index 1c5c437..fdeadd0 100644
--- a/common/args.h
+++ b/common/args.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_COMMON_ARGS_H_
diff --git a/common/args_helper.c b/common/args_helper.c
index 776a4d4..0f9e346 100644
--- a/common/args_helper.c
+++ b/common/args_helper.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/common/args_helper.h b/common/args_helper.h
index c86a612..474bcbc 100644
--- a/common/args_helper.h
+++ b/common/args_helper.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_COMMON_ARGS_HELPER_H_
diff --git a/common/av1_config.c b/common/av1_config.c
index 1d77e78..0e64b52 100644
--- a/common/av1_config.c
+++ b/common/av1_config.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #include <stdio.h>
 #include <string.h>
@@ -232,6 +233,26 @@
 // Parse Sequence Header OBU for coding tools beyond AV1
 int parse_sequence_header_beyond_av1(struct aom_read_bit_buffer *reader) {
   int result = 0;
+#if CONFIG_REF_MV_BANK
+  AV1C_READ_BIT_OR_RETURN_ERROR(enable_refmvbank);
+#endif  // CONFIG_REF_MV_BANK
+#if CONFIG_NEW_REF_SIGNALING
+  int reduced_ref_frame_set = 0;
+  do {
+    reduced_ref_frame_set = aom_rb_read_bit(reader);
+    if (result == -1) {
+      fprintf(stderr,
+              "av1c: Error reading bit for \" reduced_ref_frame_set \", "
+              "value=%d result=%d.\n",
+              reduced_ref_frame_set, result);
+      return -1;
+    }
+  } while (0);
+  if (reduced_ref_frame_set) {
+    AV1C_READ_BITS_OR_RETURN_ERROR(max_reference_frames, 2);
+  }
+  AV1C_READ_BIT_OR_RETURN_ERROR(explicit_ref_frame_map);
+#endif  // CONFIG_NEW_REF_SIGNALING
 #if CONFIG_SDP
   AV1C_READ_BIT_OR_RETURN_ERROR(enable_sdp);
 #endif
@@ -247,6 +268,9 @@
 #if CONFIG_ORIP
   AV1C_READ_BIT_OR_RETURN_ERROR(enable_orip);
 #endif
+#if CONFIG_IBP_DC || CONFIG_IBP_DIR
+  AV1C_READ_BIT_OR_RETURN_ERROR(enable_ibp);
+#endif
 
   return 0;
 }
@@ -368,10 +392,10 @@
 
     AV1C_READ_BIT_OR_RETURN_ERROR(enable_order_hint);
     if (enable_order_hint) {
-#if !CONFIG_REMOVE_DIST_WTD_COMP
-      AV1C_READ_BIT_OR_RETURN_ERROR(enable_dist_wtd_comp);
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP
       AV1C_READ_BIT_OR_RETURN_ERROR(enable_ref_frame_mvs);
+#if CONFIG_OPTFLOW_REFINEMENT
+      AV1C_READ_BIT_OR_RETURN_ERROR(enable_opfl_refine);
+#endif  // CONFIG_OPTFLOW_REFINEMENT
     }
 
     const int SELECT_SCREEN_CONTENT_TOOLS = 2;
diff --git a/common/av1_config.h b/common/av1_config.h
index a15bedb..f68c1b6 100644
--- a/common/av1_config.h
+++ b/common/av1_config.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #ifndef AOM_COMMON_AV1_CONFIG_H_
 #define AOM_COMMON_AV1_CONFIG_H_
diff --git a/common/fake_dl.cc b/common/fake_dl.cc
index 609c414..6b7880e 100644
--- a/common/fake_dl.cc
+++ b/common/fake_dl.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 // TensorFlow Lite uses dlsym and dlopen when using delegates,
diff --git a/common/fake_dl.h b/common/fake_dl.h
index 5f0604b..c75c818 100644
--- a/common/fake_dl.h
+++ b/common/fake_dl.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_COMMON_FAKE_DL_H_
diff --git a/common/ivfdec.c b/common/ivfdec.c
index 80d73b0..7eee07f 100644
--- a/common/ivfdec.c
+++ b/common/ivfdec.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "common/ivfdec.h"
diff --git a/common/ivfdec.h b/common/ivfdec.h
index dbc7733..652b449 100644
--- a/common/ivfdec.h
+++ b/common/ivfdec.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #ifndef AOM_COMMON_IVFDEC_H_
 #define AOM_COMMON_IVFDEC_H_
diff --git a/common/ivfenc.c b/common/ivfenc.c
index 64715f4..ffbcf8c 100644
--- a/common/ivfenc.c
+++ b/common/ivfenc.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "common/ivfenc.h"
diff --git a/common/ivfenc.h b/common/ivfenc.h
index 8f6d947..6b08916 100644
--- a/common/ivfenc.h
+++ b/common/ivfenc.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #ifndef AOM_COMMON_IVFENC_H_
 #define AOM_COMMON_IVFENC_H_
diff --git a/common/obudec.c b/common/obudec.c
index 650f997..4826f92 100644
--- a/common/obudec.c
+++ b/common/obudec.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <stdio.h>
diff --git a/common/obudec.h b/common/obudec.h
index b2adb1e..6f02687 100644
--- a/common/obudec.h
+++ b/common/obudec.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #ifndef AOM_COMMON_OBUDEC_H_
 #define AOM_COMMON_OBUDEC_H_
diff --git a/common/rawenc.c b/common/rawenc.c
index b72132c..4ff0293 100644
--- a/common/rawenc.c
+++ b/common/rawenc.c
@@ -1,16 +1,18 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <stdbool.h>
 #include "common/rawenc.h"
+#include <stdlib.h>
 
 #define BATCH_SIZE 8
 // When writing greyscale color, batch 8 writes for low bit-depth, 4 writes
@@ -78,9 +80,23 @@
     }
     const unsigned char *buf = img->planes[plane];
     const int stride = img->stride[plane];
-    for (int y = 0; y < h; ++y) {
-      writer_func(file_or_md5, buf, bytes_per_sample, w);
-      buf += stride;
+    if (high_bitdepth && img->bit_depth == 8) {
+      // convert 16-bit buffer to 8-bit (input bitdepth) buffer
+      uint8_t *buf8 = (uint8_t *)malloc(sizeof(*buf8) * w);
+      for (int y = 0; y < h; ++y) {
+        uint16_t *buf16 = (uint16_t *)buf;
+        for (int x = 0; x < w; ++x) {
+          buf8[x] = buf16[x] & 0xff;
+        }
+        writer_func(file_or_md5, buf8, 1, w);
+        buf += stride;
+      }
+      free(buf8);
+    } else {
+      for (int y = 0; y < h; ++y) {
+        writer_func(file_or_md5, buf, bytes_per_sample, w);
+        buf += stride;
+      }
     }
   }
 }
diff --git a/common/rawenc.h b/common/rawenc.h
index cf5e00e..f2755e6 100644
--- a/common/rawenc.h
+++ b/common/rawenc.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_COMMON_RAWENC_H_
diff --git a/common/stream_iter.c b/common/stream_iter.c
index bf523d8..078be62 100644
--- a/common/stream_iter.c
+++ b/common/stream_iter.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/common/stream_iter.h b/common/stream_iter.h
index af98a2a..73781c7 100644
--- a/common/stream_iter.h
+++ b/common/stream_iter.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #ifndef AOM_COMMON_STREAM_ITER_H_
 #define AOM_COMMON_STREAM_ITER_H_
diff --git a/common/tf_lite_includes.h b/common/tf_lite_includes.h
index 2c35d5f..debacdd 100644
--- a/common/tf_lite_includes.h
+++ b/common/tf_lite_includes.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_COMMON_TF_LITE_INCLUDES_H_
diff --git a/common/tools_common.c b/common/tools_common.c
index 6040b4b..5ddec93 100644
--- a/common/tools_common.c
+++ b/common/tools_common.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/common/tools_common.h b/common/tools_common.h
index 873a720..a6ad507 100644
--- a/common/tools_common.h
+++ b/common/tools_common.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #ifndef AOM_COMMON_TOOLS_COMMON_H_
 #define AOM_COMMON_TOOLS_COMMON_H_
diff --git a/common/video_common.h b/common/video_common.h
index bf95031..023a699 100644
--- a/common/video_common.h
+++ b/common/video_common.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_COMMON_VIDEO_COMMON_H_
diff --git a/common/video_reader.c b/common/video_reader.c
index 7b021bc..450d5dc 100644
--- a/common/video_reader.c
+++ b/common/video_reader.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #include <stdlib.h>
 #include <string.h>
diff --git a/common/video_reader.h b/common/video_reader.h
index 9ab439e..c6c6e8b 100644
--- a/common/video_reader.h
+++ b/common/video_reader.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_COMMON_VIDEO_READER_H_
diff --git a/common/video_writer.c b/common/video_writer.c
index 1d4328a..842eae3 100644
--- a/common/video_writer.c
+++ b/common/video_writer.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #include "common/video_writer.h"
 
diff --git a/common/video_writer.h b/common/video_writer.h
index 8712d47..3640f36 100644
--- a/common/video_writer.h
+++ b/common/video_writer.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_COMMON_VIDEO_WRITER_H_
diff --git a/common/warnings.c b/common/warnings.c
index efe7ae2..5534b24 100644
--- a/common/warnings.c
+++ b/common/warnings.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "common/warnings.h"
diff --git a/common/warnings.h b/common/warnings.h
index 36f1fe0..23d4621 100644
--- a/common/warnings.h
+++ b/common/warnings.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #ifndef AOM_COMMON_WARNINGS_H_
 #define AOM_COMMON_WARNINGS_H_
diff --git a/common/webmdec.cc b/common/webmdec.cc
index 33bda59..b3601d4 100644
--- a/common/webmdec.cc
+++ b/common/webmdec.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "common/webmdec.h"
diff --git a/common/webmdec.h b/common/webmdec.h
index 5ac75cb..8408525 100644
--- a/common/webmdec.h
+++ b/common/webmdec.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #ifndef AOM_COMMON_WEBMDEC_H_
 #define AOM_COMMON_WEBMDEC_H_
diff --git a/common/webmenc.cc b/common/webmenc.cc
index bb754e8..cf4b3e0 100644
--- a/common/webmenc.cc
+++ b/common/webmenc.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "common/webmenc.h"
diff --git a/common/webmenc.h b/common/webmenc.h
index c912208..4783bf2 100644
--- a/common/webmenc.h
+++ b/common/webmenc.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #ifndef AOM_COMMON_WEBMENC_H_
 #define AOM_COMMON_WEBMENC_H_
diff --git a/common/y4menc.c b/common/y4menc.c
index d228eaa..a13fc27 100644
--- a/common/y4menc.c
+++ b/common/y4menc.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
@@ -52,30 +53,25 @@
   switch (bit_depth) {
     case 8: return colorspace8(csp, fmt);
     case 9:
-      return fmt == AOM_IMG_FMT_I44416
-                 ? "C444p9 XYSCSS=444P9"
-                 : fmt == AOM_IMG_FMT_I42216 ? "C422p9 XYSCSS=422P9"
-                                             : "C420p9 XYSCSS=420P9";
+      return fmt == AOM_IMG_FMT_I44416   ? "C444p9 XYSCSS=444P9"
+             : fmt == AOM_IMG_FMT_I42216 ? "C422p9 XYSCSS=422P9"
+                                         : "C420p9 XYSCSS=420P9";
     case 10:
-      return fmt == AOM_IMG_FMT_I44416
-                 ? "C444p10 XYSCSS=444P10"
-                 : fmt == AOM_IMG_FMT_I42216 ? "C422p10 XYSCSS=422P10"
-                                             : "C420p10 XYSCSS=420P10";
+      return fmt == AOM_IMG_FMT_I44416   ? "C444p10 XYSCSS=444P10"
+             : fmt == AOM_IMG_FMT_I42216 ? "C422p10 XYSCSS=422P10"
+                                         : "C420p10 XYSCSS=420P10";
     case 12:
-      return fmt == AOM_IMG_FMT_I44416
-                 ? "C444p12 XYSCSS=444P12"
-                 : fmt == AOM_IMG_FMT_I42216 ? "C422p12 XYSCSS=422P12"
-                                             : "C420p12 XYSCSS=420P12";
+      return fmt == AOM_IMG_FMT_I44416   ? "C444p12 XYSCSS=444P12"
+             : fmt == AOM_IMG_FMT_I42216 ? "C422p12 XYSCSS=422P12"
+                                         : "C420p12 XYSCSS=420P12";
     case 14:
-      return fmt == AOM_IMG_FMT_I44416
-                 ? "C444p14 XYSCSS=444P14"
-                 : fmt == AOM_IMG_FMT_I42216 ? "C422p14 XYSCSS=422P14"
-                                             : "C420p14 XYSCSS=420P14";
+      return fmt == AOM_IMG_FMT_I44416   ? "C444p14 XYSCSS=444P14"
+             : fmt == AOM_IMG_FMT_I42216 ? "C422p14 XYSCSS=422P14"
+                                         : "C420p14 XYSCSS=420P14";
     case 16:
-      return fmt == AOM_IMG_FMT_I44416
-                 ? "C444p16 XYSCSS=444P16"
-                 : fmt == AOM_IMG_FMT_I42216 ? "C422p16 XYSCSS=422P16"
-                                             : "C420p16 XYSCSS=420P16";
+      return fmt == AOM_IMG_FMT_I44416   ? "C444p16 XYSCSS=444P16"
+             : fmt == AOM_IMG_FMT_I42216 ? "C422p16 XYSCSS=422P16"
+                                         : "C420p16 XYSCSS=420P16";
     default: assert(0); return NULL;
   }
 }
diff --git a/common/y4menc.h b/common/y4menc.h
index f6d5fd8..1a45b05 100644
--- a/common/y4menc.h
+++ b/common/y4menc.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_COMMON_Y4MENC_H_
diff --git a/common/y4minput.c b/common/y4minput.c
index 12d3c94..754831f 100644
--- a/common/y4minput.c
+++ b/common/y4minput.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  *
  * Based on code from the OggTheora software codec source code,
  * Copyright (C) 2002-2010 The Xiph.Org Foundation and contributors.
diff --git a/common/y4minput.h b/common/y4minput.h
index f6c5a3d..5771464 100644
--- a/common/y4minput.h
+++ b/common/y4minput.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  *
  * Based on code from the OggTheora software codec source code,
  * Copyright (C) 2002-2010 The Xiph.Org Foundation and contributors.
diff --git a/doc/AlgorithmDescription.md b/doc/AlgorithmDescription.md
index 799f2c7..47fe0e5 100644
--- a/doc/AlgorithmDescription.md
+++ b/doc/AlgorithmDescription.md
@@ -62,7 +62,7 @@
 addition to no split mode `PARTITION_NONE`, the partition tree supports 9
 different partitioning patterns, as shown in below figure.
 
-<figure class="image"> <center><img src="img\partition_codingblock.svg"
+<figure class="image"> <center><img src="img/partition_codingblock.svg"
 alt="Partition" width="360" /> <figcaption>Figure 1: Supported coding block
 partitions</figcaption> </figure>
 
@@ -86,7 +86,7 @@
 transform size of the next depth is shown in the following Table 1.
 
 <figure class="image"> <center><figcaption>Table 1: Transform partition size
-setting</figcaption> <img src="img\tx_partition.svg" alt="Partition" width="220"
+setting</figcaption> <img src="img/tx_partition.svg" alt="Partition" width="220"
 /> </figure>
 
 Furthermore, for intra coded blocks, the transform partition is done in a way
@@ -94,7 +94,7 @@
 coded in a raster scan order. An example of the transform block partitioning for
 intra coded block is shown in the Figure 2.
 
-<figure class="image"> <center><img src="img\intra_tx_partition.svg"
+<figure class="image"> <center><img src="img/intra_tx_partition.svg"
 alt="Partition" width="600" /> <figcaption>Figure 2: Example of transform
 partitioning for intra coded block</figcaption> </figure>
 
@@ -108,7 +108,7 @@
 luma and chroma coding blocks will implicitly split into multiples of min(W,
 64)x min(H, 64) and min(W, 32)x min(H, 32) transform blocks, respectively.
 
-<figure class="image"> <center><img src="img\inter_tx_partition.svg"
+<figure class="image"> <center><img src="img/inter_tx_partition.svg"
 alt="Partition" width="400" /> <figcaption>Figure 3: Example of transform
 partitioning for inter coded block</figcaption> </figure>
 
@@ -127,7 +127,7 @@
 indicate directional intra prediction modes and dotted arrows represent non-zero
 angle delta.
 
-<figure class="image"> <center><img src="img\intra_directional.svg"
+<figure class="image"> <center><img src="img/intra_directional.svg"
 alt="Directional intra" width="300" /> <figcaption>Figure 4: Directional intra
 prediction modes</figcaption> </figure>
 
@@ -155,7 +155,7 @@
 value closest to the Paeth predictor value, i.e., T + L -TL. The samples used in
 `PAETH predictor` are illustrated in below figure.
 
-<figure class="image"> <center><img src="img\intra_paeth.svg" alt="Directional
+<figure class="image"> <center><img src="img/intra_paeth.svg" alt="Directional
 intra" width="300" /> <figcaption>Figure 5: Paeth predictor</figcaption>
 </figure>
 
@@ -170,7 +170,7 @@
 4x2 sub-block, which means that prediction samples generated for one 4x2
 prediction block can be used to predict another 4x2 sub-block.
 
-<figure class="image"> <center><img src="img\intra_recursive.svg"
+<figure class="image"> <center><img src="img/intra_recursive.svg"
 alt="Directional intra" width="300" /> <figcaption>Figure 6: Recursive filtering
 modes</figcaption> </figure>
 
@@ -185,7 +185,7 @@
 specify the linear function between two color components are optimized by
 encoder signalled in the bitstream.
 
-<figure class="image"> <center><img src="img\intra_cfl.svg" alt="Directional
+<figure class="image"> <center><img src="img/intra_cfl.svg" alt="Directional
 intra" width="700" /> <figcaption>Figure 7: CfL prediction</figcaption>
 </figure>
 
@@ -207,7 +207,7 @@
 two sets of spatial neighboring blocks are illustrated in an example shown in
 Figure 8.
 
-<figure class="image"> <center><img src="img\inter_spatial_mvp.svg"
+<figure class="image"> <center><img src="img/inter_spatial_mvp.svg"
 alt="Directional intra" width="350" /><figcaption>Figure 8: Motion field
 estimation by linear projection</figcaption></figure>
 
@@ -236,7 +236,7 @@
 (R1) pointing from R1 to a reference frame of R1 is identified, i.e., MVref,
 which passes a 8x8 block (shaded in blue dots) of current frame. Then this MVref
 is stored in the temporal MV buffer associated with this 8x8 block. <figure
-class="image"> <center><img src="img\inter_motion_field.svg" alt="Directional
+class="image"> <center><img src="img/inter_motion_field.svg" alt="Directional
 intra" width="800" /><figcaption>Figure 9: Motion field estimation by linear
 projection</figcaption></figure> Finally, given a couple of pre-defined block
 coordinates, the associated MVs stored in the temporal MV buffer are identified
@@ -245,7 +245,7 @@
 the pre-defined block positions for deriving temporal MV predictors of a 16x16
 block are shown and up to 7 blocks will be checked to find valid temporal MV
 predictors.<figure class="image"> <center><img
-src="img\inter_tmvp_positions.svg" alt="Directional intra" width="300"
+src="img/inter_tmvp_positions.svg" alt="Directional intra" width="300"
 /><figcaption>Figure 10: Block positions for deriving temporal MV
 predictors</figcaption></figure> The temporal MV predictors are checked after
 the nearest spatial MV predictors but before the non-adjacent spatial MV
@@ -334,7 +334,7 @@
 marked in grey in the following picture. The motion vectors of block 2, 3, 4 are
 further applied and blended in the same way.
 
-<figure class="image"> <center><img src="img\inter_obmc.svg" alt="Directional
+<figure class="image"> <center><img src="img/inter_obmc.svg" alt="Directional
 intra" width="300" /><figcaption>Figure 11: neighboring blocks for OBMC
 process</figcaption></figure>
 
@@ -379,7 +379,7 @@
 
 <figure class="image"> <center><figcaption>Table 2: Transform basis functions
 (DCT-2, DST-4 and DST-7 for N-point input.</figcaption> <img src=
-"img\tx_basis.svg" alt="Partition" width="450" /> </figure>
+"img/tx_basis.svg" alt="Partition" width="450" /> </figure>
 
 For luma component, each transform block can select one pair of horizontal and
 vertical transform combination given a pre-defined set of transform type
@@ -393,18 +393,18 @@
 
 <figure class="image"> <center><figcaption>Table 3: Transform type candidates
 for luma component when max(width, height) is greater than or equal to 32.
-</figcaption> <img src="img\tx_cands_large.svg" alt="Partition" width="370" />
+</figcaption> <img src="img/tx_cands_large.svg" alt="Partition" width="370" />
 </figure>
 
 <figure class="image"> <center><figcaption>Table 4: Transform type candidates
 for luma component when max(width, height) is smaller than 32. </figcaption>
-<img src="img\tx_cands_small.svg" alt="Partition" width="440" /> </figure>
+<img src="img/tx_cands_small.svg" alt="Partition" width="440" /> </figure>
 
 The set of transform type candidates (namely transform set) is defined in Table
 5.
 
 <figure class="image"> <center><figcaption>Table 5: Definition of transform set.
-</figcaption> <img src="img\tx_set.svg" alt="Partition" width="450" /> </figure>
+</figcaption> <img src="img/tx_set.svg" alt="Partition" width="450" /> </figure>
 
 For chroma component, the transform type selection is done in an implicit way.
 For intra prediction residuals, the transform type is selected according to the
@@ -415,7 +415,7 @@
 
 <figure class="image"> <center><figcaption>Table 6: Transform type selection for
 chroma component intra prediction residuals.</figcaption> <img src=
-"img\tx_chroma.svg" alt="Partition" width="500" /> </figure>
+"img/tx_chroma.svg" alt="Partition" width="500" /> </figure>
 
 The computational cost of large size (e.g., 64-point) transforms is further
 reduced by zeroing out all the coefficients except the following two cases:
@@ -456,11 +456,11 @@
 quantization index to quantization step size for 8-bit, 10-bit and 12-bit is
 specified by a lookup table Ac_Qlookup[3][256].
 
-<figure class="image"> <center><img src="img\quant_dc.svg" alt="quant_dc"
+<figure class="image"> <center><img src="img/quant_dc.svg" alt="quant_dc"
 width="800" /><figcaption>Figure 11: Quantization step size of DC coefficients
 for different internal bit-depth</figcaption></figure>
 
-<figure class="image"> <center><img src="img\quant_ac.svg" alt="quant_ac"
+<figure class="image"> <center><img src="img/quant_ac.svg" alt="quant_ac"
 width="800" /><figcaption>Figure 12: Quantization step size of AC coefficients
 for different internal bit-depth</figcaption></figure>
 
@@ -551,14 +551,14 @@
 **Edge Direction Estimation**\
 In CDEF, edge direction search is performed at 8x8 block-level. There are
 eight edge directions in total, as illustrated in Figure 13.
-<figure class="image"> <center><img src="img\edge_direction.svg"
+<figure class="image"> <center><img src="img/edge_direction.svg"
 alt="Edge direction" width="700" /> <figcaption>Figure 13: Line number
 k for pixels following direction d=0:7 in an 8x8 block.</figcaption> </figure>
 
 The optimal edge direction d_opt is found by maximizing the following
 term [3]:
 
-<figure class="image"> <center><img src="img\equ_edge_direction.svg"
+<figure class="image"> <center><img src="img/equ_edge_direction.svg"
 alt="Equation edge direction" width="250" /> </figure>
 <!-- $$d_{opt}=\max_{d} s_d$$
 $$s_d = \sum_{k}\frac{1}{N_{d,k}}(\sum_{p\in P_{d,k}}x_p)^2,$$ -->
@@ -572,20 +572,20 @@
 while the secondary tap forms an oriented 45 degree off the edge direction
  (as shown in Figure 15).
 
-<figure class="image"> <center><img src="img\primary_tap.svg"
+<figure class="image"> <center><img src="img/primary_tap.svg"
 alt="Primary tap" width="700" /> <figcaption>Figure 14: Primary filter
 taps following edge direction. For even strengths a = 2 and b = 4, for
 odd strengths a = 3 and b = 3. The filtered pixel is shown in the
 highlighted center.</figcaption> </figure>
 
-<figure class="image"> <center><img src="img\secondary_tap.svg"
+<figure class="image"> <center><img src="img/secondary_tap.svg"
 alt="Edge direction" width="700" /> <figcaption>Figure 15: Secondary
 filter taps. The filtered pixel is shown in the highlighted center.
 </figcaption> </figure>
 
 CDEF can be described by the following equation:
 
-<figure class="image"> <center><img src="img\equ_dir_search.svg"
+<figure class="image"> <center><img src="img/equ_dir_search.svg"
 alt="Equation direction search" width="720" /> </figure>
 
 <!-- $$y(i,j)=x(i,j)+round(\sum_{m,n}w^{(p)}_{d,m,n}f(x(m,x)-x(i,j),S^{(p)},
@@ -643,13 +643,13 @@
 a combination of the degraded samples, and the difference between the degraded
 samples and the coarse restorations [4]:
 
-<figure class="image"> <center><img src="img\equ_dual_self_guided.svg"
+<figure class="image"> <center><img src="img/equ_dual_self_guided.svg"
 alt="Equation dual self guided filter" width="300" /> </figure>
 <!-- $$X_r = X + \alpha (X_1 - X) + \beta (X_2 - X)$$ -->
 
 At encoder side, alpha and beta are computed using:
 
-<figure class="image"> <center><img src="img\equ_dual_self_para.svg"
+<figure class="image"> <center><img src="img/equ_dual_self_para.svg"
 alt="Equation dual self guided filter parameter" width="220" /> </figure>
 <!-- $${\alpha, \beta}^T = (A^T A) ^{-1} A^T b,$$ -->
 
@@ -667,7 +667,7 @@
 
 Guided filtering can be described by a local linear model:
 
-<figure class="image"> <center><img src="img\equ_guided_filter.svg"
+<figure class="image"> <center><img src="img/equ_guided_filter.svg"
 alt="Equation guided filter" width="155" /> </figure>
 <!-- $$y=Fx+G,$$ -->
 
@@ -771,7 +771,7 @@
 denotes the restricted immediate reconstructed area. When D is one super block,
 the prediction area is shown in below figure.
 
-<figure class="image"> <center><img src="img\SCC_IntraBC.svg" alt="Intra block
+<figure class="image"> <center><img src="img/scc_intrabc.svg" alt="Intra block
 copy" width="600" /> <figcaption>Figure 13: the prediction area for IntraBC mode
 in one super block prediction</figcaption> </figure>
 
diff --git a/docs.cmake b/docs.cmake
index b183b79..4f1f3a4 100644
--- a/docs.cmake
+++ b/docs.cmake
@@ -1,12 +1,12 @@
 #
-# Copyright (c) 2017, Alliance for Open Media. All rights reserved
+# Copyright (c) 2021, Alliance for Open Media. All rights reserved
 #
-# This source code is subject to the terms of the BSD 2 Clause License and the
-# Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License was
-# not distributed with this source code in the LICENSE file, you can obtain it
-# at www.aomedia.org/license/software. If the Alliance for Open Media Patent
-# License 1.0 was not distributed with this source code in the PATENTS file, you
-# can obtain it at www.aomedia.org/license/patent.
+# This source code is subject to the terms of the BSD 3-Clause Clear License and
+# the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+# License was not distributed with this source code in the LICENSE file, you can
+# obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance
+# for Open Media Patent License 1.0 was not distributed with this source code in
+# the PATENTS file, you can obtain it at aomedia.org/license/patent-license/.
 #
 if(AOM_DOCS_CMAKE_)
   return()
@@ -39,23 +39,23 @@
     "${AOM_ROOT}/usage.dox")
 
 if(CONFIG_AV1_DECODER)
-  set(AOM_DOXYGEN_EXAMPLE_SOURCES ${AOM_DOXYGEN_EXAMPLE_SOURCES}
-                                  "${AOM_ROOT}/apps/aomdec.c"
-                                  "${AOM_ROOT}/examples/decode_to_md5.c"
-                                  "${AOM_ROOT}/examples/decode_with_drops.c"
-                                  "${AOM_ROOT}/examples/simple_decoder.c")
+  set(AOM_DOXYGEN_EXAMPLE_SOURCES
+      ${AOM_DOXYGEN_EXAMPLE_SOURCES}
+      "${AOM_ROOT}/apps/aomdec.c"
+      "${AOM_ROOT}/examples/decode_to_md5.c"
+      "${AOM_ROOT}/examples/decode_with_drops.c"
+      "${AOM_ROOT}/examples/simple_decoder.c")
 
-  set(AOM_DOXYGEN_EXAMPLE_DESCRIPTIONS ${AOM_DOXYGEN_EXAMPLE_DESCRIPTIONS}
-                                       "Full featured decoder."
-                                       "Frame by frame MD5 checksum."
-                                       "Drops frames while decoding."
-                                       "Simplified decoder loop.")
+  set(AOM_DOXYGEN_EXAMPLE_DESCRIPTIONS
+      ${AOM_DOXYGEN_EXAMPLE_DESCRIPTIONS} "Full featured decoder."
+      "Frame by frame MD5 checksum." "Drops frames while decoding."
+      "Simplified decoder loop.")
 
   set(AOM_DOXYGEN_SECTIONS ${AOM_DOXYGEN_SECTIONS} "av1_decoder decoder")
 
-  set(AOM_DOXYGEN_SOURCES ${AOM_DOXYGEN_SOURCES} "${AOM_ROOT}/aom/aomdx.h"
-                          "${AOM_ROOT}/usage_dx.dox"
-                          "${AOM_ROOT}/av1/decoder/decoder.h")
+  set(AOM_DOXYGEN_SOURCES
+      ${AOM_DOXYGEN_SOURCES} "${AOM_ROOT}/aom/aomdx.h"
+      "${AOM_ROOT}/usage_dx.dox" "${AOM_ROOT}/av1/decoder/decoder.h")
 
   if(CONFIG_ANALYZER)
     set(AOM_DOXYGEN_EXAMPLE_SOURCES ${AOM_DOXYGEN_EXAMPLE_SOURCES}
@@ -78,19 +78,18 @@
 endif()
 
 if(CONFIG_AV1_ENCODER)
-  set(AOM_DOXYGEN_EXAMPLE_SOURCES ${AOM_DOXYGEN_EXAMPLE_SOURCES}
-                                  "${AOM_ROOT}/apps/aomenc.c"
-                                  "${AOM_ROOT}/examples/lossless_encoder.c"
-                                  "${AOM_ROOT}/examples/set_maps.c"
-                                  "${AOM_ROOT}/examples/simple_encoder.c"
-                                  "${AOM_ROOT}/examples/twopass_encoder.c")
+  set(AOM_DOXYGEN_EXAMPLE_SOURCES
+      ${AOM_DOXYGEN_EXAMPLE_SOURCES}
+      "${AOM_ROOT}/apps/aomenc.c"
+      "${AOM_ROOT}/examples/lossless_encoder.c"
+      "${AOM_ROOT}/examples/set_maps.c"
+      "${AOM_ROOT}/examples/simple_encoder.c"
+      "${AOM_ROOT}/examples/twopass_encoder.c")
 
-  set(AOM_DOXYGEN_EXAMPLE_DESCRIPTIONS ${AOM_DOXYGEN_EXAMPLE_DESCRIPTIONS}
-                                       "Full featured encoder."
-                                       "Simplified lossless encoder."
-                                       "Set active and ROI maps."
-                                       "Simplified encoder loop."
-                                       "Two-pass encoder loop.")
+  set(AOM_DOXYGEN_EXAMPLE_DESCRIPTIONS
+      ${AOM_DOXYGEN_EXAMPLE_DESCRIPTIONS} "Full featured encoder."
+      "Simplified lossless encoder." "Set active and ROI maps."
+      "Simplified encoder loop." "Two-pass encoder loop.")
 
   set(AOM_DOXYGEN_EXAMPLE_SOURCES ${AOM_DOXYGEN_EXAMPLE_SOURCES}
                                   "${AOM_ROOT}/examples/scalable_encoder.c")
@@ -138,12 +137,16 @@
       "${AOM_ROOT}/av1/encoder/rdopt.h"
       "${AOM_ROOT}/av1/encoder/rdopt.c"
       "${AOM_ROOT}/av1/encoder/speed_features.h"
-      "${AOM_ROOT}/av1/encoder/svc_layercontext.c"
-      "${AOM_ROOT}/av1/encoder/svc_layercontext.h"
       "${AOM_ROOT}/av1/encoder/temporal_filter.h"
       "${AOM_ROOT}/av1/encoder/temporal_filter.c"
       "${AOM_ROOT}/av1/encoder/tpl_model.h"
       "${AOM_ROOT}/av1/encoder/tx_search.h")
+
+  if(CONFIG_SVC_ENCODER)
+    set(AOM_DOXYGEN_SOURCES
+        ${AOM_DOXYGEN_SOURCES} "${AOM_ROOT}/av1/encoder/svc_layercontext.c"
+        "${AOM_ROOT}/av1/encoder/svc_layercontext.h")
+  endif()
 endif()
 
 if(CONFIG_AV1_DECODER AND CONFIG_AV1_ENCODER)
@@ -203,7 +206,9 @@
 function(get_name file_path name_var)
   get_filename_component(file_basename ${file_path} NAME)
   get_filename_component(${name_var} ${file_basename} NAME_WE)
-  set(${name_var} ${${name_var}} PARENT_SCOPE)
+  set(${name_var}
+      ${${name_var}}
+      PARENT_SCOPE)
 endfunction()
 
 function(setup_documentation_targets)
@@ -230,14 +235,16 @@
 
   # Generate samples.dox, an index page that refers to the example_basename.dox
   # files that were just created.
-  set(samples_header "
+  set(samples_header
+      "
 /*!\\page samples Sample Code
 This SDK includes a number of sample applications. Each sample documents a
 feature of the SDK in both prose and the associated C code. The following
 samples are included:
 ")
 
-  set(utils_desc "
+  set(utils_desc
+      "
 In addition, the SDK contains a number of utilities. Since these utilities are
 built upon the concepts described in the sample code listed above, they are not
 documented in pieces like the samples are. Their source is included here for
@@ -323,12 +330,11 @@
   file(APPEND "${AOM_DOXYFILE}" "JAVADOC_BANNER = YES")
 
   # Add the doxygen generation rule.
-  add_custom_target(docs ALL
-                    COMMAND "${DOXYGEN_EXECUTABLE}" "${AOM_DOXYFILE}"
-                    DEPENDS "${AOM_DOXYFILE}" ${AOM_DOXYGEN_SOURCES}
-                            ${AOM_DOXYGEN_EXAMPLE_SOURCES}
-                            "${AOM_DOXYGEN_CONFIG_TEMPLATE}"
-                    SOURCES "${AOM_DOXYFILE}" ${AOM_DOXYGEN_SOURCES}
-                            ${AOM_DOXYGEN_EXAMPLE_SOURCES}
-                            "${AOM_DOXYGEN_CONFIG_TEMPLATE}")
+  add_custom_target(
+    docs ALL
+    COMMAND "${DOXYGEN_EXECUTABLE}" "${AOM_DOXYFILE}"
+    DEPENDS "${AOM_DOXYFILE}" ${AOM_DOXYGEN_SOURCES}
+            ${AOM_DOXYGEN_EXAMPLE_SOURCES} "${AOM_DOXYGEN_CONFIG_TEMPLATE}"
+    SOURCES "${AOM_DOXYFILE}" ${AOM_DOXYGEN_SOURCES}
+            ${AOM_DOXYGEN_EXAMPLE_SOURCES} "${AOM_DOXYGEN_CONFIG_TEMPLATE}")
 endfunction()
diff --git a/examples/analyzer.cc b/examples/analyzer.cc
index 501f502..e49a477 100644
--- a/examples/analyzer.cc
+++ b/examples/analyzer.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #include <wx/wx.h>
 #include <wx/aboutdlg.h>
diff --git a/examples/aom_cx_set_ref.c b/examples/aom_cx_set_ref.c
index ebe83bf..d7263d0 100644
--- a/examples/aom_cx_set_ref.c
+++ b/examples/aom_cx_set_ref.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 // AV1 Set Reference Frame
diff --git a/examples/av1_dec_fuzzer.cc b/examples/av1_dec_fuzzer.cc
index 81548d9..85434be 100644
--- a/examples/av1_dec_fuzzer.cc
+++ b/examples/av1_dec_fuzzer.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2019, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 /*
diff --git a/examples/build_av1_dec_fuzzer.sh b/examples/build_av1_dec_fuzzer.sh
index 305f077..6c2e877 100755
--- a/examples/build_av1_dec_fuzzer.sh
+++ b/examples/build_av1_dec_fuzzer.sh
@@ -1,13 +1,13 @@
 #!/bin/bash
 #
-# Copyright (c) 2019, Alliance for Open Media. All rights reserved
+# Copyright (c) 2021, Alliance for Open Media. All rights reserved
 #
-# This source code is subject to the terms of the BSD 2 Clause License and
-# the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-# was not distributed with this source code in the LICENSE file, you can
-# obtain it at www.aomedia.org/license/software. If the Alliance for Open
-# Media Patent License 1.0 was not distributed with this source code in the
-# PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+# This source code is subject to the terms of the BSD 3-Clause Clear License and the
+# Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+# not distributed with this source code in the LICENSE file, you can obtain it
+# at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+# License 1.0 was not distributed with this source code in the PATENTS file, you
+# can obtain it at aomedia.org/license/patent-license/.
 #
 ###############################################################################
 # Fuzzer for libaom decoder.
diff --git a/examples/cnn_restore/cnn_restore_README.txt b/examples/cnn_restore/cnn_restore_README.txt
index f211a4f..fc2cf42 100644
--- a/examples/cnn_restore/cnn_restore_README.txt
+++ b/examples/cnn_restore/cnn_restore_README.txt
@@ -1,12 +1,12 @@
 /*
  * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License and the
+ * Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+ * not distributed with this source code in the LICENSE file, you can obtain it
+ * at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+ * License 1.0 was not distributed with this source code in the PATENTS file, you
+ * can obtain it at aomedia.org/license/patent-license/.
  */
 
 The CNN restoration utility is developed by Google initially and contributed
diff --git a/examples/cnn_restore/cnn_restore_y4m.cc b/examples/cnn_restore/cnn_restore_y4m.cc
index fe9410a..2f95b19 100644
--- a/examples/cnn_restore/cnn_restore_y4m.cc
+++ b/examples/cnn_restore/cnn_restore_y4m.cc
@@ -1,12 +1,13 @@
 /*
  * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 // NOTE: To build this utility in libaom please configure and build with
diff --git a/examples/decode_to_md5.c b/examples/decode_to_md5.c
index 07f788f..d1bb370 100644
--- a/examples/decode_to_md5.c
+++ b/examples/decode_to_md5.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 // Frame-by-frame MD5 Checksum
diff --git a/examples/decode_with_drops.c b/examples/decode_with_drops.c
index 9bec6ee..1a0bd52 100644
--- a/examples/decode_with_drops.c
+++ b/examples/decode_with_drops.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 // Decode With Drops Example
diff --git a/examples/encoder_util.c b/examples/encoder_util.c
index e43b372..43ec560 100644
--- a/examples/encoder_util.c
+++ b/examples/encoder_util.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 // Utility functions used by encoder binaries.
diff --git a/examples/encoder_util.h b/examples/encoder_util.h
index a6bb3fb..faee336 100644
--- a/examples/encoder_util.h
+++ b/examples/encoder_util.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 // Utility functions used by encoder binaries.
diff --git a/examples/inspect.c b/examples/inspect.c
index 93cca60..fc2a53f 100644
--- a/examples/inspect.c
+++ b/examples/inspect.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 // Inspect Decoder
diff --git a/examples/lightfield_bitstream_parsing.c b/examples/lightfield_bitstream_parsing.c
index 30e4fca..4ba34f4 100644
--- a/examples/lightfield_bitstream_parsing.c
+++ b/examples/lightfield_bitstream_parsing.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 // Lightfield Bitstream Parsing
diff --git a/examples/lightfield_decoder.c b/examples/lightfield_decoder.c
index 1a40155..e8c1747 100644
--- a/examples/lightfield_decoder.c
+++ b/examples/lightfield_decoder.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 // Lightfield Decoder
diff --git a/examples/lightfield_encoder.c b/examples/lightfield_encoder.c
index 5ed8a06..4e474d4 100644
--- a/examples/lightfield_encoder.c
+++ b/examples/lightfield_encoder.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 // Lightfield Encoder
diff --git a/examples/lightfield_tile_list_decoder.c b/examples/lightfield_tile_list_decoder.c
index 6811972..a1132cd 100644
--- a/examples/lightfield_tile_list_decoder.c
+++ b/examples/lightfield_tile_list_decoder.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 // Lightfield Tile List Decoder
diff --git a/examples/lossless_encoder.c b/examples/lossless_encoder.c
index 1971b9c..4c2b16c 100644
--- a/examples/lossless_encoder.c
+++ b/examples/lossless_encoder.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <stdio.h>
diff --git a/examples/noise_model.c b/examples/noise_model.c
index 4ad94b4..0d1ad01 100644
--- a/examples/noise_model.c
+++ b/examples/noise_model.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 /*!\file
diff --git a/examples/resize_util.c b/examples/resize_util.c
index 5692c20..96fba81 100644
--- a/examples/resize_util.c
+++ b/examples/resize_util.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/examples/scalable_decoder.c b/examples/scalable_decoder.c
index 00fe820..6aafece 100644
--- a/examples/scalable_decoder.c
+++ b/examples/scalable_decoder.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 // Scalable Decoder
diff --git a/examples/scalable_encoder.c b/examples/scalable_encoder.c
index d09cbb7..b4f2acd 100644
--- a/examples/scalable_encoder.c
+++ b/examples/scalable_encoder.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 // Scalable Encoder
diff --git a/examples/set_maps.c b/examples/set_maps.c
index 69b4bcc..c62afe0 100644
--- a/examples/set_maps.c
+++ b/examples/set_maps.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 // AOM Set Active and ROI Maps
diff --git a/examples/simple_decoder.c b/examples/simple_decoder.c
index b6891dc..4e2147e 100644
--- a/examples/simple_decoder.c
+++ b/examples/simple_decoder.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 // Simple Decoder
diff --git a/examples/simple_encoder.c b/examples/simple_encoder.c
index 682fe98..6bf8277 100644
--- a/examples/simple_encoder.c
+++ b/examples/simple_encoder.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 // Simple Encoder
diff --git a/examples/tf_lite_model.cc b/examples/tf_lite_model.cc
index 4b88e54..973fd5d 100644
--- a/examples/tf_lite_model.cc
+++ b/examples/tf_lite_model.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 /*!\file
diff --git a/examples/twopass_encoder.c b/examples/twopass_encoder.c
index 38f5db7..330be7b 100644
--- a/examples/twopass_encoder.c
+++ b/examples/twopass_encoder.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 // Two Pass Encoder
diff --git a/libs.doxy_template b/libs.doxy_template
index c989b88..3108011 100644
--- a/libs.doxy_template
+++ b/libs.doxy_template
@@ -1,11 +1,11 @@
-## Copyright (c) 2020, Alliance for Open Media. All rights reserved
+## Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ##
-## This source code is subject to the terms of the BSD 2 Clause License and
-## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-## was not distributed with this source code in the LICENSE file, you can
-## obtain it at www.aomedia.org/license/software. If the Alliance for Open
-## Media Patent License 1.0 was not distributed with this source code in the
-## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+## This source code is subject to the terms of the BSD 3-Clause Clear License and the
+## Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+## not distributed with this source code in the LICENSE file, you can obtain it
+## at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+## License 1.0 was not distributed with this source code in the PATENTS file, you
+## can obtain it at aomedia.org/license/patent-license/.
 ##
 
 # Doxyfile 1.8.16
diff --git a/stats/aomstats.c b/stats/aomstats.c
index 8d59377..0d3c9b1 100644
--- a/stats/aomstats.c
+++ b/stats/aomstats.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "stats/aomstats.h"
diff --git a/stats/aomstats.h b/stats/aomstats.h
index b9c7187..8711912 100644
--- a/stats/aomstats.h
+++ b/stats/aomstats.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_STATS_AOMSTATS_H_
diff --git a/stats/rate_hist.c b/stats/rate_hist.c
index 71eb78b..1a80fe6 100644
--- a/stats/rate_hist.c
+++ b/stats/rate_hist.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "stats/rate_hist.h"
diff --git a/stats/rate_hist.h b/stats/rate_hist.h
index 55b8c5d..ce17d72 100644
--- a/stats/rate_hist.h
+++ b/stats/rate_hist.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_STATS_RATE_HIST_H_
diff --git a/test/accounting_test.cc b/test/accounting_test.cc
index 8b5c8af..8d8d964 100644
--- a/test/accounting_test.cc
+++ b/test/accounting_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <math.h>
diff --git a/test/acm_random.h b/test/acm_random.h
index 8b1d51a..e92daef 100644
--- a/test/acm_random.h
+++ b/test/acm_random.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_TEST_ACM_RANDOM_H_
diff --git a/test/altref_test.cc b/test/altref_test.cc
index 2893e93..95f5b7a 100644
--- a/test/altref_test.cc
+++ b/test/altref_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "third_party/googletest/src/googletest/include/gtest/gtest.h"
diff --git a/test/aom_integer_test.cc b/test/aom_integer_test.cc
index d5dfad9..7fed683 100644
--- a/test/aom_integer_test.cc
+++ b/test/aom_integer_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "aom/aom_integer.h"
diff --git a/test/aomcx_set_ref.sh b/test/aomcx_set_ref.sh
index 237e2f3..3ea9ba3 100755
--- a/test/aomcx_set_ref.sh
+++ b/test/aomcx_set_ref.sh
@@ -1,12 +1,12 @@
 #!/bin/sh
-## Copyright (c) 2016, Alliance for Open Media. All rights reserved
+## Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ##
-## This source code is subject to the terms of the BSD 2 Clause License and
-## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-## was not distributed with this source code in the LICENSE file, you can
-## obtain it at www.aomedia.org/license/software. If the Alliance for Open
-## Media Patent License 1.0 was not distributed with this source code in the
-## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+## This source code is subject to the terms of the BSD 3-Clause Clear License and the
+## Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+## not distributed with this source code in the LICENSE file, you can obtain it
+## at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+## License 1.0 was not distributed with this source code in the PATENTS file, you
+## can obtain it at aomedia.org/license/patent-license/.
 ##
 ## This file tests the libaom aom_cx_set_ref example. To add new tests to this
 ## file, do the following:
diff --git a/test/aomdec.sh b/test/aomdec.sh
index d94b673..c3324f6 100755
--- a/test/aomdec.sh
+++ b/test/aomdec.sh
@@ -1,12 +1,12 @@
 #!/bin/sh
-## Copyright (c) 2016, Alliance for Open Media. All rights reserved
+## Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ##
-## This source code is subject to the terms of the BSD 2 Clause License and
-## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-## was not distributed with this source code in the LICENSE file, you can
-## obtain it at www.aomedia.org/license/software. If the Alliance for Open
-## Media Patent License 1.0 was not distributed with this source code in the
-## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+## This source code is subject to the terms of the BSD 3-Clause Clear License and the
+## Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+## not distributed with this source code in the LICENSE file, you can obtain it
+## at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+## License 1.0 was not distributed with this source code in the PATENTS file, you
+## can obtain it at aomedia.org/license/patent-license/.
 ##
 ## This file tests aomdec. To add new tests to this file, do the following:
 ##   1. Write a shell function (this is your test).
diff --git a/test/aomenc.sh b/test/aomenc.sh
index e14b231..01c4434 100755
--- a/test/aomenc.sh
+++ b/test/aomenc.sh
@@ -1,12 +1,12 @@
 #!/bin/sh
-## Copyright (c) 2016, Alliance for Open Media. All rights reserved
+## Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ##
-## This source code is subject to the terms of the BSD 2 Clause License and
-## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-## was not distributed with this source code in the LICENSE file, you can
-## obtain it at www.aomedia.org/license/software. If the Alliance for Open
-## Media Patent License 1.0 was not distributed with this source code in the
-## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+## This source code is subject to the terms of the BSD 3-Clause Clear License and the
+## Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+## not distributed with this source code in the LICENSE file, you can obtain it
+## at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+## License 1.0 was not distributed with this source code in the PATENTS file, you
+## can obtain it at aomedia.org/license/patent-license/.
 ##
 ## This file tests aomenc using hantro_collage_w352h288.yuv as input. To add
 ## new tests to this file, do the following:
diff --git a/test/aq_segment_test.cc b/test/aq_segment_test.cc
index 488ba3e..cff44f4 100644
--- a/test/aq_segment_test.cc
+++ b/test/aq_segment_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "config/aom_config.h"
diff --git a/test/arf_freq_test.cc b/test/arf_freq_test.cc
index 1b9b62c..8a1c5d4 100644
--- a/test/arf_freq_test.cc
+++ b/test/arf_freq_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <memory>
diff --git a/test/av1_common_int_test.cc b/test/av1_common_int_test.cc
index dde2542..d475242 100644
--- a/test/av1_common_int_test.cc
+++ b/test/av1_common_int_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "third_party/googletest/src/googletest/include/gtest/gtest.h"
diff --git a/test/av1_config_test.cc b/test/av1_config_test.cc
index 1ecf5de..3bb9a02 100644
--- a/test/av1_config_test.cc
+++ b/test/av1_config_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #include <string.h>
 
@@ -109,11 +110,7 @@
   ASSERT_EQ(-1, write_av1config(&av1_config, 4, &bytes_written, NULL));
 }
 
-#if !CONFIG_REMOVE_DIST_WTD_COMP && !CONFIG_REMOVE_DUAL_FILTER
-TEST(Av1Config, GetAv1ConfigFromLobfObu) {
-#else
 TEST(Av1Config, DISABLED_GetAv1ConfigFromLobfObu) {
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP && !CONFIG_REMOVE_DUAL_FILTER
   // Test parsing of a Sequence Header OBU with the reduced_still_picture_header
   // unset-- aka a full Sequence Header OBU.
   ASSERT_TRUE(VerifyAv1c(kLobfFullSequenceHeaderObu,
@@ -125,11 +122,7 @@
                          false));
 }
 
-#if !CONFIG_REMOVE_DIST_WTD_COMP && !CONFIG_REMOVE_DUAL_FILTER
-TEST(Av1Config, GetAv1ConfigFromAnnexBObu) {
-#else
 TEST(Av1Config, DISABLED_GetAv1ConfigFromAnnexBObu) {
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP && !CONFIG_REMOVE_DUAL_FILTER
   // Test parsing of a Sequence Header OBU with the reduced_still_picture_header
   // unset-- aka a full Sequence Header OBU.
   ASSERT_TRUE(VerifyAv1c(kAnnexBFullSequenceHeaderObu,
@@ -141,11 +134,7 @@
                          true));
 }
 
-#if !CONFIG_REMOVE_DIST_WTD_COMP && !CONFIG_REMOVE_DUAL_FILTER
-TEST(Av1Config, ReadWriteConfig) {
-#else
 TEST(Av1Config, DISABLED_ReadWriteConfig) {
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP && !CONFIG_REMOVE_DUAL_FILTER
   Av1Config av1_config;
   memset(&av1_config, 0, sizeof(av1_config));
 
diff --git a/test/av1_convolve_scale_test.cc b/test/av1_convolve_scale_test.cc
index 9892bb1..5565ebb 100644
--- a/test/av1_convolve_scale_test.cc
+++ b/test/av1_convolve_scale_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <tuple>
diff --git a/test/av1_convolve_test.cc b/test/av1_convolve_test.cc
index d0f9abe..37c96b1 100644
--- a/test/av1_convolve_test.cc
+++ b/test/av1_convolve_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <ostream>
diff --git a/test/av1_encoder_parms_get_to_decoder.cc b/test/av1_encoder_parms_get_to_decoder.cc
index b451348..29043b1 100644
--- a/test/av1_encoder_parms_get_to_decoder.cc
+++ b/test/av1_encoder_parms_get_to_decoder.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <memory>
diff --git a/test/av1_ext_tile_test.cc b/test/av1_ext_tile_test.cc
index 0e1d7f4..7fe3d57 100644
--- a/test/av1_ext_tile_test.cc
+++ b/test/av1_ext_tile_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/test/av1_fwd_txfm1d_test.cc b/test/av1_fwd_txfm1d_test.cc
index abc46ed..35bba2a 100644
--- a/test/av1_fwd_txfm1d_test.cc
+++ b/test/av1_fwd_txfm1d_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "av1/encoder/av1_fwd_txfm1d.h"
diff --git a/test/av1_fwd_txfm2d_test.cc b/test/av1_fwd_txfm2d_test.cc
index 0e7eb09..63f6c99 100644
--- a/test/av1_fwd_txfm2d_test.cc
+++ b/test/av1_fwd_txfm2d_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <math.h>
diff --git a/test/av1_highbd_iht_test.cc b/test/av1_highbd_iht_test.cc
index a576c0f..815d982 100644
--- a/test/av1_highbd_iht_test.cc
+++ b/test/av1_highbd_iht_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <tuple>
diff --git a/test/av1_horz_only_frame_superres_test.cc b/test/av1_horz_only_frame_superres_test.cc
index e71c920..932e0e5 100644
--- a/test/av1_horz_only_frame_superres_test.cc
+++ b/test/av1_horz_only_frame_superres_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <tuple>
diff --git a/test/av1_inv_txfm1d_test.cc b/test/av1_inv_txfm1d_test.cc
index 01d4a4d..13fa73a 100644
--- a/test/av1_inv_txfm1d_test.cc
+++ b/test/av1_inv_txfm1d_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <math.h>
diff --git a/test/av1_inv_txfm2d_test.cc b/test/av1_inv_txfm2d_test.cc
index d14acfe..9652167 100644
--- a/test/av1_inv_txfm2d_test.cc
+++ b/test/av1_inv_txfm2d_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <math.h>
diff --git a/test/av1_key_value_api_test.cc b/test/av1_key_value_api_test.cc
index a25c5d8..88ba6af 100644
--- a/test/av1_key_value_api_test.cc
+++ b/test/av1_key_value_api_test.cc
@@ -1,12 +1,13 @@
 /*
  * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <cstring>
diff --git a/test/av1_nn_predict_test.cc b/test/av1_nn_predict_test.cc
index 04b44a2..3e3125d 100644
--- a/test/av1_nn_predict_test.cc
+++ b/test/av1_nn_predict_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <tuple>
@@ -210,7 +211,7 @@
   RunNnPredictSpeedTest_all(shapes, sizeof(shapes) / sizeof(*shapes), 10000000);
 }
 
-#if HAVE_SSE3
+#if HAVE_SSE3 && !CONFIG_EXCLUDE_SIMD_MISMATCH
 INSTANTIATE_TEST_SUITE_P(SSE3, NnPredictTest,
                          ::testing::Values(av1_nn_predict_sse3));
 #endif
diff --git a/test/av1_quantize_test.cc b/test/av1_quantize_test.cc
index 273201b..c7b855a 100644
--- a/test/av1_quantize_test.cc
+++ b/test/av1_quantize_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #include <stdlib.h>
 
diff --git a/test/av1_round_shift_array_test.cc b/test/av1_round_shift_array_test.cc
index 07f6b56..7b61adb 100644
--- a/test/av1_round_shift_array_test.cc
+++ b/test/av1_round_shift_array_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <math.h>
diff --git a/test/av1_txfm_test.cc b/test/av1_txfm_test.cc
index aedd45d..7e8f43b 100644
--- a/test/av1_txfm_test.cc
+++ b/test/av1_txfm_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <stdio.h>
diff --git a/test/av1_txfm_test.h b/test/av1_txfm_test.h
index 5a56d28..c9c6bce 100644
--- a/test/av1_txfm_test.h
+++ b/test/av1_txfm_test.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_TEST_AV1_TXFM_TEST_H_
diff --git a/test/av1_wedge_utils_test.cc b/test/av1_wedge_utils_test.cc
index 69280b4..d60c30e 100644
--- a/test/av1_wedge_utils_test.cc
+++ b/test/av1_wedge_utils_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "third_party/googletest/src/googletest/include/gtest/gtest.h"
diff --git a/test/best_encode.sh b/test/best_encode.sh
index a9a72ae..2ff6671 100755
--- a/test/best_encode.sh
+++ b/test/best_encode.sh
@@ -1,13 +1,13 @@
 #!/bin/bash
 #
-# Copyright (c) 2016, Alliance for Open Media. All rights reserved
+# Copyright (c) 2021, Alliance for Open Media. All rights reserved
 #
-# This source code is subject to the terms of the BSD 2 Clause License and
-# the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-# was not distributed with this source code in the LICENSE file, you can
-# obtain it at www.aomedia.org/license/software. If the Alliance for Open
-# Media Patent License 1.0 was not distributed with this source code in the
-# PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+# This source code is subject to the terms of the BSD 3-Clause Clear License and the
+# Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+# not distributed with this source code in the LICENSE file, you can obtain it
+# at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+# License 1.0 was not distributed with this source code in the PATENTS file, you
+# can obtain it at aomedia.org/license/patent-license/.
 #
 # Author: jimbankoski@google.com (Jim Bankoski)
 
diff --git a/test/binary_codes_test.cc b/test/binary_codes_test.cc
index 45660cf..68cb79c 100644
--- a/test/binary_codes_test.cc
+++ b/test/binary_codes_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <math.h>
diff --git a/test/blend_a64_mask_1d_test.cc b/test/blend_a64_mask_1d_test.cc
index 0ae4eb2..dd7a1f5 100644
--- a/test/blend_a64_mask_1d_test.cc
+++ b/test/blend_a64_mask_1d_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <math.h>
diff --git a/test/blend_a64_mask_test.cc b/test/blend_a64_mask_test.cc
index e0fa850..04ee527 100644
--- a/test/blend_a64_mask_test.cc
+++ b/test/blend_a64_mask_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <math.h>
diff --git a/test/block_test.cc b/test/block_test.cc
index d02fb21..8cd4c33 100644
--- a/test/block_test.cc
+++ b/test/block_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "aom/aom_codec.h"
diff --git a/test/boolcoder_test.cc b/test/boolcoder_test.cc
index 680ec18..1809309 100644
--- a/test/boolcoder_test.cc
+++ b/test/boolcoder_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <math.h>
diff --git a/test/borders_test.cc b/test/borders_test.cc
index 929f895..f985db7 100644
--- a/test/borders_test.cc
+++ b/test/borders_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <climits>
diff --git a/test/cdef_test.cc b/test/cdef_test.cc
index 14fa12b..c101539 100644
--- a/test/cdef_test.cc
+++ b/test/cdef_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <cstdlib>
diff --git a/test/cfl_test.cc b/test/cfl_test.cc
index 001d4fe..fe8bdb0 100644
--- a/test/cfl_test.cc
+++ b/test/cfl_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <tuple>
diff --git a/test/clear_system_state.h b/test/clear_system_state.h
index d38ff5d..513e5b8 100644
--- a/test/clear_system_state.h
+++ b/test/clear_system_state.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #ifndef AOM_TEST_CLEAR_SYSTEM_STATE_H_
 #define AOM_TEST_CLEAR_SYSTEM_STATE_H_
diff --git a/test/cnn_test.cc b/test/cnn_test.cc
index 4410493..4aea1f3 100644
--- a/test/cnn_test.cc
+++ b/test/cnn_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2019, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/test/codec_factory.h b/test/codec_factory.h
index 67cbbc8..90e77ea 100644
--- a/test/codec_factory.h
+++ b/test/codec_factory.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #ifndef AOM_TEST_CODEC_FACTORY_H_
 #define AOM_TEST_CODEC_FACTORY_H_
diff --git a/test/coding_path_sync.cc b/test/coding_path_sync.cc
index 4779120..edbe084 100644
--- a/test/coding_path_sync.cc
+++ b/test/coding_path_sync.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <vector>
diff --git a/test/comp_avg_pred_test.cc b/test/comp_avg_pred_test.cc
index 78997c6..b53d60d 100644
--- a/test/comp_avg_pred_test.cc
+++ b/test/comp_avg_pred_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "test/comp_avg_pred_test.h"
diff --git a/test/comp_avg_pred_test.h b/test/comp_avg_pred_test.h
index 4f8c471..a879c12 100644
--- a/test/comp_avg_pred_test.h
+++ b/test/comp_avg_pred_test.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_TEST_COMP_AVG_PRED_TEST_H_
diff --git a/test/comp_mask_variance_test.cc b/test/comp_mask_variance_test.cc
index ce0fca1..f8e7f3e 100644
--- a/test/comp_mask_variance_test.cc
+++ b/test/comp_mask_variance_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <cstdlib>
diff --git a/test/convolve_round_test.cc b/test/convolve_round_test.cc
index 4f17b54..e6911ca 100644
--- a/test/convolve_round_test.cc
+++ b/test/convolve_round_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/test/convolve_test.cc b/test/convolve_test.cc
index 2e75e4a..105f291 100644
--- a/test/convolve_test.cc
+++ b/test/convolve_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <string.h>
diff --git a/test/corner_match_test.cc b/test/corner_match_test.cc
index 9c3a2b9..39927e6 100644
--- a/test/corner_match_test.cc
+++ b/test/corner_match_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #include <tuple>
 
diff --git a/test/cpu_speed_test.cc b/test/cpu_speed_test.cc
index 1e0d3e6..bddd8ab 100644
--- a/test/cpu_speed_test.cc
+++ b/test/cpu_speed_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "third_party/googletest/src/googletest/include/gtest/gtest.h"
diff --git a/test/decode_api_test.cc b/test/decode_api_test.cc
index 6acd50f..58b8fb1 100644
--- a/test/decode_api_test.cc
+++ b/test/decode_api_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "third_party/googletest/src/googletest/include/gtest/gtest.h"
diff --git a/test/decode_multithreaded_test.cc b/test/decode_multithreaded_test.cc
index 5122e06..b196093 100644
--- a/test/decode_multithreaded_test.cc
+++ b/test/decode_multithreaded_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <cstdio>
diff --git a/test/decode_perf_test.cc b/test/decode_perf_test.cc
index 416fd9d..0bff17b 100644
--- a/test/decode_perf_test.cc
+++ b/test/decode_perf_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <string>
diff --git a/test/decode_test_driver.cc b/test/decode_test_driver.cc
index 70de0cf..becb639 100644
--- a/test/decode_test_driver.cc
+++ b/test/decode_test_driver.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "third_party/googletest/src/googletest/include/gtest/gtest.h"
diff --git a/test/decode_test_driver.h b/test/decode_test_driver.h
index 64722f4..d87467b 100644
--- a/test/decode_test_driver.h
+++ b/test/decode_test_driver.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_TEST_DECODE_TEST_DRIVER_H_
diff --git a/test/decode_to_md5.sh b/test/decode_to_md5.sh
index 214755f..7a25abd 100755
--- a/test/decode_to_md5.sh
+++ b/test/decode_to_md5.sh
@@ -1,12 +1,12 @@
 #!/bin/sh
-## Copyright (c) 2016, Alliance for Open Media. All rights reserved
+## Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ##
-## This source code is subject to the terms of the BSD 2 Clause License and
-## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-## was not distributed with this source code in the LICENSE file, you can
-## obtain it at www.aomedia.org/license/software. If the Alliance for Open
-## Media Patent License 1.0 was not distributed with this source code in the
-## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+## This source code is subject to the terms of the BSD 3-Clause Clear License and the
+## Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+## not distributed with this source code in the LICENSE file, you can obtain it
+## at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+## License 1.0 was not distributed with this source code in the PATENTS file, you
+## can obtain it at aomedia.org/license/patent-license/.
 ##
 ## This file tests the libaom decode_to_md5 example. To add new tests to this
 ## file, do the following:
diff --git a/test/decode_with_drops.sh b/test/decode_with_drops.sh
index 1fc13ce..a40ca0a 100755
--- a/test/decode_with_drops.sh
+++ b/test/decode_with_drops.sh
@@ -1,12 +1,12 @@
 #!/bin/sh
-## Copyright (c) 2016, Alliance for Open Media. All rights reserved
+## Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ##
-## This source code is subject to the terms of the BSD 2 Clause License and
-## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-## was not distributed with this source code in the LICENSE file, you can
-## obtain it at www.aomedia.org/license/software. If the Alliance for Open
-## Media Patent License 1.0 was not distributed with this source code in the
-## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+## This source code is subject to the terms of the BSD 3-Clause Clear License and the
+## Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+## not distributed with this source code in the LICENSE file, you can obtain it
+## at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+## License 1.0 was not distributed with this source code in the PATENTS file, you
+## can obtain it at aomedia.org/license/patent-license/.
 ##
 ## This file tests the libaom decode_with_drops example. To add new tests to
 ## this file, do the following:
diff --git a/test/divu_small_test.cc b/test/divu_small_test.cc
index f4d0846..d11d1ae 100644
--- a/test/divu_small_test.cc
+++ b/test/divu_small_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <stdlib.h>
diff --git a/test/dr_prediction_test.cc b/test/dr_prediction_test.cc
index b133754..e984800 100644
--- a/test/dr_prediction_test.cc
+++ b/test/dr_prediction_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <tuple>
diff --git a/test/dump_obu.sh b/test/dump_obu.sh
index 7dcab94..8beaa71 100755
--- a/test/dump_obu.sh
+++ b/test/dump_obu.sh
@@ -1,12 +1,12 @@
 #!/bin/sh
-## Copyright (c) 2018, Alliance for Open Media. All rights reserved
+## Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ##
-## This source code is subject to the terms of the BSD 2 Clause License and
-## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-## was not distributed with this source code in the LICENSE file, you can
-## obtain it at www.aomedia.org/license/software. If the Alliance for Open
-## Media Patent License 1.0 was not distributed with this source code in the
-## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+## This source code is subject to the terms of the BSD 3-Clause Clear License and the
+## Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+## not distributed with this source code in the LICENSE file, you can obtain it
+## at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+## License 1.0 was not distributed with this source code in the PATENTS file, you
+## can obtain it at aomedia.org/license/patent-license/.
 ##
 ## This file tests the libaom dump_obu tool. To add new tests to this
 ## file, do the following:
diff --git a/test/ec_test.cc b/test/ec_test.cc
index 853abcb..c0bf595 100644
--- a/test/ec_test.cc
+++ b/test/ec_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "third_party/googletest/src/googletest/include/gtest/gtest.h"
diff --git a/test/edge_detect_test.cc b/test/edge_detect_test.cc
index 6ac544b..f5ffa02 100644
--- a/test/edge_detect_test.cc
+++ b/test/edge_detect_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <stdbool.h>
diff --git a/test/encode_api_test.cc b/test/encode_api_test.cc
index 4b79f25..30167aa 100644
--- a/test/encode_api_test.cc
+++ b/test/encode_api_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <cstdlib>
diff --git a/test/encode_small_width_height_test.cc b/test/encode_small_width_height_test.cc
index 6f52fd5..94da7b5 100644
--- a/test/encode_small_width_height_test.cc
+++ b/test/encode_small_width_height_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 // Tests for https://crbug.com/aomedia/2777.
diff --git a/test/encode_test_driver.cc b/test/encode_test_driver.cc
index 81d0c26..55b7ea3 100644
--- a/test/encode_test_driver.cc
+++ b/test/encode_test_driver.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <memory>
diff --git a/test/encode_test_driver.h b/test/encode_test_driver.h
index a5b7cdd..647e944 100644
--- a/test/encode_test_driver.h
+++ b/test/encode_test_driver.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #ifndef AOM_TEST_ENCODE_TEST_DRIVER_H_
 #define AOM_TEST_ENCODE_TEST_DRIVER_H_
@@ -114,6 +115,7 @@
     ASSERT_EQ(AOM_CODEC_OK, res) << EncoderError();
   }
 
+#if CONFIG_SVC_ENCODER
   void Control(int ctrl_id, struct aom_svc_layer_id *arg) {
     const aom_codec_err_t res = aom_codec_control(&encoder_, ctrl_id, arg);
     ASSERT_EQ(AOM_CODEC_OK, res) << EncoderError();
@@ -128,6 +130,7 @@
     const aom_codec_err_t res = aom_codec_control(&encoder_, ctrl_id, arg);
     ASSERT_EQ(AOM_CODEC_OK, res) << EncoderError();
   }
+#endif  // CONFIG_SVC_ENCODER
 
   void Control(int ctrl_id, const char *arg) {
     const aom_codec_err_t res = aom_codec_control(&encoder_, ctrl_id, arg);
diff --git a/test/encodetxb_test.cc b/test/encodetxb_test.cc
index 61838ca..c130bab 100644
--- a/test/encodetxb_test.cc
+++ b/test/encodetxb_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <stdint.h>
diff --git a/test/end_to_end_test.cc b/test/end_to_end_test.cc
index 0a8e3d7..768dfcc 100644
--- a/test/end_to_end_test.cc
+++ b/test/end_to_end_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <memory>
diff --git a/test/error_block_test.cc b/test/error_block_test.cc
index ef985ab..03b89a4 100644
--- a/test/error_block_test.cc
+++ b/test/error_block_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <cmath>
diff --git a/test/error_resilience_test.cc b/test/error_resilience_test.cc
index 1c190f6..700734e 100644
--- a/test/error_resilience_test.cc
+++ b/test/error_resilience_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "third_party/googletest/src/googletest/include/gtest/gtest.h"
diff --git a/test/ethread_test.cc b/test/ethread_test.cc
index d29a8d7..4d9edbf 100644
--- a/test/ethread_test.cc
+++ b/test/ethread_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <string>
diff --git a/test/examples.sh b/test/examples.sh
index 66d6037..1b0de35 100755
--- a/test/examples.sh
+++ b/test/examples.sh
@@ -1,12 +1,12 @@
 #!/bin/sh
-## Copyright (c) 2016, Alliance for Open Media. All rights reserved
+## Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ##
-## This source code is subject to the terms of the BSD 2 Clause License and
-## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-## was not distributed with this source code in the LICENSE file, you can
-## obtain it at www.aomedia.org/license/software. If the Alliance for Open
-## Media Patent License 1.0 was not distributed with this source code in the
-## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+## This source code is subject to the terms of the BSD 3-Clause Clear License and the
+## Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+## not distributed with this source code in the LICENSE file, you can obtain it
+## at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+## License 1.0 was not distributed with this source code in the PATENTS file, you
+## can obtain it at aomedia.org/license/patent-license/.
 ##
 ## This file runs all of the tests for the libaom examples.
 ##
diff --git a/test/external_frame_buffer_test.cc b/test/external_frame_buffer_test.cc
index a3ca4cd..575a6f2 100644
--- a/test/external_frame_buffer_test.cc
+++ b/test/external_frame_buffer_test.cc
@@ -397,11 +397,7 @@
 // needed. The md5 checksums are computed for each frame in the video file.
 // If md5 checksums match the correct md5 data, then the test is passed.
 // Otherwise, the test failed.
-#if !CONFIG_REMOVE_DIST_WTD_COMP && !CONFIG_REMOVE_DUAL_FILTER
-TEST_P(ExternalFrameBufferMD5Test, ExtFBMD5Match) {
-#else
 TEST_P(ExternalFrameBufferMD5Test, DISABLED_ExtFBMD5Match) {
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP && !CONFIG_REMOVE_DUAL_FILTER
   const std::string filename = GET_PARAM(kVideoNameParam);
   aom_codec_dec_cfg_t cfg = aom_codec_dec_cfg_t();
 
@@ -441,11 +437,7 @@
 }
 
 #if CONFIG_WEBM_IO
-#if !CONFIG_REMOVE_DIST_WTD_COMP && !CONFIG_REMOVE_DUAL_FILTER
-TEST_F(ExternalFrameBufferTest, MinFrameBuffers) {
-#else
 TEST_F(ExternalFrameBufferTest, DISABLED_MinFrameBuffers) {
-#endif  // CONFIG_REMOVE_DIST_WTD_COMP && !CONFIG_REMOVE_DUAL_FILTER
   // Minimum number of external frame buffers for AV1 is
   // #AOM_MAXIMUM_REF_BUFFERS + #AOM_MAXIMUM_WORK_BUFFERS.
   const int num_buffers = AOM_MAXIMUM_REF_BUFFERS + AOM_MAXIMUM_WORK_BUFFERS;
@@ -455,11 +447,7 @@
   ASSERT_EQ(AOM_CODEC_OK, DecodeRemainingFrames());
 }
 
-#if !CONFIG_REMOVE_DIST_WTD_COMP && !CONFIG_REMOVE_DUAL_FILTER
-TEST_F(ExternalFrameBufferTest, EightJitterBuffers) {
-#else
 TEST_F(ExternalFrameBufferTest, DISABLED_EightJitterBuffers) {
-#endif  // CONFIG_REMOVE_DIST_WTD_COMP && !CONFIG_REMOVE_DUAL_FILTER
   // Number of buffers equals #AOM_MAXIMUM_REF_BUFFERS +
   // #AOM_MAXIMUM_WORK_BUFFERS + eight jitter buffers.
   const int jitter_buffers = 8;
@@ -471,11 +459,7 @@
   ASSERT_EQ(AOM_CODEC_OK, DecodeRemainingFrames());
 }
 
-#if !CONFIG_REMOVE_DIST_WTD_COMP && !CONFIG_REMOVE_DUAL_FILTER
-TEST_F(ExternalFrameBufferTest, NotEnoughBuffers) {
-#else
 TEST_F(ExternalFrameBufferTest, DISABLED_NotEnoughBuffers) {
-#endif  // CONFIG_REMOVE_DIST_WTD_COMP && !CONFIG_REMOVE_DUAL_FILTER
   // Minimum number of external frame buffers for AV1 is
   // #AOM_MAXIMUM_REF_BUFFERS + #AOM_MAXIMUM_WORK_BUFFERS. Most files will
   // only use 5 frame buffers at one time.
@@ -489,11 +473,7 @@
   ASSERT_EQ(AOM_CODEC_MEM_ERROR, DecodeRemainingFrames());
 }
 
-#if !CONFIG_REMOVE_DIST_WTD_COMP && !CONFIG_REMOVE_DUAL_FILTER
-TEST_F(ExternalFrameBufferTest, NoRelease) {
-#else
 TEST_F(ExternalFrameBufferTest, DISABLED_NoRelease) {
-#endif  // CONFIG_REMOVE_DIST_WTD_COMP && !CONFIG_REMOVE_DUAL_FILTER
   const int num_buffers = AOM_MAXIMUM_REF_BUFFERS + AOM_MAXIMUM_WORK_BUFFERS;
   ASSERT_EQ(AOM_CODEC_OK,
             SetFrameBufferFunctions(num_buffers, get_aom_frame_buffer,
@@ -502,11 +482,7 @@
   ASSERT_EQ(AOM_CODEC_MEM_ERROR, DecodeRemainingFrames());
 }
 
-#if !CONFIG_REMOVE_DIST_WTD_COMP && !CONFIG_REMOVE_DUAL_FILTER
-TEST_F(ExternalFrameBufferTest, NullRealloc) {
-#else
 TEST_F(ExternalFrameBufferTest, DISABLED_NullRealloc) {
-#endif  // CONFIG_REMOVE_DIST_WTD_COMP && !CONFIG_REMOVE_DUAL_FILTER
   const int num_buffers = AOM_MAXIMUM_REF_BUFFERS + AOM_MAXIMUM_WORK_BUFFERS;
   ASSERT_EQ(AOM_CODEC_OK,
             SetFrameBufferFunctions(num_buffers, get_aom_zero_frame_buffer,
@@ -514,11 +490,7 @@
   ASSERT_EQ(AOM_CODEC_MEM_ERROR, DecodeOneFrame());
 }
 
-#if !CONFIG_REMOVE_DIST_WTD_COMP && !CONFIG_REMOVE_DUAL_FILTER
-TEST_F(ExternalFrameBufferTest, ReallocOneLessByte) {
-#else
 TEST_F(ExternalFrameBufferTest, DISABLED_ReallocOneLessByte) {
-#endif  // CONFIG_REMOVE_DIST_WTD_COMP && !CONFIG_REMOVE_DUAL_FILTER
   const int num_buffers = AOM_MAXIMUM_REF_BUFFERS + AOM_MAXIMUM_WORK_BUFFERS;
   ASSERT_EQ(AOM_CODEC_OK, SetFrameBufferFunctions(
                               num_buffers, get_aom_one_less_byte_frame_buffer,
@@ -539,11 +511,7 @@
             SetFrameBufferFunctions(num_buffers, get_aom_frame_buffer, NULL));
 }
 
-#if !CONFIG_REMOVE_DIST_WTD_COMP && !CONFIG_REMOVE_DUAL_FILTER
-TEST_F(ExternalFrameBufferTest, SetAfterDecode) {
-#else
 TEST_F(ExternalFrameBufferTest, DISABLED_SetAfterDecode) {
-#endif  // CONFIG_REMOVE_DIST_WTD_COMP && !CONFIG_REMOVE_DUAL_FILTER
   const int num_buffers = AOM_MAXIMUM_REF_BUFFERS + AOM_MAXIMUM_WORK_BUFFERS;
   ASSERT_EQ(AOM_CODEC_OK, DecodeOneFrame());
   ASSERT_EQ(AOM_CODEC_ERROR,
@@ -551,11 +519,7 @@
                                     release_aom_frame_buffer));
 }
 
-#if !CONFIG_REMOVE_DIST_WTD_COMP && !CONFIG_REMOVE_DUAL_FILTER
-TEST_F(ExternalFrameBufferNonRefTest, ReleaseNonRefFrameBuffer) {
-#else
 TEST_F(ExternalFrameBufferNonRefTest, DISABLED_ReleaseNonRefFrameBuffer) {
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP && !CONFIG_REMOVE_DUAL_FILTER
   const int num_buffers = AOM_MAXIMUM_REF_BUFFERS + AOM_MAXIMUM_WORK_BUFFERS;
   ASSERT_EQ(AOM_CODEC_OK,
             SetFrameBufferFunctions(num_buffers, get_aom_frame_buffer,
diff --git a/test/fdct4x4_test.cc b/test/fdct4x4_test.cc
index 69e4bda..325f1be 100644
--- a/test/fdct4x4_test.cc
+++ b/test/fdct4x4_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <math.h>
diff --git a/test/fft_test.cc b/test/fft_test.cc
index d23aa01..2415344 100644
--- a/test/fft_test.cc
+++ b/test/fft_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <math.h>
diff --git a/test/film_grain_table_test.cc b/test/film_grain_table_test.cc
index 524d67d..89c538e 100644
--- a/test/film_grain_table_test.cc
+++ b/test/film_grain_table_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <string>
diff --git a/test/filterintra_test.cc b/test/filterintra_test.cc
index 14cdd39..0b75d0d 100644
--- a/test/filterintra_test.cc
+++ b/test/filterintra_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <tuple>
diff --git a/test/frame_error_test.cc b/test/frame_error_test.cc
index 6478f09..f8e521b 100644
--- a/test/frame_error_test.cc
+++ b/test/frame_error_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2019, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <math.h>
diff --git a/test/function_equivalence_test.h b/test/function_equivalence_test.h
index a299c48..b56cea3 100644
--- a/test/function_equivalence_test.h
+++ b/test/function_equivalence_test.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_TEST_FUNCTION_EQUIVALENCE_TEST_H_
diff --git a/test/fwd_kf_test.cc b/test/fwd_kf_test.cc
index 89ae6c8..e270523 100644
--- a/test/fwd_kf_test.cc
+++ b/test/fwd_kf_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2019, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <ostream>
diff --git a/test/fwht4x4_test.cc b/test/fwht4x4_test.cc
index b600d26..1c77dcb 100644
--- a/test/fwht4x4_test.cc
+++ b/test/fwht4x4_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <math.h>
diff --git a/test/gf_pyr_height_test.cc b/test/gf_pyr_height_test.cc
index 35724fe..60924f0 100644
--- a/test/gf_pyr_height_test.cc
+++ b/test/gf_pyr_height_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2019, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <ostream>
diff --git a/test/gviz_api.py b/test/gviz_api.py
index d3a443d..fa87152 100755
--- a/test/gviz_api.py
+++ b/test/gviz_api.py
@@ -1,13 +1,13 @@
 #!/usr/bin/python
 #
-# Copyright (c) 2016, Alliance for Open Media. All rights reserved
+# Copyright (c) 2021, Alliance for Open Media. All rights reserved
 #
-# This source code is subject to the terms of the BSD 2 Clause License and
-# the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-# was not distributed with this source code in the LICENSE file, you can
-# obtain it at www.aomedia.org/license/software. If the Alliance for Open
-# Media Patent License 1.0 was not distributed with this source code in the
-# PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+# This source code is subject to the terms of the BSD 3-Clause Clear License and the
+# Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+# not distributed with this source code in the LICENSE file, you can obtain it
+# at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+# License 1.0 was not distributed with this source code in the PATENTS file, you
+# can obtain it at aomedia.org/license/patent-license/.
 #
 
 """Converts Python data into data for Google Visualization API clients.
diff --git a/test/hash_test.cc b/test/hash_test.cc
index eb964ac..6c921ac 100644
--- a/test/hash_test.cc
+++ b/test/hash_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <cstdlib>
diff --git a/test/hbd_metrics_test.cc b/test/hbd_metrics_test.cc
index 5b03bee..fa45654 100644
--- a/test/hbd_metrics_test.cc
+++ b/test/hbd_metrics_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <math.h>
diff --git a/test/hiprec_convolve_test.cc b/test/hiprec_convolve_test.cc
index 9424a89..267d315 100644
--- a/test/hiprec_convolve_test.cc
+++ b/test/hiprec_convolve_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <tuple>
diff --git a/test/hiprec_convolve_test_util.cc b/test/hiprec_convolve_test_util.cc
index 5c6cab4..f25bdf0 100644
--- a/test/hiprec_convolve_test_util.cc
+++ b/test/hiprec_convolve_test_util.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "test/hiprec_convolve_test_util.h"
diff --git a/test/hiprec_convolve_test_util.h b/test/hiprec_convolve_test_util.h
index 85ca945..084c562 100644
--- a/test/hiprec_convolve_test_util.h
+++ b/test/hiprec_convolve_test_util.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_TEST_HIPREC_CONVOLVE_TEST_UTIL_H_
diff --git a/test/horver_correlation_test.cc b/test/horver_correlation_test.cc
index d1fd578..a98533d 100644
--- a/test/horver_correlation_test.cc
+++ b/test/horver_correlation_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <tuple>
diff --git a/test/horz_superres_test.cc b/test/horz_superres_test.cc
index 544db5a..a679db0 100644
--- a/test/horz_superres_test.cc
+++ b/test/horz_superres_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <memory>
diff --git a/test/i420_video_source.h b/test/i420_video_source.h
index 233e715..e7e4faf 100644
--- a/test/i420_video_source.h
+++ b/test/i420_video_source.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #ifndef AOM_TEST_I420_VIDEO_SOURCE_H_
 #define AOM_TEST_I420_VIDEO_SOURCE_H_
diff --git a/test/intra_edge_test.cc b/test/intra_edge_test.cc
index f7702c9..6720db3 100644
--- a/test/intra_edge_test.cc
+++ b/test/intra_edge_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <math.h>
diff --git a/test/intrabc_test.cc b/test/intrabc_test.cc
index b57eb6f..25f8057 100644
--- a/test/intrabc_test.cc
+++ b/test/intrabc_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "third_party/googletest/src/googletest/include/gtest/gtest.h"
diff --git a/test/intrapred_test.cc b/test/intrapred_test.cc
index 04e413c..137a4a7 100644
--- a/test/intrapred_test.cc
+++ b/test/intrapred_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <string>
diff --git a/test/invalid_file_test.cc b/test/invalid_file_test.cc
index e8edf13..a553fcb 100644
--- a/test/invalid_file_test.cc
+++ b/test/invalid_file_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <cstdio>
@@ -120,11 +121,7 @@
   FILE *res_file_;
 };
 
-#if !CONFIG_REMOVE_DIST_WTD_COMP && !CONFIG_REMOVE_DUAL_FILTER
-TEST_P(InvalidFileTest, ReturnCode) { RunTest(); }
-#else
 TEST_P(InvalidFileTest, DISABLED_ReturnCode) { RunTest(); }
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP && !COMP_REMOVE_DUAL_FILTER
 
 // If res_filename (the third field) is NULL, then the result filename is
 // filename + ".res" by default. Set res_filename to a string if the result
diff --git a/test/ivf_video_source.h b/test/ivf_video_source.h
index ff28414..e978800 100644
--- a/test/ivf_video_source.h
+++ b/test/ivf_video_source.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #ifndef AOM_TEST_IVF_VIDEO_SOURCE_H_
 #define AOM_TEST_IVF_VIDEO_SOURCE_H_
diff --git a/test/kf_test.cc b/test/kf_test.cc
index c88c07b..62ebf7e 100644
--- a/test/kf_test.cc
+++ b/test/kf_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <ostream>
diff --git a/test/level_test.cc b/test/level_test.cc
index 64084cd..7c053d1 100644
--- a/test/level_test.cc
+++ b/test/level_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2019, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #include <memory>
 
diff --git a/test/lightfield_test.sh b/test/lightfield_test.sh
index cf1ea73..25d4113 100755
--- a/test/lightfield_test.sh
+++ b/test/lightfield_test.sh
@@ -1,12 +1,12 @@
 #!/bin/sh
-## Copyright (c) 2018, Alliance for Open Media. All rights reserved
+## Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ##
-## This source code is subject to the terms of the BSD 2 Clause License and
-## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-## was not distributed with this source code in the LICENSE file, you can
-## obtain it at www.aomedia.org/license/software. If the Alliance for Open
-## Media Patent License 1.0 was not distributed with this source code in the
-## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+## This source code is subject to the terms of the BSD 3-Clause Clear License and the
+## Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+## not distributed with this source code in the LICENSE file, you can obtain it
+## at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+## License 1.0 was not distributed with this source code in the PATENTS file, you
+## can obtain it at aomedia.org/license/patent-license/.
 ##
 ## This file tests the lightfield example.
 ##
diff --git a/test/log2_test.cc b/test/log2_test.cc
index d7840c6..3220948 100644
--- a/test/log2_test.cc
+++ b/test/log2_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <math.h>
diff --git a/test/lossless_test.cc b/test/lossless_test.cc
index f72cdca..a5cf3d7 100644
--- a/test/lossless_test.cc
+++ b/test/lossless_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "third_party/googletest/src/googletest/include/gtest/gtest.h"
diff --git a/test/lpf_test.cc b/test/lpf_test.cc
index dea7de9..0aadb6f 100644
--- a/test/lpf_test.cc
+++ b/test/lpf_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <cmath>
diff --git a/test/masked_sad_test.cc b/test/masked_sad_test.cc
index c61bcb3..55953a7 100644
--- a/test/masked_sad_test.cc
+++ b/test/masked_sad_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #include <math.h>
 #include <stdlib.h>
diff --git a/test/masked_variance_test.cc b/test/masked_variance_test.cc
index fc276c8..0763c83 100644
--- a/test/masked_variance_test.cc
+++ b/test/masked_variance_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <math.h>
diff --git a/test/md5_helper.h b/test/md5_helper.h
index 9443cb2..641767a 100644
--- a/test/md5_helper.h
+++ b/test/md5_helper.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_TEST_MD5_HELPER_H_
diff --git a/test/metadata_test.cc b/test/metadata_test.cc
index 12ad769..26f5e47 100644
--- a/test/metadata_test.cc
+++ b/test/metadata_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2019, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "third_party/googletest/src/googletest/include/gtest/gtest.h"
diff --git a/test/monochrome_test.cc b/test/monochrome_test.cc
index fe60c95..8e79b12 100644
--- a/test/monochrome_test.cc
+++ b/test/monochrome_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <climits>
diff --git a/test/motion_vector_test.cc b/test/motion_vector_test.cc
index 2f4e8ad..1055513 100644
--- a/test/motion_vector_test.cc
+++ b/test/motion_vector_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <memory>
diff --git a/test/noise_model_test.cc b/test/noise_model_test.cc
index aad8905..41548d7 100644
--- a/test/noise_model_test.cc
+++ b/test/noise_model_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <math.h>
diff --git a/test/obmc_sad_test.cc b/test/obmc_sad_test.cc
index 4b7f9d5..dfc98f1 100644
--- a/test/obmc_sad_test.cc
+++ b/test/obmc_sad_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "third_party/googletest/src/googletest/include/gtest/gtest.h"
diff --git a/test/obmc_variance_test.cc b/test/obmc_variance_test.cc
index 41a6a6f..b3a2da3 100644
--- a/test/obmc_variance_test.cc
+++ b/test/obmc_variance_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "third_party/googletest/src/googletest/include/gtest/gtest.h"
diff --git a/test/opt_flow_test.cc b/test/opt_flow_test.cc
new file mode 100644
index 0000000..0273bd6
--- /dev/null
+++ b/test/opt_flow_test.cc
@@ -0,0 +1,1585 @@
+/*
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
+ *
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
+ */
+
+#include <set>
+#include <vector>
+#include "config/av1_rtcd.h"
+#include "config/aom_dsp_rtcd.h"
+#include "test/acm_random.h"
+#include "test/clear_system_state.h"
+#include "third_party/googletest/src/googletest/include/gtest/gtest.h"
+
+#include "aom_ports/aom_timer.h"
+#include "av1/common/reconinter.h"
+#include "av1/common/mvref_common.h"
+
+#if CONFIG_OPTFLOW_REFINEMENT
+namespace {
+
+class BlockSize {
+ public:
+  BlockSize(int w, int h) : width_(w), height_(h) {
+    n_ = (w <= 16 && h <= 16) ? OF_MIN_BSIZE : OF_BSIZE;
+  }
+
+  int Width() const { return width_; }
+  int Height() const { return height_; }
+  int OptFlowBlkSize() const { return n_; }
+
+  bool operator<(const BlockSize &other) const {
+    if (Width() == other.Width()) {
+      return Height() < other.Height();
+    }
+    return Width() < other.Width();
+  }
+
+  bool operator==(const BlockSize &other) const {
+    return Width() == other.Width() && Height() == other.Height();
+  }
+
+ private:
+  int width_;
+  int height_;
+  int n_;
+};
+
+// Block size / bit depth / test function used to parameterize the tests.
+template <typename T>
+class TestParam {
+ public:
+  TestParam(const BlockSize &block, int bd, T test_func)
+      : block_(block), bd_(bd), test_func_(test_func) {}
+
+  const BlockSize &Block() const { return block_; }
+  int BitDepth() const { return bd_; }
+  T TestFunction() const { return test_func_; }
+
+  bool operator==(const TestParam &other) const {
+    return Block() == other.Block() && BitDepth() == other.BitDepth() &&
+           TestFunction() == other.TestFunction();
+  }
+
+ private:
+  BlockSize block_;
+  int bd_;
+  T test_func_;
+};
+
+template <typename T>
+std::ostream &operator<<(std::ostream &os, const TestParam<T> &test_arg) {
+  return os << "TestParam { width:" << test_arg.Block().Width()
+            << " height:" << test_arg.Block().Height()
+            << " bd:" << test_arg.BitDepth() << " }";
+}
+
+// AV1OptFlowTest is the base class that all optical flow tests should derive
+// from.
+template <typename T>
+class AV1OptFlowTest : public ::testing::TestWithParam<TestParam<T>> {
+ public:
+  virtual ~AV1OptFlowTest() { TearDown(); }
+
+  virtual void SetUp() override {
+    rnd_.Reset(libaom_test::ACMRandom::DeterministicSeed());
+  }
+
+  virtual void TearDown() override { libaom_test::ClearSystemState(); }
+
+  // Check that two 8-bit output buffers are identical.
+  void AssertOutputEq(const int *ref, const int *test, int n) {
+    ASSERT_TRUE(ref != test) << "Buffers must be at different memory locations";
+    for (int idx = 0; idx < n; ++idx) {
+      ASSERT_EQ(ref[idx], test[idx]) << "Mismatch at index " << idx;
+    }
+  }
+
+  // Check that two 16-bit output buffers are identical.
+  void AssertOutputBufferEq(const int16_t *ref, const int16_t *test, int width,
+                            int height) {
+    ASSERT_TRUE(ref != test) << "Buffers must be in different memory locations";
+    for (int row = 0; row < height; ++row) {
+      for (int col = 0; col < width; ++col) {
+        ASSERT_EQ(ref[row * width + col], test[row * width + col])
+            << width << "x" << height << " Pixel mismatch at (" << col << ", "
+            << row << ")";
+      }
+    }
+  }
+
+  uint8_t RandomFrameIdx(int max_bit_range) {
+    const int max_val = (1 << max_bit_range) - 1;
+    uint8_t rand_val = rnd_.Rand8() & max_val;
+    return rand_val;
+  }
+
+  int8_t RelativeDistExtreme(int max_bit_range) {
+    return Rand8SingedExtremes(max_bit_range);
+  }
+
+  void RandomInput8(uint8_t *p, const TestParam<T> &param) {
+    EXPECT_EQ(8, param.BitDepth());
+    EXPECT_GE(MAX_SB_SIZE, param.Block().Width());
+    EXPECT_GE(MAX_SB_SIZE, param.Block().Height());
+    const int bw = param.Block().Width();
+    const int bh = param.Block().Height();
+    Randomize(p, bw * bh);
+  }
+
+  void Randomize9Signed(int16_t *p, int size) {
+    for (int i = 0; i < size; ++i) {
+      p[i] = rnd_.Rand9Signed();
+    }
+  }
+
+  void RandomInput9(int16_t *p, const TestParam<T> &param) {
+    EXPECT_GE(MAX_SB_SIZE, param.Block().Width());
+    EXPECT_GE(MAX_SB_SIZE, param.Block().Height());
+    const int bw = param.Block().Width();
+    const int bh = param.Block().Height();
+    Randomize9Signed(p, bw * bh);
+  }
+
+  void RandomInput16(uint16_t *p, const TestParam<T> &param,
+                     int max_bit_range) {
+    EXPECT_GE(12, param.BitDepth());
+    EXPECT_GE(MAX_SB_SIZE, param.Block().Width());
+    EXPECT_GE(MAX_SB_SIZE, param.Block().Height());
+    const int bw = param.Block().Width();
+    const int bh = param.Block().Height();
+    Randomize(p, bw * bh, max_bit_range);
+  }
+
+  void RandomInput16(int16_t *p, const TestParam<T> &param, int max_bit_range) {
+    EXPECT_GE(MAX_SB_SIZE, param.Block().Width());
+    EXPECT_GE(MAX_SB_SIZE, param.Block().Height());
+    const int bw = param.Block().Width();
+    const int bh = param.Block().Height();
+    Randomize(p, bw * bh, max_bit_range);
+  }
+
+  void RandomInput8Extreme(uint8_t *p, const TestParam<T> &param) {
+    EXPECT_EQ(8, param.BitDepth());
+    EXPECT_GE(MAX_SB_SIZE, param.Block().Width());
+    EXPECT_GE(MAX_SB_SIZE, param.Block().Height());
+    const int bw = param.Block().Width();
+    const int bh = param.Block().Height();
+    RandomizeExtreme(p, bw * bh);
+  }
+
+  void RandomInput9Extreme(int16_t *p, const TestParam<T> &param,
+                           int max_bit_range) {
+    EXPECT_GE(12, param.BitDepth());
+    EXPECT_GE(MAX_SB_SIZE, param.Block().Width());
+    EXPECT_GE(MAX_SB_SIZE, param.Block().Height());
+    const int bw = param.Block().Width();
+    const int bh = param.Block().Height();
+    Randomize9Extreme(p, bw * bh, max_bit_range);
+  }
+
+  void RandomInput16Extreme(uint16_t *p, const TestParam<T> &param,
+                            int max_bit_range) {
+    EXPECT_GE(12, param.BitDepth());
+    EXPECT_GE(MAX_SB_SIZE, param.Block().Width());
+    EXPECT_GE(MAX_SB_SIZE, param.Block().Height());
+    const int bw = param.Block().Width();
+    const int bh = param.Block().Height();
+    RandomizeExtreme(p, bw * bh, max_bit_range);
+  }
+
+  void RandomInput16Extreme(int16_t *p, const TestParam<T> &param,
+                            int max_bit_range) {
+    EXPECT_GE(12, param.BitDepth());
+    EXPECT_GE(MAX_SB_SIZE, param.Block().Width());
+    EXPECT_GE(MAX_SB_SIZE, param.Block().Height());
+    const int bw = param.Block().Width();
+    const int bh = param.Block().Height();
+    RandomizeExtreme(p, bw * bh, max_bit_range);
+  }
+
+ private:
+  void Randomize(uint8_t *p, int size) {
+    for (int i = 0; i < size; ++i) {
+      p[i] = rnd_.Rand8();
+    }
+  }
+
+  void Randomize(uint16_t *p, int size, int max_bit_range) {
+    assert(max_bit_range < 16);
+    for (int i = 0; i < size; ++i) {
+      p[i] = rnd_.Rand16() & ((1 << max_bit_range) - 1);
+    }
+  }
+
+  void Randomize(int16_t *p, int size, int max_bit_range) {
+    assert(max_bit_range < 16);
+    for (int i = 0; i < size; ++i) {
+      p[i] = rnd_.Rand15Signed() & ((1 << max_bit_range) - 1);
+    }
+  }
+
+  int RandBool() {
+    const uint32_t value = rnd_.Rand8();
+    // There's a bit more entropy in the upper bits of this implementation.
+    return (value >> 7) & 0x1;
+  }
+
+  uint8_t Rand8Extremes() { return static_cast<uint8_t>(RandBool() ? 255 : 0); }
+
+  int8_t Rand8SingedExtremes(int max_bit_range) {
+    const int max_val = (1 << max_bit_range) - 1;
+    const int half_max_val = 1 << (max_bit_range - 1);
+    uint8_t r_u8 = Rand8Extremes() & max_val;
+    return static_cast<int8_t>(r_u8 - half_max_val);
+  }
+
+  int16_t Rand9SingedExtremes(int max_bit_range) {
+    const int half_max_val = 1 << (max_bit_range - 1);
+    uint16_t r_u16 = Rand16Extremes(max_bit_range);
+    return static_cast<int16_t>(r_u16 - half_max_val);
+  }
+
+  uint16_t Rand16Extremes(int max_bit_range) {
+    const int max_val = (1 << max_bit_range) - 1;
+    return static_cast<uint16_t>(RandBool() ? max_val : 0);
+  }
+
+  int16_t Rand16SingedExtremes(int max_bit_range) {
+    const int half_max_val = 1 << (max_bit_range - 1);
+    uint16_t r_u16 = Rand16Extremes(max_bit_range);
+    return static_cast<int16_t>(r_u16 - half_max_val);
+  }
+
+  void RandomizeExtreme(uint8_t *p, int size) {
+    for (int i = 0; i < size; ++i) {
+      p[i] = Rand8Extremes();
+    }
+  }
+
+  void RandomizeExtreme(uint16_t *p, int size, int max_bit_range) {
+    for (int i = 0; i < size; ++i) {
+      p[i] = Rand16Extremes(max_bit_range);
+    }
+  }
+
+  void RandomizeExtreme(int16_t *p, int size, int max_bit_range) {
+    for (int i = 0; i < size; ++i) {
+      p[i] = Rand16SingedExtremes(max_bit_range);
+    }
+  }
+
+  void Randomize9Extreme(int16_t *p, int size, int max_bit_range) {
+    for (int i = 0; i < size; ++i) {
+      p[i] = Rand9SingedExtremes(max_bit_range);
+    }
+  }
+
+  libaom_test::ACMRandom rnd_;
+};
+
+// a function to generate test parameters for just luma block sizes.
+template <typename T>
+std::vector<TestParam<T>> GetOptFlowTestParams(
+    std::initializer_list<int> bit_depths, T test_func) {
+  std::set<BlockSize> sizes;
+  for (int bsize = BLOCK_8X8; bsize < BLOCK_SIZES_ALL; ++bsize) {
+    const int w = block_size_wide[bsize];
+    const int h = block_size_high[bsize];
+    if (w < 8 || h < 8) continue;
+    sizes.insert(BlockSize(w, h));
+  }
+  std::vector<TestParam<T>> result;
+  for (int bit_depth : bit_depths) {
+    for (const auto &block : sizes) {
+      result.push_back(TestParam<T>(block, bit_depth, test_func));
+    }
+  }
+  return result;
+}
+
+template <typename T>
+std::vector<TestParam<T>> GetOptFlowLowbdTestParams(T test_func) {
+  return GetOptFlowTestParams({ 8 }, test_func);
+}
+
+template <typename T>
+::testing::internal::ParamGenerator<TestParam<T>> BuildOptFlowParams(
+    T test_func) {
+  return ::testing::ValuesIn(GetOptFlowLowbdTestParams(test_func));
+}
+
+typedef int (*opfl_mv_refinement)(const uint8_t *p0, int pstride0,
+                                  const uint8_t *p1, int pstride1,
+                                  const int16_t *gx0, const int16_t *gy0,
+                                  const int16_t *gx1, const int16_t *gy1,
+                                  int gstride, int bw, int bh, int n, int d0,
+                                  int d1, int grad_prec_bits, int mv_prec_bits,
+                                  int *vx0, int *vy0, int *vx1, int *vy1);
+
+class AV1OptFlowRefineTest : public AV1OptFlowTest<opfl_mv_refinement> {
+ public:
+  AV1OptFlowRefineTest() {
+    const BlockSize &block = GetParam().Block();
+    const int bw = block.Width();
+    const int bh = block.Height();
+
+    input0_ = (uint8_t *)aom_memalign(16, bw * bh * sizeof(uint8_t));
+    input1_ = (uint8_t *)aom_memalign(16, bw * bh * sizeof(uint8_t));
+    gx0_ = (int16_t *)aom_memalign(16, bw * bh * sizeof(int16_t));
+    gy0_ = (int16_t *)aom_memalign(16, bw * bh * sizeof(int16_t));
+    gx1_ = (int16_t *)aom_memalign(16, bw * bh * sizeof(int16_t));
+    gy1_ = (int16_t *)aom_memalign(16, bw * bh * sizeof(int16_t));
+  }
+
+  ~AV1OptFlowRefineTest() {
+    aom_free(input0_);
+    aom_free(input1_);
+    aom_free(gx0_);
+    aom_free(gy0_);
+    aom_free(gx1_);
+    aom_free(gy1_);
+  }
+
+  void RunTest(const int is_speed) {
+    OrderHintInfo oh_info;
+    const BlockSize &block = GetParam().Block();
+    const int bw_log2 = block.Width() >> MI_SIZE_LOG2;
+    const int bh_log2 = block.Height() >> MI_SIZE_LOG2;
+    const int bd = GetParam().BitDepth();
+    const int numIter = is_speed ? 1 : 16384 / (bw_log2 * bh_log2);
+    const int oh_start_bits = is_speed ? kMaxOrderHintBits : 1;
+
+    oh_info.enable_order_hint = 1;
+    for (int oh_bits = oh_start_bits; oh_bits <= kMaxOrderHintBits; oh_bits++) {
+      for (int count = 0; count < numIter;) {
+        const int cur_frm_idx = RandomFrameIdx(oh_bits);
+        const int ref0_frm_idx = RandomFrameIdx(oh_bits);
+        const int ref1_frm_idx = RandomFrameIdx(oh_bits);
+
+        oh_info.order_hint_bits_minus_1 = oh_bits - 1;
+        const int d0 = get_relative_dist(&oh_info, cur_frm_idx, ref0_frm_idx);
+        const int d1 = get_relative_dist(&oh_info, cur_frm_idx, ref1_frm_idx);
+        if (!d0 || !d1) continue;
+
+        RandomInput8(input0_, GetParam());
+        RandomInput8(input1_, GetParam());
+        RandomInput9(gx0_, GetParam());
+        RandomInput9(gy0_, GetParam());
+        RandomInput9(gx1_, GetParam());
+        RandomInput9(gy1_, GetParam());
+
+        TestOptFlowRefine(input0_, input1_, gx0_, gy0_, gx1_, gy1_, is_speed,
+                          d0, d1);
+        count++;
+      }
+    }
+    if (is_speed) return;
+
+    // Extreme value test
+    for (int oh_bits = oh_start_bits; oh_bits <= kMaxOrderHintBits;
+         oh_bits += kMaxOrderHintBits - 1) {
+      for (int count = 0; count < numIter;) {
+        const int d0 = RelativeDistExtreme(oh_bits);
+        const int d1 = RelativeDistExtreme(oh_bits);
+        if (!d0 || !d1) continue;
+
+        RandomInput8Extreme(input0_, GetParam());
+        RandomInput8Extreme(input1_, GetParam());
+        RandomInput9Extreme(gx0_, GetParam(), bd + 1);
+        RandomInput9Extreme(gy0_, GetParam(), bd + 1);
+        RandomInput9Extreme(gx1_, GetParam(), bd + 1);
+        RandomInput9Extreme(gy1_, GetParam(), bd + 1);
+
+        TestOptFlowRefine(input0_, input1_, gx0_, gy0_, gx1_, gy1_, 0, d0, d1);
+        count++;
+      }
+    }
+  }
+
+ private:
+  void TestOptFlowRefine(uint8_t *input0, uint8_t *input1, int16_t *gx0,
+                         int16_t *gy0, int16_t *gx1, int16_t *gy1,
+                         const int is_speed, int d0, int d1) {
+    const BlockSize &block = GetParam().Block();
+    const int bw = block.Width();
+    const int bh = block.Height();
+    const int n = block.OptFlowBlkSize();
+
+    opfl_mv_refinement ref_func = av1_opfl_mv_refinement_nxn_lowbd_c;
+    opfl_mv_refinement test_func = GetParam().TestFunction();
+
+    if (is_speed)
+      OptFlowRefineSpeed(ref_func, test_func, input0, input1, gx0, gy0, gx1,
+                         gy1, bw, bh, n, d0, d1);
+    else
+      OptFlowRefine(ref_func, test_func, input0, input1, gx0, gy0, gx1, gy1, bw,
+                    bh, n, d0, d1);
+  }
+
+  void OptFlowRefine(opfl_mv_refinement ref_func, opfl_mv_refinement test_func,
+                     const uint8_t *input0, const uint8_t *input1,
+                     const int16_t *gx0, const int16_t *gy0, const int16_t *gx1,
+                     const int16_t *gy1, int bw, int bh, int n, int d0,
+                     int d1) {
+    int ref_out[4 * N_OF_OFFSETS] = { 0 };
+    int test_out[4 * N_OF_OFFSETS] = { 0 };
+    const int grad_prec_bits = 3 - kSubpelGradDeltaBits - 2;
+    const int mv_prec_bits = MV_REFINE_PREC_BITS;
+    int stride0 = bw;
+    int stride1 = bw;
+    int gstride = bw;
+    int n_blocks = 0;
+
+    n_blocks = ref_func(
+        input0, stride0, input1, stride1, gx0, gy0, gx1, gy1, gstride, bw, bh,
+        n, d0, d1, grad_prec_bits, mv_prec_bits, &ref_out[kVX_0 * N_OF_OFFSETS],
+        &ref_out[kVY_0 * N_OF_OFFSETS], &ref_out[kVX_1 * N_OF_OFFSETS],
+        &ref_out[kVY_1 * N_OF_OFFSETS]);
+    test_func(input0, stride0, input1, stride1, gx0, gy0, gx1, gy1, gstride, bw,
+              bh, n, d0, d1, grad_prec_bits, mv_prec_bits,
+              &test_out[kVX_0 * N_OF_OFFSETS], &test_out[kVY_0 * N_OF_OFFSETS],
+              &test_out[kVX_1 * N_OF_OFFSETS], &test_out[kVY_1 * N_OF_OFFSETS]);
+
+    AssertOutputEq(&ref_out[kVX_0 * N_OF_OFFSETS],
+                   &test_out[kVX_0 * N_OF_OFFSETS], n_blocks);
+    AssertOutputEq(&ref_out[kVY_0 * N_OF_OFFSETS],
+                   &test_out[kVY_0 * N_OF_OFFSETS], n_blocks);
+    AssertOutputEq(&ref_out[kVX_1 * N_OF_OFFSETS],
+                   &test_out[kVX_1 * N_OF_OFFSETS], n_blocks);
+    AssertOutputEq(&ref_out[kVY_1 * N_OF_OFFSETS],
+                   &test_out[kVY_1 * N_OF_OFFSETS], n_blocks);
+  }
+
+  void OptFlowRefineSpeed(opfl_mv_refinement ref_func,
+                          opfl_mv_refinement test_func, const uint8_t *input0,
+                          const uint8_t *input1, const int16_t *gx0,
+                          const int16_t *gy0, const int16_t *gx1,
+                          const int16_t *gy1, int bw, int bh, int n, int d0,
+                          int d1) {
+    int ref_out[4 * N_OF_OFFSETS] = { 0 };
+    int test_out[4 * N_OF_OFFSETS] = { 0 };
+    const int grad_prec_bits = 3 - kSubpelGradDeltaBits - 2;
+    const int mv_prec_bits = MV_REFINE_PREC_BITS;
+    const int bw_log2 = bw >> MI_SIZE_LOG2;
+    const int bh_log2 = bh >> MI_SIZE_LOG2;
+    int stride0 = bw;
+    int stride1 = bw;
+    int gstride = bw;
+
+    const int numIter = 2097152 / (bw_log2 * bh_log2);
+    aom_usec_timer timer_ref;
+    aom_usec_timer timer_test;
+
+    aom_usec_timer_start(&timer_ref);
+    for (int count = 0; count < numIter; count++) {
+      ref_func(input0, stride0, input1, stride1, gx0, gy0, gx1, gy1, gstride,
+               bw, bh, n, d0, d1, grad_prec_bits, mv_prec_bits,
+               &ref_out[kVX_0 * N_OF_OFFSETS], &ref_out[kVY_0 * N_OF_OFFSETS],
+               &ref_out[kVX_1 * N_OF_OFFSETS], &ref_out[kVY_1 * N_OF_OFFSETS]);
+    }
+    aom_usec_timer_mark(&timer_ref);
+
+    aom_usec_timer_start(&timer_test);
+    for (int count = 0; count < numIter; count++) {
+      test_func(
+          input0, stride0, input1, stride1, gx0, gy0, gx1, gy1, gstride, bw, bh,
+          n, d0, d1, grad_prec_bits, mv_prec_bits,
+          &test_out[kVX_0 * N_OF_OFFSETS], &test_out[kVY_0 * N_OF_OFFSETS],
+          &test_out[kVX_1 * N_OF_OFFSETS], &test_out[kVY_1 * N_OF_OFFSETS]);
+    }
+    aom_usec_timer_mark(&timer_test);
+
+    const int total_time_ref =
+        static_cast<int>(aom_usec_timer_elapsed(&timer_ref));
+    const int total_time_test =
+        static_cast<int>(aom_usec_timer_elapsed(&timer_test));
+
+    printf("ref_time = %d \t simd_time = %d \t Gain = %4.2f \n", total_time_ref,
+           total_time_test,
+           (static_cast<float>(total_time_ref) /
+            static_cast<float>(total_time_test)));
+  }
+  static constexpr int kVX_0 = 0;
+  static constexpr int kVX_1 = 1;
+  static constexpr int kVY_0 = 2;
+  static constexpr int kVY_1 = 3;
+  static constexpr int kMaxOrderHintBits = 8;
+  static constexpr int kSubpelGradDeltaBits = 3;
+  uint8_t *input0_;
+  uint8_t *input1_;
+  int16_t *gx0_;
+  int16_t *gy0_;
+  int16_t *gx1_;
+  int16_t *gy1_;
+};
+TEST_P(AV1OptFlowRefineTest, CheckOutput) { RunTest(0); }
+TEST_P(AV1OptFlowRefineTest, DISABLED_Speed) { RunTest(1); }
+
+INSTANTIATE_TEST_SUITE_P(
+    C, AV1OptFlowRefineTest,
+    BuildOptFlowParams(av1_opfl_mv_refinement_nxn_lowbd_c));
+#if HAVE_SSE4_1
+INSTANTIATE_TEST_SUITE_P(
+    SSE4_1, AV1OptFlowRefineTest,
+    BuildOptFlowParams(av1_opfl_mv_refinement_nxn_lowbd_sse4_1));
+#endif
+
+template <typename T>
+std::vector<TestParam<T>> GetOptFlowHighbdTestParams(T test_func) {
+  return GetOptFlowTestParams({ 8, 10, 12 }, test_func);
+}
+
+template <typename T>
+::testing::internal::ParamGenerator<TestParam<T>> BuildOptFlowHighbdParams(
+    T test_func) {
+  return ::testing::ValuesIn(GetOptFlowHighbdTestParams(test_func));
+}
+
+typedef int (*opfl_mv_refinement_highbd)(const uint16_t *p0, int pstride0,
+                                         const uint16_t *p1, int pstride1,
+                                         const int16_t *gx0, const int16_t *gy0,
+                                         const int16_t *gx1, const int16_t *gy1,
+                                         int gstride, int bw, int bh, int n,
+                                         int d0, int d1, int grad_prec_bits,
+                                         int mv_prec_bits, int *vx0, int *vy0,
+                                         int *vx1, int *vy1);
+
+class AV1OptFlowRefineHighbdTest
+    : public AV1OptFlowTest<opfl_mv_refinement_highbd> {
+ public:
+  AV1OptFlowRefineHighbdTest() {
+    const BlockSize &block = GetParam().Block();
+    const int bw = block.Width();
+    const int bh = block.Height();
+
+    input0_ = (uint16_t *)aom_memalign(16, bw * bh * sizeof(uint16_t));
+    input1_ = (uint16_t *)aom_memalign(16, bw * bh * sizeof(uint16_t));
+    gx0_ = (int16_t *)aom_memalign(16, bw * bh * sizeof(int16_t));
+    gy0_ = (int16_t *)aom_memalign(16, bw * bh * sizeof(int16_t));
+    gx1_ = (int16_t *)aom_memalign(16, bw * bh * sizeof(int16_t));
+    gy1_ = (int16_t *)aom_memalign(16, bw * bh * sizeof(int16_t));
+  }
+
+  ~AV1OptFlowRefineHighbdTest() {
+    aom_free(input0_);
+    aom_free(input1_);
+    aom_free(gx0_);
+    aom_free(gy0_);
+    aom_free(gx1_);
+    aom_free(gy1_);
+  }
+
+  void RunTest(const int is_speed) {
+    OrderHintInfo oh_info;
+    const BlockSize &block = GetParam().Block();
+    const int bd = GetParam().BitDepth();
+    const int bw_log2 = block.Width() >> MI_SIZE_LOG2;
+    const int bh_log2 = block.Height() >> MI_SIZE_LOG2;
+    const int numIter = is_speed ? 1 : 16384 / (bw_log2 * bh_log2);
+    const int oh_start_bits = is_speed ? kMaxOrderHintBits : 1;
+
+    oh_info.enable_order_hint = 1;
+    for (int oh_bits = oh_start_bits; oh_bits <= kMaxOrderHintBits; oh_bits++) {
+      for (int count = 0; count < numIter;) {
+        const int cur_frm_idx = RandomFrameIdx(oh_bits);
+        const int ref0_frm_idx = RandomFrameIdx(oh_bits);
+        const int ref1_frm_idx = RandomFrameIdx(oh_bits);
+
+        oh_info.order_hint_bits_minus_1 = oh_bits - 1;
+        const int d0 = get_relative_dist(&oh_info, cur_frm_idx, ref0_frm_idx);
+        const int d1 = get_relative_dist(&oh_info, cur_frm_idx, ref1_frm_idx);
+        if (!d0 || !d1) continue;
+
+        RandomInput16(input0_, GetParam(), bd);
+        RandomInput16(input1_, GetParam(), bd);
+        RandomInput16(gx0_, GetParam(), bd + 1);
+        RandomInput16(gy0_, GetParam(), bd + 1);
+        RandomInput16(gx1_, GetParam(), bd + 1);
+        RandomInput16(gy1_, GetParam(), bd + 1);
+
+        TestOptFlowRefine(input0_, input1_, gx0_, gy0_, gx1_, gy1_, is_speed,
+                          d0, d1);
+        count++;
+      }
+    }
+    if (is_speed) return;
+
+    // Extreme value test
+    for (int oh_bits = oh_start_bits; oh_bits <= kMaxOrderHintBits;
+         oh_bits += kMaxOrderHintBits - 1) {
+      for (int count = 0; count < numIter;) {
+        const int d0 = RelativeDistExtreme(oh_bits);
+        const int d1 = RelativeDistExtreme(oh_bits);
+        if (!d0 || !d1) continue;
+
+        RandomInput16Extreme(input0_, GetParam(), bd);
+        RandomInput16Extreme(input1_, GetParam(), bd);
+        RandomInput16Extreme(gx0_, GetParam(), bd + 1);
+        RandomInput16Extreme(gy0_, GetParam(), bd + 1);
+        RandomInput16Extreme(gx1_, GetParam(), bd + 1);
+        RandomInput16Extreme(gy1_, GetParam(), bd + 1);
+
+        TestOptFlowRefine(input0_, input1_, gx0_, gy0_, gx1_, gy1_, 0, d0, d1);
+        count++;
+      }
+    }
+  }
+
+ private:
+  void TestOptFlowRefine(uint16_t *input0, uint16_t *input1, int16_t *gx0,
+                         int16_t *gy0, int16_t *gx1, int16_t *gy1,
+                         const int is_speed, int d0, int d1) {
+    const BlockSize &block = GetParam().Block();
+    const int bw = block.Width();
+    const int bh = block.Height();
+    const int n = block.OptFlowBlkSize();
+
+    opfl_mv_refinement_highbd ref_func = av1_opfl_mv_refinement_nxn_highbd_c;
+    opfl_mv_refinement_highbd test_func = GetParam().TestFunction();
+
+    if (is_speed)
+      OptFlowRefineSpeed(ref_func, test_func, input0, input1, gx0, gy0, gx1,
+                         gy1, bw, bh, n, d0, d1);
+    else
+      OptFlowRefine(ref_func, test_func, input0, input1, gx0, gy0, gx1, gy1, bw,
+                    bh, n, d0, d1);
+  }
+
+  void OptFlowRefine(opfl_mv_refinement_highbd ref_func,
+                     opfl_mv_refinement_highbd test_func,
+                     const uint16_t *input0, const uint16_t *input1,
+                     const int16_t *gx0, const int16_t *gy0, const int16_t *gx1,
+                     const int16_t *gy1, int bw, int bh, int n, int d0,
+                     int d1) {
+    int ref_out[4 * N_OF_OFFSETS] = { 0 };
+    int test_out[4 * N_OF_OFFSETS] = { 0 };
+    const int grad_prec_bits = 3 - kSubpelGradDeltaBits - 2;
+    const int mv_prec_bits = MV_REFINE_PREC_BITS;
+    int stride0 = bw;
+    int stride1 = bw;
+    int gstride = bw;
+    int n_blocks = 0;
+
+    n_blocks = ref_func(
+        input0, stride0, input1, stride1, gx0, gy0, gx1, gy1, gstride, bw, bh,
+        n, d0, d1, grad_prec_bits, mv_prec_bits, &ref_out[kVX_0 * N_OF_OFFSETS],
+        &ref_out[kVY_0 * N_OF_OFFSETS], &ref_out[kVX_1 * N_OF_OFFSETS],
+        &ref_out[kVY_1 * N_OF_OFFSETS]);
+    test_func(input0, stride0, input1, stride1, gx0, gy0, gx1, gy1, gstride, bw,
+              bh, n, d0, d1, grad_prec_bits, mv_prec_bits,
+              &test_out[kVX_0 * N_OF_OFFSETS], &test_out[kVY_0 * N_OF_OFFSETS],
+              &test_out[kVX_1 * N_OF_OFFSETS], &test_out[kVY_1 * N_OF_OFFSETS]);
+
+    AssertOutputEq(&ref_out[kVX_0 * N_OF_OFFSETS],
+                   &test_out[kVX_0 * N_OF_OFFSETS], n_blocks);
+    AssertOutputEq(&ref_out[kVY_0 * N_OF_OFFSETS],
+                   &test_out[kVY_0 * N_OF_OFFSETS], n_blocks);
+    AssertOutputEq(&ref_out[kVX_1 * N_OF_OFFSETS],
+                   &test_out[kVX_1 * N_OF_OFFSETS], n_blocks);
+    AssertOutputEq(&ref_out[kVY_1 * N_OF_OFFSETS],
+                   &test_out[kVY_1 * N_OF_OFFSETS], n_blocks);
+  }
+
+  void OptFlowRefineSpeed(opfl_mv_refinement_highbd ref_func,
+                          opfl_mv_refinement_highbd test_func,
+                          const uint16_t *input0, const uint16_t *input1,
+                          const int16_t *gx0, const int16_t *gy0,
+                          const int16_t *gx1, const int16_t *gy1, int bw,
+                          int bh, int n, int d0, int d1) {
+    int ref_out[4 * N_OF_OFFSETS] = { 0 };
+    int test_out[4 * N_OF_OFFSETS] = { 0 };
+    const int grad_prec_bits = 3 - kSubpelGradDeltaBits - 2;
+    const int mv_prec_bits = MV_REFINE_PREC_BITS;
+    const int bw_log2 = bw >> MI_SIZE_LOG2;
+    const int bh_log2 = bh >> MI_SIZE_LOG2;
+    int stride0 = bw;
+    int stride1 = bw;
+    int gstride = bw;
+
+    const int numIter = 2097152 / (bw_log2 * bh_log2);
+    aom_usec_timer timer_ref;
+    aom_usec_timer timer_test;
+
+    aom_usec_timer_start(&timer_ref);
+    for (int count = 0; count < numIter; count++) {
+      ref_func(input0, stride0, input1, stride1, gx0, gy0, gx1, gy1, gstride,
+               bw, bh, n, d0, d1, grad_prec_bits, mv_prec_bits,
+               &ref_out[kVX_0 * N_OF_OFFSETS], &ref_out[kVY_0 * N_OF_OFFSETS],
+               &ref_out[kVX_1 * N_OF_OFFSETS], &ref_out[kVY_1 * N_OF_OFFSETS]);
+    }
+    aom_usec_timer_mark(&timer_ref);
+
+    aom_usec_timer_start(&timer_test);
+    for (int count = 0; count < numIter; count++) {
+      test_func(
+          input0, stride0, input1, stride1, gx0, gy0, gx1, gy1, gstride, bw, bh,
+          n, d0, d1, grad_prec_bits, mv_prec_bits,
+          &test_out[kVX_0 * N_OF_OFFSETS], &test_out[kVY_0 * N_OF_OFFSETS],
+          &test_out[kVX_1 * N_OF_OFFSETS], &test_out[kVY_1 * N_OF_OFFSETS]);
+    }
+    aom_usec_timer_mark(&timer_test);
+
+    const int total_time_ref =
+        static_cast<int>(aom_usec_timer_elapsed(&timer_ref));
+    const int total_time_test =
+        static_cast<int>(aom_usec_timer_elapsed(&timer_test));
+
+    printf("ref_time = %d \t simd_time = %d \t Gain = %4.2f \n", total_time_ref,
+           total_time_test,
+           (static_cast<float>(total_time_ref) /
+            static_cast<float>(total_time_test)));
+  }
+
+  static constexpr int kVX_0 = 0;
+  static constexpr int kVX_1 = 1;
+  static constexpr int kVY_0 = 2;
+  static constexpr int kVY_1 = 3;
+  static constexpr int kMaxOrderHintBits = 8;
+  static constexpr int kSubpelGradDeltaBits = 3;
+  uint16_t *input0_;
+  uint16_t *input1_;
+  int16_t *gx0_;
+  int16_t *gy0_;
+  int16_t *gx1_;
+  int16_t *gy1_;
+};
+TEST_P(AV1OptFlowRefineHighbdTest, CheckOutput) { RunTest(0); }
+TEST_P(AV1OptFlowRefineHighbdTest, DISABLED_Speed) { RunTest(1); }
+
+INSTANTIATE_TEST_SUITE_P(
+    C, AV1OptFlowRefineHighbdTest,
+    BuildOptFlowHighbdParams(av1_opfl_mv_refinement_nxn_highbd_c));
+
+#if HAVE_SSE4_1
+INSTANTIATE_TEST_SUITE_P(
+    SSE4_1, AV1OptFlowRefineHighbdTest,
+    BuildOptFlowHighbdParams(av1_opfl_mv_refinement_nxn_highbd_sse4_1));
+#endif
+
+#if OPFL_BICUBIC_GRAD
+typedef void (*bicubic_grad_interp_lowbd)(const int16_t *pred_src,
+                                          int16_t *x_grad, int16_t *y_grad,
+                                          const int blk_width,
+                                          const int blk_height);
+
+class AV1OptFlowBiCubicGradLowbdTest
+    : public AV1OptFlowTest<bicubic_grad_interp_lowbd> {
+ public:
+  AV1OptFlowBiCubicGradLowbdTest() {
+    const BlockSize &block = GetParam().Block();
+    const int bw = block.Width();
+    const int bh = block.Height();
+
+    pred_src_ = (int16_t *)aom_memalign(16, bw * bh * sizeof(int16_t));
+    x_grad_ref_ = (int16_t *)aom_memalign(16, bw * bh * sizeof(int16_t));
+    y_grad_ref_ = (int16_t *)aom_memalign(16, bw * bh * sizeof(int16_t));
+    x_grad_test_ = (int16_t *)aom_memalign(16, bw * bh * sizeof(int16_t));
+    y_grad_test_ = (int16_t *)aom_memalign(16, bw * bh * sizeof(int16_t));
+
+    memset(x_grad_ref_, 0, bw * bh * sizeof(int16_t));
+    memset(y_grad_ref_, 0, bw * bh * sizeof(int16_t));
+    memset(x_grad_test_, 0, bw * bh * sizeof(int16_t));
+    memset(y_grad_test_, 0, bw * bh * sizeof(int16_t));
+  }
+
+  ~AV1OptFlowBiCubicGradLowbdTest() {
+    aom_free(pred_src_);
+    aom_free(x_grad_ref_);
+    aom_free(y_grad_ref_);
+    aom_free(x_grad_test_);
+    aom_free(y_grad_test_);
+  }
+
+  void RunTest(const int is_speed) {
+    const BlockSize &block = GetParam().Block();
+    const int bd = GetParam().BitDepth();
+    const int bw_log2 = block.Width() >> MI_SIZE_LOG2;
+    const int bh_log2 = block.Height() >> MI_SIZE_LOG2;
+    const int numIter = is_speed ? 1 : 16384 / (bw_log2 * bh_log2);
+
+    for (int count = 0; count < numIter; count++) {
+      RandomInput16(pred_src_, GetParam(), bd);
+      TestBicubicGrad(pred_src_, x_grad_ref_, y_grad_ref_, x_grad_test_,
+                      y_grad_test_, is_speed);
+    }
+    if (is_speed) return;
+
+    for (int count = 0; count < numIter; count++) {
+      RandomInput16Extreme(pred_src_, GetParam(), bd);
+      TestBicubicGrad(pred_src_, x_grad_ref_, y_grad_ref_, x_grad_test_,
+                      y_grad_test_, 0);
+    }
+  }
+
+ private:
+  void TestBicubicGrad(int16_t *pred_src, int16_t *x_grad_ref,
+                       int16_t *y_grad_ref, int16_t *x_grad_test,
+                       int16_t *y_grad_test, int is_speed) {
+    const BlockSize &block = GetParam().Block();
+    const int bw = block.Width();
+    const int bh = block.Height();
+
+    bicubic_grad_interp_lowbd ref_func = av1_bicubic_grad_interpolation_c;
+    bicubic_grad_interp_lowbd test_func = GetParam().TestFunction();
+    if (is_speed)
+      BicubicGradSpeed(ref_func, test_func, pred_src, x_grad_ref, y_grad_ref,
+                       x_grad_test, y_grad_test, bw, bh);
+    else
+      BicubicGrad(ref_func, test_func, pred_src, x_grad_ref, y_grad_ref,
+                  x_grad_test, y_grad_test, bw, bh);
+  }
+
+  void BicubicGrad(bicubic_grad_interp_lowbd ref_func,
+                   bicubic_grad_interp_lowbd test_func, const int16_t *pred_src,
+                   int16_t *x_grad_ref, int16_t *y_grad_ref,
+                   int16_t *x_grad_test, int16_t *y_grad_test, const int bw,
+                   const int bh) {
+    ref_func(pred_src, x_grad_ref, y_grad_ref, bw, bh);
+    test_func(pred_src, x_grad_test, y_grad_test, bw, bh);
+
+    AssertOutputBufferEq(x_grad_ref, x_grad_test, bw, bh);
+    AssertOutputBufferEq(y_grad_ref, y_grad_test, bw, bh);
+  }
+
+  void BicubicGradSpeed(bicubic_grad_interp_lowbd ref_func,
+                        bicubic_grad_interp_lowbd test_func, int16_t *pred_src,
+                        int16_t *x_grad_ref, int16_t *y_grad_ref,
+                        int16_t *x_grad_test, int16_t *y_grad_test,
+                        const int bw, const int bh) {
+    const int bw_log2 = bw >> MI_SIZE_LOG2;
+    const int bh_log2 = bh >> MI_SIZE_LOG2;
+
+    const int numIter = 2097152 / (bw_log2 * bh_log2);
+    aom_usec_timer timer_ref;
+    aom_usec_timer timer_test;
+
+    aom_usec_timer_start(&timer_ref);
+    for (int count = 0; count < numIter; count++)
+      ref_func(pred_src, x_grad_ref, y_grad_ref, bw, bh);
+    aom_usec_timer_mark(&timer_ref);
+
+    aom_usec_timer_start(&timer_test);
+    for (int count = 0; count < numIter; count++)
+      test_func(pred_src, x_grad_test, y_grad_test, bw, bh);
+    aom_usec_timer_mark(&timer_test);
+
+    const int total_time_ref =
+        static_cast<int>(aom_usec_timer_elapsed(&timer_ref));
+    const int total_time_test =
+        static_cast<int>(aom_usec_timer_elapsed(&timer_test));
+
+    printf("ref_time = %d \t simd_time = %d \t Gain = %4.2f \n", total_time_ref,
+           total_time_test,
+           (static_cast<float>(total_time_ref) /
+            static_cast<float>(total_time_test)));
+  }
+
+  int16_t *pred_src_;
+  int16_t *x_grad_ref_;
+  int16_t *y_grad_ref_;
+  int16_t *x_grad_test_;
+  int16_t *y_grad_test_;
+};
+TEST_P(AV1OptFlowBiCubicGradLowbdTest, CheckOutput) { RunTest(0); }
+TEST_P(AV1OptFlowBiCubicGradLowbdTest, DISABLED_Speed) { RunTest(1); }
+
+INSTANTIATE_TEST_SUITE_P(C, AV1OptFlowBiCubicGradLowbdTest,
+                         BuildOptFlowParams(av1_bicubic_grad_interpolation_c));
+
+#if HAVE_SSE4_1
+INSTANTIATE_TEST_SUITE_P(
+    SSE4_1, AV1OptFlowBiCubicGradLowbdTest,
+    BuildOptFlowParams(av1_bicubic_grad_interpolation_sse4_1));
+#endif
+
+typedef void (*bicubic_grad_interp_highbd)(const int16_t *pred_src,
+                                           int16_t *x_grad, int16_t *y_grad,
+                                           const int blk_width,
+                                           const int blk_height);
+
+class AV1OptFlowBiCubicGradHighbdTest
+    : public AV1OptFlowTest<bicubic_grad_interp_highbd> {
+ public:
+  AV1OptFlowBiCubicGradHighbdTest() {
+    const BlockSize &block = GetParam().Block();
+    const int bw = block.Width();
+    const int bh = block.Height();
+
+    pred_src_ = (int16_t *)aom_memalign(16, bw * bh * sizeof(int16_t));
+    x_grad_ref_ = (int16_t *)aom_memalign(16, bw * bh * sizeof(int16_t));
+    y_grad_ref_ = (int16_t *)aom_memalign(16, bw * bh * sizeof(int16_t));
+    x_grad_test_ = (int16_t *)aom_memalign(16, bw * bh * sizeof(int16_t));
+    y_grad_test_ = (int16_t *)aom_memalign(16, bw * bh * sizeof(int16_t));
+
+    memset(x_grad_ref_, 0, bw * bh * sizeof(int16_t));
+    memset(y_grad_ref_, 0, bw * bh * sizeof(int16_t));
+    memset(x_grad_test_, 0, bw * bh * sizeof(int16_t));
+    memset(y_grad_test_, 0, bw * bh * sizeof(int16_t));
+  }
+
+  ~AV1OptFlowBiCubicGradHighbdTest() {
+    aom_free(pred_src_);
+    aom_free(x_grad_ref_);
+    aom_free(y_grad_ref_);
+    aom_free(x_grad_test_);
+    aom_free(y_grad_test_);
+  }
+
+  void Run(const int is_speed) {
+    const BlockSize &block = GetParam().Block();
+    const int bd = GetParam().BitDepth();
+    const int bw_log2 = block.Width() >> MI_SIZE_LOG2;
+    const int bh_log2 = block.Height() >> MI_SIZE_LOG2;
+    const int numIter = is_speed ? 1 : 16384 / (bw_log2 * bh_log2);
+
+    for (int count = 0; count < numIter; count++) {
+      RandomInput16(pred_src_, GetParam(), bd);
+      TestBicubicGradHighbd(pred_src_, x_grad_ref_, y_grad_ref_, x_grad_test_,
+                            y_grad_test_, is_speed);
+    }
+    if (is_speed) return;
+
+    for (int count = 0; count < numIter; count++) {
+      RandomInput16Extreme((uint16_t *)pred_src_, GetParam(), bd);
+      TestBicubicGradHighbd(pred_src_, x_grad_ref_, y_grad_ref_, x_grad_test_,
+                            y_grad_test_, 0);
+    }
+  }
+
+ private:
+  void TestBicubicGradHighbd(int16_t *pred_src, int16_t *x_grad_ref,
+                             int16_t *y_grad_ref, int16_t *x_grad_test,
+                             int16_t *y_grad_test, int is_speed) {
+    const BlockSize &block = GetParam().Block();
+    const int bw = block.Width();
+    const int bh = block.Height();
+
+    bicubic_grad_interp_highbd ref_func =
+        av1_bicubic_grad_interpolation_highbd_c;
+    bicubic_grad_interp_highbd test_func = GetParam().TestFunction();
+    if (is_speed)
+      BicubicGradHighbdSpeed(ref_func, test_func, pred_src, x_grad_ref,
+                             y_grad_ref, x_grad_test, y_grad_test, bw, bh);
+    else
+      BicubicGradHighbd(ref_func, test_func, pred_src, x_grad_ref, y_grad_ref,
+                        x_grad_test, y_grad_test, bw, bh);
+  }
+
+  void BicubicGradHighbd(bicubic_grad_interp_highbd ref_func,
+                         bicubic_grad_interp_highbd test_func,
+                         const int16_t *pred_src, int16_t *x_grad_ref,
+                         int16_t *y_grad_ref, int16_t *x_grad_test,
+                         int16_t *y_grad_test, const int bw, const int bh) {
+    ref_func(pred_src, x_grad_ref, y_grad_ref, bw, bh);
+    test_func(pred_src, x_grad_test, y_grad_test, bw, bh);
+
+    AssertOutputBufferEq(x_grad_ref, x_grad_test, bw, bh);
+    AssertOutputBufferEq(y_grad_ref, y_grad_test, bw, bh);
+  }
+
+  void BicubicGradHighbdSpeed(bicubic_grad_interp_highbd ref_func,
+                              bicubic_grad_interp_highbd test_func,
+                              int16_t *pred_src, int16_t *x_grad_ref,
+                              int16_t *y_grad_ref, int16_t *x_grad_test,
+                              int16_t *y_grad_test, const int bw,
+                              const int bh) {
+    const int bw_log2 = bw >> MI_SIZE_LOG2;
+    const int bh_log2 = bh >> MI_SIZE_LOG2;
+
+    const int numIter = 2097152 / (bw_log2 * bh_log2);
+    aom_usec_timer timer_ref;
+    aom_usec_timer timer_test;
+
+    aom_usec_timer_start(&timer_ref);
+    for (int count = 0; count < numIter; count++)
+      ref_func(pred_src, x_grad_ref, y_grad_ref, bw, bh);
+    aom_usec_timer_mark(&timer_ref);
+
+    aom_usec_timer_start(&timer_test);
+    for (int count = 0; count < numIter; count++)
+      test_func(pred_src, x_grad_test, y_grad_test, bw, bh);
+    aom_usec_timer_mark(&timer_test);
+
+    const int total_time_ref =
+        static_cast<int>(aom_usec_timer_elapsed(&timer_ref));
+    const int total_time_test =
+        static_cast<int>(aom_usec_timer_elapsed(&timer_test));
+
+    printf("ref_time = %d \t simd_time = %d \t Gain = %4.2f \n", total_time_ref,
+           total_time_test,
+           (static_cast<float>(total_time_ref) /
+            static_cast<float>(total_time_test)));
+  }
+
+  int16_t *pred_src_;
+  int16_t *x_grad_ref_;
+  int16_t *y_grad_ref_;
+  int16_t *x_grad_test_;
+  int16_t *y_grad_test_;
+};
+TEST_P(AV1OptFlowBiCubicGradHighbdTest, CheckOutput) { Run(0); }
+TEST_P(AV1OptFlowBiCubicGradHighbdTest, DISABLED_Speed) { Run(1); }
+
+INSTANTIATE_TEST_SUITE_P(
+    C, AV1OptFlowBiCubicGradHighbdTest,
+    BuildOptFlowHighbdParams(av1_bicubic_grad_interpolation_highbd_c));
+
+#if HAVE_SSE4_1
+INSTANTIATE_TEST_SUITE_P(
+    SSE4_1, AV1OptFlowBiCubicGradHighbdTest,
+    BuildOptFlowHighbdParams(av1_bicubic_grad_interpolation_highbd_sse4_1));
+#endif
+#endif  // OPFL_BICUBIC_GRAD
+
+#if OPFL_COMBINE_INTERP_GRAD_LS
+typedef int (*opfl_mv_refinement_interp_grad)(
+    const int16_t *pdiff, int pstride, const int16_t *gx, const int16_t *gy,
+    int gstride, int bw, int bh, int n, int d0, int d1, int grad_prec_bits,
+    int mv_prec_bits, int *vx0, int *vy0, int *vx1, int *vy1);
+
+class AV1OptFlowRefineInterpGradTest
+    : public AV1OptFlowTest<opfl_mv_refinement_interp_grad> {
+ public:
+  AV1OptFlowRefineInterpGradTest() {
+    const BlockSize &block = GetParam().Block();
+    const int bw = block.Width();
+    const int bh = block.Height();
+
+    input_ = (int16_t *)aom_memalign(16, bw * bh * sizeof(*input_));
+    gx_ = (int16_t *)aom_memalign(16, bw * bh * sizeof(*gx_));
+    gy_ = (int16_t *)aom_memalign(16, bw * bh * sizeof(*gy_));
+  }
+
+  ~AV1OptFlowRefineInterpGradTest() {
+    aom_free(input_);
+    aom_free(gx_);
+    aom_free(gy_);
+  }
+
+  void RunTest(const int is_speed) {
+    OrderHintInfo oh_info;
+    const BlockSize &block = GetParam().Block();
+    const int bd = GetParam().BitDepth();
+    const int bw_log2 = block.Width() >> MI_SIZE_LOG2;
+    const int bh_log2 = block.Height() >> MI_SIZE_LOG2;
+    const int numIter = is_speed ? 1 : 16384 / (bw_log2 * bh_log2);
+    const int oh_start_bits = is_speed ? kMaxOrderHintBits : 1;
+
+    oh_info.enable_order_hint = 1;
+    for (int oh_bits = oh_start_bits; oh_bits <= kMaxOrderHintBits; oh_bits++) {
+      for (int count = 0; count < numIter;) {
+        const int cur_frm_idx = RandomFrameIdx(oh_bits);
+        const int ref0_frm_idx = RandomFrameIdx(oh_bits);
+        const int ref1_frm_idx = RandomFrameIdx(oh_bits);
+
+        oh_info.order_hint_bits_minus_1 = oh_bits - 1;
+        const int d0 = get_relative_dist(&oh_info, cur_frm_idx, ref0_frm_idx);
+        const int d1 = get_relative_dist(&oh_info, cur_frm_idx, ref1_frm_idx);
+        if (!d0 || !d1) continue;
+
+        RandomInput16(input_, GetParam(), bd);
+        RandomInput16(gx_, GetParam(), bd + 1);
+        RandomInput16(gy_, GetParam(), bd + 1);
+
+        TestOptFlowRefine(input_, gx_, gy_, is_speed, d0, d1);
+        count++;
+      }
+    }
+    if (is_speed) return;
+
+    // Extreme value test
+    for (int oh_bits = oh_start_bits; oh_bits <= kMaxOrderHintBits;
+         oh_bits += kMaxOrderHintBits - 1) {
+      for (int count = 0; count < numIter;) {
+        const int d0 = RelativeDistExtreme(oh_bits);
+        const int d1 = RelativeDistExtreme(oh_bits);
+        if (!d0 || !d1) continue;
+
+        RandomInput16Extreme(input_, GetParam(), bd);
+        RandomInput16Extreme(gx_, GetParam(), bd + 1);
+        RandomInput16Extreme(gy_, GetParam(), bd + 1);
+
+        TestOptFlowRefine(input_, gx_, gy_, 0, d0, d1);
+        count++;
+      }
+    }
+  }
+
+ private:
+  void TestOptFlowRefine(int16_t *input, int16_t *gx, int16_t *gy,
+                         const int is_speed, int d0, int d1) {
+    const BlockSize &block = GetParam().Block();
+    const int bw = block.Width();
+    const int bh = block.Height();
+    const int n = block.OptFlowBlkSize();
+
+    opfl_mv_refinement_interp_grad ref_func =
+        av1_opfl_mv_refinement_nxn_interp_grad_c;
+    opfl_mv_refinement_interp_grad test_func = GetParam().TestFunction();
+
+    if (is_speed)
+      OptFlowRefineSpeed(ref_func, test_func, input, gx, gy, bw, bh, n, d0, d1);
+    else
+      OptFlowRefine(ref_func, test_func, input, gx, gy, bw, bh, n, d0, d1);
+  }
+
+  void OptFlowRefine(opfl_mv_refinement_interp_grad ref_func,
+                     opfl_mv_refinement_interp_grad test_func,
+                     const int16_t *input, const int16_t *gx, const int16_t *gy,
+                     int bw, int bh, int n, int d0, int d1) {
+    int ref_out[4 * N_OF_OFFSETS] = { 0 };
+    int test_out[4 * N_OF_OFFSETS] = { 0 };
+    const int grad_prec_bits = 3 - kSubpelGradDeltaBits - 2;
+    const int mv_prec_bits = MV_REFINE_PREC_BITS;
+    int stride = bw;
+    int gstride = bw;
+
+    int n_blocks_ref =
+        ref_func(input, stride, gx, gy, gstride, bw, bh, n, d0, d1,
+                 grad_prec_bits, mv_prec_bits, &ref_out[kVX_0 * N_OF_OFFSETS],
+                 &ref_out[kVY_0 * N_OF_OFFSETS], &ref_out[kVX_1 * N_OF_OFFSETS],
+                 &ref_out[kVY_1 * N_OF_OFFSETS]);
+    int n_blocks = test_func(
+        input, stride, gx, gy, gstride, bw, bh, n, d0, d1, grad_prec_bits,
+        mv_prec_bits, &test_out[kVX_0 * N_OF_OFFSETS],
+        &test_out[kVY_0 * N_OF_OFFSETS], &test_out[kVX_1 * N_OF_OFFSETS],
+        &test_out[kVY_1 * N_OF_OFFSETS]);
+
+    ASSERT_EQ(n_blocks_ref, n_blocks) << "Mismatch of subblock numbers";
+    AssertOutputEq(&ref_out[kVX_0 * N_OF_OFFSETS],
+                   &test_out[kVX_0 * N_OF_OFFSETS], n_blocks);
+    AssertOutputEq(&ref_out[kVY_0 * N_OF_OFFSETS],
+                   &test_out[kVY_0 * N_OF_OFFSETS], n_blocks);
+    AssertOutputEq(&ref_out[kVX_1 * N_OF_OFFSETS],
+                   &test_out[kVX_1 * N_OF_OFFSETS], n_blocks);
+    AssertOutputEq(&ref_out[kVY_1 * N_OF_OFFSETS],
+                   &test_out[kVY_1 * N_OF_OFFSETS], n_blocks);
+  }
+
+  void OptFlowRefineSpeed(opfl_mv_refinement_interp_grad ref_func,
+                          opfl_mv_refinement_interp_grad test_func,
+                          const int16_t *input, const int16_t *gx,
+                          const int16_t *gy, int bw, int bh, int n, int d0,
+                          int d1) {
+    int ref_out[4 * N_OF_OFFSETS] = { 0 };
+    int test_out[4 * N_OF_OFFSETS] = { 0 };
+    const int grad_prec_bits = 3 - kSubpelGradDeltaBits - 2;
+    const int mv_prec_bits = MV_REFINE_PREC_BITS;
+    const int bw_log2 = bw >> MI_SIZE_LOG2;
+    const int bh_log2 = bh >> MI_SIZE_LOG2;
+    int stride = bw;
+    int gstride = bw;
+
+    const int numIter = 2097152 / (bw_log2 * bh_log2);
+    aom_usec_timer timer_ref;
+    aom_usec_timer timer_test;
+
+    aom_usec_timer_start(&timer_ref);
+    for (int count = 0; count < numIter; count++) {
+      ref_func(input, stride, gx, gy, gstride, bw, bh, n, d0, d1,
+               grad_prec_bits, mv_prec_bits, &ref_out[kVX_0 * N_OF_OFFSETS],
+               &ref_out[kVY_0 * N_OF_OFFSETS], &ref_out[kVX_1 * N_OF_OFFSETS],
+               &ref_out[kVY_1 * N_OF_OFFSETS]);
+    }
+    aom_usec_timer_mark(&timer_ref);
+
+    aom_usec_timer_start(&timer_test);
+    for (int count = 0; count < numIter; count++) {
+      test_func(input, stride, gx, gy, gstride, bw, bh, n, d0, d1,
+                grad_prec_bits, mv_prec_bits, &test_out[kVX_0 * N_OF_OFFSETS],
+                &test_out[kVY_0 * N_OF_OFFSETS],
+                &test_out[kVX_1 * N_OF_OFFSETS],
+                &test_out[kVY_1 * N_OF_OFFSETS]);
+    }
+    aom_usec_timer_mark(&timer_test);
+
+    const int total_time_ref =
+        static_cast<int>(aom_usec_timer_elapsed(&timer_ref));
+    const int total_time_test =
+        static_cast<int>(aom_usec_timer_elapsed(&timer_test));
+
+    printf("ref_time = %d \t simd_time = %d \t Gain = %4.2f \n", total_time_ref,
+           total_time_test,
+           (static_cast<float>(total_time_ref) /
+            static_cast<float>(total_time_test)));
+  }
+
+  static constexpr int kVX_0 = 0;
+  static constexpr int kVX_1 = 1;
+  static constexpr int kVY_0 = 2;
+  static constexpr int kVY_1 = 3;
+  static constexpr int kMaxOrderHintBits = 8;
+  static constexpr int kSubpelGradDeltaBits = 3;
+  int16_t *input_;
+  int16_t *gx_;
+  int16_t *gy_;
+};
+TEST_P(AV1OptFlowRefineInterpGradTest, CheckOutput) { RunTest(0); }
+TEST_P(AV1OptFlowRefineInterpGradTest, DISABLED_Speed) { RunTest(1); }
+
+INSTANTIATE_TEST_SUITE_P(
+    C, AV1OptFlowRefineInterpGradTest,
+    BuildOptFlowHighbdParams(av1_opfl_mv_refinement_nxn_interp_grad_c));
+
+#if HAVE_SSE4_1
+INSTANTIATE_TEST_SUITE_P(
+    SSE4_1, AV1OptFlowRefineInterpGradTest,
+    BuildOptFlowHighbdParams(av1_opfl_mv_refinement_nxn_interp_grad_sse4_1));
+#endif
+#endif  // OPFL_COMBINE_INTERP_GRAD_LS
+
+#if OPFL_BILINEAR_GRAD || OPFL_BICUBIC_GRAD
+typedef void (*pred_buffer_copy)(const uint8_t *src1, const uint8_t *src2,
+                                 int16_t *dst1, int16_t *dst2, int bw, int bh,
+                                 int d0, int d1);
+
+class AV1OptFlowCopyPredTest : public AV1OptFlowTest<pred_buffer_copy> {
+ public:
+  AV1OptFlowCopyPredTest() {
+    const BlockSize &block = GetParam().Block();
+    const int bw = block.Width();
+    const int bh = block.Height();
+
+    src_buf1_ = (uint8_t *)aom_memalign(16, bw * bh * sizeof(*src_buf1_));
+    src_buf2_ = (uint8_t *)aom_memalign(16, bw * bh * sizeof(*src_buf2_));
+    dst_buf1_ref_ =
+        (int16_t *)aom_memalign(16, bw * bh * sizeof(*dst_buf1_ref_));
+    dst_buf2_ref_ =
+        (int16_t *)aom_memalign(16, bw * bh * sizeof(*dst_buf2_ref_));
+    dst_buf1_test_ =
+        (int16_t *)aom_memalign(16, bw * bh * sizeof(*dst_buf1_test_));
+    dst_buf2_test_ =
+        (int16_t *)aom_memalign(16, bw * bh * sizeof(*dst_buf2_test_));
+
+    memset(dst_buf2_ref_, 0, bw * bh * sizeof(*dst_buf2_ref_));
+    memset(dst_buf2_test_, 0, bw * bh * sizeof(*dst_buf2_test_));
+  }
+
+  ~AV1OptFlowCopyPredTest() {
+    aom_free(src_buf1_);
+    aom_free(src_buf2_);
+    aom_free(dst_buf1_ref_);
+    aom_free(dst_buf2_ref_);
+    aom_free(dst_buf1_test_);
+    aom_free(dst_buf2_test_);
+  }
+
+  void Run(const int is_speed) {
+    OrderHintInfo oh_info;
+    const BlockSize &block = GetParam().Block();
+    const int bw_log2 = block.Width() >> MI_SIZE_LOG2;
+    const int bh_log2 = block.Height() >> MI_SIZE_LOG2;
+    const int numIter = is_speed ? 1 : 16384 / (bw_log2 * bh_log2);
+    const int oh_start_bits = is_speed ? kMaxOrderHintBits : 1;
+
+    oh_info.enable_order_hint = 1;
+    for (int oh_bits = oh_start_bits; oh_bits <= kMaxOrderHintBits; oh_bits++) {
+      for (int count = 0; count < numIter;) {
+        const int cur_frm_idx = RandomFrameIdx(oh_bits);
+        const int ref0_frm_idx = RandomFrameIdx(oh_bits);
+        const int ref1_frm_idx = RandomFrameIdx(oh_bits);
+
+        oh_info.order_hint_bits_minus_1 = oh_bits - 1;
+        const int d0 = get_relative_dist(&oh_info, cur_frm_idx, ref0_frm_idx);
+        const int d1 = get_relative_dist(&oh_info, cur_frm_idx, ref1_frm_idx);
+        if (!d0 || !d1) continue;
+
+        RandomInput8(src_buf1_, GetParam());
+        RandomInput8(src_buf2_, GetParam());
+        TestCopyPredArray(src_buf1_, src_buf2_, dst_buf1_ref_, dst_buf2_ref_,
+                          dst_buf1_test_, dst_buf2_test_, d0, d1, is_speed);
+        count++;
+      }
+    }
+    if (is_speed) return;
+
+    // Extreme value test
+    for (int oh_bits = oh_start_bits; oh_bits <= kMaxOrderHintBits;
+         oh_bits += kMaxOrderHintBits - 1) {
+      for (int count = 0; count < numIter;) {
+        const int d0 = RelativeDistExtreme(oh_bits);
+        const int d1 = RelativeDistExtreme(oh_bits);
+        if (!d0 || !d1) continue;
+
+        RandomInput8Extreme(src_buf1_, GetParam());
+        RandomInput8Extreme(src_buf2_, GetParam());
+        TestCopyPredArray(src_buf1_, src_buf2_, dst_buf1_ref_, dst_buf2_ref_,
+                          dst_buf1_test_, dst_buf2_test_, d0, d1, 0);
+        count++;
+      }
+    }
+  }
+
+ private:
+  void TestCopyPredArray(uint8_t *src_buf1, uint8_t *src_buf2,
+                         int16_t *dst_buf1_ref, int16_t *dst_buf2_ref,
+                         int16_t *dst_buf1_test, int16_t *dst_buf2_test, int d0,
+                         int d1, int is_speed) {
+    const BlockSize &block = GetParam().Block();
+    const int bw = block.Width();
+    const int bh = block.Height();
+
+    pred_buffer_copy ref_func = av1_copy_pred_array_c;
+    pred_buffer_copy test_func = GetParam().TestFunction();
+    if (is_speed)
+      CopyPredArraySpeed(ref_func, test_func, src_buf1, src_buf2, dst_buf1_ref,
+                         dst_buf2_ref, dst_buf1_test, dst_buf2_test, d0, d1, bw,
+                         bh);
+    else
+      CopyPredArray(ref_func, test_func, src_buf1, src_buf2, dst_buf1_ref,
+                    dst_buf2_ref, dst_buf1_test, dst_buf2_test, d0, d1, bw, bh);
+  }
+
+  void CopyPredArray(pred_buffer_copy ref_func, pred_buffer_copy test_func,
+                     const uint8_t *src_buf1, uint8_t *src_buf2,
+                     int16_t *dst_buf1_ref, int16_t *dst_buf2_ref,
+                     int16_t *dst_buf1_test, int16_t *dst_buf2_test,
+                     const int d0, const int d1, const int bw, const int bh) {
+    ref_func(src_buf1, src_buf2, dst_buf1_ref, dst_buf2_ref, bw, bh, d0, d1);
+    test_func(src_buf1, src_buf2, dst_buf1_test, dst_buf2_test, bw, bh, d0, d1);
+
+    AssertOutputBufferEq(dst_buf1_ref, dst_buf1_test, bw, bh);
+    AssertOutputBufferEq(dst_buf2_ref, dst_buf2_test, bw, bh);
+  }
+
+  void CopyPredArraySpeed(pred_buffer_copy ref_func, pred_buffer_copy test_func,
+                          const uint8_t *src_buf1, uint8_t *src_buf2,
+                          int16_t *dst_buf1_ref, int16_t *dst_buf2_ref,
+                          int16_t *dst_buf1_test, int16_t *dst_buf2_test,
+                          const int d0, const int d1, const int bw,
+                          const int bh) {
+    const int bw_log2 = bw >> MI_SIZE_LOG2;
+    const int bh_log2 = bh >> MI_SIZE_LOG2;
+    printf("bw=%d, bh=%d\n", bw, bh);
+    const int numIter = 2097152 / (bw_log2 * bh_log2);
+    aom_usec_timer timer_ref;
+    aom_usec_timer timer_test;
+
+    aom_usec_timer_start(&timer_ref);
+    for (int count = 0; count < numIter; count++)
+      ref_func(src_buf1, src_buf2, dst_buf1_ref, dst_buf2_ref, bw, bh, d0, d1);
+    aom_usec_timer_mark(&timer_ref);
+
+    aom_usec_timer_start(&timer_test);
+    for (int count = 0; count < numIter; count++)
+      test_func(src_buf1, src_buf2, dst_buf1_test, dst_buf2_test, bw, bh, d0,
+                d1);
+    aom_usec_timer_mark(&timer_test);
+
+    const int total_time_ref =
+        static_cast<int>(aom_usec_timer_elapsed(&timer_ref));
+    const int total_time_test =
+        static_cast<int>(aom_usec_timer_elapsed(&timer_test));
+
+    printf("ref_time = %d \t simd_time = %d \t Gain = %4.2f \n", total_time_ref,
+           total_time_test,
+           (static_cast<float>(total_time_ref) /
+            static_cast<float>(total_time_test)));
+  }
+
+  uint8_t *src_buf1_;
+  uint8_t *src_buf2_;
+  int16_t *dst_buf1_ref_;
+  int16_t *dst_buf2_ref_;
+  int16_t *dst_buf1_test_;
+  int16_t *dst_buf2_test_;
+  static constexpr int kMaxOrderHintBits = 8;
+};
+
+TEST_P(AV1OptFlowCopyPredTest, CheckOutput) { Run(0); }
+TEST_P(AV1OptFlowCopyPredTest, DISABLED_Speed) { Run(1); }
+
+INSTANTIATE_TEST_SUITE_P(C, AV1OptFlowCopyPredTest,
+                         BuildOptFlowParams(av1_copy_pred_array_c));
+
+#if HAVE_SSE4_1
+INSTANTIATE_TEST_SUITE_P(SSE4_1, AV1OptFlowCopyPredTest,
+                         BuildOptFlowParams(av1_copy_pred_array_sse4_1));
+#endif
+
+typedef void (*pred_buffer_copy_highbd)(const uint16_t *src1,
+                                        const uint16_t *src2, int16_t *dst1,
+                                        int16_t *dst2, int bw, int bh, int d0,
+                                        int d1);
+
+class AV1OptFlowCopyPredHighbdTest
+    : public AV1OptFlowTest<pred_buffer_copy_highbd> {
+ public:
+  AV1OptFlowCopyPredHighbdTest() {
+    const BlockSize &block = GetParam().Block();
+    const int bw = block.Width();
+    const int bh = block.Height();
+
+    src_buf1_ = (uint16_t *)aom_memalign(16, bw * bh * sizeof(*src_buf1_));
+    src_buf2_ = (uint16_t *)aom_memalign(16, bw * bh * sizeof(*src_buf2_));
+    dst_buf1_ref_ =
+        (int16_t *)aom_memalign(16, bw * bh * sizeof(*dst_buf1_ref_));
+    dst_buf2_ref_ =
+        (int16_t *)aom_memalign(16, bw * bh * sizeof(*dst_buf2_ref_));
+    dst_buf1_test_ =
+        (int16_t *)aom_memalign(16, bw * bh * sizeof(*dst_buf1_test_));
+    dst_buf2_test_ =
+        (int16_t *)aom_memalign(16, bw * bh * sizeof(*dst_buf2_test_));
+
+    memset(dst_buf2_ref_, 0, bw * bh * sizeof(*dst_buf2_ref_));
+    memset(dst_buf2_test_, 0, bw * bh * sizeof(*dst_buf2_test_));
+  }
+
+  ~AV1OptFlowCopyPredHighbdTest() {
+    aom_free(src_buf1_);
+    aom_free(src_buf2_);
+    aom_free(dst_buf1_ref_);
+    aom_free(dst_buf2_ref_);
+    aom_free(dst_buf1_test_);
+    aom_free(dst_buf2_test_);
+  }
+
+  void Run(const int is_speed) {
+    OrderHintInfo oh_info;
+    const BlockSize &block = GetParam().Block();
+    const int bw_log2 = block.Width() >> MI_SIZE_LOG2;
+    const int bh_log2 = block.Height() >> MI_SIZE_LOG2;
+    const int bd = GetParam().BitDepth();
+    const int numIter = is_speed ? 1 : 16384 / (bw_log2 * bh_log2);
+    const int oh_start_bits = is_speed ? kMaxOrderHintBits : 1;
+
+    oh_info.enable_order_hint = 1;
+    for (int oh_bits = oh_start_bits; oh_bits <= kMaxOrderHintBits; oh_bits++) {
+      for (int count = 0; count < numIter;) {
+        const int cur_frm_idx = RandomFrameIdx(oh_bits);
+        const int ref0_frm_idx = RandomFrameIdx(oh_bits);
+        const int ref1_frm_idx = RandomFrameIdx(oh_bits);
+
+        oh_info.order_hint_bits_minus_1 = oh_bits - 1;
+        const int d0 = get_relative_dist(&oh_info, cur_frm_idx, ref0_frm_idx);
+        const int d1 = get_relative_dist(&oh_info, cur_frm_idx, ref1_frm_idx);
+        if (!d0 || !d1) continue;
+
+        RandomInput16(src_buf1_, GetParam(), bd);
+        RandomInput16(src_buf2_, GetParam(), bd);
+        TestCopyPredArray(src_buf1_, src_buf2_, dst_buf1_ref_, dst_buf2_ref_,
+                          dst_buf1_test_, dst_buf2_test_, d0, d1, is_speed);
+        count++;
+      }
+    }
+    if (is_speed) return;
+
+    // Extreme value test
+    for (int oh_bits = oh_start_bits; oh_bits <= kMaxOrderHintBits;
+         oh_bits += kMaxOrderHintBits - 1) {
+      for (int count = 0; count < numIter;) {
+        const int d0 = RelativeDistExtreme(oh_bits);
+        const int d1 = RelativeDistExtreme(oh_bits);
+        if (!d0 || !d1) continue;
+
+        RandomInput16Extreme(src_buf1_, GetParam(), bd);
+        RandomInput16Extreme(src_buf2_, GetParam(), bd);
+        TestCopyPredArray(src_buf1_, src_buf2_, dst_buf1_ref_, dst_buf2_ref_,
+                          dst_buf1_test_, dst_buf2_test_, d0, d1, 0);
+        count++;
+      }
+    }
+  }
+
+ private:
+  void TestCopyPredArray(uint16_t *src_buf1, uint16_t *src_buf2,
+                         int16_t *dst_buf1_ref, int16_t *dst_buf2_ref,
+                         int16_t *dst_buf1_test, int16_t *dst_buf2_test, int d0,
+                         int d1, int is_speed) {
+    const BlockSize &block = GetParam().Block();
+    const int bw = block.Width();
+    const int bh = block.Height();
+
+    pred_buffer_copy_highbd ref_func = av1_copy_pred_array_highbd_c;
+    pred_buffer_copy_highbd test_func = GetParam().TestFunction();
+    if (is_speed)
+      CopyPredArraySpeed(ref_func, test_func, src_buf1, src_buf2, dst_buf1_ref,
+                         dst_buf2_ref, dst_buf1_test, dst_buf2_test, d0, d1, bw,
+                         bh);
+    else
+      CopyPredArray(ref_func, test_func, src_buf1, src_buf2, dst_buf1_ref,
+                    dst_buf2_ref, dst_buf1_test, dst_buf2_test, d0, d1, bw, bh);
+  }
+
+  void CopyPredArray(pred_buffer_copy_highbd ref_func,
+                     pred_buffer_copy_highbd test_func,
+                     const uint16_t *src_buf1, uint16_t *src_buf2,
+                     int16_t *dst_buf1_ref, int16_t *dst_buf2_ref,
+                     int16_t *dst_buf1_test, int16_t *dst_buf2_test,
+                     const int d0, const int d1, const int bw, const int bh) {
+    ref_func(src_buf1, src_buf2, dst_buf1_ref, dst_buf2_ref, bw, bh, d0, d1);
+    test_func(src_buf1, src_buf2, dst_buf1_test, dst_buf2_test, bw, bh, d0, d1);
+
+    AssertOutputBufferEq(dst_buf1_ref, dst_buf1_test, bw, bh);
+    AssertOutputBufferEq(dst_buf2_ref, dst_buf2_test, bw, bh);
+  }
+
+  void CopyPredArraySpeed(pred_buffer_copy_highbd ref_func,
+                          pred_buffer_copy_highbd test_func,
+                          const uint16_t *src_buf1, uint16_t *src_buf2,
+                          int16_t *dst_buf1_ref, int16_t *dst_buf2_ref,
+                          int16_t *dst_buf1_test, int16_t *dst_buf2_test,
+                          const int d0, const int d1, const int bw,
+                          const int bh) {
+    const int bw_log2 = bw >> MI_SIZE_LOG2;
+    const int bh_log2 = bh >> MI_SIZE_LOG2;
+    printf("bw=%d, bh=%d\n", bw, bh);
+    const int numIter = 2097152 / (bw_log2 * bh_log2);
+    aom_usec_timer timer_ref;
+    aom_usec_timer timer_test;
+
+    aom_usec_timer_start(&timer_ref);
+    for (int count = 0; count < numIter; count++)
+      ref_func(src_buf1, src_buf2, dst_buf1_ref, dst_buf2_ref, bw, bh, d0, d1);
+    aom_usec_timer_mark(&timer_ref);
+
+    aom_usec_timer_start(&timer_test);
+    for (int count = 0; count < numIter; count++)
+      test_func(src_buf1, src_buf2, dst_buf1_test, dst_buf2_test, bw, bh, d0,
+                d1);
+    aom_usec_timer_mark(&timer_test);
+
+    const int total_time_ref =
+        static_cast<int>(aom_usec_timer_elapsed(&timer_ref));
+    const int total_time_test =
+        static_cast<int>(aom_usec_timer_elapsed(&timer_test));
+
+    printf("ref_time = %d \t simd_time = %d \t Gain = %4.2f \n", total_time_ref,
+           total_time_test,
+           (static_cast<float>(total_time_ref) /
+            static_cast<float>(total_time_test)));
+  }
+
+  uint16_t *src_buf1_;
+  uint16_t *src_buf2_;
+  int16_t *dst_buf1_ref_;
+  int16_t *dst_buf2_ref_;
+  int16_t *dst_buf1_test_;
+  int16_t *dst_buf2_test_;
+  static constexpr int kMaxOrderHintBits = 8;
+};
+
+TEST_P(AV1OptFlowCopyPredHighbdTest, CheckOutput) { Run(0); }
+TEST_P(AV1OptFlowCopyPredHighbdTest, DISABLED_Speed) { Run(1); }
+
+INSTANTIATE_TEST_SUITE_P(
+    C, AV1OptFlowCopyPredHighbdTest,
+    BuildOptFlowHighbdParams(av1_copy_pred_array_highbd_c));
+
+#if HAVE_SSE4_1
+INSTANTIATE_TEST_SUITE_P(
+    SSE4_1, AV1OptFlowCopyPredHighbdTest,
+    BuildOptFlowHighbdParams(av1_copy_pred_array_highbd_sse4_1));
+#endif
+#endif  // OPFL_BILINEAR_GRAD || OPFL_BICUBIC_GRAD
+}  // namespace
+
+#endif  // CONFIG_OPTFLOW_REFINEMENT
diff --git a/test/pickrst_test.cc b/test/pickrst_test.cc
index 9c9d74e..ce50e89 100644
--- a/test/pickrst_test.cc
+++ b/test/pickrst_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <tuple>
diff --git a/test/quant_test.cc b/test/quant_test.cc
index 15be875..9eeb257 100644
--- a/test/quant_test.cc
+++ b/test/quant_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #include "config/aom_config.h"
 
diff --git a/test/quantize_func_test.cc b/test/quantize_func_test.cc
index 9618958..585fd61 100644
--- a/test/quantize_func_test.cc
+++ b/test/quantize_func_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <tuple>
diff --git a/test/reconinter_test.cc b/test/reconinter_test.cc
index 7e440c9..59c0a9c 100644
--- a/test/reconinter_test.cc
+++ b/test/reconinter_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <stdint.h>
diff --git a/test/register_state_check.h b/test/register_state_check.h
index d404621..98fbb06 100644
--- a/test/register_state_check.h
+++ b/test/register_state_check.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_TEST_REGISTER_STATE_CHECK_H_
diff --git a/test/resize_test.cc b/test/resize_test.cc
index 0a57d31..f4fc0ee 100644
--- a/test/resize_test.cc
+++ b/test/resize_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <climits>
diff --git a/test/run_encodes.sh b/test/run_encodes.sh
index 2096d8b..a4e1851 100755
--- a/test/run_encodes.sh
+++ b/test/run_encodes.sh
@@ -1,13 +1,13 @@
 #!/bin/bash
 #
-# Copyright (c) 2016, Alliance for Open Media. All rights reserved.
+# Copyright (c) 2021, Alliance for Open Media. All rights reserved
 #
-# This source code is subject to the terms of the BSD 2 Clause License and
-# the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-# was not distributed with this source code in the LICENSE file, you can
-# obtain it at www.aomedia.org/license/software. If the Alliance for Open
-# Media Patent License 1.0 was not distributed with this source code in the
-# PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+# This source code is subject to the terms of the BSD 3-Clause Clear License and the
+# Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+# not distributed with this source code in the LICENSE file, you can obtain it
+# at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+# License 1.0 was not distributed with this source code in the PATENTS file, you
+# can obtain it at aomedia.org/license/patent-license/.
 #
 # Author: jimbankoski@google.com (Jim Bankoski)
 
diff --git a/test/sad_test.cc b/test/sad_test.cc
index 963098e..627b7ad 100644
--- a/test/sad_test.cc
+++ b/test/sad_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <string.h>
diff --git a/test/sb_multipass_test.cc b/test/sb_multipass_test.cc
index 63d601a..5c6d807 100644
--- a/test/sb_multipass_test.cc
+++ b/test/sb_multipass_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <initializer_list>
diff --git a/test/scan_test.cc b/test/scan_test.cc
index dee2ab5..558a47b 100644
--- a/test/scan_test.cc
+++ b/test/scan_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "third_party/googletest/src/googletest/include/gtest/gtest.h"
diff --git a/test/screen_content_test.cc b/test/screen_content_test.cc
index 0879c31..a6199df 100644
--- a/test/screen_content_test.cc
+++ b/test/screen_content_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #include "aom/aom_codec.h"
 #include "third_party/googletest/src/googletest/include/gtest/gtest.h"
diff --git a/test/segment_binarization_sync.cc b/test/segment_binarization_sync.cc
index bd8cf11..c00b754 100644
--- a/test/segment_binarization_sync.cc
+++ b/test/segment_binarization_sync.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "third_party/googletest/src/googletest/include/gtest/gtest.h"
diff --git a/test/selfguided_filter_test.cc b/test/selfguided_filter_test.cc
index 4aeab6e..af47dab 100644
--- a/test/selfguided_filter_test.cc
+++ b/test/selfguided_filter_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <ctime>
diff --git a/test/set_maps.sh b/test/set_maps.sh
index b79357a..05a50c8 100755
--- a/test/set_maps.sh
+++ b/test/set_maps.sh
@@ -1,12 +1,12 @@
 #!/bin/sh
-## Copyright (c) 2016, Alliance for Open Media. All rights reserved
+## Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ##
-## This source code is subject to the terms of the BSD 2 Clause License and
-## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-## was not distributed with this source code in the LICENSE file, you can
-## obtain it at www.aomedia.org/license/software. If the Alliance for Open
-## Media Patent License 1.0 was not distributed with this source code in the
-## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+## This source code is subject to the terms of the BSD 3-Clause Clear License and the
+## Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+## not distributed with this source code in the LICENSE file, you can obtain it
+## at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+## License 1.0 was not distributed with this source code in the PATENTS file, you
+## can obtain it at aomedia.org/license/patent-license/.
 ##
 ## This file tests the libaom set_maps example. To add new tests to this file,
 ## do the following:
diff --git a/test/simd_avx2_test.cc b/test/simd_avx2_test.cc
index 8a012bf..bcd0c5e 100644
--- a/test/simd_avx2_test.cc
+++ b/test/simd_avx2_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #define ARCH AVX2
diff --git a/test/simd_cmp_avx2.cc b/test/simd_cmp_avx2.cc
index cda632b..45afdd0 100644
--- a/test/simd_cmp_avx2.cc
+++ b/test/simd_cmp_avx2.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #define ARCH AVX2
diff --git a/test/simd_cmp_impl.h b/test/simd_cmp_impl.h
index d3eb336..1640336 100644
--- a/test/simd_cmp_impl.h
+++ b/test/simd_cmp_impl.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <assert.h>
diff --git a/test/simd_cmp_neon.cc b/test/simd_cmp_neon.cc
index 53c1e2a..52b809e 100644
--- a/test/simd_cmp_neon.cc
+++ b/test/simd_cmp_neon.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #if defined(__OPTIMIZE__) && __OPTIMIZE__
diff --git a/test/simd_cmp_sse2.cc b/test/simd_cmp_sse2.cc
index f7827a7..23c47e0 100644
--- a/test/simd_cmp_sse2.cc
+++ b/test/simd_cmp_sse2.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #if (defined(__OPTIMIZE__) && __OPTIMIZE__) || \
diff --git a/test/simd_cmp_sse4.cc b/test/simd_cmp_sse4.cc
index 3566764..6beab25 100644
--- a/test/simd_cmp_sse4.cc
+++ b/test/simd_cmp_sse4.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #if (defined(__OPTIMIZE__) && __OPTIMIZE__) || \
diff --git a/test/simd_cmp_ssse3.cc b/test/simd_cmp_ssse3.cc
index 57bf135..e0b8f40 100644
--- a/test/simd_cmp_ssse3.cc
+++ b/test/simd_cmp_ssse3.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #if (defined(__OPTIMIZE__) && __OPTIMIZE__) || \
diff --git a/test/simd_impl.h b/test/simd_impl.h
index 61fda00..82f6070 100644
--- a/test/simd_impl.h
+++ b/test/simd_impl.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <tuple>
diff --git a/test/simd_neon_test.cc b/test/simd_neon_test.cc
index b67b188..7367cd1 100644
--- a/test/simd_neon_test.cc
+++ b/test/simd_neon_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #if defined(__OPTIMIZE__) && __OPTIMIZE__
diff --git a/test/simd_sse2_test.cc b/test/simd_sse2_test.cc
index b37a931..cd69c83 100644
--- a/test/simd_sse2_test.cc
+++ b/test/simd_sse2_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #if (defined(__OPTIMIZE__) && __OPTIMIZE__) || \
diff --git a/test/simd_sse4_test.cc b/test/simd_sse4_test.cc
index b1c9d5c..bf9f461 100644
--- a/test/simd_sse4_test.cc
+++ b/test/simd_sse4_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #if (defined(__OPTIMIZE__) && __OPTIMIZE__) || \
diff --git a/test/simd_ssse3_test.cc b/test/simd_ssse3_test.cc
index d95c26f..d556b98 100644
--- a/test/simd_ssse3_test.cc
+++ b/test/simd_ssse3_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #if (defined(__OPTIMIZE__) && __OPTIMIZE__) || \
diff --git a/test/simple_decoder.sh b/test/simple_decoder.sh
index 9b1aea1..2dd1170 100755
--- a/test/simple_decoder.sh
+++ b/test/simple_decoder.sh
@@ -1,12 +1,12 @@
 #!/bin/sh
-## Copyright (c) 2016, Alliance for Open Media. All rights reserved
+## Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ##
-## This source code is subject to the terms of the BSD 2 Clause License and
-## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-## was not distributed with this source code in the LICENSE file, you can
-## obtain it at www.aomedia.org/license/software. If the Alliance for Open
-## Media Patent License 1.0 was not distributed with this source code in the
-## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+## This source code is subject to the terms of the BSD 3-Clause Clear License and the
+## Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+## not distributed with this source code in the LICENSE file, you can obtain it
+## at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+## License 1.0 was not distributed with this source code in the PATENTS file, you
+## can obtain it at aomedia.org/license/patent-license/.
 ##
 ## This file tests the libaom simple_decoder example code. To add new tests to
 ## this file, do the following:
diff --git a/test/simple_encoder.sh b/test/simple_encoder.sh
index dfb1a1b..c9dee2a 100755
--- a/test/simple_encoder.sh
+++ b/test/simple_encoder.sh
@@ -1,12 +1,12 @@
 #!/bin/sh
-## Copyright (c) 2016, Alliance for Open Media. All rights reserved
+## Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ##
-## This source code is subject to the terms of the BSD 2 Clause License and
-## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-## was not distributed with this source code in the LICENSE file, you can
-## obtain it at www.aomedia.org/license/software. If the Alliance for Open
-## Media Patent License 1.0 was not distributed with this source code in the
-## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+## This source code is subject to the terms of the BSD 3-Clause Clear License and the
+## Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+## not distributed with this source code in the LICENSE file, you can obtain it
+## at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+## License 1.0 was not distributed with this source code in the PATENTS file, you
+## can obtain it at aomedia.org/license/patent-license/.
 ##
 ## This file tests the libaom simple_encoder example. To add new tests to this
 ## file, do the following:
diff --git a/test/sse_sum_test.cc b/test/sse_sum_test.cc
index 3e24e89..e070f9a 100644
--- a/test/sse_sum_test.cc
+++ b/test/sse_sum_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <cmath>
diff --git a/test/still_picture_test.cc b/test/still_picture_test.cc
index 9d9b6ee..f78dc86 100644
--- a/test/still_picture_test.cc
+++ b/test/still_picture_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "third_party/googletest/src/googletest/include/gtest/gtest.h"
diff --git a/test/stream_iter_test.cc b/test/stream_iter_test.cc
index f7376ac..179c4b6 100644
--- a/test/stream_iter_test.cc
+++ b/test/stream_iter_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <stdbool.h>
diff --git a/test/subgop_test.cc b/test/subgop_test.cc
index 589cade..c54caec 100644
--- a/test/subgop_test.cc
+++ b/test/subgop_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "third_party/googletest/src/googletest/include/gtest/gtest.h"
diff --git a/test/subtract_test.cc b/test/subtract_test.cc
index eea50df..be74d30 100644
--- a/test/subtract_test.cc
+++ b/test/subtract_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <tuple>
@@ -47,7 +48,7 @@
     const int block_width = block_size_wide[bsize];
     const int block_height = block_size_high[bsize];
     int16_t *diff = reinterpret_cast<int16_t *>(
-        aom_memalign(16, sizeof(*diff) * block_width * block_height * 2));
+        aom_memalign(32, sizeof(*diff) * block_width * block_height * 2));
     uint8_t *pred = reinterpret_cast<uint8_t *>(
         aom_memalign(16, block_width * block_height * 2));
     uint8_t *src = reinterpret_cast<uint8_t *>(
@@ -93,10 +94,11 @@
 INSTANTIATE_TEST_SUITE_P(C, AV1SubtractBlockTest,
                          ::testing::Values(aom_subtract_block_c));
 
-#if HAVE_SSE2
-INSTANTIATE_TEST_SUITE_P(SSE2, AV1SubtractBlockTest,
-                         ::testing::Values(aom_subtract_block_sse2));
+#if HAVE_AVX2
+INSTANTIATE_TEST_SUITE_P(AVX2, AV1SubtractBlockTest,
+                         ::testing::Values(aom_subtract_block_avx2));
 #endif
+
 #if HAVE_NEON
 INSTANTIATE_TEST_SUITE_P(NEON, AV1SubtractBlockTest,
                          ::testing::Values(aom_subtract_block_neon));
diff --git a/test/sum_squares_test.cc b/test/sum_squares_test.cc
index 30fac46..53ba944 100644
--- a/test/sum_squares_test.cc
+++ b/test/sum_squares_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <cmath>
diff --git a/test/superframe_test.cc b/test/superframe_test.cc
index b164286..469dcad 100644
--- a/test/superframe_test.cc
+++ b/test/superframe_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <climits>
diff --git a/test/temporal_filter_test.cc b/test/temporal_filter_test.cc
index 95370bd..6ed0e12 100644
--- a/test/temporal_filter_test.cc
+++ b/test/temporal_filter_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2019, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <cmath>
diff --git a/test/test.cmake b/test/test.cmake
index 244bff2..1c7cd8e 100644
--- a/test/test.cmake
+++ b/test/test.cmake
@@ -1,12 +1,12 @@
 #
-# Copyright (c) 2017, Alliance for Open Media. All rights reserved
+# Copyright (c) 2021, Alliance for Open Media. All rights reserved
 #
-# This source code is subject to the terms of the BSD 2 Clause License and the
-# Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License was
-# not distributed with this source code in the LICENSE file, you can obtain it
-# at www.aomedia.org/license/software. If the Alliance for Open Media Patent
-# License 1.0 was not distributed with this source code in the PATENTS file, you
-# can obtain it at www.aomedia.org/license/patent.
+# This source code is subject to the terms of the BSD 3-Clause Clear License and
+# the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+# License was not distributed with this source code in the LICENSE file, you can
+# obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance
+# for Open Media Patent License 1.0 was not distributed with this source code in
+# the PATENTS file, you can obtain it at aomedia.org/license/patent-license/.
 #
 if(AOM_TEST_TEST_CMAKE_)
   return()
@@ -21,224 +21,240 @@
 set(AOM_UNIT_TEST_DATA_LIST_FILE "${AOM_ROOT}/test/test-data.sha1")
 
 list(APPEND AOM_UNIT_TEST_WRAPPER_SOURCES "${AOM_GEN_SRC_DIR}/usage_exit.c"
-            "${AOM_ROOT}/test/test_libaom.cc")
+     "${AOM_ROOT}/test/test_libaom.cc")
 
-list(APPEND AOM_UNIT_TEST_COMMON_SOURCES
-            "${AOM_ROOT}/test/acm_random.h"
-            "${AOM_ROOT}/test/aom_integer_test.cc"
-            "${AOM_ROOT}/test/av1_config_test.cc"
-            "${AOM_ROOT}/test/av1_key_value_api_test.cc"
-            "${AOM_ROOT}/test/block_test.cc"
-            "${AOM_ROOT}/test/clear_system_state.h"
-            "${AOM_ROOT}/test/codec_factory.h"
-            "${AOM_ROOT}/test/decode_test_driver.cc"
-            "${AOM_ROOT}/test/decode_test_driver.h"
-            "${AOM_ROOT}/test/function_equivalence_test.h"
-            "${AOM_ROOT}/test/log2_test.cc"
-            "${AOM_ROOT}/test/md5_helper.h"
-            "${AOM_ROOT}/test/metadata_test.cc"
-            "${AOM_ROOT}/test/register_state_check.h"
-            "${AOM_ROOT}/test/test_vectors.cc"
-            "${AOM_ROOT}/test/test_vectors.h"
-            "${AOM_ROOT}/test/transform_test_base.h"
-            "${AOM_ROOT}/test/util.h"
-            "${AOM_ROOT}/test/video_source.h")
+list(
+  APPEND
+  AOM_UNIT_TEST_COMMON_SOURCES
+  "${AOM_ROOT}/test/acm_random.h"
+  "${AOM_ROOT}/test/aom_integer_test.cc"
+  "${AOM_ROOT}/test/av1_config_test.cc"
+  "${AOM_ROOT}/test/av1_key_value_api_test.cc"
+  "${AOM_ROOT}/test/block_test.cc"
+  "${AOM_ROOT}/test/clear_system_state.h"
+  "${AOM_ROOT}/test/codec_factory.h"
+  "${AOM_ROOT}/test/decode_test_driver.cc"
+  "${AOM_ROOT}/test/decode_test_driver.h"
+  "${AOM_ROOT}/test/function_equivalence_test.h"
+  "${AOM_ROOT}/test/log2_test.cc"
+  "${AOM_ROOT}/test/md5_helper.h"
+  "${AOM_ROOT}/test/metadata_test.cc"
+  "${AOM_ROOT}/test/register_state_check.h"
+  "${AOM_ROOT}/test/test_vectors.cc"
+  "${AOM_ROOT}/test/test_vectors.h"
+  "${AOM_ROOT}/test/transform_test_base.h"
+  "${AOM_ROOT}/test/util.h"
+  "${AOM_ROOT}/test/video_source.h")
 
 if(CONFIG_INTERNAL_STATS)
   list(APPEND AOM_UNIT_TEST_COMMON_SOURCES
-              "${AOM_ROOT}/test/hbd_metrics_test.cc")
+       "${AOM_ROOT}/test/hbd_metrics_test.cc")
 endif()
 
-list(APPEND AOM_UNIT_TEST_DECODER_SOURCES "${AOM_ROOT}/test/decode_api_test.cc"
-            "${AOM_ROOT}/test/external_frame_buffer_test.cc"
-            "${AOM_ROOT}/test/invalid_file_test.cc"
-            "${AOM_ROOT}/test/test_vector_test.cc"
-            "${AOM_ROOT}/test/ivf_video_source.h")
+list(
+  APPEND
+  AOM_UNIT_TEST_DECODER_SOURCES
+  "${AOM_ROOT}/test/decode_api_test.cc"
+  "${AOM_ROOT}/test/external_frame_buffer_test.cc"
+  "${AOM_ROOT}/test/invalid_file_test.cc"
+  "${AOM_ROOT}/test/test_vector_test.cc"
+  "${AOM_ROOT}/test/ivf_video_source.h")
 
-list(APPEND AOM_UNIT_TEST_ENCODER_SOURCES
-            "${AOM_ROOT}/test/aq_segment_test.cc"
-            "${AOM_ROOT}/test/borders_test.cc"
-            "${AOM_ROOT}/test/cpu_speed_test.cc"
-            "${AOM_ROOT}/test/encode_api_test.cc"
-            "${AOM_ROOT}/test/encode_small_width_height_test.cc"
-            "${AOM_ROOT}/test/encode_test_driver.cc"
-            "${AOM_ROOT}/test/encode_test_driver.h"
-            "${AOM_ROOT}/test/end_to_end_test.cc"
-            "${AOM_ROOT}/test/gf_pyr_height_test.cc"
-            "${AOM_ROOT}/test/horz_superres_test.cc"
-            "${AOM_ROOT}/test/i420_video_source.h"
-            "${AOM_ROOT}/test/level_test.cc"
-            "${AOM_ROOT}/test/monochrome_test.cc"
-            "${AOM_ROOT}/test/resize_test.cc"
-            "${AOM_ROOT}/test/y4m_test.cc"
-            "${AOM_ROOT}/test/y4m_video_source.h"
-            "${AOM_ROOT}/test/yuv_video_source.h"
-            "${AOM_ROOT}/test/time_stamp_test.cc")
+list(
+  APPEND
+  AOM_UNIT_TEST_ENCODER_SOURCES
+  "${AOM_ROOT}/test/aq_segment_test.cc"
+  "${AOM_ROOT}/test/borders_test.cc"
+  "${AOM_ROOT}/test/cpu_speed_test.cc"
+  "${AOM_ROOT}/test/encode_api_test.cc"
+  "${AOM_ROOT}/test/encode_small_width_height_test.cc"
+  "${AOM_ROOT}/test/encode_test_driver.cc"
+  "${AOM_ROOT}/test/encode_test_driver.h"
+  "${AOM_ROOT}/test/end_to_end_test.cc"
+  "${AOM_ROOT}/test/gf_pyr_height_test.cc"
+  "${AOM_ROOT}/test/horz_superres_test.cc"
+  "${AOM_ROOT}/test/i420_video_source.h"
+  "${AOM_ROOT}/test/level_test.cc"
+  "${AOM_ROOT}/test/monochrome_test.cc"
+  "${AOM_ROOT}/test/resize_test.cc"
+  "${AOM_ROOT}/test/y4m_test.cc"
+  "${AOM_ROOT}/test/y4m_video_source.h"
+  "${AOM_ROOT}/test/yuv_video_source.h"
+  "${AOM_ROOT}/test/time_stamp_test.cc")
 
 list(APPEND AOM_DECODE_PERF_TEST_SOURCES "${AOM_ROOT}/test/decode_perf_test.cc")
 list(APPEND AOM_UNIT_TEST_WEBM_SOURCES "${AOM_ROOT}/test/webm_video_source.h")
 list(APPEND AOM_TEST_INTRA_PRED_SPEED_SOURCES "${AOM_GEN_SRC_DIR}/usage_exit.c"
-            "${AOM_ROOT}/test/test_intra_pred_speed.cc")
+     "${AOM_ROOT}/test/test_intra_pred_speed.cc")
 
 if(NOT BUILD_SHARED_LIBS)
-  list(APPEND AOM_UNIT_TEST_COMMON_SOURCES
-              "${AOM_ROOT}/test/av1_common_int_test.cc"
-              "${AOM_ROOT}/test/cdef_test.cc"
-              "${AOM_ROOT}/test/cfl_test.cc"
-              "${AOM_ROOT}/test/convolve_test.cc"
-              "${AOM_ROOT}/test/hiprec_convolve_test.cc"
-              "${AOM_ROOT}/test/hiprec_convolve_test_util.cc"
-              "${AOM_ROOT}/test/hiprec_convolve_test_util.h"
-              "${AOM_ROOT}/test/intrabc_test.cc"
-              "${AOM_ROOT}/test/intrapred_test.cc"
-              "${AOM_ROOT}/test/lpf_test.cc"
-              "${AOM_ROOT}/test/scan_test.cc"
-              "${AOM_ROOT}/test/selfguided_filter_test.cc"
-              "${AOM_ROOT}/test/simd_cmp_impl.h"
-              "${AOM_ROOT}/test/simd_impl.h")
+  list(
+    APPEND
+    AOM_UNIT_TEST_COMMON_SOURCES
+    "${AOM_ROOT}/test/av1_common_int_test.cc"
+    "${AOM_ROOT}/test/cdef_test.cc"
+    "${AOM_ROOT}/test/cfl_test.cc"
+    "${AOM_ROOT}/test/convolve_test.cc"
+    "${AOM_ROOT}/test/hiprec_convolve_test.cc"
+    "${AOM_ROOT}/test/hiprec_convolve_test_util.cc"
+    "${AOM_ROOT}/test/hiprec_convolve_test_util.h"
+    "${AOM_ROOT}/test/intrabc_test.cc"
+    "${AOM_ROOT}/test/intrapred_test.cc"
+    "${AOM_ROOT}/test/lpf_test.cc"
+    "${AOM_ROOT}/test/opt_flow_test.cc"
+    "${AOM_ROOT}/test/scan_test.cc"
+    "${AOM_ROOT}/test/selfguided_filter_test.cc"
+    "${AOM_ROOT}/test/simd_cmp_impl.h"
+    "${AOM_ROOT}/test/simd_impl.h")
 
   if(CONFIG_ACCOUNTING)
     list(APPEND AOM_UNIT_TEST_COMMON_SOURCES
-                "${AOM_ROOT}/test/accounting_test.cc")
+         "${AOM_ROOT}/test/accounting_test.cc")
   endif()
 
   if(CONFIG_AV1_DECODER AND CONFIG_AV1_ENCODER)
-    list(APPEND AOM_UNIT_TEST_COMMON_SOURCES
-                "${AOM_ROOT}/test/altref_test.cc"
-                "${AOM_ROOT}/test/av1_encoder_parms_get_to_decoder.cc"
-                "${AOM_ROOT}/test/av1_ext_tile_test.cc"
-                "${AOM_ROOT}/test/binary_codes_test.cc"
-                "${AOM_ROOT}/test/boolcoder_test.cc"
-                "${AOM_ROOT}/test/cnn_test.cc"
-                "${AOM_ROOT}/test/coding_path_sync.cc"
-                "${AOM_ROOT}/test/decode_multithreaded_test.cc"
-                "${AOM_ROOT}/test/divu_small_test.cc"
-                "${AOM_ROOT}/test/dr_prediction_test.cc"
-                "${AOM_ROOT}/test/ec_test.cc"
-                "${AOM_ROOT}/test/error_resilience_test.cc"
-                "${AOM_ROOT}/test/ethread_test.cc"
-                "${AOM_ROOT}/test/film_grain_table_test.cc"
-                "${AOM_ROOT}/test/fwd_kf_test.cc"
-                "${AOM_ROOT}/test/kf_test.cc"
-                "${AOM_ROOT}/test/lossless_test.cc"
-                "${AOM_ROOT}/test/quant_test.cc"
-                "${AOM_ROOT}/test/sb_multipass_test.cc"
-                "${AOM_ROOT}/test/screen_content_test.cc"
-                "${AOM_ROOT}/test/segment_binarization_sync.cc"
-                "${AOM_ROOT}/test/still_picture_test.cc"
-                "${AOM_ROOT}/test/subgop_test.cc"
-                "${AOM_ROOT}/test/superframe_test.cc"
-                "${AOM_ROOT}/test/tile_config_test.cc"
-                "${AOM_ROOT}/test/tile_independence_test.cc"
-                "${AOM_ROOT}/test/temporal_filter_test.cc")
+    list(
+      APPEND
+      AOM_UNIT_TEST_COMMON_SOURCES
+      "${AOM_ROOT}/test/altref_test.cc"
+      "${AOM_ROOT}/test/av1_encoder_parms_get_to_decoder.cc"
+      "${AOM_ROOT}/test/av1_ext_tile_test.cc"
+      "${AOM_ROOT}/test/binary_codes_test.cc"
+      "${AOM_ROOT}/test/boolcoder_test.cc"
+      "${AOM_ROOT}/test/cnn_test.cc"
+      "${AOM_ROOT}/test/coding_path_sync.cc"
+      "${AOM_ROOT}/test/decode_multithreaded_test.cc"
+      "${AOM_ROOT}/test/divu_small_test.cc"
+      "${AOM_ROOT}/test/dr_prediction_test.cc"
+      "${AOM_ROOT}/test/ec_test.cc"
+      "${AOM_ROOT}/test/error_resilience_test.cc"
+      "${AOM_ROOT}/test/ethread_test.cc"
+      "${AOM_ROOT}/test/film_grain_table_test.cc"
+      "${AOM_ROOT}/test/fwd_kf_test.cc"
+      "${AOM_ROOT}/test/kf_test.cc"
+      "${AOM_ROOT}/test/lossless_test.cc"
+      "${AOM_ROOT}/test/quant_test.cc"
+      "${AOM_ROOT}/test/sb_multipass_test.cc"
+      "${AOM_ROOT}/test/screen_content_test.cc"
+      "${AOM_ROOT}/test/segment_binarization_sync.cc"
+      "${AOM_ROOT}/test/still_picture_test.cc"
+      "${AOM_ROOT}/test/subgop_test.cc"
+      "${AOM_ROOT}/test/superframe_test.cc"
+      "${AOM_ROOT}/test/tile_config_test.cc"
+      "${AOM_ROOT}/test/tile_independence_test.cc"
+      "${AOM_ROOT}/test/temporal_filter_test.cc")
   endif()
 
   list(APPEND AOM_UNIT_TEST_COMMON_INTRIN_NEON
-              "${AOM_ROOT}/test/simd_cmp_neon.cc")
+       "${AOM_ROOT}/test/simd_cmp_neon.cc")
   if(HAVE_NEON)
     list(APPEND AOM_UNIT_TEST_COMMON_SOURCES
-                "${AOM_ROOT}/test/simd_neon_test.cc")
+         "${AOM_ROOT}/test/simd_neon_test.cc")
   endif()
 
   list(APPEND AOM_UNIT_TEST_COMMON_INTRIN_SSE2
-              "${AOM_ROOT}/test/simd_cmp_sse2.cc")
+       "${AOM_ROOT}/test/simd_cmp_sse2.cc")
   if(HAVE_SSE2)
     list(APPEND AOM_UNIT_TEST_COMMON_SOURCES
-                "${AOM_ROOT}/test/simd_sse2_test.cc")
+         "${AOM_ROOT}/test/simd_sse2_test.cc")
   endif()
 
   list(APPEND AOM_UNIT_TEST_COMMON_INTRIN_SSSE3
-              "${AOM_ROOT}/test/simd_cmp_ssse3.cc")
+       "${AOM_ROOT}/test/simd_cmp_ssse3.cc")
   if(HAVE_SSSE3)
     list(APPEND AOM_UNIT_TEST_COMMON_SOURCES
-                "${AOM_ROOT}/test/simd_ssse3_test.cc")
+         "${AOM_ROOT}/test/simd_ssse3_test.cc")
   endif()
 
   if(HAVE_SSE4)
     list(APPEND AOM_UNIT_TEST_COMMON_SOURCES
-                "${AOM_ROOT}/test/simd_sse4_test.cc")
+         "${AOM_ROOT}/test/simd_sse4_test.cc")
   endif()
 
   if(HAVE_SSE4_1 OR HAVE_NEON)
     list(APPEND AOM_UNIT_TEST_COMMON_SOURCES
-                "${AOM_ROOT}/test/filterintra_test.cc")
+         "${AOM_ROOT}/test/filterintra_test.cc")
   endif()
 
   list(APPEND AOM_UNIT_TEST_COMMON_INTRIN_AVX2
-              "${AOM_ROOT}/test/simd_cmp_avx2.cc")
+       "${AOM_ROOT}/test/simd_cmp_avx2.cc")
   if(HAVE_AVX2)
     list(APPEND AOM_UNIT_TEST_COMMON_SOURCES
-                "${AOM_ROOT}/test/simd_avx2_test.cc")
+         "${AOM_ROOT}/test/simd_avx2_test.cc")
   endif()
 
-  list(APPEND AOM_UNIT_TEST_ENCODER_SOURCES
-              "${AOM_ROOT}/test/arf_freq_test.cc"
-              "${AOM_ROOT}/test/av1_convolve_test.cc"
-              "${AOM_ROOT}/test/av1_fwd_txfm1d_test.cc"
-              "${AOM_ROOT}/test/av1_fwd_txfm2d_test.cc"
-              "${AOM_ROOT}/test/av1_inv_txfm1d_test.cc"
-              "${AOM_ROOT}/test/av1_inv_txfm2d_test.cc"
-              "${AOM_ROOT}/test/av1_nn_predict_test.cc"
-              "${AOM_ROOT}/test/av1_round_shift_array_test.cc"
-              "${AOM_ROOT}/test/av1_txfm_test.cc"
-              "${AOM_ROOT}/test/av1_txfm_test.h"
-              "${AOM_ROOT}/test/av1_wedge_utils_test.cc"
-              "${AOM_ROOT}/test/avg_test.cc"
-              "${AOM_ROOT}/test/blend_a64_mask_1d_test.cc"
-              "${AOM_ROOT}/test/blend_a64_mask_test.cc"
-              "${AOM_ROOT}/test/comp_avg_pred_test.cc"
-              "${AOM_ROOT}/test/comp_avg_pred_test.h"
-              "${AOM_ROOT}/test/comp_mask_variance_test.cc"
-              "${AOM_ROOT}/test/edge_detect_test.cc"
-              "${AOM_ROOT}/test/encodetxb_test.cc"
-              "${AOM_ROOT}/test/error_block_test.cc"
-              "${AOM_ROOT}/test/fft_test.cc"
-              "${AOM_ROOT}/test/fwht4x4_test.cc"
-              "${AOM_ROOT}/test/fdct4x4_test.cc"
-              "${AOM_ROOT}/test/hadamard_test.cc"
-              "${AOM_ROOT}/test/horver_correlation_test.cc"
-              "${AOM_ROOT}/test/masked_sad_test.cc"
-              "${AOM_ROOT}/test/masked_variance_test.cc"
-              "${AOM_ROOT}/test/motion_vector_test.cc"
-              "${AOM_ROOT}/test/noise_model_test.cc"
-              "${AOM_ROOT}/test/obmc_sad_test.cc"
-              "${AOM_ROOT}/test/obmc_variance_test.cc"
-              "${AOM_ROOT}/test/pickrst_test.cc"
-              "${AOM_ROOT}/test/quantize_func_test.cc"
-              "${AOM_ROOT}/test/sad_test.cc"
-              "${AOM_ROOT}/test/stream_iter_test.cc"
-              "${AOM_ROOT}/test/subtract_test.cc"
-              "${AOM_ROOT}/test/reconinter_test.cc"
-              "${AOM_ROOT}/test/sum_squares_test.cc"
-              "${AOM_ROOT}/test/sse_sum_test.cc"
-              "${AOM_ROOT}/test/variance_test.cc"
-              "${AOM_ROOT}/test/wiener_test.cc"
-              "${AOM_ROOT}/test/frame_error_test.cc"
-              "${AOM_ROOT}/test/warp_filter_test.cc"
-              "${AOM_ROOT}/test/warp_filter_test_util.cc"
-              "${AOM_ROOT}/test/warp_filter_test_util.h"
-              "${AOM_ROOT}/test/webmenc_test.cc")
+  list(
+    APPEND
+    AOM_UNIT_TEST_ENCODER_SOURCES
+    "${AOM_ROOT}/test/arf_freq_test.cc"
+    "${AOM_ROOT}/test/av1_convolve_test.cc"
+    "${AOM_ROOT}/test/av1_fwd_txfm1d_test.cc"
+    "${AOM_ROOT}/test/av1_fwd_txfm2d_test.cc"
+    "${AOM_ROOT}/test/av1_inv_txfm1d_test.cc"
+    "${AOM_ROOT}/test/av1_inv_txfm2d_test.cc"
+    "${AOM_ROOT}/test/av1_nn_predict_test.cc"
+    "${AOM_ROOT}/test/av1_round_shift_array_test.cc"
+    "${AOM_ROOT}/test/av1_txfm_test.cc"
+    "${AOM_ROOT}/test/av1_txfm_test.h"
+    "${AOM_ROOT}/test/av1_wedge_utils_test.cc"
+    "${AOM_ROOT}/test/avg_test.cc"
+    "${AOM_ROOT}/test/blend_a64_mask_1d_test.cc"
+    "${AOM_ROOT}/test/blend_a64_mask_test.cc"
+    "${AOM_ROOT}/test/comp_avg_pred_test.cc"
+    "${AOM_ROOT}/test/comp_avg_pred_test.h"
+    "${AOM_ROOT}/test/comp_mask_variance_test.cc"
+    "${AOM_ROOT}/test/edge_detect_test.cc"
+    "${AOM_ROOT}/test/encodetxb_test.cc"
+    "${AOM_ROOT}/test/error_block_test.cc"
+    "${AOM_ROOT}/test/fft_test.cc"
+    "${AOM_ROOT}/test/fwht4x4_test.cc"
+    "${AOM_ROOT}/test/fdct4x4_test.cc"
+    "${AOM_ROOT}/test/hadamard_test.cc"
+    "${AOM_ROOT}/test/horver_correlation_test.cc"
+    "${AOM_ROOT}/test/masked_sad_test.cc"
+    "${AOM_ROOT}/test/masked_variance_test.cc"
+    "${AOM_ROOT}/test/motion_vector_test.cc"
+    "${AOM_ROOT}/test/noise_model_test.cc"
+    "${AOM_ROOT}/test/obmc_sad_test.cc"
+    "${AOM_ROOT}/test/obmc_variance_test.cc"
+    "${AOM_ROOT}/test/pickrst_test.cc"
+    "${AOM_ROOT}/test/quantize_func_test.cc"
+    "${AOM_ROOT}/test/sad_test.cc"
+    "${AOM_ROOT}/test/stream_iter_test.cc"
+    "${AOM_ROOT}/test/subtract_test.cc"
+    "${AOM_ROOT}/test/reconinter_test.cc"
+    "${AOM_ROOT}/test/sum_squares_test.cc"
+    "${AOM_ROOT}/test/sse_sum_test.cc"
+    "${AOM_ROOT}/test/variance_test.cc"
+    "${AOM_ROOT}/test/wiener_test.cc"
+    "${AOM_ROOT}/test/frame_error_test.cc"
+    "${AOM_ROOT}/test/warp_filter_test.cc"
+    "${AOM_ROOT}/test/warp_filter_test_util.cc"
+    "${AOM_ROOT}/test/warp_filter_test_util.h"
+    "${AOM_ROOT}/test/webmenc_test.cc")
 
   if((HAVE_SSE4_1 OR HAVE_NEON))
     list(APPEND AOM_UNIT_TEST_ENCODER_SOURCES
-                "${AOM_ROOT}/test/av1_highbd_iht_test.cc")
+         "${AOM_ROOT}/test/av1_highbd_iht_test.cc")
   endif()
 
-  list(APPEND AOM_UNIT_TEST_ENCODER_INTRIN_SSE4_1
-              "${AOM_ROOT}/test/av1_quantize_test.cc"
-              "${AOM_ROOT}/test/corner_match_test.cc"
-              "${AOM_ROOT}/test/simd_cmp_sse4.cc")
+  list(
+    APPEND AOM_UNIT_TEST_ENCODER_INTRIN_SSE4_1
+    "${AOM_ROOT}/test/av1_quantize_test.cc"
+    "${AOM_ROOT}/test/corner_match_test.cc" "${AOM_ROOT}/test/simd_cmp_sse4.cc")
 
   if(NOT (HAVE_SSE2 OR HAVE_NEON))
     list(REMOVE_ITEM AOM_UNIT_TEST_ENCODER_SOURCES
-                     "${AOM_ROOT}/test/quantize_func_test.cc")
+         "${AOM_ROOT}/test/quantize_func_test.cc")
   endif()
 
   if(HAVE_SSE4_1)
-    list(APPEND AOM_UNIT_TEST_ENCODER_SOURCES
-                "${AOM_ROOT}/test/av1_convolve_scale_test.cc"
-                "${AOM_ROOT}/test/av1_horz_only_frame_superres_test.cc"
-                "${AOM_ROOT}/test/intra_edge_test.cc")
+    list(
+      APPEND
+      AOM_UNIT_TEST_ENCODER_SOURCES
+      "${AOM_ROOT}/test/av1_convolve_scale_test.cc"
+      "${AOM_ROOT}/test/av1_horz_only_frame_superres_test.cc"
+      "${AOM_ROOT}/test/intra_edge_test.cc")
 
   endif()
 
@@ -252,9 +268,10 @@
   find_package(PythonInterp)
   if(NOT PYTHONINTERP_FOUND)
     message(
-      FATAL_ERROR "--- Unit tests require Python, rerun cmake with "
-                  "-DENABLE_TESTS=0 to avoid this error, or install Python and "
-                  "make sure it's in your PATH.")
+      FATAL_ERROR
+        "--- Unit tests require Python, rerun cmake with "
+        "-DENABLE_TESTS=0 to avoid this error, or install Python and "
+        "make sure it's in your PATH.")
   endif()
 
   if(BUILD_SHARED_LIBS AND APPLE) # Silence an RPATH warning.
@@ -299,14 +316,15 @@
     add_dependencies(test_aom_encoder aom)
   endif()
 
-  add_executable(test_libaom ${AOM_UNIT_TEST_WRAPPER_SOURCES}
-                             $<TARGET_OBJECTS:aom_common_app_util>
-                             $<TARGET_OBJECTS:test_aom_common>)
+  add_executable(
+    test_libaom
+    ${AOM_UNIT_TEST_WRAPPER_SOURCES} $<TARGET_OBJECTS:aom_common_app_util>
+    $<TARGET_OBJECTS:test_aom_common>)
   list(APPEND AOM_APP_TARGETS test_libaom)
 
   if(CONFIG_AV1_DECODER)
     target_sources(test_libaom PRIVATE $<TARGET_OBJECTS:aom_decoder_app_util>
-                   $<TARGET_OBJECTS:test_aom_decoder>)
+                                       $<TARGET_OBJECTS:test_aom_decoder>)
 
     if(ENABLE_DECODE_PERF_TESTS AND CONFIG_WEBM_IO)
       target_sources(test_libaom PRIVATE ${AOM_DECODE_PERF_TEST_SOURCES})
@@ -315,16 +333,16 @@
 
   if(CONFIG_AV1_ENCODER)
     target_sources(test_libaom PRIVATE $<TARGET_OBJECTS:test_aom_encoder>
-                   $<TARGET_OBJECTS:aom_encoder_app_util>)
+                                       $<TARGET_OBJECTS:aom_encoder_app_util>)
 
     if(ENABLE_ENCODE_PERF_TESTS)
       target_sources(test_libaom PRIVATE ${AOM_ENCODE_PERF_TEST_SOURCES})
     endif()
 
     if(NOT BUILD_SHARED_LIBS)
-      add_executable(test_intra_pred_speed
-                     ${AOM_TEST_INTRA_PRED_SPEED_SOURCES}
-                     $<TARGET_OBJECTS:aom_common_app_util>)
+      add_executable(
+        test_intra_pred_speed ${AOM_TEST_INTRA_PRED_SPEED_SOURCES}
+                              $<TARGET_OBJECTS:aom_common_app_util>)
       target_link_libraries(test_intra_pred_speed ${AOM_LIB_LINK_TYPE} aom
                             aom_gtest)
       list(APPEND AOM_APP_TARGETS test_intra_pred_speed)
@@ -378,11 +396,11 @@
       list(GET test_file_checksums ${test_index} test_file_checksum)
       add_custom_target(
         testdata_${test_index}
-        COMMAND ${CMAKE_COMMAND}
-                -DAOM_CONFIG_DIR="${AOM_CONFIG_DIR}" -DAOM_ROOT="${AOM_ROOT}"
-                -DAOM_TEST_FILE="${test_file}"
-                -DAOM_TEST_CHECKSUM=${test_file_checksum} -P
-                "${AOM_ROOT}/test/test_data_download_worker.cmake")
+        COMMAND
+          ${CMAKE_COMMAND} -DAOM_CONFIG_DIR="${AOM_CONFIG_DIR}"
+          -DAOM_ROOT="${AOM_ROOT}" -DAOM_TEST_FILE="${test_file}"
+          -DAOM_TEST_CHECKSUM=${test_file_checksum} -P
+          "${AOM_ROOT}/test/test_data_download_worker.cmake")
       list(APPEND testdata_targets testdata_${test_index})
     endforeach()
 
@@ -407,13 +425,14 @@
       math(EXPR max_shard_index "${num_test_targets} - 1")
       foreach(shard_index RANGE ${max_shard_index})
         set(test_name "test_${shard_index}")
-        add_custom_target(${test_name}
-                          COMMAND ${CMAKE_COMMAND}
-                                  -DGTEST_SHARD_INDEX=${shard_index}
-                                  -DGTEST_TOTAL_SHARDS=${num_test_targets}
-                                  -DTEST_LIBAOM=$<TARGET_FILE:test_libaom> -P
-                                  "${AOM_ROOT}/test/test_runner.cmake"
-                          DEPENDS testdata test_libaom)
+        add_custom_target(
+          ${test_name}
+          COMMAND
+            ${CMAKE_COMMAND} -DGTEST_SHARD_INDEX=${shard_index}
+            -DGTEST_TOTAL_SHARDS=${num_test_targets}
+            -DTEST_LIBAOM=$<TARGET_FILE:test_libaom> -P
+            "${AOM_ROOT}/test/test_runner.cmake"
+          DEPENDS testdata test_libaom)
         list(APPEND test_targets ${test_name})
       endforeach()
       add_custom_target(runtests)
@@ -456,5 +475,7 @@
     endforeach()
   endforeach()
 
-  set(AOM_APP_TARGETS ${AOM_APP_TARGETS} PARENT_SCOPE)
+  set(AOM_APP_TARGETS
+      ${AOM_APP_TARGETS}
+      PARENT_SCOPE)
 endfunction()
diff --git a/test/test_data_download_worker.cmake b/test/test_data_download_worker.cmake
index a490388..9615900 100644
--- a/test/test_data_download_worker.cmake
+++ b/test/test_data_download_worker.cmake
@@ -1,12 +1,12 @@
 #
-# Copyright (c) 2017, Alliance for Open Media. All rights reserved
+# Copyright (c) 2021, Alliance for Open Media. All rights reserved
 #
-# This source code is subject to the terms of the BSD 2 Clause License and the
-# Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License was
-# not distributed with this source code in the LICENSE file, you can obtain it
-# at www.aomedia.org/license/software. If the Alliance for Open Media Patent
-# License 1.0 was not distributed with this source code in the PATENTS file, you
-# can obtain it at www.aomedia.org/license/patent.
+# This source code is subject to the terms of the BSD 3-Clause Clear License and
+# the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+# License was not distributed with this source code in the LICENSE file, you can
+# obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance
+# for Open Media Patent License 1.0 was not distributed with this source code in
+# the PATENTS file, you can obtain it at aomedia.org/license/patent-license/.
 #
 include("${AOM_ROOT}/test/test_data_util.cmake")
 
diff --git a/test/test_data_util.cmake b/test/test_data_util.cmake
index 7a9da42..ca22a15 100644
--- a/test/test_data_util.cmake
+++ b/test/test_data_util.cmake
@@ -1,580 +1,589 @@
 #
-# Copyright (c) 2017, Alliance for Open Media. All rights reserved
+# Copyright (c) 2021, Alliance for Open Media. All rights reserved
 #
-# This source code is subject to the terms of the BSD 2 Clause License and the
-# Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License was
-# not distributed with this source code in the LICENSE file, you can obtain it
-# at www.aomedia.org/license/software. If the Alliance for Open Media Patent
-# License 1.0 was not distributed with this source code in the PATENTS file, you
-# can obtain it at www.aomedia.org/license/patent.
+# This source code is subject to the terms of the BSD 3-Clause Clear License and
+# the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+# License was not distributed with this source code in the LICENSE file, you can
+# obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance
+# for Open Media Patent License 1.0 was not distributed with this source code in
+# the PATENTS file, you can obtain it at aomedia.org/license/patent-license/.
 #
 
-list(APPEND AOM_TEST_DATA_FILE_NAMES
-            "desktop1.320_180.yuv"
-            "hantro_collage_w352h288.yuv"
-            "hantro_odd.yuv"
-            "paris_352_288_30.y4m"
-            "park_joy_90p_10_420.y4m"
-            "park_joy_90p_10_422.y4m"
-            "park_joy_90p_10_444.y4m"
-            "park_joy_90p_12_420.y4m"
-            "park_joy_90p_12_422.y4m"
-            "park_joy_90p_12_444.y4m"
-            "park_joy_90p_8_420_a10-1.y4m"
-            "park_joy_90p_8_420.y4m"
-            "park_joy_90p_8_420_monochrome.y4m"
-            "park_joy_90p_8_420_vertical_csp.y4m"
-            "park_joy_90p_8_422.y4m"
-            "park_joy_90p_8_444.y4m"
-            "pixel_capture_w320h240.yuv"
-            "desktop_credits.y4m"
-            "niklas_1280_720_30.y4m"
-            "rush_hour_444.y4m"
-            "screendata.y4m"
-            "niklas_640_480_30.yuv"
-            "vase10x10.yuv"
-            "vase10x10_tiles.txt")
+list(
+  APPEND
+  AOM_TEST_DATA_FILE_NAMES
+  "desktop1.320_180.yuv"
+  "hantro_collage_w352h288.yuv"
+  "hantro_odd.yuv"
+  "paris_352_288_30.y4m"
+  "park_joy_90p_10_420.y4m"
+  "park_joy_90p_10_422.y4m"
+  "park_joy_90p_10_444.y4m"
+  "park_joy_90p_12_420.y4m"
+  "park_joy_90p_12_422.y4m"
+  "park_joy_90p_12_444.y4m"
+  "park_joy_90p_8_420_a10-1.y4m"
+  "park_joy_90p_8_420.y4m"
+  "park_joy_90p_8_420_monochrome.y4m"
+  "park_joy_90p_8_420_vertical_csp.y4m"
+  "park_joy_90p_8_422.y4m"
+  "park_joy_90p_8_444.y4m"
+  "pixel_capture_w320h240.yuv"
+  "desktop_credits.y4m"
+  "niklas_1280_720_30.y4m"
+  "rush_hour_444.y4m"
+  "screendata.y4m"
+  "niklas_640_480_30.yuv"
+  "vase10x10.yuv"
+  "vase10x10_tiles.txt")
 
 if(ENABLE_DECODE_PERF_TESTS AND CONFIG_AV1_ENCODER)
   list(APPEND AOM_TEST_DATA_FILE_NAMES "niklas_1280_720_30.yuv")
 endif()
 
 if(CONFIG_AV1_DECODER)
-  list(APPEND AOM_TEST_DATA_FILE_NAMES
-              "av1-1-b8-00-quantizer-00.ivf"
-              "av1-1-b8-00-quantizer-00.ivf.md5"
-              "av1-1-b8-00-quantizer-01.ivf"
-              "av1-1-b8-00-quantizer-01.ivf.md5"
-              "av1-1-b8-00-quantizer-02.ivf"
-              "av1-1-b8-00-quantizer-02.ivf.md5"
-              "av1-1-b8-00-quantizer-03.ivf"
-              "av1-1-b8-00-quantizer-03.ivf.md5"
-              "av1-1-b8-00-quantizer-04.ivf"
-              "av1-1-b8-00-quantizer-04.ivf.md5"
-              "av1-1-b8-00-quantizer-05.ivf"
-              "av1-1-b8-00-quantizer-05.ivf.md5"
-              "av1-1-b8-00-quantizer-06.ivf"
-              "av1-1-b8-00-quantizer-06.ivf.md5"
-              "av1-1-b8-00-quantizer-07.ivf"
-              "av1-1-b8-00-quantizer-07.ivf.md5"
-              "av1-1-b8-00-quantizer-08.ivf"
-              "av1-1-b8-00-quantizer-08.ivf.md5"
-              "av1-1-b8-00-quantizer-09.ivf"
-              "av1-1-b8-00-quantizer-09.ivf.md5"
-              "av1-1-b8-00-quantizer-10.ivf"
-              "av1-1-b8-00-quantizer-10.ivf.md5"
-              "av1-1-b8-00-quantizer-11.ivf"
-              "av1-1-b8-00-quantizer-11.ivf.md5"
-              "av1-1-b8-00-quantizer-12.ivf"
-              "av1-1-b8-00-quantizer-12.ivf.md5"
-              "av1-1-b8-00-quantizer-13.ivf"
-              "av1-1-b8-00-quantizer-13.ivf.md5"
-              "av1-1-b8-00-quantizer-14.ivf"
-              "av1-1-b8-00-quantizer-14.ivf.md5"
-              "av1-1-b8-00-quantizer-15.ivf"
-              "av1-1-b8-00-quantizer-15.ivf.md5"
-              "av1-1-b8-00-quantizer-16.ivf"
-              "av1-1-b8-00-quantizer-16.ivf.md5"
-              "av1-1-b8-00-quantizer-17.ivf"
-              "av1-1-b8-00-quantizer-17.ivf.md5"
-              "av1-1-b8-00-quantizer-18.ivf"
-              "av1-1-b8-00-quantizer-18.ivf.md5"
-              "av1-1-b8-00-quantizer-19.ivf"
-              "av1-1-b8-00-quantizer-19.ivf.md5"
-              "av1-1-b8-00-quantizer-20.ivf"
-              "av1-1-b8-00-quantizer-20.ivf.md5"
-              "av1-1-b8-00-quantizer-21.ivf"
-              "av1-1-b8-00-quantizer-21.ivf.md5"
-              "av1-1-b8-00-quantizer-22.ivf"
-              "av1-1-b8-00-quantizer-22.ivf.md5"
-              "av1-1-b8-00-quantizer-23.ivf"
-              "av1-1-b8-00-quantizer-23.ivf.md5"
-              "av1-1-b8-00-quantizer-24.ivf"
-              "av1-1-b8-00-quantizer-24.ivf.md5"
-              "av1-1-b8-00-quantizer-25.ivf"
-              "av1-1-b8-00-quantizer-25.ivf.md5"
-              "av1-1-b8-00-quantizer-26.ivf"
-              "av1-1-b8-00-quantizer-26.ivf.md5"
-              "av1-1-b8-00-quantizer-27.ivf"
-              "av1-1-b8-00-quantizer-27.ivf.md5"
-              "av1-1-b8-00-quantizer-28.ivf"
-              "av1-1-b8-00-quantizer-28.ivf.md5"
-              "av1-1-b8-00-quantizer-29.ivf"
-              "av1-1-b8-00-quantizer-29.ivf.md5"
-              "av1-1-b8-00-quantizer-30.ivf"
-              "av1-1-b8-00-quantizer-30.ivf.md5"
-              "av1-1-b8-00-quantizer-31.ivf"
-              "av1-1-b8-00-quantizer-31.ivf.md5"
-              "av1-1-b8-00-quantizer-32.ivf"
-              "av1-1-b8-00-quantizer-32.ivf.md5"
-              "av1-1-b8-00-quantizer-33.ivf"
-              "av1-1-b8-00-quantizer-33.ivf.md5"
-              "av1-1-b8-00-quantizer-34.ivf"
-              "av1-1-b8-00-quantizer-34.ivf.md5"
-              "av1-1-b8-00-quantizer-35.ivf"
-              "av1-1-b8-00-quantizer-35.ivf.md5"
-              "av1-1-b8-00-quantizer-36.ivf"
-              "av1-1-b8-00-quantizer-36.ivf.md5"
-              "av1-1-b8-00-quantizer-37.ivf"
-              "av1-1-b8-00-quantizer-37.ivf.md5"
-              "av1-1-b8-00-quantizer-38.ivf"
-              "av1-1-b8-00-quantizer-38.ivf.md5"
-              "av1-1-b8-00-quantizer-39.ivf"
-              "av1-1-b8-00-quantizer-39.ivf.md5"
-              "av1-1-b8-00-quantizer-40.ivf"
-              "av1-1-b8-00-quantizer-40.ivf.md5"
-              "av1-1-b8-00-quantizer-41.ivf"
-              "av1-1-b8-00-quantizer-41.ivf.md5"
-              "av1-1-b8-00-quantizer-42.ivf"
-              "av1-1-b8-00-quantizer-42.ivf.md5"
-              "av1-1-b8-00-quantizer-43.ivf"
-              "av1-1-b8-00-quantizer-43.ivf.md5"
-              "av1-1-b8-00-quantizer-44.ivf"
-              "av1-1-b8-00-quantizer-44.ivf.md5"
-              "av1-1-b8-00-quantizer-45.ivf"
-              "av1-1-b8-00-quantizer-45.ivf.md5"
-              "av1-1-b8-00-quantizer-46.ivf"
-              "av1-1-b8-00-quantizer-46.ivf.md5"
-              "av1-1-b8-00-quantizer-47.ivf"
-              "av1-1-b8-00-quantizer-47.ivf.md5"
-              "av1-1-b8-00-quantizer-48.ivf"
-              "av1-1-b8-00-quantizer-48.ivf.md5"
-              "av1-1-b8-00-quantizer-49.ivf"
-              "av1-1-b8-00-quantizer-49.ivf.md5"
-              "av1-1-b8-00-quantizer-50.ivf"
-              "av1-1-b8-00-quantizer-50.ivf.md5"
-              "av1-1-b8-00-quantizer-51.ivf"
-              "av1-1-b8-00-quantizer-51.ivf.md5"
-              "av1-1-b8-00-quantizer-52.ivf"
-              "av1-1-b8-00-quantizer-52.ivf.md5"
-              "av1-1-b8-00-quantizer-53.ivf"
-              "av1-1-b8-00-quantizer-53.ivf.md5"
-              "av1-1-b8-00-quantizer-54.ivf"
-              "av1-1-b8-00-quantizer-54.ivf.md5"
-              "av1-1-b8-00-quantizer-55.ivf"
-              "av1-1-b8-00-quantizer-55.ivf.md5"
-              "av1-1-b8-00-quantizer-56.ivf"
-              "av1-1-b8-00-quantizer-56.ivf.md5"
-              "av1-1-b8-00-quantizer-57.ivf"
-              "av1-1-b8-00-quantizer-57.ivf.md5"
-              "av1-1-b8-00-quantizer-58.ivf"
-              "av1-1-b8-00-quantizer-58.ivf.md5"
-              "av1-1-b8-00-quantizer-59.ivf"
-              "av1-1-b8-00-quantizer-59.ivf.md5"
-              "av1-1-b8-00-quantizer-60.ivf"
-              "av1-1-b8-00-quantizer-60.ivf.md5"
-              "av1-1-b8-00-quantizer-61.ivf"
-              "av1-1-b8-00-quantizer-61.ivf.md5"
-              "av1-1-b8-00-quantizer-62.ivf"
-              "av1-1-b8-00-quantizer-62.ivf.md5"
-              "av1-1-b8-00-quantizer-63.ivf"
-              "av1-1-b8-00-quantizer-63.ivf.md5"
-              "av1-1-b10-00-quantizer-00.ivf"
-              "av1-1-b10-00-quantizer-00.ivf.md5"
-              "av1-1-b10-00-quantizer-01.ivf"
-              "av1-1-b10-00-quantizer-01.ivf.md5"
-              "av1-1-b10-00-quantizer-02.ivf"
-              "av1-1-b10-00-quantizer-02.ivf.md5"
-              "av1-1-b10-00-quantizer-03.ivf"
-              "av1-1-b10-00-quantizer-03.ivf.md5"
-              "av1-1-b10-00-quantizer-04.ivf"
-              "av1-1-b10-00-quantizer-04.ivf.md5"
-              "av1-1-b10-00-quantizer-05.ivf"
-              "av1-1-b10-00-quantizer-05.ivf.md5"
-              "av1-1-b10-00-quantizer-06.ivf"
-              "av1-1-b10-00-quantizer-06.ivf.md5"
-              "av1-1-b10-00-quantizer-07.ivf"
-              "av1-1-b10-00-quantizer-07.ivf.md5"
-              "av1-1-b10-00-quantizer-08.ivf"
-              "av1-1-b10-00-quantizer-08.ivf.md5"
-              "av1-1-b10-00-quantizer-09.ivf"
-              "av1-1-b10-00-quantizer-09.ivf.md5"
-              "av1-1-b10-00-quantizer-10.ivf"
-              "av1-1-b10-00-quantizer-10.ivf.md5"
-              "av1-1-b10-00-quantizer-11.ivf"
-              "av1-1-b10-00-quantizer-11.ivf.md5"
-              "av1-1-b10-00-quantizer-12.ivf"
-              "av1-1-b10-00-quantizer-12.ivf.md5"
-              "av1-1-b10-00-quantizer-13.ivf"
-              "av1-1-b10-00-quantizer-13.ivf.md5"
-              "av1-1-b10-00-quantizer-14.ivf"
-              "av1-1-b10-00-quantizer-14.ivf.md5"
-              "av1-1-b10-00-quantizer-15.ivf"
-              "av1-1-b10-00-quantizer-15.ivf.md5"
-              "av1-1-b10-00-quantizer-16.ivf"
-              "av1-1-b10-00-quantizer-16.ivf.md5"
-              "av1-1-b10-00-quantizer-17.ivf"
-              "av1-1-b10-00-quantizer-17.ivf.md5"
-              "av1-1-b10-00-quantizer-18.ivf"
-              "av1-1-b10-00-quantizer-18.ivf.md5"
-              "av1-1-b10-00-quantizer-19.ivf"
-              "av1-1-b10-00-quantizer-19.ivf.md5"
-              "av1-1-b10-00-quantizer-20.ivf"
-              "av1-1-b10-00-quantizer-20.ivf.md5"
-              "av1-1-b10-00-quantizer-21.ivf"
-              "av1-1-b10-00-quantizer-21.ivf.md5"
-              "av1-1-b10-00-quantizer-22.ivf"
-              "av1-1-b10-00-quantizer-22.ivf.md5"
-              "av1-1-b10-00-quantizer-23.ivf"
-              "av1-1-b10-00-quantizer-23.ivf.md5"
-              "av1-1-b10-00-quantizer-24.ivf"
-              "av1-1-b10-00-quantizer-24.ivf.md5"
-              "av1-1-b10-00-quantizer-25.ivf"
-              "av1-1-b10-00-quantizer-25.ivf.md5"
-              "av1-1-b10-00-quantizer-26.ivf"
-              "av1-1-b10-00-quantizer-26.ivf.md5"
-              "av1-1-b10-00-quantizer-27.ivf"
-              "av1-1-b10-00-quantizer-27.ivf.md5"
-              "av1-1-b10-00-quantizer-28.ivf"
-              "av1-1-b10-00-quantizer-28.ivf.md5"
-              "av1-1-b10-00-quantizer-29.ivf"
-              "av1-1-b10-00-quantizer-29.ivf.md5"
-              "av1-1-b10-00-quantizer-30.ivf"
-              "av1-1-b10-00-quantizer-30.ivf.md5"
-              "av1-1-b10-00-quantizer-31.ivf"
-              "av1-1-b10-00-quantizer-31.ivf.md5"
-              "av1-1-b10-00-quantizer-32.ivf"
-              "av1-1-b10-00-quantizer-32.ivf.md5"
-              "av1-1-b10-00-quantizer-33.ivf"
-              "av1-1-b10-00-quantizer-33.ivf.md5"
-              "av1-1-b10-00-quantizer-34.ivf"
-              "av1-1-b10-00-quantizer-34.ivf.md5"
-              "av1-1-b10-00-quantizer-35.ivf"
-              "av1-1-b10-00-quantizer-35.ivf.md5"
-              "av1-1-b10-00-quantizer-36.ivf"
-              "av1-1-b10-00-quantizer-36.ivf.md5"
-              "av1-1-b10-00-quantizer-37.ivf"
-              "av1-1-b10-00-quantizer-37.ivf.md5"
-              "av1-1-b10-00-quantizer-38.ivf"
-              "av1-1-b10-00-quantizer-38.ivf.md5"
-              "av1-1-b10-00-quantizer-39.ivf"
-              "av1-1-b10-00-quantizer-39.ivf.md5"
-              "av1-1-b10-00-quantizer-40.ivf"
-              "av1-1-b10-00-quantizer-40.ivf.md5"
-              "av1-1-b10-00-quantizer-41.ivf"
-              "av1-1-b10-00-quantizer-41.ivf.md5"
-              "av1-1-b10-00-quantizer-42.ivf"
-              "av1-1-b10-00-quantizer-42.ivf.md5"
-              "av1-1-b10-00-quantizer-43.ivf"
-              "av1-1-b10-00-quantizer-43.ivf.md5"
-              "av1-1-b10-00-quantizer-44.ivf"
-              "av1-1-b10-00-quantizer-44.ivf.md5"
-              "av1-1-b10-00-quantizer-45.ivf"
-              "av1-1-b10-00-quantizer-45.ivf.md5"
-              "av1-1-b10-00-quantizer-46.ivf"
-              "av1-1-b10-00-quantizer-46.ivf.md5"
-              "av1-1-b10-00-quantizer-47.ivf"
-              "av1-1-b10-00-quantizer-47.ivf.md5"
-              "av1-1-b10-00-quantizer-48.ivf"
-              "av1-1-b10-00-quantizer-48.ivf.md5"
-              "av1-1-b10-00-quantizer-49.ivf"
-              "av1-1-b10-00-quantizer-49.ivf.md5"
-              "av1-1-b10-00-quantizer-50.ivf"
-              "av1-1-b10-00-quantizer-50.ivf.md5"
-              "av1-1-b10-00-quantizer-51.ivf"
-              "av1-1-b10-00-quantizer-51.ivf.md5"
-              "av1-1-b10-00-quantizer-52.ivf"
-              "av1-1-b10-00-quantizer-52.ivf.md5"
-              "av1-1-b10-00-quantizer-53.ivf"
-              "av1-1-b10-00-quantizer-53.ivf.md5"
-              "av1-1-b10-00-quantizer-54.ivf"
-              "av1-1-b10-00-quantizer-54.ivf.md5"
-              "av1-1-b10-00-quantizer-55.ivf"
-              "av1-1-b10-00-quantizer-55.ivf.md5"
-              "av1-1-b10-00-quantizer-56.ivf"
-              "av1-1-b10-00-quantizer-56.ivf.md5"
-              "av1-1-b10-00-quantizer-57.ivf"
-              "av1-1-b10-00-quantizer-57.ivf.md5"
-              "av1-1-b10-00-quantizer-58.ivf"
-              "av1-1-b10-00-quantizer-58.ivf.md5"
-              "av1-1-b10-00-quantizer-59.ivf"
-              "av1-1-b10-00-quantizer-59.ivf.md5"
-              "av1-1-b10-00-quantizer-60.ivf"
-              "av1-1-b10-00-quantizer-60.ivf.md5"
-              "av1-1-b10-00-quantizer-61.ivf"
-              "av1-1-b10-00-quantizer-61.ivf.md5"
-              "av1-1-b10-00-quantizer-62.ivf"
-              "av1-1-b10-00-quantizer-62.ivf.md5"
-              "av1-1-b10-00-quantizer-63.ivf"
-              "av1-1-b10-00-quantizer-63.ivf.md5"
-              "av1-1-b10-23-film_grain-50.ivf"
-              "av1-1-b10-23-film_grain-50.ivf.md5"
-              "av1-1-b8-01-size-16x16.ivf"
-              "av1-1-b8-01-size-16x16.ivf.md5"
-              "av1-1-b8-01-size-16x18.ivf"
-              "av1-1-b8-01-size-16x18.ivf.md5"
-              "av1-1-b8-01-size-16x32.ivf"
-              "av1-1-b8-01-size-16x32.ivf.md5"
-              "av1-1-b8-01-size-16x34.ivf"
-              "av1-1-b8-01-size-16x34.ivf.md5"
-              "av1-1-b8-01-size-16x64.ivf"
-              "av1-1-b8-01-size-16x64.ivf.md5"
-              "av1-1-b8-01-size-16x66.ivf"
-              "av1-1-b8-01-size-16x66.ivf.md5"
-              "av1-1-b8-01-size-18x16.ivf"
-              "av1-1-b8-01-size-18x16.ivf.md5"
-              "av1-1-b8-01-size-18x18.ivf"
-              "av1-1-b8-01-size-18x18.ivf.md5"
-              "av1-1-b8-01-size-18x32.ivf"
-              "av1-1-b8-01-size-18x32.ivf.md5"
-              "av1-1-b8-01-size-18x34.ivf"
-              "av1-1-b8-01-size-18x34.ivf.md5"
-              "av1-1-b8-01-size-18x64.ivf"
-              "av1-1-b8-01-size-18x64.ivf.md5"
-              "av1-1-b8-01-size-18x66.ivf"
-              "av1-1-b8-01-size-18x66.ivf.md5"
-              "av1-1-b8-01-size-196x196.ivf"
-              "av1-1-b8-01-size-196x196.ivf.md5"
-              "av1-1-b8-01-size-196x198.ivf"
-              "av1-1-b8-01-size-196x198.ivf.md5"
-              "av1-1-b8-01-size-196x200.ivf"
-              "av1-1-b8-01-size-196x200.ivf.md5"
-              "av1-1-b8-01-size-196x202.ivf"
-              "av1-1-b8-01-size-196x202.ivf.md5"
-              "av1-1-b8-01-size-196x208.ivf"
-              "av1-1-b8-01-size-196x208.ivf.md5"
-              "av1-1-b8-01-size-196x210.ivf"
-              "av1-1-b8-01-size-196x210.ivf.md5"
-              "av1-1-b8-01-size-196x224.ivf"
-              "av1-1-b8-01-size-196x224.ivf.md5"
-              "av1-1-b8-01-size-196x226.ivf"
-              "av1-1-b8-01-size-196x226.ivf.md5"
-              "av1-1-b8-01-size-198x196.ivf"
-              "av1-1-b8-01-size-198x196.ivf.md5"
-              "av1-1-b8-01-size-198x198.ivf"
-              "av1-1-b8-01-size-198x198.ivf.md5"
-              "av1-1-b8-01-size-198x200.ivf"
-              "av1-1-b8-01-size-198x200.ivf.md5"
-              "av1-1-b8-01-size-198x202.ivf"
-              "av1-1-b8-01-size-198x202.ivf.md5"
-              "av1-1-b8-01-size-198x208.ivf"
-              "av1-1-b8-01-size-198x208.ivf.md5"
-              "av1-1-b8-01-size-198x210.ivf"
-              "av1-1-b8-01-size-198x210.ivf.md5"
-              "av1-1-b8-01-size-198x224.ivf"
-              "av1-1-b8-01-size-198x224.ivf.md5"
-              "av1-1-b8-01-size-198x226.ivf"
-              "av1-1-b8-01-size-198x226.ivf.md5"
-              "av1-1-b8-01-size-200x196.ivf"
-              "av1-1-b8-01-size-200x196.ivf.md5"
-              "av1-1-b8-01-size-200x198.ivf"
-              "av1-1-b8-01-size-200x198.ivf.md5"
-              "av1-1-b8-01-size-200x200.ivf"
-              "av1-1-b8-01-size-200x200.ivf.md5"
-              "av1-1-b8-01-size-200x202.ivf"
-              "av1-1-b8-01-size-200x202.ivf.md5"
-              "av1-1-b8-01-size-200x208.ivf"
-              "av1-1-b8-01-size-200x208.ivf.md5"
-              "av1-1-b8-01-size-200x210.ivf"
-              "av1-1-b8-01-size-200x210.ivf.md5"
-              "av1-1-b8-01-size-200x224.ivf"
-              "av1-1-b8-01-size-200x224.ivf.md5"
-              "av1-1-b8-01-size-200x226.ivf"
-              "av1-1-b8-01-size-200x226.ivf.md5"
-              "av1-1-b8-01-size-202x196.ivf"
-              "av1-1-b8-01-size-202x196.ivf.md5"
-              "av1-1-b8-01-size-202x198.ivf"
-              "av1-1-b8-01-size-202x198.ivf.md5"
-              "av1-1-b8-01-size-202x200.ivf"
-              "av1-1-b8-01-size-202x200.ivf.md5"
-              "av1-1-b8-01-size-202x202.ivf"
-              "av1-1-b8-01-size-202x202.ivf.md5"
-              "av1-1-b8-01-size-202x208.ivf"
-              "av1-1-b8-01-size-202x208.ivf.md5"
-              "av1-1-b8-01-size-202x210.ivf"
-              "av1-1-b8-01-size-202x210.ivf.md5"
-              "av1-1-b8-01-size-202x224.ivf"
-              "av1-1-b8-01-size-202x224.ivf.md5"
-              "av1-1-b8-01-size-202x226.ivf"
-              "av1-1-b8-01-size-202x226.ivf.md5"
-              "av1-1-b8-01-size-208x196.ivf"
-              "av1-1-b8-01-size-208x196.ivf.md5"
-              "av1-1-b8-01-size-208x198.ivf"
-              "av1-1-b8-01-size-208x198.ivf.md5"
-              "av1-1-b8-01-size-208x200.ivf"
-              "av1-1-b8-01-size-208x200.ivf.md5"
-              "av1-1-b8-01-size-208x202.ivf"
-              "av1-1-b8-01-size-208x202.ivf.md5"
-              "av1-1-b8-01-size-208x208.ivf"
-              "av1-1-b8-01-size-208x208.ivf.md5"
-              "av1-1-b8-01-size-208x210.ivf"
-              "av1-1-b8-01-size-208x210.ivf.md5"
-              "av1-1-b8-01-size-208x224.ivf"
-              "av1-1-b8-01-size-208x224.ivf.md5"
-              "av1-1-b8-01-size-208x226.ivf"
-              "av1-1-b8-01-size-208x226.ivf.md5"
-              "av1-1-b8-01-size-210x196.ivf"
-              "av1-1-b8-01-size-210x196.ivf.md5"
-              "av1-1-b8-01-size-210x198.ivf"
-              "av1-1-b8-01-size-210x198.ivf.md5"
-              "av1-1-b8-01-size-210x200.ivf"
-              "av1-1-b8-01-size-210x200.ivf.md5"
-              "av1-1-b8-01-size-210x202.ivf"
-              "av1-1-b8-01-size-210x202.ivf.md5"
-              "av1-1-b8-01-size-210x208.ivf"
-              "av1-1-b8-01-size-210x208.ivf.md5"
-              "av1-1-b8-01-size-210x210.ivf"
-              "av1-1-b8-01-size-210x210.ivf.md5"
-              "av1-1-b8-01-size-210x224.ivf"
-              "av1-1-b8-01-size-210x224.ivf.md5"
-              "av1-1-b8-01-size-210x226.ivf"
-              "av1-1-b8-01-size-210x226.ivf.md5"
-              "av1-1-b8-01-size-224x196.ivf"
-              "av1-1-b8-01-size-224x196.ivf.md5"
-              "av1-1-b8-01-size-224x198.ivf"
-              "av1-1-b8-01-size-224x198.ivf.md5"
-              "av1-1-b8-01-size-224x200.ivf"
-              "av1-1-b8-01-size-224x200.ivf.md5"
-              "av1-1-b8-01-size-224x202.ivf"
-              "av1-1-b8-01-size-224x202.ivf.md5"
-              "av1-1-b8-01-size-224x208.ivf"
-              "av1-1-b8-01-size-224x208.ivf.md5"
-              "av1-1-b8-01-size-224x210.ivf"
-              "av1-1-b8-01-size-224x210.ivf.md5"
-              "av1-1-b8-01-size-224x224.ivf"
-              "av1-1-b8-01-size-224x224.ivf.md5"
-              "av1-1-b8-01-size-224x226.ivf"
-              "av1-1-b8-01-size-224x226.ivf.md5"
-              "av1-1-b8-01-size-226x196.ivf"
-              "av1-1-b8-01-size-226x196.ivf.md5"
-              "av1-1-b8-01-size-226x198.ivf"
-              "av1-1-b8-01-size-226x198.ivf.md5"
-              "av1-1-b8-01-size-226x200.ivf"
-              "av1-1-b8-01-size-226x200.ivf.md5"
-              "av1-1-b8-01-size-226x202.ivf"
-              "av1-1-b8-01-size-226x202.ivf.md5"
-              "av1-1-b8-01-size-226x208.ivf"
-              "av1-1-b8-01-size-226x208.ivf.md5"
-              "av1-1-b8-01-size-226x210.ivf"
-              "av1-1-b8-01-size-226x210.ivf.md5"
-              "av1-1-b8-01-size-226x224.ivf"
-              "av1-1-b8-01-size-226x224.ivf.md5"
-              "av1-1-b8-01-size-226x226.ivf"
-              "av1-1-b8-01-size-226x226.ivf.md5"
-              "av1-1-b8-01-size-32x16.ivf"
-              "av1-1-b8-01-size-32x16.ivf.md5"
-              "av1-1-b8-01-size-32x18.ivf"
-              "av1-1-b8-01-size-32x18.ivf.md5"
-              "av1-1-b8-01-size-32x32.ivf"
-              "av1-1-b8-01-size-32x32.ivf.md5"
-              "av1-1-b8-01-size-32x34.ivf"
-              "av1-1-b8-01-size-32x34.ivf.md5"
-              "av1-1-b8-01-size-32x64.ivf"
-              "av1-1-b8-01-size-32x64.ivf.md5"
-              "av1-1-b8-01-size-32x66.ivf"
-              "av1-1-b8-01-size-32x66.ivf.md5"
-              "av1-1-b8-01-size-34x16.ivf"
-              "av1-1-b8-01-size-34x16.ivf.md5"
-              "av1-1-b8-01-size-34x18.ivf"
-              "av1-1-b8-01-size-34x18.ivf.md5"
-              "av1-1-b8-01-size-34x32.ivf"
-              "av1-1-b8-01-size-34x32.ivf.md5"
-              "av1-1-b8-01-size-34x34.ivf"
-              "av1-1-b8-01-size-34x34.ivf.md5"
-              "av1-1-b8-01-size-34x64.ivf"
-              "av1-1-b8-01-size-34x64.ivf.md5"
-              "av1-1-b8-01-size-34x66.ivf"
-              "av1-1-b8-01-size-34x66.ivf.md5"
-              "av1-1-b8-01-size-64x16.ivf"
-              "av1-1-b8-01-size-64x16.ivf.md5"
-              "av1-1-b8-01-size-64x18.ivf"
-              "av1-1-b8-01-size-64x18.ivf.md5"
-              "av1-1-b8-01-size-64x32.ivf"
-              "av1-1-b8-01-size-64x32.ivf.md5"
-              "av1-1-b8-01-size-64x34.ivf"
-              "av1-1-b8-01-size-64x34.ivf.md5"
-              "av1-1-b8-01-size-64x64.ivf"
-              "av1-1-b8-01-size-64x64.ivf.md5"
-              "av1-1-b8-01-size-64x66.ivf"
-              "av1-1-b8-01-size-64x66.ivf.md5"
-              "av1-1-b8-01-size-66x16.ivf"
-              "av1-1-b8-01-size-66x16.ivf.md5"
-              "av1-1-b8-01-size-66x18.ivf"
-              "av1-1-b8-01-size-66x18.ivf.md5"
-              "av1-1-b8-01-size-66x32.ivf"
-              "av1-1-b8-01-size-66x32.ivf.md5"
-              "av1-1-b8-01-size-66x34.ivf"
-              "av1-1-b8-01-size-66x34.ivf.md5"
-              "av1-1-b8-01-size-66x64.ivf"
-              "av1-1-b8-01-size-66x64.ivf.md5"
-              "av1-1-b8-01-size-66x66.ivf"
-              "av1-1-b8-01-size-66x66.ivf.md5"
-              "av1-1-b8-02-allintra.ivf"
-              "av1-1-b8-02-allintra.ivf.md5"
-              "av1-1-b8-03-sizeup.mkv"
-              "av1-1-b8-03-sizeup.mkv.md5"
-              "av1-1-b8-03-sizedown.mkv"
-              "av1-1-b8-03-sizedown.mkv.md5"
-              "av1-1-b8-04-cdfupdate.ivf"
-              "av1-1-b8-04-cdfupdate.ivf.md5"
-              "av1-1-b8-05-mv.ivf"
-              "av1-1-b8-05-mv.ivf.md5"
-              "av1-1-b8-06-mfmv.ivf"
-              "av1-1-b8-06-mfmv.ivf.md5"
-              "av1-1-b8-22-svc-L2T1.ivf"
-              "av1-1-b8-22-svc-L2T1.ivf.md5"
-              "av1-1-b8-22-svc-L1T2.ivf"
-              "av1-1-b8-22-svc-L1T2.ivf.md5"
-              "av1-1-b8-22-svc-L2T2.ivf"
-              "av1-1-b8-22-svc-L2T2.ivf.md5"
-              "av1-1-b8-23-film_grain-50.ivf"
-              "av1-1-b8-23-film_grain-50.ivf.md5"
-              "invalid-bug-1814.ivf"
-              "invalid-bug-1814.ivf.res"
-              "invalid-chromium-906381.ivf"
-              "invalid-chromium-906381.ivf.res"
-              "invalid-google-142530197-1.ivf"
-              "invalid-google-142530197-1.ivf.res"
-              "invalid-google-142530197.ivf"
-              "invalid-google-142530197.ivf.res"
-              "invalid-oss-fuzz-10061.ivf"
-              "invalid-oss-fuzz-10061.ivf.res"
-              "invalid-oss-fuzz-10117-mc-buf-use-highbd.ivf"
-              "invalid-oss-fuzz-10117-mc-buf-use-highbd.ivf.res"
-              "invalid-oss-fuzz-10227.ivf"
-              "invalid-oss-fuzz-10227.ivf.res"
-              "invalid-oss-fuzz-10389.ivf"
-              "invalid-oss-fuzz-10389.ivf.res"
-              "invalid-oss-fuzz-10389.ivf.res.2"
-              "invalid-oss-fuzz-10555.ivf"
-              "invalid-oss-fuzz-10555.ivf.res"
-              "invalid-oss-fuzz-10705.ivf"
-              "invalid-oss-fuzz-10705.ivf.res"
-              "invalid-oss-fuzz-10723.ivf"
-              "invalid-oss-fuzz-10723.ivf.res"
-              "invalid-oss-fuzz-10723.ivf.res.2"
-              "invalid-oss-fuzz-10779.ivf"
-              "invalid-oss-fuzz-10779.ivf.res"
-              "invalid-oss-fuzz-11477.ivf"
-              "invalid-oss-fuzz-11477.ivf.res"
-              "invalid-oss-fuzz-11479.ivf"
-              "invalid-oss-fuzz-11479.ivf.res"
-              "invalid-oss-fuzz-11479.ivf.res.2"
-              "invalid-oss-fuzz-11523.ivf"
-              "invalid-oss-fuzz-11523.ivf.res"
-              "invalid-oss-fuzz-11523.ivf.res.2"
-              "invalid-oss-fuzz-15363.ivf"
-              "invalid-oss-fuzz-15363.ivf.res"
-              "invalid-oss-fuzz-16437.ivf"
-              "invalid-oss-fuzz-16437.ivf.res"
-              "invalid-oss-fuzz-9288.ivf"
-              "invalid-oss-fuzz-9288.ivf.res"
-              "invalid-oss-fuzz-9463.ivf"
-              "invalid-oss-fuzz-9463.ivf.res"
-              "invalid-oss-fuzz-9463.ivf.res.2"
-              "invalid-oss-fuzz-9482.ivf"
-              "invalid-oss-fuzz-9482.ivf.res"
-              "invalid-oss-fuzz-9720.ivf"
-              "invalid-oss-fuzz-9720.ivf.res")
+  list(
+    APPEND
+    AOM_TEST_DATA_FILE_NAMES
+    "av1-1-b8-00-quantizer-00.ivf"
+    "av1-1-b8-00-quantizer-00.ivf.md5"
+    "av1-1-b8-00-quantizer-01.ivf"
+    "av1-1-b8-00-quantizer-01.ivf.md5"
+    "av1-1-b8-00-quantizer-02.ivf"
+    "av1-1-b8-00-quantizer-02.ivf.md5"
+    "av1-1-b8-00-quantizer-03.ivf"
+    "av1-1-b8-00-quantizer-03.ivf.md5"
+    "av1-1-b8-00-quantizer-04.ivf"
+    "av1-1-b8-00-quantizer-04.ivf.md5"
+    "av1-1-b8-00-quantizer-05.ivf"
+    "av1-1-b8-00-quantizer-05.ivf.md5"
+    "av1-1-b8-00-quantizer-06.ivf"
+    "av1-1-b8-00-quantizer-06.ivf.md5"
+    "av1-1-b8-00-quantizer-07.ivf"
+    "av1-1-b8-00-quantizer-07.ivf.md5"
+    "av1-1-b8-00-quantizer-08.ivf"
+    "av1-1-b8-00-quantizer-08.ivf.md5"
+    "av1-1-b8-00-quantizer-09.ivf"
+    "av1-1-b8-00-quantizer-09.ivf.md5"
+    "av1-1-b8-00-quantizer-10.ivf"
+    "av1-1-b8-00-quantizer-10.ivf.md5"
+    "av1-1-b8-00-quantizer-11.ivf"
+    "av1-1-b8-00-quantizer-11.ivf.md5"
+    "av1-1-b8-00-quantizer-12.ivf"
+    "av1-1-b8-00-quantizer-12.ivf.md5"
+    "av1-1-b8-00-quantizer-13.ivf"
+    "av1-1-b8-00-quantizer-13.ivf.md5"
+    "av1-1-b8-00-quantizer-14.ivf"
+    "av1-1-b8-00-quantizer-14.ivf.md5"
+    "av1-1-b8-00-quantizer-15.ivf"
+    "av1-1-b8-00-quantizer-15.ivf.md5"
+    "av1-1-b8-00-quantizer-16.ivf"
+    "av1-1-b8-00-quantizer-16.ivf.md5"
+    "av1-1-b8-00-quantizer-17.ivf"
+    "av1-1-b8-00-quantizer-17.ivf.md5"
+    "av1-1-b8-00-quantizer-18.ivf"
+    "av1-1-b8-00-quantizer-18.ivf.md5"
+    "av1-1-b8-00-quantizer-19.ivf"
+    "av1-1-b8-00-quantizer-19.ivf.md5"
+    "av1-1-b8-00-quantizer-20.ivf"
+    "av1-1-b8-00-quantizer-20.ivf.md5"
+    "av1-1-b8-00-quantizer-21.ivf"
+    "av1-1-b8-00-quantizer-21.ivf.md5"
+    "av1-1-b8-00-quantizer-22.ivf"
+    "av1-1-b8-00-quantizer-22.ivf.md5"
+    "av1-1-b8-00-quantizer-23.ivf"
+    "av1-1-b8-00-quantizer-23.ivf.md5"
+    "av1-1-b8-00-quantizer-24.ivf"
+    "av1-1-b8-00-quantizer-24.ivf.md5"
+    "av1-1-b8-00-quantizer-25.ivf"
+    "av1-1-b8-00-quantizer-25.ivf.md5"
+    "av1-1-b8-00-quantizer-26.ivf"
+    "av1-1-b8-00-quantizer-26.ivf.md5"
+    "av1-1-b8-00-quantizer-27.ivf"
+    "av1-1-b8-00-quantizer-27.ivf.md5"
+    "av1-1-b8-00-quantizer-28.ivf"
+    "av1-1-b8-00-quantizer-28.ivf.md5"
+    "av1-1-b8-00-quantizer-29.ivf"
+    "av1-1-b8-00-quantizer-29.ivf.md5"
+    "av1-1-b8-00-quantizer-30.ivf"
+    "av1-1-b8-00-quantizer-30.ivf.md5"
+    "av1-1-b8-00-quantizer-31.ivf"
+    "av1-1-b8-00-quantizer-31.ivf.md5"
+    "av1-1-b8-00-quantizer-32.ivf"
+    "av1-1-b8-00-quantizer-32.ivf.md5"
+    "av1-1-b8-00-quantizer-33.ivf"
+    "av1-1-b8-00-quantizer-33.ivf.md5"
+    "av1-1-b8-00-quantizer-34.ivf"
+    "av1-1-b8-00-quantizer-34.ivf.md5"
+    "av1-1-b8-00-quantizer-35.ivf"
+    "av1-1-b8-00-quantizer-35.ivf.md5"
+    "av1-1-b8-00-quantizer-36.ivf"
+    "av1-1-b8-00-quantizer-36.ivf.md5"
+    "av1-1-b8-00-quantizer-37.ivf"
+    "av1-1-b8-00-quantizer-37.ivf.md5"
+    "av1-1-b8-00-quantizer-38.ivf"
+    "av1-1-b8-00-quantizer-38.ivf.md5"
+    "av1-1-b8-00-quantizer-39.ivf"
+    "av1-1-b8-00-quantizer-39.ivf.md5"
+    "av1-1-b8-00-quantizer-40.ivf"
+    "av1-1-b8-00-quantizer-40.ivf.md5"
+    "av1-1-b8-00-quantizer-41.ivf"
+    "av1-1-b8-00-quantizer-41.ivf.md5"
+    "av1-1-b8-00-quantizer-42.ivf"
+    "av1-1-b8-00-quantizer-42.ivf.md5"
+    "av1-1-b8-00-quantizer-43.ivf"
+    "av1-1-b8-00-quantizer-43.ivf.md5"
+    "av1-1-b8-00-quantizer-44.ivf"
+    "av1-1-b8-00-quantizer-44.ivf.md5"
+    "av1-1-b8-00-quantizer-45.ivf"
+    "av1-1-b8-00-quantizer-45.ivf.md5"
+    "av1-1-b8-00-quantizer-46.ivf"
+    "av1-1-b8-00-quantizer-46.ivf.md5"
+    "av1-1-b8-00-quantizer-47.ivf"
+    "av1-1-b8-00-quantizer-47.ivf.md5"
+    "av1-1-b8-00-quantizer-48.ivf"
+    "av1-1-b8-00-quantizer-48.ivf.md5"
+    "av1-1-b8-00-quantizer-49.ivf"
+    "av1-1-b8-00-quantizer-49.ivf.md5"
+    "av1-1-b8-00-quantizer-50.ivf"
+    "av1-1-b8-00-quantizer-50.ivf.md5"
+    "av1-1-b8-00-quantizer-51.ivf"
+    "av1-1-b8-00-quantizer-51.ivf.md5"
+    "av1-1-b8-00-quantizer-52.ivf"
+    "av1-1-b8-00-quantizer-52.ivf.md5"
+    "av1-1-b8-00-quantizer-53.ivf"
+    "av1-1-b8-00-quantizer-53.ivf.md5"
+    "av1-1-b8-00-quantizer-54.ivf"
+    "av1-1-b8-00-quantizer-54.ivf.md5"
+    "av1-1-b8-00-quantizer-55.ivf"
+    "av1-1-b8-00-quantizer-55.ivf.md5"
+    "av1-1-b8-00-quantizer-56.ivf"
+    "av1-1-b8-00-quantizer-56.ivf.md5"
+    "av1-1-b8-00-quantizer-57.ivf"
+    "av1-1-b8-00-quantizer-57.ivf.md5"
+    "av1-1-b8-00-quantizer-58.ivf"
+    "av1-1-b8-00-quantizer-58.ivf.md5"
+    "av1-1-b8-00-quantizer-59.ivf"
+    "av1-1-b8-00-quantizer-59.ivf.md5"
+    "av1-1-b8-00-quantizer-60.ivf"
+    "av1-1-b8-00-quantizer-60.ivf.md5"
+    "av1-1-b8-00-quantizer-61.ivf"
+    "av1-1-b8-00-quantizer-61.ivf.md5"
+    "av1-1-b8-00-quantizer-62.ivf"
+    "av1-1-b8-00-quantizer-62.ivf.md5"
+    "av1-1-b8-00-quantizer-63.ivf"
+    "av1-1-b8-00-quantizer-63.ivf.md5"
+    "av1-1-b10-00-quantizer-00.ivf"
+    "av1-1-b10-00-quantizer-00.ivf.md5"
+    "av1-1-b10-00-quantizer-01.ivf"
+    "av1-1-b10-00-quantizer-01.ivf.md5"
+    "av1-1-b10-00-quantizer-02.ivf"
+    "av1-1-b10-00-quantizer-02.ivf.md5"
+    "av1-1-b10-00-quantizer-03.ivf"
+    "av1-1-b10-00-quantizer-03.ivf.md5"
+    "av1-1-b10-00-quantizer-04.ivf"
+    "av1-1-b10-00-quantizer-04.ivf.md5"
+    "av1-1-b10-00-quantizer-05.ivf"
+    "av1-1-b10-00-quantizer-05.ivf.md5"
+    "av1-1-b10-00-quantizer-06.ivf"
+    "av1-1-b10-00-quantizer-06.ivf.md5"
+    "av1-1-b10-00-quantizer-07.ivf"
+    "av1-1-b10-00-quantizer-07.ivf.md5"
+    "av1-1-b10-00-quantizer-08.ivf"
+    "av1-1-b10-00-quantizer-08.ivf.md5"
+    "av1-1-b10-00-quantizer-09.ivf"
+    "av1-1-b10-00-quantizer-09.ivf.md5"
+    "av1-1-b10-00-quantizer-10.ivf"
+    "av1-1-b10-00-quantizer-10.ivf.md5"
+    "av1-1-b10-00-quantizer-11.ivf"
+    "av1-1-b10-00-quantizer-11.ivf.md5"
+    "av1-1-b10-00-quantizer-12.ivf"
+    "av1-1-b10-00-quantizer-12.ivf.md5"
+    "av1-1-b10-00-quantizer-13.ivf"
+    "av1-1-b10-00-quantizer-13.ivf.md5"
+    "av1-1-b10-00-quantizer-14.ivf"
+    "av1-1-b10-00-quantizer-14.ivf.md5"
+    "av1-1-b10-00-quantizer-15.ivf"
+    "av1-1-b10-00-quantizer-15.ivf.md5"
+    "av1-1-b10-00-quantizer-16.ivf"
+    "av1-1-b10-00-quantizer-16.ivf.md5"
+    "av1-1-b10-00-quantizer-17.ivf"
+    "av1-1-b10-00-quantizer-17.ivf.md5"
+    "av1-1-b10-00-quantizer-18.ivf"
+    "av1-1-b10-00-quantizer-18.ivf.md5"
+    "av1-1-b10-00-quantizer-19.ivf"
+    "av1-1-b10-00-quantizer-19.ivf.md5"
+    "av1-1-b10-00-quantizer-20.ivf"
+    "av1-1-b10-00-quantizer-20.ivf.md5"
+    "av1-1-b10-00-quantizer-21.ivf"
+    "av1-1-b10-00-quantizer-21.ivf.md5"
+    "av1-1-b10-00-quantizer-22.ivf"
+    "av1-1-b10-00-quantizer-22.ivf.md5"
+    "av1-1-b10-00-quantizer-23.ivf"
+    "av1-1-b10-00-quantizer-23.ivf.md5"
+    "av1-1-b10-00-quantizer-24.ivf"
+    "av1-1-b10-00-quantizer-24.ivf.md5"
+    "av1-1-b10-00-quantizer-25.ivf"
+    "av1-1-b10-00-quantizer-25.ivf.md5"
+    "av1-1-b10-00-quantizer-26.ivf"
+    "av1-1-b10-00-quantizer-26.ivf.md5"
+    "av1-1-b10-00-quantizer-27.ivf"
+    "av1-1-b10-00-quantizer-27.ivf.md5"
+    "av1-1-b10-00-quantizer-28.ivf"
+    "av1-1-b10-00-quantizer-28.ivf.md5"
+    "av1-1-b10-00-quantizer-29.ivf"
+    "av1-1-b10-00-quantizer-29.ivf.md5"
+    "av1-1-b10-00-quantizer-30.ivf"
+    "av1-1-b10-00-quantizer-30.ivf.md5"
+    "av1-1-b10-00-quantizer-31.ivf"
+    "av1-1-b10-00-quantizer-31.ivf.md5"
+    "av1-1-b10-00-quantizer-32.ivf"
+    "av1-1-b10-00-quantizer-32.ivf.md5"
+    "av1-1-b10-00-quantizer-33.ivf"
+    "av1-1-b10-00-quantizer-33.ivf.md5"
+    "av1-1-b10-00-quantizer-34.ivf"
+    "av1-1-b10-00-quantizer-34.ivf.md5"
+    "av1-1-b10-00-quantizer-35.ivf"
+    "av1-1-b10-00-quantizer-35.ivf.md5"
+    "av1-1-b10-00-quantizer-36.ivf"
+    "av1-1-b10-00-quantizer-36.ivf.md5"
+    "av1-1-b10-00-quantizer-37.ivf"
+    "av1-1-b10-00-quantizer-37.ivf.md5"
+    "av1-1-b10-00-quantizer-38.ivf"
+    "av1-1-b10-00-quantizer-38.ivf.md5"
+    "av1-1-b10-00-quantizer-39.ivf"
+    "av1-1-b10-00-quantizer-39.ivf.md5"
+    "av1-1-b10-00-quantizer-40.ivf"
+    "av1-1-b10-00-quantizer-40.ivf.md5"
+    "av1-1-b10-00-quantizer-41.ivf"
+    "av1-1-b10-00-quantizer-41.ivf.md5"
+    "av1-1-b10-00-quantizer-42.ivf"
+    "av1-1-b10-00-quantizer-42.ivf.md5"
+    "av1-1-b10-00-quantizer-43.ivf"
+    "av1-1-b10-00-quantizer-43.ivf.md5"
+    "av1-1-b10-00-quantizer-44.ivf"
+    "av1-1-b10-00-quantizer-44.ivf.md5"
+    "av1-1-b10-00-quantizer-45.ivf"
+    "av1-1-b10-00-quantizer-45.ivf.md5"
+    "av1-1-b10-00-quantizer-46.ivf"
+    "av1-1-b10-00-quantizer-46.ivf.md5"
+    "av1-1-b10-00-quantizer-47.ivf"
+    "av1-1-b10-00-quantizer-47.ivf.md5"
+    "av1-1-b10-00-quantizer-48.ivf"
+    "av1-1-b10-00-quantizer-48.ivf.md5"
+    "av1-1-b10-00-quantizer-49.ivf"
+    "av1-1-b10-00-quantizer-49.ivf.md5"
+    "av1-1-b10-00-quantizer-50.ivf"
+    "av1-1-b10-00-quantizer-50.ivf.md5"
+    "av1-1-b10-00-quantizer-51.ivf"
+    "av1-1-b10-00-quantizer-51.ivf.md5"
+    "av1-1-b10-00-quantizer-52.ivf"
+    "av1-1-b10-00-quantizer-52.ivf.md5"
+    "av1-1-b10-00-quantizer-53.ivf"
+    "av1-1-b10-00-quantizer-53.ivf.md5"
+    "av1-1-b10-00-quantizer-54.ivf"
+    "av1-1-b10-00-quantizer-54.ivf.md5"
+    "av1-1-b10-00-quantizer-55.ivf"
+    "av1-1-b10-00-quantizer-55.ivf.md5"
+    "av1-1-b10-00-quantizer-56.ivf"
+    "av1-1-b10-00-quantizer-56.ivf.md5"
+    "av1-1-b10-00-quantizer-57.ivf"
+    "av1-1-b10-00-quantizer-57.ivf.md5"
+    "av1-1-b10-00-quantizer-58.ivf"
+    "av1-1-b10-00-quantizer-58.ivf.md5"
+    "av1-1-b10-00-quantizer-59.ivf"
+    "av1-1-b10-00-quantizer-59.ivf.md5"
+    "av1-1-b10-00-quantizer-60.ivf"
+    "av1-1-b10-00-quantizer-60.ivf.md5"
+    "av1-1-b10-00-quantizer-61.ivf"
+    "av1-1-b10-00-quantizer-61.ivf.md5"
+    "av1-1-b10-00-quantizer-62.ivf"
+    "av1-1-b10-00-quantizer-62.ivf.md5"
+    "av1-1-b10-00-quantizer-63.ivf"
+    "av1-1-b10-00-quantizer-63.ivf.md5"
+    "av1-1-b10-23-film_grain-50.ivf"
+    "av1-1-b10-23-film_grain-50.ivf.md5"
+    "av1-1-b8-01-size-16x16.ivf"
+    "av1-1-b8-01-size-16x16.ivf.md5"
+    "av1-1-b8-01-size-16x18.ivf"
+    "av1-1-b8-01-size-16x18.ivf.md5"
+    "av1-1-b8-01-size-16x32.ivf"
+    "av1-1-b8-01-size-16x32.ivf.md5"
+    "av1-1-b8-01-size-16x34.ivf"
+    "av1-1-b8-01-size-16x34.ivf.md5"
+    "av1-1-b8-01-size-16x64.ivf"
+    "av1-1-b8-01-size-16x64.ivf.md5"
+    "av1-1-b8-01-size-16x66.ivf"
+    "av1-1-b8-01-size-16x66.ivf.md5"
+    "av1-1-b8-01-size-18x16.ivf"
+    "av1-1-b8-01-size-18x16.ivf.md5"
+    "av1-1-b8-01-size-18x18.ivf"
+    "av1-1-b8-01-size-18x18.ivf.md5"
+    "av1-1-b8-01-size-18x32.ivf"
+    "av1-1-b8-01-size-18x32.ivf.md5"
+    "av1-1-b8-01-size-18x34.ivf"
+    "av1-1-b8-01-size-18x34.ivf.md5"
+    "av1-1-b8-01-size-18x64.ivf"
+    "av1-1-b8-01-size-18x64.ivf.md5"
+    "av1-1-b8-01-size-18x66.ivf"
+    "av1-1-b8-01-size-18x66.ivf.md5"
+    "av1-1-b8-01-size-196x196.ivf"
+    "av1-1-b8-01-size-196x196.ivf.md5"
+    "av1-1-b8-01-size-196x198.ivf"
+    "av1-1-b8-01-size-196x198.ivf.md5"
+    "av1-1-b8-01-size-196x200.ivf"
+    "av1-1-b8-01-size-196x200.ivf.md5"
+    "av1-1-b8-01-size-196x202.ivf"
+    "av1-1-b8-01-size-196x202.ivf.md5"
+    "av1-1-b8-01-size-196x208.ivf"
+    "av1-1-b8-01-size-196x208.ivf.md5"
+    "av1-1-b8-01-size-196x210.ivf"
+    "av1-1-b8-01-size-196x210.ivf.md5"
+    "av1-1-b8-01-size-196x224.ivf"
+    "av1-1-b8-01-size-196x224.ivf.md5"
+    "av1-1-b8-01-size-196x226.ivf"
+    "av1-1-b8-01-size-196x226.ivf.md5"
+    "av1-1-b8-01-size-198x196.ivf"
+    "av1-1-b8-01-size-198x196.ivf.md5"
+    "av1-1-b8-01-size-198x198.ivf"
+    "av1-1-b8-01-size-198x198.ivf.md5"
+    "av1-1-b8-01-size-198x200.ivf"
+    "av1-1-b8-01-size-198x200.ivf.md5"
+    "av1-1-b8-01-size-198x202.ivf"
+    "av1-1-b8-01-size-198x202.ivf.md5"
+    "av1-1-b8-01-size-198x208.ivf"
+    "av1-1-b8-01-size-198x208.ivf.md5"
+    "av1-1-b8-01-size-198x210.ivf"
+    "av1-1-b8-01-size-198x210.ivf.md5"
+    "av1-1-b8-01-size-198x224.ivf"
+    "av1-1-b8-01-size-198x224.ivf.md5"
+    "av1-1-b8-01-size-198x226.ivf"
+    "av1-1-b8-01-size-198x226.ivf.md5"
+    "av1-1-b8-01-size-200x196.ivf"
+    "av1-1-b8-01-size-200x196.ivf.md5"
+    "av1-1-b8-01-size-200x198.ivf"
+    "av1-1-b8-01-size-200x198.ivf.md5"
+    "av1-1-b8-01-size-200x200.ivf"
+    "av1-1-b8-01-size-200x200.ivf.md5"
+    "av1-1-b8-01-size-200x202.ivf"
+    "av1-1-b8-01-size-200x202.ivf.md5"
+    "av1-1-b8-01-size-200x208.ivf"
+    "av1-1-b8-01-size-200x208.ivf.md5"
+    "av1-1-b8-01-size-200x210.ivf"
+    "av1-1-b8-01-size-200x210.ivf.md5"
+    "av1-1-b8-01-size-200x224.ivf"
+    "av1-1-b8-01-size-200x224.ivf.md5"
+    "av1-1-b8-01-size-200x226.ivf"
+    "av1-1-b8-01-size-200x226.ivf.md5"
+    "av1-1-b8-01-size-202x196.ivf"
+    "av1-1-b8-01-size-202x196.ivf.md5"
+    "av1-1-b8-01-size-202x198.ivf"
+    "av1-1-b8-01-size-202x198.ivf.md5"
+    "av1-1-b8-01-size-202x200.ivf"
+    "av1-1-b8-01-size-202x200.ivf.md5"
+    "av1-1-b8-01-size-202x202.ivf"
+    "av1-1-b8-01-size-202x202.ivf.md5"
+    "av1-1-b8-01-size-202x208.ivf"
+    "av1-1-b8-01-size-202x208.ivf.md5"
+    "av1-1-b8-01-size-202x210.ivf"
+    "av1-1-b8-01-size-202x210.ivf.md5"
+    "av1-1-b8-01-size-202x224.ivf"
+    "av1-1-b8-01-size-202x224.ivf.md5"
+    "av1-1-b8-01-size-202x226.ivf"
+    "av1-1-b8-01-size-202x226.ivf.md5"
+    "av1-1-b8-01-size-208x196.ivf"
+    "av1-1-b8-01-size-208x196.ivf.md5"
+    "av1-1-b8-01-size-208x198.ivf"
+    "av1-1-b8-01-size-208x198.ivf.md5"
+    "av1-1-b8-01-size-208x200.ivf"
+    "av1-1-b8-01-size-208x200.ivf.md5"
+    "av1-1-b8-01-size-208x202.ivf"
+    "av1-1-b8-01-size-208x202.ivf.md5"
+    "av1-1-b8-01-size-208x208.ivf"
+    "av1-1-b8-01-size-208x208.ivf.md5"
+    "av1-1-b8-01-size-208x210.ivf"
+    "av1-1-b8-01-size-208x210.ivf.md5"
+    "av1-1-b8-01-size-208x224.ivf"
+    "av1-1-b8-01-size-208x224.ivf.md5"
+    "av1-1-b8-01-size-208x226.ivf"
+    "av1-1-b8-01-size-208x226.ivf.md5"
+    "av1-1-b8-01-size-210x196.ivf"
+    "av1-1-b8-01-size-210x196.ivf.md5"
+    "av1-1-b8-01-size-210x198.ivf"
+    "av1-1-b8-01-size-210x198.ivf.md5"
+    "av1-1-b8-01-size-210x200.ivf"
+    "av1-1-b8-01-size-210x200.ivf.md5"
+    "av1-1-b8-01-size-210x202.ivf"
+    "av1-1-b8-01-size-210x202.ivf.md5"
+    "av1-1-b8-01-size-210x208.ivf"
+    "av1-1-b8-01-size-210x208.ivf.md5"
+    "av1-1-b8-01-size-210x210.ivf"
+    "av1-1-b8-01-size-210x210.ivf.md5"
+    "av1-1-b8-01-size-210x224.ivf"
+    "av1-1-b8-01-size-210x224.ivf.md5"
+    "av1-1-b8-01-size-210x226.ivf"
+    "av1-1-b8-01-size-210x226.ivf.md5"
+    "av1-1-b8-01-size-224x196.ivf"
+    "av1-1-b8-01-size-224x196.ivf.md5"
+    "av1-1-b8-01-size-224x198.ivf"
+    "av1-1-b8-01-size-224x198.ivf.md5"
+    "av1-1-b8-01-size-224x200.ivf"
+    "av1-1-b8-01-size-224x200.ivf.md5"
+    "av1-1-b8-01-size-224x202.ivf"
+    "av1-1-b8-01-size-224x202.ivf.md5"
+    "av1-1-b8-01-size-224x208.ivf"
+    "av1-1-b8-01-size-224x208.ivf.md5"
+    "av1-1-b8-01-size-224x210.ivf"
+    "av1-1-b8-01-size-224x210.ivf.md5"
+    "av1-1-b8-01-size-224x224.ivf"
+    "av1-1-b8-01-size-224x224.ivf.md5"
+    "av1-1-b8-01-size-224x226.ivf"
+    "av1-1-b8-01-size-224x226.ivf.md5"
+    "av1-1-b8-01-size-226x196.ivf"
+    "av1-1-b8-01-size-226x196.ivf.md5"
+    "av1-1-b8-01-size-226x198.ivf"
+    "av1-1-b8-01-size-226x198.ivf.md5"
+    "av1-1-b8-01-size-226x200.ivf"
+    "av1-1-b8-01-size-226x200.ivf.md5"
+    "av1-1-b8-01-size-226x202.ivf"
+    "av1-1-b8-01-size-226x202.ivf.md5"
+    "av1-1-b8-01-size-226x208.ivf"
+    "av1-1-b8-01-size-226x208.ivf.md5"
+    "av1-1-b8-01-size-226x210.ivf"
+    "av1-1-b8-01-size-226x210.ivf.md5"
+    "av1-1-b8-01-size-226x224.ivf"
+    "av1-1-b8-01-size-226x224.ivf.md5"
+    "av1-1-b8-01-size-226x226.ivf"
+    "av1-1-b8-01-size-226x226.ivf.md5"
+    "av1-1-b8-01-size-32x16.ivf"
+    "av1-1-b8-01-size-32x16.ivf.md5"
+    "av1-1-b8-01-size-32x18.ivf"
+    "av1-1-b8-01-size-32x18.ivf.md5"
+    "av1-1-b8-01-size-32x32.ivf"
+    "av1-1-b8-01-size-32x32.ivf.md5"
+    "av1-1-b8-01-size-32x34.ivf"
+    "av1-1-b8-01-size-32x34.ivf.md5"
+    "av1-1-b8-01-size-32x64.ivf"
+    "av1-1-b8-01-size-32x64.ivf.md5"
+    "av1-1-b8-01-size-32x66.ivf"
+    "av1-1-b8-01-size-32x66.ivf.md5"
+    "av1-1-b8-01-size-34x16.ivf"
+    "av1-1-b8-01-size-34x16.ivf.md5"
+    "av1-1-b8-01-size-34x18.ivf"
+    "av1-1-b8-01-size-34x18.ivf.md5"
+    "av1-1-b8-01-size-34x32.ivf"
+    "av1-1-b8-01-size-34x32.ivf.md5"
+    "av1-1-b8-01-size-34x34.ivf"
+    "av1-1-b8-01-size-34x34.ivf.md5"
+    "av1-1-b8-01-size-34x64.ivf"
+    "av1-1-b8-01-size-34x64.ivf.md5"
+    "av1-1-b8-01-size-34x66.ivf"
+    "av1-1-b8-01-size-34x66.ivf.md5"
+    "av1-1-b8-01-size-64x16.ivf"
+    "av1-1-b8-01-size-64x16.ivf.md5"
+    "av1-1-b8-01-size-64x18.ivf"
+    "av1-1-b8-01-size-64x18.ivf.md5"
+    "av1-1-b8-01-size-64x32.ivf"
+    "av1-1-b8-01-size-64x32.ivf.md5"
+    "av1-1-b8-01-size-64x34.ivf"
+    "av1-1-b8-01-size-64x34.ivf.md5"
+    "av1-1-b8-01-size-64x64.ivf"
+    "av1-1-b8-01-size-64x64.ivf.md5"
+    "av1-1-b8-01-size-64x66.ivf"
+    "av1-1-b8-01-size-64x66.ivf.md5"
+    "av1-1-b8-01-size-66x16.ivf"
+    "av1-1-b8-01-size-66x16.ivf.md5"
+    "av1-1-b8-01-size-66x18.ivf"
+    "av1-1-b8-01-size-66x18.ivf.md5"
+    "av1-1-b8-01-size-66x32.ivf"
+    "av1-1-b8-01-size-66x32.ivf.md5"
+    "av1-1-b8-01-size-66x34.ivf"
+    "av1-1-b8-01-size-66x34.ivf.md5"
+    "av1-1-b8-01-size-66x64.ivf"
+    "av1-1-b8-01-size-66x64.ivf.md5"
+    "av1-1-b8-01-size-66x66.ivf"
+    "av1-1-b8-01-size-66x66.ivf.md5"
+    "av1-1-b8-02-allintra.ivf"
+    "av1-1-b8-02-allintra.ivf.md5"
+    "av1-1-b8-03-sizeup.mkv"
+    "av1-1-b8-03-sizeup.mkv.md5"
+    "av1-1-b8-03-sizedown.mkv"
+    "av1-1-b8-03-sizedown.mkv.md5"
+    "av1-1-b8-04-cdfupdate.ivf"
+    "av1-1-b8-04-cdfupdate.ivf.md5"
+    "av1-1-b8-05-mv.ivf"
+    "av1-1-b8-05-mv.ivf.md5"
+    "av1-1-b8-06-mfmv.ivf"
+    "av1-1-b8-06-mfmv.ivf.md5"
+    "av1-1-b8-22-svc-L2T1.ivf"
+    "av1-1-b8-22-svc-L2T1.ivf.md5"
+    "av1-1-b8-22-svc-L1T2.ivf"
+    "av1-1-b8-22-svc-L1T2.ivf.md5"
+    "av1-1-b8-22-svc-L2T2.ivf"
+    "av1-1-b8-22-svc-L2T2.ivf.md5"
+    "av1-1-b8-23-film_grain-50.ivf"
+    "av1-1-b8-23-film_grain-50.ivf.md5"
+    "invalid-bug-1814.ivf"
+    "invalid-bug-1814.ivf.res"
+    "invalid-chromium-906381.ivf"
+    "invalid-chromium-906381.ivf.res"
+    "invalid-google-142530197-1.ivf"
+    "invalid-google-142530197-1.ivf.res"
+    "invalid-google-142530197.ivf"
+    "invalid-google-142530197.ivf.res"
+    "invalid-oss-fuzz-10061.ivf"
+    "invalid-oss-fuzz-10061.ivf.res"
+    "invalid-oss-fuzz-10117-mc-buf-use-highbd.ivf"
+    "invalid-oss-fuzz-10117-mc-buf-use-highbd.ivf.res"
+    "invalid-oss-fuzz-10227.ivf"
+    "invalid-oss-fuzz-10227.ivf.res"
+    "invalid-oss-fuzz-10389.ivf"
+    "invalid-oss-fuzz-10389.ivf.res"
+    "invalid-oss-fuzz-10389.ivf.res.2"
+    "invalid-oss-fuzz-10555.ivf"
+    "invalid-oss-fuzz-10555.ivf.res"
+    "invalid-oss-fuzz-10705.ivf"
+    "invalid-oss-fuzz-10705.ivf.res"
+    "invalid-oss-fuzz-10723.ivf"
+    "invalid-oss-fuzz-10723.ivf.res"
+    "invalid-oss-fuzz-10723.ivf.res.2"
+    "invalid-oss-fuzz-10779.ivf"
+    "invalid-oss-fuzz-10779.ivf.res"
+    "invalid-oss-fuzz-11477.ivf"
+    "invalid-oss-fuzz-11477.ivf.res"
+    "invalid-oss-fuzz-11479.ivf"
+    "invalid-oss-fuzz-11479.ivf.res"
+    "invalid-oss-fuzz-11479.ivf.res.2"
+    "invalid-oss-fuzz-11523.ivf"
+    "invalid-oss-fuzz-11523.ivf.res"
+    "invalid-oss-fuzz-11523.ivf.res.2"
+    "invalid-oss-fuzz-15363.ivf"
+    "invalid-oss-fuzz-15363.ivf.res"
+    "invalid-oss-fuzz-16437.ivf"
+    "invalid-oss-fuzz-16437.ivf.res"
+    "invalid-oss-fuzz-9288.ivf"
+    "invalid-oss-fuzz-9288.ivf.res"
+    "invalid-oss-fuzz-9463.ivf"
+    "invalid-oss-fuzz-9463.ivf.res"
+    "invalid-oss-fuzz-9463.ivf.res.2"
+    "invalid-oss-fuzz-9482.ivf"
+    "invalid-oss-fuzz-9482.ivf.res"
+    "invalid-oss-fuzz-9720.ivf"
+    "invalid-oss-fuzz-9720.ivf.res")
 endif()
 
 if(ENABLE_ENCODE_PERF_TESTS AND CONFIG_AV1_ENCODER)
-  list(APPEND AOM_TEST_DATA_FILE_NAMES "desktop_640_360_30.yuv"
-              "kirland_640_480_30.yuv" "macmarcomoving_640_480_30.yuv"
-              "macmarcostationary_640_480_30.yuv" "niklas_1280_720_30.yuv"
-              "tacomanarrows_640_480_30.yuv"
-              "tacomasmallcameramovement_640_480_30.yuv"
-              "thaloundeskmtg_640_480_30.yuv")
+  list(
+    APPEND
+    AOM_TEST_DATA_FILE_NAMES
+    "desktop_640_360_30.yuv"
+    "kirland_640_480_30.yuv"
+    "macmarcomoving_640_480_30.yuv"
+    "macmarcostationary_640_480_30.yuv"
+    "niklas_1280_720_30.yuv"
+    "tacomanarrows_640_480_30.yuv"
+    "tacomasmallcameramovement_640_480_30.yuv"
+    "thaloundeskmtg_640_480_30.yuv")
 endif()
 
 # Parses test/test-data.sha1 and writes captured file names and checksums to
@@ -607,12 +616,18 @@
 
   list(LENGTH filenames num_files)
   list(LENGTH checksums num_checksums)
-  if(NOT checksums OR NOT filenames OR NOT num_files EQUAL num_checksums)
+  if(NOT checksums
+     OR NOT filenames
+     OR NOT num_files EQUAL num_checksums)
     message(FATAL_ERROR "Parsing of ${test_data_file} failed.")
   endif()
 
-  set(${out_checksums} ${checksums} PARENT_SCOPE)
-  set(${out_files} ${filenames} PARENT_SCOPE)
+  set(${out_checksums}
+      ${checksums}
+      PARENT_SCOPE)
+  set(${out_files}
+      ${filenames}
+      PARENT_SCOPE)
 endfunction()
 
 # Appends each file name in $test_files to $test_dir and adds the result path to
@@ -621,21 +636,27 @@
   foreach(filename ${${test_files}})
     set(path_list ${path_list} "${test_dir}/${filename}")
   endforeach()
-  set(${out_path_list} ${path_list} PARENT_SCOPE)
+  set(${out_path_list}
+      ${path_list}
+      PARENT_SCOPE)
 endfunction()
 
 function(check_file local_path expected_checksum out_needs_update)
   if(EXISTS "${local_path}")
     file(SHA1 "${local_path}" file_checksum)
   else()
-    set(${out_needs_update} 1 PARENT_SCOPE)
+    set(${out_needs_update}
+        1
+        PARENT_SCOPE)
     return()
   endif()
 
   if("${file_checksum}" STREQUAL "${expected_checksum}")
     unset(${out_needs_update} PARENT_SCOPE)
   else()
-    set(${out_needs_update} 1 PARENT_SCOPE)
+    set(${out_needs_update}
+        1
+        PARENT_SCOPE)
     return()
   endif()
   message("${local_path} up to date.")
@@ -645,7 +666,9 @@
 # writes it to $local_path.
 function(download_test_file file_url file_checksum local_path)
   message("Downloading ${file_url} ...")
-  file(DOWNLOAD "${file_url}" "${local_path}" SHOW_PROGRESS EXPECTED_HASH
-                                              SHA1=${file_checksum})
+  file(
+    DOWNLOAD "${file_url}" "${local_path}"
+    SHOW_PROGRESS
+    EXPECTED_HASH SHA1=${file_checksum})
   message("Download of ${file_url} complete.")
 endfunction()
diff --git a/test/test_intra_pred_speed.cc b/test/test_intra_pred_speed.cc
index 2fb783d..7ad5e0b 100644
--- a/test/test_intra_pred_speed.cc
+++ b/test/test_intra_pred_speed.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 //  Test and time AOM intra-predictor functions
diff --git a/test/test_libaom.cc b/test/test_libaom.cc
index b55d762..4db050e 100644
--- a/test/test_libaom.cc
+++ b/test/test_libaom.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <string.h>
diff --git a/test/test_runner.cmake b/test/test_runner.cmake
index f0648d1..06895d0 100644
--- a/test/test_runner.cmake
+++ b/test/test_runner.cmake
@@ -1,12 +1,12 @@
 #
-# Copyright (c) 2017, Alliance for Open Media. All rights reserved
+# Copyright (c) 2021, Alliance for Open Media. All rights reserved
 #
-# This source code is subject to the terms of the BSD 2 Clause License and the
-# Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License was
-# not distributed with this source code in the LICENSE file, you can obtain it
-# at www.aomedia.org/license/software. If the Alliance for Open Media Patent
-# License 1.0 was not distributed with this source code in the PATENTS file, you
-# can obtain it at www.aomedia.org/license/patent.
+# This source code is subject to the terms of the BSD 3-Clause Clear License and
+# the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+# License was not distributed with this source code in the LICENSE file, you can
+# obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance
+# for Open Media Patent License 1.0 was not distributed with this source code in
+# the PATENTS file, you can obtain it at aomedia.org/license/patent-license/.
 #
 if(NOT GTEST_TOTAL_SHARDS
    OR "${GTEST_SHARD_INDEX}" STREQUAL ""
diff --git a/test/test_vector_test.cc b/test/test_vector_test.cc
index 12f606e..d4b4bc4 100644
--- a/test/test_vector_test.cc
+++ b/test/test_vector_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <cstdio>
@@ -99,11 +100,7 @@
 // The md5 checksums are computed for each frame in the video file. If md5
 // checksums match the correct md5 data, then the test is passed. Otherwise,
 // the test failed.
-#if !CONFIG_REMOVE_DIST_WTD_COMP && !CONFIG_REMOVE_DUAL_FILTER
-TEST_P(TestVectorTest, MD5Match) {
-#else
 TEST_P(TestVectorTest, DISABLED_MD5Match) {
-#endif  // !CONFIG_REMOVE_DIST_WTD_COMP && !CONFIG_REMOVE_DUAL_FILTER
   const DecodeParam input = GET_PARAM(1);
   const std::string filename = std::get<kFileName>(input);
   aom_codec_flags_t flags = 0;
diff --git a/test/test_vectors.cc b/test/test_vectors.cc
index 833ce56..15bd034 100644
--- a/test/test_vectors.cc
+++ b/test/test_vectors.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "test/test_vectors.h"
diff --git a/test/test_vectors.h b/test/test_vectors.h
index be37f6e..e5813a3 100644
--- a/test/test_vectors.h
+++ b/test/test_vectors.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_TEST_TEST_VECTORS_H_
diff --git a/test/tile_config_test.cc b/test/tile_config_test.cc
index e2b9edd..ed6a75f 100644
--- a/test/tile_config_test.cc
+++ b/test/tile_config_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "aom/aom_codec.h"
diff --git a/test/tile_independence_test.cc b/test/tile_independence_test.cc
index 668c338..d3d1847 100644
--- a/test/tile_independence_test.cc
+++ b/test/tile_independence_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <cstdio>
diff --git a/test/time_stamp_test.cc b/test/time_stamp_test.cc
index 4674516..78d30b2 100644
--- a/test/time_stamp_test.cc
+++ b/test/time_stamp_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2019, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 //  Test AOM timestamp handling
diff --git a/test/tools_common.sh b/test/tools_common.sh
index 9646e50..09b3f24 100755
--- a/test/tools_common.sh
+++ b/test/tools_common.sh
@@ -1,12 +1,12 @@
 #!/bin/sh
-## Copyright (c) 2016, Alliance for Open Media. All rights reserved
+## Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ##
-## This source code is subject to the terms of the BSD 2 Clause License and
-## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-## was not distributed with this source code in the LICENSE file, you can
-## obtain it at www.aomedia.org/license/software. If the Alliance for Open
-## Media Patent License 1.0 was not distributed with this source code in the
-## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+## This source code is subject to the terms of the BSD 3-Clause Clear License and the
+## Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+## not distributed with this source code in the LICENSE file, you can obtain it
+## at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+## License 1.0 was not distributed with this source code in the PATENTS file, you
+## can obtain it at aomedia.org/license/patent-license/.
 ##
 ##  This file contains shell code shared by test scripts for libaom tools.
 
diff --git a/test/transform_test_base.h b/test/transform_test_base.h
index 68f5cc7..91a39da 100644
--- a/test/transform_test_base.h
+++ b/test/transform_test_base.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_TEST_TRANSFORM_TEST_BASE_H_
diff --git a/test/twopass_encoder.sh b/test/twopass_encoder.sh
index 44e7327..d43338a 100755
--- a/test/twopass_encoder.sh
+++ b/test/twopass_encoder.sh
@@ -1,12 +1,12 @@
 #!/bin/sh
-## Copyright (c) 2016, Alliance for Open Media. All rights reserved
+## Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ##
-## This source code is subject to the terms of the BSD 2 Clause License and
-## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-## was not distributed with this source code in the LICENSE file, you can
-## obtain it at www.aomedia.org/license/software. If the Alliance for Open
-## Media Patent License 1.0 was not distributed with this source code in the
-## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+## This source code is subject to the terms of the BSD 3-Clause Clear License and the
+## Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+## not distributed with this source code in the LICENSE file, you can obtain it
+## at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+## License 1.0 was not distributed with this source code in the PATENTS file, you
+## can obtain it at aomedia.org/license/patent-license/.
 ##
 ## This file tests the libaom twopass_encoder example. To add new tests to this
 ## file, do the following:
diff --git a/test/util.h b/test/util.h
index ef9f92d..e311207 100644
--- a/test/util.h
+++ b/test/util.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_TEST_UTIL_H_
diff --git a/test/variance_test.cc b/test/variance_test.cc
index e566f8f..e149f4d 100644
--- a/test/variance_test.cc
+++ b/test/variance_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <cstdlib>
diff --git a/test/video_source.h b/test/video_source.h
index 3c1c5e5..0842a7f 100644
--- a/test/video_source.h
+++ b/test/video_source.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #ifndef AOM_TEST_VIDEO_SOURCE_H_
 #define AOM_TEST_VIDEO_SOURCE_H_
diff --git a/test/visual_metrics.py b/test/visual_metrics.py
index 9055feb..19e5590 100755
--- a/test/visual_metrics.py
+++ b/test/visual_metrics.py
@@ -1,13 +1,13 @@
 #!/usr/bin/python
 #
-# Copyright (c) 2016, Alliance for Open Media. All rights reserved
+# Copyright (c) 2021, Alliance for Open Media. All rights reserved
 #
-# This source code is subject to the terms of the BSD 2 Clause License and
-# the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-# was not distributed with this source code in the LICENSE file, you can
-# obtain it at www.aomedia.org/license/software. If the Alliance for Open
-# Media Patent License 1.0 was not distributed with this source code in the
-# PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+# This source code is subject to the terms of the BSD 3-Clause Clear License and the
+# Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+# not distributed with this source code in the LICENSE file, you can obtain it
+# at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+# License 1.0 was not distributed with this source code in the PATENTS file, you
+# can obtain it at aomedia.org/license/patent-license/.
 #
 
 """Converts video encoding result data from text files to visualization
diff --git a/test/warp_filter_test.cc b/test/warp_filter_test.cc
index 2816718..3bf14df 100644
--- a/test/warp_filter_test.cc
+++ b/test/warp_filter_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #include <tuple>
 
diff --git a/test/warp_filter_test_util.cc b/test/warp_filter_test_util.cc
index ba3c1df..f7ee1e5 100644
--- a/test/warp_filter_test_util.cc
+++ b/test/warp_filter_test_util.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #include "aom_ports/aom_timer.h"
 #include "test/warp_filter_test_util.h"
diff --git a/test/warp_filter_test_util.h b/test/warp_filter_test_util.h
index 51169fb..09c9070 100644
--- a/test/warp_filter_test_util.h
+++ b/test/warp_filter_test_util.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_TEST_WARP_FILTER_TEST_UTIL_H_
diff --git a/test/webm_video_source.h b/test/webm_video_source.h
index bb3d117..0f4755a 100644
--- a/test/webm_video_source.h
+++ b/test/webm_video_source.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #ifndef AOM_TEST_WEBM_VIDEO_SOURCE_H_
 #define AOM_TEST_WEBM_VIDEO_SOURCE_H_
diff --git a/test/webmenc_test.cc b/test/webmenc_test.cc
index c028f22..0fbd1e7 100644
--- a/test/webmenc_test.cc
+++ b/test/webmenc_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <string>
diff --git a/test/wiener_test.cc b/test/wiener_test.cc
index 9242887..c067573 100644
--- a/test/wiener_test.cc
+++ b/test/wiener_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <tuple>
@@ -272,12 +273,12 @@
 
 INSTANTIATE_TEST_SUITE_P(C, WienerTest, ::testing::Values(compute_stats_opt_c));
 
-#if HAVE_SSE4_1
+#if HAVE_SSE4_1 && !CONFIG_EXCLUDE_SIMD_MISMATCH
 INSTANTIATE_TEST_SUITE_P(SSE4_1, WienerTest,
                          ::testing::Values(av1_compute_stats_sse4_1));
 #endif  // HAVE_SSE4_1
 
-#if HAVE_AVX2
+#if HAVE_AVX2 && !CONFIG_EXCLUDE_SIMD_MISMATCH
 
 INSTANTIATE_TEST_SUITE_P(AVX2, WienerTest,
                          ::testing::Values(av1_compute_stats_avx2));
@@ -572,12 +573,12 @@
 INSTANTIATE_TEST_SUITE_P(C, WienerTestHighbd,
                          ::testing::Values(compute_stats_highbd_opt_c));
 
-#if HAVE_SSE4_1
+#if HAVE_SSE4_1 && !CONFIG_EXCLUDE_SIMD_MISMATCH
 INSTANTIATE_TEST_SUITE_P(SSE4_1, WienerTestHighbd,
                          ::testing::Values(av1_compute_stats_highbd_sse4_1));
 #endif  // HAVE_SSE4_1
 
-#if HAVE_AVX2
+#if HAVE_AVX2 && !CONFIG_EXCLUDE_SIMD_MISMATCH
 INSTANTIATE_TEST_SUITE_P(AVX2, WienerTestHighbd,
                          ::testing::Values(av1_compute_stats_highbd_avx2));
 #endif  // HAVE_AVX2
diff --git a/test/y4m_test.cc b/test/y4m_test.cc
index aac4a72..9e68ddd 100644
--- a/test/y4m_test.cc
+++ b/test/y4m_test.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <string>
diff --git a/test/y4m_video_source.h b/test/y4m_video_source.h
index 63f74f5..81b1deb 100644
--- a/test/y4m_video_source.h
+++ b/test/y4m_video_source.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #ifndef AOM_TEST_Y4M_VIDEO_SOURCE_H_
 #define AOM_TEST_Y4M_VIDEO_SOURCE_H_
diff --git a/test/yuv_video_source.h b/test/yuv_video_source.h
index 774ecc0..cef6a4a 100644
--- a/test/yuv_video_source.h
+++ b/test/yuv_video_source.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #ifndef AOM_TEST_YUV_VIDEO_SOURCE_H_
 #define AOM_TEST_YUV_VIDEO_SOURCE_H_
diff --git a/third_party/libyuv/include/libyuv/basic_types.h b/third_party/libyuv/include/libyuv/basic_types.h
index 66e6853..aaa443f 100644
--- a/third_party/libyuv/include/libyuv/basic_types.h
+++ b/third_party/libyuv/include/libyuv/basic_types.h
@@ -1,12 +1,12 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License and the
+ * Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+ * not distributed with this source code in the LICENSE file, you can obtain it
+ * at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+ * License 1.0 was not distributed with this source code in the PATENTS file, you
+ * can obtain it at aomedia.org/license/patent-license/.
  */
 
 #ifndef INCLUDE_LIBYUV_BASIC_TYPES_H_  // NOLINT
diff --git a/third_party/libyuv/include/libyuv/compare.h b/third_party/libyuv/include/libyuv/compare.h
index 2a9f156..6ca2c75 100644
--- a/third_party/libyuv/include/libyuv/compare.h
+++ b/third_party/libyuv/include/libyuv/compare.h
@@ -1,12 +1,12 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License and the
+ * Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+ * not distributed with this source code in the LICENSE file, you can obtain it
+ * at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+ * License 1.0 was not distributed with this source code in the PATENTS file, you
+ * can obtain it at aomedia.org/license/patent-license/.
  */
 
 #ifndef INCLUDE_LIBYUV_COMPARE_H_  // NOLINT
diff --git a/third_party/libyuv/include/libyuv/convert.h b/third_party/libyuv/include/libyuv/convert.h
index d6f206c..fc6fc77 100644
--- a/third_party/libyuv/include/libyuv/convert.h
+++ b/third_party/libyuv/include/libyuv/convert.h
@@ -1,12 +1,12 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License and the
+ * Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+ * not distributed with this source code in the LICENSE file, you can obtain it
+ * at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+ * License 1.0 was not distributed with this source code in the PATENTS file, you
+ * can obtain it at aomedia.org/license/patent-license/.
  */
 
 #ifndef INCLUDE_LIBYUV_CONVERT_H_  // NOLINT
diff --git a/third_party/libyuv/include/libyuv/convert_argb.h b/third_party/libyuv/include/libyuv/convert_argb.h
index ea75c0b..f58d5e5 100644
--- a/third_party/libyuv/include/libyuv/convert_argb.h
+++ b/third_party/libyuv/include/libyuv/convert_argb.h
@@ -1,12 +1,12 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License and the
+ * Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+ * not distributed with this source code in the LICENSE file, you can obtain it
+ * at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+ * License 1.0 was not distributed with this source code in the PATENTS file, you
+ * can obtain it at aomedia.org/license/patent-license/.
  */
 
 #ifndef INCLUDE_LIBYUV_CONVERT_ARGB_H_  // NOLINT
diff --git a/third_party/libyuv/include/libyuv/convert_from.h b/third_party/libyuv/include/libyuv/convert_from.h
index 3591b4f..bd94392 100644
--- a/third_party/libyuv/include/libyuv/convert_from.h
+++ b/third_party/libyuv/include/libyuv/convert_from.h
@@ -1,12 +1,12 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License and the
+ * Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+ * not distributed with this source code in the LICENSE file, you can obtain it
+ * at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+ * License 1.0 was not distributed with this source code in the PATENTS file, you
+ * can obtain it at aomedia.org/license/patent-license/.
  */
 
 #ifndef INCLUDE_LIBYUV_CONVERT_FROM_H_  // NOLINT
diff --git a/third_party/libyuv/include/libyuv/convert_from_argb.h b/third_party/libyuv/include/libyuv/convert_from_argb.h
index 4a62268..96283d1 100644
--- a/third_party/libyuv/include/libyuv/convert_from_argb.h
+++ b/third_party/libyuv/include/libyuv/convert_from_argb.h
@@ -1,12 +1,12 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License and the
+ * Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+ * not distributed with this source code in the LICENSE file, you can obtain it
+ * at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+ * License 1.0 was not distributed with this source code in the PATENTS file, you
+ * can obtain it at aomedia.org/license/patent-license/.
  */
 
 #ifndef INCLUDE_LIBYUV_CONVERT_FROM_ARGB_H_  // NOLINT
diff --git a/third_party/libyuv/include/libyuv/cpu_id.h b/third_party/libyuv/include/libyuv/cpu_id.h
index 870e94e..f8b8bdb 100644
--- a/third_party/libyuv/include/libyuv/cpu_id.h
+++ b/third_party/libyuv/include/libyuv/cpu_id.h
@@ -1,12 +1,12 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License and the
+ * Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+ * not distributed with this source code in the LICENSE file, you can obtain it
+ * at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+ * License 1.0 was not distributed with this source code in the PATENTS file, you
+ * can obtain it at aomedia.org/license/patent-license/.
  */
 
 #ifndef INCLUDE_LIBYUV_CPU_ID_H_  // NOLINT
diff --git a/third_party/libyuv/include/libyuv/mjpeg_decoder.h b/third_party/libyuv/include/libyuv/mjpeg_decoder.h
index fa1e51f..a7aa674 100644
--- a/third_party/libyuv/include/libyuv/mjpeg_decoder.h
+++ b/third_party/libyuv/include/libyuv/mjpeg_decoder.h
@@ -1,12 +1,12 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License and the
+ * Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+ * not distributed with this source code in the LICENSE file, you can obtain it
+ * at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+ * License 1.0 was not distributed with this source code in the PATENTS file, you
+ * can obtain it at aomedia.org/license/patent-license/.
  */
 
 #ifndef INCLUDE_LIBYUV_MJPEG_DECODER_H_  // NOLINT
diff --git a/third_party/libyuv/include/libyuv/planar_functions.h b/third_party/libyuv/include/libyuv/planar_functions.h
index 7fe4d8e..ff72787 100644
--- a/third_party/libyuv/include/libyuv/planar_functions.h
+++ b/third_party/libyuv/include/libyuv/planar_functions.h
@@ -1,12 +1,12 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License and the
+ * Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+ * not distributed with this source code in the LICENSE file, you can obtain it
+ * at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+ * License 1.0 was not distributed with this source code in the PATENTS file, you
+ * can obtain it at aomedia.org/license/patent-license/.
  */
 
 #ifndef INCLUDE_LIBYUV_PLANAR_FUNCTIONS_H_  // NOLINT
diff --git a/third_party/libyuv/include/libyuv/rotate.h b/third_party/libyuv/include/libyuv/rotate.h
index 8a9673f..5b62a9f 100644
--- a/third_party/libyuv/include/libyuv/rotate.h
+++ b/third_party/libyuv/include/libyuv/rotate.h
@@ -1,12 +1,12 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License and the
+ * Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+ * not distributed with this source code in the LICENSE file, you can obtain it
+ * at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+ * License 1.0 was not distributed with this source code in the PATENTS file, you
+ * can obtain it at aomedia.org/license/patent-license/.
  */
 
 #ifndef INCLUDE_LIBYUV_ROTATE_H_  // NOLINT
diff --git a/third_party/libyuv/include/libyuv/rotate_argb.h b/third_party/libyuv/include/libyuv/rotate_argb.h
index 2bdc8ec..f60a467 100644
--- a/third_party/libyuv/include/libyuv/rotate_argb.h
+++ b/third_party/libyuv/include/libyuv/rotate_argb.h
@@ -1,12 +1,12 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License and the
+ * Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+ * not distributed with this source code in the LICENSE file, you can obtain it
+ * at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+ * License 1.0 was not distributed with this source code in the PATENTS file, you
+ * can obtain it at aomedia.org/license/patent-license/.
  */
 
 #ifndef INCLUDE_LIBYUV_ROTATE_ARGB_H_  // NOLINT
diff --git a/third_party/libyuv/include/libyuv/rotate_row.h b/third_party/libyuv/include/libyuv/rotate_row.h
index d0bfbdd..020a3bb 100644
--- a/third_party/libyuv/include/libyuv/rotate_row.h
+++ b/third_party/libyuv/include/libyuv/rotate_row.h
@@ -1,12 +1,12 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License and the
+ * Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+ * not distributed with this source code in the LICENSE file, you can obtain it
+ * at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+ * License 1.0 was not distributed with this source code in the PATENTS file, you
+ * can obtain it at aomedia.org/license/patent-license/.
  */
 
 #ifndef INCLUDE_LIBYUV_ROTATE_ROW_H_  // NOLINT
diff --git a/third_party/libyuv/include/libyuv/row.h b/third_party/libyuv/include/libyuv/row.h
index 5c3187e..edd0a58 100644
--- a/third_party/libyuv/include/libyuv/row.h
+++ b/third_party/libyuv/include/libyuv/row.h
@@ -1,12 +1,12 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License and the
+ * Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+ * not distributed with this source code in the LICENSE file, you can obtain it
+ * at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+ * License 1.0 was not distributed with this source code in the PATENTS file, you
+ * can obtain it at aomedia.org/license/patent-license/.
  */
 
 #ifndef INCLUDE_LIBYUV_ROW_H_  // NOLINT
diff --git a/third_party/libyuv/include/libyuv/scale.h b/third_party/libyuv/include/libyuv/scale.h
index 3974aba..ee5bf73 100644
--- a/third_party/libyuv/include/libyuv/scale.h
+++ b/third_party/libyuv/include/libyuv/scale.h
@@ -1,12 +1,12 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License and the
+ * Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+ * not distributed with this source code in the LICENSE file, you can obtain it
+ * at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+ * License 1.0 was not distributed with this source code in the PATENTS file, you
+ * can obtain it at aomedia.org/license/patent-license/.
  */
 
 #ifndef INCLUDE_LIBYUV_SCALE_H_  // NOLINT
diff --git a/third_party/libyuv/include/libyuv/scale_argb.h b/third_party/libyuv/include/libyuv/scale_argb.h
index 2256383..19cc1cb 100644
--- a/third_party/libyuv/include/libyuv/scale_argb.h
+++ b/third_party/libyuv/include/libyuv/scale_argb.h
@@ -1,12 +1,12 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License and the
+ * Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+ * not distributed with this source code in the LICENSE file, you can obtain it
+ * at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+ * License 1.0 was not distributed with this source code in the PATENTS file, you
+ * can obtain it at aomedia.org/license/patent-license/.
  */
 
 #ifndef INCLUDE_LIBYUV_SCALE_ARGB_H_  // NOLINT
diff --git a/third_party/libyuv/include/libyuv/scale_row.h b/third_party/libyuv/include/libyuv/scale_row.h
index a46b5ce..be1d4d2 100644
--- a/third_party/libyuv/include/libyuv/scale_row.h
+++ b/third_party/libyuv/include/libyuv/scale_row.h
@@ -1,12 +1,12 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License and the
+ * Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+ * not distributed with this source code in the LICENSE file, you can obtain it
+ * at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+ * License 1.0 was not distributed with this source code in the PATENTS file, you
+ * can obtain it at aomedia.org/license/patent-license/.
  */
 
 #ifndef INCLUDE_LIBYUV_SCALE_ROW_H_  // NOLINT
diff --git a/third_party/libyuv/include/libyuv/version.h b/third_party/libyuv/include/libyuv/version.h
index 287b98e..662a057 100644
--- a/third_party/libyuv/include/libyuv/version.h
+++ b/third_party/libyuv/include/libyuv/version.h
@@ -1,12 +1,12 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License and the
+ * Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+ * not distributed with this source code in the LICENSE file, you can obtain it
+ * at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+ * License 1.0 was not distributed with this source code in the PATENTS file, you
+ * can obtain it at aomedia.org/license/patent-license/.
  */
 
 #ifndef INCLUDE_LIBYUV_VERSION_H_  // NOLINT
diff --git a/third_party/libyuv/include/libyuv/video_common.h b/third_party/libyuv/include/libyuv/video_common.h
index 7b0a19c..f52e969 100644
--- a/third_party/libyuv/include/libyuv/video_common.h
+++ b/third_party/libyuv/include/libyuv/video_common.h
@@ -1,12 +1,12 @@
 /*
- * Copyright (c) 2016, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License and the
+ * Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+ * not distributed with this source code in the LICENSE file, you can obtain it
+ * at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+ * License 1.0 was not distributed with this source code in the PATENTS file, you
+ * can obtain it at aomedia.org/license/patent-license/.
  */
 
 // Common definitions for video, including fourcc and VideoFormat.
diff --git a/tools/aggregate_entropy_stats.py b/tools/aggregate_entropy_stats.py
index 44a34c4..75167b7 100644
--- a/tools/aggregate_entropy_stats.py
+++ b/tools/aggregate_entropy_stats.py
@@ -1,12 +1,12 @@
 #!/usr/bin/env python
-## Copyright (c) 2017, Alliance for Open Media. All rights reserved
+## Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ##
-## This source code is subject to the terms of the BSD 2 Clause License and
-## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-## was not distributed with this source code in the LICENSE file, you can
-## obtain it at www.aomedia.org/license/software. If the Alliance for Open
-## Media Patent License 1.0 was not distributed with this source code in the
-## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+## This source code is subject to the terms of the BSD 3-Clause Clear License and the
+## Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+## not distributed with this source code in the LICENSE file, you can obtain it
+## at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+## License 1.0 was not distributed with this source code in the PATENTS file, you
+## can obtain it at aomedia.org/license/patent-license/.
 ##
 """Aggregate multiple entropy stats output which is written in 32-bit int.
 
diff --git a/tools/aom_entropy_optimizer.c b/tools/aom_entropy_optimizer.c
index ff5ab22..9913288 100644
--- a/tools/aom_entropy_optimizer.c
+++ b/tools/aom_entropy_optimizer.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 // This tool is a gadget for offline probability training.
@@ -423,15 +424,33 @@
                      "default_drl_cdf[DRL_MODE_CONTEXTS][CDF_SIZE(2)]");
 #endif  // CONFIG_NEW_INTER_MODES
 
+#if CONFIG_OPTFLOW_REFINEMENT
+  /* Optical flow MV refinement */
+  cts_each_dim[0] = INTER_COMPOUND_MODE_CONTEXTS;
+  cts_each_dim[1] = 2;
+  optimize_cdf_table(&fc.use_optflow[0][0], probsfile, 2, cts_each_dim,
+                     "static const aom_cdf_prob\ndefault_use_optflow_cdf"
+                     "[INTER_COMPOUND_MODE_CONTEXTS][CDF_SIZE(2)]");
+#endif  // CONFIG_OPTFLOW_REFINEMENT
+
   /* ext_inter experiment */
   /* New compound mode */
   cts_each_dim[0] = INTER_COMPOUND_MODE_CONTEXTS;
+#if CONFIG_OPTFLOW_REFINEMENT
+  cts_each_dim[1] = INTER_COMPOUND_REF_TYPES;
+  optimize_cdf_table(&fc.inter_compound_mode[0][0], probsfile, 2, cts_each_dim,
+                     "static const aom_cdf_prob\n"
+                     "default_inter_compound_mode_cdf"
+                     "[INTER_COMPOUND_MODE_CONTEXTS][CDF_SIZE("
+                     "INTER_COMPOUND_REF_TYPES)]");
+#else
   cts_each_dim[1] = INTER_COMPOUND_MODES;
   optimize_cdf_table(&fc.inter_compound_mode[0][0], probsfile, 2, cts_each_dim,
                      "static const aom_cdf_prob\n"
                      "default_inter_compound_mode_cdf"
                      "[INTER_COMPOUND_MODE_CONTEXTS][CDF_SIZE("
                      "INTER_COMPOUND_MODES)]");
+#endif  // CONFIG_OPTFLOW_REFINEMENT
 
   /* Interintra */
   cts_each_dim[0] = BLOCK_SIZE_GROUPS;
@@ -481,13 +500,22 @@
                      "default_obmc_cdf[BLOCK_SIZES_ALL][CDF_SIZE(2)]");
 
   /* Intra/inter flag */
-  cts_each_dim[0] = INTRA_INTER_CONTEXTS;
-  cts_each_dim[1] = 2;
+#if CONFIG_CONTEXT_DERIVATION
+  cts_each_dim[0] = INTRA_INTER_SKIP_TXFM_CONTEXTS;
+  cts_each_dim[1] = INTRA_INTER_CONTEXTS;
+  cts_each_dim[2] = 2;
   optimize_cdf_table(
-      &fc.intra_inter[0][0], probsfile, 2, cts_each_dim,
+      &fc.intra_inter[0][0][0], probsfile, 3, cts_each_dim,
       "static const aom_cdf_prob\n"
       "default_intra_inter_cdf[INTRA_INTER_CONTEXTS][CDF_SIZE(2)]");
-
+#else
+  cts_each_dim[0] = INTRA_INTER_CONTEXTS;
+  cts_each_dim[1] = 2;
+  optimize_cdf_table(&fc.intra_inter[0][0], probsfile, 2, cts_each_dim,
+                     "static const aom_cdf_prob\n"
+                     "default_intra_inter_cdf[INTRA_INTER_SKIP_TXFM_CONTEXTS]["
+                     "INTRA_INTER_CONTEXTS][CDF_SIZE(2)]");
+#endif  // CONFIG_CONTEXT_DERIVATION
   /* Single/comp ref flag */
   cts_each_dim[0] = COMP_INTER_CONTEXTS;
   cts_each_dim[1] = 2;
@@ -497,6 +525,7 @@
       "default_comp_inter_cdf[COMP_INTER_CONTEXTS][CDF_SIZE(2)]");
 
   /* ext_comp_refs experiment */
+#if !CONFIG_NEW_REF_SIGNALING
   cts_each_dim[0] = COMP_REF_TYPE_CONTEXTS;
   cts_each_dim[1] = 2;
   optimize_cdf_table(
@@ -511,8 +540,18 @@
                      "static const aom_cdf_prob\n"
                      "default_uni_comp_ref_cdf[UNI_COMP_REF_CONTEXTS][UNIDIR_"
                      "COMP_REFS - 1][CDF_SIZE(2)]");
+#endif  // !CONFIG_NEW_REF_SIGNALING
 
   /* Reference frame (single ref) */
+#if CONFIG_NEW_REF_SIGNALING
+  cts_each_dim[0] = REF_CONTEXTS;
+  cts_each_dim[1] = INTER_REFS_PER_FRAME - 1;
+  cts_each_dim[2] = 2;
+  optimize_cdf_table(&fc.single_ref[0][0][0], probsfile, 3, cts_each_dim,
+                     "static const aom_cdf_prob\n"
+                     "default_single_ref_cdf[REF_CONTEXTS][INTER_REFS_PER_"
+                     "FRAME - 1][CDF_SIZE(2)]");
+#else
   cts_each_dim[0] = REF_CONTEXTS;
   cts_each_dim[1] = SINGLE_REFS - 1;
   cts_each_dim[2] = 2;
@@ -520,8 +559,19 @@
       &fc.single_ref[0][0][0], probsfile, 3, cts_each_dim,
       "static const aom_cdf_prob\n"
       "default_single_ref_cdf[REF_CONTEXTS][SINGLE_REFS - 1][CDF_SIZE(2)]");
+#endif  // CONFIG_NEW_REF_SIGNALING
 
   /* ext_refs experiment */
+#if CONFIG_NEW_REF_SIGNALING
+  cts_each_dim[0] = REF_CONTEXTS;
+  cts_each_dim[1] = COMPREF_BIT_TYPES;
+  cts_each_dim[2] = INTER_REFS_PER_FRAME - 2;
+  cts_each_dim[3] = 2;
+  optimize_cdf_table(&fc.comp_ref[0][0][0][0], probsfile, 4, cts_each_dim,
+                     "static const aom_cdf_prob\n"
+                     "default_comp_ref_cdf[REF_CONTEXTS][COMPREF_BIT_TYPES]"
+                     "[INTER_REFS_PER_FRAME - 2][CDF_SIZE(2)]");
+#else
   cts_each_dim[0] = REF_CONTEXTS;
   cts_each_dim[1] = FWD_REFS - 1;
   cts_each_dim[2] = 2;
@@ -537,6 +587,7 @@
       &fc.comp_bwdref[0][0][0], probsfile, 3, cts_each_dim,
       "static const aom_cdf_prob\n"
       "default_comp_bwdref_cdf[REF_CONTEXTS][BWD_REFS - 1][CDF_SIZE(2)]");
+#endif  // !CONFIG_NEW_REF_SIGNALING
 
   /* palette */
   cts_each_dim[0] = PALATTE_BSIZE_CTXS;
@@ -608,13 +659,7 @@
                      "static const aom_cdf_prob "
                      "default_skip_mode_cdfs[SKIP_MODE_CONTEXTS][CDF_SIZE(2)]");
 
-  /* joint compound flag */
-  cts_each_dim[0] = COMP_INDEX_CONTEXTS;
-  cts_each_dim[1] = 2;
-  optimize_cdf_table(&fc.compound_index[0][0], probsfile, 2, cts_each_dim,
-                     "static const aom_cdf_prob default_compound_idx_cdfs"
-                     "[COMP_INDEX_CONTEXTS][CDF_SIZE(2)]");
-
+  /* joint compound group index */
   cts_each_dim[0] = COMP_GROUP_IDX_CONTEXTS;
   cts_each_dim[1] = 2;
   optimize_cdf_table(&fc.comp_group_idx[0][0], probsfile, 2, cts_each_dim,
@@ -678,6 +723,15 @@
                      "static const aom_cdf_prob "
                      "av1_default_txb_skip_cdfs[TOKEN_CDF_Q_CTXS][TX_SIZES]"
                      "[TXB_SKIP_CONTEXTS][CDF_SIZE(2)]");
+#if CONFIG_CONTEXT_DERIVATION
+  cts_each_dim[0] = TOKEN_CDF_Q_CTXS;
+  cts_each_dim[1] = V_TXB_SKIP_CONTEXTS;
+  cts_each_dim[2] = 2;
+  optimize_cdf_table(&fc.v_txb_skip[0][0][0], probsfile, 3, cts_each_dim,
+                     "static const aom_cdf_prob "
+                     "av1_default_v_txb_skip_cdfs[TOKEN_CDF_Q_CTXS]"
+                     "[V_TXB_SKIP_CONTEXTS][CDF_SIZE(2)]");
+#endif  // CONFIG_CONTEXT_DERIVATION
 
   cts_each_dim[0] = TOKEN_CDF_Q_CTXS;
   cts_each_dim[1] = TX_SIZES;
@@ -779,6 +833,34 @@
       "static const aom_cdf_prob av1_default_coeff_base_eob_multi_cdfs"
       "[TOKEN_CDF_Q_CTXS][TX_SIZES][PLANE_TYPES][SIG_COEF_CONTEXTS_EOB]"
       "[CDF_SIZE(NUM_BASE_LEVELS + 1)]");
+#if CONFIG_CONTEXT_DERIVATION
+  cts_each_dim[0] = TOKEN_CDF_Q_CTXS;
+  cts_each_dim[1] = PLANE_TYPES;
+  cts_each_dim[2] = DC_SIGN_CONTEXTS;
+  cts_each_dim[3] = 2;
+  optimize_cdf_table(&fc.dc_sign[0][0][0][0], probsfile, 4, cts_each_dim,
+                     "static const aom_cdf_prob av1_default_dc_sign_cdfs"
+                     "[TOKEN_CDF_Q_CTXS][PLANE_TYPES][DC_SIGN_CONTEXTS]"
+                     "[CDF_SIZE(2)]");
+
+  cts_each_dim[0] = TOKEN_CDF_Q_CTXS;
+  cts_each_dim[1] = CROSS_COMPONENT_CONTEXTS;
+  cts_each_dim[2] = DC_SIGN_CONTEXTS;
+  cts_each_dim[3] = 2;
+  optimize_cdf_table(
+      &fc.v_dc_sign[0][0][0][0], probsfile, 4, cts_each_dim,
+      "static const aom_cdf_prob av1_default_v_dc_sign_cdfs"
+      "[TOKEN_CDF_Q_CTXS][CROSS_COMPONENT_CONTEXTS][DC_SIGN_CONTEXTS]"
+      "[CDF_SIZE(2)]");
+
+  cts_each_dim[0] = TOKEN_CDF_Q_CTXS;
+  cts_each_dim[1] = CROSS_COMPONENT_CONTEXTS;
+  cts_each_dim[2] = 2;
+  optimize_cdf_table(&fc.v_ac_sign[0][0][0], probsfile, 3, cts_each_dim,
+                     "static const aom_cdf_prob av1_default_v_ac_sign_cdfs"
+                     "[TOKEN_CDF_Q_CTXS][CROSS_COMPONENT_CONTEXTS]"
+                     "[CDF_SIZE(2)]");
+#endif  // CONFIG_CONTEXT_DERIVATION
 
   fclose(statsfile);
   fclose(logfile);
diff --git a/tools/convexhull_framework/src/AV2CTCProgress.py b/tools/convexhull_framework/src/AV2CTCProgress.py
index d5518e9..c1c1401 100644
--- a/tools/convexhull_framework/src/AV2CTCProgress.py
+++ b/tools/convexhull_framework/src/AV2CTCProgress.py
@@ -1,12 +1,12 @@
 #!/usr/bin/env python
-## Copyright (c) 2019, Alliance for Open Media. All rights reserved
+## Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ##
-## This source code is subject to the terms of the BSD 2 Clause License and
-## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-## was not distributed with this source code in the LICENSE file, you can
-## obtain it at www.aomedia.org/license/software. If the Alliance for Open
-## Media Patent License 1.0 was not distributed with this source code in the
-## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+## This source code is subject to the terms of the BSD 3-Clause Clear License and the
+## Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+## not distributed with this source code in the LICENSE file, you can obtain it
+## at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+## License 1.0 was not distributed with this source code in the PATENTS file, you
+## can obtain it at aomedia.org/license/patent-license/.
 ##
 __author__ = "maggie.sun@intel.com, ryanlei@fb.com"
 
diff --git a/tools/convexhull_framework/src/AV2CTCTest.py b/tools/convexhull_framework/src/AV2CTCTest.py
index b4336d7..6f6b1bd 100644
--- a/tools/convexhull_framework/src/AV2CTCTest.py
+++ b/tools/convexhull_framework/src/AV2CTCTest.py
@@ -1,12 +1,12 @@
 #!/usr/bin/env python
-## Copyright (c) 2019, Alliance for Open Media. All rights reserved
+## Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ##
-## This source code is subject to the terms of the BSD 2 Clause License and
-## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-## was not distributed with this source code in the LICENSE file, you can
-## obtain it at www.aomedia.org/license/software. If the Alliance for Open
-## Media Patent License 1.0 was not distributed with this source code in the
-## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+## This source code is subject to the terms of the BSD 3-Clause Clear License and the
+## Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+## not distributed with this source code in the LICENSE file, you can obtain it
+## at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+## License 1.0 was not distributed with this source code in the PATENTS file, you
+## can obtain it at aomedia.org/license/patent-license/.
 ##
 __author__ = "maggie.sun@intel.com, ryanlei@fb.com"
 
diff --git a/tools/convexhull_framework/src/AV2CTCVideo.py b/tools/convexhull_framework/src/AV2CTCVideo.py
index 4555207..9bbb5d7 100644
--- a/tools/convexhull_framework/src/AV2CTCVideo.py
+++ b/tools/convexhull_framework/src/AV2CTCVideo.py
@@ -1,12 +1,12 @@
 #!/usr/bin/env python
-## Copyright (c) 2019, Alliance for Open Media. All rights reserved
+## Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ##
-## This source code is subject to the terms of the BSD 2 Clause License and
-## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-## was not distributed with this source code in the LICENSE file, you can
-## obtain it at www.aomedia.org/license/software. If the Alliance for Open
-## Media Patent License 1.0 was not distributed with this source code in the
-## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+## This source code is subject to the terms of the BSD 3-Clause Clear License and the
+## Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+## not distributed with this source code in the LICENSE file, you can obtain it
+## at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+## License 1.0 was not distributed with this source code in the PATENTS file, you
+## can obtain it at aomedia.org/license/patent-license/.
 ##
 __author__ = "maggie.sun@intel.com, ryanlei@fb.com"
 
diff --git a/tools/convexhull_framework/src/CalcBDRate.py b/tools/convexhull_framework/src/CalcBDRate.py
index 48c20ff..6e8ab90 100755
--- a/tools/convexhull_framework/src/CalcBDRate.py
+++ b/tools/convexhull_framework/src/CalcBDRate.py
@@ -1,12 +1,12 @@
 #!/usr/bin/env python
-## Copyright (c) 2019, Alliance for Open Media. All rights reserved
+## Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ##
-## This source code is subject to the terms of the BSD 2 Clause License and
-## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-## was not distributed with this source code in the LICENSE file, you can
-## obtain it at www.aomedia.org/license/software. If the Alliance for Open
-## Media Patent License 1.0 was not distributed with this source code in the
-## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+## This source code is subject to the terms of the BSD 3-Clause Clear License and the
+## Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+## not distributed with this source code in the LICENSE file, you can obtain it
+## at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+## License 1.0 was not distributed with this source code in the PATENTS file, you
+## can obtain it at aomedia.org/license/patent-license/.
 ##
 __author__ = "maggie.sun@intel.com, ryanlei@fb.com"
 
diff --git a/tools/convexhull_framework/src/CalcQtyWithVmafTool.py b/tools/convexhull_framework/src/CalcQtyWithVmafTool.py
index e2d2cc8..006a259 100644
--- a/tools/convexhull_framework/src/CalcQtyWithVmafTool.py
+++ b/tools/convexhull_framework/src/CalcQtyWithVmafTool.py
@@ -1,12 +1,12 @@
 #!/usr/bin/env python
-## Copyright (c) 2019, Alliance for Open Media. All rights reserved
+## Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ##
-## This source code is subject to the terms of the BSD 2 Clause License and
-## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-## was not distributed with this source code in the LICENSE file, you can
-## obtain it at www.aomedia.org/license/software. If the Alliance for Open
-## Media Patent License 1.0 was not distributed with this source code in the
-## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+## This source code is subject to the terms of the BSD 3-Clause Clear License and the
+## Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+## not distributed with this source code in the LICENSE file, you can obtain it
+## at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+## License 1.0 was not distributed with this source code in the PATENTS file, you
+## can obtain it at aomedia.org/license/patent-license/.
 ##
 __author__ = "maggie.sun@intel.com, ryanlei@fb.com"
 
diff --git a/tools/convexhull_framework/src/CalculateQualityMetrics.py b/tools/convexhull_framework/src/CalculateQualityMetrics.py
index 9bf586d..0f2cd48 100644
--- a/tools/convexhull_framework/src/CalculateQualityMetrics.py
+++ b/tools/convexhull_framework/src/CalculateQualityMetrics.py
@@ -1,12 +1,12 @@
 #!/usr/bin/env python
-## Copyright (c) 2019, Alliance for Open Media. All rights reserved
+## Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ##
-## This source code is subject to the terms of the BSD 2 Clause License and
-## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-## was not distributed with this source code in the LICENSE file, you can
-## obtain it at www.aomedia.org/license/software. If the Alliance for Open
-## Media Patent License 1.0 was not distributed with this source code in the
-## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+## This source code is subject to the terms of the BSD 3-Clause Clear License and the
+## Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+## not distributed with this source code in the LICENSE file, you can obtain it
+## at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+## License 1.0 was not distributed with this source code in the PATENTS file, you
+## can obtain it at aomedia.org/license/patent-license/.
 ##
 __author__ = "maggie.sun@intel.com, ryanlei@fb.com"
 
diff --git a/tools/convexhull_framework/src/Config.py b/tools/convexhull_framework/src/Config.py
index 93f6fb7..db42cc4 100644
--- a/tools/convexhull_framework/src/Config.py
+++ b/tools/convexhull_framework/src/Config.py
@@ -1,12 +1,12 @@
 #!/usr/bin/env python
-## Copyright (c) 2019, Alliance for Open Media. All rights reserved
+## Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ##
-## This source code is subject to the terms of the BSD 2 Clause License and
-## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-## was not distributed with this source code in the LICENSE file, you can
-## obtain it at www.aomedia.org/license/software. If the Alliance for Open
-## Media Patent License 1.0 was not distributed with this source code in the
-## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+## This source code is subject to the terms of the BSD 3-Clause Clear License and the
+## Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+## not distributed with this source code in the LICENSE file, you can obtain it
+## at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+## License 1.0 was not distributed with this source code in the PATENTS file, you
+## can obtain it at aomedia.org/license/patent-license/.
 ##
 __author__ = "maggie.sun@intel.com, ryanlei@fb.com"
 
diff --git a/tools/convexhull_framework/src/ConvexHullBDRate.py b/tools/convexhull_framework/src/ConvexHullBDRate.py
index 176dd7a..90bcf35 100644
--- a/tools/convexhull_framework/src/ConvexHullBDRate.py
+++ b/tools/convexhull_framework/src/ConvexHullBDRate.py
@@ -1,12 +1,12 @@
 #!/usr/bin/env python
-## Copyright (c) 2019, Alliance for Open Media. All rights reserved
+## Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ##
-## This source code is subject to the terms of the BSD 2 Clause License and
-## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-## was not distributed with this source code in the LICENSE file, you can
-## obtain it at www.aomedia.org/license/software. If the Alliance for Open
-## Media Patent License 1.0 was not distributed with this source code in the
-## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+## This source code is subject to the terms of the BSD 3-Clause Clear License and the
+## Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+## not distributed with this source code in the LICENSE file, you can obtain it
+## at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+## License 1.0 was not distributed with this source code in the PATENTS file, you
+## can obtain it at aomedia.org/license/patent-license/.
 ##
 __author__ = "maggie.sun@intel.com, ryanlei@fb.com"
 
diff --git a/tools/convexhull_framework/src/ConvexHullTest.py b/tools/convexhull_framework/src/ConvexHullTest.py
index d0b8f26..6c25ab5 100755
--- a/tools/convexhull_framework/src/ConvexHullTest.py
+++ b/tools/convexhull_framework/src/ConvexHullTest.py
@@ -1,12 +1,12 @@
 #!/usr/bin/env python
-## Copyright (c) 2019, Alliance for Open Media. All rights reserved
+## Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ##
-## This source code is subject to the terms of the BSD 2 Clause License and
-## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-## was not distributed with this source code in the LICENSE file, you can
-## obtain it at www.aomedia.org/license/software. If the Alliance for Open
-## Media Patent License 1.0 was not distributed with this source code in the
-## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+## This source code is subject to the terms of the BSD 3-Clause Clear License and the
+## Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+## not distributed with this source code in the LICENSE file, you can obtain it
+## at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+## License 1.0 was not distributed with this source code in the PATENTS file, you
+## can obtain it at aomedia.org/license/patent-license/.
 ##
 __author__ = "maggie.sun@intel.com, ryanlei@fb.com"
 
diff --git a/tools/convexhull_framework/src/EncDecUpscale.py b/tools/convexhull_framework/src/EncDecUpscale.py
index 010fad8..2d76031 100644
--- a/tools/convexhull_framework/src/EncDecUpscale.py
+++ b/tools/convexhull_framework/src/EncDecUpscale.py
@@ -1,12 +1,12 @@
 #!/usr/bin/env python
-## Copyright (c) 2019, Alliance for Open Media. All rights reserved
+## Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ##
-## This source code is subject to the terms of the BSD 2 Clause License and
-## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-## was not distributed with this source code in the LICENSE file, you can
-## obtain it at www.aomedia.org/license/software. If the Alliance for Open
-## Media Patent License 1.0 was not distributed with this source code in the
-## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+## This source code is subject to the terms of the BSD 3-Clause Clear License and the
+## Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+## not distributed with this source code in the LICENSE file, you can obtain it
+## at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+## License 1.0 was not distributed with this source code in the PATENTS file, you
+## can obtain it at aomedia.org/license/patent-license/.
 ##
 __author__ = "maggie.sun@intel.com, ryanlei@fb.com"
 
diff --git a/tools/convexhull_framework/src/PostAnalysis_Summary.py b/tools/convexhull_framework/src/PostAnalysis_Summary.py
index 3d2c786..c26bcfe 100644
--- a/tools/convexhull_framework/src/PostAnalysis_Summary.py
+++ b/tools/convexhull_framework/src/PostAnalysis_Summary.py
@@ -1,12 +1,12 @@
 #!/usr/bin/env python
-## Copyright (c) 2019, Alliance for Open Media. All rights reserved
+## Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ##
-## This source code is subject to the terms of the BSD 2 Clause License and
-## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-## was not distributed with this source code in the LICENSE file, you can
-## obtain it at www.aomedia.org/license/software. If the Alliance for Open
-## Media Patent License 1.0 was not distributed with this source code in the
-## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+## This source code is subject to the terms of the BSD 3-Clause Clear License and the
+## Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+## not distributed with this source code in the LICENSE file, you can obtain it
+## at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+## License 1.0 was not distributed with this source code in the PATENTS file, you
+## can obtain it at aomedia.org/license/patent-license/.
 ##
 __author__ = "maggie.sun@intel.com, ryanlei@fb.com"
 
diff --git a/tools/convexhull_framework/src/ScalingTest.py b/tools/convexhull_framework/src/ScalingTest.py
index 06e1986..ced704a 100644
--- a/tools/convexhull_framework/src/ScalingTest.py
+++ b/tools/convexhull_framework/src/ScalingTest.py
@@ -1,12 +1,12 @@
 #!/usr/bin/env python
-## Copyright (c) 2019, Alliance for Open Media. All rights reserved
+## Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ##
-## This source code is subject to the terms of the BSD 2 Clause License and
-## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-## was not distributed with this source code in the LICENSE file, you can
-## obtain it at www.aomedia.org/license/software. If the Alliance for Open
-## Media Patent License 1.0 was not distributed with this source code in the
-## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+## This source code is subject to the terms of the BSD 3-Clause Clear License and the
+## Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+## not distributed with this source code in the LICENSE file, you can obtain it
+## at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+## License 1.0 was not distributed with this source code in the PATENTS file, you
+## can obtain it at aomedia.org/license/patent-license/.
 ##
 __author__ = "maggie.sun@intel.com, ryanlei@fb.com"
 
diff --git a/tools/convexhull_framework/src/Utils.py b/tools/convexhull_framework/src/Utils.py
index fe4687d..b3d7bc4 100755
--- a/tools/convexhull_framework/src/Utils.py
+++ b/tools/convexhull_framework/src/Utils.py
@@ -1,12 +1,12 @@
 #!/usr/bin/env python
-## Copyright (c) 2019, Alliance for Open Media. All rights reserved
+## Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ##
-## This source code is subject to the terms of the BSD 2 Clause License and
-## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-## was not distributed with this source code in the LICENSE file, you can
-## obtain it at www.aomedia.org/license/software. If the Alliance for Open
-## Media Patent License 1.0 was not distributed with this source code in the
-## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+## This source code is subject to the terms of the BSD 3-Clause Clear License and the
+## Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+## not distributed with this source code in the LICENSE file, you can obtain it
+## at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+## License 1.0 was not distributed with this source code in the PATENTS file, you
+## can obtain it at aomedia.org/license/patent-license/.
 ##
 __author__ = "maggie.sun@intel.com, ryanlei@fb.com"
 
diff --git a/tools/convexhull_framework/src/VideoDecoder.py b/tools/convexhull_framework/src/VideoDecoder.py
index c8bcfe7..06ab8d6 100644
--- a/tools/convexhull_framework/src/VideoDecoder.py
+++ b/tools/convexhull_framework/src/VideoDecoder.py
@@ -1,12 +1,12 @@
 #!/usr/bin/env python
-## Copyright (c) 2019, Alliance for Open Media. All rights reserved
+## Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ##
-## This source code is subject to the terms of the BSD 2 Clause License and
-## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-## was not distributed with this source code in the LICENSE file, you can
-## obtain it at www.aomedia.org/license/software. If the Alliance for Open
-## Media Patent License 1.0 was not distributed with this source code in the
-## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+## This source code is subject to the terms of the BSD 3-Clause Clear License and the
+## Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+## not distributed with this source code in the LICENSE file, you can obtain it
+## at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+## License 1.0 was not distributed with this source code in the PATENTS file, you
+## can obtain it at aomedia.org/license/patent-license/.
 ##
 __author__ = "maggie.sun@intel.com, ryanlei@fb.com"
 
diff --git a/tools/convexhull_framework/src/VideoEncoder.py b/tools/convexhull_framework/src/VideoEncoder.py
index 1d285a1..dde54a3 100644
--- a/tools/convexhull_framework/src/VideoEncoder.py
+++ b/tools/convexhull_framework/src/VideoEncoder.py
@@ -1,12 +1,12 @@
 #!/usr/bin/env python
-## Copyright (c) 2019, Alliance for Open Media. All rights reserved
+## Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ##
-## This source code is subject to the terms of the BSD 2 Clause License and
-## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-## was not distributed with this source code in the LICENSE file, you can
-## obtain it at www.aomedia.org/license/software. If the Alliance for Open
-## Media Patent License 1.0 was not distributed with this source code in the
-## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+## This source code is subject to the terms of the BSD 3-Clause Clear License and the
+## Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+## not distributed with this source code in the LICENSE file, you can obtain it
+## at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+## License 1.0 was not distributed with this source code in the PATENTS file, you
+## can obtain it at aomedia.org/license/patent-license/.
 ##
 __author__ = "maggie.sun@intel.com, ryanlei@fb.com"
 
diff --git a/tools/convexhull_framework/src/VideoScaler.py b/tools/convexhull_framework/src/VideoScaler.py
index 54480e4..e3801d0 100644
--- a/tools/convexhull_framework/src/VideoScaler.py
+++ b/tools/convexhull_framework/src/VideoScaler.py
@@ -1,12 +1,12 @@
 #!/usr/bin/env python
-## Copyright (c) 2019, Alliance for Open Media. All rights reserved
+## Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ##
-## This source code is subject to the terms of the BSD 2 Clause License and
-## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-## was not distributed with this source code in the LICENSE file, you can
-## obtain it at www.aomedia.org/license/software. If the Alliance for Open
-## Media Patent License 1.0 was not distributed with this source code in the
-## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+## This source code is subject to the terms of the BSD 3-Clause Clear License and the
+## Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+## not distributed with this source code in the LICENSE file, you can obtain it
+## at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+## License 1.0 was not distributed with this source code in the PATENTS file, you
+## can obtain it at aomedia.org/license/patent-license/.
 ##
 __author__ = "maggie.sun@intel.com, ryanlei@fb.com"
 
diff --git a/tools/diff.py b/tools/diff.py
index bac6aab..bce64ab 100644
--- a/tools/diff.py
+++ b/tools/diff.py
@@ -1,13 +1,13 @@
 #!/usr/bin/env python
 ##
-## Copyright (c) 2016, Alliance for Open Media. All rights reserved
+## Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ##
-## This source code is subject to the terms of the BSD 2 Clause License and
-## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-## was not distributed with this source code in the LICENSE file, you can
-## obtain it at www.aomedia.org/license/software. If the Alliance for Open
-## Media Patent License 1.0 was not distributed with this source code in the
-## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+## This source code is subject to the terms of the BSD 3-Clause Clear License and the
+## Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+## not distributed with this source code in the LICENSE file, you can obtain it
+## at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+## License 1.0 was not distributed with this source code in the PATENTS file, you
+## can obtain it at aomedia.org/license/patent-license/.
 ##
 """Classes for representing diff pieces."""
 
diff --git a/tools/dump_obu.cc b/tools/dump_obu.cc
index 30ee5e7..d70729e 100644
--- a/tools/dump_obu.cc
+++ b/tools/dump_obu.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <stdlib.h>
diff --git a/tools/gen_constrained_tokenset.py b/tools/gen_constrained_tokenset.py
index 5d12ee1..e4664fa 100755
--- a/tools/gen_constrained_tokenset.py
+++ b/tools/gen_constrained_tokenset.py
@@ -1,13 +1,13 @@
 #!/usr/bin/python
 ##
-## Copyright (c) 2016, Alliance for Open Media. All rights reserved
+## Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ##
-## This source code is subject to the terms of the BSD 2 Clause License and
-## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-## was not distributed with this source code in the LICENSE file, you can
-## obtain it at www.aomedia.org/license/software. If the Alliance for Open
-## Media Patent License 1.0 was not distributed with this source code in the
-## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+## This source code is subject to the terms of the BSD 3-Clause Clear License and the
+## Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+## not distributed with this source code in the LICENSE file, you can obtain it
+## at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+## License 1.0 was not distributed with this source code in the PATENTS file, you
+## can obtain it at aomedia.org/license/patent-license/.
 ##
 """Generate the probability model for the constrained token set.
 
diff --git a/tools/intersect-diffs.py b/tools/intersect-diffs.py
index df13c4e..935233a 100755
--- a/tools/intersect-diffs.py
+++ b/tools/intersect-diffs.py
@@ -1,13 +1,13 @@
 #!/usr/bin/env python
 ##
-## Copyright (c) 2016, Alliance for Open Media. All rights reserved
+## Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ##
-## This source code is subject to the terms of the BSD 2 Clause License and
-## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-## was not distributed with this source code in the LICENSE file, you can
-## obtain it at www.aomedia.org/license/software. If the Alliance for Open
-## Media Patent License 1.0 was not distributed with this source code in the
-## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+## This source code is subject to the terms of the BSD 3-Clause Clear License and the
+## Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+## not distributed with this source code in the LICENSE file, you can obtain it
+## at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+## License 1.0 was not distributed with this source code in the PATENTS file, you
+## can obtain it at aomedia.org/license/patent-license/.
 ##
 """Calculates the "intersection" of two unified diffs.
 
diff --git a/tools/lanczos/lanczos_README.txt b/tools/lanczos/lanczos_README.txt
index 75b2da6..f191588 100644
--- a/tools/lanczos/lanczos_README.txt
+++ b/tools/lanczos/lanczos_README.txt
@@ -1,12 +1,12 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License and the
+ * Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+ * not distributed with this source code in the LICENSE file, you can obtain it
+ * at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+ * License 1.0 was not distributed with this source code in the PATENTS file, you
+ * can obtain it at aomedia.org/license/patent-license/.
  */
 
 The Lanczos resampling library and utilities are developed by Google
diff --git a/tools/lanczos/lanczos_resample.c b/tools/lanczos/lanczos_resample.c
index 801fcd0..d5765f3 100644
--- a/tools/lanczos/lanczos_resample.c
+++ b/tools/lanczos/lanczos_resample.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <stdio.h>
diff --git a/tools/lanczos/lanczos_resample.h b/tools/lanczos/lanczos_resample.h
index 3affb3e..8e89548 100644
--- a/tools/lanczos/lanczos_resample.h
+++ b/tools/lanczos/lanczos_resample.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <stdio.h>
diff --git a/tools/lanczos/lanczos_resample_filter.c b/tools/lanczos/lanczos_resample_filter.c
index b516baf..5133235 100644
--- a/tools/lanczos/lanczos_resample_filter.c
+++ b/tools/lanczos/lanczos_resample_filter.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <stdio.h>
diff --git a/tools/lanczos/lanczos_resample_y4m.c b/tools/lanczos/lanczos_resample_y4m.c
index 814e00b..d94bc14 100644
--- a/tools/lanczos/lanczos_resample_y4m.c
+++ b/tools/lanczos/lanczos_resample_y4m.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <stdio.h>
diff --git a/tools/lanczos/lanczos_resample_yuv.c b/tools/lanczos/lanczos_resample_yuv.c
index 422c397..77a5d26 100644
--- a/tools/lanczos/lanczos_resample_yuv.c
+++ b/tools/lanczos/lanczos_resample_yuv.c
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2020, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <stdio.h>
diff --git a/tools/lint-hunks.py b/tools/lint-hunks.py
index d02bee1..b08cceb 100755
--- a/tools/lint-hunks.py
+++ b/tools/lint-hunks.py
@@ -1,13 +1,13 @@
 #!/usr/bin/python
 ##
-## Copyright (c) 2016, Alliance for Open Media. All rights reserved
+## Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ##
-## This source code is subject to the terms of the BSD 2 Clause License and
-## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-## was not distributed with this source code in the LICENSE file, you can
-## obtain it at www.aomedia.org/license/software. If the Alliance for Open
-## Media Patent License 1.0 was not distributed with this source code in the
-## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+## This source code is subject to the terms of the BSD 3-Clause Clear License and the
+## Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+## not distributed with this source code in the LICENSE file, you can obtain it
+## at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+## License 1.0 was not distributed with this source code in the PATENTS file, you
+## can obtain it at aomedia.org/license/patent-license/.
 ##
 """Performs style checking on each diff hunk."""
 import getopt
diff --git a/tools/obu_parser.cc b/tools/obu_parser.cc
index 7d71386..2d78a81 100644
--- a/tools/obu_parser.cc
+++ b/tools/obu_parser.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 #include <string.h>
 
diff --git a/tools/obu_parser.h b/tools/obu_parser.h
index 1d7d2d7..f475251 100644
--- a/tools/obu_parser.h
+++ b/tools/obu_parser.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2017, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_TOOLS_OBU_PARSER_H_
diff --git a/tools/txfm_analyzer/txfm_gen_code.cc b/tools/txfm_analyzer/txfm_gen_code.cc
index 7c5400b..eb268c5 100644
--- a/tools/txfm_analyzer/txfm_gen_code.cc
+++ b/tools/txfm_analyzer/txfm_gen_code.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include <stdio.h>
diff --git a/tools/txfm_analyzer/txfm_graph.cc b/tools/txfm_analyzer/txfm_graph.cc
index a249061..75d0ecf 100644
--- a/tools/txfm_analyzer/txfm_graph.cc
+++ b/tools/txfm_analyzer/txfm_graph.cc
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #include "tools/txfm_analyzer/txfm_graph.h"
diff --git a/tools/txfm_analyzer/txfm_graph.h b/tools/txfm_analyzer/txfm_graph.h
index 8dc3614..16f0d73 100644
--- a/tools/txfm_analyzer/txfm_graph.h
+++ b/tools/txfm_analyzer/txfm_graph.h
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2018, Alliance for Open Media. All rights reserved
+ * Copyright (c) 2021, Alliance for Open Media. All rights reserved
  *
- * This source code is subject to the terms of the BSD 2 Clause License and
- * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
- * was not distributed with this source code in the LICENSE file, you can
- * obtain it at www.aomedia.org/license/software. If the Alliance for Open
- * Media Patent License 1.0 was not distributed with this source code in the
- * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ * This source code is subject to the terms of the BSD 3-Clause Clear License
+ * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
+ * License was not distributed with this source code in the LICENSE file, you
+ * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
+ * Alliance for Open Media Patent License 1.0 was not distributed with this
+ * source code in the PATENTS file, you can obtain it at
+ * aomedia.org/license/patent-license/.
  */
 
 #ifndef AOM_TOOLS_TXFM_ANALYZER_TXFM_GRAPH_H_
diff --git a/tools/wrap-commit-msg.py b/tools/wrap-commit-msg.py
index 1c78824..fd67a1c 100755
--- a/tools/wrap-commit-msg.py
+++ b/tools/wrap-commit-msg.py
@@ -1,13 +1,13 @@
 #!/usr/bin/env python
 ##
-## Copyright (c) 2016, Alliance for Open Media. All rights reserved
+## Copyright (c) 2021, Alliance for Open Media. All rights reserved
 ##
-## This source code is subject to the terms of the BSD 2 Clause License and
-## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
-## was not distributed with this source code in the LICENSE file, you can
-## obtain it at www.aomedia.org/license/software. If the Alliance for Open
-## Media Patent License 1.0 was not distributed with this source code in the
-## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+## This source code is subject to the terms of the BSD 3-Clause Clear License and the
+## Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License was
+## not distributed with this source code in the LICENSE file, you can obtain it
+## at aomedia.org/license/software-license/bsd-3-c-c/.  If the Alliance for Open Media Patent
+## License 1.0 was not distributed with this source code in the PATENTS file, you
+## can obtain it at aomedia.org/license/patent-license/.
 ##
 """Wraps paragraphs of text, preserving manual formatting