webrtc_m130/modules/audio_processing/aec3/vector_math_unittest.cc

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

210 lines
6.0 KiB
C++
Raw Normal View History

/*
* Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "modules/audio_processing/aec3/vector_math.h"
#include <math.h>
#include "rtc_base/system/arch.h"
#include "system_wrappers/include/cpu_features_wrapper.h"
#include "test/gtest.h"
namespace webrtc {
Reland of Added ARM Neon SIMD optimizations for AEC3 (patchset #1 id:1 of https://codereview.webrtc.org/2856113003/ ) Reason for revert: The original patch set was correct, but the Chromium bug number needed to be corrected. Original issue's description: > Revert of Added ARM Neon SIMD optimizations for AEC3 (patchset #2 id:970001 of https://codereview.webrtc.org/2834073005/ ) > > Reason for revert: > The bug number for the chromium bug was wrong. > > Original issue's description: > > Added ARM Neon optimizations for AEC3 > > > > This CL adds Neon SIMD optimizations for AEC3 on ARM, resulting > > in an 8 times complexity reduction. The optimizations are basically > > identical to what was already in place for SSE2. > > > > BUG=chromium:14993, webrtc:6018 > > > > Review-Url: https://codereview.webrtc.org/2834073005 > > Cr-Commit-Position: refs/heads/master@{#17993} > > Committed: https://chromium.googlesource.com/external/webrtc/+/f246b91eba0e8d95bd3fee4634887fb6d3017811 > > TBR=ivoc@webrtc.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=chromium:14993, webrtc:6018 > > Review-Url: https://codereview.webrtc.org/2856113003 > Cr-Commit-Position: refs/heads/master@{#17994} > Committed: https://chromium.googlesource.com/external/webrtc/+/b70f8cfd4d5cf6fe31a8089df9955b7e7b7ebd32 TBR=ivoc@webrtc.org # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=chromium:714993, webrtc:6018 Review-Url: https://codereview.webrtc.org/2862573002 Cr-Commit-Position: refs/heads/master@{#17997}
2017-05-03 06:45:44 -07:00
#if defined(WEBRTC_HAS_NEON)
TEST(VectorMath, Sqrt) {
std::array<float, kFftLengthBy2Plus1> x;
std::array<float, kFftLengthBy2Plus1> z;
std::array<float, kFftLengthBy2Plus1> z_neon;
for (size_t k = 0; k < x.size(); ++k) {
x[k] = (2.f / 3.f) * k;
}
std::copy(x.begin(), x.end(), z.begin());
aec3::VectorMath(Aec3Optimization::kNone).Sqrt(z);
std::copy(x.begin(), x.end(), z_neon.begin());
aec3::VectorMath(Aec3Optimization::kNeon).Sqrt(z_neon);
for (size_t k = 0; k < z.size(); ++k) {
EXPECT_NEAR(z[k], z_neon[k], 0.0001f);
EXPECT_NEAR(sqrtf(x[k]), z_neon[k], 0.0001f);
}
}
TEST(VectorMath, Multiply) {
std::array<float, kFftLengthBy2Plus1> x;
std::array<float, kFftLengthBy2Plus1> y;
std::array<float, kFftLengthBy2Plus1> z;
std::array<float, kFftLengthBy2Plus1> z_neon;
for (size_t k = 0; k < x.size(); ++k) {
x[k] = k;
y[k] = (2.f / 3.f) * k;
}
aec3::VectorMath(Aec3Optimization::kNone).Multiply(x, y, z);
aec3::VectorMath(Aec3Optimization::kNeon).Multiply(x, y, z_neon);
for (size_t k = 0; k < z.size(); ++k) {
EXPECT_FLOAT_EQ(z[k], z_neon[k]);
EXPECT_FLOAT_EQ(x[k] * y[k], z_neon[k]);
}
}
TEST(VectorMath, Accumulate) {
std::array<float, kFftLengthBy2Plus1> x;
std::array<float, kFftLengthBy2Plus1> z;
std::array<float, kFftLengthBy2Plus1> z_neon;
for (size_t k = 0; k < x.size(); ++k) {
x[k] = k;
z[k] = z_neon[k] = 2.f * k;
}
aec3::VectorMath(Aec3Optimization::kNone).Accumulate(x, z);
aec3::VectorMath(Aec3Optimization::kNeon).Accumulate(x, z_neon);
for (size_t k = 0; k < z.size(); ++k) {
EXPECT_FLOAT_EQ(z[k], z_neon[k]);
EXPECT_FLOAT_EQ(x[k] + 2.f * x[k], z_neon[k]);
}
}
#endif
#if defined(WEBRTC_ARCH_X86_FAMILY)
TEST(VectorMath, Sse2Sqrt) {
if (GetCPUInfo(kSSE2) != 0) {
std::array<float, kFftLengthBy2Plus1> x;
std::array<float, kFftLengthBy2Plus1> z;
std::array<float, kFftLengthBy2Plus1> z_sse2;
for (size_t k = 0; k < x.size(); ++k) {
x[k] = (2.f / 3.f) * k;
}
std::copy(x.begin(), x.end(), z.begin());
aec3::VectorMath(Aec3Optimization::kNone).Sqrt(z);
std::copy(x.begin(), x.end(), z_sse2.begin());
aec3::VectorMath(Aec3Optimization::kSse2).Sqrt(z_sse2);
EXPECT_EQ(z, z_sse2);
for (size_t k = 0; k < z.size(); ++k) {
EXPECT_FLOAT_EQ(z[k], z_sse2[k]);
EXPECT_FLOAT_EQ(sqrtf(x[k]), z_sse2[k]);
}
}
}
TEST(VectorMath, Avx2Sqrt) {
if (GetCPUInfo(kAVX2) != 0) {
std::array<float, kFftLengthBy2Plus1> x;
std::array<float, kFftLengthBy2Plus1> z;
std::array<float, kFftLengthBy2Plus1> z_avx2;
for (size_t k = 0; k < x.size(); ++k) {
x[k] = (2.f / 3.f) * k;
}
std::copy(x.begin(), x.end(), z.begin());
aec3::VectorMath(Aec3Optimization::kNone).Sqrt(z);
std::copy(x.begin(), x.end(), z_avx2.begin());
aec3::VectorMath(Aec3Optimization::kAvx2).Sqrt(z_avx2);
EXPECT_EQ(z, z_avx2);
for (size_t k = 0; k < z.size(); ++k) {
EXPECT_FLOAT_EQ(z[k], z_avx2[k]);
EXPECT_FLOAT_EQ(sqrtf(x[k]), z_avx2[k]);
}
}
}
TEST(VectorMath, Sse2Multiply) {
if (GetCPUInfo(kSSE2) != 0) {
std::array<float, kFftLengthBy2Plus1> x;
std::array<float, kFftLengthBy2Plus1> y;
std::array<float, kFftLengthBy2Plus1> z;
std::array<float, kFftLengthBy2Plus1> z_sse2;
for (size_t k = 0; k < x.size(); ++k) {
x[k] = k;
y[k] = (2.f / 3.f) * k;
}
aec3::VectorMath(Aec3Optimization::kNone).Multiply(x, y, z);
aec3::VectorMath(Aec3Optimization::kSse2).Multiply(x, y, z_sse2);
for (size_t k = 0; k < z.size(); ++k) {
EXPECT_FLOAT_EQ(z[k], z_sse2[k]);
EXPECT_FLOAT_EQ(x[k] * y[k], z_sse2[k]);
}
}
}
TEST(VectorMath, Avx2Multiply) {
if (GetCPUInfo(kAVX2) != 0) {
std::array<float, kFftLengthBy2Plus1> x;
std::array<float, kFftLengthBy2Plus1> y;
std::array<float, kFftLengthBy2Plus1> z;
std::array<float, kFftLengthBy2Plus1> z_avx2;
for (size_t k = 0; k < x.size(); ++k) {
x[k] = k;
y[k] = (2.f / 3.f) * k;
}
aec3::VectorMath(Aec3Optimization::kNone).Multiply(x, y, z);
aec3::VectorMath(Aec3Optimization::kAvx2).Multiply(x, y, z_avx2);
for (size_t k = 0; k < z.size(); ++k) {
EXPECT_FLOAT_EQ(z[k], z_avx2[k]);
EXPECT_FLOAT_EQ(x[k] * y[k], z_avx2[k]);
}
}
}
TEST(VectorMath, Sse2Accumulate) {
if (GetCPUInfo(kSSE2) != 0) {
std::array<float, kFftLengthBy2Plus1> x;
std::array<float, kFftLengthBy2Plus1> z;
std::array<float, kFftLengthBy2Plus1> z_sse2;
for (size_t k = 0; k < x.size(); ++k) {
x[k] = k;
z[k] = z_sse2[k] = 2.f * k;
}
aec3::VectorMath(Aec3Optimization::kNone).Accumulate(x, z);
aec3::VectorMath(Aec3Optimization::kSse2).Accumulate(x, z_sse2);
for (size_t k = 0; k < z.size(); ++k) {
EXPECT_FLOAT_EQ(z[k], z_sse2[k]);
EXPECT_FLOAT_EQ(x[k] + 2.f * x[k], z_sse2[k]);
}
}
}
TEST(VectorMath, Avx2Accumulate) {
if (GetCPUInfo(kAVX2) != 0) {
std::array<float, kFftLengthBy2Plus1> x;
std::array<float, kFftLengthBy2Plus1> z;
std::array<float, kFftLengthBy2Plus1> z_avx2;
for (size_t k = 0; k < x.size(); ++k) {
x[k] = k;
z[k] = z_avx2[k] = 2.f * k;
}
aec3::VectorMath(Aec3Optimization::kNone).Accumulate(x, z);
aec3::VectorMath(Aec3Optimization::kAvx2).Accumulate(x, z_avx2);
for (size_t k = 0; k < z.size(); ++k) {
EXPECT_FLOAT_EQ(z[k], z_avx2[k]);
EXPECT_FLOAT_EQ(x[k] + 2.f * x[k], z_avx2[k]);
}
}
}
#endif
} // namespace webrtc