Page 1 of 1

Fastest way to clear memory

Posted: Fri Nov 11, 2016 11:29 am
by cero
I'm not very familiar with 68k asm so far. What is the theoretical maximum speed you can zero memory at?

Using sgdk's memset, clearing 10kb to zero takes 70 scanlines, or 31% of a frame. The memsetU32 function takes exactly the same time.

Googling says there's a clr instruction, but it may be slower than mov, and movem should be used instead, but I don't really know.

Re: Fastest way to clear memory

Posted: Fri Nov 11, 2016 11:59 am
by BigEvilCorporation
Educated guesswork: clearing all regs and using movem would theoretically be the fastest method.

As usual, though, I get dubious about questions like this: why? I wrote a MemClear routine once, it gets called during init, never looked back.

Clearing VRAM is where it gets interesting. DMA fill/copy lets the 68k run alongside, I wonder if you could also manually write to the data port at the same time and "help out" by clearing a small chunk.

Re: Fastest way to clear memory

Posted: Fri Nov 11, 2016 3:29 pm
by cero
It'd be an acceleration structure that needs to be cleared at the start of every frame (to speed up projectile checks, so there's no combinatorial explosion enemies * projectiles).

Re: Fastest way to clear memory

Posted: Sat Nov 12, 2016 12:27 am
by Sik
That clearing is going to completely negate any advantage you get from it. 10KB is a lot for the 68000 to go through, even with the most optimal code.

Re: Fastest way to clear memory

Posted: Sat Nov 12, 2016 10:19 am
by cero
Can anyone give the theoretical max speed? I'd need to know how fast the most optimal code would be.

Re: Fastest way to clear memory

Posted: Sat Nov 12, 2016 4:52 pm
by Miquel
You can't go faster than 2 bytes for 4 cpu cycles. To that you have to add the reading of the instructions themselves.

With movem you can set up to 64 bytes for one instruction, is the fastest way, as said, but it needs to push/pop almost all registers.

Perhaps you can use a counter to know until which position information is valid.

Re: Fastest way to clear memory

Posted: Sat Nov 12, 2016 5:38 pm
by cero
Thanks, at 2 bytes per 4 cycles it'd take 42 lines, too much still.

Re: Fastest way to clear memory

Posted: Sat Nov 12, 2016 5:42 pm
by Natsumi
Having the clear a huge chunk of memory each frame is terrible design, and you need to redesign your system to not require that. Otherwise what you are doing is not feasible

Re: Fastest way to clear memory

Posted: Sat Nov 12, 2016 6:22 pm
by Sik
There's also the possibility of clearing only at the beginning and then each frame undraw all the positions that had been drawn. Basically a variant of dirty rectangles.