| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 The LibYuv Project Authors. All rights reserved. | 2 * Copyright 2011 The LibYuv 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 <stdlib.h> | 11 #include <stdlib.h> |
| 12 #include <time.h> | 12 #include <time.h> |
| 13 | 13 |
| 14 #include "libyuv/cpu_id.h" | 14 #include "libyuv/cpu_id.h" |
| 15 #include "libyuv/scale_argb.h" | 15 #include "libyuv/scale_argb.h" |
| 16 #include "libyuv/row.h" | 16 #include "libyuv/row.h" |
| 17 #include "../unit_test/unit_test.h" | 17 #include "../unit_test/unit_test.h" |
| 18 | 18 |
| 19 namespace libyuv { | 19 namespace libyuv { |
| 20 | 20 |
| 21 #define STRINGIZE(line) #line | 21 #define STRINGIZE(line) #line |
| 22 #define FILELINESTR(file, line) file ":" STRINGIZE(line) | 22 #define FILELINESTR(file, line) file ":" STRINGIZE(line) |
| 23 | 23 |
| 24 // Test scaling with C vs Opt and return maximum pixel difference. 0 = exact. | 24 // Test scaling with C vs Opt and return maximum pixel difference. 0 = exact. |
| 25 static int ARGBTestFilter(int src_width, int src_height, | 25 static int ARGBTestFilter(int src_width, int src_height, |
| 26 int dst_width, int dst_height, | 26 int dst_width, int dst_height, |
| 27 FilterMode f, int benchmark_iterations, | 27 FilterMode f, int benchmark_iterations, |
| 28 int disable_cpu_flags) { | 28 int disable_cpu_flags, int benchmark_cpu_info) { |
| 29 int i, j; | 29 int i, j; |
| 30 const int b = 0; // 128 to test for padding/stride. | 30 const int b = 0; // 128 to test for padding/stride. |
| 31 int64 src_argb_plane_size = (Abs(src_width) + b * 2) * | 31 int64 src_argb_plane_size = (Abs(src_width) + b * 2) * |
| 32 (Abs(src_height) + b * 2) * 4LL; | 32 (Abs(src_height) + b * 2) * 4LL; |
| 33 int src_stride_argb = (b * 2 + Abs(src_width)) * 4; | 33 int src_stride_argb = (b * 2 + Abs(src_width)) * 4; |
| 34 | 34 |
| 35 align_buffer_page_end(src_argb, src_argb_plane_size); | 35 align_buffer_page_end(src_argb, src_argb_plane_size); |
| 36 if (!src_argb) { | 36 if (!src_argb) { |
| 37 printf("Skipped. Alloc failed " FILELINESTR(__FILE__, __LINE__) "\n"); | 37 printf("Skipped. Alloc failed " FILELINESTR(__FILE__, __LINE__) "\n"); |
| 38 return 0; | 38 return 0; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 50 } | 50 } |
| 51 memset(dst_argb_c, 2, dst_argb_plane_size); | 51 memset(dst_argb_c, 2, dst_argb_plane_size); |
| 52 memset(dst_argb_opt, 3, dst_argb_plane_size); | 52 memset(dst_argb_opt, 3, dst_argb_plane_size); |
| 53 | 53 |
| 54 // Warm up both versions for consistent benchmarks. | 54 // Warm up both versions for consistent benchmarks. |
| 55 MaskCpuFlags(disable_cpu_flags); // Disable all CPU optimization. | 55 MaskCpuFlags(disable_cpu_flags); // Disable all CPU optimization. |
| 56 ARGBScale(src_argb + (src_stride_argb * b) + b * 4, src_stride_argb, | 56 ARGBScale(src_argb + (src_stride_argb * b) + b * 4, src_stride_argb, |
| 57 src_width, src_height, | 57 src_width, src_height, |
| 58 dst_argb_c + (dst_stride_argb * b) + b * 4, dst_stride_argb, | 58 dst_argb_c + (dst_stride_argb * b) + b * 4, dst_stride_argb, |
| 59 dst_width, dst_height, f); | 59 dst_width, dst_height, f); |
| 60 MaskCpuFlags(-1); // Enable all CPU optimization. | 60 MaskCpuFlags(benchmark_cpu_info); // Enable all CPU optimization. |
| 61 ARGBScale(src_argb + (src_stride_argb * b) + b * 4, src_stride_argb, | 61 ARGBScale(src_argb + (src_stride_argb * b) + b * 4, src_stride_argb, |
| 62 src_width, src_height, | 62 src_width, src_height, |
| 63 dst_argb_opt + (dst_stride_argb * b) + b * 4, dst_stride_argb, | 63 dst_argb_opt + (dst_stride_argb * b) + b * 4, dst_stride_argb, |
| 64 dst_width, dst_height, f); | 64 dst_width, dst_height, f); |
| 65 | 65 |
| 66 MaskCpuFlags(disable_cpu_flags); // Disable all CPU optimization. | 66 MaskCpuFlags(disable_cpu_flags); // Disable all CPU optimization. |
| 67 double c_time = get_time(); | 67 double c_time = get_time(); |
| 68 ARGBScale(src_argb + (src_stride_argb * b) + b * 4, src_stride_argb, | 68 ARGBScale(src_argb + (src_stride_argb * b) + b * 4, src_stride_argb, |
| 69 src_width, src_height, | 69 src_width, src_height, |
| 70 dst_argb_c + (dst_stride_argb * b) + b * 4, dst_stride_argb, | 70 dst_argb_c + (dst_stride_argb * b) + b * 4, dst_stride_argb, |
| 71 dst_width, dst_height, f); | 71 dst_width, dst_height, f); |
| 72 | 72 |
| 73 c_time = (get_time() - c_time); | 73 c_time = (get_time() - c_time); |
| 74 | 74 |
| 75 MaskCpuFlags(-1); // Enable all CPU optimization. | 75 MaskCpuFlags(benchmark_cpu_info); // Enable all CPU optimization. |
| 76 double opt_time = get_time(); | 76 double opt_time = get_time(); |
| 77 for (i = 0; i < benchmark_iterations; ++i) { | 77 for (i = 0; i < benchmark_iterations; ++i) { |
| 78 ARGBScale(src_argb + (src_stride_argb * b) + b * 4, src_stride_argb, | 78 ARGBScale(src_argb + (src_stride_argb * b) + b * 4, src_stride_argb, |
| 79 src_width, src_height, | 79 src_width, src_height, |
| 80 dst_argb_opt + (dst_stride_argb * b) + b * 4, dst_stride_argb, | 80 dst_argb_opt + (dst_stride_argb * b) + b * 4, dst_stride_argb, |
| 81 dst_width, dst_height, f); | 81 dst_width, dst_height, f); |
| 82 } | 82 } |
| 83 opt_time = (get_time() - opt_time) / benchmark_iterations; | 83 opt_time = (get_time() - opt_time) / benchmark_iterations; |
| 84 | 84 |
| 85 // Report performance of C vs OPT | 85 // Report performance of C vs OPT |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 #define DX(x, nom, denom) static_cast<int>((Abs(x) / nom) * nom) | 217 #define DX(x, nom, denom) static_cast<int>((Abs(x) / nom) * nom) |
| 218 #define SX(x, nom, denom) static_cast<int>((x / nom) * denom) | 218 #define SX(x, nom, denom) static_cast<int>((x / nom) * denom) |
| 219 | 219 |
| 220 #define TEST_FACTOR1(name, filter, nom, denom, max_diff) \ | 220 #define TEST_FACTOR1(name, filter, nom, denom, max_diff) \ |
| 221 TEST_F(LibYUVScaleTest, ARGBScaleDownBy##name##_##filter) { \ | 221 TEST_F(LibYUVScaleTest, ARGBScaleDownBy##name##_##filter) { \ |
| 222 int diff = ARGBTestFilter(SX(benchmark_width_, nom, denom), \ | 222 int diff = ARGBTestFilter(SX(benchmark_width_, nom, denom), \ |
| 223 SX(benchmark_height_, nom, denom), \ | 223 SX(benchmark_height_, nom, denom), \ |
| 224 DX(benchmark_width_, nom, denom), \ | 224 DX(benchmark_width_, nom, denom), \ |
| 225 DX(benchmark_height_, nom, denom), \ | 225 DX(benchmark_height_, nom, denom), \ |
| 226 kFilter##filter, benchmark_iterations_, \ | 226 kFilter##filter, benchmark_iterations_, \ |
| 227 disable_cpu_flags_); \ | 227 disable_cpu_flags_, benchmark_cpu_info_); \ |
| 228 EXPECT_LE(diff, max_diff); \ | 228 EXPECT_LE(diff, max_diff); \ |
| 229 } \ | 229 } \ |
| 230 TEST_F(LibYUVScaleTest, ARGBScaleDownClipBy##name##_##filter) { \ | 230 TEST_F(LibYUVScaleTest, ARGBScaleDownClipBy##name##_##filter) { \ |
| 231 int diff = ARGBClipTestFilter(SX(benchmark_width_, nom, denom), \ | 231 int diff = ARGBClipTestFilter(SX(benchmark_width_, nom, denom), \ |
| 232 SX(benchmark_height_, nom, denom), \ | 232 SX(benchmark_height_, nom, denom), \ |
| 233 DX(benchmark_width_, nom, denom), \ | 233 DX(benchmark_width_, nom, denom), \ |
| 234 DX(benchmark_height_, nom, denom), \ | 234 DX(benchmark_height_, nom, denom), \ |
| 235 kFilter##filter, benchmark_iterations_); \ | 235 kFilter##filter, benchmark_iterations_); \ |
| 236 EXPECT_LE(diff, max_diff); \ | 236 EXPECT_LE(diff, max_diff); \ |
| 237 } | 237 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 253 #undef TEST_FACTOR1 | 253 #undef TEST_FACTOR1 |
| 254 #undef TEST_FACTOR | 254 #undef TEST_FACTOR |
| 255 #undef SX | 255 #undef SX |
| 256 #undef DX | 256 #undef DX |
| 257 | 257 |
| 258 #define TEST_SCALETO1(name, width, height, filter, max_diff) \ | 258 #define TEST_SCALETO1(name, width, height, filter, max_diff) \ |
| 259 TEST_F(LibYUVScaleTest, name##To##width##x##height##_##filter) { \ | 259 TEST_F(LibYUVScaleTest, name##To##width##x##height##_##filter) { \ |
| 260 int diff = ARGBTestFilter(benchmark_width_, benchmark_height_, \ | 260 int diff = ARGBTestFilter(benchmark_width_, benchmark_height_, \ |
| 261 width, height, \ | 261 width, height, \ |
| 262 kFilter##filter, benchmark_iterations_, \ | 262 kFilter##filter, benchmark_iterations_, \ |
| 263 disable_cpu_flags_); \ | 263 disable_cpu_flags_, benchmark_cpu_info_); \ |
| 264 EXPECT_LE(diff, max_diff); \ | 264 EXPECT_LE(diff, max_diff); \ |
| 265 } \ | 265 } \ |
| 266 TEST_F(LibYUVScaleTest, name##From##width##x##height##_##filter) { \ | 266 TEST_F(LibYUVScaleTest, name##From##width##x##height##_##filter) { \ |
| 267 int diff = ARGBTestFilter(width, height, \ | 267 int diff = ARGBTestFilter(width, height, \ |
| 268 Abs(benchmark_width_), Abs(benchmark_height_), \ | 268 Abs(benchmark_width_), Abs(benchmark_height_), \ |
| 269 kFilter##filter, benchmark_iterations_, \ | 269 kFilter##filter, benchmark_iterations_, \ |
| 270 disable_cpu_flags_); \ | 270 disable_cpu_flags_, benchmark_cpu_info_); \ |
| 271 EXPECT_LE(diff, max_diff); \ | 271 EXPECT_LE(diff, max_diff); \ |
| 272 } \ | 272 } \ |
| 273 TEST_F(LibYUVScaleTest, name##ClipTo##width##x##height##_##filter) { \ | 273 TEST_F(LibYUVScaleTest, name##ClipTo##width##x##height##_##filter) { \ |
| 274 int diff = ARGBClipTestFilter(benchmark_width_, benchmark_height_, \ | 274 int diff = ARGBClipTestFilter(benchmark_width_, benchmark_height_, \ |
| 275 width, height, \ | 275 width, height, \ |
| 276 kFilter##filter, benchmark_iterations_); \ | 276 kFilter##filter, benchmark_iterations_); \ |
| 277 EXPECT_LE(diff, max_diff); \ | 277 EXPECT_LE(diff, max_diff); \ |
| 278 } \ | 278 } \ |
| 279 TEST_F(LibYUVScaleTest, name##ClipFrom##width##x##height##_##filter) { \ | 279 TEST_F(LibYUVScaleTest, name##ClipFrom##width##x##height##_##filter) { \ |
| 280 int diff = ARGBClipTestFilter(width, height, \ | 280 int diff = ARGBClipTestFilter(width, height, \ |
| (...skipping 12 matching lines...) Expand all Loading... |
| 293 TEST_SCALETO(ARGBScale, 1, 1) | 293 TEST_SCALETO(ARGBScale, 1, 1) |
| 294 TEST_SCALETO(ARGBScale, 320, 240) | 294 TEST_SCALETO(ARGBScale, 320, 240) |
| 295 TEST_SCALETO(ARGBScale, 352, 288) | 295 TEST_SCALETO(ARGBScale, 352, 288) |
| 296 TEST_SCALETO(ARGBScale, 569, 480) | 296 TEST_SCALETO(ARGBScale, 569, 480) |
| 297 TEST_SCALETO(ARGBScale, 640, 360) | 297 TEST_SCALETO(ARGBScale, 640, 360) |
| 298 TEST_SCALETO(ARGBScale, 1280, 720) | 298 TEST_SCALETO(ARGBScale, 1280, 720) |
| 299 #undef TEST_SCALETO1 | 299 #undef TEST_SCALETO1 |
| 300 #undef TEST_SCALETO | 300 #undef TEST_SCALETO |
| 301 | 301 |
| 302 } // namespace libyuv | 302 } // namespace libyuv |
| OLD | NEW |