Changeset 34db7fa in mainline for kernel/test/fpu/fpu1.c
- Timestamp:
- 2006-12-12T12:32:02Z (18 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 96348adc
- Parents:
- df496c5
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/test/fpu/fpu1.c
rdf496c5 r34db7fa 28 28 */ 29 29 30 #if (defined(ia32) || defined(amd64) || defined(ia64) || defined(ia32xen)) 31 30 32 #include <print.h> 31 33 #include <debug.h> … … 39 41 #include <arch/arch.h> 40 42 41 #ifdef CONFIG_BENCH 42 #include <arch/cycle.h> 43 #endif 44 45 #if (defined(ia32) || defined(amd64) || defined(ia64) || defined(ia32xen)) 46 47 #define THREADS 150*2 43 44 #define THREADS 150 48 45 #define ATTEMPTS 100 49 46 … … 53 50 54 51 #ifdef KERN_ia32_ARCH_H_ 55 static inline double sqrt(double x) { double v; __asm__ ("fsqrt\n" : "=t" (v) : "0" (x)); return v; } 52 static inline double sqrt(double x) 53 { 54 double v; 55 56 asm ( 57 "fsqrt\n" 58 : "=t" (v) 59 : "0" (x) 60 ); 61 62 return v; 63 } 56 64 #endif 57 65 58 66 #ifdef KERN_amd64_ARCH_H_ 59 static inline double sqrt(double x) { double v; __asm__ ("fsqrt\n" : "=t" (v) : "0" (x)); return v; } 67 static inline double sqrt(double x) 68 { 69 double v; 70 71 asm ( 72 "fsqrt\n" 73 : "=t" (v) 74 : "0" (x) 75 ); 76 77 return v; 78 } 60 79 #endif 61 80 62 81 #ifdef KERN_ia64_ARCH_H_ 82 83 #undef PI_10e8 84 #define PI_10e8 3141592 85 63 86 static inline long double sqrt(long double a) 64 87 { … … 66 89 long double lx = 0; 67 90 68 if(a<0.00000000000000001) return 0; 91 if (a < 0.00000000000000001) 92 return 0; 69 93 70 while(x !=lx)71 {72 lx=x;73 x=(x+(a/x))/2;74 }94 while(x != lx) { 95 lx = x; 96 x = (x + (a / x)) / 2; 97 } 98 75 99 return x; 76 100 } … … 78 102 79 103 80 81 104 static atomic_t threads_ok; 105 static atomic_t threads_fault; 82 106 static waitq_t can_start; 83 107 … … 92 116 93 117 for (i = 0; i<ATTEMPTS; i++) { 94 le=-1; 95 e=0; 96 f=1; 97 98 for(d=1;e!=le;d*=f,f+=1) { 99 le=e; 100 e=e+1/d; 101 } 102 103 if((int)(100000000*e)!=E_10e8) 104 panic("tid%d: e*10e8=%zd should be %zd\n", THREAD->tid, (unative_t) (100000000*e),(unative_t) E_10e8); 105 } 106 107 printf("tid%d: e*10e8=%zd should be %zd\n", THREAD->tid, (unative_t) (100000000*e),(unative_t) E_10e8); 118 le = -1; 119 e = 0; 120 f = 1; 121 122 for (d = 1; e != le; d *= f, f += 1) { 123 le = e; 124 e = e + 1 / d; 125 } 126 127 if ((int) (100000000 * e) != E_10e8) { 128 printf("tid%d: e*10e8=%zd should be %zd\n", THREAD->tid, (unative_t) (100000000 * e), (unative_t) E_10e8); 129 atomic_inc(&threads_fault); 130 break; 131 } 132 } 108 133 atomic_inc(&threads_ok); 109 134 } … … 111 136 static void pi(void *data) 112 137 { 113 114 #ifdef KERN_ia64_ARCH_H_115 #undef PI_10e8116 #define PI_10e8 3141592117 #endif118 119 120 138 int i; 121 139 double lpi, pi; … … 126 144 waitq_sleep(&can_start); 127 145 128 129 for (i = 0; i<ATTEMPTS; i++) { 146 for (i = 0; i < ATTEMPTS; i++) { 130 147 lpi = -1; 131 148 pi = 0; 132 149 133 for (n =2, ab = sqrt(2); lpi != pi; n *= 2, ab = ad) {150 for (n = 2, ab = sqrt(2); lpi != pi; n *= 2, ab = ad) { 134 151 double sc, cd; 135 152 136 sc = sqrt(1 - (ab *ab/4));153 sc = sqrt(1 - (ab * ab / 4)); 137 154 cd = 1 - sc; 138 ad = sqrt(ab *ab/4 + cd*cd);155 ad = sqrt(ab * ab / 4 + cd * cd); 139 156 lpi = pi; 140 157 pi = 2 * n * ad; … … 142 159 143 160 #ifdef KERN_ia64_ARCH_H_ 144 if((int)(1000000*pi)!=PI_10e8) 145 panic("tid%d: pi*10e8=%zd should be %zd\n", THREAD->tid, (unative_t) (1000000*pi),(unative_t) (PI_10e8/100)); 161 if ((int) (1000000 * pi) != PI_10e8) { 162 printf("tid%d: pi*10e8=%zd should be %zd\n", THREAD->tid, (unative_t) (1000000 * pi), (unative_t) (PI_10e8 / 100)); 163 atomic_inc(&threads_fault); 164 break; 165 } 146 166 #else 147 if ((int)(100000000*pi)!=PI_10e8)148 p anic("tid%d: pi*10e8=%zd should be %zd\n", THREAD->tid, (unative_t) (100000000*pi),(unative_t) PI_10e8);149 #endif 150 151 }152 153 printf("tid%d: pi*10e8=%zd should be %zd\n", THREAD->tid, (unative_t) (100000000*pi),(unative_t) PI_10e8);167 if ((int) (100000000 * pi) != PI_10e8) { 168 printf("tid%d: pi*10e8=%zd should be %zd\n", THREAD->tid, (unative_t) (100000000 * pi), (unative_t) PI_10e8); 169 atomic_inc(&threads_fault); 170 break; 171 } 172 #endif 173 } 154 174 atomic_inc(&threads_ok); 155 175 } 156 176 157 void test_fpu1(void) 158 { 159 #ifdef CONFIG_BENCH 160 uint64_t t0 = get_cycle(); 161 #endif 162 thread_t *t; 163 int i; 177 char * test_fpu1(void) 178 { 179 unsigned int i, total = 0; 164 180 165 181 waitq_initialize(&can_start); 166 167 printf("FPU test #1\n"); 168 printf("Creating %d threads... ", THREADS); 169 170 for (i=0; i<THREADS/2; i++) { 171 if (!(t = thread_create(e, NULL, TASK, 0, "e"))) 172 panic("could not create thread\n"); 182 atomic_set(&threads_ok, 0); 183 atomic_set(&threads_fault, 0); 184 printf("Creating %d threads... ", 2 * THREADS); 185 186 for (i = 0; i < THREADS; i++) { 187 thread_t *t; 188 189 if (!(t = thread_create(e, NULL, TASK, 0, "e"))) { 190 printf("could not create thread %d\n", 2 * i); 191 break; 192 } 173 193 thread_ready(t); 174 if (!(t = thread_create(pi, NULL, TASK, 0, "pi"))) 175 panic("could not create thread\n"); 194 total++; 195 196 if (!(t = thread_create(pi, NULL, TASK, 0, "pi"))) { 197 printf("could not create thread %d\n", 2 * i + 1); 198 break; 199 } 176 200 thread_ready(t); 201 total++; 177 202 } 178 203 printf("ok\n"); … … 180 205 thread_sleep(1); 181 206 waitq_wakeup(&can_start, WAKEUP_ALL); 182 183 while (atomic_get(&threads_ok) != THREADS) 184 ; 185 186 printf("Test passed.\n"); 187 #ifdef CONFIG_BENCH 188 uint64_t dt = get_cycle() - t0; 189 printf("Time: %.*d cycles\n", sizeof(dt) * 2, dt); 190 #endif 191 } 192 193 #else 194 195 void test_fpu1(void) 196 { 197 printf("This test is available only on Intel/AMD platforms."); 198 } 199 200 #endif 207 208 while (atomic_get(&threads_ok) != total) { 209 printf("Threads left: %d\n", total - atomic_get(&threads_ok)); 210 thread_sleep(1); 211 } 212 213 if (atomic_get(&threads_fault) == 0) 214 return NULL; 215 216 return "Test failed"; 217 } 218 219 #endif
Note:
See TracChangeset
for help on using the changeset viewer.