mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
DSP: Added SIMDRegister::copyToRawArray and SIMDRegister::fromRawArray to easily convert between raw arrays and SIMD registers
This commit is contained in:
parent
bb7b8e6ee9
commit
eb8400b366
6 changed files with 325 additions and 55 deletions
|
|
@ -115,6 +115,20 @@ struct SIMDRegister
|
|||
__mm128 for single-precision floating point on SSE architectures). */
|
||||
inline static SIMDRegister JUCE_VECTOR_CALLTYPE fromNative (vSIMDType a) noexcept { return {a}; }
|
||||
|
||||
/** Creates a new SIMDRegister from the first SIMDNumElements of a scalar array. */
|
||||
inline static SIMDRegister JUCE_VECTOR_CALLTYPE fromRawArray (const ElementType* a) noexcept
|
||||
{
|
||||
jassert (isSIMDAligned (a));
|
||||
return {CmplxOps::load (a)};
|
||||
}
|
||||
|
||||
/** Copies the elements of the SIMDRegister to a scalar array in memory. */
|
||||
inline void JUCE_VECTOR_CALLTYPE copyToRawArray (ElementType* a) const noexcept
|
||||
{
|
||||
jassert (isSIMDAligned (a));
|
||||
CmplxOps::store (value, a);
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
/** Returns the idx-th element of the receiver. Note that this does not check if idx
|
||||
is larger than the native register size. */
|
||||
|
|
@ -269,7 +283,7 @@ struct SIMDRegister
|
|||
|
||||
//==============================================================================
|
||||
/** Checks if the given pointer is suffeciently aligned for using SIMD operations. */
|
||||
static inline bool isSIMDAligned (ElementType* ptr) noexcept
|
||||
static inline bool isSIMDAligned (const ElementType* ptr) noexcept
|
||||
{
|
||||
uintptr_t bitmask = SIMDRegisterSize - 1;
|
||||
return (reinterpret_cast<uintptr_t> (ptr) & bitmask) == 0;
|
||||
|
|
@ -285,6 +299,13 @@ struct SIMDRegister
|
|||
return snapPointerToAlignment (ptr, SIMDRegisterSize);
|
||||
}
|
||||
|
||||
#ifndef DOXYGEN
|
||||
static inline const ElementType* getNextSIMDAlignedPtr (const ElementType* ptr) noexcept
|
||||
{
|
||||
return snapPointerToAlignment (ptr, SIMDRegisterSize);
|
||||
}
|
||||
#endif
|
||||
|
||||
private:
|
||||
static inline vMaskType JUCE_VECTOR_CALLTYPE toMaskType (vSIMDType a) noexcept
|
||||
{
|
||||
|
|
@ -333,6 +354,16 @@ struct CmplxSIMDOps
|
|||
{
|
||||
typedef typename SIMDNativeOps<Scalar>::vSIMDType vSIMDType;
|
||||
|
||||
static inline vSIMDType JUCE_VECTOR_CALLTYPE load (const Scalar* a) noexcept
|
||||
{
|
||||
return SIMDNativeOps<Scalar>::load (a);
|
||||
}
|
||||
|
||||
static inline void JUCE_VECTOR_CALLTYPE store (vSIMDType value, Scalar* dest) noexcept
|
||||
{
|
||||
SIMDNativeOps<Scalar>::store (value, dest);
|
||||
}
|
||||
|
||||
static inline vSIMDType JUCE_VECTOR_CALLTYPE expand (Scalar s) noexcept
|
||||
{
|
||||
return SIMDNativeOps<Scalar>::expand (s);
|
||||
|
|
@ -360,6 +391,16 @@ struct CmplxSIMDOps<std::complex<Scalar>>
|
|||
{
|
||||
typedef typename SIMDNativeOps<Scalar>::vSIMDType vSIMDType;
|
||||
|
||||
static inline vSIMDType JUCE_VECTOR_CALLTYPE load (const std::complex<Scalar>* a) noexcept
|
||||
{
|
||||
return SIMDNativeOps<Scalar>::load (reinterpret_cast<const Scalar*> (a));
|
||||
}
|
||||
|
||||
static inline void JUCE_VECTOR_CALLTYPE store (vSIMDType value, std::complex<Scalar>* dest) noexcept
|
||||
{
|
||||
SIMDNativeOps<Scalar>::store (value, reinterpret_cast<Scalar*> (dest));
|
||||
}
|
||||
|
||||
static inline vSIMDType JUCE_VECTOR_CALLTYPE expand (std::complex<Scalar> s) noexcept
|
||||
{
|
||||
const int n = sizeof (vSIMDType) / sizeof (Scalar);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue