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: 694
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: 81
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: 694
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".

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

Re: 68000 programming optimization tips? (for speed)

Post by Miquel » Mon Jul 09, 2018 5:43 am

Sik wrote:
Thu Apr 20, 2017 9:50 pm
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.
Or just do a: "neg.b" to get the appropriate value.

Hard to remember all those 68k tricks ;)

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

Re: 68000 programming optimization tips? (for speed)

Post by Sik » Mon Jul 09, 2018 7:35 am

The Scc instructions only come in byte size so if I want a word or long result I actually need to use AND if I want 1 instead of -1 (I mean, I could use EXT and NEG together, but it's not better and takes up more lines of code).

EDIT: also using AND you can get other values like 2 or 4. Convenient for offsets :v
Sik is pronounced as "seek", not as "sick".

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

Re: 68000 programming optimization tips? (for speed)

Post by Miquel » Wed Jul 11, 2018 9:40 am

You are right ;)

gasega68k
Very interested
Posts: 137
Joined: Thu Aug 22, 2013 3:47 am
Location: Venezuela - Caracas

Re: 68000 programming optimization tips? (for speed)

Post by gasega68k » Mon Aug 13, 2018 4:52 am

I don't know if this should be called programmig optimization or programming trick, but is someting that I did recently to quick save/restore X flag:

Code: Select all

    subx.b  d0,d0  ;set d0 to $ff if X is set, otherwise 0
then to restore X flag:

Code: Select all

    add.b  d0,d0
This can also work with subx.w, add.w, in this case d0 will be set to $ffff, or 0.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest