Subversion Repositories HelenOS

Rev

Rev 3149 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3149 Rev 4342
1
/*
1
/*
2
 * Copyright (c) 2005 Jakub Vana
2
 * Copyright (c) 2005 Jakub Vana
3
 * Copyright (c) 2005 Jakub Jermar
3
 * Copyright (c) 2005 Jakub Jermar
4
 * All rights reserved.
4
 * All rights reserved.
5
 *
5
 *
6
 * Redistribution and use in source and binary forms, with or without
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions
7
 * modification, are permitted provided that the following conditions
8
 * are met:
8
 * are met:
9
 *
9
 *
10
 * - Redistributions of source code must retain the above copyright
10
 * - Redistributions of source code must retain the above copyright
11
 *   notice, this list of conditions and the following disclaimer.
11
 *   notice, this list of conditions and the following disclaimer.
12
 * - Redistributions in binary form must reproduce the above copyright
12
 * - Redistributions in binary form must reproduce the above copyright
13
 *   notice, this list of conditions and the following disclaimer in the
13
 *   notice, this list of conditions and the following disclaimer in the
14
 *   documentation and/or other materials provided with the distribution.
14
 *   documentation and/or other materials provided with the distribution.
15
 * - The name of the author may not be used to endorse or promote products
15
 * - The name of the author may not be used to endorse or promote products
16
 *   derived from this software without specific prior written permission.
16
 *   derived from this software without specific prior written permission.
17
 *
17
 *
18
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
 */
28
 */
29
 
29
 
30
#if (defined(ia32) || defined(amd64) || defined(ia64) || defined(ia32xen))
-
 
31
 
-
 
32
#include <print.h>
30
#include <print.h>
33
#include <debug.h>
31
#include <debug.h>
34
 
32
 
35
#include <test.h>
33
#include <test.h>
36
#include <atomic.h>
34
#include <atomic.h>
37
#include <proc/thread.h>
35
#include <proc/thread.h>
38
 
36
 
39
#include <arch.h>
37
#include <arch.h>
40
#include <arch/arch.h>
38
#include <arch/arch.h>
41
 
39
 
42
 
40
 
43
#define THREADS     150
41
#define THREADS     150
44
#define ATTEMPTS    100
42
#define ATTEMPTS    100
45
 
43
 
46
#define E_10e8  271828182
44
#define E_10e8  271828182
47
#define PI_10e8 314159265
45
#define PI_10e8 314159265
48
 
46
 
49
 
47
 
50
#ifdef KERN_ia32_ARCH_H_
48
#ifdef KERN_ia32_ARCH_H_
51
static inline double sqrt(double x)
49
static inline double sqrt(double x)
52
{
50
{
53
    double v;
51
    double v;
54
   
52
   
55
    asm (
53
    asm (
56
        "fsqrt\n"
54
        "fsqrt\n"
57
        : "=t" (v)
55
        : "=t" (v)
58
        : "0" (x)
56
        : "0" (x)
59
    );
57
    );
60
   
58
   
61
    return v;
59
    return v;
62
}
60
}
63
#endif
61
#endif
64
 
62
 
65
#ifdef KERN_amd64_ARCH_H_
63
#ifdef KERN_amd64_ARCH_H_
66
static inline double sqrt(double x)
64
static inline double sqrt(double x)
67
{
65
{
68
    double v;
66
    double v;
69
   
67
   
70
    asm (
68
    asm (
71
        "fsqrt\n"
69
        "fsqrt\n"
72
        : "=t" (v)
70
        : "=t" (v)
73
        : "0" (x)
71
        : "0" (x)
74
    );
72
    );
75
   
73
   
76
    return v;
74
    return v;
77
}
75
}
78
#endif
76
#endif
79
 
77
 
80
#ifdef KERN_ia64_ARCH_H_
78
#ifdef KERN_ia64_ARCH_H_
81
 
79
 
82
#undef PI_10e8  
80
#undef PI_10e8  
83
#define PI_10e8 3141592
81
#define PI_10e8 3141592
84
 
82
 
85
static inline long double sqrt(long double a)
83
static inline long double sqrt(long double a)
86
{  
84
{  
87
    long double x = 1;
85
    long double x = 1;
88
    long double lx = 0;
86
    long double lx = 0;
89
 
87
 
90
    if (a < 0.00000000000000001)
88
    if (a < 0.00000000000000001)
91
        return 0;
89
        return 0;
92
       
90
       
93
    while(x != lx) {
91
    while(x != lx) {
94
        lx = x;
92
        lx = x;
95
        x = (x + (a / x)) / 2;
93
        x = (x + (a / x)) / 2;
96
    }
94
    }
97
   
95
   
98
    return x;
96
    return x;
99
}
97
}
100
#endif
98
#endif
101
 
