LDFLAGS = -msim
CCFLAGS = -O0 -g
LIBS = -lm
-OBJS = main.o fx32_vector.o
+OBJS = main.o fx32_vector.o fr32_vector_add.o fx_vector_test.o
all: a.out
.S.o:
$(CC) $(CCFLAGS) -c $<
-
\ No newline at end of file
+
--- /dev/null
+/*
+* 32bit vector addition implementation.
+*
+* function prototype
+* void fr32_vector_add(
+* const fract32 a[],
+* const fract32 b[],
+* fract32 c[],
+* int count);
+*
+* parameters
+* FP+20 - int count
+* FP+16 R2 const fr32 c[] : as result
+* FP+12 R1 const fr32 b[]
+* FP+ 8 R0 const fr32 a[]
+*
+* return
+* none
+*
+* side effect
+* out[] : obtain output data.
+*
+
+* register layout
+* P2 : out
+* P3 : count : loop counter's initial value
+* I0 : a[]
+* I1 : b[]
+* I2 : c[]
+* R0 : a[i]
+* R1 : b[i]
+* R3 : a[i]+b[i]
+*/
+
+ .text
+ .align 4
+ .global _fr32_vector_add;
+ .type _fr32_vector_add, STT_FUNC;
+
+_fr32_vector_add:
+ link 0;
+ [--sp] = (r7:4, p5:3); // save all preserved register
+
+ /* Set up registers */
+ i0 = r0;
+ i1 = r1;
+ i2 = r2;
+ p3 = [fp+20]; // load count
+
+
+ /* outer loop */
+ loop count lc0 = p3;
+ loop_begin count;
+ r0 = [i0++];
+ r1 = [i1++];
+ r3 = r0 + r1(s);
+ [i2++] = r3;
+ // store output sample
+
+ loop_end count;
+ /* end of outer loop */
+
+
+ (r7:4, p5:3) = [sp++]; // restore all preserved register
+ unlink;
+ rts;
+ .size _fr32_vector_add, .-_fr32_vector_add
c[i] = mult_fr1x32x32(a[i], b[i]);
}
- /*
- * \brief vector addition A+B => C
- * \param a input vector A
- * \param b input vector B
- * \param c input vector C
- * \count length of vector
- * \details
- * Add the 32bit fixed point A to B, then, store the result to vector C.
- */
-void fr32_vector_add(
- const fract32 a[],
- const fract32 b[],
- fract32 c[],
- int count)
-{
- int i;
-
- for ( i=0; i<count; i++)
- c[i] = add_fr1x32(a[i], b[i]);
-
-}
/*
--- /dev/null
+/*
+ * fx_vector_test.c
+ *
+ * Created on: 2014/01/19
+ * Author: takemasa
+ */
+
+#include "fx_vector_test.h"
+#include <stdio.h>
+
+void clearBuffer ( fract32 buf[], int count)
+{
+ int i;
+ for ( i= 0; i<count; i++ )
+ buf[i] = 0;
+}
+
+/*
+ * Basic test to see the continuity of HH and HL&LH product.
+ */
+#define NUMSAMPLE_01 4
+
+fract32 buf_a_01[NUMSAMPLE_01]=
+ {
+ 0x08000000, //
+ 0x7FFFFFFF, //
+ 0x01000000,
+ 0x20000000
+ };
+
+fract32 buf_b_01[NUMSAMPLE_01] =
+ {
+ 0x01000000, //
+ 0x00000001, //
+ 0x02000000, //
+ 0x00000000
+ };
+
+fract32 desired_01[NUMSAMPLE_01] =
+ {
+ 0x09000000, // Simple addition
+ 0x7FFFFFFF, // Saturated
+ 0x03000000, // dummy
+ 0x00000000, // 0 for count test
+ };
+
+void test_01_fr32_vector_add()
+{
+ fract32 output[NUMSAMPLE_01];
+ int i;
+
+
+ // clear output buffer
+ clearBuffer( output, NUMSAMPLE_01);
+ // test addition. Sample is less than NUMSAMPLE_01 to test the count parameter
+ fr32_vector_add( buf_a_01, buf_b_01, output, NUMSAMPLE_01-1);
+
+ for ( i=0; i<NUMSAMPLE_01; i++)
+ {
+ if ( output[i] != desired_01[i] )
+ {
+ printf( "test01 NG :output[%2d] = 0x%08X but should be 0x%08X\n", i, output[i], desired_01[i] );
+ return;
+ }
+ }
+ printf ("test01 OK\n");
+}
+
+#undef TAPS_01
+#undef NUMSAMPLE_01
--- /dev/null
+/*
+ * fx_vector_test.h
+ *
+ * Created on: 2014/01/19
+ * Author: takemasa
+ */
+
+
+
+#ifndef FX_VECTOR_TEST_H_
+#define FX_VECTOR_TEST_H_
+
+#include "fx32_vector.h"
+#include <limits.h>
+
+
+void test_01_fr32_vector_add();
+
+#endif /* FX_VECTOR_TEST_H_ */
int main()
{
+ test_01_fr32_vector_add();
return 0;