Re: Byte swapping efficiently




"Karl E. Peterson" <karl@xxxxxxxx> wrote in message
news:OzysLyvbGHA.1272@xxxxxxxxxxxxxxxxxxxxxxx
Hi John --

it's shifted the bottleneck away from byte-swapping, which was the
hoped outcome - it's now the simple mechanics of processing 55MB of
data that's holding the app up, but performance is now acceptable.

Depending on the layout of the data, and in what order(s) you need
to access it, you may find it an advantage to map the entire thing
into your process's memory space and treat it as one honkin-huge
array. For an idea of what I'm talking about, take a look at how
quickly this -- http://vb.mvps.org/samples/MapFile -- can
encrypt/decrypt huge files.

If I understand you right, that's pretty much what I'm doing anyway.
Basically, the file's read in two-byte chunks, then (if it's in
Motorola format) a byte-swap, as discussed, is performed for each
chunk. Other than byte-swapping issues, it's pulled into a
two-dimensional array and all other processing done with the data
entirely in memory.

If you're reading the file two bytes at a time, you can increase the
processing speed by quite a number (10+?) orders of magnitude!

Question: Would it be advantageous to have the byte-swapped data stored in
the original file? IOW, overwritten on the original data? If so, and
(especially!) if the above is also true, I'm sure we could kick the crap
out
of your current timings.
--
Working without a .NET?
http://classicvb.org/


Or read the whole file into a byte or integer array and feed it to an
Assembly Language dll routine like one of these and bang, it's done.:

DllMain PROC STDCALL, handle:dword, dwReason:dword, dwReserved:dword
MOV EAX,1
RET
DllMain ENDP
;
;THIS PROCEDURE CONVERTS INT (BIG-ENDIAN) TO INT (LITTLE-ENDIEN)
;NSRC=SOURCE ADR. NDEST=DESTINATION ADR. NWORD=# OF WORDS
BIGLIT PROC STDCALL USES ESI EDI ECX EAX, NWORD:DWORD, NSRC:DWORD,
NDEST:DWORD
MOV ESI,NSRC
MOV EDI,NDEST
MOV ECX,NWORD
LP1: MOV AH,[ESI]
MOV AL,[ESI+1]
MOV [EDI],AX
ADD ESI,2
ADD EDI,2
LOOP LP1
RET
BIGLIT ENDP
;
;THIS PROCEDURE CONVERTS INT (LITTLE-ENDIEN) TO INT (BIG-ENDIAN
INTEGERS)
;NSRC=SOURCE ADR. NDEST=DESTINATION ADR. NWORD=# OF WORDS
LITBIG PROC STDCALL USES ESI EDI ECX EAX, NWORD:DWORD, NSRC:DWORD,
NDEST:DWORD
MOV ESI,NSRC
MOV EDI,NDEST
MOV ECX,NWORD
LP2: MOV AX,[ESI]
MOV [EDI],AH
MOV [EDI+1],AL
ADD ESI,2
ADD EDI,2
LOOP LP2
RET
LITBIG ENDP
;
;THIS PROCEDURE CONVERTS LITTLE-ENDIEN TO BIG-ENDIAN INTEGERS AND
VICE VERSA
;NSRC=SOURCE ADR. NDEST=DESTINATION ADR. NWORD=# OF BYTES
ENDSWP PROC STDCALL USES ESI EDI ECX EAX, NWORD:DWORD, NSRC:DWORD,
NDEST:DWORD
MOV ESI,NSRC
MOV EDI,NDEST
MOV ECX,NWORD
ADD EDI,ECX
DEC EDI ;LAST DEST BYTE
LP2: MOV AL,[ESI]
MOV [EDI],AL
ADD ESI,1
SUB EDI,1
LOOP LP2
RET
ENDSWP ENDP
;

GalenS


.



Relevant Pages