Add the rest of atomic op.
This commit is contained in:
parent
acad5c9d8b
commit
fb72ab5c8d
6 changed files with 159 additions and 33 deletions
|
|
@ -1,7 +1,7 @@
|
|||
from llvm.core import *
|
||||
import unittest
|
||||
|
||||
test_these_orderings = filter(bool, map(lambda s:s.strip(),
|
||||
test_these_orderings = list(filter(bool, map(lambda s:s.strip(),
|
||||
'''
|
||||
unordered
|
||||
monotonic
|
||||
|
|
@ -9,10 +9,25 @@ acquire
|
|||
release
|
||||
acq_rel
|
||||
seq_cst
|
||||
'''.splitlines()))
|
||||
'''.splitlines())))
|
||||
|
||||
test_these_atomic_op = list(filter(bool, map(lambda s:s.strip(),
|
||||
'''
|
||||
xchg
|
||||
add
|
||||
sub
|
||||
and
|
||||
nand
|
||||
or
|
||||
xor
|
||||
max
|
||||
min
|
||||
umax
|
||||
umin
|
||||
'''.splitlines())))
|
||||
|
||||
class TestAtomic(unittest.TestCase):
|
||||
def test_atomic(self):
|
||||
def test_atomic_cmpxchg(self):
|
||||
mod = Module.new('mod')
|
||||
functype = Type.function(Type.void(), [])
|
||||
func = mod.add_function(functype, name='foo')
|
||||
|
|
@ -26,11 +41,34 @@ class TestAtomic(unittest.TestCase):
|
|||
|
||||
for ordering in test_these_orderings:
|
||||
inst = bldr.atomic_cmpxchg(ptr, old, new, ordering)
|
||||
self.assertEqual(ordering, str(inst).split(' ')[-1])
|
||||
self.assertEqual(ordering, str(inst).strip().split(' ')[-1])
|
||||
|
||||
|
||||
inst = bldr.atomic_cmpxchg(ptr, old, new, ordering, crossthread=False)
|
||||
self.assertEqual('singlethread', str(inst).split(' ')[-2])
|
||||
self.assertEqual('singlethread', str(inst).strip().split(' ')[-2])
|
||||
|
||||
def test_atomic_rmw(self):
|
||||
mod = Module.new('mod')
|
||||
functype = Type.function(Type.void(), [])
|
||||
func = mod.add_function(functype, name='foo')
|
||||
bb = func.append_basic_block('entry')
|
||||
bldr = Builder.new(bb)
|
||||
ptr = bldr.alloca(Type.int())
|
||||
|
||||
old = bldr.load(ptr)
|
||||
val = Constant.int(Type.int(), 1234)
|
||||
|
||||
for ordering in test_these_orderings:
|
||||
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])
|
||||
|
||||
inst = bldr.atomic_rmw('xchg', ptr, val, ordering, crossthread=False)
|
||||
self.assertEqual('singlethread', str(inst).strip().split(' ')[-2])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue