Subversion Repositories HelenOS-historic

Rev

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

Rev 827 Rev 1020
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
 
39
 
40
#define THREADS     150*2
40
#define THREADS     150*2
41
#define ATTEMPTS    100
41
#define ATTEMPTS    100
42
 
42
 
43
#define E_10e8  271828182
43
#define E_10e8  271828182
44
#define PI_10e8 314159265
44
#define PI_10e8 314159265
45
 
45
 
46
static inline double sqrt(double x) { double v; __asm__ ("fsqrt\n" : "=t" (v) : "0" (x)); return v; }
46
static inline double sqrt(double x) { double v; __asm__ ("fsqrt\n" : "=t" (v) : "0" (x)); return v; }
47
 
47
 
48
static atomic_t threads_ok;
48
static atomic_t threads_ok;
49
static waitq_t can_start;
49
static waitq_t can_start;
50
 
50
 
51
static void e(void *data)
51
static void e(void *data)
52
{
52
{
53
    int i;
53
    int i;
54
    double e,d,le,f;
54
    double e,d,le,f;
55
 
55
 
56
    waitq_sleep(&can_start);
56
    waitq_sleep(&can_start);
57
 
57
 
58
    for (i = 0; i<ATTEMPTS; i++) {
58
    for (i = 0; i<ATTEMPTS; i++) {
59
        le=-1;
59
        le=-1;
60
        e=0;
60
        e=0;
61
        f=1;
61
        f=1;
62
 
62
 
63
        for(d=1;e!=le;d*=f,f+=1) {
63
        for(d=1;e!=le;d*=f,f+=1) {
64
            le=e;
64
            le=e;
65
            e=e+1/d;
65
            e=e+1/d;
66
        }
66
        }
67
 
67
 
68
        if((int)(100000000*e)!=E_10e8)
68
        if((int)(100000000*e)!=E_10e8)
69
            panic("tid%d: e*10e8=%d\n", THREAD->tid, (int) 100000000*e);
69
            panic("tid%d: e*10e8=%d should be %d\n", THREAD->tid, (__native) (100000000*e),(__native) E_10e8);
70
    }
70
    }
71
 
71
 
-
 
72
    printf("tid%d: e*10e8=%d should be %d\n", THREAD->tid, (__native) (100000000*e),(__native) E_10e8);
72
    atomic_inc(&threads_ok);
73
    atomic_inc(&threads_ok);
73
}
74
}
74
 
75
 
75
static void pi(void *data)
76
static void pi(void *data)
76
{
77
{
77
    int i;
78
    int i;
78
    double lpi, pi;
79
    double lpi, pi;
79
    double n, ab, ad;
80
    double n, ab, ad;
80
 
81
 
81
    waitq_sleep(&can_start);
82
    waitq_sleep(&can_start);
82
 
83
 
83
 
84
 
84
    for (i = 0; i<ATTEMPTS; i++) {
85
    for (i = 0; i<ATTEMPTS; i++) {
85
        lpi = -1;
86
        lpi = -1;
86
        pi = 0;
87
        pi = 0;
87
 
88
 
88
        for (n=2, ab = sqrt(2); lpi != pi; n *= 2, ab = ad) {
89
        for (n=2, ab = sqrt(2); lpi != pi; n *= 2, ab = ad) {
89
            double sc, cd;
90
            double sc, cd;
90
 
91
 
91
            sc = sqrt(1 - (ab*ab/4));
92
            sc = sqrt(1 - (ab*ab/4));
92
            cd = 1 - sc;
93
            cd = 1 - sc;
93
            ad = sqrt(ab*ab/4 + cd*cd);
94
            ad = sqrt(ab*ab/4 + cd*cd);
94
            lpi = pi;
95
            lpi = pi;
95
            pi = 2 * n * ad;
96
            pi = 2 * n * ad;
96
        }
97
        }
97
 
98
 
98
        if((int)(100000000*pi)!=PI_10e8)
99
        if((int)(100000000*pi)!=PI_10e8)
99
            panic("tid%d: pi*10e8=%d\n", THREAD->tid, (int) 100000000*pi);
100
            panic("tid%d: pi*10e8=%d should be %d\n", THREAD->tid, (__native) (100000000*pi),(__native) PI_10e8);
100
    }
101
    }
101
 
102
 
-
 
103
    printf("tid%d: pi*10e8=%d should be %d\n", THREAD->tid, (__native) (100000000*pi),(__native) PI_10e8);
102
    atomic_inc(&threads_ok);
104
    atomic_inc(&threads_ok);
103
}
105
}
104
 
106
 
105
 
107
 
106
void test(void)
108
void test(void)
107
{
109
{
108
    thread_t *t;
110
    thread_t *t;
109
    int i;
111
    int i;
110
 
112
 
111
    waitq_initialize(&can_start);
113
    waitq_initialize(&can_start);
112
 
114
 
113
    printf("FPU test #1\n");
115
    printf("FPU test #1\n");
114
    printf("Creating %d threads... ", THREADS);
116
    printf("Creating %d threads... ", THREADS);
115
 
117
 
116
    for (i=0; i<THREADS/2; i++) {  
118
    for (i=0; i<THREADS/2; i++) {  
117
        if (!(t = thread_create(e, NULL, TASK, 0)))
119
        if (!(t = thread_create(e, NULL, TASK, 0)))
118
            panic("could not create thread\n");
120
            panic("could not create thread\n");
119
        thread_ready(t);
121
        thread_ready(t);
120
        if (!(t = thread_create(pi, NULL, TASK, 0)))
122
        if (!(t = thread_create(pi, NULL, TASK, 0)))
121
            panic("could not create thread\n");
123
            panic("could not create thread\n");
122
        thread_ready(t);
124
        thread_ready(t);
123
    }
125
    }
124
    printf("ok\n");
126
    printf("ok\n");
125
   
127
   
126
    thread_sleep(1);
128
    thread_sleep(1);
127
    waitq_wakeup(&can_start, WAKEUP_ALL);
129
    waitq_wakeup(&can_start, WAKEUP_ALL);
128
 
130
 
129
    while (atomic_get(&threads_ok) != THREADS)
131
    while (atomic_get(&threads_ok) != THREADS)
130
        ;
132
        ;
131
       
133
       
132
    printf("Test passed.\n");
134
    printf("Test passed.\n");
133
}
135
}
134
 
136