OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // MSVC++ requires this to be set before any other includes to get M_PI. | 5 // MSVC++ requires this to be set before any other includes to get M_PI. |
6 #define _USE_MATH_DEFINES | 6 #define _USE_MATH_DEFINES |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/cpu.h" |
10 #include "base/memory/aligned_memory.h" | 11 #include "base/memory/aligned_memory.h" |
11 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
12 #include "base/string_number_conversions.h" | 13 #include "base/string_number_conversions.h" |
13 #include "base/time.h" | 14 #include "base/time.h" |
14 #include "media/base/vector_math.h" | 15 #include "media/base/vector_math.h" |
15 #include "media/base/vector_math_testing.h" | 16 #include "media/base/vector_math_testing.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
17 | 18 |
18 using base::TimeTicks; | 19 using base::TimeTicks; |
19 using std::fill; | 20 using std::fill; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 } | 84 } |
84 | 85 |
85 { | 86 { |
86 SCOPED_TRACE("FMAC_C"); | 87 SCOPED_TRACE("FMAC_C"); |
87 FillTestVectors(kInputFillValue, kOutputFillValue); | 88 FillTestVectors(kInputFillValue, kOutputFillValue); |
88 vector_math::FMAC_C( | 89 vector_math::FMAC_C( |
89 input_vector.get(), kScale, kVectorSize, output_vector.get()); | 90 input_vector.get(), kScale, kVectorSize, output_vector.get()); |
90 VerifyOutput(kResult); | 91 VerifyOutput(kResult); |
91 } | 92 } |
92 | 93 |
93 #if defined(ARCH_CPU_X86_FAMILY) && defined(__SSE__) | 94 #if defined(ARCH_CPU_X86_FAMILY) |
94 { | 95 { |
| 96 ASSERT_TRUE(base::CPU().has_sse()); |
95 SCOPED_TRACE("FMAC_SSE"); | 97 SCOPED_TRACE("FMAC_SSE"); |
96 FillTestVectors(kInputFillValue, kOutputFillValue); | 98 FillTestVectors(kInputFillValue, kOutputFillValue); |
97 vector_math::FMAC_SSE( | 99 vector_math::FMAC_SSE( |
98 input_vector.get(), kScale, kVectorSize, output_vector.get()); | 100 input_vector.get(), kScale, kVectorSize, output_vector.get()); |
99 VerifyOutput(kResult); | 101 VerifyOutput(kResult); |
100 } | 102 } |
101 #endif | 103 #endif |
102 } | 104 } |
103 | 105 |
104 // Benchmark for each optimized vector_math::FMAC() method. Original benchmarks | 106 // Benchmark for each optimized vector_math::FMAC() method. Original benchmarks |
105 // were run with --vector-fmac-iterations=200000. | 107 // were run with --vector-fmac-iterations=200000. |
106 TEST_F(VectorMathTest, FMACBenchmark) { | 108 TEST_F(VectorMathTest, FMACBenchmark) { |
107 static const int kBenchmarkIterations = BenchmarkIterations(); | 109 static const int kBenchmarkIterations = BenchmarkIterations(); |
108 | 110 |
109 printf("Benchmarking %d iterations:\n", kBenchmarkIterations); | 111 printf("Benchmarking %d iterations:\n", kBenchmarkIterations); |
110 | 112 |
111 // Benchmark FMAC_C(). | 113 // Benchmark FMAC_C(). |
112 FillTestVectors(kInputFillValue, kOutputFillValue); | 114 FillTestVectors(kInputFillValue, kOutputFillValue); |
113 TimeTicks start = TimeTicks::HighResNow(); | 115 TimeTicks start = TimeTicks::HighResNow(); |
114 for (int i = 0; i < kBenchmarkIterations; ++i) { | 116 for (int i = 0; i < kBenchmarkIterations; ++i) { |
115 vector_math::FMAC_C( | 117 vector_math::FMAC_C( |
116 input_vector.get(), kScale, kVectorSize, output_vector.get()); | 118 input_vector.get(), kScale, kVectorSize, output_vector.get()); |
117 } | 119 } |
118 double total_time_c_ms = (TimeTicks::HighResNow() - start).InMillisecondsF(); | 120 double total_time_c_ms = (TimeTicks::HighResNow() - start).InMillisecondsF(); |
119 printf("FMAC_C took %.2fms.\n", total_time_c_ms); | 121 printf("FMAC_C took %.2fms.\n", total_time_c_ms); |
120 | 122 |
121 #if defined(ARCH_CPU_X86_FAMILY) && defined(__SSE__) | 123 #if defined(ARCH_CPU_X86_FAMILY) |
| 124 ASSERT_TRUE(base::CPU().has_sse()); |
| 125 |
122 // Benchmark FMAC_SSE() with unaligned size. | 126 // Benchmark FMAC_SSE() with unaligned size. |
123 ASSERT_NE((kVectorSize - 1) % (vector_math::kRequiredAlignment / | 127 ASSERT_NE((kVectorSize - 1) % (vector_math::kRequiredAlignment / |
124 sizeof(float)), 0U); | 128 sizeof(float)), 0U); |
125 FillTestVectors(kInputFillValue, kOutputFillValue); | 129 FillTestVectors(kInputFillValue, kOutputFillValue); |
126 start = TimeTicks::HighResNow(); | 130 start = TimeTicks::HighResNow(); |
127 for (int j = 0; j < kBenchmarkIterations; ++j) { | 131 for (int j = 0; j < kBenchmarkIterations; ++j) { |
128 vector_math::FMAC_SSE( | 132 vector_math::FMAC_SSE( |
129 input_vector.get(), kScale, kVectorSize - 1, output_vector.get()); | 133 input_vector.get(), kScale, kVectorSize - 1, output_vector.get()); |
130 } | 134 } |
131 double total_time_sse_unaligned_ms = | 135 double total_time_sse_unaligned_ms = |
(...skipping 14 matching lines...) Expand all Loading... |
146 double total_time_sse_aligned_ms = | 150 double total_time_sse_aligned_ms = |
147 (TimeTicks::HighResNow() - start).InMillisecondsF(); | 151 (TimeTicks::HighResNow() - start).InMillisecondsF(); |
148 printf("FMAC_SSE (aligned size) took %.2fms; which is %.2fx faster than" | 152 printf("FMAC_SSE (aligned size) took %.2fms; which is %.2fx faster than" |
149 " FMAC_C and %.2fx faster than FMAC_SSE (unaligned size).\n", | 153 " FMAC_C and %.2fx faster than FMAC_SSE (unaligned size).\n", |
150 total_time_sse_aligned_ms, total_time_c_ms / total_time_sse_aligned_ms, | 154 total_time_sse_aligned_ms, total_time_c_ms / total_time_sse_aligned_ms, |
151 total_time_sse_unaligned_ms / total_time_sse_aligned_ms); | 155 total_time_sse_unaligned_ms / total_time_sse_aligned_ms); |
152 #endif | 156 #endif |
153 } | 157 } |
154 | 158 |
155 } // namespace media | 159 } // namespace media |
OLD | NEW |