99
 
102
 
100
 
103
static atomic_t threads_ok;
101
static atomic_t threads_ok;
104
static atomic_t threads_fault;
102
static atomic_t threads_fault;
105
static waitq_t can_start;
103
static waitq_t can_start;
106
static bool sh_quiet;
104
static bool sh_quiet;
107
 
105
 
108
static void e(void *data)
106
static void e(void *data)
109
{
107
{
110
    int i;
108
    int i;
111
    double e, d, le, f;
109
    double e, d, le, f;
112
 
110
 
113
    thread_detach(THREAD);
111
    thread_detach(THREAD);
114
 
112
 
115
    waitq_sleep(&can_start);
113
    waitq_sleep(&can_start);
116
 
114
 
117
    for (i = 0; i<ATTEMPTS; i++) {
115
    for (i = 0; i<ATTEMPTS; i++) {
118
        le = -1;
116
        le = -1;
119
        e = 0;
117
        e = 0;
120
        f = 1;
118
        f = 1;
121
 
119
 
122
        for (d = 1; e != le; d *= f, f += 1) {
120
        for (d = 1; e != le; d *= f, f += 1) {
123
            le = e;
121
            le = e;
124
            e = e + 1 / d;
122
            e = e + 1 / d;
125
        }
123
        }
126
 
124
 
127
        if ((int) (100000000 * e) != E_10e8) {
125
        if ((int) (100000000 * e) != E_10e8) {
128
            if (!sh_quiet)
126
            if (!sh_quiet)
129
                printf("tid%" PRIu64 ": e*10e8=%zd should be %" PRIun "\n", THREAD->tid, (unative_t) (100000000 * e), (unative_t) E_10e8);
127
                printf("tid%" PRIu64 ": e*10e8=%zd should be %" PRIun "\n", THREAD->tid, (unative_t) (100000000 * e), (unative_t) E_10e8);
130
            atomic_inc(&threads_fault);
128
            atomic_inc(&threads_fault);
131
            break;
129
            break;
132
        }
130
        }
133
    }
131
    }
134
    atomic_inc(&threads_ok);
132
    atomic_inc(&threads_ok);
135
}
133
}
136
 
134
 
137
static void pi(void *data)
135
static void pi(void *data)
138
{
136
{
139
    int i;
137
    int i;
140
    double lpi, pi;
138
    double lpi, pi;
141
    double n, ab, ad;
139
    double n, ab, ad;
142
   
140
   
143
    thread_detach(THREAD);
141
    thread_detach(THREAD);
144
 
142
 
145
    waitq_sleep(&can_start);
143
    waitq_sleep(&can_start);
146
 
144
 
147
    for (i = 0; i < ATTEMPTS; i++) {
145
    for (i = 0; i < ATTEMPTS; i++) {
148
        lpi = -1;
146
        lpi = -1;
149
        pi = 0;
147
        pi = 0;
150
 
148
 
151
        for (n = 2, ab = sqrt(2); lpi != pi; n *= 2, ab = ad) {
149
        for (n = 2, ab = sqrt(2); lpi != pi; n *= 2, ab = ad) {
152
            double sc, cd;
150
            double sc, cd;
153
 
151
 
154
            sc = sqrt(1 - (ab * ab / 4));
152
            sc = sqrt(1 - (ab * ab / 4));
155
            cd = 1 - sc;
153
            cd = 1 - sc;
156
            ad = sqrt(ab * ab / 4 + cd * cd);
154
            ad = sqrt(ab * ab / 4 + cd * cd);
157
            lpi = pi;
155
            lpi = pi;
158
            pi = 2 * n * ad;
156
            pi = 2 * n * ad;
159
        }
157
        }
160
 
158
 
161
#ifdef KERN_ia64_ARCH_H_
159
#ifdef KERN_ia64_ARCH_H_
162
        if ((int) (1000000 * pi) != PI_10e8) {
160
        if ((int) (1000000 * pi) != PI_10e8) {
163
            if (!sh_quiet)
161
            if (!sh_quiet)
164
                printf("tid%" PRIu64 ": pi*10e8=%zd should be %" PRIun "\n", THREAD->tid, (unative_t) (1000000 * pi), (unative_t) (PI_10e8 / 100));
162
                printf("tid%" PRIu64 ": pi*10e8=%zd should be %" PRIun "\n", THREAD->tid, (unative_t) (1000000 * pi), (unative_t) (PI_10e8 / 100));
165
            atomic_inc(&threads_fault);
163
            atomic_inc(&threads_fault);
166
            break;
164
            break;
167
        }
165
        }
168
#else
166
#else
169
        if ((int) (100000000 * pi) != PI_10e8) {
167
        if ((int) (100000000 * pi) != PI_10e8) {
170
            if (!sh_quiet)
168
            if (!sh_quiet)
171
                printf("tid%" PRIu64 ": pi*10e8=%zd should be %" PRIun "\n", THREAD->tid, (unative_t) (100000000 * pi), (unative_t) PI_10e8);
169
                printf("tid%" PRIu64 ": pi*10e8=%zd should be %" PRIun "\n", THREAD->tid, (unative_t) (100000000 * pi), (unative_t) PI_10e8);
172
            atomic_inc(&threads_fault);
170
            atomic_inc(&threads_fault);
173
            break;
171
            break;
174
        }
172
        }
175
#endif
173
#endif
176
    }
174
    }
177
    atomic_inc(&threads_ok);
175
    atomic_inc(&threads_ok);
178
}
176
}
179
 
