68000 programming optimization tips? (for speed)

Ask anything your want about Megadrive/Genesis programming.

Moderator: BigEvilCorporation

GManiac
Very interested
Posts: 92
Joined: Thu Jan 29, 2009 2:05 am
Location: Russia

Re: 68000 programming optimization tips? (for speed)

Post by GManiac » Wed Apr 19, 2017 8:22 pm

By the way, a lot of people ignore Scc commands (ST, SF, Sxx), but they are pretty useful to calculate complex boolean expressions (with addition of NOT, AND, OR, EOR) rather than doing a massive branching.

User avatar
Sik
Very interested
Posts: 523
Joined: Thu Apr 10, 2008 3:03 pm
Contact:

Re: 68000 programming optimization tips? (for speed)

Post by Sik » Thu Apr 20, 2017 9:50 pm

Can confirm, once I was looking at the pathfinding code in Star Chaser and ran into a SHS instruction and was wondering what the heck was going on because of how uncommon it is. (pretty ironic since I wrote that code...)

These days I'm exploiting Scc a lot for quickly getting 0/1 values from a condition (Scc followed by AND). Or just outright 0/-1 (no AND) if I just want a boolean to be used later.
Sik is pronounced as "seek", not as "sick".

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

Re: 68000 programming optimization tips? (for speed)

Post by Natsumi » Fri Apr 21, 2017 10:53 am

also it can be very useful for something like this;

Code: Select all

.cloop		tst.b	(a1)+			; check if entry is null
		seq	d2			; if is, set d2 to $FF
		add.b	d2,d3			; and then subtract 1 from total count if so
		dbf	d1,.cloop		; loop til all cards are checked
Over branching conditionally, this actually saves 4 cycles per loop. Quite nifty optimization since this loop is ran many times over.

User avatar
Sik
Very interested
Posts: 523
Joined: Thu Apr 10, 2008 3:03 pm
Contact:

Re: 68000 programming optimization tips? (for speed)

Post by Sik » Sat Apr 22, 2017 12:35 am

Not to mention the part where you avoid an extra label just for the branch. The best kind of optimizations are those that also make the code look cleaner =O) (like using MOVEP instead of bit shifting for generating VDP commands for DMA)
Sik is pronounced as "seek", not as "sick".

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest