00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include <stdio.h>
00036 #include <stdlib.h>
00037 #include <ctype.h>
00038 #include <string.h>
00039
00040 #if defined(_LINUX_LINUX)
00041 # define HAVE_FORTRAN_H
00042 # include <fortran.h>
00043 #endif
00044
00045 #include "arith.h"
00046
00047 static int pass = 0;
00048 static int fail = 0;
00049
00050 static AR_HOST_SINT64 result[4];
00051
00052 static void check_ar_result();
00053
00054 static char prevfname[8];
00055 static int prevflen;
00056
00057 #if defined(CRAY_TS_IEEE)
00058 static AR_TYPE INT_TYPE = AR_Int_64_S;
00059 static AR_TYPE FLOAT_64 = AR_Float_IEEE_NR_64;
00060 static AR_TYPE FLOAT_128 = AR_Float_IEEE_NR_128;
00061 static AR_TYPE COMPLEX_64 = AR_Complex_IEEE_NR_64;
00062 static AR_TYPE COMPLEX_128 = AR_Complex_IEEE_NR_128;
00063 #elif _CRAY
00064 static AR_TYPE INT_TYPE = AR_Int_64_S;
00065 static AR_TYPE FLOAT_64 = AR_Float_Cray1_64;
00066 static AR_TYPE FLOAT_128 = AR_Float_Cray1_128;
00067 static AR_TYPE COMPLEX_64 = AR_Complex_Cray1_64;
00068 static AR_TYPE COMPLEX_128 = AR_Complex_Cray1_128;
00069 #else
00070 static AR_TYPE INT_TYPE = AR_Int_64_S;
00071 static AR_TYPE FLOAT_64 = AR_Float_IEEE_NR_64;
00072 static AR_TYPE FLOAT_128 = AR_Float_IEEE_NR_128;
00073 static AR_TYPE COMPLEX_64 = AR_Complex_IEEE_NR_64;
00074 static AR_TYPE COMPLEX_128 = AR_Complex_IEEE_NR_128;
00075 #endif
00076
00077
00078 int main()
00079 {
00080 prevflen = 0;
00081
00082 #if !defined(HAVE_FORTRAN_H)
00083 test_native_();
00084 #else
00085 TEST_NATIVE();
00086 #endif
00087 printf("Intrinsic test results:\n%6d passed\n%6d FAILED!!!\n",pass,fail);
00088 exit(fail);
00089 return 0;
00090 }
00091
00092 #if !defined(HAVE_FORTRAN_H)
00093 void ar_strtod_(answer)
00094 #else
00095 void AR_STRTOD(answer)
00096 #endif
00097 double* answer;
00098 {
00099 char num[32];
00100
00101 double dval;
00102
00103 int ierr;
00104 AR_TYPE rtype;
00105
00106 if(*answer >= 1.e6)
00107 sprintf(num,"%22.14e",*answer);
00108 else if(*answer >= 0.)
00109 sprintf(num,"%15.8f",*answer);
00110 else if(*answer >= -1.e6)
00111 sprintf(num,"%15.4f",*answer);
00112 else
00113 sprintf(num,"%25.16e",*answer);
00114
00115 dval = strtod(num, 0);
00116
00117 rtype = FLOAT_64;
00118
00119 ierr = AR_convert_str_to_float((AR_DATA*)&result[0], &rtype, num);
00120
00121 check_ar_result("STRTOD", strlen("STRTOD"), &result[0], ierr, &dval, 1);
00122 }
00123
00124 #ifdef LD
00125 #if !defined(HAVE_FORTRAN_H)
00126 void ar_strtold_(answer)
00127 #else
00128 void AR_STRTOLD(answer)
00129 #endif
00130 long double* answer;
00131 {
00132 char num[33];
00133
00134 long double ldval;
00135
00136 int ierr;
00137 AR_TYPE rtype;
00138
00139 #if !defined(HAVE_FORTRAN_H)
00140 if(*answer >= 1.e6L)
00141 sprintf(num,"%30.22Le",*answer);
00142 else if(*answer >= 0.)
00143 sprintf(num,"%20.12Lf",*answer);
00144 else if(*answer >= -1.e6L)
00145 sprintf(num,"%22.10Lf",*answer);
00146 else
00147 sprintf(num,"%31.23Le",*answer);
00148 sscanf(num," %Lf", &ldval);
00149 #else
00150 if(*answer >= 1.e6L)
00151 sprintf(num,"%30.22e",*answer);
00152 else if(*answer >= 0.)
00153 sprintf(num,"%20.12f",*answer);
00154 else if(*answer >= -1.e6L)
00155 sprintf(num,"%22.10f",*answer);
00156 else
00157 sprintf(num,"%31.23e",*answer);
00158 ldval = strtold(num, 0);
00159 #endif
00160
00161 rtype = FLOAT_128;
00162
00163 ierr = AR_convert_str_to_float((AR_DATA*)&result[0], &rtype, num);
00164
00165 check_ar_result("STRTOLD", strlen("STRTOLD"), &result[0], ierr, &ldval, 2);
00166 }
00167 #endif
00168
00169
00170 #if !defined(HAVE_FORTRAN_H)
00171 void ar_intrin1_(func, opnd, answer, func_len)
00172 char* func;
00173 AR_DATA* opnd;
00174 AR_DATA* answer;
00175 int func_len;
00176 #else
00177 void AR_INTRIN1(func, opnd, answer)
00178 _fcd func;
00179 AR_DATA* opnd;
00180 AR_DATA* answer;
00181 #endif
00182 {
00183 int ierr;
00184 int n;
00185 AR_TYPE rtype,otype,ptype;
00186
00187 #if !defined(HAVE_FORTRAN_H)
00188 char *fname = func;
00189 int flen = func_len;
00190 #else
00191 char *fname = _fcdtocp(func);
00192 int flen = _fcdlen(func);
00193 #endif
00194
00195 n = 1;
00196
00197 if(strncmp(&fname[flen-3],"LOG",3) == 0) {
00198 if(fname[0] == 'A')
00199 rtype = FLOAT_64;
00200 else if(fname[0] == 'D') {
00201 rtype = FLOAT_128;
00202 n = 2;
00203 }
00204 else if(fname[1] == 'L') {
00205 rtype = COMPLEX_64;
00206 n = 2;
00207 }
00208 else {
00209 rtype = COMPLEX_128;
00210 n = 4;
00211 }
00212 ierr = AR_log((AR_DATA*)&result[0], &rtype, opnd, &rtype);
00213 }
00214
00215 else if(strncmp(&fname[flen-3],"EXP",3) == 0) {
00216 if(fname[0] == 'E')
00217 rtype = FLOAT_64;
00218 else if(fname[0] == 'D') {
00219 rtype = FLOAT_128;
00220 n = 2;
00221 }
00222 else if(fname[1] == 'E') {
00223 rtype = COMPLEX_64;
00224 n = 2;
00225 }
00226 else {
00227 rtype = COMPLEX_128;
00228 n = 4;
00229 }
00230 ierr = AR_exp((AR_DATA*)&result[0], &rtype, opnd, &rtype);
00231 }
00232
00233 else if(strncmp(&fname[flen-4],"SQRT",4) == 0) {
00234 if(fname[0] == 'S')
00235 rtype = FLOAT_64;
00236 else if(fname[0] == 'D') {
00237 rtype = FLOAT_128;
00238 n = 2;
00239 }
00240 else if(fname[1] == 'S') {
00241 rtype = COMPLEX_64;
00242 n = 2;
00243 }
00244 else {
00245 rtype = COMPLEX_128;
00246 n = 4;
00247 }
00248 ierr = AR_sqrt((AR_DATA*)&result[0], &rtype, opnd, &rtype);
00249 }
00250
00251 else if(strncmp(&fname[flen-3],"ABS",3) == 0) {
00252 if(fname[1] == 'A') {
00253 rtype = FLOAT_64;
00254 otype = COMPLEX_64;
00255 }
00256 else {
00257 rtype = FLOAT_128;
00258 otype = COMPLEX_128;
00259 n = 2;
00260 }
00261 ierr = AR_cabs((AR_DATA*)&result[0], &rtype, opnd, &otype);
00262 }
00263
00264 check_ar_result(fname, flen, &result[0], ierr, answer, n);
00265 }
00266
00267 #if !defined(HAVE_FORTRAN_H)
00268 void ar_intrin2_(func, opnd1, opnd2, answer, func_len)
00269 char* func;
00270 AR_DATA* opnd1;
00271 AR_DATA* opnd2;
00272 AR_DATA* answer;
00273 int func_len;
00274 #else
00275 void AR_INTRIN2(func, opnd1, opnd2, answer)
00276 _fcd func;
00277 AR_DATA* opnd1;
00278 AR_DATA* opnd2;
00279 AR_DATA* answer;
00280 #endif
00281 {
00282 int ierr;
00283 int n;
00284 AR_TYPE rtype,otype,ptype;
00285 AR_HOST_SINT64 base,power;
00286
00287 #if !defined(HAVE_FORTRAN_H)
00288 char *fname = func;
00289 int flen = func_len;
00290 #else
00291 char *fname = _fcdtocp(func);
00292 int flen = _fcdlen(func);
00293 #endif
00294
00295 n = 1;
00296
00297 base = power = 0;
00298 if(strncmp(&fname[flen-3],"TOI",3)==0 ||
00299 strncmp(&fname[flen-3],"TOR",3)==0) {
00300 if(fname[0] == 'I') {
00301 #if _CRAY
00302 rtype = AR_Int_64_S;
00303 otype = AR_Int_64_S;
00304 #else
00305 memcpy(((char*)&base)+4, ((char*)opnd1)+4, 4);
00306 memcpy(((char*)&power)+4, ((char*)opnd2)+4, 4);
00307 if((base>>31) != 0 || (power>>31) != 0) {
00308 if((base>>31) != 0)
00309 memset((char*)opnd1, 0xff, 4);
00310 if((power>>31) != 0)
00311 memset((char*)opnd2, 0xff, 4);
00312 rtype = AR_Int_64_S;
00313 otype = AR_Int_64_S;
00314 }
00315 else {
00316 rtype = AR_Int_32_S;
00317 otype = AR_Int_32_S;
00318 }
00319 #endif
00320 }
00321 else if(fname[0] == 'R') {
00322 rtype = FLOAT_64;
00323 otype = FLOAT_64;
00324 }
00325 else if(fname[0] == 'D') {
00326 rtype = FLOAT_128;
00327 otype = FLOAT_128;
00328 n = 2;
00329 }
00330 else if(fname[1] == 'T') {
00331 rtype = COMPLEX_64;
00332 otype = COMPLEX_64;
00333 n = 2;
00334 }
00335 else {
00336 rtype = COMPLEX_128;
00337 otype = COMPLEX_128;
00338 n = 4;
00339 }
00340 if(fname[flen-1] == 'I') {
00341 #if _CRAY
00342 ptype = AR_Int_64_S;
00343 #else
00344 memcpy(((char*)&power)+4, ((char*)opnd2)+4, 4);
00345 if(otype == AR_Int_64_S || (power>>31) != 0) {
00346 if((power>>31) != 0)
00347 memset((char*)opnd2, 0xff, 4);
00348 ptype = AR_Int_64_S;
00349 }
00350 else
00351 ptype = AR_Int_32_S;
00352 #endif
00353 }
00354 else
00355 ptype = FLOAT_64;
00356 ierr = AR_power((AR_DATA*)&result[0], &rtype, opnd1, &otype, opnd2,
00357 &ptype);
00358 if(base != 0) {
00359 memset((char*)opnd1, 0, 4);
00360 if(rtype == AR_Int_64_S && (power&1))
00361 memset((char*)&result[0], 0, 4);
00362 }
00363 if(power != 0)
00364 memset((char*)opnd2, 0, 4);
00365 }
00366 else {
00367 if(fname[0] == 'D') {
00368 rtype = FLOAT_128;
00369 otype = FLOAT_128;
00370 ptype = FLOAT_128;
00371 n = 2;
00372 }
00373 else if(fname[1] == 'T') {
00374 rtype = COMPLEX_64;
00375 otype = COMPLEX_64;
00376 ptype = COMPLEX_64;
00377 n = 2;
00378 }
00379 else {
00380 rtype = COMPLEX_128;
00381 otype = COMPLEX_128;
00382 ptype = COMPLEX_128;
00383 n = 4;
00384 }
00385 ierr = AR_power((AR_DATA*)&result[0], &rtype, opnd1, &otype, opnd2,
00386 &ptype);
00387 }
00388
00389 check_ar_result(fname, flen, &result[0], ierr, answer, n);
00390 }
00391
00392 static
00393 void
00394 check_ar_result(fname, flen, ar_result, ar_error, answer, rsize)
00395 char *fname;
00396 int flen;
00397 AR_HOST_SINT64 *ar_result;
00398 int ar_error;
00399 AR_HOST_SINT64 *answer;
00400 int rsize;
00401 {
00402 int i;
00403 int ierr;
00404 AR_HOST_SINT64 xor;
00405
00406 if(prevflen != flen && strncmp(prevfname, fname, flen) != 0) {
00407 prevflen = flen;
00408 strncpy(prevfname, fname, flen);
00409 printf("Testing %*.*s intrinsic\n", flen, flen, fname);
00410 }
00411
00412 ierr = ar_error&(AR_STAT_OVERFLOW|AR_STAT_UNDEFINED|AR_STAT_INVALID_TYPE);
00413
00414 for(xor=0, i=0; i<rsize; i++)
00415 xor |= (ar_result[i]^answer[i]);
00416
00417 if((ierr & (AR_STAT_OVERFLOW|AR_STAT_UNDEFINED)) &&
00418 ((answer[0]>>52)&0x7ff) == 0x7ff) ierr=0;
00419
00420 if(ierr!=0 || xor!=0) {
00421 const char* conversion = NULL;
00422
00423 fprintf(stderr,
00424 "\n***** ERROR *** ERROR *** ERROR *** ERROR *****\n");
00425 fprintf(stderr,
00426 " arith.a %*.*s result does not match expected result of",
00427 flen, flen, fname);
00428
00429 #ifdef _CRAY
00430 conversion = " %8.8lx";
00431 #else
00432 conversion = " %8.8llx";
00433 #endif
00434
00435 for(i=0; i<rsize; i++)
00436 fprintf(stderr, conversion, (AR_HOST_UINT64)answer[i]);
00437 fprintf(stderr,"\n");
00438 if(ierr != 0)
00439 fprintf(stderr,
00440 " The arith.a routine returned an error code = 0%o\n",
00441 ierr);
00442 else {
00443 fprintf(stderr," The arith.a routine returned a result of");
00444 for(i=0; i<rsize; i++)
00445 fprintf(stderr, conversion, (AR_HOST_UINT64)ar_result[i]);
00446 fprintf(stderr,"\n");
00447 }
00448 fail++;
00449 }
00450 else
00451 pass++;
00452
00453 }
00454
00455
00456 static char USMID [] = "\n%Z%%M% %I% %G% %U%\n";
00457 static char rcsid [] = "$Id: test_ar_intrin.c,v 1.4 2003-12-11 22:08:33 eraxxon Exp $";