summaryrefslogtreecommitdiff
path: root/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions
diff options
context:
space:
mode:
authorjoshua <joshua@joshuayun.com>2023-12-30 23:54:31 -0500
committerjoshua <joshua@joshuayun.com>2023-12-30 23:54:31 -0500
commit86608c6770cf08c138a2bdab5855072f64be09ef (patch)
tree494a61b3ef37e76f9235a0d10f5c93d97290a35f /Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions
downloadsdr-software-master.tar.gz
initial commitHEADmaster
Diffstat (limited to 'Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions')
-rw-r--r--Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/BasicMathFunctions.c11
-rw-r--r--Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/abs.c53
-rw-r--r--Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/add.c57
-rw-r--r--Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/dot_prod.c65
-rw-r--r--Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/mult.c64
-rw-r--r--Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/negate.c53
-rw-r--r--Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/offset.c57
-rw-r--r--Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/scale.c69
-rw-r--r--Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/shift.c73
-rw-r--r--Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/sub.c57
10 files changed, 559 insertions, 0 deletions
diff --git a/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/BasicMathFunctions.c b/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/BasicMathFunctions.c
new file mode 100644
index 0000000..2bb5d8b
--- /dev/null
+++ b/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/BasicMathFunctions.c
@@ -0,0 +1,11 @@
+
+#include "abs.c"
+#include "add.c"
+#include "dot_prod.c"
+#include "mult.c"
+#include "negate.c"
+#include "offset.c"
+#include "scale.c"
+#include "shift.c"
+#include "sub.c"
+
diff --git a/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/abs.c b/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/abs.c
new file mode 100644
index 0000000..baca23f
--- /dev/null
+++ b/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/abs.c
@@ -0,0 +1,53 @@
+#include "ref.h"
+
+void ref_abs_f32(
+ float32_t * pSrc,
+ float32_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = pSrc[i] < 0 ? -pSrc[i] : pSrc[i];
+ }
+}
+
+void ref_abs_q31(
+ q31_t * pSrc,
+ q31_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = pSrc[i] < 0 ? -pSrc[i] : pSrc[i];
+ }
+}
+
+void ref_abs_q15(
+ q15_t * pSrc,
+ q15_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = pSrc[i] < 0 ? -pSrc[i] : pSrc[i];
+ }
+}
+
+void ref_abs_q7(
+ q7_t * pSrc,
+ q7_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = pSrc[i] < 0 ? -pSrc[i] : pSrc[i];
+ }
+}
diff --git a/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/add.c b/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/add.c
new file mode 100644
index 0000000..489c8a0
--- /dev/null
+++ b/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/add.c
@@ -0,0 +1,57 @@
+#include "ref.h"
+
+void ref_add_f32(
+ float32_t * pSrcA,
+ float32_t * pSrcB,
+ float32_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = pSrcA[i] + pSrcB[i];
+ }
+}
+
+void ref_add_q31(
+ q31_t * pSrcA,
+ q31_t * pSrcB,
+ q31_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = ref_sat_q31( (q63_t)pSrcA[i] + pSrcB[i] );
+ }
+}
+
+void ref_add_q15(
+ q15_t * pSrcA,
+ q15_t * pSrcB,
+ q15_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = ref_sat_q15( (q31_t)pSrcA[i] + pSrcB[i] );
+ }
+}
+
+void ref_add_q7(
+ q7_t * pSrcA,
+ q7_t * pSrcB,
+ q7_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = ref_sat_q7( (q15_t)pSrcA[i] + pSrcB[i] );
+ }
+}
diff --git a/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/dot_prod.c b/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/dot_prod.c
new file mode 100644
index 0000000..08f6178
--- /dev/null
+++ b/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/dot_prod.c
@@ -0,0 +1,65 @@
+#include "ref.h"
+
+void ref_dot_prod_f32(
+ float32_t * pSrcA,
+ float32_t * pSrcB,
+ uint32_t blockSize,
+ float32_t * result)
+{
+ uint32_t i;
+ float32_t sum = 0.0f;
+
+ for(i=0;i<blockSize;i++)
+ {
+ sum += pSrcA[i] * pSrcB[i];
+ }
+ *result = sum;
+}
+
+void ref_dot_prod_q31(
+ q31_t * pSrcA,
+ q31_t * pSrcB,
+ uint32_t blockSize,
+ q63_t * result)
+{
+ uint32_t i;
+ q63_t sum = 0.0f;
+
+ for(i=0;i<blockSize;i++)
+ {
+ sum += ((q63_t)pSrcA[i] * pSrcB[i]) >> 14; //16.48
+ }
+ *result = sum;
+}
+
+void ref_dot_prod_q15(
+ q15_t * pSrcA,
+ q15_t * pSrcB,
+ uint32_t blockSize,
+ q63_t * result)
+{
+ uint32_t i;
+ q63_t sum = 0.0f;
+
+ for(i=0;i<blockSize;i++)
+ {
+ sum += (q31_t)pSrcA[i] * pSrcB[i]; //34.30
+ }
+ *result = sum;
+}
+
+void ref_dot_prod_q7(
+ q7_t * pSrcA,
+ q7_t * pSrcB,
+ uint32_t blockSize,
+ q31_t * result)
+{
+ uint32_t i;
+ q31_t sum = 0.0f;
+
+ for(i=0;i<blockSize;i++)
+ {
+ sum += (q31_t)pSrcA[i] * pSrcB[i]; //18.14
+ }
+ *result = sum;
+}
diff --git a/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/mult.c b/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/mult.c
new file mode 100644
index 0000000..a77c870
--- /dev/null
+++ b/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/mult.c
@@ -0,0 +1,64 @@
+#include "ref.h"
+
+void ref_mult_f32(
+ float32_t * pSrcA,
+ float32_t * pSrcB,
+ float32_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = pSrcA[i] * pSrcB[i];
+ }
+}
+
+void ref_mult_q31(
+ q31_t * pSrcA,
+ q31_t * pSrcB,
+ q31_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+ q63_t temp;
+
+ for(i=0;i<blockSize;i++)
+ {
+ temp = ((q63_t)pSrcA[i] * pSrcB[i]) >> 32;
+ temp = temp << 1;
+ pDst[i] = ref_sat_q31(temp);
+ }
+}
+
+void ref_mult_q15(
+ q15_t * pSrcA,
+ q15_t * pSrcB,
+ q15_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+ q31_t temp;
+
+ for(i=0;i<blockSize;i++)
+ {
+ temp = ((q31_t)pSrcA[i] * pSrcB[i]) >> 15; //this comment is for JD, this is specifically 15 and not 16 like the q31 case might imply. This is because CMSIS DSP lib does it this way. No other reason.
+ pDst[i] = ref_sat_q15(temp);
+ }
+}
+
+void ref_mult_q7(
+ q7_t * pSrcA,
+ q7_t * pSrcB,
+ q7_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+ q15_t temp;
+
+ for(i=0;i<blockSize;i++)
+ {
+ temp = ((q15_t)pSrcA[i] * pSrcB[i]) >> 7;
+ pDst[i] = ref_sat_q7(temp);
+ }
+}
diff --git a/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/negate.c b/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/negate.c
new file mode 100644
index 0000000..192da1b
--- /dev/null
+++ b/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/negate.c
@@ -0,0 +1,53 @@
+#include "ref.h"
+
+void ref_negate_f32(
+ float32_t * pSrc,
+ float32_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = -pSrc[i];
+ }
+}
+
+void ref_negate_q31(
+ q31_t * pSrc,
+ q31_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = -pSrc[i];
+ }
+}
+
+void ref_negate_q15(
+ q15_t * pSrc,
+ q15_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = -pSrc[i];
+ }
+}
+
+void ref_negate_q7(
+ q7_t * pSrc,
+ q7_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = -pSrc[i];
+ }
+}
diff --git a/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/offset.c b/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/offset.c
new file mode 100644
index 0000000..b076e75
--- /dev/null
+++ b/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/offset.c
@@ -0,0 +1,57 @@
+#include "ref.h"
+
+void ref_offset_f32(
+ float32_t * pSrc,
+ float32_t offset,
+ float32_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = pSrc[i] + offset;
+ }
+}
+
+void ref_offset_q31(
+ q31_t * pSrc,
+ q31_t offset,
+ q31_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = ref_sat_q31( (q63_t)pSrc[i] + offset );
+ }
+}
+
+void ref_offset_q15(
+ q15_t * pSrc,
+ q15_t offset,
+ q15_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = ref_sat_q15( (q31_t)pSrc[i] + offset );
+ }
+}
+
+void ref_offset_q7(
+ q7_t * pSrc,
+ q7_t offset,
+ q7_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = ref_sat_q7( (q15_t)pSrc[i] + offset );
+ }
+}
diff --git a/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/scale.c b/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/scale.c
new file mode 100644
index 0000000..5ab655c
--- /dev/null
+++ b/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/scale.c
@@ -0,0 +1,69 @@
+#include "ref.h"
+
+void ref_scale_f32(
+ float32_t * pSrc,
+ float32_t scale,
+ float32_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = pSrc[i] * scale;
+ }
+}
+
+void ref_scale_q31(
+ q31_t * pSrc,
+ q31_t scaleFract,
+ int8_t shift,
+ q31_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+ int8_t kShift = shift + 1; /* Shift to apply after scaling */
+ int8_t sign = (kShift & 0x80);
+ q63_t temp;
+
+ for(i=0;i<blockSize;i++)
+ {
+ temp = ((q63_t) pSrc[i] * scaleFract) >> 32;
+ if (sign)
+ pDst[i] = temp >> -kShift;
+ else
+ pDst[i] = ref_sat_q31( (q63_t)temp << kShift );
+ }
+}
+
+void ref_scale_q15(
+ q15_t * pSrc,
+ q15_t scaleFract,
+ int8_t shift,
+ q15_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+ int8_t kShift = 15 - shift; /* Shift to apply after scaling */
+
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = ref_sat_q15(((q31_t) pSrc[i] * scaleFract) >> kShift);
+ }
+}
+
+void ref_scale_q7(
+ q7_t * pSrc,
+ q7_t scaleFract,
+ int8_t shift,
+ q7_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+ int8_t kShift = 7 - shift; /* Shift to apply after scaling */
+
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = ref_sat_q7(((q15_t) pSrc[i] * scaleFract) >> kShift);
+ }
+}
diff --git a/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/shift.c b/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/shift.c
new file mode 100644
index 0000000..3bc53ad
--- /dev/null
+++ b/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/shift.c
@@ -0,0 +1,73 @@
+#include "ref.h"
+
+void ref_shift_q31(
+ q31_t * pSrc,
+ int8_t shiftBits,
+ q31_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+
+ if (shiftBits < 0)
+ {
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = pSrc[i] << shiftBits;
+ }
+ }
+ else
+ {
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = pSrc[i] >> -shiftBits;
+ }
+ }
+}
+
+void ref_shift_q15(
+ q15_t * pSrc,
+ int8_t shiftBits,
+ q15_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+
+ if (shiftBits < 0)
+ {
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = pSrc[i] << shiftBits;
+ }
+ }
+ else
+ {
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = pSrc[i] >> -shiftBits;
+ }
+ }
+}
+
+void ref_shift_q7(
+ q7_t * pSrc,
+ int8_t shiftBits,
+ q7_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+
+ if (shiftBits < 0)
+ {
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = pSrc[i] << shiftBits;
+ }
+ }
+ else
+ {
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = pSrc[i] >> -shiftBits;
+ }
+ }
+}
diff --git a/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/sub.c b/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/sub.c
new file mode 100644
index 0000000..da89e95
--- /dev/null
+++ b/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/sub.c
@@ -0,0 +1,57 @@
+#include "ref.h"
+
+void ref_sub_f32(
+ float32_t * pSrcA,
+ float32_t * pSrcB,
+ float32_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = pSrcA[i] - pSrcB[i];
+ }
+}
+
+void ref_sub_q31(
+ q31_t * pSrcA,
+ q31_t * pSrcB,
+ q31_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = ref_sat_q31( (q63_t)pSrcA[i] - pSrcB[i] );
+ }
+}
+
+void ref_sub_q15(
+ q15_t * pSrcA,
+ q15_t * pSrcB,
+ q15_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = ref_sat_q15( (q31_t)pSrcA[i] - pSrcB[i] );
+ }
+}
+
+void ref_sub_q7(
+ q7_t * pSrcA,
+ q7_t * pSrcB,
+ q7_t * pDst,
+ uint32_t blockSize)
+{
+ uint32_t i;
+
+ for(i=0;i<blockSize;i++)
+ {
+ pDst[i] = ref_sat_q7( (q15_t)pSrcA[i] - pSrcB[i] );
+ }
+}