Back to index

cell-binutils  2.17cvs20070401
cgen-ops.h
Go to the documentation of this file.
00001 /* Semantics ops support for CGEN-based opcode libraries.
00002    Copyright (C) 2005 Free Software Foundation, Inc.
00003    Contributed by Red Hat.
00004 
00005 This file is part of the GNU opcodes library.
00006 
00007 This program is free software; you can redistribute it and/or modify
00008 it under the terms of the GNU General Public License as published by
00009 the Free Software Foundation; either version 2, or (at your option)
00010 any later version.
00011 
00012 This program is distributed in the hope that it will be useful,
00013 but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 GNU General Public License for more details.
00016 
00017 You should have received a copy of the GNU General Public License along
00018 with this program; if not, write to the Free Software Foundation, Inc.,
00019 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00020 
00021 */
00022 
00023 #ifndef CGEN_SEM_OPS_H
00024 #define CGEN_SEM_OPS_H
00025 
00026 #include <assert.h>
00027 
00028 #if defined (__GNUC__) && ! defined (SEMOPS_DEFINE_INLINE)
00029 #define SEMOPS_DEFINE_INLINE
00030 #define SEMOPS_INLINE extern inline
00031 #else
00032 #define SEMOPS_INLINE
00033 #endif
00034 
00035 /* TODO: Lazy encoding/decoding of fp values.  */
00036 
00037 /* These don't really have a mode.  */
00038 #define ANDIF(x, y) ((x) && (y))
00039 #define ORIF(x, y) ((x) || (y))
00040 
00041 #define SUBBI(x, y) ((x) - (y))
00042 #define ANDBI(x, y) ((x) & (y))
00043 #define ORBI(x, y) ((x) | (y))
00044 #define XORBI(x, y) ((x) ^ (y))
00045 #define NEGBI(x) (- (x))
00046 #define NOTBI(x) (! (BI) (x))
00047 #define INVBI(x) (~ (x))
00048 #define EQBI(x, y) ((BI) (x) == (BI) (y))
00049 #define NEBI(x, y) ((BI) (x) != (BI) (y))
00050 #define LTBI(x, y) ((BI) (x) < (BI) (y))
00051 #define LEBI(x, y) ((BI) (x) <= (BI) (y))
00052 #define GTBI(x, y) ((BI) (x) > (BI) (y))
00053 #define GEBI(x, y) ((BI) (x) >= (BI) (y))
00054 #define LTUBI(x, y) ((BI) (x) < (BI) (y))
00055 #define LEUBI(x, y) ((BI) (x) <= (BI) (y))
00056 #define GTUBI(x, y) ((BI) (x) > (BI) (y))
00057 #define GEUBI(x, y) ((BI) (x) >= (BI) (y))
00058 
00059 #define ADDQI(x, y) ((x) + (y))
00060 #define SUBQI(x, y) ((x) - (y))
00061 #define MULQI(x, y) ((x) * (y))
00062 #define DIVQI(x, y) ((QI) (x) / (QI) (y))
00063 #define UDIVQI(x, y) ((UQI) (x) / (UQI) (y))
00064 #define MODQI(x, y) ((QI) (x) % (QI) (y))
00065 #define UMODQI(x, y) ((UQI) (x) % (UQI) (y))
00066 #define SRAQI(x, y) ((QI) (x) >> (y))
00067 #define SRLQI(x, y) ((UQI) (x) >> (y))
00068 #define SLLQI(x, y) ((UQI) (x) << (y))
00069 extern QI RORQI (QI, int);
00070 extern QI ROLQI (QI, int);
00071 #define ANDQI(x, y) ((x) & (y))
00072 #define ORQI(x, y) ((x) | (y))
00073 #define XORQI(x, y) ((x) ^ (y))
00074 #define NEGQI(x) (- (x))
00075 #define NOTQI(x) (! (QI) (x))
00076 #define INVQI(x) (~ (x))
00077 #define ABSQI(x) ((x) < 0 ? -(x) : (x))
00078 #define EQQI(x, y) ((QI) (x) == (QI) (y))
00079 #define NEQI(x, y) ((QI) (x) != (QI) (y))
00080 #define LTQI(x, y) ((QI) (x) < (QI) (y))
00081 #define LEQI(x, y) ((QI) (x) <= (QI) (y))
00082 #define GTQI(x, y) ((QI) (x) > (QI) (y))
00083 #define GEQI(x, y) ((QI) (x) >= (QI) (y))
00084 #define LTUQI(x, y) ((UQI) (x) < (UQI) (y))
00085 #define LEUQI(x, y) ((UQI) (x) <= (UQI) (y))
00086 #define GTUQI(x, y) ((UQI) (x) > (UQI) (y))
00087 #define GEUQI(x, y) ((UQI) (x) >= (UQI) (y))
00088 
00089 #define ADDHI(x, y) ((x) + (y))
00090 #define SUBHI(x, y) ((x) - (y))
00091 #define MULHI(x, y) ((x) * (y))
00092 #define DIVHI(x, y) ((HI) (x) / (HI) (y))
00093 #define UDIVHI(x, y) ((UHI) (x) / (UHI) (y))
00094 #define MODHI(x, y) ((HI) (x) % (HI) (y))
00095 #define UMODHI(x, y) ((UHI) (x) % (UHI) (y))
00096 #define SRAHI(x, y) ((HI) (x) >> (y))
00097 #define SRLHI(x, y) ((UHI) (x) >> (y))
00098 #define SLLHI(x, y) ((UHI) (x) << (y))
00099 extern HI RORHI (HI, int);
00100 extern HI ROLHI (HI, int);
00101 #define ANDHI(x, y) ((x) & (y))
00102 #define ORHI(x, y) ((x) | (y))
00103 #define XORHI(x, y) ((x) ^ (y))
00104 #define NEGHI(x) (- (x))
00105 #define NOTHI(x) (! (HI) (x))
00106 #define INVHI(x) (~ (x))
00107 #define ABSHI(x) ((x) < 0 ? -(x) : (x))
00108 #define EQHI(x, y) ((HI) (x) == (HI) (y))
00109 #define NEHI(x, y) ((HI) (x) != (HI) (y))
00110 #define LTHI(x, y) ((HI) (x) < (HI) (y))
00111 #define LEHI(x, y) ((HI) (x) <= (HI) (y))
00112 #define GTHI(x, y) ((HI) (x) > (HI) (y))
00113 #define GEHI(x, y) ((HI) (x) >= (HI) (y))
00114 #define LTUHI(x, y) ((UHI) (x) < (UHI) (y))
00115 #define LEUHI(x, y) ((UHI) (x) <= (UHI) (y))
00116 #define GTUHI(x, y) ((UHI) (x) > (UHI) (y))
00117 #define GEUHI(x, y) ((UHI) (x) >= (UHI) (y))
00118 
00119 #define ADDSI(x, y) ((x) + (y))
00120 #define SUBSI(x, y) ((x) - (y))
00121 #define MULSI(x, y) ((x) * (y))
00122 #define DIVSI(x, y) ((SI) (x) / (SI) (y))
00123 #define UDIVSI(x, y) ((USI) (x) / (USI) (y))
00124 #define MODSI(x, y) ((SI) (x) % (SI) (y))
00125 #define UMODSI(x, y) ((USI) (x) % (USI) (y))
00126 #define SRASI(x, y) ((SI) (x) >> (y))
00127 #define SRLSI(x, y) ((USI) (x) >> (y))
00128 #define SLLSI(x, y) ((USI) (x) << (y))
00129 extern SI RORSI (SI, int);
00130 extern SI ROLSI (SI, int);
00131 #define ANDSI(x, y) ((x) & (y))
00132 #define ORSI(x, y) ((x) | (y))
00133 #define XORSI(x, y) ((x) ^ (y))
00134 #define NEGSI(x) (- (x))
00135 #define NOTSI(x) (! (SI) (x))
00136 #define INVSI(x) (~ (x))
00137 #define ABSSI(x) ((x) < 0 ? -(x) : (x))
00138 #define EQSI(x, y) ((SI) (x) == (SI) (y))
00139 #define NESI(x, y) ((SI) (x) != (SI) (y))
00140 #define LTSI(x, y) ((SI) (x) < (SI) (y))
00141 #define LESI(x, y) ((SI) (x) <= (SI) (y))
00142 #define GTSI(x, y) ((SI) (x) > (SI) (y))
00143 #define GESI(x, y) ((SI) (x) >= (SI) (y))
00144 #define LTUSI(x, y) ((USI) (x) < (USI) (y))
00145 #define LEUSI(x, y) ((USI) (x) <= (USI) (y))
00146 #define GTUSI(x, y) ((USI) (x) > (USI) (y))
00147 #define GEUSI(x, y) ((USI) (x) >= (USI) (y))
00148 
00149 #ifdef DI_FN_SUPPORT
00150 extern DI ADDDI (DI, DI);
00151 extern DI SUBDI (DI, DI);
00152 extern DI MULDI (DI, DI);
00153 extern DI DIVDI (DI, DI);
00154 extern DI UDIVDI (DI, DI);
00155 extern DI MODDI (DI, DI);
00156 extern DI UMODDI (DI, DI);
00157 extern DI SRADI (DI, int);
00158 extern UDI SRLDI (UDI, int);
00159 extern UDI SLLDI (UDI, int);
00160 extern DI RORDI (DI, int);
00161 extern DI ROLDI (DI, int);
00162 extern DI ANDDI (DI, DI);
00163 extern DI ORDI (DI, DI);
00164 extern DI XORDI (DI, DI);
00165 extern DI NEGDI (DI);
00166 extern int NOTDI (DI);
00167 extern DI INVDI (DI);
00168 extern int EQDI (DI, DI);
00169 extern int NEDI (DI, DI);
00170 extern int LTDI (DI, DI);
00171 extern int LEDI (DI, DI);
00172 extern int GTDI (DI, DI);
00173 extern int GEDI (DI, DI);
00174 extern int LTUDI (UDI, UDI);
00175 extern int LEUDI (UDI, UDI);
00176 extern int GTUDI (UDI, UDI);
00177 extern int GEUDI (UDI, UDI);
00178 #else /* ! DI_FN_SUPPORT */
00179 #define ADDDI(x, y) ((x) + (y))
00180 #define SUBDI(x, y) ((x) - (y))
00181 #define MULDI(x, y) ((x) * (y))
00182 #define DIVDI(x, y) ((DI) (x) / (DI) (y))
00183 #define UDIVDI(x, y) ((UDI) (x) / (UDI) (y))
00184 #define MODDI(x, y) ((DI) (x) % (DI) (y))
00185 #define UMODDI(x, y) ((UDI) (x) % (UDI) (y))
00186 #define SRADI(x, y) ((DI) (x) >> (y))
00187 #define SRLDI(x, y) ((UDI) (x) >> (y))
00188 #define SLLDI(x, y) ((UDI) (x) << (y))
00189 extern DI RORDI (DI, int);
00190 extern DI ROLDI (DI, int);
00191 #define ANDDI(x, y) ((x) & (y))
00192 #define ORDI(x, y) ((x) | (y))
00193 #define XORDI(x, y) ((x) ^ (y))
00194 #define NEGDI(x) (- (x))
00195 #define NOTDI(x) (! (DI) (x))
00196 #define INVDI(x) (~ (x))
00197 #define ABSDI(x) ((x) < 0 ? -(x) : (x))
00198 #define EQDI(x, y) ((DI) (x) == (DI) (y))
00199 #define NEDI(x, y) ((DI) (x) != (DI) (y))
00200 #define LTDI(x, y) ((DI) (x) < (DI) (y))
00201 #define LEDI(x, y) ((DI) (x) <= (DI) (y))
00202 #define GTDI(x, y) ((DI) (x) > (DI) (y))
00203 #define GEDI(x, y) ((DI) (x) >= (DI) (y))
00204 #define LTUDI(x, y) ((UDI) (x) < (UDI) (y))
00205 #define LEUDI(x, y) ((UDI) (x) <= (UDI) (y))
00206 #define GTUDI(x, y) ((UDI) (x) > (UDI) (y))
00207 #define GEUDI(x, y) ((UDI) (x) >= (UDI) (y))
00208 #endif /* DI_FN_SUPPORT */
00209 
00210 #define EXTBIQI(x) ((QI) (BI) (x))
00211 #define EXTBIHI(x) ((HI) (BI) (x))
00212 #define EXTBISI(x) ((SI) (BI) (x))
00213 #if defined (DI_FN_SUPPORT)
00214 extern DI EXTBIDI (BI);
00215 #else
00216 #define EXTBIDI(x) ((DI) (BI) (x))
00217 #endif
00218 #define EXTQIHI(x) ((HI) (QI) (x))
00219 #define EXTQISI(x) ((SI) (QI) (x))
00220 #if defined (DI_FN_SUPPORT)
00221 extern DI EXTQIDI (QI);
00222 #else
00223 #define EXTQIDI(x) ((DI) (QI) (x))
00224 #endif
00225 #define EXTHIHI(x) ((HI) (HI) (x))
00226 #define EXTHISI(x) ((SI) (HI) (x))
00227 #define EXTSISI(x) ((SI) (SI) (x))
00228 #if defined (DI_FN_SUPPORT)
00229 extern DI EXTHIDI (HI);
00230 #else
00231 #define EXTHIDI(x) ((DI) (HI) (x))
00232 #endif
00233 #if defined (DI_FN_SUPPORT)
00234 extern DI EXTSIDI (SI);
00235 #else
00236 #define EXTSIDI(x) ((DI) (SI) (x))
00237 #endif
00238 
00239 #define ZEXTBIQI(x) ((QI) (BI) (x))
00240 #define ZEXTBIHI(x) ((HI) (BI) (x))
00241 #define ZEXTBISI(x) ((SI) (BI) (x))
00242 #if defined (DI_FN_SUPPORT)
00243 extern DI ZEXTBIDI (BI);
00244 #else
00245 #define ZEXTBIDI(x) ((DI) (BI) (x))
00246 #endif
00247 #define ZEXTQIHI(x) ((HI) (UQI) (x))
00248 #define ZEXTQISI(x) ((SI) (UQI) (x))
00249 #if defined (DI_FN_SUPPORT)
00250 extern DI ZEXTQIDI (QI);
00251 #else
00252 #define ZEXTQIDI(x) ((DI) (UQI) (x))
00253 #endif
00254 #define ZEXTHISI(x) ((SI) (UHI) (x))
00255 #define ZEXTHIHI(x) ((HI) (UHI) (x))
00256 #define ZEXTSISI(x) ((SI) (USI) (x))
00257 #if defined (DI_FN_SUPPORT)
00258 extern DI ZEXTHIDI (HI);
00259 #else
00260 #define ZEXTHIDI(x) ((DI) (UHI) (x))
00261 #endif
00262 #if defined (DI_FN_SUPPORT)
00263 extern DI ZEXTSIDI (SI);
00264 #else
00265 #define ZEXTSIDI(x) ((DI) (USI) (x))
00266 #endif
00267 
00268 #define TRUNCQIBI(x) ((BI) (QI) (x))
00269 #define TRUNCHIBI(x) ((BI) (HI) (x))
00270 #define TRUNCHIQI(x) ((QI) (HI) (x))
00271 #define TRUNCSIBI(x) ((BI) (SI) (x))
00272 #define TRUNCSIQI(x) ((QI) (SI) (x))
00273 #define TRUNCSIHI(x) ((HI) (SI) (x))
00274 #define TRUNCSISI(x) ((SI) (SI) (x))
00275 #if defined (DI_FN_SUPPORT)
00276 extern BI TRUNCDIBI (DI);
00277 #else
00278 #define TRUNCDIBI(x) ((BI) (DI) (x))
00279 #endif
00280 #if defined (DI_FN_SUPPORT)
00281 extern QI TRUNCDIQI (DI);
00282 #else
00283 #define TRUNCDIQI(x) ((QI) (DI) (x))
00284 #endif
00285 #if defined (DI_FN_SUPPORT)
00286 extern HI TRUNCDIHI (DI);
00287 #else
00288 #define TRUNCDIHI(x) ((HI) (DI) (x))
00289 #endif
00290 #if defined (DI_FN_SUPPORT)
00291 extern SI TRUNCDISI (DI);
00292 #else
00293 #define TRUNCDISI(x) ((SI) (DI) (x))
00294 #endif
00295 
00296 /* Composing/decomposing the various types.
00297    Word ordering is endian-independent.  Words are specified most to least
00298    significant and word number 0 is the most significant word.
00299    ??? May also wish an endian-dependent version.  Later.  */
00300 
00301 QI SUBWORDSIQI (SI, int);
00302 HI SUBWORDSIHI (SI, int);
00303 SI SUBWORDSFSI (SF);
00304 SF SUBWORDSISF (SI);
00305 DI SUBWORDDFDI (DF);
00306 DF SUBWORDDIDF (DI);
00307 QI SUBWORDDIQI (DI, int);
00308 HI SUBWORDDIHI (DI, int);
00309 SI SUBWORDDISI (DI, int);
00310 SI SUBWORDDFSI (DF, int);
00311 SI SUBWORDXFSI (XF, int);
00312 SI SUBWORDTFSI (TF, int);
00313 
00314 UQI SUBWORDSIUQI (SI, int);
00315 UQI SUBWORDDIUQI (DI, int);
00316 
00317 #ifdef SEMOPS_DEFINE_INLINE
00318 
00319 SEMOPS_INLINE SF
00320 SUBWORDSISF (SI in)
00321 {
00322   union { SI in; SF out; } x;
00323   x.in = in;
00324   return x.out;
00325 }
00326 
00327 SEMOPS_INLINE DF
00328 SUBWORDDIDF (DI in)
00329 {
00330   union { DI in; DF out; } x;
00331   x.in = in;
00332   return x.out;
00333 }
00334 
00335 SEMOPS_INLINE QI
00336 SUBWORDSIQI (SI in, int byte)
00337 {
00338   assert (byte >= 0 && byte <= 3);
00339   return (UQI) (in >> (8 * (3 - byte))) & 0xFF;
00340 }
00341 
00342 SEMOPS_INLINE UQI
00343 SUBWORDSIUQI (SI in, int byte)
00344 {
00345   assert (byte >= 0 && byte <= 3);
00346   return (UQI) (in >> (8 * (3 - byte))) & 0xFF;
00347 }
00348 
00349 SEMOPS_INLINE QI
00350 SUBWORDDIQI (DI in, int byte)
00351 {
00352   assert (byte >= 0 && byte <= 7);
00353   return (UQI) (in >> (8 * (7 - byte))) & 0xFF;
00354 }
00355 
00356 SEMOPS_INLINE HI
00357 SUBWORDDIHI (DI in, int word)
00358 {
00359   assert (word >= 0 && word <= 3);
00360   return (UHI) (in >> (16 * (3 - word))) & 0xFFFF;
00361 }
00362 
00363 SEMOPS_INLINE HI
00364 SUBWORDSIHI (SI in, int word)
00365 {
00366   if (word == 0)
00367     return (USI) in >> 16;
00368   else
00369     return in;
00370 }
00371 
00372 SEMOPS_INLINE SI
00373 SUBWORDSFSI (SF in)
00374 {
00375   union { SF in; SI out; } x;
00376   x.in = in;
00377   return x.out;
00378 }
00379 
00380 SEMOPS_INLINE DI
00381 SUBWORDDFDI (DF in)
00382 {
00383   union { DF in; DI out; } x;
00384   x.in = in;
00385   return x.out;
00386 }
00387 
00388 SEMOPS_INLINE UQI
00389 SUBWORDDIUQI (DI in, int byte)
00390 {
00391   assert (byte >= 0 && byte <= 7);
00392   return (UQI) (in >> (8 * (7 - byte)));
00393 }
00394 
00395 SEMOPS_INLINE SI
00396 SUBWORDDISI (DI in, int word)
00397 {
00398   if (word == 0)
00399     return (UDI) in >> 32;
00400   else
00401     return in;
00402 }
00403 
00404 SEMOPS_INLINE SI
00405 SUBWORDDFSI (DF in, int word)
00406 {
00407   /* Note: typedef UDI DF; */
00408   if (word == 0)
00409     return (UDI) in >> 32;
00410   else
00411     return in;
00412 }
00413 
00414 SEMOPS_INLINE SI
00415 SUBWORDXFSI (XF in, int word)
00416 {
00417   /* Note: typedef struct { SI parts[3]; } XF; */
00418   union { XF in; SI out[3]; } x;
00419   x.in = in;
00420   return x.out[word];
00421 }
00422 
00423 SEMOPS_INLINE SI
00424 SUBWORDTFSI (TF in, int word)
00425 {
00426   /* Note: typedef struct { SI parts[4]; } TF; */
00427   union { TF in; SI out[4]; } x;
00428   x.in = in;
00429   return x.out[word];
00430 }
00431 
00432 #endif /* SUBWORD,JOIN */
00433 
00434 #endif /* CGEN_SEM_OPS_H */