Open64 (mfef90, whirl2f, and IR tools)  TAG: version-openad; SVN changeset: 916
test_mpp_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         AR_HOST_SINT64  xor;
00044 
00045         AR_TYPE         rtype,opndtype,ptype;
00046 
00047         char            line[256];
00048         char            prevfunc[9];
00049         char            func[9];
00050         char*           linep;
00051         char*           num;
00052 
00053         int             i,l,n;
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/mpp_sim_data","r");
00064         if(file == NULL) {
00065           fprintf(stderr,"Could not open results/mpp_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,"STRTOF") == 0) {
00096             rsize=1;
00097             num=line+l;
00098           }
00099           else if(strcmp(func,"STRTOD") == 0) {
00100             rsize=1;
00101             num=line+l;
00102           }
00103           else if(strcmp(func,"STRTOLD") == 0) {
00104             rsize=2;
00105             num=line+l;
00106           }
00107           else
00108             rsize=1;
00109           n=0;
00110           while(line[l] != ')') {
00111             if(num == NULL) {
00112               if(line[l]=='C') {
00113                 if(line[++l]=='D')
00114                   { n+=4; l++; }
00115                 else
00116                   n+=2;
00117               }
00118               else if(line[l++]=='D')
00119                 n+=2;
00120               else
00121                 n+=1;
00122               if(line[l]==',')
00123                 l++;
00124               else if(line[l]!=')') {
00125                 fprintf(stderr,"Invalid input on line:\n   %s\n",line);
00126                 n=0;
00127                 break;
00128               }
00129             }
00130             else {
00131               n=1;
00132               l++;
00133             }
00134           }
00135           if(n == 0) continue;
00136           linep=&line[++l];
00137           if(num == NULL) {
00138             for(i=0;i<n;i++)
00139               get_hex_input(&linep, &arg[i]);
00140           }
00141           else {
00142             line[l-1] = 0;
00143             memcpy((char*)(&arg[0])+8-sizeof(char*), &num, sizeof(char*));
00144           }
00145           for(i=0;i<rsize;i++)
00146             get_hex_input(&linep, &ans[i]);
00147           l = strlen(func);
00148           if(strncmp(func,"STRTO",5) == 0) {
00149             if(func[5] == 'F')
00150               rtype = AR_Float_IEEE_NR_32;
00151             else if(func[5] == 'D')
00152               rtype = AR_Float_IEEE_NR_64;
00153             else
00154               rtype = AR_Float_IEEE_NR_128;
00155             ierr=AR_convert_str_to_float((AR_DATA*)&result[0], &rtype, num);
00156             num[strlen(num)] = ')';
00157           }
00158           else if(strncmp(&func[l-3],"LOG",3) == 0) {
00159             if(func[0] == 'A')
00160               rtype = AR_Float_IEEE_NR_64;
00161             else if(func[0] == 'D')
00162               rtype = AR_Float_IEEE_NR_128;
00163             else if(func[0] == 'H')
00164               rtype = AR_Float_IEEE_NR_32;
00165             else if(func[1] == 'L')
00166               rtype = AR_Complex_IEEE_NR_64;
00167             else
00168               rtype = AR_Complex_IEEE_NR_128;
00169             ierr = AR_log((AR_DATA*)&result[0], &rtype, (AR_DATA*)&arg[0], &rtype);
00170           }
00171           else if(strncmp(&func[l-3],"EXP",3) == 0) {
00172             if(func[0] == 'E')
00173               rtype = AR_Float_IEEE_NR_64;
00174             else if(func[0] == 'D')
00175               rtype = AR_Float_IEEE_NR_128;
00176             else if(func[0] == 'H')
00177               rtype = AR_Float_IEEE_NR_32;
00178             else if(func[1] == 'E')
00179               rtype = AR_Complex_IEEE_NR_64;
00180             else
00181               rtype = AR_Complex_IEEE_NR_128;
00182             ierr = AR_exp((AR_DATA*)&result[0], &rtype, (AR_DATA*)&arg[0], &rtype);
00183             if(func[0] == 'C')          /* Fix order-of-operation diff in cexp */
00184               if((ierr&AR_STAT_UNDEFINED) && ans[0]==AR_STAT_OVERFLOW)
00185                 ierr = (ierr^AR_STAT_UNDEFINED) | AR_STAT_OVERFLOW;
00186               else if((ierr&AR_STAT_OVERFLOW) && ans[0]==AR_STAT_UNDEFINED)
00187                 ierr = (ierr^AR_STAT_OVERFLOW) | AR_STAT_UNDEFINED;
00188           }
00189           else if(strncmp(&func[l-4],"SQRT",4) == 0) {
00190             if(func[0] == 'S')
00191               rtype = AR_Float_IEEE_NR_64;
00192             else if(func[0] == 'D')
00193               rtype = AR_Float_IEEE_NR_128;
00194             else if(func[0] == 'H')
00195               rtype = AR_Float_IEEE_NR_32;
00196             else if(func[1] == 'S')
00197               rtype = AR_Complex_IEEE_NR_64;
00198             else
00199               rtype = AR_Complex_IEEE_NR_128;
00200             ierr = AR_sqrt((AR_DATA*)&result[0], &rtype, (AR_DATA*)&arg[0], &rtype);
00201           }
00202           else if(strncmp(&func[l-3],"ABS",3) == 0) {
00203             if(func[1] == 'A') {
00204               rtype = AR_Float_IEEE_NR_64;
00205               opndtype = AR_Complex_IEEE_NR_64;
00206             }
00207             else {
00208               rtype = AR_Float_IEEE_NR_128;
00209               opndtype = AR_Complex_IEEE_NR_128;
00210             }
00211             ierr = AR_cabs((AR_DATA*)&result[0], &rtype, (AR_DATA*)&arg[0], &opndtype);
00212           }
00213           else if(strncmp(&func[l-3],"TOI",3)==0 ||
00214                   strncmp(&func[l-3],"TOR",3)==0) {
00215             if(func[0] == 'I') {
00216               rtype = AR_Int_64_S;
00217               opndtype = AR_Int_64_S;
00218             }
00219             else if(func[0] == 'R') {
00220               rtype = AR_Float_IEEE_NR_64;
00221               opndtype = AR_Float_IEEE_NR_64;
00222             }
00223             else if(func[0] == 'H') {
00224               rtype = AR_Float_IEEE_NR_32;
00225               opndtype = AR_Float_IEEE_NR_32;
00226             }
00227             else if(func[0] == 'D') {
00228               rtype = AR_Float_IEEE_NR_128;
00229               opndtype = AR_Float_IEEE_NR_128;
00230             }
00231             else if(func[1] == 'T') {
00232               rtype = AR_Complex_IEEE_NR_64;
00233               opndtype = AR_Complex_IEEE_NR_64;
00234             }
00235             else {
00236               rtype = AR_Complex_IEEE_NR_128;
00237               opndtype = AR_Complex_IEEE_NR_128;
00238             }
00239             if(func[l-1] == 'I')
00240               ptype = AR_Int_64_S;
00241             else
00242               ptype = AR_Float_IEEE_NR_64;
00243             ierr = AR_power((AR_DATA*)&result[0], &rtype, (AR_DATA*)&arg[0], &opndtype, (AR_DATA*)&arg[n-1], &ptype);
00244           }
00245           else if(strncmp(&func[0],"MODULO",6)==0 ) {
00246             if(func[6] == 'I')
00247               rtype = AR_Int_32_S;
00248             else if(func[6] == 'J')
00249               rtype = AR_Int_64_S;
00250             else if(func[6] == 'F')
00251               rtype = AR_Float_IEEE_NR_32;
00252             else if(func[6] == 'S')
00253               rtype = AR_Float_IEEE_NR_64;
00254             ierr = AR_Modulo((AR_DATA*)&result[0], &rtype, (AR_DATA*)&arg[0], &rtype, (AR_DATA*)&arg[1], &rtype);
00255           }
00256           else if(strncmp(&func[0],"SELREALK",8)==0 ) {
00257             rtype = AR_Int_64_S;
00258             if(arg[0] < 0 && arg[1] < 0)
00259               ierr = AR_selected_real_kind((AR_DATA*)&result[0], &rtype, (AR_DATA*)NULL, &rtype, (AR_DATA*)NULL, &rtype);
00260             else if(arg[0] < 0)
00261               ierr = AR_selected_real_kind((AR_DATA*)&result[0], &rtype, (AR_DATA*)NULL, &rtype, (AR_DATA*)&arg[1], &rtype);
00262             else if(arg[1] < 0)
00263               ierr = AR_selected_real_kind((AR_DATA*)&result[0], &rtype, (AR_DATA*)&arg[0], &rtype, (AR_DATA*)NULL, &rtype);
00264             else
00265               ierr = AR_selected_real_kind((AR_DATA*)&result[0], &rtype, (AR_DATA*)&arg[0], &rtype, (AR_DATA*)&arg[1], &rtype);
00266           }
00267           else {
00268             if(func[0] == 'D') {
00269               rtype = AR_Float_IEEE_NR_128;
00270               opndtype = AR_Float_IEEE_NR_128;
00271               ptype = AR_Float_IEEE_NR_128;
00272             }
00273             else if(func[1] == 'T') {
00274               rtype = AR_Complex_IEEE_NR_64;
00275               opndtype = AR_Complex_IEEE_NR_64;
00276               ptype = AR_Complex_IEEE_NR_64;
00277             }
00278             else {
00279               rtype = AR_Complex_IEEE_NR_128;
00280               opndtype = AR_Complex_IEEE_NR_128;
00281               ptype = AR_Complex_IEEE_NR_128;
00282             }
00283             ierr = AR_power((AR_DATA*)&result[0], &rtype, (AR_DATA*)&arg[0], &opndtype, (AR_DATA*)&arg[n>>1], &ptype);
00284           }
00285           ierr &= (AR_STAT_OVERFLOW|AR_STAT_UNDERFLOW|AR_STAT_UNDEFINED|AR_STAT_INVALID_TYPE);
00286           if(rsize > 1 && (result[0]>>48) == 0x7fff)
00287              xor = result[0]^ans[0];
00288           else
00289              for(xor=0, i=0; i<rsize; i++)
00290                 xor |= (result[i]^ans[i]);
00291           if(ierr!=0 || xor!=0) {
00292             if(ierr!=0 && ans[0]==ierr)
00293               okerrs++;
00294             else {
00295               fprintf(stderr,"\n***** ERROR *** ERROR *** ERROR *** ERROR *****\n");
00296               fprintf(stderr,"   Intrinsic result does not match expected result on input line:\n   %s\n",line);
00297               if(ierr != 0)
00298                 fprintf(stderr,"   The intrinsic returned an error code = 0%o\n",ierr);
00299               else {
00300                 fprintf(stderr,"   The intrinsic returned a result of:\n   ");
00301                 for(i=0; i<rsize; i++)
00302                   fprintf(stderr," %16.16llx",result[i]);
00303                 fprintf(stderr,"\n");
00304               }
00305               fail++;
00306             }
00307           }
00308           else
00309             pass++;
00310         }
00311 
00312         printf("Intrinsic test results:\n%6d passed\n%6d passed with expected error condition\n%6d FAILED!!!\n",pass,okerrs,fail);
00313         exit(fail);
00314 
00315 }
00316 
00317 get_hex_input(str, arg)
00318 char**  str;
00319 AR_HOST_SINT64 *arg;
00320 {
00321         char*   line;
00322 
00323         int     h1,h2,h3,h4;
00324 
00325         line = *str;
00326 
00327         while(*line == ' ') line++;
00328 
00329         h1=(*line>='A')?*line-'A'+10:*line-'0'; line++;
00330         h2=(*line>='A')?*line-'A'+10:*line-'0'; line++;
00331         h3=(*line>='A')?*line-'A'+10:*line-'0'; line++;
00332         h4=(*line>='A')?*line-'A'+10:*line-'0'; line++;
00333         *arg  = (AR_HOST_SINT64)((h1<<12) | (h2<<8) | (h3<<4) | h4)<<16;
00334 
00335         h1=(*line>='A')?*line-'A'+10:*line-'0'; line++;
00336         h2=(*line>='A')?*line-'A'+10:*line-'0'; line++;
00337         h3=(*line>='A')?*line-'A'+10:*line-'0'; line++;
00338         h4=(*line>='A')?*line-'A'+10:*line-'0'; line++;
00339         *arg |= (AR_HOST_SINT64)((h1<<12) | (h2<<8) | (h3<<4) | h4);
00340 
00341         if((*line>='0' && *line<='9') ||
00342            (*line>='A' && *line<='F')) {
00343           *arg <<= 32;
00344           h1=(*line>='A')?*line-'A'+10:*line-'0'; line++;
00345           h2=(*line>='A')?*line-'A'+10:*line-'0'; line++;
00346           h3=(*line>='A')?*line-'A'+10:*line-'0'; line++;
00347           h4=(*line>='A')?*line-'A'+10:*line-'0'; line++;
00348           *arg |= (AR_HOST_SINT64)((h1<<12) | (h2<<8) | (h3<<4) | h4)<<16;
00349 
00350           h1=(*line>='A')?*line-'A'+10:*line-'0'; line++;
00351           h2=(*line>='A')?*line-'A'+10:*line-'0'; line++;
00352           h3=(*line>='A')?*line-'A'+10:*line-'0'; line++;
00353           h4=(*line>='A')?*line-'A'+10:*line-'0'; line++;
00354           *arg |= (AR_HOST_SINT64)((h1<<12) | (h2<<8) | (h3<<4) | h4);
00355         }
00356 
00357         *str = line;
00358 }
00359 
00360 
00361 static char USMID [] = "\n%Z%%M%        %I%     %G% %U%\n";
00362 static char rcsid [] = "$Id: test_mpp_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