Author Topic: The Optimization Compilation  (Read 96635 times)

0 Members and 1 Guest are viewing this topic.

Offline Happybobjr

  • James Oldiges
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2325
  • Rating: +128/-20
  • Howdy :)
    • View Profile
Re: The Optimization Compilation
« Reply #45 on: January 20, 2011, 03:04:42 pm »
thank you very much
School: East Central High School
 
Axe: 1.0.0
TI-84 +SE  ||| OS: 2.53 MP (patched) ||| Version: "M"
TI-Nspire    |||  Lent out, and never returned
____________________________________________________________

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: The Optimization Compilation
« Reply #46 on: January 21, 2011, 07:58:31 pm »
Code: [Select]
While I
Disp "O
End

Will While I work as If I? If yes, is it faster than While I = 1?

Offline Happybobjr

  • James Oldiges
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2325
  • Rating: +128/-20
  • Howdy :)
    • View Profile
Re: The Optimization Compilation
« Reply #47 on: January 21, 2011, 08:01:44 pm »
the code will create an endless loop.
that is faster than While I=1
School: East Central High School
 
Axe: 1.0.0
TI-84 +SE  ||| OS: 2.53 MP (patched) ||| Version: "M"
TI-Nspire    |||  Lent out, and never returned
____________________________________________________________

Offline rizoom

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 11
  • Rating: +1/-0
    • View Profile
Re: The Optimization Compilation
« Reply #48 on: January 24, 2011, 11:56:11 am »
And of course, instead of doing
Code: [Select]
:If EXP
:1->A
:End

or

Code: [Select]
:If EXP
:->A
:End

But this is much quicker AND smaller (saves 5 bytes)

Code: [Select]
:EXP->A
« Last Edit: January 24, 2011, 11:57:30 am by rizoom »

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: The Optimization Compilation
« Reply #49 on: January 24, 2011, 12:08:32 pm »
Unfortunately those are not equivalent pieces of code.  In the first two examples, a 1 is stored to A upon a true expression, and it remains the same under a false expression.  In the last, it is 1 when its true and 0 when its false.

Offline rizoom

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 11
  • Rating: +1/-0
    • View Profile
Re: The Optimization Compilation
« Reply #50 on: January 24, 2011, 12:13:13 pm »
Oh yes, sorry!

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: The Optimization Compilation
« Reply #51 on: January 24, 2011, 12:14:06 pm »
Hey thats ok :) Sometimes this optimization works even if there is a difference ^^

Welcome to Omnimaga too!  It's nice to see another Axe user around here :) Why don't you make a post in the Introduce Yourself page so we can all give you a proper hearty welcome :D
« Last Edit: January 24, 2011, 12:15:53 pm by Builderboy »

Offline Happybobjr

  • James Oldiges
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2325
  • Rating: +128/-20
  • Howdy :)
    • View Profile
Re: The Optimization Compilation
« Reply #52 on: January 24, 2011, 07:40:34 pm »
Hey thats ok :) Sometimes this optimization works even if there is a difference ^^

Welcome to Omnimaga too!  It's nice to see another Axe user around here :) Why don't you make a post in the Introduce Yourself page so we can all give you a proper peanut filled welcome :D
fixed


Question mark!
0-A->B->C->D.....->Z->0

to

0->{l1-56}
fill(l1-56,56)
School: East Central High School
 
Axe: 1.0.0
TI-84 +SE  ||| OS: 2.53 MP (patched) ||| Version: "M"
TI-Nspire    |||  Lent out, and never returned
____________________________________________________________

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: The Optimization Compilation
« Reply #53 on: January 24, 2011, 08:30:46 pm »
Question mark!
0-A->B->C->D.....->Z->0

to

0->{l1-56}
fill(l1-56,56)
How about this:
0->{oA}
Fill(oA,56)

This takes into account the moving of variables. :)
« Last Edit: January 24, 2011, 08:30:58 pm by ztrumpet »

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: The Optimization Compilation
« Reply #54 on: January 24, 2011, 09:15:05 pm »
If you only need to initialize five or fewer 2-byte values like variables, it is best to initialize them without any special commands. With this method, you can also avoid changing the values of any memory locations that you don't want to initialize between values you do want to initialize.

Code: (18 bytes) [Select]
0→A→B→X→Y→{L₁}ʳ


However, if you need to initialize more than five values, it is best to use the Fill() method, like you suggested for zeroing out every variable. However, a few slight changes:
  • Storing 2 bytes to a constant address (e.g. °A) is more optimized than storing 1 byte.
  • Because of the above modification and the first two bytes now being equal to 0, the start address for Fill() can be increased by 1 (e.g. °A+1) to save some clock cycles by reducing the total number of bytes needed to be filled by 1.
  • There are only 27 variables, for a total of 54 bytes. Subtracting 1 for the above reason and 1 more due to the fact that the size argument of Fill() doesn't count the starting byte gives a grand total of 52 bytes to fill.

