Add easier atomic api
This commit is contained in:
parent
fb72ab5c8d
commit
4d763680f6
2 changed files with 40 additions and 0 deletions
34
llvm/core.py
34
llvm/core.py
|
|
@ -2014,6 +2014,40 @@ class Builder(object):
|
|||
ordering.lower(), int(bool(crossthread)))
|
||||
return _make_value(inst)
|
||||
|
||||
def atomic_xchg(self, *args, **kwargs):
|
||||
return self.atomic_rmw('xchg', *args, **kwargs)
|
||||
|
||||
def atomic_add(self, *args, **kwargs):
|
||||
return self.atomic_rmw('add', *args, **kwargs)
|
||||
|
||||
def atomic_sub(self, *args, **kwargs):
|
||||
return self.atomic_rmw('sub', *args, **kwargs)
|
||||
|
||||
def atomic_and(self, *args, **kwargs):
|
||||
return self.atomic_rmw('and', *args, **kwargs)
|
||||
|
||||
def atomic_nand(self, *args, **kwargs):
|
||||
return self.atomic_rmw('nand', *args, **kwargs)
|
||||
|
||||
def atomic_or(self, *args, **kwargs):
|
||||
return self.atomic_rmw('or', *args, **kwargs)
|
||||
|
||||
def atomic_xor(self, *args, **kwargs):
|
||||
return self.atomic_rmw('xor', *args, **kwargs)
|
||||
|
||||
def atomic_max(self, *args, **kwargs):
|
||||
return self.atomic_rmw('max', *args, **kwargs)
|
||||
|
||||
def atomic_min(self, *args, **kwargs):
|
||||
return self.atomic_rmw('min', *args, **kwargs)
|
||||
|
||||
def atomic_umax(self, *args, **kwargs):
|
||||
return self.atomic_rmw('umax', *args, **kwargs)
|
||||
|
||||
def atomic_umin(self, *args, **kwargs):
|
||||
return self.atomic_rmw('umin', *args, **kwargs)
|
||||
|
||||
|
||||
#===----------------------------------------------------------------------===
|
||||
# Memory buffer
|
||||
#===----------------------------------------------------------------------===
|
||||
|
|
|
|||
|
|
@ -62,6 +62,7 @@ class TestAtomic(unittest.TestCase):
|
|||
inst = bldr.atomic_rmw('xchg', ptr, val, ordering)
|
||||
self.assertEqual(ordering, str(inst).split(' ')[-1])
|
||||
|
||||
|
||||
for op in test_these_atomic_op:
|
||||
inst = bldr.atomic_rmw(op, ptr, val, ordering)
|
||||
self.assertEqual(op, str(inst).strip().split(' ')[3])
|
||||
|
|
@ -70,5 +71,10 @@ class TestAtomic(unittest.TestCase):
|
|||
self.assertEqual('singlethread', str(inst).strip().split(' ')[-2])
|
||||
|
||||
|
||||
for op in test_these_atomic_op:
|
||||
atomic_op = getattr(bldr, 'atomic_%s' % op)
|
||||
inst = atomic_op(ptr, val, ordering)
|
||||
self.assertEqual(op, str(inst).strip().split(' ')[3])
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue