1/* 2 * Copyright 2003-2009, Axel D�rfler, axeld@pinc-software.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 6#define FUNCTION(x) .global x; .type x,@function; x 7 8.text 9 10/* int atomic_add(int *value, int increment) 11 * (r3) r3 r4 12 */ 13FUNCTION(atomic_add): 14lost1: lwarx %r5, 0, %r3 // reserve memory address located in "r3" 15 add %r0, %r5, %r4 // (contents are stored in "r5") 16 stwcx. %r0, 0, %r3 17 bne- lost1 // try again if reservation was lost 18 mr %r3, %r5 // return old value (was in "r5") 19 blr 20 21/* int atomic_and(int *value, int andValue) 22 * (r3) r3 r4 23 */ 24FUNCTION(atomic_and): 25lost2: lwarx %r5, 0, %r3 26 and %r0, %r5, %r4 27 stwcx. %r0, 0, %r3 28 bne- lost2 29 mr %r3, %r5 30 blr 31 32/* int atomic_or(int *value, int orValue) 33 * (r3) r3 r4 34 */ 35FUNCTION(atomic_or): 36lost3: lwarx %r5, 0, %r3 37 or %r0, %r5, %r4 38 stwcx. %r0, 0, %r3 39 bne- lost3 40 mr %r3, %r5 41 blr 42 43/* int atomic_set(int *value, int setTo) 44 * (r3) r3 r4 45 */ 46FUNCTION(atomic_set): 47lost4: lwarx %r5, 0, %r3 48 stwcx. %r4, 0, %r3 49 bne- lost4 50 mr %r3, %r5 51 blr 52 53/* int atomic_test_and_set(int *value, int setTo, int testValue) 54 * (r3) r3 r4 r5 55 */ 56FUNCTION(atomic_test_and_set): 57lost5: lwarx %r6, 0, %r3 58 cmpw %r6, %r5 59 bne out5 60 stwcx. %r4, 0, %r3 61 bne- lost5 62out5: mr %r3, %r6 63 blr 64 65/* int atomic_get(int *value) 66 * (r3) r3 67 */ 68FUNCTION(atomic_get): 69lost6: lwarx %r5, 0, %r3 70 stwcx. %r5, 0, %r3 71 bne- lost6 72 mr %r3, %r5 73 blr 74