| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 The LibYuv Project Authors. All rights reserved. | 2 * Copyright 2012 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 | 12 |
| 13 #include "libyuv/cpu_id.h" | 13 #include "libyuv/cpu_id.h" |
| 14 #include "libyuv/rotate_argb.h" | 14 #include "libyuv/rotate_argb.h" |
| 15 #include "libyuv/row.h" | 15 #include "libyuv/row.h" |
| 16 #include "../unit_test/unit_test.h" | 16 #include "../unit_test/unit_test.h" |
| 17 | 17 |
| 18 namespace libyuv { | 18 namespace libyuv { |
| 19 | 19 |
| 20 void TestRotateBpp(int src_width, int src_height, | 20 void TestRotateBpp(int src_width, int src_height, |
| 21 int dst_width, int dst_height, | 21 int dst_width, int dst_height, |
| 22 libyuv::RotationMode mode, | 22 libyuv::RotationMode mode, |
| 23 int benchmark_iterations, int disable_cpu_flags, | 23 int benchmark_iterations, |
| 24 int disable_cpu_flags, |
| 25 int benchmark_cpu_info, |
| 24 const int kBpp) { | 26 const int kBpp) { |
| 25 if (src_width < 1) { | 27 if (src_width < 1) { |
| 26 src_width = 1; | 28 src_width = 1; |
| 27 } | 29 } |
| 28 if (src_height < 1) { | 30 if (src_height < 1) { |
| 29 src_height = 1; | 31 src_height = 1; |
| 30 } | 32 } |
| 31 if (dst_width < 1) { | 33 if (dst_width < 1) { |
| 32 dst_width = 1; | 34 dst_width = 1; |
| 33 } | 35 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 47 align_buffer_64(dst_argb_opt, dst_argb_plane_size); | 49 align_buffer_64(dst_argb_opt, dst_argb_plane_size); |
| 48 memset(dst_argb_c, 2, dst_argb_plane_size); | 50 memset(dst_argb_c, 2, dst_argb_plane_size); |
| 49 memset(dst_argb_opt, 3, dst_argb_plane_size); | 51 memset(dst_argb_opt, 3, dst_argb_plane_size); |
| 50 | 52 |
| 51 if (kBpp == 1) { | 53 if (kBpp == 1) { |
| 52 MaskCpuFlags(disable_cpu_flags); // Disable all CPU optimization. | 54 MaskCpuFlags(disable_cpu_flags); // Disable all CPU optimization. |
| 53 RotatePlane(src_argb, src_stride_argb, | 55 RotatePlane(src_argb, src_stride_argb, |
| 54 dst_argb_c, dst_stride_argb, | 56 dst_argb_c, dst_stride_argb, |
| 55 src_width, src_height, mode); | 57 src_width, src_height, mode); |
| 56 | 58 |
| 57 MaskCpuFlags(-1); // Enable all CPU optimization. | 59 MaskCpuFlags(benchmark_cpu_info); // Enable all CPU optimization. |
| 58 for (int i = 0; i < benchmark_iterations; ++i) { | 60 for (int i = 0; i < benchmark_iterations; ++i) { |
| 59 RotatePlane(src_argb, src_stride_argb, | 61 RotatePlane(src_argb, src_stride_argb, |
| 60 dst_argb_opt, dst_stride_argb, | 62 dst_argb_opt, dst_stride_argb, |
| 61 src_width, src_height, mode); | 63 src_width, src_height, mode); |
| 62 } | 64 } |
| 63 } else if (kBpp == 4) { | 65 } else if (kBpp == 4) { |
| 64 MaskCpuFlags(disable_cpu_flags); // Disable all CPU optimization. | 66 MaskCpuFlags(disable_cpu_flags); // Disable all CPU optimization. |
| 65 ARGBRotate(src_argb, src_stride_argb, | 67 ARGBRotate(src_argb, src_stride_argb, |
| 66 dst_argb_c, dst_stride_argb, | 68 dst_argb_c, dst_stride_argb, |
| 67 src_width, src_height, mode); | 69 src_width, src_height, mode); |
| 68 | 70 |
| 69 MaskCpuFlags(-1); // Enable all CPU optimization. | 71 MaskCpuFlags(benchmark_cpu_info); // Enable all CPU optimization. |
| 70 for (int i = 0; i < benchmark_iterations; ++i) { | 72 for (int i = 0; i < benchmark_iterations; ++i) { |
| 71 ARGBRotate(src_argb, src_stride_argb, | 73 ARGBRotate(src_argb, src_stride_argb, |
| 72 dst_argb_opt, dst_stride_argb, | 74 dst_argb_opt, dst_stride_argb, |
| 73 src_width, src_height, mode); | 75 src_width, src_height, mode); |
| 74 } | 76 } |
| 75 } | 77 } |
| 76 | 78 |
| 77 // Rotation should be exact. | 79 // Rotation should be exact. |
| 78 for (int i = 0; i < dst_argb_plane_size; ++i) { | 80 for (int i = 0; i < dst_argb_plane_size; ++i) { |
| 79 EXPECT_EQ(dst_argb_c[i], dst_argb_opt[i]); | 81 EXPECT_EQ(dst_argb_c[i], dst_argb_opt[i]); |
| 80 } | 82 } |
| 81 | 83 |
| 82 free_aligned_buffer_64(dst_argb_c); | 84 free_aligned_buffer_64(dst_argb_c); |
| 83 free_aligned_buffer_64(dst_argb_opt); | 85 free_aligned_buffer_64(dst_argb_opt); |
| 84 free_aligned_buffer_64(src_argb); | 86 free_aligned_buffer_64(src_argb); |
| 85 } | 87 } |
| 86 | 88 |
| 87 static void ARGBTestRotate(int src_width, int src_height, | 89 static void ARGBTestRotate(int src_width, int src_height, |
| 88 int dst_width, int dst_height, | 90 int dst_width, int dst_height, |
| 89 libyuv::RotationMode mode, | 91 libyuv::RotationMode mode, |
| 90 int benchmark_iterations, int disable_cpu_flags) { | 92 int benchmark_iterations, |
| 93 int disable_cpu_flags, |
| 94 int benchmark_cpu_info) { |
| 91 TestRotateBpp(src_width, src_height, | 95 TestRotateBpp(src_width, src_height, |
| 92 dst_width, dst_height, | 96 dst_width, dst_height, |
| 93 mode, benchmark_iterations, disable_cpu_flags, 4); | 97 mode, benchmark_iterations, |
| 98 disable_cpu_flags, benchmark_cpu_info, 4); |
| 94 } | 99 } |
| 95 | 100 |
| 96 TEST_F(LibYUVRotateTest, ARGBRotate0) { | 101 TEST_F(LibYUVRotateTest, ARGBRotate0) { |
| 97 ARGBTestRotate(benchmark_width_, benchmark_height_, | 102 ARGBTestRotate(benchmark_width_, benchmark_height_, |
| 98 benchmark_width_, benchmark_height_, | 103 benchmark_width_, benchmark_height_, |
| 99 kRotate0, benchmark_iterations_, disable_cpu_flags_); | 104 kRotate0, benchmark_iterations_, |
| 105 disable_cpu_flags_, benchmark_cpu_info_); |
| 100 } | 106 } |
| 101 | 107 |
| 102 TEST_F(LibYUVRotateTest, ARGBRotate90) { | 108 TEST_F(LibYUVRotateTest, ARGBRotate90) { |
| 103 ARGBTestRotate(benchmark_width_, benchmark_height_, | 109 ARGBTestRotate(benchmark_width_, benchmark_height_, |
| 104 benchmark_height_, benchmark_width_, | 110 benchmark_height_, benchmark_width_, |
| 105 kRotate90, benchmark_iterations_, disable_cpu_flags_); | 111 kRotate90, benchmark_iterations_, |
| 112 disable_cpu_flags_, benchmark_cpu_info_); |
| 106 } | 113 } |
| 107 | 114 |
| 108 TEST_F(LibYUVRotateTest, ARGBRotate180) { | 115 TEST_F(LibYUVRotateTest, ARGBRotate180) { |
| 109 ARGBTestRotate(benchmark_width_, benchmark_height_, | 116 ARGBTestRotate(benchmark_width_, benchmark_height_, |
| 110 benchmark_width_, benchmark_height_, | 117 benchmark_width_, benchmark_height_, |
| 111 kRotate180, benchmark_iterations_, disable_cpu_flags_); | 118 kRotate180, benchmark_iterations_, |
| 119 disable_cpu_flags_, benchmark_cpu_info_); |
| 112 } | 120 } |
| 113 | 121 |
| 114 TEST_F(LibYUVRotateTest, ARGBRotate270) { | 122 TEST_F(LibYUVRotateTest, ARGBRotate270) { |
| 115 ARGBTestRotate(benchmark_width_, benchmark_height_, | 123 ARGBTestRotate(benchmark_width_, benchmark_height_, |
| 116 benchmark_height_, benchmark_width_, | 124 benchmark_height_, benchmark_width_, |
| 117 kRotate270, benchmark_iterations_, disable_cpu_flags_); | 125 kRotate270, benchmark_iterations_, |
| 126 disable_cpu_flags_, benchmark_cpu_info_); |
| 118 } | 127 } |
| 119 | 128 |
| 120 TEST_F(LibYUVRotateTest, ARGBRotate0_Odd) { | 129 TEST_F(LibYUVRotateTest, ARGBRotate0_Odd) { |
| 121 ARGBTestRotate(benchmark_width_ - 3, benchmark_height_ - 1, | 130 ARGBTestRotate(benchmark_width_ - 3, benchmark_height_ - 1, |
| 122 benchmark_width_ - 3, benchmark_height_ - 1, | 131 benchmark_width_ - 3, benchmark_height_ - 1, |
| 123 kRotate0, benchmark_iterations_, disable_cpu_flags_); | 132 kRotate0, benchmark_iterations_, |
| 133 disable_cpu_flags_, benchmark_cpu_info_); |
| 124 } | 134 } |
| 125 | 135 |
| 126 TEST_F(LibYUVRotateTest, ARGBRotate90_Odd) { | 136 TEST_F(LibYUVRotateTest, ARGBRotate90_Odd) { |
| 127 ARGBTestRotate(benchmark_width_ - 3, benchmark_height_ - 1, | 137 ARGBTestRotate(benchmark_width_ - 3, benchmark_height_ - 1, |
| 128 benchmark_height_ - 1, benchmark_width_ - 3, | 138 benchmark_height_ - 1, benchmark_width_ - 3, |
| 129 kRotate90, benchmark_iterations_, disable_cpu_flags_); | 139 kRotate90, benchmark_iterations_, |
| 140 disable_cpu_flags_, benchmark_cpu_info_); |
| 130 } | 141 } |
| 131 | 142 |
| 132 TEST_F(LibYUVRotateTest, ARGBRotate180_Odd) { | 143 TEST_F(LibYUVRotateTest, ARGBRotate180_Odd) { |
| 133 ARGBTestRotate(benchmark_width_ - 3, benchmark_height_ - 1, | 144 ARGBTestRotate(benchmark_width_ - 3, benchmark_height_ - 1, |
| 134 benchmark_width_ - 3, benchmark_height_ - 1, | 145 benchmark_width_ - 3, benchmark_height_ - 1, |
| 135 kRotate180, benchmark_iterations_, disable_cpu_flags_); | 146 kRotate180, benchmark_iterations_, |
| 147 disable_cpu_flags_, benchmark_cpu_info_); |
| 136 } | 148 } |
| 137 | 149 |
| 138 TEST_F(LibYUVRotateTest, ARGBRotate270_Odd) { | 150 TEST_F(LibYUVRotateTest, ARGBRotate270_Odd) { |
| 139 ARGBTestRotate(benchmark_width_ - 3, benchmark_height_ - 1, | 151 ARGBTestRotate(benchmark_width_ - 3, benchmark_height_ - 1, |
| 140 benchmark_height_ - 1, benchmark_width_ - 3, | 152 benchmark_height_ - 1, benchmark_width_ - 3, |
| 141 kRotate270, benchmark_iterations_, disable_cpu_flags_); | 153 kRotate270, benchmark_iterations_, |
| 154 disable_cpu_flags_, benchmark_cpu_info_); |
| 142 } | 155 } |
| 143 | 156 |
| 144 static void TestRotatePlane(int src_width, int src_height, | 157 static void TestRotatePlane(int src_width, int src_height, |
| 145 int dst_width, int dst_height, | 158 int dst_width, int dst_height, |
| 146 libyuv::RotationMode mode, | 159 libyuv::RotationMode mode, |
| 147 int benchmark_iterations, int disable_cpu_flags) { | 160 int benchmark_iterations, |
| 161 int disable_cpu_flags, |
| 162 int benchmark_cpu_info) { |
| 148 TestRotateBpp(src_width, src_height, | 163 TestRotateBpp(src_width, src_height, |
| 149 dst_width, dst_height, | 164 dst_width, dst_height, |
| 150 mode, benchmark_iterations, disable_cpu_flags, 1); | 165 mode, benchmark_iterations, |
| 166 disable_cpu_flags, benchmark_cpu_info, 1); |
| 151 } | 167 } |
| 152 | 168 |
| 153 TEST_F(LibYUVRotateTest, RotatePlane0) { | 169 TEST_F(LibYUVRotateTest, RotatePlane0) { |
| 154 TestRotatePlane(benchmark_width_, benchmark_height_, | 170 TestRotatePlane(benchmark_width_, benchmark_height_, |
| 155 benchmark_width_, benchmark_height_, | 171 benchmark_width_, benchmark_height_, |
| 156 kRotate0, benchmark_iterations_, disable_cpu_flags_); | 172 kRotate0, benchmark_iterations_, |
| 173 disable_cpu_flags_, benchmark_cpu_info_); |
| 157 } | 174 } |
| 158 | 175 |
| 159 TEST_F(LibYUVRotateTest, RotatePlane90) { | 176 TEST_F(LibYUVRotateTest, RotatePlane90) { |
| 160 TestRotatePlane(benchmark_width_, benchmark_height_, | 177 TestRotatePlane(benchmark_width_, benchmark_height_, |
| 161 benchmark_height_, benchmark_width_, | 178 benchmark_height_, benchmark_width_, |
| 162 kRotate90, benchmark_iterations_, disable_cpu_flags_); | 179 kRotate90, benchmark_iterations_, |
| 180 disable_cpu_flags_, benchmark_cpu_info_); |
| 163 } | 181 } |
| 164 | 182 |
| 165 TEST_F(LibYUVRotateTest, RotatePlane180) { | 183 TEST_F(LibYUVRotateTest, RotatePlane180) { |
| 166 TestRotatePlane(benchmark_width_, benchmark_height_, | 184 TestRotatePlane(benchmark_width_, benchmark_height_, |
| 167 benchmark_width_, benchmark_height_, | 185 benchmark_width_, benchmark_height_, |
| 168 kRotate180, benchmark_iterations_, disable_cpu_flags_); | 186 kRotate180, benchmark_iterations_, |
| 187 disable_cpu_flags_, benchmark_cpu_info_); |
| 169 } | 188 } |
| 170 | 189 |
| 171 TEST_F(LibYUVRotateTest, RotatePlane270) { | 190 TEST_F(LibYUVRotateTest, RotatePlane270) { |
| 172 TestRotatePlane(benchmark_width_, benchmark_height_, | 191 TestRotatePlane(benchmark_width_, benchmark_height_, |
| 173 benchmark_height_, benchmark_width_, | 192 benchmark_height_, benchmark_width_, |
| 174 kRotate270, benchmark_iterations_, disable_cpu_flags_); | 193 kRotate270, benchmark_iterations_, |
| 194 disable_cpu_flags_, benchmark_cpu_info_); |
| 175 } | 195 } |
| 176 | 196 |
| 177 TEST_F(LibYUVRotateTest, RotatePlane0_Odd) { | 197 TEST_F(LibYUVRotateTest, RotatePlane0_Odd) { |
| 178 TestRotatePlane(benchmark_width_ - 3, benchmark_height_ - 1, | 198 TestRotatePlane(benchmark_width_ - 3, benchmark_height_ - 1, |
| 179 benchmark_width_ - 3, benchmark_height_ - 1, | 199 benchmark_width_ - 3, benchmark_height_ - 1, |
| 180 kRotate0, benchmark_iterations_, disable_cpu_flags_); | 200 kRotate0, benchmark_iterations_, |
| 201 disable_cpu_flags_, benchmark_cpu_info_); |
| 181 } | 202 } |
| 182 | 203 |
| 183 TEST_F(LibYUVRotateTest, RotatePlane90_Odd) { | 204 TEST_F(LibYUVRotateTest, RotatePlane90_Odd) { |
| 184 TestRotatePlane(benchmark_width_ - 3, benchmark_height_ - 1, | 205 TestRotatePlane(benchmark_width_ - 3, benchmark_height_ - 1, |
| 185 benchmark_height_ - 1, benchmark_width_ - 3, | 206 benchmark_height_ - 1, benchmark_width_ - 3, |
| 186 kRotate90, benchmark_iterations_, disable_cpu_flags_); | 207 kRotate90, benchmark_iterations_, |
| 208 disable_cpu_flags_, benchmark_cpu_info_); |
| 187 } | 209 } |
| 188 | 210 |
| 189 TEST_F(LibYUVRotateTest, RotatePlane180_Odd) { | 211 TEST_F(LibYUVRotateTest, RotatePlane180_Odd) { |
| 190 TestRotatePlane(benchmark_width_ - 3, benchmark_height_ - 1, | 212 TestRotatePlane(benchmark_width_ - 3, benchmark_height_ - 1, |
| 191 benchmark_width_ - 3, benchmark_height_ - 1, | 213 benchmark_width_ - 3, benchmark_height_ - 1, |
| 192 kRotate180, benchmark_iterations_, disable_cpu_flags_); | 214 kRotate180, benchmark_iterations_, |
| 215 disable_cpu_flags_, benchmark_cpu_info_); |
| 193 } | 216 } |
| 194 | 217 |
| 195 TEST_F(LibYUVRotateTest, RotatePlane270_Odd) { | 218 TEST_F(LibYUVRotateTest, RotatePlane270_Odd) { |
| 196 TestRotatePlane(benchmark_width_ - 3, benchmark_height_ - 1, | 219 TestRotatePlane(benchmark_width_ - 3, benchmark_height_ - 1, |
| 197 benchmark_height_ - 1, benchmark_width_ - 3, | 220 benchmark_height_ - 1, benchmark_width_ - 3, |
| 198 kRotate270, benchmark_iterations_, disable_cpu_flags_); | 221 kRotate270, benchmark_iterations_, |
| 222 disable_cpu_flags_, benchmark_cpu_info_); |
| 199 } | 223 } |
| 200 | 224 |
| 201 } // namespace libyuv | 225 } // namespace libyuv |
| OLD | NEW |