Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 %s -emit-llvm -o - -triple=i686-apple-darwin9 > %t1 |
Daniel Dunbar | 4fcfde4 | 2009-11-08 01:45:36 +0000 | [diff] [blame] | 2 | // RUN: grep @llvm.atomic.load.add.i32 %t1 | count 3 |
| 3 | // RUN: grep @llvm.atomic.load.sub.i8 %t1 | count 2 |
| 4 | // RUN: grep @llvm.atomic.load.min.i32 %t1 |
| 5 | // RUN: grep @llvm.atomic.load.max.i32 %t1 |
| 6 | // RUN: grep @llvm.atomic.load.umin.i32 %t1 |
| 7 | // RUN: grep @llvm.atomic.load.umax.i32 %t1 |
| 8 | // RUN: grep @llvm.atomic.swap.i32 %t1 |
| 9 | // RUN: grep @llvm.atomic.cmp.swap.i32 %t1 | count 4 |
| 10 | // RUN: grep @llvm.atomic.load.and.i32 %t1 | count 2 |
| 11 | // RUN: grep @llvm.atomic.load.or.i8 %t1 |
Chris Lattner | 5caa370 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 12 | // RUN: grep @llvm.atomic.load.xor.i8 %t1 |
Mon P Wang | 1ffe281 | 2008-05-09 22:40:52 +0000 | [diff] [blame] | 13 | |
| 14 | |
| 15 | int atomic(void) |
| 16 | { |
Daniel Dunbar | eb4f81e | 2009-05-27 23:45:33 +0000 | [diff] [blame] | 17 | // non-sensical test for sync functions |
Mon P Wang | 1ffe281 | 2008-05-09 22:40:52 +0000 | [diff] [blame] | 18 | int old; |
| 19 | int val = 1; |
Chris Lattner | 5caa370 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 20 | char valc = 1; |
Mon P Wang | 1ffe281 | 2008-05-09 22:40:52 +0000 | [diff] [blame] | 21 | unsigned int uval = 1; |
| 22 | int cmp = 0; |
| 23 | |
| 24 | old = __sync_fetch_and_add(&val, 1); |
Chris Lattner | 5caa370 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 25 | old = __sync_fetch_and_sub(&valc, 2); |
Mon P Wang | 1ffe281 | 2008-05-09 22:40:52 +0000 | [diff] [blame] | 26 | old = __sync_fetch_and_min(&val, 3); |
| 27 | old = __sync_fetch_and_max(&val, 4); |
| 28 | old = __sync_fetch_and_umin(&uval, 5u); |
| 29 | old = __sync_fetch_and_umax(&uval, 6u); |
| 30 | old = __sync_lock_test_and_set(&val, 7); |
| 31 | old = __sync_val_compare_and_swap(&val, 4, 1976); |
Daniel Dunbar | 0002d23 | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 32 | old = __sync_bool_compare_and_swap(&val, 4, 1976); |
Mon P Wang | 1ffe281 | 2008-05-09 22:40:52 +0000 | [diff] [blame] | 33 | old = __sync_fetch_and_and(&val, 0x9); |
| 34 | old = __sync_fetch_and_or(&val, 0xa); |
| 35 | old = __sync_fetch_and_xor(&val, 0xb); |
Chris Lattner | f58cd9b | 2009-05-13 04:46:13 +0000 | [diff] [blame] | 36 | old = __sync_fetch_and_nand(&val, 0xb); |
Daniel Dunbar | 0002d23 | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 37 | |
| 38 | old = __sync_add_and_fetch(&val, 1); |
| 39 | old = __sync_sub_and_fetch(&val, 2); |
Chris Lattner | 5caa370 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 40 | old = __sync_and_and_fetch(&valc, 3); |
| 41 | old = __sync_or_and_fetch(&valc, 4); |
| 42 | old = __sync_xor_and_fetch(&valc, 5); |
Chris Lattner | f58cd9b | 2009-05-13 04:46:13 +0000 | [diff] [blame] | 43 | old = __sync_nand_and_fetch(&valc, 5); |
Daniel Dunbar | 0002d23 | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 44 | |
Chris Lattner | e7ac0a9 | 2009-05-08 15:36:58 +0000 | [diff] [blame] | 45 | |
| 46 | __sync_val_compare_and_swap((void **)0, (void *)0, (void *)0); |
| 47 | |
Chris Lattner | f58cd9b | 2009-05-13 04:46:13 +0000 | [diff] [blame] | 48 | |
| 49 | __sync_lock_release(&val); |
| 50 | __sync_synchronize (); |
| 51 | |
Mon P Wang | 1ffe281 | 2008-05-09 22:40:52 +0000 | [diff] [blame] | 52 | return old; |
| 53 | } |