+Random Terrain Posted July 30, 2011 Share Posted July 30, 2011 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. Quote Link to comment Share on other sites More sharing options...
jwierer Posted July 30, 2011 Share Posted July 30, 2011 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 1 Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted July 30, 2011 Author Share Posted July 30, 2011 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? Quote Link to comment Share on other sites More sharing options...
ScumSoft Posted July 30, 2011 Share Posted July 30, 2011 (edited) 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 July 30, 2011 by ScumSoft Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted July 30, 2011 Author Share Posted July 30, 2011 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. Quote Link to comment Share on other sites More sharing options...
RevEng Posted July 30, 2011 Share Posted July 30, 2011 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. 1 Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted July 30, 2011 Author Share Posted July 30, 2011 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. Quote Link to comment Share on other sites More sharing options...
ScumSoft Posted July 30, 2011 Share Posted July 30, 2011 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. Quote Link to comment Share on other sites More sharing options...
bogax Posted August 1, 2011 Share Posted August 1, 2011 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 Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted August 1, 2011 Author Share Posted August 1, 2011 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. Quote Link to comment Share on other sites More sharing options...
GroovyBee Posted August 1, 2011 Share Posted August 1, 2011 temp6=(player0y-10)/4 Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted August 1, 2011 Author Share Posted August 1, 2011 temp6=(player0y-10)/4 Damn you math magicians! I'll never figure out your trick! Where do you keep the rabbit? You aren't wearing any sleeves! Quote Link to comment Share on other sites More sharing options...
GroovyBee Posted August 1, 2011 Share Posted August 1, 2011 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 Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted August 1, 2011 Author Share Posted August 1, 2011 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. Quote Link to comment Share on other sites More sharing options...
bogax Posted August 1, 2011 Share Posted August 1, 2011 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 Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted August 1, 2011 Author Share Posted August 1, 2011 I took algebra in 10th and 11th grade, but I forgot pretty much everything I learned. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.