177
 
180
char * test_fpu1(bool quiet)
178
char * test_fpu1(bool quiet)
181
{
179
{
182
    unsigned int i, total = 0;
180
    unsigned int i, total = 0;
183
    sh_quiet = quiet;
181
    sh_quiet = quiet;
184
 
182
 
185
    waitq_initialize(&can_start);
183
    waitq_initialize(&can_start);
186
    atomic_set(&threads_ok, 0);
184
    atomic_set(&threads_ok, 0);
187
    atomic_set(&threads_fault, 0);
185
    atomic_set(&threads_fault, 0);
188
   
186
   
189
    if (!quiet)
187
    if (!quiet)
190
        printf("Creating %u threads... ", 2 * THREADS);
188
        printf("Creating %u threads... ", 2 * THREADS);
191
 
189
 
192
    for (i = 0; i < THREADS; i++) {  
190
    for (i = 0; i < THREADS; i++) {  
193
        thread_t *t;
191
        thread_t *t;
194
       
192
       
195
        if (!(t = thread_create(e, NULL, TASK, 0, "e", false))) {
193
        if (!(t = thread_create(e, NULL, TASK, 0, "e", false))) {
196
            if (!quiet)
194
            if (!quiet)
197
                printf("could not create thread %u\n", 2 * i);
195
                printf("could not create thread %u\n", 2 * i);
198
            break;
196
            break;
199
        }
197
        }
200
        thread_ready(t);
198
        thread_ready(t);
201
        total++;
199
        total++;
202
       
200
       
203
        if (!(t = thread_create(pi, NULL, TASK, 0, "pi", false))) {
201
        if (!(t = thread_create(pi, NULL, TASK, 0, "pi", false))) {
204
            if (!quiet)
202
            if (!quiet)
205
                printf("could not create thread %u\n", 2 * i + 1);
203
                printf("could not create thread %u\n", 2 * i + 1);
206
            break;
204
            break;
207
        }
205
        }
208
        thread_ready(t);
206
        thread_ready(t);
209
        total++;
207
        total++;
210
    }
208
    }
211
   
209
   
212
    if (!quiet)
210
    if (!quiet)
213
        printf("ok\n");
211
        printf("ok\n");
214
   
212
   
215
    thread_sleep(1);
213
    thread_sleep(1);
216
    waitq_wakeup(&can_start, WAKEUP_ALL);
214
    waitq_wakeup(&can_start, WAKEUP_ALL);
217
   
215
   
218
    while (atomic_get(&threads_ok) != (long) total) {
216
    while (atomic_get(&threads_ok) != (long) total) {
219
        if (!quiet)
217
        if (!quiet)
220
            printf("Threads left: %d\n", total - atomic_get(&threads_ok));
218
            printf("Threads left: %d\n", total - atomic_get(&threads_ok));
221
        thread_sleep(1);
219
        thread_sleep(1);
222
    }
220
    }
223
   
221
   
224
    if (atomic_get(&threads_fault) == 0)
222
    if (atomic_get(&threads_fault) == 0)
225
        return NULL;
223
        return NULL;
226
   
224
   
227
    return "Test failed";
225
    return "Test failed";
228
}
226
}
229
 
-
 
230
#endif
-
 
231
 
227