FASTEST Ram clearing?
3 messages in this thread
Whats the bestest fastest way to clear a large block of memory in 68K? Its
larger than 64K (for sure). Do you guys (or gals/whatevers) think the
scheme using multipal registers set to zero and "saving" them on a register
(stack like) is the best? What are your ways? THANKS!
If you want to clear the mememory once when it's allocated the memory
allocator can be told to that. If you are wanting to clear the memory more
then once, then this is how I would do it. First I would make sure that
the amount of memory is evenly divisuble by four, by rounding up the # of
bytes you need to the next highest longword, and then clear by longwords.
;a0-pointer to top of memory to clear, longword aligned
;d0-# of bytes to clear, evenly divisible by 4
add.l a0,d0 ;address of longword to stop at
clr.l d1 loop1: move.l d1,(a0)+
cmp.l d0,a0
bne loop1
Jay,
The fastest technique I can think of for zeroing a large block of memory
would be the following code, where A0 is the start of the block:
movem.l d1-d7,a1-a6,-(a7) ; save as many registers as possible
(13)
; zero the registers d1-d7,a1-a6
add.l #size,a0 ; start at the top and work down
; I assume here that A0 will be even
move.l #(size/(4*13))-1,d0 loop movem.l d1-d7/a1-a6,-(a0) ; zero
4*13 = 52 bytes per loop
dbf d0,loop
movem.l (a7)+,d1-d7,a1-a6 ; restore the registers
Each loop clears 52 bytes and takes 148 cycles, so under 3 clock cycles
per byte. Compare this with 3 cycles per byte for MOVE.L D0,(A0)+ plus a
further 2.5 cycles per byte for looping. Of course, you have to deal
separately with the few bytes left over if the block size is not 52.
Personally, I would try to avoid clearing a large block of memory. Do you
_really_ need to clear this memory? Surely you will be writing something
else into it later, so why zero it now? How about using a flag to indicate
whether or not the memory contents are valid?
Regards,
Shraddhan – via Whap! from Hertfordshire in the UK