Author Topic: Assembly Programmers - Help Axe Optimize!  (Read 139573 times)

0 Members and 1 Guest are viewing this topic.

Offline calcdude84se

  • Needs Motivation
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2272
  • Rating: +78/-13
  • Wondering where their free time went...
    • View Profile
Re: Assembly Programmers - Help Axe Optimize!
« Reply #90 on: November 28, 2010, 06:09:36 pm »
This relates to the underlying z80 machine code (or ASM, if you prefer) that Axe generates. ;)
"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 Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Assembly Programmers - Help Axe Optimize!
« Reply #91 on: November 28, 2010, 06:10:09 pm »
This relates to the underlying z80 machine code (or ASM, if you prefer) that Axe generates. ;)

Good then, so the 'executables', which is, the .asm files are now running faster!

ASHBAD_ALVIN

  • Guest
Re: Assembly Programmers - Help Axe Optimize!
« Reply #92 on: November 28, 2010, 06:40:57 pm »
I would love to help with optimization, I can help with virtually everything except messing with archive, writing apps, and advanced sprite routines.

Other than that, I can help with everything else.

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Assembly Programmers - Help Axe Optimize!
« Reply #93 on: December 01, 2010, 03:38:20 pm »
Just some minor stuff. None of these improve size, but they'll shave off a few cycles.

Code: [Select]
p_Add510:
.db 4
inc h
inc h
dec hl
dec hl
p_Add514:
.db 4
inc h
inc h
inc hl
inc hl
p_Add767:
.db 4
inc h
inc h
inc h
dec hl
p_Add769:
.db 4
inc h
inc h
inc h
inc hl
p_Add1024:
.db 4
inc h
inc h
inc h
inc h
p_Sub510:
.db 4
dec h
dec h
inc hl
inc hl
p_Sub514:
.db 4
dec h
dec h
dec hl
dec hl
p_Sub767:
.db 4
dec h
dec h
dec h
inc hl
p_Sub769:
.db 4
dec h
dec h
dec h
dec hl
p_Sub1024:
.db 4
dec h
dec h
dec h
dec h

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Assembly Programmers - Help Axe Optimize!
« Reply #94 on: December 17, 2010, 01:11:47 am »
Some constant equality checking optimizations. Feel free to extrapolate these optimizations to values that previously weren't optimized because the code would have been too large.

Code: (Current code) [Select]
p_EQN256:
.db 9
inc h
ld a,l
or h
jr z,$+5
ld hl,255
inc l
p_EQN2:
.db 10
inc hl
inc hl
ld a,l
or h
jr z,$+5
ld hl,255
inc l
p_EQN1:
.db 9
inc hl
ld a,l
or h
jr z,$+5
ld hl,255
inc l
p_EQ0:
.db 8
ld a,l
or h
jr z,$+5
ld hl,255
inc l
p_EQ256:
.db 9
dec h
ld a,l
or h
jr z,$+5
ld hl,255
inc l

       
Code: (Optimized code) [Select]
p_EQN256:
.db 8
inc h
ld a,l
or h
add 255
sbc hl,hl
inc hl
p_EQN2:
.db 8
inc l
ld a,l
and h
sub 255
sbc hl,hl
inc hl

p_EQN1:
.db 7
ld a,l
and h
sub 255
sbc hl,hl
inc hl

p_EQ0:
.db 7
ld a,l
or h
add 255
sbc hl,hl
inc hl
p_EQ256:
.db 8
dec h
ld a,l
or h
add 255
sbc hl,hl
inc hl



Also, p_Div32768 can be optimized to be the same as p_SLT0 and p_GetBit0.
« Last Edit: December 17, 2010, 01:14:22 am by Runer112 »

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Assembly Programmers - Help Axe Optimize!
« Reply #95 on: December 20, 2010, 05:42:17 pm »
A few more equality checking optimizations. Not sure why I didn't see these before.

Code: (Current code) [Select]
p_NEN3:
.db 10
inc hl
inc hl
inc hl
ld a,l
or h
jr z,$+5
ld hl,1
p_NEN2:
.db 9
inc hl
inc hl
ld a,l
or h
jr z,$+5
ld hl,1
p_NEN1:
.db 8
inc hl
ld a,l
or h
jr z,$+5
ld hl,1

       
Code: (Optimized code) [Select]
p_NEN3:
.db 9
inc l
inc l
ld a,l
and h
add a,1
sbc hl,hl
inc hl
p_NEN2:
.db 8
inc l
ld a,l
and h
add a,1
sbc hl,hl
inc hl
p_NEN1:
.db 7
ld a,l
and h
add a,1
sbc hl,hl
inc hl


