0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024 #include <inttypes.h>
0025 #include <stdio.h>
0026 #include <stdlib.h>
0027 #include <unistd.h>
0028 #include <sys/mman.h>
0029 #include <string.h>
0030 #include <assert.h>
0031
0032 #include "tm.h"
0033 #include "utils.h"
0034
0035 int test_vmxcopy()
0036 {
0037 long double vecin = 1.3;
0038 long double vecout;
0039 unsigned long pgsize = getpagesize();
0040 int i;
0041 int fd;
0042 int size = pgsize*16;
0043 char tmpfile[] = "/tmp/page_faultXXXXXX";
0044 char buf[pgsize];
0045 char *a;
0046 uint64_t aborted = 0;
0047
0048 SKIP_IF(!have_htm());
0049 SKIP_IF(htm_is_synthetic());
0050 SKIP_IF(!is_ppc64le());
0051
0052 fd = mkstemp(tmpfile);
0053 assert(fd >= 0);
0054
0055 memset(buf, 0, pgsize);
0056 for (i = 0; i < size; i += pgsize)
0057 assert(write(fd, buf, pgsize) == pgsize);
0058
0059 unlink(tmpfile);
0060
0061 a = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
0062 assert(a != MAP_FAILED);
0063
0064 asm __volatile__(
0065 "lxvd2x 40,0,%[vecinptr];"
0066 "tbegin.;"
0067 "beq 3f;"
0068 "tsuspend.;"
0069 "xxlxor 40,40,40;"
0070 "std 5, 0(%[map]);"
0071 "tabort. 0;"
0072 "tresume.;"
0073 "tend.;"
0074 "li %[res], 0;"
0075 "b 5f;"
0076
0077
0078 "3:;"
0079 "li %[res], 1;"
0080
0081 "5:;"
0082 "stxvd2x 40,0,%[vecoutptr];"
0083 : [res]"=&r"(aborted)
0084 : [vecinptr]"r"(&vecin),
0085 [vecoutptr]"r"(&vecout),
0086 [map]"r"(a)
0087 : "memory", "r0", "r3", "r4", "r5", "r6", "r7");
0088
0089 if (aborted && (vecin != vecout)){
0090 printf("FAILED: vector state leaked on abort %f != %f\n",
0091 (double)vecin, (double)vecout);
0092 return 1;
0093 }
0094
0095 munmap(a, size);
0096
0097 close(fd);
0098
0099 return 0;
0100 }
0101
0102 int main(void)
0103 {
0104 return test_harness(test_vmxcopy, "tm_vmxcopy");
0105 }