Is there a C or C++ idiom I can use to encourage the VisualDSP compiler to use the loop counter? Will the compiler EVER use the loop counter? For example, I have an EPROM checksum loop that sums a megabyte of EPROM. This is an obvious 1-instruction loop, but the compiler generates a conventional test and branch loop of many instructions. Here's an example of what I want the compiler to figure out: typedef unsigned long ulong; ulong byte_checksum(const ulong *base_address, ulong count) { #if 0 ulong sum = 0; while (count--) sum += *base_address++; return sum & 0xFF; #else ulong sum; --count; asm volatile ("%0=%0-%0;\n" // init sum "r2=DM(%2,m6);\n" // read first value "lcntr=%1, do sum until lce;\n" "sum: %0=%0+r2, r2=DM(%2,m6);\n" : "d" (sum) : "d" (count), "w" (base_address) : "r2"); return sum & 0xFF; // r0 #endif } Kenneth Porter Kensington Laboratories, Inc. mailto: http://www.kensingtonlabs.com |
|
Idioms to encourage lcntr usage
Started by ●October 25, 2000
Reply by ●October 25, 20002000-10-25
I am told that the loop counter is used when the loop variable is a
signed int. The old GNU compiler did not care if the loop counter was unsigned. I am told that the old GNU compiler never checked for the loop counter going negative and that this violates K&R C. The point is that the new compiler is compliant with K&R and it will always make slow loops if you use unsigned ints for loop counters. Try using a signed int for the loop counter and see if the compiler makes nice tight loops. I am assured it will. Brian -----Original Message----- From: Kenneth Porter [mailto:] Sent: Tuesday, October 24, 2000 11:36 PM To: DSPTools.Support Cc: SHARC list Subject: [adsp] Idioms to encourage lcntr usage Is there a C or C++ idiom I can use to encourage the VisualDSP compiler to use the loop counter? Will the compiler EVER use the loop counter? For example, I have an EPROM checksum loop that sums a megabyte of EPROM. This is an obvious 1-instruction loop, but the compiler generates a conventional test and branch loop of many instructions. Here's an example of what I want the compiler to figure out: typedef unsigned long ulong; ulong byte_checksum(const ulong *base_address, ulong count) { #if 0 ulong sum = 0; while (count--) sum += *base_address++; return sum & 0xFF; #else ulong sum; --count; asm volatile ("%0=%0-%0;\n" // init sum "r2=DM(%2,m6);\n" // read first value "lcntr=%1, do sum until lce;\n" "sum: %0=%0+r2, r2=DM(%2,m6);\n" : "d" (sum) : "d" (count), "w" (base_address) : "r2"); return sum & 0xFF; // r0 #endif } Kenneth Porter Kensington Laboratories, Inc. mailto: http://www.kensingtonlabs.com To Join: Send an email to To Post: Send an email to To Leave: Send an email to Archives: http://www.egroups.com/group/adsp Other Groups: http://www.dsprelated.com |