average_blend.cc: fix 10-bit init

when LIBGAV1_ENABLE_ALL_DSP_FUNCTIONS is set always define
average_blend.

+ add Dsp.TablesArePopulatedCOnly in dsp_test.cc

PiperOrigin-RevId: 348529620
Change-Id: I0d62e8c2d253199ecd8c2a69a4a88f0b14d972be
diff --git a/src/dsp/average_blend.cc b/src/dsp/average_blend.cc
index a59abb0..d3ec21f 100644
--- a/src/dsp/average_blend.cc
+++ b/src/dsp/average_blend.cc
@@ -76,9 +76,7 @@
   Dsp* const dsp = dsp_internal::GetWritableDspTable(10);
   assert(dsp != nullptr);
 #if LIBGAV1_ENABLE_ALL_DSP_FUNCTIONS
-#ifndef LIBGAV1_Dsp10bpp_AverageBlend
   dsp->average_blend = AverageBlend_C<10, uint16_t>;
-#endif
 #else  // !LIBGAV1_ENABLE_ALL_DSP_FUNCTIONS
   static_cast<void>(dsp);
 #ifndef LIBGAV1_Dsp10bpp_AverageBlend
diff --git a/src/dsp/dsp.cc b/src/dsp/dsp.cc
index b0126d7..713f478 100644
--- a/src/dsp/dsp.cc
+++ b/src/dsp/dsp.cc
@@ -39,6 +39,26 @@
 namespace libgav1 {
 namespace dsp_internal {
 
+void DspInit_C() {
+  dsp::AverageBlendInit_C();
+  dsp::CdefInit_C();
+  dsp::ConvolveInit_C();
+  dsp::DistanceWeightedBlendInit_C();
+  dsp::FilmGrainInit_C();
+  dsp::IntraEdgeInit_C();
+  dsp::IntraPredInit_C();
+  dsp::InverseTransformInit_C();
+  dsp::LoopFilterInit_C();
+  dsp::LoopRestorationInit_C();
+  dsp::MaskBlendInit_C();
+  dsp::MotionFieldProjectionInit_C();
+  dsp::MotionVectorSearchInit_C();
+  dsp::ObmcInit_C();
+  dsp::SuperResInit_C();
+  dsp::WarpInit_C();
+  dsp::WeightMaskInit_C();
+}
+
 dsp::Dsp* GetWritableDspTable(int bitdepth) {
   switch (bitdepth) {
     case 8: {
@@ -62,23 +82,7 @@
 void DspInit() {
   static std::once_flag once;
   std::call_once(once, []() {
-    AverageBlendInit_C();
-    CdefInit_C();
-    ConvolveInit_C();
-    DistanceWeightedBlendInit_C();
-    FilmGrainInit_C();
-    IntraEdgeInit_C();
-    IntraPredInit_C();
-    InverseTransformInit_C();
-    LoopFilterInit_C();
-    LoopRestorationInit_C();
-    MaskBlendInit_C();
-    MotionFieldProjectionInit_C();
-    MotionVectorSearchInit_C();
-    ObmcInit_C();
-    SuperResInit_C();
-    WarpInit_C();
-    WeightMaskInit_C();
+    dsp_internal::DspInit_C();
 #if LIBGAV1_ENABLE_SSE4_1 || LIBGAV1_ENABLE_AVX2
     const uint32_t cpu_features = GetCpuInfo();
 #if LIBGAV1_ENABLE_SSE4_1
diff --git a/src/dsp/dsp.h b/src/dsp/dsp.h
index 5a85ab2..39c4e63 100644
--- a/src/dsp/dsp.h
+++ b/src/dsp/dsp.h
@@ -900,6 +900,11 @@
   (LIBGAV1_ENABLE_ALL_DSP_FUNCTIONS || \
    LIBGAV1_Dsp10bpp_##func == LIBGAV1_CPU_SSE4_1)
 
+// Initializes C-only function pointers. Note some entries may be set to
+// nullptr if LIBGAV1_ENABLE_ALL_DSP_FUNCTIONS is not defined. This is meant
+// for use in tests only, it is not thread-safe.
+void DspInit_C();
+
 // Returns the appropriate Dsp table for |bitdepth| or nullptr if one doesn't
 // exist. This version is meant for use by test or dsp/*Init() functions only.
 dsp::Dsp* GetWritableDspTable(int bitdepth);
diff --git a/src/dsp/dsp_test.cc b/src/dsp/dsp_test.cc
index 3d8e935..5c5672a 100644
--- a/src/dsp/dsp_test.cc
+++ b/src/dsp/dsp_test.cc
@@ -24,6 +24,10 @@
 #include "src/utils/constants.h"
 #include "src/utils/cpu.h"
 
+#if LIBGAV1_ENABLE_ALL_DSP_FUNCTIONS
+#include "tests/utils.h"
+#endif
+
 namespace libgav1 {
 namespace dsp {
 namespace {
@@ -36,15 +40,14 @@
     k1DTransformSize4,   // Wht.
 };
 
-TEST(Dsp, TablesArePopulated) {
+void CheckTables(bool c_only) {
 #if LIBGAV1_MAX_BITDEPTH >= 10
-  const int bitdepths[] = {8, 10};
+  static constexpr int kBitdepths[] = {kBitdepth8, kBitdepth10};
 #else
-  const int bitdepths[] = {8};
+  static constexpr int kBitdepths[] = {kBitdepth8};
 #endif
-  DspInit();
 
-  for (const auto& bitdepth : bitdepths) {
+  for (const auto& bitdepth : kBitdepths) {
     const Dsp* const dsp = GetDspTable(bitdepth);
     ASSERT_NE(dsp, nullptr);
     SCOPED_TRACE(absl::StrCat("bitdepth: ", bitdepth));
@@ -105,6 +108,7 @@
     const uint32_t cpu_features = GetCpuInfo();
     super_res_coefficients_is_nonnull = (cpu_features & kSSE4_1) != 0;
 #endif
+    if (c_only) super_res_coefficients_is_nonnull = false;
     if (bitdepth == 8 && super_res_coefficients_is_nonnull) {
       EXPECT_NE(dsp->super_res_coefficients, nullptr);
     } else {
@@ -209,6 +213,22 @@
   }
 }
 
+TEST(Dsp, TablesArePopulated) {
+  DspInit();
+  CheckTables(/*c_only=*/false);
+}
+
+#if LIBGAV1_ENABLE_ALL_DSP_FUNCTIONS
+TEST(Dsp, TablesArePopulatedCOnly) {
+  test_utils::ResetDspTable(kBitdepth8);
+#if LIBGAV1_MAX_BITDEPTH >= 10
+  test_utils::ResetDspTable(kBitdepth10);
+#endif
+  dsp_internal::DspInit_C();
+  CheckTables(/*c_only=*/true);
+}
+#endif  // LIBGAV1_ENABLE_ALL_DSP_FUNCTIONS
+
 TEST(Dsp, GetDspTable) {
   EXPECT_EQ(GetDspTable(1), nullptr);
   EXPECT_NE(GetDspTable(8), nullptr);
diff --git a/tests/libgav1_tests.cmake b/tests/libgav1_tests.cmake
index 84a7038..5f88717 100644
--- a/tests/libgav1_tests.cmake
+++ b/tests/libgav1_tests.cmake
@@ -210,6 +210,7 @@
                          OBJLIB_DEPS
                          libgav1_decoder
                          libgav1_dsp
+                         libgav1_tests_utils
                          libgav1_utils
                          LIB_DEPS
                          absl::strings