Open64 (mfef90, whirl2f, and IR tools)  TAG: version-openad; SVN changeset: 916
int64.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 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 
00036 /* Some macros to implement 64-bit integer operations with arrays of 16-bit
00037  * unsigned integers.
00038  */
00039 
00040 #if _CRAY
00041 #define ZERO64(a) ( *((long*)&(a)) = 0 )
00042 #else
00043 #define ZERO64(a) ( (a).part1 = (a).part2 = (a).part3 = (a).part4 = 0 )
00044 #endif
00045 
00046 #if _CRAY
00047 #define COPY64(to,fr) ( *((long*)&(to)) = *((long*)&(fr)) )
00048 #else
00049 #define COPY64(to,fr) ( (to).part1 = (fr).part1,                        \
00050                         (to).part2 = (fr).part2,                        \
00051                         (to).part3 = (fr).part3,                        \
00052                         (to).part4 = (fr).part4 )
00053 #endif
00054 
00055 #if _CRAY
00056 #define SHLEFT64(x) ( *((long*)&(x)) = *((long*)&(x))<<1 )
00057 #else
00058 #define SHLEFT64(x) do {                                                \
00059         (x).part1 = ((x).part1 << 1) | ((x).part2 >> 15);               \
00060         (x).part2 = ((x).part2 << 1) | ((x).part3 >> 15);               \
00061         (x).part3 = ((x).part3 << 1) | ((x).part4 >> 15);               \
00062         (x).part4 = (x).part4 << 1;                                     \
00063 } while (0)
00064 #endif
00065 
00066 #if _CRAY
00067 #define SHLEFT64N(x,n) ( *((long*)&(x)) = *((long*)&(x))<<(n) )
00068 #else
00069 #define SHLEFT64N(x,n) do {                                             \
00070         register int _n = n;                                            \
00071         switch(_n>>4){                                                  \
00072         case 0:                                                         \
00073                 (x).part1 = ((x).part1 << _n) | ((x).part2 >> (16-_n)); \
00074                 (x).part2 = ((x).part2 << _n) | ((x).part3 >> (16-_n)); \
00075                 (x).part3 = ((x).part3 << _n) | ((x).part4 >> (16-_n)); \
00076                 (x).part4 = ((x).part4 << _n);                          \
00077                 break;                                                  \
00078         case 1:                                                         \
00079                 (x).part1 = ((x).part2 << (_n-16)) | ((x).part3 >> (32-_n));\
00080                 (x).part2 = ((x).part3 << (_n-16)) | ((x).part4 >> (32-_n));\
00081                 (x).part3 = ((x).part4 << (_n-16));                     \
00082                 (x).part4 = 0;                                          \
00083                 break;                                                  \
00084         case 2:                                                         \
00085                 (x).part1 = ((x).part3 << (_n-32)) | ((x).part4 >> (48-_n));\
00086                 (x).part2 = ((x).part4 << (_n-32));                     \
00087                 (x).part3 = (x).part4 = 0;                              \
00088                 break;                                                  \
00089         case 3:                                                         \
00090                 (x).part1 = ((x).part4 << (_n-48));                     \
00091                 (x).part2 = (x).part3 = (x).part4 = 0;                  \
00092                 break;                                                  \
00093         default:                                                        \
00094                 (x).part1 = (x).part2 = (x).part3 = (x).part4 = 0;      \
00095         }                                                               \
00096 } while(0)
00097 #endif
00098 
00099 #if _CRAY
00100 #define SHRIGHT64(x) ( *((unsigned long*)&(x)) = *((unsigned long*)&(x))>>1 )
00101 #else
00102 #define SHRIGHT64(x) do {                                               \
00103         (x).part4 = ((x).part4 >> 1) | (((x).part3 & 1) << 15);         \
00104         (x).part3 = ((x).part3 >> 1) | (((x).part2 & 1) << 15);         \
00105         (x).part2 = ((x).part2 >> 1) | (((x).part1 & 1) << 15);         \
00106         (x).part1 >>= 1;                                                \
00107 } while (0)
00108 #endif
00109 
00110 #if _CRAY
00111 #define SHRIGHT64N(x,n) ( *((unsigned long*)&(x)) = *((unsigned long*)&(x))>>(n) )
00112 #else
00113 #define SHRIGHT64N(x,n) do {                                            \
00114         register int _n = n;                                            \
00115         switch(_n>>4) {                                                 \
00116         case 0:                                                         \
00117                 (x).part4 = ((x).part4 >> _n) | ((x).part3 << (16-_n)); \
00118                 (x).part3 = ((x).part3 >> _n) | ((x).part2 << (16-_n)); \
00119                 (x).part2 = ((x).part2 >> _n) | ((x).part1 << (16-_n)); \
00120                 (x).part1 = ((x).part1 >> _n);                          \
00121                 break;                                                  \
00122         case 1:                                                         \
00123                 (x).part4 = ((x).part3 >> (_n-16)) | ((x).part2 << (32-_n));\
00124                 (x).part3 = ((x).part2 >> (_n-16)) | ((x).part1 << (32-_n));\
00125                 (x).part2 = ((x).part1 >> (_n-16));                     \
00126                 (x).part1 = 0;                                          \
00127                 break;                                                  \
00128         case 2:                                                         \
00129                 (x).part4 = ((x).part2 >> (_n-32)) | ((x).part1 << (48-_n));\
00130                 (x).part3 = ((x).part1 >> (_n-32));                     \
00131                 (x).part2 = (x).part1 = 0;                              \
00132                 break;                                                  \
00133         case 3:                                                         \
00134                 (x).part4 = ((x).part1 >> (_n-48));                     \
00135                 (x).part3 = (x).part2 = (x).part1 = 0;                  \
00136                 break;                                                  \
00137         default:                                                        \
00138                 (x).part4 = (x).part3 = (x).part2 = (x).part1 = 0;      \
00139         }                                                               \
00140 } while(0)
00141 #endif
00142 
00143 #if _CRAY
00144 #define SHRIGHT64X(x) ( *((unsigned long*)&(x)) = \
00145         (*((unsigned long*)&(x))&0x8000000000000000) | (*((unsigned long*)&(x))>>1) )
00146 #else
00147 #define SHRIGHT64X(x) do {                                              \
00148         (x).part4 = ((x).part4 >> 1) | (((x).part3 & 1) << 15);         \
00149         (x).part3 = ((x).part3 >> 1) | (((x).part2 & 1) << 15);         \
00150         (x).part2 = ((x).part2 >> 1) | (((x).part1 & 1) << 15);         \
00151         (x).part1 = ((x).part1 >> 1) | ((x).part1 & (1 << 15));         \
00152 } while (0)
00153 #endif
00154 
00155 #if _CRAY
00156 #define SIGNBIT(x)      ( *((long*)&(x))>>63 )
00157 #else
00158 #define SIGNBIT(x)      ( (x).part1 >> 15 )
00159 #endif
00160 
00161 #if _CRAY
00162 #define ADD64(sum,a,b) ( *((long*)&(sum)) = *((long*)&(a)) + *((long*)&(b)) )
00163 #else
00164 #define ADD64(sum,a,b) do {                                             \
00165         unsigned long t = (a).part4 + (b).part4;                        \
00166         (sum).part4 = t;                                                \
00167         t >>= 16;                                                       \
00168         (sum).part3 = t += (a).part3 + (b).part3;                       \
00169         t >>= 16;                                                       \
00170         (sum).part2 = t += (a).part2 + (b).part2;                       \
00171         (sum).part1 = (t >> 16) + (a).part1 + (b).part1;                \
00172 } while (0)
00173 #endif
00174 
00175 #if _CRAY
00176 #define INC64(a) ( (*((long*)&(a)))++ )
00177 #else
00178 #define INC64(a) do {                                                   \
00179         unsigned long t = (a).part4 + 1;                                \
00180         (a).part4 = t;                                                  \
00181         (a).part3 = t = (t >> 16) + (a).part3;                          \
00182         (a).part2 = t = (t >> 16) + (a).part2;                          \
00183         (a).part1 += t >> 16;                                           \
00184 } while (0)
00185 #endif
00186 
00187 #if _CRAY
00188 #define DEC64(a) ( (*((long*)&(a)))-- )
00189 #else
00190 #define DEC64(a) do {                                                   \
00191         unsigned long t = (a).part4 + MASKR (16);                       \
00192         (a).part4 = t;                                                  \
00193         (a).part3 = t = (t >> 16) + (a).part3 + MASKR (16);             \
00194         (a).part2 = t = (t >> 16) + (a).part2 + MASKR (16);             \
00195         (a).part1 += (t >> 16) + MASKR (16);                            \
00196 } while (0)
00197 #endif
00198 
00199 #if _CRAY
00200 #define NEG64(a) ( *((long*)&(a)) = -(*((long*)&(a))) )
00201 #else
00202 #define NEG64(a) do {                                                   \
00203         NOT64 (a);                                                      \
00204         INC64 (a);                                                      \
00205 } while (0)
00206 #endif
00207 
00208 #define MULSTEP(sum,bits,val,ct) do {                                   \
00209         int i;                                                          \
00210         for (i = 0; i < (ct); i++) {                                    \
00211                 SHLEFT64 (bits);                                        \
00212                 if (SIGNBIT (bits))                                     \
00213                         ADD64 (sum, sum, val);                          \
00214                 SHRIGHT64 (val);                                        \
00215         }                                                               \
00216 } while (0)
00217 
00218 #if _CRAY
00219 #define NOT64(a) ( *((long*)&(a)) = ~(*((long*)&(a))) )
00220 #else
00221 #define NOT64(a) ( (a).part1 ^= MASKR (16),                             \
00222                    (a).part2 ^= MASKR (16),                             \
00223                    (a).part3 ^= MASKR (16),                             \
00224                    (a).part4 ^= MASKR (16) )
00225 #endif
00226 
00227 
00228 #ifdef _LITTLE_ENDIAN
00229 #define WORD_SWAP(x)    \
00230   { unsigned long t  ;  \
00231     t = (x).part1 ;   (x).part1 = (x).part4; (x).part4=t;             \
00232     t = (x).part2 ;   (x).part2 = (x).part3; (x).part3=t;             \
00233    }
00234 #else
00235 #define WORD_SWAP(x) 
00236 #endif
00237 
00238 /* $Id: int64.h,v 1.1.1.1 2002-05-22 20:06:19 dsystem Exp $ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines