Open64 (mfef90, whirl2f, and IR tools)
TAG: version-openad; SVN changeset: 916
|
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 #include <ctype.h> 00037 00038 #include "arith.h" 00039 00040 main() { 00041 AR_HOST_SINT64 ans[4]; 00042 AR_HOST_SINT64 arg[8]; 00043 AR_HOST_SINT64 result[4]; 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 int rsize; 00057 00058 AR_HOST_SINT64 xor; 00059 00060 FILE *file; 00061 00062 pass=okerrs=fail=0; 00063 00064 file = fopen("results/tsieee_sim_data","r"); 00065 if(file == NULL) { 00066 fprintf(stderr, "Could not open results/tsieee_sim_data\n"); 00067 exit(0); 00068 } 00069 00070 prevfunc[0]=0; 00071 while(fgets(line,256,file) != NULL) { 00072 i=l=0; 00073 while(line[l] != '(') 00074 func[i++]=line[l++]; 00075 func[i]=0; 00076 if(strcmp(func,"STOP") == 0) exit(0); 00077 if(strcmp(func,prevfunc)) { 00078 printf("Testing %s intrinsic\n",func); 00079 strcpy(prevfunc,func); 00080 } 00081 l++; 00082 num=NULL; 00083 if(func[0]=='C') { 00084 if(func[1]=='X') 00085 rsize=4; 00086 else if(strcmp(func,"COS")!=0 && strcmp(func,"COSH")!=0) 00087 rsize=2; 00088 else 00089 rsize=1; 00090 } 00091 else if(func[0]=='X' && func[1] == 'D') 00092 rsize=2; 00093 else if(strcmp(func,"STRTOD") == 0) { 00094 rsize=1; 00095 num=line+l; 00096 } 00097 else if(strcmp(func,"STRTOF") == 0) { 00098 rsize=1; 00099 num=line+l; 00100 } 00101 else if(strcmp(func,"STRTOLD") == 0) { 00102 rsize=2; 00103 num=line+l; 00104 } 00105 else if(strcmp(func,"STRTOXD") == 0) { 00106 rsize=2; 00107 num=line+l; 00108 } 00109 else 00110 rsize=1; 00111 n=0; 00112 while(line[l] != ')') { 00113 if(num == NULL) { 00114 if(line[l]=='C') { 00115 if(line[++l]=='X') { 00116 n+=4; l++; 00117 if(line[l]=='D') l++; 00118 } 00119 else 00120 n+=2; 00121 } 00122 else if(line[l++]=='X') { 00123 if(line[l]=='D') 00124 { n+=2; l++; } 00125 else 00126 n+=1; 00127 } 00128 else 00129 n+=1; 00130 if(line[l]==',') 00131 l++; 00132 else if(line[l]!=')') { 00133 fprintf(stderr,"Invalid input on line:\n %s\n",line); 00134 n=0; 00135 break; 00136 } 00137 } 00138 else { 00139 n=1; 00140 if(line[l] == 'D') line[l] = 'E'; 00141 l++; 00142 } 00143 } 00144 if(n == 0) continue; 00145 linep=&line[++l]; 00146 if(num == NULL) { 00147 for(i=0;i<n;i++) 00148 get_hex_input(&linep, &arg[i]); 00149 } 00150 else { 00151 if(line[l-2] == '"') 00152 line[l-2] = 0; 00153 else 00154 line[l-1] = 0; 00155 if(num[0] == '"') num++; 00156 memcpy((char*)(&arg[0])+8-sizeof(char*), &num, sizeof(char*)); 00157 } 00158 for(i=0;i<rsize;i++) 00159 get_hex_input(&linep, &ans[i]); 00160 l = strlen(func); 00161 if(strncmp(func,"STRTO",5) == 0) { 00162 if(func[5] == 'D') 00163 rtype = AR_Float_IEEE_NR_64; 00164 else if(func[5] == 'X') 00165 rtype = AR_Float_IEEE_NR_128; 00166 else 00167 rtype = AR_Float_IEEE_NR_32; 00168 ierr=AR_convert_str_to_float((AR_DATA*)&result[0], &rtype, num); 00169 num[strlen(num)] = ')'; 00170 } 00171 else if(strncmp(&func[l-3],"LOG",3) == 0) { 00172 if(func[0] == 'A') 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] == 'X') 00177 rtype = AR_Float_IEEE_NR_128; 00178 else if(func[1] == 'L') 00179 rtype = AR_Complex_IEEE_NR_64; 00180 else 00181 rtype = AR_Complex_IEEE_NR_128; 00182 ierr = AR_log((AR_DATA*)&result[0], &rtype, (AR_DATA*)&arg[0], &rtype); 00183 } 00184 else if(strncmp(&func[l-3],"EXP",3) == 0) { 00185 if(func[0] == 'E') 00186 rtype = AR_Float_IEEE_NR_64; 00187 else if(func[0] == 'D') 00188 rtype = AR_Float_IEEE_NR_128; 00189 else if(func[0] == 'X') 00190 rtype = AR_Float_IEEE_NR_128; 00191 else if(func[1] == 'E') 00192 rtype = AR_Complex_IEEE_NR_64; 00193 else 00194 rtype = AR_Complex_IEEE_NR_128; 00195 ierr = AR_exp((AR_DATA*)&result[0], &rtype, (AR_DATA*)&arg[0], &rtype); 00196 } 00197 else if(strncmp(&func[l-4],"SQRT",4) == 0) { 00198 if(func[0] == 'S') 00199 rtype = AR_Float_IEEE_NR_64; 00200 else if(func[0] == 'D') 00201 rtype = AR_Float_IEEE_NR_128; 00202 else if(func[0] == 'X') 00203 rtype = AR_Float_IEEE_NR_128; 00204 else if(func[1] == 'S') 00205 rtype = AR_Complex_IEEE_NR_64; 00206 else 00207 rtype = AR_Complex_IEEE_NR_128; 00208 ierr = AR_sqrt((AR_DATA*)&result[0], &rtype, (AR_DATA*)&arg[0], &rtype); 00209 } 00210 else if(strncmp(&func[l-3],"ABS",3) == 0) { 00211 if(func[1] == 'A') { 00212 rtype = AR_Float_IEEE_NR_64; 00213 opndtype = AR_Complex_IEEE_NR_64; 00214 } 00215 else { 00216 rtype = AR_Float_IEEE_NR_128; 00217 opndtype = AR_Complex_IEEE_NR_128; 00218 } 00219 rsize >>= 1; 00220 ierr = AR_cabs((AR_DATA*)&result[0], &rtype, (AR_DATA*)&arg[0], &opndtype); 00221 } 00222 else if(strncmp(&func[l-3],"TOI",3)==0 || 00223 strncmp(&func[l-3],"TOD",3)==0) { 00224 if(func[0] == 'I') { 00225 rtype = AR_Int_64_S; 00226 opndtype = AR_Int_64_S; 00227 } 00228 else if(func[0] == 'D') { 00229 rtype = AR_Float_IEEE_NR_64; 00230 opndtype = AR_Float_IEEE_NR_64; 00231 } 00232 else if(func[0] == 'X') { 00233 rtype = AR_Float_IEEE_NR_128; 00234 opndtype = AR_Float_IEEE_NR_128; 00235 } 00236 else if(func[1] == 'T') { 00237 rtype = AR_Complex_IEEE_NR_64; 00238 opndtype = AR_Complex_IEEE_NR_64; 00239 } 00240 else { 00241 rtype = AR_Complex_IEEE_NR_128; 00242 opndtype = AR_Complex_IEEE_NR_128; 00243 } 00244 if(func[l-1] == 'I') 00245 ptype = AR_Int_64_S; 00246 else if(func[l-1] == 'D') 00247 ptype = AR_Float_IEEE_NR_64; 00248 else 00249 ptype = AR_Float_IEEE_NR_128; 00250 ierr = AR_power((AR_DATA*)&result[0], &rtype, (AR_DATA*)&arg[0], &opndtype, (AR_DATA*)&arg[n-1], &ptype); 00251 } 00252 else if(strncmp(&func[0],"MODULO",6)==0 ) { 00253 if(func[6] == 'I') { 00254 rtype = AR_Int_46_S; 00255 if(arg[0] & 0x80000000) 00256 arg[0] |= ((AR_HOST_SINT64)0xffffffff)<<32; 00257 if(arg[1] & 0x80000000) 00258 arg[1] |= ((AR_HOST_SINT64)0xffffffff)<<32; 00259 } 00260 else if(func[6] == 'J') 00261 rtype = AR_Int_64_S; 00262 else if(func[6] == 'F') 00263 rtype = AR_Float_IEEE_NR_32; 00264 else if(func[6] == 'S') 00265 rtype = AR_Float_IEEE_NR_64; 00266 else if(func[6] == 'D') 00267 rtype = AR_Float_IEEE_NR_128; 00268 ierr = AR_Modulo((AR_DATA*)&result[0], &rtype, (AR_DATA*)&arg[0], &rtype, (AR_DATA*)&arg[n>>1], &rtype); 00269 } 00270 else if(strncmp(&func[0],"SELREALK",8)==0 ) { 00271 rtype = AR_Int_64_S; 00272 if(arg[0] < 0 && arg[1] < 0) 00273 ierr = AR_selected_real_kind((AR_DATA*)&result[0], &rtype, (AR_DATA*)NULL, &rtype, (AR_DATA*)NULL, &rtype); 00274 else if(arg[0] < 0) 00275 ierr = AR_selected_real_kind((AR_DATA*)&result[0], &rtype, (AR_DATA*)NULL, &rtype, (AR_DATA*)&arg[1], &rtype); 00276 else if(arg[1] < 0) 00277 ierr = AR_selected_real_kind((AR_DATA*)&result[0], &rtype, (AR_DATA*)&arg[0], &rtype, (AR_DATA*)NULL, &rtype); 00278 else 00279 ierr = AR_selected_real_kind((AR_DATA*)&result[0], &rtype, (AR_DATA*)&arg[0], &rtype, (AR_DATA*)&arg[1], &rtype); 00280 } 00281 else { 00282 if(func[0] == 'D') { 00283 rtype = AR_Float_IEEE_NR_64; 00284 opndtype = AR_Float_IEEE_NR_64; 00285 ptype = AR_Float_IEEE_NR_64; 00286 } 00287 else if(func[1] == 'T') { 00288 rtype = AR_Complex_IEEE_NR_64; 00289 opndtype = AR_Complex_IEEE_NR_64; 00290 ptype = AR_Complex_IEEE_NR_64; 00291 } 00292 else if(func[0] == 'X' && func[1] == 'D') { 00293 rtype = AR_Float_IEEE_NR_128; 00294 opndtype = AR_Float_IEEE_NR_128; 00295 ptype = AR_Float_IEEE_NR_128; 00296 } 00297 else { 00298 rtype = AR_Complex_IEEE_NR_128; 00299 opndtype = AR_Complex_IEEE_NR_128; 00300 ptype = AR_Complex_IEEE_NR_128; 00301 } 00302 ierr = AR_power((AR_DATA*)&result[0], &rtype, (AR_DATA*)&arg[0], &opndtype, (AR_DATA*)&arg[n>>1], &ptype); 00303 } 00304 ierr &= (AR_STAT_OVERFLOW|AR_STAT_UNDERFLOW|AR_STAT_UNDEFINED|AR_STAT_INVALID_TYPE); 00305 if(rsize > 1 && ((result[0]>>52)&0x7ff) == 0x7ff) 00306 xor = result[0]^ans[0]; 00307 else 00308 for(xor=0, i=0; i<rsize; i++) 00309 xor |= (result[i]^ans[i]); 00310 if(ierr!=0 || xor!=0) { 00311 if(ierr!=0 && ans[0]==ierr) 00312 okerrs++; 00313 else { 00314 fprintf(stderr,"\n***** ERROR *** ERROR *** ERROR *** ERROR *****\n"); 00315 fprintf(stderr," Intrinsic result does not match expected result on input line:\n %s\n",line); 00316 if(ierr != 0) 00317 fprintf(stderr," The intrinsic returned an error code = 0%o\n",ierr); 00318 else { 00319 fprintf(stderr," The intrinsic returned a result of:\n "); 00320 for(i=0; i<rsize; i++) 00321 fprintf(stderr," %16.16llx",result[i]); 00322 fprintf(stderr,"\n"); 00323 } 00324 fail++; 00325 } 00326 } 00327 else 00328 pass++; 00329 } 00330 00331 printf("Intrinsic test results:\n%6d passed\n%6d passed with expected error condition\n%6d FAILED!!!\n",pass,okerrs,fail); 00332 exit(fail); 00333 00334 } 00335 00336 get_hex_input(str, arg) 00337 char** str; 00338 AR_HOST_SINT64 *arg; 00339 { 00340 char* line; 00341 00342 int h1,h2,h3,h4; 00343 00344 line = *str; 00345 00346 while(!isxdigit(*line)) line++; 00347 00348 h1=(*line>='A')?*line-'A'+10:*line-'0'; line++; 00349 h2=(*line>='A')?*line-'A'+10:*line-'0'; line++; 00350 h3=(*line>='A')?*line-'A'+10:*line-'0'; line++; 00351 h4=(*line>='A')?*line-'A'+10:*line-'0'; line++; 00352 (*arg) = (AR_HOST_SINT64)((h1<<12) | (h2<<8) | (h3<<4) | h4)<<16; 00353 00354 h1=(*line>='A')?*line-'A'+10:*line-'0'; line++; 00355 h2=(*line>='A')?*line-'A'+10:*line-'0'; line++; 00356 h3=(*line>='A')?*line-'A'+10:*line-'0'; line++; 00357 h4=(*line>='A')?*line-'A'+10:*line-'0'; line++; 00358 (*arg) |= (AR_HOST_SINT64)((h1<<12) | (h2<<8) | (h3<<4) | h4); 00359 00360 if(isxdigit(*line)) { 00361 (*arg) <<= 32; 00362 00363 h1=(*line>='A')?*line-'A'+10:*line-'0'; line++; 00364 h2=(*line>='A')?*line-'A'+10:*line-'0'; line++; 00365 h3=(*line>='A')?*line-'A'+10:*line-'0'; line++; 00366 h4=(*line>='A')?*line-'A'+10:*line-'0'; line++; 00367 (*arg) |= (AR_HOST_SINT64)((h1<<12) | (h2<<8) | (h3<<4) | h4)<<16; 00368 00369 h1=(*line>='A')?*line-'A'+10:*line-'0'; line++; 00370 h2=(*line>='A')?*line-'A'+10:*line-'0'; line++; 00371 h3=(*line>='A')?*line-'A'+10:*line-'0'; line++; 00372 h4=(*line>='A')?*line-'A'+10:*line-'0'; line++; 00373 (*arg) |= (AR_HOST_SINT64)((h1<<12) | (h2<<8) | (h3<<4) | h4); 00374 } 00375 00376 *str = line; 00377 } 00378 00379 00380 static char USMID [] = "\n%Z%%M% %I% %G% %U%\n"; 00381 static char rcsid [] = "$Id: test_tsieee_sim.c,v 1.1.1.1 2002-05-22 20:06:19 dsystem Exp $";