aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Tsou <tom@tsou.cc>2015-03-25 12:55:11 -0700
committerTom Tsou <tom@tsou.cc>2015-03-25 12:58:12 -0700
commitc5b568d49c61bfa70e1837278b65d758668a6dff (patch)
tree94971127a3be5066c6a94150d3f6588ad3b31859
parent722d4f70a4085448e0c02ba3fb9a4ee6a9077118 (diff)
sigproc: Make convolution and convert input buffers immutable
For good practice, use const specifier when applicable. Signed-off-by: Tom Tsou <tom@tsou.cc>
-rw-r--r--Transceiver52M/common/convert.h4
-rw-r--r--Transceiver52M/common/convolve.h16
-rw-r--r--Transceiver52M/common/convolve_base.c24
-rw-r--r--Transceiver52M/x86/convert.c19
-rw-r--r--Transceiver52M/x86/convolve.c60
5 files changed, 68 insertions, 55 deletions
diff --git a/Transceiver52M/common/convert.h b/Transceiver52M/common/convert.h
index 5b557bf..4827c28 100644
--- a/Transceiver52M/common/convert.h
+++ b/Transceiver52M/common/convert.h
@@ -1,7 +1,7 @@
#ifndef _CONVERT_H_
#define _CONVERT_H_
-void convert_float_short(short *out, float *in, float scale, int len);
-void convert_short_float(float *out, short *in, int len);
+void convert_float_short(short *out, const float *in, float scale, int len);
+void convert_short_float(float *out, const short *in, int len);
#endif /* _CONVERT_H_ */
diff --git a/Transceiver52M/common/convolve.h b/Transceiver52M/common/convolve.h
index aef9953..08bda0c 100644
--- a/Transceiver52M/common/convolve.h
+++ b/Transceiver52M/common/convolve.h
@@ -3,26 +3,26 @@
void *convolve_h_alloc(int num);
-int convolve_real(float *x, int x_len,
- float *h, int h_len,
+int convolve_real(const float *x, int x_len,
+ const float *h, int h_len,
float *y, int y_len,
int start, int len,
int step, int offset);
-int convolve_complex(float *x, int x_len,
- float *h, int h_len,
+int convolve_complex(const float *x, int x_len,
+ const float *h, int h_len,
float *y, int y_len,
int start, int len,
int step, int offset);
-int base_convolve_real(float *x, int x_len,
- float *h, int h_len,
+int base_convolve_real(const float *x, int x_len,
+ const float *h, int h_len,
float *y, int y_len,
int start, int len,
int step, int offset);
-int base_convolve_complex(float *x, int x_len,
- float *h, int h_len,
+int base_convolve_complex(const float *x, int x_len,
+ const float *h, int h_len,
float *y, int y_len,
int start, int len,
int step, int offset);
diff --git a/Transceiver52M/common/convolve_base.c b/Transceiver52M/common/convolve_base.c
index 41dba1c..71453a1 100644
--- a/Transceiver52M/common/convolve_base.c
+++ b/Transceiver52M/common/convolve_base.c
@@ -26,21 +26,21 @@
#endif
/* Base multiply and accumulate complex-real */
-static void mac_real(float *x, float *h, float *y)
+static void mac_real(const float *x, const float *h, float *y)
{
y[0] += x[0] * h[0];
y[1] += x[1] * h[0];
}
/* Base multiply and accumulate complex-complex */
-static void mac_cmplx(float *x, float *h, float *y)
+static void mac_cmplx(const float *x, const float *h, float *y)
{
y[0] += x[0] * h[0] - x[1] * h[1];
y[1] += x[0] * h[1] + x[1] * h[0];
}
/* Base vector complex-complex multiply and accumulate */
-static void mac_real_vec_n(float *x, float *h, float *y,
+static void mac_real_vec_n(const float *x, const float *h, float *y,
int len, int step, int offset)
{
for (int i = offset; i < len; i += step)
@@ -48,7 +48,7 @@ static void mac_real_vec_n(float *x, float *h, float *y,
}
/* Base vector complex-complex multiply and accumulate */
-static void mac_cmplx_vec_n(float *x, float *h, float *y,
+static void mac_cmplx_vec_n(const float *x, const float *h, float *y,
int len, int step, int offset)
{
for (int i = offset; i < len; i += step)
@@ -56,8 +56,8 @@ static void mac_cmplx_vec_n(float *x, float *h, float *y,
}
/* Base complex-real convolution */
-int _base_convolve_real(float *x, int x_len,
- float *h, int h_len,
+int _base_convolve_real(const float *x, int x_len,
+ const float *h, int h_len,
float *y, int y_len,
int start, int len,
int step, int offset)
@@ -73,8 +73,8 @@ int _base_convolve_real(float *x, int x_len,
}
/* Base complex-complex convolution */
-int _base_convolve_complex(float *x, int x_len,
- float *h, int h_len,
+int _base_convolve_complex(const float *x, int x_len,
+ const float *h, int h_len,
float *y, int y_len,
int start, int len,
int step, int offset)
@@ -110,8 +110,8 @@ int bounds_check(int x_len, int h_len, int y_len,
}
/* API: Non-aligned (no SSE) complex-real */
-int base_convolve_real(float *x, int x_len,
- float *h, int h_len,
+int base_convolve_real(const float *x, int x_len,
+ const float *h, int h_len,
float *y, int y_len,
int start, int len,
int step, int offset)
@@ -128,8 +128,8 @@ int base_convolve_real(float *x, int x_len,
}
/* API: Non-aligned (no SSE) complex-complex */
-int base_convolve_complex(float *x, int x_len,
- float *h, int h_len,
+int base_convolve_complex(const float *x, int x_len,
+ const float *h, int h_len,
float *y, int y_len,
int start, int len,
int step, int offset)
diff --git a/Transceiver52M/x86/convert.c b/Transceiver52M/x86/convert.c
index 40831da..eafe7b2 100644
--- a/Transceiver52M/x86/convert.c
+++ b/Transceiver52M/x86/convert.c
@@ -34,7 +34,7 @@
/* 16*N 16-bit signed integer converted to single precision floats */
static void _sse_convert_si16_ps_16n(float *restrict out,
- short *restrict in,
+ const short *restrict in,
int len)
{
__m128i m0, m1, m2, m3, m4, m5;
@@ -69,7 +69,7 @@ static void _sse_convert_si16_ps_16n(float *restrict out,
/* 16*N 16-bit signed integer conversion with remainder */
static void _sse_convert_si16_ps(float *restrict out,
- short *restrict in,
+ const short *restrict in,
int len)
{
int start = len / 16 * 16;
@@ -83,7 +83,7 @@ static void _sse_convert_si16_ps(float *restrict out,
/* 8*N single precision floats scaled and converted to 16-bit signed integer */
static void _sse_convert_scale_ps_si16_8n(short *restrict out,
- float *restrict in,
+ const float *restrict in,
float scale, int len)
{
__m128 m0, m1, m2;
@@ -111,7 +111,7 @@ static void _sse_convert_scale_ps_si16_8n(short *restrict out,
/* 8*N single precision floats scaled and converted with remainder */
static void _sse_convert_scale_ps_si16(short *restrict out,
- float *restrict in,
+ const float *restrict in,
float scale, int len)
{
int start = len / 8 * 8;
@@ -124,7 +124,7 @@ static void _sse_convert_scale_ps_si16(short *restrict out,
/* 16*N single precision floats scaled and converted to 16-bit signed integer */
static void _sse_convert_scale_ps_si16_16n(short *restrict out,
- float *restrict in,
+ const float *restrict in,
float scale, int len)
{
__m128 m0, m1, m2, m3, m4;
@@ -158,7 +158,8 @@ static void _sse_convert_scale_ps_si16_16n(short *restrict out,
}
}
#else /* HAVE_SSE3 */
-static void convert_scale_ps_si16(short *out, float *in, float scale, int len)
+static void convert_scale_ps_si16(short *out, const float *in,
+ float scale, int len)
{
for (int i = 0; i < len; i++)
out[i] = in[i] * scale;
@@ -166,14 +167,14 @@ static void convert_scale_ps_si16(short *out, float *in, float scale, int len)
#endif
#ifndef HAVE_SSE4_1
-static void convert_si16_ps(float *out, short *in, int len)
+static void convert_si16_ps(float *out, const short *in, int len)
{
for (int i = 0; i < len; i++)
out[i] = in[i];
}
#endif
-void convert_float_short(short *out, float *in, float scale, int len)
+void convert_float_short(short *out, const float *in, float scale, int len)
{
#ifdef HAVE_SSE3
if (!(len % 16))
@@ -187,7 +188,7 @@ void convert_float_short(short *out, float *in, float scale, int len)
#endif
}
-void convert_short_float(float *out, short *in, int len)
+void convert_short_float(float *out, const short *in, int len)
{
#ifdef HAVE_SSE4_1
if (!(len % 16))
diff --git a/Transceiver52M/x86/convolve.c b/Transceiver52M/x86/convolve.c
index 1c0a91c..04923bc 100644
--- a/Transceiver52M/x86/convolve.c
+++ b/Transceiver52M/x86/convolve.c
@@ -27,14 +27,14 @@
#endif
/* Forward declarations from base implementation */
-int _base_convolve_real(float *x, int x_len,
- float *h, int h_len,
+int _base_convolve_real(const float *x, int x_len,
+ const float *h, int h_len,
float *y, int y_len,
int start, int len,
int step, int offset);
-int _base_convolve_complex(float *x, int x_len,
- float *h, int h_len,
+int _base_convolve_complex(const float *x, int x_len,
+ const float *h, int h_len,
float *y, int y_len,
int start, int len,
int step, int offset);
@@ -47,8 +47,8 @@ int bounds_check(int x_len, int h_len, int y_len,
#include <pmmintrin.h>
/* 4-tap SSE complex-real convolution */
-static void sse_conv_real4(float *restrict x,
- float *restrict h,
+static void sse_conv_real4(const float *restrict x,
+ const float *restrict h,
float *restrict y,
int len)
{
@@ -81,8 +81,8 @@ static void sse_conv_real4(float *restrict x,
}
/* 8-tap SSE complex-real convolution */
-static void sse_conv_real8(float *restrict x,
- float *restrict h,
+static void sse_conv_real8(const float *restrict x,
+ const float *restrict h,
float *restrict y,
int len)
{
@@ -128,8 +128,8 @@ static void sse_conv_real8(float *restrict x,
}
/* 12-tap SSE complex-real convolution */
-static void sse_conv_real12(float *restrict x,
- float *restrict h,
+static void sse_conv_real12(const float *restrict x,
+ const float *restrict h,
float *restrict y,
int len)
{
@@ -190,8 +190,8 @@ static void sse_conv_real12(float *restrict x,
}
/* 16-tap SSE complex-real convolution */
-static void sse_conv_real16(float *restrict x,
- float *restrict h,
+static void sse_conv_real16(const float *restrict x,
+ const float *restrict h,
float *restrict y,
int len)
{
@@ -265,8 +265,8 @@ static void sse_conv_real16(float *restrict x,
}
/* 20-tap SSE complex-real convolution */
-static void sse_conv_real20(float *restrict x,
- float *restrict h,
+static void sse_conv_real20(const float *restrict x,
+ const float *restrict h,
float *restrict y,
int len)
{
@@ -351,7 +351,10 @@ static void sse_conv_real20(float *restrict x,
}
/* 4*N-tap SSE complex-real convolution */
-static void sse_conv_real4n(float *x, float *h, float *y, int h_len, int len)
+static void sse_conv_real4n(const float *x,
+ const float *h,
+ float *y,
+ int h_len, int len)
{
__m128 m0, m1, m2, m4, m5, m6, m7;
@@ -391,7 +394,10 @@ static void sse_conv_real4n(float *x, float *h, float *y, int h_len, int len)
}
/* 4*N-tap SSE complex-complex convolution */
-static void sse_conv_cmplx_4n(float *x, float *h, float *y, int h_len, int len)
+static void sse_conv_cmplx_4n(const float *x,
+ const float *h,
+ float *y,
+ int h_len, int len)
{
__m128 m0, m1, m2, m3, m4, m5, m6, m7;
@@ -439,7 +445,10 @@ static void sse_conv_cmplx_4n(float *x, float *h, float *y, int h_len, int len)
}
/* 8*N-tap SSE complex-complex convolution */
-static void sse_conv_cmplx_8n(float *x, float *h, float *y, int h_len, int len)
+static void sse_conv_cmplx_8n(const float *x,
+ const float *h,
+ float *y,
+ int h_len, int len)
{
__m128 m0, m1, m2, m3, m4, m5, m6, m7;
__m128 m8, m9, m10, m11, m12, m13, m14, m15;
@@ -511,14 +520,16 @@ static void sse_conv_cmplx_8n(float *x, float *h, float *y, int h_len, int len)
#endif
/* API: Aligned complex-real */
-int convolve_real(float *x, int x_len,
- float *h, int h_len,
+int convolve_real(const float *x, int x_len,
+ const float *h, int h_len,
float *y, int y_len,
int start, int len,
int step, int offset)
{
- void (*conv_func)(float *, float *, float *, int) = NULL;
- void (*conv_func_n)(float *, float *, float *, int, int) = NULL;
+ void (*conv_func)(const float *, const float *,
+ float *, int) = NULL;
+ void (*conv_func_n)(const float *, const float *,
+ float *, int, int) = NULL;
if (bounds_check(x_len, h_len, y_len, start, len, step) < 0)
return -1;
@@ -566,13 +577,14 @@ int convolve_real(float *x, int x_len,
}
/* API: Aligned complex-complex */
-int convolve_complex(float *x, int x_len,
- float *h, int h_len,
+int convolve_complex(const float *x, int x_len,
+ const float *h, int h_len,
float *y, int y_len,
int start, int len,
int step, int offset)
{
- void (*conv_func)(float *, float *, float *, int, int) = NULL;
+ void (*conv_func)(const float *, const float *,
+ float *, int, int) = NULL;
if (bounds_check(x_len, h_len, y_len, start, len, step) < 0)
return -1;