Editing BoostC Optimizations
Jump to navigation
Jump to search
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 6: | Line 6: | ||
− | = some notes from the forum still to be formatted = | + | == some notes from the forum still to be formatted == |
The following post yeilded several real and unreal optimizations | The following post yeilded several real and unreal optimizations | ||
Line 12: | Line 12: | ||
− | == Incrementing == | + | ==== Incrementing ==== |
subtracting/deincrementing is faster than adding/incrementing | subtracting/deincrementing is faster than adding/incrementing | ||
Line 20: | Line 20: | ||
Post: http://forum.sourceboost.com/index.php?showtopic=2433&pid=9574&mode=threaded&start=#entry9574 | Post: http://forum.sourceboost.com/index.php?showtopic=2433&pid=9574&mode=threaded&start=#entry9574 | ||
− | == Avoid Division == | + | ==== Avoid Division ==== |
not using division saves ~35 bytes | not using division saves ~35 bytes | ||
− | Valid? division is slow, but we think not by | + | Valid? division is slow, but we think not by poweres of 2, which are shifts ( if divisor know at compile time ) |
Post: http://forum.sourceboost.com/index.php?showtopic=2433&pid=9574&mode=threaded&start=#entry9574 | Post: http://forum.sourceboost.com/index.php?showtopic=2433&pid=9574&mode=threaded&start=#entry9574 | ||
− | == Left vs Right Shift == | + | ==== Left vs Right Shift ==== |
Left Shifting is faster than Right | Left Shifting is faster than Right | ||
Line 36: | Line 36: | ||
Post: http://forum.sourceboost.com/index.php?showtopic=2433&pid=9574&mode=threaded&start=#entry9574 | Post: http://forum.sourceboost.com/index.php?showtopic=2433&pid=9574&mode=threaded&start=#entry9574 | ||
− | == Function call in ISR == | + | ==== Function call in ISR ==== |
Calling a function in an ISR takes longer than outside an ISR | Calling a function in an ISR takes longer than outside an ISR | ||
Line 44: | Line 44: | ||
Post: http://forum.sourceboost.com/index.php?showtopic=2433&pid=9574&mode=threaded&start=#entry9574 | Post: http://forum.sourceboost.com/index.php?showtopic=2433&pid=9574&mode=threaded&start=#entry9574 | ||
− | == Function called Only Once == | + | ==== Function called Only Once ==== |
Never use a function for a single operation, you waste time calling and returning | Never use a function for a single operation, you waste time calling and returning | ||
Line 52: | Line 52: | ||
Post: http://forum.sourceboost.com/index.php?showtopic=2433&pid=9574&mode=threaded&start=#entry9574 | Post: http://forum.sourceboost.com/index.php?showtopic=2433&pid=9574&mode=threaded&start=#entry9574 | ||
− | == Shift for Division == | + | ==== Shift for Division ==== |
Use bit shifting instead of division for speed savings and possible ram savings | Use bit shifting instead of division for speed savings and possible ram savings | ||
Line 95: | Line 95: | ||
Post: http://forum.sourceboost.com/index.php?showtopic=2433&pid=9574&mode=threaded&start=#entry9574 | Post: http://forum.sourceboost.com/index.php?showtopic=2433&pid=9574&mode=threaded&start=#entry9574 | ||
− | == ROM vs RAM == | + | ==== ROM vs RAM ==== |
Write constants into ROM not RAM | Write constants into ROM not RAM | ||
Line 103: | Line 103: | ||
Post: http://forum.sourceboost.com/index.php?showtopic=2433&pid=9574&mode=threaded&start=#entry9574 | Post: http://forum.sourceboost.com/index.php?showtopic=2433&pid=9574&mode=threaded&start=#entry9574 | ||
− | == Return Values == | + | ==== Return Values ==== |
Do not return values from functions that you wont use/do not need. | Do not return values from functions that you wont use/do not need. | ||
Line 111: | Line 111: | ||
Post: http://forum.sourceboost.com/index.php?showtopic=2433&pid=9574&mode=threaded&start=#entry9574 | Post: http://forum.sourceboost.com/index.php?showtopic=2433&pid=9574&mode=threaded&start=#entry9574 | ||
− | == ROM vs RAM == | + | ==== ROM vs RAM ==== |
+ | |||
Reuse common code or write a common function and call it will save huge amounts of space | Reuse common code or write a common function and call it will save huge amounts of space | ||
Line 120: | Line 121: | ||
Post: http://forum.sourceboost.com/index.php?showtopic=2433&pid=9574&mode=threaded&start=#entry9574 | Post: http://forum.sourceboost.com/index.php?showtopic=2433&pid=9574&mode=threaded&start=#entry9574 | ||
− | == ()?:; == | + | ==== ()?:; ==== |
i had forgotten about this one but the good old ()?:; (tri-unary?) function conditionally yields | i had forgotten about this one but the good old ()?:; (tri-unary?) function conditionally yields | ||
Line 130: | Line 131: | ||
left empty or there is no value in using it and will actually result in longer code. | left empty or there is no value in using it and will actually result in longer code. | ||
− | + | CODE | |
− | + | (test)?(result=1):(result=0); | |
VS | VS | ||
− | + | CODE | |
− | + | if(test) | |
− | + | { | |
− | + | result=1; | |
− | + | } | |
− | + | else | |
− | + | { | |
− | + | result=0; | |
− | + | } | |
Line 151: | Line 152: | ||
For code like that, I would expect this: | For code like that, I would expect this: | ||
+ | CODE | ||
+ | result = (test ? 1 : 0) | ||
+ | to do better, but it doesn't, either... | ||
+ | |||
+ | |||
+ | |||
+ | For code like that, I would expect this: | ||
+ | CODE | ||
+ | result = (test ? 1 : 0) | ||
+ | to do better, but it doesn't, either... | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | Odd, altho my tests were simply: | ||
+ | |||
+ | CODE | ||
+ | (testBit)?(_ONE = 1):(_ONE = 0); | ||
+ | 0039 08A1 MOVF main_1_testBit, F | ||
+ | 003A 1903 BTFSC STATUS,Z | ||
+ | 003B 283E GOTO label268438744 | ||
+ | 003C 1486 BSF gbl__ONE,1 | ||
+ | 003D 283F GOTO label268438746 | ||
+ | 003E label268438744 | ||
+ | 003E 1086 BCF gbl__ONE,1 | ||
+ | 003F label268438746 | ||
+ | |||
+ | if(testBit) | ||
+ | 003F 08A1 MOVF main_1_testBit, F | ||
+ | 0040 1903 BTFSC STATUS,Z | ||
+ | 0041 2844 GOTO label268438747 | ||
+ | 0044 label268438747 | ||
+ | |||
+ | { | ||
+ | _ONE = 1; | ||
+ | 0042 1486 BSF gbl__ONE,1 | ||
− | + | } | |
+ | else | ||
+ | 0043 2837 GOTO label268438739 | ||
− | + | { | |
+ | _ONE = 0; | ||
+ | 0044 1086 BCF gbl__ONE,1 | ||
+ | |||
+ | } | ||
Line 196: | Line 240: | ||
Post: http://forum.sourceboost.com/index.php?showtopic=2433&pid=9574&mode=threaded&start=#entry9574 | Post: http://forum.sourceboost.com/index.php?showtopic=2433&pid=9574&mode=threaded&start=#entry9574 | ||
− | = Still More we are working on = | + | ==== Still More we are working on ==== |
− | |||
Software stack is slower than hardware ( but deeper ) | Software stack is slower than hardware ( but deeper ) | ||
Line 204: | Line 247: | ||
Valid? we think so. | Valid? we think so. | ||
− | + | Inline function does not really use call and return so is faster, but if called multiple time may take more space ( but for short funtions the call return... can take more space than the function itself. Would be nice if someone did measurements. | |
− | + | Valid? we think so. | |
− | |||
== Local vs Global == | == Local vs Global == | ||
Line 214: | Line 256: | ||
Local values vs global variables. | Local values vs global variables. | ||
− | Issue not understood, local may require some stack heap management, but space should be recovered when function exits so local variable saves memory overall. Probably you should follow good pratices and use variables of th narrowest scope possible. | + | Issue not understood, local may require some stack heap management, but space should be recovered when function exits so local variable saves memory overall. Probably you should follow good pratices and use variables of th narrowest scope possible . |
− | |||
− | |||
− | |||
− | |||
− | |||
− |