FreeBSD: add file descriptor tracking for _umtx_op
[valgrind.git] / none / tests / s390x / mvc.c
blob636234b579a3e55d52c2164893654471c84b7dd5
1 #include <stdio.h>
2 #include <assert.h>
3 #include <string.h>
5 char buffer[] = "0123456789abcdefXXXXX";
6 char target[] = "---------------------";
7 char overlap[]= "012345678901234567890";
8 char full[300];
10 int main(void)
12 int i;
14 /* Normal copy */
15 printf("------- Copy 17 bytes from BUFFER to TARGET\n");
16 printf("before: buffer = |%s|\n", buffer);
17 printf("before: target = |%s|\n", target);
18 asm volatile( "mvc 0(17,%0),0(%1)\n"
19 ::"a" (target),"a" (buffer): "memory");
20 printf("after: buffer = |%s|\n", buffer);
21 printf("after: target = |%s|\n", target);
22 printf("\n");
24 /* Destructive overlap #1 */
25 printf("------- Destructive overlap #1\n");
26 printf("before: |%s|\n", overlap);
27 asm volatile( "mvc 1(17,%0),0(%1)\n"
28 ::"a" (overlap),"a" (overlap): "memory");
29 printf("after: |%s|\n", overlap);
31 /* Destructive overlap #2 */
32 printf("------- Destructive overlap #2\n");
33 memset(target, '-', sizeof target - 1); // restore initial state
34 printf("before: target = |%s|\n", target);
35 asm volatile( "mvi 0(%0),'x'\n\t" // target[1] = 'x'
36 "mvc 1(2,%0),0(%0)\n\t" // target[2:3] = target[1]
37 :: "a" (target+1));
38 printf("after: target = |%s|\n", target);
40 /* Destructive overlap #3 */
41 printf("------- Destructive overlap #3 (max length)\n");
42 memset(full, '-', sizeof full);
43 full[0] = 'x';
44 asm volatile( "mvc 1(256,%0),0(%0)\n\t" // full[1:256] = full[0]
45 :: "a" (full));
46 /* Verify: the first 256+1 characters should be 'x' followed by '-' */
47 for (i = 0; i <= 256; ++i)
48 assert(full[i] == 'x');
49 for ( ; i < sizeof full; ++i)
50 assert(full[i] == '-');
51 printf("\n");
53 /* Non-destructive overlap */
54 printf("------- Non-destructive overlap buf[0:4] = buf[10:14]\n");
55 char buf[] = "0123456789abcde";
56 printf("before: buf = |%s|\n", buf);
57 asm volatile( "mvc 0(5,%0),10(%1)\n"
58 ::"a" (buf),"a" (buf): "memory");
59 printf("after: buf = |%s|\n", buf);
60 printf("\n");
62 /* Move inverse (mvcin) */
63 printf("------- Move inverse 17 bytes from BUFFER to TARGET\n");
64 printf("before: target = |%s|\n", target);
65 asm volatile( "mvcin 0(17,%0),0(%1)\n"
66 ::"a" (target),"a" (buffer + 16): "memory");
67 printf("after: target = |%s|\n", target);
68 return 0;