Rev 1882 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1882 | Rev 2020 | ||
---|---|---|---|
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 | #ifdef CONFIG_BENCH |
|
- | 42 | #include <arch/cycle.h> |
|
- | 43 | #endif |
|
- | 44 | ||
- | 45 | #if (defined(ia32) || defined(amd64) || defined(ia64) || defined(ia32xen)) |
|
- | 46 | ||
41 | #define THREADS 150*2 |
47 | #define THREADS 150*2 |
42 | #define ATTEMPTS 100 |
48 | #define ATTEMPTS 100 |
43 | 49 | ||
44 | #define E_10e8 271828182 |
50 | #define E_10e8 271828182 |
45 | #define PI_10e8 314159265 |
51 | #define PI_10e8 314159265 |
46 | 52 | ||
47 | 53 | ||
48 | #ifdef KERN_ia32_ARCH_H_ |
54 | #ifdef KERN_ia32_ARCH_H_ |
49 | static inline double sqrt(double x) { double v; __asm__ ("fsqrt\n" : "=t" (v) : "0" (x)); return v; } |
55 | static inline double sqrt(double x) { double v; __asm__ ("fsqrt\n" : "=t" (v) : "0" (x)); return v; } |
50 | #endif |
56 | #endif |
51 | 57 | ||
52 | #ifdef KERN_amd64_ARCH_H_ |
58 | #ifdef KERN_amd64_ARCH_H_ |
53 | static inline double sqrt(double x) { double v; __asm__ ("fsqrt\n" : "=t" (v) : "0" (x)); return v; } |
59 | static inline double sqrt(double x) { double v; __asm__ ("fsqrt\n" : "=t" (v) : "0" (x)); return v; } |
54 | #endif |
60 | #endif |
55 | 61 | ||
56 | #ifdef KERN_ia64_ARCH_H_ |
62 | #ifdef KERN_ia64_ARCH_H_ |
57 | static inline long double sqrt(long double a) |
63 | static inline long double sqrt(long double a) |
58 | { |
64 | { |
59 | long double x = 1; |
65 | long double x = 1; |
60 | long double lx = 0; |
66 | long double lx = 0; |
61 | 67 | ||
62 | if(a<0.00000000000000001) return 0; |
68 | if(a<0.00000000000000001) return 0; |
63 | 69 | ||
64 | while(x!=lx) |
70 | while(x!=lx) |
65 | { |
71 | { |
66 | lx=x; |
72 | lx=x; |
67 | x=(x+(a/x))/2; |
73 | x=(x+(a/x))/2; |
68 | } |
74 | } |
69 | return x; |
75 | return x; |
70 | } |
76 | } |
71 | #endif |
77 | #endif |
72 | 78 | ||
73 | 79 | ||
74 | 80 | ||
75 | static atomic_t threads_ok; |
81 | static atomic_t threads_ok; |
76 | static waitq_t can_start; |
82 | static waitq_t can_start; |
77 | 83 | ||
78 | static void e(void *data) |
84 | static void e(void *data) |
79 | { |
85 | { |
80 | int i; |
86 | int i; |
81 | double e,d,le,f; |
87 | double e,d,le,f; |
82 | 88 | ||
83 | thread_detach(THREAD); |
89 | thread_detach(THREAD); |
84 | 90 | ||
85 | waitq_sleep(&can_start); |
91 | waitq_sleep(&can_start); |
86 | 92 | ||
87 | for (i = 0; i<ATTEMPTS; i++) { |
93 | for (i = 0; i<ATTEMPTS; i++) { |
88 | le=-1; |
94 | le=-1; |
89 | e=0; |
95 | e=0; |
90 | f=1; |
96 | f=1; |
91 | 97 | ||
92 | for(d=1;e!=le;d*=f,f+=1) { |
98 | for(d=1;e!=le;d*=f,f+=1) { |
93 | le=e; |
99 | le=e; |
94 | e=e+1/d; |
100 | e=e+1/d; |
95 | } |
101 | } |
96 | 102 | ||
97 | if((int)(100000000*e)!=E_10e8) |
103 | if((int)(100000000*e)!=E_10e8) |
98 | panic("tid%d: e*10e8=%zd should be %zd\n", THREAD->tid, (unative_t) (100000000*e),(unative_t) E_10e8); |
104 | panic("tid%d: e*10e8=%zd should be %zd\n", THREAD->tid, (unative_t) (100000000*e),(unative_t) E_10e8); |
99 | } |
105 | } |
100 | 106 | ||
101 | printf("tid%d: e*10e8=%zd should be %zd\n", THREAD->tid, (unative_t) (100000000*e),(unative_t) E_10e8); |
107 | 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); |
108 | atomic_inc(&threads_ok); |
103 | } |
109 | } |
104 | 110 | ||
105 | static void pi(void *data) |
111 | static void pi(void *data) |
106 | { |
112 | { |
107 | 113 | ||
108 | #ifdef KERN_ia64_ARCH_H_ |
114 | #ifdef KERN_ia64_ARCH_H_ |
109 | #undef PI_10e8 |
115 | #undef PI_10e8 |
110 | #define PI_10e8 3141592 |
116 | #define PI_10e8 3141592 |
111 | #endif |
117 | #endif |
112 | 118 | ||
113 | 119 | ||
114 | int i; |
120 | int i; |
115 | double lpi, pi; |
121 | double lpi, pi; |
116 | double n, ab, ad; |
122 | double n, ab, ad; |
117 | 123 | ||
118 | thread_detach(THREAD); |
124 | thread_detach(THREAD); |
119 | 125 | ||
120 | waitq_sleep(&can_start); |
126 | waitq_sleep(&can_start); |
121 | 127 | ||
122 | 128 | ||
123 | for (i = 0; i<ATTEMPTS; i++) { |
129 | for (i = 0; i<ATTEMPTS; i++) { |
124 | lpi = -1; |
130 | lpi = -1; |
125 | pi = 0; |
131 | pi = 0; |
126 | 132 | ||
127 | for (n=2, ab = sqrt(2); lpi != pi; n *= 2, ab = ad) { |
133 | for (n=2, ab = sqrt(2); lpi != pi; n *= 2, ab = ad) { |
128 | double sc, cd; |
134 | double sc, cd; |
129 | 135 | ||
130 | sc = sqrt(1 - (ab*ab/4)); |
136 | sc = sqrt(1 - (ab*ab/4)); |
131 | cd = 1 - sc; |
137 | cd = 1 - sc; |
132 | ad = sqrt(ab*ab/4 + cd*cd); |
138 | ad = sqrt(ab*ab/4 + cd*cd); |
133 | lpi = pi; |
139 | lpi = pi; |
134 | pi = 2 * n * ad; |
140 | pi = 2 * n * ad; |
135 | } |
141 | } |
136 | 142 | ||
137 | #ifdef KERN_ia64_ARCH_H_ |
143 | #ifdef KERN_ia64_ARCH_H_ |
138 | if((int)(1000000*pi)!=PI_10e8) |
144 | if((int)(1000000*pi)!=PI_10e8) |
139 | panic("tid%d: pi*10e8=%zd should be %zd\n", THREAD->tid, (unative_t) (1000000*pi),(unative_t) (PI_10e8/100)); |
145 | panic("tid%d: pi*10e8=%zd should be %zd\n", THREAD->tid, (unative_t) (1000000*pi),(unative_t) (PI_10e8/100)); |
140 | #else |
146 | #else |
141 | if((int)(100000000*pi)!=PI_10e8) |
147 | if((int)(100000000*pi)!=PI_10e8) |
142 | panic("tid%d: pi*10e8=%zd should be %zd\n", THREAD->tid, (unative_t) (100000000*pi),(unative_t) PI_10e8); |
148 | panic("tid%d: pi*10e8=%zd should be %zd\n", THREAD->tid, (unative_t) (100000000*pi),(unative_t) PI_10e8); |
143 | #endif |
149 | #endif |
144 | 150 | ||
145 | } |
151 | } |
146 | 152 | ||
147 | printf("tid%d: pi*10e8=%zd should be %zd\n", THREAD->tid, (unative_t) (100000000*pi),(unative_t) PI_10e8); |
153 | 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); |
154 | atomic_inc(&threads_ok); |
149 | } |
155 | } |
150 | 156 | ||
151 | void test(void) |
157 | void test_fpu1(void) |
152 | { |
158 | { |
- | 159 | #ifdef CONFIG_BENCH |
|
- | 160 | uint64_t t0 = get_cycle(); |
|
- | 161 | #endif |
|
153 | thread_t *t; |
162 | thread_t *t; |
154 | int i; |
163 | int i; |
155 | 164 | ||
156 | waitq_initialize(&can_start); |
165 | waitq_initialize(&can_start); |
157 | 166 | ||
158 | printf("FPU test #1\n"); |
167 | printf("FPU test #1\n"); |
159 | printf("Creating %d threads... ", THREADS); |
168 | printf("Creating %d threads... ", THREADS); |
160 | 169 | ||
161 | for (i=0; i<THREADS/2; i++) { |
170 | for (i=0; i<THREADS/2; i++) { |
162 | if (!(t = thread_create(e, NULL, TASK, 0, "e"))) |
171 | if (!(t = thread_create(e, NULL, TASK, 0, "e"))) |
163 | panic("could not create thread\n"); |
172 | panic("could not create thread\n"); |
164 | thread_ready(t); |
173 | thread_ready(t); |
165 | if (!(t = thread_create(pi, NULL, TASK, 0, "pi"))) |
174 | if (!(t = thread_create(pi, NULL, TASK, 0, "pi"))) |
166 | panic("could not create thread\n"); |
175 | panic("could not create thread\n"); |
167 | thread_ready(t); |
176 | thread_ready(t); |
168 | } |
177 | } |
169 | printf("ok\n"); |
178 | printf("ok\n"); |
170 | 179 | ||
171 | thread_sleep(1); |
180 | thread_sleep(1); |
172 | waitq_wakeup(&can_start, WAKEUP_ALL); |
181 | waitq_wakeup(&can_start, WAKEUP_ALL); |
173 | 182 | ||
174 | while (atomic_get(&threads_ok) != THREADS) |
183 | while (atomic_get(&threads_ok) != THREADS) |
175 | ; |
184 | ; |
176 | 185 | ||
177 | printf("Test passed.\n"); |
186 | printf("Test passed.\n"); |
- | 187 | #ifdef CONFIG_BENCH |
|
- | 188 | uint64_t dt = get_cycle() - t0; |
|
- | 189 | printf("Time: %.*d cycles\n", sizeof(dt) * 2, dt); |
|
- | 190 | #endif |
|
- | 191 | } |
|
- | 192 | ||
- | 193 | #else |
|
- | 194 | ||
- | 195 | void test_fpu1(void) |
|
- | 196 | { |
|
- | 197 | printf("This test is available only on Intel/AMD platforms."); |
|
178 | } |
198 | } |
- | 199 | ||
- | 200 | #endif |
|
179 | 201 |