Bug 1266047 - Fix crash in mozilla::AudioBufferAddWithScale_SSE r=padenot
authorDan Minor <dminor@mozilla.com>
Wed, 20 Apr 2016 11:54:50 -0400
changeset 332034 1d6411584d7b5515be877eb65324e3deefc8b1be
parent 332033 f69911bd0bc2ce6fb0b4a2a825de0fcd092f3ef6
child 332035 ee179e178809b0aae6ce4a803d04386f32364fc3
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot
bugs1266047, 1266112
milestone48.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1266047 - Fix crash in mozilla::AudioBufferAddWithScale_SSE r=padenot This adds alignment checks to fallback to scalar operations if the received buffers are not properly aligned. Bug 1266112 is the follow on to either fix the alignment problem or add a vector path for the aligned portion of the buffers. MozReview-Commit-ID: 5HCXzipXlqD
dom/media/webaudio/AudioNodeEngine.cpp
dom/media/webaudio/AudioNodeEngineSSE2.cpp
--- a/dom/media/webaudio/AudioNodeEngine.cpp
+++ b/dom/media/webaudio/AudioNodeEngine.cpp
@@ -5,16 +5,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "AudioNodeEngine.h"
 #ifdef BUILD_ARM_NEON
 #include "mozilla/arm.h"
 #include "AudioNodeEngineNEON.h"
 #endif
 #ifdef USE_SSE2
+#include "AlignmentUtils.h"
 #include "AudioNodeEngineSSE2.h"
 #endif
 
 namespace mozilla {
 
 already_AddRefed<ThreadSharedFloatArrayBufferList>
 ThreadSharedFloatArrayBufferList::Create(uint32_t aChannelCount,
                                          size_t aLength,
@@ -71,17 +72,20 @@ void AudioBufferAddWithScale(const float
 #ifdef BUILD_ARM_NEON
   if (mozilla::supports_neon()) {
     AudioBufferAddWithScale_NEON(aInput, aScale, aOutput, aSize);
     return;
   }
 #endif
 
 #ifdef USE_SSE2
-  if (mozilla::supports_sse2()) {
+  // TODO: See Bug 1266112, we should either fix the source of the unaligned
+  //       buffers or do as much as possible with vector instructions and
+  //       fallback to scalar instructions where necessary.
+  if (mozilla::supports_sse2() && IS_ALIGNED16(aInput) && IS_ALIGNED16(aOutput)) {
     AudioBufferAddWithScale_SSE(aInput, aScale, aOutput, aSize);
     return;
   }
 #endif
 
   if (aScale == 1.0f) {
     for (uint32_t i = 0; i < aSize; ++i) {
       aOutput[i] += aInput[i];
@@ -112,20 +116,23 @@ AudioBlockCopyChannelWithScale(const flo
 #ifdef BUILD_ARM_NEON
     if (mozilla::supports_neon()) {
       AudioBlockCopyChannelWithScale_NEON(aInput, aScale, aOutput);
       return;
     }
 #endif
 
 #ifdef USE_SSE2
-  if (mozilla::supports_sse2()) {
-    AudioBlockCopyChannelWithScale_SSE(aInput, aScale, aOutput);
-    return;
-  }
+    // TODO: See Bug 1266112, we should either fix the source of the unaligned
+    //       buffers or do as much as possible with vector instructions and
+    //       fallback to scalar instructions where necessary.
+    if (mozilla::supports_sse2() && IS_ALIGNED16(aInput) && IS_ALIGNED16(aOutput)) {
+      AudioBlockCopyChannelWithScale_SSE(aInput, aScale, aOutput);
+      return;
+    }
 #endif
 
     for (uint32_t i = 0; i < WEBAUDIO_BLOCK_SIZE; ++i) {
       aOutput[i] = aInput[i]*aScale;
     }
   }
 }
 
--- a/dom/media/webaudio/AudioNodeEngineSSE2.cpp
+++ b/dom/media/webaudio/AudioNodeEngineSSE2.cpp
@@ -1,15 +1,15 @@
 /* -*- mode: c++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* this source code form is subject to the terms of the mozilla public
  * license, v. 2.0. if a copy of the mpl was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+#include "AudioNodeEngineSSE2.h"
 #include "AlignmentUtils.h"
-#include "AudioNodeEngineSSE2.h"
 #include <emmintrin.h>
 
 
 namespace mozilla {
 void
 AudioBufferAddWithScale_SSE(const float* aInput,
                             float aScale,
                             float* aOutput,