source: mainline/kernel/test/fpu/fpu1_ia64.c@ eada065e

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

avoid ugly ifdefs in fpu1 test

  • Property mode set to 100644
File size: 4.1 KB
RevLine 
[b312247]1/*
[df4ed85]2 * Copyright (c) 2005 Jakub Vana
3 * Copyright (c) 2005 Jakub Jermar
[b312247]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 */
[6de2480e]29
30#include <print.h>
31#include <debug.h>
32
33#include <test.h>
[23684b7]34#include <atomic.h>
[6de2480e]35#include <proc/thread.h>
36
[32a89bf]37#include <arch.h>
[9e1c942]38#include <arch/arch.h>
[32a89bf]39
[50661ab]40
[e45a3b9]41#define THREADS 150
42#define ATTEMPTS 100
[c01bd280]43
[e45a3b9]44#define E_10e8 271828182
45#define PI_10e8 3141592
[c01bd280]46
[e45a3b9]47static inline long double sqrt(long double a)
[34db7fa]48{
[9e1c942]49 long double x = 1;
50 long double lx = 0;
[e45a3b9]51
[34db7fa]52 if (a < 0.00000000000000001)
53 return 0;
[9e1c942]54
[e45a3b9]55 while (x != lx) {
[34db7fa]56 lx = x;
57 x = (x + (a / x)) / 2;
[9e1c942]58 }
[34db7fa]59
[e45a3b9]60 return x;
[9e1c942]61}
62
[e507afa]63static atomic_t threads_ok;
[34db7fa]64static atomic_t threads_fault;
[c01bd280]65static waitq_t can_start;
[c8410ec9]66static bool sh_quiet;
[c01bd280]67
[b312247]68static void e(void *data)
[6de2480e]69{
[54ca3523]70 int i;
[c8410ec9]71 double e, d, le, f;
[e45a3b9]72
[8d6d76a]73 thread_detach(THREAD);
[e45a3b9]74
[c01bd280]75 waitq_sleep(&can_start);
[e45a3b9]76
[54ca3523]77 for (i = 0; i<ATTEMPTS; i++) {
[34db7fa]78 le = -1;
79 e = 0;
80 f = 1;
[e45a3b9]81
[34db7fa]82 for (d = 1; e != le; d *= f, f += 1) {
83 le = e;
84 e = e + 1 / d;
[54ca3523]85 }
[e45a3b9]86
[34db7fa]87 if ((int) (100000000 * e) != E_10e8) {
[c8410ec9]88 if (!sh_quiet)
[cd8ad52]89 printf("tid%" PRIu64 ": e*10e8=%zd should be %" PRIun "\n", THREAD->tid, (unative_t) (100000000 * e), (unative_t) E_10e8);
[34db7fa]90 atomic_inc(&threads_fault);
91 break;
92 }
[c01bd280]93 }
[992bbb97]94 atomic_inc(&threads_ok);
[6de2480e]95}
96
[c01bd280]97static void pi(void *data)
98{
[54ca3523]99 int i;
[76cec1e]100 double lpi, pi;
101 double n, ab, ad;
[8d6d76a]102
103 thread_detach(THREAD);
[e45a3b9]104
[c01bd280]105 waitq_sleep(&can_start);
[e45a3b9]106
[34db7fa]107 for (i = 0; i < ATTEMPTS; i++) {
[54ca3523]108 lpi = -1;
109 pi = 0;
[e45a3b9]110
[34db7fa]111 for (n = 2, ab = sqrt(2); lpi != pi; n *= 2, ab = ad) {
[76cec1e]112 double sc, cd;
[e45a3b9]113
[34db7fa]114 sc = sqrt(1 - (ab * ab / 4));
[76cec1e]115 cd = 1 - sc;
[34db7fa]116 ad = sqrt(ab * ab / 4 + cd * cd);
[76cec1e]117 lpi = pi;
118 pi = 2 * n * ad;
119 }
[e45a3b9]120
[34db7fa]121 if ((int) (1000000 * pi) != PI_10e8) {
[c8410ec9]122 if (!sh_quiet)
[cd8ad52]123 printf("tid%" PRIu64 ": pi*10e8=%zd should be %" PRIun "\n", THREAD->tid, (unative_t) (1000000 * pi), (unative_t) (PI_10e8 / 100));
[34db7fa]124 atomic_inc(&threads_fault);
125 break;
126 }
[c01bd280]127 }
[992bbb97]128 atomic_inc(&threads_ok);
[c01bd280]129}
[6de2480e]130
[95155b0c]131char * test_fpu1(bool quiet)
[6de2480e]132{
[34db7fa]133 unsigned int i, total = 0;
[c8410ec9]134 sh_quiet = quiet;
[e45a3b9]135
[c01bd280]136 waitq_initialize(&can_start);
[34db7fa]137 atomic_set(&threads_ok, 0);
138 atomic_set(&threads_fault, 0);
[c8410ec9]139
140 if (!quiet)
[cd8ad52]141 printf("Creating %u threads... ", 2 * THREADS);
[e45a3b9]142
[34db7fa]143 for (i = 0; i < THREADS; i++) {
144 thread_t *t;
145
[62b6d17]146 if (!(t = thread_create(e, NULL, TASK, 0, "e", false))) {
[c8410ec9]147 if (!quiet)
[cd8ad52]148 printf("could not create thread %u\n", 2 * i);
[34db7fa]149 break;
150 }
[c01bd280]151 thread_ready(t);
[34db7fa]152 total++;
153
[62b6d17]154 if (!(t = thread_create(pi, NULL, TASK, 0, "pi", false))) {
[c8410ec9]155 if (!quiet)
[cd8ad52]156 printf("could not create thread %u\n", 2 * i + 1);
[34db7fa]157 break;
158 }
[b312247]159 thread_ready(t);
[34db7fa]160 total++;
[b312247]161 }
[c8410ec9]162
163 if (!quiet)
164 printf("ok\n");
[af22f158]165
[c01bd280]166 thread_sleep(1);
167 waitq_wakeup(&can_start, WAKEUP_ALL);
[34db7fa]168
[6c441cf8]169 while (atomic_get(&threads_ok) != (long) total) {
[c8410ec9]170 if (!quiet)
171 printf("Threads left: %d\n", total - atomic_get(&threads_ok));
[34db7fa]172 thread_sleep(1);
173 }
174
175 if (atomic_get(&threads_fault) == 0)
176 return NULL;
177
178 return "Test failed";
[6de2480e]179}
Note: See TracBrowser for help on using the repository browser.