Changeset 104893 in webkit


Ignore:
Timestamp:
Jan 12, 2012 8:27:54 PM (12 years ago)
Author:
commit-queue@webkit.org
Message:

Add vsma in VectorMath to handle vector scale multiply and add and use it in AudioBus
https://bugs.webkit.org/show_bug.cgi?id=75835

When summing a audio bus, the source is multiplied with the scale and
then summed into the destination bus. Add this function to fulfill it.

Patch by Wei James <james.wei@intel.com> on 2012-01-12
Reviewed by Kenneth Russell.

  • platform/audio/AudioBus.cpp:
  • platform/audio/VectorMath.cpp:

(WebCore::VectorMath::vsma):

  • platform/audio/VectorMath.h:
Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r104887 r104893  
     12012-01-12  Wei James  <james.wei@intel.com>
     2
     3        Add vsma in VectorMath to handle vector scale multiply and add and use it in AudioBus
     4        https://bugs.webkit.org/show_bug.cgi?id=75835
     5
     6        When summing a audio bus, the source is multiplied with the scale and
     7        then summed into the destination bus. Add this function to fulfill it.
     8
     9        Reviewed by Kenneth Russell.
     10
     11        * platform/audio/AudioBus.cpp:
     12        * platform/audio/VectorMath.cpp:
     13        (WebCore::VectorMath::vsma):
     14        * platform/audio/VectorMath.h:
     15
    1162012-01-12  James Simonsen  <simonjam@chromium.org>
    217
  • trunk/Source/WebCore/platform/audio/AudioBus.cpp

    r104859 r104893  
    253253    }
    254254
    255 // FIXME: this can be optimized with additional VectorMath functions.
    256255#define STEREO_SUM_V \
    257     for (; k < framesToProcess; ++k) \
    258         STEREO_SUM
     256    { \
     257        vsma(sourceL, 1, &gain, destinationL, 1, framesToProcess - k); \
     258        vsma(sourceR, 1, &gain, destinationR, 1, framesToProcess - k); \
     259    }
    259260
    260261// Mono -> stereo (mix equally into L and R)
     
    270271
    271272#define MONO2STEREO_SUM_V \
    272     for (; k < framesToProcess; ++k) \
    273         MONO2STEREO_SUM
     273    { \
     274        vsma(sourceL, 1, &gain, destinationL, 1, framesToProcess - k); \
     275        vsma(sourceL, 1, &gain, destinationR, 1, framesToProcess - k); \
     276    }
    274277   
    275278#define MONO_SUM \
     
    280283
    281284#define MONO_SUM_V \
    282     for (; k < framesToProcess; ++k) \
    283         MONO_SUM
     285    { \
     286        vsma(sourceL, 1, &gain, destinationL, 1, framesToProcess - k); \
     287    }
    284288
    285289#define STEREO_NO_SUM \
  • trunk/Source/WebCore/platform/audio/VectorMath.cpp

    r104147 r104893  
    9191}
    9292
     93void vsma(const float* sourceP, int sourceStride, const float* scale, float* destP, int destStride, size_t framesToProcess)
     94{
     95    vDSP_vsma(sourceP, sourceStride, scale, destP, destStride, destP, destStride, framesToProcess);
     96}
     97
    9398#else
     99
     100void vsma(const float* sourceP, int sourceStride, const float* scale, float* destP, int destStride, size_t framesToProcess)
     101{
     102    int n = framesToProcess;
     103
     104#ifdef __SSE2__
     105    if ((sourceStride == 1) && (destStride == 1)) {
     106        float k = *scale;
     107
     108        // If the sourceP address is not 16-byte aligned, the first several frames (at most three) should be processed seperately.
     109        while ((reinterpret_cast<uintptr_t>(sourceP) & 0x0F) && n) {
     110            *destP += k * *sourceP;
     111            sourceP++;
     112            destP++;
     113            n--;
     114        }
     115
     116        // Now the sourceP address aligned and start to apply SSE.
     117        int tailFrames = n % 4;
     118        float* endP = destP + n - tailFrames;
     119
     120        __m128 pSource;
     121        __m128 dest;
     122        __m128 temp;
     123        __m128 mScale = _mm_set_ps1(k);
     124
     125        bool destAligned = !(reinterpret_cast<uintptr_t>(destP) & 0x0F);
     126
     127#define SSE2_MULT_ADD(loadInstr, storeInstr)        \
     128            while (destP < endP)                    \
     129            {                                       \
     130                pSource = _mm_load_ps(sourceP);     \
     131                temp = _mm_mul_ps(pSource, mScale); \
     132                dest = _mm_##loadInstr##_ps(destP); \
     133                dest = _mm_add_ps(dest, temp);      \
     134                _mm_##storeInstr##_ps(destP, dest); \
     135                sourceP += 4;                       \
     136                destP += 4;                         \
     137            }
     138
     139        if (destAligned)
     140            SSE2_MULT_ADD(load, store)
     141        else
     142            SSE2_MULT_ADD(loadu, storeu)
     143
     144        n = tailFrames;
     145    }
     146#endif
     147    while (n) {
     148        *destP += *sourceP * *scale;
     149        sourceP += sourceStride;
     150        destP += destStride;
     151        n--;
     152    }
     153}
     154
    94155
    95156void vsmul(const float* sourceP, int sourceStride, const float* scale, float* destP, int destStride, size_t framesToProcess)
  • trunk/Source/WebCore/platform/audio/VectorMath.h

    r104143 r104893  
    3232namespace VectorMath {
    3333
     34// Vector scalar multiply and then add.
     35void vsma(const float* sourceP, int sourceStride, const float* scale, float* destP, int destStride, size_t framesToProcess);
     36
    3437void vsmul(const float* sourceP, int sourceStride, const float* scale, float* destP, int destStride, size_t framesToProcess);
    3538void vadd(const float* source1P, int sourceStride1, const float* source2P, int sourceStride2, float* destP, int destStride, size_t framesToProcess);
Note: See TracChangeset for help on using the changeset viewer.