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.1 of the GNU Lesser General Public License 00007 as 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 Lesser General Public 00021 License along with this program; if not, write the Free Software 00022 Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, 00023 USA. 00024 00025 Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pky, 00026 Mountain View, CA 94043, or: 00027 00028 http://www.sgi.com 00029 00030 For further information regarding this notice, see: 00031 00032 http://oss.sgi.com/projects/GenInfo/NoticeExplan 00033 00034 */ 00035 00036 00037 #pragma ident "@(#) libfi/element/selrealkind.c 92.1 06/16/99 15:47:23" 00038 #include <fortran.h> 00039 #include <stddef.h> 00040 #include <fmath.h> 00041 00042 static struct { 00043 int kind; 00044 int maxprecision; 00045 int maxexprange; 00046 } values[] = { 00047 { 4, PRECISION_REAL4_F90, RANGE_REAL4_F90 }, 00048 { 8, PRECISION_REAL8_F90, RANGE_REAL8_F90 }, 00049 #if _F_REAL16 == 1 00050 { 16, PRECISION_REAL16_F90, RANGE_REAL16_F90 }, 00051 #endif /* _F_REAL16 */ 00052 }; 00053 00054 00055 #define NUMKINDS (signed)(sizeof(values)/sizeof(values[0])) 00056 00057 #define _CODE_SEL() \ 00058 if (prec != NULL) \ 00059 precval = *prec; \ 00060 if (range != NULL) \ 00061 exprangval = *range; \ 00062 for (i=0; i<NUMKINDS; i++) { \ 00063 if (exp_match == 0 && exprangval <= values[i].maxexprange) { \ 00064 exp_match = values[i].kind; \ 00065 } \ 00066 if (prec_match == 0 && precval <= values[i].maxprecision) { \ 00067 prec_match = values[i].kind; \ 00068 } \ 00069 if (exp_match && prec_match) \ 00070 break; \ 00071 } \ 00072 if (exp_match == 0 && prec_match == 0) \ 00073 return(-3); \ 00074 else if (prec_match == 0) \ 00075 return(-1); \ 00076 else if (exp_match == 0) \ 00077 return(-2); \ 00078 return ( (exp_match > prec_match) ? exp_match : prec_match); 00079 00080 #define _CODE_SEL_MIPS() \ 00081 if (prec != NULL) \ 00082 precval = *prec; \ 00083 if (range != NULL) \ 00084 exprangval = *range; \ 00085 for (i=0; i<NUMKINDS; i++) { \ 00086 if (exp_match == 0 && exprangval <= values[i].maxexprange) { \ 00087 exp_match = values[i].kind; \ 00088 e_indx = i + 1; \ 00089 } \ 00090 if (prec_match == 0 && precval <= values[i].maxprecision) { \ 00091 prec_match = values[i].kind; \ 00092 p_indx = i + 1; \ 00093 } \ 00094 if (exp_match && prec_match) \ 00095 break; \ 00096 } \ 00097 if (exp_match == 0 && prec_match == 0) \ 00098 return(-3); \ 00099 else if (prec_match == 0) \ 00100 return(-1); \ 00101 else if (exp_match == 0) \ 00102 return(-2); \ 00103 /* Check for a precision of kind=16 and an exponent of kind=8. \ 00104 * The exponent range for kind=8 is larger than the exponent \ 00105 * range for kind=16 on mips only. The result of intrinsic \ 00106 * selected_real_kind for this combination is being evaluated \ 00107 * by the Fortran standards committee and the values returned \ 00108 * here may change. \ 00109 */ \ 00110 if (exp_match > prec_match) \ 00111 result = e_indx - 1; \ 00112 else \ 00113 result = p_indx - 1; \ 00114 if (values[result].maxexprange < exprangval ) return (-2); \ 00115 if (values[result].maxprecision < precval ) return (-1); \ 00116 return (values[result].kind); 00117 00118 /* 00119 * SELECTED_REAL_KIND(P,R) 00120 * Returns a value of the kind type parameter of a 00121 * real data type with decimal precision of at least P and 00122 * a decimal exponent range of at least R. 00123 * P and R may be negative values according to F90 00124 * interpretation 201. 00125 * NONSUCCESSFUL RETURN VALUES: 00126 * -3 indicates that neither P nor R is available. 00127 * -2 indicates that R is not available. 00128 * -1 indicates that P is not available. 00129 * SUCCESSFUL RETURN VALUES: 00130 * Return the KIND type parameter for P and R. If more than 00131 * one KIND type parameter fits P and R, return the smallest 00132 * of these kind values. 00133 */ 00134 00135 #ifdef _UNICOS 00136 /* Duplicate name to build the F90 compiler version 1.1 and previous */ 00137 #pragma _CRI duplicate _SELECTED_REAL_KIND_ as _SELECTED_REAL_KIND 00138 #endif /* UNICOS */ 00139 00140 _f_int 00141 _SELECTED_REAL_KIND_ (_f_int *prec, 00142 _f_int *range) 00143 { 00144 #if defined(__mips) 00145 int e_indx = 0; /* found exponent range match */ 00146 int p_indx = 0; /* found precision match */ 00147 int result; 00148 #endif /* mips */ 00149 int i; 00150 int exprangval = 0; /* exponent range argument */ 00151 int precval = 0; /* precision value argument */ 00152 int exp_match = 0; /* found exponent range match */ 00153 int prec_match = 0; /* found precision match */ 00154 #if defined(__mips) 00155 _CODE_SEL_MIPS(); 00156 #else /* mips */ 00157 _CODE_SEL(); 00158 #endif /* mips */ 00159 } 00160 00161 #ifndef _UNICOS 00162 /* Duplicate name to build the Sparc F90 compiler prerelease version */ 00163 _f_int _SELECTED_REAL_KIND(_f_int *prec, _f_int *range) 00164 { 00165 #if defined(__mips) 00166 int e_indx = 0; /* found exponent range match */ 00167 int p_indx = 0; /* found precision match */ 00168 int result; 00169 #endif /* mips */ 00170 int i; 00171 int exprangval = 0; /* exponent range argument */ 00172 int precval = 0; /* precision value argument */ 00173 int exp_match = 0; /* found exponent range match */ 00174 int prec_match = 0; /* found precision match */ 00175 #if defined(__mips) 00176 _CODE_SEL_MIPS(); 00177 #else /* mips */ 00178 _CODE_SEL(); 00179 #endif /* mips */ 00180 } 00181 #endif /* not UNICOS */ 00182 00183 #ifdef _F_INT4 00184 /* 00185 * SELECTED_REAL_KIND_4(P,R) 00186 * Returns a value of the kind type parameter of a 00187 * real data type with decimal precision of at least P and 00188 * a decimal exponent range of at least R. 00189 * P and R may be negative values according to F90 00190 * interpretation 201. 00191 * The compiler casts the arguments to default integer. 00192 * NONSUCCESSFUL RETURN VALUES: 00193 * -3 indicates that neither P nor R is available. 00194 * -2 indicates that R is not available. 00195 * -1 indicates that P is not available. 00196 * SUCCESSFUL RETURN VALUES: 00197 * Return the KIND type parameter for P and R. If more than 00198 * one KIND type parameter fits P and R, return the smallest 00199 * of these kind values. 00200 */ 00201 00202 #ifdef _UNICOS 00203 /* Duplicate name to build the F90 compiler version 1.1 and previous */ 00204 #pragma _CRI duplicate _SELECTED_REAL_KIND_4_ as _SELECTED_REAL_KIND_4 00205 #endif /* UNICOS */ 00206 00207 _f_int4 00208 _SELECTED_REAL_KIND_4_ (_f_int *prec, 00209 _f_int *range) 00210 { 00211 #if defined(__mips) 00212 int e_indx = 0; /* found exponent range match */ 00213 int p_indx = 0; /* found precision match */ 00214 int result; 00215 #endif /* mips */ 00216 int i; 00217 int exprangval = 0; /* exponent range argument */ 00218 int precval = 0; /* precision value argument */ 00219 _f_int4 exp_match = 0; /* found exponent range match */ 00220 _f_int4 prec_match = 0; /* found precision match */ 00221 #if defined(__mips) 00222 _CODE_SEL_MIPS(); 00223 #else /* mips */ 00224 _CODE_SEL(); 00225 #endif /* mips */ 00226 } 00227 00228 #ifndef _UNICOS 00229 /* Duplicate name to build the Sparc F90 compiler prerelease version */ 00230 _f_int4 _SELECTED_REAL_KIND_4(_f_int *prec, _f_int *range) 00231 { 00232 #if defined(__mips) 00233 int e_indx = 0; /* found exponent range match */ 00234 int p_indx = 0; /* found precision match */ 00235 int result; 00236 #endif /* mips */ 00237 int i; 00238 int exprangval = 0; /* exponent range argument */ 00239 int precval = 0; /* precision value argument */ 00240 _f_int4 exp_match = 0; /* found exponent range match */ 00241 _f_int4 prec_match = 0; /* found precision match */ 00242 #if defined(__mips) 00243 _CODE_SEL_MIPS(); 00244 #else /* mips */ 00245 _CODE_SEL(); 00246 #endif /* mips */ 00247 } 00248 #endif /* not UNICOS */ 00249 00250 #endif /* _F_INT4 */ 00251 00252 00253 #ifdef _F_INT8 00254 /* 00255 * SELECTED_REAL_KIND_8(P,R) 00256 * Returns a value of the kind type parameter of a 00257 * real data type with decimal precision of at least P and 00258 * a decimal exponent range of at least R. 00259 * P and R may be negative values according to F90 00260 * interpretation 201. 00261 * The compiler casts the arguments to default integer. 00262 * NONSUCCESSFUL RETURN VALUES: 00263 * -3 indicates that neither P nor R is available. 00264 * -2 indicates that R is not available. 00265 * -1 indicates that P is not available. 00266 * SUCCESSFUL RETURN VALUES: 00267 * Return the KIND type parameter for P and R. If more than 00268 * one KIND type parameter fits P and R, return the smallest 00269 * of these kind values. 00270 */ 00271 00272 #ifdef _UNICOS 00273 /* Duplicate name to build the F90 compiler version 1.1 and previous */ 00274 #pragma _CRI duplicate _SELECTED_REAL_KIND_8_ as _SELECTED_REAL_KIND_8 00275 #endif /* UNICOS */ 00276 00277 _f_int8 00278 _SELECTED_REAL_KIND_8_ (_f_int *prec, 00279 _f_int *range) 00280 { 00281 #if defined(__mips) 00282 int e_indx = 0; /* found exponent range match */ 00283 int p_indx = 0; /* found precision match */ 00284 int result; 00285 #endif /* mips */ 00286 int i; 00287 int exprangval = 0; /* exponent range argument */ 00288 int precval = 0; /* precision value argument */ 00289 _f_int8 exp_match = 0; /* found exponent range match */ 00290 _f_int8 prec_match = 0; /* found precision match */ 00291 #if defined(__mips) 00292 _CODE_SEL_MIPS(); 00293 #else /* mips */ 00294 _CODE_SEL(); 00295 #endif /* mips */ 00296 } 00297 00298 #ifndef _UNICOS 00299 /* Duplicate name to build the Sparc F90 compiler prerelease version */ 00300 _f_int8 _SELECTED_REAL_KIND_8(_f_int *prec, _f_int *range) 00301 { 00302 #if defined(__mips) 00303 int e_indx = 0; /* found exponent range match */ 00304 int p_indx = 0; /* found precision match */ 00305 int result; 00306 #endif /* mips */ 00307 int i; 00308 int exprangval = 0; /* exponent range argument */ 00309 int precval = 0; /* precision value argument */ 00310 _f_int8 exp_match = 0; /* found exponent range match */ 00311 _f_int8 prec_match = 0; /* found precision match */ 00312 #if defined(__mips) 00313 _CODE_SEL_MIPS(); 00314 #else /* mips */ 00315 _CODE_SEL(); 00316 #endif /* mips */ 00317 } 00318 #endif /* not UNICOS */ 00319 00320 #endif /* _F_INT8 */