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