Open64 (mfef90, whirl2f, and IR tools)  TAG: version-openad; SVN changeset: 916
test_cray1_sim.c
Go to the documentation of this file.
00001 /*
00002 
00003   Copyright (C) 2000, 2001 Silicon Graphics, Inc.  All Rights Reserved.
00004 
00005   This program is free software; you can redistribute it and/or modify it
00006   under the terms of version 2 of the GNU General Public License as
00007   published by the Free Software Foundation.
00008 
00009   This program is distributed in the hope that it would be useful, but
00010   WITHOUT ANY WARRANTY; without even the implied warranty of
00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
00012 
00013   Further, this software is distributed without any warranty that it is
00014   free of the rightful claim of any third person regarding infringement 
00015   or the like.  Any license provided herein, whether implied or 
00016   otherwise, applies only to this software file.  Patent licenses, if 
00017   any, provided herein do not apply to combinations of this program with 
00018   other software, or any other product whatsoever.  
00019 
00020   You should have received a copy of the GNU General Public License along
00021   with this program; if not, write the Free Software Foundation, Inc., 59
00022   Temple Place - Suite 330, Boston MA 02111-1307, USA.
00023 
00024   Contact information:  Silicon Graphics, Inc., 1600 Amphitheatre Pky,
00025   Mountain View, CA 94043, or:
00026 
00027   http://www.sgi.com
00028 
00029   For further information regarding this notice, see:
00030 
00031   http://oss.sgi.com/projects/GenInfo/NoticeExplan
00032 
00033 */
00034 
00035 #include <stdio.h>
00036 
00037 #include "arith.h"
00038 
00039 main() {
00040         AR_HOST_SINT64  ans[4];
00041         AR_HOST_SINT64  arg[8];
00042         AR_HOST_SINT64  result[4];
00043 
00044         AR_TYPE         rtype,opndtype,ptype;
00045 
00046         char            line[256];
00047         char            prevfunc[9];
00048         char            func[9];
00049         char*           linep;
00050         char*           num;
00051 
00052         int             i,l,n;
00053         int             sum,xor;
00054         int             ierr;
00055         int             pass,okerrs,fail;
00056 
00057         int             rsize;
00058 
00059         FILE            *file;
00060 
00061         pass=okerrs=fail=0;
00062 
00063         file = fopen("results/cray1_sim_data","r");
00064         if(file == NULL) {
00065                 fprintf(stderr, "Could not open results/cray1_sim_data\n");
00066                 exit(0);
00067         }
00068 
00069         prevfunc[0]=0;
00070         while(fgets(line,256,file) != NULL) {
00071           i=l=0;
00072           while(line[l] != '(')
00073             func[i++]=line[l++];
00074           func[i]=0;
00075           if(strcmp(func,"STOP") == 0) exit(0);
00076           if(strcmp(func,prevfunc)) {
00077             printf("Testing %s intrinsic\n",func);
00078             strcpy(prevfunc,func);
00079           }
00080           l++;
00081           num=NULL;
00082           if(func[0]=='C') {
00083             if(func[1]=='D')
00084               if(strcmp(func,"CDABS") != 0)
00085                 rsize=4;
00086               else
00087                 rsize=2;
00088             else if(strcmp(func,"CABS")!=0 && strcmp(func,"COS")!=0)
00089               rsize=2;
00090             else
00091               rsize=1;
00092           }
00093           else if(func[0]=='D')
00094             rsize=2;
00095           else if(strcmp(func,"STRTOD") == 0) {
00096             rsize=1;
00097             num=line+l;
00098           }
00099           else if(strcmp(func,"STRTOLD") == 0) {
00100             rsize=2;
00101             num=line+l;
00102           }
00103           else if(strcmp(func,"MODULOD") == 0)
00104             rsize=2;
00105           else
00106             rsize=1;
00107           n=0;
00108           while(line[l] != ')') {
00109             if(num == NULL) {
00110               if(line[l]=='C') {
00111                 if(line[++l]=='D')
00112                   { n+=4; l++; }
00113                 else
00114                   n+=2;
00115               }
00116               else if(line[l++]=='D')
00117                 n+=2;
00118               else
00119                 n+=1;
00120               if(line[l]==',')
00121                 l++;
00122               else if(line[l]!=')') {
00123                 fprintf(stderr,"Invalid input on line:\n   %s\n",line);
00124                 n=0;
00125                 break;
00126               }
00127             }
00128             else {
00129               n=1;
00130               l++;
00131             }
00132           }
00133           if(n == 0) continue;
00134           linep=&line[++l];
00135           if(num == NULL) {
00136             for(i=0;i<n;i++)
00137               get_hex_input(&linep, &arg[i]);
00138           }
00139           else {
00140             line[l-1] = 0;
00141             memcpy((char*)(&arg[0])+8-sizeof(char*), &num, sizeof(char*));
00142           }
00143           for(i=0;i<rsize;i++)
00144             get_hex_input(&linep, &ans[i]);
00145           l = strlen(func);
00146           if(strncmp(func,"STRTO",5) == 0) {
00147             if(func[5] == 'D')
00148               rtype = AR_Float_Cray1_64;
00149             else
00150               rtype = AR_Float_Cray1_128;
00151             ierr=AR_convert_str_to_float((AR_DATA*)&result[0], &rtype, num);
00152             num[strlen(num)] = ')';
00153           }
00154           else if(strncmp(&func[l-3],"LOG",3) == 0) {
00155             if(func[0] == 'A')
00156               rtype = AR_Float_Cray1_64;
00157             else if(func[0] == 'D')
00158               rtype = AR_Float_Cray1_128;
00159             else if(func[1] == 'L')
00160               rtype = AR_Complex_Cray1_64;
00161             else
00162               rtype = AR_Complex_Cray1_128;
00163             ierr = AR_log((AR_DATA*)&result[0], &rtype, (AR_DATA*)&arg[0], &rtype);
00164           }
00165           else if(strncmp(&func[l-3],"EXP",3) == 0) {
00166             if(func[0] == 'E')
00167               rtype = AR_Float_Cray1_64;
00168             else if(func[0] == 'D')
00169               rtype = AR_Float_Cray1_128;
00170             else if(func[1] == 'E')
00171               rtype = AR_Complex_Cray1_64;
00172             else
00173               rtype = AR_Complex_Cray1_128;
00174             ierr = AR_exp((AR_DATA*)&result[0], &rtype, (AR_DATA*)&arg[0], &rtype);
00175           }
00176           else if(strncmp(&func[l-4],"SQRT",4) == 0) {
00177             if(func[0] == 'S')
00178               rtype = AR_Float_Cray1_64;
00179             else if(func[0] == 'D')
00180               rtype = AR_Float_Cray1_128;
00181             else if(func[1] == 'S')
00182               rtype = AR_Complex_Cray1_64;
00183             else
00184               rtype = AR_Complex_Cray1_128;
00185             ierr = AR_sqrt((AR_DATA*)&result[0], &rtype, (AR_DATA*)&arg[0], &rtype);
00186           }
00187           else if(strncmp(&func[l-3],"ABS",3) == 0) {
00188             if(func[1] == 'A') {
00189               rtype = AR_Float_Cray1_64;
00190               opndtype = AR_Complex_Cray1_64;
00191             }
00192             else {
00193               rtype = AR_Float_Cray1_128;
00194               opndtype = AR_Complex_Cray1_128;
00195             }
00196             ierr = AR_cabs((AR_DATA*)&result[0], &rtype, (AR_DATA*)&arg[0], &opndtype);
00197           }
00198           else if(strncmp(&func[l-3],"TOI",3)==0 ||
00199                   strncmp(&func[l-3],"TOR",3)==0) {
00200             if(func[0] == 'I') {
00201               rtype = AR_Int_64_S;
00202               opndtype = AR_Int_64_S;
00203             }
00204             else if(func[0] == 'R') {
00205               rtype = AR_Float_Cray1_64;
00206               opndtype = AR_Float_Cray1_64;
00207             }
00208             else if(func[0] == 'D') {
00209               rtype = AR_Float_Cray1_128;
00210               opndtype = AR_Float_Cray1_128;
00211             }
00212             else if(func[1] == 'T') {
00213               rtype = AR_Complex_Cray1_64;
00214               opndtype = AR_Complex_Cray1_64;
00215             }
00216             else {
00217               rtype = AR_Complex_Cray1_128;
00218               opndtype = AR_Complex_Cray1_128;
00219             }
00220             if(func[l-1] == 'I')
00221               ptype = AR_Int_64_S;
00222             else
00223               ptype = AR_Float_Cray1_64;
00224             ierr = AR_power((AR_DATA*)&result[0], &rtype, (AR_DATA*)&arg[0], &opndtype, (AR_DATA*)&arg[n-1], &ptype);
00225           }
00226           else if(strncmp(&func[0],"MODULO",6)==0 ) {
00227             if(func[6] == 'I')
00228               rtype = AR_Int_46_S;
00229             else if(func[6] == 'J')
00230               rtype = AR_Int_64_S;
00231             else if(func[6] == 'S')
00232               rtype = AR_Float_Cray1_64;
00233             else if(func[6] == 'D')
00234               rtype = AR_Float_Cray1_128;
00235             ierr = AR_Modulo((AR_DATA*)&result[0], &rtype, (AR_DATA*)&arg[0], &rtype, (AR_DATA*)&arg[n>>1], &rtype);
00236           }
00237           else if(strncmp(&func[0],"SELREALK",8)==0 ) {
00238             rtype = AR_Int_64_S;
00239             if(arg[0] < 0 && arg[1] < 0)
00240               ierr = AR_selected_real_kind((AR_DATA*)&result[0], &rtype, (AR_DATA*)NULL, &rtype, (AR_DATA*)NULL, &rtype);
00241             else if(arg[0] < 0)
00242               ierr = AR_selected_real_kind((AR_DATA*)&result[0], &rtype, (AR_DATA*)NULL, &rtype, (AR_DATA*)&arg[1], &rtype);
00243             else if(arg[1] < 0)
00244               ierr = AR_selected_real_kind((AR_DATA*)&result[0], &rtype, (AR_DATA*)&arg[0], &rtype, (AR_DATA*)NULL, &rtype);
00245             else
00246               ierr = AR_selected_real_kind((AR_DATA*)&result[0], &rtype, (AR_DATA*)&arg[0], &rtype, (AR_DATA*)&arg[1], &rtype);
00247           }
00248           else {
00249             if(func[0] == 'D') {
00250               rtype = AR_Float_Cray1_128;
00251               opndtype = AR_Float_Cray1_128;
00252               ptype = AR_Float_Cray1_128;
00253             }
00254             else if(func[1] == 'T') {
00255               rtype = AR_Complex_Cray1_64;
00256               opndtype = AR_Complex_Cray1_64;
00257               ptype = AR_Complex_Cray1_64;
00258             }
00259             else {
00260               rtype = AR_Complex_Cray1_128;
00261               opndtype = AR_Complex_Cray1_128;
00262               ptype = AR_Complex_Cray1_128;
00263             }
00264             ierr = AR_power((AR_DATA*)&result[0], &rtype, (AR_DATA*)&arg[0], &opndtype, (AR_DATA*)&arg[n>>1], &ptype);
00265           }
00266           ierr &= (AR_STAT_OVERFLOW|AR_STAT_UNDERFLOW|AR_STAT_UNDEFINED|AR_STAT_INVALID_TYPE);
00267           for(xor=0, i=0; i<rsize; i++)
00268              xor |= (result[i]^ans[i]);
00269           if(ierr!=0 || xor!=0) {
00270             if(ierr!=0 && ans[0]==ierr)
00271               okerrs++;
00272             else {
00273               fprintf(stderr,"\n***** ERROR *** ERROR *** ERROR *** ERROR *****\n");
00274               fprintf(stderr,"   Intrinsic result does not match expected result on input line:\n   %s\n",line);
00275               if(ierr != 0)
00276                 fprintf(stderr,"   The intrinsic returned an error code = 0%o\n",ierr);
00277               else {
00278                 fprintf(stderr,"   The intrinsic returned a result of:\n   ");
00279                 for(i=0; i<rsize; i++)
00280                   fprintf(stderr," %8.8x %8.8x",result[i]);
00281                 fprintf(stderr,"\n");
00282               }
00283               fail++;
00284             }
00285           }
00286           else
00287             pass++;
00288         }
00289 
00290         printf("Intrinsic test results:\n%6d passed\n%6d passed with expected error condition\n%6d FAILED!!!\n",pass,okerrs,fail);
00291         exit(fail);
00292 
00293 }
00294 
00295 get_hex_input(str, arg)
00296 char**  str;
00297 AR_HOST_SINT64 *arg;
00298 {
00299         char*   line;
00300 
00301         int     h1,h2,h3,h4;
00302 
00303         line = *str;
00304 
00305         while(*line == ' ') line++;
00306 
00307         h1=(*line>='A')?*line-'A'+10:*line-'0'; line++;
00308         h2=(*line>='A')?*line-'A'+10:*line-'0'; line++;
00309         h3=(*line>='A')?*line-'A'+10:*line-'0'; line++;
00310         h4=(*line>='A')?*line-'A'+10:*line-'0'; line++;
00311         (*arg)  = (AR_HOST_SINT64)((h1<<12) | (h2<<8) | (h3<<4) | h4)<<48;
00312 
00313         h1=(*line>='A')?*line-'A'+10:*line-'0'; line++;
00314         h2=(*line>='A')?*line-'A'+10:*line-'0'; line++;
00315         h3=(*line>='A')?*line-'A'+10:*line-'0'; line++;
00316         h4=(*line>='A')?*line-'A'+10:*line-'0'; line++;
00317         (*arg) |= (AR_HOST_SINT64)((h1<<12) | (h2<<8) | (h3<<4) | h4)<<32;
00318 
00319         h1=(*line>='A')?*line-'A'+10:*line-'0'; line++;
00320         h2=(*line>='A')?*line-'A'+10:*line-'0'; line++;
00321         h3=(*line>='A')?*line-'A'+10:*line-'0'; line++;
00322         h4=(*line>='A')?*line-'A'+10:*line-'0'; line++;
00323         (*arg) |= (AR_HOST_SINT64)((h1<<12) | (h2<<8) | (h3<<4) | h4)<<16;
00324 
00325         h1=(*line>='A')?*line-'A'+10:*line-'0'; line++;
00326         h2=(*line>='A')?*line-'A'+10:*line-'0'; line++;
00327         h3=(*line>='A')?*line-'A'+10:*line-'0'; line++;
00328         h4=(*line>='A')?*line-'A'+10:*line-'0'; line++;
00329         (*arg) |= (AR_HOST_SINT64)((h1<<12) | (h2<<8) | (h3<<4) | h4)<<0;
00330 
00331         *str = line;
00332 }
00333 
00334 
00335 static char USMID [] = "\n%Z%%M%        %I%     %G% %U%\n";
00336 static char rcsid [] = "$Id: test_cray1_sim.c,v 1.1.1.1 2002-05-22 20:06:19 dsystem Exp $";
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines