Add support for armv7s to cmake aom_dsp build.

- Add function add_gas_asm_library() to handle conversion of asm
  sources and creation of custom dependencies.
- Uses add_asm_library() to create the library build.
- Add aom_dsp_common_neon_intrinsics target for the neon intrinsics.

BUG=https://bugs.chromium.org/p/aomedia/issues/detail?id=76

Change-Id: Ifd99fbd69998a79613e0f5b61003a47973a804bc
diff --git a/aom_dsp/aom_dsp.cmake b/aom_dsp/aom_dsp.cmake
index 91c5bad..75319f9 100644
--- a/aom_dsp/aom_dsp.cmake
+++ b/aom_dsp/aom_dsp.cmake
@@ -64,6 +64,40 @@
     "${AOM_ROOT}/aom_dsp/x86/fwd_txfm_avx2.c"
     "${AOM_ROOT}/aom_dsp/x86/loopfilter_avx2.c")
 
+set(AOM_DSP_COMMON_ASM_NEON
+    "${AOM_ROOT}/aom_dsp/arm/aom_convolve8_avg_neon_asm.asm"
+    "${AOM_ROOT}/aom_dsp/arm/aom_convolve8_neon_asm.asm"
+    "${AOM_ROOT}/aom_dsp/arm/aom_convolve_avg_neon_asm.asm"
+    "${AOM_ROOT}/aom_dsp/arm/aom_convolve_copy_neon_asm.asm"
+    "${AOM_ROOT}/aom_dsp/arm/idct16x16_1_add_neon.asm"
+    "${AOM_ROOT}/aom_dsp/arm/idct16x16_add_neon.asm"
+    "${AOM_ROOT}/aom_dsp/arm/idct32x32_1_add_neon.asm"
+    "${AOM_ROOT}/aom_dsp/arm/idct32x32_add_neon.asm"
+    "${AOM_ROOT}/aom_dsp/arm/idct4x4_1_add_neon.asm"
+    "${AOM_ROOT}/aom_dsp/arm/idct4x4_add_neon.asm"
+    "${AOM_ROOT}/aom_dsp/arm/idct8x8_1_add_neon.asm"
+    "${AOM_ROOT}/aom_dsp/arm/idct8x8_add_neon.asm"
+    "${AOM_ROOT}/aom_dsp/arm/intrapred_neon_asm.asm"
+    "${AOM_ROOT}/aom_dsp/arm/loopfilter_16_neon.asm"
+    "${AOM_ROOT}/aom_dsp/arm/loopfilter_4_neon.asm"
+    "${AOM_ROOT}/aom_dsp/arm/loopfilter_8_neon.asm"
+    "${AOM_ROOT}/aom_dsp/arm/loopfilter_mb_neon.asm"
+    "${AOM_ROOT}/aom_dsp/arm/save_reg_neon.asm")
+
+set(AOM_DSP_COMMON_INTRIN_NEON
+    "${AOM_ROOT}/aom_dsp/arm/aom_convolve_neon.c"
+    "${AOM_ROOT}/aom_dsp/arm/avg_neon.c"
+    "${AOM_ROOT}/aom_dsp/arm/fwd_txfm_neon.c"
+    "${AOM_ROOT}/aom_dsp/arm/hadamard_neon.c"
+    "${AOM_ROOT}/aom_dsp/arm/idct16x16_neon.c"
+    "${AOM_ROOT}/aom_dsp/arm/intrapred_neon.c"
+    "${AOM_ROOT}/aom_dsp/arm/loopfilter_neon.c"
+    "${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/subtract_neon.c"
+    "${AOM_ROOT}/aom_dsp/arm/variance_neon.c")
+
 if (CONFIG_AOM_HIGHBITDEPTH)
   set(AOM_DSP_COMMON_ASM_SSE2
       ${AOM_DSP_COMMON_ASM_SSE2}
@@ -354,6 +388,18 @@
     endif ()
   endif ()
 
+  if (HAVE_NEON_ASM)
+    if (AOM_ADS2GAS_REQUIRED)
+      add_gas_asm_library("aom_dsp_common_neon" "AOM_DSP_COMMON_ASM_NEON" "aom")
+    else ()
+      add_asm_library("aom_dsp_common_neon" "AOM_DSP_COMMON_ASM_NEON" "aom")
+    endif ()
+  endif ()
+
+  if (HAVE_NEON)
+    add_intrinsics_object_library("${AOM_NEON_INTRIN_FLAG}" "neon"
+                                  "aom_dsp_common" "AOM_DSP_COMMON_INTRIN_NEON")
+  endif ()
   # Pass the new lib targets up to the parent scope instance of
   # $AOM_LIB_TARGETS.
   set(AOM_LIB_TARGETS ${AOM_LIB_TARGETS} PARENT_SCOPE)
diff --git a/build/cmake/aom_optimization.cmake b/build/cmake/aom_optimization.cmake
index b2c6498..e2b0ba0 100644
--- a/build/cmake/aom_optimization.cmake
+++ b/build/cmake/aom_optimization.cmake
@@ -148,4 +148,57 @@
   set(AOM_LIB_TARGETS ${AOM_LIB_TARGETS} PARENT_SCOPE)
 endfunction ()
 
+# Converts asm sources in $asm_sources using $AOM_ADS2GAS and calls
+# add_asm_library() to create a library from the converted sources. At
+# generation time the converted sources are created, and a custom rule is added
+# to ensure the sources are reconverted when the original asm source is updated.
+# See add_asm_library() for more information.
+function (add_gas_asm_library lib_name asm_sources dependent_target)
+  set(asm_converted_source_dir "${AOM_CONFIG_DIR}/asm_gas/${lib_name}")
+  if (NOT EXISTS "${asm_converted_source_dir}")
+    file(MAKE_DIRECTORY "${asm_converted_source_dir}")
+  endif ()
+
+  # Create the converted version of each assembly source at generation time.
+  unset(gas_target_sources)
+  foreach (neon_asm_source ${${asm_sources}})
+    get_filename_component(output_asm_source "${neon_asm_source}" NAME)
+    set(output_asm_source "${asm_converted_source_dir}/${output_asm_source}")
+    set(output_asm_source "${output_asm_source}.${AOM_GAS_EXT}")
+    execute_process(COMMAND "${PERL_EXECUTABLE}" "${AOM_ADS2GAS}"
+                    INPUT_FILE "${neon_asm_source}"
+                    OUTPUT_FILE "${output_asm_source}")
+    list(APPEND gas_target_sources "${output_asm_source}")
+  endforeach ()
+
+  add_asm_library("${lib_name}" "gas_target_sources" "${dependent_target}")
+
+  # For each of the converted sources, create a custom rule that will regenerate
+  # the converted source when its input is touched.
+  list(LENGTH gas_target_sources num_asm_files)
+  math(EXPR num_asm_files "${num_asm_files} - 1")
+  foreach(NUM RANGE ${num_asm_files})
+    list(GET ${asm_sources} ${NUM} neon_asm_source)
+    list(GET gas_target_sources ${NUM} gas_asm_source)
+
+    # Grab only the filename for the custom command output to keep build output
+    # reasonably sane.
+    get_filename_component(neon_name "${neon_asm_source}" NAME)
+    get_filename_component(gas_name "${gas_asm_source}" NAME)
+
+    add_custom_command(
+        OUTPUT "${gas_asm_source}"
+        COMMAND ${PERL_EXECUTABLE}
+        ARGS "${AOM_ADS2GAS}" < "${neon_asm_source}" > "${gas_asm_source}"
+        DEPENDS "${neon_asm_source}"
+        COMMENT "ads2gas conversion ${neon_name} -> ${gas_name}"
+        WORKING_DIRECTORY "${AOM_CONFIG_DIR}"
+        VERBATIM)
+  endforeach ()
+
+  # Update the sources list passed in to include the converted asm source files.
+  list(APPEND asm_sources ${gas_target_sources})
+  set(${asm_sources} ${${asm_sources}} PARENT_SCOPE)
+endfunction ()
+
 endif ()  # AOM_BUILD_CMAKE_AOM_OPTIMIZATION_CMAKE_