Offline Happybobjr

  • James Oldiges
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2325
  • Rating: +128/-20
  • Howdy :)
    • View Profile
Re: Assembly Programmers - Help Axe Optimize!
« Reply #96 on: December 20, 2010, 05:53:58 pm »
will this increase speed, decrease size or both?
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 Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Assembly Programmers - Help Axe Optimize!
« Reply #97 on: December 20, 2010, 05:57:40 pm »
These will decrease size, but also slightly decrease speed. I believe that Quigibo prefers smaller sizes over slightly slower code.

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Assembly Programmers - Help Axe Optimize!
« Reply #98 on: December 20, 2010, 06:00:00 pm »
Concerning optimizations:

I used an Assembly Disassembler to disassemble my game uPong and the code was 1531 lines! It was huge. Hopefully, thanks to Runner's and other members' optimizations, Axe programs can get smaller and smaller :)

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Assembly Programmers - Help Axe Optimize!
« Reply #99 on: December 20, 2010, 06:01:55 pm »
Concerning optimizations:

I used an Assembly Disassembler to disassemble my game uPong and the code was 1531 lines! It was huge. Hopefully, thanks to Runner's and other members' optimizations, Axe programs can get smaller and smaller :)

Axe programs always have some overhead. You can get rid of memory storing like with For( loops and switch them to use registers, and you'd get it several times faster too :)




Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Assembly Programmers - Help Axe Optimize!
« Reply #100 on: December 20, 2010, 06:34:04 pm »
The more assembly instructions available, the more you could optimize programs. But I don't want Axe to just turn into an assembly compiler with a 16-bit math engine and some other pre-built structures on the side. If you want that, you probably know assembly anyways and could just write your program in assembly and grab some of Axe's routines.

However, three instructions that I believe would complement Axe very well without defeating the purpose of its hl-based system are the ex de,hl, push hl, and pop hl instructions.

Quigibo had toyed with the idea of implementing the ex de,hl instruction before, allowing it to be called with either →π or π. They would do the same thing, but it would be a more familiar syntax for programmers used to a variable system in which storing and recalling values are different instructions. And/or he could implement the instruction as the Exch() command with no arguments.

Although there would definitely need to be a warning to only use push and pop if you know how stacks work and know what you're doing, those would be pretty helpful I think. Maybe push hl could be StoreGDB and pop hl could be RecallGDB .


In case Quigibo is reading this, any chance of these happening?
« Last Edit: December 20, 2010, 06:42:01 pm by Runer112 »

Ashbad

  • Guest
Re: Assembly Programmers - Help Axe Optimize!
« Reply #101 on: December 20, 2010, 06:35:49 pm »
well, that's a great idea, but maybe even more commands to let advanced users toy with assembly instructions further?

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: Assembly Programmers - Help Axe Optimize!
« Reply #102 on: December 20, 2010, 06:39:20 pm »
I don't think push and pop are that good of an idea because of the stack thing.  And all of those are only 2 hex characters of the Asm() command anyway.  The exchange I am still thinking about, I'm trying to see how practical it would be and how many commands are actually safe to use and I could change some commands to use bc instead.

Thanks again for the optimizations of the equalities, those are very widely used in programs so its great to see those optimized.  I extended your optimizations to equality comparisons against variables too which actually reduces the number of auto-optimizations I need to do since the general cases are smaller.
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Assembly Programmers - Help Axe Optimize!
« Reply #103 on: December 20, 2010, 06:45:47 pm »
I realize that the stack can be very dangerous, as one push without a pop and you can say goodbye to the contents of your RAM. But the stack is also one of the most powerful programming tools present on the calculator. As long as you added warnings not to use the stack commands unless users know how the stack functions, I think it would be a very nice addition. And I would be happy to write an addition to the documentation about stack usage so users who aren't familiar with stacks could learn their power. ;)
« Last Edit: December 20, 2010, 06:47:41 pm by Runer112 »

Ashbad

  • Guest
Re: Assembly Programmers - Help Axe Optimize!
« Reply #104 on: December 20, 2010, 06:48:48 pm »
very true, I personally love the stack most among most other things, that's one thing I always loved about raw assembly programming.

Then, Axe can appeal to just about everybody :)