source: mainline/kernel/test/fpu/fpu1_x86.c@ 95285378

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 95285378 was 96b02eb9, checked in by Martin Decky <martin@…>, 15 years ago

more unification of basic types

  • use sysarg_t and native_t (unsigned and signed variant) in both kernel and uspace
  • remove ipcarg_t in favour of sysarg_t

(no change in functionality)

  • Property mode set to 100644
File size: 3.9 KB
Line 
1/*
2 * Copyright (c) 2005 Jakub Vana
3 * Copyright (c) 2005 Jakub 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 */
29
30#include <print.h>
31#include <debug.h>
32
33#include <test.h>
34#include <atomic.h>
35#include <proc/thread.h>
36
37#include <arch.h>
38#include <arch/arch.h>
39
40
41#define THREADS 150
42#define ATTEMPTS 100
43
44#define E_10e8 271828182
45#define PI_10e8 314159265
46
47static 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}
59
60static atomic_t threads_ok;
61static atomic_t threads_fault;
62static waitq_t can_start;
63
64static void e(void *data)
65{
66 int i;
67 double e, d, le, f;
68
69 thread_detach(THREAD);
70
71 waitq_sleep(&can_start);
72
73 for (i = 0; i<ATTEMPTS; i++) {
74 le = -1;
75 e = 0;
76 f = 1;
77
78 for (d = 1; e != le; d *= f, f += 1) {
79 le = e;
80 e = e + 1 / d;
81 }
82
83 if ((int) (100000000 * e) != E_10e8) {
84 TPRINTF("tid%" PRIu64 ": e*10e8=%" PRIun " should be %" PRIun "\n",
85 THREAD->tid, (sysarg_t) (100000000 * e), (sysarg_t) E_10e8);
86 atomic_inc(&threads_fault);
87 break;
88 }
89 }
90 atomic_inc(&threads_ok);
91}
92
93static void pi(void *data)
94{
95 int i;
96 double lpi, pi;
97 double n, ab, ad;
98
99 thread_detach(THREAD);
100
101 waitq_sleep(&can_start);
102
103 for (i = 0; i < ATTEMPTS; i++) {
104 lpi = -1;
105 pi = 0;
106
107 for (n = 2, ab = sqrt(2); lpi != pi; n *= 2, ab = ad) {
108 double sc, cd;
109
110 sc = sqrt(1 - (ab * ab / 4));
111 cd = 1 - sc;
112 ad = sqrt(ab * ab / 4 + cd * cd);
113 lpi = pi;
114 pi = 2 * n * ad;
115 }
116
117 if ((int) (100000000 * pi) != PI_10e8) {
118 TPRINTF("tid%" PRIu64 ": pi*10e8=%" PRIun " should be %" PRIun "\n",
119 THREAD->tid, (sysarg_t) (100000000 * pi), (sysarg_t) PI_10e8);
120 atomic_inc(&threads_fault);
121 break;
122 }
123 }
124 atomic_inc(&threads_ok);
125}
126
127const char *test_fpu1(void)
128{
129 unsigned int i;
130 atomic_count_t total = 0;
131
132 waitq_initialize(&can_start);
133 atomic_set(&threads_ok, 0);
134 atomic_set(&threads_fault, 0);
135
136 TPRINTF("Creating %u threads... ", 2 * THREADS);
137
138 for (i = 0; i < THREADS; i++) {
139 thread_t *t;
140
141 if (!(t = thread_create(e, NULL, TASK, 0, "e", false))) {
142 TPRINTF("could not create thread %u\n", 2 * i);
143 break;
144 }
145 thread_ready(t);
146 total++;
147
148 if (!(t = thread_create(pi, NULL, TASK, 0, "pi", false))) {
149 TPRINTF("could not create thread %u\n", 2 * i + 1);
150 break;
151 }
152 thread_ready(t);
153 total++;
154 }
155
156 TPRINTF("ok\n");
157
158 thread_sleep(1);
159 waitq_wakeup(&can_start, WAKEUP_ALL);
160
161 while (atomic_get(&threads_ok) != total) {
162 TPRINTF("Threads left: %" PRIua "\n", total - atomic_get(&threads_ok));
163 thread_sleep(1);
164 }
165
166 if (atomic_get(&threads_fault) == 0)
167 return NULL;
168
169 return "Test failed";
170}
Note: See TracBrowser for help on using the repository browser.