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