OSDN Git Service

Passed test of vector_add
authorsuikan <suikan@users.sourceforge.jp>
Sat, 15 Feb 2014 09:35:27 +0000 (18:35 +0900)
committersuikan <suikan@users.sourceforge.jp>
Sat, 15 Feb 2014 09:35:27 +0000 (18:35 +0900)
algorithm_vector/Makefile
algorithm_vector/fr32_vector_add.S [new file with mode: 0644]
algorithm_vector/fx32_vector.c
algorithm_vector/fx_vector_test.c [new file with mode: 0644]
algorithm_vector/fx_vector_test.h [new file with mode: 0644]
algorithm_vector/main.c

index 35befde..1979294 100644 (file)
@@ -2,7 +2,7 @@ CC            = bfin-elf-gcc
 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
 
@@ -18,4 +18,4 @@ clean:
 .S.o:
        $(CC) $(CCFLAGS) -c $<
 
-       
\ No newline at end of file
+       
diff --git a/algorithm_vector/fr32_vector_add.S b/algorithm_vector/fr32_vector_add.S
new file mode 100644 (file)
index 0000000..a536438
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+* 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
index 8f5e8a7..f9aa1a8 100644 (file)
@@ -29,27 +29,6 @@ void fr32_vector_mult(
         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]);
-
-}
 
 
     /*
diff --git a/algorithm_vector/fx_vector_test.c b/algorithm_vector/fx_vector_test.c
new file mode 100644 (file)
index 0000000..cde0a24
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * 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
diff --git a/algorithm_vector/fx_vector_test.h b/algorithm_vector/fx_vector_test.h
new file mode 100644 (file)
index 0000000..72c792d
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ * 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_ */
index 7415e16..4bae9e9 100644 (file)
@@ -17,6 +17,7 @@
 int main()
 {
 
+    test_01_fr32_vector_add();
 
 
     return 0;