cons: disable dangerous conswrites()
[akaros.git] / tests / xmm.c
1 /* Copyright (c) 2014 The Regents of the University of California
2  * Kevin Klues <klueska@cs.berkeley.edu>
3  * See LICENSE for details.
4  *
5  * xmm_test: test the reading/writing of the xmm registers */
6
7 #include <stdio.h>
8 #include <pthread.h>
9 #include <stdlib.h>
10 #include <unistd.h>
11 #include <parlib/pvcalarm.h>
12
13 static void nothing() {}
14
15 static void read_xmm(int id)
16 {
17         char array[16*16] __attribute__((aligned(128))) = {0};
18         asm volatile (
19                 "movdqa %%xmm0,  %0;"
20                 "movdqa %%xmm1,  %1;"
21                 "movdqa %%xmm2,  %2;"
22                 "movdqa %%xmm3,  %3;"
23                 "movdqa %%xmm4,  %4;"
24                 "movdqa %%xmm5,  %5;"
25                 "movdqa %%xmm6,  %6;"
26                 "movdqa %%xmm7,  %7;"
27                 "movdqa %%xmm8,  %8;"
28                 "movdqa %%xmm9,  %9;"
29                 "movdqa %%xmm10, %10;"
30                 "movdqa %%xmm11, %11;"
31                 "movdqa %%xmm12, %12;"
32                 "movdqa %%xmm13, %13;"
33                 "movdqa %%xmm14, %14;"
34                 "movdqa %%xmm15, %15;"
35                 :"=m"(array[0*16]), 
36                  "=m"(array[1*16]), 
37                  "=m"(array[2*16]), 
38                  "=m"(array[3*16]), 
39                  "=m"(array[4*16]), 
40                  "=m"(array[5*16]), 
41                  "=m"(array[6*16]), 
42                  "=m"(array[7*16]), 
43                  "=m"(array[8*16]), 
44                  "=m"(array[9*16]), 
45                  "=m"(array[10*16]), 
46                  "=m"(array[11*16]), 
47                  "=m"(array[12*16]), 
48                  "=m"(array[13*16]), 
49                  "=m"(array[14*16]), 
50                  "=m"(array[15*16])
51                 :
52                 :
53         );
54         for (int i=0; i<16; i++) {
55                 int *addr = (int*)(array + i*16);
56                 if (*addr != id) {
57                         printf("ERROR: xmm%d, id: %d, *addr: %d\n",
58                                i, id, *addr);
59                         abort();
60                 }
61         }
62 }
63
64 static void write_xmm(int __id)
65 {
66         char id[16] __attribute__((aligned(128)));
67
68         *((int*)id) = __id;
69         asm volatile (
70                 "movdqa %0, %%xmm0;"
71                 "movdqa %0, %%xmm1;"
72                 "movdqa %0, %%xmm2;"
73                 "movdqa %0, %%xmm3;"
74                 "movdqa %0, %%xmm4;"
75                 "movdqa %0, %%xmm5;"
76                 "movdqa %0, %%xmm6;"
77                 "movdqa %0, %%xmm7;"
78                 "movdqa %0, %%xmm8;"
79                 "movdqa %0, %%xmm9;"
80                 "movdqa %0, %%xmm10;"
81                 "movdqa %0, %%xmm11;"
82                 "movdqa %0, %%xmm12;"
83                 "movdqa %0, %%xmm13;"
84                 "movdqa %0, %%xmm14;"
85                 "movdqa %0, %%xmm15;"
86                 :
87                 :"m"(id[0])
88                  :"%xmm0","%xmm1","%xmm2","%xmm3",
89                  "%xmm4","%xmm5","%xmm6","%xmm7",
90                  "%xmm8","%xmm9","%xmm10","%xmm11",
91                  "%xmm12","%xmm13","%xmm14","%xmm15"
92         );
93 }
94
95 void *worker_thread(void* arg)
96 {       
97         write_xmm((int)(long)arg);
98         while (1)
99                 read_xmm((int)(long)arg);
100         return 0;
101 }
102
103 int main(int argc, char** argv) 
104 {
105         #define NUM_THREADS     1000
106         pthread_t children[NUM_THREADS];
107
108         enable_pvcalarms(PVCALARM_REAL, 10000, nothing);
109         for (int i=0; i<NUM_THREADS; i++)
110                 pthread_create(&children[i], NULL, &worker_thread,
111                                (void*)(long)i + 2);
112         worker_thread((void*)(long)1);
113         return 0;
114
115