Home | History | Annotate | Download | only in cgen
      1 /* Basic semantics ops support for CGEN.
      2    Copyright (C) 2005-2014 Free Software Foundation, Inc.
      3    Contributed by Red Hat.
      4 
      5    This file is part of the GNU opcodes library.
      6 
      7    This library is free software; you can redistribute it and/or modify
      8    it under the terms of the GNU General Public License as published by
      9    the Free Software Foundation; either version 3, or (at your option)
     10    any later version.
     11 
     12    It is distributed in the hope that it will be useful,
     13    but WITHOUT ANY WARRANTY; without even the implied warranty of
     14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15    GNU General Public License for more details.
     16 
     17    You should have received a copy of the GNU General Public License
     18    along with this library; see the file COPYING3.  If not, write to the
     19    Free Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
     20    02110-1301, USA.  */
     21 
     22 #ifndef CGEN_BASIC_OPS_H
     23 #define CGEN_BASIC_OPS_H
     24 
     25 #include <assert.h>
     26 
     27 #if defined (__GNUC__) && ! defined (SEMOPS_DEFINE_INLINE)
     28 #define SEMOPS_DEFINE_INLINE
     29 #define SEMOPS_INLINE extern inline
     30 #else
     31 #define SEMOPS_INLINE
     32 #endif
     33 
     34 /* These don't really have a mode.  */
     35 #define ANDIF(x, y) ((x) && (y))
     36 #define ORIF(x, y) ((x) || (y))
     37 
     38 #define SUBBI(x, y) ((x) - (y))
     39 #define ANDBI(x, y) ((x) & (y))
     40 #define ORBI(x, y) ((x) | (y))
     41 #define XORBI(x, y) ((x) ^ (y))
     42 #define NEGBI(x) (- (x))
     43 #define NOTBI(x) (! (BI) (x))
     44 #define INVBI(x) (~ (x))
     45 #define EQBI(x, y) ((BI) (x) == (BI) (y))
     46 #define NEBI(x, y) ((BI) (x) != (BI) (y))
     47 #define LTBI(x, y) ((BI) (x) < (BI) (y))
     48 #define LEBI(x, y) ((BI) (x) <= (BI) (y))
     49 #define GTBI(x, y) ((BI) (x) > (BI) (y))
     50 #define GEBI(x, y) ((BI) (x) >= (BI) (y))
     51 #define LTUBI(x, y) ((BI) (x) < (BI) (y))
     52 #define LEUBI(x, y) ((BI) (x) <= (BI) (y))
     53 #define GTUBI(x, y) ((BI) (x) > (BI) (y))
     54 #define GEUBI(x, y) ((BI) (x) >= (BI) (y))
     55 
     56 #define ADDQI(x, y) ((x) + (y))
     58 #define SUBQI(x, y) ((x) - (y))
     59 #define MULQI(x, y) ((x) * (y))
     60 #define DIVQI(x, y) ((QI) (x) / (QI) (y))
     61 #define UDIVQI(x, y) ((UQI) (x) / (UQI) (y))
     62 #define MODQI(x, y) ((QI) (x) % (QI) (y))
     63 #define UMODQI(x, y) ((UQI) (x) % (UQI) (y))
     64 #define SRAQI(x, y) ((QI) (x) >> (y))
     65 #define SRLQI(x, y) ((UQI) (x) >> (y))
     66 #define SLLQI(x, y) ((UQI) (x) << (y))
     67 extern QI RORQI (QI, int);
     68 extern QI ROLQI (QI, int);
     69 #define ANDQI(x, y) ((x) & (y))
     70 #define ORQI(x, y) ((x) | (y))
     71 #define XORQI(x, y) ((x) ^ (y))
     72 #define NEGQI(x) (- (x))
     73 #define NOTQI(x) (! (QI) (x))
     74 #define INVQI(x) (~ (x))
     75 #define ABSQI(x) ((x) < 0 ? -(x) : (x))
     76 #define EQQI(x, y) ((QI) (x) == (QI) (y))
     77 #define NEQI(x, y) ((QI) (x) != (QI) (y))
     78 #define LTQI(x, y) ((QI) (x) < (QI) (y))
     79 #define LEQI(x, y) ((QI) (x) <= (QI) (y))
     80 #define GTQI(x, y) ((QI) (x) > (QI) (y))
     81 #define GEQI(x, y) ((QI) (x) >= (QI) (y))
     82 #define LTUQI(x, y) ((UQI) (x) < (UQI) (y))
     83 #define LEUQI(x, y) ((UQI) (x) <= (UQI) (y))
     84 #define GTUQI(x, y) ((UQI) (x) > (UQI) (y))
     85 #define GEUQI(x, y) ((UQI) (x) >= (UQI) (y))
     86 
     87 #define ADDHI(x, y) ((x) + (y))
     89 #define SUBHI(x, y) ((x) - (y))
     90 #define MULHI(x, y) ((x) * (y))
     91 #define DIVHI(x, y) ((HI) (x) / (HI) (y))
     92 #define UDIVHI(x, y) ((UHI) (x) / (UHI) (y))
     93 #define MODHI(x, y) ((HI) (x) % (HI) (y))
     94 #define UMODHI(x, y) ((UHI) (x) % (UHI) (y))
     95 #define SRAHI(x, y) ((HI) (x) >> (y))
     96 #define SRLHI(x, y) ((UHI) (x) >> (y))
     97 #define SLLHI(x, y) ((UHI) (x) << (y))
     98 extern HI RORHI (HI, int);
     99 extern HI ROLHI (HI, int);
    100 #define ANDHI(x, y) ((x) & (y))
    101 #define ORHI(x, y) ((x) | (y))
    102 #define XORHI(x, y) ((x) ^ (y))
    103 #define NEGHI(x) (- (x))
    104 #define NOTHI(x) (! (HI) (x))
    105 #define INVHI(x) (~ (x))
    106 #define ABSHI(x) ((x) < 0 ? -(x) : (x))
    107 #define EQHI(x, y) ((HI) (x) == (HI) (y))
    108 #define NEHI(x, y) ((HI) (x) != (HI) (y))
    109 #define LTHI(x, y) ((HI) (x) < (HI) (y))
    110 #define LEHI(x, y) ((HI) (x) <= (HI) (y))
    111 #define GTHI(x, y) ((HI) (x) > (HI) (y))
    112 #define GEHI(x, y) ((HI) (x) >= (HI) (y))
    113 #define LTUHI(x, y) ((UHI) (x) < (UHI) (y))
    114 #define LEUHI(x, y) ((UHI) (x) <= (UHI) (y))
    115 #define GTUHI(x, y) ((UHI) (x) > (UHI) (y))
    116 #define GEUHI(x, y) ((UHI) (x) >= (UHI) (y))
    117 
    118 #define ADDSI(x, y) ((x) + (y))
    120 #define SUBSI(x, y) ((x) - (y))
    121 #define MULSI(x, y) ((x) * (y))
    122 #define DIVSI(x, y) ((SI) (x) / (SI) (y))
    123 #define UDIVSI(x, y) ((USI) (x) / (USI) (y))
    124 #define MODSI(x, y) ((SI) (x) % (SI) (y))
    125 #define UMODSI(x, y) ((USI) (x) % (USI) (y))
    126 #define SRASI(x, y) ((SI) (x) >> (y))
    127 #define SRLSI(x, y) ((USI) (x) >> (y))
    128 #define SLLSI(x, y) ((USI) (x) << (y))
    129 extern SI RORSI (SI, int);
    130 extern SI ROLSI (SI, int);
    131 #define ANDSI(x, y) ((x) & (y))
    132 #define ORSI(x, y) ((x) | (y))
    133 #define XORSI(x, y) ((x) ^ (y))
    134 #define NEGSI(x) (- (x))
    135 #define NOTSI(x) (! (SI) (x))
    136 #define INVSI(x) (~ (x))
    137 #define ABSSI(x) ((x) < 0 ? -(x) : (x))
    138 #define EQSI(x, y) ((SI) (x) == (SI) (y))
    139 #define NESI(x, y) ((SI) (x) != (SI) (y))
    140 #define LTSI(x, y) ((SI) (x) < (SI) (y))
    141 #define LESI(x, y) ((SI) (x) <= (SI) (y))
    142 #define GTSI(x, y) ((SI) (x) > (SI) (y))
    143 #define GESI(x, y) ((SI) (x) >= (SI) (y))
    144 #define LTUSI(x, y) ((USI) (x) < (USI) (y))
    145 #define LEUSI(x, y) ((USI) (x) <= (USI) (y))
    146 #define GTUSI(x, y) ((USI) (x) > (USI) (y))
    147 #define GEUSI(x, y) ((USI) (x) >= (USI) (y))
    148 
    149 #ifdef DI_FN_SUPPORT
    151 extern DI ADDDI (DI, DI);
    152 extern DI SUBDI (DI, DI);
    153 extern DI MULDI (DI, DI);
    154 extern DI DIVDI (DI, DI);
    155 extern DI UDIVDI (DI, DI);
    156 extern DI MODDI (DI, DI);
    157 extern DI UMODDI (DI, DI);
    158 extern DI SRADI (DI, int);
    159 extern UDI SRLDI (UDI, int);
    160 extern UDI SLLDI (UDI, int);
    161 extern DI RORDI (DI, int);
    162 extern DI ROLDI (DI, int);
    163 extern DI ANDDI (DI, DI);
    164 extern DI ORDI (DI, DI);
    165 extern DI XORDI (DI, DI);
    166 extern DI NEGDI (DI);
    167 extern int NOTDI (DI);
    168 extern DI INVDI (DI);
    169 extern int EQDI (DI, DI);
    170 extern int NEDI (DI, DI);
    171 extern int LTDI (DI, DI);
    172 extern int LEDI (DI, DI);
    173 extern int GTDI (DI, DI);
    174 extern int GEDI (DI, DI);
    175 extern int LTUDI (UDI, UDI);
    176 extern int LEUDI (UDI, UDI);
    177 extern int GTUDI (UDI, UDI);
    178 extern int GEUDI (UDI, UDI);
    179 #else /* ! DI_FN_SUPPORT */
    180 #define ADDDI(x, y) ((x) + (y))
    181 #define SUBDI(x, y) ((x) - (y))
    182 #define MULDI(x, y) ((x) * (y))
    183 #define DIVDI(x, y) ((DI) (x) / (DI) (y))
    184 #define UDIVDI(x, y) ((UDI) (x) / (UDI) (y))
    185 #define MODDI(x, y) ((DI) (x) % (DI) (y))
    186 #define UMODDI(x, y) ((UDI) (x) % (UDI) (y))
    187 #define SRADI(x, y) ((DI) (x) >> (y))
    188 #define SRLDI(x, y) ((UDI) (x) >> (y))
    189 #define SLLDI(x, y) ((UDI) (x) << (y))
    190 extern DI RORDI (DI, int);
    191 extern DI ROLDI (DI, int);
    192 #define ANDDI(x, y) ((x) & (y))
    193 #define ORDI(x, y) ((x) | (y))
    194 #define XORDI(x, y) ((x) ^ (y))
    195 #define NEGDI(x) (- (x))
    196 #define NOTDI(x) (! (DI) (x))
    197 #define INVDI(x) (~ (x))
    198 #define ABSDI(x) ((x) < 0 ? -(x) : (x))
    199 #define EQDI(x, y) ((DI) (x) == (DI) (y))
    200 #define NEDI(x, y) ((DI) (x) != (DI) (y))
    201 #define LTDI(x, y) ((DI) (x) < (DI) (y))
    202 #define LEDI(x, y) ((DI) (x) <= (DI) (y))
    203 #define GTDI(x, y) ((DI) (x) > (DI) (y))
    204 #define GEDI(x, y) ((DI) (x) >= (DI) (y))
    205 #define LTUDI(x, y) ((UDI) (x) < (UDI) (y))
    206 #define LEUDI(x, y) ((UDI) (x) <= (UDI) (y))
    207 #define GTUDI(x, y) ((UDI) (x) > (UDI) (y))
    208 #define GEUDI(x, y) ((UDI) (x) >= (UDI) (y))
    209 #endif /* DI_FN_SUPPORT */
    210 
    211 #define EXTBIQI(x) ((QI) (BI) (x))
    213 #define EXTBIHI(x) ((HI) (BI) (x))
    214 #define EXTBISI(x) ((SI) (BI) (x))
    215 #if defined (DI_FN_SUPPORT)
    216 extern DI EXTBIDI (BI);
    217 #else
    218 #define EXTBIDI(x) ((DI) (BI) (x))
    219 #endif
    220 #define EXTQIHI(x) ((HI) (QI) (x))
    221 #define EXTQISI(x) ((SI) (QI) (x))
    222 #if defined (DI_FN_SUPPORT)
    223 extern DI EXTQIDI (QI);
    224 #else
    225 #define EXTQIDI(x) ((DI) (QI) (x))
    226 #endif
    227 #define EXTHIHI(x) ((HI) (HI) (x))
    228 #define EXTHISI(x) ((SI) (HI) (x))
    229 #define EXTSISI(x) ((SI) (SI) (x))
    230 #if defined (DI_FN_SUPPORT)
    231 extern DI EXTHIDI (HI);
    232 #else
    233 #define EXTHIDI(x) ((DI) (HI) (x))
    234 #endif
    235 #if defined (DI_FN_SUPPORT)
    236 extern DI EXTSIDI (SI);
    237 #else
    238 #define EXTSIDI(x) ((DI) (SI) (x))
    239 #endif
    240 
    241 #define ZEXTBIQI(x) ((QI) (BI) (x))
    243 #define ZEXTBIHI(x) ((HI) (BI) (x))
    244 #define ZEXTBISI(x) ((SI) (BI) (x))
    245 #if defined (DI_FN_SUPPORT)
    246 extern DI ZEXTBIDI (BI);
    247 #else
    248 #define ZEXTBIDI(x) ((DI) (BI) (x))
    249 #endif
    250 #define ZEXTQIHI(x) ((HI) (UQI) (x))
    251 #define ZEXTQISI(x) ((SI) (UQI) (x))
    252 #if defined (DI_FN_SUPPORT)
    253 extern DI ZEXTQIDI (QI);
    254 #else
    255 #define ZEXTQIDI(x) ((DI) (UQI) (x))
    256 #endif
    257 #define ZEXTHISI(x) ((SI) (UHI) (x))
    258 #define ZEXTHIHI(x) ((HI) (UHI) (x))
    259 #define ZEXTSISI(x) ((SI) (USI) (x))
    260 #if defined (DI_FN_SUPPORT)
    261 extern DI ZEXTHIDI (HI);
    262 #else
    263 #define ZEXTHIDI(x) ((DI) (UHI) (x))
    264 #endif
    265 #if defined (DI_FN_SUPPORT)
    266 extern DI ZEXTSIDI (SI);
    267 #else
    268 #define ZEXTSIDI(x) ((DI) (USI) (x))
    269 #endif
    270 
    271 #define TRUNCQIBI(x) ((BI) (QI) (x))
    273 #define TRUNCHIBI(x) ((BI) (HI) (x))
    274 #define TRUNCHIQI(x) ((QI) (HI) (x))
    275 #define TRUNCSIBI(x) ((BI) (SI) (x))
    276 #define TRUNCSIQI(x) ((QI) (SI) (x))
    277 #define TRUNCSIHI(x) ((HI) (SI) (x))
    278 #define TRUNCSISI(x) ((SI) (SI) (x))
    279 #if defined (DI_FN_SUPPORT)
    280 extern BI TRUNCDIBI (DI);
    281 #else
    282 #define TRUNCDIBI(x) ((BI) (DI) (x))
    283 #endif
    284 #if defined (DI_FN_SUPPORT)
    285 extern QI TRUNCDIQI (DI);
    286 #else
    287 #define TRUNCDIQI(x) ((QI) (DI) (x))
    288 #endif
    289 #if defined (DI_FN_SUPPORT)
    290 extern HI TRUNCDIHI (DI);
    291 #else
    292 #define TRUNCDIHI(x) ((HI) (DI) (x))
    293 #endif
    294 #if defined (DI_FN_SUPPORT)
    295 extern SI TRUNCDISI (DI);
    296 #else
    297 #define TRUNCDISI(x) ((SI) (DI) (x))
    298 #endif
    299 
    300 /* Composing/decomposing the various types.
    302    Word ordering is endian-independent.  Words are specified most to least
    303    significant and word number 0 is the most significant word.
    304    ??? May also wish an endian-dependent version.  Later.  */
    305 
    306 static QI SUBWORDSIQI (SI, int);
    307 static HI SUBWORDSIHI (SI, int);
    308 static QI SUBWORDDIQI (DI, int);
    309 static HI SUBWORDDIHI (DI, int);
    310 static SI SUBWORDDISI (DI, int);
    311 
    312 #ifdef SEMOPS_DEFINE_INLINE
    313 
    314 SEMOPS_INLINE QI
    315 SUBWORDSIQI (SI in, int byte)
    316 {
    317   assert (byte >= 0 && byte <= 3);
    318   return (UQI) (in >> (8 * (3 - byte))) & 0xFF;
    319 }
    320 
    321 SEMOPS_INLINE HI
    322 SUBWORDSIHI (SI in, int word)
    323 {
    324   if (word == 0)
    325     return (USI) in >> 16;
    326   else
    327     return in;
    328 }
    329 
    330 SEMOPS_INLINE QI
    331 SUBWORDDIQI (DI in, int byte)
    332 {
    333   assert (byte >= 0 && byte <= 7);
    334   return (UQI) (in >> (8 * (7 - byte))) & 0xFF;
    335 }
    336 
    337 SEMOPS_INLINE HI
    338 SUBWORDDIHI (DI in, int word)
    339 {
    340   assert (word >= 0 && word <= 3);
    341   return (UHI) (in >> (16 * (3 - word))) & 0xFFFF;
    342 }
    343 
    344 SEMOPS_INLINE SI
    345 SUBWORDDISI (DI in, int word)
    346 {
    347   if (word == 0)
    348     return (UDI) in >> 32;
    349   else
    350     return in;
    351 }
    352 
    353 #endif /* SUBWORD,JOIN */
    354 
    355 #endif /* CGEN_BASIC_OPS_H */
    356