/* cycles.c David Rowe 11/5/06 Test program to measure execution cycles of DSP operations on the Blackfin. Thanks to Jean-Marc Valin of Speex for helping with Blackfin code samples and comments. */ #include void test1(); void test2(); void test3(); void test4(); #define N 100 /* size of vectors */ #define M 10 /* number of times to repeat tests */ int before; /* cycle counter value just before test loop */ int after; /* cycle counter value just after test loop */ int main() { printf("Theoretical best case is N/2 = %d cycles\n", N/2); test1(); test2(); test3(); test4(); return 0; } /* find dot product of two vectors, C version */ int dot(short *x, short *y, int len) { int i,dot; dot = 0; for(i=0; i> 1;\n\t" "LOOP_BEGIN dot%=;\n\t" "A1 += R0.H * R1.H, A0 += R0.L * R1.L || R0 = [I0++] || R1 = [I1++];\n\t" "LOOP_END dot%=;\n\t" "R0 = (A0 += A1);\n\t" "%0 = R0 >> 1;\n\t" /* correct for left shift during multiply */ : "=&d" (dot), "=&d" (before), "=&d" (after) : "a" (x), "a" (y), "a" (len) : "I0", "I1", "A1", "A0", "R0", "R1" ); return dot; } /* find dot product of two vectors, built in cycles measurement */ int dot2(short *x, short *y, int len) { int dot; __asm__ ( "I0 = %3;\n\t" "I1 = %4;\n\t" "A1 = A0 = 0;\n\t" "R0 = [I0++] || R1 = [I1++];\n\t" "R2 = CYCLES;\n\t" "%1 = R2;\n\t" "LOOP dot%= LC0 = %5 >> 1;\n\t" "LOOP_BEGIN dot%=;\n\t" "A1 += R0.H * R1.H, A0 += R0.L * R1.L || R0 = [I0++] || R1 = [I1++];\n\t" "LOOP_END dot%=;\n\t" "R2 = CYCLES;\n\t" "%2 = R2;\n\t" "R0 = (A0 += A1);\n\t" "%0 = R0 >> 1;\n\t" /* correct for left shift during multiply */ : "=&d" (dot), "=&d" (before), "=&d" (after) : "a" (x), "a" (y), "a" (len) : "I0", "I1", "A1", "A0", "R0", "R1", "R2" ); return dot; } /* C-callable function to return value of CYCLES register */ int cycles() { int ret; __asm__ __volatile__ ( "%0 = CYCLES;\n\t" : "=&d" (ret) : : "R1" ); return ret; } void test1() { short x[N]; short y[N]; int i,k, ret; unsigned int before, after; unsigned int time[M]; for(i=0; i