OSDN Git Service

fr_vector_neg() passed test.
authorsuikan <suikan@users.sourceforge.jp>
Sat, 22 Feb 2014 03:30:09 +0000 (12:30 +0900)
committersuikan <suikan@users.sourceforge.jp>
Sat, 22 Feb 2014 03:30:09 +0000 (12:30 +0900)
algorithm_vector/Makefile
algorithm_vector/fr32_vector_neg.S [new file with mode: 0644]
algorithm_vector/fx32_vector.h
algorithm_vector/fx_vector_test.c
algorithm_vector/fx_vector_test.h
algorithm_vector/main.c

index adc31b1..78164dc 100644 (file)
@@ -4,7 +4,7 @@ CCFLAGS       =  -O0 -g
 LIBS             = -lm
 OBJS          = main.o fx32_vector.o fr32_vector_add.o fx_vector_test.o fr32_vector_add_svv.o \
                                fr32_vector_sub.o  fr32_vector_sub_svv.o fr32_vector_mul.o fr32_vector_mul_svv.o \
-                               fr32_vector_complex_mul.o
+                               fr32_vector_complex_mul.o fr32_vector_neg.S
 
 all:   a.out
 
diff --git a/algorithm_vector/fr32_vector_neg.S b/algorithm_vector/fr32_vector_neg.S
new file mode 100644 (file)
index 0000000..64f1dc6
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+* 32bit vector negate implementation.
+*
+* function prototype
+* void fr32_vector_neg(
+*        const fract32 a[],
+*        fract32 b[],
+*        int count);
+*
+* parameters
+*   FP+16      R2  count
+*      FP+12   R1      const fr32 b[]
+*      FP+ 8   R0      const fr32 a[]
+*
+* return
+*      none
+*
+* side effect
+*   out[] : obtain output data
+*
+
+* register layout
+*      P1 : count : loop counter's initial value
+*   I0 : a
+*      I1 : b
+*   R0 : a[i]
+*   R1 : -a[i]
+*/
+
+       .text
+       .align 4
+       .global _fr32_vector_neg;
+       .type _fr32_vector_neg, STT_FUNC;
+
+_fr32_vector_neg:
+       link    0;
+       [--sp] = (r7:4, p5:3);          // save all preserved register
+
+               /* Set up registers */
+       i0 = r0;                                // load a
+       i1 = r1;                                // load b
+       p1 = R2;                                // load count
+
+               /* outer loop */
+       loop count lc0 = p1;    // Todo : can be 3 parallel instruction. But seems to be simulator bug in 2013RC1RC
+       loop_begin count;
+               r0 = [i0++];
+               r1 = - r0(s);
+               [i1++] = r1;
+       loop_end count;
+               /* end of outer loop */
+
+
+       (r7:4, p5:3) = [sp++];          // restore all preserved register
+       unlink;
+       rts;
+       .size   _fr32_vector_neg, .-_fr32_vector_neg
index 4065834..058c661 100644 (file)
@@ -37,7 +37,7 @@ void fr32_vector_add(
      * \brief vector subtraction A-B => C
      * \param a input vector A
      * \param b input vector B
-     * \param c input vector C
+     * \param c output vector C
      * \count length of vector
      * \details
      * Subtract the 32bit fixed point B from A, then, store the result to vector C.
@@ -52,7 +52,7 @@ void fr32_vector_sub(
  * \brief vector addition A+B => C
  * \param a input scalar A
  * \param b input vector B
- * \param c input vector C
+ * \param c output vector C
  * \count length of vector
  * \details
  * Add the 32bit fixed point scalar A to vector B, then, store the result to vector C.
@@ -67,7 +67,7 @@ void fr32_vector_add_svv(
  * \brief vector Sbutraction A-B => C
  * \param a input scalar A
  * \param b input vector B
- * \param c input vector C
+ * \param c output vector C
  * \count length of vector
  * \details
  * Subtract the 32bit fixed point vector B from scalar A , then, store the result to vector C.
@@ -82,7 +82,7 @@ void fr32_vector_sub_svv(
      * \brief vector multiplying A*B => C
      * \param a input vector A
      * \param b input vector B
-     * \param c input vector C
+     * \param c output vector C
      * \count length of vector
      * \details
      * Multiply the 32bit fixed point A by B, then, store the result to vector C.
@@ -95,9 +95,9 @@ void fr32_vector_mul(
 
     /**
      * \brief vector multiplying A*B => C
-     * \param a input vector A
-     * \param b input scalar B
-     * \param c input vector C
+     * \param a input scalar A
+     * \param b input vector B
+     * \param c output vector C
      * \count length of vector
      * \details
      * Multiply the 32bit fixed point vector B by scalar A, then, store the result to vector C.
@@ -114,8 +114,8 @@ void fr32_vector_mul_svv(
      * \param ai input vector im(A)
      * \param br input vector re(B)
      * \param bi input vector im(B)
-     * \param cr input vector re(C)
-     * \param ci input vector im(C)
+     * \param cr output vector re(C)
+     * \param ci output vector im(C)
      * \count length of vector
      * \details
      * Mulitiply the complex fxied point vector A by B. Then, store the result to vector C
@@ -130,5 +130,32 @@ void fr32_vector_complex_mul(
         int count
         );
 
+    /**
+     * \brief vector negate -A => B
+     * \param a input vector A
+     * \param b output vector B
+     * \count length of vector
+     * \details
+     * Negate the input vector A, then, store the result to vector B.
+     */
+void fr32_vector_neg(
+        const fract32 a[],
+        fract32 b[],
+        int count);
+
+    /**
+     * \brief vector fill A => B
+     * \param a input scalar A
+     * \param b output vectr B
+     * \count length of vector
+     * \details
+     * Fill output vector B by input scalar A
+     */
+void fr32_vector_fill(
+        const fract32 a,
+        fract32 b[],
+        int count);
+
+
 
 #endif /* FX32_VECTOR_H_ */
index 68d4867..dbcc266 100644 (file)
@@ -749,3 +749,53 @@ void test_07_fr32_vector_complex_mul()
 #undef TAPS_07
 #undef NUMSAMPLE_07
 
+
+/*
+ * Basic test to see scalar + vector addition.
+ */
+#define NUMSAMPLE_08 5
+
+fract32 buf_a_08[NUMSAMPLE_08]=
+    {
+        0x00000001,     //
+        0xFFFFFFFF,     //
+        0x80000001,
+        0x80000000,
+        0x20000000
+    };
+
+
+fract32 desired_08[NUMSAMPLE_08] =
+    {
+        0xFFFFFFFF,         // -1
+        0x00000001,         // 1
+        0x7FFFFFFF,
+        0x7FFFFFFF,         // saturated
+        0x00000000,         // 0 for count test
+    };
+
+void test_08_fr32_vector_neg()
+{
+    fract32 output[NUMSAMPLE_08];
+    int i;
+
+
+        // clear output buffer
+    clearBuffer( output, NUMSAMPLE_08);
+        // test subtraction. Sample is less than NUMSAMPLE_08 to test the count parameter
+    fr32_vector_neg( buf_a_08, output, NUMSAMPLE_08-1);
+
+    for ( i=0; i<NUMSAMPLE_08; i++)
+    {
+        if ( output[i] != desired_08[i] )
+        {
+            printf( "test_08 NG :output[%2d] = 0x%08X but should be 0x%08X\n", i, output[i], desired_08[i] );
+            return;
+        }
+    }
+    printf ("test_08 OK\n");
+}
+
+#undef TAPS_08
+#undef NUMSAMPLE_08
+
index 010286d..49eb60a 100644 (file)
@@ -20,6 +20,8 @@ void test_03_fr32_vector_sub();
 void test_04_fr32_vector_sub_svv();
 void test_05_fr32_vector_mul();
 void test_06_fr32_vector_mul_svv();
+void test_07_fr32_vector_complex_mul();
+void test_08_fr32_vector_neg();
 
 
 #endif /* FX_VECTOR_TEST_H_ */
index af6a251..5cf4de8 100644 (file)
@@ -24,6 +24,7 @@ int main()
     test_05_fr32_vector_mul();
     test_06_fr32_vector_mul_svv();
     test_07_fr32_vector_complex_mul();
+    test_08_fr32_vector_neg();