Skip to content

Commit

Permalink
Cherry pick PR #2300: [media] Enable NEON optimization for WSOLA algo…
Browse files Browse the repository at this point in the history
…rithm (#2311)

Refer to the original PR: youtube/cobalt#2300

From https://codereview.chromium.org/2527533002, the NEON intrinsic
speeds up MultiChannelDotProduct() by ~9x on ARM.

b/315159208

Co-authored-by: Bo-Rong Chen <[email protected]>
  • Loading branch information
cobalt-github-releaser-bot and borongc authored Jan 27, 2024
1 parent 2a9d16f commit de262c9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 3 additions & 0 deletions starboard/build/config/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ config("native_target_build") {
config("starboard_implementation") {
# This allows the benchmarks to include internal only header files.
defines = [ "STARBOARD_IMPLEMENTATION" ]
if (current_cpu == "arm64" || (current_cpu == "arm" && arm_use_neon)) {
defines += [ "USE_NEON" ]
}
}

config("speed") {
Expand Down
8 changes: 5 additions & 3 deletions starboard/shared/starboard/player/filter/wsola_internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@
#include "starboard/common/scoped_ptr.h"
#include "starboard/memory.h"

// TODO: Detect Neon on ARM platform and enable SIMD.
#if SB_IS(ARCH_X86) || SB_IS(ARCH_X64)
#define USE_SIMD 1
#include <xmmintrin.h>
#endif // SB_IS(ARCH_X86) || SB_IS(ARCH_X64)
#elif (SB_IS(ARCH_ARM) || SB_IS(ARCH_ARM64)) && defined(USE_NEON)
#define USE_SIMD 1
#include <arm_neon.h>
#endif

namespace starboard {
namespace shared {
Expand Down Expand Up @@ -111,7 +113,7 @@ void MultiChannelDotProduct(const scoped_refptr<DecodedAudio>& a,
// Reduce to a single float for this channel.
float32x2_t m_half = vadd_f32(vget_high_f32(m_sum), vget_low_f32(m_sum));
dot_product[ch] = vget_lane_f32(vpadd_f32(m_half, m_half), 0);
#endif // SB_IS(ARCH_X86) || SB_IS(ARCH_X64)
#endif
}

if (!rem) {
Expand Down

0 comments on commit de262c9

Please sign in to comment.