Add missing zstd.h to coregrind Makefile.am noinst_HEADERS
[valgrind.git] / memcheck / tests / amd64-solaris / context_sse.c
blobdb22f3e6ee0199f652fec752fcce1e66643c056d
1 /* Test if SSE valus are correctly propagated into and out of a signal handler
2 and also check that the same applies for uninitialised values and their
3 origins. */
5 #include <assert.h>
6 #include <signal.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <unistd.h>
10 #include <sys/syscall.h>
11 #include <ucontext.h>
13 #include "config.h"
15 static siginfo_t si;
16 static ucontext_t uc;
17 /* x0 is always zero, but is visible to Valgrind as uninitialised. */
18 static upad128_t x0;
19 static upad128_t d0 = {0};
21 static void sighandler(int sig, siginfo_t *sip, void *arg)
23 ucontext_t *ucp = (ucontext_t *) arg;
25 si = *sip;
26 uc = *ucp;
28 ucp->uc_mcontext.fpregs.fp_reg_set.fpchip_state.xmm[0] = d0;
29 ucp->uc_mcontext.fpregs.fp_reg_set.fpchip_state.xmm[1] = x0;
32 int main(void)
34 struct sigaction sa;
35 pid_t pid;
36 upad128_t out[8];
37 upad128_t y0;
39 #if defined(SOLARIS_FPCHIP_STATE_TAKES_UNDERSCORE)
40 struct _fpchip_state *fs;
41 #else
42 struct fpchip_state *fs;
43 #endif
44 fs = &uc.uc_mcontext.fpregs.fp_reg_set.fpchip_state;
46 /* Uninitialised, but we know px[0] is 0x0. */
47 upad128_t *px = malloc(sizeof(*px));
48 x0 = px[0];
50 /* Uninitialised, but we know py[0] is 0x0. */
51 upad128_t *py = malloc(sizeof(*py));
52 y0 = py[0];
54 sa.sa_sigaction = sighandler;
55 sa.sa_flags = SA_SIGINFO;
56 if (sigfillset(&sa.sa_mask)) {
57 perror("sigfillset");
58 return 1;
60 if (sigaction(SIGUSR1, &sa, NULL)) {
61 perror("sigaction");
62 return 1;
65 pid = getpid();
67 __asm__ __volatile__(
68 /* Set values in the SSE registers. */
69 "movups %[y0], %%xmm0\n"
70 "movups %[d0], %%xmm1\n"
71 "movups %[d0], %%xmm2\n"
72 "movups %[y0], %%xmm3\n"
73 "movups %[y0], %%xmm4\n"
74 "movups %[d0], %%xmm5\n"
75 "movups %[d0], %%xmm6\n"
76 "movups %[y0], %%xmm7\n"
78 /* Trigger the signal handler. */
79 "syscall\n"
80 "movups %%xmm0, 0x00 + %[out]\n"
81 "movups %%xmm1, 0x10 + %[out]\n"
82 "movups %%xmm2, 0x20 + %[out]\n"
83 "movups %%xmm3, 0x30 + %[out]\n"
84 "movups %%xmm4, 0x40 + %[out]\n"
85 "movups %%xmm5, 0x50 + %[out]\n"
86 "movups %%xmm6, 0x60 + %[out]\n"
87 "movups %%xmm7, 0x70 + %[out]\n"
88 : [out] "=m" (out[0])
89 : "a" (SYS_kill), "D" (pid), "S" (SIGUSR1), [y0] "m" (y0), [d0] "m" (d0)
90 : "rdx", "cc", "memory");
92 printf("Values in the signal handler:\n");
93 printf(" xmm1=%Lf, xmm2=%Lf, xmm5=%Lf, xmm6=%Lf\n",
94 fs->xmm[1]._q, fs->xmm[2]._q, fs->xmm[5]._q, fs->xmm[6]._q);
95 /* Check that fs->xmm[0], fs->xmm[3], fs->xmm[4] and fs->xmm[7] contain
96 uninitialised values (origin is py[0]). */
97 if (fs->xmm[0]._q || fs->xmm[3]._q || fs->xmm[4]._q || fs->xmm[7]._q)
98 assert(0);
100 printf("Values after the return from the signal handler:\n");
101 printf(" xmm0=%Lf, xmm2=%Lf, xmm5=%Lf, xmm6=%Lf\n",
102 out[0]._q, out[2]._q, out[5]._q, out[6]._q);
103 /* Check that out[1], out[3], out[4] and out[7] contain uninitialised
104 values (origin is px[0]). */
105 if (out[1]._q || out[3]._q || out[4]._q || out[7]._q)
106 assert(0);
108 return 0;