1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#include <inttypes.h>
25#include <stdio.h>
26#include <stdlib.h>
27#include <unistd.h>
28#include <sys/mman.h>
29#include <string.h>
30#include <assert.h>
31
32#include "tm.h"
33#include "utils.h"
34
35int test_vmxcopy()
36{
37 long double vecin = 1.3;
38 long double vecout;
39 unsigned long pgsize = getpagesize();
40 int i;
41 int fd;
42 int size = pgsize*16;
43 char tmpfile[] = "/tmp/page_faultXXXXXX";
44 char buf[pgsize];
45 char *a;
46 uint64_t aborted = 0;
47
48 SKIP_IF(!have_htm());
49 SKIP_IF(!is_ppc64le());
50
51 fd = mkstemp(tmpfile);
52 assert(fd >= 0);
53
54 memset(buf, 0, pgsize);
55 for (i = 0; i < size; i += pgsize)
56 assert(write(fd, buf, pgsize) == pgsize);
57
58 unlink(tmpfile);
59
60 a = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
61 assert(a != MAP_FAILED);
62
63 asm __volatile__(
64 "lxvd2x 40,0,%[vecinptr];"
65 "tbegin.;"
66 "beq 3f;"
67 "tsuspend.;"
68 "xxlxor 40,40,40;"
69 "std 5, 0(%[map]);"
70 "tabort. 0;"
71 "tresume.;"
72 "tend.;"
73 "li %[res], 0;"
74 "b 5f;"
75
76
77 "3:;"
78 "li %[res], 1;"
79
80 "5:;"
81 "stxvd2x 40,0,%[vecoutptr];"
82 : [res]"=r"(aborted)
83 : [vecinptr]"r"(&vecin),
84 [vecoutptr]"r"(&vecout),
85 [map]"r"(a)
86 : "memory", "r0", "r3", "r4", "r5", "r6", "r7");
87
88 if (aborted && (vecin != vecout)){
89 printf("FAILED: vector state leaked on abort %f != %f\n",
90 (double)vecin, (double)vecout);
91 return 1;
92 }
93
94 munmap(a, size);
95
96 close(fd);
97
98 return 0;
99}
100
101int main(void)
102{
103 return test_harness(test_vmxcopy, "tm_vmxcopy");
104}
105