short answer:
yeah, don’t use integer division.
longer answer:
here’s a really, really quick test [bfin_div.c]
#include <fract.h>
fract32 div256 (int x) {
return x / 256;
}
fract32 div256_shift(int x) {
return x >> 8;
}
fract32 div256_shift_intrinsic(int x) {
return shr_fr1x32(x, 8);
}
compiled with bfin-elf-gcc -c bfin_div.c -o bfin_div.o -O3
then disassmebled with bfin-elf-objdump -S bfin_div.o
result:
00000000 <_div256>:
0: 00 e8 00 00 LINK 0x0; /* (0) */
4: 08 30 R1 = R0;
6: 80 0c CC = R0 < 0x0;
8: 06 18 IF CC JUMP 0x14 <_div256+0x14>;
a: 82 c6 c1 01 R0 = R1 >>> 0x8;
e: 01 e8 00 00 UNLINK;
12: 10 00 RTS;
14: 20 e1 ff 00 R0 = 0xff (X); /* R0=0xff(255) */
18: 41 50 R1 = R1 + R0;
1a: 82 c6 c1 01 R0 = R1 >>> 0x8;
1e: 01 e8 00 00 UNLINK;
22: 10 00 RTS;
00000024 <_div256_shift>:
24: 00 00 NOP;
26: 00 e8 00 00 LINK 0x0; /* (0) */
2a: 40 4d R0 >>>= 0x8;
2c: 01 e8 00 00 UNLINK;
30: 10 00 RTS;
...
00000034 <_div256_shift_intrinsic>:
34: 00 00 NOP;
36: 00 e8 00 00 LINK 0x0; /* (0) */
3a: 40 4d R0 >>>= 0x8;
3c: 01 e8 00 00 UNLINK;
40: 10 00 RTS;
...
so it looks like bfin-elf-gcc is smart enough to replace the constant div with a shift, but it is also doing some checking on negative numbers, because it doesn’t know that the blackfin rshift instruction performs sign-extension (or something.)
IIRC, bfin-elf-gcc is also smart enough to use hardware loop counting in some situations, but not in others. in some i was able to squeeze a couple cycles out of some DSP mix loops by writing them as inline assembly. (in other cases the compiler was smarter than me.) but of course this multiplies the coding time by a large factor. in the current structures, there didn’t seem to be any significant gains. but i’ll consider doing this when refactoring the DSP algos for block processing.
it’s always worth looking at the disassembly for your core DSP loops.
BTW:, i apologize that i haven’t made faster progress on this. winter is always a busy time for NAMM and other reasons. the basic proof of concept for block processing is functional; i’ll get back into extending it in a couple weeks.