| 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/cpu.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 ASSERT_TRUE(base::CPU().has_sse()); | 96 ASSERT_TRUE(base::CPU().has_sse()); |
| 97 SCOPED_TRACE("FMAC_SSE"); | 97 SCOPED_TRACE("FMAC_SSE"); |
| 98 FillTestVectors(kInputFillValue, kOutputFillValue); | 98 FillTestVectors(kInputFillValue, kOutputFillValue); |
| 99 vector_math::FMAC_SSE( | 99 vector_math::FMAC_SSE( |
| 100 input_vector.get(), kScale, kVectorSize, output_vector.get()); | 100 input_vector.get(), kScale, kVectorSize, output_vector.get()); |
| 101 VerifyOutput(kResult); | 101 VerifyOutput(kResult); |
| 102 } | 102 } |
| 103 #endif | 103 #endif |
| 104 } | 104 } |
| 105 | 105 |
| 106 // Ensure each optimized vector_math::FMUL() method returns the same value. |
| 107 TEST_F(VectorMathTest, FMUL) { |
| 108 static const float kResult = kInputFillValue * kScale; |
| 109 |
| 110 { |
| 111 SCOPED_TRACE("FMUL"); |
| 112 FillTestVectors(kInputFillValue, kOutputFillValue); |
| 113 vector_math::FMUL( |
| 114 input_vector.get(), kScale, kVectorSize, output_vector.get()); |
| 115 VerifyOutput(kResult); |
| 116 } |
| 117 |
| 118 { |
| 119 SCOPED_TRACE("FMUL_C"); |
| 120 FillTestVectors(kInputFillValue, kOutputFillValue); |
| 121 vector_math::FMUL_C( |
| 122 input_vector.get(), kScale, kVectorSize, output_vector.get()); |
| 123 VerifyOutput(kResult); |
| 124 } |
| 125 |
| 126 #if defined(ARCH_CPU_X86_FAMILY) |
| 127 { |
| 128 ASSERT_TRUE(base::CPU().has_sse()); |
| 129 SCOPED_TRACE("FMUL_SSE"); |
| 130 FillTestVectors(kInputFillValue, kOutputFillValue); |
| 131 vector_math::FMUL_SSE( |
| 132 input_vector.get(), kScale, kVectorSize, output_vector.get()); |
| 133 VerifyOutput(kResult); |
| 134 } |
| 135 #endif |
| 136 } |
| 137 |
| 106 // Benchmark for each optimized vector_math::FMAC() method. Original benchmarks | 138 // Benchmark for each optimized vector_math::FMAC() method. Original benchmarks |
| 107 // were run with --vector-fmac-iterations=200000. | 139 // were run with --vector-fmac-iterations=200000. |
| 108 TEST_F(VectorMathTest, FMACBenchmark) { | 140 TEST_F(VectorMathTest, FMACBenchmark) { |
| 109 static const int kBenchmarkIterations = BenchmarkIterations(); | 141 static const int kBenchmarkIterations = BenchmarkIterations(); |
| 110 | 142 |
| 111 printf("Benchmarking %d iterations:\n", kBenchmarkIterations); | 143 printf("Benchmarking %d iterations:\n", kBenchmarkIterations); |
| 112 | 144 |
| 113 // Benchmark FMAC_C(). | 145 // Benchmark FMAC_C(). |
| 114 FillTestVectors(kInputFillValue, kOutputFillValue); | 146 FillTestVectors(kInputFillValue, kOutputFillValue); |
| 115 TimeTicks start = TimeTicks::HighResNow(); | 147 TimeTicks start = TimeTicks::HighResNow(); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 } | 181 } |
| 150 double total_time_sse_aligned_ms = | 182 double total_time_sse_aligned_ms = |
| 151 (TimeTicks::HighResNow() - start).InMillisecondsF(); | 183 (TimeTicks::HighResNow() - start).InMillisecondsF(); |
| 152 printf("FMAC_SSE (aligned size) took %.2fms; which is %.2fx faster than" | 184 printf("FMAC_SSE (aligned size) took %.2fms; which is %.2fx faster than" |
| 153 " FMAC_C and %.2fx faster than FMAC_SSE (unaligned size).\n", | 185 " FMAC_C and %.2fx faster than FMAC_SSE (unaligned size).\n", |
| 154 total_time_sse_aligned_ms, total_time_c_ms / total_time_sse_aligned_ms, | 186 total_time_sse_aligned_ms, total_time_c_ms / total_time_sse_aligned_ms, |
| 155 total_time_sse_unaligned_ms / total_time_sse_aligned_ms); | 187 total_time_sse_unaligned_ms / total_time_sse_aligned_ms); |
| 156 #endif | 188 #endif |
| 157 } | 189 } |
| 158 | 190 |
| 191 |
| 192 // Benchmark for each optimized vector_math::FMUL() method. Original benchmarks |
| 193 // were run with --vector-math-iterations=200000. |
| 194 TEST_F(VectorMathTest, FMULBenchmark) { |
| 195 static const int kBenchmarkIterations = BenchmarkIterations(); |
| 196 |
| 197 printf("Benchmarking %d iterations:\n", kBenchmarkIterations); |
| 198 |
| 199 // Benchmark FMUL_C(). |
| 200 FillTestVectors(kInputFillValue, kOutputFillValue); |
| 201 TimeTicks start = TimeTicks::HighResNow(); |
| 202 for (int i = 0; i < kBenchmarkIterations; ++i) { |
| 203 vector_math::FMUL_C( |
| 204 input_vector.get(), kScale, kVectorSize, output_vector.get()); |
| 205 } |
| 206 double total_time_c_ms = (TimeTicks::HighResNow() - start).InMillisecondsF(); |
| 207 printf("FMUL_C took %.2fms.\n", total_time_c_ms); |
| 208 |
| 209 #if defined(ARCH_CPU_X86_FAMILY) |
| 210 ASSERT_TRUE(base::CPU().has_sse()); |
| 211 |
| 212 // Benchmark FMUL_SSE() with unaligned size. |
| 213 ASSERT_NE((kVectorSize - 1) % (vector_math::kRequiredAlignment / |
| 214 sizeof(float)), 0U); |
| 215 FillTestVectors(kInputFillValue, kOutputFillValue); |
| 216 start = TimeTicks::HighResNow(); |
| 217 for (int j = 0; j < kBenchmarkIterations; ++j) { |
| 218 vector_math::FMUL_SSE( |
| 219 input_vector.get(), kScale, kVectorSize - 1, output_vector.get()); |
| 220 } |
| 221 double total_time_sse_unaligned_ms = |
| 222 (TimeTicks::HighResNow() - start).InMillisecondsF(); |
| 223 printf("FMUL_SSE (unaligned size) took %.2fms; which is %.2fx faster than" |
| 224 " FMUL_C.\n", total_time_sse_unaligned_ms, |
| 225 total_time_c_ms / total_time_sse_unaligned_ms); |
| 226 |
| 227 // Benchmark FMUL_SSE() with aligned size. |
| 228 ASSERT_EQ(kVectorSize % (vector_math::kRequiredAlignment / sizeof(float)), |
| 229 0U); |
| 230 FillTestVectors(kInputFillValue, kOutputFillValue); |
| 231 start = TimeTicks::HighResNow(); |
| 232 for (int j = 0; j < kBenchmarkIterations; ++j) { |
| 233 vector_math::FMUL_SSE( |
| 234 input_vector.get(), kScale, kVectorSize, output_vector.get()); |
| 235 } |
| 236 double total_time_sse_aligned_ms = |
| 237 (TimeTicks::HighResNow() - start).InMillisecondsF(); |
| 238 printf("FMUL_SSE (aligned size) took %.2fms; which is %.2fx faster than" |
| 239 " FMUL_C and %.2fx faster than FMUL_SSE (unaligned size).\n", |
| 240 total_time_sse_aligned_ms, total_time_c_ms / total_time_sse_aligned_ms, |
| 241 total_time_sse_unaligned_ms / total_time_sse_aligned_ms); |
| 242 #endif |
| 243 } |
| 244 |
| 159 } // namespace media | 245 } // namespace media |
| OLD | NEW |