Open64 (mfef90, whirl2f, and IR tools)  TAG: version-openad; SVN changeset: 916
f90_macros.h
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.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 /* USMID @(#) libfi/include/f90_macros.h        92.0    10/08/98 14:37:14 */
00038 
00039 
00040 /************************************************************************
00041  *
00042  * This file contains C macros that are used by the MPP version
00043  * of the Fortran 90 array intrinsics.
00044  *
00045  ************************************************************************/
00046 
00047 
00048 /*
00049  * LOG2(n) - Find the log base 2 of a power of 2
00050  */
00051 
00052 #define BITS_PER_INT ( sizeof ( int ) * 8 )
00053 #define LOG2(num)      ( BITS_PER_INT - _leadz(num) - 1 )
00054 
00055 
00056 /************************************************************************
00057  *
00058  * EXTENT_CHK() - Check the extents for an array. If any of the
00059  *              extents are zero, then doctor up a NULL result
00060  *              and return to the caller.
00061  *
00062  * Arguments:     DopeVectorType * array;
00063  *
00064  * Variables used: DopeVectorType * result;
00065  *
00066  ************************************************************************/
00067 
00068 #define EXTENT_CHK(array)                                               \
00069 _Pragma("shortloop");                                                   \
00070         for (i=0; i < array->n_dim; i++) {                              \
00071             if (array->dimension[i].extent == 0) {                      \
00072                 result->ptr_alloc = 1;                                  \
00073                 result->assoc = 1;                                      \
00074                 result->n_dim = 0;                                      \
00075                 result->dimension[0].extent = 0;                        \
00076                 result->dimension[0].stride_mult = 1;                   \
00077                 return;                                                 \
00078             }                                                           \
00079         }
00080 
00081 
00082 
00083 /************************************************************************
00084  *
00085  * SETUP_EXTENTS() - Set up an array of extents for the source array,
00086  *                 and the result array based on dim.
00087  *
00088  * Variables used:  DopeVectorType * result;
00089  *                DopeVectorType * source;
00090  *                long src_extents[RANK];
00091  *                long res_extents[RANK-1];
00092  *                long blkcnts[RANK];
00093  *                long dim;
00094  *                long dim_bcnt;
00095  *
00096  ************************************************************************/
00097 
00098 #define SETUP_EXTENTS()                                                 \
00099         for (i=0; i < RANK; i++) {                                      \
00100             src_extents[i] = source->dimension[i].extent;               \
00101         }                                                               \
00102 _Pragma("shortloop");                                                   \
00103         for (i=0; i < *dim-1; i++) {                                    \
00104             res_extents[i] =  src_extents[i];                           \
00105         }                                                               \
00106         for (i=*dim-1; i < RANK-1; i++) {                               \
00107             res_extents[i] = src_extents[i+1];                          \
00108         }
00109 
00110 
00111 /************************************************************************
00112  *
00113  * SETUP_BLKCNTS() - Set up an array of block counts for each
00114  *                 dimension of the source array.
00115  *
00116  * Variables used: long blkcnts[RANK];
00117  *               long dim_bcnt;
00118  *               DopeVectorType * source;
00119  *
00120  ************************************************************************/
00121 
00122 #define SETUP_BLKCNTS()                                                 \
00123         if (_in_parallel()) {                                           \
00124             long *sdd_ptr;                                              \
00125             sdd_ptr = source->base_addr.a.ptr;                          \
00126             for (i=0; i < RANK; i++) {                                  \
00127                 blkcnts[i] = _blkct(sdd_ptr,i+1,_MY_PE());              \
00128             }                                                           \
00129             for (i=0; i < *dim-1; i++) {                                \
00130                 dim_bcnt[i] = blkcnts[i];                               \
00131             }                                                           \
00132             for (i = *dim-1;  i < RANK-1; i++) {                        \
00133                 dim_bcnt[i] = blkcnts[i+1];                             \
00134             }                                                           \
00135         }
00136 
00137 
00138 
00139 /************************************************************************
00140  *
00141  * INIT_SDD() -    Initialize the shared data descriptor for the
00142  *               shared result temporary so that it describes
00143  *               one distributed array that is dimensioned the
00144  *               same as the source array excluding DIM and has
00145  *               each dimension distributed :BLOCK.
00146  *
00147  * Variables used: DopeVectorType * result;
00148  *               void * result_base_ptr;
00149  *               long weights[result->n_dim];
00150  *               long blknums[result->n_dim];
00151  *               long res_extents[result->n_dim];
00152  *
00153  ************************************************************************/
00154 
00155 #define INIT_SDD()                                                      \
00156         for (i=0; i < result->n_dim; i++) {                             \
00157             blknums[i] = result->dimension[i].extent;                   \
00158             weights[i] = 2;                                             \
00159         }                                                               \
00160         _init_sdd(result->base_addr.a.ptr, result_base_ptr,             \
00161                 result->n_dim, weights, blknums, res_extents);
00162         
00163 
00164 /*
00165  * INIT_LOC_SDD() - Initialize the shared data descriptor for the
00166  *                  shared temporary result so that it describes
00167  *                  one distributed array that is dimensioned
00168  *                  (_N_PES,RANK) and distributed across the
00169  *                  processors (:BLOCK(1),:).
00170  *
00171  *                  Used in the distributed versions of MAXLOC
00172  *                  and MINLOC.
00173  *
00174  * Variables uses:  DopeVectorType * result;
00175  *                  DopeVectorType * source;
00176  *                  long dim1_tmp, dim2_tmp;
00177  *                  void * result_base_ptr;
00178  */
00179 
00180 #define INIT_LOC_SDD()                                                  \
00181                                                                         \
00182         /*                                                              \
00183          * Set the base address field in the sdd to the base pointer.   \
00184          */                                                             \
00185                                                                         \
00186         _sdd_write_base(result->base_addr.a.ptr,result_base_ptr);       \
00187                                                                         \
00188         /*                                                              \
00189          * Calculate cyc_ebp and pe_bcnt for the 1st dimension as       \
00190          * log2(_N_PES). blk_ebp for the first dimension is always 0.   \
00191          */                                                             \
00192                                                                         \
00193         dim1_tmp = LOG2(_N_PES);                                        \
00194         _sdd_write_cyc_ebp(result->base_addr.a.ptr,1,dim1_tmp);         \
00195         _sdd_write_pe_bcnt(result->base_addr.a.ptr,1,dim1_tmp);         \
00196         _sdd_write_blk_ebp(result->base_addr.a.ptr,1,0);
00197 
00198 
00199 
00200 /************************************************************************
00201  *
00202  * CHECK_MASK(sdd_ptr, flag) - Check to see if a mask argument
00203  *              was provided by the user, then check to see if it
00204  *              is an array or a scalar. If the mask is a non-zero
00205  *              scalar, then treat as if no mask was provided. If
00206  *              the mask is a scalar with a value of zero, then set
00207  *              the result to 0 and return to caller. If the mask
00208  *              is a shared array, then set up the mask's sdd
00209  *              pointer.
00210  *
00211  * Arguments:     void * sdd_ptr;
00212  *              long flag;
00213  *
00214  * Variables used: void * result_base_ptr;
00215  *               DopeVectorType * source;
00216  *               DopeVectorType * mask;
00217  * 
00218  ************************************************************************/
00219 
00220 #define USE_IT          1L
00221 #define DONT_USE_IT     0L
00222 #define FALSE_MASK      -1L
00223 
00224 #define CHECK_MASK(sdd_ptr, flag)                                       \
00225         flag = DONT_USE_IT;                                             \
00226         if (mask) {                                                     \
00227             if (mask->n_dim > 0) {                                      \
00228                 sdd_ptr = mask->base_addr.a.ptr;                        \
00229                 flag = USE_IT;                                          \
00230             } else {                                                    \
00231                 if (_ltob((int *)mask->base_addr.a.ptr) == 0) {         \
00232                     flag = FALSE_MASK;                                  \
00233                 }                                                       \
00234             }                                                           \
00235         } else {                                                        \
00236             sdd_ptr = 0;                                                \
00237         }
00238 
00239 
00240 /************************************************************************
00241  *
00242  * CHECK_STOP(sdd_ptr, flag) - Check to see if the stop argument
00243  *              provided by the user is an array or a scalar. If the mask
00244  *              is a non-zero scalar, then treat as if no mask was provided.
00245  *              If the mask is a scalar with a value of zero, then set
00246  *              the result to 0 and return to caller. If the mask
00247  *              is a shared array, then set up the mask's sdd
00248  *              pointer.
00249  *
00250  * Arguments:     void * sdd_ptr;
00251  *              long flag;
00252  *
00253  * Variables used: void * result_base_ptr;
00254  *               DopeVectorType * source;
00255  *               DopeVectorType * mask;
00256  * 
00257  ************************************************************************/
00258 
00259 #define USE_IT          1L
00260 #define FALSE_MASK      -1L
00261 
00262 #define CHECK_STOP(sdd_ptr, flag)                                       \
00263         if (stop->n_dim > 0) {                                          \
00264             sdd_ptr = stop->base_addr.a.ptr;                            \
00265             flag = USE_IT;                                              \
00266         } else {                                                        \
00267             if (_ltob((int *)stop->base_addr.a.ptr) == 0) {             \
00268                 flag = FALSE_MASK;                                      \
00269             }                                                           \
00270         }
00271 
00272 
00273 /************************************************************************
00274  *
00275  * DIM_CHK(dim) - Check to insure that the DIM arguments to the
00276  *              array intrinsics contains a legal value from 1
00277  *              through the extent of the source array.
00278  *
00279  * Arguments:     long dim;
00280  *
00281  ************************************************************************/
00282 
00283 #define DIM_CHK(dim)                                                    \
00284         if ((*dim < 1) || (*dim > RANK)) {                              \
00285             _lerror(_LELVL_ABORT, FESCIDIM);                            \
00286         }
00287 
00288 
00289 /************************************************************************
00290  *
00291  * INIT_DIM_COUNT() - Check to insure that the DIM argument to the
00292  *              shift arrary intrinsics contains a legal value from 1
00293  *              through the extent of the source array.  If no DIM is
00294  *                present, make it default to 1.
00295  *
00296  * Arguments:     long dim;
00297  *
00298  ************************************************************************/
00299 
00300 #define INIT_DIM_COUNT()                                                \
00301         if (dim == NULL) {                                              \
00302             dim_val = 1;                                                \
00303         } else if ((*dim < 1) || (*dim > RANK)) {                       \
00304             _lerror(_LELVL_ABORT, FESCIDIM);                            \
00305         } else {                                                        \
00306             dim_val = *dim;                                             \
00307         }
00308 
00309 /***********************************************************************
00310  * INIT_SHFT_SDD()      - Fill in the sdd fields for the result sdd.
00311  *                      Since the result will always be the same shape
00312  *                      as the source, the distribution will also be
00313  *                      the same, so the sdd fields will be copied.
00314  **********************************************************************/
00315 
00316 #define INIT_SHFT_SDD()                                                 \
00317                                                                         \
00318 /*                                                                      \
00319  *      Set the base address field in the sdd to the base pointer.      \
00320  */                                                                     \
00321                                                                         \
00322         _sdd_write_base(result_sdd_ptr, result->base_addr.a.ptr);       \
00323                                                                         \
00324 /*                                                                      \
00325  *      Copy the block fields from the source sdd to the result sdd     \
00326  */                                                                     \
00327                                                                         \
00328 _Pragma ("shortloop"); \
00329         for (i = 0; i < RANK; i++) {                                    \
00330             tmp = _sdd_read_cyc_ebp (source->base_addr.a.ptr, i);       \
00331             _sdd_write_cyc_ebp (result->base_addr.a.ptr, i, tmp);       \
00332             tmp = _sdd_read_pe_bcnt (source->base_addr.a.ptr, i);       \
00333             _sdd_write_pe_bcnt (result->base_addr.a.ptr, i, tmp);       \
00334             tmp = _sdd_read_blk_ebp (source->base_addr.a.ptr, i);       \
00335             _sdd_write_blk_ebp (result->base_addr.a.ptr, i, tmp);       \
00336             tmp = _sdd_read_canon (source->base_addr.a.ptr);            \
00337             _sdd_write_canon (result->base_addr.a.ptr, tmp);            \
00338             tmp = _sdd_read_offset (source->base_addr.a.ptr);           \
00339             _sdd_write_offset (result->base_addr.a.ptr, tmp);           \
00340         }                                                               \
00341 
00342 
00343 /***********************************************************************
00344  *      The shift count can be a scalar or an array.  If scalar, set the
00345  *      shift scalar flag, and set the shift value counter to the shift
00346  *      value.  If shift is an array, clear the shift scalar flag.  In
00347  *      either case, the shift array pointer will be passed to the work
00348  *      routine, but it will not be used if the scalar flag is set.
00349  **********************************************************************/
00350 
00351 #define INIT_SHIFT_COUNT()                                              \
00352         if (shift->n_dim == 0) {                                        \
00353             shflag = _btol (1);                                         \
00354             i = (int) shift->base_addr.a.ptr;                           \
00355             if (i > 0)                                                  \
00356                 shptr = (int *) shift->base_addr.a.ptr;                 \
00357             else {                                                      \
00358                 shptr = (int *) _sdd_read_base(shift->base_addr.a.ptr); \
00359             }                                                           \
00360             shftval = shptr[0];                                         \
00361         } else {                                                        \
00362             shflag = _btol (0);                                         \
00363         }                                                               \
00364 
00365 
00366 /***********************************************************************
00367  *      The boundary value for an eoshift call can be non-existent, a
00368  *      scalar value, or an array.  If non-existent, we need to set the
00369  *      boundary flag to indicate a scalar, and set the scalar boundary
00370  *      variable to the default value.  If the bound is a scalar, we
00371  *      need to set the scalar flag, and put the value in the scalar
00372  *      boundary variable.  If the bound argument is an array, clear
00373  *      the boundary scalar flag.
00374  **********************************************************************/
00375 
00376 #define INIT_BOUND_1WORD()                                              \
00377         if (boundary) {                                                 \
00378             if (boundary->n_dim == 0) {                                 \
00379                 bndflag = 1;                                            \
00380                 i = (int) boundary->base_addr.a.ptr;                    \
00381                 if (i > 0)                                              \
00382                     vptr = (void *) boundary->base_addr.a.ptr;          \
00383                 else                                                    \
00384                     vptr = _sdd_read_base(boundary->base_addr.a.ptr);   \
00385                 ptr = (int *) vptr;                                     \
00386                 bndval = ptr[0];                                        \
00387             } else {                                                    \
00388                 bndflag = 0;                                            \
00389             }                                                           \
00390         } else {                                                        \
00391             bndflag = 1;                                                \
00392             if (source->type_lens.type == DVTYPE_INTEGER)               \
00393                 bndval = 0;                                             \
00394             else if (source->type_lens.type == DVTYPE_REAL)             \
00395                 bndval = *(int *) &defaultr;                            \
00396             else                                                        \
00397                 bndval = _btol (0);                                     \
00398         }
00399 
00400 #define INIT_BOUND_2WORD()                                              \
00401         if (boundary) {                                                 \
00402             if (boundary->n_dim == 0) {                                 \
00403                 bndflag = 1;                                            \
00404                 i = (int) boundary->base_addr.a.ptr;                    \
00405                 if (i > 0)                                              \
00406                     vptr = (void *) boundary->base_addr.a.ptr;          \
00407                 else                                                    \
00408                     vptr = _sdd_read_base(boundary->base_addr.a.ptr);   \
00409                 ptr = (_f_comp *) vptr;                                 \
00410                 bndval = ptr[0];                                        \
00411             } else {                                                    \
00412                 bndflag = 0;                                            \
00413             }                                                           \
00414         } else {                                                        \
00415             bndflag = 1;                                                \
00416             bndval = 0.0 + 0.0i;                                        \
00417         }
00418 
00419 /************************************************************************
00420  *
00421  * SETUP_PRE_BLKCNTS() - Set up an array of block counts for each
00422  *                 dimension of the source array.
00423  *
00424  * Variables used: long blkcnts[RANK];
00425  *               long dim_bcnt;
00426  *               DopeVectorType * source;
00427  *
00428  ************************************************************************/
00429 
00430 #define SETUP_PRE_BLKCNTS()                                             \
00431         if (_in_parallel()) {                                           \
00432             long *sdd_ptr;                                              \
00433             sdd_ptr = source->base_addr.a.ptr;                          \
00434             for (i=0; i < RANK; i++) {                                  \
00435                 blkcnts[i] = _blkct(sdd_ptr,i+1,_MY_PE());              \
00436             }                                                           \
00437         }
00438 
00439 
00440 
00441 
00442                                                                         
00443 #ifdef  NOMORE
00444         /*                                                              \
00445          * Calculate cyc_ebp and blk_ebp for the 2nd dimension as       \
00446          * log2(source->n_dim) + cyc_ebp for dimension 1. The pe_cnt    \
00447          * is always 0 for the 2nd dimension.                           \
00448          */                                                             \
00449                                                                         \
00450         dim2_tmp = LOG2(RANK);                                          \
00451         if (_popcnt(RANK) != 1) {                                       \
00452             dim2_tmp++; /* adjust since n_dim not a power of 2 */       \
00453         }                                                               \
00454         dim2_tmp += dim1_tmp;                                           \
00455         _sdd_write_cyc_ebp(result->base_addr.a.ptr,2,dim2_tmp);         \
00456         _sdd_write_pe_bcnt(result->base_addr.a.ptr,2,0);                \
00457         _sdd_write_blk_ebp(result->base_addr.a.ptr,2,dim2_tmp);
00458 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines