Rev 3918 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3918 | Rev 4153 | ||
---|---|---|---|
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 | 32 | ||
33 | #include <test.h> |
33 | #include <test.h> |
34 | #include <atomic.h> |
34 | #include <atomic.h> |
35 | #include <proc/thread.h> |
35 | #include <proc/thread.h> |
36 | 36 | ||
37 | #include <arch.h> |
37 | #include <arch.h> |
38 | #include <arch/arch.h> |
38 | #include <arch/arch.h> |
39 | 39 | ||
40 | 40 | ||
41 | #define THREADS 150 |
41 | #define THREADS 150 |
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 | static inline double sqrt(double x) |
47 | static inline double sqrt(double x) |
48 | { |
48 | { |
49 | double v; |
49 | double v; |
50 | 50 | ||
51 | asm ( |
51 | asm ( |
52 | "fsqrt\n" |
52 | "fsqrt\n" |
53 | : "=t" (v) |
53 | : "=t" (v) |
54 | : "0" (x) |
54 | : "0" (x) |
55 | ); |
55 | ); |
56 | 56 | ||
57 | return v; |
57 | return v; |
58 | } |
58 | } |
59 | 59 | ||
60 | static atomic_t threads_ok; |
60 | static atomic_t threads_ok; |
61 | static atomic_t threads_fault; |
61 | static atomic_t threads_fault; |
62 | static waitq_t can_start; |
62 | static waitq_t can_start; |
63 | static bool sh_quiet; |
63 | static bool sh_quiet; |
64 | 64 | ||
65 | static void e(void *data) |
65 | static void e(void *data) |
66 | { |
66 | { |
67 | int i; |
67 | int i; |
68 | double e, d, le, f; |
68 | double e, d, le, f; |
69 | 69 | ||
70 | thread_detach(THREAD); |
70 | thread_detach(THREAD); |
71 | 71 | ||
72 | waitq_sleep(&can_start); |
72 | waitq_sleep(&can_start); |
73 | 73 | ||
74 | for (i = 0; i<ATTEMPTS; i++) { |
74 | for (i = 0; i<ATTEMPTS; i++) { |
75 | le = -1; |
75 | le = -1; |
76 | e = 0; |
76 | e = 0; |
77 | f = 1; |
77 | f = 1; |
78 | 78 | ||
79 | for (d = 1; e != le; d *= f, f += 1) { |
79 | for (d = 1; e != le; d *= f, f += 1) { |
80 | le = e; |
80 | le = e; |
81 | e = e + 1 / d; |
81 | e = e + 1 / d; |
82 | } |
82 | } |
83 | 83 | ||
84 | if ((int) (100000000 * e) != E_10e8) { |
84 | if ((int) (100000000 * e) != E_10e8) { |
85 | if (!sh_quiet) |
85 | if (!sh_quiet) |
86 | printf("tid%" PRIu64 ": e*10e8=%zd should be %" PRIun "\n", THREAD->tid, (unative_t) (100000000 * e), (unative_t) E_10e8); |
86 | printf("tid%" PRIu64 ": e*10e8=%zd should be %" PRIun "\n", THREAD->tid, (unative_t) (100000000 * e), (unative_t) E_10e8); |
87 | atomic_inc(&threads_fault); |
87 | atomic_inc(&threads_fault); |
88 | break; |
88 | break; |
89 | } |
89 | } |
90 | } |
90 | } |
91 | atomic_inc(&threads_ok); |
91 | atomic_inc(&threads_ok); |
92 | } |
92 | } |
93 | 93 | ||
94 | static void pi(void *data) |
94 | static void pi(void *data) |
95 | { |
95 | { |
96 | int i; |
96 | int i; |
97 | double lpi, pi; |
97 | double lpi, pi; |
98 | double n, ab, ad; |
98 | double n, ab, ad; |
99 | 99 | ||
100 | thread_detach(THREAD); |
100 | thread_detach(THREAD); |
101 | 101 | ||
102 | waitq_sleep(&can_start); |
102 | waitq_sleep(&can_start); |
103 | 103 | ||
104 | for (i = 0; i < ATTEMPTS; i++) { |
104 | for (i = 0; i < ATTEMPTS; i++) { |
105 | lpi = -1; |
105 | lpi = -1; |
106 | pi = 0; |
106 | pi = 0; |
107 | 107 | ||
108 | for (n = 2, ab = sqrt(2); lpi != pi; n *= 2, ab = ad) { |
108 | for (n = 2, ab = sqrt(2); lpi != pi; n *= 2, ab = ad) { |
109 | double sc, cd; |
109 | double sc, cd; |
110 | 110 | ||
111 | sc = sqrt(1 - (ab * ab / 4)); |
111 | sc = sqrt(1 - (ab * ab / 4)); |
112 | cd = 1 - sc; |
112 | cd = 1 - sc; |
113 | ad = sqrt(ab * ab / 4 + cd * cd); |
113 | ad = sqrt(ab * ab / 4 + cd * cd); |
114 | lpi = pi; |
114 | lpi = pi; |
115 | pi = 2 * n * ad; |
115 | pi = 2 * n * ad; |
116 | } |
116 | } |
117 | 117 | ||
118 | if ((int) (100000000 * pi) != PI_10e8) { |
118 | if ((int) (100000000 * pi) != PI_10e8) { |
119 | if (!sh_quiet) |
119 | if (!sh_quiet) |
120 | printf("tid%" PRIu64 ": pi*10e8=%zd should be %" PRIun "\n", THREAD->tid, (unative_t) (100000000 * pi), (unative_t) PI_10e8); |
120 | printf("tid%" PRIu64 ": pi*10e8=%zd should be %" PRIun "\n", THREAD->tid, (unative_t) (100000000 * pi), (unative_t) PI_10e8); |
121 | atomic_inc(&threads_fault); |
121 | atomic_inc(&threads_fault); |
122 | break; |
122 | break; |
123 | } |
123 | } |
124 | } |
124 | } |
125 | atomic_inc(&threads_ok); |
125 | atomic_inc(&threads_ok); |
126 | } |
126 | } |
127 | 127 | ||
128 | char * test_fpu1(bool quiet) |
128 | char * test_fpu1(bool quiet) |
129 | { |
129 | { |
130 | unsigned int i, total = 0; |
130 | unsigned int i, total = 0; |
131 | sh_quiet = quiet; |
131 | sh_quiet = quiet; |
132 | 132 | ||
133 | waitq_initialize(&can_start); |
133 | waitq_initialize(&can_start); |
134 | atomic_set(&threads_ok, 0); |
134 | atomic_set(&threads_ok, 0); |
135 | atomic_set(&threads_fault, 0); |
135 | atomic_set(&threads_fault, 0); |
136 | 136 | ||
137 | if (!quiet) |
137 | if (!quiet) |
138 | printf("Creating %u threads... ", 2 * THREADS); |
138 | printf("Creating %u threads... ", 2 * THREADS); |
139 | 139 | ||
140 | for (i = 0; i < THREADS; i++) { |
140 | for (i = 0; i < THREADS; i++) { |
141 | thread_t *t; |
141 | thread_t *t; |
142 | 142 | ||
143 | if (!(t = thread_create(e, NULL, TASK, 0, "e", false))) { |
143 | if (!(t = thread_create(e, NULL, TASK, 0, "e", false))) { |
144 | if (!quiet) |
144 | if (!quiet) |
145 | printf("could not create thread %u\n", 2 * i); |
145 | printf("could not create thread %u\n", 2 * i); |
146 | break; |
146 | break; |
147 | } |
147 | } |
148 | thread_ready(t); |
148 | thread_ready(t); |
149 | total++; |
149 | total++; |
150 | 150 | ||
151 | if (!(t = thread_create(pi, NULL, TASK, 0, "pi", false))) { |
151 | if (!(t = thread_create(pi, NULL, TASK, 0, "pi", false))) { |
152 | if (!quiet) |
152 | if (!quiet) |
153 | printf("could not create thread %u\n", 2 * i + 1); |
153 | printf("could not create thread %u\n", 2 * i + 1); |
154 | break; |
154 | break; |
155 | } |
155 | } |
156 | thread_ready(t); |
156 | thread_ready(t); |
157 | total++; |
157 | total++; |
158 | } |
158 | } |
159 | 159 | ||
160 | if (!quiet) |
160 | if (!quiet) |
161 | printf("ok\n"); |
161 | printf("ok\n"); |
162 | 162 | ||
163 | thread_sleep(1); |
163 | thread_sleep(1); |
164 | waitq_wakeup(&can_start, WAKEUP_ALL); |
164 | waitq_wakeup(&can_start, WAKEUP_ALL); |
165 | 165 | ||
166 | while (atomic_get(&threads_ok) != (long) total) { |
166 | while (atomic_get(&threads_ok) != (long) total) { |
167 | if (!quiet) |
167 | if (!quiet) |
168 | printf("Threads left: %d\n", total - atomic_get(&threads_ok)); |
168 | printf("Threads left: %d\n", total - atomic_get(&threads_ok)); |
169 | thread_sleep(1); |
169 | thread_sleep(1); |
170 | } |
170 | } |
171 | 171 | ||
172 | if (atomic_get(&threads_fault) == 0) |
172 | if (atomic_get(&threads_fault) == 0) |
173 | return NULL; |
173 | return NULL; |
174 | 174 | ||
175 | return "Test failed"; |
175 | return "Test failed"; |
176 | } |
176 | } |
177 | 177 |