Code: (20 bytes) [Select]
0→{°A}ʳ
Fill(°A+1,52)


The above method can also be used to initialize 1-byte values by adjusting the size parameter of Fill() accordingly. Note, though, that it will only work for initializing 2-byte values whose low and high bytes are equal, like 0. To initialize six or fewer 2-byte values that do not adhere to this, use the first method mentioned in this post. To initialize more than six 2-byte values that do not adhere to this, use something like the following method. This example will initialize all 27 variables to the hex value 1337:

Code: (21 bytes) [Select]
ᴇ1337→{°A}ʳ
Copy(°A,+2,52)

Offline squidgetx

  • Food.
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1881
  • Rating: +503/-17
  • rawr.
    • View Profile
Re: The Optimization Compilation
« Reply #55 on: February 03, 2011, 08:09:53 pm »
Added discussion regarding preevaluating expressions. It seems easy, but sometimes you don't remember to do it :P (I know I didn't in SandLand)

Pre-evaluating expressions: Especially in games that heavily reference arrays throughout a section of code, it is often good both for speed and memory to pre-evaluate expressions that do not change throughout the loop. Look at this code for drawing a scrolling 16x16 tilemapper with X and Y positions in pixels:
Code: [Select]
For(A,0,7)
For(B,0,11)
If {Y/8+B*16+(X/8)+A+L1}
Pt-On(A*8-(X^8),B*8-(Y^8),{Y/8+B*32+(X/8)+A}*8+Pic0
End
End
End
There is a HUGE speed gain from simply preevaluating some of the expressions before entering the loop:
Code: [Select]
X/8->E
Y/8->F
X^8->I
Y^8->J
For(A,0,7)
For(B,0,11)
If {F+B*16+E+A+L1}->C
Pt-On(A*8-I,B*8-J,C*8+Pic0
End
End
End

...and also added the thing about Fill(). Man, this thing is getting hard to edit XD
« Last Edit: February 03, 2011, 08:16:42 pm by squidgetx »

Offline calcdude84se

  • Needs Motivation
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2272
  • Rating: +78/-13
  • Wondering where their free time went...
    • View Profile
Re: The Optimization Compilation
« Reply #56 on: February 05, 2011, 09:51:28 pm »
Code: [Select]
X/8->E
Y/8->F
X^8->I
Y^8->J
For(A,0,7)
*8-I->G
For(B,0,11)
If {F+B*16+E+A+L1}->C
Pt-On(G,B*8-J,C*8+Pic0
End
End
End
Even pre-evaluating for inner For( loops ;D
« Last Edit: February 05, 2011, 09:51:51 pm by calcdude84se »
"People think computers will keep them from making mistakes. They're wrong. With computers you make mistakes faster."
-Adam Osborne
Spoiler For "PartesOS links":
I'll put it online when it does something.

Offline Happybobjr

  • James Oldiges
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2325
  • Rating: +128/-20
  • Howdy :)
    • View Profile
Re: The Optimization Compilation
« Reply #57 on: February 05, 2011, 09:55:46 pm »

X/8->E
Y/8->F
X^8->I
Y^8->J
For(A,0,7)
*8-I->G
For(B,0,11)
If {+F*16+E+A+L1}->C
Pt-On(G,B*8-J,C*8+Pic0
End
End
End


could you optimize that to... ^
« Last Edit: February 05, 2011, 09:56:22 pm by Happybobjr »
School: East Central High School
 
Axe: 1.0.0
TI-84 +SE  ||| OS: 2.53 MP (patched) ||| Version: "M"
TI-Nspire    |||  Lent out, and never returned
____________________________________________________________

Offline calcdude84se

  • Needs Motivation
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2272
  • Rating: +78/-13
  • Wondering where their free time went...
    • View Profile
Re: The Optimization Compilation
« Reply #58 on: February 05, 2011, 09:58:12 pm »
Yes you can :)
"People think computers will keep them from making mistakes. They're wrong. With computers you make mistakes faster."
-Adam Osborne
Spoiler For "PartesOS links":
I'll put it online when it does something.

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: The Optimization Compilation
« Reply #59 on: February 05, 2011, 10:03:19 pm »
No, that doesn't work. You're not guaranteed that the last result will be B in the first statement of the For( loop. In fact, I tested and it isn't. It would actually be 11-B (though I wouldn't rely on that since it might change in other versions of Axe)
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman