| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "webrtc/modules/audio_processing/aec3/vector_math.h" | 11 #include "webrtc/modules/audio_processing/aec3/vector_math.h" |
| 12 | 12 |
| 13 #include <math.h> | 13 #include <math.h> |
| 14 | 14 |
| 15 #include "webrtc/system_wrappers/include/cpu_features_wrapper.h" | 15 #include "webrtc/system_wrappers/include/cpu_features_wrapper.h" |
| 16 #include "webrtc/test/gtest.h" | 16 #include "webrtc/test/gtest.h" |
| 17 #include "webrtc/typedefs.h" | 17 #include "webrtc/typedefs.h" |
| 18 | 18 |
| 19 namespace webrtc { | 19 namespace webrtc { |
| 20 | 20 |
| 21 #if defined(WEBRTC_HAS_NEON) | |
| 22 | |
| 23 TEST(VectorMath, Sqrt) { | |
| 24 std::array<float, kFftLengthBy2Plus1> x; | |
| 25 std::array<float, kFftLengthBy2Plus1> z; | |
| 26 std::array<float, kFftLengthBy2Plus1> z_neon; | |
| 27 | |
| 28 for (size_t k = 0; k < x.size(); ++k) { | |
| 29 x[k] = (2.f / 3.f) * k; | |
| 30 } | |
| 31 | |
| 32 std::copy(x.begin(), x.end(), z.begin()); | |
| 33 aec3::VectorMath(Aec3Optimization::kNone).Sqrt(z); | |
| 34 std::copy(x.begin(), x.end(), z_neon.begin()); | |
| 35 aec3::VectorMath(Aec3Optimization::kNeon).Sqrt(z_neon); | |
| 36 for (size_t k = 0; k < z.size(); ++k) { | |
| 37 EXPECT_NEAR(z[k], z_neon[k], 0.0001f); | |
| 38 EXPECT_NEAR(sqrtf(x[k]), z_neon[k], 0.0001f); | |
| 39 } | |
| 40 } | |
| 41 | |
| 42 TEST(VectorMath, Multiply) { | |
| 43 std::array<float, kFftLengthBy2Plus1> x; | |
| 44 std::array<float, kFftLengthBy2Plus1> y; | |
| 45 std::array<float, kFftLengthBy2Plus1> z; | |
| 46 std::array<float, kFftLengthBy2Plus1> z_neon; | |
| 47 | |
| 48 for (size_t k = 0; k < x.size(); ++k) { | |
| 49 x[k] = k; | |
| 50 y[k] = (2.f / 3.f) * k; | |
| 51 } | |
| 52 | |
| 53 aec3::VectorMath(Aec3Optimization::kNone).Multiply(x, y, z); | |
| 54 aec3::VectorMath(Aec3Optimization::kNeon).Multiply(x, y, z_neon); | |
| 55 for (size_t k = 0; k < z.size(); ++k) { | |
| 56 EXPECT_FLOAT_EQ(z[k], z_neon[k]); | |
| 57 EXPECT_FLOAT_EQ(x[k] * y[k], z_neon[k]); | |
| 58 } | |
| 59 } | |
| 60 | |
| 61 TEST(VectorMath, Accumulate) { | |
| 62 std::array<float, kFftLengthBy2Plus1> x; | |
| 63 std::array<float, kFftLengthBy2Plus1> z; | |
| 64 std::array<float, kFftLengthBy2Plus1> z_neon; | |
| 65 | |
| 66 for (size_t k = 0; k < x.size(); ++k) { | |
| 67 x[k] = k; | |
| 68 z[k] = z_neon[k] = 2.f * k; | |
| 69 } | |
| 70 | |
| 71 aec3::VectorMath(Aec3Optimization::kNone).Accumulate(x, z); | |
| 72 aec3::VectorMath(Aec3Optimization::kNeon).Accumulate(x, z_neon); | |
| 73 for (size_t k = 0; k < z.size(); ++k) { | |
| 74 EXPECT_FLOAT_EQ(z[k], z_neon[k]); | |
| 75 EXPECT_FLOAT_EQ(x[k] + 2.f * x[k], z_neon[k]); | |
| 76 } | |
| 77 } | |
| 78 #endif | |
| 79 | |
| 80 #if defined(WEBRTC_ARCH_X86_FAMILY) | 21 #if defined(WEBRTC_ARCH_X86_FAMILY) |
| 81 | 22 |
| 82 TEST(VectorMath, Sqrt) { | 23 TEST(VectorMath, Sqrt) { |
| 83 if (WebRtc_GetCPUInfo(kSSE2) != 0) { | 24 if (WebRtc_GetCPUInfo(kSSE2) != 0) { |
| 84 std::array<float, kFftLengthBy2Plus1> x; | 25 std::array<float, kFftLengthBy2Plus1> x; |
| 85 std::array<float, kFftLengthBy2Plus1> z; | 26 std::array<float, kFftLengthBy2Plus1> z; |
| 86 std::array<float, kFftLengthBy2Plus1> z_sse2; | 27 std::array<float, kFftLengthBy2Plus1> z_sse2; |
| 87 | 28 |
| 88 for (size_t k = 0; k < x.size(); ++k) { | 29 for (size_t k = 0; k < x.size(); ++k) { |
| 89 x[k] = (2.f / 3.f) * k; | 30 x[k] = (2.f / 3.f) * k; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 aec3::VectorMath(Aec3Optimization::kSse2).Accumulate(x, z_sse2); | 78 aec3::VectorMath(Aec3Optimization::kSse2).Accumulate(x, z_sse2); |
| 138 for (size_t k = 0; k < z.size(); ++k) { | 79 for (size_t k = 0; k < z.size(); ++k) { |
| 139 EXPECT_FLOAT_EQ(z[k], z_sse2[k]); | 80 EXPECT_FLOAT_EQ(z[k], z_sse2[k]); |
| 140 EXPECT_FLOAT_EQ(x[k] + 2.f * x[k], z_sse2[k]); | 81 EXPECT_FLOAT_EQ(x[k] + 2.f * x[k], z_sse2[k]); |
| 141 } | 82 } |
| 142 } | 83 } |
| 143 } | 84 } |
| 144 #endif | 85 #endif |
| 145 | 86 |
| 146 } // namespace webrtc | 87 } // namespace webrtc |
| OLD | NEW |