Author Topic: The Optimization Compilation  (Read 96023 times)

0 Members and 2 Guests are viewing this topic.

Offline Fast Crash

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 192
  • Rating: +45/-7
  • Virus of tomorrow
    • View Profile
Re: The Optimization Compilation
« Reply #15 on: December 29, 2010, 05:49:30 pm »
Very Nice tricks ! Congratulations !

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 #16 on: December 29, 2010, 06:46:57 pm »
By the way, you can't have non-constant data as part of the Data() command.  And that whole inData() optimization only works for comparisons with numbers between 0-255.  You can optimize it to this always though:

Code: [Select]
!If A-EXP1 [16bit and] (A-EXP2)
Wait, but you can't use bitwise-and like a logical "and" the same way you can with "or".
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline kindermoumoute

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 836
  • Rating: +54/-3
    • View Profile
Re: The Optimization Compilation
« Reply #17 on: December 29, 2010, 06:55:44 pm »
Wooooaa ! I need translate this in my french tutorial, can I ?  :love:
Projects :

Worms armageddon z80 :
- smoothscrolling Pixelmapping : 100%
- Map editor : 80%
- Game System : 0%

Tutoriel français sur l'Axe Parser
- 1ère partie : en ligne.
- 2ème partie : en ligne.
- 3ème partie : en ligne.
- 4ème partie : 10%
- Annexe : 100%

Offline squidgetx

  • Food.
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1881
  • Rating: +503/-17
  • rawr.
    • View Profile
Re: The Optimization Compilation
« Reply #18 on: December 29, 2010, 07:55:40 pm »
By the way, you can't have non-constant data as part of the Data() command.  And that whole inData() optimization only works for comparisons with numbers between 0-255.  You can optimize it to this always though:

Code: [Select]
!If A-EXP1 [16bit and] (A-EXP2)
Wait, but you can't use bitwise-and like a logical "and" the same way you can with "or".

Actually, yeah, i think calc84's right (I tried it today and it didn't work).

And kinder, go ahead :)

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: The Optimization Compilation
« Reply #19 on: December 29, 2010, 08:45:05 pm »
Oh you're right.  But I just realized that your other optimization doesn't work either. You cannot do this for AND:
Code: [Select]
!If A-EXP1 + (B-EXP2)This doesn't work because there are more solutions than there should be.  For instance, if A were EXP2 and B were EXP1 the expression would be zero when it should be non-zero.

But you can do this for a compound OR:
Code: [Select]
If A=EXP1 + (B=EXP2)
And you can do this for a compound AND:
Code: [Select]
!If A-EXP1 [16-bit or] (B-EXP2)
And speaking of optimizations.  One major optimization that usually gets ignored is recycling large axe commands.  Axe is not like BASIC and so each command needs its own subroutine to add to your program.  For instance, lets say you use Pt-On() and Pt-Mask() in your code.  Each one has to bring its own 100+ byte subroutine into your program.  But you can probably get away with having just a Pt-Mask routine, recycling it to act like Pt-On by simply adding a 2nd layer to your sprite which is only 8 bytes extra instead of 100ish.  Or you could do the opposite too and only have Pt-On() and Pt-Change() to manually change both buffers at once.  This generally reduces the overall size of the program by a lot when you use the routines only once or very rarely in your code.  And I don't mean calling it rarely, it could be the most used routine in your code, I just mean rarely appears in your source.

More examples: You can draw pixels and boxes with just sprite commands.  Boxes can be drawn with just pixels or lines.  Strait lines can be drawn with just boxes or pixels.  Its best if you only have one type of DispGraph in your all your code.  Pre-flip sprites so you don't need the flip commands in your code.  etc.

The only downside is that it slightly reduces the speed since its not as specialized but its usually worth it because you save a lot of memory, especially in smaller programs.
« Last Edit: December 29, 2010, 09:07:48 pm by Quigibo »
___Axe_Parser___
Today the calculator, tomorrow the world!

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 #20 on: December 29, 2010, 11:06:12 pm »
Awesome!  Thanks squidgetx! ;D

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: The Optimization Compilation
« Reply #21 on: December 29, 2010, 11:46:14 pm »
In case anyone was wondering, here is the smallest loop structure that I know of in Axe. It will execute the loop n times, with A starting at n-1 and decreasing down to 0:

Code: [Select]
n
While
  -1→A
  ;Code
  A
End

And if Quigibo adds conditional jumps, this sort of Do...While loop would be even smaller (which he has not yet, so don't bother with this code as of Axe 0.4.7):

Code: [Select]
n
Lbl L
  →A
  ;Code
!If A-1
  Goto L
End


EDIT: As a side note in case you read this Quigibo, any chance for Do...While loops? They're more optimized than normal While loops.
« Last Edit: December 29, 2010, 11:47:16 pm by Runer112 »

Offline Michael_Lee

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1019
  • Rating: +124/-9
    • View Profile
Re: The Optimization Compilation
« Reply #22 on: December 29, 2010, 11:50:51 pm »
In case anyone was wondering, here is the smallest loop structure that I know of in Axe.

By smallest, do you mean in terms of size, or in terms of speed?  (or both?)
My website: Currently boring.

Projects:
Axe Interpreter
   > Core: Done
   > Memory: Need write code to add constants.
   > Graphics: Rewritten.  Needs to integrate sprites with constants.
   > IO: GetKey done.  Need to add mostly homescreen IO stuff.
Croquette:
   > Stomping bugs
   > Internet version: On hold until I can make my website less boring/broken.

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: The Optimization Compilation
« Reply #23 on: December 30, 2010, 12:01:33 am »
Both ;) It's 8 bytes smaller and should save about 52 t-states per iteration.

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 #24 on: December 30, 2010, 12:25:28 am »
Wow that is a great loop optimization O.O i think with all the optimizations present here i could shave hundreds of bytes off of all of my Axe projects O.O

Offline squidgetx

  • Food.
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1881
  • Rating: +503/-17
  • rawr.
    • View Profile
Re: The Optimization Compilation
« Reply #25 on: December 30, 2010, 07:21:32 am »
Quigibo, when I use "+" I meant 16 bit "or" (I think I wrote that there next to it...) and wow, nice, Runer :)

Also, edited those new opts into the first post
« Last Edit: December 30, 2010, 07:48:48 pm by squidgetx »

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: The Optimization Compilation
« Reply #26 on: December 30, 2010, 11:29:56 pm »
Nice, so would it be better to use this instead of a For( loop?

Offline squidgetx

  • Food.
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1881
  • Rating: +503/-17
  • rawr.
    • View Profile
Re: The Optimization Compilation
« Reply #27 on: January 02, 2011, 10:43:11 am »
^yes.

I'm adding another opt that is rather specific (ofc by Runer112) (moving around a sprite) but I think that people will appreciate it. i also commented it so that you can understand what it's doing more easily (because at first you can't even begin to decipher what it's doing lol)
« Last Edit: January 02, 2011, 10:50:18 am by squidgetx »

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: The Optimization Compilation
« Reply #28 on: January 02, 2011, 10:45:30 am »
Nice squidget, the one from the other post, I went :crazy:

Offline squidgetx

  • Food.
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1881
  • Rating: +503/-17
  • rawr.
    • View Profile
Re: The Optimization Compilation
« Reply #29 on: January 03, 2011, 06:48:45 pm »
updated with discussion regarding +1 over 1 with respect to false expression testing (!If statements)

Again, thanks to Runer112 lol