Shop OBEX P1 Docs P2 Docs Learn Events
Basic SPIN optimization — Parallax Forums

Basic SPIN optimization

kuismakuisma Posts: 134
edited 2010-12-10 09:55 in General Discussion
I'd like PropTool to perform basic optimization

Things like
CON
   DEBUG_FOO = false
[...]

  if DEBUG_FOO
    ... do something ...

I'd very much prefer this not to render binary code never executed.

Comments

  • Dave HeinDave Hein Posts: 6,347
    edited 2010-12-10 08:42
    There are many optimizations that could be done, but I doubt if they'll be added to the Prop Tool any time soon. There are some simple optimaztion that could be done like automatically folding constants, replacing byte[ptr][0] with byte[ptr], replacing x := 0 with x~, etc. However, that would take all the "fun" out of programming in Spin.

    As far as your suggestion, it could be done with #define and #if if that was added.

    Dave
  • kuismakuisma Posts: 134
    edited 2010-12-10 08:52
    Dave Hein wrote: »
    As far as your suggestion, it could be done with #define and #if if that was added.

    Right on!

    But without a pre-processor, Parallax can even without changing the semantics gain some of the benefits by implementing this kind of trivial and non-destructive code optimization. Would this really take the fun out of Spin? What kind of side effects are you using to benefit from code behind unconditionally false conditions..? Maybe I'm missing some of the features of Spin..?

    I'm running out of code space, and removing conditional debugging is not my idea of optimization. :(
  • Dave HeinDave Hein Posts: 6,347
    edited 2010-12-10 09:55
    If you're running out of code space you should try using BST with some of the optimizations turned on. This might save you some space. There are also a few programming tricks that will save space and run faster. Use unary operations when possible. x++ is more efficient than x += 1, which is more efficient than x := x + 1. Also, it is more efficient to address the first few stack and var variables than to address the remaining stack, var and dat variables. I think it is the first 8 stack and var variables that use a compact addressing scheme. There are a few other tricks that are documented somewhere, but I can't find the reference right now.

    Dave
Sign In or Register to comment.