TweetFollow Us on Twitter

Aug 99 Tips

Volume Number: 15 (1999)
Issue Number: 8
Column Tag: Tips & Tidbits

Tips and Tidbits

by Jeff Clites, tips@mactech.com

Blistering Blitting

The June issue of MacTech highlighted some ways to move pixels around but there was no mention of a little-known PPC ASM instruction that can be used to speed pixel blitting (and all memory moving functions for that matter) called lmw/stmw.

When the data is aligned, it takes 4 cycles to execute a normal move memory. These two instructions are very powerful because they take 3 + n cycles to move n words. Hence each additional move only takes 1 cycle. This instruction works differently on different PPCs. The 601 treats these instruction like multiple lwa while the 603e, 604 and, G3 treat the instruction like a multimove.

There are a few restrictions on the following code:

  1. It works fastest when the baseAddrs are aligned.
  2. The code is for 8-bit pixels (tip: change r23 to 12 for 16 bit pixels and to 6 for 32 bit pixels).
  3. The width must be a multiple of 24 for 8 bit pixels (12 for 16 bit pixels, and 6 for 32 bit pixels). If it isn't there will be pixel overwriting. Most of the overwrite will be overwritten with the next scan line. You have been warned! (Any destination world should have a few more words in its baseAddr.)
  4. This assumes the same palette for the source and destination worlds (in 8-bit mode).
  5. This assumes the same depth for the source and destination worlds.

The following is an example of how to move pixels three times faster than the fastest method presented in Fast Blit Strategies.

export SpeedCopy[DS]
export .SpeedCopy[PR]
toc
	tc SpeedCopy[TC],	SpeedCopy[DS]	;TOC entry "SpeedCopy" for
																	;transition vector "SpeedCopy"
		csect	SpeedCopy[DS]			 		;Define transition vector "SpeedCopy"
		dc.l		.SpeedCopy[PR]	 				;Pointer to code
		dc.l		TOC[tc0]								;Pointer to TOC
		dc.l		0
# Prolog: SpeedCopy
;void SpeedCopy(long height, long width, long srcRowbytes,
;		unsigned long *dest, long destRowbytes,	unsigned long* src);
		csect	.SpeedCopy[PR]			;Prolog begins here
		;r3	= dest.height
		;r4	= dest.width
		;r5	= dest.rowbytes
		;r6	= dest.baseAddr
		;r7	= src.rowbytes
		;r8	= src.baseAddr
		stmw		r22,-36(SP)					;store temp register space
		li			r22, 1
		li			r23, 24
@lineLoop
		mr			r12,r4							;x = dest.width
		mr			r10,r6							;tmpdest = dest
		mr			r11,r8							;tmpsrc = src
@pixelLoop:
		lmw		r25,0(r11)					;Move 4 + 4 + 4 + 4 + 4 + 4 from 
														;tempSource to r25 thru r31
		subf.	r12,r23,r12					;Subtract num Pixels from total, test against 0
		addi		r11,r11,24					;Add pixel width to tempSource even for	
														;different size pixels
		stmw		r25,0(r10)					;Move pixels from r25 thru r31 to screen
		addi		r10,r10,24					;Add pixel width to dest even for different
														;size pixels
		bgt		@pixelLoop					;Loop if the subtraction is greater than 0
		subf.	r3, r22, r3				;Subtract one line from height, test against 0
		add		r8,r8,r7						;Add src.rowbytes to src.baseaddr
		add		r6,r6,r5						;Add dest.rowbytes to dest.baseaddr
		bne		@lineLoop					;Loop if height not equal to 0
		lmw		r22,-36(SP)					;Restore register space
		blr
end

With a few changes this code can pixel double, copy every other line, or both.

The best way to make a machine go faster is to make it do less. This is one of only a handful of cases where you can do more with less.

Brad Anderson anderson@rpmmusic.com

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

Combo Quest (Games)
Combo Quest 1.0 Device: iOS Universal Category: Games Price: $.99, Version: 1.0 (iTunes) Description: Combo Quest is an epic, time tap role-playing adventure. In this unique masterpiece, you are a knight on a heroic quest to retrieve... | Read more »
Hero Emblems (Games)
Hero Emblems 1.0 Device: iOS Universal Category: Games Price: $2.99, Version: 1.0 (iTunes) Description: ** 25% OFF for a limited time to celebrate the release ** ** Note for iPhone 6 user: If it doesn't run fullscreen on your device... | Read more »
Puzzle Blitz (Games)
Puzzle Blitz 1.0 Device: iOS Universal Category: Games Price: $1.99, Version: 1.0 (iTunes) Description: Puzzle Blitz is a frantic puzzle solving race against the clock! Solve as many puzzles as you can, before time runs out! You have... | Read more »
Sky Patrol (Games)
Sky Patrol 1.0.1 Device: iOS Universal Category: Games Price: $1.99, Version: 1.0.1 (iTunes) Description: 'Strategic Twist On The Classic Shooter Genre' - Indie Game Mag... | Read more »
The Princess Bride - The Official Game...
The Princess Bride - The Official Game 1.1 Device: iOS Universal Category: Games Price: $3.99, Version: 1.1 (iTunes) Description: An epic game based on the beloved classic movie? Inconceivable! Play the world of The Princess Bride... | Read more »
Frozen Synapse (Games)
Frozen Synapse 1.0 Device: iOS iPhone Category: Games Price: $2.99, Version: 1.0 (iTunes) Description: Frozen Synapse is a multi-award-winning tactical game. (Full cross-play with desktop and tablet versions) 9/10 Edge 9/10 Eurogamer... | Read more »
Space Marshals (Games)
Space Marshals 1.0.1 Device: iOS Universal Category: Games Price: $4.99, Version: 1.0.1 (iTunes) Description: ### IMPORTANT ### Please note that iPhone 4 is not supported. Space Marshals is a Sci-fi Wild West adventure taking place... | Read more »
Battle Slimes (Games)
Battle Slimes 1.0 Device: iOS Universal Category: Games Price: $1.99, Version: 1.0 (iTunes) Description: BATTLE SLIMES is a fun local multiplayer game. Control speedy & bouncy slime blobs as you compete with friends and family.... | Read more »
Spectrum - 3D Avenue (Games)
Spectrum - 3D Avenue 1.0 Device: iOS Universal Category: Games Price: $2.99, Version: 1.0 (iTunes) Description: "Spectrum is a pretty cool take on twitchy/reaction-based gameplay with enough complexity and style to stand out from the... | Read more »
Drop Wizard (Games)
Drop Wizard 1.0 Device: iOS Universal Category: Games Price: $1.99, Version: 1.0 (iTunes) Description: Bring back the joy of arcade games! Drop Wizard is an action arcade game where you play as Teo, a wizard on a quest to save his... | Read more »

Price Scanner via MacPrices.net

Apple’s M4 Mac minis on sale for record-low p...
B&H Photo has M4 and M4 Pro Mac minis in stock and on sale right now for up to $150 off Apple’s MSRP, each including free 1-2 day shipping to most US addresses. Prices start at only $469: – M4... Read more
Deal Alert! Mac Studio with M4 Max CPU on sal...
B&H Photo has the standard-configuration Mac Studio model with Apple’s M4 Max CPU in stock today and on sale for $300 off MSRP, now $1699 (10-Core CPU and 32GB RAM/512GB SSD). B&H also... Read more

Jobs Board

All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.