Rev 3874 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 3874 | Rev 3918 | ||
|---|---|---|---|
| Line 36... | Line 36... | ||
| 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 | - | ||
| 48 | #ifdef KERN_ia32_ARCH_H_ |
- | |
| 49 | static inline double sqrt(double x) |
- | |
| 50 | { |
- | |
| 51 | double v; |
- | |
| 52 | - | ||
| 53 | asm ( |
- | |
| 54 | "fsqrt\n" |
- | |
| 55 | : "=t" (v) |
- | |
| 56 | : "0" (x) |
- | |
| 57 | ); |
- | |
| 58 | - | ||
| 59 | return v; |
- | |
| 60 | } |
- | |
| 61 | #endif |
- | |
| 62 | - | ||
| 63 | #ifdef KERN_amd64_ARCH_H_ |
- | |
| 64 | static inline double sqrt(double x) |
47 | static inline double sqrt(double x) |
| 65 | { |
48 | { |
| 66 | double v; |
49 | double v; |
| 67 | 50 | ||
| 68 | asm ( |
51 | asm ( |
| Line 71... | Line 54... | ||
| 71 | : "0" (x) |
54 | : "0" (x) |
| 72 | ); |
55 | ); |
| 73 | 56 | ||
| 74 | return v; |
57 | return v; |
| 75 | } |
58 | } |
| 76 | #endif |
- | |
| 77 | - | ||
| 78 | #ifdef KERN_ia64_ARCH_H_ |
- | |
| 79 | - | ||
| 80 | #undef PI_10e8 |
- | |
| 81 | #define PI_10e8 3141592 |
- | |
| 82 | - | ||
| 83 | static inline long double sqrt(long double a) |
- | |
| 84 | { |
- | |
| 85 | long double x = 1; |
- | |
| 86 | long double lx = 0; |
- | |
| 87 | - | ||
| 88 | if (a < 0.00000000000000001) |
- | |
| 89 | return 0; |
- | |
| 90 | - | ||
| 91 | while(x != lx) { |
- | |
| 92 | lx = x; |
- | |
| 93 | x = (x + (a / x)) / 2; |
- | |
| 94 | } |
- | |
| 95 | - | ||
| 96 | return x; |
- | |
| 97 | } |
- | |
| 98 | #endif |
- | |
| 99 | - | ||
| 100 | 59 | ||
| 101 | static atomic_t threads_ok; |
60 | static atomic_t threads_ok; |
| 102 | static atomic_t threads_fault; |
61 | static atomic_t threads_fault; |
| 103 | static waitq_t can_start; |
62 | static waitq_t can_start; |
| 104 | static bool sh_quiet; |
63 | static bool sh_quiet; |
| 105 | 64 | ||
| 106 | static void e(void *data) |
65 | static void e(void *data) |
| 107 | { |
66 | { |
| 108 | int i; |
67 | int i; |
| 109 | double e, d, le, f; |
68 | double e, d, le, f; |
| 110 | 69 | ||
| 111 | thread_detach(THREAD); |
70 | thread_detach(THREAD); |
| 112 | 71 | ||
| 113 | waitq_sleep(&can_start); |
72 | waitq_sleep(&can_start); |
| 114 | 73 | ||
| 115 | for (i = 0; i<ATTEMPTS; i++) { |
74 | for (i = 0; i<ATTEMPTS; i++) { |
| 116 | le = -1; |
75 | le = -1; |
| 117 | e = 0; |
76 | e = 0; |
| 118 | f = 1; |
77 | f = 1; |
| 119 | 78 | ||
| 120 | for (d = 1; e != le; d *= f, f += 1) { |
79 | for (d = 1; e != le; d *= f, f += 1) { |
| 121 | le = e; |
80 | le = e; |
| 122 | e = e + 1 / d; |
81 | e = e + 1 / d; |
| 123 | } |
82 | } |
| 124 | 83 | ||
| 125 | if ((int) (100000000 * e) != E_10e8) { |
84 | if ((int) (100000000 * e) != E_10e8) { |
| 126 | if (!sh_quiet) |
85 | if (!sh_quiet) |
| 127 | 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); |
| 128 | atomic_inc(&threads_fault); |
87 | atomic_inc(&threads_fault); |
| 129 | break; |
88 | break; |
| Line 137... | Line 96... | ||
| 137 | int i; |
96 | int i; |
| 138 | double lpi, pi; |
97 | double lpi, pi; |
| 139 | double n, ab, ad; |
98 | double n, ab, ad; |
| 140 | 99 | ||
| 141 | thread_detach(THREAD); |
100 | thread_detach(THREAD); |
| 142 | 101 | ||
| 143 | waitq_sleep(&can_start); |
102 | waitq_sleep(&can_start); |
| 144 | 103 | ||
| 145 | for (i = 0; i < ATTEMPTS; i++) { |
104 | for (i = 0; i < ATTEMPTS; i++) { |
| 146 | lpi = -1; |
105 | lpi = -1; |
| 147 | pi = 0; |
106 | pi = 0; |
| 148 | 107 | ||
| 149 | 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) { |
| 150 | double sc, cd; |
109 | double sc, cd; |
| 151 | 110 | ||
| 152 | sc = sqrt(1 - (ab * ab / 4)); |
111 | sc = sqrt(1 - (ab * ab / 4)); |
| 153 | cd = 1 - sc; |
112 | cd = 1 - sc; |
| 154 | ad = sqrt(ab * ab / 4 + cd * cd); |
113 | ad = sqrt(ab * ab / 4 + cd * cd); |
| 155 | lpi = pi; |
114 | lpi = pi; |
| 156 | pi = 2 * n * ad; |
115 | pi = 2 * n * ad; |
| 157 | } |
116 | } |
| 158 | - | ||
| 159 | #ifdef KERN_ia64_ARCH_H_ |
- | |
| 160 | if ((int) (1000000 * pi) != PI_10e8) { |
- | |
| 161 | if (!sh_quiet) |
- | |
| 162 | printf("tid%" PRIu64 ": pi*10e8=%zd should be %" PRIun "\n", THREAD->tid, (unative_t) (1000000 * pi), (unative_t) (PI_10e8 / 100)); |
- | |
| 163 | atomic_inc(&threads_fault); |
- | |
| 164 | break; |
- | |
| 165 | } |
117 | |
| 166 | #else |
- | |
| 167 | if ((int) (100000000 * pi) != PI_10e8) { |
118 | if ((int) (100000000 * pi) != PI_10e8) { |
| 168 | if (!sh_quiet) |
119 | if (!sh_quiet) |
| 169 | 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); |
| 170 | atomic_inc(&threads_fault); |
121 | atomic_inc(&threads_fault); |
| 171 | break; |
122 | break; |
| 172 | } |
123 | } |
| 173 | #endif |
- | |
| 174 | } |
124 | } |
| 175 | atomic_inc(&threads_ok); |
125 | atomic_inc(&threads_ok); |
| 176 | } |
126 | } |
| 177 | 127 | ||
| 178 | char * test_fpu1(bool quiet) |
128 | char * test_fpu1(bool quiet) |
| 179 | { |
129 | { |
| 180 | unsigned int i, total = 0; |
130 | unsigned int i, total = 0; |
| 181 | sh_quiet = quiet; |
131 | sh_quiet = quiet; |
| 182 | 132 | ||
| 183 | waitq_initialize(&can_start); |
133 | waitq_initialize(&can_start); |
| 184 | atomic_set(&threads_ok, 0); |
134 | atomic_set(&threads_ok, 0); |
| 185 | atomic_set(&threads_fault, 0); |
135 | atomic_set(&threads_fault, 0); |
| 186 | 136 | ||
| 187 | if (!quiet) |
137 | if (!quiet) |
| 188 | printf("Creating %u threads... ", 2 * THREADS); |
138 | printf("Creating %u threads... ", 2 * THREADS); |
| 189 | 139 | ||
| 190 | for (i = 0; i < THREADS; i++) { |
140 | for (i = 0; i < THREADS; i++) { |
| 191 | thread_t *t; |
141 | thread_t *t; |
| 192 | 142 | ||
| 193 | if (!(t = thread_create(e, NULL, TASK, 0, "e", false))) { |
143 | if (!(t = thread_create(e, NULL, TASK, 0, "e", false))) { |
| 194 | if (!quiet) |
144 | if (!quiet) |