13.07.2015 Views

Magazine - 1000 BiT

Magazine - 1000 BiT

Magazine - 1000 BiT

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

TEST-AND-SET implements the Alpha version of a test and set operation using//the Load-Locked .. store-conditional instructions. The purpose of this//function is to check the value pointed to by spinlock-address and, i f the//value is 0, set it to 1 and return success (1) in RO. If either the spinlock//value is already 1 or the store-conditional failed, the value of the spinlock//remains unchanged and a failure status (0,2, or 3) is returned in RO./ ///The status returned in RO is one of the following:// 0 failure (spinlock was clear; still clear, store-conditional failed)// 1 success (spinlock was clear; now set)// 2 - failure (spinlock was set; still set, store-conditional failed)// 3 - failure (spinlock was set; still set)/ /#define TEST-AND-SET (spinlock-address) asm( "Ldl-1 $0,($16);" o r $0,1,$1;"""st 1-c $1,($16); ""st1 $0,1,$0; ""or $0,$1,$0 ",(spinlock-address));// BASIC-SPINLOCK-ACQUIRE implements the simple case of acquiring a spinlock. I f// the spinlock is already owned or the store-conditional fails, this function// spins until the spinlock is acquired. This function doesn't return until the// spinlock is acquired./ /#define BASIC~SPINLOCK~ACQUIRE(spin1ock~address)C Long status = 0; \\while (1) \C \i f (*(spinlock-address) == 0) \C \status = TEST-AND-SET (spinlock-address); \i f (status == 1) \C \MB; \break; \\\\1Figure 1(:ode Scclucnccs for 1,ocl;ing Intrinsicsinstruction-caclic miss rntc OF 10 to 12 pcrcclir canct'fccti\~cl!~ stall the

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!