Rev 3874 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
86 | jermar | 1 | /* |
2071 | jermar | 2 | * Copyright (c) 2005 Jakub Vana |
3 | * Copyright (c) 2005 Jakub Jermar |
||
86 | jermar | 4 | * All rights reserved. |
5 | * |
||
6 | * Redistribution and use in source and binary forms, with or without |
||
7 | * modification, are permitted provided that the following conditions |
||
8 | * are met: |
||
9 | * |
||
10 | * - Redistributions of source code must retain the above copyright |
||
11 | * notice, this list of conditions and the following disclaimer. |
||
12 | * - Redistributions in binary form must reproduce the above copyright |
||
13 | * notice, this list of conditions and the following disclaimer in the |
||
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 |
||
16 | * derived from this software without specific prior written permission. |
||
17 | * |
||
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 |
||
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
||
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
||
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
||
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 |
||
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 |
||
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
28 | */ |
||
84 | vana | 29 | |
30 | #include <print.h> |
||
31 | #include <debug.h> |
||
32 | |||
33 | #include <test.h> |
||
1104 | jermar | 34 | #include <atomic.h> |
84 | vana | 35 | #include <proc/thread.h> |
36 | |||
94 | jermar | 37 | #include <arch.h> |
1023 | vana | 38 | #include <arch/arch.h> |
94 | jermar | 39 | |
2020 | decky | 40 | |
3918 | decky | 41 | #define THREADS 150 |
42 | #define ATTEMPTS 100 |
||
91 | jermar | 43 | |
3918 | decky | 44 | #define E_10e8 271828182 |
45 | #define PI_10e8 314159265 |
||
91 | jermar | 46 | |
2027 | decky | 47 | static inline double sqrt(double x) |
48 | { |
||
49 | double v; |
||
50 | |||
51 | asm ( |
||
52 | "fsqrt\n" |
||
53 | : "=t" (v) |
||
54 | : "0" (x) |
||
55 | ); |
||
56 | |||
57 | return v; |
||
58 | } |
||
1023 | vana | 59 | |
483 | jermar | 60 | static atomic_t threads_ok; |
2027 | decky | 61 | static atomic_t threads_fault; |
91 | jermar | 62 | static waitq_t can_start; |
2051 | decky | 63 | static bool sh_quiet; |
91 | jermar | 64 | |
86 | jermar | 65 | static void e(void *data) |
84 | vana | 66 | { |
92 | jermar | 67 | int i; |
2051 | decky | 68 | double e, d, le, f; |
3918 | decky | 69 | |
1658 | vana | 70 | thread_detach(THREAD); |
3918 | decky | 71 | |
91 | jermar | 72 | waitq_sleep(&can_start); |
3918 | decky | 73 | |
92 | jermar | 74 | for (i = 0; i<ATTEMPTS; i++) { |
2027 | decky | 75 | le = -1; |
76 | e = 0; |
||
77 | f = 1; |
||
3918 | decky | 78 | |
2027 | decky | 79 | for (d = 1; e != le; d *= f, f += 1) { |
80 | le = e; |
||
81 | e = e + 1 / d; |
||
92 | jermar | 82 | } |
3918 | decky | 83 | |
2027 | decky | 84 | if ((int) (100000000 * e) != E_10e8) { |
2051 | decky | 85 | if (!sh_quiet) |
3069 | decky | 86 | printf("tid%" PRIu64 ": e*10e8=%zd should be %" PRIun "\n", THREAD->tid, (unative_t) (100000000 * e), (unative_t) E_10e8); |
2027 | decky | 87 | atomic_inc(&threads_fault); |
88 | break; |
||
89 | } |
||
86 | jermar | 90 | } |
119 | jermar | 91 | atomic_inc(&threads_ok); |
84 | vana | 92 | } |
93 | |||
91 | jermar | 94 | static void pi(void *data) |
95 | { |
||
92 | jermar | 96 | int i; |
125 | jermar | 97 | double lpi, pi; |
98 | double n, ab, ad; |
||
1658 | vana | 99 | |
100 | thread_detach(THREAD); |
||
3918 | decky | 101 | |
91 | jermar | 102 | waitq_sleep(&can_start); |
3918 | decky | 103 | |
2027 | decky | 104 | for (i = 0; i < ATTEMPTS; i++) { |
92 | jermar | 105 | lpi = -1; |
106 | pi = 0; |
||
3918 | decky | 107 | |
2027 | decky | 108 | for (n = 2, ab = sqrt(2); lpi != pi; n *= 2, ab = ad) { |
125 | jermar | 109 | double sc, cd; |
3918 | decky | 110 | |
2027 | decky | 111 | sc = sqrt(1 - (ab * ab / 4)); |
125 | jermar | 112 | cd = 1 - sc; |
2027 | decky | 113 | ad = sqrt(ab * ab / 4 + cd * cd); |
125 | jermar | 114 | lpi = pi; |
115 | pi = 2 * n * ad; |
||
116 | } |
||
3918 | decky | 117 | |
2027 | decky | 118 | if ((int) (100000000 * pi) != PI_10e8) { |
2051 | decky | 119 | if (!sh_quiet) |
3069 | decky | 120 | printf("tid%" PRIu64 ": pi*10e8=%zd should be %" PRIun "\n", THREAD->tid, (unative_t) (100000000 * pi), (unative_t) PI_10e8); |
2027 | decky | 121 | atomic_inc(&threads_fault); |
122 | break; |
||
123 | } |
||
91 | jermar | 124 | } |
119 | jermar | 125 | atomic_inc(&threads_ok); |
91 | jermar | 126 | } |
127 | |||
2050 | decky | 128 | char * test_fpu1(bool quiet) |
84 | vana | 129 | { |
2027 | decky | 130 | unsigned int i, total = 0; |
2051 | decky | 131 | sh_quiet = quiet; |
3918 | decky | 132 | |
91 | jermar | 133 | waitq_initialize(&can_start); |
2027 | decky | 134 | atomic_set(&threads_ok, 0); |
135 | atomic_set(&threads_fault, 0); |
||
2051 | decky | 136 | |
137 | if (!quiet) |
||
3069 | decky | 138 | printf("Creating %u threads... ", 2 * THREADS); |
3918 | decky | 139 | |
2027 | decky | 140 | for (i = 0; i < THREADS; i++) { |
141 | thread_t *t; |
||
142 | |||
2042 | decky | 143 | if (!(t = thread_create(e, NULL, TASK, 0, "e", false))) { |
2051 | decky | 144 | if (!quiet) |
3069 | decky | 145 | printf("could not create thread %u\n", 2 * i); |
2027 | decky | 146 | break; |
147 | } |
||
86 | jermar | 148 | thread_ready(t); |
2027 | decky | 149 | total++; |
150 | |||
2042 | decky | 151 | if (!(t = thread_create(pi, NULL, TASK, 0, "pi", false))) { |
2051 | decky | 152 | if (!quiet) |
3069 | decky | 153 | printf("could not create thread %u\n", 2 * i + 1); |
2027 | decky | 154 | break; |
155 | } |
||
91 | jermar | 156 | thread_ready(t); |
2027 | decky | 157 | total++; |
86 | jermar | 158 | } |
90 | vana | 159 | |
2051 | decky | 160 | if (!quiet) |
161 | printf("ok\n"); |
||
162 | |||
91 | jermar | 163 | thread_sleep(1); |
164 | waitq_wakeup(&can_start, WAKEUP_ALL); |
||
2027 | decky | 165 | |
2745 | decky | 166 | while (atomic_get(&threads_ok) != (long) total) { |
2051 | decky | 167 | if (!quiet) |
168 | printf("Threads left: %d\n", total - atomic_get(&threads_ok)); |
||
2027 | decky | 169 | thread_sleep(1); |
170 | } |
||
171 | |||
172 | if (atomic_get(&threads_fault) == 0) |
||
173 | return NULL; |
||
174 | |||
175 | return "Test failed"; |
||
84 | vana | 176 | } |