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

Side by Side Diff: Source/modules/webaudio/AudioParamTimeline.cpp

Issue 1288773003: SSE2 Optimization for ParamEvent::SetTarget (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Added extra comments. Created 5 years, 4 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 | « LayoutTests/webaudio/audioparam-setTargetAtTime.html ('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 (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 342
343 case ParamEvent::SetTarget: 343 case ParamEvent::SetTarget:
344 { 344 {
345 currentTime = fillToTime; 345 currentTime = fillToTime;
346 346
347 // Exponential approach to target value with given time cons tant. 347 // Exponential approach to target value with given time cons tant.
348 float target = event.value(); 348 float target = event.value();
349 float timeConstant = event.timeConstant(); 349 float timeConstant = event.timeConstant();
350 float discreteTimeConstant = static_cast<float>(AudioUtiliti es::discreteTimeConstantForSampleRate(timeConstant, controlRate)); 350 float discreteTimeConstant = static_cast<float>(AudioUtiliti es::discreteTimeConstantForSampleRate(timeConstant, controlRate));
351 351
352 #if CPU(X86) || CPU(X86_64)
353 // Resorve recursion by expanding constants to achieve a 4-s tep loop unrolling.
Raymond Toy 2015/08/14 16:00:03 "Resorve"?
adrian.belgun 2015/08/17 07:58:14 Done. Sorry for that.
354 // v1 = v0 + (t - v0) * c
355 // v2 = v1 + (t - v1) * c
356 // v2 = v0 + (t - v0) * c + (t - (v0 + (t - v0) * c)) * c
357 // v2 = v0 + (t - v0) * c + (t - v0) * c - (t - v0) * c * c
358 // v2 = v0 + (t - v0) * (2c - c^2)
359 // Thus c0 = c, c1 = 2c - c^2. The same logic applies to c2 and c3.
360 const float c0 = discreteTimeConstant;
361 const float c1 = 2 * c0 - c0 * c0;
362 const float c2 = 3 * c0 - 3 * c0 * c0 + c0 * c0 * c0;
363 const float c3 = 4 * c0 - 6 * c0 * c0 + 4 * c0 * c0 * c0 - c 0 * c0 * c0 * c0;
364
365 float delta;
366 __m128 vC = _mm_set_ps(c2, c1, c0, 0);
367 __m128 vDelta, vValue, vResult;
368
369 // Process 4 loop steps.
370 unsigned fillToFrameTrunc = writeIndex + ((fillToFrame - wri teIndex) / 4) * 4;
371 for (; writeIndex < fillToFrameTrunc; writeIndex += 4) {
372 delta = target - value;
373 vDelta = _mm_set_ps1(delta);
374 vValue = _mm_set_ps1(value);
375
376 vResult = _mm_add_ps(vValue, _mm_mul_ps(vDelta, vC));
377 _mm_storeu_ps(values + writeIndex, vResult);
378
379 // Update value for next iteration.
380 value += delta * c3;
381 }
382 #endif
383 // Serially process remaining values
352 for (; writeIndex < fillToFrame; ++writeIndex) { 384 for (; writeIndex < fillToFrame; ++writeIndex) {
353 values[writeIndex] = value; 385 values[writeIndex] = value;
354 value += (target - value) * discreteTimeConstant; 386 value += (target - value) * discreteTimeConstant;
355 } 387 }
356 388
357 break; 389 break;
358 } 390 }
359 391
360 case ParamEvent::SetValueCurve: 392 case ParamEvent::SetValueCurve:
361 { 393 {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 // to the end of the values buffer. 490 // to the end of the values buffer.
459 for (; writeIndex < numberOfValues; ++writeIndex) 491 for (; writeIndex < numberOfValues; ++writeIndex)
460 values[writeIndex] = value; 492 values[writeIndex] = value;
461 493
462 return value; 494 return value;
463 } 495 }
464 496
465 } // namespace blink 497 } // namespace blink
466 498
467 #endif // ENABLE(WEB_AUDIO) 499 #endif // ENABLE(WEB_AUDIO)
OLDNEW
« no previous file with comments | « LayoutTests/webaudio/audioparam-setTargetAtTime.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698