Skip to content

Commit

Permalink
Restrict 7081 (#50)
Browse files Browse the repository at this point in the history
Allowing __restrict to be used correctly

Addresses surge-synthesizer/surge#7081
  • Loading branch information
baconpaul authored Jul 29, 2023
1 parent 2fb5e31 commit 97aebc2
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
22 changes: 22 additions & 0 deletions include/sst/basic-blocks/dsp/BlockInterpolators.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,28 @@ template <int maxBlockSize, bool first_run_checks = true> struct alignas(16) lip
fade_block_to(src21, src22, dst2, bsQuad);
}

void fade_blocks_inplace(float *__restrict inAOut, float *__restrict inB) const
{
for (int i = 0; i < numRegisters; ++i)
{
auto a = _mm_load_ps(inAOut + (i << 2));
auto b = _mm_load_ps(inB + (i << 2));
auto sa = _mm_mul_ps(a, _mm_sub_ps(one, line[i]));
auto sb = _mm_mul_ps(b, line[i]);
auto r = _mm_add_ps(sa, sb);
_mm_store_ps(inAOut + (i << 2), r);
}
}

void fade_2_blocks_inplace(float *__restrict src11out, float *__restrict src12,
float *__restrict src21out, float *__restrict src22,
int bsQuad = -1) const
{
assert(bsQuad == -1 || bsQuad == numRegisters);
fade_blocks_inplace(src11out, src12);
fade_blocks_inplace(src21out, src22);
}

void store_block(float *__restrict out, int bsQuad = -1) const
{
assert(bsQuad == -1 || bsQuad == numRegisters);
Expand Down
26 changes: 26 additions & 0 deletions include/sst/basic-blocks/mechanics/block-ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ inline void add_block(const float *__restrict src1, const float *__restrict src2
}
}

template <size_t blocksize>
inline void add_block(float *__restrict srcdst, const float *__restrict src2)
{
for (auto i = 0U; i < blocksize; ++i)
{
srcdst[i] = srcdst[i] + src2[i];
}
}

template <size_t blockSize>
inline void mul_block(float *__restrict src1, float *src2, float *__restrict dst)
{
Expand All @@ -96,6 +105,23 @@ inline void mul_block(float *__restrict src1, float scalar, float *__restrict ds
dst[i] = src1[i] * scalar;
}
}

template <size_t blockSize> inline void mul_block(float *__restrict srcDst, float *__restrict by)
{
for (auto i = 0U; i < blockSize; ++i)
{
srcDst[i] = srcDst[i] * by[i];
}
}

template <size_t blockSize> inline void mul_block(float *__restrict srcDst, float by)
{
for (auto i = 0U; i < blockSize; ++i)
{
srcDst[i] = srcDst[i] * by;
}
}

template <size_t blockSize>
inline void scale_by(const float *__restrict scale, float *__restrict target)
{
Expand Down

0 comments on commit 97aebc2

Please sign in to comment.