Subversion Repositories HelenOS-historic

Rev

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

Rev 1020 Rev 1023
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
#include <print.h>
30
#include <print.h>
31
#include <debug.h>
31
#include <debug.h>
32
#include <panic.h>
32
#include <panic.h>
33
 
33
 
34
#include <test.h>
34
#include <test.h>
35
#include <arch/atomic.h>
35
#include <arch/atomic.h>
36
#include <proc/thread.h>
36
#include <proc/thread.h>
37
 
37
 
38
#include <arch.h>
38
#include <arch.h>
-
 
39
#include <arch/arch.h>
39
 
40
 
40
#define THREADS     150*2
41
#define THREADS     15*2
41
#define ATTEMPTS    100
42
#define ATTEMPTS    10
42
 
43
 
43
#define E_10e8  271828182
44
#define E_10e8  271828182
44
#define PI_10e8 314159265
45
#define PI_10e8 314159265
45
 
46
 
-
 
47
 
-
 
48
#ifdef __ia32_ARCH_H__
-
 
49
static inline double sqrt(double x) { double v; __asm__ ("fsqrt\n" : "=t" (v) : "0" (x)); return v; }
-
 
50
#endif
-
 
51
 
-
 
52
#ifdef __amd64_ARCH_H__
46
static inline double sqrt(double x) { double v; __asm__ ("fsqrt\n" : "=t" (v) : "0" (x)); return v; }
53
static inline double sqrt(double x) { double v; __asm__ ("fsqrt\n" : "=t" (v) : "0" (x)); return v; }
-
 
54
#endif
-
 
55
 
-
 
56
#ifdef __ia64_ARCH_H__
-
 
57
static inline long double sqrt(long double a)
-
 
58
{  
-
 
59
    long double x = 1;
-
 
60
    long double lx = 0;
-
 
61
 
-
 
62
    if(a<0.00000000000000001) return 0;
-
 
63
       
-
 
64
    while(x!=lx)
-
 
65
    {
-
 
66
        lx=x;
-
 
67
        x=(x+(a/x))/2;
-
 
68
    }
-
 
69
    return x;
-
 
70
}
-
 
71
#endif
-
 
72
 
-
 
73
 
47
 
74
 
48
static atomic_t threads_ok;
75
static atomic_t threads_ok;
49
static waitq_t can_start;
76
static waitq_t can_start;
50
 
77
 
51
static void e(void *data)
78
static void e(void *data)
52
{
79
{
53
    int i;
80
    int i;
54
    double e,d,le,f;
81
    double e,d,le,f;
55
 
82
 
56
    waitq_sleep(&can_start);
83
    waitq_sleep(&can_start);
57
 
84
 
58
    for (i = 0; i<ATTEMPTS; i++) {
85
    for (i = 0; i<ATTEMPTS; i++) {
59
        le=-1;
86
        le=-1;
60
        e=0;
87
        e=0;
61
        f=1;
88
        f=1;
62
 
89
 
63
        for(d=1;e!=le;d*=f,f+=1) {
90
        for(d=1;e!=le;d*=f,f+=1) {
64
            le=e;
91
            le=e;
65
            e=e+1/d;
92
            e=e+1/d;
66
        }
93
        }
67
 
94
 
68
        if((int)(100000000*e)!=E_10e8)
95
        if((int)(100000000*e)!=E_10e8)
69
            panic("tid%d: e*10e8=%d should be %d\n", THREAD->tid, (__native) (100000000*e),(__native) E_10e8);
96
            panic("tid%d: e*10e8=%d should be %d\n", THREAD->tid, (__native) (100000000*e),(__native) E_10e8);
70
    }
97
    }
71
 
98
 
72
    printf("tid%d: e*10e8=%d should be %d\n", THREAD->tid, (__native) (100000000*e),(__native) E_10e8);
99
    printf("tid%d: e*10e8=%d should be %d\n", THREAD->tid, (__native) (100000000*e),(__native) E_10e8);
73
    atomic_inc(&threads_ok);
100
    atomic_inc(&threads_ok);
74
}
101
}
75
 
102
 
