| |
Rudi Account closed
Registered: May 2010 Posts: 125 |
Questions about Basic-statements and logic
Hi,
//PW is DIM-table to {1,2,4,8,16,32,64,128}
210 B1 = PW(7-D0)
212 B2 = PW(R7)
214 B3 = PW(7-D1)
220 P1 = (PEEK(W+B) AND B1) / B1
222 P2 = (PEEK(W+A) AND B2) / B2
224 P3 = (PEEK(W+C) AND B3) / B3
I changed 220, 222 and 224 to:
220 P1 = (PEEK(W+B) AND B1)
222 P2 = (PEEK(W+A) AND B2)
224 P3 = (PEEK(W+C) AND B3)
and added the lines:
226 IF P1=B1 THEN P1=1
227 IF P2=B2 THEN P2=1
228 IF P3=B3 THEN P3=1
but it seems slower. IF..THEN slower than the divides. I guess Basic is doing alot of logic for this and waste more cycles. any ideas what to do to remove the divides?
I first thought of doing a lookup table, but that doesnt. In worst case I have to poke or read data statements of shift-opcodes, but are there any other ways?
Thanks. |
|
| |
Frantic
Registered: Mar 2003 Posts: 1648 |
Try assembler. :D |
| |
Mr. SID
Registered: Jan 2003 Posts: 424 |
What Frantic said... |
| |
TNT Account closed
Registered: Oct 2004 Posts: 189 |
If you're adamant using BASIC define two-dimensional array A(7,255) with each element containing either 0 or 1 depending on whether the wanted bit (first index) is set in given byte (second index).
That will reduce your logic into
P1 = A(X, PEEK(MEM))
where X is wanted bit, 0..7. |
| |
JackAsser
Registered: Jun 2002 Posts: 2014 |
Since you're optimising the cellular automata stuff (obviously) why do you need 0 or 1. Why not 0 or x?
A simple logical-or is then like p1+p2+p3 != 0
A simple logical-and would be p1+p2+p3 == 0
Or use asm... :D |
| |
Perplex
Registered: Feb 2009 Posts: 255 |
You should also use the % suffix on names of variables and arrays that are intended to hold integer values. This should speed up most operations quite a bit. |
| |
Oswald
Registered: Apr 2002 Posts: 5094 |
great chance to learn asm, the problem is both simple and interesting enough for it at the same time. |
| |
Mr. SID
Registered: Jan 2003 Posts: 424 |
I was under the impression that integer variables in BASIC 2.0 are slower than normal ones, because internally they're still represented as floats. Am I wrong? |
| |
WdW
Registered: Jun 2013 Posts: 13 |
yes, they are! so you're right. |
| |
Perplex
Registered: Feb 2009 Posts: 255 |
Really? Oh dear, disregard my suggestion then. Also, what Frantic said. :P |
| |
Tao
Registered: Aug 2002 Posts: 115 |
Quote: I was under the impression that integer variables in BASIC 2.0 are slower than normal ones, because internally they're still represented as floats. Am I wrong?
Seriously? I never knew. And here I've been trying to ensure that new code in C*Base used integers instead of floats o_O |
... 15 posts hidden. Click here to view all posts.... |
Previous - 1 | 2 | 3 - Next |