| |
Rudi Account closed
Registered: May 2010 Posts: 125 |
Fast way to rotate a char?
Im not talking about rol or ror, but swap bits so that they are rotated 90 degrees:
Example:
a char (and the bits can be random):
10110010 byte 1..
11010110 byte 2.. etc..
00111001
01010110
11011010
10110101
00110011
10110100 after "rotation" (rows and columns are swapped):
11001101
01011000
10100111
11111111
00101000
01010101
11011010
00100110 is it possible to use lookup tables for this or would that lookup table be too big?
or other lookuptable for getting and setting bits?
-Rudi |
|
... 105 posts hidden. Click here to view all posts.... |
| |
Krill
Registered: Apr 2002 Posts: 2980 |
While 8x8 tile transpose is an entertaining academic exercise, i'm dubious of its practical applications for C-64 purposes.
In fact, i'd be hard-pressed to find an effect that is rendered faster with generating "horizontal" 8x8 tiles first and then rotating them, as opposed to rendering "vertical" 8x8 tiles right away.
Also, an actual chunky to char approach seems more feasible. Render to linear chunky bitmap (1 byte per pixel), then collect the bits and render final 8x8 tiles. |
| |
Rudi Account closed
Registered: May 2010 Posts: 125 |
Krill: Bear in mind im not too an experienced coder on C64 that I see solutions right away. I figured out this might be an nice intellectual exercise for myself, hopefully for others too(?) but wether or not it has any practical usage, that I have no idea..
Btw, I have a working 336 cycles. It consists of twelve "copies" of this code (pseudocode):lda $<zp1>
tay
and #<mask1>
ldx $<zp2>
eor $<tab1>, x
sta $<zp3>
txa
and #<mask2>
eor $<tab2>, y
sta $<zp4> |
| |
Axis/Oxyron Account closed
Registered: Apr 2007 Posts: 91 |
Rudi, except of the fact that you used EOR instead of ORA and didnt use LAX for the first read on zp (would be possible if you swap x and y registers), this looks identical to the code I posted pretty early in this thread. Is there a special reason to use EOR? |
| |
Rudi Account closed
Registered: May 2010 Posts: 125 |
Quote: Rudi, except of the fact that you used EOR instead of ORA and didnt use LAX for the first read on zp (would be possible if you swap x and y registers), this looks identical to the code I posted pretty early in this thread. Is there a special reason to use EOR?
The eor was a consequence of the formulas i used for masking and swapping (I derived this from Kalms tutor):
Example for the 4x4 swapping:tmp0 = byte0 & 0xf0; //xxxx----
tmp1 = byte1 & 0xf0; //xxxx----
tmp2 = byte2 & 0xf0; //xxxx----
tmp3 = byte3 & 0xf0; //xxxx----
tmp4 = byte4 & 0x0f; //----xxxx
tmp5 = byte5 & 0x0f; //----xxxx
tmp6 = byte6 & 0x0f; //----xxxx
tmp7 = byte7 & 0x0f; //----xxxx
data0 = byte0 << 4;
data1 = byte1 << 4;
data2 = byte2 << 4;
data3 = byte3 << 4;
data4 = byte4 >> 4;
data5 = byte5 >> 4;
data6 = byte6 >> 4;
data7 = byte7 >> 4;
data0 ^= tmp4;
data1 ^= tmp5;
data2 ^= tmp6;
data3 ^= tmp7;
data4 ^= tmp0;
data5 ^= tmp1;
data6 ^= tmp2;
data7 ^= tmp3; Sorry for the long code..
EOR is used for the last xor-swapping. Since I cannot use lookup-table for two different values (fex. data0 and tmp4). The last eight operations in the above are done with the EOR-instruction.
Some of the lookup-tables i derived are doing EOR, AND and SHIFTS at the same time:shl2_eor_cc[i] = (i ^ (i & 0xcc)) << 2;
shr2_eor_33[i] = (i ^ (i & 0x33)) >> 2;
shl1_eor_aa[i] = (i ^ (i & 0xaa)) << 1;
shr1_eor_55[i] = (i ^ (i & 0x55)) >> 1; I scratched my head around how your ORA worked. And since I didnt understand that Dreamass-macrocode I wrote mine from scratch. But maybe I should look at your LAX-method next.
Edit: Now I see that it doesnt really matter if one use ora or eor for this technique. |
| |
Axis/Oxyron Account closed
Registered: Apr 2007 Posts: 91 |
But you know that:
(i ^ (i & 0xcc))
is the same as:
i & 0x33
;o) |
| |
Rudi Account closed
Registered: May 2010 Posts: 125 |
Quote: But you know that:
(i ^ (i & 0xcc))
is the same as:
i & 0x33
;o)
No, didnt think about that hehe.
Btw, 312 cycles now (with LAX). |
| |
Bitbreaker
Registered: Oct 2002 Posts: 508 |
Quoting Axis/OxyronBut you know that:
(i ^ (i & 0xcc))
is the same as:
i & 0x33
;o)
smells like the version of the tab that shifts only 1 bit to the right could be substituted by some asr magic?
Also the and maskX looks like it could be included into something, too static to be done that often :-) |
| |
Rudi Account closed
Registered: May 2010 Posts: 125 |
XAA might be something too. |
| |
Rudi Account closed
Registered: May 2010 Posts: 125 |
Here's a different approach to it:ldx $82 ;3
xaa #$33 ;2 a=(x & 0x33)
ldy $80 ;3
eor shl2_eor_cc, y ;4*
sta $90 ;3
lda shr2_eor_33, x ;4*
eor tab_cc, y ;4*
sta $92 ;3 uses the same amount of cycles though.
Bitbreaker: yes, one could probably optimize the 1x1 rotator with other illegal-opcodes. sine some of them do one shift. |
| |
Bitbreaker
Registered: Oct 2002 Posts: 508 |
Besides that it will produce rubbish as xaa can add some unpredictable value to A before doing the txa and and part :-) |
Previous - 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 - Next |