def _define_atomic_cas(module, ordering):
 ftype = ir.FunctionType(ir.IntType(32), [_word_type.as_pointer(), _word_type, _word_type, _word_type.as_pointer()])
 fn_cas = ir.Function(module, ftype, name='nrt_atomic_cas')
 [ptr, cmp, repl, oldptr] = fn_cas.args
 bb = fn_cas.append_basic_block()
 builder = ir.IRBuilder(bb)
 outtup = builder.cmpxchg(ptr, cmp, repl, ordering=ordering)
 (old, ok) = cgutils.unpack_tuple(builder, outtup, 2)
 builder.store(old, oldptr)
 builder.ret(builder.zext(ok, ftype.return_type))
 return fn_cas

def _define_atomic_cas ( module , ordering ) : ftype = ir . FunctionType ( ir . IntType ( 32 ) , [ _word_type . as_pointer ( ) , _word_type , _word_type , _word_type . as_pointer ( ) ] ) fn_cas = ir . Function ( module , ftype , name = 'nrt_atomic_cas' ) [ ptr , cmp , repl , oldptr ] = fn_cas . args bb = fn_cas . append_basic_block ( ) builder = ir . IRBuilder ( bb ) outtup = builder . cmpxchg ( ptr , cmp , repl , ordering = ordering ) ( old , ok ) = cgutils . unpack_tuple ( builder , outtup , 2 ) builder . store ( old , oldptr ) builder . ret ( builder . zext ( ok , ftype . return_type ) ) return fn_cas
define a llvm function for atomic compare-and-swap .