76
static void pi(void *data)
103
static void pi(void *data)
77
{
104
{
-
 
105
 
-
 
106
#ifdef __ia64_ARCH_H__
-
 
107
#undef PI_10e8  
-
 
108
#define PI_10e8 3141592
-
 
109
#endif
-
 
110
 
78
    int i;
111
    int i;
79
    double lpi, pi;
112
    double lpi, pi;
80
    double n, ab, ad;
113
    double n, ab, ad;
81
 
114
 
82
    waitq_sleep(&can_start);
115
    waitq_sleep(&can_start);
83
 
116
 
84
 
117
 
85
    for (i = 0; i<ATTEMPTS; i++) {
118
    for (i = 0; i<ATTEMPTS; i++) {
86
        lpi = -1;
119
        lpi = -1;
87
        pi = 0;
120
        pi = 0;
88
 
121
 
89
        for (n=2, ab = sqrt(2); lpi != pi; n *= 2, ab = ad) {
122
        for (n=2, ab = sqrt(2); lpi != pi; n *= 2, ab = ad) {
90
            double sc, cd;
123
            double sc, cd;
91
 
124
 
92
            sc = sqrt(1 - (ab*ab/4));
125
            sc = sqrt(1 - (ab*ab/4));
93
            cd = 1 - sc;
126
            cd = 1 - sc;
94
            ad = sqrt(ab*ab/4 + cd*cd);
127
            ad = sqrt(ab*ab/4 + cd*cd);
95
            lpi = pi;
128
            lpi = pi;
96
            pi = 2 * n * ad;
129
            pi = 2 * n * ad;
97
        }
130
        }
98
 
131
 
-
 
132
#ifdef __ia64_ARCH_H__
-
 
133
        if((int)(1000000*pi)!=PI_10e8)
-
 
134
            panic("tid%d: pi*10e8=%d should be %d\n", THREAD->tid, (__native) (1000000*pi),(__native) (PI_10e8/100));
-
 
135
#else
99
        if((int)(100000000*pi)!=PI_10e8)
136
        if((int)(100000000*pi)!=PI_10e8)
100
            panic("tid%d: pi*10e8=%d should be %d\n", THREAD->tid, (__native) (100000000*pi),(__native) PI_10e8);
137
            panic("tid%d: pi*10e8=%d should be %d\n", THREAD->tid, (__native) (100000000*pi),(__native) PI_10e8);
-
 
138
#endif
-
 
139
 
101
    }
140
    }
102
 
141
 
103
    printf("tid%d: pi*10e8=%d should be %d\n", THREAD->tid, (__native) (100000000*pi),(__native) PI_10e8);
142
    printf("tid%d: pi*10e8=%d should be %d\n", THREAD->tid, (__native) (100000000*pi),(__native) PI_10e8);
104
    atomic_inc(&threads_ok);
143
    atomic_inc(&threads_ok);
105
}
144
}
106
 
145
 
107
 
146
 
108
void test(void)
147
void test(void)
109
{
148
{
110
    thread_t *t;
149
    thread_t *t;
111
    int i;
150
    int i;
112
 
151
 
113
    waitq_initialize(&can_start);
152
    waitq_initialize(&can_start);
114
 
153
 
115
    printf("FPU test #1\n");
154
    printf("FPU test #1\n");
116
    printf("Creating %d threads... ", THREADS);
155
    printf("Creating %d threads... ", THREADS);
117
 
156
 
118
    for (i=0; i<THREADS/2; i++) {  
157
    for (i=0; i<THREADS/2; i++) {  
119
        if (!(t = thread_create(e, NULL, TASK, 0)))
158
        if (!(t = thread_create(e, NULL, TASK, 0)))
120
            panic("could not create thread\n");
159
            panic("could not create thread\n");
121
        thread_ready(t);
160
        thread_ready(t);
122
        if (!(t = thread_create(pi, NULL, TASK, 0)))
161
        if (!(t = thread_create(pi, NULL, TASK, 0)))
123
            panic("could not create thread\n");
162
            panic("could not create thread\n");
124
        thread_ready(t);
163
        thread_ready(t);
125
    }
164
    }
126
    printf("ok\n");
165
    printf("ok\n");
127
   
166
   
128
    thread_sleep(1);
167
    thread_sleep(1);
129
    waitq_wakeup(&can_start, WAKEUP_ALL);
168
    waitq_wakeup(&can_start, WAKEUP_ALL);
130
 
169
 
131
    while (atomic_get(&threads_ok) != THREADS)
170
    while (atomic_get(&threads_ok) != THREADS)
132
        ;
171
        ;
133
       
172
       
134
    printf("Test passed.\n");
173
    printf("Test passed.\n");
135
}
174
}
-
 
175
 
-
 
176
/*
-
 
177
static void pi(void *data)
-
 
178
{
-
 
179
#undef PI_10e8 
-
 
180
#define PI_10e8 3141592
-
 
181
 
-
 
182
 
-
 
183
    int i;
-
 
184
    double lpi, pi;
-
 
185
    double n, ab, ad;
-
 
186
 
-
 
187
 
-
 
188
    printf("pi test\n");
-
 
189
 
-
 
190
    waitq_sleep(&can_start);
-
 
191
 
-
 
192
 
-
 
193
    for (i = 0; i<ATTEMPTS; i++) {
-
 
194
        lpi = -1;
-
 
195
        pi = 0;
-
 
196
 
-
 
197
        for (n=2, ab = sqrt(2); lpi != pi; n *= 2, ab = ad) {
-
 
198
            double sc, cd;
-
 
199
 
-
 
200
            sc = sqrt(1 - (ab*ab/4));
-
 
201
            cd = 1 - sc;
-
 
202
            ad = sqrt(ab*ab/4 + cd*cd);
-
 
203
            lpi = pi;
-
 
204
            pi = 2 * n * ad;
-
 
205
        }
-
 
206
 
-
 
207
        atomic_inc(&threads_ok);
-
 
208
        if((int)(1000000*pi)!=PI_10e8)
-
 
209
            panic("tid%d: pi*10e6=%d\n", THREAD->tid, (int) 1000000*pi);
-
 
210
    }
-
 
211
 
-
 
212
    printf("tid%d: pi*10e6=%d\n", THREAD->tid, (int) 1000000*pi);
-
 
213
}
-
 
214
*/
136
 
215