On Sun, 28 Aug 2016, Bob Ammerman wrote: >> As to the contention that the best C compilers can somehow best an >> experienced Assembly programmer, well, I'll leave that open to debate. > > I like to consider myself an "experienced" assembly programmer (at least = the > gray hair on my head would serve to indicate so). > > I had a project on a PIC24 that required the implementation of TEA (tiny > encryption algorithm). This algorithm consists of a lot of shifting, > rotating and bit twiddling, and, with speed of the essence, I thought it > wise to code in assembly. After spending way too much time on it, I was a= ble > to come up with a version that kept all the working variables in register= s, > using every single register except the stack pointer. It ran fast, and I = was > very proud of my work. Curiosity overtook me and I decided to see what th= e > compiler would do with it. I quickly cobbled up a C version of it, withou= t > much regard to efficiency. To my surprise the compiler's code was > substantially identical to mine (modulo storing things in different > registers). It spilled one variable to the stack, and missed a few detail= s, > but its run time was only 15% slower than my very carefully optimized cod= e. It is common for an experienced embedded C programmer to be able to tweak=20 C code so as to coax the compiler to generate better optimization on=20 successive iterations. For example you might find that a C compiler generates better code if the=20 control variable of a for loop decrements down to 0, or if the control=20 variable is not used inside the for loop at all. You might also find that=20 indexing an array is much slower that auto incrementing a pointer. Regards Sergio Masci --=20 http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .