Commit ffdd2535 authored by Eero Häkkinen's avatar Eero Häkkinen Committed by Commit Bot

Move Mac OS X optimized VectorMath code to its own file

This CL is part of VectorMath code clean up series:
[1/4] https://chromium-review.googlesource.com/c/824046
[2/4] this CL
[3/4] https://chromium-review.googlesource.com/c/824048
[4/4] https://chromium-review.googlesource.com/c/824049

Bug: 778262
Change-Id: If74c8bc5761b73a4282de20ae4c72e6ad839e464
Reviewed-on: https://chromium-review.googlesource.com/824047Reviewed-by: default avatarKenneth Russell <kbr@chromium.org>
Reviewed-by: default avatarRaymond Toy <rtoy@chromium.org>
Commit-Queue: Eero Häkkinen <eero.hakkinen@intel.com>
Cr-Commit-Position: refs/heads/master@{#524607}
parent d046a9d9
......@@ -474,6 +474,7 @@ jumbo_component("platform") {
"audio/cpu/x86/VectorMathX86.h",
"audio/ffmpeg/FFTFrameFFMPEG.cpp",
"audio/mac/FFTFrameMac.cpp",
"audio/mac/VectorMathMac.h",
"bindings/ActiveScriptWrappableBase.cpp",
"bindings/ActiveScriptWrappableBase.h",
"bindings/CallbackFunctionBase.cpp",
......
......@@ -31,17 +31,13 @@
#include "platform/wtf/Assertions.h"
#include "platform/wtf/CPU.h"
#if !defined(OS_MACOSX)
#if defined(ARCH_CPU_X86_FAMILY)
#if defined(OS_MACOSX)
#include "platform/audio/mac/VectorMathMac.h"
#elif defined(ARCH_CPU_X86_FAMILY)
#include "platform/audio/cpu/x86/VectorMathX86.h"
#else
#include "platform/audio/VectorMathScalar.h"
#endif
#endif
#if defined(OS_MACOSX)
#include <Accelerate/Accelerate.h>
#endif
#if WTF_CPU_ARM_NEON
#include <arm_neon.h>
......@@ -57,124 +53,10 @@ namespace blink {
namespace VectorMath {
#if defined(OS_MACOSX)
// On the Mac we use the highly optimized versions in Accelerate.framework
// In 32-bit mode (__ppc__ or __i386__) <Accelerate/Accelerate.h> includes
// <vecLib/vDSP_translate.h> which defines macros of the same name as
// our namespaced function names, so we must handle this case differently. Other
// architectures (64bit, ARM, etc.) do not include this header file.
void Vsmul(const float* source_p,
int source_stride,
const float* scale,
float* dest_p,
int dest_stride,
size_t frames_to_process) {
#if defined(ARCH_CPU_X86)
::vsmul(source_p, source_stride, scale, dest_p, dest_stride,
frames_to_process);
#else
vDSP_vsmul(source_p, source_stride, scale, dest_p, dest_stride,
frames_to_process);
#endif
}
void Vadd(const float* source1p,
int source_stride1,
const float* source2p,
int source_stride2,
float* dest_p,
int dest_stride,
size_t frames_to_process) {
#if defined(ARCH_CPU_X86)
::vadd(source1p, source_stride1, source2p, source_stride2, dest_p,
dest_stride, frames_to_process);
#else
vDSP_vadd(source1p, source_stride1, source2p, source_stride2, dest_p,
dest_stride, frames_to_process);
#endif
}
void Vmul(const float* source1p,
int source_stride1,
const float* source2p,
int source_stride2,
float* dest_p,
int dest_stride,
size_t frames_to_process) {
#if defined(ARCH_CPU_X86)
::vmul(source1p, source_stride1, source2p, source_stride2, dest_p,
dest_stride, frames_to_process);
#else
vDSP_vmul(source1p, source_stride1, source2p, source_stride2, dest_p,
dest_stride, frames_to_process);
#endif
}
void Zvmul(const float* real1p,
const float* imag1p,
const float* real2p,
const float* imag2p,
float* real_dest_p,
float* imag_dest_p,
size_t frames_to_process) {
DSPSplitComplex sc1;
DSPSplitComplex sc2;
DSPSplitComplex dest;
sc1.realp = const_cast<float*>(real1p);
sc1.imagp = const_cast<float*>(imag1p);
sc2.realp = const_cast<float*>(real2p);
sc2.imagp = const_cast<float*>(imag2p);
dest.realp = real_dest_p;
dest.imagp = imag_dest_p;
#if defined(ARCH_CPU_X86)
::zvmul(&sc1, 1, &sc2, 1, &dest, 1, frames_to_process, 1);
#else
vDSP_zvmul(&sc1, 1, &sc2, 1, &dest, 1, frames_to_process, 1);
#endif
}
void Vsma(const float* source_p,
int source_stride,
const float* scale,
float* dest_p,
int dest_stride,
size_t frames_to_process) {
vDSP_vsma(source_p, source_stride, scale, dest_p, dest_stride, dest_p,
dest_stride, frames_to_process);
}
void Vmaxmgv(const float* source_p,
int source_stride,
float* max_p,
size_t frames_to_process) {
vDSP_maxmgv(source_p, source_stride, max_p, frames_to_process);
}
void Vsvesq(const float* source_p,
int source_stride,
float* sum_p,
size_t frames_to_process) {
vDSP_svesq(const_cast<float*>(source_p), source_stride, sum_p,
frames_to_process);
}
void Vclip(const float* source_p,
int source_stride,
const float* low_threshold_p,
const float* high_threshold_p,
float* dest_p,
int dest_stride,
size_t frames_to_process) {
vDSP_vclip(const_cast<float*>(source_p), source_stride,
const_cast<float*>(low_threshold_p),
const_cast<float*>(high_threshold_p), dest_p, dest_stride,
frames_to_process);
}
#else
namespace {
#if defined(ARCH_CPU_X86_FAMILY)
#if defined(OS_MACOSX)
namespace Impl = Mac;
#elif defined(ARCH_CPU_X86_FAMILY)
namespace Impl = X86;
#else
namespace Impl = Scalar;
......@@ -598,8 +480,6 @@ void Vclip(const float* source_p,
dest_stride, frames_to_process);
}
#endif // defined(OS_MACOSX)
} // namespace VectorMath
} // namespace blink
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef VectorMathMac_h
#define VectorMathMac_h
#include <Accelerate/Accelerate.h>
#include "build/build_config.h"
namespace blink {
namespace VectorMath {
namespace Mac {
// On the Mac we use the highly optimized versions in Accelerate.framework
// In 32-bit mode (__ppc__ or __i386__) <Accelerate/Accelerate.h> includes
// <vecLib/vDSP_translate.h> which defines macros of the same name as
// our namespaced function names, so we must handle this case differently. Other
// architectures (64bit, ARM, etc.) do not include this header file.
static ALWAYS_INLINE void Vadd(const float* source1p,
int source_stride1,
const float* source2p,
int source_stride2,
float* dest_p,
int dest_stride,
size_t frames_to_process) {
#if defined(ARCH_CPU_X86)
::vadd(source1p, source_stride1, source2p, source_stride2, dest_p,
dest_stride, frames_to_process);
#else
vDSP_vadd(source1p, source_stride1, source2p, source_stride2, dest_p,
dest_stride, frames_to_process);
#endif
}
static ALWAYS_INLINE void Vclip(const float* source_p,
int source_stride,
const float* low_threshold_p,
const float* high_threshold_p,
float* dest_p,
int dest_stride,
size_t frames_to_process) {
vDSP_vclip(const_cast<float*>(source_p), source_stride,
const_cast<float*>(low_threshold_p),
const_cast<float*>(high_threshold_p), dest_p, dest_stride,
frames_to_process);
}
static ALWAYS_INLINE void Vmaxmgv(const float* source_p,
int source_stride,
float* max_p,
size_t frames_to_process) {
vDSP_maxmgv(source_p, source_stride, max_p, frames_to_process);
}
static ALWAYS_INLINE void Vmul(const float* source1p,
int source_stride1,
const float* source2p,
int source_stride2,
float* dest_p,
int dest_stride,
size_t frames_to_process) {
#if defined(ARCH_CPU_X86)
::vmul(source1p, source_stride1, source2p, source_stride2, dest_p,
dest_stride, frames_to_process);
#else
vDSP_vmul(source1p, source_stride1, source2p, source_stride2, dest_p,
dest_stride, frames_to_process);
#endif
}
static ALWAYS_INLINE void Vsma(const float* source_p,
int source_stride,
const float* scale,
float* dest_p,
int dest_stride,
size_t frames_to_process) {
vDSP_vsma(source_p, source_stride, scale, dest_p, dest_stride, dest_p,
dest_stride, frames_to_process);
}
static ALWAYS_INLINE void Vsmul(const float* source_p,
int source_stride,
const float* scale,
float* dest_p,
int dest_stride,
size_t frames_to_process) {
#if defined(ARCH_CPU_X86)
::vsmul(source_p, source_stride, scale, dest_p, dest_stride,
frames_to_process);
#else
vDSP_vsmul(source_p, source_stride, scale, dest_p, dest_stride,
frames_to_process);
#endif
}
static ALWAYS_INLINE void Vsvesq(const float* source_p,
int source_stride,
float* sum_p,
size_t frames_to_process) {
vDSP_svesq(const_cast<float*>(source_p), source_stride, sum_p,
frames_to_process);
}
static ALWAYS_INLINE void Zvmul(const float* real1p,
const float* imag1p,
const float* real2p,
const float* imag2p,
float* real_dest_p,
float* imag_dest_p,
size_t frames_to_process) {
DSPSplitComplex sc1;
DSPSplitComplex sc2;
DSPSplitComplex dest;
sc1.realp = const_cast<float*>(real1p);
sc1.imagp = const_cast<float*>(imag1p);
sc2.realp = const_cast<float*>(real2p);
sc2.imagp = const_cast<float*>(imag2p);
dest.realp = real_dest_p;
dest.imagp = imag_dest_p;
#if defined(ARCH_CPU_X86)
::zvmul(&sc1, 1, &sc2, 1, &dest, 1, frames_to_process, 1);
#else
vDSP_zvmul(&sc1, 1, &sc2, 1, &dest, 1, frames_to_process, 1);
#endif
}
} // namespace Mac
} // namespace VectorMath
} // namespace blink
#endif // VectorMathMac_h
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment