2
* Copyright (c) 2005 Ondrej Palkovsky
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
9
* - Redistributions of source code must retain the above copyright
10
* notice, this list of conditions and the following disclaimer.
11
* - Redistributions in binary form must reproduce the above copyright
12
* notice, this list of conditions and the following disclaimer in the
13
* documentation and/or other materials provided with the distribution.
14
* - The name of the author may not be used to endorse or promote products
15
* derived from this software without specific prior written permission.
17
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
#include <proc/thread.h>
35
#include <time/delay.h>
43
static atomic_t threads_ok;
44
static atomic_t threads_fault;
45
static waitq_t can_start;
47
static void testit1(void *data)
50
int arg __attribute__((aligned(16))) = (int) ((unative_t) data);
51
int after_arg __attribute__((aligned(16)));
53
thread_detach(THREAD);
55
waitq_sleep(&can_start);
57
for (i = 0; i < ATTEMPTS; i++) {
59
"movlpd %[arg], %%xmm2\n"
65
"movlpd %%xmm2, %[after_arg]\n"
66
: [after_arg] "=m" (after_arg)
69
if (arg != after_arg) {
70
TPRINTF("tid%" PRIu64 ": arg(%d) != %d\n", THREAD->tid, arg, after_arg);
71
atomic_inc(&threads_fault);
75
atomic_inc(&threads_ok);
78
static void testit2(void *data)
81
int arg __attribute__((aligned(16))) = (int) ((unative_t) data);
82
int after_arg __attribute__((aligned(16)));
84
thread_detach(THREAD);
86
waitq_sleep(&can_start);
88
for (i = 0; i < ATTEMPTS; i++) {
90
"movlpd %[arg], %%xmm2\n"
96
"movlpd %%xmm2, %[after_arg]\n"
97
: [after_arg] "=m" (after_arg)
100
if (arg != after_arg) {
101
TPRINTF("tid%" PRIu64 ": arg(%d) != %d\n", THREAD->tid, arg, after_arg);
102
atomic_inc(&threads_fault);
106
atomic_inc(&threads_ok);
109
char *test_sse1(void)
111
unsigned int i, total = 0;
113
waitq_initialize(&can_start);
114
atomic_set(&threads_ok, 0);
115
atomic_set(&threads_fault, 0);
117
TPRINTF("Creating %u threads... ", 2 * THREADS);
119
for (i = 0; i < THREADS; i++) {
122
if (!(t = thread_create(testit1, (void *) ((unative_t) 2 * i), TASK, 0, "testit1", false))) {
123
TPRINTF("could not create thread %u\n", 2 * i);
129
if (!(t = thread_create(testit2, (void *) ((unative_t) 2 * i + 1), TASK, 0, "testit2", false))) {
130
TPRINTF("could not create thread %u\n", 2 * i + 1);
140
waitq_wakeup(&can_start, WAKEUP_ALL);
142
while (atomic_get(&threads_ok) != (long) total) {
143
TPRINTF("Threads left: %d\n", total - atomic_get(&threads_ok));
147
if (atomic_get(&threads_fault) == 0)
150
return "Test failed";