Subversion Repositories HelenOS-historic

Rev

Rev 1658 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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