• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: inline assembly
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: inline assembly


  • Subject: Re: inline assembly
  • From: Shaun Wexler <email@hidden>
  • Date: Wed, 25 Feb 2004 02:07:05 -0800

On Feb 25, 2004, at 12:04 AM, Andrew Pinski wrote:

Try this instead (aka do not use inline-asm except when needed, also you
should not be calling extern functions from within inline-asm at all, it
messes up GCC optimizations):

Thanks Andrew. Already tonight before you posted your reply, I'd removed all those ugly asm blocks and rewrote my whole shebang as inline asm functions, and it really cleaned things up a lot. I eschewed the sched_yield() call in favor of SYSCALL_THREAD_SWITCH. Methinks this will work just fine...


Here's what I've written for high-performance locking:

typedef volatile int SKWAtomicLock __attribute__ ((aligned (4)));

inline asm int SKWTryLockAtomic(SKWAtomicLock *lock)
{
		lwzx		r0, 0, lock
		cmpwi   	r0, 0
		bne-		locked
		li      	r3, 1
	acquire:
		lwarx   	r0, 0, lock
		cmpwi   	r0, 0
		bne-    	fail
  		stwcx.  	r3, 0, lock
  		bne-    	acquire
  		isync
  		b       	success
	fail:
		stwcx.  	r0, 0, lock
	locked:
		li      	r3, 0
	success:
}

inline asm void SKWLockAtomic(SKWAtomicLock *lock)
{
	trylock:
		lwarx   	r0, 0, lock
		cmpwi   	r0, 0
		beq+    	acquire
		stwcx.  	r0, 0, lock
		li		r3, 0
		li		r4, 1
		li		r5, 1
		li		r0, -61
		sc
		b		trylock
	acquire:
		li      	r0, 1
		stwcx. 	r0, 0, lock
		bne-    	trylock
		isync
}

inline asm void SKWUnlockAtomic(SKWAtomicLock *lock)
{
		sync
		li		r0, 0
		stwx		r0, 0, lock
}

I'm finishing up a nice set of various atomic functions, to throw into my goodie box. Profiling proved that all of the hot spots in MacFOH were fairly far down in system libs. Due to an ongoing DTS incident, I had to (temporarily?) skirt around the CGS to achieve refresh sync-lock for single-buffered windowed OpenGL contexts, and happen to uncover some pretty useful IOKit API's which I always assumed were SPI's. My live-resizing of windows is now so fast that the grow box stays glued to the cursor, even when spanning multiple large mon's. More importantly, audio & MIDI threading is unaffected by GLDriver et al. :)
--
Shaun Wexler
MacFOH
http://www.macfoh.com
_______________________________________________
xcode-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/xcode-users
Do not post admin requests to the list. They will be ignored.



References: 
 >inline assembly (From: Shaun Wexler <email@hidden>)
 >Re: inline assembly (From: Andrew Pinski <email@hidden>)

  • Prev by Date: Re: Application runs in xcode but not on its own
  • Next by Date: Handy tip for separate build location
  • Previous by thread: Re: inline assembly
  • Next by thread: Linking against libcrypto under 10.3 and having app work under 10.2
  • Index(es):
    • Date
    • Thread