Skip to main content

sesh_sdk/
vec.rs

1//! Vector operations for batch audio processing.
2//!
3//! Each op has two code paths: an inline Rust fallback (always available) and a
4//! host-accelerated import (used when `sesh_vec_version() > 0`). The SDK selects
5//! the path at runtime. Plugin authors call the same functions regardless of platform.
6
7use std::sync::atomic::{AtomicU32, Ordering};
8
9// ---------------------------------------------------------------------------
10// Host capability detection
11// ---------------------------------------------------------------------------
12
13extern "C" {
14    fn sesh_vec_version() -> u32;
15}
16
17/// Cached host vec version. 0 = not yet queried, u32::MAX = stubs (web).
18static HOST_VEC_VERSION: AtomicU32 = AtomicU32::new(0);
19
20fn host_version() -> u32 {
21    let v = HOST_VEC_VERSION.load(Ordering::Relaxed);
22    if v != 0 {
23        return v;
24    }
25    let v = unsafe { sesh_vec_version() };
26    // Store non-zero so we don't re-query. If host returns 0, store a sentinel.
27    let store = if v == 0 { u32::MAX } else { v };
28    HOST_VEC_VERSION.store(store, Ordering::Relaxed);
29    v
30}
31
32#[inline]
33fn use_host_ops() -> bool {
34    host_version() > 0 && host_version() != u32::MAX
35}
36
37// ---------------------------------------------------------------------------
38// Host imports (C ABI, raw pointers)
39// ---------------------------------------------------------------------------
40
41extern "C" {
42    fn sesh_vec_copy_host(dst: *mut f32, src: *const f32, len: u32);
43    fn sesh_vec_fill_host(dst: *mut f32, value: f32, len: u32);
44    fn sesh_vec_add_host(dst: *mut f32, a: *const f32, b: *const f32, len: u32);
45    fn sesh_vec_add_scalar_host(dst: *mut f32, value: f32, len: u32);
46    fn sesh_vec_mul_host(dst: *mut f32, a: *const f32, b: *const f32, len: u32);
47    fn sesh_vec_mul_scalar_host(dst: *mut f32, value: f32, len: u32);
48    fn sesh_vec_mul_add_host(dst: *mut f32, src: *const f32, gain: f32, len: u32);
49    fn sesh_vec_clamp_host(dst: *mut f32, src: *const f32, min: f32, max: f32, len: u32);
50    fn sesh_vec_ring_write_host(
51        buf: *mut f32, buf_len: u32, pos: *mut u32, src: *const f32, len: u32,
52    );
53    fn sesh_vec_ring_read_host(
54        buf: *const f32, buf_len: u32, pos: u32, dst: *mut f32, offset: u32, len: u32,
55    );
56    fn sesh_vec_delay_read_host(
57        buf: *const f32, buf_len: u32, pos: u32, dst: *mut f32, time: *const f32, len: u32,
58    );
59    fn sesh_vec_osc_host(
60        phase: *mut f32, dst: *mut f32, freq: f32, waveform: u32, sample_rate: f32, len: u32,
61    );
62    fn sesh_vec_biquad_host(
63        state: *mut f32, dst: *mut f32, src: *const f32,
64        cutoff: *const f32, q: *const f32, gain: *const f32,
65        filter_type: u32, sample_rate: f32, len: u32,
66    );
67    fn sesh_vec_envelope_host(
68        state: *mut f32, dst: *mut f32, src: *const f32,
69        attack: *const f32, release: *const f32,
70        mode: u32, sample_rate: f32, len: u32,
71    );
72    fn sesh_vec_tanh_host(dst: *mut f32, src: *const f32, drive: *const f32, len: u32);
73    fn sesh_vec_hard_clip_host(dst: *mut f32, src: *const f32, threshold: *const f32, len: u32);
74    fn sesh_vec_abs_host(dst: *mut f32, src: *const f32, len: u32);
75    fn sesh_vec_neg_host(dst: *mut f32, src: *const f32, len: u32);
76    fn sesh_vec_sqrt_host(dst: *mut f32, src: *const f32, len: u32);
77    fn sesh_vec_recip_host(dst: *mut f32, src: *const f32, len: u32);
78    fn sesh_vec_div_host(dst: *mut f32, a: *const f32, b: *const f32, len: u32);
79    fn sesh_vec_pow_host(dst: *mut f32, src: *const f32, exp: *const f32, len: u32);
80}
81
82// ---------------------------------------------------------------------------
83// Enums and state types
84// ---------------------------------------------------------------------------
85
86/// Oscillator waveform shape.
87#[repr(u32)]
88#[derive(Clone, Copy)]
89pub enum Waveform {
90    Sine = 0,
91    Triangle = 1,
92    Saw = 2,
93    Square = 3,
94}
95
96/// Biquad filter type.
97#[repr(u32)]
98#[derive(Clone, Copy)]
99pub enum FilterType {
100    Lowpass = 0,
101    Highpass = 1,
102    Bandpass = 2,
103    Notch = 3,
104    /// Parametric EQ band — boost/cut at cutoff frequency.
105    Peak = 4,
106    /// Boost/cut below cutoff frequency.
107    LowShelf = 5,
108    /// Boost/cut above cutoff frequency.
109    HighShelf = 6,
110    /// Phase shift without changing amplitude — used in phasers.
111    Allpass = 7,
112}
113
114/// Internal state for a biquad filter (two-sample history).
115#[repr(C)]
116pub struct BiquadState {
117    pub x1: f32,
118    pub x2: f32,
119    pub y1: f32,
120    pub y2: f32,
121}
122
123impl BiquadState {
124    pub const fn new() -> Self {
125        Self { x1: 0.0, x2: 0.0, y1: 0.0, y2: 0.0 }
126    }
127}
128
129/// Envelope follower detection mode.
130#[repr(u32)]
131#[derive(Clone, Copy)]
132pub enum EnvelopeMode {
133    /// Track instantaneous peaks.
134    Peak = 0,
135    /// Track root-mean-square level.
136    Rms = 1,
137}
138
139/// Internal state for an envelope follower.
140#[repr(C)]
141pub struct EnvelopeState {
142    pub current: f32,
143}
144
145impl EnvelopeState {
146    pub const fn new() -> Self {
147        Self { current: 0.0 }
148    }
149}
150
151// ===========================================================================
152// Math ops
153// ===========================================================================
154
155/// Copy `src` into `dst`.
156pub fn vec_copy(dst: &mut [f32], src: &[f32]) {
157    let len = dst.len().min(src.len());
158    if use_host_ops() {
159        unsafe { sesh_vec_copy_host(dst.as_mut_ptr(), src.as_ptr(), len as u32) }
160    } else {
161        dst[..len].copy_from_slice(&src[..len]);
162    }
163}
164
165/// Fill `dst` with a constant value.
166pub fn vec_fill(dst: &mut [f32], value: f32) {
167    let len = dst.len();
168    if use_host_ops() {
169        unsafe { sesh_vec_fill_host(dst.as_mut_ptr(), value, len as u32) }
170    } else {
171        for s in dst.iter_mut() {
172            *s = value;
173        }
174    }
175}
176
177/// Element-wise addition: `dst[i] = a[i] + b[i]`.
178pub fn vec_add(dst: &mut [f32], a: &[f32], b: &[f32]) {
179    let len = dst.len().min(a.len()).min(b.len());
180    if use_host_ops() {
181        unsafe { sesh_vec_add_host(dst.as_mut_ptr(), a.as_ptr(), b.as_ptr(), len as u32) }
182    } else {
183        for i in 0..len {
184            dst[i] = a[i] + b[i];
185        }
186    }
187}
188
189/// Add scalar to every element: `dst[i] += value`.
190pub fn vec_add_scalar(dst: &mut [f32], value: f32) {
191    let len = dst.len();
192    if use_host_ops() {
193        unsafe { sesh_vec_add_scalar_host(dst.as_mut_ptr(), value, len as u32) }
194    } else {
195        for s in dst.iter_mut() {
196            *s += value;
197        }
198    }
199}
200
201/// Element-wise multiplication: `dst[i] = a[i] * b[i]`.
202pub fn vec_mul(dst: &mut [f32], a: &[f32], b: &[f32]) {
203    let len = dst.len().min(a.len()).min(b.len());
204    if use_host_ops() {
205        unsafe { sesh_vec_mul_host(dst.as_mut_ptr(), a.as_ptr(), b.as_ptr(), len as u32) }
206    } else {
207        for i in 0..len {
208            dst[i] = a[i] * b[i];
209        }
210    }
211}
212
213/// Multiply every element by scalar: `dst[i] *= value`.
214pub fn vec_mul_scalar(dst: &mut [f32], value: f32) {
215    let len = dst.len();
216    if use_host_ops() {
217        unsafe { sesh_vec_mul_scalar_host(dst.as_mut_ptr(), value, len as u32) }
218    } else {
219        for s in dst.iter_mut() {
220            *s *= value;
221        }
222    }
223}
224
225/// Multiply and accumulate: `dst[i] += src[i] * gain`.
226pub fn vec_mul_add(dst: &mut [f32], src: &[f32], gain: f32) {
227    let len = dst.len().min(src.len());
228    if use_host_ops() {
229        unsafe { sesh_vec_mul_add_host(dst.as_mut_ptr(), src.as_ptr(), gain, len as u32) }
230    } else {
231        for i in 0..len {
232            dst[i] += src[i] * gain;
233        }
234    }
235}
236
237/// Clamp: `dst[i] = clamp(src[i], min, max)`.
238pub fn vec_clamp(dst: &mut [f32], src: &[f32], min: f32, max: f32) {
239    let len = dst.len().min(src.len());
240    if use_host_ops() {
241        unsafe { sesh_vec_clamp_host(dst.as_mut_ptr(), src.as_ptr(), min, max, len as u32) }
242    } else {
243        for i in 0..len {
244            dst[i] = src[i].clamp(min, max);
245        }
246    }
247}
248
249// ===========================================================================
250// Circular buffer ops
251// ===========================================================================
252
253/// Write `src` into circular buffer `buf` starting at `*pos`, wrapping at `buf.len()`.
254/// Advances `*pos` by `src.len()`.
255pub fn vec_ring_write(buf: &mut [f32], pos: &mut usize, src: &[f32]) {
256    let buf_len = buf.len();
257    let frames = src.len();
258    if use_host_ops() {
259        let mut pos32 = *pos as u32;
260        unsafe {
261            sesh_vec_ring_write_host(
262                buf.as_mut_ptr(), buf_len as u32, &mut pos32, src.as_ptr(), frames as u32,
263            );
264        }
265        *pos = pos32 as usize;
266    } else {
267        for i in 0..frames {
268            buf[(*pos + i) % buf_len] = src[i];
269        }
270        *pos = (*pos + frames) % buf_len;
271    }
272}
273
274/// Read `dst.len()` contiguous samples from circular buffer at `pos - offset`, wrapping.
275pub fn vec_ring_read(buf: &[f32], pos: usize, dst: &mut [f32], offset: usize) {
276    let buf_len = buf.len();
277    let frames = dst.len();
278    if use_host_ops() {
279        unsafe {
280            sesh_vec_ring_read_host(
281                buf.as_ptr(), buf_len as u32, pos as u32,
282                dst.as_mut_ptr(), offset as u32, frames as u32,
283            );
284        }
285    } else {
286        let start = (pos + buf_len - offset) % buf_len;
287        for i in 0..frames {
288            dst[i] = buf[(start + i) % buf_len];
289        }
290    }
291}
292
293// ===========================================================================
294// Delay op
295// ===========================================================================
296
297/// Per-sample modulated delay read with linear interpolation.
298///
299/// For each sample `i`, reads from circular buffer at a fractional offset
300/// `time[i]` samples behind where the write head was at sample `i`.
301/// `pos` should be the write head position *after* the most recent `vec_ring_write`.
302pub fn vec_delay_read(buf: &[f32], pos: usize, dst: &mut [f32], time: &[f32]) {
303    let buf_len = buf.len();
304    let frames = dst.len().min(time.len());
305    if use_host_ops() {
306        unsafe {
307            sesh_vec_delay_read_host(
308                buf.as_ptr(), buf_len as u32, pos as u32,
309                dst.as_mut_ptr(), time.as_ptr(), frames as u32,
310            );
311        }
312    } else {
313        for i in 0..frames {
314            // The write head was at (pos - frames + i) when sample i was written.
315            let write_pos_at_i = (pos + buf_len - frames + i) % buf_len;
316
317            let delay_int = time[i] as usize;
318            let delay_frac = time[i] - delay_int as f32;
319
320            let idx1 = (write_pos_at_i + buf_len - delay_int) % buf_len;
321            let idx2 = (idx1 + buf_len - 1) % buf_len;
322
323            dst[i] = buf[idx1] + delay_frac * (buf[idx2] - buf[idx1]);
324        }
325    }
326}
327
328// ===========================================================================
329// Oscillator
330// ===========================================================================
331
332/// Fill `dst` with oscillator output. Advances `*phase`. `freq` is in Hz.
333pub fn vec_osc(
334    phase: &mut f32,
335    dst: &mut [f32],
336    freq: f32,
337    waveform: Waveform,
338    sample_rate: f32,
339) {
340    let frames = dst.len();
341    if use_host_ops() {
342        unsafe {
343            sesh_vec_osc_host(
344                phase as *mut f32, dst.as_mut_ptr(),
345                freq, waveform as u32, sample_rate, frames as u32,
346            );
347        }
348    } else {
349        let phase_inc = freq / sample_rate;
350        for i in 0..frames {
351            dst[i] = match waveform {
352                Waveform::Sine => (*phase * std::f32::consts::TAU).sin(),
353                Waveform::Triangle => 4.0 * (*phase - (*phase + 0.5).floor()).abs() - 1.0,
354                Waveform::Saw => 2.0 * (*phase - (*phase + 0.5).floor()),
355                Waveform::Square => if *phase % 1.0 < 0.5 { 1.0 } else { -1.0 },
356            };
357            *phase += phase_inc;
358            if *phase >= 1.0 {
359                *phase -= 1.0;
360            }
361        }
362    }
363}
364
365// ===========================================================================
366// Filter
367// ===========================================================================
368
369/// Biquad filter with per-sample modulation of cutoff, Q, and gain.
370///
371/// `cutoff` is in Hz, `q` is the Q factor, `gain` is in dB (used for Peak/Shelf types).
372/// Coefficients are recomputed each sample from the parameter buffers.
373pub fn vec_biquad(
374    state: &mut BiquadState,
375    dst: &mut [f32],
376    src: &[f32],
377    cutoff: &[f32],
378    q: &[f32],
379    gain: &[f32],
380    filter_type: FilterType,
381    sample_rate: f32,
382) {
383    let frames = dst.len().min(src.len()).min(cutoff.len()).min(q.len()).min(gain.len());
384    if use_host_ops() {
385        unsafe {
386            sesh_vec_biquad_host(
387                state as *mut BiquadState as *mut f32,
388                dst.as_mut_ptr(), src.as_ptr(),
389                cutoff.as_ptr(), q.as_ptr(), gain.as_ptr(),
390                filter_type as u32, sample_rate, frames as u32,
391            );
392        }
393    } else {
394        for i in 0..frames {
395            let w0 = std::f32::consts::TAU * cutoff[i] / sample_rate;
396            let cos_w0 = w0.cos();
397            let sin_w0 = w0.sin();
398            let alpha = sin_w0 / (2.0 * q[i]);
399            let a_db = gain[i];
400            let a_lin = 10.0f32.powf(a_db / 40.0);
401
402            let (b0, b1, b2, a0, a1, a2) = match filter_type {
403                FilterType::Lowpass => {
404                    let b1 = 1.0 - cos_w0;
405                    let b0 = b1 / 2.0;
406                    (b0, b1, b0, 1.0 + alpha, -2.0 * cos_w0, 1.0 - alpha)
407                }
408                FilterType::Highpass => {
409                    let b1 = -(1.0 + cos_w0);
410                    let b0 = (1.0 + cos_w0) / 2.0;
411                    (b0, b1, b0, 1.0 + alpha, -2.0 * cos_w0, 1.0 - alpha)
412                }
413                FilterType::Bandpass => {
414                    (alpha, 0.0, -alpha, 1.0 + alpha, -2.0 * cos_w0, 1.0 - alpha)
415                }
416                FilterType::Notch => {
417                    (1.0, -2.0 * cos_w0, 1.0, 1.0 + alpha, -2.0 * cos_w0, 1.0 - alpha)
418                }
419                FilterType::Peak => {
420                    (
421                        1.0 + alpha * a_lin,
422                        -2.0 * cos_w0,
423                        1.0 - alpha * a_lin,
424                        1.0 + alpha / a_lin,
425                        -2.0 * cos_w0,
426                        1.0 - alpha / a_lin,
427                    )
428                }
429                FilterType::LowShelf => {
430                    let two_sqrt_a_alpha = 2.0 * a_lin.sqrt() * alpha;
431                    (
432                        a_lin * ((a_lin + 1.0) - (a_lin - 1.0) * cos_w0 + two_sqrt_a_alpha),
433                        2.0 * a_lin * ((a_lin - 1.0) - (a_lin + 1.0) * cos_w0),
434                        a_lin * ((a_lin + 1.0) - (a_lin - 1.0) * cos_w0 - two_sqrt_a_alpha),
435                        (a_lin + 1.0) + (a_lin - 1.0) * cos_w0 + two_sqrt_a_alpha,
436                        -2.0 * ((a_lin - 1.0) + (a_lin + 1.0) * cos_w0),
437                        (a_lin + 1.0) + (a_lin - 1.0) * cos_w0 - two_sqrt_a_alpha,
438                    )
439                }
440                FilterType::HighShelf => {
441                    let two_sqrt_a_alpha = 2.0 * a_lin.sqrt() * alpha;
442                    (
443                        a_lin * ((a_lin + 1.0) + (a_lin - 1.0) * cos_w0 + two_sqrt_a_alpha),
444                        -2.0 * a_lin * ((a_lin - 1.0) + (a_lin + 1.0) * cos_w0),
445                        a_lin * ((a_lin + 1.0) + (a_lin - 1.0) * cos_w0 - two_sqrt_a_alpha),
446                        (a_lin + 1.0) - (a_lin - 1.0) * cos_w0 + two_sqrt_a_alpha,
447                        2.0 * ((a_lin - 1.0) - (a_lin + 1.0) * cos_w0),
448                        (a_lin + 1.0) - (a_lin - 1.0) * cos_w0 - two_sqrt_a_alpha,
449                    )
450                }
451                FilterType::Allpass => {
452                    (1.0 - alpha, -2.0 * cos_w0, 1.0 + alpha, 1.0 + alpha, -2.0 * cos_w0, 1.0 - alpha)
453                }
454            };
455
456            // Normalize coefficients.
457            let b0 = b0 / a0;
458            let b1 = b1 / a0;
459            let b2 = b2 / a0;
460            let a1 = a1 / a0;
461            let a2 = a2 / a0;
462
463            let x0 = src[i];
464            let y0 = b0 * x0 + b1 * state.x1 + b2 * state.x2
465                - a1 * state.y1 - a2 * state.y2;
466
467            state.x2 = state.x1;
468            state.x1 = x0;
469            state.y2 = state.y1;
470            state.y1 = y0;
471
472            dst[i] = y0;
473        }
474    }
475}
476
477// ===========================================================================
478// Dynamics
479// ===========================================================================
480
481/// Envelope follower. Tracks amplitude of `src` with attack/release smoothing.
482///
483/// `attack` and `release` are in seconds (per-sample buffers for modulation).
484/// Output in `dst` is the smoothed envelope value.
485pub fn vec_envelope(
486    state: &mut EnvelopeState,
487    dst: &mut [f32],
488    src: &[f32],
489    attack: &[f32],
490    release: &[f32],
491    mode: EnvelopeMode,
492    sample_rate: f32,
493) {
494    let frames = dst.len().min(src.len()).min(attack.len()).min(release.len());
495    if use_host_ops() {
496        unsafe {
497            sesh_vec_envelope_host(
498                state as *mut EnvelopeState as *mut f32,
499                dst.as_mut_ptr(), src.as_ptr(),
500                attack.as_ptr(), release.as_ptr(),
501                mode as u32, sample_rate, frames as u32,
502            );
503        }
504    } else {
505        for i in 0..frames {
506            let input_level = match mode {
507                EnvelopeMode::Peak => src[i].abs(),
508                EnvelopeMode::Rms => src[i] * src[i],
509            };
510
511            let att_coeff = (-1.0 / (attack[i] * sample_rate)).exp();
512            let rel_coeff = (-1.0 / (release[i] * sample_rate)).exp();
513
514            let coeff = if input_level > state.current { att_coeff } else { rel_coeff };
515            state.current = coeff * state.current + (1.0 - coeff) * input_level;
516
517            dst[i] = match mode {
518                EnvelopeMode::Peak => state.current,
519                EnvelopeMode::Rms => state.current.sqrt(),
520            };
521        }
522    }
523}
524
525// ===========================================================================
526// Waveshaping
527// ===========================================================================
528
529/// Soft saturation: `dst[i] = tanh(src[i] * drive[i])`.
530pub fn vec_tanh(dst: &mut [f32], src: &[f32], drive: &[f32]) {
531    let len = dst.len().min(src.len()).min(drive.len());
532    if use_host_ops() {
533        unsafe { sesh_vec_tanh_host(dst.as_mut_ptr(), src.as_ptr(), drive.as_ptr(), len as u32) }
534    } else {
535        for i in 0..len {
536            dst[i] = (src[i] * drive[i]).tanh();
537        }
538    }
539}
540
541/// Hard clipping: clamp `src` to `±threshold[i]`.
542pub fn vec_hard_clip(dst: &mut [f32], src: &[f32], threshold: &[f32]) {
543    let len = dst.len().min(src.len()).min(threshold.len());
544    if use_host_ops() {
545        unsafe {
546            sesh_vec_hard_clip_host(dst.as_mut_ptr(), src.as_ptr(), threshold.as_ptr(), len as u32)
547        }
548    } else {
549        for i in 0..len {
550            dst[i] = src[i].clamp(-threshold[i], threshold[i]);
551        }
552    }
553}
554
555// ===========================================================================
556// Unary / additional math ops
557// ===========================================================================
558
559/// Absolute value: `dst[i] = |src[i]|`.
560pub fn vec_abs(dst: &mut [f32], src: &[f32]) {
561    let len = dst.len().min(src.len());
562    if use_host_ops() {
563        unsafe { sesh_vec_abs_host(dst.as_mut_ptr(), src.as_ptr(), len as u32) }
564    } else {
565        for i in 0..len {
566            dst[i] = src[i].abs();
567        }
568    }
569}
570
571/// Negate: `dst[i] = -src[i]`. Phase inversion.
572pub fn vec_neg(dst: &mut [f32], src: &[f32]) {
573    let len = dst.len().min(src.len());
574    if use_host_ops() {
575        unsafe { sesh_vec_neg_host(dst.as_mut_ptr(), src.as_ptr(), len as u32) }
576    } else {
577        for i in 0..len {
578            dst[i] = -src[i];
579        }
580    }
581}
582
583/// Square root: `dst[i] = sqrt(src[i])`.
584pub fn vec_sqrt(dst: &mut [f32], src: &[f32]) {
585    let len = dst.len().min(src.len());
586    if use_host_ops() {
587        unsafe { sesh_vec_sqrt_host(dst.as_mut_ptr(), src.as_ptr(), len as u32) }
588    } else {
589        for i in 0..len {
590            dst[i] = src[i].sqrt();
591        }
592    }
593}
594
595/// Reciprocal: `dst[i] = 1.0 / src[i]`.
596pub fn vec_recip(dst: &mut [f32], src: &[f32]) {
597    let len = dst.len().min(src.len());
598    if use_host_ops() {
599        unsafe { sesh_vec_recip_host(dst.as_mut_ptr(), src.as_ptr(), len as u32) }
600    } else {
601        for i in 0..len {
602            dst[i] = 1.0 / src[i];
603        }
604    }
605}
606
607/// Element-wise division: `dst[i] = a[i] / b[i]`.
608pub fn vec_div(dst: &mut [f32], a: &[f32], b: &[f32]) {
609    let len = dst.len().min(a.len()).min(b.len());
610    if use_host_ops() {
611        unsafe { sesh_vec_div_host(dst.as_mut_ptr(), a.as_ptr(), b.as_ptr(), len as u32) }
612    } else {
613        for i in 0..len {
614            dst[i] = a[i] / b[i];
615        }
616    }
617}
618
619/// Element-wise power: `dst[i] = src[i].powf(exp[i])`.
620pub fn vec_pow(dst: &mut [f32], src: &[f32], exp: &[f32]) {
621    let len = dst.len().min(src.len()).min(exp.len());
622    if use_host_ops() {
623        unsafe { sesh_vec_pow_host(dst.as_mut_ptr(), src.as_ptr(), exp.as_ptr(), len as u32) }
624    } else {
625        for i in 0..len {
626            dst[i] = src[i].powf(exp[i]);
627        }
628    }
629}