source: mainline/kernel/test/fpu/fpu1_ia64.c@ 7e752b2

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 7e752b2 was 7e752b2, checked in by Martin Decky <martin@…>, 15 years ago
  • correct printf() formatting strings and corresponding arguments
  • minor cstyle changes and other small fixes
  • Property mode set to 100644
File size: 4.0 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;
66
[b312247]67static void e(void *data)
[6de2480e]68{
[54ca3523]69 int i;
[c8410ec9]70 double e, d, le, f;
[e45a3b9]71
[8d6d76a]72 thread_detach(THREAD);
[e45a3b9]73
[c01bd280]74 waitq_sleep(&can_start);
[e45a3b9]75
[54ca3523]76 for (i = 0; i<ATTEMPTS; i++) {
[34db7fa]77 le = -1;
78 e = 0;
79 f = 1;
[e45a3b9]80
[34db7fa]81 for (d = 1; e != le; d *= f, f += 1) {
82 le = e;
83 e = e + 1 / d;
[54ca3523]84 }
[e45a3b9]85
[34db7fa]86 if ((int) (100000000 * e) != E_10e8) {
[cb01e1e]87 TPRINTF("tid%" PRIu64 ": e*10e8=%zd should be %" PRIun "\n", THREAD->tid, (unative_t) (100000000 * e), (unative_t) E_10e8);
[34db7fa]88 atomic_inc(&threads_fault);
89 break;
90 }
[c01bd280]91 }
[992bbb97]92 atomic_inc(&threads_ok);
[6de2480e]93}
94
[c01bd280]95static void pi(void *data)
96{
[54ca3523]97 int i;
[76cec1e]98 double lpi, pi;
99 double n, ab, ad;
[8d6d76a]100
101 thread_detach(THREAD);
[e45a3b9]102
[c01bd280]103 waitq_sleep(&can_start);
[e45a3b9]104
[34db7fa]105 for (i = 0; i < ATTEMPTS; i++) {
[54ca3523]106 lpi = -1;
107 pi = 0;
[e45a3b9]108
[34db7fa]109 for (n = 2, ab = sqrt(2); lpi != pi; n *= 2, ab = ad) {
[76cec1e]110 double sc, cd;
[e45a3b9]111
[34db7fa]112 sc = sqrt(1 - (ab * ab / 4));
[76cec1e]113 cd = 1 - sc;
[34db7fa]114 ad = sqrt(ab * ab / 4 + cd * cd);
[76cec1e]115 lpi = pi;
116 pi = 2 * n * ad;
117 }
[e45a3b9]118
[34db7fa]119 if ((int) (1000000 * pi) != PI_10e8) {
[cb01e1e]120 TPRINTF("tid%" PRIu64 ": pi*10e8=%zd should be %" PRIun "\n", THREAD->tid, (unative_t) (1000000 * pi), (unative_t) (PI_10e8 / 100));
[34db7fa]121 atomic_inc(&threads_fault);
122 break;
123 }
[c01bd280]124 }
[992bbb97]125 atomic_inc(&threads_ok);
[c01bd280]126}
[6de2480e]127
[a000878c]128const char *test_fpu1(void)
[6de2480e]129{
[228666c]130 unsigned int i;
131 atomic_count_t total = 0;
[e45a3b9]132
[c01bd280]133 waitq_initialize(&can_start);
[34db7fa]134 atomic_set(&threads_ok, 0);
135 atomic_set(&threads_fault, 0);
[c8410ec9]136
[cb01e1e]137 TPRINTF("Creating %u threads... ", 2 * THREADS);
[e45a3b9]138
[cb01e1e]139 for (i = 0; i < THREADS; i++) {
[34db7fa]140 thread_t *t;
141
[62b6d17]142 if (!(t = thread_create(e, NULL, TASK, 0, "e", false))) {
[cb01e1e]143 TPRINTF("could not create thread %u\n", 2 * i);
[34db7fa]144 break;
145 }
[c01bd280]146 thread_ready(t);
[34db7fa]147 total++;
148
[62b6d17]149 if (!(t = thread_create(pi, NULL, TASK, 0, "pi", false))) {
[cb01e1e]150 TPRINTF("could not create thread %u\n", 2 * i + 1);
[34db7fa]151 break;
152 }
[b312247]153 thread_ready(t);
[34db7fa]154 total++;
[b312247]155 }
[c8410ec9]156
[cb01e1e]157 TPRINTF("ok\n");
[af22f158]158
[c01bd280]159 thread_sleep(1);
160 waitq_wakeup(&can_start, WAKEUP_ALL);
[34db7fa]161
[228666c]162 while (atomic_get(&threads_ok) != total) {
[7e752b2]163 TPRINTF("Threads left: %" PRIua "\n",
164 total - atomic_get(&threads_ok));
[34db7fa]165 thread_sleep(1);
166 }
167
168 if (atomic_get(&threads_fault) == 0)
169 return NULL;
170
171 return "Test failed";
[6de2480e]172}
Note: See TracBrowser for help on using the repository browser.