Author Topic: Axe Parser  (Read 564902 times)

0 Members and 4 Guests are viewing this topic.

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: Axe Parser
« Reply #30 on: February 03, 2010, 05:45:25 pm »
When I said fast, I didn't expect unrolled fast ;)  I'd prefer the smallest code possible that doesn't use a naive method.

I think I see the pattern though.  I can just figure out how to roll it up again. 

Here is the super efficient HL*DE multiplication routine I'm using, only 14 bytes  :)  The real routine is a little bit bigger just because it has to find which of the two arguments is smallest and exchange them if necessarily.
Code: [Select]
_DE_Times_L:
xor a
ld h,a
ld a,l
ld l,h
_Loop:
rra
jr nc,_Skip
add hl,de
_Skip:
sla e
rl d
or a
jr nz,_Loop
ret
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: Axe Parser
« Reply #31 on: February 03, 2010, 05:51:25 pm »
Hold up, found a more efficient method (and I put it into loops just for you ;D)

Code: [Select]
div_hl_de:
; BC = HL/DE, HL = remainder

xor a
sub e
ld e,a
sbc a,a
sub d
ld d,a

ld a,h
ld b,l
ld hl,0
ld c,8

div_loop_1:
rla
adc hl,hl
add hl,de
jr c,$+4
sbc hl,de
dec c
jr nz,div_loop_1
rla

ld c,a
ld a,b
ld b,8

div_loop_2:
rla
adc hl,hl
add hl,de
jr c,$+4
sbc hl,de
djnz div_loop_2
rla

ld b,a
ret
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

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: Axe Parser
« Reply #32 on: February 03, 2010, 07:46:14 pm »
That's awesome code!  ;D Great job on it, though I only kinda understand. (The time for explaining is not now, so you don't need to explain it to me now. :) )
« Last Edit: February 03, 2010, 07:46:33 pm by ztrumpet »

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: Axe Parser
« Reply #33 on: February 03, 2010, 11:11:55 pm »
Thanks for that division routine, but I found this one and its a lot smaller.

Code: [Select]
HL_div_DE:
ld a,h
ld c,l
ld hl,0
ld b,16
__DivLoop:
sll c
rla
adc hl,hl
sbc hl,de
jr nc,__DivSkip
add hl,de
dec c
__DivSkip:
djnz __DivLoop
ld h,a
ld l,c
ret

I'm just a little bit worried about the use of the sll command, will that sacrifice compatibility with the Nspire?
« Last Edit: February 03, 2010, 11:12:44 pm by Quigibo »
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: Axe Parser
« Reply #34 on: February 03, 2010, 11:45:58 pm »
Thanks for that division routine, but I found this one and its a lot smaller.

Code: [Select]
HL_div_DE:
ld a,h
ld c,l
ld hl,0
ld b,16
__DivLoop:
sll c
rla
adc hl,hl
sbc hl,de
jr nc,__DivSkip
add hl,de
dec c
__DivSkip:
djnz __DivLoop
ld h,a
ld l,c
ret

I'm just a little bit worried about the use of the sll command, will that sacrifice compatibility with the Nspire?
You are correct. You can replace it with "scf \ rl c" though

Edit:
Also, if you haven't done this already, I'd like to suggest that you auto-generate multiplication algorithms when multiplying by constants. Like A*9 would become:
Code: [Select]
ld hl,(var_a)
ld d,h
ld e,l
add hl,hl
add hl,hl
add hl,hl
add hl,de
« Last Edit: February 03, 2010, 11:56:42 pm by calc84maniac »
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline Silver Shadow

  • Beta Tester
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 817
  • Rating: +27/-7
    • View Profile
Re: Axe Parser
« Reply #35 on: February 04, 2010, 07:56:41 am »
Thanks for that division routine, but I found this one and its a lot smaller.

Code: [Select]
HL_div_DE:
ld a,h
ld c,l
ld hl,0
ld b,16
__DivLoop:
sll c
rla
adc hl,hl
sbc hl,de
jr nc,__DivSkip
add hl,de
dec c
__DivSkip:
djnz __DivLoop
ld h,a
ld l,c
ret

I'm just a little bit worried about the use of the sll command, will that sacrifice compatibility with the Nspire?
I definitely want this to work on the NSpire, so could you use another method instead?
Former Coder of Tomorrow


Offline Eeems

  • Mr. Dictator
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6268
  • Rating: +318/-36
  • little oof
    • View Profile
    • Eeems
Re: Axe Parser
« Reply #36 on: February 04, 2010, 09:40:15 am »
 think calc84 gave a way that works.
/e

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: Axe Parser
« Reply #37 on: February 04, 2010, 04:04:22 pm »
Yeah, its only one byte more for the compatibility.  Worth it. ;)

Quote
Also, if you haven't done this already, I'd like to suggest that you auto-generate multiplication algorithms when multiplying by constants.
I probably will for powers of 2, but I don't think there will really need to be such high speed math operations, I mean, I don't think anyone will be making a first person shooter or anything.  But I guess if a few microseconds are important enough to account for the program size increase, you can always add some Hex code to do the faster multiplication.
___Axe_Parser___
Today the calculator, tomorrow the world!

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: Axe Parser
« Reply #38 on: February 04, 2010, 06:48:34 pm »
I am confused by what this means. Does it means it would be only possible to mutiply by 2, 4 and the like? It might become an issue for example if I did a small RPG where your max HP and attack power was like 101 x character LV

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: Axe Parser
« Reply #39 on: February 04, 2010, 06:54:02 pm »
No, no, it just means that multiplying by powers of 2 will use a smaller, faster code that multiplying the regular way.  Its just an optimization.  Even things like +1 and +2 can be optimized.

Probably won't be in the next release, but I'll get to automatic optimizations eventually.
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: Axe Parser
« Reply #40 on: February 04, 2010, 06:54:17 pm »
I am confused by what this means. Does it means it would be only possible to mutiply by 2, 4 and the like? It might become an issue for example if I did a small RPG where your max HP and attack power was like 101 x character LV
He's just saying that it would be slower to multiply by anything else because it would call a general routine instead of adding manually

Edit: Ninjaaaaa
« Last Edit: February 04, 2010, 06:54:47 pm by calc84maniac »
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

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: Axe Parser
« Reply #41 on: February 04, 2010, 06:55:03 pm »
aaaah ok, I see, thanks for clarifying

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Axe Parser
« Reply #42 on: February 04, 2010, 06:55:27 pm »
I think (but i'm not sure) is that when multiplying by any arbitrary number, it uses the general multiplication routine, but when multiplying by 2, you use the dedicated x2 routine?

EDIT: nice Ninja there Quigibo :P
EDIT2: Double ninja  :o
EDIT3: Damn Triple ninja :(

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: Axe Parser
« Reply #43 on: February 04, 2010, 06:57:40 pm »
I think (but i'm not sure) is that when multiplying by any arbitrary number, it uses the general multiplication routine, but when multiplying by 2, you use the dedicated x2 routine?

Correct.  The general x2 routine is to add the number to itself :P
« Last Edit: February 04, 2010, 06:58:13 pm by Quigibo »
___Axe_Parser___
Today the calculator, tomorrow the world!

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: Axe Parser
« Reply #44 on: February 05, 2010, 02:49:00 am »
I removed all replies from the updates thread and moved them here.