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 |
(...skipping 1131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1142 EXPECT_LE(max_diff, 1); | 1142 EXPECT_LE(max_diff, 1); |
1143 } | 1143 } |
1144 | 1144 |
1145 TEST_F(LibYUVPlanarTest, ARGBBlend_Opt) { | 1145 TEST_F(LibYUVPlanarTest, ARGBBlend_Opt) { |
1146 int max_diff = TestBlend(benchmark_width_, benchmark_height_, | 1146 int max_diff = TestBlend(benchmark_width_, benchmark_height_, |
1147 benchmark_iterations_, | 1147 benchmark_iterations_, |
1148 disable_cpu_flags_, benchmark_cpu_info_, +1, 0); | 1148 disable_cpu_flags_, benchmark_cpu_info_, +1, 0); |
1149 EXPECT_LE(max_diff, 1); | 1149 EXPECT_LE(max_diff, 1); |
1150 } | 1150 } |
1151 | 1151 |
1152 #ifdef HAS_BLENDPLANEROW_AVX2 | |
1153 static void TestBlendPlaneRow(int width, int height, int benchmark_iterations, | |
1154 int invert, int off) { | |
1155 int has_ssse3 = TestCpuFlag(kCpuHasSSSE3); | |
1156 int has_avx2 = TestCpuFlag(kCpuHasAVX2); | |
1157 width = width * height; | |
1158 height = 1; | |
1159 if (width < 256) { | |
1160 width = 256; | |
1161 } | |
1162 const int kBpp = 1; | |
1163 const int kStride = width * kBpp; | |
1164 align_buffer_64(src_argb_a, kStride * height + off); | |
1165 align_buffer_64(src_argb_b, kStride * height + off); | |
1166 align_buffer_64(src_argb_alpha, kStride * height + off); | |
1167 align_buffer_64(dst_argb_c, kStride * height + off); | |
1168 align_buffer_64(dst_argb_opt, kStride * height + off); | |
1169 memset(dst_argb_c, 255, kStride * height + off); | |
1170 memset(dst_argb_opt, 255, kStride * height + off); | |
1171 | |
1172 if (has_ssse3) { | |
1173 // Test source is maintained exactly if alpha is 255. | |
1174 for (int i = 0; i < 256; ++i) { | |
1175 src_argb_a[i + off] = i; | |
1176 src_argb_b[i + off] = 255 - i; | |
1177 src_argb_alpha[i + off] = 255; | |
1178 } | |
1179 BlendPlaneRow_SSSE3(src_argb_a + off, | |
1180 src_argb_b + off, | |
1181 src_argb_alpha + off, | |
1182 dst_argb_opt + off, | |
1183 256); | |
1184 for (int i = 0; i < 256; ++i) { | |
1185 EXPECT_EQ(src_argb_a[i + off], dst_argb_opt[i + off]); | |
1186 } | |
1187 // Test destination is maintained exactly if alpha is 0. | |
1188 for (int i = 0; i < 256; ++i) { | |
1189 src_argb_a[i + off] = i; | |
1190 src_argb_b[i + off] = 255 - i; | |
1191 src_argb_alpha[i + off] = 0; | |
1192 } | |
1193 BlendPlaneRow_SSSE3(src_argb_a + off, | |
1194 src_argb_b + off, | |
1195 src_argb_alpha + off, | |
1196 dst_argb_opt + off, | |
1197 256); | |
1198 for (int i = 0; i < 256; ++i) { | |
1199 EXPECT_EQ(src_argb_b[i + off], dst_argb_opt[i + off]); | |
1200 } | |
1201 } | |
1202 for (int i = 0; i < kStride * height; ++i) { | |
1203 src_argb_a[i + off] = (fastrand() & 0xff); | |
1204 src_argb_b[i + off] = (fastrand() & 0xff); | |
1205 src_argb_alpha[i + off] = (fastrand() & 0xff); | |
1206 } | |
1207 | |
1208 BlendPlaneRow_C(src_argb_a + off, | |
1209 src_argb_b + off, | |
1210 src_argb_alpha + off, | |
1211 dst_argb_c + off, | |
1212 width * height); | |
1213 for (int i = 0; i < benchmark_iterations; ++i) { | |
1214 if (has_avx2) { | |
1215 BlendPlaneRow_AVX2(src_argb_a + off, | |
1216 src_argb_b + off, | |
1217 src_argb_alpha + off, | |
1218 dst_argb_opt + off, | |
1219 width * height); | |
1220 } else { | |
1221 if (has_ssse3) { | |
1222 BlendPlaneRow_SSSE3(src_argb_a + off, | |
1223 src_argb_b + off, | |
1224 src_argb_alpha + off, | |
1225 dst_argb_opt + off, | |
1226 width * height); | |
1227 } else { | |
1228 BlendPlaneRow_C(src_argb_a + off, | |
1229 src_argb_b + off, | |
1230 src_argb_alpha + off, | |
1231 dst_argb_opt + off, | |
1232 width * height); | |
1233 } | |
1234 } | |
1235 } | |
1236 for (int i = 0; i < kStride * height; ++i) { | |
1237 EXPECT_EQ(dst_argb_c[i + off], dst_argb_opt[i + off]); | |
1238 } | |
1239 free_aligned_buffer_64(src_argb_a); | |
1240 free_aligned_buffer_64(src_argb_b); | |
1241 free_aligned_buffer_64(src_argb_alpha); | |
1242 free_aligned_buffer_64(dst_argb_c); | |
1243 free_aligned_buffer_64(dst_argb_opt); | |
1244 return; | |
1245 } | |
1246 | |
1247 TEST_F(LibYUVPlanarTest, BlendPlaneRow_Opt) { | |
1248 TestBlendPlaneRow(benchmark_width_, benchmark_height_, benchmark_iterations_, | |
1249 +1, 0); | |
1250 } | |
1251 TEST_F(LibYUVPlanarTest, BlendPlaneRow_Unaligned) { | |
1252 TestBlendPlaneRow(benchmark_width_, benchmark_height_, benchmark_iterations_, | |
1253 +1, 1); | |
1254 } | |
1255 #endif | |
1256 | |
1257 static void TestBlendPlane(int width, int height, int benchmark_iterations, | 1152 static void TestBlendPlane(int width, int height, int benchmark_iterations, |
1258 int disable_cpu_flags, int benchmark_cpu_info, | 1153 int disable_cpu_flags, int benchmark_cpu_info, |
1259 int invert, int off) { | 1154 int invert, int off) { |
1260 if (width < 1) { | 1155 if (width < 1) { |
1261 width = 1; | 1156 width = 1; |
1262 } | 1157 } |
1263 const int kBpp = 1; | 1158 const int kBpp = 1; |
1264 const int kStride = width * kBpp; | 1159 const int kStride = width * kBpp; |
1265 align_buffer_64(src_argb_a, kStride * height + off); | 1160 align_buffer_64(src_argb_a, kStride * height + off); |
1266 align_buffer_64(src_argb_b, kStride * height + off); | 1161 align_buffer_64(src_argb_b, kStride * height + off); |
(...skipping 1359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2626 | 2521 |
2627 TEST_F(LibYUVPlanarTest, SetPlane_Opt) { | 2522 TEST_F(LibYUVPlanarTest, SetPlane_Opt) { |
2628 int max_diff = TestARGBRect(benchmark_width_, benchmark_height_, | 2523 int max_diff = TestARGBRect(benchmark_width_, benchmark_height_, |
2629 benchmark_iterations_, | 2524 benchmark_iterations_, |
2630 disable_cpu_flags_, benchmark_cpu_info_, | 2525 disable_cpu_flags_, benchmark_cpu_info_, |
2631 +1, 0, 1); | 2526 +1, 0, 1); |
2632 EXPECT_EQ(0, max_diff); | 2527 EXPECT_EQ(0, max_diff); |
2633 } | 2528 } |
2634 | 2529 |
2635 } // namespace libyuv | 2530 } // namespace libyuv |
OLD | NEW |