Fastest way to clear memory

Ask anything your want about Megadrive/Genesis programming.

Moderator: BigEvilCorporation

Post Reply
cero
Very interested
Posts: 338
Joined: Mon Nov 30, 2015 1:55 pm

Fastest way to clear memory

Post by cero » Fri Nov 11, 2016 11:29 am

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.

BigEvilCorporation
Very interested
Posts: 209
Joined: Sat Sep 08, 2012 10:41 am
Contact:

Re: Fastest way to clear memory

Post by BigEvilCorporation » Fri Nov 11, 2016 11:59 am

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.
A blog of my Megadrive programming adventures: http://www.bigevilcorporation.co.uk

cero
Very interested
Posts: 338
Joined: Mon Nov 30, 2015 1:55 pm

Re: Fastest way to clear memory

Post by cero » Fri Nov 11, 2016 3:29 pm

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).

Sik
Very interested
Posts: 939
Joined: Thu Apr 10, 2008 3:03 pm
Contact:

Re: Fastest way to clear memory

Post by Sik » Sat Nov 12, 2016 12:27 am

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.
Sik is pronounced as "seek", not as "sick".

cero
Very interested
Posts: 338
Joined: Mon Nov 30, 2015 1:55 pm

Re: Fastest way to clear memory

Post by cero » Sat Nov 12, 2016 10:19 am

Can anyone give the theoretical max speed? I'd need to know how fast the most optimal code would be.

Miquel
Very interested
Posts: 514
Joined: Sat Jul 30, 2016 12:33 am

Re: Fastest way to clear memory

Post by Miquel » Sat Nov 12, 2016 4:52 pm

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.
Last edited by Miquel on Wed Nov 16, 2016 2:48 pm, edited 1 time in total.
HELP. Spanish TVs are brain washing people to be hostile to me.

cero
Very interested
Posts: 338
Joined: Mon Nov 30, 2015 1:55 pm

Re: Fastest way to clear memory

Post by cero » Sat Nov 12, 2016 5:38 pm

Thanks, at 2 bytes per 4 cycles it'd take 42 lines, too much still.

Natsumi
Very interested
Posts: 82
Joined: Mon Oct 05, 2015 3:00 pm
Location: 0x0
Contact:

Re: Fastest way to clear memory

Post by Natsumi » Sat Nov 12, 2016 5:42 pm

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

Sik
Very interested
Posts: 939
Joined: Thu Apr 10, 2008 3:03 pm
Contact:

Re: Fastest way to clear memory

Post by Sik » Sat Nov 12, 2016 6:22 pm

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.
Sik is pronounced as "seek", not as "sick".

Post Reply