??? 06/29/05 17:40 Read: times |
#96215 - Really Wicked Optimisations! Responding to: ???'s previous message |
Erik Malund said:
rules for optimum '51 C
1) Take the darn PC hat off. '51 C is not "just c" 2) ALWAYS use the smallest size of a variable that will fit 3) Make counters in loops -- instead of ++ wherever possible 4) Keil has - on request - provided for things like malloc, that does not mean they are "good" it is a disaster in a '51 5) The '51 has very powerful bit instructions - USE THEM. E.g. if a function can return TRUE or FALSE a bit is enough. Some more: 6) Always use unsigned where possible 7) DATA access is fastest, and uses least code; IDATA is next best; PDATA is next best; XDATA is worst (for both speed & code size). Therefore, put your most-accessed variables in DATA; put loop counters in DATA; put anything needing fastest access in DATA, etc 8) Avoid floating point 9) Remember, printf takes a lot of code! 10) Make maximum use of local variables - they are overlayable, globals aren't (but don't forget that passing parameters around takes code - especially if you go over the limit that the compiler can pass in registers) |