Changeset c01bd280 in mainline


Ignore:
Timestamp:
2005-05-19T23:19:06Z (20 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
54ca3523
Parents:
af22f158
Message:

Rename test/fpu/fpu0 to test/fpu/fpu1.
Enhance and beautify FPU test #1.
Add pi calculation to FPU test #1.

Files:
1 edited
1 moved

Legend:

Unmodified
Added
Removed
  • src/Makefile.config

    raf22f158 rc01bd280  
    66
    77# Support for symetric multiprocessors
    8 #SMP=__SMP__
     8SMP=__SMP__
    99
    1010# Improved support for hyperthreading
     
    3030#TEST_DIR=synch/semaphore1/
    3131#TEST_DIR=synch/semaphore2/
    32 TEST_DIR=fpu/fpu0
     32TEST_DIR=fpu/fpu1
  • test/fpu/fpu1/test.c

    raf22f158 rc01bd280  
    11/*
    22 * Copyright (C) 2005 Jakub Vana
     3 * Copyright (C) 2005 Jakub Jermar
    34 * All rights reserved.
    45 *
     
    4243#include <proc/thread.h>
    4344
     45#define THREADS         150*2
     46
     47#define E_10e8  271828182
     48#define PI_10e8 314159265
     49
     50static inline double sqrt(double x) { double v; __asm__ ("fsqrt\n" : "=t" (v) : "0" (x)); return v; }
     51
     52static volatile int threads_ok;
     53static waitq_t can_start;
     54
    4455static void e(void *data)
    4556{
    46         int i;
    47         while(1)
    48         {
    49                 double e,d,le,f;
    50                 le=-1;
    51                 e=0;
    52                 f=1;
    53                 for(i=0,d=1;e!=le;d*=f,f+=1,i++)
    54                 {
    55                         le=e;
    56                         e=e+1/d;
    57                         if (i>20000000)
    58                         {
    59 //                              printf("tid%d: e LOOPING\n", THREAD->tid);
    60                                 putchar('!');
    61                                 i = 0;
    62                         }
    63                        
    64                 }
    65    
    66                 if((int)(100000000*e)==271828182) printf("tid%d: e OK\n", THREAD->tid);
    67                 else panic("tid%d: e FAILED (100000000*e=%d)\n", THREAD->tid, (int) 100000000*e);
     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;
    6867        }
     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);
    6974}
    7075
     76static void pi(void *data)
     77{
     78        double lpi = -1, pi = 0;
     79        double ab, ad;
     80        int n;
     81
     82        waitq_sleep(&can_start);
     83
     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}
    71100
    72101
     
    76105        int i;
    77106
    78         for (i=0; i<4; i++) { 
    79                 t = thread_create(e, NULL, TASK, 0);
     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");
     115                thread_ready(t);
     116                if (!(t = thread_create(pi, NULL, TASK, 0)))
     117                        panic("could not create thread\n");
    80118                thread_ready(t);
    81119        }
     120        printf("ok\n");
    82121       
    83         while(1);
     122        thread_sleep(1);
     123        waitq_wakeup(&can_start, WAKEUP_ALL);
    84124
     125        while (threads_ok != THREADS)
     126                ;
     127               
     128        printf("Test passed.\n");
    85129}
Note: See TracChangeset for help on using the changeset viewer.