Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: unit_test/color_test.cc

Issue 1367403007: Speed up rounding to byte test (Closed) Base URL: https://chromium.googlesource.com/libyuv/libyuv@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/libyuv/version.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 The LibYuv Project Authors. All rights reserved. 2 * Copyright 2015 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 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 *r = orig_pixels[2]; 222 *r = orig_pixels[2];
223 } 223 }
224 224
225 // Pick a method for clamping. 225 // Pick a method for clamping.
226 #define CLAMPMETHOD_IF 1 226 #define CLAMPMETHOD_IF 1
227 // #define CLAMPMETHOD_TABLE 1 227 // #define CLAMPMETHOD_TABLE 1
228 // #define CLAMPMETHOD_TERNARY 1 228 // #define CLAMPMETHOD_TERNARY 1
229 // #define CLAMPMETHOD_MASK 1 229 // #define CLAMPMETHOD_MASK 1
230 230
231 // Pick a method for rounding. 231 // Pick a method for rounding.
232 #define ROUND(f) static_cast<int>(f + 0.5) 232 #define ROUND(f) lrintf(f)
brucedawson 2015/10/02 18:48:07 But, lrintf is ~376 times slower on VC++ (https://
fbarchard 2015/10/02 21:44:53 Done.
233 // #define ROUND(f) lrintf(f) 233 //#define ROUND(f) static_cast<int>(f + 0.5)
234 // #define ROUND(f) static_cast<int>(round(f)) 234 //#define ROUND(f) static_cast<int>(round(f))
235 // #define ROUND(f) _mm_cvt_ss2si(_mm_load_ss(&f)) 235 //#define ROUND(f) _mm_cvt_ss2si(_mm_load_ss(&f))
236 236
237 #if defined(CLAMPMETHOD_IF) 237 #if defined(CLAMPMETHOD_IF)
238 static int RoundToByte(float f) { 238 static int RoundToByte(float f) {
239 int i = ROUND(f); 239 int i = ROUND(f);
240 if (i < 0) { 240 if (i < 0) {
241 i = 0; 241 i = 0;
242 } 242 }
243 if (i > 255) { 243 if (i > 255) {
244 i = 255; 244 i = 255;
245 } 245 }
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 int i = ROUND(f); 307 int i = ROUND(f);
308 i = ((-(i) >> 31) & (i)); // clamp to 0. 308 i = ((-(i) >> 31) & (i)); // clamp to 0.
309 return (((255 - (i)) >> 31) | (i)) & 255; // clamp to 255. 309 return (((255 - (i)) >> 31) | (i)) & 255; // clamp to 255.
310 } 310 }
311 #endif 311 #endif
312 312
313 #define RANDOM256(s) ((s & 1) ? ((s >> 1) ^ 0xb8) : (s >> 1)) 313 #define RANDOM256(s) ((s & 1) ? ((s >> 1) ^ 0xb8) : (s >> 1))
314 314
315 TEST_F(libyuvTest, TestRoundToByte) { 315 TEST_F(libyuvTest, TestRoundToByte) {
316 int allb = 0; 316 int allb = 0;
317 for (int i = 0; i < benchmark_iterations_; ++i) { 317 int count = benchmark_width_ * benchmark_height_ * benchmark_iterations_;
318 for (int u2 = 0; u2 < 256; ++u2) { 318 for (int i = 0; i < count; ++i) {
319 for (int v2 = 0; v2 < 256; ++v2) { 319 int y = RANDOM256(i);
320 for (int y2 = 0; y2 < 256; ++y2) { 320 int b = RoundToByte(y * 810.33 - 257);
321 int y = RANDOM256(y2); 321 allb |= b;
322 int b = RoundToByte(y * 810.33 - 257);
323 allb |= b;
324 }
325 }
326 }
327 } 322 }
328 EXPECT_GE(allb, 0); 323 EXPECT_GE(allb, 0);
329 EXPECT_LE(allb, 255); 324 EXPECT_LE(allb, 255);
330 } 325 }
331 326
332 static void YUVToRGBReference(int y, int u, int v, int* r, int* g, int* b) { 327 static void YUVToRGBReference(int y, int u, int v, int* r, int* g, int* b) {
333 *r = RoundToByte((y - 16) * 1.164 - (v - 128) * -1.596); 328 *r = RoundToByte((y - 16) * 1.164 - (v - 128) * -1.596);
334 *g = RoundToByte((y - 16) * 1.164 - (u - 128) * 0.391 - (v - 128) * 0.813); 329 *g = RoundToByte((y - 16) * 1.164 - (u - 128) * 0.391 - (v - 128) * 0.813);
335 *b = RoundToByte((y - 16) * 1.164 - (u - 128) * -2.018); 330 *b = RoundToByte((y - 16) * 1.164 - (u - 128) * -2.018);
336 } 331 }
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 EXPECT_EQ(r0, r1); 546 EXPECT_EQ(r0, r1);
552 EXPECT_EQ(g0, g1); 547 EXPECT_EQ(g0, g1);
553 EXPECT_EQ(b0, b1); 548 EXPECT_EQ(b0, b1);
554 EXPECT_EQ(r0, r2); 549 EXPECT_EQ(r0, r2);
555 EXPECT_EQ(g0, g2); 550 EXPECT_EQ(g0, g2);
556 EXPECT_EQ(b0, b2); 551 EXPECT_EQ(b0, b2);
557 } 552 }
558 } 553 }
559 554
560 } // namespace libyuv 555 } // namespace libyuv
OLDNEW
« no previous file with comments | « include/libyuv/version.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698