0 Members and 2 Guests are viewing this topic.
Why is post-check more optimized than a Repeat loop, though?
Quote from: ScoutDavid on December 31, 2010, 05:22:09 pmQuote from: Runer112 on December 31, 2010, 05:20:38 pmSpeaking of optimizing control structures, any chance for Do...While loops?I'd like Switch cases more than Do...While loops, but I don't really know how the second works.Do...While loops are a lot like While...End loops, except that the check to advance to another iteration of the loop is at the end instead of the beginning. This turns out to be more optimized. Whereas a While...End loop has two jumps, one to exit the loop if the condition is false and one to jump back to the beginning, a Do...While combines the two into one jump that jumps back to the beginning if the condition is true.I don't know how good that explanation was, but perhaps this pseudocode will help clarify it. Numbers in brackets indicate the number of bytes the real code takes:While...End loop Do...While loop Code: [Select];While[x] Loop condition[2] Check if loop condition is true or false[3] Exit the loop if false;Loop contents;End[3] Jump back to the beginning of the loop Code: [Select];Do;[0] Start of the loop, takes no actual code;Loop contents;While[x] Loop condition[2] Check if loop condition is true or false[3] Jump back to the beginning of the loop if true
Quote from: Runer112 on December 31, 2010, 05:20:38 pmSpeaking of optimizing control structures, any chance for Do...While loops?I'd like Switch cases more than Do...While loops, but I don't really know how the second works.
Speaking of optimizing control structures, any chance for Do...While loops?
;While[x] Loop condition[2] Check if loop condition is true or false[3] Exit the loop if false;Loop contents;End[3] Jump back to the beginning of the loop
;Do;[0] Start of the loop, takes no actual code;Loop contents;While[x] Loop condition[2] Check if loop condition is true or false[3] Jump back to the beginning of the loop if true
I like leaving the last Return in because it helps code readability, and it makes it easier to add new subroutines after it. It doesn't actually affect the compiled code, right?
Quote from: ztrumpet on February 28, 2011, 09:50:07 pmLooks great! Are you going to keep the ship on the screen?What do you mean?
Looks great! Are you going to keep the ship on the screen?
Quote from: Deep Thought on March 01, 2011, 09:26:00 amWhy is post-check more optimized than a Repeat loop, though?I think I remember mentioning why this is in a previous post somewhere... ah yes, here it is:
Quote from: Deep Thought on March 01, 2011, 09:26:00 amI like leaving the last Return in because it helps code readability, and it makes it easier to add new subroutines after it. It doesn't actually affect the compiled code, right?I agree that it improves readability, but because Axe automatically adds a return to the end of programs it's redundant and a waste of 1 byte. You can always improve readability while maintaining optimization by keeping the final Return, but commenting it out.
Quote from: Deep Thought on February 28, 2011, 10:55:41 pmQuote from: ztrumpet on February 28, 2011, 09:50:07 pmLooks great! Are you going to keep the ship on the screen?What do you mean?Are you going to make it so the player's sprite cannot go off the screen?
Axe actually checks if there's already a Return at the end. If there is, it isn't added.
I swear Quigibo mentioned he optimized the Return...Maybe it was just a feature request. I'll check.
Return optimization in no longer automatic due to possible program leaks.