Jump to content
IGNORED

Which is faster?


Random Terrain

Recommended Posts

Which is faster?

 

 

This:

 

temp6 = ((player0y-4)/4)-1

 

 

 

Or this:

 

temp6 = player0y-4 : temp6 = temp6/4 : temp6 = temp6-1

 

 

 

Or is there an even faster way than either of those?

 

 

 

Thanks.

You could simplify the math. ((player0y-4)/4)-1 = (player0y/4 - 4/4) -1 = player0y/4 - 2

 

temp6 = (player0y/4)-2

 

-Jeff

  • Like 1
Link to comment
Share on other sites

You could simplify the math. ((player0y-4)/4)-1 = (player0y/4 - 4/4) -1 = player0y/4 - 2

 

temp6 = (player0y/4)-2

Thanks. That's an improvement, but in cases where you can't do something simple like that, I wonder which style would be faster?

Link to comment
Share on other sites

You can always do something simple like that.

There are no existing cases where this math cannot be applied on the 2600 :)

 

 asm
lda player0y ;[0]+3
lsr          ;[3]+2
lsr          ;[5]+2
sec          ;[7]+2
sbc #2       ;[9]+2
sta temp6    ;[11]+3 14-cycles for routine
end

 

You would be trying to optimize this routine, which is already pretty much as optimized as you can get.

Edited by ScumSoft
Link to comment
Share on other sites

You can always do something simple like that.

I don't know what you mean. For example, if it was temp6 = ((player0y-3)/4)-1 instead, you couldn't do what jwierer did. He lucked out because the number I was subtracting turned out to be 4, but at one time, the number was something else.

Link to comment
Share on other sites

Which is faster?

 

temp6 = ((player0y-4)/4)-1

...takes 18 cycles

 

temp6 = player0y-4 : temp6 = temp6/4 : temp6 = temp6-1

...takes 26 cycles.

 

When bB works though a complex statement, it uses the registers (faster) instead of memory locations (slower) to hold the intermediate calculations.

 

There's not a faster way to do it in bB, with the exception of assembly or simplifying the math, as demonstrated.

  • Like 1
Link to comment
Share on other sites

Which is faster?

 

temp6 = ((player0y-4)/4)-1

...takes 18 cycles

 

temp6 = player0y-4 : temp6 = temp6/4 : temp6 = temp6-1

...takes 26 cycles.

 

When bB works though a complex statement, it uses the registers (faster) instead of memory locations (slower) to hold the intermediate calculations.

 

There's not a faster way in bB, with the exception of assembly or simplifying the math, as demonstrated.

Thanks. That's good to know.

Link to comment
Share on other sites

You can always do something simple like that.

I don't know what you mean. For example, if it was temp6 = ((player0y-3)/4)-1 instead, you couldn't do what jwierer did. He lucked out because the number I was subtracting turned out to be 4, but at one time, the number was something else.

What I meant was that you can always break down something complex and make it simple for the 6502.

((player0y-3)/4)-1 is the same as:

 

rem divide ((a-b)/4) - 1
asm
lda temp1  ;Load any value 0-255 in A
sec        ;Set carry
sbc temp2  ;Subtract any value 0-255
lsr        ;Divide by 2
lsr        ;Divide by 4
clc        ;Clear carry
sbc #1     ;Subtract 1 from result
sta temp3  ;Store result
end

 

This is just a straight forward method, I am sure math tricks can be used to do the same in less cycles.

Link to comment
Share on other sites

I don't know what you mean. For example, if it was temp6 = ((player0y-3)/4)-1 instead, you couldn't do what jwierer did. He lucked out because the number I was subtracting turned out to be 4, but at one time, the number was something else.

 

temp6 = (player0y-7)/4

Link to comment
Share on other sites

I don't know what you mean. For example, if it was temp6 = ((player0y-3)/4)-1 instead, you couldn't do what jwierer did. He lucked out because the number I was subtracting turned out to be 4, but at one time, the number was something else.

 

temp6 = (player0y-7)/4

That's what I get for pulling a random number out of the air. Now try temp6 = ((player0y-6)/4)-1. I'll figure out how you do that magic trick sooner or later.

 

:D

Link to comment
Share on other sites

Its easy to see the answer when you write it as :-

 

temp6=((player0y-6)/4)-1

temp6=((player0y-6)/4)-(4/4)

temp6=(player0y-6-4)/4

temp6=(player0y-10)/4

Even after seeing where you guys were hiding the rabbit, it still looks like magic. Very weird, but cool. Thanks.

Link to comment
Share on other sites

Even after seeing where you guys were hiding the rabbit, it still looks like magic. Very weird, but cool. Thanks.

 

Not sure how to answer that.

 

My gut reaction is to say there's no magic to it.

 

But it is sort of magical or wonderous or at least fascintaing,

maybe that's the key to interest.

 

What it is is pretty mundane 7th grade algebra.

 

you wouldn't have any trouble learning it.

 

Boolean algebra has similar rules/properties

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...