Bug 7060 - oil_scalarmultiply_s32_ns
oil_scalarmultiply_s32_ns
Status: NEW
Product: liboil
Classification: Unclassified
Component: unknown
unspecified
x86 (IA32) Linux (All)
: high enhancement
Assigned To: David Schleef
David Schleef
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2006-05-29 05:47 UTC by Stefan Kost
Modified: 2008-03-07 06:38 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stefan Kost 2006-05-29 05:47:14 UTC
please add oil_scalarmultiply_s32_ns like oil_scalarmultiply_f32_ns.

The functionallity should be similar to (taken from GstVolume):
  if (this->real_vol_i > VOLUME_UNITY_INT) {
    for (i = 0; i < num_samples; i++) {
      /* we use bitshifting instead of dividing by UNITY_INT for speed */
      val = (gint) * data;
      *data++ =
          (gint16) CLAMP ((this->real_vol_i * val) >> VOLUME_UNITY_BIT_SHIFT,
          VOLUME_MIN_INT16, VOLUME_MAX_INT16);
    }
  } else {
    for (i = 0; i < num_samples; i++) {
      /* we use bitshifting instead of dividing by UNITY_INT for speed */
      val = (gint) * data;
      *data++ = (gint16) ((this->real_vol_i * val) >> VOLUME_UNITY_BIT_SHIFT);
    }
  }

It would be okay to have two functions, one with CLAMP and one without.
Comment 1 Sebastian Dröge (slomo) 2008-03-07 06:38:48 UTC
What about having

oil_scalarmultiply_s32_ns (int32 *d, int32 *s1, int32 *s2_1, int32 *s2_2, int n)

which does

    if (*s2_1 < *s2_2)
      for (i = 0; i < n; i++) {
        d[i] = (s1[i] * (*s2_1)) / (*s2_2);
      }
    else
      for (i = 0; i < n; i++) {
        d[i] = CLAMP ((s1[i] * (*s2_1)) / (*s2_2), MININT32, MAXINT32);
      }

Only needs to take care of putting s1[i] * (*s2_1) into int64 (and docs should say that it does clipping).

IIRC MMX or MMXExt provides something to multiply and store in the next larger value type so it could be implemented for this at least... or was it some version of SSE? Whatever, if the API is fine I'll look it up again :)


Also this function could be made available for 8 and 16 bits maybe, not sure about 64 or 24 bits...