1 /* Supply a set of generic atomic functions to test the compiler make the
2    calls properly.  */
3 /* { dg-do compile } */
4 /* { dg-options "-w" } */
5 
6 /* Test that the generic builtins make calls as expected.  This file provides
7    the exact entry points the test file will require.  All these routines
8    simply set the first parameter to 1, and the caller will test for that.  */
9 
10 #include <stdlib.h>
11 #include <stdbool.h>
12 #include <string.h>
13 
14 
15 char
__atomic_exchange_1(char * p,char t,int i)16 __atomic_exchange_1 (char *p, char t, int i)
17 {
18   *p = 1;
19 }
20 
21 short
__atomic_load_2(short * p,int i)22 __atomic_load_2 (short *p, int i)
23 {
24   *p = 1;
25 }
26 
27 void
__atomic_store_1(char * p,char v,int i)28 __atomic_store_1 (char *p, char v, int i)
29 {
30   *p = 1;
31 }
32 
__atomic_compare_exchange_2(short * p,short * a,short b,int y,int z)33 int __atomic_compare_exchange_2 (short *p, short *a, short b, int y, int z)
34 {
35   /* Fail if the memory models aren't correct as that will indicate the external
36      call has failed to remove the weak/strong parameter as required by the
37      library.  */
38   if (y != __ATOMIC_SEQ_CST || z != __ATOMIC_ACQUIRE)
39     *p = 0;
40   else
41     *p = 1;
42 }
43 
__atomic_fetch_add_1(char * p,char v,int i)44 char __atomic_fetch_add_1 (char *p, char v, int i)
45 {
46   *p = 1;
47 }
48 
__atomic_fetch_add_2(short * p,short v,int i)49 short __atomic_fetch_add_2 (short *p, short v, int i)
50 {
51   *p = 1;
52 }
53 
54 /* Really perform a NAND.  PR51040 showed incorrect calculation of a
55    non-inlined fetch_nand.  */
56 unsigned char
__atomic_fetch_nand_1(unsigned char * p,unsigned char v,int i)57 __atomic_fetch_nand_1 (unsigned char *p, unsigned char v, int i)
58 {
59   unsigned char ret;
60 
61   ret = *p;
62   *p = ~(*p & v);
63 
64   return ret;
65 }
66 
__atomic_is_lock_free(int i,void * p)67 int __atomic_is_lock_free (int i, void *p)
68 {
69   return 10;
70 }
71