2018-06-09 Steven G. Kargl <kargl@gcc.gnu.org>
[official-gcc.git] / libgomp / testsuite / libgomp.hsa.c / memory-operations-1.c
bloba17be932111a74d459015d85da5a358a0d645245
1 #include <assert.h>
3 #define C 55
5 int i, j, k;
7 static void
8 test_bzero (unsigned size)
10 unsigned bsize = size * sizeof (int);
11 int *x = __builtin_malloc (bsize);
12 __builtin_memset (x, C, bsize);
14 #pragma omp target map(tofrom: x[:size]) map(from: bsize)
16 __builtin_bzero (x, bsize);
19 char *buffer = (char *) x;
20 for (unsigned i = 0; i < bsize; ++i)
21 assert (buffer[i] == 0);
24 static void
25 test_memcpy (unsigned size)
27 unsigned bsize = size * sizeof (int);
28 int *x = __builtin_malloc (bsize);
29 __builtin_memset (x, C, bsize);
30 int *y = __builtin_malloc (bsize);
32 #pragma omp target map(tofrom: x[:size], y[:size]) map(from: bsize)
34 __builtin_memcpy (y, x, bsize);
37 char *buffer = (char *) y;
38 for (unsigned i = 0; i < bsize; ++i)
39 assert (buffer[i] == C);
42 static void
43 test_mempcpy (unsigned size)
45 unsigned bsize = size * sizeof (int);
46 int *x = __builtin_malloc (bsize);
47 __builtin_memset (x, C, bsize);
48 int *y = __builtin_malloc (bsize);
49 int *ptr = 0;
51 #pragma omp target map(tofrom :x[:size], y[:size], ptr) map(from: bsize)
53 ptr = __builtin_mempcpy (y, x, bsize);
56 char *buffer = (char *) y;
57 for (unsigned i = 0; i < bsize; ++i)
58 assert (buffer[i] == C);
60 assert (ptr == y + size);
63 static void
64 test_memset (unsigned size)
66 unsigned bsize = size * sizeof (int);
67 int *x = __builtin_malloc (bsize);
68 __builtin_bzero (x, bsize);
70 #pragma omp target map(tofrom : x[:size]) map(from: bsize)
72 __builtin_memset (x, C, bsize);
75 char *buffer = (char *) x;
76 for (unsigned i = 0; i < bsize; ++i)
77 assert (buffer[i] == C);
80 int
81 main (void)
83 unsigned tests[] = {1, 2, 3, 4, 5, 8, 15, 17, 23, 33, 0};
85 for (unsigned i = 0; tests[i]; i++)
87 test_bzero (tests[i]);
88 test_memset (tests[i]);
89 test_memcpy (tests[i]);
90 test_mempcpy (tests[i]);