| 1 |
/* { dg-do run } */ |
| 2 |
/* { dg-require-effective-target sync_char_short } */ |
| 3 |
/* { dg-options } */ |
| 4 |
/* { dg-options "-march=i486" { target { { i?86-*-* x86_64-*-* } && ia32 } } } */ |
| 5 |
/* { dg-options "-mcpu=v9" { target sparc*-*-* } } */ |
| 6 |
|
| 7 |
/* Test basic functionality of the intrinsics. */ |
| 8 |
|
| 9 |
/* This is a copy of gcc.dg/ia64-sync-3.c, for 8-bit and 16-bit. */ |
| 10 |
|
| 11 |
__extension__ typedef __SIZE_TYPE__ size_t; |
| 12 |
|
| 13 |
extern void abort (void); |
| 14 |
extern void *memcpy (void *, const void *, size_t); |
| 15 |
extern int memcmp (const void *, const void *, size_t); |
| 16 |
|
| 17 |
static signed char AC[4]; |
| 18 |
static signed char init_qi[4] = { -30,-30,-50,-50 }; |
| 19 |
static signed char test_qi[4] = { -115,-115,25,25 }; |
| 20 |
|
| 21 |
static void |
| 22 |
do_qi (void) |
| 23 |
{ |
| 24 |
if (__sync_val_compare_and_swap(AC+0, -30, -115) != -30) |
| 25 |
abort (); |
| 26 |
if (__sync_val_compare_and_swap(AC+0, -30, -115) != -115) |
| 27 |
abort (); |
| 28 |
if (__sync_bool_compare_and_swap(AC+1, -30, -115) != 1) |
| 29 |
abort (); |
| 30 |
if (__sync_bool_compare_and_swap(AC+1, -30, -115) != 0) |
| 31 |
abort (); |
| 32 |
|
| 33 |
if (__sync_val_compare_and_swap(AC+2, AC[2], 25) != -50) |
| 34 |
abort (); |
| 35 |
if (__sync_val_compare_and_swap(AC+2, AC[2], 25) != 25) |
| 36 |
abort (); |
| 37 |
if (__sync_bool_compare_and_swap(AC+3, AC[3], 25) != 1) |
| 38 |
abort (); |
| 39 |
if (__sync_bool_compare_and_swap(AC+3, AC[3], 25) != 1) |
| 40 |
abort (); |
| 41 |
} |
| 42 |
|
| 43 |
static short AS[4]; |
| 44 |
static short init_hi[4] = { -30,-30,-50,-50 }; |
| 45 |
static short test_hi[4] = { -115,-115,25,25 }; |
| 46 |
|
| 47 |
static void |
| 48 |
do_hi (void) |
| 49 |
{ |
| 50 |
if (__sync_val_compare_and_swap(AS+0, -30, -115) != -30) |
| 51 |
abort (); |
| 52 |
if (__sync_val_compare_and_swap(AS+0, -30, -115) != -115) |
| 53 |
abort (); |
| 54 |
if (__sync_bool_compare_and_swap(AS+1, -30, -115) != 1) |
| 55 |
abort (); |
| 56 |
if (__sync_bool_compare_and_swap(AS+1, -30, -115) != 0) |
| 57 |
abort (); |
| 58 |
|
| 59 |
if (__sync_val_compare_and_swap(AS+2, AS[2], 25) != -50) |
| 60 |
abort (); |
| 61 |
if (__sync_val_compare_and_swap(AS+2, AS[2], 25) != 25) |
| 62 |
abort (); |
| 63 |
if (__sync_bool_compare_and_swap(AS+3, AS[3], 25) != 1) |
| 64 |
abort (); |
| 65 |
if (__sync_bool_compare_and_swap(AS+3, AS[3], 25) != 1) |
| 66 |
abort (); |
| 67 |
} |
| 68 |
|
| 69 |
int main() |
| 70 |
{ |
| 71 |
memcpy(AC, init_qi, sizeof(init_qi)); |
| 72 |
memcpy(AS, init_hi, sizeof(init_hi)); |
| 73 |
|
| 74 |
do_qi (); |
| 75 |
do_hi (); |
| 76 |
|
| 77 |
if (memcmp (AC, test_qi, sizeof(test_qi))) |
| 78 |
abort (); |
| 79 |
if (memcmp (AS, test_hi, sizeof(test_hi))) |
| 80 |
abort (); |
| 81 |
|
| 82 |
return 0; |
| 83 |
} |