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