parlib: UTH_EXT_BLK_JUSTICE -> _MISC
[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", i, id, *addr);
58                         abort();
59                 }
60         }
61 }
62
63 static void write_xmm(int __id)
64 {
65         char id[16] __attribute__((aligned(128)));
66         *((int*)id) = __id;
67         asm volatile (
68                 "movdqa %0, %%xmm0;"
69                 "movdqa %0, %%xmm1;"
70                 "movdqa %0, %%xmm2;"
71                 "movdqa %0, %%xmm3;"
72                 "movdqa %0, %%xmm4;"
73                 "movdqa %0, %%xmm5;"
74                 "movdqa %0, %%xmm6;"
75                 "movdqa %0, %%xmm7;"
76                 "movdqa %0, %%xmm8;"
77                 "movdqa %0, %%xmm9;"
78                 "movdqa %0, %%xmm10;"
79                 "movdqa %0, %%xmm11;"
80                 "movdqa %0, %%xmm12;"
81                 "movdqa %0, %%xmm13;"
82                 "movdqa %0, %%xmm14;"
83                 "movdqa %0, %%xmm15;"
84                 :
85                 :"m"(id[0])
86             :"%xmm0","%xmm1","%xmm2","%xmm3",
87                  "%xmm4","%xmm5","%xmm6","%xmm7",
88                  "%xmm8","%xmm9","%xmm10","%xmm11",
89                  "%xmm12","%xmm13","%xmm14","%xmm15"
90         );
91 }
92
93 void *worker_thread(void* arg)
94 {       
95         write_xmm((int)(long)arg);
96         while (1)
97                 read_xmm((int)(long)arg);
98         return 0;
99 }
100
101 int main(int argc, char** argv) 
102 {
103         #define NUM_THREADS     1000
104         pthread_t children[NUM_THREADS];
105
106         enable_pvcalarms(PVCALARM_REAL, 10000, nothing);
107         for (int i=0; i<NUM_THREADS; i++)
108                 pthread_create(&children[i], NULL, &worker_thread, (void*)(long)i+2);
109         worker_thread((void*)(long)1);
110         return 0;
111
112