Rev 90 | Rev 92 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
86 | jermar | 1 | /* |
2 | * Copyright (C) 2005 Jakub Vana |
||
91 | jermar | 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 <arch/interrupt.h> |
||
31 | #include <print.h> |
||
32 | #include <debug.h> |
||
33 | #include <panic.h> |
||
34 | #include <arch/i8259.h> |
||
35 | #include <func.h> |
||
36 | #include <cpu.h> |
||
37 | #include <arch/asm.h> |
||
38 | #include <mm/tlb.h> |
||
39 | |||
40 | #include <test.h> |
||
41 | #include <arch.h> |
||
42 | #include <arch/smp/atomic.h> |
||
43 | #include <proc/thread.h> |
||
44 | |||
91 | jermar | 45 | #define THREADS 150*2 |
46 | |||
47 | #define E_10e8 271828182 |
||
48 | #define PI_10e8 314159265 |
||
49 | |||
50 | static inline double sqrt(double x) { double v; __asm__ ("fsqrt\n" : "=t" (v) : "0" (x)); return v; } |
||
51 | |||
52 | static volatile int threads_ok; |
||
53 | static waitq_t can_start; |
||
54 | |||
86 | jermar | 55 | static void e(void *data) |
84 | vana | 56 | { |
91 | jermar | 57 | double e,d,le,f; |
58 | le=-1; |
||
59 | e=0; |
||
60 | f=1; |
||
61 | |||
62 | waitq_sleep(&can_start); |
||
63 | |||
64 | for(d=1;e!=le;d*=f,f+=1) { |
||
65 | le=e; |
||
66 | e=e+1/d; |
||
86 | jermar | 67 | } |
91 | jermar | 68 | |
69 | if((int)(100000000*e)==E_10e8) { |
||
70 | atomic_inc((int *) &threads_ok); |
||
71 | } |
||
72 | else |
||
73 | printf("tid%d: e*10e8=%d)\n", THREAD->tid, (int) 100000000*e); |
||
84 | vana | 74 | } |
75 | |||
91 | jermar | 76 | static void pi(void *data) |
77 | { |
||
78 | double lpi = -1, pi = 0; |
||
79 | double ab, ad; |
||
80 | int n; |
||
84 | vana | 81 | |
91 | jermar | 82 | waitq_sleep(&can_start); |
84 | vana | 83 | |
91 | jermar | 84 | for (n=2, ab = sqrt(2); lpi != pi; n *= 2, ab = ad) { |
85 | double sc, cd; |
||
86 | |||
87 | sc = sqrt(1 - (ab*ab/4)); |
||
88 | cd = 1 - sc; |
||
89 | ad = sqrt(ab*ab/4 + cd*cd); |
||
90 | lpi = pi; |
||
91 | pi = 2 * n * ad; |
||
92 | } |
||
93 | |||
94 | if((int)(100000000*pi)==PI_10e8) { |
||
95 | atomic_inc((int *) &threads_ok); |
||
96 | } |
||
97 | else |
||
98 | printf("tid%d: pi*10e8=%d)\n", THREAD->tid, (int) 100000000*pi); |
||
99 | } |
||
100 | |||
101 | |||
84 | vana | 102 | void test(void) |
103 | { |
||
86 | jermar | 104 | thread_t *t; |
105 | int i; |
||
84 | vana | 106 | |
91 | jermar | 107 | waitq_initialize(&can_start); |
108 | |||
109 | printf("FPU test #1\n"); |
||
110 | printf("Creating %d threads... ", THREADS); |
||
111 | |||
112 | for (i=0; i<THREADS/2; i++) { |
||
113 | if (!(t = thread_create(e, NULL, TASK, 0))) |
||
114 | panic("could not create thread\n"); |
||
86 | jermar | 115 | thread_ready(t); |
91 | jermar | 116 | if (!(t = thread_create(pi, NULL, TASK, 0))) |
117 | panic("could not create thread\n"); |
||
118 | thread_ready(t); |
||
86 | jermar | 119 | } |
91 | jermar | 120 | printf("ok\n"); |
90 | vana | 121 | |
91 | jermar | 122 | thread_sleep(1); |
123 | waitq_wakeup(&can_start, WAKEUP_ALL); |
||
84 | vana | 124 | |
91 | jermar | 125 | while (threads_ok != THREADS) |
126 | ; |
||
127 | |||
128 | printf("Test passed.\n"); |
||
84 | vana | 129 | } |