Stretch bit in word into longword
Here I am again stuck in very silly problems.
I'm trying to write a piece of code to transform a word into a longword by "stretching" the bits. For example: %1010110011010101 should become: %11001100111100001111001100110011 so every value repeated twice. But I have no idea how to proceed. Actually it's an exercise to learn manipulate data and I really need some help here. I tried by copying the data, then LSR by 1 bit and copy it again with a XOR but all I got was a big mess :banghead |
Probably an easier way to do it... but a five minute shot.
Code:
moveq #0,d0 mcgeezer |
This is faster and the number of processor cycles used are a constant:
Code:
move.w #%1010110011010101,d0 Yes, is ugly :) Probably with a LUT can be made much faster. |
makes sense and actually works, thanks!
|
Quote:
|
A simple trick to make it much faster on bare 68k:
Code:
move.w #%1010110011010101,d0 my previous one: 396 cycles this: 272 cycles** *of course only for this number of 1 bits **occhio allo swap ;) |
LUT version: 82 cycles :D
Code:
lea lut(pc),a0 |
Quote:
:) |
Slightly lower cycle count (-4):
Code:
... |
Quote:
Another little gain (-2): Code:
move.w #%1010110011010101,d0 |
Getting too old for this :(, should've noticed earlier. 2 cycles faster, so the same as yours, but without extra mem accesses.
Code:
... |
Quote:
Damn, that's why last night I dreamed of a lsr #7, but this morning I forgot it! :p |
Anyone shorter? :)
|
Quote:
|
Quote:
Code:
move.w #%1010110011010101,d0 |
Quote:
Thinks that a 512byte lut already seemed big to me... It would be interesting to calculate how many cycles it takes to fill the lut ;) |
Quote:
This is a rather typical example of code where we need to know what the program does and how badly it needs to be fast... |
The non-LUT code can be shortened and sped up quite a bit:
Code:
|
Another possibility is ye olde c2p merge trick (unverified, but it gives the idea) :
Code:
move.w d0,d1 |
All times are GMT +2. The time now is 14:04. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.