1
2
3
4
5
6
7
8
9
10
11
12#include <inttypes.h>
13#include <htmintrin.h>
14#include <string.h>
15#include <stdlib.h>
16#include <stdio.h>
17#include <pthread.h>
18#include <sys/mman.h>
19#include <unistd.h>
20
21#include "tm.h"
22#include "utils.h"
23
24int passed;
25
26void *worker(void *unused)
27{
28 __int128 vmx0;
29 uint64_t texasr;
30
31 asm goto (
32 "li 3, 1;"
33 "std 3, 0(%[vmx0_ptr]);"
34 "lvx 0, 0, %[vmx0_ptr];"
35
36
37 "lis 3, 0x3fff;"
38 "1: ;"
39 "addi 3, 3, -1;"
40 "cmpdi 3, 0;"
41 "bne 1b;"
42
43
44
45 "tbegin. ;"
46 "beq failure;"
47
48
49 "vaddcuw 0,0,0;"
50
51 "tend. ;"
52 "b %l[success];"
53
54
55 "failure: ;"
56 "lvx 1, 0, %[vmx0_ptr];"
57 "vcmpequb. 2, 0, 1;"
58 "bc 4, 24, %l[value_mismatch];"
59 "b %l[value_match];"
60 :
61 : [vmx0_ptr] "r"(&vmx0)
62 : "r3"
63 : success, value_match, value_mismatch
64 );
65
66
67value_mismatch:
68 texasr = __builtin_get_texasr();
69
70 printf("\n\n==============\n\n");
71 printf("Failure with error: %lx\n", _TEXASR_FAILURE_CODE(texasr));
72 printf("Summary error : %lx\n", _TEXASR_FAILURE_SUMMARY(texasr));
73 printf("TFIAR exact : %lx\n\n", _TEXASR_TFIAR_EXACT(texasr));
74
75 passed = 0;
76 return NULL;
77
78
79value_match:
80
81 return NULL;
82
83success:
84
85 return NULL;
86}
87
88int tm_vmx_unavail_test()
89{
90 int threads;
91 pthread_t *thread;
92
93 SKIP_IF(!have_htm());
94
95 passed = 1;
96
97 threads = sysconf(_SC_NPROCESSORS_ONLN) * 4;
98 thread = malloc(sizeof(pthread_t)*threads);
99 if (!thread)
100 return EXIT_FAILURE;
101
102 for (uint64_t i = 0; i < threads; i++)
103 pthread_create(&thread[i], NULL, &worker, NULL);
104
105 for (uint64_t i = 0; i < threads; i++)
106 pthread_join(thread[i], NULL);
107
108 free(thread);
109
110 return passed ? EXIT_SUCCESS : EXIT_FAILURE;
111}
112
113
114int main(int argc, char **argv)
115{
116 return test_harness(tm_vmx_unavail_test, "tm_vmx_unavail_test");
117}
118