| 1 |
/* { dg-do run } */ |
| 2 |
/* { dg-require-effective-target sync_int_long } */ |
| 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 |
__extension__ typedef __SIZE_TYPE__ size_t; |
| 10 |
|
| 11 |
extern void abort (void); |
| 12 |
extern void *memcpy (void *, const void *, size_t); |
| 13 |
extern int memcmp (const void *, const void *, size_t); |
| 14 |
|
| 15 |
static int AI[4]; |
| 16 |
static int init_si[4] = { -30,-30,-50,-50 }; |
| 17 |
static int test_si[4] = { -115,-115,25,25 }; |
| 18 |
|
| 19 |
static void |
| 20 |
do_si (void) |
| 21 |
{ |
| 22 |
if (__sync_val_compare_and_swap(AI+0, -30, -115) != -30) |
| 23 |
abort (); |
| 24 |
if (__sync_val_compare_and_swap(AI+0, -30, -115) != -115) |
| 25 |
abort (); |
| 26 |
if (__sync_bool_compare_and_swap(AI+1, -30, -115) != 1) |
| 27 |
abort (); |
| 28 |
if (__sync_bool_compare_and_swap(AI+1, -30, -115) != 0) |
| 29 |
abort (); |
| 30 |
|
| 31 |
if (__sync_val_compare_and_swap(AI+2, AI[2], 25) != -50) |
| 32 |
abort (); |
| 33 |
if (__sync_val_compare_and_swap(AI+2, AI[2], 25) != 25) |
| 34 |
abort (); |
| 35 |
if (__sync_bool_compare_and_swap(AI+3, AI[3], 25) != 1) |
| 36 |
abort (); |
| 37 |
if (__sync_bool_compare_and_swap(AI+3, AI[3], 25) != 1) |
| 38 |
abort (); |
| 39 |
} |
| 40 |
|
| 41 |
static long AL[4]; |
| 42 |
static long init_di[4] = { -30,-30,-50,-50 }; |
| 43 |
static long test_di[4] = { -115,-115,25,25 }; |
| 44 |
|
| 45 |
static void |
| 46 |
do_di (void) |
| 47 |
{ |
| 48 |
if (__sync_val_compare_and_swap(AL+0, -30, -115) != -30) |
| 49 |
abort (); |
| 50 |
if (__sync_val_compare_and_swap(AL+0, -30, -115) != -115) |
| 51 |
abort (); |
| 52 |
if (__sync_bool_compare_and_swap(AL+1, -30, -115) != 1) |
| 53 |
abort (); |
| 54 |
if (__sync_bool_compare_and_swap(AL+1, -30, -115) != 0) |
| 55 |
abort (); |
| 56 |
|
| 57 |
if (__sync_val_compare_and_swap(AL+2, AL[2], 25) != -50) |
| 58 |
abort (); |
| 59 |
if (__sync_val_compare_and_swap(AL+2, AL[2], 25) != 25) |
| 60 |
abort (); |
| 61 |
if (__sync_bool_compare_and_swap(AL+3, AL[3], 25) != 1) |
| 62 |
abort (); |
| 63 |
if (__sync_bool_compare_and_swap(AL+3, AL[3], 25) != 1) |
| 64 |
abort (); |
| 65 |
} |
| 66 |
|
| 67 |
int main() |
| 68 |
{ |
| 69 |
memcpy(AI, init_si, sizeof(init_si)); |
| 70 |
memcpy(AL, init_di, sizeof(init_di)); |
| 71 |
|
| 72 |
do_si (); |
| 73 |
do_di (); |
| 74 |
|
| 75 |
if (memcmp (AI, test_si, sizeof(test_si))) |
| 76 |
abort (); |
| 77 |
if (memcmp (AL, test_di, sizeof(test_di))) |
| 78 |
abort (); |
| 79 |
|
| 80 |
return 0; |
| 81 |
} |